devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v4 0/2] Add reset/enable GPIO support to SPI driver
@ 2021-12-14 16:33 David Mosberger-Tang
  2021-12-14 16:33 ` [PATCH v4 1/2] wilc1000: " David Mosberger-Tang
  2021-12-14 16:33 ` [PATCH v4 2/2] wilc1000: Document enable-gpios and reset-gpios properties David Mosberger-Tang
  0 siblings, 2 replies; 7+ messages in thread
From: David Mosberger-Tang @ 2021-12-14 16:33 UTC (permalink / raw)
  To: Ajay Singh
  Cc: Adham Abozaeid, Claudiu Beznea, David S. Miller, devicetree,
	Jakub Kicinski, Kalle Valo, linux-kernel, linux-wireless, netdev,
	Rob Herring, David Mosberger-Tang

I made a mistake last night when checking whether gpiod_set_value() is
safe to call with a NULL gpiod descriptor (it is).  v4 of the patch
just fixes that mistake.  It does simplify the code nicely.

This version also fixes the error handling when the reset gpio is
missing.

David Mosberger-Tang (2):
  wilc1000: Add reset/enable GPIO support to SPI driver
  wilc1000: Document enable-gpios and reset-gpios properties

 .../net/wireless/microchip,wilc1000.yaml      | 17 ++++++
 drivers/net/wireless/microchip/wilc1000/spi.c | 58 ++++++++++++++++++-
 .../net/wireless/microchip/wilc1000/wlan.c    |  2 +-
 3 files changed, 73 insertions(+), 4 deletions(-)

-- 
2.25.1


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

* [PATCH v4 1/2] wilc1000: Add reset/enable GPIO support to SPI driver
  2021-12-14 16:33 [PATCH v4 0/2] Add reset/enable GPIO support to SPI driver David Mosberger-Tang
@ 2021-12-14 16:33 ` David Mosberger-Tang
  2021-12-14 16:33 ` [PATCH v4 2/2] wilc1000: Document enable-gpios and reset-gpios properties David Mosberger-Tang
  1 sibling, 0 replies; 7+ messages in thread
From: David Mosberger-Tang @ 2021-12-14 16:33 UTC (permalink / raw)
  To: Ajay Singh
  Cc: Adham Abozaeid, Claudiu Beznea, David S. Miller, devicetree,
	Jakub Kicinski, Kalle Valo, linux-kernel, linux-wireless, netdev,
	Rob Herring, David Mosberger-Tang

For the SDIO driver, the RESET/ENABLE pins of WILC1000 are controlled
through the SDIO power sequence driver.  This commit adds analogous
support for the SPI driver.  Specifically, during initialization, the
chip will be ENABLEd and taken out of RESET and during
deinitialization, the chip will be placed back into RESET and disabled
(both to reduce power consumption and to ensure the WiFi radio is
off).

Both RESET and ENABLE GPIOs are optional.  However, if the ENABLE GPIO
is specified, then the RESET GPIO should normally also be specified as
otherwise there is no way to ensure proper timing of the ENABLE/RESET
sequence.

Signed-off-by: David Mosberger-Tang <davidm@egauge.net>
---
 drivers/net/wireless/microchip/wilc1000/spi.c | 58 ++++++++++++++++++-
 .../net/wireless/microchip/wilc1000/wlan.c    |  2 +-
 2 files changed, 56 insertions(+), 4 deletions(-)

diff --git a/drivers/net/wireless/microchip/wilc1000/spi.c b/drivers/net/wireless/microchip/wilc1000/spi.c
index 6e7fd18c14e7..0b4425e56bfa 100644
--- a/drivers/net/wireless/microchip/wilc1000/spi.c
+++ b/drivers/net/wireless/microchip/wilc1000/spi.c
@@ -8,6 +8,7 @@
 #include <linux/spi/spi.h>
 #include <linux/crc7.h>
 #include <linux/crc-itu-t.h>
