Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'net-dsa-microchip-add-strap-description-to-set-spi-as-interface-bus'

Bastien Curutchet says:

====================
net: dsa: microchip: Add strap description to set SPI as interface bus

At reset, the KSZ8463 uses a strap-based configuration to set SPI as
interface bus. If the required pull-ups/pull-downs are missing
(by mistake or by design to save power) the pins may float and the
configuration can go wrong preventing any communication with the switch.

This small series aims to allow to configure the KSZ8463 switch at
reset when the hardware straps are missing.

PATCH 0 and 1 add a new property to the bindings that describes the GPIOs
to be set during reset in order to configure the switch properly.

PATCH 2 implements the use of these properties in the driver.
====================

Link: https://patch.msgid.link/20250918-ksz-strap-pins-v3-0-16662e881728@bootlin.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>

+98 -34
+53 -34
Documentation/devicetree/bindings/net/dsa/microchip,ksz.yaml
··· 10 10 - Marek Vasut <marex@denx.de> 11 11 - Woojung Huh <Woojung.Huh@microchip.com> 12 12 13 - allOf: 14 - - $ref: /schemas/spi/spi-peripheral-props.yaml# 15 - 16 13 properties: 17 14 # See Documentation/devicetree/bindings/net/dsa/dsa.yaml for a list of additional 18 15 # required and optional properties. ··· 33 36 - microchip,ksz8563 34 37 - microchip,ksz8567 35 38 - microchip,lan9646 39 + 40 + pinctrl-names: 41 + items: 42 + - const: default 43 + - const: reset 44 + description: 45 + Used during reset for strap configuration. 36 46 37 47 reset-gpios: 38 48 description: ··· 111 107 - compatible 112 108 - reg 113 109 114 - if: 115 - not: 116 - properties: 117 - compatible: 118 - enum: 119 - - microchip,ksz8863 120 - - microchip,ksz8873 121 - then: 122 - $ref: dsa.yaml#/$defs/ethernet-ports 123 - else: 124 - patternProperties: 125 - "^(ethernet-)?ports$": 110 + allOf: 111 + - $ref: /schemas/spi/spi-peripheral-props.yaml# 112 + 113 + - if: 114 + not: 115 + properties: 116 + compatible: 117 + enum: 118 + - microchip,ksz8863 119 + - microchip,ksz8873 120 + then: 121 + $ref: dsa.yaml#/$defs/ethernet-ports 122 + else: 126 123 patternProperties: 127 - "^(ethernet-)?port@[0-2]$": 128 - $ref: dsa-port.yaml# 129 - unevaluatedProperties: false 130 - properties: 131 - microchip,rmii-clk-internal: 132 - $ref: /schemas/types.yaml#/definitions/flag 133 - description: 134 - When ksz88x3 is acting as clock provier (via REFCLKO) it 135 - can select between internal and external RMII reference 136 - clock. Internal reference clock means that the clock for 137 - the RMII of ksz88x3 is provided by the ksz88x3 internally 138 - and the REFCLKI pin is unconnected. For the external 139 - reference clock, the clock needs to be fed back to ksz88x3 140 - via REFCLKI. 141 - If microchip,rmii-clk-internal is set, ksz88x3 will provide 142 - rmii reference clock internally, otherwise reference clock 143 - should be provided externally. 144 - dependencies: 145 - microchip,rmii-clk-internal: [ethernet] 124 + "^(ethernet-)?ports$": 125 + patternProperties: 126 + "^(ethernet-)?port@[0-2]$": 127 + $ref: dsa-port.yaml# 128 + unevaluatedProperties: false 129 + properties: 130 + microchip,rmii-clk-internal: 131 + $ref: /schemas/types.yaml#/definitions/flag 132 + description: 133 + When ksz88x3 is acting as clock provier (via REFCLKO) it 134 + can select between internal and external RMII reference 135 + clock. Internal reference clock means that the clock for 136 + the RMII of ksz88x3 is provided by the ksz88x3 internally 137 + and the REFCLKI pin is unconnected. For the external 138 + reference clock, the clock needs to be fed back to ksz88x3 139 + via REFCLKI. 140 + If microchip,rmii-clk-internal is set, ksz88x3 will provide 141 + rmii reference clock internally, otherwise reference clock 142 + should be provided externally. 143 + dependencies: 144 + microchip,rmii-clk-internal: [ethernet] 145 + - if: 146 + properties: 147 + compatible: 148 + contains: 149 + const: microchip,ksz8463 150 + then: 151 + properties: 152 + straps-rxd-gpios: 153 + description: 154 + RXD0 and RXD1 pins, used to select SPI as bus interface. 155 + minItems: 2 156 + maxItems: 2 146 157 147 158 unevaluatedProperties: false 148 159
+45
drivers/net/dsa/microchip/ksz_common.c
··· 23 23 #include <linux/of_mdio.h> 24 24 #include <linux/of_net.h> 25 25 #include <linux/micrel_phy.h> 26 + #include <linux/pinctrl/consumer.h> 26 27 #include <net/dsa.h> 27 28 #include <net/ieee8021q.h> 28 29 #include <net/pkt_cls.h> ··· 5346 5345 return 0; 5347 5346 } 5348 5347 5348 + static int ksz8463_configure_straps_spi(struct ksz_device *dev) 5349 + { 5350 + struct pinctrl *pinctrl; 5351 + struct gpio_desc *rxd0; 5352 + struct gpio_desc *rxd1; 5353 + 5354 + rxd0 = devm_gpiod_get_index_optional(dev->dev, "straps-rxd", 0, GPIOD_OUT_LOW); 5355 + if (IS_ERR(rxd0)) 5356 + return PTR_ERR(rxd0); 5357 + 5358 + rxd1 = devm_gpiod_get_index_optional(dev->dev, "straps-rxd", 1, GPIOD_OUT_HIGH); 5359 + if (IS_ERR(rxd1)) 5360 + return PTR_ERR(rxd1); 5361 + 5362 + if (!rxd0 && !rxd1) 5363 + return 0; 5364 + 5365 + if ((rxd0 && !rxd1) || (rxd1 && !rxd0)) 5366 + return -EINVAL; 5367 + 5368 + pinctrl = devm_pinctrl_get_select(dev->dev, "reset"); 5369 + if (IS_ERR(pinctrl)) 5370 + return PTR_ERR(pinctrl); 5371 + 5372 + return 0; 5373 + } 5374 + 5375 + static int ksz8463_release_straps_spi(struct ksz_device *dev) 5376 + { 5377 + return pinctrl_select_default_state(dev->dev); 5378 + } 5379 + 5349 5380 int ksz_switch_register(struct ksz_device *dev) 5350 5381 { 5351 5382 const struct ksz_chip_data *info; ··· 5393 5360 return PTR_ERR(dev->reset_gpio); 5394 5361 5395 5362 if (dev->reset_gpio) { 5363 + if (of_device_is_compatible(dev->dev->of_node, "microchip,ksz8463")) { 5364 + ret = ksz8463_configure_straps_spi(dev); 5365 + if (ret) 5366 + return ret; 5367 + } 5368 + 5396 5369 gpiod_set_value_cansleep(dev->reset_gpio, 1); 5397 5370 usleep_range(10000, 12000); 5398 5371 gpiod_set_value_cansleep(dev->reset_gpio, 0); 5399 5372 msleep(100); 5373 + 5374 + if (of_device_is_compatible(dev->dev->of_node, "microchip,ksz8463")) { 5375 + ret = ksz8463_release_straps_spi(dev); 5376 + if (ret) 5377 + return ret; 5378 + } 5400 5379 } 5401 5380 5402 5381 mutex_init(&dev->dev_mutex);