[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <20260121151506.813783-4-dam.dejean@gmail.com>
Date: Wed, 21 Jan 2026 16:15:06 +0100
From: Damien Dejean <dam.dejean@...il.com>
To: andrew@...n.ch,
krzk+dt@...nel.org
Cc: netdev@...r.kernel.org,
devicetree@...r.kernel.org,
linux-kernel@...r.kernel.org,
edumazet@...gle.com,
davem@...emloft.net,
kuba@...nel.org,
pabeni@...hat.com,
hkallweit1@...il.com,
Damien Dejean <dam.dejean@...il.com>
Subject: [PATCH v2 4/4] net: phy: realtek: add RTL8224 polarity support
The RTL8224 has a register to configure the polarity of every pair of
each port. It provides device designers more flexbility when wiring the
chip.
Unfortunately, the register is left in an unknown state after a reset.
Thus on devices where the bootloader don't initialize it, the driver has
to do it to detect and use a link.
The MDI polarity swap can be set in the device tree using the property
realtek,mdi-cfg-polarity. The u32 value is a bitfield where bit[0..3]
control the polarity of pairs A..D.
Signed-off-by: Damien Dejean <dam.dejean@...il.com>
---
drivers/net/phy/realtek/realtek_main.c | 39 +++++++++++++++++++++++++-
1 file changed, 38 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
index 85b0eea936e4..d2dc4f7a1971 100644
--- a/drivers/net/phy/realtek/realtek_main.c
+++ b/drivers/net/phy/realtek/realtek_main.c
@@ -164,6 +164,7 @@
#define RTL8224_SRAM_RTCT_LEN(pair) (0x8028 + (pair) * 4)
#define RTL8224_VND1_MDI_PAIR_SWAP 0xa90
+#define RTL8224_VND1_MDI_POLARITY_SWAP 0xa94
#define RTL8366RB_POWER_SAVE 0x15
#define RTL8366RB_POWER_SAVE_ON BIT(12)
@@ -1719,9 +1720,45 @@ static int rtl8224_mdi_config_order(struct phy_device *phydev)
RTL8224_VND1_MDI_PAIR_SWAP, val);
}
+static int rtl8224_mdi_config_polarity(struct phy_device *phydev)
+{
+ struct device_node *np = phydev->mdio.dev.of_node;
+ u8 port_offset = phydev->mdio.addr & 3;
+ u32 polarity, val;
+ int ret;
+
+ ret = of_property_read_u32(np, "realtek,mdi-cfg-polarity", &polarity);
+
+ /* Do nothing if the property is not present */
+ if (ret == -EINVAL)
+ return 0;
+
+ if (!ret)
+ return ret;
+
+ if (polarity & ~0xf)
+ return -EINVAL;
+
+ val = __phy_package_read_mmd(phydev, 0, MDIO_MMD_VEND1,
+ RTL8224_VND1_MDI_POLARITY_SWAP);
+ if (val < 0)
+ return val;
+
+ val &= ~(0xf << port_offset);
+ val |= polarity << port_offset;
+ return __phy_package_write_mmd(phydev, 0, MDIO_MMD_VEND1,
+ RTL8224_VND1_MDI_POLARITY_SWAP, val);
+}
+
static int rtl8224_config_init(struct phy_device *phydev)
{
- return rtl8224_mdi_config_order(phydev);
+ int ret;
+
+ ret = rtl8224_mdi_config_order(phydev);
+ if (!ret)
+ return ret;
+
+ return rtl8224_mdi_config_polarity(phydev);
}
static int rtl8224_probe(struct phy_device *phydev)
--
2.47.3
Powered by blists - more mailing lists