Add a driver for the Motorcomm YT8831 2.5G Ethernet PHY. Verified the
driver on BPI-R3 with MediaTek SoC.
YT8831 2.5G Ethernet PHY works in AUTO_BX2500_SGMII or FORCE_BX2500
mode, supports 2.5G/1000M/100M/10M speeds.
Signed-off-by: Frank.sae <fran…@motor-comm.com>
---
v6:
- Fix yt8831_config_aneg(): remove incorrect genphy_c45_config_aneg() call.
YT8831 uses C22 for autoneg; C45 MMD is only used to program 2.5G capability,
not for C45 autoneg. Avoid double autoneg restart.
v5:
- As suggested by Andrew, when in AUTO_BX2500_SGMII mode, modify phy->interface
in .read_status to trigger host to change the media side.
- Add YT8831_RSSR_TOP_SPACE for read/write_page.
Link: https://lore.kernel.org/netdev/2026…@motor-comm.com/
v4:
- Remove WoL support for now, it will be submitted in follow-up patch
Link: https://lore.kernel.org/netdev/2026…@motor-comm.com/
v3:
- Fix the kernel doc format of yt8831_set_wol()/yt8831_read_page()/yt8831_write_page()
- Fix wrong reg addr for WoL magic addr
- Add PHY_ID_YT8831 entry to motorcomm_tbl for module auto-load
Link: https://lore.kernel.org/netdev/2026…@motor-comm.com/
v2:
- Fix the notes of function yt8831_set_wol has no return value
- Fix YT8831 SDS config_init softreset error
- Fix YT8831 read_status dont read LP's 2.5G status
Link: https://lore.kernel.org/all/2026…@motor-comm.com/
v1:
Link: https://lore.kernel.org/all/2026…@motor-comm.com/
---
drivers/net/phy/motorcomm.c | 385 +++++++++++++++++++++++++++++++++++-
1 file changed, 383 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index a87e83fdf590..56a348180c3a 100644
--- a/drivers/net/phy/motorcomm.c
+++ b/drivers/net/phy/motorcomm.c
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: GPL-2.0+
/*
- * Motorcomm 8511/8521/8522/8531/8531S/861x/8821 PHY driver.
+ * Motorcomm 8511/8521/8522/8531/8531S/861x/8821/8831 PHY driver.
*
* Author: Peter Geis <pgwi…@gmail.com>
* Author: Frank <Fran…@motor-comm.com>
@@ -22,6 +22,7 @@
/* Live captured from YT921x switch internal MDIO bus */
#define PHY_ID_INT861X 0x01e04281
#define PHY_ID_YT8821 0x4f51ea19
+#define PHY_ID_YT8831 0x4f51e938
/* YT8521/YT8531S/YT8821 Register Overview
* UTP Register space | FIBER Register space
* ------------------------------------------------------------
@@ -171,6 +172,12 @@
#define YT8521_RSSR_UTP_SPACE (0x0 << 1)
#define YT8521_RSSR_TO_BE_ARBITRATED (0xFF)
+#define YT8831_REG_SPACE_SELECT_REG 0x8020
+#define YT8831_RSSR_SPACE_MASK (BIT(1) | BIT(0))
+#define YT8831_RSSR_FIBER_SPACE BIT(1)
+#define YT8831_RSSR_UTP_SPACE BIT(0)
+#define YT8831_RSSR_TOP_SPACE 0x0
+
#define YT8521_CHIP_CONFIG_REG 0xA001
#define YT8521_CCR_SW_RST BIT(15)
#define YT8531_RGMII_LDO_VOL_MASK GENMASK(5, 4)
@@ -258,6 +265,34 @@
#define YTPHY_WCR_INTR_SEL BIT(6)
#define YTPHY_WCR_ENABLE BIT(3)
+#define YT8831_SDS_WRITE_PROTECT_REG 0x873
+#define YT8831_SDS_SGMII_OUTPUT_REG 0x1002
+
+#define YT8831_UTP_WRITE_PROTECT_REG 0x1
+#define YT8831_UTP_DAC_DATA_DLY_REG 0x0
+#define YT8831_UTP_REF_DLAY_SEL_REG 0x3
+#define YT8831_UTP_REF_DLAY_SEL_FEXT_REG 0x4
+#define YT8831_UTP_COE_MANUAL_SHIFT_SEL_2500_REG 0x723
+#define YT8831_UTP_EEE_OPTIM_1_REG 0x727
+#define YT8831_UTP_EEE_OPTIM_2_REG 0x339
+#define YT8831_UTP_EEE_MSE1_REG 0xc3
+#define YT8831_UTP_EEE_MSE2_REG 0x32
+#define YT8831_UTP_EEE_OPTIM_3_REG 0xff
+#define YT8831_UTP_EEE_OPTIM_4_REG 0x372
+#define YT8831_UTP_EEE_OPTIM_5_REG 0x336
+#define YT8831_UTP_EEE_OPTIM_6_REG 0x340
+#define YT8831_UTP_PSAN_OPTIM_REG 0x1e58
+#define YT8831_UTP_1000M_TEMPLATE_OPTIM_1_REG 0x209e
+#define YT8831_UTP_1000M_TEMPLATE_OPTIM_2_REG 0x20a4
+#define YT8831_UTP_1000M_TEMPLATE_OPTIM_3_REG 0x20a9
+#define YT8831_UTP_1000M_TEMPLATE_OPTIM_4_REG 0x20af
+#define YT8831_UTP_1000M_TEMPLATE_OPTIM_5_REG 0x20b4
+#define YT8831_UTP_1000M_TEMPLATE_OPTIM_6_REG 0x20ba
+#define YT8831_UTP_1000M_TEMPLATE_OPTIM_7_REG 0x20bf
+#define YT8831_UTP_1000M_TEMPLATE_OPTIM_8_REG 0x20c5
+#define YT8831_UTP_2500M_TEMPLATE_OPTIM_1_REG 0x20ff
+#define YT8831_UTP_2500M_TEMPLATE_OPTIM_2_REG 0x2100
+
/* 2b00 84ms
* 2b01 168ms *default*
* 2b10 336ms
@@ -397,6 +432,16 @@
#define YT8821_CHIP_MODE_AUTO_BX2500_SGMII 0
#define YT8821_CHIP_MODE_FORCE_BX2500 1
+#define YT8831_CHIP_MODE_SEL 0x8802
+#define YT8831_CHIP_MODE_SEL_MASK GENMASK(2, 0)
+#define YT8831_CHIP_MODE_AUTO_BX2500_SGMII 0x0
+#define YT8831_CHIP_MODE_FORCE_2500BASEX BIT(0)
+#define YT8831_CHIP_MODE_UTP_TO_FIBER_FORCE (BIT(2) | BIT(0))
+
+#define YT8831_MDIO_ADDRESS_CTL 0x8004
+#define YT8831_MDIO_ADDRESS_CTL_EN_BROADCAST_MASK BIT(8)
+#define YT8831_MDIO_ADDRESS_CTL_EN_BROADCAST BIT(8)
+
struct yt8521_priv {
/* combo_advertising is used for case of YT8521 in combo mode,
* this means that yt8521 may work in utp or fiber mode which depends
@@ -798,6 +843,24 @@ static int yt8521_read_page(struct phy_device *phydev)
return YT8521_RSSR_UTP_SPACE;
};
+/**
+ * yt8831_read_page() - read reg page
+ * @phydev: a pointer to a &struct phy_device
+ *
+ * Returns: current reg space of yt8831 (YT8831_RSSR_FIBER_SPACE/
+ * YT8831_RSSR_UTP_SPACE) or negative errno code
+ */
+static int yt8831_read_page(struct phy_device *phydev)
+{
+ int old_page;
+
+ old_page = ytphy_read_ext(phydev, YT8831_REG_SPACE_SELECT_REG);
+ if (old_page < 0)
+ return old_page;
+
+ return old_page & YT8831_RSSR_SPACE_MASK;
+};
+
/**
* yt8521_write_page() - write reg page
* @phydev: a pointer to a &struct phy_device
@@ -818,6 +881,24 @@ static int yt8521_write_page(struct phy_device *phydev, int page)
return ytphy_modify_ext(phydev, YT8521_REG_SPACE_SELECT_REG, mask, set);
};
+/**
+ * yt8831_write_page() - write reg page
+ * @phydev: a pointer to a &struct phy_device
+ * @page: The reg page(YT8831_RSSR_FIBER_SPACE/YT8831_RSSR_UTP_SPACE) to write.
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt8831_write_page(struct phy_device *phydev, int page)
+{
+ if (page < 0 || page > YT8831_RSSR_SPACE_MASK) {
+ phydev_err(phydev, "Invalid page %d\n", page);
+ return -EINVAL;
+ }
+
+ return ytphy_modify_ext(phydev, YT8831_REG_SPACE_SELECT_REG,
+ YT8831_RSSR_SPACE_MASK, page);
+};
+
/**
* struct ytphy_cfg_reg_map - map a config value to a register value
* @cfg: value in device configuration
@@ -2554,6 +2635,213 @@ static int yt8521_get_features(struct phy_device *phydev)
return ret;
}
+/**
+ * yt8831_config_aneg() - config auto-aneg
+ * @phydev: a pointer to a &struct phy_device
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt8831_config_aneg(struct phy_device *phydev)
+{
+ bool changed = false;
+ int ret;
+ u32 adv;
+
+ /* YT8831 advertises 10/100/1000BASE-T through the Clause 22
+ * registers and 2.5GBASE-T through the Clause 45 AN MMD. Only
+ * the latter needs to be programmed here; __genphy_config_aneg()
+ * programs the Clause 22 advertisement and restarts AN once.
+ */
+ if (phydev->autoneg == AUTONEG_ENABLE) {
+ adv = linkmode_adv_to_mii_10gbt_adv_t(phydev->advertising);
+ ret = phy_modify_mmd_changed(phydev, MDIO_MMD_AN, MDIO_AN_10GBT_CTRL,
+ MDIO_AN_10GBT_CTRL_ADV10G |
+ MDIO_AN_10GBT_CTRL_ADV5G |
+ MDIO_AN_10GBT_CTRL_ADV2_5G, adv);
+ if (ret < 0)
+ return ret;
+ if (ret > 0)
+ changed = true;
+ }
+
+ return __genphy_config_aneg(phydev, changed);
+}
+
+/**
+ * yt8831_top_init() - top init
+ * @phydev: a pointer to a &struct phy_device
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt8831_top_init(struct phy_device *phydev)
+{
+ int old_page, ret;
+
+ ret = old_page = phy_select_page(phydev, YT8831_RSSR_TOP_SPACE);
+ if (old_page < 0) {
+ phydev_err(phydev, "Failed to select page: %d\n",
+ old_page);
+ return old_page;
+ }
+
+ /* Disable broadcast */
+ ret = ytphy_write_ext(phydev, YT8831_MDIO_ADDRESS_CTL, 0x101f);
+ if (ret < 0)
+ goto err_restore_page;
+
+ /* Gloable Reset */
+ ret = ytphy_write_ext(phydev, YT8831_CHIP_MODE_SEL, 0x2000);
+ if (ret < 0)
+ goto err_restore_page;
+
+err_restore_page:
+ return phy_restore_page(phydev, old_page, ret);
+}
+
+/**
+ * yt8831_serdes_init() - serdes init
+ * @phydev: a pointer to a &struct phy_device
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt8831_serdes_init(struct phy_device *phydev)
+{
+ int old_page, ret;
+
+ ret = old_page = phy_select_page(phydev, YT8831_RSSR_FIBER_SPACE);
+ if (old_page < 0) {
+ phydev_err(phydev, "Failed to select page: %d\n",
+ old_page);
+ return old_page;
+ }
+
+ ret = ytphy_write_ext(phydev, YT8831_SDS_WRITE_PROTECT_REG, 0x1);
+ if (ret < 0)
+ goto err_restore_page;
+
+ ret = ytphy_write_ext(phydev, YT8831_SDS_SGMII_OUTPUT_REG, 0xc4);
+ if (ret < 0)
+ goto err_restore_page;
+
+ /* softreset sds space */
+ ret = __phy_modify(phydev, MII_BMCR, BMCR_RESET, BMCR_RESET);
+ if (ret < 0)
+ goto err_restore_page;
+
+err_restore_page:
+ return phy_restore_page(phydev, old_page, ret);
+}
+
+/**
+ * yt8831_utp_init() - utp init
+ * @phydev: a pointer to a &struct phy_device
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt8831_utp_init(struct phy_device *phydev)
+{
+ int ret;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_WRITE_PROTECT_REG, 0x3);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_DAC_DATA_DLY_REG, 0xc8d);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_REF_DLAY_SEL_REG, 0xa426);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_REF_DLAY_SEL_FEXT_REG, 0x8009);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_COE_MANUAL_SHIFT_SEL_2500_REG, 6);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_EEE_OPTIM_1_REG, 0x1001);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_EEE_OPTIM_2_REG, 0x7c52);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_EEE_MSE1_REG, 0x3848);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_EEE_MSE2_REG, 0xa8e8);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_EEE_OPTIM_3_REG, 0x5200);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_EEE_OPTIM_4_REG, 0x5849);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_EEE_OPTIM_5_REG, 0xb00a);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_EEE_OPTIM_6_REG, 0x3022);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_PSAN_OPTIM_REG, 0x1f10);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_1000M_TEMPLATE_OPTIM_1_REG, 0x22c8);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_1000M_TEMPLATE_OPTIM_2_REG, 0x2437);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_1000M_TEMPLATE_OPTIM_3_REG, 0x22c8);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_1000M_TEMPLATE_OPTIM_4_REG, 0x2437);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_1000M_TEMPLATE_OPTIM_5_REG, 0x22c8);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_1000M_TEMPLATE_OPTIM_6_REG, 0x2437);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_1000M_TEMPLATE_OPTIM_7_REG, 0x22c8);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_1000M_TEMPLATE_OPTIM_8_REG, 0x2437);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_2500M_TEMPLATE_OPTIM_1_REG, 0x1111);
+ if (ret < 0)
+ goto err;
+
+ ret = ytphy_write_ext_with_lock(phydev, YT8831_UTP_2500M_TEMPLATE_OPTIM_2_REG, 0x1111);
+ if (ret < 0)
+ goto err;
+
+err:
+ return ret;
+}
+
/**
* yt861x_config_init() - apply the auto sleep setting to the PHY
* @phydev: a pointer to a &struct phy_device
@@ -2992,6 +3280,37 @@ static int yt8821_soft_reset(struct phy_device *phydev)
YT8521_CCR_SW_RST, 0);
}
+/**
+ * yt8831_config_init() - phy initialisation
+ * @phydev: a pointer to a &struct phy_device
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt8831_config_init(struct phy_device *phydev)
+{
+ int ret;
+
+ __set_bit(PHY_INTERFACE_MODE_2500BASEX,
+ phydev->possible_interfaces);
+
+ __set_bit(PHY_INTERFACE_MODE_SGMII,
+ phydev->possible_interfaces);
+
+ ret = yt8831_top_init(phydev);
+ if (ret < 0)
+ return ret;
+
+ ret = yt8831_serdes_init(phydev);
+ if (ret < 0)
+ return ret;
+
+ ret = yt8831_utp_init(phydev);
+ if (ret < 0)
+ return ret;
+
+ return genphy_soft_reset(phydev);
+}
+
/**
* yt8821_config_init() - phy initializatioin
* @phydev: a pointer to a &struct phy_device
@@ -3102,6 +3421,53 @@ static void yt8821_update_interface(struct phy_device *phydev)
}
}
+/**
+ * yt8831_read_status() - determines the negotiated speed and duplex
+ * @phydev: a pointer to a &struct phy_device
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt8831_read_status(struct phy_device *phydev)
+{
+ int ret;
+ int val;
+
+ phydev->speed = SPEED_UNKNOWN;
+ phydev->duplex = DUPLEX_UNKNOWN;
+
+ ret = genphy_read_status(phydev);
+ if (ret < 0)
+ return ret;
+
+ ret = genphy_c45_read_status(phydev);
+ if (ret < 0)
+ return ret;
+
+ ret = phy_read(phydev, YTPHY_SPECIFIC_STATUS_REG);
+ if (ret < 0)
+ return ret;
+
+ val = ret;
+ if (val & YTPHY_SSR_LINK) {
+ phydev->link = true;
+ yt8821_adjust_status(phydev, val);
+ }
+
+ phydev_dbg(phydev,
+ "%s, phy addr: %d, link %s\n",
+ __func__, phydev->mdio.addr, phydev->link ? "up" : "down");
+
+ val = ytphy_read_ext_with_lock(phydev, YT8831_CHIP_MODE_SEL);
+ if (val < 0)
+ return val;
+
+ if (FIELD_GET(YT8521_CCR_MODE_SEL_MASK, val) ==
+ YT8821_CHIP_MODE_AUTO_BX2500_SGMII)
+ yt8821_update_interface(phydev);
+
+ return 0;
+}
+
/**
* yt8821_read_status() - determines the negotiated speed and duplex
* @phydev: a pointer to a &struct phy_device
@@ -3337,11 +3703,25 @@ static struct phy_driver motorcomm_phy_drvs[] = {
.suspend = yt8821_suspend,
.resume = yt8821_resume,
},
+ {
+ PHY_ID_MATCH_EXACT(PHY_ID_YT8831),
+ .name = "YT8831/YT8821-VD 2.5Gbps PHY",
+ .get_features = yt8821_get_features,
+ .read_page = yt8831_read_page,
+ .write_page = yt8831_write_page,
+ .config_aneg = yt8831_config_aneg,
+ .aneg_done = genphy_aneg_done,
+ .config_init = yt8831_config_init,
+ .read_status = yt8831_read_status,
+ .soft_reset = genphy_soft_reset,
+ .suspend = genphy_suspend,
+ .resume = genphy_resume,
+ },
};
module_phy_driver(motorcomm_phy_drvs);
-MODULE_DESCRIPTION("Motorcomm 8511/8521/8531/8531S/861x/8821 PHY driver");
+MODULE_DESCRIPTION("Motorcomm 8511/8521/8531/8531S/861x/8821/8831 PHY driver");
MODULE_AUTHOR("Peter Geis");
MODULE_AUTHOR("Frank");
MODULE_LICENSE("GPL");
@@ -3354,6 +3734,7 @@ static const struct mdio_device_id __maybe_unused motorcomm_tbl[] = {
{ PHY_ID_MATCH_EXACT(PHY_ID_YT8531S) },
{ PHY_ID_MATCH_EXACT(PHY_ID_INT861X) },
{ PHY_ID_MATCH_EXACT(PHY_ID_YT8821) },
+ { PHY_ID_MATCH_EXACT(PHY_ID_YT8831) },
{ /* sentinel */ }
};
--
2.43.0