dwmac-generic.c 2.3 KB

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