media: rc: set timeout to smallest value required by enabled protocols
authorSean Young <sean@mess.org>
Fri, 23 Mar 2018 20:47:37 +0000 (16:47 -0400)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Fri, 20 Apr 2018 13:14:31 +0000 (09:14 -0400)
The longer the IR timeout, the longer the rc device waits until delivering
the trailing space. So, by reducing this timeout, we reduce the delay for
the last scancode to be delivered.

Note that the lirc daemon disables all protocols, in which case we revert
back to the default value.

Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
13 files changed:
drivers/media/rc/ir-imon-decoder.c
drivers/media/rc/ir-jvc-decoder.c
drivers/media/rc/ir-mce_kbd-decoder.c
drivers/media/rc/ir-nec-decoder.c
drivers/media/rc/ir-rc5-decoder.c
drivers/media/rc/ir-rc6-decoder.c
drivers/media/rc/ir-sanyo-decoder.c
drivers/media/rc/ir-sharp-decoder.c
drivers/media/rc/ir-sony-decoder.c
drivers/media/rc/ir-xmp-decoder.c
drivers/media/rc/rc-core-priv.h
drivers/media/rc/rc-ir-raw.c
drivers/media/rc/rc-main.c

index a1ff06a26542a76626754470ebe576268c783fa8..52ea3b2fda74f67bce8a9bb619fa70bcedf0987f 100644 (file)
@@ -170,6 +170,7 @@ static struct ir_raw_handler imon_handler = {
        .decode         = ir_imon_decode,
        .encode         = ir_imon_encode,
        .carrier        = 38000,
+       .min_timeout    = IMON_UNIT * IMON_BITS * 2,
 };
 
 static int __init ir_imon_decode_init(void)
index 8cb68ae43282388423f6fe49159ee64a4982e401..5706cfe60027fefe32622ccac6fee549de8dfd0e 100644 (file)
@@ -213,6 +213,7 @@ static struct ir_raw_handler jvc_handler = {
        .decode         = ir_jvc_decode,
        .encode         = ir_jvc_encode,
        .carrier        = 38000,
+       .min_timeout    = JVC_TRAILER_SPACE,
 };
 
 static int __init ir_jvc_decode_init(void)
index c110984ca6716c3701790f033ee2582348a691e0..05f2a36769c0137a845fbfb03d3d28943e2739cd 100644 (file)
@@ -475,6 +475,7 @@ static struct ir_raw_handler mce_kbd_handler = {
        .raw_register   = ir_mce_kbd_register,
        .raw_unregister = ir_mce_kbd_unregister,
        .carrier        = 36000,
+       .min_timeout    = MCIR2_MAX_LEN + MCIR2_UNIT / 2,
 };
 
 static int __init ir_mce_kbd_decode_init(void)
index 21647b809e6f1ea541ad39b9edd303307594197b..6a8973ae36842c6a670ec220f6a90e942b96437a 100644 (file)
@@ -253,6 +253,7 @@ static struct ir_raw_handler nec_handler = {
        .decode         = ir_nec_decode,
        .encode         = ir_nec_encode,
        .carrier        = 38000,
+       .min_timeout    = NEC_TRAILER_SPACE,
 };
 
 static int __init ir_nec_decode_init(void)
index 74d3b859c3a2d4765669fedd17670dc993af5cfa..cbfaadbee8fa7d0b171ea472a117115483787218 100644 (file)
@@ -274,6 +274,7 @@ static struct ir_raw_handler rc5_handler = {
        .decode         = ir_rc5_decode,
        .encode         = ir_rc5_encode,
        .carrier        = 36000,
+       .min_timeout    = RC5_TRAILER,
 };
 
 static int __init ir_rc5_decode_init(void)
index 8314da32453fbd1ae97874bb725e4a2431fd9797..66e07109f6fcc53b133e5710b219843a4b3f3d03 100644 (file)
@@ -394,6 +394,7 @@ static struct ir_raw_handler rc6_handler = {
        .decode         = ir_rc6_decode,
        .encode         = ir_rc6_encode,
        .carrier        = 36000,
+       .min_timeout    = RC6_SUFFIX_SPACE,
 };
 
 static int __init ir_rc6_decode_init(void)
index 4efe6db5376acad37c00e65075f9a25266046c85..dd6ee1e339d617f01b8f05d40e280b2d4e7b1f2b 100644 (file)
@@ -210,6 +210,7 @@ static struct ir_raw_handler sanyo_handler = {
        .decode         = ir_sanyo_decode,
        .encode         = ir_sanyo_encode,
        .carrier        = 38000,
+       .min_timeout    = SANYO_TRAILER_SPACE,
 };
 
 static int __init ir_sanyo_decode_init(void)
index 6a38c50566a4c145c7de9411eee2fd96c42e60d8..f96e0c992eed3ee287af6d800a6ebb131de9bdfd 100644 (file)
@@ -226,6 +226,7 @@ static struct ir_raw_handler sharp_handler = {
        .decode         = ir_sharp_decode,
        .encode         = ir_sharp_encode,
        .carrier        = 38000,
+       .min_timeout    = SHARP_ECHO_SPACE + SHARP_ECHO_SPACE / 4,
 };
 
 static int __init ir_sharp_decode_init(void)
