Skip to contentSkip to conversation

dt-bindings: net: dsa: convert binding for mediatek switches

RFC Superseded Frank Wunderlich 3 participants 9 messages May 2, 2022 – May 4, 2022

Subsystems (5)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

RFC 1/1 dt-bindings: net: dsa: convert binding for mediatek switches

From: Frank Wunderlich <[email protected]>

Convert txt binding to yaml binding for Mediatek switches.

---
 .../devicetree/bindings/net/dsa/mediatek.yaml | 435 ++++++++++++++++++
 .../devicetree/bindings/net/dsa/mt7530.txt    | 327 -------------
 2 files changed, 435 insertions(+), 327 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/mediatek.yaml
 delete mode 100644 Documentation/devicetree/bindings/net/dsa/mt7530.txt
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +435 -0
new file mode 100644
index 000000000000..c1724809d34e
@@ -0,0 +1,435 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/dsa/mediatek.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek MT7530 Ethernet switch
+
+maintainers:
+  - Sean Wang <[email protected]>
+  - Landen Chao <[email protected]>
+  - DENG Qingfang <[email protected]>
+
+description: |
+  Port 5 of mt7530 and mt7621 switch is muxed between:
+  1. GMAC5: GMAC5 can interface with another external MAC or PHY.
+  2. PHY of port 0 or port 4: PHY interfaces with an external MAC like 2nd GMAC
+     of the SOC. Used in many setups where port 0/4 becomes the WAN port.
+     Note: On a MT7621 SOC with integrated switch: 2nd GMAC can only connected to
+       GMAC5 when the gpios for RGMII2 (GPIO 22-33) are not used and not
+       connected to external component!
+
+  Port 5 modes/configurations:
+  1. Port 5 is disabled and isolated: An external phy can interface to the 2nd
+     GMAC of the SOC.
+     In the case of a build-in MT7530 switch, port 5 shares the RGMII bus with 2nd
+     GMAC and an optional external phy. Mind the GPIO/pinctl settings of the SOC!
+  2. Port 5 is muxed to PHY of port 0/4: Port 0/4 interfaces with 2nd GMAC.
+     It is a simple MAC to PHY interface, port 5 needs to be setup for xMII mode
+     and RGMII delay.
+  3. Port 5 is muxed to GMAC5 and can interface to an external phy.
+     Port 5 becomes an extra switch port.
+     Only works on platform where external phy TX<->RX lines are swapped.
+     Like in the Ubiquiti ER-X-SFP.
+  4. Port 5 is muxed to GMAC5 and interfaces with the 2nd GAMC as 2nd CPU port.
+     Currently a 2nd CPU port is not supported by DSA code.
+
+  Depending on how the external PHY is wired:
+  1. normal: The PHY can only connect to 2nd GMAC but not to the switch
+  2. swapped: RGMII TX, RX are swapped; external phy interface with the switch as
+     a ethernet port. But can't interface to the 2nd GMAC.
+
+    Based on the DT the port 5 mode is configured.
+
+  Driver tries to lookup the phy-handle of the 2nd GMAC of the master device.
+  When phy-handle matches PHY of port 0 or 4 then port 5 set-up as mode 2.
+  phy-mode must be set, see also example 2 below!
+  * mt7621: phy-mode = "rgmii-txid";
+  * mt7623: phy-mode = "rgmii";
+
+  CPU-Ports need a phy-mode property:
+    Allowed values on mt7530 and mt7621:
+      - "rgmii"
+      - "trgmii"
+    On mt7531:
+      - "1000base-x"
+      - "2500base-x"
+      - "sgmii"
+
+
+properties:
+  compatible:
+    enum:
+      - mediatek,mt7530
+      - mediatek,mt7531
+      - mediatek,mt7621
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  core-supply:
+    description: |
+      Phandle to the regulator node necessary for the core power.
+
+  "#gpio-cells":
+    description: |
+      Must be 2 if gpio-controller is defined.
+    const: 2
+
+  gpio-controller:
+    type: boolean
+    description: |
+      Boolean; if defined, MT7530's LED controller will run on
+      GPIO mode.
+
+  "#interrupt-cells":
+    const: 1
+
+  interrupt-controller:
+    type: boolean
+    description: |
+      Boolean; Enables the internal interrupt controller.
+
+  interrupts:
+    description: |
+      Parent interrupt for the interrupt controller.
+    maxItems: 1
+
+  io-supply:
+    description: |
+      Phandle to the regulator node necessary for the I/O power.
+      See Documentation/devicetree/bindings/regulator/mt6323-regulator.txt
+      for details for the regulator setup on these boards.
+
+  mediatek,mcm:
+    type: boolean
+    description: |
+      Boolean; if defined, indicates that either MT7530 is the part
+      on multi-chip module belong to MT7623A has or the remotely standalone
+      chip as the function MT7623N reference board provided for.
+
+  reset-gpios:
+    description: |
+      Should be a gpio specifier for a reset line.
+    maxItems: 1
+
+  reset-names:
+    description: |
+      Should be set to "mcm".
+    const: mcm
+
+  resets:
+    description: |
+      Phandle pointing to the system reset controller with
+      line index for the ethsys.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+allOf:
+  - $ref: "dsa.yaml#"
+  - if:
+      required:
+        - mediatek,mcm
+    then:
+      required:
+        - resets
+        - reset-names
+    else:
+      required:
+        - reset-gpios
+
+  - if:
+      required:
+        - interrupt-controller
+    then:
+      required:
+        - "#interrupt-cells"
+        - interrupts
+
+  - if:
+      properties:
+        compatible:
+          items:
+            - const: mediatek,mt7530
+    then:
+      required:
+        - core-supply
+        - io-supply
+
+
+patternProperties:
+  "^ports$":
+    type: object
+
+    patternProperties:
+      "^port@[0-9]+$":
+        type: object
+        description: Ethernet switch ports
+
+        $ref: dsa-port.yaml#
+
+        properties:
+          reg:
+            description: |
+              Port address described must be 6 for CPU port and from 0 to 5 for user ports.
+
+        unevaluatedProperties: false
+
+        allOf:
+          - if:
+              properties:
+                label:
+                  items:
+                    - const: cpu
+            then:
+              required:
+                - reg
+                - phy-mode
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    mdio0 {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        switch@0 {
+            compatible = "mediatek,mt7530";
+            #address-cells = <1>;
+            #size-cells = <0>;
+            reg = <0>;
+
+            core-supply = <&mt6323_vpa_reg>;
+            io-supply = <&mt6323_vemc3v3_reg>;
+            reset-gpios = <&pio 33 0>;
+
+            ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                port@0 {
+                    reg = <0>;
+                    label = "lan0";
+                };
+
+                port@1 {
+                    reg = <1>;
+                    label = "lan1";
+                };
+
+                port@2 {
+                    reg = <2>;
+                    label = "lan2";
+                };
+
+                port@3 {
+                    reg = <3>;
+                    label = "lan3";
+                };
+
+                port@4 {
+                    reg = <4>;
+                    label = "wan";
+                };
+
+                port@6 {
+                    reg = <6>;
+                    label = "cpu";
+                    ethernet = <&gmac0>;
+                    phy-mode = "trgmii";
+                    fixed-link {
+                        speed = <1000>;
+                        full-duplex;
+                    };
+                };
+            };
+        };
+    };
+
+  - |
+    //Example 2: MT7621: Port 4 is WAN port: 2nd GMAC -> Port 5 -> PHY port 4.
+
+    eth {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        gmac0: mac@0 {
+            compatible = "mediatek,eth-mac";
+            reg = <0>;
+            phy-mode = "rgmii";
+
+            fixed-link {
+                speed = <1000>;
+                full-duplex;
+                pause;
+            };
+        };
+
+        gmac1: mac@1 {
+            compatible = "mediatek,eth-mac";
+            reg = <1>;
+            phy-mode = "rgmii-txid";
+            phy-handle = <&phy4>;
+        };
+
+        mdio: mdio-bus {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            /* Internal phy */
+            phy4: ethernet-phy@4 {
+                reg = <4>;
+            };
+
+            mt7530: switch@1f {
+                compatible = "mediatek,mt7621";
+                #address-cells = <1>;
+                #size-cells = <0>;
+                reg = <0x1f>;
+                mediatek,mcm;
+
+                resets = <&rstctrl 2>;
+                reset-names = "mcm";
+
+                ports {
+                    #address-cells = <1>;
+                    #size-cells = <0>;
+
+                    port@0 {
+                        reg = <0>;
+                        label = "lan0";
+                    };
+
+                    port@1 {
+                        reg = <1>;
+                        label = "lan1";
+                    };
+
+                    port@2 {
+                        reg = <2>;
+                        label = "lan2";
+                    };
+
+                    port@3 {
+                        reg = <3>;
+                        label = "lan3";
+                    };
+
+        /* Commented out. Port 4 is handled by 2nd GMAC.
+                    port@4 {
+                        reg = <4>;
+                        label = "lan4";
+                    };
+        */
+
+                    port@6 {
+                        reg = <6>;
+                        label = "cpu";
+                        ethernet = <&gmac0>;
+                        phy-mode = "rgmii";
+
+                        fixed-link {
+                            speed = <1000>;
+                            full-duplex;
+                            pause;
+                        };
+                    };
+                };
+            };
+        };
+    };
+
+  - |
+    //Example 3: MT7621: Port 5 is connected to external PHY: Port 5 -> external PHY.
+
+    eth {
+        #address-cells = <1>;
+        #size-cells = <0>;
+        gmac_0: mac@0 {
+            compatible = "mediatek,eth-mac";
+            reg = <0>;
+            phy-mode = "rgmii";
+
+            fixed-link {
+                speed = <1000>;
+                full-duplex;
+                pause;
+            };
+        };
+
+        mdio0: mdio-bus {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            /* External phy */
+            ephy5: ethernet-phy@7 {
+                reg = <7>;
+            };
+
+            switch@1f {
+                compatible = "mediatek,mt7621";
+                #address-cells = <1>;
+                #size-cells = <0>;
+                reg = <0x1f>;
+                mediatek,mcm;
+
+                resets = <&rstctrl 2>;
+                reset-names = "mcm";
+
+                ports {
+                    #address-cells = <1>;
+                    #size-cells = <0>;
+
+                    port@0 {
+                        reg = <0>;
+                        label = "lan0";
+                    };
+
+                    port@1 {
+                        reg = <1>;
+                        label = "lan1";
+                    };
+
+                    port@2 {
+                        reg = <2>;
+                        label = "lan2";
+                    };
+
+                    port@3 {
+                        reg = <3>;
+                        label = "lan3";
+                    };
+
+                    port@4 {
+                        reg = <4>;
+                        label = "lan4";
+                    };
+
+                    port@5 {
+                        reg = <5>;
+                        label = "lan5";
+                        phy-mode = "rgmii";
+                        phy-handle = <&ephy5>;
+                    };
+
+                    cpu_port0: port@6 {
+                        reg = <6>;
+                        label = "cpu";
+                        ethernet = <&gmac_0>;
+                        phy-mode = "rgmii";
+
+                        fixed-link {
+                            speed = <1000>;
+                            full-duplex;
+                            pause;
+                        };
+                    };
+                };
+            };
+        };
+    };
Documentation/devicetree/bindings/net/dsa/mt7530.txt deleted +0 -327

