Skip to content

Commit

Permalink
net: phy: smsc: LAN8710/20: add phy refclk in support
Browse files Browse the repository at this point in the history
Add support to specify the clock provider for the PHY refclk and don't
rely on 'magic' host clock setup. [1] tried to address this by
introducing a flag and fixing the corresponding host. But this commit
breaks the IRQ support since the irq setup during .config_intr() is
thrown away because the reset comes from the side without respecting the
current PHY state within the PHY library state machine. Furthermore the
commit fixed the problem only for FEC based hosts other hosts acting
like the FEC are not covered.

This commit goes the other way around to address the bug fixed by [1].
Instead of resetting the device from the side every time the refclk gets
(re-)enabled it requests and enables the clock till the device gets
removed. Now the PHY library is the only place where the PHY gets reset
to respect the PHY library state machine.

[1] commit 7f64e5b ("net: phy: smsc: LAN8710/20: add
    PHY_RST_AFTER_CLK_EN flag")

Signed-off-by: Marco Felsch <m.felsch@pengutronix.de>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Marco Felsch authored and David S. Miller committed Sep 9, 2020
1 parent 84475a9 commit bedd8d7
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions drivers/net/phy/smsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
*
*/

#include <linux/clk.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mii.h>
Expand Down Expand Up @@ -44,6 +45,7 @@ static struct smsc_hw_stat smsc_hw_stats[] = {

struct smsc_phy_priv {
bool energy_enable;
struct clk *refclk;
};

static int smsc_phy_config_intr(struct phy_device *phydev)
Expand Down Expand Up @@ -253,11 +255,20 @@ static void smsc_get_stats(struct phy_device *phydev,
data[i] = smsc_get_stat(phydev, i);
}

static void smsc_phy_remove(struct phy_device *phydev)
{
struct smsc_phy_priv *priv = phydev->priv;

clk_disable_unprepare(priv->refclk);
clk_put(priv->refclk);
}

static int smsc_phy_probe(struct phy_device *phydev)
{
struct device *dev = &phydev->mdio.dev;
struct device_node *of_node = dev->of_node;
struct smsc_phy_priv *priv;
int ret;

priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
if (!priv)
Expand All @@ -270,6 +281,19 @@ static int smsc_phy_probe(struct phy_device *phydev)

phydev->priv = priv;

/* Make clk optional to keep DTB backward compatibility. */
priv->refclk = clk_get_optional(dev, NULL);
if (IS_ERR(priv->refclk))
dev_err_probe(dev, PTR_ERR(priv->refclk), "Failed to request clock\n");

ret = clk_prepare_enable(priv->refclk);
if (ret)
return ret;

ret = clk_set_rate(priv->refclk, 50 * 1000 * 1000);
if (ret)
return ret;

return 0;
}

Expand Down Expand Up @@ -376,6 +400,7 @@ static struct phy_driver smsc_phy_driver[] = {
.flags = PHY_RST_AFTER_CLK_EN,

.probe = smsc_phy_probe,
.remove = smsc_phy_remove,

/* basic functions */
.read_status = lan87xx_read_status,
Expand Down

0 comments on commit bedd8d7

Please sign in to comment.