Skip to contentSkip to conversation

phy: add common PHY polarity properties support

PATCH Superseded Lucien.Jheng 2 participants 9 messages Mar 8 – Mar 15

Subsystems (4)

v2 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v2 cover phy: add common PHY polarity properties support

This series ports PHY polarity inversion support via generic device tree properties from Linux kernel, synchronizing with Merge tag 'phy-for-7.0' of git://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy.

Patch 1 introduces a new PHY_COMMON_PROPS library providing helper functions (phy_get_rx_polarity, phy_get_tx_polarity, and their "manual" variants) for PHY drivers to read standard polarity properties from the device tree. The PHY_POL_NORMAL, PHY_POL_INVERT, and PHY_POL_AUTO constants are consumed from dts/upstream/include, which is already on the compiler include path.

Patch 2 updates the Airoha EN8811H PHY driver to use the new standard rx-polarity and tx-polarity properties, with backward compatibility fallback to the now-deprecated airoha,pnswap-rx and airoha,pnswap-tx boolean properties.

Changes in v2:
- Drop DT binding patches (v1 patches 1 and 3): already merged via the DTS upstream subtree merge (tag 'v7.0-rc2-dts')
- Drop creation of include/dt-bindings/phy/phy.h: the header is now provided by dts/upstream/include/dt-bindings/phy/phy.h, which is already in the build's include search path

Lucien.Jheng (2):
phy: add common PHY properties support
net: phy: air_en8811h: use standard rx-polarity/tx-polarity properties

 drivers/net/phy/airoha/Kconfig       |   1 +
 drivers/net/phy/airoha/air_en8811.c  |  91 +++++++--
 drivers/phy/Kconfig                  |   8 +
 drivers/phy/Makefile                 |   1 +
 drivers/phy/phy-common-props.c       | 286 +++++++++++++++++++++++++++
 include/linux/phy/phy-common-props.h |  70 +++++++
 6 files changed, 442 insertions(+), 15 deletions(-)
 create mode 100644 drivers/phy/phy-common-props.c
 create mode 100644 include/linux/phy/phy-common-props.h

--
2.34.1

#1 lore raw

PATCH v2 1/2 phy: add common PHY properties support

Add a new PHY_COMMON_PROPS library that provides helper functions for PHY drivers to read standardized polarity properties from the device tree node:

- phy_get_rx_polarity() / phy_get_tx_polarity()
- phy_get_manual_rx_polarity() / phy_get_manual_tx_polarity()

The dt-bindings/phy/phy.h header with PHY_POL_NORMAL, PHY_POL_INVERT, and PHY_POL_AUTO constants is provided via dts/upstream/include, which is already in the build include path.

Ported from Merge tag 'phy-for-7.0':
git://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy

---
 drivers/phy/Kconfig                  |   8 +
 drivers/phy/Makefile                 |   1 +
 drivers/phy/phy-common-props.c       | 286 +++++++++++++++++++++++++++
 include/linux/phy/phy-common-props.h |  70 +++++++
 4 files changed, 365 insertions(+)
 create mode 100644 drivers/phy/phy-common-props.c
 create mode 100644 include/linux/phy/phy-common-props.h
drivers/phy/Kconfig +8 -0
index 09810b62b51..18419c1d490 100644
@@ -339,4 +339,12 @@ source "drivers/phy/qcom/Kconfig"
 source "drivers/phy/renesas/Kconfig"
 source "drivers/phy/starfive/Kconfig"
 
+config PHY_COMMON_PROPS
+	bool "Common PHY properties support"
+	help
+	  Enable support for common PHY properties defined in the device tree,
+	  such as rx-polarity and tx-polarity. This provides helpers for PHY
+	  drivers to read polarity and other standard PHY properties from the
+	  device tree node.
+
 endmenu
drivers/phy/Makefile +1 -0
index 83102349669..91610692cc0 100644
@@ -42,6 +42,7 @@ obj-$(CONFIG_PHY_NPCM_USB) += phy-npcm-usb.o
 obj-$(CONFIG_$(PHASE_)PHY_IMX8MQ_USB) += phy-imx8mq-usb.o
 obj-$(CONFIG_PHY_IMX8M_PCIE) += phy-imx8m-pcie.o
 obj-$(CONFIG_PHY_XILINX_ZYNQMP) += phy-zynqmp.o
