2011-12-21 11:58:19 +08:00
|
|
|
/*******************************************************************************
|
|
|
|
This contains the functions to handle the pci driver.
|
|
|
|
|
|
|
|
Copyright (C) 2011-2012 Vayavya Labs Pvt Ltd
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
|
|
under the terms and conditions of the GNU General Public License,
|
|
|
|
version 2, as published by the Free Software Foundation.
|
|
|
|
|
|
|
|
This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along with
|
|
|
|
this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
The full GNU General Public License is included in this distribution in
|
|
|
|
the file called "COPYING".
|
|
|
|
|
|
|
|
Author: Rayagond Kokatanur <rayagond@vayavyalabs.com>
|
|
|
|
Author: Giuseppe Cavallaro <peppe.cavallaro@st.com>
|
|
|
|
*******************************************************************************/
|
|
|
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include "stmmac.h"
|
|
|
|
|
2015-01-28 03:44:47 +08:00
|
|
|
struct stmmac_pci_info {
|
|
|
|
struct pci_dev *pdev;
|
|
|
|
int (*setup)(struct plat_stmmacenet_data *plat,
|
|
|
|
struct stmmac_pci_info *info);
|
|
|
|
};
|
|
|
|
|
2014-11-28 21:40:56 +08:00
|
|
|
static void stmmac_default_data(struct plat_stmmacenet_data *plat)
|
2011-12-21 11:58:19 +08:00
|
|
|
{
|
2014-11-28 21:40:56 +08:00
|
|
|
plat->bus_id = 1;
|
|
|
|
plat->phy_addr = 0;
|
|
|
|
plat->interface = PHY_INTERFACE_MODE_GMII;
|
|
|
|
plat->clk_csr = 2; /* clk_csr_i = 20-35MHz & MDC = clk_csr_i/16 */
|
|
|
|
plat->has_gmac = 1;
|
|
|
|
plat->force_sf_dma_mode = 1;
|
2011-12-21 11:58:19 +08:00
|
|
|
|
2014-11-28 21:40:56 +08:00
|
|
|
plat->mdio_bus_data->phy_reset = NULL;
|
|
|
|
plat->mdio_bus_data->phy_mask = 0;
|
2012-04-19 03:48:21 +08:00
|
|
|
|
2014-11-28 21:40:56 +08:00
|
|
|
plat->dma_cfg->pbl = 32;
|
|
|
|
plat->dma_cfg->burst_len = DMA_AXI_BLEN_256;
|
2014-11-01 00:28:03 +08:00
|
|
|
|
|
|
|
/* Set default value for multicast hash bins */
|
2014-11-28 21:40:56 +08:00
|
|
|
plat->multicast_filter_bins = HASH_TABLE_SIZE;
|
2014-11-01 00:28:03 +08:00
|
|
|
|
|
|
|
/* Set default value for unicast filter entries */
|
2014-11-28 21:40:56 +08:00
|
|
|
plat->unicast_filter_entries = 1;
|
2011-12-21 11:58:19 +08:00
|
|
|
}
|
|
|
|
|
2015-01-28 03:44:47 +08:00
|
|
|
static int quark_default_data(struct plat_stmmacenet_data *plat,
|
|
|
|
struct stmmac_pci_info *info)
|
|
|
|
{
|
|
|
|
struct pci_dev *pdev = info->pdev;
|
|
|
|
|
|
|
|
plat->bus_id = PCI_DEVID(pdev->bus->number, pdev->devfn);
|
|
|
|
plat->phy_addr = 1;
|
|
|
|
plat->interface = PHY_INTERFACE_MODE_RMII;
|
|
|
|
plat->clk_csr = 2;
|
|
|
|
plat->has_gmac = 1;
|
|
|
|
plat->force_sf_dma_mode = 1;
|
|
|
|
|
|
|
|
plat->mdio_bus_data->phy_reset = NULL;
|
|
|
|
plat->mdio_bus_data->phy_mask = 0;
|
|
|
|
|
|
|
|
plat->dma_cfg->pbl = 16;
|
|
|
|
plat->dma_cfg->burst_len = DMA_AXI_BLEN_256;
|
|
|
|
plat->dma_cfg->fixed_burst = 1;
|
|
|
|
|
|
|
|
/* Set default value for multicast hash bins */
|
|
|
|
plat->multicast_filter_bins = HASH_TABLE_SIZE;
|
|
|
|
|
|
|
|
/* Set default value for unicast filter entries */
|
|
|
|
plat->unicast_filter_entries = 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct stmmac_pci_info quark_pci_info = {
|
|
|
|
.setup = quark_default_data,
|
|
|
|
};
|
|
|
|
|
2011-12-21 11:58:19 +08:00
|
|
|
/**
|
|
|
|
* stmmac_pci_probe
|
|
|
|
*
|
|
|
|
* @pdev: pci device pointer
|
|
|
|
* @id: pointer to table of device id/id's.
|
|
|
|
*
|
|
|
|
* Description: This probing function gets called for all PCI devices which
|
|
|
|
* match the ID table and are not "owned" by other driver yet. This function
|
|
|
|
* gets passed a "struct pci_dev *" for each device whose entry in the ID table
|
|
|
|
* matches the device. The probe functions returns zero when the driver choose
|
|
|
|
* to take "ownership" of the device or an error code(-ve no) otherwise.
|
|
|
|
*/
|
2012-12-03 22:23:34 +08:00
|
|
|
static int stmmac_pci_probe(struct pci_dev *pdev,
|
2012-12-06 22:30:56 +08:00
|
|
|
const struct pci_device_id *id)
|
2011-12-21 11:58:19 +08:00
|
|
|
{
|
2015-01-28 03:44:47 +08:00
|
|
|
struct stmmac_pci_info *info = (struct stmmac_pci_info *)id->driver_data;
|
2014-11-28 21:40:56 +08:00
|
|
|
struct plat_stmmacenet_data *plat;
|
2014-11-05 18:27:28 +08:00
|
|
|
struct stmmac_priv *priv;
|
2011-12-21 11:58:19 +08:00
|
|
|
int i;
|
2014-11-05 18:27:28 +08:00
|
|
|
int ret;
|
2011-12-21 11:58:19 +08:00
|
|
|
|
2014-11-28 21:40:56 +08:00
|
|
|
plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
|
|
|
|
if (!plat)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
plat->mdio_bus_data = devm_kzalloc(&pdev->dev,
|
|
|
|
sizeof(*plat->mdio_bus_data),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!plat->mdio_bus_data)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
plat->dma_cfg = devm_kzalloc(&pdev->dev, sizeof(*plat->dma_cfg),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!plat->dma_cfg)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
2011-12-21 11:58:19 +08:00
|
|
|
/* Enable pci device */
|
2014-11-05 18:27:28 +08:00
|
|
|
ret = pcim_enable_device(pdev);
|
2011-12-21 11:58:19 +08:00
|
|
|
if (ret) {
|
2014-11-05 18:27:29 +08:00
|
|
|
dev_err(&pdev->dev, "%s: ERROR: failed to enable device\n",
|
|
|
|
__func__);
|
2011-12-21 11:58:19 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Get the base address of device */
|
2014-11-05 18:27:26 +08:00
|
|
|
for (i = 0; i <= PCI_STD_RESOURCE_END; i++) {
|
2011-12-21 11:58:19 +08:00
|
|
|
if (pci_resource_len(pdev, i) == 0)
|
|
|
|
continue;
|
2014-11-05 18:27:28 +08:00
|
|
|
ret = pcim_iomap_regions(pdev, BIT(i), pci_name(pdev));
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2011-12-21 11:58:19 +08:00
|
|
|
break;
|
|
|
|
}
|
2014-11-05 18:27:28 +08:00
|
|
|
|
2011-12-21 11:58:19 +08:00
|
|
|
pci_set_master(pdev);
|
|
|
|
|
2015-01-28 03:44:47 +08:00
|
|
|
if (info) {
|
|
|
|
info->pdev = pdev;
|
|
|
|
if (info->setup) {
|
|
|
|
ret = info->setup(plat, info);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
stmmac_default_data(plat);
|
2011-12-21 11:58:19 +08:00
|
|
|
|
2014-11-28 21:40:56 +08:00
|
|
|
priv = stmmac_dvr_probe(&pdev->dev, plat, pcim_iomap_table(pdev)[i]);
|
2014-01-17 21:24:41 +08:00
|
|
|
if (IS_ERR(priv)) {
|
2014-11-05 18:27:29 +08:00
|
|
|
dev_err(&pdev->dev, "%s: main driver probe failed\n", __func__);
|
2014-11-05 18:27:28 +08:00
|
|
|
return PTR_ERR(priv);
|
2011-12-21 11:58:19 +08:00
|
|
|
}
|
|
|
|
priv->dev->irq = pdev->irq;
|
|
|
|
priv->wol_irq = pdev->irq;
|
|
|
|
|
|
|
|
pci_set_drvdata(pdev, priv->dev);
|
|
|
|
|
2014-11-05 18:27:29 +08:00
|
|
|
dev_dbg(&pdev->dev, "STMMAC PCI driver registration completed\n");
|
2011-12-21 11:58:19 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-07-10 18:56:00 +08:00
|
|
|
* stmmac_pci_remove
|
2011-12-21 11:58:19 +08:00
|
|
|
*
|
|
|
|
* @pdev: platform device pointer
|
|
|
|
* Description: this function calls the main to free the net resources
|
|
|
|
* and releases the PCI resources.
|
|
|
|
*/
|
2012-12-03 22:23:34 +08:00
|
|
|
static void stmmac_pci_remove(struct pci_dev *pdev)
|
2011-12-21 11:58:19 +08:00
|
|
|
{
|
|
|
|
struct net_device *ndev = pci_get_drvdata(pdev);
|
|
|
|
|
|
|
|
stmmac_dvr_remove(ndev);
|
|
|
|
}
|
|
|
|
|
2014-11-05 18:27:27 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int stmmac_pci_suspend(struct device *dev)
|
2011-12-21 11:58:19 +08:00
|
|
|
{
|
2014-11-05 18:27:27 +08:00
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
2011-12-21 11:58:19 +08:00
|
|
|
struct net_device *ndev = pci_get_drvdata(pdev);
|
|
|
|
|
2014-11-05 18:27:27 +08:00
|
|
|
return stmmac_suspend(ndev);
|
2011-12-21 11:58:19 +08:00
|
|
|
}
|
|
|
|
|
2014-11-05 18:27:27 +08:00
|
|
|
static int stmmac_pci_resume(struct device *dev)
|
2011-12-21 11:58:19 +08:00
|
|
|
{
|
2014-11-05 18:27:27 +08:00
|
|
|
struct pci_dev *pdev = to_pci_dev(dev);
|
2011-12-21 11:58:19 +08:00
|
|
|
struct net_device *ndev = pci_get_drvdata(pdev);
|
|
|
|
|
|
|
|
return stmmac_resume(ndev);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2014-11-05 18:27:27 +08:00
|
|
|
static SIMPLE_DEV_PM_OPS(stmmac_pm_ops, stmmac_pci_suspend, stmmac_pci_resume);
|
|
|
|
|
2011-12-21 11:58:19 +08:00
|
|
|
#define STMMAC_VENDOR_ID 0x700
|
2015-01-28 03:44:47 +08:00
|
|
|
#define STMMAC_QUARK_ID 0x0937
|
2011-12-21 11:58:19 +08:00
|
|
|
#define STMMAC_DEVICE_ID 0x1108
|
|
|
|
|
2014-08-08 21:56:03 +08:00
|
|
|
static const struct pci_device_id stmmac_id_table[] = {
|
2012-01-24 07:08:56 +08:00
|
|
|
{PCI_DEVICE(STMMAC_VENDOR_ID, STMMAC_DEVICE_ID)},
|
|
|
|
{PCI_DEVICE(PCI_VENDOR_ID_STMICRO, PCI_DEVICE_ID_STMICRO_MAC)},
|
2015-01-28 03:44:47 +08:00
|
|
|
{PCI_VDEVICE(INTEL, STMMAC_QUARK_ID), (kernel_ulong_t)&quark_pci_info},
|
2012-01-24 07:08:56 +08:00
|
|
|
{}
|
2011-12-21 11:58:19 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
MODULE_DEVICE_TABLE(pci, stmmac_id_table);
|
|
|
|
|
2014-11-10 18:38:59 +08:00
|
|
|
static struct pci_driver stmmac_pci_driver = {
|
2011-12-21 11:58:19 +08:00
|
|
|
.name = STMMAC_RESOURCE_NAME,
|
|
|
|
.id_table = stmmac_id_table,
|
|
|
|
.probe = stmmac_pci_probe,
|
2012-12-03 22:23:34 +08:00
|
|
|
.remove = stmmac_pci_remove,
|
2014-11-05 18:27:27 +08:00
|
|
|
.driver = {
|
|
|
|
.pm = &stmmac_pm_ops,
|
|
|
|
},
|
2011-12-21 11:58:19 +08:00
|
|
|
};
|
|
|
|
|
2014-11-10 18:38:59 +08:00
|
|
|
module_pci_driver(stmmac_pci_driver);
|
|
|
|
|
2011-12-21 11:58:19 +08:00
|
|
|
MODULE_DESCRIPTION("STMMAC 10/100/1000 Ethernet PCI driver");
|
|
|
|
MODULE_AUTHOR("Rayagond Kokatanur <rayagond.kokatanur@vayavyalabs.com>");
|
|
|
|
MODULE_AUTHOR("Giuseppe Cavallaro <peppe.cavallaro@st.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|