From: Jiaxing Hu <gahing@gahingwoo.com>
To: Frank.Sae@motor-comm.com, andrew@lunn.ch, hkallweit1@gmail.com,
linux@armlinux.org.uk, davem@davemloft.net, edumazet@google.com,
kuba@kernel.org, pabeni@redhat.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
maxime.chevallier@bootlin.com, heiko@sntech.de,
linux-rockchip@lists.infradead.org, attinagaoxu@gmail.com,
alchark@gmail.com
Subject: [PATCH net-next v2] net: phy: motorcomm: enable the reference clock for YT8521 and YT8531
Date: Tue, 28 Jul 2026 08:56:02 +1200 [thread overview]
Message-ID: <20260727205602.1188008-1-gahing@gahingwoo.com> (raw)
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
_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip
next reply other threads:[~2026-07-27 21:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-27 20:56 Jiaxing Hu [this message]
2026-07-28 2:14 ` [PATCH net-next v2] net: phy: motorcomm: enable the reference clock for YT8521 and YT8531 Gavin Gao
2026-07-28 4:16 ` Alexey Charkov
2026-07-28 13:57 ` Gavin Gao
2026-07-28 20:54 ` Andrew Lunn
2026-07-28 23:09 ` Jiaxing Hu
2026-07-29 6:07 ` Gavin Gao
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=20260727205602.1188008-1-gahing@gahingwoo.com \
--to=gahing@gahingwoo.com \
--cc=Frank.Sae@motor-comm.com \
--cc=alchark@gmail.com \
--cc=andrew@lunn.ch \
--cc=attinagaoxu@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=heiko@sntech.de \
--cc=hkallweit1@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux@armlinux.org.uk \
--cc=maxime.chevallier@bootlin.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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