blob: a316187967eaf053df248dcae4fd2f5a488f23c9 [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
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +020029struct stmmac_pci_info {
30 struct pci_dev *pdev;
31 int (*setup)(struct plat_stmmacenet_data *plat,
32 struct stmmac_pci_info *info);
33};
34
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020035static void stmmac_default_data(struct plat_stmmacenet_data *plat)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000036{
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020037 plat->bus_id = 1;
38 plat->phy_addr = 0;
39 plat->interface = PHY_INTERFACE_MODE_GMII;
40 plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
41 plat->has_gmac = 1;
42 plat->force_sf_dma_mode = 1;
Andy Shevchenko1e19e082014-10-31 18:28:03 +020043
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020044 plat->mdio_bus_data->phy_reset = NULL;
45 plat->mdio_bus_data->phy_mask = 0;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000046
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020047 plat->dma_cfg->pbl = 32;
48 plat->dma_cfg->burst_len = DMA_AXI_BLEN_256;
Andy Shevchenko1e19e082014-10-31 18:28:03 +020049
50 /* Set default value for multicast hash bins */
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020051 plat->multicast_filter_bins = HASH_TABLE_SIZE;
Andy Shevchenko1e19e082014-10-31 18:28:03 +020052
53 /* Set default value for unicast filter entries */
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020054 plat->unicast_filter_entries = 1;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000055}
56
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +020057static int quark_default_data(struct plat_stmmacenet_data *plat,
58 struct stmmac_pci_info *info)
59{
60 struct pci_dev *pdev = info->pdev;
61
62 plat->bus_id = PCI_DEVID(pdev->bus->number, pdev->devfn);
63 plat->phy_addr = 1;
64 plat->interface = PHY_INTERFACE_MODE_RMII;
65 plat->clk_csr = 2;
66 plat->has_gmac = 1;
67 plat->force_sf_dma_mode = 1;
68
69 plat->mdio_bus_data->phy_reset = NULL;
70 plat->mdio_bus_data->phy_mask = 0;
71
72 plat->dma_cfg->pbl = 16;
73 plat->dma_cfg->burst_len = DMA_AXI_BLEN_256;
74 plat->dma_cfg->fixed_burst = 1;
75
76 /* Set default value for multicast hash bins */
77 plat->multicast_filter_bins = HASH_TABLE_SIZE;
78
79 /* Set default value for unicast filter entries */
80 plat->unicast_filter_entries = 1;
81
82 return 0;
83}
84
85static struct stmmac_pci_info quark_pci_info = {
86 .setup = quark_default_data,
87};
88
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000089/**
90 * stmmac_pci_probe
91 *
92 * @pdev: pci device pointer
93 * @id: pointer to table of device id/id's.
94 *
95 * Description: This probing function gets called for all PCI devices which
96 * match the ID table and are not "owned" by other driver yet. This function
97 * gets passed a "struct pci_dev *" for each device whose entry in the ID table
98 * matches the device. The probe functions returns zero when the driver choose
99 * to take "ownership" of the device or an error code(-ve no) otherwise.
100 */
Bill Pemberton979857b2012-12-03 09:23:34 -0500101static int stmmac_pci_probe(struct pci_dev *pdev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +0000102 const struct pci_device_id *id)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000103{
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200104 struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +0200105 struct plat_stmmacenet_data *plat;
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200106 struct stmmac_priv *priv;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000107 int i;
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200108 int ret;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000109
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +0200110 plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
111 if (!plat)
112 return -ENOMEM;
113
114 plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
115 sizeof(*plat->mdio_bus_data),
116 GFP_KERNEL);
117 if (!plat->mdio_bus_data)
118 return -ENOMEM;
119
120 plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
121 GFP_KERNEL);
122 if (!plat->dma_cfg)
123 return -ENOMEM;
124
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000125 /* Enable pci device */
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200126 ret = pcim_enable_device(pdev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000127 if (ret) {
Andy Shevchenko7627fc02014-11-05 12:27:29 +0200128 dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
129 __func__);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000130 return ret;
131 }
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000132
133 /* Get the base address of device */
Andy Shevchenko295f9d02014-11-05 12:27:26 +0200134 for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000135 if (pci_resource_len(pdev, i) == 0)
136 continue;
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200137 ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
138 if (ret)
139 return ret;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000140 break;
141 }
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200142
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000143 pci_set_master(pdev);
144
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200145 if (info) {
146 info->pdev = pdev;
147 if (info->setup) {
148 ret = info->setup(plat, info);
149 if (ret)
150 return ret;
151 }
152 } else
153 stmmac_default_data(plat);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000154
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +0200155 priv = stmmac_dvr_probe(&pdev->dev, plat, pcim_iomap_table(pdev)[i]);
Chen-Yu Tsaic5e4ddb2014-01-17 21:24:41 +0800156 if (IS_ERR(priv)) {
Andy Shevchenko7627fc02014-11-05 12:27:29 +0200157 dev_err(&pdev->dev, "%s: main driver probe failed\n", __func__);
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200158 return PTR_ERR(priv);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000159 }
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000160 priv->dev->irq = pdev->irq;
161 priv->wol_irq = pdev->irq;
162
163 pci_set_drvdata(pdev, priv->dev);
164
Andy Shevchenko7627fc02014-11-05 12:27:29 +0200165 dev_dbg(&pdev->dev, "STMMAC PCI driver registration completed\n");
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000166
167 return 0;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000168}
169
170/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000171 * stmmac_pci_remove
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000172 *
173 * @pdev: platform device pointer
174 * Description: this function calls the main to free the net resources
175 * and releases the PCI resources.
176 */
Bill Pemberton979857b2012-12-03 09:23:34 -0500177static void stmmac_pci_remove(struct pci_dev *pdev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000178{
179 struct net_device *ndev = pci_get_drvdata(pdev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000180
181 stmmac_dvr_remove(ndev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000182}
183
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200184#ifdef CONFIG_PM_SLEEP
185static int stmmac_pci_suspend(struct device *dev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000186{
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200187 struct pci_dev *pdev = to_pci_dev(dev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000188 struct net_device *ndev = pci_get_drvdata(pdev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000189
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200190 return stmmac_suspend(ndev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000191}
192
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200193static int stmmac_pci_resume(struct device *dev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000194{
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200195 struct pci_dev *pdev = to_pci_dev(dev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000196 struct net_device *ndev = pci_get_drvdata(pdev);
197
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000198 return stmmac_resume(ndev);
199}
200#endif
201
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200202static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_pci_suspend, stmmac_pci_resume);
203
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000204#define STMMAC_VENDOR_ID 0x700
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200205#define STMMAC_QUARK_ID 0x0937
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000206#define STMMAC_DEVICE_ID 0x1108
207
Benoit Taine9baa3c32014-08-08 15:56:03 +0200208static const struct pci_device_id stmmac_id_table[] = {
Alessandro Rubini5437f4b2012-01-23 23:08:56 +0000209 {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
210 {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
Kweh, Hock Leong5b99a6b2015-01-27 21:44:47 +0200211 {PCI_VDEVICE(INTEL, STMMAC_QUARK_ID), (kernel_ulong_t)&quark_pci_info},
Alessandro Rubini5437f4b2012-01-23 23:08:56 +0000212 {}
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000213};
214
215MODULE_DEVICE_TABLE(pci, stmmac_id_table);
216
Andy Shevchenkob2e2f0c2014-11-10 12:38:59 +0200217static struct pci_driver stmmac_pci_driver = {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000218 .name = STMMAC_RESOURCE_NAME,
219 .id_table = stmmac_id_table,
220 .probe = stmmac_pci_probe,
Bill Pemberton979857b2012-12-03 09:23:34 -0500221 .remove = stmmac_pci_remove,
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200222 .driver = {
223 .pm = &stmmac_pm_ops,
224 },
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000225};
226
Andy Shevchenkob2e2f0c2014-11-10 12:38:59 +0200227module_pci_driver(stmmac_pci_driver);
228
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000229MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
230MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
231MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
232MODULE_LICENSE("GPL");