From patchwork Tue Dec 14 16:33:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Mosberger-Tang X-Patchwork-Id: 524501 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5ACDAC433EF for ; Tue, 14 Dec 2021 16:33:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236020AbhLNQdY (ORCPT ); Tue, 14 Dec 2021 11:33:24 -0500 Received: from o1.ptr2625.egauge.net ([167.89.112.53]:24396 "EHLO o1.ptr2625.egauge.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234085AbhLNQdW (ORCPT ); Tue, 14 Dec 2021 11:33:22 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=egauge.net; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type; s=sgd; bh=YKirxG6CHpVK3733gG5FZmHPmsrKUthxnkRneucGCgw=; b=A7Bt9aTZHEEcFGpGJPHS/9i4n6JSKVF9v2Nlkg1arripnaR4A0X7wdlv1cJIxorcd0MX vu4w+m8gd8LEVVwSUDqGT+jRB0mU2ZDVd0yL+UUZfrcAEIhEZLwjD7wQ6gnqpkL5OCW1Q/ M/yBH9SqFwnJRpSyTLcBHW5hUQ3A1VUehLjrhD1TC6XGfmtQHzP4d+Ew7YGCRrlY0iic6l VT6+aruy1RsBaJgLPGnes02heJdwRw7uJQ20/13uEsEHEx8BAgcOdsn9iD/l+KaTSc2B8H lcVqRXbdoIkec04h0+3EEix1jMjT5GvoIJBFG8FCqABSOctJmxlLRhnCwtdooMWg== Received: by filterdrecv-656998cfdd-tjhxw with SMTP id filterdrecv-656998cfdd-tjhxw-1-61B8C750-99 2021-12-14 16:33:20.975233689 +0000 UTC m=+7232761.515384775 Received: from pearl.egauge.net (unknown) by geopod-ismtpd-6-1 (SG) with ESMTP id gvMLUwjWRMqJ4UCan4wi2w Tue, 14 Dec 2021 16:33:20.780 +0000 (UTC) Received: by pearl.egauge.net (Postfix, from userid 1000) id 3E96C700311; Tue, 14 Dec 2021 09:33:20 -0700 (MST) From: David Mosberger-Tang Subject: [PATCH v4 1/2] wilc1000: Add reset/enable GPIO support to SPI driver Date: Tue, 14 Dec 2021 16:33:21 +0000 (UTC) Message-Id: <20211214163315.3769677-2-davidm@egauge.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211214163315.3769677-1-davidm@egauge.net> References: <20211214163315.3769677-1-davidm@egauge.net> MIME-Version: 1.0 X-SG-EID: +kMxBqj35EdRUKoy8diX1j4AXmPtd302oan+iXZuF8m2Nw4HRW2irNspffT/khET6RJF6+Prbl0h/EtF1rRLvG+2bBk199qTQ9Y+y8OdPepVB2E7/lVQog/8OV6APWhy6EICmrPKPqm+Dze2FDGD7wECo7VnBAKwJF67WpXfFoNuuDUIvXpfDjyXZBhyzNMji2YJ3ncHyb1tTRnDaDpWn0i/n+ZRQEYYXOF0wFhG9i+JkiuyMExL7siuM+/Z7Z6KGCf2b/ZIx+waqZ91zFYFHA== To: Ajay Singh Cc: Adham Abozaeid , Claudiu Beznea , "David S. Miller" , devicetree@vger.kernel.org, Jakub Kicinski , Kalle Valo , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Rob Herring , David Mosberger-Tang X-Entity-ID: Xg4JGAcGrJFIz2kDG9eoaQ== Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org 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 --- 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 #include #include +#include #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, From patchwork Tue Dec 14 16:33:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Mosberger-Tang X-Patchwork-Id: 524500 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10F83C433EF for ; Tue, 14 Dec 2021 16:33:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235961AbhLNQdd (ORCPT ); Tue, 14 Dec 2021 11:33:33 -0500 Received: from o1.ptr2625.egauge.net ([167.89.112.53]:25386 "EHLO o1.ptr2625.egauge.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235980AbhLNQdY (ORCPT ); Tue, 14 Dec 2021 11:33:24 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=egauge.net; h=from:subject:in-reply-to:references:mime-version:to:cc: content-transfer-encoding:content-type; s=sgd; bh=yQXnRnX5mAV219nBVUMu6m7E3hTr67JRAHd87199Dpg=; b=DXBRUXbnGdklKRKTxORhG97uAouv2hixXJA6lqRz1x7Q7c8ZgDKVlaA8tCIgpdHxxnaW jP9wqIQP3WghJgM1CJWSHzstyp/dirsqbPcL3IqMyEwpawc06fX/wGZfJR2oTL9WrUAhZT He22ZJFSEaMO43RqzlBrUbLfgvWNc19AAZuRk+rrAV2cPKMfnZoEFppgT0XAJ8kHJiPRt8 pIFqoR8+cJli0Jp2EUzUdu3yjbzYmJkMBW3JlSTyAUmRRrFVrqd7FRkSH4al6UXxQmYw+c hLezr9NTY59CFUI77tnLr0Ql8d5qhbbudkO696BJi78zIDVcFmPDxj04apUrjhXw== Received: by filterdrecv-55446c4d49-ww7gg with SMTP id filterdrecv-55446c4d49-ww7gg-1-61B8C752-84 2021-12-14 16:33:22.516521248 +0000 UTC m=+8964793.130447238 Received: from pearl.egauge.net (unknown) by geopod-ismtpd-1-0 (SG) with ESMTP id TK2IY_rHQcakZ4T_OtfL8Q Tue, 14 Dec 2021 16:33:22.348 +0000 (UTC) Received: by pearl.egauge.net (Postfix, from userid 1000) id 083CE700269; Tue, 14 Dec 2021 09:33:22 -0700 (MST) From: David Mosberger-Tang Subject: [PATCH v4 2/2] wilc1000: Document enable-gpios and reset-gpios properties Date: Tue, 14 Dec 2021 16:33:22 +0000 (UTC) Message-Id: <20211214163315.3769677-3-davidm@egauge.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211214163315.3769677-1-davidm@egauge.net> References: <20211214163315.3769677-1-davidm@egauge.net> MIME-Version: 1.0 X-SG-EID: +kMxBqj35EdRUKoy8diX1j4AXmPtd302oan+iXZuF8m2Nw4HRW2irNspffT/khET6RJF6+Prbl0h/EtF1rRLvH93Xhh/YR9spz2BtA5gO8dpXLqtzVT1vHEwdJSvMWZx2WdZTHyNXu1UE5ARhbnTmdjbrbP9IjXyX8HUoKo0APkCDIeRRyVZxxsFRoR3FFi0p5BnlDn6lfwjL4iNkjO2n1FdBNXtkx1mi9C7raxqt49d00OxinZMZTkKVNyb6ezLEJ2P0lKE5TORkjQK7Ull3Q== To: Ajay Singh Cc: Adham Abozaeid , Claudiu Beznea , "David S. Miller" , devicetree@vger.kernel.org, Jakub Kicinski , Kalle Valo , linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org, netdev@vger.kernel.org, Rob Herring , David Mosberger-Tang X-Entity-ID: Xg4JGAcGrJFIz2kDG9eoaQ== Precedence: bulk List-ID: X-Mailing-List: linux-wireless@vger.kernel.org Add documentation for the ENABLE and RESET GPIOs that may be needed by wilc1000-spi. Signed-off-by: David Mosberger-Tang --- .../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>; }; };