dwmac-meson.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Amlogic Meson6 and Meson8 DWMAC glue layer
  4. *
  5. * Copyright (C) 2014 Beniamino Galvani <[email protected]>
  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 void meson6_dwmac_fix_mac_speed(void *priv, unsigned int speed)
  21. {
  22. struct meson_dwmac *dwmac = priv;
  23. unsigned int val;
  24. val = readl(dwmac->reg);
  25. switch (speed) {
  26. case SPEED_10:
  27. val &= ~ETHMAC_SPEED_100;
  28. break;
  29. case SPEED_100:
  30. val |= ETHMAC_SPEED_100;
  31. break;
  32. }
  33. writel(val, dwmac->reg);
  34. }
  35. static int meson6_dwmac_probe(struct platform_device *pdev)
  36. {
  37. struct plat_stmmacenet_data *plat_dat;
  38. struct stmmac_resources stmmac_res;
  39. struct meson_dwmac *dwmac;
  40. int ret;
  41. ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  42. if (ret)
  43. return ret;
  44. plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  45. if (IS_ERR(plat_dat))
  46. return PTR_ERR(plat_dat);
  47. dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
  48. if (!dwmac) {
  49. ret = -ENOMEM;
  50. goto err_remove_config_dt;
  51. }
  52. dwmac->reg = devm_platform_ioremap_resource(pdev, 1);
  53. if (IS_ERR(dwmac->reg)) {
  54. ret = PTR_ERR(dwmac->reg);
  55. goto err_remove_config_dt;
  56. }
  57. plat_dat->bsp_priv = dwmac;
  58. plat_dat->fix_mac_speed = meson6_dwmac_fix_mac_speed;
  59. ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  60. if (ret)
  61. goto err_remove_config_dt;
  62. return 0;
  63. err_remove_config_dt:
  64. stmmac_remove_config_dt(pdev, plat_dat);
  65. return ret;
  66. }
  67. static const struct of_device_id meson6_dwmac_match[] = {
  68. { .compatible = "amlogic,meson6-dwmac" },
  69. { }
  70. };
  71. MODULE_DEVICE_TABLE(of, meson6_dwmac_match);
  72. static struct platform_driver meson6_dwmac_driver = {
  73. .probe = meson6_dwmac_probe,
  74. .remove = stmmac_pltfr_remove,
  75. .driver = {
  76. .name = "meson6-dwmac",
  77. .pm = &stmmac_pltfr_pm_ops,
  78. .of_match_table = meson6_dwmac_match,
  79. },
  80. };
  81. module_platform_driver(meson6_dwmac_driver);
  82. MODULE_AUTHOR("Beniamino Galvani <[email protected]>");
  83. MODULE_DESCRIPTION("Amlogic Meson6 and Meson8 DWMAC glue layer");
  84. MODULE_LICENSE("GPL v2");