From: Damien Dejean <dam.dejean@gmail.com>
To: andrew@lunn.ch, krzk+dt@kernel.org, robh@kernel.org, kuba@kernel.org
Cc: netdev@vger.kernel.org, devicetree@vger.kernel.org,
linux-kernel@vger.kernel.org, edumazet@google.com,
davem@davemloft.net, pabeni@redhat.com, hkallweit1@gmail.com,
Damien Dejean <dam.dejean@gmail.com>
Subject: [PATCH v5 4/4] net: phy: realtek: add RTL8224 polarity support
Date: Mon, 2 Feb 2026 21:04:11 +0100 [thread overview]
Message-ID: <20260202200411.373161-4-dam.dejean@gmail.com> (raw)
In-Reply-To: <20260202200411.373161-1-dam.dejean@gmail.com>
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
enet-phy-lane-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@gmail.com>
---
drivers/net/phy/realtek/realtek_main.c | 45 +++++++++++++++++++++++++-
1 file changed, 44 insertions(+), 1 deletion(-)
diff --git a/drivers/net/phy/realtek/realtek_main.c b/drivers/net/phy/realtek/realtek_main.c
index 85e928a0d3dc..d23672e33432 100644
--- a/drivers/net/phy/realtek/realtek_main.c
+++ b/drivers/net/phy/realtek/realtek_main.c
@@ -172,6 +172,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)
@@ -1861,9 +1862,51 @@ static int rtl8224_mdi_config_order(struct phy_device *phydev)
return ret;
}
+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, val;
+
+ ret = of_property_read_u32(np, "enet-phy-lane-polarity", &polarity);
+
+ /* Do nothing if the property is not present */
+ if (ret == -EINVAL)
+ return 0;
+
+ if (ret)
+ return ret;
+
+ if (polarity & ~0xf)
+ return -EINVAL;
+
+ phy_lock_mdio_bus(phydev);
+ val = __phy_package_read_mmd(phydev, 0, MDIO_MMD_VEND1,
+ RTL8224_VND1_MDI_POLARITY_SWAP);
+ if (val < 0) {
+ ret = val;
+ goto exit;
+ }
+
+ val &= ~(0xf << offset);
+ val |= polarity << offset;
+ ret = __phy_package_write_mmd(phydev, 0, MDIO_MMD_VEND1,
+ RTL8224_VND1_MDI_POLARITY_SWAP, val);
+exit:
+ phy_unlock_mdio_bus(phydev);
+ return ret;
+}
+
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
next prev parent reply other threads:[~2026-02-02 20:04 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-02 20:04 [PATCH v5 1/4] dt-bindings: net: ethernet-phy: add property enet-phy-lane-order Damien Dejean
2026-02-02 20:04 ` [PATCH v5 2/4] net: phy: realtek: add RTL8224 pair order support Damien Dejean
2026-02-02 20:04 ` [PATCH v5 3/4] dt-bindings: net: ethernet-phy: add property enet-phy-lane-polarity Damien Dejean
2026-02-02 20:04 ` Damien Dejean [this message]
2026-02-03 9:09 ` [PATCH v5 1/4] dt-bindings: net: ethernet-phy: add property enet-phy-lane-order Maxime Chevallier
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260202200411.373161-4-dam.dejean@gmail.com \
--to=dam.dejean@gmail.com \
--cc=andrew@lunn.ch \
--cc=davem@davemloft.net \
--cc=devicetree@vger.kernel.org \
--cc=edumazet@google.com \
--cc=hkallweit1@gmail.com \
--cc=krzk+dt@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=robh@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox