0378-media-rc-gpio-ir-recv-add-timeout-on-idle.patch 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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
  5. Many decoders require a trailing space (period without IR illumination)
  6. to be delivered before completing a decode.
  7. Since the gpio-ir-recv driver only delivers events on gpio transitions,
  8. a single IR symbol (caused by a quick touch on an IR remote) will not
  9. be properly decoded without the use of a timer to flush the tail end
  10. state of the IR receiver.
  11. This patch initializes and uses a timer and the timeout field of rcdev
  12. to complete the stream and allow decode.
  13. The timeout can be overridden through the use of the LIRC_SET_REC_TIMEOUT
  14. ioctl.
  15. Signed-off-by: Eric Nelson <eric@nelint.com>
  16. Acked-by: Sean Young <sean@mess.org>
  17. Signed-off-by: Mauro Carvalho Chehab <mchehab@osg.samsung.com>
  18. ---
  19. drivers/media/rc/gpio-ir-recv.c | 22 ++++++++++++++++++++++
  20. 1 file changed, 22 insertions(+)
  21. --- a/drivers/media/rc/gpio-ir-recv.c
  22. +++ b/drivers/media/rc/gpio-ir-recv.c
  23. @@ -30,6 +30,7 @@ struct gpio_rc_dev {
  24. struct rc_dev *rcdev;
  25. int gpio_nr;
  26. bool active_low;
  27. + struct timer_list flush_timer;
  28. };
  29. #ifdef CONFIG_OF
  30. @@ -93,12 +94,26 @@ static irqreturn_t gpio_ir_recv_irq(int
  31. if (rc < 0)
  32. goto err_get_value;
  33. + mod_timer(&gpio_dev->flush_timer,
  34. + jiffies + nsecs_to_jiffies(gpio_dev->rcdev->timeout));
  35. +
  36. ir_raw_event_handle(gpio_dev->rcdev);
  37. err_get_value:
  38. return IRQ_HANDLED;
  39. }
  40. +static void flush_timer(unsigned long arg)
  41. +{
  42. + struct gpio_rc_dev *gpio_dev = (struct gpio_rc_dev *)arg;
  43. + DEFINE_IR_RAW_EVENT(ev);
  44. +
  45. + ev.timeout = true;
  46. + ev.duration = gpio_dev->rcdev->timeout;
  47. + ir_raw_event_store(gpio_dev->rcdev, &ev);
  48. + ir_raw_event_handle(gpio_dev->rcdev);
  49. +}
  50. +
  51. static int gpio_ir_recv_probe(struct platform_device *pdev)
  52. {
  53. struct gpio_rc_dev *gpio_dev;
  54. @@ -144,6 +159,9 @@ static int gpio_ir_recv_probe(struct pla
  55. rcdev->input_id.version = 0x0100;
  56. rcdev->dev.parent = &pdev->dev;
  57. rcdev->driver_name = GPIO_IR_DRIVER_NAME;
  58. + rcdev->min_timeout = 0;
  59. + rcdev->timeout = IR_DEFAULT_TIMEOUT;
  60. + rcdev->max_timeout = 10 * IR_DEFAULT_TIMEOUT;
  61. if (pdata->allowed_protos)
  62. rcdev->allowed_protocols = pdata->allowed_protos;
  63. else
  64. @@ -154,6 +172,9 @@ static int gpio_ir_recv_probe(struct pla
  65. gpio_dev->gpio_nr = pdata->gpio_nr;
  66. gpio_dev->active_low = pdata->active_low;
  67. + setup_timer(&gpio_dev->flush_timer, flush_timer,
  68. + (unsigned long)gpio_dev);
  69. +
  70. rc = gpio_request(pdata->gpio_nr, "gpio-ir-recv");
  71. if (rc < 0)
  72. goto err_gpio_request;
  73. @@ -196,6 +217,7 @@ static int gpio_ir_recv_remove(struct pl
  74. struct gpio_rc_dev *gpio_dev = platform_get_drvdata(pdev);
  75. free_irq(gpio_to_irq(gpio_dev->gpio_nr), gpio_dev);
  76. + del_timer_sync(&gpio_dev->flush_timer);
  77. rc_unregister_device(gpio_dev->rcdev);
  78. gpio_free(gpio_dev->gpio_nr);
  79. kfree(gpio_dev);