dt-bindings: net: realtek,rtl82xx: add a property to set MDI order
Subsystems (4)
PATCH v2 1/4 dt-bindings: net: realtek,rtl82xx: add a property to set MDI order
MDI pair order reversal is usually configured by the bootloader. However, on some design the configuration is left untouched during boot and needs to be set by the driver.
Add the property 'realtek,mdi-cfg-order' to allow forcing normal or reverse order of the MDI pairs.
--- Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml | 7 +++++++ 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml +7 -0
@@ -55,6 +55,12 @@ properties: description: Enable Wake-on-LAN support for the RTL8211F PHY. + realtek,mdi-cfg-order: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1] + description: + Force normal (0) or reverse (1) order of MDI pairs. + unevaluatedProperties: false allOf:
@@ -79,5 +85,6 @@ examples: reg = <1>; realtek,clkout-disable; realtek,aldps-enable; + realtek,mdi-cfg-order = <1>; }; };
base-commit: 983d014aafb14ee5e4915465bf8948e8f3a723b5
Signature · 1 line
2.47.3
PATCH v2 2/4 net: phy: realtek: add RTL8224 pair order support
The RTL8224 has a register to configure a pair swap (from ABCD order to DCBA) providing PCB designers more flexbility when wiring the chip. The swap parameter has to be set correctly for each of the 4 ports before the chip can detect a link.
After a reset, this register is (unfortunately) left in a random state, thus it has to be initialized. On most of the devices the bootloader does it once for all and we can rely on the value set, on some other it is not and the kernel has to do it.
The MDI pair swap can be set in the device tree using the property realtek,mdi-cfg-order. The property is set to 0 to keep the default order (ABCD), or 1 to reverse the pairs (DCBA).
--- drivers/net/phy/realtek/Kconfig | 1 + drivers/net/phy/realtek/realtek_main.c | 50 ++++++++++++++++++++++++++ 2 files changed, 51 insertions(+)
drivers/net/phy/realtek/Kconfig +1 -0
@@ -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
drivers/net/phy/realtek/realtek_main.c +50 -0
74 lines not on this page · raw message
Signature · 1 line
2.47.3
kernel test robot
build botRe: [PATCH v2 2/4] net: phy: realtek: add RTL8224 pair order support
kernel test robot noticed the following build warnings:
Hi Damien,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 983d014aafb14ee5e4915465bf8948e8f3a723b5]
url: https://github.com/intel-lab-lkp/linux/commits/Damien-Dejean/net-phy-realtek-add-RTL8224-pair-order-support/20260122-000009 base: 983d014aafb14ee5e4915465bf8948e8f3a723b5 patch link: https://lore.kernel.org/r/20260121151506.813783-2-dam.dejean%40gmail.com patch subject: [PATCH v2 2/4] net: phy: realtek: add RTL8224 pair order support config: i386-randconfig-141-20260122 (https://download.01.org/0day-ci/archive/20260122/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 smatch version: v0.5.0-8985-g2614ff1a
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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
New smatch warnings:drivers/net/phy/realtek/realtek_main.c:1710 rtl8224_mdi_config_order() warn: unsigned 'val' is never less than zero.
Old smatch warnings:drivers/net/phy/realtek/realtek_main.c:805 rtl821x_resume() warn: 'priv->clk' from clk_prepare_enable() not released on lines: 801.
vim +/val +1710 drivers/net/phy/realtek/realtek_main.c
1688
1689 static int rtl8224_mdi_config_order(struct phy_device *phydev)
1690 {
1691 struct device_node *np = phydev->mdio.dev.of_node;
1692 u8 port_offset = phydev->mdio.addr & 3;
1693 u32 mdi_conf, val;
1694 int ret;
1695
1696 ret = of_property_read_u32(np, "realtek,mdi-cfg-order", &mdi_conf);
1697
1698 /* Do nothing in case the property is not present */
1699 if (ret == -EINVAL)
1700 return 0;
1701
1702 if (ret)
1703 return ret;
1704
1705 if (mdi_conf & ~1)
1706 return -EINVAL;
1707
1708 val = __phy_package_read_mmd(phydev, 0, MDIO_MMD_VEND1,
1709 RTL8224_VND1_MDI_PAIR_SWAP);
> 1710 if (val < 0)
1711 return val;
1712
1713 if (mdi_conf)
1714 val |= (1 << port_offset);
1715 else
1716 val &= ~(1 << port_offset);
1717
1718 return __phy_package_write_mmd(phydev, 0, MDIO_MMD_VEND1,
1719 RTL8224_VND1_MDI_PAIR_SWAP, val);
1720 }
1721
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v2 2/4] net: phy: realtek: add RTL8224 pair order support
In reply to Damien Dejeankernel test robot noticed the following build warnings:
Hi Damien,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 983d014aafb14ee5e4915465bf8948e8f3a723b5]
url: https://github.com/intel-lab-lkp/linux/commits/Damien-Dejean/net-phy-realtek-add-RTL8224-pair-order-support/20260122-000009 base: 983d014aafb14ee5e4915465bf8948e8f3a723b5 patch link: https://lore.kernel.org/r/20260121151506.813783-2-dam.dejean%40gmail.com patch subject: [PATCH v2 2/4] net: phy: realtek: add RTL8224 pair order support config: i386-randconfig-141-20260122 (https://download.01.org/0day-ci/archive/20260123/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 smatch version: v0.5.0-8994-gd50c5a4c
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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
New smatch warnings:drivers/net/phy/realtek/realtek_main.c:1710 rtl8224_mdi_config_order() warn: unsigned 'val' is never less than zero.
Old smatch warnings:drivers/net/phy/realtek/realtek_main.c:805 rtl821x_resume() warn: 'priv->clk' from clk_prepare_enable() not released on lines: 801.
vim +/val +1710 drivers/net/phy/realtek/realtek_main.c
1688
1689 static int rtl8224_mdi_config_order(struct phy_device *phydev)
1690 {
1691 struct device_node *np = phydev->mdio.dev.of_node;
1692 u8 port_offset = phydev->mdio.addr & 3;
1693 u32 mdi_conf, val;
1694 int ret;
1695
1696 ret = of_property_read_u32(np, "realtek,mdi-cfg-order", &mdi_conf);
1697
1698 /* Do nothing in case the property is not present */
1699 if (ret == -EINVAL)
1700 return 0;
1701
1702 if (ret)
1703 return ret;
1704
1705 if (mdi_conf & ~1)
1706 return -EINVAL;
1707
1708 val = __phy_package_read_mmd(phydev, 0, MDIO_MMD_VEND1,
1709 RTL8224_VND1_MDI_PAIR_SWAP);
> 1710 if (val < 0)
1711 return val;
1712
1713 if (mdi_conf)
1714 val |= (1 << port_offset);
1715 else
1716 val &= ~(1 << port_offset);
1717
1718 return __phy_package_write_mmd(phydev, 0, MDIO_MMD_VEND1,
1719 RTL8224_VND1_MDI_PAIR_SWAP, val);
1720 }
1721
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
PATCH v2 3/4 dt-bindings: net: realtek,rtl82xx: add a property to set MDI polarity
In reply to Damien DejeanMDI pair polarity is usually configured by the bootloader. However, on some designs the configuration is left untouched during boot and needs to be set by the driver.
Add the property 'realtek,mdi-cfg-polarity' to configure the polarity of each pair. Bit 0 to 3 configure the polarity or pairs A to D, if set to 1 the polarity is reversed for this pair.
--- Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml | 7 +++++++ 1 file changed, 7 insertions(+)
Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml +7 -0
@@ -61,6 +61,13 @@ properties: description: Force normal (0) or reverse (1) order of MDI pairs. + realtek,mdi-cfg-polarity: + 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. + $ref: /schemas/types.yaml#/definitions/uint32 + unevaluatedProperties: false allOf:
Signature · 1 line
2.47.3
Rob Herring
maintainerRe: [PATCH v2 3/4] dt-bindings: net: realtek,rtl82xx: add a property to set MDI polarity
Quoted 18 lines · Damien Dejean
MDI pair polarity is usually configured by the bootloader. However, on some designs the configuration is left untouched during boot and needs to be set by the driver.
Add the property 'realtek,mdi-cfg-polarity' to configure the polarity of each pair. Bit 0 to 3 configure the polarity or pairs A to D, if set to 1 the polarity is reversed for this pair.
Signed-off-by Damien Dejean <[email protected]>--- Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml | 7 +++++++ 1 file changed, 7 insertions(+)Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml +0
-0
Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml properties: · line 69
Quoted 9 lines
Documentation/devicetree/bindings/net/realtek,rtl82xx.yaml +6
-0@@ -61,6 +61,13 @@ properties: description: Force normal (0) or reverse (1) order of MDI pairs. + realtek,mdi-cfg-polarity: + 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. + $ref: /schemas/types.yaml#/definitions/uint32
maximum: 0xf
However, are these properties something that should be common?
Rob
Re: [PATCH v2 3/4] dt-bindings: net: realtek,rtl82xx: add a property to set MDI polarity
Quoted 4 lines · Rob Herring
However, are these properties something that should be common?
If by common you mean « not Realtek specific » I have no idea if this kind of mapping is possible on other chips. Marvell Aquantia phys have an « order » (marvell,mdi-cfg-order) property like the one I introduced in the patch before this one (thanks Andrew), but that’s all I know.
Rob Herring
maintainerRe: [PATCH v2 3/4] dt-bindings: net: realtek,rtl82xx: add a property to set MDI polarity
Quoted 7 lines · Damien Dejean
Quoted 5 lines · Rob Herring
However, are these properties something that should be common?
If by common you mean « not Realtek specific »
Yes.
Quoted 1 line
I have no idea if this kind of mapping is possible on other chips. Marvell Aquantia phys have an « order » (marvell,mdi-cfg-order) property like the one I introduced in the patch before this one (thanks Andrew), but that’s all I know.
Seems like it is.
Rob
PATCH v2 4/4 net: phy: realtek: add RTL8224 polarity support
In reply to Damien DejeanThe 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.
--- drivers/net/phy/realtek/realtek_main.c | 39 +++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-)
drivers/net/phy/realtek/realtek_main.c +38 -1
@@ -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)
Signature · 1 line
2.47.3
kernel test robot
build botRe: [PATCH v2 4/4] net: phy: realtek: add RTL8224 polarity support
kernel test robot noticed the following build warnings:
Hi Damien,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 983d014aafb14ee5e4915465bf8948e8f3a723b5]
url: https://github.com/intel-lab-lkp/linux/commits/Damien-Dejean/net-phy-realtek-add-RTL8224-pair-order-support/20260122-000009 base: 983d014aafb14ee5e4915465bf8948e8f3a723b5 patch link: https://lore.kernel.org/r/20260121151506.813783-4-dam.dejean%40gmail.com patch subject: [PATCH v2 4/4] net: phy: realtek: add RTL8224 polarity support config: i386-randconfig-141-20260122 (https://download.01.org/0day-ci/archive/20260123/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 smatch version: v0.5.0-8994-gd50c5a4c
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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
New smatch warnings:drivers/net/phy/realtek/realtek_main.c:1744 rtl8224_mdi_config_polarity() warn: unsigned 'val' is never less than zero.
Old smatch warnings:drivers/net/phy/realtek/realtek_main.c:806 rtl821x_resume() warn: 'priv->clk' from clk_prepare_enable() not released on lines: 802. drivers/net/phy/realtek/realtek_main.c:1711 rtl8224_mdi_config_order() warn: unsigned 'val' is never less than zero.
vim +/val +1744 drivers/net/phy/realtek/realtek_main.c
1722
1723 static int rtl8224_mdi_config_polarity(struct phy_device *phydev)
1724 {
1725 struct device_node *np = phydev->mdio.dev.of_node;
1726 u8 port_offset = phydev->mdio.addr & 3;
1727 u32 polarity, val;
1728 int ret;
1729
1730 ret = of_property_read_u32(np, "realtek,mdi-cfg-polarity", &polarity);
1731
1732 /* Do nothing if the property is not present */
1733 if (ret == -EINVAL)
1734 return 0;
1735
1736 if (!ret)
1737 return ret;
1738
1739 if (polarity & ~0xf)
1740 return -EINVAL;
1741
1742 val = __phy_package_read_mmd(phydev, 0, MDIO_MMD_VEND1,
1743 RTL8224_VND1_MDI_POLARITY_SWAP);
> 1744 if (val < 0)
1745 return val;
1746
1747 val &= ~(0xf << port_offset);
1748 val |= polarity << port_offset;
1749 return __phy_package_write_mmd(phydev, 0, MDIO_MMD_VEND1,
1750 RTL8224_VND1_MDI_POLARITY_SWAP, val);
1751 }
1752
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki
kernel test robot
build botRe: [PATCH v2 4/4] net: phy: realtek: add RTL8224 polarity support
In reply to Damien Dejeankernel test robot noticed the following build warnings:
Hi Damien,
kernel test robot noticed the following build warnings:
[auto build test WARNING on 983d014aafb14ee5e4915465bf8948e8f3a723b5]
url: https://github.com/intel-lab-lkp/linux/commits/Damien-Dejean/net-phy-realtek-add-RTL8224-pair-order-support/20260122-000009 base: 983d014aafb14ee5e4915465bf8948e8f3a723b5 patch link: https://lore.kernel.org/r/20260121151506.813783-4-dam.dejean%40gmail.com patch subject: [PATCH v2 4/4] net: phy: realtek: add RTL8224 polarity support config: x86_64-defconfig (https://download.01.org/0day-ci/archive/20260123/[email protected]/config) compiler: gcc-14 (Debian 14.2.0-19) 14.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260123/[email protected]/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 <[email protected]>
| Closes: https://lore.kernel.org/oe-kbuild-all/[email protected]/
All warnings (new ones prefixed by >>):
In function 'rtl8224_mdi_config_polarity',
inlined from 'rtl8224_config_init' at drivers/net/phy/realtek/realtek_main.c:1761:9:
>> drivers/net/phy/realtek/realtek_main.c:1739:12: warning: 'polarity' is used uninitialized [-Wuninitialized]
1739 | if (polarity & ~0xf)
| ^
drivers/net/phy/realtek/realtek_main.c:1727:13: note: 'polarity' was declared here
1727 | u32 polarity, val;
| ^~~~~~~~vim +/polarity +1739 drivers/net/phy/realtek/realtek_main.c
1722
1723 static int rtl8224_mdi_config_polarity(struct phy_device *phydev)
1724 {
1725 struct device_node *np = phydev->mdio.dev.of_node;
1726 u8 port_offset = phydev->mdio.addr & 3;
1727 u32 polarity, val;
1728 int ret;
1729
1730 ret = of_property_read_u32(np, "realtek,mdi-cfg-polarity", &polarity);
1731
1732 /* Do nothing if the property is not present */
1733 if (ret == -EINVAL)
1734 return 0;
1735
1736 if (!ret)
1737 return ret;
1738
> 1739 if (polarity & ~0xf)
1740 return -EINVAL;
1741
1742 val = __phy_package_read_mmd(phydev, 0, MDIO_MMD_VEND1,
1743 RTL8224_VND1_MDI_POLARITY_SWAP);
1744 if (val < 0)
1745 return val;
1746
1747 val &= ~(0xf << port_offset);
1748 val |= polarity << port_offset;
1749 return __phy_package_write_mmd(phydev, 0, MDIO_MMD_VEND1,
1750 RTL8224_VND1_MDI_POLARITY_SWAP, val);
1751 }
1752
Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests/wiki