2010-09-15 14:11:21 +00:00
|
|
|
/*
|
|
|
|
* DaVinci MDIO Module driver
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Texas Instruments.
|
|
|
|
*
|
|
|
|
* Shamelessly ripped out of davinci_emac.c, original copyrights follow:
|
|
|
|
*
|
|
|
|
* Copyright (C) 2009 Texas Instruments.
|
|
|
|
*
|
|
|
|
* ---------------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that 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., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
* ---------------------------------------------------------------------------
|
|
|
|
*/
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/sched.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/phy.h>
|
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/err.h>
|
|
|
|
#include <linux/io.h>
|
2012-07-17 08:09:49 +00:00
|
|
|
#include <linux/pm_runtime.h>
|
2010-09-15 14:11:21 +00:00
|
|
|
#include <linux/davinci_emac.h>
|
2012-08-06 05:05:57 +00:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_device.h>
|
2014-07-16 12:13:03 +00:00
|
|
|
#include <linux/of_mdio.h>
|
2013-06-06 18:15:15 +00:00
|
|
|
#include <linux/pinctrl/consumer.h>
|
2010-09-15 14:11:21 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This timeout definition is a worst-case ultra defensive measure against
|
|
|
|
* unexpected controller lock ups. Ideally, we should never ever hit this
|
|
|
|
* scenario in practice.
|
|
|
|
*/
|
|
|
|
#define MDIO_TIMEOUT 100 /* msecs */
|
|
|
|
|
|
|
|
#define PHY_REG_MASK 0x1f
|
|
|
|
#define PHY_ID_MASK 0x1f
|
|
|
|
|
|
|
|
#define DEF_OUT_FREQ 2200000 /* 2.2 MHz */
|
|
|
|
|
2016-06-24 18:23:54 +00:00
|
|
|
struct davinci_mdio_of_param {
|
|
|
|
int autosuspend_delay_ms;
|
|
|
|
};
|
|
|
|
|
2010-09-15 14:11:21 +00:00
|
|
|
struct davinci_mdio_regs {
|
|
|
|
u32 version;
|
|
|
|
u32 control;
|
|
|
|
#define CONTROL_IDLE BIT(31)
|
|
|
|
#define CONTROL_ENABLE BIT(30)
|
2012-02-22 22:07:58 +00:00
|
|
|
#define CONTROL_MAX_DIV (0xffff)
|
2010-09-15 14:11:21 +00:00
|
|
|
|
|
|
|
u32 alive;
|
|
|
|
u32 link;
|
|
|
|
u32 linkintraw;
|
|
|
|
u32 linkintmasked;
|
|
|
|
u32 __reserved_0[2];
|
|
|
|
u32 userintraw;
|
|
|
|
u32 userintmasked;
|
|
|
|
u32 userintmaskset;
|
|
|
|
u32 userintmaskclr;
|
|
|
|
u32 __reserved_1[20];
|
|
|
|
|
|
|
|
struct {
|
|
|
|
u32 access;
|
|
|
|
#define USERACCESS_GO BIT(31)
|
|
|
|
#define USERACCESS_WRITE BIT(30)
|
|
|
|
#define USERACCESS_ACK BIT(29)
|
|
|
|
#define USERACCESS_READ (0)
|
|
|
|
#define USERACCESS_DATA (0xffff)
|
|
|
|
|
|
|
|
u32 physel;
|
|
|
|
} user[0];
|
|
|
|
};
|
|
|
|
|
2014-01-16 06:05:41 +00:00
|
|
|
static const struct mdio_platform_data default_pdata = {
|
2010-09-15 14:11:21 +00:00
|
|
|
.bus_freq = DEF_OUT_FREQ,
|
|
|
|
};
|
|
|
|
|
|
|
|
struct davinci_mdio_data {
|
|
|
|
struct mdio_platform_data pdata;
|
|
|
|
struct davinci_mdio_regs __iomem *regs;
|
|
|
|
struct clk *clk;
|
|
|
|
struct device *dev;
|
|
|
|
struct mii_bus *bus;
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
bool active_in_suspend;
|
2010-09-15 14:11:21 +00:00
|
|
|
unsigned long access_time; /* jiffies */
|
2014-07-16 12:13:03 +00:00
|
|
|
/* Indicates that driver shouldn't modify phy_mask in case
|
|
|
|
* if MDIO bus is registered from DT.
|
|
|
|
*/
|
|
|
|
bool skip_scan;
|
2016-06-24 18:23:49 +00:00
|
|
|
u32 clk_div;
|
2010-09-15 14:11:21 +00:00
|
|
|
};
|
|
|
|
|
2016-06-24 18:23:49 +00:00
|
|
|
static void davinci_mdio_init_clk(struct davinci_mdio_data *data)
|
2010-09-15 14:11:21 +00:00
|
|
|
{
|
|
|
|
u32 mdio_in, div, mdio_out_khz, access_time;
|
|
|
|
|
|
|
|
mdio_in = clk_get_rate(data->clk);
|
|
|
|
div = (mdio_in / data->pdata.bus_freq) - 1;
|
|
|
|
if (div > CONTROL_MAX_DIV)
|
|
|
|
div = CONTROL_MAX_DIV;
|
|
|
|
|
2016-06-24 18:23:49 +00:00
|
|
|
data->clk_div = div;
|
2010-09-15 14:11:21 +00:00
|
|
|
/*
|
|
|
|
* One mdio transaction consists of:
|
|
|
|
* 32 bits of preamble
|
|
|
|
* 32 bits of transferred data
|
|
|
|
* 24 bits of bus yield (not needed unless shared?)
|
|
|
|
*/
|
|
|
|
mdio_out_khz = mdio_in / (1000 * (div + 1));
|
|
|
|
access_time = (88 * 1000) / mdio_out_khz;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In the worst case, we could be kicking off a user-access immediately
|
|
|
|
* after the mdio bus scan state-machine triggered its own read. If
|
|
|
|
* so, our request could get deferred by one access cycle. We
|
|
|
|
* defensively allow for 4 access cycles.
|
|
|
|
*/
|
|
|
|
data->access_time = usecs_to_jiffies(access_time * 4);
|
|
|
|
if (!data->access_time)
|
|
|
|
data->access_time = 1;
|
|
|
|
}
|
|
|
|
|
2016-06-24 18:23:49 +00:00
|
|
|
static void davinci_mdio_enable(struct davinci_mdio_data *data)
|
|
|
|
{
|
|
|
|
/* set enable and clock divider */
|
|
|
|
__raw_writel(data->clk_div | CONTROL_ENABLE, &data->regs->control);
|
|
|
|
}
|
|
|
|
|
2010-09-15 14:11:21 +00:00
|
|
|
static int davinci_mdio_reset(struct mii_bus *bus)
|
|
|
|
{
|
|
|
|
struct davinci_mdio_data *data = bus->priv;
|
|
|
|
u32 phy_mask, ver;
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
int ret;
|
2010-09-15 14:11:21 +00:00
|
|
|
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
ret = pm_runtime_get_sync(data->dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
pm_runtime_put_noidle(data->dev);
|
|
|
|
return ret;
|
|
|
|
}
|
2010-09-15 14:11:21 +00:00
|
|
|
|
|
|
|
/* wait for scan logic to settle */
|
|
|
|
msleep(PHY_MAX_ADDR * data->access_time);
|
|
|
|
|
|
|
|
/* dump hardware version info */
|
|
|
|
ver = __raw_readl(&data->regs->version);
|
|
|
|
dev_info(data->dev, "davinci mdio revision %d.%d\n",
|
|
|
|
(ver >> 8) & 0xff, ver & 0xff);
|
|
|
|
|
2014-07-16 12:13:03 +00:00
|
|
|
if (data->skip_scan)
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
goto done;
|
2014-07-16 12:13:03 +00:00
|
|
|
|
2010-09-15 14:11:21 +00:00
|
|
|
/* get phy mask from the alive register */
|
|
|
|
phy_mask = __raw_readl(&data->regs->alive);
|
|
|
|
if (phy_mask) {
|
|
|
|
/* restrict mdio bus to live phys only */
|
|
|
|
dev_info(data->dev, "detected phy mask %x\n", ~phy_mask);
|
|
|
|
phy_mask = ~phy_mask;
|
|
|
|
} else {
|
|
|
|
/* desperately scan all phys */
|
|
|
|
dev_warn(data->dev, "no live phy, scanning all\n");
|
|
|
|
phy_mask = 0;
|
|
|
|
}
|
|
|
|
data->bus->phy_mask = phy_mask;
|
|
|
|
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
done:
|
|
|
|
pm_runtime_mark_last_busy(data->dev);
|
|
|
|
pm_runtime_put_autosuspend(data->dev);
|
|
|
|
|
2010-09-15 14:11:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait until hardware is ready for another user access */
|
|
|
|
static inline int wait_for_user_access(struct davinci_mdio_data *data)
|
|
|
|
{
|
|
|
|
struct davinci_mdio_regs __iomem *regs = data->regs;
|
|
|
|
unsigned long timeout = jiffies + msecs_to_jiffies(MDIO_TIMEOUT);
|
|
|
|
u32 reg;
|
|
|
|
|
|
|
|
while (time_after(timeout, jiffies)) {
|
|
|
|
reg = __raw_readl(®s->user[0].access);
|
|
|
|
if ((reg & USERACCESS_GO) == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
reg = __raw_readl(®s->control);
|
|
|
|
if ((reg & CONTROL_IDLE) == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An emac soft_reset may have clobbered the mdio controller's
|
|
|
|
* state machine. We need to reset and retry the current
|
|
|
|
* operation
|
|
|
|
*/
|
|
|
|
dev_warn(data->dev, "resetting idled controller\n");
|
2016-06-24 18:23:49 +00:00
|
|
|
davinci_mdio_enable(data);
|
2010-09-15 14:11:21 +00:00
|
|
|
return -EAGAIN;
|
|
|
|
}
|
2012-04-16 04:35:25 +00:00
|
|
|
|
|
|
|
reg = __raw_readl(®s->user[0].access);
|
|
|
|
if ((reg & USERACCESS_GO) == 0)
|
|
|
|
return 0;
|
|
|
|
|
2010-09-15 14:11:21 +00:00
|
|
|
dev_err(data->dev, "timed out waiting for user access\n");
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* wait until hardware state machine is idle */
|
|
|
|
static inline int wait_for_idle(struct davinci_mdio_data *data)
|
|
|
|
{
|
|
|
|
struct davinci_mdio_regs __iomem *regs = data->regs;
|
|
|
|
unsigned long timeout = jiffies + msecs_to_jiffies(MDIO_TIMEOUT);
|
|
|
|
|
|
|
|
while (time_after(timeout, jiffies)) {
|
|
|
|
if (__raw_readl(®s->control) & CONTROL_IDLE)
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
dev_err(data->dev, "timed out waiting for idle\n");
|
|
|
|
return -ETIMEDOUT;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int davinci_mdio_read(struct mii_bus *bus, int phy_id, int phy_reg)
|
|
|
|
{
|
|
|
|
struct davinci_mdio_data *data = bus->priv;
|
|
|
|
u32 reg;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (phy_reg & ~PHY_REG_MASK || phy_id & ~PHY_ID_MASK)
|
|
|
|
return -EINVAL;
|
|
|
|
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
ret = pm_runtime_get_sync(data->dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
pm_runtime_put_noidle(data->dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-15 14:11:21 +00:00
|
|
|
reg = (USERACCESS_GO | USERACCESS_READ | (phy_reg << 21) |
|
|
|
|
(phy_id << 16));
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
ret = wait_for_user_access(data);
|
|
|
|
if (ret == -EAGAIN)
|
|
|
|
continue;
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
__raw_writel(reg, &data->regs->user[0].access);
|
|
|
|
|
|
|
|
ret = wait_for_user_access(data);
|
|
|
|
if (ret == -EAGAIN)
|
|
|
|
continue;
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
reg = __raw_readl(&data->regs->user[0].access);
|
|
|
|
ret = (reg & USERACCESS_ACK) ? (reg & USERACCESS_DATA) : -EIO;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
pm_runtime_mark_last_busy(data->dev);
|
|
|
|
pm_runtime_put_autosuspend(data->dev);
|
2010-09-15 14:11:21 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int davinci_mdio_write(struct mii_bus *bus, int phy_id,
|
|
|
|
int phy_reg, u16 phy_data)
|
|
|
|
{
|
|
|
|
struct davinci_mdio_data *data = bus->priv;
|
|
|
|
u32 reg;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
if (phy_reg & ~PHY_REG_MASK || phy_id & ~PHY_ID_MASK)
|
|
|
|
return -EINVAL;
|
|
|
|
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
ret = pm_runtime_get_sync(data->dev);
|
|
|
|
if (ret < 0) {
|
|
|
|
pm_runtime_put_noidle(data->dev);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2010-09-15 14:11:21 +00:00
|
|
|
reg = (USERACCESS_GO | USERACCESS_WRITE | (phy_reg << 21) |
|
|
|
|
(phy_id << 16) | (phy_data & USERACCESS_DATA));
|
|
|
|
|
|
|
|
while (1) {
|
|
|
|
ret = wait_for_user_access(data);
|
|
|
|
if (ret == -EAGAIN)
|
|
|
|
continue;
|
|
|
|
if (ret < 0)
|
|
|
|
break;
|
|
|
|
|
|
|
|
__raw_writel(reg, &data->regs->user[0].access);
|
|
|
|
|
|
|
|
ret = wait_for_user_access(data);
|
|
|
|
if (ret == -EAGAIN)
|
|
|
|
continue;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
pm_runtime_mark_last_busy(data->dev);
|
|
|
|
pm_runtime_put_autosuspend(data->dev);
|
|
|
|
|
|
|
|
return ret;
|
2010-09-15 14:11:21 +00:00
|
|
|
}
|
|
|
|
|
2013-06-25 15:54:53 +00:00
|
|
|
#if IS_ENABLED(CONFIG_OF)
|
2012-08-06 05:05:57 +00:00
|
|
|
static int davinci_mdio_probe_dt(struct mdio_platform_data *data,
|
|
|
|
struct platform_device *pdev)
|
|
|
|
{
|
|
|
|
struct device_node *node = pdev->dev.of_node;
|
|
|
|
u32 prop;
|
|
|
|
|
|
|
|
if (!node)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (of_property_read_u32(node, "bus_freq", &prop)) {
|
2014-05-12 04:51:20 +00:00
|
|
|
dev_err(&pdev->dev, "Missing bus_freq property in the DT.\n");
|
2012-08-06 05:05:57 +00:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
data->bus_freq = prop;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2013-06-25 15:54:53 +00:00
|
|
|
#endif
|
2012-08-06 05:05:57 +00:00
|
|
|
|
2016-06-24 18:23:54 +00:00
|
|
|
#if IS_ENABLED(CONFIG_OF)
|
|
|
|
static const struct davinci_mdio_of_param of_cpsw_mdio_data = {
|
|
|
|
.autosuspend_delay_ms = 100,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct of_device_id davinci_mdio_of_mtable[] = {
|
|
|
|
{ .compatible = "ti,davinci_mdio", },
|
|
|
|
{ .compatible = "ti,cpsw-mdio", .data = &of_cpsw_mdio_data},
|
|
|
|
{ /* sentinel */ },
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, davinci_mdio_of_mtable);
|
|
|
|
#endif
|
|
|
|
|
2012-12-03 14:24:03 +00:00
|
|
|
static int davinci_mdio_probe(struct platform_device *pdev)
|
2010-09-15 14:11:21 +00:00
|
|
|
{
|
2013-08-30 05:06:02 +00:00
|
|
|
struct mdio_platform_data *pdata = dev_get_platdata(&pdev->dev);
|
2010-09-15 14:11:21 +00:00
|
|
|
struct device *dev = &pdev->dev;
|
|
|
|
struct davinci_mdio_data *data;
|
|
|
|
struct resource *res;
|
|
|
|
struct phy_device *phy;
|
|
|
|
int ret, addr;
|
2016-06-24 18:23:54 +00:00
|
|
|
int autosuspend_delay_ms = -1;
|
2010-09-15 14:11:21 +00:00
|
|
|
|
2014-04-30 12:23:34 +00:00
|
|
|
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
|
2013-02-03 17:43:58 +00:00
|
|
|
if (!data)
|
2010-09-15 14:11:21 +00:00
|
|
|
return -ENOMEM;
|
|
|
|
|
2014-04-30 12:23:34 +00:00
|
|
|
data->bus = devm_mdiobus_alloc(dev);
|
2010-09-15 14:11:21 +00:00
|
|
|
if (!data->bus) {
|
|
|
|
dev_err(dev, "failed to alloc mii bus\n");
|
2014-04-30 12:23:34 +00:00
|
|
|
return -ENOMEM;
|
2010-09-15 14:11:21 +00:00
|
|
|
}
|
|
|
|
|
2012-08-06 05:05:57 +00:00
|
|
|
if (dev->of_node) {
|
2016-06-24 18:23:54 +00:00
|
|
|
const struct of_device_id *of_id;
|
|
|
|
|
|
|
|
ret = davinci_mdio_probe_dt(&data->pdata, pdev);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
2012-08-06 05:05:57 +00:00
|
|
|
snprintf(data->bus->id, MII_BUS_ID_SIZE, "%s", pdev->name);
|
2016-06-24 18:23:54 +00:00
|
|
|
|
|
|
|
of_id = of_match_device(davinci_mdio_of_mtable, &pdev->dev);
|
|
|
|
if (of_id) {
|
|
|
|
const struct davinci_mdio_of_param *of_mdio_data;
|
|
|
|
|
|
|
|
of_mdio_data = of_id->data;
|
|
|
|
if (of_mdio_data)
|
|
|
|
autosuspend_delay_ms =
|
|
|
|
of_mdio_data->autosuspend_delay_ms;
|
|
|
|
}
|
2012-08-06 05:05:57 +00:00
|
|
|
} else {
|
|
|
|
data->pdata = pdata ? (*pdata) : default_pdata;
|
|
|
|
snprintf(data->bus->id, MII_BUS_ID_SIZE, "%s-%x",
|
|
|
|
pdev->name, pdev->id);
|
|
|
|
}
|
|
|
|
|
2010-09-15 14:11:21 +00:00
|
|
|
data->bus->name = dev_name(dev);
|
|
|
|
data->bus->read = davinci_mdio_read,
|
|
|
|
data->bus->write = davinci_mdio_write,
|
|
|
|
data->bus->reset = davinci_mdio_reset,
|
|
|
|
data->bus->parent = dev;
|
|
|
|
data->bus->priv = data;
|
|
|
|
|
2014-04-30 12:23:34 +00:00
|
|
|
data->clk = devm_clk_get(dev, "fck");
|
2010-09-15 14:11:21 +00:00
|
|
|
if (IS_ERR(data->clk)) {
|
|
|
|
dev_err(dev, "failed to get device clock\n");
|
2016-06-24 18:23:46 +00:00
|
|
|
return PTR_ERR(data->clk);
|
2010-09-15 14:11:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
dev_set_drvdata(dev, data);
|
|
|
|
data->dev = dev;
|
|
|
|
|
|
|
|
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
|
2014-04-30 12:23:36 +00:00
|
|
|
data->regs = devm_ioremap_resource(dev, res);
|
2016-06-24 18:23:46 +00:00
|
|
|
if (IS_ERR(data->regs))
|
|
|
|
return PTR_ERR(data->regs);
|
|
|
|
|
2016-06-24 18:23:49 +00:00
|
|
|
davinci_mdio_init_clk(data);
|
|
|
|
|
2016-06-24 18:23:54 +00:00
|
|
|
pm_runtime_set_autosuspend_delay(&pdev->dev, autosuspend_delay_ms);
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
pm_runtime_use_autosuspend(&pdev->dev);
|
2016-06-24 18:23:46 +00:00
|
|
|
pm_runtime_enable(&pdev->dev);
|
2010-09-15 14:11:21 +00:00
|
|
|
|
2014-07-16 12:13:03 +00:00
|
|
|
/* register the mii bus
|
|
|
|
* Create PHYs from DT only in case if PHY child nodes are explicitly
|
|
|
|
* defined to support backward compatibility with DTs which assume that
|
|
|
|
* Davinci MDIO will always scan the bus for PHYs detection.
|
|
|
|
*/
|
|
|
|
if (dev->of_node && of_get_child_count(dev->of_node)) {
|
|
|
|
data->skip_scan = true;
|
|
|
|
ret = of_mdiobus_register(data->bus, dev->of_node);
|
|
|
|
} else {
|
|
|
|
ret = mdiobus_register(data->bus);
|
|
|
|
}
|
2010-09-15 14:11:21 +00:00
|
|
|
if (ret)
|
|
|
|
goto bail_out;
|
|
|
|
|
|
|
|
/* scan and dump the bus */
|
|
|
|
for (addr = 0; addr < PHY_MAX_ADDR; addr++) {
|
2016-01-06 19:11:18 +00:00
|
|
|
phy = mdiobus_get_phy(data->bus, addr);
|
2010-09-15 14:11:21 +00:00
|
|
|
if (phy) {
|
|
|
|
dev_info(dev, "phy[%d]: device %s, driver %s\n",
|
2016-01-06 19:11:16 +00:00
|
|
|
phy->mdio.addr, phydev_name(phy),
|
2010-09-15 14:11:21 +00:00
|
|
|
phy->drv ? phy->drv->name : "unknown");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
bail_out:
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
pm_runtime_dont_use_autosuspend(&pdev->dev);
|
2012-07-17 08:09:49 +00:00
|
|
|
pm_runtime_disable(&pdev->dev);
|
2010-09-15 14:11:21 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2012-12-03 14:24:03 +00:00
|
|
|
static int davinci_mdio_remove(struct platform_device *pdev)
|
2010-09-15 14:11:21 +00:00
|
|
|
{
|
2013-08-19 12:00:37 +00:00
|
|
|
struct davinci_mdio_data *data = platform_get_drvdata(pdev);
|
2010-09-15 14:11:21 +00:00
|
|
|
|
2014-04-30 12:23:34 +00:00
|
|
|
if (data->bus)
|
2012-08-30 06:37:32 +00:00
|
|
|
mdiobus_unregister(data->bus);
|
2010-09-15 14:11:21 +00:00
|
|
|
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
pm_runtime_dont_use_autosuspend(&pdev->dev);
|
2012-07-17 08:09:49 +00:00
|
|
|
pm_runtime_disable(&pdev->dev);
|
2010-09-15 14:11:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-06-24 18:23:50 +00:00
|
|
|
#ifdef CONFIG_PM
|
|
|
|
static int davinci_mdio_runtime_suspend(struct device *dev)
|
2010-09-15 14:11:21 +00:00
|
|
|
{
|
|
|
|
struct davinci_mdio_data *data = dev_get_drvdata(dev);
|
|
|
|
u32 ctrl;
|
|
|
|
|
|
|
|
/* shutdown the scan state machine */
|
|
|
|
ctrl = __raw_readl(&data->regs->control);
|
|
|
|
ctrl &= ~CONTROL_ENABLE;
|
|
|
|
__raw_writel(ctrl, &data->regs->control);
|
|
|
|
wait_for_idle(data);
|
|
|
|
|
2016-06-24 18:23:50 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int davinci_mdio_runtime_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct davinci_mdio_data *data = dev_get_drvdata(dev);
|
|
|
|
|
|
|
|
davinci_mdio_enable(data);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef CONFIG_PM_SLEEP
|
|
|
|
static int davinci_mdio_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct davinci_mdio_data *data = dev_get_drvdata(dev);
|
|
|
|
int ret = 0;
|
|
|
|
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
data->active_in_suspend = !pm_runtime_status_suspended(dev);
|
|
|
|
if (data->active_in_suspend)
|
|
|
|
ret = pm_runtime_force_suspend(dev);
|
2016-06-24 18:23:50 +00:00
|
|
|
if (ret < 0)
|
|
|
|
return ret;
|
|
|
|
|
2013-06-06 18:15:15 +00:00
|
|
|
/* Select sleep pin state */
|
|
|
|
pinctrl_pm_select_sleep_state(dev);
|
|
|
|
|
2010-09-15 14:11:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int davinci_mdio_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct davinci_mdio_data *data = dev_get_drvdata(dev);
|
|
|
|
|
2013-06-06 18:15:15 +00:00
|
|
|
/* Select default pin state */
|
|
|
|
pinctrl_pm_select_default_state(dev);
|
|
|
|
|
drivers: net: davinci_mdio: implement pm runtime auto mode
Davinci MDIO is always used as slave device which services
read/write requests from MDIO/PHY core. It doesn't use IRQ also.
As result, It's possible to relax PM runtime constraints for Davinci
MDIO and enable it on demand, instead of powering it during probe
and powering off during removal.
Hence, implement PM runtime autosuspend for Davinci MDIO, but keep it
disabled by default, because Davinci MDIO is integrated in big set of
TI devices and not all of them expected to work corectly with RPM
autosuspend enabled:
- expected to work on SoCs where MDIO is part of TI CPSW
(cpsw.c DRA7/am57x, am437x, am335x, dm814x)
- not verified on Keystone 2 and other SoCs where MDIO is used with TI EMAC IP
(davinci_emac.c: dm6467-emac, am3517-emac, dm816-emac).
Davinci MDIO RPM autosuspend can be enabled through sysfs:
echo 100 > /sys/devices/../48484000.ethernet/48485000.mdio/power/autosuspend_delay_ms
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
2016-06-24 18:23:51 +00:00
|
|
|
if (data->active_in_suspend)
|
|
|
|
pm_runtime_force_resume(dev);
|
2010-09-15 14:11:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2015-02-27 11:19:44 +00:00
|
|
|
#endif
|
2010-09-15 14:11:21 +00:00
|
|
|
|
|
|
|
static const struct dev_pm_ops davinci_mdio_pm_ops = {
|
2016-06-24 18:23:50 +00:00
|
|
|
SET_RUNTIME_PM_OPS(davinci_mdio_runtime_suspend,
|
|
|
|
davinci_mdio_runtime_resume, NULL)
|
2015-02-27 11:19:44 +00:00
|
|
|
SET_LATE_SYSTEM_SLEEP_PM_OPS(davinci_mdio_suspend, davinci_mdio_resume)
|
2010-09-15 14:11:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static struct platform_driver davinci_mdio_driver = {
|
|
|
|
.driver = {
|
|
|
|
.name = "davinci_mdio",
|
|
|
|
.pm = &davinci_mdio_pm_ops,
|
2012-08-06 05:05:57 +00:00
|
|
|
.of_match_table = of_match_ptr(davinci_mdio_of_mtable),
|
2010-09-15 14:11:21 +00:00
|
|
|
},
|
|
|
|
.probe = davinci_mdio_probe,
|
2012-12-03 14:24:03 +00:00
|
|
|
.remove = davinci_mdio_remove,
|
2010-09-15 14:11:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int __init davinci_mdio_init(void)
|
|
|
|
{
|
|
|
|
return platform_driver_register(&davinci_mdio_driver);
|
|
|
|
}
|
|
|
|
device_initcall(davinci_mdio_init);
|
|
|
|
|
|
|
|
static void __exit davinci_mdio_exit(void)
|
|
|
|
{
|
|
|
|
platform_driver_unregister(&davinci_mdio_driver);
|
|
|
|
}
|
|
|
|
module_exit(davinci_mdio_exit);
|
|
|
|
|
|
|
|
MODULE_LICENSE("GPL");
|
|
|
|
MODULE_DESCRIPTION("DaVinci MDIO driver");
|