dwmac-meson.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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/platform_device.h>
  18. #include <linux/stmmac.h>
  19. #include "stmmac_platform.h"
  20. #define ETHMAC_SPEED_100 BIT(1)
  21. struct meson_dwmac {
  22. struct device *dev;
  23. void __iomem *reg;
  24. };
  25. static void meson6_dwmac_fix_mac_speed(void *priv, unsigned int speed)
  26. {
  27. struct meson_dwmac *dwmac = priv;
  28. unsigned int val;
  29. val = readl(dwmac->reg);
  30. switch (speed) {
  31. case SPEED_10:
  32. val &= ~ETHMAC_SPEED_100;
  33. break;
  34. case SPEED_100:
  35. val |= ETHMAC_SPEED_100;
  36. break;
  37. }
  38. writel(val, dwmac->reg);
  39. }
  40. static void *meson6_dwmac_setup(struct platform_device *pdev)
  41. {
  42. struct meson_dwmac *dwmac;
  43. struct resource *res;
  44. dwmac = devm_kzalloc(&pdev->dev, sizeof(*dwmac), GFP_KERNEL);
  45. if (!dwmac)
  46. return ERR_PTR(-ENOMEM);
  47. res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  48. dwmac->reg = devm_ioremap_resource(&pdev->dev, res);
  49. if (IS_ERR(dwmac->reg))
  50. return ERR_CAST(dwmac->reg);
  51. return dwmac;
  52. }
  53. const struct stmmac_of_data meson6_dwmac_data = {
  54. .setup = meson6_dwmac_setup,
  55. .fix_mac_speed = meson6_dwmac_fix_mac_speed,
  56. };