[net-next v11 1/7] dt-bindings: net: Add MTIP L2 switch description

Lukasz Majewski posted 7 patches 9 months, 1 week ago
There is a newer version of this series
[net-next v11 1/7] dt-bindings: net: Add MTIP L2 switch description
Posted by Lukasz Majewski 9 months, 1 week ago
This patch provides description of the MTIP L2 switch available in some
NXP's SOCs - e.g. imx287.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
Reviewed-by: Stefan Wahren <wahrenst@gmx.net>

---
Changes for v2:
- Rename the file to match exactly the compatible
  (nxp,imx287-mtip-switch)

Changes for v3:
- Remove '-' from const:'nxp,imx287-mtip-switch'
- Use '^port@[12]+$' for port patternProperties
- Drop status = "okay";
- Provide proper indentation for 'example' binding (replace 8
  spaces with 4 spaces)
- Remove smsc,disable-energy-detect; property
- Remove interrupt-parent and interrupts properties as not required
- Remove #address-cells and #size-cells from required properties check
- remove description from reg:
- Add $ref: ethernet-switch.yaml#

Changes for v4:
- Use $ref: ethernet-switch.yaml#/$defs/ethernet-ports and remove already
  referenced properties
- Rename file to nxp,imx28-mtip-switch.yaml

Changes for v5:
- Provide proper description for 'ethernet-port' node

Changes for v6:
- Proper usage of
  $ref: ethernet-switch.yaml#/$defs/ethernet-ports/patternProperties
  when specifying the 'ethernet-ports' property
- Add description and check for interrupt-names property

Changes for v7:
- Change switch interrupt name from 'mtipl2sw' to 'enet_switch'

Changes for v8:
- None

Changes for v9:
- Add GPIO_ACTIVE_LOW to reset-gpios mdio phandle

Changes for v10:
- None

Changes for v11:
- None
---
 .../bindings/net/nxp,imx28-mtip-switch.yaml   | 149 ++++++++++++++++++
 1 file changed, 149 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml

