Skip to contentSkip to conversation

net: dsa: ksz: Add reset GPIO handling

PATCH RESEND In review Marek Vasut 3 participants 6 messages Dec 10, 2018

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

v2 cover net: dsa: ksz: Add reset GPIO handling

Add code to handle optional reset GPIO in the KSZ switch driver and a matching DT property adjustments.

Marek Vasut (2):
net: dsa: ksz: Add optional reset GPIO to Microchip KSZ switch binding
net: dsa: ksz: Add reset GPIO handling

 .../devicetree/bindings/net/dsa/ksz.txt         |  4 ++++
 drivers/net/dsa/microchip/ksz_common.c          | 17 +++++++++++++++++
 drivers/net/dsa/microchip/ksz_priv.h            |  2 ++
 3 files changed, 23 insertions(+)
Signature · 1 line
2.18.0
#1 lore raw

PATCH RESEND v2 1/2 net: dsa: ksz: Add optional reset GPIO to Microchip KSZ switch binding

Add optional reset GPIO, as such a signal is available on the KSZ switches.

Cc Andrew Lunn <[email protected]>
Cc Florian Fainelli <[email protected]>
Cc Woojung Huh <[email protected]>
Cc David S. Miller <[email protected]>

---
V2: No change

---
 Documentation/devicetree/bindings/net/dsa/ksz.txt | 4 ++++
 1 file changed, 4 insertions(+)
Documentation/devicetree/bindings/net/dsa/ksz.txt +4 -0
index ac145b885e955..0f407fb371ce1 100644
@@ -8,6 +8,10 @@ Required properties:
   - "microchip,ksz9477"
   - "microchip,ksz9897"
 
+Optional properties:
+
+- reset-gpios		: Should be a gpio specifier for a reset line
+
 See Documentation/devicetree/bindings/net/dsa/dsa.txt for a list of additional
 required and optional properties.
 
Signature · 1 line
2.18.0
maintainer Reviewed-by on v2 1/2
#2 lore raw

Re: [PATCH V2 RESEND 1/2] net: dsa: ksz: Add optional reset GPIO to Microchip KSZ switch binding

Quoted 3 lines · Marek Vasut

Add optional reset GPIO, as such a signal is available on the KSZ switches.

Hi Marek

Thanks for creating the patchset.

Andrew

#3 lore raw

PATCH RESEND v2 2/2 net: dsa: ksz: Add reset GPIO handling

In reply to Marek Vasut

Add code to handle optional reset GPIO in the KSZ switch driver. The switch has a reset GPIO line which can be controlled by the CPU, so make sure it is configured correctly in such setups.

Cc Vivien Didelot <[email protected]>
Cc Woojung Huh <[email protected]>
Cc David S. Miller <[email protected]>
Cc Tristram Ha <[email protected]>

---
V2: Switch to devm_gpiod_get_optional()

---
 drivers/net/dsa/microchip/ksz_common.c | 17 +++++++++++++++++
 drivers/net/dsa/microchip/ksz_priv.h   |  2 ++
 2 files changed, 19 insertions(+)
drivers/net/dsa/microchip/ksz_common.c +17 -0
index 9705808c3af7a..3b12e2dcff31b 100644
@@ -8,12 +8,14 @@
 #include <linux/delay.h>
 #include <linux/export.h>
 #include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/kernel.h>
 #include <linux/module.h>
 #include <linux/platform_data/microchip-ksz.h>
 #include <linux/phy.h>
 #include <linux/etherdevice.h>
 #include <linux/if_bridge.h>
+#include <linux/of_gpio.h>
 #include <linux/of_net.h>
 #include <net/dsa.h>
 #include <net/switchdev.h>
@@ -294,6 +296,17 @@ int ksz_switch_register(struct ksz_device *dev,
 	if (dev->pdata)
 		dev->chip_id = dev->pdata->chip_id;
 
+	dev->reset_gpio = devm_gpiod_get_optional(dev->dev, "reset",
+						  GPIOD_OUT_LOW);
+	if (IS_ERR(dev->reset_gpio))
+		return PTR_ERR(dev->reset_gpio);
+
+	if (dev->reset_gpio) {
+		gpiod_set_value(dev->reset_gpio, 1);
+		mdelay(10);
+		gpiod_set_value(dev->reset_gpio, 0);
+	}
+
 	mutex_init(&dev->reg_mutex);
 	mutex_init(&dev->stats_mutex);
 	mutex_init(&dev->alu_mutex);
@@ -329,6 +342,10 @@ void ksz_switch_remove(struct ksz_device *dev)
 {
 	dev->dev_ops->exit(dev);
 	dsa_unregister_switch(dev->ds);
+
+	if (dev->reset_gpio)
+		gpiod_set_value(dev->reset_gpio, 1);
+
 }
 EXPORT_SYMBOL(ksz_switch_remove);
 
drivers/net/dsa/microchip/ksz_priv.h +2 -0
index a38ff0841ed4e..60b49010904bf 100644
@@ -59,6 +59,8 @@ struct ksz_device {
 
 	void *priv;
 
+	struct gpio_desc *reset_gpio;	/* Optional reset GPIO */
+
 	/* chip specific data */
 	u32 chip_id;
 	int num_vlans;
Signature · 1 line
2.18.0