327 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw

Documentation/devicetree/bindings/net/dsa/mediatek.yaml

Quoted 17 lines · Frank Wunderlich

From: Frank Wunderlich <[email protected]>

Convert txt binding to yaml binding for Mediatek switches.

---
 .../devicetree/bindings/net/dsa/mediatek.yaml | 435 ++++++++++++++++++
 .../devicetree/bindings/net/dsa/mt7530.txt    | 327 -------------
 2 files changed, 435 insertions(+), 327 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/mediatek.yaml
 delete mode 100644 Documentation/devicetree/bindings/net/dsa/mt7530.txt
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +0 -0
new file mode 100644
index 000000000000..c1724809d34e

Specific name please, so previous (with vendor prefix) was better:
mediatek,mt7530.yaml

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 1

Quoted 2 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +1 -0
@@ -0,0 +1,435 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)

You should CC previous contributors and get their acks on this. You copied here a lot of description.

Quoted 75 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +75 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/dsa/mediatek.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek MT7530 Ethernet switch
+
+maintainers:
+  - Sean Wang <[email protected]>
+  - Landen Chao <[email protected]>
+  - DENG Qingfang <[email protected]>
+
+description: |
+  Port 5 of mt7530 and mt7621 switch is muxed between:
+  1. GMAC5: GMAC5 can interface with another external MAC or PHY.
+  2. PHY of port 0 or port 4: PHY interfaces with an external MAC like 2nd GMAC
+     of the SOC. Used in many setups where port 0/4 becomes the WAN port.
+     Note: On a MT7621 SOC with integrated switch: 2nd GMAC can only connected to
+       GMAC5 when the gpios for RGMII2 (GPIO 22-33) are not used and not
+       connected to external component!
+
+  Port 5 modes/configurations:
+  1. Port 5 is disabled and isolated: An external phy can interface to the 2nd
+     GMAC of the SOC.
+     In the case of a build-in MT7530 switch, port 5 shares the RGMII bus with 2nd
+     GMAC and an optional external phy. Mind the GPIO/pinctl settings of the SOC!
+  2. Port 5 is muxed to PHY of port 0/4: Port 0/4 interfaces with 2nd GMAC.
+     It is a simple MAC to PHY interface, port 5 needs to be setup for xMII mode
+     and RGMII delay.
+  3. Port 5 is muxed to GMAC5 and can interface to an external phy.
+     Port 5 becomes an extra switch port.
+     Only works on platform where external phy TX<->RX lines are swapped.
+     Like in the Ubiquiti ER-X-SFP.
+  4. Port 5 is muxed to GMAC5 and interfaces with the 2nd GAMC as 2nd CPU port.
+     Currently a 2nd CPU port is not supported by DSA code.
+
+  Depending on how the external PHY is wired:
+  1. normal: The PHY can only connect to 2nd GMAC but not to the switch
+  2. swapped: RGMII TX, RX are swapped; external phy interface with the switch as
+     a ethernet port. But can't interface to the 2nd GMAC.
+
+    Based on the DT the port 5 mode is configured.
+
+  Driver tries to lookup the phy-handle of the 2nd GMAC of the master device.
+  When phy-handle matches PHY of port 0 or 4 then port 5 set-up as mode 2.
+  phy-mode must be set, see also example 2 below!
+  * mt7621: phy-mode = "rgmii-txid";
+  * mt7623: phy-mode = "rgmii";
+
+  CPU-Ports need a phy-mode property:
+    Allowed values on mt7530 and mt7621:
+      - "rgmii"
+      - "trgmii"
+    On mt7531:
+      - "1000base-x"
+      - "2500base-x"
+      - "sgmii"
+
+
+properties:
+  compatible:
+    enum:
+      - mediatek,mt7530
+      - mediatek,mt7531
+      - mediatek,mt7621
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  core-supply:
+    description: |
+      Phandle to the regulator node necessary for the core power.

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 86

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +10 -0
+
+  "#gpio-cells":
+    description: |
+      Must be 2 if gpio-controller is defined.
+    const: 2
+
+  gpio-controller:
+    type: boolean
+    description: |
+      Boolean; if defined, MT7530's LED controller will run on

