dwmac-meson.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Amlogic Meson 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. return -ENOMEM;
  57. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  58. dwmac->reg = devm_ioremap_resource(&pdev->dev, res);
  59. if (IS_ERR(dwmac->reg))
  60. return PTR_ERR(dwmac->reg);
  61. plat_dat->bsp_priv = dwmac;
  62. plat_dat->fix_mac_speed = meson6_dwmac_fix_mac_speed;
  63. return stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  64. }
  65. static const struct of_device_id meson6_dwmac_match[] = {
  66. { .compatible = "amlogic,meson6-dwmac" },
  67. { }
  68. };
  69. MODULE_DEVICE_TABLE(of, meson6_dwmac_match);
  70. static struct platform_driver meson6_dwmac_driver = {
  71. .probe = meson6_dwmac_probe,
  72. .remove = stmmac_pltfr_remove,
  73. .driver = {
  74. .name = "meson6-dwmac",
  75. .pm = &stmmac_pltfr_pm_ops,
  76. .of_match_table = meson6_dwmac_match,
  77. },
  78. };
  79. module_platform_driver(meson6_dwmac_driver);
  80. MODULE_AUTHOR("Beniamino Galvani <b.galvani@gmail.com>");
  81. MODULE_DESCRIPTION("Amlogic Meson DWMAC glue layer");
  82. MODULE_LICENSE("GPL v2");