net: dsa: qca8k: introduce reset via gpio feature
authorChristian Lamparter <chunkeey@gmail.com>
Tue, 25 Jun 2019 08:41:51 +0000 (10:41 +0200)
committerDavid S. Miller <davem@davemloft.net>
Thu, 27 Jun 2019 18:17:30 +0000 (11:17 -0700)
The QCA8337(N) has a RESETn signal on Pin B42 that
triggers a chip reset if the line is pulled low.
The datasheet says that: "The active low duration
must be greater than 10 ms".

This can hopefully fix some of the issues related
to pin strapping in OpenWrt for the EA8500 which
suffers from detection issues after a SoC reset.

Please note that the qca8k_probe() function does
currently require to read the chip's revision
register for identification purposes.

Signed-off-by: Christian Lamparter <chunkeey@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/dsa/qca8k.c
drivers/net/dsa/qca8k.h

index c4fa400efdcc82643dcd4d2c762ed8079305adf7..27709f866c23ad3302f4215bc1a2e29c534543f4 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/of_platform.h>
 #include <linux/if_bridge.h>
 #include <linux/mdio.h>
+#include <linux/gpio.h>
 #include <linux/etherdevice.h>
 
 #include "qca8k.h"
@@ -1046,6 +1047,20 @@ qca8k_sw_probe(struct mdio_device *mdiodev)
        priv->bus = mdiodev->bus;
        priv->dev = &mdiodev->dev;
 
+       priv->reset_gpio = devm_gpiod_get_optional(priv->dev, "reset",
+                                                  GPIOD_ASIS);
+       if (IS_ERR(priv->reset_gpio))
+               return PTR_ERR(priv->reset_gpio);
+
+       if (priv->reset_gpio) {
+               gpiod_set_value_cansleep(priv->reset_gpio, 1);
+               /* The active low duration must be greater than 10 ms
+                * and checkpatch.pl wants 20 ms.
+                */
+               msleep(20);
+               gpiod_set_value_cansleep(priv->reset_gpio, 0);
+       }
+
        /* read the switches ID register */
        id = qca8k_read(priv, QCA8K_REG_MASK_CTRL);
        id >>= QCA8K_MASK_CTRL_ID_S;
index 91557433ce2fc458e8cd8ce595a0a6a4e263a866..42d6ea24eb14ecffbd9e199ce1b344abaa6cf108 100644 (file)
@@ -10,6 +10,7 @@
 
 #include <linux/delay.h>
 #include <linux/regmap.h>
+#include <linux/gpio.h>
 
 #define QCA8K_NUM_PORTS                                        7
 
@@ -174,6 +175,7 @@ struct qca8k_priv {
        struct mutex reg_mutex;
        struct device *dev;
        struct dsa_switch_ops ops;
+       struct gpio_desc *reset_gpio;
 };
 
 struct qca8k_mib_desc {