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 | |
| 29 | struct plat_stmmacenet_data plat_dat; |
| 30 | struct stmmac_mdio_bus_data mdio_data; |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 31 | struct stmmac_dma_cfg dma_cfg; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 32 | |
| 33 | static void stmmac_default_data(void) |
| 34 | { |
| 35 | memset(&plat_dat, 0, sizeof(struct plat_stmmacenet_data)); |
| 36 | plat_dat.bus_id = 1; |
| 37 | plat_dat.phy_addr = 0; |
| 38 | plat_dat.interface = PHY_INTERFACE_MODE_GMII; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 39 | plat_dat.clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */ |
| 40 | plat_dat.has_gmac = 1; |
| 41 | plat_dat.force_sf_dma_mode = 1; |
| 42 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 43 | mdio_data.phy_reset = NULL; |
| 44 | mdio_data.phy_mask = 0; |
| 45 | plat_dat.mdio_bus_data = &mdio_data; |
Giuseppe CAVALLARO | 0f1f88a | 2012-04-18 19:48:21 +0000 | [diff] [blame] | 46 | |
| 47 | dma_cfg.pbl = 32; |
| 48 | dma_cfg.burst_len = DMA_AXI_BLEN_256; |
| 49 | plat_dat.dma_cfg = &dma_cfg; |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 50 | } |
| 51 | |
| 52 | /** |
| 53 | * stmmac_pci_probe |
| 54 | * |
| 55 | * @pdev: pci device pointer |
| 56 | * @id: pointer to table of device id/id's. |
| 57 | * |
| 58 | * Description: This probing function gets called for all PCI devices which |
| 59 | * match the ID table and are not "owned" by other driver yet. This function |
| 60 | * gets passed a "struct pci_dev *" for each device whose entry in the ID table |
| 61 | * matches the device. The probe functions returns zero when the driver choose |
| 62 | * to take "ownership" of the device or an error code(-ve no) otherwise. |
| 63 | */ |
Bill Pemberton | 979857b | 2012-12-03 09:23:34 -0500 | [diff] [blame] | 64 | static int stmmac_pci_probe(struct pci_dev *pdev, |
Greg Kroah-Hartman | 1dd06ae | 2012-12-06 14:30:56 +0000 | [diff] [blame^] | 65 | const struct pci_device_id *id) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 66 | { |
| 67 | int ret = 0; |
| 68 | void __iomem *addr = NULL; |
| 69 | struct stmmac_priv *priv = NULL; |
| 70 | int i; |
| 71 | |
| 72 | /* Enable pci device */ |
| 73 | ret = pci_enable_device(pdev); |
| 74 | if (ret) { |
| 75 | pr_err("%s : ERROR: failed to enable %s device\n", __func__, |
| 76 | pci_name(pdev)); |
| 77 | return ret; |
| 78 | } |
| 79 | if (pci_request_regions(pdev, STMMAC_RESOURCE_NAME)) { |
| 80 | pr_err("%s: ERROR: failed to get PCI region\n", __func__); |
| 81 | ret = -ENODEV; |
| 82 | goto err_out_req_reg_failed; |
| 83 | } |
| 84 | |
| 85 | /* Get the base address of device */ |
| 86 | for (i = 0; i <= 5; i++) { |
| 87 | if (pci_resource_len(pdev, i) == 0) |
| 88 | continue; |
| 89 | addr = pci_iomap(pdev, i, 0); |
| 90 | if (addr == NULL) { |
Masanari Iida | 8c1a7f5 | 2012-02-08 02:08:21 +0000 | [diff] [blame] | 91 | pr_err("%s: ERROR: cannot map register memory, aborting", |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 92 | __func__); |
| 93 | ret = -EIO; |
| 94 | goto err_out_map_failed; |
| 95 | } |
| 96 | break; |
| 97 | } |
| 98 | pci_set_master(pdev); |
| 99 | |
| 100 | stmmac_default_data(); |
| 101 | |
Giuseppe CAVALLARO | cf3f047 | 2012-02-15 00:10:39 +0000 | [diff] [blame] | 102 | priv = stmmac_dvr_probe(&(pdev->dev), &plat_dat, addr); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 103 | if (!priv) { |
Masanari Iida | 0f09a34 | 2012-02-12 03:45:41 +0000 | [diff] [blame] | 104 | pr_err("%s: main driver probe failed", __func__); |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 105 | goto err_out; |
| 106 | } |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 107 | priv->dev->irq = pdev->irq; |
| 108 | priv->wol_irq = pdev->irq; |
| 109 | |
| 110 | pci_set_drvdata(pdev, priv->dev); |
| 111 | |
| 112 | pr_debug("STMMAC platform driver registration completed"); |
| 113 | |
| 114 | return 0; |
| 115 | |
| 116 | err_out: |
| 117 | pci_clear_master(pdev); |
| 118 | err_out_map_failed: |
| 119 | pci_release_regions(pdev); |
| 120 | err_out_req_reg_failed: |
| 121 | pci_disable_device(pdev); |
| 122 | |
| 123 | return ret; |
| 124 | } |
| 125 | |
| 126 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 127 | * stmmac_pci_remove |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 128 | * |
| 129 | * @pdev: platform device pointer |
| 130 | * Description: this function calls the main to free the net resources |
| 131 | * and releases the PCI resources. |
| 132 | */ |
Bill Pemberton | 979857b | 2012-12-03 09:23:34 -0500 | [diff] [blame] | 133 | static void stmmac_pci_remove(struct pci_dev *pdev) |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 134 | { |
| 135 | struct net_device *ndev = pci_get_drvdata(pdev); |
| 136 | struct stmmac_priv *priv = netdev_priv(ndev); |
| 137 | |
| 138 | stmmac_dvr_remove(ndev); |
| 139 | |
| 140 | pci_set_drvdata(pdev, NULL); |
| 141 | pci_iounmap(pdev, priv->ioaddr); |
| 142 | pci_release_regions(pdev); |
| 143 | pci_disable_device(pdev); |
| 144 | } |
| 145 | |
| 146 | #ifdef CONFIG_PM |
| 147 | static int stmmac_pci_suspend(struct pci_dev *pdev, pm_message_t state) |
| 148 | { |
| 149 | struct net_device *ndev = pci_get_drvdata(pdev); |
| 150 | int ret; |
| 151 | |
| 152 | ret = stmmac_suspend(ndev); |
| 153 | pci_save_state(pdev); |
| 154 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 155 | |
| 156 | return ret; |
| 157 | } |
| 158 | |
| 159 | static int stmmac_pci_resume(struct pci_dev *pdev) |
| 160 | { |
| 161 | struct net_device *ndev = pci_get_drvdata(pdev); |
| 162 | |
| 163 | pci_set_power_state(pdev, PCI_D0); |
| 164 | pci_restore_state(pdev); |
| 165 | |
| 166 | return stmmac_resume(ndev); |
| 167 | } |
| 168 | #endif |
| 169 | |
| 170 | #define STMMAC_VENDOR_ID 0x700 |
| 171 | #define STMMAC_DEVICE_ID 0x1108 |
| 172 | |
| 173 | static DEFINE_PCI_DEVICE_TABLE(stmmac_id_table) = { |
Alessandro Rubini | 5437f4b | 2012-01-23 23:08:56 +0000 | [diff] [blame] | 174 | {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)}, |
| 175 | {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)}, |
| 176 | {} |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 177 | }; |
| 178 | |
| 179 | MODULE_DEVICE_TABLE(pci, stmmac_id_table); |
| 180 | |
Giuseppe CAVALLARO | ba27ec6 | 2012-06-04 19:22:57 +0000 | [diff] [blame] | 181 | struct pci_driver stmmac_pci_driver = { |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 182 | .name = STMMAC_RESOURCE_NAME, |
| 183 | .id_table = stmmac_id_table, |
| 184 | .probe = stmmac_pci_probe, |
Bill Pemberton | 979857b | 2012-12-03 09:23:34 -0500 | [diff] [blame] | 185 | .remove = stmmac_pci_remove, |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 186 | #ifdef CONFIG_PM |
| 187 | .suspend = stmmac_pci_suspend, |
| 188 | .resume = stmmac_pci_resume, |
| 189 | #endif |
| 190 | }; |
| 191 | |
Giuseppe CAVALLARO | bfab27a | 2011-12-21 03:58:19 +0000 | [diff] [blame] | 192 | MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver"); |
| 193 | MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>"); |
| 194 | MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>"); |
| 195 | MODULE_LICENSE("GPL"); |