Skip to contentSkip to conversation

net: dsa: microchip: enable setting rmii reference

PATCH Superseded Ante Knezic 3 participants 11 messages Oct 18, 2023 – Oct 20, 2023

Subsystems (5)

v3 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

v3 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.

---
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      | 17 +++++++++++++++++
 drivers/net/dsa/microchip/ksz8795.c                     | 10 +++++++++-
 drivers/net/dsa/microchip/ksz8795_reg.h                 |  3 +++
 drivers/net/dsa/microchip/ksz_common.h                  |  1 +
 4 files changed, 30 insertions(+), 1 deletion(-)
Signature · 1 line
2.11.0
#2 lore raw

PATCH v3 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.

---
 drivers/net/dsa/microchip/ksz8795.c     | 10 +++++++++-
 drivers/net/dsa/microchip/ksz8795_reg.h |  3 +++
 drivers/net/dsa/microchip/ksz_common.h  |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/ksz8795.c +9 -1
index 91aba470fb2f..b50ad9552c65 100644
@@ -1312,8 +1312,16 @@ void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port)
 	ksz_port_cfg(dev, port, P_PRIO_CTRL, PORT_802_1P_ENABLE, true);
 
 	if (cpu_port) {
-		if (!ksz_is_ksz88x3(dev))
+		if (!ksz_is_ksz88x3(dev)) {
 			ksz8795_cpu_interface_select(dev, port);
+		} else {
+			dev->rmii_clk_internal = of_property_read_bool(dev->dev->of_node,
+								       "microchip,rmii-clk-internal");
+
+			ksz_cfg(dev, KSZ88X3_REG_FVID_AND_HOST_MODE,
+				KSZ88X3_PORT3_RMII_CLK_INTERNAL,
+				dev->rmii_clk_internal);
+		}
 
 		member = dsa_user_ports(ds);
 	} else {
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)
drivers/net/dsa/microchip/ksz_common.h +1 -0
index 8842efca0871..e5b0445fe2ca 100644
@@ -163,6 +163,7 @@ struct ksz_device {
 	phy_interface_t compat_interface;
 	bool synclko_125;
 	bool synclko_disable;
+	bool rmii_clk_internal;
 
 	struct vlan_table *vlan_cache;
 
Signature · 1 line
2.11.0
#1 lore raw

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

In reply to Ante Knezic

Add documentation for selecting reference rmii clock on KSZ88X3 devices

---
 .../devicetree/bindings/net/dsa/microchip,ksz.yaml      | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +17 -0
index 41014f5c01c4..624feb1bb9be 100644
@@ -72,6 +72,23 @@ properties:
   interrupts:
     maxItems: 1
 
+  microchip,rmii-clk-internal:
+    $ref: /schemas/types.yaml#/definitions/flag
+    description:
+      Set if the RMII reference clock is provided internally. Otherwise
+      reference clock should be provided externally.
+
+if:
+  not:
+    properties:
+      compatible:
+        enum:
+          - microchip,ksz8863
+          - microchip,ksz8873
+then:
+  properties:
+    microchip,rmii-clk-internal: false
+
 required:
   - compatible
   - reg
Signature · 1 line
2.11.0
maintainer
#3 lore raw

Re: [PATCH net-next v3 2/2] net:dsa:microchip: add property to select internal RMII reference clock

In reply to Ante Knezic
Quoted 25 lines · 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.

---
 drivers/net/dsa/microchip/ksz8795.c     | 10 +++++++++-
 drivers/net/dsa/microchip/ksz8795_reg.h |  3 +++
 drivers/net/dsa/microchip/ksz_common.h  |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/ksz8795.c +0 -1
index 91aba470fb2f..b50ad9552c65 100644
@@ -1312,8 +1312,16 @@ void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port)
 	ksz_port_cfg(dev, port, P_PRIO_CTRL, PORT_802_1P_ENABLE, true);
 
 	if (cpu_port) {
-		if (!ksz_is_ksz88x3(dev))

drivers/net/dsa/microchip/ksz8795.c void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port) · line 1324

Quoted 10 lines
drivers/net/dsa/microchip/ksz8795.c +9 -0
+		if (!ksz_is_ksz88x3(dev)) {
 			ksz8795_cpu_interface_select(dev, port);
+		} else {
+			dev->rmii_clk_internal = of_property_read_bool(dev->dev->of_node,
+								       "microchip,rmii-clk-internal");
+
+			ksz_cfg(dev, KSZ88X3_REG_FVID_AND_HOST_MODE,
+				KSZ88X3_PORT3_RMII_CLK_INTERNAL,
+				dev->rmii_clk_internal);
+		}

It looks like this is the only use of dev->rmii_clk_internal? So does it actually need to be a member of ksz_device?

Andrew

#4 lore raw

Re: [PATCH net-next v3 2/2] net:dsa:microchip: add property to select

Quoted 2 lines · Andrew Lunn

It looks like this is the only use of dev->rmii_clk_internal? So does it actually need to be a member of ksz_device?

Yes, I guess you are right, sorry about that, it probably won't be used later on and should be removed from ksz_device.
I will repost if the rest of the patch is ok?

maintainer
#5 lore raw

Re: [PATCH net-next v3 2/2] net:dsa:microchip: add property to select

Quoted 8 lines · Ante Knezic
Quoted 2 lines · Andrew Lunn

It looks like this is the only use of dev->rmii_clk_internal? So does it actually need to be a member of ksz_device?

Yes, I guess you are right, sorry about that, it probably won't be used later on and should be removed from ksz_device.
I will repost if the rest of the patch is ok?

The rest looks O.K. to me.

Andrew

---
pw-bot: cr

maintainer
#6 lore raw

Re: [PATCH net-next v3 2/2] net:dsa:microchip: add property to select internal RMII reference clock

In reply to Ante Knezic
Quoted 24 lines · 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.

---
 drivers/net/dsa/microchip/ksz8795.c     | 10 +++++++++-
 drivers/net/dsa/microchip/ksz8795_reg.h |  3 +++
 drivers/net/dsa/microchip/ksz_common.h  |  1 +
 3 files changed, 13 insertions(+), 1 deletion(-)
drivers/net/dsa/microchip/ksz8795.c +0 -0
index 91aba470fb2f..b50ad9552c65 100644
@@ -1312,8 +1312,16 @@ void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port)
 	ksz_port_cfg(dev, port, P_PRIO_CTRL, PORT_802_1P_ENABLE, true);
 
 	if (cpu_port) {

drivers/net/dsa/microchip/ksz8795.c void ksz8_port_setup(struct ksz_device *dev, int port, bool cpu_port) · line 1323

Quoted 10 lines
drivers/net/dsa/microchip/ksz8795.c +8 -1
-		if (!ksz_is_ksz88x3(dev))
+		if (!ksz_is_ksz88x3(dev)) {
 			ksz8795_cpu_interface_select(dev, port);
+		} else {
+			dev->rmii_clk_internal = of_property_read_bool(dev->dev->of_node,
+								       "microchip,rmii-clk-internal");
+
+			ksz_cfg(dev, KSZ88X3_REG_FVID_AND_HOST_MODE,
+				KSZ88X3_PORT3_RMII_CLK_INTERNAL,
+				dev->rmii_clk_internal);

Odd code placement, and it looks too crammed/shifted to the right due to indentation.

The calling pattern is as follows: ksz8_port_setup() has 2 callers.

One is from
ds->ops->port_setup()
-> ksz_port_setup()
-> filters out everything except user ports
-> dev->dev_ops->port_setup()

      -> ksz8_port_setup()

and the other is from
ds->ops->setup() // switch-wide
-> dev->dev_ops->config_cpu_port()
-> ksz8_config_cpu_port()

      -> ksz8_port_setup()

So user ports and CPU ports meet at ksz8_port_setup() from different call paths, but I think it's strange to continue this coding pattern for port stuff that's not common between user ports and CPU ports. For that reason, the placement of the existing ksz8795_cpu_interface_select() is also weird, when it could have been directly placed under ksz8_config_cpu_port(), and it would have not confusingly shared a code path with user ports.

Could you please add a dedicated ksz88x3_config_rmii_clk(), called directly from ksz8_config_cpu_port()? It can have this as first step:

	if (!ksz_is_ksz88x3(dev))
		return 0;

and then the rest of the code can have a single level of indentation, which would look much more natural.

Quoted 5 lines
drivers/net/dsa/microchip/ksz8795.c +1 -0
+		}
 
 		member = dsa_user_ports(ds);
 	} else {
#7 lore raw

Re: [PATCH net-next v3 2/2] net:dsa:microchip: add property to select

Quoted 8 lines · Vladimir Oltean

So user ports and CPU ports meet at ksz8_port_setup() from different call paths, but I think it's strange to continue this coding pattern for port stuff that's not common between user ports and CPU ports. For that reason, the placement of the existing ksz8795_cpu_interface_select() is also weird, when it could have been directly placed under ksz8_config_cpu_port(), and it would have not confusingly shared a code path with user ports.

Quoted 8 lines

Could you please add a dedicated ksz88x3_config_rmii_clk(), called directly from ksz8_config_cpu_port()? It can have this as first step:

	if (!ksz_is_ksz88x3(dev))
		return 0;

and then the rest of the code can have a single level of indentation, which would look much more natural.

Ok, will do. I am guessing I should leave the existing ksz8795_cpu_interface_select() as it is?

maintainer
#8 lore raw

Re: [PATCH net-next v3 2/2] net:dsa:microchip: add property to select

Quoted 2 lines · Ante Knezic

Ok, will do. I am guessing I should leave the existing ksz8795_cpu_interface_select() as it is?

I would encourage moving it to the simpler call path as well, but ultimately this is up to you.

maintainer
#9 lore raw

Re: [PATCH net-next v3 2/2] net:dsa:microchip: add property to select

Quoted 6 lines · Vladimir Oltean
Quoted 2 lines · Ante Knezic

Ok, will do. I am guessing I should leave the existing ksz8795_cpu_interface_select() as it is?

I would encourage moving it to the simpler call path as well, but ultimately this is up to you.

Also, could you please put spaces in the commit prefix ("net: dsa: microchip: ")?

maintainer
#10 lore raw

Re: [PATCH net-next v3 2/2] net:dsa:microchip: add property to select

+Oleksij

Quoted 9 lines · Vladimir Oltean
Quoted 6 lines · Vladimir Oltean
Quoted 2 lines · Ante Knezic

Ok, will do. I am guessing I should leave the existing ksz8795_cpu_interface_select() as it is?

I would encourage moving it to the simpler call path as well, but ultimately this is up to you.

Also, could you please put spaces in the commit prefix ("net: dsa: microchip: ")?

One more thing. You two are working on separate things on the KSZ driver (Oleksij on
https://patchwork.kernel.org/project/netdevbpf/cover/[email protected]/),
and this creates conflicts in the DT schema and in ksz_common.h. For the most part, those are avoidable. Could you coordinate so that both of your next submissions do not conflict with each other? That means that each of your series can be applied independently of the other (Ante's first, or Oleksij's first).

For example, the dt-schema properties do not seem alphabetically sorted (microchip,synclko-125 comes after reset-gpios), so putting wakeup-source after reset-gpios, and leaving microchip,rmii-clk-internal at the end, seems a viable strategy in avoiding that conflict.

The conflict in ksz_common.h will be automatically avoided when rmii_clk_internal stops being stored in struct ksz_device.