blob: 77a6d68f718999739415d029702db4668c117e5b [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{
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +020074 struct stmmac_priv *priv;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000075 int i;
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +020076 int ret;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000077
78 /* Enable pci device */
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +020079 ret = pcim_enable_device(pdev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000080 if (ret) {
Andy Shevchenko7627fc02014-11-05 12:27:29 +020081 dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
82 __func__);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000083 return ret;
84 }
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000085
86 /* Get the base address of device */
Andy Shevchenko295f9d02014-11-05 12:27:26 +020087 for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000088 if (pci_resource_len(pdev, i) == 0)
89 continue;
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +020090 ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
91 if (ret)
92 return ret;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000093 break;
94 }
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +020095
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000096 pci_set_master(pdev);
97
98 stmmac_default_data();
99
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200100 priv = stmmac_dvr_probe(&pdev->dev, &plat_dat,
101 pcim_iomap_table(pdev)[i]);
Chen-Yu Tsaic5e4ddb2014-01-17 21:24:41 +0800102 if (IS_ERR(priv)) {
Andy Shevchenko7627fc02014-11-05 12:27:29 +0200103 dev_err(&pdev->dev, "%s: main driver probe failed\n", __func__);
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200104 return PTR_ERR(priv);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000105 }
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000106 priv->dev->irq = pdev->irq;
107 priv->wol_irq = pdev->irq;
108
109 pci_set_drvdata(pdev, priv->dev);
110
Andy Shevchenko7627fc02014-11-05 12:27:29 +0200111 dev_dbg(&pdev->dev, "STMMAC PCI driver registration completed\n");
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000112
113 return 0;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000114}
115
116/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000117 * stmmac_pci_remove
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000118 *
119 * @pdev: platform device pointer
120 * Description: this function calls the main to free the net resources
121 * and releases the PCI resources.
122 */
Bill Pemberton979857b2012-12-03 09:23:34 -0500123static void stmmac_pci_remove(struct pci_dev *pdev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000124{
125 struct net_device *ndev = pci_get_drvdata(pdev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000126
127 stmmac_dvr_remove(ndev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000128}
129
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200130#ifdef CONFIG_PM_SLEEP
131static int stmmac_pci_suspend(struct device *dev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000132{
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200133 struct pci_dev *pdev = to_pci_dev(dev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000134 struct net_device *ndev = pci_get_drvdata(pdev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000135
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200136 return stmmac_suspend(ndev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000137}
138
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200139static int stmmac_pci_resume(struct device *dev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000140{
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200141 struct pci_dev *pdev = to_pci_dev(dev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000142 struct net_device *ndev = pci_get_drvdata(pdev);
143
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000144 return stmmac_resume(ndev);
145}
146#endif
147
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200148static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_pci_suspend, stmmac_pci_resume);
149
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000150#define STMMAC_VENDOR_ID 0x700
151#define STMMAC_DEVICE_ID 0x1108
152
Benoit Taine9baa3c32014-08-08 15:56:03 +0200153static const struct pci_device_id stmmac_id_table[] = {
Alessandro Rubini5437f4b2012-01-23 23:08:56 +0000154 {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
155 {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
156 {}
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000157};
158
159MODULE_DEVICE_TABLE(pci, stmmac_id_table);
160
Andy Shevchenkob2e2f0c2014-11-10 12:38:59 +0200161static struct pci_driver stmmac_pci_driver = {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000162 .name = STMMAC_RESOURCE_NAME,
163 .id_table = stmmac_id_table,
164 .probe = stmmac_pci_probe,
Bill Pemberton979857b2012-12-03 09:23:34 -0500165 .remove = stmmac_pci_remove,
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200166 .driver = {
167 .pm = &stmmac_pm_ops,
168 },
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000169};
170
Andy Shevchenkob2e2f0c2014-11-10 12:38:59 +0200171module_pci_driver(stmmac_pci_driver);
172
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000173MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
174MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
175MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
176MODULE_LICENSE("GPL");