+obj-$(CONFIG_PHY_COMMON_PROPS) += phy-common-props.o
 obj-y += cadence/
 obj-y += ti/
 obj-y += qcom/
drivers/phy/phy-common-props.c new file +286 -0

286 lines not on this page · raw message

include/linux/phy/phy-common-props.h new file +70 -0

70 lines not on this page · raw message

Signature · 1 line
2.34.1
maintainer
#2 lore raw

Re: [PATCH v2 1/2] phy: add common PHY properties support

Quoted 16 lines · Lucien.Jheng

Add a new PHY_COMMON_PROPS library that provides helper functions for PHY drivers to read standardized polarity properties from the device tree node:

- phy_get_rx_polarity() / phy_get_tx_polarity()
- phy_get_manual_rx_polarity() / phy_get_manual_tx_polarity()

The dt-bindings/phy/phy.h header with PHY_POL_NORMAL, PHY_POL_INVERT, and PHY_POL_AUTO constants is provided via dts/upstream/include, which is already in the build include path.

Ported from Merge tag 'phy-for-7.0':
git://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy

Quoted 8 lines
---
 drivers/phy/Kconfig                  |   8 +
 drivers/phy/Makefile                 |   1 +
 drivers/phy/phy-common-props.c       | 286 +++++++++++++++++++++++++++
 include/linux/phy/phy-common-props.h |  70 +++++++
 4 files changed, 365 insertions(+)
 create mode 100644 drivers/phy/phy-common-props.c
 create mode 100644 include/linux/phy/phy-common-props.h

Thanks for doing this. Do you think you can also port the KUnit tests to U-Boot's own "ut" test framework? Should be testable with the sandbox.

export KBUILD_OUTPUT=output-sandbox
make sandbox_defconfig NO_SDL=1
make -j 8 NO_SDL=1
$KBUILD_OUTPUT/u-boot -d $KBUILD_OUTPUT/arch/sandbox/dts/test.dtb ut phy # or phy_common_props for the new code

#3 lore raw

Re: [PATCH v2 1/2] phy: add common PHY properties support

Vladimir Oltean 於 2026/3/10 下午 04:32 寫道:

Quoted 25 lines · Lucien.Jheng
Quoted 16 lines

Add a new PHY_COMMON_PROPS library that provides helper functions for PHY drivers to read standardized polarity properties from the device tree node:

- phy_get_rx_polarity() / phy_get_tx_polarity()
- phy_get_manual_rx_polarity() / phy_get_manual_tx_polarity()

The dt-bindings/phy/phy.h header with PHY_POL_NORMAL, PHY_POL_INVERT, and PHY_POL_AUTO constants is provided via dts/upstream/include, which is already in the build include path.

Ported from Merge tag 'phy-for-7.0':
git://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy

Quoted 8 lines
---
  drivers/phy/Kconfig                  |   8 +
  drivers/phy/Makefile                 |   1 +
  drivers/phy/phy-common-props.c       | 286 +++++++++++++++++++++++++++
  include/linux/phy/phy-common-props.h |  70 +++++++
  4 files changed, 365 insertions(+)

create mode 100644 drivers/phy/phy-common-props.c create mode 100644 include/linux/phy/phy-common-props.h

Quoted 8 lines

Thanks for doing this. Do you think you can also port the KUnit tests to U-Boot's own "ut" test framework? Should be testable with the sandbox.

export KBUILD_OUTPUT=output-sandbox
make sandbox_defconfig NO_SDL=1
make -j 8 NO_SDL=1
$KBUILD_OUTPUT/u-boot -d $KBUILD_OUTPUT/arch/sandbox/dts/test.dtb ut phy # or phy_common_props for the new code

I haven't used KUnit before, but I'll try to port it to U-Boot.

Let me look into the commands you provided and figure out how to port it.

Thanks

