diff mbox series

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

Message ID 893a3ad19b28c6bb1bf5ea18dee2fa5855f0c207.1697620929.git.ante.knezic@helmholz.de (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next,v3,1/2] dt-bindings: net: microchip,ksz: document microchip,rmii-clk-internal | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1363 this patch: 1363
netdev/cc_maintainers success CCed 10 of 10 maintainers
netdev/build_clang success Errors and warnings before: 1388 this patch: 1388
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 1388 this patch: 1388
netdev/checkpatch warning WARNING: line length of 89 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 1 this patch: 1
netdev/source_inline success Was 0 now: 0

Commit Message

Ante Knezic Oct. 18, 2023, 9:24 a.m. UTC
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.

Signed-off-by: Ante Knezic <ante.knezic@helmholz.de>
---
 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(-)

Comments

Andrew Lunn Oct. 18, 2023, 1:52 p.m. UTC | #1
On Wed, Oct 18, 2023 at 11:24:14AM +0200, Ante Knezic wrote:
> 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.
> 
> Signed-off-by: Ante Knezic <ante.knezic@helmholz.de>
> ---
>  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(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
> index 91aba470fb2f..b50ad9552c65 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -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);
> +		}

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
Ante Knezic Oct. 18, 2023, 2:06 p.m. UTC | #2
On Wed, 18 Oct 2023 15:52:27 +0200, Andrew Lunn wrote:

> 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?
Andrew Lunn Oct. 18, 2023, 2:09 p.m. UTC | #3
On Wed, Oct 18, 2023 at 04:06:28PM +0200, Ante Knezic wrote:
> On Wed, 18 Oct 2023 15:52:27 +0200, Andrew Lunn wrote:
> 
> > 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
Vladimir Oltean Oct. 19, 2023, 4:54 p.m. UTC | #4
On Wed, Oct 18, 2023 at 11:24:14AM +0200, Ante Knezic wrote:
> 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.
> 
> Signed-off-by: Ante Knezic <ante.knezic@helmholz.de>
> ---
>  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(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
> index 91aba470fb2f..b50ad9552c65 100644
> --- a/drivers/net/dsa/microchip/ksz8795.c
> +++ b/drivers/net/dsa/microchip/ksz8795.c
> @@ -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);

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.

> +		}
>  
>  		member = dsa_user_ports(ds);
>  	} else {
>
Ante Knezic Oct. 20, 2023, 8:46 a.m. UTC | #5
On Thu, 19 Oct 2023 19:54:09 +0300, Vladimir Oltean wrote:

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

Ok, will do. I am guessing I should leave the existing 
ksz8795_cpu_interface_select() as it is?
Vladimir Oltean Oct. 20, 2023, 9:27 a.m. UTC | #6
On Fri, Oct 20, 2023 at 10:46:20AM +0200, Ante Knezic wrote:
> 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.
Vladimir Oltean Oct. 20, 2023, 10 a.m. UTC | #7
On Fri, Oct 20, 2023 at 12:27:29PM +0300, Vladimir Oltean wrote:
> On Fri, Oct 20, 2023 at 10:46:20AM +0200, Ante Knezic wrote:
> > 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: ")?
Vladimir Oltean Oct. 20, 2023, 10:26 a.m. UTC | #8
+Oleksij

On Fri, Oct 20, 2023 at 01:00:53PM +0300, Vladimir Oltean wrote:
> On Fri, Oct 20, 2023 at 12:27:29PM +0300, Vladimir Oltean wrote:
> > On Fri, Oct 20, 2023 at 10:46:20AM +0200, Ante Knezic wrote:
> > > 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/20231019122850.1199821-1-o.rempel@pengutronix.de/),
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.
diff mbox series

Patch

diff --git a/drivers/net/dsa/microchip/ksz8795.c b/drivers/net/dsa/microchip/ksz8795.c
index 91aba470fb2f..b50ad9552c65 100644
--- a/drivers/net/dsa/microchip/ksz8795.c
+++ b/drivers/net/dsa/microchip/ksz8795.c
@@ -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 {
diff --git a/drivers/net/dsa/microchip/ksz8795_reg.h b/drivers/net/dsa/microchip/ksz8795_reg.h
index 3c9dae53e4d8..beca974e0171 100644
--- a/drivers/net/dsa/microchip/ksz8795_reg.h
+++ b/drivers/net/dsa/microchip/ksz8795_reg.h
@@ -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)
diff --git a/drivers/net/dsa/microchip/ksz_common.h b/drivers/net/dsa/microchip/ksz_common.h
index 8842efca0871..e5b0445fe2ca 100644
--- a/drivers/net/dsa/microchip/ksz_common.h
+++ b/drivers/net/dsa/microchip/ksz_common.h
@@ -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;