No need to repeat Boolean.

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 95

Quoted 9 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +9 -0
+      GPIO mode.
+
+  "#interrupt-cells":
+    const: 1
+
+  interrupt-controller:
+    type: boolean
+    description: |
+      Boolean; Enables the internal interrupt controller.

Skip description.

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 99

Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +4 -0
+
+  interrupts:
+    description: |
+      Parent interrupt for the interrupt controller.

Skip description.

Documentation/devicetree/bindings/net/dsa/mediatek.yaml

Quoted 12 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +12 -0
+    maxItems: 1
+
+  io-supply:
+    description: |
+      Phandle to the regulator node necessary for the I/O power.
+      See Documentation/devicetree/bindings/regulator/mt6323-regulator.txt
+      for details for the regulator setup on these boards.
+
+  mediatek,mcm:
+    type: boolean
+    description: |
+      Boolean; 

No need to repeat Boolean.

Quoted 13 lines

if defined, indicates that either MT7530 is the part

Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +12 -0
+      on multi-chip module belong to MT7623A has or the remotely standalone
+      chip as the function MT7623N reference board provided for.
+
+  reset-gpios:
+    description: |
+      Should be a gpio specifier for a reset line.
+    maxItems: 1
+
+  reset-names:
+    description: |
+      Should be set to "mcm".
+    const: mcm

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 133

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +10 -0
+
+  resets:
+    description: |
+      Phandle pointing to the system reset controller with
+      line index for the ethsys.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg

What about address/size cells?

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 139

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+
+allOf:
+  - $ref: "dsa.yaml#"
+  - if:
+      required:
+        - mediatek,mcm

Original bindings had this reversed.

Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +4 -0
+    then:
+      required:
+        - resets
+        - reset-names

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 153

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +10 -0
+    else:
+      required:
+        - reset-gpios
+
+  - if:
+      required:
+        - interrupt-controller
+    then:
+      required:
+        - "#interrupt-cells"

This should come from dt schema already...

Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +5 -0
+        - interrupts
+
+  - if:
+      properties:
+        compatible:

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 168

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +10 -0
+          items:
+            - const: mediatek,mt7530
+    then:
+      required:
+        - core-supply
+        - io-supply
+
+
+patternProperties:
+  "^ports$":

It''s not a pattern, so put it under properties, like regular property.

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 176

Quoted 8 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +8 -0
+    type: object
+
+    patternProperties:
+      "^port@[0-9]+$":
+        type: object
+        description: Ethernet switch ports
+
+        $ref: dsa-port.yaml#

This should go to allOf below.

Quoted 14 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +14 -0
+
+        properties:
+          reg:
+            description: |
+              Port address described must be 6 for CPU port and from 0 to 5 for user ports.
+
+        unevaluatedProperties: false
+
+        allOf:
+          - if:
+              properties:
+                label:
+                  items:
+                    - const: cpu

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 200

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +10 -0
+            then:
+              required:
+                - reg
+                - phy-mode
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    mdio0 {

Just mdio

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 211

Quoted 11 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +11 -0
+        #address-cells = <1>;
+        #size-cells = <0>;
+        switch@0 {
+            compatible = "mediatek,mt7530";
+            #address-cells = <1>;
+            #size-cells = <0>;
+            reg = <0>;
+
+            core-supply = <&mt6323_vpa_reg>;
+            io-supply = <&mt6323_vemc3v3_reg>;
+            reset-gpios = <&pio 33 0>;

Use GPIO flag define/constant.

Quoted 37 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +37 -0
+
+            ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                port@0 {
+                    reg = <0>;
+                    label = "lan0";
+                };
+
+                port@1 {
+                    reg = <1>;
+                    label = "lan1";
+                };
+
+                port@2 {
+                    reg = <2>;
+                    label = "lan2";
+                };
+
+                port@3 {
+                    reg = <3>;
+                    label = "lan3";
+                };
+
+                port@4 {
+                    reg = <4>;
+                    label = "wan";
+                };
+
+                port@6 {
+                    reg = <6>;
+                    label = "cpu";
+                    ethernet = <&gmac0>;
+                    phy-mode = "trgmii";
+                    fixed-link {
+                        speed = <1000>;
+                        full-duplex;

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 258

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +10 -0
+                    };
+                };
+            };
+        };
+    };
+
+  - |
+    //Example 2: MT7621: Port 4 is WAN port: 2nd GMAC -> Port 5 -> PHY port 4.
+
+    eth {

s/eth/ethernet/

Quoted 60 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +60 -0
+        #address-cells = <1>;
+        #size-cells = <0>;
+        gmac0: mac@0 {
+            compatible = "mediatek,eth-mac";
+            reg = <0>;
+            phy-mode = "rgmii";
+
+            fixed-link {
+                speed = <1000>;
+                full-duplex;
+                pause;
+            };
+        };
+
+        gmac1: mac@1 {
+            compatible = "mediatek,eth-mac";
+            reg = <1>;
+            phy-mode = "rgmii-txid";
+            phy-handle = <&phy4>;
+        };
+
+        mdio: mdio-bus {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            /* Internal phy */
+            phy4: ethernet-phy@4 {
+                reg = <4>;
+            };
+
+            mt7530: switch@1f {
+                compatible = "mediatek,mt7621";
+                #address-cells = <1>;
+                #size-cells = <0>;
+                reg = <0x1f>;
+                mediatek,mcm;
+
+                resets = <&rstctrl 2>;
+                reset-names = "mcm";
+
+                ports {
+                    #address-cells = <1>;
+                    #size-cells = <0>;
+
+                    port@0 {
+                        reg = <0>;
+                        label = "lan0";
+                    };
+
+                    port@1 {
+                        reg = <1>;
+                        label = "lan1";
+                    };
+
+                    port@2 {
+                        reg = <2>;
+                        label = "lan2";
+                    };
+
+                    port@3 {

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 328

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +10 -0
+                        reg = <3>;
+                        label = "lan3";
+                    };
+
+        /* Commented out. Port 4 is handled by 2nd GMAC.
+                    port@4 {
+                        reg = <4>;
+                        label = "lan4";
+                    };
+        */

Messed up indentation

Quoted 12 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +12 -0
+
+                    port@6 {
+                        reg = <6>;
+                        label = "cpu";
+                        ethernet = <&gmac0>;
+                        phy-mode = "rgmii";
+
+                        fixed-link {
+                            speed = <1000>;
+                            full-duplex;
+                            pause;
+                        };

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 350

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +10 -0
+                    };
+                };
+            };
+        };
+    };
+
+  - |
+    //Example 3: MT7621: Port 5 is connected to external PHY: Port 5 -> external PHY.
+
+    eth {

Also ethernet?

Best regards,
Krzysztof

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#2 lore raw

Hi,

thank you for first review.

Quoted 17 lines

Gesendet: Dienstag, 03. Mai 2022 um 14:05 Uhr
Von: "Krzysztof Kozlowski" <[email protected]>
Betreff: Re: [RFC v1] dt-bindings: net: dsa: convert binding for mediatek switches

Quoted 12 lines · Frank Wunderlich

From: Frank Wunderlich <[email protected]>

Convert txt binding to yaml binding for Mediatek switches.

---
 .../devicetree/bindings/net/dsa/mediatek.yaml | 435 ++++++++++++++++++
 .../devicetree/bindings/net/dsa/mt7530.txt    | 327 -------------
 2 files changed, 435 insertions(+), 327 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/mediatek.yaml
 delete mode 100644 Documentation/devicetree/bindings/net/dsa/mt7530.txt
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml

Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +0 -0
new file mode 100644
index 000000000000..c1724809d34e

Specific name please, so previous (with vendor prefix) was better:
mediatek,mt7530.yaml

ok, named it mediatek only because mt7530 is only one possible chip and driver handles 3 different "variants".

Quoted 5 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 1

Quoted 2 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +1 -0
@@ -0,0 +1,435 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)

