Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 1 | /******************************************************************************* |
| 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 Leong | 5b99a6b | 2015-01-27 21:44:47 +0200 | [diff] [blame^] | 29 | struct 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 Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame] | 35 | static void stmmac_default_data(struct plat_stmmacenet_data *plat) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 36 | { |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame] | 37 | 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 Shevchenko | 1e19e08 | 2014-10-31 18:28:03 +0200 | [diff] [blame] | 43 | |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame] | 44 | plat->mdio_bus_data->phy_reset = NULL; |
| 45 | plat->mdio_bus_data->phy_mask = 0; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 46 | |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame] | 47 | plat->dma_cfg->pbl = 32; |
| 48 | plat->dma_cfg->burst_len = DMA_AXI_BLEN_256; |
Andy Shevchenko | 1e19e08 | 2014-10-31 18:28:03 +0200 | [diff] [blame] | 49 | |
| 50 | /* Set default value for multicast hash bins */ |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame] | 51 | plat->multicast_filter_bins = HASH_TABLE_SIZE; |
Andy Shevchenko | 1e19e08 | 2014-10-31 18:28:03 +0200 | [diff] [blame] | 52 | |
| 53 | /* Set default value for unicast filter entries */ |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame] | 54 | plat->unicast_filter_entries = 1; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 55 | } |
| 56 | |
Kweh, Hock Leong | 5b99a6b | 2015-01-27 21:44:47 +0200 | [diff] [blame^] | 57 | static 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 | |
| 85 | static struct stmmac_pci_info quark_pci_info = { |
| 86 | .setup = quark_default_data, |
| 87 | }; |
| 88 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 89 | /** |
| 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 Pemberton | 979857b | 2012-12-03 09:23:34 -0500 | [diff] [blame] | 101 | static int stmmac_pci_probe(struct pci_dev *pdev, |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 102 | const struct pci_device_id *id) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 103 | { |
Kweh, Hock Leong | 5b99a6b | 2015-01-27 21:44:47 +0200 | [diff] [blame^] | 104 | struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data; |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame] | 105 | struct plat_stmmacenet_data *plat; |
Andy Shevchenko | 2a3e8e9 | 2014-11-05 12:27:28 +0200 | [diff] [blame] | 106 | struct stmmac_priv *priv; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 107 | int i; |
Andy Shevchenko | 2a3e8e9 | 2014-11-05 12:27:28 +0200 | [diff] [blame] | 108 | int ret; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 109 | |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame] | 110 | 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 CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 125 | /* Enable pci device */ |
Andy Shevchenko | 2a3e8e9 | 2014-11-05 12:27:28 +0200 | [diff] [blame] | 126 | ret = pcim_enable_device(pdev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 127 | if (ret) { |
Andy Shevchenko | 7627fc0 | 2014-11-05 12:27:29 +0200 | [diff] [blame] | 128 | dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n", |
| 129 | __func__); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 130 | return ret; |
| 131 | } |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 132 | |
| 133 | /* Get the base address of device */ |
Andy Shevchenko | 295f9d0 | 2014-11-05 12:27:26 +0200 | [diff] [blame] | 134 | for (i = 0; i <= PCI_STD_RESOURCE_END; i++) { |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 135 | if (pci_resource_len(pdev, i) == 0) |
| 136 | continue; |
Andy Shevchenko | 2a3e8e9 | 2014-11-05 12:27:28 +0200 | [diff] [blame] | 137 | ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev)); |
| 138 | if (ret) |
| 139 | return ret; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 140 | break; |
| 141 | } |
Andy Shevchenko | 2a3e8e9 | 2014-11-05 12:27:28 +0200 | [diff] [blame] | 142 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 143 | pci_set_master(pdev); |
| 144 | |
Kweh, Hock Leong | 5b99a6b | 2015-01-27 21:44:47 +0200 | [diff] [blame^] | 145 | 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 CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 154 | |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame] | 155 | priv = stmmac_dvr_probe(&pdev->dev, plat, pcim_iomap_table(pdev)[i]); |
Chen-Yu Tsai | c5e4ddb | 2014-01-17 21:24:41 +0800 | [diff] [blame] | 156 | if (IS_ERR(priv)) { |
Andy Shevchenko | 7627fc0 | 2014-11-05 12:27:29 +0200 | [diff] [blame] | 157 | dev_err(&pdev->dev, "%s: main driver probe failed\n", __func__); |
Andy Shevchenko | 2a3e8e9 | 2014-11-05 12:27:28 +0200 | [diff] [blame] | 158 | return PTR_ERR(priv); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 159 | } |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 160 | priv->dev->irq = pdev->irq; |
| 161 | priv->wol_irq = pdev->irq; |
| 162 | |
| 163 | pci_set_drvdata(pdev, priv->dev); |
| 164 | |
Andy Shevchenko | 7627fc0 | 2014-11-05 12:27:29 +0200 | [diff] [blame] | 165 | dev_dbg(&pdev->dev, "STMMAC PCI driver registration completed\n"); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 166 | |
| 167 | return 0; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 171 | * stmmac_pci_remove |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 172 | * |
| 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 Pemberton | 979857b | 2012-12-03 09:23:34 -0500 | [diff] [blame] | 177 | static void stmmac_pci_remove(struct pci_dev *pdev) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 178 | { |
| 179 | struct net_device *ndev = pci_get_drvdata(pdev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 180 | |
| 181 | stmmac_dvr_remove(ndev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 182 | } |
| 183 | |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 184 | #ifdef CONFIG_PM_SLEEP |
| 185 | static int stmmac_pci_suspend(struct device *dev) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 186 | { |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 187 | struct pci_dev *pdev = to_pci_dev(dev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 188 | struct net_device *ndev = pci_get_drvdata(pdev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 189 | |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 190 | return stmmac_suspend(ndev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 191 | } |
| 192 | |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 193 | static int stmmac_pci_resume(struct device *dev) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 194 | { |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 195 | struct pci_dev *pdev = to_pci_dev(dev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 196 | struct net_device *ndev = pci_get_drvdata(pdev); |
| 197 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 198 | return stmmac_resume(ndev); |
| 199 | } |
| 200 | #endif |
| 201 | |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 202 | static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_pci_suspend, stmmac_pci_resume); |
| 203 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 204 | #define STMMAC_VENDOR_ID 0x700 |
Kweh, Hock Leong | 5b99a6b | 2015-01-27 21:44:47 +0200 | [diff] [blame^] | 205 | #define STMMAC_QUARK_ID 0x0937 |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 206 | #define STMMAC_DEVICE_ID 0x1108 |
| 207 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 208 | static const struct pci_device_id stmmac_id_table[] = { |
Alessandro Rubini | 5437f4b | 2012-01-23 23:08:56 +0000 | [diff] [blame] | 209 | {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)}, |
| 210 | {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)}, |
Kweh, Hock Leong | 5b99a6b | 2015-01-27 21:44:47 +0200 | [diff] [blame^] | 211 | {PCI_VDEVICE(INTEL, STMMAC_QUARK_ID), (kernel_ulong_t)&quark_pci_info}, |
Alessandro Rubini | 5437f4b | 2012-01-23 23:08:56 +0000 | [diff] [blame] | 212 | {} |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 213 | }; |
| 214 | |
| 215 | MODULE_DEVICE_TABLE(pci, stmmac_id_table); |
| 216 | |
Andy Shevchenko | b2e2f0c | 2014-11-10 12:38:59 +0200 | [diff] [blame] | 217 | static struct pci_driver stmmac_pci_driver = { |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 218 | .name = STMMAC_RESOURCE_NAME, |
| 219 | .id_table = stmmac_id_table, |
| 220 | .probe = stmmac_pci_probe, |
Bill Pemberton | 979857b | 2012-12-03 09:23:34 -0500 | [diff] [blame] | 221 | .remove = stmmac_pci_remove, |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 222 | .driver = { |
| 223 | .pm = &stmmac_pm_ops, |
| 224 | }, |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 225 | }; |
| 226 | |
Andy Shevchenko | b2e2f0c | 2014-11-10 12:38:59 +0200 | [diff] [blame] | 227 | module_pci_driver(stmmac_pci_driver); |
| 228 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 229 | MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver"); |
| 230 | MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>"); |
| 231 | MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>"); |
| 232 | MODULE_LICENSE("GPL"); |