Commit | Line | Data |
---|---|---|
bfab27a1 GC |
1 | /******************************************************************************* |
2 | This contains the functions to handle the pci driver. | |
3 | ||
4 | Copyright (C) 2011-2012 Vayavya Labs Pvt Ltd | |
5 | ||
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. | |
9 | ||
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. | |
14 | ||
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. | |
18 | ||
19 | The full GNU General Public License is included in this distribution in | |
20 | the file called "COPYING". | |
21 | ||
22 | Author: Rayagond Kokatanur <rayagond@vayavyalabs.com> | |
23 | Author: Giuseppe Cavallaro <peppe.cavallaro@st.com> | |
24 | *******************************************************************************/ | |
25 | ||
26 | #include <linux/pci.h> | |
27 | #include "stmmac.h" | |
28 | ||
29 | struct plat_stmmacenet_data plat_dat; | |
30 | struct stmmac_mdio_bus_data mdio_data; | |
0f1f88a8 | 31 | struct stmmac_dma_cfg dma_cfg; |
bfab27a1 GC |
32 | |
33 | static void stmmac_default_data(void) | |
34 | { | |
35 | memset(&plat_dat, 0, sizeof(struct plat_stmmacenet_data)); | |
36 | plat_dat.bus_id = 1; | |
37 | plat_dat.phy_addr = 0; | |
38 | plat_dat.interface = PHY_INTERFACE_MODE_GMII; | |
bfab27a1 GC |
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; | |
42 | ||
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; | |
0f1f88a8 GC |
47 | |
48 | dma_cfg.pbl = 32; | |
49 | dma_cfg.burst_len = DMA_AXI_BLEN_256; | |
50 | plat_dat.dma_cfg = &dma_cfg; | |
bfab27a1 GC |
51 | } |
52 | ||
53 | /** | |
54 | * stmmac_pci_probe | |
55 | * | |
56 | * @pdev: pci device pointer | |
57 | * @id: pointer to table of device id/id's. | |
58 | * | |
59 | * Description: This probing function gets called for all PCI devices which | |
60 | * match the ID table and are not "owned" by other driver yet. This function | |
61 | * gets passed a "struct pci_dev *" for each device whose entry in the ID table | |
62 | * matches the device. The probe functions returns zero when the driver choose | |
63 | * to take "ownership" of the device or an error code(-ve no) otherwise. | |
64 | */ | |
65 | static int __devinit stmmac_pci_probe(struct pci_dev *pdev, | |
66 | const struct pci_device_id *id) | |
67 | { | |
68 | int ret = 0; | |
69 | void __iomem *addr = NULL; | |
70 | struct stmmac_priv *priv = NULL; | |
71 | int i; | |
72 | ||
73 | /* Enable pci device */ | |
74 | ret = pci_enable_device(pdev); | |
75 | if (ret) { | |
76 | pr_err("%s : ERROR: failed to enable %s device\n", __func__, | |
77 | pci_name(pdev)); | |
78 | return ret; | |
79 | } | |
80 | if (pci_request_regions(pdev, STMMAC_RESOURCE_NAME)) { | |
81 | pr_err("%s: ERROR: failed to get PCI region\n", __func__); | |
82 | ret = -ENODEV; | |
83 | goto err_out_req_reg_failed; | |
84 | } | |
85 | ||
86 | /* Get the base address of device */ | |
87 | for (i = 0; i <= 5; i++) { | |
88 | if (pci_resource_len(pdev, i) == 0) | |
89 | continue; | |
90 | addr = pci_iomap(pdev, i, 0); | |
91 | if (addr == NULL) { | |
8c1a7f52 | 92 | pr_err("%s: ERROR: cannot map register memory, aborting", |
bfab27a1 GC |
93 | __func__); |
94 | ret = -EIO; | |
95 | goto err_out_map_failed; | |
96 | } | |
97 | break; | |
98 | } | |
99 | pci_set_master(pdev); | |
100 | ||
101 | stmmac_default_data(); | |
102 | ||
cf3f047b | 103 | priv = stmmac_dvr_probe(&(pdev->dev), &plat_dat, addr); |
bfab27a1 | 104 | if (!priv) { |
0f09a343 | 105 | pr_err("%s: main driver probe failed", __func__); |
bfab27a1 GC |
106 | goto err_out; |
107 | } | |
bfab27a1 GC |
108 | priv->dev->irq = pdev->irq; |
109 | priv->wol_irq = pdev->irq; | |
110 | ||
111 | pci_set_drvdata(pdev, priv->dev); | |
112 | ||
113 | pr_debug("STMMAC platform driver registration completed"); | |
114 | ||
115 | return 0; | |
116 | ||
117 | err_out: | |
118 | pci_clear_master(pdev); | |
119 | err_out_map_failed: | |
120 | pci_release_regions(pdev); | |
121 | err_out_req_reg_failed: | |
122 | pci_disable_device(pdev); | |
123 | ||
124 | return ret; | |
125 | } | |
126 | ||
127 | /** | |
128 | * stmmac_dvr_remove | |
129 | * | |
130 | * @pdev: platform device pointer | |
131 | * Description: this function calls the main to free the net resources | |
132 | * and releases the PCI resources. | |
133 | */ | |
134 | static void __devexit stmmac_pci_remove(struct pci_dev *pdev) | |
135 | { | |
136 | struct net_device *ndev = pci_get_drvdata(pdev); | |
137 | struct stmmac_priv *priv = netdev_priv(ndev); | |
138 | ||
139 | stmmac_dvr_remove(ndev); | |
140 | ||
141 | pci_set_drvdata(pdev, NULL); | |
142 | pci_iounmap(pdev, priv->ioaddr); | |
143 | pci_release_regions(pdev); | |
144 | pci_disable_device(pdev); | |
145 | } | |
146 | ||
147 | #ifdef CONFIG_PM | |
148 | static int stmmac_pci_suspend(struct pci_dev *pdev, pm_message_t state) | |
149 | { | |
150 | struct net_device *ndev = pci_get_drvdata(pdev); | |
151 | int ret; | |
152 | ||
153 | ret = stmmac_suspend(ndev); | |
154 | pci_save_state(pdev); | |
155 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); | |
156 | ||
157 | return ret; | |
158 | } | |
159 | ||
160 | static int stmmac_pci_resume(struct pci_dev *pdev) | |
161 | { | |
162 | struct net_device *ndev = pci_get_drvdata(pdev); | |
163 | ||
164 | pci_set_power_state(pdev, PCI_D0); | |
165 | pci_restore_state(pdev); | |
166 | ||
167 | return stmmac_resume(ndev); | |
168 | } | |
169 | #endif | |
170 | ||
171 | #define STMMAC_VENDOR_ID 0x700 | |
172 | #define STMMAC_DEVICE_ID 0x1108 | |
173 | ||
174 | static DEFINE_PCI_DEVICE_TABLE(stmmac_id_table) = { | |
5437f4b2 AR |
175 | {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)}, |
176 | {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)}, | |
177 | {} | |
bfab27a1 GC |
178 | }; |
179 | ||
180 | MODULE_DEVICE_TABLE(pci, stmmac_id_table); | |
181 | ||
ba27ec66 | 182 | struct pci_driver stmmac_pci_driver = { |
bfab27a1 GC |
183 | .name = STMMAC_RESOURCE_NAME, |
184 | .id_table = stmmac_id_table, | |
185 | .probe = stmmac_pci_probe, | |
186 | .remove = __devexit_p(stmmac_pci_remove), | |
187 | #ifdef CONFIG_PM | |
188 | .suspend = stmmac_pci_suspend, | |
189 | .resume = stmmac_pci_resume, | |
190 | #endif | |
191 | }; | |
192 | ||
bfab27a1 GC |
193 | MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver"); |
194 | MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>"); | |
195 | MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>"); | |
196 | MODULE_LICENSE("GPL"); |