You should CC previous contributors and get their acks on this. You copied here a lot of description.

added 3 Persons that made commits to txt before to let them know about this change

and yes, i tried to define at least the phy-mode requirement as yaml-depency, but failed because i cannot match compatible in subnode.

Quoted 79 lines
Quoted 79 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +79 -0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/net/dsa/mediatek.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Mediatek MT7530 Ethernet switch
+
+maintainers:
+  - Sean Wang <[email protected]>
+  - Landen Chao <[email protected]>
+  - DENG Qingfang <[email protected]>
+
+description: |
+  Port 5 of mt7530 and mt7621 switch is muxed between:
+  1. GMAC5: GMAC5 can interface with another external MAC or PHY.
+  2. PHY of port 0 or port 4: PHY interfaces with an external MAC like 2nd GMAC
+     of the SOC. Used in many setups where port 0/4 becomes the WAN port.
+     Note: On a MT7621 SOC with integrated switch: 2nd GMAC can only connected to
+       GMAC5 when the gpios for RGMII2 (GPIO 22-33) are not used and not
+       connected to external component!
+
+  Port 5 modes/configurations:
+  1. Port 5 is disabled and isolated: An external phy can interface to the 2nd
+     GMAC of the SOC.
+     In the case of a build-in MT7530 switch, port 5 shares the RGMII bus with 2nd
+     GMAC and an optional external phy. Mind the GPIO/pinctl settings of the SOC!
+  2. Port 5 is muxed to PHY of port 0/4: Port 0/4 interfaces with 2nd GMAC.
+     It is a simple MAC to PHY interface, port 5 needs to be setup for xMII mode
+     and RGMII delay.
+  3. Port 5 is muxed to GMAC5 and can interface to an external phy.
+     Port 5 becomes an extra switch port.
+     Only works on platform where external phy TX<->RX lines are swapped.
+     Like in the Ubiquiti ER-X-SFP.
+  4. Port 5 is muxed to GMAC5 and interfaces with the 2nd GAMC as 2nd CPU port.
+     Currently a 2nd CPU port is not supported by DSA code.
+
+  Depending on how the external PHY is wired:
+  1. normal: The PHY can only connect to 2nd GMAC but not to the switch
+  2. swapped: RGMII TX, RX are swapped; external phy interface with the switch as
+     a ethernet port. But can't interface to the 2nd GMAC.
+
+    Based on the DT the port 5 mode is configured.
+
+  Driver tries to lookup the phy-handle of the 2nd GMAC of the master device.
+  When phy-handle matches PHY of port 0 or 4 then port 5 set-up as mode 2.
+  phy-mode must be set, see also example 2 below!
+  * mt7621: phy-mode = "rgmii-txid";
+  * mt7623: phy-mode = "rgmii";
+
+  CPU-Ports need a phy-mode property:
+    Allowed values on mt7530 and mt7621:
+      - "rgmii"
+      - "trgmii"
+    On mt7531:
+      - "1000base-x"
+      - "2500base-x"
+      - "sgmii"
+
+
+properties:
+  compatible:
+    enum:
+      - mediatek,mt7530
+      - mediatek,mt7531
+      - mediatek,mt7621
+
+  "#address-cells":
+    const: 1
+
+  "#size-cells":
+    const: 0
+
+  core-supply:
+    description: |
+      Phandle to the regulator node necessary for the core power.
+
+  "#gpio-cells":
+    description: |
+      Must be 2 if gpio-controller is defined.
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 86

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+    const: 2
+
+  gpio-controller:
+    type: boolean
+    description: |
+      Boolean; if defined, MT7530's LED controller will run on

No need to repeat Boolean.

ok, will change

Quoted 11 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 95

Quoted 9 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +9 -0
+      GPIO mode.
+
+  "#interrupt-cells":
+    const: 1
+
+  interrupt-controller:
+    type: boolean
+    description: |
+      Boolean; Enables the internal interrupt controller.

Skip description.

ok

Quoted 6 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 99

Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +4 -0
+
+  interrupts:
+    description: |
+      Parent interrupt for the interrupt controller.

Skip description.

ok

Quoted 6 lines
Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+    maxItems: 1
+
+  io-supply:
+    description: |
+      Phandle to the regulator node necessary for the I/O power.
+      See Documentation/devicetree/bindings/regulator/mt6323-regulator.txt
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+      for details for the regulator setup on these boards.
+
+  mediatek,mcm:
+    type: boolean
+    description: |
+      Boolean;

No need to repeat Boolean.

ack

Quoted 17 lines
Quoted 17 lines

