1 /*******************************************************************************
2 This contains the functions to handle the pci driver.
4 Copyright (C) 2011-2012 Vayavya Labs Pvt Ltd
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.
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
15 The full GNU General Public License is included in this distribution in
16 the file called "COPYING".
18 Author: Rayagond Kokatanur <rayagond@vayavyalabs.com>
19 Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
20 *******************************************************************************/
22 #include <linux/pci.h>
23 #include <linux/dmi.h>
28 * This struct is used to associate PCI Function of MAC controller on a board,
29 * discovered via DMI, with the address of PHY connected to the MAC. The
30 * negative value of the address means that MAC controller is not connected
33 struct stmmac_pci_dmi_data {
39 struct stmmac_pci_info {
41 int (*setup)(struct plat_stmmacenet_data *plat,
42 struct stmmac_pci_info *info);
43 struct stmmac_pci_dmi_data *dmi;
46 static int stmmac_pci_find_phy_addr(struct stmmac_pci_info *info)
48 const char *name = dmi_get_system_info(DMI_BOARD_NAME);
49 unsigned int func = PCI_FUNC(info->pdev->devfn);
50 struct stmmac_pci_dmi_data *dmi;
53 * Galileo boards with old firmware don't support DMI. We always return
54 * 1 here, so at least first found MAC controller would be probed.
59 for (dmi = info->dmi; dmi->name && *dmi->name; dmi++) {
60 if (!strcmp(dmi->name, name) && dmi->func == func)
67 static void stmmac_default_data(struct plat_stmmacenet_data *plat)
71 plat->interface = PHY_INTERFACE_MODE_GMII;
72 plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
74 plat->force_sf_dma_mode = 1;
76 plat->mdio_bus_data->phy_reset = NULL;
77 plat->mdio_bus_data->phy_mask = 0;
79 plat->dma_cfg->pbl = 32;
80 plat->dma_cfg->pblx8 = true;
83 /* Set default value for multicast hash bins */
84 plat->multicast_filter_bins = HASH_TABLE_SIZE;
86 /* Set default value for unicast filter entries */
87 plat->unicast_filter_entries = 1;
89 /* Set the maxmtu to a default of JUMBO_LEN */
90 plat->maxmtu = JUMBO_LEN;
93 static int quark_default_data(struct plat_stmmacenet_data *plat,
94 struct stmmac_pci_info *info)
96 struct pci_dev *pdev = info->pdev;
100 * Refuse to load the driver and register net device if MAC controller
101 * does not connect to any PHY interface.
103 ret = stmmac_pci_find_phy_addr(info);
107 plat->bus_id = PCI_DEVID(pdev->bus->number, pdev->devfn);
108 plat->phy_addr = ret;
109 plat->interface = PHY_INTERFACE_MODE_RMII;
112 plat->force_sf_dma_mode = 1;
114 plat->mdio_bus_data->phy_reset = NULL;
115 plat->mdio_bus_data->phy_mask = 0;
117 plat->dma_cfg->pbl = 16;
118 plat->dma_cfg->pblx8 = true;
119 plat->dma_cfg->fixed_burst = 1;
122 /* Set default value for multicast hash bins */
123 plat->multicast_filter_bins = HASH_TABLE_SIZE;
125 /* Set default value for unicast filter entries */
126 plat->unicast_filter_entries = 1;
128 /* Set the maxmtu to a default of JUMBO_LEN */
129 plat->maxmtu = JUMBO_LEN;
134 static struct stmmac_pci_dmi_data quark_pci_dmi_data[] = {
141 .name = "GalileoGen2",
148 static struct stmmac_pci_info quark_pci_info = {
149 .setup = quark_default_data,
150 .dmi = quark_pci_dmi_data,
156 * @pdev: pci device pointer
157 * @id: pointer to table of device id/id's.
159 * Description: This probing function gets called for all PCI devices which
160 * match the ID table and are not "owned" by other driver yet. This function
161 * gets passed a "struct pci_dev *" for each device whose entry in the ID table
162 * matches the device. The probe functions returns zero when the driver choose
163 * to take "ownership" of the device or an error code(-ve no) otherwise.
165 static int stmmac_pci_probe(struct pci_dev *pdev,
166 const struct pci_device_id *id)
168 struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
169 struct plat_stmmacenet_data *plat;
170 struct stmmac_resources res;
174 plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
178 plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
179 sizeof(*plat->mdio_bus_data),
181 if (!plat->mdio_bus_data)
184 plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
189 /* Enable pci device */
190 ret = pcim_enable_device(pdev);
192 dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
197 /* Get the base address of device */
198 for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
199 if (pci_resource_len(pdev, i) == 0)
201 ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
207 pci_set_master(pdev);
212 ret = info->setup(plat, info);
217 stmmac_default_data(plat);
219 pci_enable_msi(pdev);
221 memset(&res, 0, sizeof(res));
222 res.addr = pcim_iomap_table(pdev)[i];
223 res.wol_irq = pdev->irq;
226 return stmmac_dvr_probe(&pdev->dev, plat, &res);
232 * @pdev: platform device pointer
233 * Description: this function calls the main to free the net resources
234 * and releases the PCI resources.
236 static void stmmac_pci_remove(struct pci_dev *pdev)
238 stmmac_dvr_remove(&pdev->dev);
241 static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_suspend, stmmac_resume);
243 #define STMMAC_VENDOR_ID 0x700
244 #define STMMAC_QUARK_ID 0x0937
245 #define STMMAC_DEVICE_ID 0x1108
247 static const struct pci_device_id stmmac_id_table[] = {
248 {PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
249 {PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
250 {PCI_VDEVICE(INTEL, STMMAC_QUARK_ID), (kernel_ulong_t)&quark_pci_info},
254 MODULE_DEVICE_TABLE(pci, stmmac_id_table);
256 static struct pci_driver stmmac_pci_driver = {
257 .name = STMMAC_RESOURCE_NAME,
258 .id_table = stmmac_id_table,
259 .probe = stmmac_pci_probe,
260 .remove = stmmac_pci_remove,
262 .pm = &stmmac_pm_ops,
266 module_pci_driver(stmmac_pci_driver);
268 MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
269 MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
270 MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
271 MODULE_LICENSE("GPL");