diff --git a/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml b/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
new file mode 100644
index 000000000000..35f1fe268de7
--- /dev/null
+++ b/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
@@ -0,0 +1,149 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/nxp,imx28-mtip-switch.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NXP SoC Ethernet Switch Controller (L2 MoreThanIP switch)
+
+maintainers:
+  - Lukasz Majewski <lukma@denx.de>
+
+description:
+  The 2-port switch ethernet subsystem provides ethernet packet (L2)
+  communication and can be configured as an ethernet switch. It provides the
+  reduced media independent interface (RMII), the management data input
+  output (MDIO) for physical layer device (PHY) management.
+
+properties:
+  compatible:
+    const: nxp,imx28-mtip-switch
+
+  reg:
+    maxItems: 1
+
+  phy-supply:
+    description:
+      Regulator that powers Ethernet PHYs.
+
+  clocks:
+    items:
+      - description: Register accessing clock
+      - description: Bus access clock
+      - description: Output clock for external device - e.g. PHY source clock
+      - description: IEEE1588 timer clock
+
+  clock-names:
+    items:
+      - const: ipg
+      - const: ahb
+      - const: enet_out
+      - const: ptp
+
+  interrupts:
+    items:
+      - description: Switch interrupt
+      - description: ENET0 interrupt
+      - description: ENET1 interrupt
+
+  interrupt-names:
+    items:
+      - const: enet_switch
+      - const: enet0
+      - const: enet1
+
+  pinctrl-names: true
+
+  ethernet-ports:
+    type: object
+    $ref: ethernet-switch.yaml#/$defs/ethernet-ports/patternProperties
+    additionalProperties: true
+
+    patternProperties:
+      '^ethernet-port@[12]$':
+        type: object
+        additionalProperties: true
+        properties:
+          reg:
+            items:
+              - enum: [1, 2]
+            description: MTIP L2 switch port number
+
+        required:
+          - reg
+          - label
+          - phy-mode
+          - phy-handle
+
+  mdio:
+    type: object
+    $ref: mdio.yaml#
+    unevaluatedProperties: false
+    description:
+      Specifies the mdio bus in the switch, used as a container for phy nodes.
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - interrupts
+  - interrupt-names
+  - mdio
+  - ethernet-ports
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    #include<dt-bindings/interrupt-controller/irq.h>
+    #include<dt-bindings/gpio/gpio.h>
+    switch@800f0000 {
+        compatible = "nxp,imx28-mtip-switch";
+        reg = <0x800f0000 0x20000>;
+        pinctrl-names = "default";
+        pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>;
+        phy-supply = <&reg_fec_3v3>;
+        interrupts = <100>, <101>, <102>;
+        interrupt-names = "enet_switch", "enet0", "enet1";
+        clocks = <&clks 57>, <&clks 57>, <&clks 64>, <&clks 35>;
+        clock-names = "ipg", "ahb", "enet_out", "ptp";
+
+        ethernet-ports {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            mtip_port1: ethernet-port@1 {
+                reg = <1>;
+                label = "lan0";
+                local-mac-address = [ 00 00 00 00 00 00 ];
+                phy-mode = "rmii";
+                phy-handle = <&ethphy0>;
+            };
+
+            mtip_port2: ethernet-port@2 {
+                reg = <2>;
+                label = "lan1";
+                local-mac-address = [ 00 00 00 00 00 00 ];
+                phy-mode = "rmii";
+                phy-handle = <&ethphy1>;
+            };
+        };
+
+        mdio_sw: mdio {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            reset-gpios = <&gpio2 13 GPIO_ACTIVE_LOW>;
+            reset-delay-us = <25000>;
+            reset-post-delay-us = <10000>;
+
+            ethphy0: ethernet-phy@0 {
+                reg = <0>;
+            };
+
+            ethphy1: ethernet-phy@1 {
+                reg = <1>;
+            };
+        };
+    };
-- 
2.39.5
Re: [net-next v11 1/7] dt-bindings: net: Add MTIP L2 switch description
Posted by Rob Herring 9 months ago
On Sun, May 04, 2025 at 04:55:32PM +0200, Lukasz Majewski wrote:
> This patch provides description of the MTIP L2 switch available in some
> NXP's SOCs - e.g. imx287.
> 
> Signed-off-by: Lukasz Majewski <lukma@denx.de>
> Reviewed-by: Stefan Wahren <wahrenst@gmx.net>
> 
> ---
> Changes for v2:
> - Rename the file to match exactly the compatible
>   (nxp,imx287-mtip-switch)
> 
> Changes for v3:
> - Remove '-' from const:'nxp,imx287-mtip-switch'
> - Use '^port@[12]+$' for port patternProperties
> - Drop status = "okay";
> - Provide proper indentation for 'example' binding (replace 8
>   spaces with 4 spaces)
> - Remove smsc,disable-energy-detect; property
> - Remove interrupt-parent and interrupts properties as not required
> - Remove #address-cells and #size-cells from required properties check
> - remove description from reg:
> - Add $ref: ethernet-switch.yaml#
> 
> Changes for v4:
> - Use $ref: ethernet-switch.yaml#/$defs/ethernet-ports and remove already
>   referenced properties
> - Rename file to nxp,imx28-mtip-switch.yaml
> 
> Changes for v5:
> - Provide proper description for 'ethernet-port' node
> 
> Changes for v6:
> - Proper usage of
>   $ref: ethernet-switch.yaml#/$defs/ethernet-ports/patternProperties
>   when specifying the 'ethernet-ports' property
> - Add description and check for interrupt-names property
> 
> Changes for v7:
> - Change switch interrupt name from 'mtipl2sw' to 'enet_switch'
> 
> Changes for v8:
> - None
> 
> Changes for v9:
> - Add GPIO_ACTIVE_LOW to reset-gpios mdio phandle
> 
> Changes for v10:
> - None
> 
> Changes for v11:
> - None
> ---
>  .../bindings/net/nxp,imx28-mtip-switch.yaml   | 149 ++++++++++++++++++
>  1 file changed, 149 insertions(+)
>  create mode 100644 Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> 
> diff --git a/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml b/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> new file mode 100644
> index 000000000000..35f1fe268de7
> --- /dev/null
> +++ b/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> @@ -0,0 +1,149 @@
> +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
> +%YAML 1.2
> +---
> +$id: http://devicetree.org/schemas/net/nxp,imx28-mtip-switch.yaml#
> +$schema: http://devicetree.org/meta-schemas/core.yaml#
> +
> +title: NXP SoC Ethernet Switch Controller (L2 MoreThanIP switch)
> +
> +maintainers:
> +  - Lukasz Majewski <lukma@denx.de>
> +
> +description:
> +  The 2-port switch ethernet subsystem provides ethernet packet (L2)
> +  communication and can be configured as an ethernet switch. It provides the
> +  reduced media independent interface (RMII), the management data input
> +  output (MDIO) for physical layer device (PHY) management.
> +
> +properties:
> +  compatible:
> +    const: nxp,imx28-mtip-switch
> +
> +  reg:
> +    maxItems: 1
> +
> +  phy-supply:
> +    description:
> +      Regulator that powers Ethernet PHYs.
> +
> +  clocks:
> +    items:
> +      - description: Register accessing clock
> +      - description: Bus access clock
> +      - description: Output clock for external device - e.g. PHY source clock
> +      - description: IEEE1588 timer clock
> +
> +  clock-names:
> +    items:
> +      - const: ipg
> +      - const: ahb
> +      - const: enet_out
> +      - const: ptp
> +
> +  interrupts:
> +    items:
> +      - description: Switch interrupt
> +      - description: ENET0 interrupt
> +      - description: ENET1 interrupt
> +
> +  interrupt-names:
> +    items:
> +      - const: enet_switch
> +      - const: enet0
> +      - const: enet1
> +
> +  pinctrl-names: true
> +
> +  ethernet-ports:
> +    type: object
> +    $ref: ethernet-switch.yaml#/$defs/ethernet-ports/patternProperties

