blob: e17a970eaf2b87a1ff184270835102a85fa5f1f4 [file] [log] [blame]
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +00001/*******************************************************************************
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
stephen hemminger47d1f712013-12-30 10:38:57 -080029static struct plat_stmmacenet_data plat_dat;
30static struct stmmac_mdio_bus_data mdio_data;
31static struct stmmac_dma_cfg dma_cfg;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000032
33static void stmmac_default_data(void)
34{
35 memset(&plat_dat, 0, sizeof(struct plat_stmmacenet_data));
Andy Shevchenko1e19e082014-10-31 18:28:03 +020036
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000037 plat_dat.bus_id = 1;
38 plat_dat.phy_addr = 0;
39 plat_dat.interface = PHY_INTERFACE_MODE_GMII;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000040 plat_dat.clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
41 plat_dat.has_gmac = 1;
42 plat_dat.force_sf_dma_mode = 1;
43
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000044 mdio_data.phy_reset = NULL;
45 mdio_data.phy_mask = 0;
46 plat_dat.mdio_bus_data = &mdio_data;
Giuseppe CAVALLARO0f1f88a2012-04-18 19:48:21 +000047
48 dma_cfg.pbl = 32;
49 dma_cfg.burst_len = DMA_AXI_BLEN_256;
50 plat_dat.dma_cfg = &dma_cfg;
Andy Shevchenko1e19e082014-10-31 18:28:03 +020051
52 /* Set default value for multicast hash bins */
53 plat_dat.multicast_filter_bins = HASH_TABLE_SIZE;
54
55 /* Set default value for unicast filter entries */
56 plat_dat.unicast_filter_entries = 1;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000057}
58
59/**
60 * stmmac_pci_probe
61 *
62 * @pdev: pci device pointer
63 * @id: pointer to table of device id/id's.
64 *
65 * Description: This probing function gets called for all PCI devices which
66 * match the ID table and are not "owned" by other driver yet. This function
67 * gets passed a "struct pci_dev *" for each device whose entry in the ID table
68 * matches the device. The probe functions returns zero when the driver choose
69 * to take "ownership" of the device or an error code(-ve no) otherwise.
70 */
Bill Pemberton979857b2012-12-03 09:23:34 -050071static int stmmac_pci_probe(struct pci_dev *pdev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000072 const struct pci_device_id *id)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000073{
74 int ret = 0;
75 void __iomem *addr = NULL;
76 struct stmmac_priv *priv = NULL;
77 int i;
78
79 /* Enable pci device */
80 ret = pci_enable_device(pdev);
81 if (ret) {
82 pr_err("%s : ERROR: failed to enable %s device\n", __func__,
83 pci_name(pdev));
84 return ret;
85 }
86 if (pci_request_regions(pdev, STMMAC_RESOURCE_NAME)) {
87 pr_err("%s: ERROR: failed to get PCI region\n", __func__);
88 ret = -ENODEV;
89 goto err_out_req_reg_failed;
90 }
91
92 /* Get the base address of device */
93 for (i = 0; i <= 5; i++) {
94 if (pci_resource_len(pdev, i) == 0)
95 continue;
96 addr = pci_iomap(pdev, i, 0);
97 if (addr == NULL) {
Giuseppe CAVALLAROceb694992013-04-08 02:10:01 +000098 pr_err("%s: ERROR: cannot map register memory aborting",
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000099 __func__);
100 ret = -EIO;
101 goto err_out_map_failed;
102 }
103 break;
104 }
105 pci_set_master(pdev);
106
107 stmmac_default_data();
108
Giuseppe CAVALLAROcf3f0472012-02-15 00:10:39 +0000109 priv = stmmac_dvr_probe(&(pdev->dev), &plat_dat, addr);
Chen-Yu Tsaic5e4ddb2014-01-17 21:24:41 +0800110 if (IS_ERR(priv)) {
Masanari Iida0f09a342012-02-12 03:45:41 +0000111 pr_err("%s: main driver probe failed", __func__);
Chen-Yu Tsaic5e4ddb2014-01-17 21:24:41 +0800112 ret = PTR_ERR(priv);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000113 goto err_out;
114 }
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000115 priv->dev->irq = pdev->irq;
116 priv->wol_irq = pdev->irq;
117
118 pci_set_drvdata(pdev, priv->dev);
119
120 pr_debug("STMMAC platform driver registration completed");
121
122 return 0;
123
124err_out:
125 pci_clear_master(pdev);
126err_out_map_failed:
127 pci_release_regions(pdev);
128err_out_req_reg_failed:
129 pci_disable_device(pdev);
130
131 return ret;
132}
133
134/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000135 * stmmac_pci_remove
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000136 *
137 * @pdev: platform device pointer
138 * Description: this function calls the main to free the net resources
139 * and releases the PCI resources.
140 */
Bill Pemberton979857b2012-12-03 09:23:34 -0500141static void stmmac_pci_remove(struct pci_dev *pdev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000142{
143 struct net_device *ndev = pci_get_drvdata(pdev);
144 struct stmmac_priv *priv = netdev_priv(ndev);
145
146 stmmac_dvr_remove(ndev);
147
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000148 pci_iounmap(pdev, priv->ioaddr);
149 pci_release_regions(pdev);
150 pci_disable_device(pdev);
151}
152
153#ifdef CONFIG_PM
154static int stmmac_pci_suspend(struct pci_dev *pdev, pm_message_t state)
155{
156 struct net_device *ndev = pci_get_drvdata(pdev);
157 int ret;
158
159 ret = stmmac_suspend(ndev);
160 pci_save_state(pdev);
161 pci_set_power_state(pdev, pci_choose_state(pdev, state));
162
163 return ret;
164}
165
166static int stmmac_pci_resume(struct pci_dev *pdev)
167{
168 struct net_device *ndev = pci_get_drvdata(pdev);
169
170 pci_set_power_state(pdev, PCI_D0);
171 pci_restore_state(pdev);
172
173 return stmmac_resume(ndev);
174}
175#endif
176
177#define STMMAC_VENDOR_ID 0x700
178#define STMMAC_DEVICE_ID 0x1108
179
Benoit Taine9baa3c32014-08-08 15:56:03 +0200180static const struct pci_device_id stmmac_id_table[] = {
Alessandro Rubini5437f4b2012-01-23 23:08:56 +0000181 {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
182 {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
183 {}
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000184};
185
186MODULE_DEVICE_TABLE(pci, stmmac_id_table);
187
Giuseppe CAVALLAROba27ec62012-06-04 19:22:57 +0000188struct pci_driver stmmac_pci_driver = {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000189 .name = STMMAC_RESOURCE_NAME,
190 .id_table = stmmac_id_table,
191 .probe = stmmac_pci_probe,
Bill Pemberton979857b2012-12-03 09:23:34 -0500192 .remove = stmmac_pci_remove,
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000193#ifdef CONFIG_PM
194 .suspend = stmmac_pci_suspend,
195 .resume = stmmac_pci_resume,
196#endif
197};
198
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000199MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
200MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
201MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
202MODULE_LICENSE("GPL");