maintainer
#4 lore raw

Re: [PATCH v2 1/2] phy: add common PHY properties support

Quoted 1 line · Lucien.Jheng

I haven't used KUnit before

Enable CONFIG_KUNIT and CONFIG_PHY_COMMON_PROPS_TEST in the .config, build and boot the resulting kernel. The tests will run at boot time and appear in dmesg.

#5 lore raw

Re: [PATCH v2 1/2] phy: add common PHY properties support

Vladimir Oltean 於 2026/3/11 上午 01:40 寫道:

Quoted 5 lines · Lucien.Jheng
Quoted 1 line

I haven't used KUnit before

Enable CONFIG_KUNIT and CONFIG_PHY_COMMON_PROPS_TEST in the .config, build and boot the resulting kernel. The tests will run at boot time and appear in dmesg.

Thank you for your sharing.

I will try to run KUnit test.

#6 lore raw

PATCH v2 2/2 net: phy: air_en8811h: use standard rx-polarity/tx-polarity properties

In reply to Lucien.Jheng

Replace the proprietary airoha,pnswap-rx / airoha,pnswap-tx boolean device tree properties with the standard rx-polarity and tx-polarity properties defined in phy-common-props.yaml.

The driver first tries the standard properties; if absent it falls back to the legacy ones for backward compatibility. The legacy properties are marked deprecated in the bindings.

---
The log below demonstrates the usage of the legacy and common PHY properties newly implemented in this version. You could choose one of method to configure polarity of EN8811H.

1. EN8811H DTS using common PHY properties

	phy14: eth-phy@14 {
		compatible = "ethernet-phy-id03a2.a411";
		reg = <14>;
		//phy-supply = <&en8811_a>;
		pinctrl-names = "default";
		pinctrl-0 = <&en8811_pwr_a>;
		// airoha,pnswap-rx;
		rx-polarity = <PHY_POL_INVERT>;
		tx-polarity = <PHY_POL_NORMAL>;

		reset-gpios = <&pio 49 GPIO_ACTIVE_LOW>;
		reset-assert-us = <10000>;
		reset-deassert-us = <20000>;
	};

UBoot log:
mtk-eth ethernet@15100000: MD32 firmware version: 24112802
phy_get_polarity_for_mode: querying 'rx-polarity' for mode '2500base-x' (supported=0x3, default=0) ofnode_get_u32_prop_for_name: looking up '2500base-x' in props='rx-polarity' names='rx-polarity-names' default=0
ofnode_read_prop: rx-polarity: ofnode_count_u32_prop: property 'rx-polarity' has 4 bytes (1 elements) ofnode_get_u32_prop_for_name: 'rx-polarity' has 1 elements, 'rx-polarity-names' has -1 entries ofnode_get_u32_prop_for_name: '2500base-x' not found in 'rx-polarity-names', trying 'default' ofnode_get_u32_prop_for_name: 'default' entry not found in 'rx-polarity-names' ofnode_get_u32_prop_for_name: single-element 'rx-polarity', reading directly
ofnode_read_u32_index: rx-polarity: 0x1 (1)
ofnode_get_u32_prop_for_name: resolved value 1 for name '2500base-x' from 'rx-polarity'
phy_get_polarity_for_mode: 'rx-polarity' for mode '2500base-x' = 1
mtk-eth ethernet@15100000: EN8811H: RX polarity = inverted
phy_get_polarity_for_mode: querying 'tx-polarity' for mode '2500base-x' (supported=0x3, default=0) ofnode_get_u32_prop_for_name: looking up '2500base-x' in props='tx-polarity' names='tx-polarity-names' default=0
ofnode_read_prop: tx-polarity: ofnode_count_u32_prop: property 'tx-polarity' has 4 bytes (1 elements) ofnode_get_u32_prop_for_name: 'tx-polarity' has 1 elements, 'tx-polarity-names' has -1 entries ofnode_get_u32_prop_for_name: '2500base-x' not found in 'tx-polarity-names', trying 'default' ofnode_get_u32_prop_for_name: 'default' entry not found in 'tx-polarity-names' ofnode_get_u32_prop_for_name: single-element 'tx-polarity', reading directly
ofnode_read_u32_index: tx-polarity: 0x0 (0)
ofnode_get_u32_prop_for_name: resolved value 0 for name '2500base-x' from 'tx-polarity'
phy_get_polarity_for_mode: 'tx-polarity' for mode '2500base-x' = 0
mtk-eth ethernet@15100000: EN8811H: TX polarity = normal
eth0: ethernet@15100000
Hit any key to stop autoboot: 0
BPI-R3M>

