From: Marco Felsch <m.felsch@pengutronix.de>
To: davem@davemloft.net, kuba@kernel.org, robh+dt@kernel.org,
andrew@lunn.ch, f.fainelli@gmail.com, hkallweit1@gmail.com,
linux@armlinux.org.uk, zhengdejin5@gmail.com,
richard.leitner@skidata.com
Cc: netdev@vger.kernel.org, kernel@pengutronix.de,
devicetree@vger.kernel.org
Subject: [PATCH v3 4/5] net: phy: smsc: LAN8710/20: add phy refclk in support
Date: Wed, 9 Sep 2020 15:45:00 +0200 [thread overview]
Message-ID: <20200909134501.32529-5-m.felsch@pengutronix.de> (raw)
In-Reply-To: <20200909134501.32529-1-m.felsch@pengutronix.de>
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 7f64e5b18ebb ("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>
---
v3:
- Add Florian's tag
- s/phy-state-machine/PHY library state machine/
- s/phy/PHY/
- reword last sentence of the commit message
v2:
- use non-devres clk_* functions and instead use the remove() function
- propagate errors upstream if the optional clk can't be retrieved.
- make use if dev_err_probe()
- adapt commit subject to cover that only the LAN8710/20 devices are
changed
drivers/net/phy/smsc.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c
index 5f4f198df0eb..bdf8593e385e 100644
--- a/drivers/net/phy/smsc.c
+++ b/drivers/net/phy/smsc.c
@@ -12,6 +12,7 @@
*
*/
+#include <linux/clk.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/mii.h>
@@ -33,6 +34,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)
@@ -194,11 +196,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)
@@ -211,6 +222,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;
}
@@ -310,6 +334,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,
--
2.20.1
next prev parent reply other threads:[~2020-09-09 16:44 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-09 13:44 [PATCH v3 0/5] SMSC: Cleanups and clock setup Marco Felsch
2020-09-09 13:44 ` [PATCH v3 1/5] net: phy: smsc: skip ENERGYON interrupt if disabled Marco Felsch
2020-09-09 13:44 ` [PATCH v3 2/5] net: phy: smsc: simplify config_init callback Marco Felsch
2020-09-09 13:44 ` [PATCH v3 3/5] dt-bindings: net: phy: smsc: document reference clock Marco Felsch
2020-09-09 13:45 ` Marco Felsch [this message]
2020-09-09 13:45 ` [PATCH v3 5/5] net: phy: smsc: LAN8710/20: remove PHY_RST_AFTER_CLK_EN flag Marco Felsch
2020-09-09 15:43 ` Florian Fainelli
2020-09-09 21:15 ` [PATCH v3 0/5] SMSC: Cleanups and clock setup David Miller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20200909134501.32529-5-m.felsch@pengutronix.de \
--to=m.felsch@pengutronix.de \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=f.fainelli@gmail.com \
--cc=hkallweit1@gmail.com \
--cc=kernel@pengutronix.de \
--cc=kuba@kernel.org \
--cc=linux@armlinux.org.uk \
--cc=netdev@vger.kernel.org \
--cc=richard.leitner@skidata.com \
--cc=robh+dt@kernel.org \
--cc=zhengdejin5@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).