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
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>
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));
36 plat_dat.phy_addr = 0;
37 plat_dat.interface = PHY_INTERFACE_MODE_GMII;
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;
44 mdio_data.phy_reset = NULL;
45 mdio_data.phy_mask = 0;
46 plat_dat.mdio_bus_data = &mdio_data;
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)
65 void __iomem *addr = NULL;
66 struct stmmac_priv *priv = NULL;
69 /* Enable pci device */
70 ret = pci_enable_device(pdev);
72 pr_err("%s : ERROR: failed to enable %s device\n", __func__,
76 if (pci_request_regions(pdev, STMMAC_RESOURCE_NAME)) {
77 pr_err("%s: ERROR: failed to get PCI region\n", __func__);
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)
86 addr = pci_iomap(pdev, i, 0);
88 pr_err("%s: ERROR: cannot map register memory, aborting",
91 goto err_out_map_failed;
97 stmmac_default_data();
99 priv = stmmac_dvr_probe(&(pdev->dev), &plat_dat);
101 pr_err("%s: main driver probe failed", __func__);
105 priv->dev->base_addr = (unsigned long)addr;
106 priv->dev->irq = pdev->irq;
107 priv->wol_irq = pdev->irq;
109 pci_set_drvdata(pdev, priv->dev);
111 pr_debug("STMMAC platform driver registration completed");
116 pci_clear_master(pdev);
118 pci_release_regions(pdev);
119 err_out_req_reg_failed:
120 pci_disable_device(pdev);
128 * @pdev: platform device pointer
129 * Description: this function calls the main to free the net resources
130 * and releases the PCI resources.
132 static void __devexit stmmac_pci_remove(struct pci_dev *pdev)
134 struct net_device *ndev = pci_get_drvdata(pdev);
135 struct stmmac_priv *priv = netdev_priv(ndev);
137 stmmac_dvr_remove(ndev);
139 pci_set_drvdata(pdev, NULL);
140 pci_iounmap(pdev, priv->ioaddr);
141 pci_release_regions(pdev);
142 pci_disable_device(pdev);
146 static int stmmac_pci_suspend(struct pci_dev *pdev, pm_message_t state)
148 struct net_device *ndev = pci_get_drvdata(pdev);
151 ret = stmmac_suspend(ndev);
152 pci_save_state(pdev);
153 pci_set_power_state(pdev, pci_choose_state(pdev, state));
158 static int stmmac_pci_resume(struct pci_dev *pdev)
160 struct net_device *ndev = pci_get_drvdata(pdev);
162 pci_set_power_state(pdev, PCI_D0);
163 pci_restore_state(pdev);
165 return stmmac_resume(ndev);
169 #define STMMAC_VENDOR_ID 0x700
170 #define STMMAC_DEVICE_ID 0x1108
172 static DEFINE_PCI_DEVICE_TABLE(stmmac_id_table) = {
173 {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
174 {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
178 MODULE_DEVICE_TABLE(pci, stmmac_id_table);
180 static struct pci_driver stmmac_driver = {
181 .name = STMMAC_RESOURCE_NAME,
182 .id_table = stmmac_id_table,
183 .probe = stmmac_pci_probe,
184 .remove = __devexit_p(stmmac_pci_remove),
186 .suspend = stmmac_pci_suspend,
187 .resume = stmmac_pci_resume,
192 * stmmac_init_module - Entry point for the driver
193 * Description: This function is the entry point for the driver.
195 static int __init stmmac_init_module(void)
199 ret = pci_register_driver(&stmmac_driver);
201 pr_err("%s: ERROR: driver registration failed\n", __func__);
207 * stmmac_cleanup_module - Cleanup routine for the driver
208 * Description: This function is the cleanup routine for the driver.
210 static void __exit stmmac_cleanup_module(void)
212 pci_unregister_driver(&stmmac_driver);
215 module_init(stmmac_init_module);
216 module_exit(stmmac_cleanup_module);
218 MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
219 MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
220 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
221 MODULE_LICENSE("GPL");