media: lirc: use the correct carrier for scancode transmit
authorSean Young <sean@mess.org>
Sat, 25 Feb 2017 11:51:30 +0000 (06:51 -0500)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Thu, 14 Dec 2017 15:35:15 +0000 (10:35 -0500)
If the lirc device supports it, set the carrier for the protocol.

Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
12 files changed:
drivers/media/rc/ir-jvc-decoder.c
drivers/media/rc/ir-lirc-codec.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/rc-core-priv.h
drivers/media/rc/rc-ir-raw.c
include/media/rc-core.h

index 22c8aee3df4fee44ec294da322e0afc66c57651c..c03c776cfa54594983e0381fd655afc637940bd0 100644 (file)
@@ -212,6 +212,7 @@ static struct ir_raw_handler jvc_handler = {
        .protocols      = RC_PROTO_BIT_JVC,
        .decode         = ir_jvc_decode,
        .encode         = ir_jvc_encode,
+       .carrier        = 38000,
 };
 
 static int __init ir_jvc_decode_init(void)
index 0a3ec693d290ad633ab08f156693242c88cebb35..bdacbadac4165d245a51926bb77a10db3ee3bb80 100644 (file)
@@ -122,6 +122,17 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
        if (!lirc)
                return -EFAULT;
 
+       dev = lirc->dev;
+       if (!dev) {
+               ret = -EFAULT;
+               goto out;
+       }
+
+       if (!dev->tx_ir) {
+               ret = -EINVAL;
+               goto out;
+       }
+
        if (lirc->send_mode == LIRC_MODE_SCANCODE) {
                struct lirc_scancode scan;
 
@@ -154,6 +165,13 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
                for (i = 0; i < count; i++)
                        /* Convert from NS to US */
                        txbuf[i] = DIV_ROUND_UP(raw[i].duration, 1000);
+
+               if (dev->s_tx_carrier) {
+                       int carrier = ir_raw_encode_carrier(scan.rc_proto);
+
+                       if (carrier > 0)
+                               dev->s_tx_carrier(dev, carrier);
+               }
        } else {
                if (n < sizeof(unsigned int) || n % sizeof(unsigned int))
                        return -EINVAL;
@@ -167,17 +185,6 @@ static ssize_t ir_lirc_transmit_ir(struct file *file, const char __user *buf,
                        return PTR_ERR(txbuf);
        }
 
-       dev = lirc->dev;
-       if (!dev) {
-               ret = -EFAULT;
-               goto out;
-       }
-
-       if (!dev->tx_ir) {
-               ret = -EINVAL;
-               goto out;
-       }
-
        for (i = 0; i < count; i++) {
                if (txbuf[i] > IR_MAX_DURATION / 1000 - duration || !txbuf[i]) {
                        ret = -EINVAL;
index 69d6264d54e6ed4d46d5415ce67ad24c5808af12..dbc6e00bace2dd240511b60bc69badfe59aa81d1 100644 (file)
@@ -473,6 +473,7 @@ static struct ir_raw_handler mce_kbd_handler = {
        .encode         = ir_mce_kbd_encode,
        .raw_register   = ir_mce_kbd_register,
        .raw_unregister = ir_mce_kbd_unregister,
+       .carrier        = 36000,
 };
 
 static int __init ir_mce_kbd_decode_init(void)
index 22eed9505244ffe6582efafd7f98b26b281aafe7..31d7bafe7bdabad409106c14a394175bb08bd4b9 100644 (file)
@@ -254,6 +254,7 @@ static struct ir_raw_handler nec_handler = {
                                                        RC_PROTO_BIT_NEC32,
        .decode         = ir_nec_decode,
        .encode         = ir_nec_encode,
+       .carrier        = 38000,
 };
 
 static int __init ir_nec_decode_init(void)
index cbff3e26d481cae0a4ea2ddece5a077f6cbae26a..f589d99245eb7522b52494749cd92565247ec6fb 100644 (file)
@@ -273,6 +273,7 @@ static struct ir_raw_handler rc5_handler = {
                                                        RC_PROTO_BIT_RC5_SZ,
        .decode         = ir_rc5_decode,
        .encode         = ir_rc5_encode,
+       .carrier        = 36000,
 };
 
 static int __init ir_rc5_decode_init(void)
index 5d0d2fe3b7a7fd5f174a6337aa97ba2c3bdb39c8..665025303c281c96ae78750ca8826e73f1195d29 100644 (file)
@@ -408,6 +408,7 @@ static struct ir_raw_handler rc6_handler = {
                          RC_PROTO_BIT_RC6_MCE,
        .decode         = ir_rc6_decode,
        .encode         = ir_rc6_encode,
+       .carrier        = 36000,
 };
 
 static int __init ir_rc6_decode_init(void)
index 2138f0e9472d74ec000a686e391177458fa6588d..ded39cdfc6efc82b5b4930bc9b4ac94f418f62d7 100644 (file)
@@ -209,6 +209,7 @@ static struct ir_raw_handler sanyo_handler = {
        .protocols      = RC_PROTO_BIT_SANYO,
        .decode         = ir_sanyo_decode,
        .encode         = ir_sanyo_encode,
+       .carrier        = 38000,
 };
 
 static int __init ir_sanyo_decode_init(void)
index 7140dd6160eee2c4de9e7b4448c961117f9e9a0d..df296991906c4a267304119b8a256201359ed935 100644 (file)
@@ -226,6 +226,7 @@ static struct ir_raw_handler sharp_handler = {
        .protocols      = RC_PROTO_BIT_SHARP,
        .decode         = ir_sharp_decode,
        .encode         = ir_sharp_encode,
+       .carrier        = 38000,
 };
 
 static int __init ir_sharp_decode_init(void)
index a47ced763031d2fcf20c15de9c4a837a7a1da101..e4bcff21c0252f52196d0febb3c2c958c26ee524 100644 (file)
@@ -221,6 +221,7 @@ static struct ir_raw_handler sony_handler = {
                                                        RC_PROTO_BIT_SONY20,
        .decode         = ir_sony_decode,
        .encode         = ir_sony_encode,
+       .carrier        = 40000,
 };
 
 static int __init ir_sony_decode_init(void)
index d10fc998e1db4aac4e5b50ed8f0b115d1e332f24..2fab4069c023aafb4b2d923dba701011cc3f9fea 100644 (file)
@@ -19,6 +19,7 @@ struct ir_raw_handler {
        int (*decode)(struct rc_dev *dev, struct ir_raw_event event);
        int (*encode)(enum rc_proto protocol, u32 scancode,
                      struct ir_raw_event *events, unsigned int max);
+       u32 carrier;
 
        /* These two should only be used by the lirc decoder */
        int (*raw_register)(struct rc_dev *dev);
index 0616eee564a89dfad8e7d8f0abfee2d774d0fa78..208db8a5adff5f92b562eee0c6f43d2add3a2d9d 100644 (file)
@@ -484,6 +484,36 @@ static void edge_handle(struct timer_list *t)
        ir_raw_event_handle(dev);
 }
 
+/**
+ * ir_raw_encode_carrier() - Get carrier used for protocol
+ *
+ * @protocol:          protocol
+ *
+ * Attempts to find the carrier for the specified protocol
+ *
+ * Returns:    The carrier in Hz
+ *             -EINVAL if the protocol is invalid, or if no
+ *             compatible encoder was found.
+ */
+int ir_raw_encode_carrier(enum rc_proto protocol)
+{
+       struct ir_raw_handler *handler;
+       int ret = -EINVAL;
+       u64 mask = BIT_ULL(protocol);
+
+       mutex_lock(&ir_raw_handler_lock);
+       list_for_each_entry(handler, &ir_raw_handler_list, list) {
+               if (handler->protocols & mask && handler->encode) {
+                       ret = handler->carrier;
+                       break;
+               }
+       }
+       mutex_unlock(&ir_raw_handler_lock);
+
+       return ret;
+}
+EXPORT_SYMBOL(ir_raw_encode_carrier);
+
 /*
  * Used to (un)register raw event clients
  */
index 314a1edb6189bf47c722723511cf5ede6d7c9233..ca48632ec8e2ae18bf7fecc215cd1cee01303150 100644 (file)
@@ -309,6 +309,7 @@ int ir_raw_event_store_with_filter(struct rc_dev *dev,
 void ir_raw_event_set_idle(struct rc_dev *dev, bool idle);
 int ir_raw_encode_scancode(enum rc_proto protocol, u32 scancode,
                           struct ir_raw_event *events, unsigned int max);
+int ir_raw_encode_carrier(enum rc_proto protocol);
 
 static inline void ir_raw_event_reset(struct rc_dev *dev)
 {