phy: add common PHY polarity properties support
v5 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.
Patch 3 adds sandbox DM unit tests for the new library, ported from the Linux KUnit test (linux/drivers/phy/phy-common-props-test.c), along with the 8 sandbox DT test nodes in arch/sandbox/dts/test.dts and the CONFIG_PHY_COMMON_PROPS=y entry in configs/sandbox_defconfig. 16 unit test cases (8 for rx, 8 for tx) cover: missing property, single value with no names array, count mismatches, name-based lookup, missing default fallback, default fallback, and unsupported polarity value.
Changes in v5:
- patch 3: switch ret checks from ut_asserteq() to ut_assert() in PHY common props DM tests to avoid Coverity INTEGER_OVERFLOW false positives from signed-to-unsigned promotion in the test macro
Changes in v4:
- Squash former patches 3 and 4 into a single patch to fix bisectability (the test code referenced DT nodes that were only added in the following patch)
- Add CONFIG_PHY_COMMON_PROPS=y to configs/sandbox_defconfig
- patch 1: replace printf with pr_err for error-condition messages in phy-common-props.c
- patch 2: use phy_string_for_interface() instead of direct array access phy_interface_strings[] in en8811h_config_serdes_polarity()
- patch 2: remove unused local variables ofnode node and u32 pbus_value from en8811h_config()
Changes in v3:
- patch 1: fix ofnode_get_u32_prop_for_name() to apply default_val and return 0 when the polarity property is absent, instead of returning -ENOENT; update @node and @default_val kdoc accordingly — this aligns the "missing property" path with the behaviour expected by phy_get_manual_rx/tx_polarity() and is validated by the new unit tests
- Add unit tests for the PHY_COMMON_PROPS library (patches 3-4), ported from Linux KUnit test linux/drivers/phy/phy-common-props-test.c
- Add test/dm/Makefile build entry gated on CONFIG_PHY_COMMON_PROPS
- Add 8 sandbox DT nodes to arch/sandbox/dts/test.dts covering all test scenarios; include <dt-bindings/phy/phy.h> in test.dts
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 (3):
phy: add common PHY properties support
net: phy: airoha: air_en8811: use standard rx-polarity/tx-polarity properties
test: dm: add PHY common props unit tests and sandbox DT nodes
arch/sandbox/dts/test.dts | 60 +++++ configs/sandbox_defconfig | 1 + drivers/net/phy/airoha/Kconfig | 1 + drivers/net/phy/airoha/air_en8811.c | 60 +++-- drivers/phy/Kconfig | 8 + drivers/phy/Makefile | 1 + drivers/phy/phy-common-props.c | 286 ++++++++++++++++++++++++ include/linux/phy/phy-common-props.h | 69 ++++++ test/dm/Makefile | 1 + test/dm/phy_common_props.c | 319 +++++++++++++++++++++++++++ 10 files changed, 790 insertions(+), 16 deletions(-) create mode 100644 drivers/phy/phy-common-props.c create mode 100644 include/linux/phy/phy-common-props.h create mode 100644 test/dm/phy_common_props.c
--
2.34.1
PATCH v5 1/3 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 | 69 +++++++ 4 files changed, 364 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
@@ -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
@@ -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 +69 -0
69 lines not on this page · raw message
Signature · 1 line
2.34.1
PATCH v5 2/3 net: phy: airoha: air_en8811: use standard rx-polarity/tx-polarity properties
In reply to Lucien.JhengReplace 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.
Backward compatibility is maintained by reading the legacy boolean properties first and passing them as the default_pol argument to phy_get_rx/tx_polarity(). If the standard properties are absent the legacy values are used transparently, so existing device trees remain functional without modification.
---
``` dts config rx-polarity = <PHY_POL_INVERT>; tx-polarity = <PHY_POL_NORMAL>; ```en8811h init log with new PHY common props:
U-Boot 2026.01-rc5--gd1a76e2e4a64-dirty (Apr 25 2026 - 15:37:25 +0800)
131072 bytes read in 57 ms (2.2 MiB/s)
mtk-eth ethernet@15100000: MD32 firmware version: 24112802ofnode_read_bool: airoha,pnswap-rx: falsephy_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=0ofnode_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 directlyofnode_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' = 1ofnode_read_bool: airoha,pnswap-tx: falsephy_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=0ofnode_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 directlyofnode_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
drivers/net/phy/airoha/Kconfig | 1 + drivers/net/phy/airoha/air_en8811.c | 60 +++++++++++++++++++++-------- 2 files changed, 45 insertions(+), 16 deletions(-)
drivers/net/phy/airoha/Kconfig +1 -0
@@ -7,6 +7,7 @@ config PHY_AIROHA_EN8811 depends on PHY_AIROHA depends on SUPPORTS_FW_LOADER select FW_LOADER + select PHY_COMMON_PROPS help AIROHA EN8811H supported. AIROHA AN8811HB supported.
drivers/net/phy/airoha/air_en8811.c +44 -16
81 lines not on this page · raw message
--
2.34.1
PATCH v5 3/3 test: dm: add PHY common props unit tests and sandbox DT nodes
In reply to Lucien.JhengAdd sandbox DM unit tests for the PHY common properties library and the corresponding device tree test nodes to arch/sandbox/dts/test.dts. Also enable CONFIG_PHY_COMMON_PROPS in configs/sandbox_defconfig so the tests are built and run in the sandbox environment.
The test file covers rx/tx polarity lookups for all relevant cases:
- missing property (defaults to PHY_POL_NORMAL)
- single value without names array (applies to all modes)
- count mismatch between values and names arrays (-EINVAL)
- name found by exact match
- name not found with no "default" fallback (-EINVAL)
- name not found with a "default" entry (uses fallback value)
- unsupported polarity value (-EOPNOTSUPP)
Ported from Linux KUnit test:
linux/drivers/phy/phy-common-props-test.c
---
``` execute phy common props tests in sandbox:
Bloblist at 100 not found (err=-2)pinctrl_select_state_full() sandbox_serial serial: pinctrl_select_state_full: uclass_get_device_by_phandle_id: err=-19
U-Boot 2026.01-rc5--gd1a76e2e4a64-dirty (Apr 25 2026 - 15:40:39 +0800)
Reset Status: WARM Reset Status: COLD Model: sandbox DRAM: 256 MiB Core: 294 devices, 105 uclasses, devicetree: board, universal payload active WDT: Not starting wdt-gpio-toggle WDT: Not starting wdt-gpio-level WDT: Not starting wdt@0 NAND: 4100 MiB MMC: Can't map file 'mmc1.img': Invalid argument
sandbox_mmc_probe() mmc1: Unable to map file 'mmc1.img'
Can't map file 'mmc1.img': Invalid argument
sandbox_mmc_probe() mmc1: Unable to map file 'mmc1.img'
mmc_probe() mmc1 - probe failed: -1
mmc2: 2 (SD)Can't map file 'mmc1.img': Invalid argument
sandbox_mmc_probe() mmc1: Unable to map file 'mmc1.img'
, mmc0: 0 (SD)
Loading Environment from nowhere... OK
In: serial Out: serial,vidconsole Err: serial,vidconsole Model: sandbox Net: eth0: eth@10002000, eth5: eth@10003000, eth3: sbe5, eth6: eth@10004000, eth8: phy-test-eth, eth4: dsa-test-eth, eth2: lan0, eth7: lan1
Test: phy_common_props_rx_find_by_name: phy_common_props.c
Test: phy_common_props_rx_find_by_name: phy_common_props.c (flat tree)
Test: phy_common_props_rx_missing: phy_common_props.c
Test: phy_common_props_rx_missing: phy_common_props.c (flat tree)
Test: phy_common_props_rx_more_names: phy_common_props.c
Test: phy_common_props_rx_more_names: phy_common_props.c (flat tree)
Test: phy_common_props_rx_more_values: phy_common_props.c
Test: phy_common_props_rx_more_values: phy_common_props.c (flat tree)
Test: phy_common_props_rx_no_default: phy_common_props.c
Test: phy_common_props_rx_no_default: phy_common_props.c (flat tree)
Test: phy_common_props_rx_single_value: phy_common_props.c
Test: phy_common_props_rx_single_value: phy_common_props.c (flat tree)
Test: phy_common_props_rx_unsupported: phy_common_props.c
Test: phy_common_props_rx_unsupported: phy_common_props.c (flat tree)
Test: phy_common_props_rx_with_default: phy_common_props.c
Test: phy_common_props_rx_with_default: phy_common_props.c (flat tree)
Test: phy_common_props_tx_find_by_name: phy_common_props.c
Test: phy_common_props_tx_find_by_name: phy_common_props.c (flat tree)
Test: phy_common_props_tx_missing: phy_common_props.c
Test: phy_common_props_tx_missing: phy_common_props.c (flat tree)
Test: phy_common_props_tx_more_names: phy_common_props.c
Test: phy_common_props_tx_more_names: phy_common_props.c (flat tree)
Test: phy_common_props_tx_more_values: phy_common_props.c
Test: phy_common_props_tx_more_values: phy_common_props.c (flat tree)
Test: phy_common_props_tx_no_default: phy_common_props.c
Test: phy_common_props_tx_no_default: phy_common_props.c (flat tree)
Test: phy_common_props_tx_single_value: phy_common_props.c
Test: phy_common_props_tx_single_value: phy_common_props.c (flat tree)
Test: phy_common_props_tx_unsupported: phy_common_props.c
Test: phy_common_props_tx_unsupported: phy_common_props.c (flat tree)
Test: phy_common_props_tx_with_default: phy_common_props.c
Test: phy_common_props_tx_with_default: phy_common_props.c (flat tree) Tests run: 16, 41 ms, average: 2 ms, failures: 0
arch/sandbox/dts/test.dts | 60 +++++++ configs/sandbox_defconfig | 1 + test/dm/Makefile | 1 + test/dm/phy_common_props.c | 319 +++++++++++++++++++++++++++++++++++++ 4 files changed, 381 insertions(+) create mode 100644 test/dm/phy_common_props.c
arch/sandbox/dts/test.dts +60 -0
@@ -16,6 +16,7 @@ #include <dt-bindings/leds/common.h> #include <dt-bindings/pinctrl/sandbox-pinmux.h> #include <dt-bindings/mux/mux.h> +#include <dt-bindings/phy/phy.h> / { model = "sandbox";
@@ -502,6 +503,65 @@ phy-names = "phy1"; }; + /* PHY common props test nodes */ + phy_common_props_missing: phy-common-props-missing { + /* empty: no rx-polarity or tx-polarity properties */ + }; + + phy_common_props_more_values: phy-common-props-more-values { + /* 3 values but only 2 names => count mismatch */ + rx-polarity = <PHY_POL_NORMAL PHY_POL_INVERT PHY_POL_NORMAL>; + rx-polarity-names = "sgmii", "2500base-x"; + tx-polarity = <PHY_POL_NORMAL PHY_POL_INVERT PHY_POL_NORMAL>; + tx-polarity-names = "sgmii", "2500base-x"; + }; + + phy_common_props_single: phy-common-props-single { + /* 1 value, no names array => value applies to all modes */ + rx-polarity = <PHY_POL_INVERT>; + tx-polarity = <PHY_POL_INVERT>; + }; + + phy_common_props_more_names: phy-common-props-more-names { + /* 2 values but 3 names => count mismatch */ + rx-polarity = <PHY_POL_NORMAL PHY_POL_INVERT>; + rx-polarity-names = "sgmii", "2500base-x", "1000base-x"; + tx-polarity = <PHY_POL_NORMAL PHY_POL_INVERT>; + tx-polarity-names = "sgmii", "2500base-x", "1000base-x"; + }; + + phy_common_props_find_by_name: phy-common-props-find-by-name { + /* valid 3-element arrays, lookup by mode name */ + rx-polarity = <PHY_POL_NORMAL PHY_POL_INVERT PHY_POL_AUTO>; + rx-polarity-names = "sgmii", "2500base-x", "usb-ss"; + tx-polarity = <PHY_POL_NORMAL PHY_POL_INVERT PHY_POL_NORMAL>; + tx-polarity-names = "sgmii", "2500base-x", "1000base-x"; + }; + + phy_common_props_no_default: phy-common-props-no-default { + /* name not in array, no "default" entry => -EINVAL */ + rx-polarity = <PHY_POL_NORMAL PHY_POL_INVERT>; + rx-polarity-names = "2500base-x", "1000base-x"; + tx-polarity = <PHY_POL_NORMAL PHY_POL_INVERT>; + tx-polarity-names = "2500base-x", "1000base-x"; + }; + + phy_common_props_with_default: phy-common-props-with-default { + /* name not in array, but "default" entry exists */ + rx-polarity = <PHY_POL_NORMAL PHY_POL_INVERT>; + rx-polarity-names = "2500base-x", "default"; + tx-polarity = <PHY_POL_NORMAL PHY_POL_INVERT>; + tx-polarity-names = "2500base-x", "default"; + }; + + phy_common_props_unsupported: phy-common-props-unsupported { + /* PHY_POL_AUTO is not supported for manual-only modes */ + rx-polarity = <PHY_POL_AUTO>; + rx-polarity-names = "sgmii"; + tx-polarity = <PHY_POL_AUTO>; + tx-polarity-names = "sgmii"; + }; + some-bus { #address-cells = <1>; #size-cells = <0>;
configs/sandbox_defconfig +1 -0
@@ -284,6 +284,7 @@ CONFIG_PCI_REGION_MULTI_ENTRY=y CONFIG_PCI_FTPCI100=y CONFIG_PCI_SANDBOX=y CONFIG_PHY=y +CONFIG_PHY_COMMON_PROPS=y CONFIG_PHY_SANDBOX=y CONFIG_PINCTRL=y CONFIG_PINCONF=y
test/dm/Makefile +1 -0
@@ -88,6 +88,7 @@ obj-$(CONFIG_P2SB) += p2sb.o obj-$(CONFIG_PCI_ENDPOINT) += pci_ep.o obj-$(CONFIG_PCH) += pch.o obj-$(CONFIG_PHY) += phy.o +obj-$(CONFIG_PHY_COMMON_PROPS) += phy_common_props.o ifneq ($(CONFIG_PINMUX),) obj-$(CONFIG_PINCONF) += pinmux.o endif
test/dm/phy_common_props.c new file +319 -0
319 lines not on this page · raw message
--
2.34.1