2. EN8811H DTS using legacy configuration

	phy14: eth-phy@14 {
		compatible = "ethernet-phy-id03a2.a411";
		reg = <14>;
		//phy-supply = <&en8811_a>;
		pinctrl-names = "default";
		pinctrl-0 = <&en8811_pwr_a>;
		airoha,pnswap-rx;

		reset-gpios = <&pio 49 GPIO_ACTIVE_LOW>;
		reset-assert-us = <10000>;
		reset-deassert-us = <20000>;
	};

UBoot log:
mtk-eth ethernet@15100000: MD32 firmware version: 24112802
phy_get_polarity_for_mode: querying 'rx-polarity' for mode '2500base-x' (supported=0x3, default=0) ofnode_get_u32_prop_for_name: looking up '2500base-x' in props='rx-polarity' names='rx-polarity-names' default=0
ofnode_read_prop: rx-polarity: <not found>
ofnode_count_u32_prop: property 'rx-polarity' not found (err=-22) ofnode_get_u32_prop_for_name: 'rx-polarity' is absent, returning -ENOENT
phy_get_polarity_for_mode: 'rx-polarity' lookup failed for mode '2500base-x' (err=-2)
mtk-eth ethernet@15100000: EN8811H: Legacy RX polarity
ofnode_read_bool: airoha,pnswap-rx: true
phy_get_polarity_for_mode: querying 'tx-polarity' for mode '2500base-x' (supported=0x3, default=0) ofnode_get_u32_prop_for_name: looking up '2500base-x' in props='tx-polarity' names='tx-polarity-names' default=0
ofnode_read_prop: tx-polarity: <not found>
ofnode_count_u32_prop: property 'tx-polarity' not found (err=-22) ofnode_get_u32_prop_for_name: 'tx-polarity' is absent, returning -ENOENT
phy_get_polarity_for_mode: 'tx-polarity' lookup failed for mode '2500base-x' (err=-2)
mtk-eth ethernet@15100000: EN8811H: Legacy TX polarity
ofnode_read_bool: airoha,pnswap-tx: false
eth0: ethernet@15100000
Hit any key to stop autoboot: 0
BPI-R3M>

 drivers/net/phy/airoha/Kconfig      |  1 +
 drivers/net/phy/airoha/air_en8811.c | 91 ++++++++++++++++++++++++-----
 2 files changed, 77 insertions(+), 15 deletions(-)
drivers/net/phy/airoha/Kconfig +1 -0
index 999564e4848..efe3c0f485b 100644
@@ -6,6 +6,7 @@ config PHY_AIROHA_EN8811
 	bool "Airoha Ethernet EN8811H support"
 	depends on PHY_AIROHA
 	select FW_LOADER
+	select PHY_COMMON_PROPS
 	help
 	  AIROHA EN8811H supported.
 
drivers/net/phy/airoha/air_en8811.c +76 -15

112 lines not on this page · raw message

--
2.34.1

maintainer
#7 lore raw

Re: [PATCH v2 2/2] net: phy: air_en8811h: use standard rx-polarity/tx-polarity properties

Quoted 59 lines · Lucien.Jheng
drivers/net/phy/airoha/air_en8811.c +39 -2
index 1a628ede82b..0ec11ba5231 100644
@@ -23,6 +23,7 @@
 #include <linux/compat.h>
 #include <dm/device_compat.h>
 #include <u-boot/crc.h>
+#include <linux/phy/phy-common-props.h>
 
 #define EN8811H_PHY_ID		0x03a2a411
 
