net: phy: motorcomm: enable the reference clock for YT8521 and YT8531
Subsystems (5)
PATCH v2 1/1 net: phy: motorcomm: enable the reference clock for YT8521 and YT8531
These PHYs need a 25 MHz reference. On boards without a local crystal it is fed from the SoC and described as a clock on the PHY node. Get and enable it in probe, via a small helper called from both yt8521_probe and yt8531_probe, so the PHY is clocked before its registers are accessed. The clock is optional, so crystal-clocked boards are unaffected.
---
Changes in v2:
- Factor the clock enable into ytphy_get_and_enable_refclk() and call it from yt8521_probe as well, so the YT8521 is covered too, not only the YT8531. v1 only touched yt8531_probe.
- Carried Andrew's Reviewed-by; the enable itself is unchanged, only moved into the helper.
v1: https://lore.kernel.org/all/[email protected]/
A second crystal-less RK3576 board with a YT8521 needs the same handling (see the RK3576 GMAC 25M refout thread [1]), so v2 covers both PHYs. This supersedes the withdrawn dwmac-rk MAC-side series. The DTS that consumes the clock (rk3576-armsom-cm5) goes to the rockchip tree separately; the clock is optional so this patch stands alone. The YT8531 path is tested on an ArmSoM CM5-IO (links at 1000 Mbit/s).
[1] https://lore.kernel.org/all/[email protected]/
drivers/net/phy/motorcomm.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
drivers/net/phy/motorcomm.c +33 -0
@@ -6,6 +6,7 @@* Author: Frank <[email protected]> */ +#include <linux/clk.h> #include <linux/etherdevice.h> #include <linux/kernel.h> #include <linux/module.h>
@@ -1043,6 +1044,29 @@ static int yt8531_set_ds(struct phy_device *phydev)return 0 ; } +/** +* ytphy_get_and_enable_refclk() - get and enable the PHY reference clock +* @phydev: a pointer to a &struct phy_device +* +* A crystal-less YT8521/YT8531 takes its 25 MHz reference from the SoC. When +* that reference is described as a clock, enable it for the life of the +* device. It is optional, so crystal-clocked boards are unaffected. +* +* returns 0 or negative errno code +*/ +static int ytphy_get_and_enable_refclk (struct phy_device *phydev) +{ +struct device *dev = &phydev->mdio.dev; +struct clk *clk; + + clk =devm_clk_get_optional_enabled (dev,NULL ); +if (IS_ERR (clk)) +return dev_err_probe (dev,PTR_ERR (clk), +"failed to get and enable the reference clock\n" ); + +return 0 ; +} +/** * yt8521_probe() - read chip config then set suitable polling_mode * @phydev: a pointer to a &struct phy_device
@@ -1064,6 +1088,10 @@ static int yt8521_probe(struct phy_device *phydev) phydev->priv = priv; + ret =ytphy_get_and_enable_refclk (phydev); +if (ret) +return ret; + chip_config =ytphy_read_ext_with_lock (phydev,YT8521_CHIP_CONFIG_REG );if (chip_config <0 )return chip_config;
@@ -1171,6 +1199,11 @@ static int yt8531_probe(struct phy_device *phydev)struct device *dev = &phydev->mdio.dev;u16 mask, val;u32 freq; +int ret; + + ret =ytphy_get_and_enable_refclk (phydev); +if (ret) +return ret;if (device_property_read_u32 (dev,"motorcomm,clk-out-frequency-hz" , &freq)) freq =YTPHY_DTS_OUTPUT_CLK_DIS ;
Signature · 1 line
2.43.0
Hi Jiaxing,
Thanks for folding in YT8521 support.
I tested this on a PicoCOM RK3576 ACP board with a Motorcomm YT8521 PHY. The 25 MHz reference clock from RK3576 REFCLKO25M_GMACx_OUT stays active, and Ethernet works.
Thanks,
Gavin
Quoted 100 lines · Jiaxing Hu
These PHYs need a 25 MHz reference. On boards without a local crystal it is fed from the SoC and described as a clock on the PHY node. Get and enable it in probe, via a small helper called from both
yt8521_probeandyt8531_probe, so the PHY is clocked before its registers are accessed. The clock is optional, so crystal-clocked boards are unaffected.Reviewed-by Andrew Lunn <[email protected]>Signed-off-by Jiaxing Hu <[email protected]>---
Changes in v2:
- Factor the clock enable intoytphy_get_and_enable_refclk()and call it fromyt8521_probeas well, so the YT8521 is covered too, not only the YT8531. v1 only touchedyt8531_probe.
- Carried Andrew's Reviewed-by; the enable itself is unchanged, only moved into the helper.v1: https://lore.kernel.org/all/[email protected]/
A second crystal-less RK3576 board with a YT8521 needs the same handling (see the RK3576 GMAC 25M refout thread [1]), so v2 covers both PHYs. This supersedes the withdrawn dwmac-rk MAC-side series. The DTS that consumes the clock (rk3576-armsom-cm5) goes to the rockchip tree separately; the clock is optional so this patch stands alone. The YT8531 path is tested on an ArmSoM CM5-IO (links at 1000 Mbit/s).
[1] https://lore.kernel.org/all/[email protected]/
drivers/net/phy/motorcomm.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)drivers/net/phy/motorcomm.c +33
-1@@ -6,6 +6,7 @@* Author: Frank <[email protected]> */ +#include <linux/clk.h> #include <linux/etherdevice.h> #include <linux/kernel.h> #include <linux/module.h> @@ -1043,6 +1044,29 @@ static int yt8531_set_ds(struct phy_device *phydev)return 0 ; } +/** +* ytphy_get_and_enable_refclk() - get and enable the PHY reference clock +* @phydev: a pointer to a &struct phy_device +* +* A crystal-less YT8521/YT8531 takes its 25 MHz reference from the SoC. When +* that reference is described as a clock, enable it for the life of the +* device. It is optional, so crystal-clocked boards are unaffected. +* +* returns 0 or negative errno code +*/ +static int ytphy_get_and_enable_refclk (struct phy_device *phydev) +{ +struct device *dev = &phydev->mdio.dev; +struct clk *clk; + + clk =devm_clk_get_optional_enabled (dev,NULL ); +if (IS_ERR (clk)) +return dev_err_probe (dev,PTR_ERR (clk), +"failed to get and enable the reference clock\n" ); + +return 0 ; +} +/** * yt8521_probe() - read chip config then set suitable polling_mode * @phydev: a pointer to a &struct phy_device @@ -1064,6 +1088,10 @@ static int yt8521_probe(struct phy_device *phydev) phydev->priv = priv; + ret =ytphy_get_and_enable_refclk (phydev); +if (ret) +return ret; + chip_config =ytphy_read_ext_with_lock (phydev,YT8521_CHIP_CONFIG_REG );if (chip_config <0 )return chip_config;@@ -1171,6 +1199,11 @@ static int yt8531_probe(struct phy_device *phydev)struct device *dev = &phydev->mdio.dev;u16 mask, val;u32 freq; +int ret; + + ret =ytphy_get_and_enable_refclk (phydev); +if (ret) +return ret;if (device_property_read_u32 (dev,"motorcomm,clk-out-frequency-hz" , &freq)) freq =YTPHY_DTS_OUTPUT_CLK_DIS ; --2.43.0
Hi Jaxing,
Quoted 57 lines · Jiaxing Hu
These PHYs need a 25 MHz reference. On boards without a local crystal it is fed from the SoC and described as a clock on the PHY node. Get and enable it in probe, via a small helper called from both
yt8521_probeandyt8531_probe, so the PHY is clocked before its registers are accessed. The clock is optional, so crystal-clocked boards are unaffected.Reviewed-by Andrew Lunn <[email protected]>Signed-off-by Jiaxing Hu <[email protected]>---
Changes in v2:
- Factor the clock enable intoytphy_get_and_enable_refclk()and call it fromyt8521_probeas well, so the YT8521 is covered too, not only the YT8531. v1 only touchedyt8531_probe.
- Carried Andrew's Reviewed-by; the enable itself is unchanged, only moved into the helper.v1: https://lore.kernel.org/all/[email protected]/
A second crystal-less RK3576 board with a YT8521 needs the same handling (see the RK3576 GMAC 25M refout thread [1]), so v2 covers both PHYs. This supersedes the withdrawn dwmac-rk MAC-side series. The DTS that consumes the clock (rk3576-armsom-cm5) goes to the rockchip tree separately; the clock is optional so this patch stands alone. The YT8531 path is tested on an ArmSoM CM5-IO (links at 1000 Mbit/s).
[1] https://lore.kernel.org/all/[email protected]/
drivers/net/phy/motorcomm.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)drivers/net/phy/motorcomm.c +10
-0@@ -6,6 +6,7 @@* Author: Frank <[email protected]> */ +#include <linux/clk.h> #include <linux/etherdevice.h> #include <linux/kernel.h> #include <linux/module.h> @@ -1043,6 +1044,29 @@ static int yt8531_set_ds(struct phy_device *phydev)return 0 ; } +/** +* ytphy_get_and_enable_refclk() - get and enable the PHY reference clock +* @phydev: a pointer to a &struct phy_device +* +* A crystal-less YT8521/YT8531 takes its 25 MHz reference from the SoC. When +* that reference is described as a clock, enable it for the life of the +* device. It is optional, so crystal-clocked boards are unaffected. +* +* returns 0 or negative errno code
drivers/net/phy/motorcomm.c static int yt8531_set_ds(struct phy_device *phydev) · line 1065
Quoted 10 lines
drivers/net/phy/motorcomm.c +10
-0+*/ +static int ytphy_get_and_enable_refclk (struct phy_device *phydev) +{ +struct device *dev = &phydev->mdio.dev; +struct clk *clk; + + clk =devm_clk_get_optional_enabled (dev,NULL ); +if (IS_ERR (clk)) +return dev_err_probe (dev,PTR_ERR (clk), +"failed to get and enable the reference clock\n" );
A helper for a single-line function call looks like an overkill, and requires scrolling to understand what is going on where an open-coded version would be self-explanatory at the first glance.
Maybe fold it into the two caller functions instead?
Best regards,
Alexey
Hi Alexey,
I slightly prefer keeping the helper.
This looks like a common pattern for the Motorcomm family rather than a YT8521/YT8531-specific detail. Other PHYs in the same series may need the same optional reference clock handling later, and a small helper keeps that path easy to reuse without duplicating the same code.
Best Regards,
Gavin Gao
Quoted 80 lines · Alexey Charkov
Hi Jaxing,
Quoted 57 lines · Jiaxing Hu
These PHYs need a 25 MHz reference. On boards without a local crystal it is fed from the SoC and described as a clock on the PHY node. Get and enable it in probe, via a small helper called from both
yt8521_probeandyt8531_probe, so the PHY is clocked before its registers are accessed. The clock is optional, so crystal-clocked boards are unaffected.Reviewed-by Andrew Lunn <[email protected]>Signed-off-by Jiaxing Hu <[email protected]>---
Changes in v2:
- Factor the clock enable intoytphy_get_and_enable_refclk()and call it fromyt8521_probeas well, so the YT8521 is covered too, not only the YT8531. v1 only touchedyt8531_probe.
- Carried Andrew's Reviewed-by; the enable itself is unchanged, only moved into the helper.v1: https://lore.kernel.org/all/[email protected]/
A second crystal-less RK3576 board with a YT8521 needs the same handling (see the RK3576 GMAC 25M refout thread [1]), so v2 covers both PHYs. This supersedes the withdrawn dwmac-rk MAC-side series. The DTS that consumes the clock (rk3576-armsom-cm5) goes to the rockchip tree separately; the clock is optional so this patch stands alone. The YT8531 path is tested on an ArmSoM CM5-IO (links at 1000 Mbit/s).
[1] https://lore.kernel.org/all/[email protected]/
drivers/net/phy/motorcomm.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)drivers/net/phy/motorcomm.c +10
-0@@ -6,6 +6,7 @@* Author: Frank <[email protected]> */ +#include <linux/clk.h> #include <linux/etherdevice.h> #include <linux/kernel.h> #include <linux/module.h> @@ -1043,6 +1044,29 @@ static int yt8531_set_ds(struct phy_device *phydev)return 0 ; } +/** +* ytphy_get_and_enable_refclk() - get and enable the PHY reference clock +* @phydev: a pointer to a &struct phy_device +* +* A crystal-less YT8521/YT8531 takes its 25 MHz reference from the SoC. When +* that reference is described as a clock, enable it for the life of the +* device. It is optional, so crystal-clocked boards are unaffected. +* +* returns 0 or negative errno code drivers/net/phy/motorcomm.c static int yt8531_set_ds(struct phy_device *phydev) · line 1065
Quoted 10 lines
drivers/net/phy/motorcomm.c +10
-0+*/ +static int ytphy_get_and_enable_refclk (struct phy_device *phydev) +{ +struct device *dev = &phydev->mdio.dev; +struct clk *clk; + + clk =devm_clk_get_optional_enabled (dev,NULL ); +if (IS_ERR (clk)) +return dev_err_probe (dev,PTR_ERR (clk), +"failed to get and enable the reference clock\n" );A helper for a single-line function call looks like an overkill, and requires scrolling to understand what is going on where an open-coded version would be self-explanatory at the first glance.
Maybe fold it into the two caller functions instead?
Best regards,
Alexey
Andrew Lunn
maintainerQuoted 8 lines · Gavin Gao
Hi Alexey,
I slightly prefer keeping the helper.
This looks like a common pattern for the Motorcomm family rather than a YT8521/YT8531-specific detail. Other PHYs in the same series may need the same optional reference clock handling later, and a small helper keeps that path easy to reuse without duplicating the same code.
Please don't top post.
Look around at other drivers. Is it generally put into a tiny helper, or used inline?
My gut feeling from reviewing lots of drivers is that it is inline.
Andrew
---
pw-bot: cr
Quoted 4 lines
Look around at other drivers. Is it generally put into a tiny helper, or used inline?
My gut feeling from reviewing lots of drivers is that it is inline.
Agreed. v3 open-codes the get-and-enable in both yt8521_probe and yt8531_probe, with no helper. I had already sent it before this mail:
https://lore.kernel.org/all/[email protected]/
It carries your Reviewed-by and Gavin's Tested-by.
Jiaxing
Quoted 6 lines · Andrew Lunn
Please don't top post.
Look around at other drivers. Is it generally put into a tiny helper, or used inline?
Quoted 6 lines
My gut feeling from reviewing lots of drivers is that it is inline.
Andrew
---
pw-bot: cr
Hi Alexey,
Sorry for the top posting.
Fair point. I checked a few PHY drivers and this kind of optional clock handling is often open-coded in probe. Inline is fine with me.
Signature · 2 lines
Best Regards, Gavin Gao