dt-bindings: net: ethernet-phy: add property enet-phy-lane-order
Subsystems (4)
PATCH v5 1/4 dt-bindings: net: ethernet-phy: add property enet-phy-lane-order
Add property enet-phy-lane-order to the device tree bindings to define the lane order of the PHY. To simplify PCB design some manufacturers allow to wire the pairs in a reverse order, and change the order in software.
The property can be set to 0 to force the normal lane order (ABCD), or 1 to force the reverse lane order (DCBA).
--- Documentation/devicetree/bindings/net/ethernet-phy.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/net/ethernet-phy.yaml +6 -0
@@ -126,6 +126,12 @@ properties: e.g. wrong bootstrap configuration caused by issues in PCB layout design. + enet-phy-lane-order: + $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1] + description: + For normal (0) or reverse (1) order of the pairs (ABCD -> DCBA). + eee-broken-100tx: $ref: /schemas/types.yaml#/definitions/flag description:
Signature · 1 line
2.47.3
PATCH v5 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 enet-phy-lane-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 | 55 ++++++++++++++++++++++++++ 2 files changed, 56 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 +55 -0
73 lines not on this page · raw message
Signature · 1 line
2.47.3
PATCH v5 3/4 dt-bindings: net: ethernet-phy: add property enet-phy-lane-polarity
In reply to Damien DejeanAdd the property enet-phy-lane-polarity to describe the polarity of the PHY lanes. To ease PCB designs some manufacturers allow to wire the pairs with a reverse polarity and provide a way to configure it.
The property 'enet-phy-lane-polarity' sets 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/ethernet-phy.yaml | 8 ++++++++ 1 file changed, 8 insertions(+)
Documentation/devicetree/bindings/net/ethernet-phy.yaml +8 -0
@@ -132,6 +132,14 @@ properties: description: For normal (0) or reverse (1) order of the pairs (ABCD -> DCBA). + enet-phy-lane-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:
Signature · 1 line
2.47.3
PATCH v5 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 enet-phy-lane-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 | 45 +++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-)
drivers/net/phy/realtek/realtek_main.c +44 -1
@@ -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)
Signature · 1 line
2.47.3
Hi,
Quoted 18 lines · Damien Dejean
Add property enet-phy-lane-order to the device tree bindings to define the lane order of the PHY. To simplify PCB design some manufacturers allow to wire the pairs in a reverse order, and change the order in software.
The property can be set to 0 to force the normal lane order (ABCD), or 1 to force the reverse lane order (DCBA).
Signed-off-by Damien Dejean <[email protected]>--- Documentation/devicetree/bindings/net/ethernet-phy.yaml | 6 ++++++ 1 file changed, 6 insertions(+)Documentation/devicetree/bindings/net/ethernet-phy.yaml +0
-0
Documentation/devicetree/bindings/net/ethernet-phy.yaml properties: · line 129
Quoted 4 lines
Documentation/devicetree/bindings/net/ethernet-phy.yaml +1
-0@@ -126,6 +126,12 @@ properties: e.g. wrong bootstrap configuration caused by issues in PCB layout design. + enet-phy-lane-order:
As this is specific to BaseT, maybe rename that "enet-phy-pair-order" ?
Documentation/devicetree/bindings/net/ethernet-phy.yaml properties: · line 133
Quoted 4 lines
Documentation/devicetree/bindings/net/ethernet-phy.yaml +4
-0+ $ref: /schemas/types.yaml#/definitions/uint32 + enum: [0, 1] + description: + For normal (0) or reverse (1) order of the pairs (ABCD -> DCBA).
We now have a binding in DT for ethernet-connectors, and I'd says this is typically the kind of info I'd put in there :
The way you'd use that is by adding a ".attach_mdi_port()" callback in your phy driver, and in there you'd parse these properties and do the proper settings.
We're missing a few things, such as storing a ref to the of_node corresponding to the connector into phy_port.
This is brand new though, maybe Maintainers would like for phy_port to stabilize before building more on top of it ?
Maxime