All of lore.kernel.org
 help / color / mirror / Atom feed
From: Matthias Reichl <hias@horus.com>
To: Sean Young <sean@mess.org>
Cc: linux-media@vger.kernel.org
Subject: [PATCH] [media] rc: gpio-ir-tx: switch to gpiod, fix inverted polarity
Date: Thu, 3 Aug 2017 12:08:38 +0200	[thread overview]
Message-ID: <20170803100837.r7pxmyvpyflg552i@camel2.lan> (raw)
In-Reply-To: <20170731202908.hk7dpclt5m5lhpdd@gofer.mess.org>

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 <hias@horus.com>
---

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 <linux/kernel.h>
 #include <linux/module.h>
-#include <linux/gpio.h>
+#include <linux/gpio/consumer.h>
 #include <linux/delay.h>
 #include <linux/slab.h>
 #include <linux/of.h>
-#include <linux/of_gpio.h>
 #include <linux/platform_device.h>
 #include <media/rc-core.h>
 
@@ -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");
-- 
2.11.0

  reply	other threads:[~2017-08-03 10:08 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-07  9:51 [PATCH v2 0/6] Generic Raspberry Pi IR transmitters Sean Young
2017-07-07  9:51 ` [PATCH v2 1/6] [media] rc-core: rename input_name to device_name Sean Young
2017-07-07  9:51 ` [PATCH v2 2/6] [media] rc: mce kbd decoder not needed for IR TX drivers Sean Young
2017-07-07  9:51 ` [PATCH v2 3/6] [media] rc: gpio-ir-tx: add new driver Sean Young
2017-07-21 14:12   ` Matthias Reichl
2017-07-21 19:51     ` Matthias Reichl
2017-07-31 20:29     ` Sean Young
2017-08-03 10:08       ` Matthias Reichl [this message]
2017-07-07  9:52 ` [PATCH v2 4/6] [media] rc: pwm-ir-tx: " Sean Young
2017-07-07 16:48   ` Pavel Machek
2017-07-21 21:12   ` Matthias Reichl
     [not found] ` <cover.1499419624.git.sean-hENCXIMQXOg@public.gmane.org>
2017-07-07  9:52   ` [PATCH v2 5/6] [media] dt-bindings: gpio-ir-tx: add support for GPIO IR Transmitter Sean Young
2017-07-07  9:52     ` Sean Young
2017-07-10 15:05     ` Rob Herring
2017-07-10 15:10       ` Sean Young
2017-07-10 15:10         ` Sean Young
     [not found]         ` <20170710151016.5iaokchdejxozrte-3XSxi2G4b3iXFJAUJl40Xg@public.gmane.org>
2017-07-11 11:52           ` [PATCH v3] " Sean Young
2017-07-11 11:52             ` Sean Young
2017-07-11 18:45             ` Rob Herring
     [not found]   ` <580c648de65344e9316ff153ba316efd4d527f12.1499419624.git.sean-hENCXIMQXOg@public.gmane.org>
2017-07-07  9:52     ` [PATCH v2 6/6] [media] dt-bindings: pwm-ir-tx: Add support for PWM " Sean Young
2017-07-07  9:52       ` Sean Young
     [not found]       ` <e18cec2d3f66cd59d8683cb07fc59e3a2086cf6e.1499419624.git.sean-hENCXIMQXOg@public.gmane.org>
2017-07-10 15:13         ` Rob Herring
2017-07-10 15:13           ` Rob Herring

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170803100837.r7pxmyvpyflg552i@camel2.lan \
    --to=hias@horus.com \
    --cc=linux-media@vger.kernel.org \
    --cc=sean@mess.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.