[media] serial_ir: generate timeout
authorSean Young <sean@mess.org>
Fri, 2 Dec 2016 17:16:11 +0000 (15:16 -0200)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Mon, 30 Jan 2017 14:04:56 +0000 (12:04 -0200)
No timeout is generated by serial_ir since the port only generates
interrupts on edges. Some IR protocols like rc6 and rc5 need a trailing
space or timeout so they know there are no more bits coming.

Without it, the current key will only be reported once some more IR
occurs.

Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/rc/serial_ir.c

index 436bd58b5f05f252098ec433ac7305feb033034e..2cb6471641bde9d6c500e42d3c55bc4be3a52962 100644 (file)
@@ -137,6 +137,7 @@ struct serial_ir {
        ktime_t lastkt;
        struct rc_dev *rcdev;
        struct platform_device *pdev;
+       struct timer_list timeout_timer;
 
        unsigned int freq;
        unsigned int duty_cycle;
@@ -395,9 +396,14 @@ static irqreturn_t serial_ir_irq_handler(int i, void *blah)
                        frbwrite(data, !(dcd ^ sense));
                        serial_ir.lastkt = kt;
                        last_dcd = dcd;
-                       ir_raw_event_handle(serial_ir.rcdev);
                }
        } while (!(sinp(UART_IIR) & UART_IIR_NO_INT)); /* still pending ? */
+
+       mod_timer(&serial_ir.timeout_timer,
+                 jiffies + nsecs_to_jiffies(serial_ir.rcdev->timeout));
+
+       ir_raw_event_handle(serial_ir.rcdev);
+
        return IRQ_HANDLED;
 }
 
@@ -471,6 +477,16 @@ static int hardware_init_port(void)
        return 0;
 }
 
+static void serial_ir_timeout(unsigned long arg)
+{
+       DEFINE_IR_RAW_EVENT(ev);
+
+       ev.timeout = true;
+       ev.duration = serial_ir.rcdev->timeout;
+       ir_raw_event_store_with_filter(serial_ir.rcdev, &ev);
+       ir_raw_event_handle(serial_ir.rcdev);
+}
+
 static int serial_ir_probe(struct platform_device *dev)
 {
        int i, nlow, nhigh, result;
@@ -500,6 +516,9 @@ static int serial_ir_probe(struct platform_device *dev)
                return -EBUSY;
        }
 
+       setup_timer(&serial_ir.timeout_timer, serial_ir_timeout,
+                   (unsigned long)&serial_ir);
+
        result = hardware_init_port();
        if (result < 0)
                return result;
@@ -781,7 +800,9 @@ static int __init serial_ir_init_module(void)
        rcdev->allowed_protocols = RC_BIT_ALL;
        rcdev->driver_name = KBUILD_MODNAME;
        rcdev->map_name = RC_MAP_RC6_MCE;
+       rcdev->min_timeout = 1;
        rcdev->timeout = IR_DEFAULT_TIMEOUT;
+       rcdev->max_timeout = 10 * IR_DEFAULT_TIMEOUT;
        rcdev->rx_resolution = 250000;
 
        serial_ir.rcdev = rcdev;
@@ -797,6 +818,7 @@ serial_cleanup:
 
 static void __exit serial_ir_exit_module(void)
 {
+       del_timer_sync(&serial_ir.timeout_timer);
        rc_unregister_device(serial_ir.rcdev);
        serial_ir_exit();
 }