2019-01-22 01:34:53 +07:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2009-10-15 02:04:38 +07:00
|
|
|
/*
|
2016-03-12 00:53:10 +07:00
|
|
|
* Copyright (C) 2009-2015 Cavium, Inc.
|
2009-10-15 02:04:38 +07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/platform_device.h>
|
2015-07-29 05:12:11 +07:00
|
|
|
#include <linux/of_address.h>
|
2012-07-05 23:12:39 +07:00
|
|
|
#include <linux/of_mdio.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/gfp.h>
|
2009-10-15 02:04:38 +07:00
|
|
|
#include <linux/phy.h>
|
2012-07-05 23:12:39 +07:00
|
|
|
#include <linux/io.h>
|
2009-10-15 02:04:38 +07:00
|
|
|
|
2016-03-12 00:53:10 +07:00
|
|
|
#include "mdio-cavium.h"
|
2009-10-15 02:04:38 +07:00
|
|
|
|
2012-12-03 21:24:14 +07:00
|
|
|
static int octeon_mdiobus_probe(struct platform_device *pdev)
|
2009-10-15 02:04:38 +07:00
|
|
|
{
|
2016-03-12 00:53:10 +07:00
|
|
|
struct cavium_mdiobus *bus;
|
2016-01-07 02:11:14 +07:00
|
|
|
struct mii_bus *mii_bus;
|
2012-07-05 23:12:39 +07:00
|
|
|
struct resource *res_mem;
|
2016-03-12 00:53:10 +07:00
|
|
|
resource_size_t mdio_phys;
|
|
|
|
resource_size_t regsize;
|
2010-04-02 08:17:54 +07:00
|
|
|
union cvmx_smix_en smi_en;
|
2009-10-15 02:04:38 +07:00
|
|
|
int err = -ENOENT;
|
|
|
|
|
2016-01-07 02:11:14 +07:00
|
|
|
mii_bus = devm_mdiobus_alloc_size(&pdev->dev, sizeof(*bus));
|
|
|
|
if (!mii_bus)
|
2009-10-15 02:04:38 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2012-07-05 23:12:39 +07:00
|
|
|
res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (res_mem == NULL) {
|
|
|
|
dev_err(&pdev->dev, "found no memory resource\n");
|
2015-07-29 05:12:12 +07:00
|
|
|
return -ENXIO;
|
2012-07-05 23:12:39 +07:00
|
|
|
}
|
2015-07-29 05:12:12 +07:00
|
|
|
|
2016-01-07 02:11:14 +07:00
|
|
|
bus = mii_bus->priv;
|
|
|
|
bus->mii_bus = mii_bus;
|
2016-03-12 00:53:10 +07:00
|
|
|
mdio_phys = res_mem->start;
|
|
|
|
regsize = resource_size(res_mem);
|
2015-07-29 05:12:12 +07:00
|
|
|
|
2016-03-12 00:53:10 +07:00
|
|
|
if (!devm_request_mem_region(&pdev->dev, mdio_phys, regsize,
|
2012-07-05 23:12:39 +07:00
|
|
|
res_mem->name)) {
|
|
|
|
dev_err(&pdev->dev, "request_mem_region failed\n");
|
2015-07-29 05:12:12 +07:00
|
|
|
return -ENXIO;
|
2012-07-05 23:12:39 +07:00
|
|
|
}
|
2015-07-29 05:12:12 +07:00
|
|
|
|
2020-07-07 08:49:38 +07:00
|
|
|
bus->register_base = devm_ioremap(&pdev->dev, mdio_phys, regsize);
|
2015-07-29 05:12:12 +07:00
|
|
|
if (!bus->register_base) {
|
|
|
|
dev_err(&pdev->dev, "dev_ioremap failed\n");
|
|
|
|
return -ENOMEM;
|
|
|
|
}
|
2009-10-15 02:04:38 +07:00
|
|
|
|
2010-04-02 08:17:54 +07:00
|
|
|
smi_en.u64 = 0;
|
|
|
|
smi_en.s.en = 1;
|
2015-07-29 05:12:11 +07:00
|
|
|
oct_mdio_writeq(smi_en.u64, bus->register_base + SMI_EN);
|
2009-10-15 02:04:38 +07:00
|
|
|
|
2016-03-12 00:53:10 +07:00
|
|
|
bus->mii_bus->name = KBUILD_MODNAME;
|
2020-07-07 08:49:38 +07:00
|
|
|
snprintf(bus->mii_bus->id, MII_BUS_ID_SIZE, "%px", bus->register_base);
|
2009-10-15 02:04:38 +07:00
|
|
|
bus->mii_bus->parent = &pdev->dev;
|
|
|
|
|
2016-03-12 00:53:10 +07:00
|
|
|
bus->mii_bus->read = cavium_mdiobus_read;
|
|
|
|
bus->mii_bus->write = cavium_mdiobus_write;
|
2009-10-15 02:04:38 +07:00
|
|
|
|
2013-08-21 17:15:15 +07:00
|
|
|
platform_set_drvdata(pdev, bus);
|
2009-10-15 02:04:38 +07:00
|
|
|
|
2012-07-05 23:12:39 +07:00
|
|
|
err = of_mdiobus_register(bus->mii_bus, pdev->dev.of_node);
|
2009-10-15 02:04:38 +07:00
|
|
|
if (err)
|
2012-07-05 23:12:39 +07:00
|
|
|
goto fail_register;
|
2009-10-15 02:04:38 +07:00
|
|
|
|
2016-03-12 00:53:10 +07:00
|
|
|
dev_info(&pdev->dev, "Probed\n");
|
2009-10-15 02:04:38 +07:00
|
|
|
|
|
|
|
return 0;
|
2012-07-05 23:12:39 +07:00
|
|
|
fail_register:
|
2009-10-15 02:04:38 +07:00
|
|
|
mdiobus_free(bus->mii_bus);
|
2010-04-02 08:17:54 +07:00
|
|
|
smi_en.u64 = 0;
|
2015-07-29 05:12:11 +07:00
|
|
|
oct_mdio_writeq(smi_en.u64, bus->register_base + SMI_EN);
|
2009-10-15 02:04:38 +07:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-12-03 21:24:14 +07:00
|
|
|
static int octeon_mdiobus_remove(struct platform_device *pdev)
|
2009-10-15 02:04:38 +07:00
|
|
|
{
|
2016-03-12 00:53:10 +07:00
|
|
|
struct cavium_mdiobus *bus;
|
2010-04-02 08:17:54 +07:00
|
|
|
union cvmx_smix_en smi_en;
|
2009-10-15 02:04:38 +07:00
|
|
|
|
2013-09-02 15:10:09 +07:00
|
|
|
bus = platform_get_drvdata(pdev);
|
2009-10-15 02:04:38 +07:00
|
|
|
|
|
|
|
mdiobus_unregister(bus->mii_bus);
|
|
|
|
mdiobus_free(bus->mii_bus);
|
2010-04-02 08:17:54 +07:00
|
|
|
smi_en.u64 = 0;
|
2015-07-29 05:12:11 +07:00
|
|
|
oct_mdio_writeq(smi_en.u64, bus->register_base + SMI_EN);
|
2009-10-15 02:04:38 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-03-18 01:40:23 +07:00
|
|
|
static const struct of_device_id octeon_mdiobus_match[] = {
|
2012-07-05 23:12:39 +07:00
|
|
|
{
|
|
|
|
.compatible = "cavium,octeon-3860-mdio",
|
|
|
|
},
|
|
|
|
{},
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, octeon_mdiobus_match);
|
|
|
|
|
2009-10-15 02:04:38 +07:00
|
|
|
static struct platform_driver octeon_mdiobus_driver = {
|
|
|
|
.driver = {
|
2016-03-12 00:53:10 +07:00
|
|
|
.name = KBUILD_MODNAME,
|
2012-07-05 23:12:39 +07:00
|
|
|
.of_match_table = octeon_mdiobus_match,
|
2009-10-15 02:04:38 +07:00
|
|
|
},
|
|
|
|
.probe = octeon_mdiobus_probe,
|
2012-12-03 21:24:14 +07:00
|
|
|
.remove = octeon_mdiobus_remove,
|
2009-10-15 02:04:38 +07:00
|
|
|
};
|
|
|
|
|
2013-03-20 08:41:32 +07:00
|
|
|
module_platform_driver(octeon_mdiobus_driver);
|
2009-10-15 02:04:38 +07:00
|
|
|
|
2016-03-12 00:53:10 +07:00
|
|
|
MODULE_DESCRIPTION("Cavium OCTEON MDIO bus driver");
|
2009-10-15 02:04:38 +07:00
|
|
|
MODULE_AUTHOR("David Daney");
|
2019-01-22 01:34:53 +07:00
|
|
|
MODULE_LICENSE("GPL v2");
|