'patternProperties' is wrong. Drop.

> +    additionalProperties: true

Drop.

> +
> +    patternProperties:
> +      '^ethernet-port@[12]$':
> +        type: object
> +        additionalProperties: true
> +        properties:
> +          reg:
> +            items:
> +              - enum: [1, 2]
> +            description: MTIP L2 switch port number
> +
> +        required:
> +          - reg
> +          - label

'label' shouldn't ever be required because s/w shouldn't care what the 
value is.

> +          - phy-mode
> +          - phy-handle
> +
> +  mdio:
> +    type: object
> +    $ref: mdio.yaml#
> +    unevaluatedProperties: false
> +    description:
> +      Specifies the mdio bus in the switch, used as a container for phy nodes.
> +
> +required:
> +  - compatible
> +  - reg
> +  - clocks
> +  - clock-names
> +  - interrupts
> +  - interrupt-names
> +  - mdio
> +  - ethernet-ports
> +
> +unevaluatedProperties: false
> +
> +examples:
> +  - |
> +    #include<dt-bindings/interrupt-controller/irq.h>
> +    #include<dt-bindings/gpio/gpio.h>
> +    switch@800f0000 {
> +        compatible = "nxp,imx28-mtip-switch";
> +        reg = <0x800f0000 0x20000>;
> +        pinctrl-names = "default";
> +        pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>;
> +        phy-supply = <&reg_fec_3v3>;
> +        interrupts = <100>, <101>, <102>;
> +        interrupt-names = "enet_switch", "enet0", "enet1";
> +        clocks = <&clks 57>, <&clks 57>, <&clks 64>, <&clks 35>;
> +        clock-names = "ipg", "ahb", "enet_out", "ptp";
> +
> +        ethernet-ports {
> +            #address-cells = <1>;
> +            #size-cells = <0>;
> +
> +            mtip_port1: ethernet-port@1 {
> +                reg = <1>;
> +                label = "lan0";
> +                local-mac-address = [ 00 00 00 00 00 00 ];
> +                phy-mode = "rmii";
> +                phy-handle = <&ethphy0>;
> +            };
> +
> +            mtip_port2: ethernet-port@2 {
> +                reg = <2>;
> +                label = "lan1";
> +                local-mac-address = [ 00 00 00 00 00 00 ];
> +                phy-mode = "rmii";
> +                phy-handle = <&ethphy1>;
> +            };
> +        };
> +
> +        mdio_sw: mdio {
> +            #address-cells = <1>;
> +            #size-cells = <0>;
> +
> +            reset-gpios = <&gpio2 13 GPIO_ACTIVE_LOW>;
> +            reset-delay-us = <25000>;
> +            reset-post-delay-us = <10000>;
> +
> +            ethphy0: ethernet-phy@0 {
> +                reg = <0>;
> +            };
> +
> +            ethphy1: ethernet-phy@1 {
> +                reg = <1>;
> +            };
> +        };
> +    };
> -- 
> 2.39.5
>
Re: [net-next v11 1/7] dt-bindings: net: Add MTIP L2 switch description
Posted by Lukasz Majewski 9 months ago
Hi Rob,

