From patchwork Thu Aug 3 10:08:38 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matthias Reichl X-Patchwork-Id: 9878667 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 E8E2160360 for ; Thu, 3 Aug 2017 10:09:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E353828721 for ; Thu, 3 Aug 2017 10:09:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D52D72872F; Thu, 3 Aug 2017 10:09:10 +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=-6.9 required=2.0 tests=BAYES_00,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 C6E6C2872F for ; Thu, 3 Aug 2017 10:09:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752470AbdHCKIo (ORCPT ); Thu, 3 Aug 2017 06:08:44 -0400 Received: from mail.horus.com ([78.46.148.228]:38732 "EHLO mail.horus.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752440AbdHCKIk (ORCPT ); Thu, 3 Aug 2017 06:08:40 -0400 Received: from [192.168.1.20] (193-81-117-14.adsl.highway.telekom.at [193.81.117.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "E-Mail Matthias Reichl", Issuer "HiassofT CA 2014" (verified OK)) by mail.horus.com (Postfix) with ESMTPS id 060B86408D; Thu, 3 Aug 2017 12:08:39 +0200 (CEST) Received: by camel2.lan (Postfix, from userid 1000) id 1FCB11C7298; Thu, 3 Aug 2017 12:08:38 +0200 (CEST) Date: Thu, 3 Aug 2017 12:08:38 +0200 From: Matthias Reichl To: Sean Young Cc: linux-media@vger.kernel.org Subject: [PATCH] [media] rc: gpio-ir-tx: switch to gpiod, fix inverted polarity Message-ID: <20170803100837.r7pxmyvpyflg552i@camel2.lan> References: <92a66fd9852c3143d5726eb3869d58e28d841c84.1499419624.git.sean@mess.org> <20170721141245.3uv55fqxa557dmnt@camel2.lan> <20170731202908.hk7dpclt5m5lhpdd@gofer.mess.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20170731202908.hk7dpclt5m5lhpdd@gofer.mess.org> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Manual handling of gpio output polarity was inverted. Switch to using gpiod, this allows us to simplify the code, delegate polarity handling to gpiod and remove the buggy local polarity handling code. Signed-off-by: Matthias Reichl --- This patch is against [PATCH v2 3/6] [media] rc: gpio-ir-tx: add new driver. Feel free to squash these two patches into one for v3. so long, Hias drivers/media/rc/gpio-ir-tx.c | 41 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 28 deletions(-) diff --git a/drivers/media/rc/gpio-ir-tx.c b/drivers/media/rc/gpio-ir-tx.c index 7a5371dbb360..ca6834d09467 100644 --- a/drivers/media/rc/gpio-ir-tx.c +++ b/drivers/media/rc/gpio-ir-tx.c @@ -13,11 +13,10 @@ #include #include -#include +#include #include #include #include -#include #include #include @@ -25,8 +24,7 @@ #define DEVICE_NAME "GPIO Bit Banging IR Transmitter" struct gpio_ir { - int gpio_nr; - bool active_low; + struct gpio_desc *gpio; unsigned int carrier; unsigned int duty_cycle; /* we need a spinlock to hold the cpu while transmitting */ @@ -101,14 +99,12 @@ static int gpio_ir_tx(struct rc_dev *dev, unsigned int *txbuf, ktime_t last = ktime_add_us(edge, txbuf[i]); while (ktime_get() < last) { - gpio_set_value(gpio_ir->gpio_nr, - gpio_ir->active_low); + gpiod_set_value(gpio_ir->gpio, 1); edge += pulse; delta = edge - ktime_get(); if (delta > 0) ndelay(delta); - gpio_set_value(gpio_ir->gpio_nr, - !gpio_ir->active_low); + gpiod_set_value(gpio_ir->gpio, 0); edge += space; delta = edge - ktime_get(); if (delta > 0) @@ -128,16 +124,7 @@ static int gpio_ir_tx_probe(struct platform_device *pdev) { struct gpio_ir *gpio_ir; struct rc_dev *rcdev; - enum of_gpio_flags flags; - int rc, gpio; - - gpio = of_get_gpio_flags(pdev->dev.of_node, 0, &flags); - if (gpio < 0) { - if (gpio != -EPROBE_DEFER) - dev_err(&pdev->dev, "Failed to get gpio flags (%d)\n", - gpio); - return -EINVAL; - } + int rc; gpio_ir = devm_kmalloc(&pdev->dev, sizeof(*gpio_ir), GFP_KERNEL); if (!gpio_ir) @@ -147,6 +134,14 @@ static int gpio_ir_tx_probe(struct platform_device *pdev) if (!rcdev) return -ENOMEM; + gpio_ir->gpio = devm_gpiod_get(&pdev->dev, NULL, GPIOD_OUT_LOW); + if (IS_ERR(gpio_ir->gpio)) { + if (PTR_ERR(gpio_ir->gpio) != -EPROBE_DEFER) + dev_err(&pdev->dev, "Failed to get gpio (%ld)\n", + PTR_ERR(gpio_ir->gpio)); + return PTR_ERR(gpio_ir->gpio); + } + rcdev->priv = gpio_ir; rcdev->driver_name = DRIVER_NAME; rcdev->device_name = DEVICE_NAME; @@ -154,20 +149,10 @@ static int gpio_ir_tx_probe(struct platform_device *pdev) rcdev->s_tx_duty_cycle = gpio_ir_tx_set_duty_cycle; rcdev->s_tx_carrier = gpio_ir_tx_set_carrier; - gpio_ir->gpio_nr = gpio; - gpio_ir->active_low = (flags & OF_GPIO_ACTIVE_LOW) != 0; gpio_ir->carrier = 38000; gpio_ir->duty_cycle = 50; spin_lock_init(&gpio_ir->lock); - rc = devm_gpio_request(&pdev->dev, gpio, "gpio-ir-tx"); - if (rc < 0) - return rc; - - rc = gpio_direction_output(gpio, !gpio_ir->active_low); - if (rc < 0) - return rc; - rc = devm_rc_register_device(&pdev->dev, rcdev); if (rc < 0) dev_err(&pdev->dev, "failed to register rc device\n");