+#include <linux/gpio/consumer.h>
 
 #include "netdev.h"
 #include "cfg80211.h"
@@ -43,6 +44,10 @@ struct wilc_spi {
 	bool probing_crc;	/* true if we're probing chip's CRC config */
 	bool crc7_enabled;	/* true if crc7 is currently enabled */
 	bool crc16_enabled;	/* true if crc16 is currently enabled */
+	struct wilc_gpios {
+		struct gpio_desc *enable;	/* ENABLE GPIO or NULL */
+		struct gpio_desc *reset;	/* RESET GPIO or NULL */
+	} gpios;
 };
 
 static const struct wilc_hif_func wilc_hif_spi;
@@ -152,6 +157,46 @@ struct wilc_spi_special_cmd_rsp {
 	u8 status;
 } __packed;
 
+static int wilc_parse_gpios(struct wilc *wilc)
+{
+	struct spi_device *spi = to_spi_device(wilc->dev);
+	struct wilc_spi *spi_priv = wilc->bus_data;
+	struct wilc_gpios *gpios = &spi_priv->gpios;
+
+	/* get ENABLE pin and deassert it (if it is defined): */
+	gpios->enable = devm_gpiod_get_optional(&spi->dev,
+						"enable", GPIOD_OUT_LOW);
+	/* get RESET pin and assert it (if it is defined): */
+	if (gpios->enable) {
+		/* if enable pin exists, reset must exist as well */
+		gpios->reset = devm_gpiod_get(&spi->dev,
+					      "reset", GPIOD_OUT_HIGH);
+		if (IS_ERR(gpios->reset)) {
+			dev_err(&spi->dev, "missing reset gpio.\n");
+			return PTR_ERR(gpios->reset);
+		}
+	} else {
+		gpios->reset = devm_gpiod_get_optional(&spi->dev,
+						       "reset", GPIOD_OUT_HIGH);
+	}
+	return 0;
+}
+
+static void wilc_wlan_power(struct wilc *wilc, bool on)
+{
+	struct wilc_spi *spi_priv = wilc->bus_data;
+	struct wilc_gpios *gpios = &spi_priv->gpios;
+
+	if (on) {
+		gpiod_set_value(gpios->enable, 1);	/* assert ENABLE */
+		mdelay(5);
+		gpiod_set_value(gpios->reset, 0);	/* deassert RESET */
+	} else {
+		gpiod_set_value(gpios->reset, 1);	/* assert RESET */
+		gpiod_set_value(gpios->enable, 0);	/* deassert ENABLE */
+	}
+}
+
 static int wilc_bus_probe(struct spi_device *spi)
 {
 	int ret;
@@ -171,6 +216,10 @@ static int wilc_bus_probe(struct spi_device *spi)
 	wilc->bus_data = spi_priv;
 	wilc->dev_irq_num = spi->irq;
 
+	ret = wilc_parse_gpios(wilc);
+	if (ret < 0)
+		goto netdev_cleanup;
+
 	wilc->rtc_clk = devm_clk_get_optional(&spi->dev, "rtc");
 	if (IS_ERR(wilc->rtc_clk)) {
 		ret = PTR_ERR(wilc->rtc_clk);
@@ -984,9 +1033,10 @@ static int wilc_spi_reset(struct wilc *wilc)
 
 static int wilc_spi_deinit(struct wilc *wilc)
 {
-	/*
-	 * TODO:
-	 */
+	struct wilc_spi *spi_priv = wilc->bus_data;
+
+	spi_priv->isinit = false;
+	wilc_wlan_power(wilc, false);
 	return 0;
 }
 
@@ -1007,6 +1057,8 @@ static int wilc_spi_init(struct wilc *wilc, bool resume)
 		dev_err(&spi->dev, "Fail cmd read chip id...\n");
 	}
 
+	wilc_wlan_power(wilc, true);
+
 	/*
 	 * configure protocol
 	 */
diff --git a/drivers/net/wireless/microchip/wilc1000/wlan.c b/drivers/net/wireless/microchip/wilc1000/wlan.c
index 82566544419a..f1e4ac3a2ad5 100644
--- a/drivers/net/wireless/microchip/wilc1000/wlan.c
+++ b/drivers/net/wireless/microchip/wilc1000/wlan.c
@@ -1253,7 +1253,7 @@ void wilc_wlan_cleanup(struct net_device *dev)
 	wilc->rx_buffer = NULL;
 	kfree(wilc->tx_buffer);
 	wilc->tx_buffer = NULL;
-	wilc->hif_func->hif_deinit(NULL);
+	wilc->hif_func->hif_deinit(wilc);
 }
 
 static int wilc_wlan_cfg_commit(struct wilc_vif *vif, int type,
-- 
2.25.1


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

* [PATCH v4 2/2] wilc1000: Document enable-gpios and reset-gpios properties
  2021-12-14 16:33 [PATCH v4 0/2] Add reset/enable GPIO support to SPI driver David Mosberger-Tang
  2021-12-14 16:33 ` [PATCH v4 1/2] wilc1000: " David Mosberger-Tang
@ 2021-12-14 16:33 ` David Mosberger-Tang
  2021-12-14 20:04   ` Rob Herring
  1 sibling, 1 reply; 7+ messages in thread
From: David Mosberger-Tang @ 2021-12-14 16:33 UTC (permalink / raw)
  To: Ajay Singh
  Cc: Adham Abozaeid, Claudiu Beznea, David S. Miller, devicetree,
	Jakub Kicinski, Kalle Valo, linux-kernel, linux-wireless, netdev,
	Rob Herring, David Mosberger-Tang

Add documentation for the ENABLE and RESET GPIOs that may be needed by
wilc1000-spi.

Signed-off-by: David Mosberger-Tang <davidm@egauge.net>
---
 .../net/wireless/microchip,wilc1000.yaml        | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.yaml b/Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.yaml
index 6c35682377e6..790a774a19ee 100644
--- a/Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.yaml
+++ b/Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.yaml
@@ -32,6 +32,21 @@ properties:
   clock-names:
     const: rtc
 
+  enable-gpios:
+    maxItems: 1
+    description: Used by wilc1000-spi to determine the GPIO line
+      connected to the ENABLE line.  If specified, reset-gpios
+      must be specified as well as otherwise the driver cannot
+      ensure the timing required between asserting ENABLE
+      and deasserting RESET.  This should be declared as an
+      active-high signal.
+
+  reset-gpios:
+    maxItems: 1
+    description: Used by wilc1000-spi to determine the GPIO line
+      connected to the RESET line.  This should be declared as an
+      active-low signal.
+
 required:
   - compatible
   - interrupts
@@ -51,6 +66,8 @@ examples:
         interrupts = <27 0>;
         clocks = <&pck1>;
         clock-names = "rtc";
+        enable-gpios = <&pioA 5 GPIO_ACTIVE_HIGH>;
+        reset-gpios = <&pioA 6 GPIO_ACTIVE_LOW>;
       };
     };
 
-- 
2.25.1


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

* Re: [PATCH v4 2/2] wilc1000: Document enable-gpios and reset-gpios properties
  2021-12-14 16:33 ` [PATCH v4 2/2] wilc1000: Document enable-gpios and reset-gpios properties David Mosberger-Tang
@ 2021-12-14 20:04   ` Rob Herring
  2021-12-14 23:30     ` David Mosberger-Tang
  0 siblings, 1 reply; 7+ messages in thread
From: Rob Herring @ 2021-12-14 20:04 UTC (permalink / raw)
  To: David Mosberger-Tang
  Cc: Rob Herring, Kalle Valo, netdev, Adham Abozaeid, Claudiu Beznea,
	linux-kernel, David S. Miller, Ajay Singh, linux-wireless,
	devicetree, Jakub Kicinski

On Tue, 14 Dec 2021 16:33:22 +0000, David Mosberger-Tang wrote:
> Add documentation for the ENABLE and RESET GPIOs that may be needed by
> wilc1000-spi.
> 
> Signed-off-by: David Mosberger-Tang <davidm@egauge.net>
> ---
>  .../net/wireless/microchip,wilc1000.yaml        | 17 +++++++++++++++++
>  1 file changed, 17 insertions(+)
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
Error: Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.example.dts:30.37-38 syntax error
FATAL ERROR: Unable to parse input tree
make[1]: *** [scripts/Makefile.lib:373: Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.example.dt.yaml] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [Makefile:1413: dt_binding_check] Error 2

doc reference errors (make refcheckdocs):

See https://patchwork.ozlabs.org/patch/1567796

This check can fail if there are any dependencies. The base for a patch
series is generally the most recent rc1.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit.


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

* Re: [PATCH v4 2/2] wilc1000: Document enable-gpios and reset-gpios properties
  2021-12-14 20:04   ` Rob Herring
@ 2021-12-14 23:30     ` David Mosberger-Tang
  2021-12-14 23:54       ` Rob Herring
  0 siblings, 1 reply; 7+ messages in thread
From: David Mosberger-Tang @ 2021-12-14 23:30 UTC (permalink / raw)
  To: Rob Herring
  Cc: Rob Herring, Kalle Valo, netdev, Adham Abozaeid, Claudiu Beznea,
	linux-kernel, David S. Miller, Ajay Singh, linux-wireless,
	devicetree, Jakub Kicinski

On Tue, 2021-12-14 at 14:04 -0600, Rob Herring wrote:
> On Tue, 14 Dec 2021 16:33:22 +0000, David Mosberger-Tang wrote:
> > Add documentation for the ENABLE and RESET GPIOs that may be needed by
> > wilc1000-spi.
> > 
> > Signed-off-by: David Mosberger-Tang <davidm@egauge.net>
> > ---
> >  .../net/wireless/microchip,wilc1000.yaml        | 17 +++++++++++++++++
> >  1 file changed, 17 insertions(+)
> > 
> 
> My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
> on your patch (DT_CHECKER_FLAGS is new in v5.13):
> 
> yamllint warnings/errors:
> 
> dtschema/dtc warnings/errors:
> Error: Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.example.dts:30.37-38 syntax error
> FATAL ERROR: Unable to parse input tree
> make[1]: *** [scripts/Makefile.lib:373: Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.example.dt.yaml] Error 1
> make[1]: *** Waiting for unfinished jobs....
> make: *** [Makefile:1413: dt_binding_check] Error 2

So this error appears due to GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW in these
lines:

        enable-gpios = <&pioA 5 GPIO_ACTIVE_HIGH>;
        reset-gpios = <&pioA 6 GPIO_ACTIVE_LOW>;

I can replace those with 0 and 1 respectively, but I doubt a lot of people would
recognize what those integers standard for.  Is there a better way to get this
to pass?

  --david


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

* Re: [PATCH v4 2/2] wilc1000: Document enable-gpios and reset-gpios properties
  2021-12-14 23:30     ` David Mosberger-Tang
@ 2021-12-14 23:54       ` Rob Herring
  2021-12-15  2:53         ` David Mosberger-Tang
  0 siblings, 1 reply; 7+ messages in thread
From: Rob Herring @ 2021-12-14 23:54 UTC (permalink / raw)
  To: David Mosberger-Tang
  Cc: Kalle Valo, netdev, Adham Abozaeid, Claudiu Beznea, linux-kernel,
	David S. Miller, Ajay Singh, linux-wireless, devicetree,
	Jakub Kicinski

On Tue, Dec 14, 2021 at 5:30 PM David Mosberger-Tang <davidm@egauge.net> wrote:
>
> On Tue, 2021-12-14 at 14:04 -0600, Rob Herring wrote:
> > On Tue, 14 Dec 2021 16:33:22 +0000, David Mosberger-Tang wrote:
> > > Add documentation for the ENABLE and RESET GPIOs that may be needed by
> > > wilc1000-spi.
> > >
> > > Signed-off-by: David Mosberger-Tang <davidm@egauge.net>
> > > ---
> > >  .../net/wireless/microchip,wilc1000.yaml        | 17 +++++++++++++++++
> > >  1 file changed, 17 insertions(+)
> > >
> >
> > My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
> > on your patch (DT_CHECKER_FLAGS is new in v5.13):
> >
> > yamllint warnings/errors:
> >
> > dtschema/dtc warnings/errors:
> > Error: Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.example.dts:30.37-38 syntax error
> > FATAL ERROR: Unable to parse input tree
> > make[1]: *** [scripts/Makefile.lib:373: Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.example.dt.yaml] Error 1
> > make[1]: *** Waiting for unfinished jobs....
> > make: *** [Makefile:1413: dt_binding_check] Error 2
>
> So this error appears due to GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW in these
> lines:
>
>         enable-gpios = <&pioA 5 GPIO_ACTIVE_HIGH>;
>         reset-gpios = <&pioA 6 GPIO_ACTIVE_LOW>;
>
> I can replace those with 0 and 1 respectively, but I doubt a lot of people would
> recognize what those integers standard for.  Is there a better way to get this
> to pass?

Include the header(s) you use in the example.

Rob

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

* Re: [PATCH v4 2/2] wilc1000: Document enable-gpios and reset-gpios properties
  2021-12-14 23:54       ` Rob Herring
@ 2021-12-15  2:53         ` David Mosberger-Tang
  0 siblings, 0 replies; 7+ messages in thread
From: David Mosberger-Tang @ 2021-12-15  2:53 UTC (permalink / raw)
  To: Rob Herring
  Cc: Kalle Valo, netdev, Adham Abozaeid, Claudiu Beznea, linux-kernel,
	David S. Miller, Ajay Singh, linux-wireless, devicetree,
	Jakub Kicinski

On Tue, 2021-12-14 at 17:54 -0600, Rob Herring wrote:
> On Tue, Dec 14, 2021 at 5:30 PM David Mosberger-Tang <davidm@egauge.net> wrote:
> > On Tue, 2021-12-14 at 14:04 -0600, Rob Herring wrote:
> > > 
> > > dtschema/dtc warnings/errors:
> > > Error: Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.example.dts:30.37-38 syntax error
> > > FATAL ERROR: Unable to parse input tree
> > > make[1]: *** [scripts/Makefile.lib:373: Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.example.dt.yaml] Error 1
> > > make[1]: *** Waiting for unfinished jobs....
> > > make: *** [Makefile:1413: dt_binding_check] Error 2
> > 
> > So this error appears due to GPIO_ACTIVE_HIGH and GPIO_ACTIVE_LOW in these
> > lines:
> > 
> >         enable-gpios = <&pioA 5 GPIO_ACTIVE_HIGH>;
> >         reset-gpios = <&pioA 6 GPIO_ACTIVE_LOW>;
> > 
> > I can replace those with 0 and 1 respectively, but I doubt a lot of people would
> > recognize what those integers standard for.  Is there a better way to get this
> > to pass?
> 
> Include the header(s) you use in the example.

Huh, that works, thanks!

  --david


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

end of thread, other threads:[~2021-12-15  2:53 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-14 16:33 [PATCH v4 0/2] Add reset/enable GPIO support to SPI driver David Mosberger-Tang
2021-12-14 16:33 ` [PATCH v4 1/2] wilc1000: " David Mosberger-Tang
2021-12-14 16:33 ` [PATCH v4 2/2] wilc1000: Document enable-gpios and reset-gpios properties David Mosberger-Tang
2021-12-14 20:04   ` Rob Herring
2021-12-14 23:30     ` David Mosberger-Tang
2021-12-14 23:54       ` Rob Herring
2021-12-15  2:53         ` David Mosberger-Tang

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).