@@ -660,11 +661,82 @@ static int air_leds_init(struct phy_device *phydev, int num, u16 dur, int mode)
 	return 0;
 }
 
-static int en8811h_config(struct phy_device *phydev)
+static int en8811h_config_polarity(struct phy_device *phydev)
 {
-	struct en8811h_priv *priv = phydev->priv;
 	ofnode node = phy_get_ofnode(phydev);
+	unsigned int rx_pol, tx_pol;
 	u32 pbus_value = 0;
+	int ret;
+	bool use_legacy = false;
+
+	if (!ofnode_valid(node))
+		return 0;
+
+	/* Try standard rx-polarity property first */
+	ret = phy_get_manual_rx_polarity(node,
+					 phy_interface_strings[phydev->interface],
+					 &rx_pol);
+	if (ret == 0) {
+		dev_info(phydev->dev, "EN8811H: RX polarity = %s\n",
+			 rx_pol == PHY_POL_INVERT ? "inverted" : "normal");
+		if (rx_pol == PHY_POL_INVERT)
+			pbus_value |= EN8811H_POLARITY_RX_REVERSE;
+		else
+			pbus_value &= ~EN8811H_POLARITY_RX_REVERSE;
+	} else if (ret == -ENOENT) {
+		/* Fall back to legacy airoha,pnswap-rx property */
+		use_legacy = true;
+		dev_info(phydev->dev, "EN8811H: Legacy RX polarity\n");
+
+		if (ofnode_read_bool(node, "airoha,pnswap-rx"))
+			pbus_value |= EN8811H_POLARITY_RX_REVERSE;
+		else
+			pbus_value &= ~EN8811H_POLARITY_RX_REVERSE;
+	} else {
+		dev_err(phydev->dev, "EN8811H: Error reading rx-polarity: %d\n", ret);
+		return ret;
+	}
+
+	/* Try standard tx-polarity property first */
+	ret = phy_get_manual_tx_polarity(node,
+					 phy_interface_strings[phydev->interface],
+					 &tx_pol);
+	if (ret == 0) {

drivers/net/phy/airoha/air_en8811.c static int air_leds_init(struct phy_device *phydev, int num, u16 dur, int mode) · line 714

Quoted 10 lines
drivers/net/phy/airoha/air_en8811.c +10 -0
+		dev_info(phydev->dev, "EN8811H: TX polarity = %s\n",
+			 tx_pol == PHY_POL_INVERT ? "inverted" : "normal");
+		if (tx_pol == PHY_POL_INVERT)
+			pbus_value &= ~EN8811H_POLARITY_TX_NORMAL;
+		else
+			pbus_value |= EN8811H_POLARITY_TX_NORMAL;
+	} else if (ret == -ENOENT) {
+		/* Fall back to legacy airoha,pnswap-tx property */
+		if (!use_legacy)
+			dev_err(phydev->dev, "EN8811H: Mixing standard and legacy polarity properties\n");

Mixing should be perfectly legal. Otherwise there's no way of converting an old scheme to the new one without breaking backwards compatibility.

The way in which this is done in Linux is by reading the legacy properties first (with a fallback on PHY_POL_NORMAL if absent) and then using them as "default" argument for phy_get_(rx|tx)_polarity(). The phy_get_manual_(rx|tx)_polarity() are intended for the use case where you have no legacy property to support.

I believe doing the same way here would simplify your logic quite a bit. No need to look at the specific "ret" value, and no need to duplicate the pbus_value modification.

Quoted 53 lines
drivers/net/phy/airoha/air_en8811.c +27 -14
+
+		dev_info(phydev->dev, "EN8811H: Legacy TX polarity\n");
+
+		if (ofnode_read_bool(node, "airoha,pnswap-tx"))
+			pbus_value &= ~EN8811H_POLARITY_TX_NORMAL;
+		else
+			pbus_value |= EN8811H_POLARITY_TX_NORMAL;
+	} else {
+		dev_err(phydev->dev, "EN8811H: Error reading tx-polarity: %d\n", ret);
+		return ret;
+	}
+
+	/* Apply polarity configuration to hardware */
+	ret = air_buckpbus_reg_modify(phydev, EN8811H_POLARITY,
+				      EN8811H_POLARITY_RX_REVERSE |
+				      EN8811H_POLARITY_TX_NORMAL, pbus_value);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int en8811h_config(struct phy_device *phydev)
+{
+	struct en8811h_priv *priv = phydev->priv;
 	int ret = 0;
 
 	/* If restart happened in .probe(), no need to restart now */
@@ -695,19 +767,8 @@ static int en8811h_config(struct phy_device *phydev)
 	if (ret < 0)
 		return ret;
 
-	/* Serdes polarity */
-	pbus_value = 0;
-	if (ofnode_read_bool(node, "airoha,pnswap-rx"))
-		pbus_value |=  EN8811H_POLARITY_RX_REVERSE;
-	else
-		pbus_value &= ~EN8811H_POLARITY_RX_REVERSE;
-	if (ofnode_read_bool(node, "airoha,pnswap-tx"))
-		pbus_value &= ~EN8811H_POLARITY_TX_NORMAL;
-	else
-		pbus_value |=  EN8811H_POLARITY_TX_NORMAL;
-	ret = air_buckpbus_reg_modify(phydev, EN8811H_POLARITY,
-				      EN8811H_POLARITY_RX_REVERSE |
-				      EN8811H_POLARITY_TX_NORMAL, pbus_value);
+	/* Configure Serdes polarity from device tree */
+	ret = en8811h_config_polarity(phydev);
 	if (ret < 0)
 		return ret;
 
--

2.34.1

#8 lore raw

Re: [PATCH v2 2/2] net: phy: air_en8811h: use standard rx-polarity/tx-polarity properties

Vladimir Oltean 於 2026/3/10 下午 04:28 寫道:

Quoted 79 lines · Lucien.Jheng
Quoted 59 lines
drivers/net/phy/airoha/air_en8811.c +39 -2
index 1a628ede82b..0ec11ba5231 100644
@@ -23,6 +23,7 @@
  #include <linux/compat.h>
  #include <dm/device_compat.h>
  #include <u-boot/crc.h>
+#include <linux/phy/phy-common-props.h>
 
  #define EN8811H_PHY_ID		0x03a2a411
 
@@ -660,11 +661,82 @@ static int air_leds_init(struct phy_device *phydev, int num, u16 dur, int mode)
  	return 0;
  }
 
-static int en8811h_config(struct phy_device *phydev)
+static int en8811h_config_polarity(struct phy_device *phydev)
  {
-	struct en8811h_priv *priv = phydev->priv;
  	ofnode node = phy_get_ofnode(phydev);
+	unsigned int rx_pol, tx_pol;
  	u32 pbus_value = 0;
+	int ret;
+	bool use_legacy = false;
+
+	if (!ofnode_valid(node))
+		return 0;
+
+	/* Try standard rx-polarity property first */
+	ret = phy_get_manual_rx_polarity(node,
+					 phy_interface_strings[phydev->interface],
+					 &rx_pol);
+	if (ret == 0) {
+		dev_info(phydev->dev, "EN8811H: RX polarity = %s\n",
+			 rx_pol == PHY_POL_INVERT ? "inverted" : "normal");
+		if (rx_pol == PHY_POL_INVERT)
+			pbus_value |= EN8811H_POLARITY_RX_REVERSE;
+		else
+			pbus_value &= ~EN8811H_POLARITY_RX_REVERSE;
+	} else if (ret == -ENOENT) {
+		/* Fall back to legacy airoha,pnswap-rx property */
+		use_legacy = true;
+		dev_info(phydev->dev, "EN8811H: Legacy RX polarity\n");
+
+		if (ofnode_read_bool(node, "airoha,pnswap-rx"))
+			pbus_value |= EN8811H_POLARITY_RX_REVERSE;
+		else
+			pbus_value &= ~EN8811H_POLARITY_RX_REVERSE;
+	} else {
+		dev_err(phydev->dev, "EN8811H: Error reading rx-polarity: %d\n", ret);
+		return ret;
+	}
+
+	/* Try standard tx-polarity property first */
+	ret = phy_get_manual_tx_polarity(node,
+					 phy_interface_strings[phydev->interface],
+					 &tx_pol);
+	if (ret == 0) {

drivers/net/phy/airoha/air_en8811.c static int air_leds_init(struct phy_device *phydev, int num, u16 dur, int mode) · line 714

Quoted 10 lines
drivers/net/phy/airoha/air_en8811.c +10 -0
+		dev_info(phydev->dev, "EN8811H: TX polarity = %s\n",
+			 tx_pol == PHY_POL_INVERT ? "inverted" : "normal");
+		if (tx_pol == PHY_POL_INVERT)
+			pbus_value &= ~EN8811H_POLARITY_TX_NORMAL;
+		else
+			pbus_value |= EN8811H_POLARITY_TX_NORMAL;
+	} else if (ret == -ENOENT) {
+		/* Fall back to legacy airoha,pnswap-tx property */
+		if (!use_legacy)
+			dev_err(phydev->dev, "EN8811H: Mixing standard and legacy polarity properties\n");

Mixing should be perfectly legal. Otherwise there's no way of converting an old scheme to the new one without breaking backwards compatibility.

The way in which this is done in Linux is by reading the legacy properties first (with a fallback on PHY_POL_NORMAL if absent) and then using them as "default" argument for phy_get_(rx|tx)_polarity(). The phy_get_manual_(rx|tx)_polarity() are intended for the use case where you have no legacy property to support.

Quoted 3 lines

I believe doing the same way here would simplify your logic quite a bit. No need to look at the specific "ret" value, and no need to duplicate the pbus_value modification.

Thank you for your comment.

I think I misinterpreted the code section.

I will re-examine the Linux implementation and refine my code accordingly.

Quoted 53 lines
Quoted 53 lines
drivers/net/phy/airoha/air_en8811.c +27 -14
+
+		dev_info(phydev->dev, "EN8811H: Legacy TX polarity\n");
+
+		if (ofnode_read_bool(node, "airoha,pnswap-tx"))
+			pbus_value &= ~EN8811H_POLARITY_TX_NORMAL;
+		else
+			pbus_value |= EN8811H_POLARITY_TX_NORMAL;
+	} else {
+		dev_err(phydev->dev, "EN8811H: Error reading tx-polarity: %d\n", ret);
+		return ret;
+	}
+
+	/* Apply polarity configuration to hardware */
+	ret = air_buckpbus_reg_modify(phydev, EN8811H_POLARITY,
+				      EN8811H_POLARITY_RX_REVERSE |
+				      EN8811H_POLARITY_TX_NORMAL, pbus_value);
+	if (ret < 0)
+		return ret;
+
+	return 0;
+}
+
+static int en8811h_config(struct phy_device *phydev)
+{
+	struct en8811h_priv *priv = phydev->priv;
  	int ret = 0;
 
  	/* If restart happened in .probe(), no need to restart now */
@@ -695,19 +767,8 @@ static int en8811h_config(struct phy_device *phydev)
  	if (ret < 0)
  		return ret;
 
-	/* Serdes polarity */
-	pbus_value = 0;
-	if (ofnode_read_bool(node, "airoha,pnswap-rx"))
-		pbus_value |=  EN8811H_POLARITY_RX_REVERSE;
-	else
-		pbus_value &= ~EN8811H_POLARITY_RX_REVERSE;
-	if (ofnode_read_bool(node, "airoha,pnswap-tx"))
-		pbus_value &= ~EN8811H_POLARITY_TX_NORMAL;
-	else
-		pbus_value |=  EN8811H_POLARITY_TX_NORMAL;
-	ret = air_buckpbus_reg_modify(phydev, EN8811H_POLARITY,
-				      EN8811H_POLARITY_RX_REVERSE |
-				      EN8811H_POLARITY_TX_NORMAL, pbus_value);
+	/* Configure Serdes polarity from device tree */
+	ret = en8811h_config_polarity(phydev);
  	if (ret < 0)
  		return ret;
 
--

2.34.1