dwmac-generic.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /*
  2. * Generic DWMAC platform driver
  3. *
  4. * Copyright (C) 2007-2011 STMicroelectronics Ltd
  5. * Copyright (C) 2015 Joachim Eastwood <manabian@gmail.com>
  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/acpi.h>
  12. #include <linux/module.h>
  13. #include <linux/of.h>
  14. #include <linux/platform_device.h>
  15. #include "stmmac.h"
  16. #include "stmmac_platform.h"
  17. static int dwmac_generic_probe(struct platform_device *pdev)
  18. {
  19. struct plat_stmmacenet_data *plat_dat;
  20. struct stmmac_resources stmmac_res;
  21. int ret;
  22. ret = stmmac_get_platform_resources(pdev, &stmmac_res);
  23. if (ret)
  24. return ret;
  25. if (pdev->dev.of_node) {
  26. plat_dat = stmmac_probe_config_dt(pdev, &stmmac_res.mac);
  27. if (IS_ERR(plat_dat)) {
  28. dev_err(&pdev->dev, "dt configuration failed\n");
  29. return PTR_ERR(plat_dat);
  30. }
  31. } else if (has_acpi_companion(&pdev->dev)) {
  32. plat_dat = stmmac_probe_config_acpi(pdev, &stmmac_res.mac);
  33. if (!plat_dat) {
  34. dev_err(&pdev->dev, "acpi configuration failed\n");
  35. return -EINVAL;
  36. }
  37. } else {
  38. plat_dat = dev_get_platdata(&pdev->dev);
  39. if (!plat_dat) {
  40. dev_err(&pdev->dev, "no platform data provided\n");
  41. return -EINVAL;
  42. }
  43. /* Set default value for multicast hash bins */
  44. plat_dat->multicast_filter_bins = HASH_TABLE_SIZE;
  45. /* Set default value for unicast filter entries */
  46. plat_dat->unicast_filter_entries = 1;
  47. }
  48. /* Custom initialisation (if needed) */
  49. if (plat_dat->init) {
  50. ret = plat_dat->init(pdev, plat_dat->bsp_priv);
  51. if (ret)
  52. goto err_remove_config_dt;
  53. }
  54. ret = stmmac_dvr_probe(&pdev->dev, plat_dat, &stmmac_res);
  55. if (ret)
  56. goto err_exit;
  57. return 0;
  58. err_exit:
  59. if (plat_dat->exit)
  60. plat_dat->exit(pdev, plat_dat->bsp_priv);
  61. err_remove_config_dt:
  62. if (pdev->dev.of_node)
  63. stmmac_remove_config_dt(pdev, plat_dat);
  64. return ret;
  65. }
  66. static const struct of_device_id dwmac_generic_match[] = {
  67. { .compatible = "st,spear600-gmac"},
  68. { .compatible = "snps,dwmac-3.50a"},
  69. { .compatible = "snps,dwmac-3.610"},
  70. { .compatible = "snps,dwmac-3.70a"},
  71. { .compatible = "snps,dwmac-3.710"},
  72. { .compatible = "snps,dwmac-4.00"},
  73. { .compatible = "snps,dwmac-4.10a"},
  74. { .compatible = "snps,dwmac"},
  75. { .compatible = "snps,dwxgmac-2.10"},
  76. { .compatible = "snps,dwxgmac"},
  77. { }
  78. };
  79. MODULE_DEVICE_TABLE(of, dwmac_generic_match);
  80. #ifdef CONFIG_ACPI
  81. static const struct acpi_device_id dwmac_acpi_ids[] = {
  82. { .id = "PHYT0004" },
  83. { .id = "FTGM0001" },
  84. {},
  85. };
  86. MODULE_DEVICE_TABLE(acpi, dwmac_acpi_ids);
  87. #else
  88. #define dwmac_acpi_ids NULL
  89. #endif
  90. static struct platform_driver dwmac_generic_driver = {
  91. .probe = dwmac_generic_probe,
  92. .remove = stmmac_pltfr_remove,
  93. .driver = {
  94. .name = STMMAC_RESOURCE_NAME,
  95. .pm = &stmmac_pltfr_pm_ops,
  96. .of_match_table = of_match_ptr(dwmac_generic_match),
  97. .acpi_match_table = ACPI_PTR(dwmac_acpi_ids),
  98. },
  99. };
  100. module_platform_driver(dwmac_generic_driver);
  101. MODULE_DESCRIPTION("Generic dwmac driver");
  102. MODULE_LICENSE("GPL v2");