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 regiser memory, aborting",
91 goto err_out_map_failed
;
97 stmmac_default_data();
99 priv
= stmmac_dvr_probe(&(pdev
->dev
), &plat_dat
, addr
);
101 pr_err("%s: main driver probe failed", __func__
);
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");
114 pci_clear_master(pdev
);
116 pci_release_regions(pdev
);
117 err_out_req_reg_failed
:
118 pci_disable_device(pdev
);
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
);
144 static int stmmac_pci_suspend(struct pci_dev
*pdev
, pm_message_t state
)
146 struct net_device
*ndev
= pci_get_drvdata(pdev
);
149 ret
= stmmac_suspend(ndev
);
150 pci_save_state(pdev
);
151 pci_set_power_state(pdev
, pci_choose_state(pdev
, state
));
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
);
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
),
184 .suspend
= stmmac_pci_suspend
,
185 .resume
= stmmac_pci_resume
,
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)
197 ret
= pci_register_driver(&stmmac_driver
);
199 pr_err("%s: ERROR: driver registration failed\n", __func__
);
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");