index 6764ec9de646f7169d4057e9b6ff6110be035bf9..5065c081238d95a545126f094287adc2305da45c 100644 (file)
@@ -224,6 +224,7 @@ static struct ir_raw_handler sony_handler = {
        .decode         = ir_sony_decode,
        .encode         = ir_sony_encode,
        .carrier        = 40000,
+       .min_timeout    = SONY_TRAILER_SPACE,
 };
 
 static int __init ir_sony_decode_init(void)
index 58b47af1a763759b943792c1d760b3a4425bd1d2..c965f51df1c1a2477531752ef33bcf85b71c6c84 100644 (file)
@@ -199,6 +199,7 @@ static int ir_xmp_decode(struct rc_dev *dev, struct ir_raw_event ev)
 static struct ir_raw_handler xmp_handler = {
        .protocols      = RC_PROTO_BIT_XMP,
        .decode         = ir_xmp_decode,
+       .min_timeout    = XMP_TRAILER_SPACE,
 };
 
 static int __init ir_xmp_decode_init(void)
index e0e6a17460f631bf9948e0e26201a5e27c682392..f78551344ecad2cd3958a0332d53f467553f9bf9 100644 (file)
@@ -37,6 +37,7 @@ struct ir_raw_handler {
        int (*encode)(enum rc_proto protocol, u32 scancode,
                      struct ir_raw_event *events, unsigned int max);
        u32 carrier;
+       u32 min_timeout;
 
        /* These two should only be used by the mce kbd decoder */
        int (*raw_register)(struct rc_dev *dev);
index 374f83105a234d873e7024e0650c078191efe9f8..22e44c8f16fdefc88b5d0e607bad9e1b637eaa45 100644 (file)
@@ -233,7 +233,36 @@ ir_raw_get_allowed_protocols(void)
 
 static int change_protocol(struct rc_dev *dev, u64 *rc_proto)
 {
-       /* the caller will update dev->enabled_protocols */
+       struct ir_raw_handler *handler;
+       u32 timeout = 0;
+
+       if (!dev->max_timeout)
+               return 0;
+
+       mutex_lock(&ir_raw_handler_lock);
+       list_for_each_entry(handler, &ir_raw_handler_list, list) {
+               if (handler->protocols & *rc_proto) {
+                       if (timeout < handler->min_timeout)
+                               timeout = handler->min_timeout;
+               }
+       }
+       mutex_unlock(&ir_raw_handler_lock);
+
+       if (timeout == 0)
+               timeout = IR_DEFAULT_TIMEOUT;
+       else
+               timeout += MS_TO_NS(10);
+
+       if (timeout < dev->min_timeout)
+               timeout = dev->min_timeout;
+       else if (timeout > dev->max_timeout)
+               timeout = dev->max_timeout;
+
+       if (dev->s_timeout)
+               dev->s_timeout(dev, timeout);
+       else
+               dev->timeout = timeout;
+
        return 0;
 }
 
index b67be33bd62f5a872fa322663245a532ceb9b006..6a720e9c7aa83d17a2a5ac20dfa07a4c7f2e8c2d 100644 (file)
@@ -1241,6 +1241,9 @@ static ssize_t store_protocols(struct device *device,
        if (rc < 0)
                goto out;
 
+       if (dev->driver_type == RC_DRIVER_IR_RAW)
+               ir_raw_load_modules(&new_protocols);
+
        rc = dev->change_protocol(dev, &new_protocols);
        if (rc < 0) {
                dev_dbg(&dev->dev, "Error setting protocols to 0x%llx\n",
@@ -1248,9 +1251,6 @@ static ssize_t store_protocols(struct device *device,
                goto out;
        }
 
-       if (dev->driver_type == RC_DRIVER_IR_RAW)
-               ir_raw_load_modules(&new_protocols);
-
        if (new_protocols != old_protocols) {
                *current_protocols = new_protocols;
                dev_dbg(&dev->dev, "Protocols changed to 0x%llx\n",
@@ -1735,6 +1735,9 @@ static int rc_prepare_rx_device(struct rc_dev *dev)
        if (dev->driver_type == RC_DRIVER_SCANCODE && !dev->change_protocol)
                dev->enabled_protocols = dev->allowed_protocols;
 
+       if (dev->driver_type == RC_DRIVER_IR_RAW)
+               ir_raw_load_modules(&rc_proto);
+
        if (dev->change_protocol) {
                rc = dev->change_protocol(dev, &rc_proto);
                if (rc < 0)
@@ -1742,9 +1745,6 @@ static int rc_prepare_rx_device(struct rc_dev *dev)
                dev->enabled_protocols = rc_proto;
        }
 
-       if (dev->driver_type == RC_DRIVER_IR_RAW)
-               ir_raw_load_modules(&rc_proto);
-
        set_bit(EV_KEY, dev->input_dev->evbit);
        set_bit(EV_REP, dev->input_dev->evbit);
        set_bit(EV_MSC, dev->input_dev->evbit);