if defined, indicates that either MT7530 is the part

Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +16 -0
+      on multi-chip module belong to MT7623A has or the remotely standalone
+      chip as the function MT7623N reference board provided for.
+
+  reset-gpios:
+    description: |
+      Should be a gpio specifier for a reset line.
+    maxItems: 1
+
+  reset-names:
+    description: |
+      Should be set to "mcm".
+    const: mcm
+
+  resets:
+    description: |
+      Phandle pointing to the system reset controller with
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 133

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+      line index for the ethsys.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg

What about address/size cells?

you're right even if they are const to a value they need to be set

Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 139

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+
+allOf:
+  - $ref: "dsa.yaml#"
+  - if:
+      required:
+        - mediatek,mcm

Original bindings had this reversed.

i know, but i think it is better readable and i will drop the else-part later. Driver supports optional reset ("mediatek,mcm" unset and without reset-gpios) as this is needed if there is a shared reset-line for gmac and switch like on R2 Pro.

i left this as separate commit to be posted later to have a nearly 1:1 conversion here.

Quoted 15 lines
Quoted 4 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +4 -0
+    then:
+      required:
+        - resets
+        - reset-names

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 153

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +10 -0
+    else:
+      required:
+        - reset-gpios
+
+  - if:
+      required:
+        - interrupt-controller
+    then:
+      required:
+        - "#interrupt-cells"
Quoted 1 line

This should come from dt schema already...

so i should drop (complete block for interrupt controller)?

Quoted 9 lines
Quoted 9 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +9 -0
+        - interrupts
+
+  - if:
+      properties:
+        compatible:
+          items:
+            - const: mediatek,mt7530
+    then:
+      required:
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 168

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+        - core-supply
+        - io-supply
+
+
+patternProperties:
+  "^ports$":

It''s not a pattern, so put it under properties, like regular property.

can i then make the subnodes match? so the full block will move above required between "mediatek,mcm" and "reset-gpios"

ports:
type: object

patternProperties:
"^port@[0-9]+$":
type: object
description: Ethernet switch ports

properties:
reg:
description: |
Port address described must be 5 or 6 for CPU port and from 0 to 5 for user ports.

unevaluatedProperties: false

allOf:
- $ref: dsa-port.yaml#
- if:
....

basicly this "ports"-property should be required too, right?

Quoted 10 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 176

Quoted 8 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +8 -0
+    type: object
+
+    patternProperties:
+      "^port@[0-9]+$":
+        type: object
+        description: Ethernet switch ports
+
+        $ref: dsa-port.yaml#

This should go to allOf below.

see above

Quoted 18 lines
Quoted 18 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +18 -0
+
+        properties:
+          reg:
+            description: |
+              Port address described must be 6 for CPU port and from 0 to 5 for user ports.
+
+        unevaluatedProperties: false
+
+        allOf:
+          - if:
+              properties:
+                label:
+                  items:
+                    - const: cpu
+            then:
+              required:
+                - reg
+                - phy-mode
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 200

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    mdio0 {

Just mdio

ok

Quoted 12 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 211

Quoted 11 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +11 -0
+        #address-cells = <1>;
+        #size-cells = <0>;
+        switch@0 {
+            compatible = "mediatek,mt7530";
+            #address-cells = <1>;
+            #size-cells = <0>;
+            reg = <0>;
+
+            core-supply = <&mt6323_vpa_reg>;
+            io-supply = <&mt6323_vemc3v3_reg>;
+            reset-gpios = <&pio 33 0>;
Quoted 1 line

Use GPIO flag define/constant.

this example seems to be taken from bpi-r2 (i had taken it from the txt). In dts for this board there are no constants too.

i guess
include/dt-bindings/gpio/gpio.h:14:#define GPIO_ACTIVE_HIGH 0

for 33 there seem no constant..all other references to pio node are with numbers too and there seem no binding header defining the gpio pins (only functions in include/dt-bindings/pinctrl/mt7623-pinfunc.h)

Quoted 41 lines
Quoted 41 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +41 -0
+
+            ports {
+                #address-cells = <1>;
+                #size-cells = <0>;
+                port@0 {
+                    reg = <0>;
+                    label = "lan0";
+                };
+
+                port@1 {
+                    reg = <1>;
+                    label = "lan1";
+                };
+
+                port@2 {
+                    reg = <2>;
+                    label = "lan2";
+                };
+
+                port@3 {
+                    reg = <3>;
+                    label = "lan3";
+                };
+
+                port@4 {
+                    reg = <4>;
+                    label = "wan";
+                };
+
+                port@6 {
+                    reg = <6>;
+                    label = "cpu";
+                    ethernet = <&gmac0>;
+                    phy-mode = "trgmii";
+                    fixed-link {
+                        speed = <1000>;
+                        full-duplex;
+                    };
+                };
+            };
+        };
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 258

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+    };
+
+  - |
+    //Example 2: MT7621: Port 4 is WAN port: 2nd GMAC -> Port 5 -> PHY port 4.
+
+    eth {

s/eth/ethernet/

ok

Quoted 64 lines
Quoted 64 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +64 -0
+        #address-cells = <1>;
+        #size-cells = <0>;
+        gmac0: mac@0 {
+            compatible = "mediatek,eth-mac";
+            reg = <0>;
+            phy-mode = "rgmii";
+
+            fixed-link {
+                speed = <1000>;
+                full-duplex;
+                pause;
+            };
+        };
+
+        gmac1: mac@1 {
+            compatible = "mediatek,eth-mac";
+            reg = <1>;
+            phy-mode = "rgmii-txid";
+            phy-handle = <&phy4>;
+        };
+
+        mdio: mdio-bus {
+            #address-cells = <1>;
+            #size-cells = <0>;
+
+            /* Internal phy */
+            phy4: ethernet-phy@4 {
+                reg = <4>;
+            };
+
+            mt7530: switch@1f {
+                compatible = "mediatek,mt7621";
+                #address-cells = <1>;
+                #size-cells = <0>;
+                reg = <0x1f>;
+                mediatek,mcm;
+
+                resets = <&rstctrl 2>;
+                reset-names = "mcm";
+
+                ports {
+                    #address-cells = <1>;
+                    #size-cells = <0>;
+
+                    port@0 {
+                        reg = <0>;
+                        label = "lan0";
+                    };
+
+                    port@1 {
+                        reg = <1>;
+                        label = "lan1";
+                    };
+
+                    port@2 {
+                        reg = <2>;
+                        label = "lan2";
+                    };
+
+                    port@3 {
+                        reg = <3>;
+                        label = "lan3";
+                    };
+
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 328

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+        /* Commented out. Port 4 is handled by 2nd GMAC.
+                    port@4 {
+                        reg = <4>;
+                        label = "lan4";
+                    };
+        */

Messed up indentation

will fix it

Quoted 16 lines
Quoted 16 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +16 -0
+
+                    port@6 {
+                        reg = <6>;
+                        label = "cpu";
+                        ethernet = <&gmac0>;
+                        phy-mode = "rgmii";
+
+                        fixed-link {
+                            speed = <1000>;
+                            full-duplex;
+                            pause;
+                        };
+                    };
+                };
+            };
+        };
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 350

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+    };
+
+  - |
+    //Example 3: MT7621: Port 5 is connected to external PHY: Port 5 -> external PHY.
+
+    eth {

Also ethernet?

will do

Quoted 2 lines

Best regards,
Krzysztof

regards Frank

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#3 lore raw
Quoted 38 lines · Frank Wunderlich

Hi,

thank you for first review.

Quoted 17 lines

Gesendet: Dienstag, 03. Mai 2022 um 14:05 Uhr
Von: "Krzysztof Kozlowski" <[email protected]>
Betreff: Re: [RFC v1] dt-bindings: net: dsa: convert binding for mediatek switches

Quoted 12 lines · Frank Wunderlich

From: Frank Wunderlich <[email protected]>

Convert txt binding to yaml binding for Mediatek switches.

---
 .../devicetree/bindings/net/dsa/mediatek.yaml | 435 ++++++++++++++++++
 .../devicetree/bindings/net/dsa/mt7530.txt    | 327 -------------
 2 files changed, 435 insertions(+), 327 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/mediatek.yaml
 delete mode 100644 Documentation/devicetree/bindings/net/dsa/mt7530.txt
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml

Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +0 -0
new file mode 100644
index 000000000000..c1724809d34e

Specific name please, so previous (with vendor prefix) was better:
mediatek,mt7530.yaml

ok, named it mediatek only because mt7530 is only one possible chip and driver handles 3 different "variants".

Quoted 5 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 1

Quoted 2 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +1 -0
@@ -0,0 +1,435 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)

