blob: 054520d67de4a93c4ca14098b8c27b5f6d44cde8 [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
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020029static void stmmac_default_data(struct plat_stmmacenet_data *plat)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000030{
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020031 plat->bus_id = 1;
32 plat->phy_addr = 0;
33 plat->interface = PHY_INTERFACE_MODE_GMII;
34 plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
35 plat->has_gmac = 1;
36 plat->force_sf_dma_mode = 1;
Andy Shevchenko1e19e082014-10-31 18:28:03 +020037
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020038 plat->mdio_bus_data->phy_reset = NULL;
39 plat->mdio_bus_data->phy_mask = 0;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000040
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020041 plat->dma_cfg->pbl = 32;
42 plat->dma_cfg->burst_len = DMA_AXI_BLEN_256;
Andy Shevchenko1e19e082014-10-31 18:28:03 +020043
44 /* Set default value for multicast hash bins */
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020045 plat->multicast_filter_bins = HASH_TABLE_SIZE;
Andy Shevchenko1e19e082014-10-31 18:28:03 +020046
47 /* Set default value for unicast filter entries */
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020048 plat->unicast_filter_entries = 1;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000049}
50
51/**
52 * stmmac_pci_probe
53 *
54 * @pdev: pci device pointer
55 * @id: pointer to table of device id/id's.
56 *
57 * Description: This probing function gets called for all PCI devices which
58 * match the ID table and are not "owned" by other driver yet. This function
59 * gets passed a "struct pci_dev *" for each device whose entry in the ID table
60 * matches the device. The probe functions returns zero when the driver choose
61 * to take "ownership" of the device or an error code(-ve no) otherwise.
62 */
Bill Pemberton979857b2012-12-03 09:23:34 -050063static int stmmac_pci_probe(struct pci_dev *pdev,
Greg Kroah-Hartman1dd06ae2012-12-06 14:30:56 +000064 const struct pci_device_id *id)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000065{
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020066 struct plat_stmmacenet_data *plat;
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +020067 struct stmmac_priv *priv;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000068 int i;
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +020069 int ret;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000070
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +020071 plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
72 if (!plat)
73 return -ENOMEM;
74
75 plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
76 sizeof(*plat->mdio_bus_data),
77 GFP_KERNEL);
78 if (!plat->mdio_bus_data)
79 return -ENOMEM;
80
81 plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
82 GFP_KERNEL);
83 if (!plat->dma_cfg)
84 return -ENOMEM;
85
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000086 /* Enable pci device */
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +020087 ret = pcim_enable_device(pdev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000088 if (ret) {
Andy Shevchenko7627fc02014-11-05 12:27:29 +020089 dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
90 __func__);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000091 return ret;
92 }
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000093
94 /* Get the base address of device */
Andy Shevchenko295f9d02014-11-05 12:27:26 +020095 for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +000096 if (pci_resource_len(pdev, i) == 0)
97 continue;
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +020098 ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
99 if (ret)
100 return ret;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000101 break;
102 }
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200103
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000104 pci_set_master(pdev);
105
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +0200106 stmmac_default_data(plat);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000107
Andy Shevchenkoc4b2b9a2014-11-28 15:40:56 +0200108 priv = stmmac_dvr_probe(&pdev->dev, plat, pcim_iomap_table(pdev)[i]);
Chen-Yu Tsaic5e4ddb2014-01-17 21:24:41 +0800109 if (IS_ERR(priv)) {
Andy Shevchenko7627fc02014-11-05 12:27:29 +0200110 dev_err(&pdev->dev, "%s: main driver probe failed\n", __func__);
Andy Shevchenko2a3e8e92014-11-05 12:27:28 +0200111 return PTR_ERR(priv);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000112 }
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000113 priv->dev->irq = pdev->irq;
114 priv->wol_irq = pdev->irq;
115
116 pci_set_drvdata(pdev, priv->dev);
117
Andy Shevchenko7627fc02014-11-05 12:27:29 +0200118 dev_dbg(&pdev->dev, "STMMAC PCI driver registration completed\n");
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000119
120 return 0;
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000121}
122
123/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +0000124 * stmmac_pci_remove
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000125 *
126 * @pdev: platform device pointer
127 * Description: this function calls the main to free the net resources
128 * and releases the PCI resources.
129 */
Bill Pemberton979857b2012-12-03 09:23:34 -0500130static void stmmac_pci_remove(struct pci_dev *pdev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000131{
132 struct net_device *ndev = pci_get_drvdata(pdev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000133
134 stmmac_dvr_remove(ndev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000135}
136
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200137#ifdef CONFIG_PM_SLEEP
138static int stmmac_pci_suspend(struct device *dev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000139{
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200140 struct pci_dev *pdev = to_pci_dev(dev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000141 struct net_device *ndev = pci_get_drvdata(pdev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000142
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200143 return stmmac_suspend(ndev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000144}
145
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200146static int stmmac_pci_resume(struct device *dev)
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000147{
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200148 struct pci_dev *pdev = to_pci_dev(dev);
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000149 struct net_device *ndev = pci_get_drvdata(pdev);
150
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000151 return stmmac_resume(ndev);
152}
153#endif
154
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200155static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_pci_suspend, stmmac_pci_resume);
156
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000157#define STMMAC_VENDOR_ID 0x700
158#define STMMAC_DEVICE_ID 0x1108
159
Benoit Taine9baa3c32014-08-08 15:56:03 +0200160static const struct pci_device_id stmmac_id_table[] = {
Alessandro Rubini5437f4b2012-01-23 23:08:56 +0000161 {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
162 {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
163 {}
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000164};
165
166MODULE_DEVICE_TABLE(pci, stmmac_id_table);
167
Andy Shevchenkob2e2f0c2014-11-10 12:38:59 +0200168static struct pci_driver stmmac_pci_driver = {
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000169 .name = STMMAC_RESOURCE_NAME,
170 .id_table = stmmac_id_table,
171 .probe = stmmac_pci_probe,
Bill Pemberton979857b2012-12-03 09:23:34 -0500172 .remove = stmmac_pci_remove,
Andy Shevchenko3be3d812014-11-05 12:27:27 +0200173 .driver = {
174 .pm = &stmmac_pm_ops,
175 },
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000176};
177
Andy Shevchenkob2e2f0c2014-11-10 12:38:59 +0200178module_pci_driver(stmmac_pci_driver);
179
Giuseppe CAVALLARObfab27a2011-12-21 03:58:19 +0000180MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
181MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
182MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
183MODULE_LICENSE("GPL");