> On Sun, May 04, 2025 at 04:55:32PM +0200, Lukasz Majewski wrote:
> > This patch provides description of the MTIP L2 switch available in
> > some NXP's SOCs - e.g. imx287.
> > 
> > Signed-off-by: Lukasz Majewski <lukma@denx.de>
> > Reviewed-by: Stefan Wahren <wahrenst@gmx.net>
> > 
> > ---
> > Changes for v2:
> > - Rename the file to match exactly the compatible
> >   (nxp,imx287-mtip-switch)
> > 
> > Changes for v3:
> > - Remove '-' from const:'nxp,imx287-mtip-switch'
> > - Use '^port@[12]+$' for port patternProperties
> > - Drop status = "okay";
> > - Provide proper indentation for 'example' binding (replace 8
> >   spaces with 4 spaces)
> > - Remove smsc,disable-energy-detect; property
> > - Remove interrupt-parent and interrupts properties as not required
> > - Remove #address-cells and #size-cells from required properties
> > check
> > - remove description from reg:
> > - Add $ref: ethernet-switch.yaml#
> > 
> > Changes for v4:
> > - Use $ref: ethernet-switch.yaml#/$defs/ethernet-ports and remove
> > already referenced properties
> > - Rename file to nxp,imx28-mtip-switch.yaml
> > 
> > Changes for v5:
> > - Provide proper description for 'ethernet-port' node
> > 
> > Changes for v6:
> > - Proper usage of
> >   $ref: ethernet-switch.yaml#/$defs/ethernet-ports/patternProperties
> >   when specifying the 'ethernet-ports' property
> > - Add description and check for interrupt-names property
> > 
> > Changes for v7:
> > - Change switch interrupt name from 'mtipl2sw' to 'enet_switch'
> > 
> > Changes for v8:
> > - None
> > 
> > Changes for v9:
> > - Add GPIO_ACTIVE_LOW to reset-gpios mdio phandle
> > 
> > Changes for v10:
> > - None
> > 
> > Changes for v11:
> > - None
> > ---
> >  .../bindings/net/nxp,imx28-mtip-switch.yaml   | 149
> > ++++++++++++++++++ 1 file changed, 149 insertions(+)
> >  create mode 100644
> > Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> > 
> > diff --git
> > a/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> > b/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> > new file mode 100644 index 000000000000..35f1fe268de7 --- /dev/null
> > +++
> > b/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> > @@ -0,0 +1,149 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR
> > BSD-2-Clause) +%YAML 1.2
> > +---
> > +$id: http://devicetree.org/schemas/net/nxp,imx28-mtip-switch.yaml#
> > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > +
> > +title: NXP SoC Ethernet Switch Controller (L2 MoreThanIP switch)
> > +
> > +maintainers:
> > +  - Lukasz Majewski <lukma@denx.de>
> > +
> > +description:
> > +  The 2-port switch ethernet subsystem provides ethernet packet
> > (L2)
> > +  communication and can be configured as an ethernet switch. It
> > provides the
> > +  reduced media independent interface (RMII), the management data
> > input
> > +  output (MDIO) for physical layer device (PHY) management.
> > +
> > +properties:
> > +  compatible:
> > +    const: nxp,imx28-mtip-switch
> > +
> > +  reg:
> > +    maxItems: 1
> > +
> > +  phy-supply:
> > +    description:
> > +      Regulator that powers Ethernet PHYs.
> > +
> > +  clocks:
> > +    items:
> > +      - description: Register accessing clock
> > +      - description: Bus access clock
> > +      - description: Output clock for external device - e.g. PHY
> > source clock
> > +      - description: IEEE1588 timer clock
> > +
> > +  clock-names:
> > +    items:
> > +      - const: ipg
> > +      - const: ahb
> > +      - const: enet_out
> > +      - const: ptp
> > +
> > +  interrupts:
> > +    items:
> > +      - description: Switch interrupt
> > +      - description: ENET0 interrupt
> > +      - description: ENET1 interrupt
> > +
> > +  interrupt-names:
> > +    items:
> > +      - const: enet_switch
> > +      - const: enet0
> > +      - const: enet1
> > +
> > +  pinctrl-names: true
> > +
> > +  ethernet-ports:
> > +    type: object
> > +    $ref:
> > ethernet-switch.yaml#/$defs/ethernet-ports/patternProperties  
> 
> 'patternProperties' is wrong. Drop.
> 

When I do drop it, then
make dt_binding_check DT_SCHEMA_FILES=nxp,imx28-mtip-switch.yaml

shows:

nxp,imx28-mtip-switch.example.dtb: switch@800f0000: ethernet-ports:
'oneOf' conditional failed, one must be fixed:

'ports' is a required property 
'ethernet-ports' is a required property
        from schema $id:
        http://devicetree.org/schemas/net/nxp,imx28-mtip-switch.yaml#

We do have ethernet-ports:
and we do "include" ($ref)
https://elixir.bootlin.com/linux/v6.14.6/source/Documentation/devicetree/bindings/net/ethernet-switch.yaml#L77

which is what we exactly need.

> > +    additionalProperties: true  
> 
> Drop.
> 

When removed we do have:
nxp,imx28-mtip-switch.example.dtb: switch@800f0000: Unevaluated
properties are not allowed ('ethernet-ports' was unexpected)

or 

nxp,imx28-mtip-switch.yaml: ethernet-ports: Missing
additionalProperties/unevaluatedProperties constraint

Depending if I do remove 'patternProperties' above.

To sum up - with the current code, the DT schema checks pass. It also
looks like the $ref for ethernet-switch is used in an optimal way.

I would opt for keeping the code as is for v12.

> > +
> > +    patternProperties:
> > +      '^ethernet-port@[12]$':
> > +        type: object
> > +        additionalProperties: true
> > +        properties:
> > +          reg:
> > +            items:
> > +              - enum: [1, 2]
> > +            description: MTIP L2 switch port number
> > +
> > +        required:
> > +          - reg
> > +          - label  
> 
> 'label' shouldn't ever be required because s/w shouldn't care what
> the value is.

Ok, I will remove it for v12.

> 
> > +          - phy-mode
> > +          - phy-handle
> > +
> > +  mdio:
> > +    type: object
> > +    $ref: mdio.yaml#
> > +    unevaluatedProperties: false
> > +    description:
> > +      Specifies the mdio bus in the switch, used as a container
> > for phy nodes. +
> > +required:
> > +  - compatible
> > +  - reg
> > +  - clocks
> > +  - clock-names
> > +  - interrupts
> > +  - interrupt-names
> > +  - mdio
> > +  - ethernet-ports
> > +
> > +unevaluatedProperties: false
> > +
> > +examples:
> > +  - |
> > +    #include<dt-bindings/interrupt-controller/irq.h>
> > +    #include<dt-bindings/gpio/gpio.h>
> > +    switch@800f0000 {
> > +        compatible = "nxp,imx28-mtip-switch";
> > +        reg = <0x800f0000 0x20000>;
> > +        pinctrl-names = "default";
> > +        pinctrl-0 = <&mac0_pins_a>, <&mac1_pins_a>;
> > +        phy-supply = <&reg_fec_3v3>;
> > +        interrupts = <100>, <101>, <102>;
> > +        interrupt-names = "enet_switch", "enet0", "enet1";
> > +        clocks = <&clks 57>, <&clks 57>, <&clks 64>, <&clks 35>;
> > +        clock-names = "ipg", "ahb", "enet_out", "ptp";
> > +
> > +        ethernet-ports {
> > +            #address-cells = <1>;
> > +            #size-cells = <0>;
> > +
> > +            mtip_port1: ethernet-port@1 {
> > +                reg = <1>;
> > +                label = "lan0";
> > +                local-mac-address = [ 00 00 00 00 00 00 ];
> > +                phy-mode = "rmii";
> > +                phy-handle = <&ethphy0>;
> > +            };
> > +
> > +            mtip_port2: ethernet-port@2 {
> > +                reg = <2>;
> > +                label = "lan1";
> > +                local-mac-address = [ 00 00 00 00 00 00 ];
> > +                phy-mode = "rmii";
> > +                phy-handle = <&ethphy1>;
> > +            };
> > +        };
> > +
> > +        mdio_sw: mdio {
> > +            #address-cells = <1>;
> > +            #size-cells = <0>;
> > +
> > +            reset-gpios = <&gpio2 13 GPIO_ACTIVE_LOW>;
> > +            reset-delay-us = <25000>;
> > +            reset-post-delay-us = <10000>;
> > +
> > +            ethphy0: ethernet-phy@0 {
> > +                reg = <0>;
> > +            };
> > +
> > +            ethphy1: ethernet-phy@1 {
> > +                reg = <1>;
> > +            };
> > +        };
> > +    };
> > -- 
> > 2.39.5
> >   




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de
Re: [net-next v11 1/7] dt-bindings: net: Add MTIP L2 switch description
Posted by Rob Herring 9 months ago
On Tue, May 13, 2025 at 08:09:20AM +0200, Lukasz Majewski wrote:
> Hi Rob,
> 
> > On Sun, May 04, 2025 at 04:55:32PM +0200, Lukasz Majewski wrote:
> > > This patch provides description of the MTIP L2 switch available in
> > > some NXP's SOCs - e.g. imx287.
> > > 
> > > Signed-off-by: Lukasz Majewski <lukma@denx.de>
> > > Reviewed-by: Stefan Wahren <wahrenst@gmx.net>
> > > 
> > > ---
> > > Changes for v2:
> > > - Rename the file to match exactly the compatible
> > >   (nxp,imx287-mtip-switch)
> > > 
> > > Changes for v3:
> > > - Remove '-' from const:'nxp,imx287-mtip-switch'
> > > - Use '^port@[12]+$' for port patternProperties
> > > - Drop status = "okay";
> > > - Provide proper indentation for 'example' binding (replace 8
> > >   spaces with 4 spaces)
> > > - Remove smsc,disable-energy-detect; property
> > > - Remove interrupt-parent and interrupts properties as not required
> > > - Remove #address-cells and #size-cells from required properties
> > > check
> > > - remove description from reg:
> > > - Add $ref: ethernet-switch.yaml#
> > > 
> > > Changes for v4:
> > > - Use $ref: ethernet-switch.yaml#/$defs/ethernet-ports and remove
> > > already referenced properties
> > > - Rename file to nxp,imx28-mtip-switch.yaml
> > > 
> > > Changes for v5:
> > > - Provide proper description for 'ethernet-port' node
> > > 
> > > Changes for v6:
> > > - Proper usage of
> > >   $ref: ethernet-switch.yaml#/$defs/ethernet-ports/patternProperties
> > >   when specifying the 'ethernet-ports' property
> > > - Add description and check for interrupt-names property
> > > 
> > > Changes for v7:
> > > - Change switch interrupt name from 'mtipl2sw' to 'enet_switch'
> > > 
> > > Changes for v8:
> > > - None
> > > 
> > > Changes for v9:
> > > - Add GPIO_ACTIVE_LOW to reset-gpios mdio phandle
> > > 
> > > Changes for v10:
> > > - None
> > > 
> > > Changes for v11:
> > > - None
> > > ---
> > >  .../bindings/net/nxp,imx28-mtip-switch.yaml   | 149
> > > ++++++++++++++++++ 1 file changed, 149 insertions(+)
> > >  create mode 100644
> > > Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> > > 
> > > diff --git
> > > a/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> > > b/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> > > new file mode 100644 index 000000000000..35f1fe268de7 --- /dev/null
> > > +++
> > > b/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> > > @@ -0,0 +1,149 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR
> > > BSD-2-Clause) +%YAML 1.2
> > > +---
> > > +$id: http://devicetree.org/schemas/net/nxp,imx28-mtip-switch.yaml#
> > > +$schema: http://devicetree.org/meta-schemas/core.yaml#
> > > +
> > > +title: NXP SoC Ethernet Switch Controller (L2 MoreThanIP switch)
> > > +
> > > +maintainers:
> > > +  - Lukasz Majewski <lukma@denx.de>
> > > +
> > > +description:
> > > +  The 2-port switch ethernet subsystem provides ethernet packet
> > > (L2)
> > > +  communication and can be configured as an ethernet switch. It
> > > provides the
> > > +  reduced media independent interface (RMII), the management data
> > > input
> > > +  output (MDIO) for physical layer device (PHY) management.
> > > +
> > > +properties:
> > > +  compatible:
> > > +    const: nxp,imx28-mtip-switch
> > > +
> > > +  reg:
> > > +    maxItems: 1
> > > +
> > > +  phy-supply:
> > > +    description:
> > > +      Regulator that powers Ethernet PHYs.
> > > +
> > > +  clocks:
> > > +    items:
> > > +      - description: Register accessing clock
> > > +      - description: Bus access clock
> > > +      - description: Output clock for external device - e.g. PHY
> > > source clock
> > > +      - description: IEEE1588 timer clock
> > > +
> > > +  clock-names:
> > > +    items:
> > > +      - const: ipg
> > > +      - const: ahb
> > > +      - const: enet_out
> > > +      - const: ptp
> > > +
> > > +  interrupts:
> > > +    items:
> > > +      - description: Switch interrupt
> > > +      - description: ENET0 interrupt
> > > +      - description: ENET1 interrupt
> > > +
> > > +  interrupt-names:
> > > +    items:
> > > +      - const: enet_switch
> > > +      - const: enet0
> > > +      - const: enet1
> > > +
> > > +  pinctrl-names: true
> > > +
> > > +  ethernet-ports:
> > > +    type: object
> > > +    $ref:
> > > ethernet-switch.yaml#/$defs/ethernet-ports/patternProperties  
> > 
> > 'patternProperties' is wrong. Drop.
> > 
> 
> When I do drop it, then
> make dt_binding_check DT_SCHEMA_FILES=nxp,imx28-mtip-switch.yaml
> 
> shows:
> 
> nxp,imx28-mtip-switch.example.dtb: switch@800f0000: ethernet-ports:
> 'oneOf' conditional failed, one must be fixed:
> 
> 'ports' is a required property 
> 'ethernet-ports' is a required property
>         from schema $id:
>         http://devicetree.org/schemas/net/nxp,imx28-mtip-switch.yaml#

