2012-11-13 00:03:47 +08:00
|
|
|
/*
|
|
|
|
* Driver for the MDIO interface of Marvell network interfaces.
|
|
|
|
*
|
|
|
|
* Since the MDIO interface of Marvell network interfaces is shared
|
|
|
|
* between all network interfaces, having a single driver allows to
|
|
|
|
* handle concurrent accesses properly (you may have four Ethernet
|
2013-10-29 17:33:34 +08:00
|
|
|
* ports, but they in fact share the same SMI interface to access
|
|
|
|
* the MDIO bus). This driver is currently used by the mvneta and
|
|
|
|
* mv643xx_eth drivers.
|
2012-11-13 00:03:47 +08:00
|
|
|
*
|
|
|
|
* Copyright (C) 2012 Marvell
|
|
|
|
*
|
|
|
|
* Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
|
|
|
|
*
|
|
|
|
* This file is licensed under the terms of the GNU General Public
|
|
|
|
* License version 2. This program is licensed "as is" without any
|
|
|
|
* warranty of any kind, whether express or implied.
|
|
|
|
*/
|
|
|
|
|
2017-06-15 22:43:16 +08:00
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/io.h>
|
2012-11-13 00:03:47 +08:00
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
2017-06-15 22:43:23 +08:00
|
|
|
#include <linux/of_device.h>
|
2017-06-15 22:43:16 +08:00
|
|
|
#include <linux/of_mdio.h>
|
2012-11-13 00:03:47 +08:00
|
|
|
#include <linux/phy.h>
|
|
|
|
#include <linux/platform_device.h>
|
2013-03-22 11:39:27 +08:00
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/wait.h>
|
2012-11-13 00:03:47 +08:00
|
|
|
|
2017-06-15 22:43:17 +08:00
|
|
|
#define MVMDIO_SMI_DATA_SHIFT 0
|
|
|
|
#define MVMDIO_SMI_PHY_ADDR_SHIFT 16
|
|
|
|
#define MVMDIO_SMI_PHY_REG_SHIFT 21
|
|
|
|
#define MVMDIO_SMI_READ_OPERATION BIT(26)
|
|
|
|
#define MVMDIO_SMI_WRITE_OPERATION 0
|
|
|
|
#define MVMDIO_SMI_READ_VALID BIT(27)
|
|
|
|
#define MVMDIO_SMI_BUSY BIT(28)
|
|
|
|
#define MVMDIO_ERR_INT_CAUSE 0x007C
|
|
|
|
#define MVMDIO_ERR_INT_SMI_DONE 0x00000010
|
|
|
|
#define MVMDIO_ERR_INT_MASK 0x0080
|
2012-11-13 00:03:47 +08:00
|
|
|
|
2017-06-15 22:43:23 +08:00
|
|
|
#define MVMDIO_XSMI_MGNT_REG 0x0
|
|
|
|
#define MVMDIO_XSMI_PHYADDR_SHIFT 16
|
|
|
|
#define MVMDIO_XSMI_DEVADDR_SHIFT 21
|
|
|
|
#define MVMDIO_XSMI_WRITE_OPERATION (0x5 << 26)
|
|
|
|
#define MVMDIO_XSMI_READ_OPERATION (0x7 << 26)
|
|
|
|
#define MVMDIO_XSMI_READ_VALID BIT(29)
|
|
|
|
#define MVMDIO_XSMI_BUSY BIT(30)
|
|
|
|
#define MVMDIO_XSMI_ADDR_REG 0x8
|
|
|
|
|
2013-10-29 17:33:31 +08:00
|
|
|
/*
|
|
|
|
* SMI Timeout measurements:
|
|
|
|
* - Kirkwood 88F6281 (Globalscale Dreamplug): 45us to 95us (Interrupt)
|
|
|
|
* - Armada 370 (Globalscale Mirabox): 41us to 43us (Polled)
|
|
|
|
*/
|
2017-06-15 22:43:17 +08:00
|
|
|
#define MVMDIO_SMI_TIMEOUT 1000 /* 1000us = 1ms */
|
|
|
|
#define MVMDIO_SMI_POLL_INTERVAL_MIN 45
|
|
|
|
#define MVMDIO_SMI_POLL_INTERVAL_MAX 55
|
2013-10-29 17:33:31 +08:00
|
|
|
|
2017-06-15 22:43:23 +08:00
|
|
|
#define MVMDIO_XSMI_POLL_INTERVAL_MIN 150
|
|
|
|
#define MVMDIO_XSMI_POLL_INTERVAL_MAX 160
|
|
|
|
|
2012-11-13 00:03:47 +08:00
|
|
|
struct orion_mdio_dev {
|
2013-03-22 11:39:26 +08:00
|
|
|
void __iomem *regs;
|
2017-04-10 23:28:31 +08:00
|
|
|
struct clk *clk[3];
|
2013-03-22 11:39:27 +08:00
|
|
|
/*
|
|
|
|
* If we have access to the error interrupt pin (which is
|
|
|
|
* somewhat misnamed as it not only reflects internal errors
|
|
|
|
* but also reflects SMI completion), use that to wait for
|
|
|
|
* SMI access completion instead of polling the SMI busy bit.
|
|
|
|
*/
|
|
|
|
int err_interrupt;
|
|
|
|
wait_queue_head_t smi_busy_wait;
|
2012-11-13 00:03:47 +08:00
|
|
|
};
|
|
|
|
|
2017-06-15 22:43:23 +08:00
|
|
|
enum orion_mdio_bus_type {
|
|
|
|
BUS_TYPE_SMI,
|
|
|
|
BUS_TYPE_XSMI
|
|
|
|
};
|
|
|
|
|
2017-06-15 22:43:20 +08:00
|
|
|
struct orion_mdio_ops {
|
|
|
|
int (*is_done)(struct orion_mdio_dev *);
|
2017-06-15 22:43:21 +08:00
|
|
|
unsigned int poll_interval_min;
|
|
|
|
unsigned int poll_interval_max;
|
2017-06-15 22:43:20 +08:00
|
|
|
};
|
2013-03-22 11:39:27 +08:00
|
|
|
|
2012-11-19 18:40:15 +08:00
|
|
|
/* Wait for the SMI unit to be ready for another operation
|
2012-11-13 00:03:47 +08:00
|
|
|
*/
|
2017-06-15 22:43:20 +08:00
|
|
|
static int orion_mdio_wait_ready(const struct orion_mdio_ops *ops,
|
|
|
|
struct mii_bus *bus)
|
2012-11-13 00:03:47 +08:00
|
|
|
{
|
|
|
|
struct orion_mdio_dev *dev = bus->priv;
|
2013-10-29 17:33:31 +08:00
|
|
|
unsigned long timeout = usecs_to_jiffies(MVMDIO_SMI_TIMEOUT);
|
|
|
|
unsigned long end = jiffies + timeout;
|
|
|
|
int timedout = 0;
|
2012-11-13 00:03:47 +08:00
|
|
|
|
2013-10-29 17:33:31 +08:00
|
|
|
while (1) {
|
2017-06-15 22:43:20 +08:00
|
|
|
if (ops->is_done(dev))
|
2013-10-29 17:33:31 +08:00
|
|
|
return 0;
|
|
|
|
else if (timedout)
|
|
|
|
break;
|
2012-11-13 00:03:47 +08:00
|
|
|
|
2013-10-29 17:33:31 +08:00
|
|
|
if (dev->err_interrupt <= 0) {
|
2017-06-15 22:43:21 +08:00
|
|
|
usleep_range(ops->poll_interval_min,
|
|
|
|
ops->poll_interval_max);
|
2012-11-13 00:03:47 +08:00
|
|
|
|
2013-10-29 17:33:31 +08:00
|
|
|
if (time_is_before_jiffies(end))
|
|
|
|
++timedout;
|
|
|
|
} else {
|
2013-12-19 21:09:48 +08:00
|
|
|
/* wait_event_timeout does not guarantee a delay of at
|
|
|
|
* least one whole jiffie, so timeout must be no less
|
|
|
|
* than two.
|
|
|
|
*/
|
|
|
|
if (timeout < 2)
|
|
|
|
timeout = 2;
|
2013-03-22 11:39:27 +08:00
|
|
|
wait_event_timeout(dev->smi_busy_wait,
|
2017-06-15 22:43:20 +08:00
|
|
|
ops->is_done(dev), timeout);
|
2013-10-29 17:33:31 +08:00
|
|
|
|
|
|
|
++timedout;
|
|
|
|
}
|
2012-11-13 00:03:47 +08:00
|
|
|
}
|
|
|
|
|
2013-10-29 17:33:31 +08:00
|
|
|
dev_err(bus->parent, "Timeout: SMI busy for too long\n");
|
|
|
|
return -ETIMEDOUT;
|
2012-11-13 00:03:47 +08:00
|
|
|
}
|
|
|
|
|
2017-06-15 22:43:20 +08:00
|
|
|
static int orion_mdio_smi_is_done(struct orion_mdio_dev *dev)
|
|
|
|
{
|
|
|
|
return !(readl(dev->regs) & MVMDIO_SMI_BUSY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct orion_mdio_ops orion_mdio_smi_ops = {
|
|
|
|
.is_done = orion_mdio_smi_is_done,
|
2017-06-15 22:43:21 +08:00
|
|
|
.poll_interval_min = MVMDIO_SMI_POLL_INTERVAL_MIN,
|
|
|
|
.poll_interval_max = MVMDIO_SMI_POLL_INTERVAL_MAX,
|
2017-06-15 22:43:20 +08:00
|
|
|
};
|
|
|
|
|
2017-06-15 22:43:23 +08:00
|
|
|
static int orion_mdio_smi_read(struct mii_bus *bus, int mii_id,
|
|
|
|
int regnum)
|
2012-11-13 00:03:47 +08:00
|
|
|
{
|
|
|
|
struct orion_mdio_dev *dev = bus->priv;
|
|
|
|
u32 val;
|
|
|
|
int ret;
|
|
|
|
|
2017-06-15 22:43:22 +08:00
|
|
|
if (regnum & MII_ADDR_C45)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2017-06-15 22:43:20 +08:00
|
|
|
ret = orion_mdio_wait_ready(&orion_mdio_smi_ops, bus);
|
2013-10-29 17:33:32 +08:00
|
|
|
if (ret < 0)
|
2017-06-15 22:43:24 +08:00
|
|
|
return ret;
|
2012-11-13 00:03:47 +08:00
|
|
|
|
|
|
|
writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) |
|
|
|
|
(regnum << MVMDIO_SMI_PHY_REG_SHIFT) |
|
|
|
|
MVMDIO_SMI_READ_OPERATION),
|
2013-03-22 11:39:26 +08:00
|
|
|
dev->regs);
|
2012-11-13 00:03:47 +08:00
|
|
|
|
2017-06-15 22:43:20 +08:00
|
|
|
ret = orion_mdio_wait_ready(&orion_mdio_smi_ops, bus);
|
2013-10-29 17:33:32 +08:00
|
|
|
if (ret < 0)
|
2017-06-15 22:43:24 +08:00
|
|
|
return ret;
|
2013-10-29 17:33:32 +08:00
|
|
|
|
|
|
|
val = readl(dev->regs);
|
|
|
|
if (!(val & MVMDIO_SMI_READ_VALID)) {
|
|
|
|
dev_err(bus->parent, "SMI bus read not valid\n");
|
2017-06-15 22:43:24 +08:00
|
|
|
return -ENODEV;
|
2012-11-13 00:03:47 +08:00
|
|
|
}
|
|
|
|
|
2017-06-15 22:43:24 +08:00
|
|
|
return val & GENMASK(15, 0);
|
2012-11-13 00:03:47 +08:00
|
|
|
}
|
|
|
|
|
2017-06-15 22:43:23 +08:00
|
|
|
static int orion_mdio_smi_write(struct mii_bus *bus, int mii_id,
|
|
|
|
int regnum, u16 value)
|
2012-11-13 00:03:47 +08:00
|
|
|
{
|
|
|
|
struct orion_mdio_dev *dev = bus->priv;
|
|
|
|
int ret;
|
|
|
|
|
2017-06-15 22:43:22 +08:00
|
|
|
if (regnum & MII_ADDR_C45)
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
2017-06-15 22:43:20 +08:00
|
|
|
ret = orion_mdio_wait_ready(&orion_mdio_smi_ops, bus);
|
2013-10-29 17:33:33 +08:00
|
|
|
if (ret < 0)
|
2017-06-15 22:43:24 +08:00
|
|
|
return ret;
|
2012-11-13 00:03:47 +08:00
|
|
|
|
|
|
|
writel(((mii_id << MVMDIO_SMI_PHY_ADDR_SHIFT) |
|
|
|
|
(regnum << MVMDIO_SMI_PHY_REG_SHIFT) |
|
|
|
|
MVMDIO_SMI_WRITE_OPERATION |
|
|
|
|
(value << MVMDIO_SMI_DATA_SHIFT)),
|
2013-03-22 11:39:26 +08:00
|
|
|
dev->regs);
|
2012-11-13 00:03:47 +08:00
|
|
|
|
2017-06-15 22:43:24 +08:00
|
|
|
return 0;
|
2012-11-13 00:03:47 +08:00
|
|
|
}
|
|
|
|
|
2017-06-15 22:43:23 +08:00
|
|
|
static int orion_mdio_xsmi_is_done(struct orion_mdio_dev *dev)
|
|
|
|
{
|
|
|
|
return !(readl(dev->regs + MVMDIO_XSMI_MGNT_REG) & MVMDIO_XSMI_BUSY);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct orion_mdio_ops orion_mdio_xsmi_ops = {
|
|
|
|
.is_done = orion_mdio_xsmi_is_done,
|
|
|
|
.poll_interval_min = MVMDIO_XSMI_POLL_INTERVAL_MIN,
|
|
|
|
.poll_interval_max = MVMDIO_XSMI_POLL_INTERVAL_MAX,
|
|
|
|
};
|
|
|
|
|
|
|
|
static int orion_mdio_xsmi_read(struct mii_bus *bus, int mii_id,
|
|
|
|
int regnum)
|
|
|
|
{
|
|
|
|
struct orion_mdio_dev *dev = bus->priv;
|
|
|
|
u16 dev_addr = (regnum >> 16) & GENMASK(4, 0);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(regnum & MII_ADDR_C45))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
ret = orion_mdio_wait_ready(&orion_mdio_xsmi_ops, bus);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
writel(regnum & GENMASK(15, 0), dev->regs + MVMDIO_XSMI_ADDR_REG);
|
|
|
|
writel((mii_id << MVMDIO_XSMI_PHYADDR_SHIFT) |
|
|
|
|
(dev_addr << MVMDIO_XSMI_DEVADDR_SHIFT) |
|
|
|
|
MVMDIO_XSMI_READ_OPERATION,
|
|
|
|
dev->regs + MVMDIO_XSMI_MGNT_REG);
|
|
|
|
|
|
|
|
ret = orion_mdio_wait_ready(&orion_mdio_xsmi_ops, bus);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!(readl(dev->regs + MVMDIO_XSMI_MGNT_REG) &
|
|
|
|
MVMDIO_XSMI_READ_VALID)) {
|
|
|
|
dev_err(bus->parent, "XSMI bus read not valid\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
|
|
|
return readl(dev->regs + MVMDIO_XSMI_MGNT_REG) & GENMASK(15, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int orion_mdio_xsmi_write(struct mii_bus *bus, int mii_id,
|
|
|
|
int regnum, u16 value)
|
|
|
|
{
|
|
|
|
struct orion_mdio_dev *dev = bus->priv;
|
|
|
|
u16 dev_addr = (regnum >> 16) & GENMASK(4, 0);
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (!(regnum & MII_ADDR_C45))
|
|
|
|
return -EOPNOTSUPP;
|
|
|
|
|
|
|
|
ret = orion_mdio_wait_ready(&orion_mdio_xsmi_ops, bus);
|
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
writel(regnum & GENMASK(15, 0), dev->regs + MVMDIO_XSMI_ADDR_REG);
|
|
|
|
writel((mii_id << MVMDIO_XSMI_PHYADDR_SHIFT) |
|
|
|
|
(dev_addr << MVMDIO_XSMI_DEVADDR_SHIFT) |
|
|
|
|
MVMDIO_XSMI_WRITE_OPERATION | value,
|
|
|
|
dev->regs + MVMDIO_XSMI_MGNT_REG);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2013-03-22 11:39:27 +08:00
|
|
|
static irqreturn_t orion_mdio_err_irq(int irq, void *dev_id)
|
|
|
|
{
|
|
|
|
struct orion_mdio_dev *dev = dev_id;
|
|
|
|
|
|
|
|
if (readl(dev->regs + MVMDIO_ERR_INT_CAUSE) &
|
|
|
|
MVMDIO_ERR_INT_SMI_DONE) {
|
|
|
|
writel(~MVMDIO_ERR_INT_SMI_DONE,
|
|
|
|
dev->regs + MVMDIO_ERR_INT_CAUSE);
|
|
|
|
wake_up(&dev->smi_busy_wait);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
return IRQ_NONE;
|
|
|
|
}
|
|
|
|
|
2012-12-21 21:42:15 +08:00
|
|
|
static int orion_mdio_probe(struct platform_device *pdev)
|
2012-11-13 00:03:47 +08:00
|
|
|
{
|
2017-06-15 22:43:23 +08:00
|
|
|
enum orion_mdio_bus_type type;
|
2013-03-22 11:39:25 +08:00
|
|
|
struct resource *r;
|
2012-11-13 00:03:47 +08:00
|
|
|
struct mii_bus *bus;
|
|
|
|
struct orion_mdio_dev *dev;
|
2017-04-10 23:28:31 +08:00
|
|
|
int i, ret;
|
2012-11-13 00:03:47 +08:00
|
|
|
|
2017-06-15 22:43:23 +08:00
|
|
|
type = (enum orion_mdio_bus_type)of_device_get_match_data(&pdev->dev);
|
|
|
|
|
2013-03-22 11:39:25 +08:00
|
|
|
r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
|
|
|
if (!r) {
|
|
|
|
dev_err(&pdev->dev, "No SMI register address given\n");
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2014-05-23 07:07:02 +08:00
|
|
|
bus = devm_mdiobus_alloc_size(&pdev->dev,
|
|
|
|
sizeof(struct orion_mdio_dev));
|
|
|
|
if (!bus)
|
2012-11-13 00:03:47 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2017-06-15 22:43:23 +08:00
|
|
|
switch (type) {
|
|
|
|
case BUS_TYPE_SMI:
|
|
|
|
bus->read = orion_mdio_smi_read;
|
|
|
|
bus->write = orion_mdio_smi_write;
|
|
|
|
break;
|
|
|
|
case BUS_TYPE_XSMI:
|
|
|
|
bus->read = orion_mdio_xsmi_read;
|
|
|
|
bus->write = orion_mdio_xsmi_write;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2012-11-13 00:03:47 +08:00
|
|
|
bus->name = "orion_mdio_bus";
|
|
|
|
snprintf(bus->id, MII_BUS_ID_SIZE, "%s-mii",
|
|
|
|
dev_name(&pdev->dev));
|
|
|
|
bus->parent = &pdev->dev;
|
|
|
|
|
|
|
|
dev = bus->priv;
|
2013-03-22 11:39:26 +08:00
|
|
|
dev->regs = devm_ioremap(&pdev->dev, r->start, resource_size(r));
|
|
|
|
if (!dev->regs) {
|
2013-03-22 11:39:25 +08:00
|
|
|
dev_err(&pdev->dev, "Unable to remap SMI register\n");
|
2016-10-01 05:56:37 +08:00
|
|
|
return -ENODEV;
|
2013-03-22 11:39:27 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
init_waitqueue_head(&dev->smi_busy_wait);
|
|
|
|
|
2017-04-10 23:28:31 +08:00
|
|
|
for (i = 0; i < ARRAY_SIZE(dev->clk); i++) {
|
|
|
|
dev->clk[i] = of_clk_get(pdev->dev.of_node, i);
|
|
|
|
if (IS_ERR(dev->clk[i]))
|
|
|
|
break;
|
|
|
|
clk_prepare_enable(dev->clk[i]);
|
|
|
|
}
|
2013-04-07 09:09:47 +08:00
|
|
|
|
2013-03-22 11:39:27 +08:00
|
|
|
dev->err_interrupt = platform_get_irq(pdev, 0);
|
2017-04-10 23:28:20 +08:00
|
|
|
if (dev->err_interrupt > 0 &&
|
|
|
|
resource_size(r) < MVMDIO_ERR_INT_MASK + 4) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"disabling interrupt, resource size is too small\n");
|
|
|
|
dev->err_interrupt = 0;
|
|
|
|
}
|
2014-05-01 00:28:51 +08:00
|
|
|
if (dev->err_interrupt > 0) {
|
2013-03-22 11:39:27 +08:00
|
|
|
ret = devm_request_irq(&pdev->dev, dev->err_interrupt,
|
|
|
|
orion_mdio_err_irq,
|
|
|
|
IRQF_SHARED, pdev->name, dev);
|
|
|
|
if (ret)
|
|
|
|
goto out_mdio;
|
|
|
|
|
|
|
|
writel(MVMDIO_ERR_INT_SMI_DONE,
|
|
|
|
dev->regs + MVMDIO_ERR_INT_MASK);
|
2014-05-01 00:28:51 +08:00
|
|
|
|
|
|
|
} else if (dev->err_interrupt == -EPROBE_DEFER) {
|
2017-12-06 22:23:23 +08:00
|
|
|
ret = -EPROBE_DEFER;
|
|
|
|
goto out_mdio;
|
2012-11-13 00:03:47 +08:00
|
|
|
}
|
|
|
|
|
2018-05-16 07:56:19 +08:00
|
|
|
ret = of_mdiobus_register(bus, pdev->dev.of_node);
|
2012-11-13 00:03:47 +08:00
|
|
|
if (ret < 0) {
|
|
|
|
dev_err(&pdev->dev, "Cannot register MDIO bus (%d)\n", ret);
|
2013-03-22 11:39:27 +08:00
|
|
|
goto out_mdio;
|
2012-11-13 00:03:47 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
platform_set_drvdata(pdev, bus);
|
|
|
|
|
|
|
|
return 0;
|
2013-03-22 11:39:27 +08:00
|
|
|
|
|
|
|
out_mdio:
|
2017-04-10 23:28:04 +08:00
|
|
|
if (dev->err_interrupt > 0)
|
|
|
|
writel(0, dev->regs + MVMDIO_ERR_INT_MASK);
|
2017-04-10 23:28:31 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(dev->clk); i++) {
|
|
|
|
if (IS_ERR(dev->clk[i]))
|
|
|
|
break;
|
|
|
|
clk_disable_unprepare(dev->clk[i]);
|
|
|
|
clk_put(dev->clk[i]);
|
|
|
|
}
|
|
|
|
|
2013-03-22 11:39:27 +08:00
|
|
|
return ret;
|
2012-11-13 00:03:47 +08:00
|
|
|
}
|
|
|
|
|
2012-12-21 21:42:15 +08:00
|
|
|
static int orion_mdio_remove(struct platform_device *pdev)
|
2012-11-13 00:03:47 +08:00
|
|
|
{
|
|
|
|
struct mii_bus *bus = platform_get_drvdata(pdev);
|
2013-03-22 11:39:27 +08:00
|
|
|
struct orion_mdio_dev *dev = bus->priv;
|
2017-04-10 23:28:31 +08:00
|
|
|
int i;
|
2013-03-22 11:39:27 +08:00
|
|
|
|
2017-04-10 23:28:09 +08:00
|
|
|
if (dev->err_interrupt > 0)
|
|
|
|
writel(0, dev->regs + MVMDIO_ERR_INT_MASK);
|
2012-11-13 00:03:47 +08:00
|
|
|
mdiobus_unregister(bus);
|
2017-04-10 23:28:31 +08:00
|
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(dev->clk); i++) {
|
|
|
|
if (IS_ERR(dev->clk[i]))
|
|
|
|
break;
|
|
|
|
clk_disable_unprepare(dev->clk[i]);
|
|
|
|
clk_put(dev->clk[i]);
|
|
|
|
}
|
2013-04-07 09:09:47 +08:00
|
|
|
|
2012-11-13 00:03:47 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct of_device_id orion_mdio_match[] = {
|
2017-06-15 22:43:23 +08:00
|
|
|
{ .compatible = "marvell,orion-mdio", .data = (void *)BUS_TYPE_SMI },
|
|
|
|
{ .compatible = "marvell,xmdio", .data = (void *)BUS_TYPE_XSMI },
|
2012-11-13 00:03:47 +08:00
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, orion_mdio_match);
|
|
|
|
|
|
|
|
static struct platform_driver orion_mdio_driver = {
|
|
|
|
.probe = orion_mdio_probe,
|
2012-12-21 21:42:15 +08:00
|
|
|
.remove = orion_mdio_remove,
|
2012-11-13 00:03:47 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "orion-mdio",
|
|
|
|
.of_match_table = orion_mdio_match,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
module_platform_driver(orion_mdio_driver);
|
|
|
|
|
|
|
|
MODULE_DESCRIPTION("Marvell MDIO interface driver");
|
|
|
|
MODULE_AUTHOR("Thomas Petazzoni <thomas.petazzoni@free-electrons.com>");
|
|
|
|
MODULE_LICENSE("GPL");
|
2013-03-24 18:33:59 +08:00
|
|
|
MODULE_ALIAS("platform:orion-mdio");
|