Allow disabling KSZ switch refclock
Subsystems (5)
v3 cover Allow disabling KSZ switch refclock
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(-)
Signature · 1 line
2.31.1
PATCH v3 1/2 net: dsa: microchip: Document property to disable reference clock
Document the 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.
--- .../devicetree/bindings/net/dsa/microchip,ksz.yaml | 6 ++++++ 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml +6 -0
@@ -42,6 +42,12 @@ properties: description: Set if the output SYNCLKO frequency should be set to 125MHz instead of 25MHz. + microchip,synclko-disable: + $ref: /schemas/types.yaml#/definitions/flag + description: + Set if the output SYNCLKO clock should be disabled. Do not mix with + microchip,synclko-125. + required: - compatible - reg
Signature · 1 line
2.31.1
PATCH v3 2/2 net: dsa: microchip: Add property to disable reference clock
In reply to Robert HancockAdd 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.
--- 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(-)
drivers/net/dsa/microchip/ksz9477.c +6 -1
@@ -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 );return 0 ; }
drivers/net/dsa/microchip/ksz_common.c +6 -0
@@ -434,6 +434,12 @@ int ksz_switch_register(struct ksz_device *dev, } dev->synclko_125 =of_property_read_bool (dev->dev->of_node,"microchip,synclko-125" ); + dev->synclko_disable =of_property_read_bool (dev->dev->of_node, +"microchip,synclko-disable" ); +if (dev->synclko_125 && dev->synclko_disable) { +dev_err (dev->dev,"inconsistent synclko settings\n" ); +return -EINVAL ; + } } ret =dsa_register_switch (dev->ds);
drivers/net/dsa/microchip/ksz_common.h +1 -0
@@ -75,6 +75,7 @@ struct ksz_device {u32 regs_size;bool phy_errata_9477;bool synclko_125; +bool synclko_disable;struct vlan_table *vlan_cache;
Signature · 1 line
2.31.1
Re: [PATCH net-next v3 2/2] net: dsa: microchip: Add property to disable reference clock
Quoted 5 lines · Robert Hancock
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 <[email protected]>
This looks good, I would just have done the hunk below a bit differently:
Quoted 13 lines
--- 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(-)drivers/net/dsa/microchip/ksz9477.c +0
-0@@ -222,9 +222,14 @@ static int ksz9477_reset_switch(struct ksz_device *dev) (BROADCAST_STORM_VALUE * BROADCAST_STORM_PROT_RATE) / 100);
drivers/net/dsa/microchip/ksz9477.c static int ksz9477_reset_switch(struct ksz_device *dev) · line 232
Quoted 10 lines
drivers/net/dsa/microchip/ksz9477.c +6
-1-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.
Signature · 1 line
Florian