From patchwork Tue Nov 15 13:18:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: smlng X-Patchwork-Id: 9429779 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 6819360484 for ; Tue, 15 Nov 2016 13:18:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53F06287D1 for ; Tue, 15 Nov 2016 13:18:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 48ADD28810; Tue, 15 Nov 2016 13:18:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A9687287D1 for ; Tue, 15 Nov 2016 13:18:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934255AbcKONSg (ORCPT ); Tue, 15 Nov 2016 08:18:36 -0500 Received: from mo4-p00-ob.smtp.rzone.de ([81.169.146.162]:32367 "EHLO mo4-p00-ob.smtp.rzone.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932539AbcKONSf (ORCPT ); Tue, 15 Nov 2016 08:18:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; t=1479215912; l=4079; s=domk; d=mlng.net; h=Date:Subject:To:From; bh=d8hXrZ1qQKQEJWUFKguqrMMVXDPEo9IwSHuakyi2oww=; b=iMXTP6sXhaGfuC24XdbrTkFBTgJ2oa1oWVphiQA+/4gYwHhX8vzgC86MK3Uj4cHnQ4 bKzzaqoLC8YsPxtAxJT4IKcJpTAoPVzw4tF5yqB6hR6dg68/d/GdLd1C1ixuFowoHSZx HOsHlN7OHo6i/acjWBW1LjijDIdsEa4UrV66U= X-RZG-AUTH: :P0wJeU6vNfGjFOQoHOeSMdzhLW81CLKmKIrJajXoQ7Ju4AQdoNc8 X-RZG-CLASS-ID: mo00 Received: from Sebastians-Air.lan ([141.22.28.250]) by smtp.strato.de (RZmta 39.9 AUTH) with ESMTPSA id c02d87sAFDIV38v (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (curve secp521r1 with 521 ECDH bits, eq. 15360 bits RSA)) (Client did not present a certificate) for ; Tue, 15 Nov 2016 14:18:31 +0100 (CET) From: smlng To: linux-wpan@vger.kernel.org Subject: [PATCH bluetooth-next 1/1] drivers: mrf24j40: add support for reset and wake pin Date: Tue, 15 Nov 2016 14:18:30 +0100 Message-Id: <20161115131830.90383-1-s@mlng.net> X-Mailer: git-send-email 2.10.2 Sender: linux-wpan-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-wpan@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The mrf24j40 requires a high on the RESET pin, otherwise it will reset itself over and over. With this patch the driver will ensure that a GPIO (if connected) will be set to high during device initialization. Details: - set reset to high on driver probe - make pin configurable via device tree (overlay) - similar to the at86rf233 driver - update devicetree documentation Signed-off-by: smlng --- .../bindings/net/ieee802154/mrf24j40.txt | 4 ++ drivers/net/ieee802154/mrf24j40.c | 59 ++++++++++++++++++++-- include/linux/spi/mrf24j40.h | 9 ++++ 3 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 include/linux/spi/mrf24j40.h diff --git a/Documentation/devicetree/bindings/net/ieee802154/mrf24j40.txt b/Documentation/devicetree/bindings/net/ieee802154/mrf24j40.txt index a4ed2efb5b73..2fabba041e48 100644 --- a/Documentation/devicetree/bindings/net/ieee802154/mrf24j40.txt +++ b/Documentation/devicetree/bindings/net/ieee802154/mrf24j40.txt @@ -9,6 +9,10 @@ Required properties: - reg: the chipselect index - interrupts: the interrupt generated by the device. +Optional properties: + - reset-gpio: GPIO spec for the rstn pin + - wake-gpio: GPIO spec for the wake pin + Example: mrf24j40ma@0 { diff --git a/drivers/net/ieee802154/mrf24j40.c b/drivers/net/ieee802154/mrf24j40.c index 7b131f8e4093..275b54d6bad3 100644 --- a/drivers/net/ieee802154/mrf24j40.c +++ b/drivers/net/ieee802154/mrf24j40.c @@ -16,9 +16,11 @@ */ #include +#include #include #include #include +#include #include #include #include @@ -1276,16 +1278,67 @@ static void mrf24j40_phy_setup(struct mrf24j40 *devrec) } } +static int +mrf24j40_get_pdata(struct spi_device *spi, int *rstn, int *wake) +{ + struct mrf24j40_platform_data *pdata = spi->dev.platform_data; + + if (!IS_ENABLED(CONFIG_OF) || !spi->dev.of_node) { + if (!pdata) + return -ENOENT; + + *rstn = pdata->rstn; + *wake = pdata->wake; + return 0; + } + + *rstn = of_get_named_gpio(spi->dev.of_node, "reset-gpio", 0); + *wake = of_get_named_gpio(spi->dev.of_node, "wake-gpio", 0); + return 0; +} + static int mrf24j40_probe(struct spi_device *spi) { int ret = -ENOMEM, irq_type; + int rc, rstn, wake; struct ieee802154_hw *hw; struct mrf24j40 *devrec; - dev_info(&spi->dev, "probe(). IRQ: %d\n", spi->irq); + if (!spi->irq) { + dev_err(&spi->dev, "no IRQ specified\n"); + return -EINVAL; + } - /* Register with the 802154 subsystem */ + rc = mrf24j40_get_pdata(spi, &rstn, &wake); + if (rc < 0) { + dev_err(&spi->dev, "failed to parse platform_data: %d\n", rc); + return rc; + } + + if (gpio_is_valid(rstn)) { + rc = devm_gpio_request_one(&spi->dev, rstn, + GPIOF_OUT_INIT_HIGH, "rstn"); + if (rc) + return rc; + } + if (gpio_is_valid(wake)) { + rc = devm_gpio_request_one(&spi->dev, wake, + GPIOF_OUT_INIT_LOW, "wake"); + if (rc) + return rc; + } + + /* Reset */ + if (gpio_is_valid(rstn)) { + udelay(1); + gpio_set_value(rstn, 0); + udelay(1); + gpio_set_value(rstn, 1); + usleep_range(120, 240); + } + + /* Register with the 802154 subsystem */ hw = ieee802154_alloc_hw(sizeof(*devrec), &mrf24j40_ops); if (!hw) goto err_ret; @@ -1350,7 +1403,7 @@ static int mrf24j40_probe(struct spi_device *spi) goto err_register_device; } - dev_dbg(printdev(devrec), "registered mrf24j40\n"); + dev_info(printdev(devrec), "registered mrf24j40\n"); ret = ieee802154_register_hw(devrec->hw); if (ret) goto err_register_device; diff --git a/include/linux/spi/mrf24j40.h b/include/linux/spi/mrf24j40.h new file mode 100644 index 000000000000..60810194cae9 --- /dev/null +++ b/include/linux/spi/mrf24j40.h @@ -0,0 +1,9 @@ +#ifndef _SPI_MRF24J40_H +#define _SPI_MRF24J40_H + +struct mrf24j40_platform_data { + int rstn; + int wake; +}; + +#endif /* _SPI_MRF24J40_H */