Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

[media] rc: gpio-ir-recv: add timeout on idle

Many decoders require a trailing space (period without IR illumination)
to be delivered before completing a decode.

Since the gpio-ir-recv driver only delivers events on gpio transitions,
a single IR symbol (caused by a quick touch on an IR remote) will not
be properly decoded without the use of a timer to flush the tail end
state of the IR receiver.

This patch initializes and uses a timer and the timeout field of rcdev
to complete the stream and allow decode.

The timeout can be overridden through the use of the LIRC_SET_REC_TIMEOUT
ioctl.

Signed-off-by: Eric Nelson <eric@nelint.com>
Acked-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>

authored by

Eric Nelson and committed by
Mauro Carvalho Chehab
3fb136f3 c8e1bbc5

+22
+22
drivers/media/rc/gpio-ir-recv.c
··· 30 30 struct rc_dev *rcdev; 31 31 int gpio_nr; 32 32 bool active_low; 33 + struct timer_list flush_timer; 33 34 }; 34 35 35 36 #ifdef CONFIG_OF ··· 94 93 if (rc < 0) 95 94 goto err_get_value; 96 95 96 + mod_timer(&gpio_dev->flush_timer, 97 + jiffies + nsecs_to_jiffies(gpio_dev->rcdev->timeout)); 98 + 97 99 ir_raw_event_handle(gpio_dev->rcdev); 98 100 99 101 err_get_value: 100 102 return IRQ_HANDLED; 103 + } 104 + 105 + static void flush_timer(unsigned long arg) 106 + { 107 + struct gpio_rc_dev *gpio_dev = (struct gpio_rc_dev *)arg; 108 + DEFINE_IR_RAW_EVENT(ev); 109 + 110 + ev.timeout = true; 111 + ev.duration = gpio_dev->rcdev->timeout; 112 + ir_raw_event_store(gpio_dev->rcdev, &ev); 113 + ir_raw_event_handle(gpio_dev->rcdev); 101 114 } 102 115 103 116 static int gpio_ir_recv_probe(struct platform_device *pdev) ··· 159 144 rcdev->input_id.version = 0x0100; 160 145 rcdev->dev.parent = &pdev->dev; 161 146 rcdev->driver_name = GPIO_IR_DRIVER_NAME; 147 + rcdev->min_timeout = 0; 148 + rcdev->timeout = IR_DEFAULT_TIMEOUT; 149 + rcdev->max_timeout = 10 * IR_DEFAULT_TIMEOUT; 162 150 if (pdata->allowed_protos) 163 151 rcdev->allowed_protocols = pdata->allowed_protos; 164 152 else ··· 171 153 gpio_dev->rcdev = rcdev; 172 154 gpio_dev->gpio_nr = pdata->gpio_nr; 173 155 gpio_dev->active_low = pdata->active_low; 156 + 157 + setup_timer(&gpio_dev->flush_timer, flush_timer, 158 + (unsigned long)gpio_dev); 174 159 175 160 rc = gpio_request(pdata->gpio_nr, "gpio-ir-recv"); 176 161 if (rc < 0) ··· 217 196 struct gpio_rc_dev *gpio_dev = platform_get_drvdata(pdev); 218 197 219 198 free_irq(gpio_to_irq(gpio_dev->gpio_nr), gpio_dev); 199 + del_timer_sync(&gpio_dev->flush_timer); 220 200 rc_unregister_device(gpio_dev->rcdev); 221 201 gpio_free(gpio_dev->gpio_nr); 222 202 kfree(gpio_dev);