From 4c1028a34760a2541d3dae43c8863fd5f7d917ae Mon Sep 17 00:00:00 2001 From: Maxime Chevallier Date: Sat, 5 Sep 2026 09:28:26 +0200 Subject: [PATCH] net: phy: motorcomm: Split yt8521_config_init() page management In preparation for separate .config_init() implementations for YT8521 and YT8531S, let's split the yt8521_config_init() into a high-level helper that deals with page handling, and another one that implements the logic. This will ease splitting the YT8531S-specific logic out. Signed-off-by: Maxime Chevallier Link: https://patch.msgid.link/20260905072830.28986-2-maxime.chevallier@bootlin.com Signed-off-by: Jakub Kicinski --- drivers/net/phy/motorcomm.c | 66 +++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 29 deletions(-) diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c index c5a2cda8d31b..58e4d67b945f 100644 --- a/drivers/net/phy/motorcomm.c +++ b/drivers/net/phy/motorcomm.c @@ -1680,6 +1680,41 @@ static int yt8521_resume(struct phy_device *phydev) return yt8521_modify_utp_fiber_bmcr(phydev, BMCR_PDOWN, 0); } +static int __yt8521_config_init(struct phy_device *phydev) +{ + struct device *dev = &phydev->mdio.dev; + int ret = 0; + + /* set rgmii delay mode */ + if (phydev->interface != PHY_INTERFACE_MODE_SGMII) { + ret = ytphy_rgmii_clk_delay_config(phydev); + if (ret < 0) + return ret; + } + + if (device_property_read_bool(dev, "motorcomm,auto-sleep-disabled")) { + /* disable auto sleep */ + ret = ytphy_modify_ext(phydev, YT8521_EXTREG_SLEEP_CONTROL1_REG, + YT8521_ESC1R_SLEEP_SW, 0); + if (ret < 0) + return ret; + } + + if (device_property_read_bool(dev, "motorcomm,keep-pll-enabled")) { + /* enable RXC clock when no wire plug */ + ret = ytphy_modify_ext(phydev, YT8521_CLOCK_GATING_REG, + YT8521_CGR_RX_CLK_EN, 0); + if (ret < 0) + return ret; + } + + if (phy_interface_is_rgmii(phydev) && + phydev_id_compare(phydev, PHY_ID_YT8531S)) + ret = yt8531_set_ds(phydev); + + return ret; +} + /** * yt8521_config_init() - called to initialize the PHY * @phydev: a pointer to a &struct phy_device @@ -1688,40 +1723,13 @@ static int yt8521_resume(struct phy_device *phydev) */ static int yt8521_config_init(struct phy_device *phydev) { - struct device *dev = &phydev->mdio.dev; - int old_page; - int ret = 0; + int old_page, ret = 0; old_page = phy_select_page(phydev, YT8521_RSSR_UTP_SPACE); if (old_page < 0) goto err_restore_page; - /* set rgmii delay mode */ - if (phydev->interface != PHY_INTERFACE_MODE_SGMII) { - ret = ytphy_rgmii_clk_delay_config(phydev); - if (ret < 0) - goto err_restore_page; - } - - if (device_property_read_bool(dev, "motorcomm,auto-sleep-disabled")) { - /* disable auto sleep */ - ret = ytphy_modify_ext(phydev, YT8521_EXTREG_SLEEP_CONTROL1_REG, - YT8521_ESC1R_SLEEP_SW, 0); - if (ret < 0) - goto err_restore_page; - } - - if (device_property_read_bool(dev, "motorcomm,keep-pll-enabled")) { - /* enable RXC clock when no wire plug */ - ret = ytphy_modify_ext(phydev, YT8521_CLOCK_GATING_REG, - YT8521_CGR_RX_CLK_EN, 0); - if (ret < 0) - goto err_restore_page; - } - - if (phy_interface_is_rgmii(phydev) && - phydev_id_compare(phydev, PHY_ID_YT8531S)) - ret = yt8531_set_ds(phydev); + ret = __yt8521_config_init(phydev); err_restore_page: return phy_restore_page(phydev, old_page, ret);