mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-09-04 20:19:47 +08:00
ENETC ports can manage the MDIO bus via local register interface. However there's also a centralized way to manage the MDIO bus, via the MDIO PCIe endpoint device integrated by the same root complex that also integrates the ENETC ports (eth controllers). Depending on board design and use case, centralized access to MDIO may be better than using local ENETC port registers. For instance, on the LS1028A QDS board where MDIO muxing is required. Also, the LS1028A on-chip switch doesn't have a local MDIO register interface. The current patch registers the above PCIe endpoint as a separate MDIO bus and provides a driver for it by re-using the code used for local MDIO access. It also allows the ENETC port PHYs to be managed by this driver if the local "mdio" node is missing from the ENETC port node. Signed-off-by: Claudiu Manoil <claudiu.manoil@nxp.com> Reviewed-by: Andrew Lunn <andrew@lunn.ch> Signed-off-by: David S. Miller <davem@davemloft.net>
102 lines
2.3 KiB
C
102 lines
2.3 KiB
C
// SPDX-License-Identifier: (GPL-2.0+ OR BSD-3-Clause)
|
|
/* Copyright 2019 NXP */
|
|
#include <linux/of_mdio.h>
|
|
#include "enetc_mdio.h"
|
|
|
|
#define ENETC_MDIO_DEV_ID 0xee01
|
|
#define ENETC_MDIO_DEV_NAME "FSL PCIe IE Central MDIO"
|
|
#define ENETC_MDIO_BUS_NAME ENETC_MDIO_DEV_NAME " Bus"
|
|
#define ENETC_MDIO_DRV_NAME ENETC_MDIO_DEV_NAME " driver"
|
|
|
|
static int enetc_pci_mdio_probe(struct pci_dev *pdev,
|
|
const struct pci_device_id *ent)
|
|
{
|
|
struct enetc_mdio_priv *mdio_priv;
|
|
struct device *dev = &pdev->dev;
|
|
struct enetc_hw *hw;
|
|
struct mii_bus *bus;
|
|
int err;
|
|
|
|
hw = devm_kzalloc(dev, sizeof(*hw), GFP_KERNEL);
|
|
if (!hw)
|
|
return -ENOMEM;
|
|
|
|
bus = devm_mdiobus_alloc_size(dev, sizeof(*mdio_priv));
|
|
if (!bus)
|
|
return -ENOMEM;
|
|
|
|
bus->name = ENETC_MDIO_BUS_NAME;
|
|
bus->read = enetc_mdio_read;
|
|
bus->write = enetc_mdio_write;
|
|
bus->parent = dev;
|
|
mdio_priv = bus->priv;
|
|
mdio_priv->hw = hw;
|
|
snprintf(bus->id, MII_BUS_ID_SIZE, "%s", dev_name(dev));
|
|
|
|
pcie_flr(pdev);
|
|
err = pci_enable_device_mem(pdev);
|
|
if (err) {
|
|
dev_err(dev, "device enable failed\n");
|
|
return err;
|
|
}
|
|
|
|
err = pci_request_region(pdev, 0, KBUILD_MODNAME);
|
|
if (err) {
|
|
dev_err(dev, "pci_request_region failed\n");
|
|
goto err_pci_mem_reg;
|
|
}
|
|
|
|
hw->port = pci_iomap(pdev, 0, 0);
|
|
if (!hw->port) {
|
|
err = -ENXIO;
|
|
dev_err(dev, "iomap failed\n");
|
|
goto err_ioremap;
|
|
}
|
|
|
|
err = of_mdiobus_register(bus, dev->of_node);
|
|
if (err)
|
|
goto err_mdiobus_reg;
|
|
|
|
pci_set_drvdata(pdev, bus);
|
|
|
|
return 0;
|
|
|
|
err_mdiobus_reg:
|
|
iounmap(mdio_priv->hw->port);
|
|
err_ioremap:
|
|
pci_release_mem_regions(pdev);
|
|
err_pci_mem_reg:
|
|
pci_disable_device(pdev);
|
|
|
|
return err;
|
|
}
|
|
|
|
static void enetc_pci_mdio_remove(struct pci_dev *pdev)
|
|
{
|
|
struct mii_bus *bus = pci_get_drvdata(pdev);
|
|
struct enetc_mdio_priv *mdio_priv;
|
|
|
|
mdiobus_unregister(bus);
|
|
mdio_priv = bus->priv;
|
|
iounmap(mdio_priv->hw->port);
|
|
pci_release_mem_regions(pdev);
|
|
pci_disable_device(pdev);
|
|
}
|
|
|
|
static const struct pci_device_id enetc_pci_mdio_id_table[] = {
|
|
{ PCI_DEVICE(PCI_VENDOR_ID_FREESCALE, ENETC_MDIO_DEV_ID) },
|
|
{ 0, } /* End of table. */
|
|
};
|
|
MODULE_DEVICE_TABLE(pci, enetc_pci_mdio_id_table);
|
|
|
|
static struct pci_driver enetc_pci_mdio_driver = {
|
|
.name = KBUILD_MODNAME,
|
|
.id_table = enetc_pci_mdio_id_table,
|
|
.probe = enetc_pci_mdio_probe,
|
|
.remove = enetc_pci_mdio_remove,
|
|
};
|
|
module_pci_driver(enetc_pci_mdio_driver);
|
|
|
|
MODULE_DESCRIPTION(ENETC_MDIO_DRV_NAME);
|
|
MODULE_LICENSE("Dual BSD/GPL");
|