From patchwork Mon Aug 29 11:26:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Russell King (Oracle)" X-Patchwork-Id: 9303657 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 27FAF601C0 for ; Mon, 29 Aug 2016 11:31:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 19F832868E for ; Mon, 29 Aug 2016 11:31:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0E53628778; Mon, 29 Aug 2016 11:31:27 +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=-4.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EF1B42868E for ; Mon, 29 Aug 2016 11:31:25 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1beKlG-0003Sr-0T; Mon, 29 Aug 2016 11:29:54 +0000 Received: from pandora.armlinux.org.uk ([2001:4d48:ad52:3201:214:fdff:fe10:1be6]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1beKiP-0001TB-U1 for linux-arm-kernel@lists.infradead.org; Mon, 29 Aug 2016 11:27:02 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2014; h=Date:Sender:Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Subject:Cc:To:From:References:In-Reply-To; bh=r1Fd9BqNITg8QZ0/i2BYpfMlI+XOrDZ88COQ5nPYpRo=; b=ZhgdQwci7OwbETBDEaeApJ1aTokgEkVTT9YAKFJZkde9ljeSMXS2RDmt/AV3n7fwE6xbtObcKHoMyrxVxnz2Y+Cu/MdVrl078JPqJ+ZIosmy75cEH2lWmKwIXjNc16rmNwsICl5a7n5z2z8vZ6VdsXpykRyb6aXHgUknJC9qoc4=; Received: from e0022681537dd.dyn.armlinux.org.uk ([fd8f:7570:feb6:1:222:68ff:fe15:37dd]:58878 helo=rmk-PC.armlinux.org.uk) by pandora.armlinux.org.uk with esmtpsa (TLSv1:AES128-SHA:128) (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1beKhl-0004Gk-DP; Mon, 29 Aug 2016 12:26:17 +0100 Received: from rmk by rmk-PC.armlinux.org.uk with local (Exim 4.82_1-5b7a7c0-XX) (envelope-from ) id 1beKhj-0001Gz-HL; Mon, 29 Aug 2016 12:26:15 +0100 In-Reply-To: <20160829112540.GF1041@n2100.armlinux.org.uk> References: <20160829112540.GF1041@n2100.armlinux.org.uk> From: Russell King To: dmaengine@vger.kernel.org, linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org Subject: [PATCH 3/8] net: irda/sa1100_ir: add gpiod APIs for controlling IrDA transceiver MIME-Version: 1.0 Content-Disposition: inline Message-Id: Date: Mon, 29 Aug 2016 12:26:15 +0100 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160829_042658_901402_B16A40BB X-CRM114-Status: GOOD ( 15.52 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Vinod Koul , Dan Williams , Samuel Ortiz Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add GPIO support using the gpiod APIs for controlling the IrDA transceiver modes (FIR vs SIR), power and range. Signed-off-by: Russell King --- drivers/net/irda/sa1100_ir.c | 58 ++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 56 insertions(+), 2 deletions(-) diff --git a/drivers/net/irda/sa1100_ir.c b/drivers/net/irda/sa1100_ir.c index 7bc9c2955d4b..25c63c9ff33c 100644 --- a/drivers/net/irda/sa1100_ir.c +++ b/drivers/net/irda/sa1100_ir.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include #include @@ -72,6 +73,10 @@ struct sa1100_irda { int (*tx_start)(struct sk_buff *, struct net_device *, struct sa1100_irda *); irqreturn_t (*irq)(struct net_device *, struct sa1100_irda *); + + struct gpio_desc *fsel_gpio; + struct gpio_desc *pwr_gpio; + struct gpio_desc *md_gpio[2]; }; static int sa1100_irda_set_speed(struct sa1100_irda *, int); @@ -574,6 +579,8 @@ static int sa1100_irda_set_speed(struct sa1100_irda *si, int speed) if (si->pdata->set_speed) si->pdata->set_speed(si->dev, speed); + if (si->fsel_gpio) + gpiod_set_value(si->fsel_gpio, 0); si->speed = speed; si->tx_start = sa1100_irda_sir_tx_start; @@ -600,6 +607,8 @@ static int sa1100_irda_set_speed(struct sa1100_irda *si, int speed) if (si->pdata->set_speed) si->pdata->set_speed(si->dev, speed); + if (si->fsel_gpio) + gpiod_set_value(si->fsel_gpio, 1); sa1100_irda_rx_alloc(si); sa1100_irda_rx_dma_start(si); @@ -629,9 +638,19 @@ static int __sa1100_irda_set_power(struct sa1100_irda *si, unsigned int state) { int ret = 0; - if (si->pdata->set_power) + if (si->pdata->set_power) { ret = si->pdata->set_power(si->dev, state); - return ret; + } else if (si->pwr_gpio) { + gpiod_set_value_cansleep(si->pwr_gpio, state); + } else if (si->md_gpio[0] && si->md_gpio[1]) { + int vals[2]; + + vals[0] = state < 2; + vals[1] = state == 1 || state == 2; + + gpiod_set_array_value_cansleep(2, si->md_gpio, vals); + } + return 0; } static inline int @@ -914,6 +933,21 @@ static const struct net_device_ops sa1100_irda_netdev_ops = { .ndo_do_ioctl = sa1100_irda_ioctl, }; +static int sa1100_irda_get_gpio(struct device *dev, struct gpio_desc **descp, + const char *name, enum gpiod_flags flags) +{ + struct gpio_desc *desc = devm_gpiod_get_optional(dev, name, flags); + + if (IS_ERR(desc)) { + int err = PTR_ERR(desc); + dev_err(dev, "unable to get %s gpio: %d\n", name, err); + return err; + } + + *descp = desc; + return 0; +} + static int sa1100_irda_probe(struct platform_device *pdev) { struct net_device *dev; @@ -950,6 +984,26 @@ static int sa1100_irda_probe(struct platform_device *pdev) si->dev = &pdev->dev; si->pdata = pdev->dev.platform_data; + err = sa1100_irda_get_gpio(&pdev->dev, &si->fsel_gpio, "ir-fsel", + GPIOD_OUT_LOW); + if (err) + goto err_mem_5; + + err = sa1100_irda_get_gpio(&pdev->dev, &si->pwr_gpio, "ir-power", + GPIOD_OUT_LOW); + if (err) + goto err_mem_5; + + err = sa1100_irda_get_gpio(&pdev->dev, &si->md_gpio[0], "ir-md0", + GPIOD_OUT_HIGH); + if (err) + goto err_mem_5; + + err = sa1100_irda_get_gpio(&pdev->dev, &si->md_gpio[1], "ir-md1", + GPIOD_OUT_LOW); + if (err) + goto err_mem_5; + sg_init_table(&si->dma_rx.sg, 1); sg_init_table(&si->dma_tx.sg, 1);