From patchwork Tue Dec 21 21:25:34 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: 526798 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 DFC8CC433F5 for ; Tue, 21 Dec 2021 21:25:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236534AbhLUVZg (ORCPT ); Tue, 21 Dec 2021 16:25:36 -0500 Received: from o1.ptr2625.egauge.net ([167.89.112.53]:46240 "EHLO o1.ptr2625.egauge.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235866AbhLUVZf (ORCPT ); Tue, 21 Dec 2021 16:25:35 -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=GhknQ87+Tv1LmYbdBKN1RfjxKncXbw6QuueDhACEINk=; b=V2sZySGRr+92Ls5vHoOgt7JRt07mwHUmsKLLshep1SnGHuSy45C5Ompy7WiBB3KA8ZQx XvsIli2wvIKSZHHvY3yhEu7C6cU8TGguVJjnBZhCPQSSSXfUQ7vstVAZZYczHSdIeq9cXj b1gOe1ecaW8qkWmTWP9toCU4KVSuxr8/Q4/wwgwmkJw2ficX8jzO3Po4YBYSxzR1B/if7V y4IzSKfGHcoQb/0miVlm3rHdt8YHhFcMxfwYAd8hipHTDuSHoOTDcaYYRR57fRfyI/uU+p beOkz4fTMB8ENRa0O9pefKWbNzE7ABalX21U3ry8wywzTHXzE2r2tAaD6/XqT3Xw== Received: by filterdrecv-75ff7b5ffb-v6hzv with SMTP id filterdrecv-75ff7b5ffb-v6hzv-1-61C2464E-39 2021-12-21 21:25:34.638731428 +0000 UTC m=+9587076.829192542 Received: from pearl.egauge.net (unknown) by geopod-ismtpd-3-1 (SG) with ESMTP id calMx7_ASpimB95p8AtDUQ Tue, 21 Dec 2021 21:25:34.496 +0000 (UTC) Received: by pearl.egauge.net (Postfix, from userid 1000) id B87E8700356; Tue, 21 Dec 2021 14:25:33 -0700 (MST) From: David Mosberger-Tang Subject: [PATCH v7 1/2] wilc1000: Add reset/enable GPIO support to SPI driver Date: Tue, 21 Dec 2021 21:25:34 +0000 (UTC) Message-Id: <20211221212531.4011609-2-davidm@egauge.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211221212531.4011609-1-davidm@egauge.net> References: <20211221212531.4011609-1-davidm@egauge.net> MIME-Version: 1.0 X-SG-EID: +kMxBqj35EdRUKoy8diX1j4AXmPtd302oan+iXZuF8m2Nw4HRW2irNspffT/khET6RJF6+Prbl0h/EtF1rRLvFd9EQKyTuRHwMkdmG4eA0s3wODjoobJqig+D+CRuoBhWy1To12klxdSmaM0Y0p99RxzMREPHR9HPN2xtoRYfRBdtUn8jtIhuAYGqsO+I/5FKCdB9OylmaAo1Rhc/Mi/7m/9R7dyLjPx5pSsdhQnXxRcb2le2m1DzPIrtJK2MofbSx9JuNti10QlmuxURiZU0A== 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 Reviewed-by: Claudiu Beznea --- drivers/net/wireless/microchip/wilc1000/spi.c | 62 ++++++++++++++++++- .../net/wireless/microchip/wilc1000/wlan.c | 2 +- 2 files changed, 60 insertions(+), 4 deletions(-) diff --git a/drivers/net/wireless/microchip/wilc1000/spi.c b/drivers/net/wireless/microchip/wilc1000/spi.c index 5ace9e3a56fc8..2c2ed4b09efd5 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" @@ -45,6 +46,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,50 @@ 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) { + /* assert ENABLE: */ + gpiod_set_value(gpios->enable, 1); + mdelay(5); + /* deassert RESET: */ + gpiod_set_value(gpios->reset, 0); + } else { + /* assert RESET: */ + gpiod_set_value(gpios->reset, 1); + /* deassert ENABLE: */ + gpiod_set_value(gpios->enable, 0); + } +} + static int wilc_bus_probe(struct spi_device *spi) { int ret; @@ -171,6 +220,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); @@ -983,9 +1036,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; } @@ -1006,6 +1060,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 3f339c2f46f11..1a37a49fe6477 100644 --- a/drivers/net/wireless/microchip/wilc1000/wlan.c +++ b/drivers/net/wireless/microchip/wilc1000/wlan.c @@ -1254,7 +1254,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 21 21:25:34 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: 526797 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 D3AF2C433F5 for ; Tue, 21 Dec 2021 21:25:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236475AbhLUVZn (ORCPT ); Tue, 21 Dec 2021 16:25:43 -0500 Received: from o1.ptr2625.egauge.net ([167.89.112.53]:46308 "EHLO o1.ptr2625.egauge.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236492AbhLUVZg (ORCPT ); Tue, 21 Dec 2021 16:25:36 -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=HO3cs/bAxWQRthzU1+hg6bvoy48ikxmGEMUA2a7K9+w=; b=XPKv87IqusJyRBZnCbyca+lIIiq5h7/v3a6+RxyOUMNdV4eKK2q81hAZ1i7H0YolOL3Y e0dR1to8dlZyvuREOjYPNX3Ycyydb9a0FYKopLtmLMOl5ukwdekgRD1uUkD3kYX9tjUkal ZZINs1qJ57Vnpu4DITTFqhWTqpfNks2X0vAu5E6NROaxdg7rJ9WnYr7YitRyqjJlcAAe2l OJj0jROJBW8EDLEgwbAJPUE03GHwRNo2FMg84ZSSFnkvvekghd46Y8T+jxRYu+DO4cYHSu EFpR9tWh6qYF2PhEhVDXrP3kPQnJAeDrCG69zngAuta3TDaMgDlT1aijqifp8s5A== Received: by filterdrecv-75ff7b5ffb-ktk29 with SMTP id filterdrecv-75ff7b5ffb-ktk29-1-61C2464E-50 2021-12-21 21:25:34.665138902 +0000 UTC m=+9587099.899018923 Received: from pearl.egauge.net (unknown) by geopod-ismtpd-1-1 (SG) with ESMTP id q1v2zsc-RY6pU-ZMXq5ZTQ Tue, 21 Dec 2021 21:25:34.472 +0000 (UTC) Received: by pearl.egauge.net (Postfix, from userid 1000) id BBA4A7003AA; Tue, 21 Dec 2021 14:25:33 -0700 (MST) From: David Mosberger-Tang Subject: [PATCH v7 2/2] wilc1000: Document enable-gpios and reset-gpios properties Date: Tue, 21 Dec 2021 21:25:34 +0000 (UTC) Message-Id: <20211221212531.4011609-3-davidm@egauge.net> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211221212531.4011609-1-davidm@egauge.net> References: <20211221212531.4011609-1-davidm@egauge.net> MIME-Version: 1.0 X-SG-EID: +kMxBqj35EdRUKoy8diX1j4AXmPtd302oan+iXZuF8m2Nw4HRW2irNspffT/khET6RJF6+Prbl0h/EtF1rRLvNkxAMBqlRWJnXBiCdBWzv9OKWVEpA8riEnI5pBRHA1T77DKWuv8JL15yLKrmob/ypa//Dem0v1MT4R9+fBmqTs/rRf3xVLmtVBaUJufRcrwY0Ul+SgYVWVl6NfDqe9n83xdLHqLTj3+BW41q6h/2iuTWWm+z34oERx3RdCq/llAzl9ywHjsTjSWIuEgLYCfvw== 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 , Rob Herring 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 Reviewed-by: Rob Herring --- .../net/wireless/microchip,wilc1000.yaml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.yaml b/Documentation/devicetree/bindings/net/wireless/microchip,wilc1000.yaml index 6c35682377e6d..60de78f1bc7b9 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 @@ -40,6 +55,8 @@ additionalProperties: false examples: - | + #include + spi { #address-cells = <1>; #size-cells = <0>; @@ -51,6 +68,8 @@ examples: interrupts = <27 0>; clocks = <&pck1>; clock-names = "rtc"; + enable-gpios = <&pioA 5 GPIO_ACTIVE_HIGH>; + reset-gpios = <&pioA 6 GPIO_ACTIVE_LOW>; }; };