Actually, it needs to be at the top-level as well:

allOf:
  - $ref: ethernet-switch.yaml#/$defs/ethernet-ports


> 
> We do have ethernet-ports:
> and we do "include" ($ref)
> https://elixir.bootlin.com/linux/v6.14.6/source/Documentation/devicetree/bindings/net/ethernet-switch.yaml#L77
> 
> which is what we exactly need.

The $ref is effectively pasting in what you reference, so the result 
would be:

ethernet-ports:
  type: object
  "^(ethernet-)?ports$":
    patternProperties:
      "^(ethernet-)?port@[0-9a-f]+$":
        description: Ethernet switch ports
        $ref: ethernet-switch-port.yaml#
        unevaluatedProperties: false

A DT node/property name and json-schema keyword at the same level is 
never correct. json-schema behavior is to ignore (silently) any unknown 
keyword. So the validator sees the keyword "^(ethernet-)?ports$" and 
ignores everything below it.


> 
> > > +    additionalProperties: true  
> > 
> > Drop.
> > 
> 
> When removed we do have:
> nxp,imx28-mtip-switch.example.dtb: switch@800f0000: Unevaluated
> properties are not allowed ('ethernet-ports' was unexpected)
> 
> or 
> 
> nxp,imx28-mtip-switch.yaml: ethernet-ports: Missing
> additionalProperties/unevaluatedProperties constraint

