dwmac-generic.c 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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/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.50a"},
  62. { .compatible = "snps,dwmac-3.610"},
  63. { .compatible = "snps,dwmac-3.70a"},
  64. { .compatible = "snps,dwmac-3.710"},
  65. { .compatible = "snps,dwmac-4.00"},
  66. { .compatible = "snps,dwmac-4.10a"},
  67. { .compatible = "snps,dwmac"},
  68. { }
  69. };
  70. MODULE_DEVICE_TABLE(of, dwmac_generic_match);
  71. static struct platform_driver dwmac_generic_driver = {
  72. .probe = dwmac_generic_probe,
  73. .remove = stmmac_pltfr_remove,
  74. .driver = {
  75. .name = STMMAC_RESOURCE_NAME,
  76. .pm = &stmmac_pltfr_pm_ops,
  77. .of_match_table = of_match_ptr(dwmac_generic_match),
  78. },
  79. };
  80. module_platform_driver(dwmac_generic_driver);
  81. MODULE_DESCRIPTION("Generic dwmac driver");
  82. MODULE_LICENSE("GPL v2");