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