dwmac-meson.c 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Amlogic Meson6 and Meson8 DWMAC glue layer
  4. *
  5. * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
  6. */
  7. #include <linux/device.h>
  8. #include <linux/ethtool.h>
  9. #include <linux/io.h>
  10. #include <linux/ioport.h>
  11. #include <linux/module.h>
  12. #include <linux/platform_device.h>
  13. #include <linux/stmmac.h>
  14. #include "stmmac_platform.h"
  15. #define ETHMAC_SPEED_100 BIT(1)
  16. struct meson_dwmac {
  17. struct device *dev;
  18. void __iomem *reg;
  19. };
  20. static int meson6_dwmac_set_clk_tx_rate(void *bsp_priv, struct clk *clk_tx_i,
  21. phy_interface_t interface, int speed)
  22. {
  23. struct meson_dwmac *dwmac = bsp_priv;
  24. unsigned int val;
  25. val = readl(dwmac->reg);
  26. switch (speed) {
  27. case SPEED_10:
  28. val &= ~ETHMAC_SPEED_100;
  29. break;
  30. case SPEED_100:
  31. val |= ETHMAC_SPEED_100;
  32. break;
  33. }
  34. writel(val, dwmac->reg);
  35. return 0;
  36. }
  37. static int meson6_dwmac_probe(struct platform_device *pdev)
  38. {
  39. struct plat_stmmacenet_data *plat_dat;
  40. struct stmmac_resources stmmac_res;
  41. struct meson_dwmac *dwmac;
  42. int ret;
  43. ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  44. if (ret)
  45. return ret;
  46. plat_dat = devm_stmmac_probe_config_dt(pdev, stmmac_res.mac);
  47. if (IS_ERR(plat_dat))
  48. return PTR_ERR(plat_dat);
  49. dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
  50. if (!dwmac)
  51. return -ENOMEM;
  52. dwmac->reg = devm_platform_ioremap_resource(pdev, 1);
  53. if (IS_ERR(dwmac->reg))
  54. return PTR_ERR(dwmac->reg);
  55. plat_dat->bsp_priv = dwmac;
  56. plat_dat->set_clk_tx_rate = meson6_dwmac_set_clk_tx_rate;
  57. return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  58. }
  59. static const struct of_device_id meson6_dwmac_match[] = {
  60. { .compatible = "amlogic,meson6-dwmac" },
  61. { }
  62. };
  63. MODULE_DEVICE_TABLE(of, meson6_dwmac_match);
  64. static struct platform_driver meson6_dwmac_driver = {
  65. .probe = meson6_dwmac_probe,
  66. .remove = stmmac_pltfr_remove,
  67. .driver = {
  68. .name = "meson6-dwmac",
  69. .pm = &stmmac_pltfr_pm_ops,
  70. .of_match_table = meson6_dwmac_match,
  71. },
  72. };
  73. module_platform_driver(meson6_dwmac_driver);
  74. MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
  75. MODULE_DESCRIPTION("Amlogic Meson6 and Meson8 DWMAC glue layer");
  76. MODULE_LICENSE("GPL v2");