stmmac_pci.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  1. /*******************************************************************************
  2. This contains the functions to handle the pci driver.
  3. Copyright (C) 2011-2012 Vayavya Labs Pvt Ltd
  4. This program is free software; you can redistribute it and/or modify it
  5. under the terms and conditions of the GNU General Public License,
  6. version 2, as published by the Free Software Foundation.
  7. This program is distributed in the hope it will be useful, but WITHOUT
  8. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  9. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  10. more details.
  11. You should have received a copy of the GNU General Public License along with
  12. this program; if not, write to the Free Software Foundation, Inc.,
  13. 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
  14. The full GNU General Public License is included in this distribution in
  15. the file called "COPYING".
  16. Author: Rayagond Kokatanur <rayagond@vayavyalabs.com>
  17. Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
  18. *******************************************************************************/
  19. #include <linux/pci.h>
  20. #include "stmmac.h"
  21. struct plat_stmmacenet_data plat_dat;
  22. struct stmmac_mdio_bus_data mdio_data;
  23. static void stmmac_default_data(void)
  24. {
  25. memset(&plat_dat, 0, sizeof(struct plat_stmmacenet_data));
  26. plat_dat.bus_id = 1;
  27. plat_dat.phy_addr = 0;
  28. plat_dat.interface = PHY_INTERFACE_MODE_GMII;
  29. plat_dat.pbl = 32;
  30. plat_dat.clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
  31. plat_dat.has_gmac = 1;
  32. plat_dat.force_sf_dma_mode = 1;
  33. mdio_data.bus_id = 1;
  34. mdio_data.phy_reset = NULL;
  35. mdio_data.phy_mask = 0;
  36. plat_dat.mdio_bus_data = &mdio_data;
  37. }
  38. /**
  39. * stmmac_pci_probe
  40. *
  41. * @pdev: pci device pointer
  42. * @id: pointer to table of device id/id's.
  43. *
  44. * Description: This probing function gets called for all PCI devices which
  45. * match the ID table and are not "owned" by other driver yet. This function
  46. * gets passed a "struct pci_dev *" for each device whose entry in the ID table
  47. * matches the device. The probe functions returns zero when the driver choose
  48. * to take "ownership" of the device or an error code(-ve no) otherwise.
  49. */
  50. static int __devinit stmmac_pci_probe(struct pci_dev *pdev,
  51. const struct pci_device_id *id)
  52. {
  53. int ret = 0;
  54. void __iomem *addr = NULL;
  55. struct stmmac_priv *priv = NULL;
  56. int i;
  57. /* Enable pci device */
  58. ret = pci_enable_device(pdev);
  59. if (ret) {
  60. pr_err("%s : ERROR: failed to enable %s device\n", __func__,
  61. pci_name(pdev));
  62. return ret;
  63. }
  64. if (pci_request_regions(pdev, STMMAC_RESOURCE_NAME)) {
  65. pr_err("%s: ERROR: failed to get PCI region\n", __func__);
  66. ret = -ENODEV;
  67. goto err_out_req_reg_failed;
  68. }
  69. /* Get the base address of device */
  70. for (i = 0; i <= 5; i++) {
  71. if (pci_resource_len(pdev, i) == 0)
  72. continue;
  73. addr = pci_iomap(pdev, i, 0);
  74. if (addr == NULL) {
  75. pr_err("%s: ERROR: cannot map register memory, aborting",
  76. __func__);
  77. ret = -EIO;
  78. goto err_out_map_failed;
  79. }
  80. break;
  81. }
  82. pci_set_master(pdev);
  83. stmmac_default_data();
  84. priv = stmmac_dvr_probe(&(pdev->dev), &plat_dat, addr);
  85. if (!priv) {
  86. pr_err("%s: main driver probe failed", __func__);
  87. goto err_out;
  88. }
  89. priv->dev->irq = pdev->irq;
  90. priv->wol_irq = pdev->irq;
  91. pci_set_drvdata(pdev, priv->dev);
  92. pr_debug("STMMAC platform driver registration completed");
  93. return 0;
  94. err_out:
  95. pci_clear_master(pdev);
  96. err_out_map_failed:
  97. pci_release_regions(pdev);
  98. err_out_req_reg_failed:
  99. pci_disable_device(pdev);
  100. return ret;
  101. }
  102. /**
  103. * stmmac_dvr_remove
  104. *
  105. * @pdev: platform device pointer
  106. * Description: this function calls the main to free the net resources
  107. * and releases the PCI resources.
  108. */
  109. static void __devexit stmmac_pci_remove(struct pci_dev *pdev)
  110. {
  111. struct net_device *ndev = pci_get_drvdata(pdev);
  112. struct stmmac_priv *priv = netdev_priv(ndev);
  113. stmmac_dvr_remove(ndev);
  114. pci_set_drvdata(pdev, NULL);
  115. pci_iounmap(pdev, priv->ioaddr);
  116. pci_release_regions(pdev);
  117. pci_disable_device(pdev);
  118. }
  119. #ifdef CONFIG_PM
  120. static int stmmac_pci_suspend(struct pci_dev *pdev, pm_message_t state)
  121. {
  122. struct net_device *ndev = pci_get_drvdata(pdev);
  123. int ret;
  124. ret = stmmac_suspend(ndev);
  125. pci_save_state(pdev);
  126. pci_set_power_state(pdev, pci_choose_state(pdev, state));
  127. return ret;
  128. }
  129. static int stmmac_pci_resume(struct pci_dev *pdev)
  130. {
  131. struct net_device *ndev = pci_get_drvdata(pdev);
  132. pci_set_power_state(pdev, PCI_D0);
  133. pci_restore_state(pdev);
  134. return stmmac_resume(ndev);
  135. }
  136. #endif
  137. #define STMMAC_VENDOR_ID 0x700
  138. #define STMMAC_DEVICE_ID 0x1108
  139. static DEFINE_PCI_DEVICE_TABLE(stmmac_id_table) = {
  140. {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
  141. {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
  142. {}
  143. };
  144. MODULE_DEVICE_TABLE(pci, stmmac_id_table);
  145. static struct pci_driver stmmac_driver = {
  146. .name = STMMAC_RESOURCE_NAME,
  147. .id_table = stmmac_id_table,
  148. .probe = stmmac_pci_probe,
  149. .remove = __devexit_p(stmmac_pci_remove),
  150. #ifdef CONFIG_PM
  151. .suspend = stmmac_pci_suspend,
  152. .resume = stmmac_pci_resume,
  153. #endif
  154. };
  155. /**
  156. * stmmac_init_module - Entry point for the driver
  157. * Description: This function is the entry point for the driver.
  158. */
  159. static int __init stmmac_init_module(void)
  160. {
  161. int ret;
  162. ret = pci_register_driver(&stmmac_driver);
  163. if (ret < 0)
  164. pr_err("%s: ERROR: driver registration failed\n", __func__);
  165. return ret;
  166. }
  167. /**
  168. * stmmac_cleanup_module - Cleanup routine for the driver
  169. * Description: This function is the cleanup routine for the driver.
  170. */
  171. static void __exit stmmac_cleanup_module(void)
  172. {
  173. pci_unregister_driver(&stmmac_driver);
  174. }
  175. module_init(stmmac_init_module);
  176. module_exit(stmmac_cleanup_module);
  177. MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
  178. MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
  179. MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
  180. MODULE_LICENSE("GPL");