1 From 0cb8bcc4bbdb393d9f8ffa3b81eb09c4f1628be9 Mon Sep 17 00:00:00 2001
2 From: Eric Nelson <eric@nelint.com>
3 Date: Wed, 23 Sep 2015 11:07:08 -0300
4 Subject: [PATCH] [media] rc: gpio-ir-recv: add timeout on idle
6 Many decoders require a trailing space (period without IR illumination)
7 to be delivered before completing a decode.
9 Since the gpio-ir-recv driver only delivers events on gpio transitions,
10 a single IR symbol (caused by a quick touch on an IR remote) will not
11 be properly decoded without the use of a timer to flush the tail end
12 state of the IR receiver.
14 This patch initializes and uses a timer and the timeout field of rcdev
15 to complete the stream and allow decode.
17 The timeout can be overridden through the use of the LIRC_SET_REC_TIMEOUT
20 Signed-off-by: Eric Nelson <eric@nelint.com>
21 Acked-by: Sean Young <sean@mess.org>
22 Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
24 drivers/media/rc/gpio-ir-recv.c | 22 ++++++++++++++++++++++
25 1 file changed, 22 insertions(+)
27 --- a/drivers/media/rc/gpio-ir-recv.c
28 +++ b/drivers/media/rc/gpio-ir-recv.c
29 @@ -30,6 +30,7 @@ struct gpio_rc_dev {
33 + struct timer_list flush_timer;
37 @@ -93,12 +94,26 @@ static irqreturn_t gpio_ir_recv_irq(int
41 + mod_timer(&gpio_dev->flush_timer,
42 + jiffies + nsecs_to_jiffies(gpio_dev->rcdev->timeout));
44 ir_raw_event_handle(gpio_dev->rcdev);
50 +static void flush_timer(unsigned long arg)
52 + struct gpio_rc_dev *gpio_dev = (struct gpio_rc_dev *)arg;
53 + DEFINE_IR_RAW_EVENT(ev);
56 + ev.duration = gpio_dev->rcdev->timeout;
57 + ir_raw_event_store(gpio_dev->rcdev, &ev);
58 + ir_raw_event_handle(gpio_dev->rcdev);
61 static int gpio_ir_recv_probe(struct platform_device *pdev)
63 struct gpio_rc_dev *gpio_dev;
64 @@ -144,6 +159,9 @@ static int gpio_ir_recv_probe(struct pla
65 rcdev->input_id.version = 0x0100;
66 rcdev->dev.parent = &pdev->dev;
67 rcdev->driver_name = GPIO_IR_DRIVER_NAME;
68 + rcdev->min_timeout = 0;
69 + rcdev->timeout = IR_DEFAULT_TIMEOUT;
70 + rcdev->max_timeout = 10 * IR_DEFAULT_TIMEOUT;
71 if (pdata->allowed_protos)
72 rcdev->allowed_protocols = pdata->allowed_protos;
74 @@ -154,6 +172,9 @@ static int gpio_ir_recv_probe(struct pla
75 gpio_dev->gpio_nr = pdata->gpio_nr;
76 gpio_dev->active_low = pdata->active_low;
78 + setup_timer(&gpio_dev->flush_timer, flush_timer,
79 + (unsigned long)gpio_dev);
81 rc = gpio_request(pdata->gpio_nr, "gpio-ir-recv");
83 goto err_gpio_request;
84 @@ -196,6 +217,7 @@ static int gpio_ir_recv_remove(struct pl
85 struct gpio_rc_dev *gpio_dev = platform_get_drvdata(pdev);
87 free_irq(gpio_to_irq(gpio_dev->gpio_nr), gpio_dev);
88 + del_timer_sync(&gpio_dev->flush_timer);
89 rc_unregister_device(gpio_dev->rcdev);
90 gpio_free(gpio_dev->gpio_nr);