summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakub Kicinski <kuba@kernel.org>2026-03-21 05:12:48 +0300
committerJakub Kicinski <kuba@kernel.org>2026-03-21 05:12:48 +0300
commitfa782d4df0b7fa5f3f9d2d7d74f422004487836c (patch)
treec0f3a5d9180522dadd58026b0a441d67ac8ec3cc
parent82a5852595f5afb36aebddcc3ebc2654ee4d3879 (diff)
parentbeed9c0e9b53c98bc66d28d46fbe38c347e9aa74 (diff)
downloadlinux-fa782d4df0b7fa5f3f9d2d7d74f422004487836c.tar.xz
Merge branch 'net-phy-realtek-pair-order-and-polarity'
Damien Dejean says: ==================== net: phy: realtek: pair order and polarity The RTL8224 PHY gives the manufacturer some flexbility with the pair order and polarity to ease the wiring on the PCB. Then the correct pair order and pair polarity must be provided to the PHY to function properly. This series adds the support to configure the pair order and the pair polarity to the Realtek PHY driver. ==================== Link: https://patch.msgid.link/20260318215502.106528-1-dam.dejean@gmail.com Signed-off-by: Jakub Kicinski <kuba@kernel.org>
-rw-r--r--Documentation/devicetree/bindings/net/ethernet-phy.yaml14
-rw-r--r--drivers/net/phy/realtek/Kconfig1
-rw-r--r--drivers/net/phy/realtek/realtek_main.c96
3 files changed, 111 insertions, 0 deletions
diff --git a/Documentation/devicetree/bindings/net/ethernet-phy.yaml b/Documentation/devicetree/bindings/net/ethernet-phy.yaml
index 58634fee9fc4..21a1a63506f0 100644
--- a/Documentation/devicetree/bindings/net/ethernet-phy.yaml
+++ b/Documentation/devicetree/bindings/net/ethernet-phy.yaml
@@ -126,6 +126,20 @@ properties:
e.g. wrong bootstrap configuration caused by issues in PCB
layout design.
+ enet-phy-pair-order:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ enum: [0, 1]
+ description:
+ For normal (0) or reverse (1) order of the pairs (ABCD -> DCBA).
+
+ enet-phy-pair-polarity:
+ $ref: /schemas/types.yaml#/definitions/uint32
+ maximum: 0xf
+ description:
+ A bitmap to describe pair polarity swap. Bit 0 to swap polarity of pair A,
+ bit 1 to swap polarity of pair B, bit 2 to swap polarity of pair C and bit
+ 3 to swap polarity of pair D.
+
eee-broken-100tx:
$ref: /schemas/types.yaml#/definitions/flag
description:
diff --git a/drivers/net/phy/realtek/Kconfig b/drivers/net/phy/realtek/Kconfig
index b05c2a1e9024..a741b34d193e 100644
--- a/drivers/net/phy/realtek/Kconfig
+++ b/drivers/net/phy/realtek/Kconfig
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
config REALTEK_PHY
tristate "Realtek PHYs"
+ select PHY_PACKAGE
help
Currently supports RTL821x/RTL822x and fast ethernet PHYs
diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
index 530b4e26d16e..023e47ad605b 100644
--- a/drivers/net/phy/realtek/realtek_main.c
+++ b/drivers/net/phy/realtek/realtek_main.c
@@ -171,6 +171,9 @@
#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)
@@ -1820,6 +1823,97 @@ static int rtl8224_cable_test_get_status(struct phy_device *phydev, bool *finish
return rtl8224_cable_test_report(phydev, finished);
}
+static int rtl8224_package_modify_mmd(struct phy_device *phydev, int devad,
+ u32 regnum, u16 mask, u16 set)
+{
+ int val, ret;
+
+ phy_lock_mdio_bus(phydev);
+
+ val = __phy_package_read_mmd(phydev, 0, devad, regnum);
+ if (val < 0) {
+ ret = val;
+ goto exit;
+ }
+
+ val &= ~mask;
+ val |= set;
+
+ ret = __phy_package_write_mmd(phydev, 0, devad, regnum, val);
+
+exit:
+ phy_unlock_mdio_bus(phydev);
+ return ret;
+}
+
+static int rtl8224_mdi_config_order(struct phy_device *phydev)
+{
+ struct device_node *np = phydev->mdio.dev.of_node;
+ u8 port_offset = phydev->mdio.addr & 3;
+ u32 order = 0;
+ int ret;
+
+ ret = of_property_read_u32(np, "enet-phy-pair-order", &order);
+
+ /* Do nothing in case the property is not present */
+ if (ret == -EINVAL || ret == -ENOSYS)
+ return 0;
+
+ if (ret)
+ return ret;
+
+ if (order & ~1)
+ return -EINVAL;
+
+ return rtl8224_package_modify_mmd(phydev, MDIO_MMD_VEND1,
+ RTL8224_VND1_MDI_PAIR_SWAP,
+ BIT(port_offset),
+ order ? BIT(port_offset) : 0);
+}
+
+static int rtl8224_mdi_config_polarity(struct phy_device *phydev)
+{
+ struct device_node *np = phydev->mdio.dev.of_node;
+ u8 offset = (phydev->mdio.addr & 3) * 4;
+ u32 polarity = 0;
+ int ret;
+
+ ret = of_property_read_u32(np, "enet-phy-pair-polarity", &polarity);
+
+ /* Do nothing if the property is not present */
+ if (ret == -EINVAL || ret == -ENOSYS)
+ return 0;
+
+ if (ret)
+ return ret;
+
+ if (polarity & ~0xf)
+ return -EINVAL;
+
+ return rtl8224_package_modify_mmd(phydev, MDIO_MMD_VEND1,
+ RTL8224_VND1_MDI_POLARITY_SWAP,
+ 0xf << offset,
+ polarity << offset);
+}
+
+static int rtl8224_config_init(struct phy_device *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)
+{
+ /* Chip exposes 4 ports, join all of them in the same package */
+ return devm_phy_package_join(&phydev->mdio.dev, phydev,
+ phydev->mdio.addr & ~3, 0);
+}
+
static bool rtlgen_supports_2_5gbps(struct phy_device *phydev)
{
int val;
@@ -2395,6 +2489,8 @@ static struct phy_driver realtek_drvs[] = {
PHY_ID_MATCH_EXACT(0x001ccad0),
.name = "RTL8224 2.5Gbps PHY",
.flags = PHY_POLL_CABLE_TEST,
+ .probe = rtl8224_probe,
+ .config_init = rtl8224_config_init,
.get_features = rtl822x_c45_get_features,
.config_aneg = rtl822x_c45_config_aneg,
.read_status = rtl822x_c45_read_status,