Skip to contentSkip to conversation

net: dsa: microchip: enable setting rmii reference

PATCH Superseded Ante Knezic 3 participants 5 messages Nov 27, 2023 – Nov 28, 2023

Subsystems (5)

v6 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v6 cover net: dsa: microchip: enable setting rmii reference

KSZ88X3 devices can select between internal and external RMII reference clock. This patch series introduces new device tree property for setting reference clock to internal.

---
V6:
- use dev->cpu_port and dsa_to_port() instead of parsing the device tree.
V5:
- move rmii-clk-internal to be a port device tree property.
V4:
- remove rmii_clk_internal from ksz_device, as its not needed any more
- move rmii clk config as well as ksz8795_cpu_interface_select to ksz8_config_cpu_port
V3:
- move ksz_cfg from global switch config to port config as suggested by Vladimir Oltean
- reverse patch order as suggested by Vladimir Oltean
- adapt dt schema as suggested by Conor Dooley
V2:
- don't rely on default register settings - enforce set/clear property as suggested by Andrew Lunn
- enforce dt schema as suggested by Conor Dooley

Ante Knezic (2):
dt-bindings: net: microchip,ksz: document microchip,rmii-clk-internal
net: dsa: microchip: add property to select internal RMII reference
clock

 .../devicetree/bindings/net/dsa/microchip,ksz.yaml | 38 +++++++++++++++++++++-
 drivers/net/dsa/microchip/ksz8795.c                | 29 +++++++++++++----
 drivers/net/dsa/microchip/ksz8795_reg.h            |  3 ++
 3 files changed, 63 insertions(+), 7 deletions(-)
Signature · 1 line
2.11.0
#1 lore raw

PATCH v6 1/2 dt-bindings: net: microchip,ksz: document microchip,rmii-clk-internal

Add documentation for selecting reference rmii clock on KSZ88X3 devices

---
 .../devicetree/bindings/net/dsa/microchip,ksz.yaml | 38 +++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +37 -1
index b3029c64d0d5..6fd482f2656b 100644
@@ -11,7 +11,6 @@ maintainers:
   - Woojung Huh <[email protected]>
 
 allOf:
-  - $ref: dsa.yaml#/$defs/ethernet-ports
   - $ref: /schemas/spi/spi-peripheral-props.yaml#
 
 properties:
@@ -78,6 +77,43 @@ required:
   - compatible
   - reg
 
+if:
+  not:
+    properties:
+      compatible:
+        enum:
+          - microchip,ksz8863
+          - microchip,ksz8873
+then:
+  $ref: dsa.yaml#/$defs/ethernet-ports
+else:
+  patternProperties:
+    "^(ethernet-)?ports$":
+      patternProperties:
+        "^(ethernet-)?port@[0-2]$":
+          $ref: dsa-port.yaml#
+          properties:
+            microchip,rmii-clk-internal:
+              $ref: /schemas/types.yaml#/definitions/flag
+              description:
+                When ksz88x3 is acting as clock provier (via REFCLKO) it
+                can select between internal and external RMII reference
+                clock. Internal reference clock means that the clock for
+                the RMII of ksz88x3 is provided by the ksz88x3 internally
+                and the REFCLKI pin is unconnected. For the external
+                reference clock, the clock needs to be fed back to ksz88x3
+                via REFCLKI.
+                If microchip,rmii-clk-internal is set, ksz88x3 will provide
+                rmii reference clock internally, otherwise reference clock
+                should be provided externally.
+          if:
+            not:
+              required: [ ethernet ]
+          then:
+            properties:
+              microchip,rmii-clk-internal: false
+          unevaluatedProperties: false
+
 unevaluatedProperties: false
 
 examples:
Signature · 1 line
2.11.0
maintainer
#2 lore raw

Re: [PATCH net-next v6 1/2] dt-bindings: net: microchip,ksz: document microchip,rmii-clk-internal

Quoted 6 lines · Ante Knezic

Add documentation for selecting reference rmii clock on KSZ88X3 devices

---
 .../devicetree/bindings/net/dsa/microchip,ksz.yaml | 38 +++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

You forgot Conor's ack.

Quoted 43 lines
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +26 -1
index b3029c64d0d5..6fd482f2656b 100644
@@ -11,7 +11,6 @@ maintainers:
   - Woojung Huh <[email protected]>
 
 allOf:
-  - $ref: dsa.yaml#/$defs/ethernet-ports
   - $ref: /schemas/spi/spi-peripheral-props.yaml#
 
 properties:
@@ -78,6 +77,43 @@ required:
   - compatible
   - reg
 
+if:
+  not:
+    properties:
+      compatible:
+        enum:
+          - microchip,ksz8863
+          - microchip,ksz8873
+then:
+  $ref: dsa.yaml#/$defs/ethernet-ports
+else:
+  patternProperties:
+    "^(ethernet-)?ports$":
+      patternProperties:
+        "^(ethernet-)?port@[0-2]$":
+          $ref: dsa-port.yaml#
+          properties:
+            microchip,rmii-clk-internal:
+              $ref: /schemas/types.yaml#/definitions/flag
+              description:
+                When ksz88x3 is acting as clock provier (via REFCLKO) it
+                can select between internal and external RMII reference
+                clock. Internal reference clock means that the clock for
+                the RMII of ksz88x3 is provided by the ksz88x3 internally
+                and the REFCLKI pin is unconnected. For the external
+                reference clock, the clock needs to be fed back to ksz88x3
+                via REFCLKI.

Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml required: · line 115

Quoted 10 lines
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +9 -0
+                If microchip,rmii-clk-internal is set, ksz88x3 will provide
+                rmii reference clock internally, otherwise reference clock
+                should be provided externally.
 
+          if:
+            not:
+              required: [ ethernet ]
+          then:
+            properties:
+              microchip,rmii-clk-internal: false

This can be expressed as:

dependencies:
microchip,rmii-clk-internal: [ethernet]

Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml required: · line 115

Quoted 1 line
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +1 -0
+          unevaluatedProperties: false

Move this under the $ref.

Quoted 7 lines
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +1 -0
+
 unevaluatedProperties: false
 

examples:

Signature · 1 line
2.11.0
#3 lore raw

Re: [PATCH net-next v6 1/2] dt-bindings: net: microchip,ksz: document microchip,rmii-clk-internal

Quoted 9 lines · Rob Herring
Quoted 6 lines · Ante Knezic

Add documentation for selecting reference rmii clock on KSZ88X3 devices

---
 .../devicetree/bindings/net/dsa/microchip,ksz.yaml | 38 +++++++++++++++++++++-
 1 file changed, 37 insertions(+), 1 deletion(-)

You forgot Conor's ack.

I think that's for the better, v5 and v6 look to have changed a decent amount from what I acked in v4.

#4 lore raw

PATCH v6 2/2 net: dsa: microchip: add property to select internal RMII reference clock

In reply to Ante Knezic

Microchip KSZ8863/KSZ8873 have the ability to select between internal and external RMII reference clock. By default, reference clock needs to be provided via REFCLKI_3 pin. If required, device can be setup to provide RMII clock internally so that REFCLKI_3 pin can be left unconnected.
Add a new "microchip,rmii-clk-internal" property which will set RMII clock reference to internal. If property is not set, reference clock needs to be provided externally.

While at it, move the ksz8795_cpu_interface_select() to ksz8_config_cpu_port() to get a cleaner call path for cpu port.

---
 drivers/net/dsa/microchip/ksz8795.c     | 29 +++++++++++++++++++++++------
 drivers/net/dsa/microchip/ksz8795_reg.h |  3 +++
 2 files changed, 26 insertions(+), 6 deletions(-)
drivers/net/dsa/microchip/ksz8795.c +23 -6
index 4bf4d67557dc..9fd2be9c4022 100644
@@ -1358,6 +1358,9 @@ static void ksz8795_cpu_interface_select(struct ksz_device *dev, int port)
 {
 	struct ksz_port *p = &dev->ports[port];
 
+	if (!ksz_is_ksz87xx(dev))
+		return;
+
 	if (!p->interface && dev->compat_interface) {
 		dev_warn(dev->dev,
 			 "Using legacy switch \"phy-mode\" property, because it is missing on port %d node. "
@@ -1391,18 +1394,29 @@ void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port)
 	/* enable 802.1p priority */
 	ksz_port_cfg(dev, port, P_PRIO_CTRL, PORT_802_1P_ENABLE, true);
 
-	if (cpu_port) {
-		if (!ksz_is_ksz88x3(dev))
-			ksz8795_cpu_interface_select(dev, port);
-
+	if (cpu_port)
 		member = dsa_user_ports(ds);
-	} else {
+	else
 		member = BIT(dsa_upstream_port(ds, port));
-	}
 
 	ksz8_cfg_port_member(dev, port, member);
 }
 
+static void ksz88x3_config_rmii_clk(struct ksz_device *dev)
+{
+	struct dsa_port *cpu_dp = dsa_to_port(dev->ds, dev->cpu_port);
+	bool rmii_clk_internal;
+
+	if (!ksz_is_ksz88x3(dev))
+		return;
+
+	rmii_clk_internal = of_property_read_bool(cpu_dp->dn,
+						  "microchip,rmii-clk-internal");
+
+	ksz_cfg(dev, KSZ88X3_REG_FVID_AND_HOST_MODE,
+		KSZ88X3_PORT3_RMII_CLK_INTERNAL, rmii_clk_internal);
+}
+
 void ksz8_config_cpu_port(struct dsa_switch *ds)
 {
 	struct ksz_device *dev = ds->priv;
@@ -1419,6 +1433,9 @@ void ksz8_config_cpu_port(struct dsa_switch *ds)
 
 	ksz8_port_setup(dev, dev->cpu_port, true);
 
+	ksz8795_cpu_interface_select(dev, dev->cpu_port);
+	ksz88x3_config_rmii_clk(dev);
+
 	for (i = 0; i < dev->phy_port_cnt; i++) {
 		ksz_port_stp_state_set(ds, i, BR_STATE_DISABLED);
 	}
drivers/net/dsa/microchip/ksz8795_reg.h +3 -0
index 3c9dae53e4d8..beca974e0171 100644
@@ -22,6 +22,9 @@
 #define KSZ8863_GLOBAL_SOFTWARE_RESET	BIT(4)
 #define KSZ8863_PCS_RESET		BIT(0)
 
+#define KSZ88X3_REG_FVID_AND_HOST_MODE  0xC6
+#define KSZ88X3_PORT3_RMII_CLK_INTERNAL BIT(3)
+
 #define REG_SW_CTRL_0			0x02
 
 #define SW_NEW_BACKOFF			BIT(7)
Signature · 1 line
2.11.0