dwmac-meson.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /*
  2. * Amlogic Meson6 and Meson8 DWMAC glue layer
  3. *
  4. * Copyright (C) 2014 Beniamino Galvani <b.galvani@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * You should have received a copy of the GNU General Public License
  11. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  12. */
  13. #include <linux/device.h>
  14. #include <linux/ethtool.h>
  15. #include <linux/io.h>
  16. #include <linux/ioport.h>
  17. #include <linux/module.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/stmmac.h>
  20. #include "stmmac_platform.h"
  21. #define ETHMAC_SPEED_100 BIT(1)
  22. struct meson_dwmac {
  23. struct device *dev;
  24. void __iomem *reg;
  25. };
  26. static void meson6_dwmac_fix_mac_speed(void *priv, unsigned int speed)
  27. {
  28. struct meson_dwmac *dwmac = priv;
  29. unsigned int val;
  30. val = readl(dwmac->reg);
  31. switch (speed) {
  32. case SPEED_10:
  33. val &= ~ETHMAC_SPEED_100;
  34. break;
  35. case SPEED_100:
  36. val |= ETHMAC_SPEED_100;
  37. break;
  38. }
  39. writel(val, dwmac->reg);
  40. }
  41. static int meson6_dwmac_probe(struct platform_device *pdev)
  42. {
  43. struct plat_stmmacenet_data *plat_dat;
  44. struct stmmac_resources stmmac_res;
  45. struct meson_dwmac *dwmac;
  46. struct resource *res;
  47. int ret;
  48. ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  49. if (ret)
  50. return ret;
  51. plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  52. if (IS_ERR(plat_dat))
  53. return PTR_ERR(plat_dat);
  54. dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
  55. if (!dwmac) {
  56. ret = -ENOMEM;
  57. goto err_remove_config_dt;
  58. }
  59. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  60. dwmac->reg = devm_ioremap_resource(&pdev->dev, res);
  61. if (IS_ERR(dwmac->reg)) {
  62. ret = PTR_ERR(dwmac->reg);
  63. goto err_remove_config_dt;
  64. }
  65. plat_dat->bsp_priv = dwmac;
  66. plat_dat->fix_mac_speed = meson6_dwmac_fix_mac_speed;
  67. ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  68. if (ret)
  69. goto err_remove_config_dt;
  70. return 0;
  71. err_remove_config_dt:
  72. stmmac_remove_config_dt(pdev, plat_dat);
  73. return ret;
  74. }
  75. static const struct of_device_id meson6_dwmac_match[] = {
  76. { .compatible = "amlogic,meson6-dwmac" },
  77. { }
  78. };
  79. MODULE_DEVICE_TABLE(of, meson6_dwmac_match);
  80. static struct platform_driver meson6_dwmac_driver = {
  81. .probe = meson6_dwmac_probe,
  82. .remove = stmmac_pltfr_remove,
  83. .driver = {
  84. .name = "meson6-dwmac",
  85. .pm = &stmmac_pltfr_pm_ops,
  86. .of_match_table = meson6_dwmac_match,
  87. },
  88. };
  89. module_platform_driver(meson6_dwmac_driver);
  90. MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
  91. MODULE_DESCRIPTION("Amlogic Meson6 and Meson8 DWMAC glue layer");
  92. MODULE_LICENSE("GPL v2");