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 | |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame^] | 29 | static void stmmac_default_data(struct plat_stmmacenet_data *plat) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 30 | { |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame^] | 31 | 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 Shevchenko | 1e19e08 | 2014-10-31 18:28:03 +0200 | [diff] [blame] | 37 | |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame^] | 38 | plat->mdio_bus_data->phy_reset = NULL; |
| 39 | plat->mdio_bus_data->phy_mask = 0; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 40 | |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame^] | 41 | plat->dma_cfg->pbl = 32; |
| 42 | plat->dma_cfg->burst_len = DMA_AXI_BLEN_256; |
Andy Shevchenko | 1e19e08 | 2014-10-31 18:28:03 +0200 | [diff] [blame] | 43 | |
| 44 | /* Set default value for multicast hash bins */ |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame^] | 45 | plat->multicast_filter_bins = HASH_TABLE_SIZE; |
Andy Shevchenko | 1e19e08 | 2014-10-31 18:28:03 +0200 | [diff] [blame] | 46 | |
| 47 | /* Set default value for unicast filter entries */ |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame^] | 48 | plat->unicast_filter_entries = 1; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 49 | } |
| 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 Pemberton | 979857b | 2012-12-03 09:23:34 -0500 | [diff] [blame] | 63 | static int stmmac_pci_probe(struct pci_dev *pdev, |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame] | 64 | const struct pci_device_id *id) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 65 | { |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame^] | 66 | struct plat_stmmacenet_data *plat; |
Andy Shevchenko | 2a3e8e9 | 2014-11-05 12:27:28 +0200 | [diff] [blame] | 67 | struct stmmac_priv *priv; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 68 | int i; |
Andy Shevchenko | 2a3e8e9 | 2014-11-05 12:27:28 +0200 | [diff] [blame] | 69 | int ret; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 70 | |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame^] | 71 | 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 CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 86 | /* Enable pci device */ |
Andy Shevchenko | 2a3e8e9 | 2014-11-05 12:27:28 +0200 | [diff] [blame] | 87 | ret = pcim_enable_device(pdev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 88 | if (ret) { |
Andy Shevchenko | 7627fc0 | 2014-11-05 12:27:29 +0200 | [diff] [blame] | 89 | dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n", |
| 90 | __func__); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 91 | return ret; |
| 92 | } |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 93 | |
| 94 | /* Get the base address of device */ |
Andy Shevchenko | 295f9d0 | 2014-11-05 12:27:26 +0200 | [diff] [blame] | 95 | for (i = 0; i <= PCI_STD_RESOURCE_END; i++) { |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 96 | if (pci_resource_len(pdev, i) == 0) |
| 97 | continue; |
Andy Shevchenko | 2a3e8e9 | 2014-11-05 12:27:28 +0200 | [diff] [blame] | 98 | ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev)); |
| 99 | if (ret) |
| 100 | return ret; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 101 | break; |
| 102 | } |
Andy Shevchenko | 2a3e8e9 | 2014-11-05 12:27:28 +0200 | [diff] [blame] | 103 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 104 | pci_set_master(pdev); |
| 105 | |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame^] | 106 | stmmac_default_data(plat); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 107 | |
Andy Shevchenko | c4b2b9a | 2014-11-28 15:40:56 +0200 | [diff] [blame^] | 108 | 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] | 109 | if (IS_ERR(priv)) { |
Andy Shevchenko | 7627fc0 | 2014-11-05 12:27:29 +0200 | [diff] [blame] | 110 | dev_err(&pdev->dev, "%s: main driver probe failed\n", __func__); |
Andy Shevchenko | 2a3e8e9 | 2014-11-05 12:27:28 +0200 | [diff] [blame] | 111 | return PTR_ERR(priv); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 112 | } |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 113 | priv->dev->irq = pdev->irq; |
| 114 | priv->wol_irq = pdev->irq; |
| 115 | |
| 116 | pci_set_drvdata(pdev, priv->dev); |
| 117 | |
Andy Shevchenko | 7627fc0 | 2014-11-05 12:27:29 +0200 | [diff] [blame] | 118 | dev_dbg(&pdev->dev, "STMMAC PCI driver registration completed\n"); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 119 | |
| 120 | return 0; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 121 | } |
| 122 | |
| 123 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 124 | * stmmac_pci_remove |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 125 | * |
| 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 Pemberton | 979857b | 2012-12-03 09:23:34 -0500 | [diff] [blame] | 130 | static void stmmac_pci_remove(struct pci_dev *pdev) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 131 | { |
| 132 | struct net_device *ndev = pci_get_drvdata(pdev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 133 | |
| 134 | stmmac_dvr_remove(ndev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 135 | } |
| 136 | |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 137 | #ifdef CONFIG_PM_SLEEP |
| 138 | static int stmmac_pci_suspend(struct device *dev) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 139 | { |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 140 | struct pci_dev *pdev = to_pci_dev(dev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 141 | struct net_device *ndev = pci_get_drvdata(pdev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 142 | |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 143 | return stmmac_suspend(ndev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 144 | } |
| 145 | |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 146 | static int stmmac_pci_resume(struct device *dev) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 147 | { |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 148 | struct pci_dev *pdev = to_pci_dev(dev); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 149 | struct net_device *ndev = pci_get_drvdata(pdev); |
| 150 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 151 | return stmmac_resume(ndev); |
| 152 | } |
| 153 | #endif |
| 154 | |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 155 | static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_pci_suspend, stmmac_pci_resume); |
| 156 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 157 | #define STMMAC_VENDOR_ID 0x700 |
| 158 | #define STMMAC_DEVICE_ID 0x1108 |
| 159 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 160 | static const struct pci_device_id stmmac_id_table[] = { |
Alessandro Rubini | 5437f4b | 2012-01-23 23:08:56 +0000 | [diff] [blame] | 161 | {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)}, |
| 162 | {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)}, |
| 163 | {} |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 164 | }; |
| 165 | |
| 166 | MODULE_DEVICE_TABLE(pci, stmmac_id_table); |
| 167 | |
Andy Shevchenko | b2e2f0c | 2014-11-10 12:38:59 +0200 | [diff] [blame] | 168 | static struct pci_driver stmmac_pci_driver = { |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 169 | .name = STMMAC_RESOURCE_NAME, |
| 170 | .id_table = stmmac_id_table, |
| 171 | .probe = stmmac_pci_probe, |
Bill Pemberton | 979857b | 2012-12-03 09:23:34 -0500 | [diff] [blame] | 172 | .remove = stmmac_pci_remove, |
Andy Shevchenko | 3be3d81 | 2014-11-05 12:27:27 +0200 | [diff] [blame] | 173 | .driver = { |
| 174 | .pm = &stmmac_pm_ops, |
| 175 | }, |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 176 | }; |
| 177 | |
Andy Shevchenko | b2e2f0c | 2014-11-10 12:38:59 +0200 | [diff] [blame] | 178 | module_pci_driver(stmmac_pci_driver); |
| 179 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 180 | MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver"); |
| 181 | MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>"); |
| 182 | MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>"); |
| 183 | MODULE_LICENSE("GPL"); |