1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26#include <linux/pci.h>
27#include "stmmac.h"
28
29struct plat_stmmacenet_data plat_dat;
30struct stmmac_mdio_bus_data mdio_data;
31struct stmmac_dma_cfg dma_cfg;
32
33static 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;
39 plat_dat.clk_csr = 2;
40 plat_dat.has_gmac = 1;
41 plat_dat.force_sf_dma_mode = 1;
42
43 mdio_data.phy_reset = NULL;
44 mdio_data.phy_mask = 0;
45 plat_dat.mdio_bus_data = &mdio_data;
46
47 dma_cfg.pbl = 32;
48 dma_cfg.burst_len = DMA_AXI_BLEN_256;
49 plat_dat.dma_cfg = &dma_cfg;
50}
51
52
53
54
55
56
57
58
59
60
61
62
63
64static int stmmac_pci_probe(struct pci_dev *pdev,
65 const struct pci_device_id *id)
66{
67 int ret = 0;
68 void __iomem *addr = NULL;
69 struct stmmac_priv *priv = NULL;
70 int i;
71
72
73 ret = pci_enable_device(pdev);
74 if (ret) {
75 pr_err("%s : ERROR: failed to enable %s device\n", __func__,
76 pci_name(pdev));
77 return ret;
78 }
79 if (pci_request_regions(pdev, STMMAC_RESOURCE_NAME)) {
80 pr_err("%s: ERROR: failed to get PCI region\n", __func__);
81 ret = -ENODEV;
82 goto err_out_req_reg_failed;
83 }
84
85
86 for (i = 0; i <= 5; i++) {
87 if (pci_resource_len(pdev, i) == 0)
88 continue;
89 addr = pci_iomap(pdev, i, 0);
90 if (addr == NULL) {
91 pr_err("%s: ERROR: cannot map register memory aborting",
92 __func__);
93 ret = -EIO;
94 goto err_out_map_failed;
95 }
96 break;
97 }
98 pci_set_master(pdev);
99
100 stmmac_default_data();
101
102 priv = stmmac_dvr_probe(&(pdev->dev), &plat_dat, addr);
103 if (!priv) {
104 pr_err("%s: main driver probe failed", __func__);
105 ret = -ENODEV;
106 goto err_out;
107 }
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
117err_out:
118 pci_clear_master(pdev);
119err_out_map_failed:
120 pci_release_regions(pdev);
121err_out_req_reg_failed:
122 pci_disable_device(pdev);
123
124 return ret;
125}
126
127
128
129
130
131
132
133
134static void 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
148static 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
160static 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
174static DEFINE_PCI_DEVICE_TABLE(stmmac_id_table) = {
175 {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
176 {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
177 {}
178};
179
180MODULE_DEVICE_TABLE(pci, stmmac_id_table);
181
182struct pci_driver stmmac_pci_driver = {
183 .name = STMMAC_RESOURCE_NAME,
184 .id_table = stmmac_id_table,
185 .probe = stmmac_pci_probe,
186 .remove = stmmac_pci_remove,
187#ifdef CONFIG_PM
188 .suspend = stmmac_pci_suspend,
189 .resume = stmmac_pci_resume,
190#endif
191};
192
193MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
194MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
195MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
196MODULE_LICENSE("GPL");
197