emac_arc.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * emac_arc.c - ARC EMAC specific glue layer
  3. *
  4. * Copyright (C) 2014 Romain Perier
  5. *
  6. * Romain Perier <romain.perier@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. */
  18. #include <linux/etherdevice.h>
  19. #include <linux/module.h>
  20. #include <linux/of_net.h>
  21. #include <linux/platform_device.h>
  22. #include "emac.h"
  23. #define DRV_NAME "emac_arc"
  24. #define DRV_VERSION "1.0"
  25. static int emac_arc_probe(struct platform_device *pdev)
  26. {
  27. struct device *dev = &pdev->dev;
  28. struct net_device *ndev;
  29. struct arc_emac_priv *priv;
  30. int interface, err;
  31. if (!dev->of_node)
  32. return -ENODEV;
  33. ndev = alloc_etherdev(sizeof(struct arc_emac_priv));
  34. if (!ndev)
  35. return -ENOMEM;
  36. platform_set_drvdata(pdev, ndev);
  37. SET_NETDEV_DEV(ndev, dev);
  38. priv = netdev_priv(ndev);
  39. priv->drv_name = DRV_NAME;
  40. priv->drv_version = DRV_VERSION;
  41. interface = of_get_phy_mode(dev->of_node);
  42. if (interface < 0)
  43. interface = PHY_INTERFACE_MODE_MII;
  44. priv->clk = devm_clk_get(dev, "hclk");
  45. if (IS_ERR(priv->clk)) {
  46. dev_err(dev, "failed to retrieve host clock from device tree\n");
  47. err = -EINVAL;
  48. goto out_netdev;
  49. }
  50. err = arc_emac_probe(ndev, interface);
  51. out_netdev:
  52. if (err)
  53. free_netdev(ndev);
  54. return err;
  55. }
  56. static int emac_arc_remove(struct platform_device *pdev)
  57. {
  58. struct net_device *ndev = platform_get_drvdata(pdev);
  59. int err;
  60. err = arc_emac_remove(ndev);
  61. free_netdev(ndev);
  62. return err;
  63. }
  64. static const struct of_device_id emac_arc_dt_ids[] = {
  65. { .compatible = "snps,arc-emac" },
  66. { /* Sentinel */ }
  67. };
  68. MODULE_DEVICE_TABLE(of, emac_arc_dt_ids);
  69. static struct platform_driver emac_arc_driver = {
  70. .probe = emac_arc_probe,
  71. .remove = emac_arc_remove,
  72. .driver = {
  73. .name = DRV_NAME,
  74. .of_match_table = emac_arc_dt_ids,
  75. },
  76. };
  77. module_platform_driver(emac_arc_driver);
  78. MODULE_AUTHOR("Romain Perier <romain.perier@gmail.com>");
  79. MODULE_DESCRIPTION("ARC EMAC platform driver");
  80. MODULE_LICENSE("GPL");