From: Ladislav Michl <ladis@linux-mips.org>
To: linux-media@vger.kernel.org
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
Sean Young <sean@mess.org>, Andi Shyti <andi.shyti@samsung.com>
Subject: [PATCH 10/10] media: rc: gpio-ir-recv: use gpiolib API
Date: Wed, 6 Sep 2017 10:15:30 +0200 [thread overview]
Message-ID: <20170906081530.ya3rs56vfathcvh7@lenoch> (raw)
In-Reply-To: <20170906080748.wgxbmunfsu33bd6x@lenoch>
Use of gpiolib API simplifies driver a bit.
Signed-off-by: Ladislav Michl <ladis@linux-mips.org>
---
drivers/media/rc/Kconfig | 1 +
drivers/media/rc/gpio-ir-recv.c | 64 +++++++++++++++++------------------------
2 files changed, 27 insertions(+), 38 deletions(-)
diff --git a/drivers/media/rc/Kconfig b/drivers/media/rc/Kconfig
index 5e83b76495f7..852bf639f1ca 100644
--- a/drivers/media/rc/Kconfig
+++ b/drivers/media/rc/Kconfig
@@ -382,6 +382,7 @@ config RC_LOOPBACK
config IR_GPIO_CIR
tristate "GPIO IR remote control"
depends on RC_CORE
+ depends on (OF && GPIOLIB) || COMPILE_TEST
---help---
Say Y if you want to use GPIO based IR Receiver.
diff --git a/drivers/media/rc/gpio-ir-recv.c b/drivers/media/rc/gpio-ir-recv.c
index 77498d0c8970..c87f085226f2 100644
--- a/drivers/media/rc/gpio-ir-recv.c
+++ b/drivers/media/rc/gpio-ir-recv.c
@@ -26,39 +26,34 @@
struct gpio_rc_dev {
struct rc_dev *rcdev;
- int gpio_nr;
- bool active_low;
+ struct gpio_desc *gpiod;
+ int irq;
struct timer_list flush_timer;
};
static irqreturn_t gpio_ir_recv_irq(int irq, void *dev_id)
{
+ int val;
struct gpio_rc_dev *gpio_dev = dev_id;
- int gval;
- int rc = 0;
enum raw_event_type type = IR_SPACE;
- gval = gpio_get_value(gpio_dev->gpio_nr);
+ val = gpiod_get_value(gpio_dev->gpiod);
+ if (val < 0)
+ goto err;
- if (gval < 0)
- goto err_get_value;
-
- if (gpio_dev->active_low)
- gval = !gval;
-
- if (gval == 1)
+ if (val)
type = IR_PULSE;
- rc = ir_raw_event_store_edge(gpio_dev->rcdev, type);
- if (rc < 0)
- goto err_get_value;
+ val = ir_raw_event_store_edge(gpio_dev->rcdev, type);
+ if (val < 0)
+ goto err;
mod_timer(&gpio_dev->flush_timer,
jiffies + nsecs_to_jiffies(gpio_dev->rcdev->timeout));
ir_raw_event_handle(gpio_dev->rcdev);
-err_get_value:
+err:
return IRQ_HANDLED;
}
@@ -76,7 +71,6 @@ static void flush_timer(unsigned long arg)
static int gpio_ir_recv_probe(struct platform_device *pdev)
{
int rc;
- enum of_gpio_flags flags;
struct rc_dev *rcdev;
struct gpio_rc_dev *gpio_dev;
struct device *dev = &pdev->dev;
@@ -89,15 +83,17 @@ static int gpio_ir_recv_probe(struct platform_device *pdev)
if (!gpio_dev)
return -ENOMEM;
- rc = of_get_gpio_flags(np, 0, &flags);
- if (rc < 0) {
+ gpio_dev->gpiod = devm_gpiod_get(dev, NULL, GPIOD_IN);
+ if (IS_ERR(gpio_dev->gpiod)) {
+ rc = PTR_ERR(gpio_dev->gpiod);
+ /* Just try again if this happens */
if (rc != -EPROBE_DEFER)
- dev_err(dev, "Failed to get gpio flags (%d)\n", rc);
+ dev_err(dev, "error getting gpio (%d)\n", rc);
return rc;
}
-
- gpio_dev->gpio_nr = rc;
- gpio_dev->active_low = (flags & OF_GPIO_ACTIVE_LOW);
+ gpio_dev->irq = gpiod_to_irq(gpio_dev->gpiod);
+ if (gpio_dev->irq < 0)
+ return gpio_dev->irq;
rcdev = devm_rc_allocate_device(dev, RC_DRIVER_IR_RAW);
if (!rcdev)
@@ -125,11 +121,6 @@ static int gpio_ir_recv_probe(struct platform_device *pdev)
setup_timer(&gpio_dev->flush_timer, flush_timer,
(unsigned long)gpio_dev);
- rc = devm_gpio_request_one(dev, gpio_dev->gpio_nr, GPIOF_DIR_IN,
- "gpio-ir-recv");
- if (rc < 0)
- return rc;
-
rc = devm_rc_register_device(dev, rcdev);
if (rc < 0) {
dev_err(dev, "failed to register rc device\n");
@@ -138,8 +129,7 @@ static int gpio_ir_recv_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, gpio_dev);
- return devm_request_irq(dev, gpio_to_irq(gpio_dev->gpio_nr),
- gpio_ir_recv_irq,
+ return devm_request_irq(dev, gpio_dev->irq, gpio_ir_recv_irq,
IRQF_TRIGGER_FALLING | IRQF_TRIGGER_RISING,
"gpio-ir-recv-irq", gpio_dev);
}
@@ -155,26 +145,24 @@ static int gpio_ir_recv_remove(struct platform_device *pdev)
#ifdef CONFIG_PM
static int gpio_ir_recv_suspend(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct gpio_rc_dev *gpio_dev = platform_get_drvdata(pdev);
+ struct gpio_rc_dev *gpio_dev = dev_get_drvdata(dev);
if (device_may_wakeup(dev))
- enable_irq_wake(gpio_to_irq(gpio_dev->gpio_nr));
+ enable_irq_wake(gpio_dev->irq);
else
- disable_irq(gpio_to_irq(gpio_dev->gpio_nr));
+ disable_irq(gpio_dev->irq);
return 0;
}
static int gpio_ir_recv_resume(struct device *dev)
{
- struct platform_device *pdev = to_platform_device(dev);
- struct gpio_rc_dev *gpio_dev = platform_get_drvdata(pdev);
+ struct gpio_rc_dev *gpio_dev = dev_get_drvdata(dev);
if (device_may_wakeup(dev))
- disable_irq_wake(gpio_to_irq(gpio_dev->gpio_nr));
+ disable_irq_wake(gpio_dev->irq);
else
- enable_irq(gpio_to_irq(gpio_dev->gpio_nr));
+ enable_irq(gpio_dev->irq);
return 0;
}
--
2.11.0
prev parent reply other threads:[~2017-09-06 8:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-09-06 8:07 [PATCH 00/10] media: rc: gpio-ir-recv: driver update Ladislav Michl
2017-09-06 8:08 ` [PATCH 01/10] media: rc: gpio-ir-recv: use helper vaiable to acess device info Ladislav Michl
2017-09-06 8:09 ` [PATCH 02/10] media: rc: gpio-ir-recv: use devm_kzalloc Ladislav Michl
2017-09-06 8:10 ` [PATCH 03/10] media: rc: gpio-ir-recv: use devm_rc_allocate_device Ladislav Michl
2017-09-06 8:10 ` [PATCH 04/10] media: rc: gpio-ir-recv: use devm_gpio_request_one Ladislav Michl
2017-09-06 8:11 ` [PATCH 05/10] media: rc: gpio-ir-recv: use devm_rc_register_device Ladislav Michl
2017-09-06 8:12 ` [PATCH 06/10] media: rc: gpio-ir-recv: do not allow threaded interrupt handler Ladislav Michl
2017-09-06 8:12 ` [PATCH 07/10] media: rc: gpio-ir-recv: use devm_request_irq Ladislav Michl
2017-09-06 8:13 ` [PATCH 08/10] media: rc: gpio-ir-recv: use KBUILD_MODNAME Ladislav Michl
2017-09-06 8:14 ` [PATCH 09/10] media: rc: gpio-ir-recv: remove gpio_ir_recv_platform_data Ladislav Michl
2017-09-06 8:15 ` Ladislav Michl [this message]
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=20170906081530.ya3rs56vfathcvh7@lenoch \
--to=ladis@linux-mips.org \
--cc=andi.shyti@samsung.com \
--cc=linux-media@vger.kernel.org \
--cc=mchehab@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox