Netdev List
 help / color / mirror / Atom feed
* [PATCH net-next v2] net: phy: motorcomm: enable the reference clock for YT8521 and YT8531
@ 2026-07-27 20:56 Jiaxing Hu
  2026-07-28  2:14 ` Gavin Gao
  2026-07-28  4:16 ` Alexey Charkov
  0 siblings, 2 replies; 3+ messages in thread
From: Jiaxing Hu @ 2026-07-27 20:56 UTC (permalink / raw)
  To: Frank.Sae, andrew, hkallweit1, linux, davem, edumazet, kuba,
	pabeni
  Cc: netdev, linux-kernel, maxime.chevallier, heiko, linux-rockchip,
	attinagaoxu, alchark

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.

Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Jiaxing Hu <gahing@gahingwoo.com>
---

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/20260719034555.3623003-1-gahing@gahingwoo.com/

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/20260727021048.3375444-1-attinagaoxu@gmail.com/

 drivers/net/phy/motorcomm.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index 708491bc1..32eb5ce93 100644
--- a/drivers/net/phy/motorcomm.c
+++ b/drivers/net/phy/motorcomm.c
@@ -6,6 +6,7 @@
  * Author: Frank <Frank.Sae@motor-comm.com>
  */
 
+#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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v2] net: phy: motorcomm: enable the reference clock for YT8521 and YT8531
  2026-07-27 20:56 [PATCH net-next v2] net: phy: motorcomm: enable the reference clock for YT8521 and YT8531 Jiaxing Hu
@ 2026-07-28  2:14 ` Gavin Gao
  2026-07-28  4:16 ` Alexey Charkov
  1 sibling, 0 replies; 3+ messages in thread
From: Gavin Gao @ 2026-07-28  2:14 UTC (permalink / raw)
  To: Jiaxing Hu
  Cc: Frank.Sae, andrew, hkallweit1, linux, davem, edumazet, kuba,
	pabeni, netdev, linux-kernel, maxime.chevallier, heiko,
	linux-rockchip, alchark

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.

Tested-by: Gavin Gao <attinagaoxu@gmail.com>

Thanks,
Gavin

On Tue, Jul 28, 2026 at 5:04 AM Jiaxing Hu <gahing@gahingwoo.com> wrote:
>
> 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.
>
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Jiaxing Hu <gahing@gahingwoo.com>
> ---
>
> 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/20260719034555.3623003-1-gahing@gahingwoo.com/
>
> 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/20260727021048.3375444-1-attinagaoxu@gmail.com/
>
>  drivers/net/phy/motorcomm.c | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
>
> diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
> index 708491bc1..32eb5ce93 100644
> --- a/drivers/net/phy/motorcomm.c
> +++ b/drivers/net/phy/motorcomm.c
> @@ -6,6 +6,7 @@
>   * Author: Frank <Frank.Sae@motor-comm.com>
>   */
>
> +#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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH net-next v2] net: phy: motorcomm: enable the reference clock for YT8521 and YT8531
  2026-07-27 20:56 [PATCH net-next v2] net: phy: motorcomm: enable the reference clock for YT8521 and YT8531 Jiaxing Hu
  2026-07-28  2:14 ` Gavin Gao
@ 2026-07-28  4:16 ` Alexey Charkov
  1 sibling, 0 replies; 3+ messages in thread
From: Alexey Charkov @ 2026-07-28  4:16 UTC (permalink / raw)
  To: Jiaxing Hu
  Cc: Frank.Sae, andrew, hkallweit1, linux, davem, edumazet, kuba,
	pabeni, netdev, linux-kernel, maxime.chevallier, heiko,
	linux-rockchip, attinagaoxu

Hi Jaxing,

On Tue, Jul 28, 2026 at 1:04 AM Jiaxing Hu <gahing@gahingwoo.com> wrote:
>
> 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.
>
> Reviewed-by: Andrew Lunn <andrew@lunn.ch>
> Signed-off-by: Jiaxing Hu <gahing@gahingwoo.com>
> ---
>
> 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/20260719034555.3623003-1-gahing@gahingwoo.com/
>
> 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/20260727021048.3375444-1-attinagaoxu@gmail.com/
>
>  drivers/net/phy/motorcomm.c | 33 +++++++++++++++++++++++++++++++++
>  1 file changed, 33 insertions(+)
>
> diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
> index 708491bc1..32eb5ce93 100644
> --- a/drivers/net/phy/motorcomm.c
> +++ b/drivers/net/phy/motorcomm.c
> @@ -6,6 +6,7 @@
>   * Author: Frank <Frank.Sae@motor-comm.com>
>   */
>
> +#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");

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2026-07-28  4:16 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-27 20:56 [PATCH net-next v2] net: phy: motorcomm: enable the reference clock for YT8521 and YT8531 Jiaxing Hu
2026-07-28  2:14 ` Gavin Gao
2026-07-28  4:16 ` Alexey Charkov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox