netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: dsa: ksz: Add reset GPIO handling
@ 2018-12-07 17:44 Marek Vasut
  2018-12-07 19:55 ` Andrew Lunn
  0 siblings, 1 reply; 3+ messages in thread
From: Marek Vasut @ 2018-12-07 17:44 UTC (permalink / raw)
  To: netdev
  Cc: f.fainelli, vivien.didelot, andrew, Woojung.Huh, UNGLinuxDriver,
	Marek Vasut, Woojung Huh, David S . Miller, Tristram Ha

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.

Signed-off-by: Marek Vasut <marex@denx.de>
Cc: Vivien Didelot <vivien.didelot@savoirfairelinux.com>
Cc: Woojung Huh <woojung.huh@microchip.com>
Cc: David S. Miller <davem@davemloft.net>
Cc: Tristram Ha <Tristram.Ha@microchip.com>
---
 drivers/net/dsa/microchip/ksz_common.c | 26 ++++++++++++++++++++++++++
 drivers/net/dsa/microchip/ksz_priv.h   |  2 ++
 2 files changed, 28 insertions(+)

diff --git a/drivers/net/dsa/microchip/ksz_common.c b/drivers/net/dsa/microchip/ksz_common.c
index 9705808c3af7a..1f50b31722958 100644
--- a/drivers/net/dsa/microchip/ksz_common.c
+++ b/drivers/net/dsa/microchip/ksz_common.c
@@ -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>
@@ -289,11 +291,31 @@ EXPORT_SYMBOL(ksz_switch_alloc);
 int ksz_switch_register(struct ksz_device *dev,
 			const struct ksz_dev_ops *ops)
 {
+	struct device_node *np = dev->dev->of_node;
+	enum of_gpio_flags reset_gpio_flags;
+	unsigned long flags;
+	int reset_gpio;
 	int ret;
 
 	if (dev->pdata)
 		dev->chip_id = dev->pdata->chip_id;
 
+	dev->reset_gpio = -1;
+	reset_gpio = of_get_named_gpio_flags(np, "reset-gpios", 0,
+					     &reset_gpio_flags);
+	if (reset_gpio >= 0) {
+		flags = (reset_gpio_flags == OF_GPIO_ACTIVE_LOW) ?
+			GPIOF_ACTIVE_LOW : 0;
+		ret = devm_gpio_request_one(dev->dev, reset_gpio, flags,
+					    "switch-reset");
+		if (ret) {
+			dev_err(dev->dev, "failed to get reset-gpios: %d\n", ret);
+			return -EIO;
+		}
+		dev->reset_gpio = reset_gpio;
+		gpiod_set_value(gpio_to_desc(reset_gpio), 0);
+	}
+
 	mutex_init(&dev->reg_mutex);
 	mutex_init(&dev->stats_mutex);
 	mutex_init(&dev->alu_mutex);
@@ -329,6 +351,10 @@ void ksz_switch_remove(struct ksz_device *dev)
 {
 	dev->dev_ops->exit(dev);
 	dsa_unregister_switch(dev->ds);
+
+	if (dev->reset_gpio >= 0)
+		gpiod_set_value(gpio_to_desc(dev->reset_gpio), 1);
+
 }
 EXPORT_SYMBOL(ksz_switch_remove);
 
diff --git a/drivers/net/dsa/microchip/ksz_priv.h b/drivers/net/dsa/microchip/ksz_priv.h
index a38ff0841ed4e..6dd2ebfd6e12f 100644
--- a/drivers/net/dsa/microchip/ksz_priv.h
+++ b/drivers/net/dsa/microchip/ksz_priv.h
@@ -59,6 +59,8 @@ struct ksz_device {
 
 	void *priv;
 
+	int reset_gpio;			/* Optional reset GPIO */
+
 	/* chip specific data */
 	u32 chip_id;
 	int num_vlans;
-- 
2.18.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: dsa: ksz: Add reset GPIO handling
  2018-12-07 17:44 [PATCH] net: dsa: ksz: Add reset GPIO handling Marek Vasut
@ 2018-12-07 19:55 ` Andrew Lunn
  2018-12-07 21:52   ` Marek Vasut
  0 siblings, 1 reply; 3+ messages in thread
From: Andrew Lunn @ 2018-12-07 19:55 UTC (permalink / raw)
  To: Marek Vasut
  Cc: netdev, f.fainelli, vivien.didelot, Woojung.Huh, UNGLinuxDriver,
	David S . Miller, Tristram Ha

> +	dev->reset_gpio = -1;
> +	reset_gpio = of_get_named_gpio_flags(np, "reset-gpios", 0,
> +					     &reset_gpio_flags);
> +	if (reset_gpio >= 0) {
> +		flags = (reset_gpio_flags == OF_GPIO_ACTIVE_LOW) ?
> +			GPIOF_ACTIVE_LOW : 0;

Can you use devm_gpiod_get_optional()? It makes this a lot simpler.
Take a look at mv88e6xxx/chip.c which also uses a GPIO for reset.

You also need to update the binding documentation for this new
property.

	Andrew

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] net: dsa: ksz: Add reset GPIO handling
  2018-12-07 19:55 ` Andrew Lunn
@ 2018-12-07 21:52   ` Marek Vasut
  0 siblings, 0 replies; 3+ messages in thread
From: Marek Vasut @ 2018-12-07 21:52 UTC (permalink / raw)
  To: Andrew Lunn
  Cc: netdev, f.fainelli, vivien.didelot, Woojung.Huh, UNGLinuxDriver,
	David S . Miller, Tristram Ha

On 12/07/2018 08:55 PM, Andrew Lunn wrote:
>> +	dev->reset_gpio = -1;
>> +	reset_gpio = of_get_named_gpio_flags(np, "reset-gpios", 0,
>> +					     &reset_gpio_flags);
>> +	if (reset_gpio >= 0) {
>> +		flags = (reset_gpio_flags == OF_GPIO_ACTIVE_LOW) ?
>> +			GPIOF_ACTIVE_LOW : 0;
> 
> Can you use devm_gpiod_get_optional()? It makes this a lot simpler.
> Take a look at mv88e6xxx/chip.c which also uses a GPIO for reset.

Done

> You also need to update the binding documentation for this new
> property.

Will do in a separate patch.

-- 
Best regards,
Marek Vasut

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-07 21:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-07 17:44 [PATCH] net: dsa: ksz: Add reset GPIO handling Marek Vasut
2018-12-07 19:55 ` Andrew Lunn
2018-12-07 21:52   ` Marek Vasut

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).