'additionalProperties: true' should suppress that.

> 
> Depending if I do remove 'patternProperties' above.
> 
> To sum up - with the current code, the DT schema checks pass. It also
> looks like the $ref for ethernet-switch is used in an optimal way.
> 
> I would opt for keeping the code as is for v12.
Re: [net-next v11 1/7] dt-bindings: net: Add MTIP L2 switch description
Posted by Lukasz Majewski 9 months ago
Hi Rob,

Thanks for your detailed explanation.

> On Tue, May 13, 2025 at 08:09:20AM +0200, Lukasz Majewski wrote:
> > Hi Rob,
> >   
> > > On Sun, May 04, 2025 at 04:55:32PM +0200, Lukasz Majewski wrote:  
> > > > This patch provides description of the MTIP L2 switch available
> > > > in some NXP's SOCs - e.g. imx287.
> > > > 
> > > > Signed-off-by: Lukasz Majewski <lukma@denx.de>
> > > > Reviewed-by: Stefan Wahren <wahrenst@gmx.net>
> > > > 
> > > > ---
> > > > Changes for v2:
> > > > - Rename the file to match exactly the compatible
> > > >   (nxp,imx287-mtip-switch)
> > > > 
> > > > Changes for v3:
> > > > - Remove '-' from const:'nxp,imx287-mtip-switch'
> > > > - Use '^port@[12]+$' for port patternProperties
> > > > - Drop status = "okay";
> > > > - Provide proper indentation for 'example' binding (replace 8
> > > >   spaces with 4 spaces)
> > > > - Remove smsc,disable-energy-detect; property
> > > > - Remove interrupt-parent and interrupts properties as not
> > > > required
> > > > - Remove #address-cells and #size-cells from required properties
> > > > check
> > > > - remove description from reg:
> > > > - Add $ref: ethernet-switch.yaml#
> > > > 
> > > > Changes for v4:
> > > > - Use $ref: ethernet-switch.yaml#/$defs/ethernet-ports and
> > > > remove already referenced properties
> > > > - Rename file to nxp,imx28-mtip-switch.yaml
> > > > 
> > > > Changes for v5:
> > > > - Provide proper description for 'ethernet-port' node
> > > > 
> > > > Changes for v6:
> > > > - Proper usage of
> > > >   $ref:
> > > > ethernet-switch.yaml#/$defs/ethernet-ports/patternProperties
> > > > when specifying the 'ethernet-ports' property
> > > > - Add description and check for interrupt-names property
> > > > 
> > > > Changes for v7:
> > > > - Change switch interrupt name from 'mtipl2sw' to 'enet_switch'
> > > > 
> > > > Changes for v8:
> > > > - None
> > > > 
> > > > Changes for v9:
> > > > - Add GPIO_ACTIVE_LOW to reset-gpios mdio phandle
> > > > 
> > > > Changes for v10:
> > > > - None
> > > > 
> > > > Changes for v11:
> > > > - None
> > > > ---
> > > >  .../bindings/net/nxp,imx28-mtip-switch.yaml   | 149
> > > > ++++++++++++++++++ 1 file changed, 149 insertions(+)
> > > >  create mode 100644
> > > > Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> > > > 
> > > > diff --git
> > > > a/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> > > > b/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> > > > new file mode 100644 index 000000000000..35f1fe268de7 ---
> > > > /dev/null +++
> > > > b/Documentation/devicetree/bindings/net/nxp,imx28-mtip-switch.yaml
> > > > @@ -0,0 +1,149 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR
> > > > BSD-2-Clause) +%YAML 1.2
> > > > +---
> > > > +$id:
> > > > http://devicetree.org/schemas/net/nxp,imx28-mtip-switch.yaml#
> > > > +$schema: http://devicetree.org/meta-schemas/core.yaml# +
> > > > +title: NXP SoC Ethernet Switch Controller (L2 MoreThanIP
> > > > switch) +
> > > > +maintainers:
> > > > +  - Lukasz Majewski <lukma@denx.de>
> > > > +
> > > > +description:
> > > > +  The 2-port switch ethernet subsystem provides ethernet packet
> > > > (L2)
> > > > +  communication and can be configured as an ethernet switch. It
> > > > provides the
> > > > +  reduced media independent interface (RMII), the management
> > > > data input
> > > > +  output (MDIO) for physical layer device (PHY) management.
> > > > +
> > > > +properties:
> > > > +  compatible:
> > > > +    const: nxp,imx28-mtip-switch
> > > > +
> > > > +  reg:
> > > > +    maxItems: 1
> > > > +
> > > > +  phy-supply:
> > > > +    description:
> > > > +      Regulator that powers Ethernet PHYs.
> > > > +
> > > > +  clocks:
> > > > +    items:
> > > > +      - description: Register accessing clock
> > > > +      - description: Bus access clock
> > > > +      - description: Output clock for external device - e.g.
> > > > PHY source clock
> > > > +      - description: IEEE1588 timer clock
> > > > +
> > > > +  clock-names:
> > > > +    items:
> > > > +      - const: ipg
> > > > +      - const: ahb
> > > > +      - const: enet_out
> > > > +      - const: ptp
> > > > +
> > > > +  interrupts:
> > > > +    items:
> > > > +      - description: Switch interrupt
> > > > +      - description: ENET0 interrupt
> > > > +      - description: ENET1 interrupt
> > > > +
> > > > +  interrupt-names:
> > > > +    items:
> > > > +      - const: enet_switch
> > > > +      - const: enet0
> > > > +      - const: enet1
> > > > +
> > > > +  pinctrl-names: true
> > > > +
> > > > +  ethernet-ports:
> > > > +    type: object
> > > > +    $ref:
> > > > ethernet-switch.yaml#/$defs/ethernet-ports/patternProperties    
> > > 
> > > 'patternProperties' is wrong. Drop.
> > >   
> > 
> > When I do drop it, then
> > make dt_binding_check DT_SCHEMA_FILES=nxp,imx28-mtip-switch.yaml
> > 
> > shows:
> > 
> > nxp,imx28-mtip-switch.example.dtb: switch@800f0000: ethernet-ports:
> > 'oneOf' conditional failed, one must be fixed:
> > 
> > 'ports' is a required property 
> > 'ethernet-ports' is a required property
> >         from schema $id:
> >         http://devicetree.org/schemas/net/nxp,imx28-mtip-switch.yaml#
> >  
> 
> Actually, it needs to be at the top-level as well:
> 
> allOf:
>   - $ref: ethernet-switch.yaml#/$defs/ethernet-ports
> 

