dwmac-meson.c 1.5 KB

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