dwmac-generic.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * Generic DWMAC platform driver
  3. *
  4. * Copyright (C) 2007-2011 STMicroelectronics Ltd
  5. * Copyright (C) 2015 Joachim Eastwood <[email protected]>
  6. *
  7. * This file is licensed under the terms of the GNU General Public
  8. * License version 2. This program is licensed "as is" without any
  9. * warranty of any kind, whether express or implied.
  10. */
  11. #include <linux/module.h>
  12. #include <linux/of.h>
  13. #include <linux/platform_device.h>
  14. #include "stmmac.h"
  15. #include "stmmac_platform.h"
  16. static int dwmac_generic_probe(struct platform_device *pdev)
  17. {
  18. struct plat_stmmacenet_data *plat_dat;
  19. struct stmmac_resources stmmac_res;
  20. int ret;
  21. ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  22. if (ret)
  23. return ret;
  24. if (pdev->dev.of_node) {
  25. plat_dat = stmmac_probe_config_dt(pdev, stmmac_res.mac);
  26. if (IS_ERR(plat_dat)) {
  27. dev_err(&pdev->dev, "dt configuration failed\n");
  28. return PTR_ERR(plat_dat);
  29. }
  30. } else {
  31. plat_dat = dev_get_platdata(&pdev->dev);
  32. if (!plat_dat) {
  33. dev_err(&pdev->dev, "no platform data provided\n");
  34. return -EINVAL;
  35. }
  36. /* Set default value for multicast hash bins */
  37. plat_dat->multicast_filter_bins = HASH_TABLE_SIZE;
  38. /* Set default value for unicast filter entries */
  39. plat_dat->unicast_filter_entries = 1;
  40. }
  41. /* Custom initialisation (if needed) */
  42. if (plat_dat->init) {
  43. ret = plat_dat->init(pdev, plat_dat->bsp_priv);
  44. if (ret)
  45. goto err_remove_config_dt;
  46. }
  47. ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  48. if (ret)
  49. goto err_exit;
  50. return 0;
  51. err_exit:
  52. if (plat_dat->exit)
  53. plat_dat->exit(pdev, plat_dat->bsp_priv);
  54. err_remove_config_dt:
  55. if (pdev->dev.of_node)
  56. stmmac_remove_config_dt(pdev, plat_dat);
  57. return ret;
  58. }
  59. static const struct of_device_id dwmac_generic_match[] = {
  60. { .compatible = "st,spear600-gmac"},
  61. { .compatible = "snps,dwmac-3.40a"},
  62. { .compatible = "snps,dwmac-3.50a"},
  63. { .compatible = "snps,dwmac-3.610"},
  64. { .compatible = "snps,dwmac-3.70a"},
  65. { .compatible = "snps,dwmac-3.710"},
  66. { .compatible = "snps,dwmac-4.00"},
  67. { .compatible = "snps,dwmac-4.10a"},
  68. { .compatible = "snps,dwmac"},
  69. { .compatible = "snps,dwxgmac-2.10"},
  70. { .compatible = "snps,dwxgmac"},
  71. { }
  72. };
  73. MODULE_DEVICE_TABLE(of, dwmac_generic_match);
  74. static struct platform_driver dwmac_generic_driver = {
  75. .probe = dwmac_generic_probe,
  76. .remove = stmmac_pltfr_remove,
  77. .driver = {
  78. .name = STMMAC_RESOURCE_NAME,
  79. .pm = &stmmac_pltfr_pm_ops,
  80. .of_match_table = of_match_ptr(dwmac_generic_match),
  81. },
  82. };
  83. module_platform_driver(dwmac_generic_driver);
  84. MODULE_DESCRIPTION("Generic dwmac driver");
  85. MODULE_LICENSE("GPL v2");