SMSC: Cleanups and clock setup
Subsystems (4)
v2 cover SMSC: Cleanups and clock setup
Hi,
this small series cleans the smsc-phy code a bit and adds the support to specify the phy clock source. Adding the phy clock source support is also the main purpose of this series.
Each file has its own changelog.
Regards,
Marco
Marco Felsch (5):
net: phy: smsc: skip ENERGYON interrupt if disabled
net: phy: smsc: simplify config_init callback
dt-bindings: net: phy: smsc: document reference clock
net: phy: smsc: LAN8710/20: add phy refclk in support
net: phy: smsc: LAN8710/20: remove PHY_RST_AFTER_CLK_EN flag
.../devicetree/bindings/net/smsc-lan87xx.txt | 4 ++ drivers/net/phy/smsc.c | 59 +++++++++++++++---- 2 files changed, 50 insertions(+), 13 deletions(-)
Signature · 1 line
2.20.1
PATCH v2 1/5 net: phy: smsc: skip ENERGYON interrupt if disabled
Don't enable the interrupt if the platform disable the energy detection by "smsc,disable-energy-detect".
---
v2:
- Add Andrew's tag
drivers/net/phy/smsc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
drivers/net/phy/smsc.c +11 -4
@@ -37,10 +37,17 @@ struct smsc_phy_priv {static int smsc_phy_config_intr (struct phy_device *phydev) { -int rc =phy_write (phydev,MII_LAN83C185_IM , - ((PHY_INTERRUPT_ENABLED == phydev->interrupts) - ?MII_LAN83C185_ISF_INT_PHYLIB_EVENTS - :0 )); +struct smsc_phy_priv *priv = phydev->priv; +u16 intmask =0 ; +int rc; + +if (phydev->interrupts) { + intmask =MII_LAN83C185_ISF_INT4 |MII_LAN83C185_ISF_INT6 ; +if (priv->energy_enable) + intmask |=MII_LAN83C185_ISF_INT7 ; + } + + rc =phy_write (phydev,MII_LAN83C185_IM , intmask);return rc <0 ? rc :0 ; }
Signature · 1 line
2.20.1
Re: [PATCH v2 1/5] net: phy: smsc: skip ENERGYON interrupt if disabled
Quoted 19 lines · Marco Felsch
Don't enable the interrupt if the platform disable the energy detection by "smsc,disable-energy-detect".
Signed-off-by Marco Felsch <[email protected]>Reviewed-by Andrew Lunn <[email protected]>---
v2:
- Add Andrew's tagdrivers/net/phy/smsc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)drivers/net/phy/smsc.c +0
-0@@ -37,10 +37,17 @@ struct smsc_phy_priv {static int smsc_phy_config_intr (struct phy_device *phydev)
drivers/net/phy/smsc.c struct smsc_phy_priv { · line 44
Quoted 10 lines
drivers/net/phy/smsc.c +5
-4{ -int rc =phy_write (phydev,MII_LAN83C185_IM , - ((PHY_INTERRUPT_ENABLED == phydev->interrupts) - ?MII_LAN83C185_ISF_INT_PHYLIB_EVENTS - :0 )); +struct smsc_phy_priv *priv = phydev->priv; +u16 intmask =0 ; +int rc; + +if (phydev->interrupts) {
Not that it changes the code functionally, but it would be nice to preserve the phydev->interrupts == PHY_INTERRUPT_ENABLED.
drivers/net/phy/smsc.c struct smsc_phy_priv { · line 48
Quoted 4 lines
drivers/net/phy/smsc.c +4
-0+ intmask =MII_LAN83C185_ISF_INT4 |MII_LAN83C185_ISF_INT6 ; +if (priv->energy_enable) + intmask |=MII_LAN83C185_ISF_INT7 ; + }
Signature · 1 line
Florian
Re: [PATCH v2 1/5] net: phy: smsc: skip ENERGYON interrupt if disabled
Quoted 26 lines · Florian Fainelli
Quoted 23 lines · Marco Felsch
Don't enable the interrupt if the platform disable the energy detection by "smsc,disable-energy-detect".
Signed-off-by Marco Felsch <[email protected]>Reviewed-by Andrew Lunn <[email protected]>---
v2:
- Add Andrew's tagdrivers/net/phy/smsc.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)drivers/net/phy/smsc.c +0
-4@@ -37,10 +37,17 @@ struct smsc_phy_priv {static int smsc_phy_config_intr (struct phy_device *phydev) { -int rc =phy_write (phydev,MII_LAN83C185_IM , - ((PHY_INTERRUPT_ENABLED == phydev->interrupts) - ?MII_LAN83C185_ISF_INT_PHYLIB_EVENTS - :0 ));
Quoted 8 lines
drivers/net/phy/smsc.c struct smsc_phy_priv { · line 44
Quoted 5 lines
drivers/net/phy/smsc.c +5
-0+struct smsc_phy_priv *priv = phydev->priv; +u16 intmask =0 ; +int rc; + +if (phydev->interrupts) {Not that it changes the code functionally, but it would be nice to preserve the
phydev->interrupts==PHY_INTERRUPT_ENABLED.
Okay, I will apply this and add your reviewed-by tag.
Thanks,
Marco
Quoted 11 lines
drivers/net/phy/smsc.c struct smsc_phy_priv { · line 48
Quoted 5 lines
drivers/net/phy/smsc.c +4
-0+ intmask =MII_LAN83C185_ISF_INT4 |MII_LAN83C185_ISF_INT6 ; +if (priv->energy_enable) + intmask |=MII_LAN83C185_ISF_INT7 ; + }Reviewed-by Florian Fainelli <[email protected]>Signature · 1 line
Florian
Signature · 4 lines
Pengutronix e.K. | | Steuerwalder Str. 21 | http://www.pengutronix.de/ | 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 | Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
PATCH v2 2/5 net: phy: smsc: simplify config_init callback
In reply to Marco FelschExit the driver specific config_init hook early if energy detection is disabled. We can do this because we don't need to clear the interrupt status here. Clearing the status should be removed anyway since this is handled by the phy_enable_interrupts().
---
v2:
- no change
drivers/net/phy/smsc.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-)
drivers/net/phy/smsc.c +10 -8
@@ -62,19 +62,21 @@ static int smsc_phy_ack_interrupt(struct phy_device *phydev)static int smsc_phy_config_init (struct phy_device *phydev) {struct smsc_phy_priv *priv = phydev->priv; +int rc; + +if (!priv->energy_enable) +return 0 ; -int rc =phy_read (phydev,MII_LAN83C185_CTRL_STATUS ); + rc =phy_read (phydev,MII_LAN83C185_CTRL_STATUS );if (rc <0 )return rc; -if (priv->energy_enable) { -/* Enable energy detect mode for this SMSC Transceivers */ - rc =phy_write (phydev,MII_LAN83C185_CTRL_STATUS , - rc |MII_LAN83C185_EDPWRDOWN ); -if (rc <0 ) -return rc; - } +/* Enable energy detect mode for this SMSC Transceivers */ + rc =phy_write (phydev,MII_LAN83C185_CTRL_STATUS , + rc |MII_LAN83C185_EDPWRDOWN ); +if (rc <0 ) +return rc;return smsc_phy_ack_interrupt (phydev); }
Signature · 1 line
2.20.1
Re: [PATCH v2 2/5] net: phy: smsc: simplify config_init callback
Quoted 6 lines · Marco Felsch
Exit the driver specific
config_inithook early if energy detection is disabled. We can do this because we don't need to clear the interrupt status here. Clearing the status should be removed anyway since this is handled by thephy_enable_interrupts().Signed-off-by Marco Felsch <[email protected]>
Signature · 1 line
Florian
PATCH v2 3/5 dt-bindings: net: phy: smsc: document reference clock
In reply to Marco FelschAdd support to specify the reference clock for the phy.
---
v2:
- no change
Documentation/devicetree/bindings/net/smsc-lan87xx.txt | 4 ++++ 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/net/smsc-lan87xx.txt +4 -0
@@ -5,6 +5,10 @@ through an Ethernet OF device node. Optional properties: +- clocks: + The clock used as phy reference clock and is connected to phy + pin XTAL1/CLKIN. + - smsc,disable-energy-detect: If set, do not enable energy detect mode for the SMSC phy. default: enable energy detect mode
Signature · 1 line
2.20.1
Re: [PATCH v2 3/5] dt-bindings: net: phy: smsc: document reference clock
Quoted 3 lines · Marco Felsch
Add support to specify the reference clock for the phy.
Signed-off-by Marco Felsch <[email protected]>
Signature · 1 line
Florian
PATCH v2 4/5 net: phy: smsc: LAN8710/20: add phy refclk in support
In reply to Marco FelschAdd support to specify the clock provider for the phy refclk and don't rely on 'magic' host clock setup. Commit [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-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. The phy is still rest but now within the phylib and with respect to the phy-state-machine.
[1] commit 7f64e5b18ebb ("net: phy: smsc: LAN8710/20: add PHY_RST_AFTER_CLK_EN flag")
---
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(+)
drivers/net/phy/smsc.c +25 -0
@@ -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,
Signature · 1 line
2.20.1
Re: [PATCH v2 4/5] net: phy: smsc: LAN8710/20: add phy refclk in support
Quoted 9 lines · Marco Felsch
Add support to specify the clock provider for the phy refclk and don't rely on 'magic' host clock setup. Commit [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-state-machine. Furthermore the commit fixed the problem only for FEC based hosts other hosts acting like the FEC are not covered.
Quoted 5 lines
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. The phy is still rest but now within the phylib and with respect to the phy-state-machine.
s/rest/reset/
s/phy/PHY/
s/phy-state-machine/PHY library state machine/
(this applies to patch #5 as well)
With those things corrected:
Signature · 1 line
Florian
PATCH v2 5/5 net: phy: smsc: LAN8710/20: remove PHY_RST_AFTER_CLK_EN flag
In reply to Marco FelschDon't reset the phy without respect to the phy-state-machine because this breaks the phy IRQ mode. We can archive the same behaviour if the refclk in is specified.
---
v2:
- adapt the subject to align with previous patch
drivers/net/phy/smsc.c | 1 - 1 file changed, 1 deletion(-)
drivers/net/phy/smsc.c +0 -1
@@ -331,7 +331,6 @@ static struct phy_driver smsc_phy_driver[] = { .name = "SMSC LAN8710/LAN8720",/* PHY_BASIC_FEATURES */ - .flags = PHY_RST_AFTER_CLK_EN, .probe = smsc_phy_probe, .remove = smsc_phy_remove,
Signature · 1 line
2.20.1