So after your suggestions - I've add:

allOf:
  - $ref: ethernet-switch.yaml#/$defs/ethernet-ports

In the top level of the file - above of
properties:
  ...
  ethernet-ports:
    type: object
    additionalProperties: true

    patternProperties:
	'^ethernet-port@[12]$':
	  type:·object
          additionalProperties:·true
          properties:
	    reg:
              items:
                - enum: [1, 2]
              description: MTIP L2 switch port number

And after calling:
make dt_binding_check DT_SCHEMA_FILES=nxp,imx28-mtip-switch.yaml

there are no errors.

However, when I make a mistake nad in the "examples" section I change
'lablel' -> 'labelx' I see

switch@800f0000: ethernet-ports:ethernet-port@2: Unevaluated properties
are not allowed ('labelx' was unexpected)

which I suppose is expected behaviour.

> 
> > 
> > We do have ethernet-ports:
> > and we do "include" ($ref)
> > https://elixir.bootlin.com/linux/v6.14.6/source/Documentation/devicetree/bindings/net/ethernet-switch.yaml#L77
> > 
> > which is what we exactly need.  
> 
> The $ref is effectively pasting in what you reference, so the result 
> would be:
> 
> ethernet-ports:
>   type: object
>   "^(ethernet-)?ports$":
>     patternProperties:
>       "^(ethernet-)?port@[0-9a-f]+$":
>         description: Ethernet switch ports
>         $ref: ethernet-switch-port.yaml#
>         unevaluatedProperties: false
> 
> A DT node/property name and json-schema keyword at the same level is 
> never correct. json-schema behavior is to ignore (silently) any
> unknown keyword. So the validator sees the keyword
> "^(ethernet-)?ports$" and ignores everything below it.
> 
> 
> >   
> > > > +    additionalProperties: true    
> > > 
> > > Drop.
> > >   
> > 
> > When removed we do have:
> > nxp,imx28-mtip-switch.example.dtb: switch@800f0000: Unevaluated
> > properties are not allowed ('ethernet-ports' was unexpected)
> > 
> > or 
> > 
> > nxp,imx28-mtip-switch.yaml: ethernet-ports: Missing
> > additionalProperties/unevaluatedProperties constraint  
> 
> 'additionalProperties: true' should suppress that.
> 
> > 
> > Depending if I do remove 'patternProperties' above.
> > 
> > To sum up - with the current code, the DT schema checks pass. It
> > also looks like the $ref for ethernet-switch is used in an optimal
> > way.
> > 
> > I would opt for keeping the code as is for v12.  




Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de