You should CC previous contributors and get their acks on this. You copied here a lot of description.

Quoted 4 lines

added 3 Persons that made commits to txt before to let them know about this change

and yes, i tried to define at least the phy-mode requirement as yaml-depency, but failed because i cannot match compatible in subnode.

I don't remember such syntax.

(...)

Quoted 38 lines
Quoted 18 lines
Quoted 18 lines

if defined, indicates that either MT7530 is the part

Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +16 -0
+      on multi-chip module belong to MT7623A has or the remotely standalone
+      chip as the function MT7623N reference board provided for.
+
+  reset-gpios:
+    description: |
+      Should be a gpio specifier for a reset line.
+    maxItems: 1
+
+  reset-names:
+    description: |
+      Should be set to "mcm".
+    const: mcm
+
+  resets:
+    description: |
+      Phandle pointing to the system reset controller with
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 133

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+      line index for the ethsys.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg

What about address/size cells?

you're right even if they are const to a value they need to be set

Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 139

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+
+allOf:
+  - $ref: "dsa.yaml#"
+  - if:
+      required:
+        - mediatek,mcm

Original bindings had this reversed.

Quoted 5 lines

i know, but i think it is better readable and i will drop the else-part later. Driver supports optional reset ("mediatek,mcm" unset and without reset-gpios) as this is needed if there is a shared reset-line for gmac and switch like on R2 Pro.

i left this as separate commit to be posted later to have a nearly 1:1 conversion here.

Ah, I missed that actually your syntax is better. No need to reverse/negate and the changes do not have to be strict 1:1.

Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +14 -0
+    then:
+      required:
+        - resets
+        - reset-names
+    else:
+      required:
+        - reset-gpios
+
+  - if:
+      required:
+        - interrupt-controller
+    then:
+      required:
+        - "#interrupt-cells"
Quoted 3 lines
Quoted 1 line

This should come from dt schema already...

so i should drop (complete block for interrupt controller)?

The interrupts you need. What I mean, you can skip requirement of cells.

Quoted 19 lines
Quoted 10 lines
Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +9 -0
+        - interrupts
+
+  - if:
+      properties:
+        compatible:
+          items:
+            - const: mediatek,mt7530
+    then:
+      required:
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 168

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+        - core-supply
+        - io-supply
+
+
+patternProperties:
+  "^ports$":

It''s not a pattern, so put it under properties, like regular property.

Quoted 1 line

can i then make the subnodes match? so the full block will move above required between "mediatek,mcm" and "reset-gpios"

Yes, subnodes stay with patternProperties.

Quoted 14 lines

ports:
type: object

patternProperties:
"^port@[0-9]+$":
type: object
description: Ethernet switch ports

properties:
reg:
description: |
Port address described must be 5 or 6 for CPU port and from 0 to 5 for user ports.

Quoted 8 lines

unevaluatedProperties: false

allOf:
- $ref: dsa-port.yaml#
- if:
....

basicly this "ports"-property should be required too, right?

Previous binding did not enforce it, I think, but it is reasonable to require ports.

Quoted 58 lines
Quoted 12 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 176

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +8 -0
+    type: object
+
+    patternProperties:
+      "^port@[0-9]+$":
+        type: object
+        description: Ethernet switch ports
+
+        $ref: dsa-port.yaml#

This should go to allOf below.

see above

Quoted 18 lines
Quoted 18 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +18 -0
+
+        properties:
+          reg:
+            description: |
+              Port address described must be 6 for CPU port and from 0 to 5 for user ports.
+
+        unevaluatedProperties: false
+
+        allOf:
+          - if:
+              properties:
+                label:
+                  items:
+                    - const: cpu
+            then:
+              required:
+                - reg
+                - phy-mode
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 200

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    mdio0 {

Just mdio

ok

Quoted 12 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 211

Quoted 11 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +11 -0
+        #address-cells = <1>;
+        #size-cells = <0>;
+        switch@0 {
+            compatible = "mediatek,mt7530";
+            #address-cells = <1>;
+            #size-cells = <0>;
+            reg = <0>;
+
+            core-supply = <&mt6323_vpa_reg>;
+            io-supply = <&mt6323_vemc3v3_reg>;
+            reset-gpios = <&pio 33 0>;
Quoted 1 line

Use GPIO flag define/constant.

Quoted 8 lines

this example seems to be taken from bpi-r2 (i had taken it from the txt). In dts for this board there are no constants too.

i guess
include/dt-bindings/gpio/gpio.h:14:#define GPIO_ACTIVE_HIGH 0

for 33 there seem no constant..all other references to pio node are with numbers too and there seem no binding header defining the gpio pins (only functions in include/dt-bindings/pinctrl/mt7623-pinfunc.h)

ok, then my comment

Best regards,
Krzysztof

#4 lore raw

Hi,

Quoted 43 lines

Gesendet: Dienstag, 03. Mai 2022 um 16:40 Uhr
Von: "Krzysztof Kozlowski" <[email protected]>
Betreff: Re: Aw: Re: [RFC v1] dt-bindings: net: dsa: convert binding for mediatek switches

Quoted 38 lines · Frank Wunderlich

Hi,

thank you for first review.

Quoted 17 lines

Gesendet: Dienstag, 03. Mai 2022 um 14:05 Uhr
Von: "Krzysztof Kozlowski" <[email protected]>
Betreff: Re: [RFC v1] dt-bindings: net: dsa: convert binding for mediatek switches

Quoted 12 lines · Frank Wunderlich

From: Frank Wunderlich <[email protected]>

Convert txt binding to yaml binding for Mediatek switches.

---
 .../devicetree/bindings/net/dsa/mediatek.yaml | 435 ++++++++++++++++++
 .../devicetree/bindings/net/dsa/mt7530.txt    | 327 -------------
 2 files changed, 435 insertions(+), 327 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/net/dsa/mediatek.yaml
 delete mode 100644 Documentation/devicetree/bindings/net/dsa/mt7530.txt
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml

Quoted 5 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +0 -0
new file mode 100644
index 000000000000..c1724809d34e

Specific name please, so previous (with vendor prefix) was better:
mediatek,mt7530.yaml

ok, named it mediatek only because mt7530 is only one possible chip and driver handles 3 different "variants".

Quoted 5 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 1

Quoted 2 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +1 -0
@@ -0,0 +1,435 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)

You should CC previous contributors and get their acks on this. You copied here a lot of description.

Quoted 8 lines
Quoted 4 lines

added 3 Persons that made commits to txt before to let them know about this change

and yes, i tried to define at least the phy-mode requirement as yaml-depency, but failed because i cannot match compatible in subnode.

I don't remember such syntax.

(...)

have not posted this version as it was failing in dtbs_check, this was how i tried:

https://github.com/frank-w/BPI-R2-4.14/blob/8f2033eb6fcae273580263c3f0b31f0d48821740/Documentation/devicetree/bindings/net/dsa/mediatek.yaml#L177

Quoted 37 lines
Quoted 37 lines
Quoted 17 lines
Quoted 17 lines

if defined, indicates that either MT7530 is the part

Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +16 -0
+      on multi-chip module belong to MT7623A has or the remotely standalone
+      chip as the function MT7623N reference board provided for.
+
+  reset-gpios:
+    description: |
+      Should be a gpio specifier for a reset line.
+    maxItems: 1
+
+  reset-names:
+    description: |
+      Should be set to "mcm".
+    const: mcm
+
+  resets:
+    description: |
+      Phandle pointing to the system reset controller with
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 133

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+      line index for the ethsys.
+    maxItems: 1
+
+required:
+  - compatible
+  - reg

What about address/size cells?

you're right even if they are const to a value they need to be set

Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 139

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+
+allOf:
+  - $ref: "dsa.yaml#"
+  - if:
+      required:
+        - mediatek,mcm

Original bindings had this reversed.

Quoted 8 lines
Quoted 5 lines

i know, but i think it is better readable and i will drop the else-part later. Driver supports optional reset ("mediatek,mcm" unset and without reset-gpios) as this is needed if there is a shared reset-line for gmac and switch like on R2 Pro.

i left this as separate commit to be posted later to have a nearly 1:1 conversion here.

Ah, I missed that actually your syntax is better. No need to reverse/negate and the changes do not have to be strict 1:1.

yes, but a conversion implies same meaning, so changing things later ;)

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
Quoted 14 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +14 -0
+    then:
+      required:
+        - resets
+        - reset-names
+    else:
+      required:
+        - reset-gpios
+
+  - if:
+      required:
+        - interrupt-controller
+    then:
+      required:
+        - "#interrupt-cells"
Quoted 5 lines
Quoted 3 lines
Quoted 1 line

This should come from dt schema already...

so i should drop (complete block for interrupt controller)?

The interrupts you need. What I mean, you can skip requirement of cells.

ok, i drop only the #interrupt-cells

Quoted 43 lines
Quoted 18 lines
Quoted 9 lines
Quoted 9 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +9 -0
+        - interrupts
+
+  - if:
+      properties:
+        compatible:
+          items:
+            - const: mediatek,mt7530
+    then:
+      required:
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 168

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+        - core-supply
+        - io-supply
+
+
+patternProperties:
+  "^ports$":

It''s not a pattern, so put it under properties, like regular property.

Quoted 1 line

can i then make the subnodes match? so the full block will move above required between "mediatek,mcm" and "reset-gpios"

Yes, subnodes stay with patternProperties.

Quoted 21 lines

ports:
type: object

patternProperties:
"^port@[0-9]+$":
type: object
description: Ethernet switch ports

properties:
reg:
description: |
Port address described must be 5 or 6 for CPU port and from 0 to 5 for user ports.

unevaluatedProperties: false

allOf:
- $ref: dsa-port.yaml#
- if:
....

Quoted 4 lines
Quoted 1 line

basicly this "ports"-property should be required too, right?

Previous binding did not enforce it, I think, but it is reasonable to require ports.

basicly it is required in dsa.yaml, so it will be redundant here

https://elixir.bootlin.com/linux/v5.18-rc5/source/Documentation/devicetree/bindings/net/dsa/dsa.yaml#L55

this defines it as pattern "^(ethernet-)?ports$" and should be processed by dsa-core. so maybe changing it to same pattern instead of moving up as normal property?

Quoted 59 lines
Quoted 59 lines
Quoted 10 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 176

Quoted 8 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +8 -0
+    type: object
+
+    patternProperties:
+      "^port@[0-9]+$":
+        type: object
+        description: Ethernet switch ports
+
+        $ref: dsa-port.yaml#

This should go to allOf below.

see above

Quoted 18 lines
Quoted 18 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +18 -0
+
+        properties:
+          reg:
+            description: |
+              Port address described must be 6 for CPU port and from 0 to 5 for user ports.
+
+        unevaluatedProperties: false
+
+        allOf:
+          - if:
+              properties:
+                label:
+                  items:
+                    - const: cpu
+            then:
+              required:
+                - reg
+                - phy-mode
Quoted 8 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 200

Quoted 6 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +6 -0
+
+unevaluatedProperties: false
+
+examples:
+  - |
+    mdio0 {

Just mdio

ok

Quoted 12 lines

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 211

Quoted 11 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +11 -0
+        #address-cells = <1>;
+        #size-cells = <0>;
+        switch@0 {
+            compatible = "mediatek,mt7530";
+            #address-cells = <1>;
+            #size-cells = <0>;
+            reg = <0>;
+
+            core-supply = <&mt6323_vpa_reg>;
+            io-supply = <&mt6323_vemc3v3_reg>;
+            reset-gpios = <&pio 33 0>;
Quoted 1 line

Use GPIO flag define/constant.

this example seems to be taken from bpi-r2 (i had taken it from the txt). In dts for this board there are no constants too.

Quoted 7 lines
Quoted 5 lines

i guess
include/dt-bindings/gpio/gpio.h:14:#define GPIO_ACTIVE_HIGH 0

for 33 there seem no constant..all other references to pio node are with numbers too and there seem no binding header defining the gpio pins (only functions in include/dt-bindings/pinctrl/mt7623-pinfunc.h)

ok, then my comment

you mean adding a comment to the example that GPIO-flags/constants should be used instead of magic numbers?

Quoted 2 lines

Best regards,
Krzysztof

this is how it looks like without the port-property-change:
https://github.com/frank-w/BPI-R2-4.14/blob/5.18-mt7531-mainline/Documentation/devicetree/bindings/net/dsa/mediatek,mt7530.yaml

regards Frank

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#5 lore raw
Quoted 4 lines · Frank Wunderlich

have not posted this version as it was failing in dtbs_check, this was how i tried:

https://github.com/frank-w/BPI-R2-4.14/blob/8f2033eb6fcae273580263c3f0b31f0d48821740/Documentation/devicetree/bindings/net/dsa/mediatek.yaml#L177

You have mixed up indentation of the second if (and missing -).

(...)

Quoted 11 lines
Quoted 5 lines
Quoted 2 lines

basicly this "ports"-property should be required too, right?

Previous binding did not enforce it, I think, but it is reasonable to require ports.

basicly it is required in dsa.yaml, so it will be redundant here

https://elixir.bootlin.com/linux/v5.18-rc5/source/Documentation/devicetree/bindings/net/dsa/dsa.yaml#L55

this defines it as pattern "^(ethernet-)?ports$" and should be processed by dsa-core. so maybe changing it to same pattern instead of moving up as normal property?

Just keep what is already used in existing DTS.

Quoted 6 lines
Quoted 4 lines
Quoted 2 lines

for 33 there seem no constant..all other references to pio node are with numbers too and there seem no binding header defining the gpio pins (only functions in include/dt-bindings/pinctrl/mt7623-pinfunc.h)

ok, then my comment

you mean adding a comment to the example that GPIO-flags/constants should be used instead of magic numbers?

I think something was cut from my reply. I wanted to say:
"ok, then my comment can be skipped"

But I think your check was not correct. I looked at bpi-r2 DTS (mt7623n) and pio controller uses GPIO flags.

Best regards,
Krzysztof

#6 lore raw

m 4. Mai 2022 08:51:41 MESZ schrieb Krzysztof Kozlowski <[email protected]>:

Quoted 9 lines · Frank Wunderlich
Quoted 2 lines

have not posted this version as it was failing in dtbs_check, this

was how i tried:

Quoted 2 lines

https://github.com/frank-w/BPI-R2-4.14/blob/8f2033eb6fcae273580263c3f0b31f0d48821740/Documentation/devicetree/bindings/net/dsa/mediatek.yaml#L177

You have mixed up indentation of the second if (and missing -).

The "compatible if" should be a child of the "if" above,because phy-mode property only exists for cpu-port. I can try with additional "-" (but i guess this is only needed for allOf)

Rob told me that i cannot check compatible in subnode and this check will be always true...just like my experience.
I can only make the compatible check at top-level and then need to define substructure based on this (so define structure twice). He suggested me adding this to description for now.

Imho this can be added later if really needed...did not found any example checking for compatible in a subnode. All were in top level. Afair these properties are handled by dsa-core/phylink and driver only compares constants set there.

Quoted 12 lines

(...)

Quoted 4 lines
Quoted 4 lines
Quoted 2 lines

basicly this "ports"-property should be required too, right?

Previous binding did not enforce it, I think, but it is reasonable

to

Quoted 5 lines
Quoted 1 line

require ports.

basicly it is required in dsa.yaml, so it will be redundant here

Quoted 7 lines

https://elixir.bootlin.com/linux/v5.18-rc5/source/Documentation/devicetree/bindings/net/dsa/dsa.yaml#L55

Quoted 2 lines

this defines it as pattern "^(ethernet-)?ports$" and should be

processed by dsa-core. so maybe changing it to same pattern instead of moving up as normal property?

Just keep what is already used in existing DTS.

Currently only "ports" is used...so i will change it to "normal" property.

Quoted 5 lines
Quoted 1 line
Quoted 1 line
Quoted 1 line

for 33 there seem no constant..all other references to pio node are

with numbers too and there seem no binding

Quoted 1 line
Quoted 1 line
Quoted 1 line

header defining the gpio pins (only functions in

include/dt-bindings/pinctrl/mt7623-pinfunc.h)

Quoted 1 line
Quoted 1 line
Quoted 7 lines
Quoted 3 lines
Quoted 1 line

ok, then my comment

you mean adding a comment to the example that GPIO-flags/constants

should be used instead of magic numbers?

I think something was cut from my reply. I wanted to say:
"ok, then my comment can be skipped"

Ok

Quoted 3 lines

But I think your check was not correct. I looked at bpi-r2 DTS (mt7623n)
and pio controller uses GPIO flags.

I see only same as in the example

https://elixir.bootlin.com/linux/latest/source/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts#L196

Quoted 2 lines

Best regards,
Krzysztof

regards Frank

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek

#7 lore raw
Quoted 9 lines · Frank Wunderlich

m 4. Mai 2022 08:51:41 MESZ schrieb Krzysztof Kozlowski <[email protected]>:

Quoted 8 lines · Frank Wunderlich
Quoted 2 lines

have not posted this version as it was failing in dtbs_check, this

was how i tried:

Quoted 2 lines

https://github.com/frank-w/BPI-R2-4.14/blob/8f2033eb6fcae273580263c3f0b31f0d48821740/Documentation/devicetree/bindings/net/dsa/mediatek.yaml#L177

Quoted 8 lines
Quoted 1 line

You have mixed up indentation of the second if (and missing -).

The "compatible if" should be a child of the "if" above,because phy-mode property only exists for cpu-port. I can try with additional "-" (but i guess this is only needed for allOf)

Rob told me that i cannot check compatible in subnode and this check will be always true...just like my experience.
I can only make the compatible check at top-level and then need to define substructure based on this (so define structure twice). He suggested me adding this to description for now.

Imho this can be added later if really needed...did not found any example checking for compatible in a subnode. All were in top level. Afair these properties are handled by dsa-core/phylink and driver only compares constants set there.

Sure.

Quoted 8 lines
Quoted 4 lines

But I think your check was not correct. I looked at bpi-r2 DTS (mt7623n)
and pio controller uses GPIO flags.

I see only same as in the example

https://elixir.bootlin.com/linux/latest/source/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts#L196

I meant other consumers of pio GPIOs:
https://elixir.bootlin.com/linux/latest/source/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts#L97

https://elixir.bootlin.com/linux/latest/source/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts#L320

Best regards,
Krzysztof

#8 lore raw
In reply to Krzysztof Kozlowski

Hi

Quoted 8 lines

Gesendet: Dienstag, 03. Mai 2022 um 14:05 Uhr
Von: "Krzysztof Kozlowski" <[email protected]>

Documentation/devicetree/bindings/net/dsa/mediatek.yaml line 133

Quoted 3 lines
Documentation/devicetree/bindings/net/dsa/mediatek.yaml new file +3 -0
+required:
+  - compatible
+  - reg

What about address/size cells?

in current devicetrees the address-cells/size-cells are set above the switch on mdio-bus so i would not add these to required for switch.

https://elixir.bootlin.com/linux/latest/source/arch/arm/boot/dts/mt7623n-bananapi-bpi-r2.dts#L190

regards Frank

_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek