dwmac-lpc18xx.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /*
  2. * DWMAC glue for NXP LPC18xx/LPC43xx Ethernet
  3. *
  4. * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
  5. *
  6. * This file is licensed under the terms of the GNU General Public
  7. * License version 2. This program is licensed "as is" without any
  8. * warranty of any kind, whether express or implied.
  9. */
  10. #include <linux/mfd/syscon.h>
  11. #include <linux/module.h>
  12. #include <linux/of.h>
  13. #include <linux/of_net.h>
  14. #include <linux/phy.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/regmap.h>
  17. #include <linux/stmmac.h>
  18. #include "stmmac_platform.h"
  19. /* Register defines for CREG syscon */
  20. #define LPC18XX_CREG_CREG6 0x12c
  21. # define LPC18XX_CREG_CREG6_ETHMODE_MASK 0x7
  22. # define LPC18XX_CREG_CREG6_ETHMODE_MII 0x0
  23. # define LPC18XX_CREG_CREG6_ETHMODE_RMII 0x4
  24. static int lpc18xx_dwmac_probe(struct platform_device *pdev)
  25. {
  26. struct plat_stmmacenet_data *plat_dat;
  27. struct stmmac_resources stmmac_res;
  28. struct regmap *reg;
  29. u8 ethmode;
  30. int ret;
  31. ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  32. if (ret)
  33. return ret;
  34. plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  35. if (IS_ERR(plat_dat))
  36. return PTR_ERR(plat_dat);
  37. plat_dat->has_gmac = true;
  38. reg = syscon_regmap_lookup_by_compatible("nxp,lpc1850-creg");
  39. if (IS_ERR(reg)) {
  40. dev_err(&pdev->dev, "syscon lookup failed\n");
  41. ret = PTR_ERR(reg);
  42. goto err_remove_config_dt;
  43. }
  44. if (plat_dat->interface == PHY_INTERFACE_MODE_MII) {
  45. ethmode = LPC18XX_CREG_CREG6_ETHMODE_MII;
  46. } else if (plat_dat->interface == PHY_INTERFACE_MODE_RMII) {
  47. ethmode = LPC18XX_CREG_CREG6_ETHMODE_RMII;
  48. } else {
  49. dev_err(&pdev->dev, "Only MII and RMII mode supported\n");
  50. ret = -EINVAL;
  51. goto err_remove_config_dt;
  52. }
  53. regmap_update_bits(reg, LPC18XX_CREG_CREG6,
  54. LPC18XX_CREG_CREG6_ETHMODE_MASK, ethmode);
  55. ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  56. if (ret)
  57. goto err_remove_config_dt;
  58. return 0;
  59. err_remove_config_dt:
  60. stmmac_remove_config_dt(pdev, plat_dat);
  61. return ret;
  62. }
  63. static const struct of_device_id lpc18xx_dwmac_match[] = {
  64. { .compatible = "nxp,lpc1850-dwmac" },
  65. { }
  66. };
  67. MODULE_DEVICE_TABLE(of, lpc18xx_dwmac_match);
  68. static struct platform_driver lpc18xx_dwmac_driver = {
  69. .probe = lpc18xx_dwmac_probe,
  70. .remove = stmmac_pltfr_remove,
  71. .driver = {
  72. .name = "lpc18xx-dwmac",
  73. .pm = &stmmac_pltfr_pm_ops,
  74. .of_match_table = lpc18xx_dwmac_match,
  75. },
  76. };
  77. module_platform_driver(lpc18xx_dwmac_driver);
  78. MODULE_AUTHOR("Joachim Eastwood <manabian@gmail.com>");
  79. MODULE_DESCRIPTION("DWMAC glue for LPC18xx/43xx Ethernet");
  80. MODULE_LICENSE("GPL v2");