sxgbe_platform.c 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /* 10G controller driver for Samsung SoCs
  2. *
  3. * Copyright (C) 2013 Samsung Electronics Co., Ltd.
  4. * http://www.samsung.com
  5. *
  6. * Author: Siva Reddy Kallam <siva.kallam@samsung.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 version 2 as
  10. * published by the Free Software Foundation.
  11. */
  12. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  13. #include <linux/etherdevice.h>
  14. #include <linux/io.h>
  15. #include <linux/module.h>
  16. #include <linux/netdevice.h>
  17. #include <linux/of.h>
  18. #include <linux/of_irq.h>
  19. #include <linux/of_net.h>
  20. #include <linux/phy.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/sxgbe_platform.h>
  23. #include "sxgbe_common.h"
  24. #include "sxgbe_reg.h"
  25. #ifdef CONFIG_OF
  26. static int sxgbe_probe_config_dt(struct platform_device *pdev,
  27. struct sxgbe_plat_data *plat,
  28. const char **mac)
  29. {
  30. struct device_node *np = pdev->dev.of_node;
  31. struct sxgbe_dma_cfg *dma_cfg;
  32. if (!np)
  33. return -ENODEV;
  34. *mac = of_get_mac_address(np);
  35. plat->interface = of_get_phy_mode(np);
  36. plat->bus_id = of_alias_get_id(np, "ethernet");
  37. if (plat->bus_id < 0)
  38. plat->bus_id = 0;
  39. plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
  40. sizeof(*plat->mdio_bus_data),
  41. GFP_KERNEL);
  42. dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*dma_cfg), GFP_KERNEL);
  43. if (!dma_cfg)
  44. return -ENOMEM;
  45. plat->dma_cfg = dma_cfg;
  46. of_property_read_u32(np, "samsung,pbl", &dma_cfg->pbl);
  47. if (of_property_read_u32(np, "samsung,burst-map", &dma_cfg->burst_map) == 0)
  48. dma_cfg->fixed_burst = true;
  49. return 0;
  50. }
  51. #else
  52. static int sxgbe_probe_config_dt(struct platform_device *pdev,
  53. struct sxgbe_plat_data *plat,
  54. const char **mac)
  55. {
  56. return -ENOSYS;
  57. }
  58. #endif /* CONFIG_OF */
  59. /**
  60. * sxgbe_platform_probe
  61. * @pdev: platform device pointer
  62. * Description: platform_device probe function. It allocates
  63. * the necessary resources and invokes the main to init
  64. * the net device, register the mdio bus etc.
  65. */
  66. static int sxgbe_platform_probe(struct platform_device *pdev)
  67. {
  68. int ret;
  69. int i, chan;
  70. struct resource *res;
  71. struct device *dev = &pdev->dev;
  72. void __iomem *addr;
  73. struct sxgbe_priv_data *priv = NULL;
  74. struct sxgbe_plat_data *plat_dat = NULL;
  75. const char *mac = NULL;
  76. struct net_device *ndev = platform_get_drvdata(pdev);
  77. struct device_node *node = dev->of_node;
  78. /* Get memory resource */
  79. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  80. addr = devm_ioremap_resource(dev, res);
  81. if (IS_ERR(addr))
  82. return PTR_ERR(addr);
  83. if (pdev->dev.of_node) {
  84. plat_dat = devm_kzalloc(&pdev->dev,
  85. sizeof(struct sxgbe_plat_data),
  86. GFP_KERNEL);
  87. if (!plat_dat)
  88. return -ENOMEM;
  89. ret = sxgbe_probe_config_dt(pdev, plat_dat, &mac);
  90. if (ret) {
  91. pr_err("%s: main dt probe failed\n", __func__);
  92. return ret;
  93. }
  94. }
  95. priv = sxgbe_drv_probe(&(pdev->dev), plat_dat, addr);
  96. if (!priv) {
  97. pr_err("%s: main driver probe failed\n", __func__);
  98. goto err_out;
  99. }
  100. /* Get the SXGBE common INT information */
  101. priv->irq = irq_of_parse_and_map(node, 0);
  102. if (priv->irq <= 0) {
  103. dev_err(dev, "sxgbe common irq parsing failed\n");
  104. goto err_drv_remove;
  105. }
  106. /* Get MAC address if available (DT) */
  107. if (mac)
  108. ether_addr_copy(priv->dev->dev_addr, mac);
  109. /* Get the TX/RX IRQ numbers */
  110. for (i = 0, chan = 1; i < SXGBE_TX_QUEUES; i++) {
  111. priv->txq[i]->irq_no = irq_of_parse_and_map(node, chan++);
  112. if (priv->txq[i]->irq_no <= 0) {
  113. dev_err(dev, "sxgbe tx irq parsing failed\n");
  114. goto err_tx_irq_unmap;
  115. }
  116. }
  117. for (i = 0; i < SXGBE_RX_QUEUES; i++) {
  118. priv->rxq[i]->irq_no = irq_of_parse_and_map(node, chan++);
  119. if (priv->rxq[i]->irq_no <= 0) {
  120. dev_err(dev, "sxgbe rx irq parsing failed\n");
  121. goto err_rx_irq_unmap;
  122. }
  123. }
  124. priv->lpi_irq = irq_of_parse_and_map(node, chan);
  125. if (priv->lpi_irq <= 0) {
  126. dev_err(dev, "sxgbe lpi irq parsing failed\n");
  127. goto err_rx_irq_unmap;
  128. }
  129. platform_set_drvdata(pdev, priv->dev);
  130. pr_debug("platform driver registration completed\n");
  131. return 0;
  132. err_rx_irq_unmap:
  133. while (--i)
  134. irq_dispose_mapping(priv->rxq[i]->irq_no);
  135. i = SXGBE_TX_QUEUES;
  136. err_tx_irq_unmap:
  137. while (--i)
  138. irq_dispose_mapping(priv->txq[i]->irq_no);
  139. irq_dispose_mapping(priv->irq);
  140. err_drv_remove:
  141. sxgbe_drv_remove(ndev);
  142. err_out:
  143. return -ENODEV;
  144. }
  145. /**
  146. * sxgbe_platform_remove
  147. * @pdev: platform device pointer
  148. * Description: this function calls the main to free the net resources
  149. * and calls the platforms hook and release the resources (e.g. mem).
  150. */
  151. static int sxgbe_platform_remove(struct platform_device *pdev)
  152. {
  153. struct net_device *ndev = platform_get_drvdata(pdev);
  154. int ret = sxgbe_drv_remove(ndev);
  155. return ret;
  156. }
  157. #ifdef CONFIG_PM
  158. static int sxgbe_platform_suspend(struct device *dev)
  159. {
  160. struct net_device *ndev = dev_get_drvdata(dev);
  161. return sxgbe_suspend(ndev);
  162. }
  163. static int sxgbe_platform_resume(struct device *dev)
  164. {
  165. struct net_device *ndev = dev_get_drvdata(dev);
  166. return sxgbe_resume(ndev);
  167. }
  168. static int sxgbe_platform_freeze(struct device *dev)
  169. {
  170. struct net_device *ndev = dev_get_drvdata(dev);
  171. return sxgbe_freeze(ndev);
  172. }
  173. static int sxgbe_platform_restore(struct device *dev)
  174. {
  175. struct net_device *ndev = dev_get_drvdata(dev);
  176. return sxgbe_restore(ndev);
  177. }
  178. static const struct dev_pm_ops sxgbe_platform_pm_ops = {
  179. .suspend = sxgbe_platform_suspend,
  180. .resume = sxgbe_platform_resume,
  181. .freeze = sxgbe_platform_freeze,
  182. .thaw = sxgbe_platform_restore,
  183. .restore = sxgbe_platform_restore,
  184. };
  185. #else
  186. static const struct dev_pm_ops sxgbe_platform_pm_ops;
  187. #endif /* CONFIG_PM */
  188. static const struct of_device_id sxgbe_dt_ids[] = {
  189. { .compatible = "samsung,sxgbe-v2.0a"},
  190. { /* sentinel */ }
  191. };
  192. MODULE_DEVICE_TABLE(of, sxgbe_dt_ids);
  193. static struct platform_driver sxgbe_platform_driver = {
  194. .probe = sxgbe_platform_probe,
  195. .remove = sxgbe_platform_remove,
  196. .driver = {
  197. .name = SXGBE_RESOURCE_NAME,
  198. .pm = &sxgbe_platform_pm_ops,
  199. .of_match_table = of_match_ptr(sxgbe_dt_ids),
  200. },
  201. };
  202. int sxgbe_register_platform(void)
  203. {
  204. int err;
  205. err = platform_driver_register(&sxgbe_platform_driver);
  206. if (err)
  207. pr_err("failed to register the platform driver\n");
  208. return err;
  209. }
  210. void sxgbe_unregister_platform(void)
  211. {
  212. platform_driver_unregister(&sxgbe_platform_driver);
  213. }