Thread View: linux.kernel.netdev
13 messages
13 total messages
Started by "Frank.sae"
Wed, 18 Nov 2026 03:35
[PATCH net-next v3] net: phy: motorcomm: add YT8831 2.5G PHY support
Author: "Frank.sae"
Date: Wed, 18 Nov 2026 03:35
Date: Wed, 18 Nov 2026 03:35
701 lines
27488 bytes
27488 bytes
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
interface, supports 2.5G/1000M/100M/10M speeds, and WoL(magic packet).
Signed-off-by: Frank.sae <frank.sae@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
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/20261109064332.3381180-1-frank.sae@motor-comm.com/
v1:
Link: https://lore.kernel.org/all/20261022054642.1332801-1-frank.sae@motor-comm.com/
---
drivers/net/phy/motorcomm.c | 554 +++++++++++++++++++++++++++++++++++-
1 file changed, 552 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index a87e83fdf590..52d2b2efc6f5 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 <pgwipeout@gmail.com>
* Author: Frank <Frank.Sae@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,11 @@
#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 YT8521_CHIP_CONFIG_REG 0xA001
#define YT8521_CCR_SW_RST BIT(15)
#define YT8531_RGMII_LDO_VOL_MASK GENMASK(5, 4)
@@ -258,6 +264,52 @@
#define YTPHY_WCR_INTR_SEL BIT(6)
#define YTPHY_WCR_ENABLE BIT(3)
+#define YT8831_WOL_CONFIG_REG 0x160a
+#define YT8831_WOL_ENABLE_MASK BIT(0)
+#define YT8831_WOL_ENABLE BIT(0)
+#define YT8831_WOL_DISABLE 0x0
+#define YT8831_WOL_PULSE_WIDTH_MASK (BIT(3) | BIT(2))
+#define YT8831_WOL_PULSE_WIDTH_168MS BIT(2)
+#define YT8831_WOL_OUTPUT_TYPE_SEL_MASK BIT(1)
+#define YT8831_WOL_OUTPUT_TYPE_SEL_PULSE BIT(1)
+
+#define YT8831_WOL_MACADDR2_REG 0x1604
+#define YT8831_WOL_MACADDR1_REG 0x1606
+#define YT8831_WOL_MACADDR0_REG 0x1608
+
+#define YT8831_WCR_INTR_REG 0x8301
+#define YT8831_WCR_INTR_SEL_MASK (BIT(1) | BIT(0))
+#define YT8831_WCR_INTR_SEL_WOL_ONLY 0x2
+#define YT8831_WCR_INTR_SEL_ALL 0x1
+
+#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 +449,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
@@ -543,6 +605,29 @@ static int ytphy_modify_ext_with_lock(struct phy_device *phydev, u16 regnum,
return ret;
}
+/**
+ * yt8831_get_wol() - report whether wake-on-lan is enabled
+ * @phydev: a pointer to a &struct phy_device
+ * @wol: a pointer to a &struct ethtool_wolinfo
+ *
+ * NOTE: YT8831_WOL_CONFIG_REG is common ext reg.
+ */
+static void yt8831_get_wol(struct phy_device *phydev,
+ struct ethtool_wolinfo *wol)
+{
+ int wol_config;
+
+ wol->supported = WAKE_MAGIC;
+ wol->wolopts = 0;
+
+ wol_config = ytphy_read_ext_with_lock(phydev, YT8831_WOL_CONFIG_REG);
+ if (wol_config < 0)
+ return;
+
+ if (wol_config & YT8831_WOL_ENABLE_MASK)
+ wol->wolopts |= WAKE_MAGIC;
+}
+
/**
* ytphy_get_wol() - report whether wake-on-lan is enabled
* @phydev: a pointer to a &struct phy_device
@@ -704,6 +789,83 @@ static int yt8531_set_wol(struct phy_device *phydev,
return 0;
}
+/**
+ * yt8831_set_wol() - turn wake-on-lan on or off
+ * @phydev: a pointer to a &struct phy_device
+ * @wol: a pointer to a &struct ethtool_wolinfo
+ *
+ * NOTE: YT8831_WOL_CONFIG_REG is common ext reg.
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt8831_set_wol(struct phy_device *phydev,
+ struct ethtool_wolinfo *wol)
+{
+ const u16 mac_addr_reg[] = {
+ YT8831_WOL_MACADDR2_REG,
+ YT8831_WOL_MACADDR1_REG,
+ YT8831_WOL_MACADDR0_REG,
+ };
+ const u8 *mac_addr;
+ u16 mask, val;
+ int ret;
+ u8 i;
+
+ if (!phydev->attached_dev)
+ return -ENODEV;
+ if (!is_valid_ether_addr(phydev->attached_dev->dev_addr))
+ return -EINVAL;
+
+ if (wol->wolopts & WAKE_MAGIC) {
+ mac_addr = phydev->attached_dev->dev_addr;
+
+ /* Store the device address for the magic packet */
+ for (i = 0; i < 3; i++) {
+ ret = ytphy_write_ext_with_lock(phydev, mac_addr_reg[i],
+ ((mac_addr[i * 2] << 8)) |
+ (mac_addr[i * 2 + 1]));
+ if (ret < 0)
+ return ret;
+ }
+
+ /* Enable WOL feature */
+ mask = YT8831_WOL_ENABLE_MASK
+ | YT8831_WOL_PULSE_WIDTH_MASK
+ | YT8831_WOL_OUTPUT_TYPE_SEL_MASK;
+
+ val = YT8831_WOL_ENABLE
+ | YT8831_WOL_PULSE_WIDTH_168MS
+ | YT8831_WOL_OUTPUT_TYPE_SEL_PULSE;
+
+ ret = ytphy_modify_ext_with_lock(phydev, YT8831_WOL_CONFIG_REG,
+ mask, val);
+ if (ret < 0)
+ return ret;
+
+ /* Enable WOL interrupt */
+ ret = ytphy_modify_ext_with_lock(phydev, YT8831_WCR_INTR_REG,
+ YT8831_WCR_INTR_SEL_MASK,
+ YT8831_WCR_INTR_SEL_WOL_ONLY);
+ if (ret < 0)
+ return ret;
+ } else {
+ /* Disable WOL feature */
+ mask = YT8831_WOL_ENABLE_MASK;
+ ret = ytphy_modify_ext_with_lock(phydev, YT8831_WOL_CONFIG_REG,
+ mask, YT8831_WOL_DISABLE);
+ if (ret < 0)
+ return ret;
+
+ /* Disable WOL interrupt */
+ ret = ytphy_modify_ext_with_lock(phydev, YT8831_WCR_INTR_REG,
+ YT8831_WCR_INTR_SEL_MASK, YT8831_WCR_INTR_SEL_ALL);
+ if (ret < 0)
+ return ret;
+ }
+
+ return 0;
+}
+
static int yt8511_read_page(struct phy_device *phydev)
{
return __phy_read(phydev, YT8511_PAGE_SELECT);
@@ -798,6 +960,27 @@ 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;
+
+ if ((old_page & YT8831_RSSR_SPACE_MASK) == YT8831_RSSR_FIBER_SPACE)
+ return YT8831_RSSR_FIBER_SPACE;
+
+ return YT8831_RSSR_UTP_SPACE;
+};
+
/**
* yt8521_write_page() - write reg page
* @phydev: a pointer to a &struct phy_device
@@ -818,6 +1001,26 @@ 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)
+{
+ int mask = YT8831_RSSR_SPACE_MASK;
+ int set;
+
+ if ((page & YT8831_RSSR_SPACE_MASK) == YT8831_RSSR_FIBER_SPACE)
+ set = YT8831_RSSR_FIBER_SPACE;
+ else
+ set = YT8831_RSSR_UTP_SPACE;
+
+ return ytphy_modify_ext(phydev, YT8831_REG_SPACE_SELECT_REG, mask, set);
+};
+
/**
* struct ytphy_cfg_reg_map - map a config value to a register value
* @cfg: value in device configuration
@@ -2554,6 +2757,184 @@ static int yt8521_get_features(struct phy_device *phydev)
return ret;
}
+static int yt8831_config_aneg(struct phy_device *phydev)
+{
+ int ret;
+
+ ret = genphy_config_aneg(phydev);
+ if (ret < 0)
+ return ret;
+
+ return genphy_c45_config_aneg(phydev);
+}
+
+/**
+ * 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;
+
+ 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);
+ goto err_restore_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;
+}
+
+/**
+ * yt8831_get_rate_matching - read register to get phy chip mode
+ * @phydev: target phy_device struct
+ * @iface: PHY data interface type
+ *
+ * Returns: rate matching type or negative errno code
+ */
+static int yt8831_get_rate_matching(struct phy_device *phydev,
+ phy_interface_t iface)
+{
+ int val;
+
+ val = ytphy_read_ext_with_lock(phydev, YT8831_CHIP_MODE_SEL);
+ if (val < 0)
+ return val;
+
+ if (FIELD_GET(YT8831_CHIP_MODE_SEL_MASK, val) ==
+ YT8831_CHIP_MODE_FORCE_2500BASEX)
+ return RATE_MATCH_PAUSE;
+
+ return RATE_MATCH_NONE;
+}
+
/**
* yt861x_config_init() - apply the auto sleep setting to the PHY
* @phydev: a pointer to a &struct phy_device
@@ -2992,6 +3373,65 @@ 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)
+{
+ u8 mode = YT8831_CHIP_MODE_AUTO_BX2500_SGMII;
+ int ret;
+
+
+ __set_bit(PHY_INTERFACE_MODE_2500BASEX,
+ phydev->possible_interfaces);
+
+ __set_bit(PHY_INTERFACE_MODE_SGMII,
+ phydev->possible_interfaces);
+
+ switch (phydev->interface) {
+ case PHY_INTERFACE_MODE_2500BASEX:
+ mode = YT8831_CHIP_MODE_FORCE_2500BASEX;
+ phydev->rate_matching = RATE_MATCH_PAUSE;
+ break;
+ case PHY_INTERFACE_MODE_SGMII:
+ mode = YT8831_CHIP_MODE_AUTO_BX2500_SGMII;
+ phydev->rate_matching = RATE_MATCH_NONE;
+ break;
+ default:
+ mode = YT8831_CHIP_MODE_AUTO_BX2500_SGMII;
+ phydev->rate_matching = RATE_MATCH_NONE;
+ break;
+ }
+
+ ret = ytphy_modify_ext_with_lock(phydev,
+ YT8831_CHIP_MODE_SEL,
+ YT8831_CHIP_MODE_SEL_MASK,
+ mode);
+ if (ret < 0)
+ return ret;
+
+ /* Disable broadcast*/
+ ret = ytphy_modify_ext_with_lock(phydev,
+ YT8831_MDIO_ADDRESS_CTL,
+ YT8831_MDIO_ADDRESS_CTL_EN_BROADCAST_MASK,
+ 0);
+ 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 +3542,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(YT8831_CHIP_MODE_SEL_MASK, val) ==
+ YT8831_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
@@ -3190,6 +3677,28 @@ static int yt8821_modify_utp_fiber_bmcr(struct phy_device *phydev,
mask, set);
}
+/**
+ * yt8831_suspend() - suspend the hardware
+ * @phydev: a pointer to a &struct phy_device
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt8831_suspend(struct phy_device *phydev)
+{
+ struct ethtool_wolinfo wol = {0};
+ int ret;
+
+ yt8831_get_wol(phydev, &wol);
+
+ /* if wol enable, do nothing */
+ if (wol.wolopts & WAKE_MAGIC)
+ ret = 0;
+ else
+ ret = genphy_suspend(phydev);
+
+ return ret;
+}
+
/**
* yt8821_suspend() - suspend the hardware
* @phydev: a pointer to a &struct phy_device
@@ -3212,6 +3721,29 @@ static int yt8821_suspend(struct phy_device *phydev)
return yt8821_modify_utp_fiber_bmcr(phydev, 0, BMCR_PDOWN);
}
+/**
+ * yt8831_resume() - resume the hardware
+ * @phydev: a pointer to a &struct phy_device
+ *
+ * Returns: 0 or negative errno code
+ */
+static int yt8831_resume(struct phy_device *phydev)
+{
+ struct ethtool_wolinfo wol = {0};
+ int ret;
+
+ yt8831_get_wol(phydev, &wol);
+
+ /* if wol enable, do nothing */
+ if (wol.wolopts & WAKE_MAGIC)
+ ret = 0;
+ else
+ ret = genphy_resume(phydev);
+
+ return ret;
+}
+
+
/**
* yt8821_resume() - resume the hardware
* @phydev: a pointer to a &struct phy_device
@@ -3337,11 +3869,28 @@ 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,
+ .get_wol = yt8831_get_wol,
+ .set_wol = yt8831_set_wol,
+ .config_aneg = yt8831_config_aneg,
+ .aneg_done = genphy_aneg_done,
+ .config_init = yt8831_config_init,
+ .get_rate_matching = yt8831_get_rate_matching,
+ .read_status = yt8831_read_status,
+ .soft_reset = genphy_soft_reset,
+ .suspend = yt8831_suspend,
+ .resume = yt8831_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 +3903,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
Re: [PATCH net-next v3] net: phy: motorcomm: add YT8831 2.5G PHY support
Author: Andrew Lunn
Date: Wed, 18 Nov 2026 14:14
Date: Wed, 18 Nov 2026 14:14
18 lines
8800 bytes
8800 bytes
On Wed, Nov 18, 2026 at 03:35:39AM +0000, Frank.sae wrote:
> 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
> interface, supports 2.5G/1000M/100M/10M speeds, and WoL(magic packet).
Please break the patch up. Add basic support as a patch, then
downshift and WoL as additional patches.
The WoL code looks wrong, i don't see any calls to
device_may_wakeup(), device_set_wakeup_capable() etc.
Andrew
---
pw-bot: cr
Re: [PATCH net-next v3] net: phy: motorcomm: add YT8831 2.5G PHY support
Author: Andrew Lunn
Date: Wed, 18 Nov 2026 14:17
Date: Wed, 18 Nov 2026 14:17
7 lines
8362 bytes
8362 bytes
> + case PHY_INTERFACE_MODE_SGMII:
> + mode = YT8831_CHIP_MODE_AUTO_BX2500_SGMII;
What exactly is AUTO_BX2500_SGMII and how does it differ from SGMII?
Andrew
Re: [PATCH net-next v3] net: phy: motorcomm: add YT8831 2.5G PHY support
Author: "Frank.sae"
Date: Thu, 19 Nov 2026 05:56
Date: Thu, 19 Nov 2026 05:56
28 lines
8607 bytes
8607 bytes
> Please break the patch up. Add basic support as a patch, then > downshift and WoL as additional patches. > > The WoL code looks wrong, i don't see any calls to > device_may_wakeup(), device_set_wakeup_capable() etc. > > What exactly is AUTO_BX2500_SGMII and how does it differ from SGMII? Hi Andrew, Thanks for your review. I have split the submission: This v4 only contains basic YT8831 PHY support. Downshift is not implemented for YT8831 at this time. WoL support is removed from this series; I will fix the wakeup API handling (device_set_wakeup_capable() / device_may_wakeup()) and send WoL as a separate follow-up patch later. AUTO_BX2500_SGMII is YT8831 chip-specific mode: When operating in AUTO_BX2500_SGMII mode, the YT8831 adjusts the PHY media side to 2500-BaseX or SGMII based on the connection speed on the PHY UTP side. 1. Media: 2500BX – UTP: 2.5G 2. Media: SGMII – UTP: 1000M/100M/10M Differnece from SGMII is it also includes the 2500-BaseX mode, which is switched automatically. The v4 basic support patch will follow shortly. Frank
Re: [PATCH net-next v3] net: phy: motorcomm: add YT8831 2.5G PHY support
Author: kernel test robot
Date: Thu, 19 Nov 2026 06:42
Date: Thu, 19 Nov 2026 06:42
87 lines
12730 bytes
12730 bytes
Hi Frank.sae,
kernel test robot noticed the following build warnings:
[auto build test WARNING on net-next/main]
url: https://github.com/intel-lab-lkp/linux/commits/Frank-sae/net-phy-motorcomm-add-YT8831-2-5G-PHY-support/20261118-033539
base: net-next/main
patch link: https://lore.kernel.org/r/20261118033539.36633-1-frank.sae%40motor-comm.com
patch subject: [PATCH net-next v3] net: phy: motorcomm: add YT8831 2.5G PHY support
config: loongarch-defconfig (https://download.01.org/0day-ci/archive/20261119/202611191438.hJl6vCfi-lkp@intel.com/config)
compiler: clang version 24.0.0git (https://github.com/llvm/llvm-project 3b14d7c370558b46e5f0c6494a05c492e59bf32c)
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20261119/202611191438.hJl6vCfi-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202611191438.hJl6vCfi-lkp@intel.com/
All warnings (new ones prefixed by >>):
>> drivers/net/phy/motorcomm.c:2782:6: warning: variable 'ret' is used uninitialized whenever 'if' condition is true [-Wsometimes-uninitialized]
2782 | if (old_page < 0) {
| ^~~~~~~~~~~~
drivers/net/phy/motorcomm.c:2802:44: note: uninitialized use occurs here
2802 | return phy_restore_page(phydev, old_page, ret);
| ^~~
drivers/net/phy/motorcomm.c:2782:2: note: remove the 'if' if its condition is always false
2782 | if (old_page < 0) {
| ^~~~~~~~~~~~~~~~~~~
2783 | phydev_err(phydev, "Failed to select page: %d\n",
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2784 | old_page);
| ~~~~~~~~~~
2785 | goto err_restore_page;
| ~~~~~~~~~~~~~~~~~~~~~~
2786 | }
| ~
drivers/net/phy/motorcomm.c:2779:19: note: initialize the variable 'ret' to silence this warning
2779 | int old_page, ret;
| ^
| = 0
1 warning generated.
vim +2782 drivers/net/phy/motorcomm.c
2770
2771 /**
2772 * yt8831_serdes_init() - serdes init
2773 * @phydev: a pointer to a &struct phy_device
2774 *
2775 * Returns: 0 or negative errno code
2776 */
2777 static int yt8831_serdes_init(struct phy_device *phydev)
2778 {
2779 int old_page, ret;
2780
2781 old_page = phy_select_page(phydev, YT8831_RSSR_FIBER_SPACE);
> 2782 if (old_page < 0) {
2783 phydev_err(phydev, "Failed to select page: %d\n",
2784 old_page);
2785 goto err_restore_page;
2786 }
2787
2788 ret = ytphy_write_ext(phydev, YT8831_SDS_WRITE_PROTECT_REG, 0x1);
2789 if (ret < 0)
2790 goto err_restore_page;
2791
2792 ret = ytphy_write_ext(phydev, YT8831_SDS_SGMII_OUTPUT_REG, 0xc4);
2793 if (ret < 0)
2794 goto err_restore_page;
2795
2796 /* softreset sds space */
2797 ret = __phy_modify(phydev, MII_BMCR, BMCR_RESET, BMCR_RESET);
2798 if (ret < 0)
2799 goto err_restore_page;
2800
2801 err_restore_page:
2802 return phy_restore_page(phydev, old_page, ret);
2803 }
2804
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
Re: [PATCH net-next v3] net: phy: motorcomm: add YT8831 2.5G PHY support
Author: Andrew Lunn
Date: Thu, 19 Nov 2026 13:14
Date: Thu, 19 Nov 2026 13:14
40 lines
10116 bytes
10116 bytes
On Thu, Nov 19, 2026 at 05:56:45AM +0000, Frank.sae wrote: > > Please break the patch up. Add basic support as a patch, then > > downshift and WoL as additional patches. > > > > The WoL code looks wrong, i don't see any calls to > > device_may_wakeup(), device_set_wakeup_capable() etc. > > > > What exactly is AUTO_BX2500_SGMII and how does it differ from SGMII? > > Hi Andrew, > > Thanks for your review. > > I have split the submission: > This v4 only contains basic YT8831 PHY support. > Downshift is not implemented for YT8831 at this time. > WoL support is removed from this series; I will fix the wakeup API handling > (device_set_wakeup_capable() / device_may_wakeup()) and send WoL as a separate follow-up patch later. > > AUTO_BX2500_SGMII is YT8831 chip-specific mode: > When operating in AUTO_BX2500_SGMII mode, the YT8831 adjusts the PHY media side to 2500-BaseX or SGMII based on the connection speed on the PHY UTP side. > 1. Media: 2500BX – UTP: 2.5G > 2. Media: SGMII – UTP: 1000M/100M/10M > Differnece from SGMII is it also includes the 2500-BaseX mode, which is switched automatically. Ah, O.K. Most multi-gige PHYs do this. Basically there are two different ways it can work: * The host side changes with the media side. When the link goes up, read_settings needs to set phydev->interface. See mv3310_update_interface() as an example. * The PHY performs rate adaptation. The host side runs at a fixed speed, e.g. 2500BaseX. The PHY then rebuilds the frames it gets from the MAC, buffers them, and then sends them out the media at the speed negotiated. Pause frames are used to slow down the MAC so the buffers in the PHY don't overflow. Andrew
Re: [PATCH net-next v3] net: phy: motorcomm: add YT8831 2.5G PHY support
Author: "Frank.sae"
Date: Mon, 23 Nov 2026 06:47
Date: Mon, 23 Nov 2026 06:47
45 lines
9376 bytes
9376 bytes
> > > Please break the patch up. Add basic support as a patch, then > > > downshift and WoL as additional patches. > > > > > > The WoL code looks wrong, i don't see any calls to > > > device_may_wakeup(), device_set_wakeup_capable() etc. > > > > > > What exactly is AUTO_BX2500_SGMII and how does it differ from SGMII? > > > > Hi Andrew, > > > > Thanks for your review. > > > > I have split the submission: > > This v4 only contains basic YT8831 PHY support. > > Downshift is not implemented for YT8831 at this time. > > WoL support is removed from this series; I will fix the wakeup API handling > >(device_set_wakeup_capable() / device_may_wakeup()) and send WoL as a separate follow-up patch later. > > > > AUTO_BX2500_SGMII is YT8831 chip-specific mode: > > When operating in AUTO_BX2500_SGMII mode, the YT8831 adjusts the PHY media side to 2500-BaseX or SGMII based on the connection speed on the PHY UTP side. > > 1. Media: 2500BX – UTP: 2.5G > > 2. Media: SGMII – UTP: 1000M/100M/10M > > Differnece from SGMII is it also includes the 2500-BaseX mode, which is switched automatically. > Ah, O.K. Most multi-gige PHYs do this. Basically there are two >different ways it can work: > > * The host side changes with the media side. When the link goes up, > read_settings needs to set phydev->interface. See > mv3310_update_interface() as an example. > > * The PHY performs rate adaptation. The host side runs at a fixed > speed, e.g. 2500BaseX. The PHY then rebuilds the frames it gets from > the MAC, buffers them, and then sends them out the media at the > speed negotiated. Pause frames are used to slow down the MAC so the > buffers in the PHY don't overflow. Hi Andrew, Thank you for your guidance. I will update patch v5 based on the way of 'mv3310_update_interface' Frank
[PATCH net-next v5 0/1] net: phy: motorcomm: add YT8831 2.5G PHY basic support
Author: "Frank.sae"
Date: Thu, 26 Nov 2026 06:46
Date: Thu, 26 Nov 2026 06:46
27 lines
8249 bytes
8249 bytes
This is v5 series adding Motorcomm YT8831 2.5G PHY basic support. The series only includes basic PHY driver now. WoL and downshift features will be submitted as separate follow-up patches later, as Andrew suggested. Patch 1: net: phy: motorcomm: add YT8831 2.5G PHY basic support Changes v5: - As suggested by Andrew, when in AUTO_BX2500_SGMII mode, modify phy->interface in .read_status to trigger host to handle media side correctly. - Add YT8831_RSSR_TOP_SPACE definition for read/write_page access. Tested on BPI-R3 with MediaTek SoC. Thanks, Frank.sae Frank.sae (1): net: phy: motorcomm: add YT8831 2.5G PHY basic support drivers/net/phy/motorcomm.c | 370 +++++++++++++++++++++++++++++++++++- 1 file changed, 368 insertions(+), 2 deletions(-) -- 2.43.0
[PATCH net-next v5 1/1] net: phy: motorcomm: add YT8831 2.5G PHY basic support
Author: "Frank.sae"
Date: Thu, 26 Nov 2026 06:46
Date: Thu, 26 Nov 2026 06:46
496 lines
22534 bytes
22534 bytes
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 <frank.sae@motor-comm.com>
---
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.
v4:
- Remove WoL support for now, it will be submitted in follow-up patch
Link: https://lore.kernel.org/netdev/20261119055947.653568-2-frank.sae@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/20261118033539.36633-1-frank.sae@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/20261109064332.3381180-1-frank.sae@motor-comm.com/
v1:
Link: https://lore.kernel.org/all/20261022054642.1332801-1-frank.sae@motor-comm.com/
---
drivers/net/phy/motorcomm.c | 370 +++++++++++++++++++++++++++++++++++-
1 file changed, 368 insertions(+), 2 deletions(-)
diff --git a/drivers/net/phy/motorcomm.c b/drivers/net/phy/motorcomm.c
index a87e83fdf590..93d541d86a52 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 <pgwipeout@gmail.com>
* Author: Frank <Frank.Sae@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,198 @@ 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)
+{
+ int ret;
+
+ ret = genphy_config_aneg(phydev);
+ if (ret < 0)
+ return ret;
+
+ return genphy_c45_config_aneg(phydev);
+}
+
+/**
+ * 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 +3265,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 +3406,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 +3688,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 +3719,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
Re: [PATCH net-next v5 1/1] net: phy: motorcomm: add YT8831 2.5G PHY basic support
Author: Andrew Lunn
Date: Sun, 29 Nov 2026 16:45
Date: Sun, 29 Nov 2026 16:45
21 lines
8737 bytes
8737 bytes
> +/**
> + * 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)
> +{
> + int ret;
> +
> + ret = genphy_config_aneg(phydev);
> + if (ret < 0)
> + return ret;
> +
> + return genphy_c45_config_aneg(phydev);
That looks odd. So you restart the autoneg twice? Are there any other
PHY drivers which do this?
Andrew
[PATCH net-next v6 0/1] net: phy: motorcomm: add YT8831 2.5G PHY basic support
Author: "Frank.sae"
Date: Mon, 30 Nov 2026 08:32
Date: Mon, 30 Nov 2026 08:32
27 lines
8476 bytes
8476 bytes
Hi Andrew, Thanks for your review. YT8831 uses C22 for auto-negotiation itself. The C45 MMD space is only used to configure 2.5G capability bits, not for Clause45 autoneg. Calling genphy_c45_config_aneg() was wrong and caused AN restart twice. This v6 fixes that issue, we keep __genphy_config_aneg() for C22 AN, and use explicit phy_write_mmd() to set 2.5G advertisement capability which is following `rtl822x_config_aneg` This is v6 adding Motorcomm YT8831 2.5G PHY basic support. Changes since v5: - 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. This avoids double autoneg restart. Patch 1: net: phy: motorcomm: add YT8831 2.5G PHY basic support Frank.sae (1): net: phy: motorcomm: add YT8831 2.5G PHY basic support drivers/net/phy/motorcomm.c | 385 +++++++++++++++++++++++++++++++++++- 1 file changed, 383 insertions(+), 2 deletions(-) -- 2.43.0
[PATCH net-next v6 1/1] net: phy: motorcomm: add YT8831 2.5G PHY basic support
Author: "Frank.sae"
Date: Mon, 30 Nov 2026 08:32
Date: Mon, 30 Nov 2026 08:32
516 lines
23444 bytes
23444 bytes
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 <frank.sae@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/20261126064622.2757584-2-frank.sae@motor-comm.com/
v4:
- Remove WoL support for now, it will be submitted in follow-up patch
Link: https://lore.kernel.org/netdev/20261119055947.653568-2-frank.sae@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/20261118033539.36633-1-frank.sae@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/20261109064332.3381180-1-frank.sae@motor-comm.com/
v1:
Link: https://lore.kernel.org/all/20261022054642.1332801-1-frank.sae@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 <pgwipeout@gmail.com>
* Author: Frank <Frank.Sae@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
Re: [PATCH net-next v6 1/1] net: phy: motorcomm: add YT8831 2.5G PHY basic support
Author: Andrew Lunn
Date: Mon, 30 Nov 2026 13:09
Date: Mon, 30 Nov 2026 13:09
13 lines
8646 bytes
8646 bytes
On Mon, Nov 30, 2026 at 08:32:53AM +0000, Frank.sae wrote:
> 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 <frank.sae@motor-comm.com>
Reviewed-by: Andrew Lunn <andrew@lunn.ch>
Andrew
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads