public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties
@ 2026-01-11  9:39 Vladimir Oltean
  2026-01-11  9:39 ` [PATCH v3 net-next 01/10] dt-bindings: phy: rename transmit-amplitude.yaml to phy-common-props.yaml Vladimir Oltean
                   ` (11 more replies)
  0 siblings, 12 replies; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-11  9:39 UTC (permalink / raw)
  To: netdev, devicetree, linux-phy
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Bjørn Mork, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

Introduce "rx-polarity" and "tx-polarity" device tree properties.
Convert two existing networking use cases - the EN8811H Ethernet PHY and
the Mediatek LynxI PCS.

Requested merge strategy:
Patches 1-5 through linux-phy
linux-phy provides stable branch or tag to netdev
patches 6-10 through netdev

v2 at:
https://lore.kernel.org/netdev/20260103210403.438687-1-vladimir.oltean@nxp.com/
Changes since v2:
- fix bug with existing fwnode which is missing polarity properties.
  This is supposed to return the default value, not an error. (thanks to
  Bjørn Mork).
- fix inconsistency between PHY_COMMON_PROPS and GENERIC_PHY_COMMON_PROPS
  Kconfig options by using PHY_COMMON_PROPS everywhere (thanks to Bjørn
  Mork).

v1 at:
https://lore.kernel.org/netdev/20251122193341.332324-1-vladimir.oltean@nxp.com/
Changes since v1:
- API changes: split error code from returned value; introduce two new
  helpers for simple driver cases
- Add KUnit tests
- Bug fixes in core code and in drivers
- Defer XPCS patches for later (*)
- Convert Mediatek LynxI PCS
- Logical change: rx-polarity and tx-polarity refer to the currently
  described block, and not necessarily to device pins
- Apply Rob's feedback
- Drop the "joint maintainership" idea.

(*) To simplify the generic XPCS driver, I've decided to make
"tx-polarity" default to <PHY_POL_NORMAL>, rather than <PHY_POL_NORMAL>
OR <PHY_POL_INVERT> for SJA1105. But in order to avoid breakage, it
creates a hard dependency on this patch set being merged *first*:
https://lore.kernel.org/netdev/20251118190530.580267-1-vladimir.oltean@nxp.com/
so that the SJA1105 driver can provide an XPCS fwnode with the right
polarity specified. All patches in context can be seen at:
https://github.com/vladimiroltean/linux/tree/phy-polarity-inversion

Original cover letter:

Polarity inversion (described in patch 4/10) is a feature with at least
4 potential new users waiting for a generic description:
- Horatiu Vultur with the lan966x SerDes
- Daniel Golle with the MaxLinear GSW1xx switches
- Bjørn Mork with the AN8811HB Ethernet PHY
- Me with a custom SJA1105 board, switch which uses the DesignWare XPCS

I became interested in exploring the problem space because I was averse
to the idea of adding vendor-specific device tree properties to describe
a common need.

This set contains an implementation of a generic feature that should
cater to all known needs that were identified during my documentation
phase.

Apart from what is converted here, we also have the following, which I
did not touch:
- "st,px_rx_pol_inv" - its binding is a .txt file and I don't have time
  for such a large detour to convert it to dtschema.
- "st,pcie-tx-pol-inv" and "st,sata-tx-pol-inv" - these are defined in a
  .txt schema but are not implemented in any driver. My verdict would be
  "delete the properties" but again, I would prefer not introducing such
  dependency to this series.

Vladimir Oltean (10):
  dt-bindings: phy: rename transmit-amplitude.yaml to
    phy-common-props.yaml
  dt-bindings: phy-common-props: create a reusable "protocol-names"
    definition
  dt-bindings: phy-common-props: ensure protocol-names are unique
  dt-bindings: phy-common-props: RX and TX lane polarity inversion
  phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  dt-bindings: net: airoha,en8811h: deprecate "airoha,pnswap-rx" and
    "airoha,pnswap-tx"
  net: phy: air_en8811h: deprecate "airoha,pnswap-rx" and
    "airoha,pnswap-tx"
  dt-bindings: net: pcs: mediatek,sgmiisys: deprecate "mediatek,pnswap"
  net: pcs: pcs-mtk-lynxi: pass SGMIISYS OF node to PCS
  net: pcs: pcs-mtk-lynxi: deprecate "mediatek,pnswap"

 .../bindings/net/airoha,en8811h.yaml          |  11 +-
 .../bindings/net/pcs/mediatek,sgmiisys.yaml   |   7 +-
 .../bindings/phy/phy-common-props.yaml        | 157 +++++++
 .../bindings/phy/transmit-amplitude.yaml      | 103 -----
 MAINTAINERS                                   |  10 +
 drivers/net/dsa/mt7530-mdio.c                 |   4 +-
 drivers/net/ethernet/mediatek/mtk_eth_soc.c   |  19 +-
 drivers/net/pcs/Kconfig                       |   1 +
 drivers/net/pcs/pcs-mtk-lynxi.c               |  63 ++-
 drivers/net/phy/Kconfig                       |   1 +
 drivers/net/phy/air_en8811h.c                 |  53 ++-
 drivers/phy/Kconfig                           |  22 +
 drivers/phy/Makefile                          |   2 +
 drivers/phy/phy-common-props-test.c           | 422 ++++++++++++++++++
 drivers/phy/phy-common-props.c                | 209 +++++++++
 include/dt-bindings/phy/phy.h                 |   4 +
 include/linux/pcs/pcs-mtk-lynxi.h             |   5 +-
 include/linux/phy/phy-common-props.h          |  32 ++
 18 files changed, 979 insertions(+), 146 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-common-props.yaml
 delete mode 100644 Documentation/devicetree/bindings/phy/transmit-amplitude.yaml
 create mode 100644 drivers/phy/phy-common-props-test.c
 create mode 100644 drivers/phy/phy-common-props.c
 create mode 100644 include/linux/phy/phy-common-props.h

-- 
2.43.0


^ permalink raw reply	[flat|nested] 25+ messages in thread

* [PATCH v3 net-next 01/10] dt-bindings: phy: rename transmit-amplitude.yaml to phy-common-props.yaml
  2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
@ 2026-01-11  9:39 ` Vladimir Oltean
  2026-01-11  9:39 ` [PATCH v3 net-next 02/10] dt-bindings: phy-common-props: create a reusable "protocol-names" definition Vladimir Oltean
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-11  9:39 UTC (permalink / raw)
  To: netdev, devicetree, linux-phy
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Bjørn Mork, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

I would like to add more properties similar to tx-p2p-microvolt, and I
don't think it makes sense to create one schema for each such property
(transmit-amplitude.yaml, lane-polarity.yaml, transmit-equalization.yaml
etc).

Instead, let's rename to phy-common-props.yaml, which makes it a more
adequate host schema for all the above properties.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Acked-by: Rob Herring (Arm) <robh@kernel.org>
---
v1->v3: none

 .../{transmit-amplitude.yaml => phy-common-props.yaml}    | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
 rename Documentation/devicetree/bindings/phy/{transmit-amplitude.yaml => phy-common-props.yaml} (90%)

diff --git a/Documentation/devicetree/bindings/phy/transmit-amplitude.yaml b/Documentation/devicetree/bindings/phy/phy-common-props.yaml
similarity index 90%
rename from Documentation/devicetree/bindings/phy/transmit-amplitude.yaml
rename to Documentation/devicetree/bindings/phy/phy-common-props.yaml
index 617f3c0b3dfb..255205ac09cd 100644
--- a/Documentation/devicetree/bindings/phy/transmit-amplitude.yaml
+++ b/Documentation/devicetree/bindings/phy/phy-common-props.yaml
@@ -1,14 +1,14 @@
 # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause)
 %YAML 1.2
 ---
-$id: http://devicetree.org/schemas/phy/transmit-amplitude.yaml#
+$id: http://devicetree.org/schemas/phy/phy-common-props.yaml#
 $schema: http://devicetree.org/meta-schemas/core.yaml#
 
-title: Common PHY and network PCS transmit amplitude property
+title: Common PHY and network PCS properties
 
 description:
-  Binding describing the peak-to-peak transmit amplitude for common PHYs
-  and network PCSes.
+  Common PHY and network PCS properties, such as peak-to-peak transmit
+  amplitude.
 
 maintainers:
   - Marek Behún <kabel@kernel.org>
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 net-next 02/10] dt-bindings: phy-common-props: create a reusable "protocol-names" definition
  2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
  2026-01-11  9:39 ` [PATCH v3 net-next 01/10] dt-bindings: phy: rename transmit-amplitude.yaml to phy-common-props.yaml Vladimir Oltean
@ 2026-01-11  9:39 ` Vladimir Oltean
  2026-01-11  9:39 ` [PATCH v3 net-next 03/10] dt-bindings: phy-common-props: ensure protocol-names are unique Vladimir Oltean
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-11  9:39 UTC (permalink / raw)
  To: netdev, devicetree, linux-phy
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Bjørn Mork, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

Other properties also need to be defined per protocol than just
tx-p2p-microvolt-names. Create a common definition to avoid copying a 55
line property.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
---
v1->v3: none

 .../bindings/phy/phy-common-props.yaml        | 34 +++++++++++--------
 1 file changed, 19 insertions(+), 15 deletions(-)

diff --git a/Documentation/devicetree/bindings/phy/phy-common-props.yaml b/Documentation/devicetree/bindings/phy/phy-common-props.yaml
index 255205ac09cd..775f4dfe3cc3 100644
--- a/Documentation/devicetree/bindings/phy/phy-common-props.yaml
+++ b/Documentation/devicetree/bindings/phy/phy-common-props.yaml
@@ -13,22 +13,12 @@ description:
 maintainers:
   - Marek Behún <kabel@kernel.org>
 
-properties:
-  tx-p2p-microvolt:
+$defs:
+  protocol-names:
     description:
-      Transmit amplitude voltages in microvolts, peak-to-peak. If this property
-      contains multiple values for various PHY modes, the
-      'tx-p2p-microvolt-names' property must be provided and contain
-      corresponding mode names.
-
-  tx-p2p-microvolt-names:
-    description: |
-      Names of the modes corresponding to voltages in the 'tx-p2p-microvolt'
-      property. Required only if multiple voltages are provided.
-
-      If a value of 'default' is provided, the system should use it for any PHY
-      mode that is otherwise not defined here. If 'default' is not provided, the
-      system should use manufacturer default value.
+      Names of the PHY modes. If a value of 'default' is provided, the system
+      should use it for any PHY mode that is otherwise not defined here. If
+      'default' is not provided, the system should use manufacturer default value.
     minItems: 1
     maxItems: 16
     items:
@@ -89,6 +79,20 @@ properties:
         - mipi-dphy-univ
         - mipi-dphy-v2.5-univ
 
+properties:
+  tx-p2p-microvolt:
+    description:
+      Transmit amplitude voltages in microvolts, peak-to-peak. If this property
+      contains multiple values for various PHY modes, the
+      'tx-p2p-microvolt-names' property must be provided and contain
+      corresponding mode names.
+
+  tx-p2p-microvolt-names:
+    description:
+      Names of the modes corresponding to voltages in the 'tx-p2p-microvolt'
+      property. Required only if multiple voltages are provided.
+    $ref: "#/$defs/protocol-names"
+
 dependencies:
   tx-p2p-microvolt-names: [ tx-p2p-microvolt ]
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 net-next 03/10] dt-bindings: phy-common-props: ensure protocol-names are unique
  2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
  2026-01-11  9:39 ` [PATCH v3 net-next 01/10] dt-bindings: phy: rename transmit-amplitude.yaml to phy-common-props.yaml Vladimir Oltean
  2026-01-11  9:39 ` [PATCH v3 net-next 02/10] dt-bindings: phy-common-props: create a reusable "protocol-names" definition Vladimir Oltean
@ 2026-01-11  9:39 ` Vladimir Oltean
  2026-01-11  9:39 ` [PATCH v3 net-next 04/10] dt-bindings: phy-common-props: RX and TX lane polarity inversion Vladimir Oltean
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-11  9:39 UTC (permalink / raw)
  To: netdev, devicetree, linux-phy
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Bjørn Mork, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

Rob Herring points out that "The default for .*-names is the entries
don't have to be unique.":
https://lore.kernel.org/linux-phy/20251204155219.GA1533839-robh@kernel.org/

Let's use uniqueItems: true to make sure the schema enforces this. It
doesn't make sense in this case to have duplicate properties for the
same SerDes protocol.

Note that this can only be done with the $defs + $ref pattern as
established by the previous commit. When the tx-p2p-microvolt-names
constraints were expressed directly under "properties", it would have
been validated by the string-array meta-schema, which does not support
the 'uniqueItems' keyword as can be seen below.

properties:tx-p2p-microvolt-names: Additional properties are not allowed ('uniqueItems' was unexpected)
        from schema $id: http://devicetree.org/meta-schemas/string-array.yaml

Suggested-by: Rob Herring <robh@kernel.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
---
v2->v3: none
v1->v2: patch is new

 Documentation/devicetree/bindings/phy/phy-common-props.yaml | 1 +
 1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/phy/phy-common-props.yaml b/Documentation/devicetree/bindings/phy/phy-common-props.yaml
index 775f4dfe3cc3..31bf1382262a 100644
--- a/Documentation/devicetree/bindings/phy/phy-common-props.yaml
+++ b/Documentation/devicetree/bindings/phy/phy-common-props.yaml
@@ -21,6 +21,7 @@ $defs:
       'default' is not provided, the system should use manufacturer default value.
     minItems: 1
     maxItems: 16
+    uniqueItems: true
     items:
       enum:
         - default
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 net-next 04/10] dt-bindings: phy-common-props: RX and TX lane polarity inversion
  2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
                   ` (2 preceding siblings ...)
  2026-01-11  9:39 ` [PATCH v3 net-next 03/10] dt-bindings: phy-common-props: ensure protocol-names are unique Vladimir Oltean
@ 2026-01-11  9:39 ` Vladimir Oltean
  2026-01-11  9:39 ` [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity() Vladimir Oltean
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-11  9:39 UTC (permalink / raw)
  To: netdev, devicetree, linux-phy
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Bjørn Mork, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

Differential signaling is a technique for high-speed protocols to be
more resilient to noise. At the transmit side we have a positive and a
negative signal which are mirror images of each other. At the receiver,
if we subtract the negative signal (say of amplitude -A) from the
positive signal (say +A), we recover the original single-ended signal at
twice its original amplitude. But any noise, like one coming from EMI
from outside sources, is supposed to have an almost equal impact upon
the positive (A + E, E being for "error") and negative signal (-A + E).
So (A + E) - (-A + E) eliminates this noise, and this is what makes
differential signaling useful.

Except that in order to work, there must be strict requirements observed
during PCB design and layout, like the signal traces needing to have the
same length and be physically close to each other, and many others.

Sometimes it is not easy to fulfill all these requirements, a simple
case to understand is when on chip A's pins, the positive pin is on the
left and the negative is on the right, but on the chip B's pins (with
which A tries to communicate), positive is on the right and negative on
the left. The signals would need to cross, using vias and other ugly
stuff that affects signal integrity (introduces impedance
discontinuities which cause reflections, etc).

So sometimes, board designers intentionally connect differential lanes
the wrong way, and expect somebody else to invert that signal to recover
useful data. This is where RX and TX polarity inversion comes in as a
generic concept that applies to any high-speed serial protocol as long
as it uses differential signaling.

I've stopped two attempts to introduce more vendor-specific descriptions
of this only in the past month:
https://lore.kernel.org/linux-phy/20251110110536.2596490-1-horatiu.vultur@microchip.com/
https://lore.kernel.org/netdev/20251028000959.3kiac5kwo5pcl4ft@skbuf/

and in the kernel we already have merged:
- "st,px_rx_pol_inv"
- "st,pcie-tx-pol-inv"
- "st,sata-tx-pol-inv"
- "mediatek,pnswap"
- "airoha,pnswap-rx"
- "airoha,pnswap-tx"

and maybe more. So it is pretty general.

One additional element of complexity is introduced by the fact that for
some protocols, receivers can automatically detect and correct for an
inverted lane polarity (example: the PCIe LTSSM does this in the
Polling.Configuration state; the USB 3.1 Link Layer Test Specification
says that the detection and correction of the lane polarity inversion in
SuperSpeed operation shall be enabled in Polling.RxEQ.). Whereas for
other protocols (SGMII, SATA, 10GBase-R, etc etc), the polarity is all
manual and there is no detection mechanism mandated by their respective
standards.

So why would one even describe rx-polarity and tx-polarity for protocols
like PCIe, if it had to always be PHY_POL_AUTO?

Related question: why would we define the polarity as an array per
protocol? Isn't the physical PCB layout protocol-agnostic, and aren't we
describing the same physical reality from the lens of different protocols?

The answer to both questions is because multi-protocol PHYs exist
(supporting e.g. USB2 and USB3, or SATA and PCIe, or PCIe and Ethernet
over the same lane), one would need to manually set the polarity for
SATA/Ethernet, while leaving it at auto for PCIe/USB 3.0+.

I also investigated from another angle: what if polarity inversion in
the PHY is one layer, and then the PCIe/USB3 LTSSM polarity detection is
another layer on top? Then rx-polarity = <PHY_POL_AUTO> doesn't make
sense, it can still be rx-polarity = <PHY_POL_NORMAL> or <PHY_POL_INVERT>,
and the link training state machine figures things out on top of that.
This would radically simplify the design, as the elimination of
PHY_POL_AUTO inherently means that the need for a property array per
protocol also goes away.

I don't know how things are in the general case, but at least in the 10G
and 28G Lynx SerDes blocks from NXP Layerscape devices, this isn't the
case, and there's only a single level of RX polarity inversion: in the
SerDes lane. In the case of PCIe, the controller is in charge of driving
the RDAT_INV bit autonomously, and it is read-only to software.

So the existence of this kind of SerDes lane proves the need for
PHY_POL_AUTO to be a third state.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
---
v2->v3: none
v1->v2:
- logical change: the bindings refer to the described block's I/O
  signals, not necessarily device pins. This means that a PCS that needs
  to internall invert a polarity to work around an inverting PMA in
  order to achieve normal polarity at the pin needs to be described as
  PHY_POL_INVERT now.
- clarify that default values are undefined.
- fix a checkpatch issue: duplicated "the the" in rx-polarity description

 .../bindings/phy/phy-common-props.yaml        | 49 +++++++++++++++++++
 include/dt-bindings/phy/phy.h                 |  4 ++
 2 files changed, 53 insertions(+)

diff --git a/Documentation/devicetree/bindings/phy/phy-common-props.yaml b/Documentation/devicetree/bindings/phy/phy-common-props.yaml
index 31bf1382262a..b2c709cc1b0d 100644
--- a/Documentation/devicetree/bindings/phy/phy-common-props.yaml
+++ b/Documentation/devicetree/bindings/phy/phy-common-props.yaml
@@ -94,15 +94,64 @@ properties:
       property. Required only if multiple voltages are provided.
     $ref: "#/$defs/protocol-names"
 
+  rx-polarity:
+    description:
+      An array of values indicating whether the differential receiver's
+      polarity is inverted. Each value can be one of
+      PHY_POL_NORMAL (0) which means the negative signal is decoded from the
+      RXN input, and the positive signal from the RXP input;
+      PHY_POL_INVERT (1) which means the negative signal is decoded from the
+      RXP input, and the positive signal from the RXN input;
+      PHY_POL_AUTO (2) which means the receiver performs automatic polarity
+      detection and correction, which is a mandatory part of link training for
+      some protocols (PCIe, USB SS).
+
+      The values are defined in <dt-bindings/phy/phy.h>. If the property is
+      absent, the default value is undefined.
+
+      Note that the RXP and RXN inputs refer to the block that this property is
+      under, and do not necessarily directly translate to external pins.
+
+      If this property contains multiple values for various protocols, the
+      'rx-polarity-names' property must be provided.
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 1
+    maxItems: 16
+    items:
+      enum: [0, 1, 2]
+
+  rx-polarity-names:
+    $ref: '#/$defs/protocol-names'
+
+  tx-polarity:
+    description:
+      Like 'rx-polarity', except it applies to differential transmitters,
+      and only the values of PHY_POL_NORMAL and PHY_POL_INVERT are possible.
+    $ref: /schemas/types.yaml#/definitions/uint32-array
+    minItems: 1
+    maxItems: 16
+    items:
+      enum: [0, 1]
+
+  tx-polarity-names:
+    $ref: '#/$defs/protocol-names'
+
 dependencies:
   tx-p2p-microvolt-names: [ tx-p2p-microvolt ]
+  rx-polarity-names: [ rx-polarity ]
+  tx-polarity-names: [ tx-polarity ]
 
 additionalProperties: true
 
 examples:
   - |
+    #include <dt-bindings/phy/phy.h>
+
     phy: phy {
       #phy-cells = <1>;
       tx-p2p-microvolt = <915000>, <1100000>, <1200000>;
       tx-p2p-microvolt-names = "2500base-x", "usb-hs", "usb-ss";
+      rx-polarity = <PHY_POL_AUTO>, <PHY_POL_NORMAL>;
+      rx-polarity-names = "usb-ss", "default";
+      tx-polarity = <PHY_POL_INVERT>;
     };
diff --git a/include/dt-bindings/phy/phy.h b/include/dt-bindings/phy/phy.h
index 6b901b342348..f8d4094f0880 100644
--- a/include/dt-bindings/phy/phy.h
+++ b/include/dt-bindings/phy/phy.h
@@ -24,4 +24,8 @@
 #define PHY_TYPE_CPHY		11
 #define PHY_TYPE_USXGMII	12
 
+#define PHY_POL_NORMAL		0
+#define PHY_POL_INVERT		1
+#define PHY_POL_AUTO		2
+
 #endif /* _DT_BINDINGS_PHY */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
                   ` (3 preceding siblings ...)
  2026-01-11  9:39 ` [PATCH v3 net-next 04/10] dt-bindings: phy-common-props: RX and TX lane polarity inversion Vladimir Oltean
@ 2026-01-11  9:39 ` Vladimir Oltean
  2026-01-11 11:53   ` Bjørn Mork
  2026-02-26 13:22   ` Geert Uytterhoeven
  2026-01-11  9:39 ` [PATCH v3 net-next 06/10] dt-bindings: net: airoha,en8811h: deprecate "airoha,pnswap-rx" and "airoha,pnswap-tx" Vladimir Oltean
                   ` (6 subsequent siblings)
  11 siblings, 2 replies; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-11  9:39 UTC (permalink / raw)
  To: netdev, devicetree, linux-phy
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Bjørn Mork, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

Add helpers in the generic PHY folder which can be used using 'select
GENERIC_PHY_COMMON_PROPS' from Kconfig, without otherwise needing to
enable GENERIC_PHY.

These helpers need to deal with the slight messiness of the fact that
the polarity properties are arrays per protocol, and with the fact that
there is no default value mandated by the standard properties, all
default values depend on driver and protocol (PHY_POL_NORMAL may be a
good default for SGMII, whereas PHY_POL_AUTO may be a good default for
PCIe).

Push the supported mask of polarities to these helpers, to simplify
drivers such that they don't need to validate what's in the device tree
(or other firmware description).

Add a KUnit test suite to make sure that the API produces the expected
results. The fact that we use fwnode structures means we can validate
with software nodes, and as opposed to the device_property API, we can
bypass the need to have a device structure.

Co-developed-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Bjørn Mork <bjorn@mork.no>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
Note that on 32-bit systems I am expecting a sparse warning:
drivers/phy/phy-common-props-test.c:420:1: error: bad constant expression
drivers/phy/phy-common-props-test.c:421:1: error: bad constant expression
drivers/phy/phy-common-props-test.c:422:1: error: bad constant expression
caused by:
https://lore.kernel.org/lkml/20251008033844.work.801-kees@kernel.org/
AFAIU this is pending a fix in sparse 0.6.5, not available yet.

v2->v3:
- rename GENERIC_PHY_COMMON_PROPS to just PHY_COMMON_PROPS (more
  representative).
- fix case where querying PHY polarity returned error for fwnode with
  missing property, rather than default value, as reported by Bjorn
  Mork.
- add tests for the above condition
- add credits to Bjorn Mork for signaling the above.
v1->v2:
- add KUnit test suite
- replace joint maintainership model with linux-phy being the only tree.
- split the combined return code (if negative, error, if positive, valid
  return value) into a single "error or zero" return code and an
  unsigned int pointer argument to the returned polarity
- add __must_check to ensure that callers are forced to test for errors
- add a reusable fwnode_get_u32_prop_for_name() helper for further
  property parsing
- remove support for looking up polarity of a NULL PHY mode
- introduce phy_get_manual_rx_polarity() and
  phy_get_manual_tx_polarity() helpers to reduce boilerplate in simple
  drivers
- bug fix: a polarity defined as a single value rather than an array was
  not validated against the supported mask
- bug fix: the default polarity was not validated against the supported
  mask
- bug fix: wrong error message if the polarity value is unsupported

 MAINTAINERS                          |  10 +
 drivers/phy/Kconfig                  |  22 ++
 drivers/phy/Makefile                 |   2 +
 drivers/phy/phy-common-props-test.c  | 422 +++++++++++++++++++++++++++
 drivers/phy/phy-common-props.c       | 209 +++++++++++++
 include/linux/phy/phy-common-props.h |  32 ++
 6 files changed, 697 insertions(+)
 create mode 100644 drivers/phy/phy-common-props-test.c
 create mode 100644 drivers/phy/phy-common-props.c
 create mode 100644 include/linux/phy/phy-common-props.h

diff --git a/MAINTAINERS b/MAINTAINERS
index 6737aad729d6..aa82c3f6a89f 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -20519,6 +20519,16 @@ L:	linux-mtd@lists.infradead.org
 S:	Maintained
 F:	drivers/mtd/devices/phram.c
 
+PHY COMMON PROPERTIES
+M:	Vladimir Oltean <vladimir.oltean@nxp.com>
+L:	netdev@vger.kernel.org
+S:	Maintained
+Q:	https://patchwork.kernel.org/project/netdevbpf/list/
+F:	Documentation/devicetree/bindings/phy/phy-common-props.yaml
+F:	drivers/phy/phy-common-props-test.c
+F:	drivers/phy/phy-common-props.c
+F:	include/linux/phy/phy-common-props.h
+
 PICOLCD HID DRIVER
 M:	Bruno Prémont <bonbons@linux-vserver.org>
 L:	linux-input@vger.kernel.org
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 678dd0452f0a..62153a3924b9 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -5,6 +5,28 @@
 
 menu "PHY Subsystem"
 
+config PHY_COMMON_PROPS
+	bool
+	help
+	  This parses properties common between generic PHYs and Ethernet PHYs.
+
+	  Select this from consumer drivers to gain access to helpers for
+	  parsing properties from the
+	  Documentation/devicetree/bindings/phy/phy-common-props.yaml schema.
+
+config PHY_COMMON_PROPS_TEST
+	tristate "KUnit tests for PHY common props" if !KUNIT_ALL_TESTS
+	select PHY_COMMON_PROPS
+	depends on KUNIT
+	default KUNIT_ALL_TESTS
+	help
+	  This builds KUnit tests for the PHY common property API.
+
+	  For more information on KUnit and unit tests in general,
+	  please refer to the KUnit documentation in Documentation/dev-tools/kunit/.
+
+	  When in doubt, say N.
+
 config GENERIC_PHY
 	bool "PHY Core"
 	help
diff --git a/drivers/phy/Makefile b/drivers/phy/Makefile
index bfb27fb5a494..30b150d68de7 100644
--- a/drivers/phy/Makefile
+++ b/drivers/phy/Makefile
@@ -3,6 +3,8 @@
 # Makefile for the phy drivers.
 #
 
+obj-$(CONFIG_PHY_COMMON_PROPS)		+= phy-common-props.o
+obj-$(CONFIG_PHY_COMMON_PROPS_TEST)	+= phy-common-props-test.o
 obj-$(CONFIG_GENERIC_PHY)		+= phy-core.o
 obj-$(CONFIG_GENERIC_PHY_MIPI_DPHY)	+= phy-core-mipi-dphy.o
 obj-$(CONFIG_PHY_CAN_TRANSCEIVER)	+= phy-can-transceiver.o
diff --git a/drivers/phy/phy-common-props-test.c b/drivers/phy/phy-common-props-test.c
new file mode 100644
index 000000000000..e937ec8a4126
--- /dev/null
+++ b/drivers/phy/phy-common-props-test.c
@@ -0,0 +1,422 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * phy-common-props-test.c  --  Unit tests for PHY common properties API
+ *
+ * Copyright 2025-2026 NXP
+ */
+#include <kunit/test.h>
+#include <linux/property.h>
+#include <linux/phy/phy-common-props.h>
+#include <dt-bindings/phy/phy.h>
+
+/* Test: rx-polarity property is missing */
+static void phy_test_rx_polarity_is_missing(struct kunit *test)
+{
+	static const struct property_entry entries[] = {
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, val, PHY_POL_NORMAL);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: rx-polarity has more values than rx-polarity-names */
+static void phy_test_rx_polarity_more_values_than_names(struct kunit *test)
+{
+	static const u32 rx_pol[] = { PHY_POL_NORMAL, PHY_POL_INVERT, PHY_POL_NORMAL };
+	static const char * const rx_pol_names[] = { "sgmii", "2500base-x" };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("rx-polarity", rx_pol),
+		PROPERTY_ENTRY_STRING_ARRAY("rx-polarity-names", rx_pol_names),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: rx-polarity has 1 value and rx-polarity-names does not exist */
+static void phy_test_rx_polarity_single_value_no_names(struct kunit *test)
+{
+	static const u32 rx_pol[] = { PHY_POL_INVERT };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("rx-polarity", rx_pol),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, val, PHY_POL_INVERT);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: rx-polarity-names has more values than rx-polarity */
+static void phy_test_rx_polarity_more_names_than_values(struct kunit *test)
+{
+	static const u32 rx_pol[] = { PHY_POL_NORMAL, PHY_POL_INVERT };
+	static const char * const rx_pol_names[] = { "sgmii", "2500base-x", "1000base-x" };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("rx-polarity", rx_pol),
+		PROPERTY_ENTRY_STRING_ARRAY("rx-polarity-names", rx_pol_names),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: rx-polarity and rx-polarity-names have same length, find the name */
+static void phy_test_rx_polarity_find_by_name(struct kunit *test)
+{
+	static const u32 rx_pol[] = { PHY_POL_NORMAL, PHY_POL_INVERT, PHY_POL_AUTO };
+	static const char * const rx_pol_names[] = { "sgmii", "2500base-x", "usb-ss" };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("rx-polarity", rx_pol),
+		PROPERTY_ENTRY_STRING_ARRAY("rx-polarity-names", rx_pol_names),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, val, PHY_POL_NORMAL);
+
+	ret = phy_get_manual_rx_polarity(node, "2500base-x", &val);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, val, PHY_POL_INVERT);
+
+	ret = phy_get_rx_polarity(node, "usb-ss", BIT(PHY_POL_AUTO),
+				  PHY_POL_AUTO, &val);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, val, PHY_POL_AUTO);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: same length, name not found, no "default" - error */
+static void phy_test_rx_polarity_name_not_found_no_default(struct kunit *test)
+{
+	static const u32 rx_pol[] = { PHY_POL_NORMAL, PHY_POL_INVERT };
+	static const char * const rx_pol_names[] = { "2500base-x", "1000base-x" };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("rx-polarity", rx_pol),
+		PROPERTY_ENTRY_STRING_ARRAY("rx-polarity-names", rx_pol_names),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: same length, name not found, but "default" exists */
+static void phy_test_rx_polarity_name_not_found_with_default(struct kunit *test)
+{
+	static const u32 rx_pol[] = { PHY_POL_NORMAL, PHY_POL_INVERT };
+	static const char * const rx_pol_names[] = { "2500base-x", "default" };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("rx-polarity", rx_pol),
+		PROPERTY_ENTRY_STRING_ARRAY("rx-polarity-names", rx_pol_names),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, val, PHY_POL_INVERT);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: polarity found but value is unsupported */
+static void phy_test_rx_polarity_unsupported_value(struct kunit *test)
+{
+	static const u32 rx_pol[] = { PHY_POL_AUTO };
+	static const char * const rx_pol_names[] = { "sgmii" };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("rx-polarity", rx_pol),
+		PROPERTY_ENTRY_STRING_ARRAY("rx-polarity-names", rx_pol_names),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_rx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, -EOPNOTSUPP);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: tx-polarity property is missing */
+static void phy_test_tx_polarity_is_missing(struct kunit *test)
+{
+	static const struct property_entry entries[] = {
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, val, PHY_POL_NORMAL);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: tx-polarity has more values than tx-polarity-names */
+static void phy_test_tx_polarity_more_values_than_names(struct kunit *test)
+{
+	static const u32 tx_pol[] = { PHY_POL_NORMAL, PHY_POL_INVERT, PHY_POL_NORMAL };
+	static const char * const tx_pol_names[] = { "sgmii", "2500base-x" };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("tx-polarity", tx_pol),
+		PROPERTY_ENTRY_STRING_ARRAY("tx-polarity-names", tx_pol_names),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: tx-polarity has 1 value and tx-polarity-names does not exist */
+static void phy_test_tx_polarity_single_value_no_names(struct kunit *test)
+{
+	static const u32 tx_pol[] = { PHY_POL_INVERT };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("tx-polarity", tx_pol),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, val, PHY_POL_INVERT);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: tx-polarity-names has more values than tx-polarity */
+static void phy_test_tx_polarity_more_names_than_values(struct kunit *test)
+{
+	static const u32 tx_pol[] = { PHY_POL_NORMAL, PHY_POL_INVERT };
+	static const char * const tx_pol_names[] = { "sgmii", "2500base-x", "1000base-x" };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("tx-polarity", tx_pol),
+		PROPERTY_ENTRY_STRING_ARRAY("tx-polarity-names", tx_pol_names),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: tx-polarity and tx-polarity-names have same length, find the name */
+static void phy_test_tx_polarity_find_by_name(struct kunit *test)
+{
+	static const u32 tx_pol[] = { PHY_POL_NORMAL, PHY_POL_INVERT, PHY_POL_NORMAL };
+	static const char * const tx_pol_names[] = { "sgmii", "2500base-x", "1000base-x" };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("tx-polarity", tx_pol),
+		PROPERTY_ENTRY_STRING_ARRAY("tx-polarity-names", tx_pol_names),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, val, PHY_POL_NORMAL);
+
+	ret = phy_get_manual_tx_polarity(node, "2500base-x", &val);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, val, PHY_POL_INVERT);
+
+	ret = phy_get_manual_tx_polarity(node, "1000base-x", &val);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, val, PHY_POL_NORMAL);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: same length, name not found, no "default" - error */
+static void phy_test_tx_polarity_name_not_found_no_default(struct kunit *test)
+{
+	static const u32 tx_pol[] = { PHY_POL_NORMAL, PHY_POL_INVERT };
+	static const char * const tx_pol_names[] = { "2500base-x", "1000base-x" };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("tx-polarity", tx_pol),
+		PROPERTY_ENTRY_STRING_ARRAY("tx-polarity-names", tx_pol_names),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, -EINVAL);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: same length, name not found, but "default" exists */
+static void phy_test_tx_polarity_name_not_found_with_default(struct kunit *test)
+{
+	static const u32 tx_pol[] = { PHY_POL_NORMAL, PHY_POL_INVERT };
+	static const char * const tx_pol_names[] = { "2500base-x", "default" };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("tx-polarity", tx_pol),
+		PROPERTY_ENTRY_STRING_ARRAY("tx-polarity-names", tx_pol_names),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, 0);
+	KUNIT_EXPECT_EQ(test, val, PHY_POL_INVERT);
+
+	fwnode_remove_software_node(node);
+}
+
+/* Test: polarity found but value is unsupported (AUTO for TX) */
+static void phy_test_tx_polarity_unsupported_value(struct kunit *test)
+{
+	static const u32 tx_pol[] = { PHY_POL_AUTO };
+	static const char * const tx_pol_names[] = { "sgmii" };
+	static const struct property_entry entries[] = {
+		PROPERTY_ENTRY_U32_ARRAY("tx-polarity", tx_pol),
+		PROPERTY_ENTRY_STRING_ARRAY("tx-polarity-names", tx_pol_names),
+		{}
+	};
+	struct fwnode_handle *node;
+	unsigned int val;
+	int ret;
+
+	node = fwnode_create_software_node(entries, NULL);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, node);
+
+	ret = phy_get_manual_tx_polarity(node, "sgmii", &val);
+	KUNIT_EXPECT_EQ(test, ret, -EOPNOTSUPP);
+
+	fwnode_remove_software_node(node);
+}
+
+static struct kunit_case phy_common_props_test_cases[] = {
+	KUNIT_CASE(phy_test_rx_polarity_is_missing),
+	KUNIT_CASE(phy_test_rx_polarity_more_values_than_names),
+	KUNIT_CASE(phy_test_rx_polarity_single_value_no_names),
+	KUNIT_CASE(phy_test_rx_polarity_more_names_than_values),
+	KUNIT_CASE(phy_test_rx_polarity_find_by_name),
+	KUNIT_CASE(phy_test_rx_polarity_name_not_found_no_default),
+	KUNIT_CASE(phy_test_rx_polarity_name_not_found_with_default),
+	KUNIT_CASE(phy_test_rx_polarity_unsupported_value),
+	KUNIT_CASE(phy_test_tx_polarity_is_missing),
+	KUNIT_CASE(phy_test_tx_polarity_more_values_than_names),
+	KUNIT_CASE(phy_test_tx_polarity_single_value_no_names),
+	KUNIT_CASE(phy_test_tx_polarity_more_names_than_values),
+	KUNIT_CASE(phy_test_tx_polarity_find_by_name),
+	KUNIT_CASE(phy_test_tx_polarity_name_not_found_no_default),
+	KUNIT_CASE(phy_test_tx_polarity_name_not_found_with_default),
+	KUNIT_CASE(phy_test_tx_polarity_unsupported_value),
+	{}
+};
+
+static struct kunit_suite phy_common_props_test_suite = {
+	.name = "phy-common-props",
+	.test_cases = phy_common_props_test_cases,
+};
+
+kunit_test_suite(phy_common_props_test_suite);
+
+MODULE_DESCRIPTION("Test module for PHY common properties API");
+MODULE_AUTHOR("Vladimir Oltean <vladimir.oltean@nxp.com>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/phy/phy-common-props.c b/drivers/phy/phy-common-props.c
new file mode 100644
index 000000000000..3e814bcbea86
--- /dev/null
+++ b/drivers/phy/phy-common-props.c
@@ -0,0 +1,209 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * phy-common-props.c  --  Common PHY properties
+ *
+ * Copyright 2025-2026 NXP
+ */
+#include <linux/export.h>
+#include <linux/fwnode.h>
+#include <linux/phy/phy-common-props.h>
+#include <linux/printk.h>
+#include <linux/property.h>
+#include <linux/slab.h>
+
+/**
+ * fwnode_get_u32_prop_for_name - Find u32 property by name, or default value
+ * @fwnode: Pointer to firmware node, or NULL to use @default_val
+ * @name: Property name used as lookup key in @names_title (must not be NULL)
+ * @props_title: Name of u32 array property holding values
+ * @names_title: Name of string array property holding lookup keys
+ * @default_val: Default value if @fwnode is NULL or @props_title is empty
+ * @val: Pointer to store the returned value
+ *
+ * This function retrieves a u32 value from @props_title based on a name lookup
+ * in @names_title. The value stored in @val is determined as follows:
+ *
+ * - If @fwnode is NULL or @props_title is empty: @default_val is used
+ * - If @props_title has exactly one element and @names_title is empty:
+ *   that element is used
+ * - Otherwise: @val is set to the element at the same index where @name is
+ *   found in @names_title.
+ * - If @name is not found, the function looks for a "default" entry in
+ *   @names_title and uses the corresponding value from @props_title
+ *
+ * When both @props_title and @names_title are present, they must have the
+ * same number of elements (except when @props_title has exactly one element).
+ *
+ * Return: zero on success, negative error on failure.
+ */
+static int fwnode_get_u32_prop_for_name(struct fwnode_handle *fwnode,
+					const char *name,
+					const char *props_title,
+					const char *names_title,
+					unsigned int default_val,
+					unsigned int *val)
+{
+	int err, n_props, n_names, idx;
+	u32 *props;
+
+	if (!name) {
+		pr_err("Lookup key inside \"%s\" is mandatory\n", names_title);
+		return -EINVAL;
+	}
+
+	n_props = fwnode_property_count_u32(fwnode, props_title);
+	if (n_props <= 0) {
+		/* fwnode is NULL, or is missing requested property */
+		*val = default_val;
+		return 0;
+	}
+
+	n_names = fwnode_property_string_array_count(fwnode, names_title);
+	if (n_names >= 0 && n_props != n_names) {
+		pr_err("%pfw mismatch between \"%s\" and \"%s\" property count (%d vs %d)\n",
+		       fwnode, props_title, names_title, n_props, n_names);
+		return -EINVAL;
+	}
+
+	idx = fwnode_property_match_string(fwnode, names_title, name);
+	if (idx < 0)
+		idx = fwnode_property_match_string(fwnode, names_title, "default");
+	/*
+	 * If the mode name is missing, it can only mean the specified property
+	 * is the default one for all modes, so reject any other property count
+	 * than 1.
+	 */
+	if (idx < 0 && n_props != 1) {
+		pr_err("%pfw \"%s \" property has %d elements, but cannot find \"%s\" in \"%s\" and there is no default value\n",
+		       fwnode, props_title, n_props, name, names_title);
+		return -EINVAL;
+	}
+
+	if (n_props == 1) {
+		err = fwnode_property_read_u32(fwnode, props_title, val);
+		if (err)
+			return err;
+
+		return 0;
+	}
+
+	/* We implicitly know idx >= 0 here */
+	props = kcalloc(n_props, sizeof(*props), GFP_KERNEL);
+	if (!props)
+		return -ENOMEM;
+
+	err = fwnode_property_read_u32_array(fwnode, props_title, props, n_props);
+	if (err >= 0)
+		*val = props[idx];
+
+	kfree(props);
+
+	return err;
+}
+
+static int phy_get_polarity_for_mode(struct fwnode_handle *fwnode,
+				     const char *mode_name,
+				     unsigned int supported,
+				     unsigned int default_val,
+				     const char *polarity_prop,
+				     const char *names_prop,
+				     unsigned int *val)
+{
+	int err;
+
+	err = fwnode_get_u32_prop_for_name(fwnode, mode_name, polarity_prop,
+					   names_prop, default_val, val);
+	if (err)
+		return err;
+
+	if (!(supported & BIT(*val))) {
+		pr_err("%d is not a supported value for %pfw '%s' element '%s'\n",
+		       *val, fwnode, polarity_prop, mode_name);
+		err = -EOPNOTSUPP;
+	}
+
+	return err;
+}
+
+/**
+ * phy_get_rx_polarity - Get RX polarity for PHY differential lane
+ * @fwnode: Pointer to the PHY's firmware node.
+ * @mode_name: The name of the PHY mode to look up.
+ * @supported: Bit mask of PHY_POL_NORMAL, PHY_POL_INVERT and PHY_POL_AUTO
+ * @default_val: Default polarity value if property is missing
+ * @val: Pointer to returned polarity.
+ *
+ * Return: zero on success, negative error on failure.
+ */
+int __must_check phy_get_rx_polarity(struct fwnode_handle *fwnode,
+				     const char *mode_name,
+				     unsigned int supported,
+				     unsigned int default_val,
+				     unsigned int *val)
+{
+	return phy_get_polarity_for_mode(fwnode, mode_name, supported,
+					 default_val, "rx-polarity",
+					 "rx-polarity-names", val);
+}
+EXPORT_SYMBOL_GPL(phy_get_rx_polarity);
+
+/**
+ * phy_get_tx_polarity - Get TX polarity for PHY differential lane
+ * @fwnode: Pointer to the PHY's firmware node.
+ * @mode_name: The name of the PHY mode to look up.
+ * @supported: Bit mask of PHY_POL_NORMAL and PHY_POL_INVERT
+ * @default_val: Default polarity value if property is missing
+ * @val: Pointer to returned polarity.
+ *
+ * Return: zero on success, negative error on failure.
+ */
+int __must_check phy_get_tx_polarity(struct fwnode_handle *fwnode,
+				     const char *mode_name, unsigned int supported,
+				     unsigned int default_val, unsigned int *val)
+{
+	return phy_get_polarity_for_mode(fwnode, mode_name, supported,
+					 default_val, "tx-polarity",
+					 "tx-polarity-names", val);
+}
+EXPORT_SYMBOL_GPL(phy_get_tx_polarity);
+
+/**
+ * phy_get_manual_rx_polarity - Get manual RX polarity for PHY differential lane
+ * @fwnode: Pointer to the PHY's firmware node.
+ * @mode_name: The name of the PHY mode to look up.
+ * @val: Pointer to returned polarity.
+ *
+ * Helper for PHYs which do not support protocols with automatic RX polarity
+ * detection and correction.
+ *
+ * Return: zero on success, negative error on failure.
+ */
+int __must_check phy_get_manual_rx_polarity(struct fwnode_handle *fwnode,
+					    const char *mode_name,
+					    unsigned int *val)
+{
+	return phy_get_rx_polarity(fwnode, mode_name,
+				   BIT(PHY_POL_NORMAL) | BIT(PHY_POL_INVERT),
+				   PHY_POL_NORMAL, val);
+}
+EXPORT_SYMBOL_GPL(phy_get_manual_rx_polarity);
+
+/**
+ * phy_get_manual_tx_polarity - Get manual TX polarity for PHY differential lane
+ * @fwnode: Pointer to the PHY's firmware node.
+ * @mode_name: The name of the PHY mode to look up.
+ * @val: Pointer to returned polarity.
+ *
+ * Helper for PHYs without any custom default value for the TX polarity.
+ *
+ * Return: zero on success, negative error on failure.
+ */
+int __must_check phy_get_manual_tx_polarity(struct fwnode_handle *fwnode,
+					    const char *mode_name,
+					    unsigned int *val)
+{
+	return phy_get_tx_polarity(fwnode, mode_name,
+				   BIT(PHY_POL_NORMAL) | BIT(PHY_POL_INVERT),
+				   PHY_POL_NORMAL, val);
+}
+EXPORT_SYMBOL_GPL(phy_get_manual_tx_polarity);
diff --git a/include/linux/phy/phy-common-props.h b/include/linux/phy/phy-common-props.h
new file mode 100644
index 000000000000..680e13de4558
--- /dev/null
+++ b/include/linux/phy/phy-common-props.h
@@ -0,0 +1,32 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * phy-common-props.h -- Common properties for generic PHYs
+ *
+ * Copyright 2025 NXP
+ */
+
+#ifndef __PHY_COMMON_PROPS_H
+#define __PHY_COMMON_PROPS_H
+
+#include <dt-bindings/phy/phy.h>
+
+struct fwnode_handle;
+
+int __must_check phy_get_rx_polarity(struct fwnode_handle *fwnode,
+				     const char *mode_name,
+				     unsigned int supported,
+				     unsigned int default_val,
+				     unsigned int *val);
+int __must_check phy_get_tx_polarity(struct fwnode_handle *fwnode,
+				     const char *mode_name,
+				     unsigned int supported,
+				     unsigned int default_val,
+				     unsigned int *val);
+int __must_check phy_get_manual_rx_polarity(struct fwnode_handle *fwnode,
+					    const char *mode_name,
+					    unsigned int *val);
+int __must_check phy_get_manual_tx_polarity(struct fwnode_handle *fwnode,
+					    const char *mode_name,
+					    unsigned int *val);
+
+#endif /* __PHY_COMMON_PROPS_H */
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 net-next 06/10] dt-bindings: net: airoha,en8811h: deprecate "airoha,pnswap-rx" and "airoha,pnswap-tx"
  2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
                   ` (4 preceding siblings ...)
  2026-01-11  9:39 ` [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity() Vladimir Oltean
@ 2026-01-11  9:39 ` Vladimir Oltean
  2026-01-11  9:39 ` [PATCH v3 net-next 07/10] net: phy: air_en8811h: " Vladimir Oltean
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-11  9:39 UTC (permalink / raw)
  To: netdev, devicetree, linux-phy
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Bjørn Mork, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

Reference the common PHY properties, and update the example to use them.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
---
v1->v3: none

 .../devicetree/bindings/net/airoha,en8811h.yaml       | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/net/airoha,en8811h.yaml b/Documentation/devicetree/bindings/net/airoha,en8811h.yaml
index ecb5149ec6b0..0de6e9284fbc 100644
--- a/Documentation/devicetree/bindings/net/airoha,en8811h.yaml
+++ b/Documentation/devicetree/bindings/net/airoha,en8811h.yaml
@@ -16,6 +16,7 @@ description:
 
 allOf:
   - $ref: ethernet-phy.yaml#
+  - $ref: /schemas/phy/phy-common-props.yaml#
 
 properties:
   compatible:
@@ -30,12 +31,18 @@ properties:
     description:
       Reverse rx polarity of the SERDES. This is the receiving
       side of the lines from the MAC towards the EN881H.
+      This property is deprecated, for details please refer to
+      Documentation/devicetree/bindings/phy/phy-common-props.yaml
+    deprecated: true
 
   airoha,pnswap-tx:
     type: boolean
     description:
       Reverse tx polarity of SERDES. This is the transmitting
       side of the lines from EN8811H towards the MAC.
+      This property is deprecated, for details please refer to
+      Documentation/devicetree/bindings/phy/phy-common-props.yaml
+    deprecated: true
 
 required:
   - reg
@@ -44,6 +51,8 @@ unevaluatedProperties: false
 
 examples:
   - |
+    #include <dt-bindings/phy/phy.h>
+
     mdio {
         #address-cells = <1>;
         #size-cells = <0>;
@@ -51,6 +60,6 @@ examples:
         ethernet-phy@1 {
             compatible = "ethernet-phy-id03a2.a411";
             reg = <1>;
-            airoha,pnswap-rx;
+            rx-polarity = <PHY_POL_INVERT>;
         };
     };
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 net-next 07/10] net: phy: air_en8811h: deprecate "airoha,pnswap-rx" and "airoha,pnswap-tx"
  2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
                   ` (5 preceding siblings ...)
  2026-01-11  9:39 ` [PATCH v3 net-next 06/10] dt-bindings: net: airoha,en8811h: deprecate "airoha,pnswap-rx" and "airoha,pnswap-tx" Vladimir Oltean
@ 2026-01-11  9:39 ` Vladimir Oltean
  2026-01-11  9:39 ` [PATCH v3 net-next 08/10] dt-bindings: net: pcs: mediatek,sgmiisys: deprecate "mediatek,pnswap" Vladimir Oltean
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-11  9:39 UTC (permalink / raw)
  To: netdev, devicetree, linux-phy
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Bjørn Mork, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

Prefer the new "rx-polarity" and "tx-polarity" properties, and use the
vendor specific ones as fallback if the standard description doesn't
exist.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v2->v3: none
v1->v2:
- adapt to API change: error code and returned value have been split
- bug fix: supported mask of polarities should be BIT(PHY_POL_NORMAL) |
  BIT(PHY_POL_INVERT) rather than PHY_POL_NORMAL | PHY_POL_INVERT.

 drivers/net/phy/Kconfig       |  1 +
 drivers/net/phy/air_en8811h.c | 53 +++++++++++++++++++++++++----------
 2 files changed, 39 insertions(+), 15 deletions(-)

diff --git a/drivers/net/phy/Kconfig b/drivers/net/phy/Kconfig
index a7ade7b95a2e..7b73332a13d9 100644
--- a/drivers/net/phy/Kconfig
+++ b/drivers/net/phy/Kconfig
@@ -98,6 +98,7 @@ config AS21XXX_PHY
 
 config AIR_EN8811H_PHY
 	tristate "Airoha EN8811H 2.5 Gigabit PHY"
+	select PHY_COMMON_PROPS
 	help
 	  Currently supports the Airoha EN8811H PHY.
 
diff --git a/drivers/net/phy/air_en8811h.c b/drivers/net/phy/air_en8811h.c
index badd65f0ccee..e890bb2c0aa8 100644
--- a/drivers/net/phy/air_en8811h.c
+++ b/drivers/net/phy/air_en8811h.c
@@ -14,6 +14,7 @@
 #include <linux/clk.h>
 #include <linux/clk-provider.h>
 #include <linux/phy.h>
+#include <linux/phy/phy-common-props.h>
 #include <linux/firmware.h>
 #include <linux/property.h>
 #include <linux/wordpart.h>
@@ -966,11 +967,45 @@ static int en8811h_probe(struct phy_device *phydev)
 	return 0;
 }
 
+static int en8811h_config_serdes_polarity(struct phy_device *phydev)
+{
+	struct device *dev = &phydev->mdio.dev;
+	unsigned int pol, default_pol;
+	u32 pbus_value = 0;
+	int ret;
+
+	default_pol = PHY_POL_NORMAL;
+	if (device_property_read_bool(dev, "airoha,pnswap-rx"))
+		default_pol = PHY_POL_INVERT;
+
+	ret = phy_get_rx_polarity(dev_fwnode(dev), phy_modes(phydev->interface),
+				  BIT(PHY_POL_NORMAL) | BIT(PHY_POL_INVERT),
+				  default_pol, &pol);
+	if (ret)
+		return ret;
+	if (pol == PHY_POL_INVERT)
+		pbus_value |= EN8811H_POLARITY_RX_REVERSE;
+
+	default_pol = PHY_POL_NORMAL;
+	if (device_property_read_bool(dev, "airoha,pnswap-tx"))
+		default_pol = PHY_POL_INVERT;
+
+	ret = phy_get_tx_polarity(dev_fwnode(dev), phy_modes(phydev->interface),
+				  BIT(PHY_POL_NORMAL) | BIT(PHY_POL_INVERT),
+				  default_pol, &pol);
+	if (ret)
+		return ret;
+	if (pol == PHY_POL_NORMAL)
+		pbus_value |= EN8811H_POLARITY_TX_NORMAL;
+
+	return air_buckpbus_reg_modify(phydev, EN8811H_POLARITY,
+				       EN8811H_POLARITY_RX_REVERSE |
+				       EN8811H_POLARITY_TX_NORMAL, pbus_value);
+}
+
 static int en8811h_config_init(struct phy_device *phydev)
 {
 	struct en8811h_priv *priv = phydev->priv;
-	struct device *dev = &phydev->mdio.dev;
-	u32 pbus_value;
 	int ret;
 
 	/* If restart happened in .probe(), no need to restart now */
@@ -1003,19 +1038,7 @@ static int en8811h_config_init(struct phy_device *phydev)
 	if (ret < 0)
 		return ret;
 
-	/* Serdes polarity */
-	pbus_value = 0;
-	if (device_property_read_bool(dev, "airoha,pnswap-rx"))
-		pbus_value |=  EN8811H_POLARITY_RX_REVERSE;
-	else
-		pbus_value &= ~EN8811H_POLARITY_RX_REVERSE;
-	if (device_property_read_bool(dev, "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);
+	ret = en8811h_config_serdes_polarity(phydev);
 	if (ret < 0)
 		return ret;
 
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 net-next 08/10] dt-bindings: net: pcs: mediatek,sgmiisys: deprecate "mediatek,pnswap"
  2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
                   ` (6 preceding siblings ...)
  2026-01-11  9:39 ` [PATCH v3 net-next 07/10] net: phy: air_en8811h: " Vladimir Oltean
@ 2026-01-11  9:39 ` Vladimir Oltean
  2026-01-11  9:39 ` [PATCH v3 net-next 09/10] net: pcs: pcs-mtk-lynxi: pass SGMIISYS OF node to PCS Vladimir Oltean
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-11  9:39 UTC (permalink / raw)
  To: netdev, devicetree, linux-phy
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Bjørn Mork, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

Reference the common PHY properties, and update the example to use them.
Note that a PCS subnode exists, and it seems a better container of the
polarity description than the SGMIISYS node that hosts "mediatek,pnswap".
So use that.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
Reviewed-by: Rob Herring (Arm) <robh@kernel.org>
---
v1->v3: none

 .../devicetree/bindings/net/pcs/mediatek,sgmiisys.yaml     | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/Documentation/devicetree/bindings/net/pcs/mediatek,sgmiisys.yaml b/Documentation/devicetree/bindings/net/pcs/mediatek,sgmiisys.yaml
index 1bacc0eeff75..b8478416f8ef 100644
--- a/Documentation/devicetree/bindings/net/pcs/mediatek,sgmiisys.yaml
+++ b/Documentation/devicetree/bindings/net/pcs/mediatek,sgmiisys.yaml
@@ -39,12 +39,17 @@ properties:
     const: 1
 
   mediatek,pnswap:
-    description: Invert polarity of the SGMII data lanes
+    description:
+      Invert polarity of the SGMII data lanes.
+      This property is deprecated, for details please refer to
+      Documentation/devicetree/bindings/phy/phy-common-props.yaml.
     type: boolean
+    deprecated: true
 
   pcs:
     type: object
     description: MediaTek LynxI HSGMII PCS
+    $ref: /schemas/phy/phy-common-props.yaml#
     properties:
       compatible:
         const: mediatek,mt7988-sgmii
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 net-next 09/10] net: pcs: pcs-mtk-lynxi: pass SGMIISYS OF node to PCS
  2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
                   ` (7 preceding siblings ...)
  2026-01-11  9:39 ` [PATCH v3 net-next 08/10] dt-bindings: net: pcs: mediatek,sgmiisys: deprecate "mediatek,pnswap" Vladimir Oltean
@ 2026-01-11  9:39 ` Vladimir Oltean
  2026-01-11  9:39 ` [PATCH v3 net-next 10/10] net: pcs: pcs-mtk-lynxi: deprecate "mediatek,pnswap" Vladimir Oltean
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-11  9:39 UTC (permalink / raw)
  To: netdev, devicetree, linux-phy
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Bjørn Mork, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

The Mediatek LynxI PCS is used from the MT7530 DSA driver (where it does
not have an OF presence) and from mtk_eth_soc, where it does
(Documentation/devicetree/bindings/net/pcs/mediatek,sgmiisys.yaml
informs of a combined clock provider + SGMII PCS "SGMIISYS" syscon
block).

Currently, mtk_eth_soc parses the SGMIISYS OF node for the
"mediatek,pnswap" property and sets a bit in the "flags" argument of
mtk_pcs_lynxi_create() if set.

I'd like to deprecate "mediatek,pnswap" in favour of a property which
takes the current phy-mode into consideration. But this is only known at
mtk_pcs_lynxi_config() time, and not known at mtk_pcs_lynxi_create(),
when the SGMIISYS OF node is parsed.

To achieve that, we must pass the OF node of the PCS, if it exists, to
mtk_pcs_lynxi_create(), and let the PCS take a reference on it and
handle property parsing whenever it wants.

Use the fwnode API which is more general than OF (in case we ever need
to describe the PCS using some other format). This API should be NULL
tolerant, so add no particular tests for the mt7530 case.

Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v2->v3: none
v1->v2: patch is new

 drivers/net/dsa/mt7530-mdio.c               |  4 ++--
 drivers/net/ethernet/mediatek/mtk_eth_soc.c | 19 ++++++++-----------
 drivers/net/pcs/pcs-mtk-lynxi.c             | 15 ++++++++++-----
 include/linux/pcs/pcs-mtk-lynxi.h           |  5 ++---
 4 files changed, 22 insertions(+), 21 deletions(-)

diff --git a/drivers/net/dsa/mt7530-mdio.c b/drivers/net/dsa/mt7530-mdio.c
index 0286a6cecb6f..11ea924a9f35 100644
--- a/drivers/net/dsa/mt7530-mdio.c
+++ b/drivers/net/dsa/mt7530-mdio.c
@@ -113,8 +113,8 @@ mt7531_create_sgmii(struct mt7530_priv *priv)
 			ret = PTR_ERR(regmap);
 			break;
 		}
-		pcs = mtk_pcs_lynxi_create(priv->dev, regmap,
-					   MT7531_PHYA_CTRL_SIGNAL3, 0);
+		pcs = mtk_pcs_lynxi_create(priv->dev, NULL, regmap,
+					   MT7531_PHYA_CTRL_SIGNAL3);
 		if (!pcs) {
 			ret = -ENXIO;
 			break;
diff --git a/drivers/net/ethernet/mediatek/mtk_eth_soc.c b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
index e68997a29191..8534579b8470 100644
--- a/drivers/net/ethernet/mediatek/mtk_eth_soc.c
+++ b/drivers/net/ethernet/mediatek/mtk_eth_soc.c
@@ -4991,7 +4991,6 @@ static int mtk_sgmii_init(struct mtk_eth *eth)
 {
 	struct device_node *np;
 	struct regmap *regmap;
-	u32 flags;
 	int i;
 
 	for (i = 0; i < MTK_MAX_DEVS; i++) {
@@ -5000,18 +4999,16 @@ static int mtk_sgmii_init(struct mtk_eth *eth)
 			break;
 
 		regmap = syscon_node_to_regmap(np);
-		flags = 0;
-		if (of_property_read_bool(np, "mediatek,pnswap"))
-			flags |= MTK_SGMII_FLAG_PN_SWAP;
-
-		of_node_put(np);
-
-		if (IS_ERR(regmap))
+		if (IS_ERR(regmap)) {
+			of_node_put(np);
 			return PTR_ERR(regmap);
+		}
 
-		eth->sgmii_pcs[i] = mtk_pcs_lynxi_create(eth->dev, regmap,
-							 eth->soc->ana_rgc3,
-							 flags);
+		eth->sgmii_pcs[i] = mtk_pcs_lynxi_create(eth->dev,
+							 of_fwnode_handle(np),
+							 regmap,
+							 eth->soc->ana_rgc3);
+		of_node_put(np);
 	}
 
 	return 0;
diff --git a/drivers/net/pcs/pcs-mtk-lynxi.c b/drivers/net/pcs/pcs-mtk-lynxi.c
index 149ddf51d785..7f719da5812e 100644
--- a/drivers/net/pcs/pcs-mtk-lynxi.c
+++ b/drivers/net/pcs/pcs-mtk-lynxi.c
@@ -81,6 +81,7 @@ struct mtk_pcs_lynxi {
 	phy_interface_t		interface;
 	struct			phylink_pcs pcs;
 	u32			flags;
+	struct fwnode_handle	*fwnode;
 };
 
 static struct mtk_pcs_lynxi *pcs_to_mtk_pcs_lynxi(struct phylink_pcs *pcs)
@@ -168,7 +169,7 @@ static int mtk_pcs_lynxi_config(struct phylink_pcs *pcs, unsigned int neg_mode,
 		regmap_set_bits(mpcs->regmap, SGMSYS_RESERVED_0,
 				SGMII_SW_RESET);
 
-		if (mpcs->flags & MTK_SGMII_FLAG_PN_SWAP)
+		if (fwnode_property_read_bool(mpcs->fwnode, "mediatek,pnswap"))
 			regmap_update_bits(mpcs->regmap, SGMSYS_QPHY_WRAP_CTRL,
 					   SGMII_PN_SWAP_MASK,
 					   SGMII_PN_SWAP_TX_RX);
@@ -268,8 +269,8 @@ static const struct phylink_pcs_ops mtk_pcs_lynxi_ops = {
 };
 
 struct phylink_pcs *mtk_pcs_lynxi_create(struct device *dev,
-					 struct regmap *regmap, u32 ana_rgc3,
-					 u32 flags)
+					 struct fwnode_handle *fwnode,
+					 struct regmap *regmap, u32 ana_rgc3)
 {
 	struct mtk_pcs_lynxi *mpcs;
 	u32 id, ver;
@@ -303,10 +304,10 @@ struct phylink_pcs *mtk_pcs_lynxi_create(struct device *dev,
 
 	mpcs->ana_rgc3 = ana_rgc3;
 	mpcs->regmap = regmap;
-	mpcs->flags = flags;
 	mpcs->pcs.ops = &mtk_pcs_lynxi_ops;
 	mpcs->pcs.poll = true;
 	mpcs->interface = PHY_INTERFACE_MODE_NA;
+	mpcs->fwnode = fwnode_handle_get(fwnode);
 
 	__set_bit(PHY_INTERFACE_MODE_SGMII, mpcs->pcs.supported_interfaces);
 	__set_bit(PHY_INTERFACE_MODE_1000BASEX, mpcs->pcs.supported_interfaces);
@@ -318,10 +319,14 @@ EXPORT_SYMBOL(mtk_pcs_lynxi_create);
 
 void mtk_pcs_lynxi_destroy(struct phylink_pcs *pcs)
 {
+	struct mtk_pcs_lynxi *mpcs;
+
 	if (!pcs)
 		return;
 
-	kfree(pcs_to_mtk_pcs_lynxi(pcs));
+	mpcs = pcs_to_mtk_pcs_lynxi(pcs);
+	fwnode_handle_put(mpcs->fwnode);
+	kfree(mpcs);
 }
 EXPORT_SYMBOL(mtk_pcs_lynxi_destroy);
 
diff --git a/include/linux/pcs/pcs-mtk-lynxi.h b/include/linux/pcs/pcs-mtk-lynxi.h
index be3b4ab32f4a..1bd4a27a8898 100644
--- a/include/linux/pcs/pcs-mtk-lynxi.h
+++ b/include/linux/pcs/pcs-mtk-lynxi.h
@@ -5,9 +5,8 @@
 #include <linux/phylink.h>
 #include <linux/regmap.h>
 
-#define MTK_SGMII_FLAG_PN_SWAP BIT(0)
 struct phylink_pcs *mtk_pcs_lynxi_create(struct device *dev,
-					 struct regmap *regmap,
-					 u32 ana_rgc3, u32 flags);
+					 struct fwnode_handle *fwnode,
+					 struct regmap *regmap, u32 ana_rgc3);
 void mtk_pcs_lynxi_destroy(struct phylink_pcs *pcs);
 #endif
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* [PATCH v3 net-next 10/10] net: pcs: pcs-mtk-lynxi: deprecate "mediatek,pnswap"
  2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
                   ` (8 preceding siblings ...)
  2026-01-11  9:39 ` [PATCH v3 net-next 09/10] net: pcs: pcs-mtk-lynxi: pass SGMIISYS OF node to PCS Vladimir Oltean
@ 2026-01-11  9:39 ` Vladimir Oltean
  2026-01-14 13:18 ` [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vinod Koul
  2026-01-14 14:01 ` (subset) " Vinod Koul
  11 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-11  9:39 UTC (permalink / raw)
  To: netdev, devicetree, linux-phy
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Bjørn Mork, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

Prefer the new "rx-polarity" and "tx-polarity" properties, which in this
case have the advantage that polarity inversion can be specified per
direction (and per protocol, although this isn't useful here).

We use the vendor specific ones as fallback if the standard description
doesn't exist.

Daniel, referring to the Mediatek SDK, clarifies that the combined
SGMII_PN_SWAP_TX_RX register field should be split like this: bit 0 is
TX and bit 1 is RX:
https://lore.kernel.org/linux-phy/aSW--slbJWpXK0nv@makrotopia.org/

Suggested-by: Daniel Golle <daniel@makrotopia.org>
Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>
---
v2->v3: s/GENERIC_PHY_COMMON_PROPS/PHY_COMMON_PROPS/
v1->v2: patch is new

 drivers/net/pcs/Kconfig         |  1 +
 drivers/net/pcs/pcs-mtk-lynxi.c | 50 +++++++++++++++++++++++++++++----
 2 files changed, 45 insertions(+), 6 deletions(-)

diff --git a/drivers/net/pcs/Kconfig b/drivers/net/pcs/Kconfig
index ecbc3530e780..e417fd66f660 100644
--- a/drivers/net/pcs/Kconfig
+++ b/drivers/net/pcs/Kconfig
@@ -20,6 +20,7 @@ config PCS_LYNX
 
 config PCS_MTK_LYNXI
 	tristate
+	select PHY_COMMON_PROPS
 	select REGMAP
 	help
 	  This module provides helpers to phylink for managing the LynxI PCS
diff --git a/drivers/net/pcs/pcs-mtk-lynxi.c b/drivers/net/pcs/pcs-mtk-lynxi.c
index 7f719da5812e..74dbce205f71 100644
--- a/drivers/net/pcs/pcs-mtk-lynxi.c
+++ b/drivers/net/pcs/pcs-mtk-lynxi.c
@@ -11,6 +11,7 @@
 #include <linux/mdio.h>
 #include <linux/of.h>
 #include <linux/pcs/pcs-mtk-lynxi.h>
+#include <linux/phy/phy-common-props.h>
 #include <linux/phylink.h>
 #include <linux/regmap.h>
 
@@ -62,8 +63,9 @@
 
 /* Register to QPHY wrapper control */
 #define SGMSYS_QPHY_WRAP_CTRL		0xec
-#define SGMII_PN_SWAP_MASK		GENMASK(1, 0)
-#define SGMII_PN_SWAP_TX_RX		(BIT(0) | BIT(1))
+#define SGMII_PN_SWAP_RX		BIT(1)
+#define SGMII_PN_SWAP_TX		BIT(0)
+
 
 /* struct mtk_pcs_lynxi -  This structure holds each sgmii regmap andassociated
  *                         data
@@ -121,6 +123,42 @@ static void mtk_pcs_lynxi_get_state(struct phylink_pcs *pcs,
 					 FIELD_GET(SGMII_LPA, adv));
 }
 
+static int mtk_pcs_config_polarity(struct mtk_pcs_lynxi *mpcs,
+				   phy_interface_t interface)
+{
+	struct fwnode_handle *fwnode = mpcs->fwnode, *pcs_fwnode;
+	unsigned int pol, default_pol = PHY_POL_NORMAL;
+	unsigned int val = 0;
+	int ret;
+
+	if (fwnode_property_read_bool(fwnode, "mediatek,pnswap"))
+		default_pol = PHY_POL_INVERT;
+
+	pcs_fwnode = fwnode_get_named_child_node(fwnode, "pcs");
+
+	ret = phy_get_rx_polarity(pcs_fwnode, phy_modes(interface),
+				  BIT(PHY_POL_NORMAL) | BIT(PHY_POL_INVERT),
+				  default_pol, &pol);
+	if (ret) {
+		fwnode_handle_put(pcs_fwnode);
+		return ret;
+	}
+	if (pol == PHY_POL_INVERT)
+		val |= SGMII_PN_SWAP_RX;
+
+	ret = phy_get_tx_polarity(pcs_fwnode, phy_modes(interface),
+				  BIT(PHY_POL_NORMAL) | BIT(PHY_POL_INVERT),
+				  default_pol, &pol);
+	fwnode_handle_put(pcs_fwnode);
+	if (ret)
+		return ret;
+	if (pol == PHY_POL_INVERT)
+		val |= SGMII_PN_SWAP_TX;
+
+	return regmap_update_bits(mpcs->regmap, SGMSYS_QPHY_WRAP_CTRL,
+				  SGMII_PN_SWAP_RX | SGMII_PN_SWAP_TX, val);
+}
+
 static int mtk_pcs_lynxi_config(struct phylink_pcs *pcs, unsigned int neg_mode,
 				phy_interface_t interface,
 				const unsigned long *advertising,
@@ -130,6 +168,7 @@ static int mtk_pcs_lynxi_config(struct phylink_pcs *pcs, unsigned int neg_mode,
 	bool mode_changed = false, changed;
 	unsigned int rgc3, sgm_mode, bmcr;
 	int advertise, link_timer;
+	int ret;
 
 	advertise = phylink_mii_c22_pcs_encode_advertisement(interface,
 							     advertising);
@@ -169,10 +208,9 @@ static int mtk_pcs_lynxi_config(struct phylink_pcs *pcs, unsigned int neg_mode,
 		regmap_set_bits(mpcs->regmap, SGMSYS_RESERVED_0,
 				SGMII_SW_RESET);
 
-		if (fwnode_property_read_bool(mpcs->fwnode, "mediatek,pnswap"))
-			regmap_update_bits(mpcs->regmap, SGMSYS_QPHY_WRAP_CTRL,
-					   SGMII_PN_SWAP_MASK,
-					   SGMII_PN_SWAP_TX_RX);
+		ret = mtk_pcs_config_polarity(mpcs, interface);
+		if (ret)
+			return ret;
 
 		if (interface == PHY_INTERFACE_MODE_2500BASEX)
 			rgc3 = SGMII_PHY_SPEED_3_125G;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  2026-01-11  9:39 ` [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity() Vladimir Oltean
@ 2026-01-11 11:53   ` Bjørn Mork
  2026-01-11 14:15     ` Vladimir Oltean
  2026-02-26 13:22   ` Geert Uytterhoeven
  1 sibling, 1 reply; 25+ messages in thread
From: Bjørn Mork @ 2026-01-11 11:53 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, devicetree, linux-phy, linux-kernel, linux-arm-kernel,
	linux-mediatek, Daniel Golle, Horatiu Vultur, Andrew Lunn,
	Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

Vladimir Oltean <vladimir.oltean@nxp.com> writes:

> Add helpers in the generic PHY folder which can be used using 'select
> GENERIC_PHY_COMMON_PROPS' from Kconfig

The code looks good to me now.

But renaming stuff is hard. Leftover old config symbol in the commit
description here. Could be fixed up on merge, maybe?


Bjørn

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  2026-01-11 11:53   ` Bjørn Mork
@ 2026-01-11 14:15     ` Vladimir Oltean
  2026-01-14 13:10       ` Vinod Koul
  0 siblings, 1 reply; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-11 14:15 UTC (permalink / raw)
  To: Bjørn Mork
  Cc: netdev, devicetree, linux-phy, linux-kernel, linux-arm-kernel,
	linux-mediatek, Daniel Golle, Horatiu Vultur, Andrew Lunn,
	Heiner Kallweit, Russell King, David S. Miller, Eric Dumazet,
	Jakub Kicinski, Paolo Abeni, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Vinod Koul, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

On Sun, Jan 11, 2026 at 12:53:15PM +0100, Bjørn Mork wrote:
> Vladimir Oltean <vladimir.oltean@nxp.com> writes:
> 
> > Add helpers in the generic PHY folder which can be used using 'select
> > GENERIC_PHY_COMMON_PROPS' from Kconfig
> 
> The code looks good to me now.
> 
> But renaming stuff is hard. Leftover old config symbol in the commit
> description here. Could be fixed up on merge, maybe?
> 
> 
> Bjørn

This is unfortunate. I'll let Vinot comment on the preferred approach,
although I also wouldn't prefer resending to fix a minor commit message
mistake. Thanks for spotting and for the review in general.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  2026-01-11 14:15     ` Vladimir Oltean
@ 2026-01-14 13:10       ` Vinod Koul
  2026-01-15  9:34         ` Paolo Abeni
  0 siblings, 1 reply; 25+ messages in thread
From: Vinod Koul @ 2026-01-14 13:10 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Bjørn Mork, netdev, devicetree, linux-phy, linux-kernel,
	linux-arm-kernel, linux-mediatek, Daniel Golle, Horatiu Vultur,
	Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Neil Armstrong,
	Matthias Brugger, AngeloGioacchino Del Regno, Eric Woudstra,
	Marek Behún, Lee Jones, Patrice Chotard

On 11-01-26, 16:15, Vladimir Oltean wrote:
> On Sun, Jan 11, 2026 at 12:53:15PM +0100, Bjørn Mork wrote:
> > Vladimir Oltean <vladimir.oltean@nxp.com> writes:
> > 
> > > Add helpers in the generic PHY folder which can be used using 'select
> > > GENERIC_PHY_COMMON_PROPS' from Kconfig
> > 
> > The code looks good to me now.
> > 
> > But renaming stuff is hard. Leftover old config symbol in the commit
> > description here. Could be fixed up on merge, maybe?
> > 
> > 
> > Bjørn
> 
> This is unfortunate. I'll let Vinot comment on the preferred approach,
> although I also wouldn't prefer resending to fix a minor commit message
> mistake. Thanks for spotting and for the review in general.

Yes fixed that while applying

-- 
~Vinod

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties
  2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
                   ` (9 preceding siblings ...)
  2026-01-11  9:39 ` [PATCH v3 net-next 10/10] net: pcs: pcs-mtk-lynxi: deprecate "mediatek,pnswap" Vladimir Oltean
@ 2026-01-14 13:18 ` Vinod Koul
  2026-01-16  3:16   ` Jakub Kicinski
  2026-01-14 14:01 ` (subset) " Vinod Koul
  11 siblings, 1 reply; 25+ messages in thread
From: Vinod Koul @ 2026-01-14 13:18 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, devicetree, linux-phy, linux-kernel, linux-arm-kernel,
	linux-mediatek, Daniel Golle, Horatiu Vultur, Bjørn Mork,
	Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Neil Armstrong,
	Matthias Brugger, AngeloGioacchino Del Regno, Eric Woudstra,
	Marek Behún, Lee Jones, Patrice Chotard

On 11-01-26, 11:39, Vladimir Oltean wrote:
> Introduce "rx-polarity" and "tx-polarity" device tree properties.
> Convert two existing networking use cases - the EN8811H Ethernet PHY and
> the Mediatek LynxI PCS.
> 
> Requested merge strategy:
> Patches 1-5 through linux-phy


The following changes since commit 8f0b4cce4481fb22653697cced8d0d04027cb1e8:

  Linux 6.19-rc1 (2025-12-14 16:05:07 +1200)

are available in the Git repository at:

  git://git.kernel.org/pub/scm/linux/kernel/git/phy/linux-phy.git tags/phy_common_properties

for you to fetch changes up to e7556b59ba65179612bce3fa56bb53d1b4fb20db:

  phy: add phy_get_rx_polarity() and phy_get_tx_polarity() (2026-01-14 18:16:05 +0530)

----------------------------------------------------------------
phy common properties

Vladimir Oltean <vladimir.oltean@nxp.com> wrote:

Introduce "rx-polarity" and "tx-polarity" device tree properties with
Kunit tests

----------------------------------------------------------------
Vladimir Oltean (5):
      dt-bindings: phy: rename transmit-amplitude.yaml to phy-common-props.yaml
      dt-bindings: phy-common-props: create a reusable "protocol-names" definition
      dt-bindings: phy-common-props: ensure protocol-names are unique
      dt-bindings: phy-common-props: RX and TX lane polarity inversion
      phy: add phy_get_rx_polarity() and phy_get_tx_polarity()

 .../devicetree/bindings/phy/phy-common-props.yaml  | 157 ++++++++
 .../bindings/phy/transmit-amplitude.yaml           | 103 -----
 MAINTAINERS                                        |  10 +
 drivers/phy/Kconfig                                |  22 ++
 drivers/phy/Makefile                               |   2 +
 drivers/phy/phy-common-props-test.c                | 422 +++++++++++++++++++++
 drivers/phy/phy-common-props.c                     | 209 ++++++++++
 include/dt-bindings/phy/phy.h                      |   4 +
 include/linux/phy/phy-common-props.h               |  32 ++
 9 files changed, 858 insertions(+), 103 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/phy/phy-common-props.yaml
 delete mode 100644 Documentation/devicetree/bindings/phy/transmit-amplitude.yaml
 create mode 100644 drivers/phy/phy-common-props-test.c
 create mode 100644 drivers/phy/phy-common-props.c
 create mode 100644 include/linux/phy/phy-common-props.h

> linux-phy provides stable branch or tag to netdev
> patches 6-10 through netdev
> 
> v2 at:
> https://lore.kernel.org/netdev/20260103210403.438687-1-vladimir.oltean@nxp.com/
> Changes since v2:
> - fix bug with existing fwnode which is missing polarity properties.
>   This is supposed to return the default value, not an error. (thanks to
>   Bjørn Mork).
> - fix inconsistency between PHY_COMMON_PROPS and GENERIC_PHY_COMMON_PROPS
>   Kconfig options by using PHY_COMMON_PROPS everywhere (thanks to Bjørn
>   Mork).
> 
> v1 at:
> https://lore.kernel.org/netdev/20251122193341.332324-1-vladimir.oltean@nxp.com/
> Changes since v1:
> - API changes: split error code from returned value; introduce two new
>   helpers for simple driver cases
> - Add KUnit tests
> - Bug fixes in core code and in drivers
> - Defer XPCS patches for later (*)
> - Convert Mediatek LynxI PCS
> - Logical change: rx-polarity and tx-polarity refer to the currently
>   described block, and not necessarily to device pins
> - Apply Rob's feedback
> - Drop the "joint maintainership" idea.
> 
> (*) To simplify the generic XPCS driver, I've decided to make
> "tx-polarity" default to <PHY_POL_NORMAL>, rather than <PHY_POL_NORMAL>
> OR <PHY_POL_INVERT> for SJA1105. But in order to avoid breakage, it
> creates a hard dependency on this patch set being merged *first*:
> https://lore.kernel.org/netdev/20251118190530.580267-1-vladimir.oltean@nxp.com/
> so that the SJA1105 driver can provide an XPCS fwnode with the right
> polarity specified. All patches in context can be seen at:
> https://github.com/vladimiroltean/linux/tree/phy-polarity-inversion
> 
> Original cover letter:
> 
> Polarity inversion (described in patch 4/10) is a feature with at least
> 4 potential new users waiting for a generic description:
> - Horatiu Vultur with the lan966x SerDes
> - Daniel Golle with the MaxLinear GSW1xx switches
> - Bjørn Mork with the AN8811HB Ethernet PHY
> - Me with a custom SJA1105 board, switch which uses the DesignWare XPCS
> 
> I became interested in exploring the problem space because I was averse
> to the idea of adding vendor-specific device tree properties to describe
> a common need.
> 
> This set contains an implementation of a generic feature that should
> cater to all known needs that were identified during my documentation
> phase.
> 
> Apart from what is converted here, we also have the following, which I
> did not touch:
> - "st,px_rx_pol_inv" - its binding is a .txt file and I don't have time
>   for such a large detour to convert it to dtschema.
> - "st,pcie-tx-pol-inv" and "st,sata-tx-pol-inv" - these are defined in a
>   .txt schema but are not implemented in any driver. My verdict would be
>   "delete the properties" but again, I would prefer not introducing such
>   dependency to this series.
> 
> Vladimir Oltean (10):
>   dt-bindings: phy: rename transmit-amplitude.yaml to
>     phy-common-props.yaml
>   dt-bindings: phy-common-props: create a reusable "protocol-names"
>     definition
>   dt-bindings: phy-common-props: ensure protocol-names are unique
>   dt-bindings: phy-common-props: RX and TX lane polarity inversion
>   phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
>   dt-bindings: net: airoha,en8811h: deprecate "airoha,pnswap-rx" and
>     "airoha,pnswap-tx"
>   net: phy: air_en8811h: deprecate "airoha,pnswap-rx" and
>     "airoha,pnswap-tx"
>   dt-bindings: net: pcs: mediatek,sgmiisys: deprecate "mediatek,pnswap"
>   net: pcs: pcs-mtk-lynxi: pass SGMIISYS OF node to PCS
>   net: pcs: pcs-mtk-lynxi: deprecate "mediatek,pnswap"
> 
>  .../bindings/net/airoha,en8811h.yaml          |  11 +-
>  .../bindings/net/pcs/mediatek,sgmiisys.yaml   |   7 +-
>  .../bindings/phy/phy-common-props.yaml        | 157 +++++++
>  .../bindings/phy/transmit-amplitude.yaml      | 103 -----
>  MAINTAINERS                                   |  10 +
>  drivers/net/dsa/mt7530-mdio.c                 |   4 +-
>  drivers/net/ethernet/mediatek/mtk_eth_soc.c   |  19 +-
>  drivers/net/pcs/Kconfig                       |   1 +
>  drivers/net/pcs/pcs-mtk-lynxi.c               |  63 ++-
>  drivers/net/phy/Kconfig                       |   1 +
>  drivers/net/phy/air_en8811h.c                 |  53 ++-
>  drivers/phy/Kconfig                           |  22 +
>  drivers/phy/Makefile                          |   2 +
>  drivers/phy/phy-common-props-test.c           | 422 ++++++++++++++++++
>  drivers/phy/phy-common-props.c                | 209 +++++++++
>  include/dt-bindings/phy/phy.h                 |   4 +
>  include/linux/pcs/pcs-mtk-lynxi.h             |   5 +-
>  include/linux/phy/phy-common-props.h          |  32 ++
>  18 files changed, 979 insertions(+), 146 deletions(-)
>  create mode 100644 Documentation/devicetree/bindings/phy/phy-common-props.yaml
>  delete mode 100644 Documentation/devicetree/bindings/phy/transmit-amplitude.yaml
>  create mode 100644 drivers/phy/phy-common-props-test.c
>  create mode 100644 drivers/phy/phy-common-props.c
>  create mode 100644 include/linux/phy/phy-common-props.h
> 
> -- 
> 2.43.0

-- 
~Vinod

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: (subset) [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties
  2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
                   ` (10 preceding siblings ...)
  2026-01-14 13:18 ` [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vinod Koul
@ 2026-01-14 14:01 ` Vinod Koul
  11 siblings, 0 replies; 25+ messages in thread
From: Vinod Koul @ 2026-01-14 14:01 UTC (permalink / raw)
  To: netdev, devicetree, linux-phy, Vladimir Oltean
  Cc: linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Bjørn Mork, Andrew Lunn, Heiner Kallweit,
	Russell King, David S. Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Rob Herring, Krzysztof Kozlowski, Conor Dooley,
	Neil Armstrong, Matthias Brugger, AngeloGioacchino Del Regno,
	Eric Woudstra, Marek Behún, Lee Jones, Patrice Chotard


On Sun, 11 Jan 2026 11:39:29 +0200, Vladimir Oltean wrote:
> Introduce "rx-polarity" and "tx-polarity" device tree properties.
> Convert two existing networking use cases - the EN8811H Ethernet PHY and
> the Mediatek LynxI PCS.
> 
> Requested merge strategy:
> Patches 1-5 through linux-phy
> linux-phy provides stable branch or tag to netdev
> patches 6-10 through netdev
> 
> [...]

Applied, thanks!

[01/10] dt-bindings: phy: rename transmit-amplitude.yaml to phy-common-props.yaml
        commit: b7b4dcd96e3dfbb955d152c9ce4b490498b0f4b4
[02/10] dt-bindings: phy-common-props: create a reusable "protocol-names" definition
        commit: 33c79865c7d3cc84705ed133c101794902e60269
[03/10] dt-bindings: phy-common-props: ensure protocol-names are unique
        commit: 01fc2215940c20bbb22fa196a331ec9d50e45452
[04/10] dt-bindings: phy-common-props: RX and TX lane polarity inversion
        commit: fceb17ac05e772ffc82f1f008e876bf7752f0576
[05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
        commit: e7556b59ba65179612bce3fa56bb53d1b4fb20db

Best regards,
-- 
~Vinod



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  2026-01-14 13:10       ` Vinod Koul
@ 2026-01-15  9:34         ` Paolo Abeni
  2026-01-15  9:37           ` Paolo Abeni
  0 siblings, 1 reply; 25+ messages in thread
From: Paolo Abeni @ 2026-01-15  9:34 UTC (permalink / raw)
  To: Vinod Koul, Vladimir Oltean
  Cc: Bjørn Mork, netdev, devicetree, linux-phy, linux-kernel,
	linux-arm-kernel, linux-mediatek, Daniel Golle, Horatiu Vultur,
	Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard

On 1/14/26 2:10 PM, Vinod Koul wrote:
> On 11-01-26, 16:15, Vladimir Oltean wrote:
>> On Sun, Jan 11, 2026 at 12:53:15PM +0100, Bjørn Mork wrote:
>>> Vladimir Oltean <vladimir.oltean@nxp.com> writes:
>>>
>>>> Add helpers in the generic PHY folder which can be used using 'select
>>>> GENERIC_PHY_COMMON_PROPS' from Kconfig
>>>
>>> The code looks good to me now.
>>>
>>> But renaming stuff is hard. Leftover old config symbol in the commit
>>> description here. Could be fixed up on merge, maybe?
>>>
>>>
>>> Bjørn
>>
>> This is unfortunate. I'll let Vinot comment on the preferred approach,
>> although I also wouldn't prefer resending to fix a minor commit message
>> mistake. Thanks for spotting and for the review in general.
> 
> Yes fixed that while applying

Could you please share a stable branch/tag, so that we can pull patches
1-5 into the net-next tree from there?

Thanks!

Paolo



^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  2026-01-15  9:34         ` Paolo Abeni
@ 2026-01-15  9:37           ` Paolo Abeni
  2026-01-15  9:39             ` Vladimir Oltean
  0 siblings, 1 reply; 25+ messages in thread
From: Paolo Abeni @ 2026-01-15  9:37 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Bjørn Mork, netdev, devicetree, linux-phy, linux-kernel,
	linux-arm-kernel, linux-mediatek, Daniel Golle, Horatiu Vultur,
	Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard, Vinod Koul

On 1/15/26 10:34 AM, Paolo Abeni wrote:
> On 1/14/26 2:10 PM, Vinod Koul wrote:
>> On 11-01-26, 16:15, Vladimir Oltean wrote:
>>> On Sun, Jan 11, 2026 at 12:53:15PM +0100, Bjørn Mork wrote:
>>>> Vladimir Oltean <vladimir.oltean@nxp.com> writes:
>>>>
>>>>> Add helpers in the generic PHY folder which can be used using 'select
>>>>> GENERIC_PHY_COMMON_PROPS' from Kconfig
>>>>
>>>> The code looks good to me now.
>>>>
>>>> But renaming stuff is hard. Leftover old config symbol in the commit
>>>> description here. Could be fixed up on merge, maybe?
>>>>
>>>>
>>>> Bjørn
>>>
>>> This is unfortunate. I'll let Vinot comment on the preferred approach,
>>> although I also wouldn't prefer resending to fix a minor commit message
>>> mistake. Thanks for spotting and for the review in general.
>>
>> Yes fixed that while applying
> 
> Could you please share a stable branch/tag, so that we can pull patches
> 1-5 into the net-next tree from there?

Vladimir, could you please re-post patches 1-5 after that Vinod shares
the above? So that we don't keep in PW the dangling (current) series.

Thanks,

Paolo


^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  2026-01-15  9:37           ` Paolo Abeni
@ 2026-01-15  9:39             ` Vladimir Oltean
  2026-01-16  3:19               ` Jakub Kicinski
  0 siblings, 1 reply; 25+ messages in thread
From: Vladimir Oltean @ 2026-01-15  9:39 UTC (permalink / raw)
  To: Paolo Abeni
  Cc: Bjørn Mork, netdev, devicetree, linux-phy, linux-kernel,
	linux-arm-kernel, linux-mediatek, Daniel Golle, Horatiu Vultur,
	Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard, Vinod Koul

Hi Paolo,

On Thu, Jan 15, 2026 at 10:37:33AM +0100, Paolo Abeni wrote:
> On 1/15/26 10:34 AM, Paolo Abeni wrote:
> > On 1/14/26 2:10 PM, Vinod Koul wrote:
> >> On 11-01-26, 16:15, Vladimir Oltean wrote:
> >>> On Sun, Jan 11, 2026 at 12:53:15PM +0100, Bjørn Mork wrote:
> >>>> Vladimir Oltean <vladimir.oltean@nxp.com> writes:
> >>>>
> >>>>> Add helpers in the generic PHY folder which can be used using 'select
> >>>>> GENERIC_PHY_COMMON_PROPS' from Kconfig
> >>>>
> >>>> The code looks good to me now.
> >>>>
> >>>> But renaming stuff is hard. Leftover old config symbol in the commit
> >>>> description here. Could be fixed up on merge, maybe?
> >>>>
> >>>>
> >>>> Bjørn
> >>>
> >>> This is unfortunate. I'll let Vinot comment on the preferred approach,
> >>> although I also wouldn't prefer resending to fix a minor commit message
> >>> mistake. Thanks for spotting and for the review in general.
> >>
> >> Yes fixed that while applying
> > 
> > Could you please share a stable branch/tag, so that we can pull patches
> > 1-5 into the net-next tree from there?
> 
> Vladimir, could you please re-post patches 1-5 after that Vinod shares
> the above? So that we don't keep in PW the dangling (current) series.
> 
> Thanks,
> 
> Paolo
>
Vinod did share the PR:
https://lore.kernel.org/netdev/aWeXvFcGNK5T6As9@vaman/

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties
  2026-01-14 13:18 ` [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vinod Koul
@ 2026-01-16  3:16   ` Jakub Kicinski
  0 siblings, 0 replies; 25+ messages in thread
From: Jakub Kicinski @ 2026-01-16  3:16 UTC (permalink / raw)
  To: Vinod Koul
  Cc: Vladimir Oltean, netdev, devicetree, linux-phy, linux-kernel,
	linux-arm-kernel, linux-mediatek, Daniel Golle, Horatiu Vultur,
	Bjørn Mork, Andrew Lunn, Heiner Kallweit, Russell King,
	David S. Miller, Eric Dumazet, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Neil Armstrong,
	Matthias Brugger, AngeloGioacchino Del Regno, Eric Woudstra,
	Marek Behún, Lee Jones, Patrice Chotard

On Wed, 14 Jan 2026 18:48:52 +0530 Vinod Koul wrote:
> Subject: Re: [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties

You can submit the PR in reply to the series, but please rewrite the
subject to a typical PR format. Patchwork does not register this reply
as a submission.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  2026-01-15  9:39             ` Vladimir Oltean
@ 2026-01-16  3:19               ` Jakub Kicinski
  0 siblings, 0 replies; 25+ messages in thread
From: Jakub Kicinski @ 2026-01-16  3:19 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: Paolo Abeni, Bjørn Mork, netdev, devicetree, linux-phy,
	linux-kernel, linux-arm-kernel, linux-mediatek, Daniel Golle,
	Horatiu Vultur, Andrew Lunn, Heiner Kallweit, Russell King,
	David S. Miller, Eric Dumazet, Rob Herring, Krzysztof Kozlowski,
	Conor Dooley, Neil Armstrong, Matthias Brugger,
	AngeloGioacchino Del Regno, Eric Woudstra, Marek Behún,
	Lee Jones, Patrice Chotard, Vinod Koul

On Thu, 15 Jan 2026 11:39:28 +0200 Vladimir Oltean wrote:
> > > Could you please share a stable branch/tag, so that we can pull patches
> > > 1-5 into the net-next tree from there?  
> > 
> > Vladimir, could you please re-post patches 1-5 after that Vinod shares
> > the above? So that we don't keep in PW the dangling (current) series.
> >  
> Vinod did share the PR:
> https://lore.kernel.org/netdev/aWeXvFcGNK5T6As9@vaman/

IIUC Paolo did not pull Vinod's PR, so pulled now, you can repost.

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  2026-01-11  9:39 ` [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity() Vladimir Oltean
  2026-01-11 11:53   ` Bjørn Mork
@ 2026-02-26 13:22   ` Geert Uytterhoeven
  2026-02-26 15:10     ` Vladimir Oltean
  1 sibling, 1 reply; 25+ messages in thread
From: Geert Uytterhoeven @ 2026-02-26 13:22 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, devicetree, linux-phy, linux-kernel, linux-arm-kernel,
	linux-mediatek, Daniel Golle, Horatiu Vultur, Bjørn Mork,
	Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Neil Armstrong,
	Matthias Brugger, AngeloGioacchino Del Regno, Eric Woudstra,
	Marek Behún, Lee Jones, Patrice Chotard,
	open list:KERNEL SELFTEST FRAMEWORK, KUnit Development

Hi Vladimir,

CC kunit

On Sun, 11 Jan 2026 at 10:44, Vladimir Oltean <vladimir.oltean@nxp.com> wrote:
> Add helpers in the generic PHY folder which can be used using 'select
> GENERIC_PHY_COMMON_PROPS' from Kconfig, without otherwise needing to
> enable GENERIC_PHY.
>
> These helpers need to deal with the slight messiness of the fact that
> the polarity properties are arrays per protocol, and with the fact that
> there is no default value mandated by the standard properties, all
> default values depend on driver and protocol (PHY_POL_NORMAL may be a
> good default for SGMII, whereas PHY_POL_AUTO may be a good default for
> PCIe).
>
> Push the supported mask of polarities to these helpers, to simplify
> drivers such that they don't need to validate what's in the device tree
> (or other firmware description).
>
> Add a KUnit test suite to make sure that the API produces the expected
> results. The fact that we use fwnode structures means we can validate
> with software nodes, and as opposed to the device_property API, we can
> bypass the need to have a device structure.
>
> Co-developed-by: Bjørn Mork <bjorn@mork.no>
> Signed-off-by: Bjørn Mork <bjorn@mork.no>
> Signed-off-by: Vladimir Oltean <vladimir.oltean@nxp.com>

Thanks for your patch, which is now commit e7556b59ba651796
("phy: add phy_get_rx_polarity() and phy_get_tx_polarity()") in
v7.0-rc1.

> --- a/drivers/phy/Kconfig
> +++ b/drivers/phy/Kconfig
> @@ -5,6 +5,28 @@
>
>  menu "PHY Subsystem"
>
> +config PHY_COMMON_PROPS
> +       bool
> +       help
> +         This parses properties common between generic PHYs and Ethernet PHYs.
> +
> +         Select this from consumer drivers to gain access to helpers for
> +         parsing properties from the
> +         Documentation/devicetree/bindings/phy/phy-common-props.yaml schema.
> +
> +config PHY_COMMON_PROPS_TEST
> +       tristate "KUnit tests for PHY common props" if !KUNIT_ALL_TESTS
> +       select PHY_COMMON_PROPS

This select means that enabling KUNIT_ALL_TESTS also enables extra
functionality, which may not be desirable in a production system.
As PHY_COMMON_PROPS is bool, this extra functionality is even part of
the base kernel if KUNIT_ALL_TESTS=m.  Unfortunately PHY_COMMON_PROPS is
invisible, so this cannot just be changed from "select" to "depends on".
But perhaps PHY_COMMON_PROPS can be made visible if KUNIT_ALL_TESTS,
so the select can be turned into a dependency?

> +       depends on KUNIT
> +       default KUNIT_ALL_TESTS
> +       help
> +         This builds KUnit tests for the PHY common property API.
> +
> +         For more information on KUnit and unit tests in general,
> +         please refer to the KUnit documentation in Documentation/dev-tools/kunit/.
> +
> +         When in doubt, say N.
> +
>  config GENERIC_PHY
>         bool "PHY Core"
>         help

Gr{oetje,eeting}s,

                        Geert


--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  2026-02-26 13:22   ` Geert Uytterhoeven
@ 2026-02-26 15:10     ` Vladimir Oltean
  2026-02-26 15:13       ` Geert Uytterhoeven
  0 siblings, 1 reply; 25+ messages in thread
From: Vladimir Oltean @ 2026-02-26 15:10 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: netdev, devicetree, linux-phy, linux-kernel, linux-arm-kernel,
	linux-mediatek, Daniel Golle, Horatiu Vultur, Bjørn Mork,
	Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Neil Armstrong,
	Matthias Brugger, AngeloGioacchino Del Regno, Eric Woudstra,
	Marek Behún, Lee Jones, Patrice Chotard,
	open list:KERNEL SELFTEST FRAMEWORK, KUnit Development

Hi Geert,

On Thu, Feb 26, 2026 at 02:22:29PM +0100, Geert Uytterhoeven wrote:
> > +config PHY_COMMON_PROPS
> > +       bool
> > +       help
> > +         This parses properties common between generic PHYs and Ethernet PHYs.
> > +
> > +         Select this from consumer drivers to gain access to helpers for
> > +         parsing properties from the
> > +         Documentation/devicetree/bindings/phy/phy-common-props.yaml schema.
> > +
> > +config PHY_COMMON_PROPS_TEST
> > +       tristate "KUnit tests for PHY common props" if !KUNIT_ALL_TESTS
> > +       select PHY_COMMON_PROPS
> 
> This select means that enabling KUNIT_ALL_TESTS also enables extra
> functionality, which may not be desirable in a production system.
> As PHY_COMMON_PROPS is bool, this extra functionality is even part of
> the base kernel if KUNIT_ALL_TESTS=m.  Unfortunately PHY_COMMON_PROPS is
> invisible, so this cannot just be changed from "select" to "depends on".
> But perhaps PHY_COMMON_PROPS can be made visible if KUNIT_ALL_TESTS,
> so the select can be turned into a dependency?

Is this what you're asking for?

-- >8 --
diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
index 02467dfd4fb0..1875d5b784f6 100644
--- a/drivers/phy/Kconfig
+++ b/drivers/phy/Kconfig
@@ -6,7 +6,7 @@
 menu "PHY Subsystem"
 
 config PHY_COMMON_PROPS
-	bool
+	bool "PHY common properties" if KUNIT_ALL_TESTS
 	help
 	  This parses properties common between generic PHYs and Ethernet PHYs.
 
@@ -16,8 +16,7 @@ config PHY_COMMON_PROPS
 
 config PHY_COMMON_PROPS_TEST
 	tristate "KUnit tests for PHY common props" if !KUNIT_ALL_TESTS
-	select PHY_COMMON_PROPS
-	depends on KUNIT
+	depends on KUNIT && PHY_COMMON_PROPS
 	default KUNIT_ALL_TESTS
 	help
 	  This builds KUnit tests for the PHY common property API.
-- >8 --

^ permalink raw reply related	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  2026-02-26 15:10     ` Vladimir Oltean
@ 2026-02-26 15:13       ` Geert Uytterhoeven
  2026-02-26 15:21         ` Vladimir Oltean
  0 siblings, 1 reply; 25+ messages in thread
From: Geert Uytterhoeven @ 2026-02-26 15:13 UTC (permalink / raw)
  To: Vladimir Oltean
  Cc: netdev, devicetree, linux-phy, linux-kernel, linux-arm-kernel,
	linux-mediatek, Daniel Golle, Horatiu Vultur, Bjørn Mork,
	Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Neil Armstrong,
	Matthias Brugger, AngeloGioacchino Del Regno, Eric Woudstra,
	Marek Behún, Lee Jones, Patrice Chotard,
	open list:KERNEL SELFTEST FRAMEWORK, KUnit Development

Hi Vladimir,

On Thu, 26 Feb 2026 at 16:10, Vladimir Oltean <vladimir.oltean@nxp.com> wrote:
> On Thu, Feb 26, 2026 at 02:22:29PM +0100, Geert Uytterhoeven wrote:
> > > +config PHY_COMMON_PROPS
> > > +       bool
> > > +       help
> > > +         This parses properties common between generic PHYs and Ethernet PHYs.
> > > +
> > > +         Select this from consumer drivers to gain access to helpers for
> > > +         parsing properties from the
> > > +         Documentation/devicetree/bindings/phy/phy-common-props.yaml schema.
> > > +
> > > +config PHY_COMMON_PROPS_TEST
> > > +       tristate "KUnit tests for PHY common props" if !KUNIT_ALL_TESTS
> > > +       select PHY_COMMON_PROPS
> >
> > This select means that enabling KUNIT_ALL_TESTS also enables extra
> > functionality, which may not be desirable in a production system.
> > As PHY_COMMON_PROPS is bool, this extra functionality is even part of
> > the base kernel if KUNIT_ALL_TESTS=m.  Unfortunately PHY_COMMON_PROPS is
> > invisible, so this cannot just be changed from "select" to "depends on".
> > But perhaps PHY_COMMON_PROPS can be made visible if KUNIT_ALL_TESTS,
> > so the select can be turned into a dependency?
>
> Is this what you're asking for?
>
> -- >8 --
> diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> index 02467dfd4fb0..1875d5b784f6 100644
> --- a/drivers/phy/Kconfig
> +++ b/drivers/phy/Kconfig
> @@ -6,7 +6,7 @@
>  menu "PHY Subsystem"
>
>  config PHY_COMMON_PROPS
> -       bool
> +       bool "PHY common properties" if KUNIT_ALL_TESTS
>         help
>           This parses properties common between generic PHYs and Ethernet PHYs.
>
> @@ -16,8 +16,7 @@ config PHY_COMMON_PROPS
>
>  config PHY_COMMON_PROPS_TEST
>         tristate "KUnit tests for PHY common props" if !KUNIT_ALL_TESTS
> -       select PHY_COMMON_PROPS
> -       depends on KUNIT
> +       depends on KUNIT && PHY_COMMON_PROPS
>         default KUNIT_ALL_TESTS
>         help
>           This builds KUnit tests for the PHY common property API.
> -- >8 --

Yes, that would work.  Do you think it is acceptable?
Thanks!

Gr{oetje,eeting}s,

                        Geert

-- 
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org

In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
                                -- Linus Torvalds

^ permalink raw reply	[flat|nested] 25+ messages in thread

* Re: [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity()
  2026-02-26 15:13       ` Geert Uytterhoeven
@ 2026-02-26 15:21         ` Vladimir Oltean
  0 siblings, 0 replies; 25+ messages in thread
From: Vladimir Oltean @ 2026-02-26 15:21 UTC (permalink / raw)
  To: Geert Uytterhoeven
  Cc: netdev, devicetree, linux-phy, linux-kernel, linux-arm-kernel,
	linux-mediatek, Daniel Golle, Horatiu Vultur, Bjørn Mork,
	Andrew Lunn, Heiner Kallweit, Russell King, David S. Miller,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Rob Herring,
	Krzysztof Kozlowski, Conor Dooley, Vinod Koul, Neil Armstrong,
	Matthias Brugger, AngeloGioacchino Del Regno, Eric Woudstra,
	Marek Behún, Lee Jones, Patrice Chotard,
	open list:KERNEL SELFTEST FRAMEWORK, KUnit Development

On Thu, Feb 26, 2026 at 04:13:59PM +0100, Geert Uytterhoeven wrote:
> Hi Vladimir,
> 
> On Thu, 26 Feb 2026 at 16:10, Vladimir Oltean <vladimir.oltean@nxp.com> wrote:
> > On Thu, Feb 26, 2026 at 02:22:29PM +0100, Geert Uytterhoeven wrote:
> > > > +config PHY_COMMON_PROPS
> > > > +       bool
> > > > +       help
> > > > +         This parses properties common between generic PHYs and Ethernet PHYs.
> > > > +
> > > > +         Select this from consumer drivers to gain access to helpers for
> > > > +         parsing properties from the
> > > > +         Documentation/devicetree/bindings/phy/phy-common-props.yaml schema.
> > > > +
> > > > +config PHY_COMMON_PROPS_TEST
> > > > +       tristate "KUnit tests for PHY common props" if !KUNIT_ALL_TESTS
> > > > +       select PHY_COMMON_PROPS
> > >
> > > This select means that enabling KUNIT_ALL_TESTS also enables extra
> > > functionality, which may not be desirable in a production system.
> > > As PHY_COMMON_PROPS is bool, this extra functionality is even part of
> > > the base kernel if KUNIT_ALL_TESTS=m.  Unfortunately PHY_COMMON_PROPS is
> > > invisible, so this cannot just be changed from "select" to "depends on".
> > > But perhaps PHY_COMMON_PROPS can be made visible if KUNIT_ALL_TESTS,
> > > so the select can be turned into a dependency?
> >
> > Is this what you're asking for?
> >
> > -- >8 --
> > diff --git a/drivers/phy/Kconfig b/drivers/phy/Kconfig
> > index 02467dfd4fb0..1875d5b784f6 100644
> > --- a/drivers/phy/Kconfig
> > +++ b/drivers/phy/Kconfig
> > @@ -6,7 +6,7 @@
> >  menu "PHY Subsystem"
> >
> >  config PHY_COMMON_PROPS
> > -       bool
> > +       bool "PHY common properties" if KUNIT_ALL_TESTS
> >         help
> >           This parses properties common between generic PHYs and Ethernet PHYs.
> >
> > @@ -16,8 +16,7 @@ config PHY_COMMON_PROPS
> >
> >  config PHY_COMMON_PROPS_TEST
> >         tristate "KUnit tests for PHY common props" if !KUNIT_ALL_TESTS
> > -       select PHY_COMMON_PROPS
> > -       depends on KUNIT
> > +       depends on KUNIT && PHY_COMMON_PROPS
> >         default KUNIT_ALL_TESTS
> >         help
> >           This builds KUnit tests for the PHY common property API.
> > -- >8 --
> 
> Yes, that would work.  Do you think it is acceptable?
> Thanks!

Yes, I think it's fine. I misinterpreted what kunit_"all"_tests means,
then read its prompt which says "All KUnit tests with satisfied dependencies".

I'll send a patch.

^ permalink raw reply	[flat|nested] 25+ messages in thread

end of thread, other threads:[~2026-02-26 15:21 UTC | newest]

Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-01-11  9:39 [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vladimir Oltean
2026-01-11  9:39 ` [PATCH v3 net-next 01/10] dt-bindings: phy: rename transmit-amplitude.yaml to phy-common-props.yaml Vladimir Oltean
2026-01-11  9:39 ` [PATCH v3 net-next 02/10] dt-bindings: phy-common-props: create a reusable "protocol-names" definition Vladimir Oltean
2026-01-11  9:39 ` [PATCH v3 net-next 03/10] dt-bindings: phy-common-props: ensure protocol-names are unique Vladimir Oltean
2026-01-11  9:39 ` [PATCH v3 net-next 04/10] dt-bindings: phy-common-props: RX and TX lane polarity inversion Vladimir Oltean
2026-01-11  9:39 ` [PATCH v3 net-next 05/10] phy: add phy_get_rx_polarity() and phy_get_tx_polarity() Vladimir Oltean
2026-01-11 11:53   ` Bjørn Mork
2026-01-11 14:15     ` Vladimir Oltean
2026-01-14 13:10       ` Vinod Koul
2026-01-15  9:34         ` Paolo Abeni
2026-01-15  9:37           ` Paolo Abeni
2026-01-15  9:39             ` Vladimir Oltean
2026-01-16  3:19               ` Jakub Kicinski
2026-02-26 13:22   ` Geert Uytterhoeven
2026-02-26 15:10     ` Vladimir Oltean
2026-02-26 15:13       ` Geert Uytterhoeven
2026-02-26 15:21         ` Vladimir Oltean
2026-01-11  9:39 ` [PATCH v3 net-next 06/10] dt-bindings: net: airoha,en8811h: deprecate "airoha,pnswap-rx" and "airoha,pnswap-tx" Vladimir Oltean
2026-01-11  9:39 ` [PATCH v3 net-next 07/10] net: phy: air_en8811h: " Vladimir Oltean
2026-01-11  9:39 ` [PATCH v3 net-next 08/10] dt-bindings: net: pcs: mediatek,sgmiisys: deprecate "mediatek,pnswap" Vladimir Oltean
2026-01-11  9:39 ` [PATCH v3 net-next 09/10] net: pcs: pcs-mtk-lynxi: pass SGMIISYS OF node to PCS Vladimir Oltean
2026-01-11  9:39 ` [PATCH v3 net-next 10/10] net: pcs: pcs-mtk-lynxi: deprecate "mediatek,pnswap" Vladimir Oltean
2026-01-14 13:18 ` [PATCH v3 net-next 00/10] PHY polarity inversion via generic device tree properties Vinod Koul
2026-01-16  3:16   ` Jakub Kicinski
2026-01-14 14:01 ` (subset) " Vinod Koul

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox