mbox series

[net-next,v3,0/2] Allow disabling KSZ switch refclock

Message ID 20220127003318.3633212-1-robert.hancock@calian.com
Headers show
Series Allow disabling KSZ switch refclock | expand

Message

Robert Hancock Jan. 27, 2022, 12:33 a.m. UTC
The reference clock output from the KSZ9477 and related Microchip
switch devices is not required on all board designs. Add a device
tree property to disable it for power and EMI reasons.

Changes since v2:
-check for conflicting options in DT, added note in bindings doc

Changes since v1:
-added Acked-by on patch 1, rebase to net-next

Robert Hancock (2):
  net: dsa: microchip: Document property to disable reference clock
  net: dsa: microchip: Add property to disable reference clock

 .../devicetree/bindings/net/dsa/microchip,ksz.yaml         | 6 ++++++
 drivers/net/dsa/microchip/ksz9477.c                        | 7 ++++++-
 drivers/net/dsa/microchip/ksz_common.c                     | 6 ++++++
 drivers/net/dsa/microchip/ksz_common.h                     | 1 +
 4 files changed, 19 insertions(+), 1 deletion(-)

Comments

Florian Fainelli Jan. 27, 2022, 12:42 a.m. UTC | #1
On 1/26/2022 4:33 PM, Robert Hancock wrote:
> Add a new microchip,synclko-disable property which can be specified
> to disable the reference clock output from the device if not required
> by the board design.
> 
> Signed-off-by: Robert Hancock <robert.hancock@calian.com>

This looks good, I would just have done the hunk below a bit differently:

> ---
>   drivers/net/dsa/microchip/ksz9477.c    | 7 ++++++-
>   drivers/net/dsa/microchip/ksz_common.c | 6 ++++++
>   drivers/net/dsa/microchip/ksz_common.h | 1 +
>   3 files changed, 13 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/net/dsa/microchip/ksz9477.c b/drivers/net/dsa/microchip/ksz9477.c
> index 353b5f981740..33d52050cd68 100644
> --- a/drivers/net/dsa/microchip/ksz9477.c
> +++ b/drivers/net/dsa/microchip/ksz9477.c
> @@ -222,9 +222,14 @@ static int ksz9477_reset_switch(struct ksz_device *dev)
>   			   (BROADCAST_STORM_VALUE *
>   			   BROADCAST_STORM_PROT_RATE) / 100);
>   
> -	if (dev->synclko_125)
> +	if (dev->synclko_disable)
> +		ksz_write8(dev, REG_SW_GLOBAL_OUTPUT_CTRL__1, 0);
> +	else if (dev->synclko_125)
>   		ksz_write8(dev, REG_SW_GLOBAL_OUTPUT_CTRL__1,
>   			   SW_ENABLE_REFCLKO | SW_REFCLKO_IS_125MHZ);
> +	else
> +		ksz_write8(dev, REG_SW_GLOBAL_OUTPUT_CTRL__1,
> +			   SW_ENABLE_REFCLKO);

Since you write to the same register in all of these branches, why not 
do this:

	u32 tmp = SW_ENABLE_REFCLKO;

	if (dev->synclko_disable)
		tmp = 0
	else if (dev->synclko_125)
		tmp = SW_ENABLE_REFCLKO | SW_REFCLKO_IS_125MHZ;

	ksz_write8(dev, REG_SW_GLOBAL_OUTPUT_CTRL__1, tmp);

even though the compiler may just do that for you under the hood.