OSDN Git Service

[media] rc: rc-ir-raw: Add scancode encoder callback
authorJames Hogan <james@albanarts.com>
Tue, 31 Mar 2015 17:48:06 +0000 (14:48 -0300)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Mon, 30 Jan 2017 15:46:55 +0000 (13:46 -0200)
Add a callback to raw ir handlers for encoding and modulating a scancode
to a set of raw events. This could be used for transmit, or for
converting a wakeup scancode to a form that is more suitable for raw
hardware wake up filters.

Signed-off-by: James Hogan <james@albanarts.com>
Signed-off-by: Antti Seppälä <a.seppala@gmail.com>
Signed-off-by: Sean Young <sean@mess.org>
Cc: David Härdeman <david@hardeman.nu>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/rc/rc-core-priv.h
drivers/media/rc/rc-ir-raw.c
include/media/rc-core.h

index 577128a..18f9326 100644 (file)
@@ -27,6 +27,8 @@ struct ir_raw_handler {
 
        u64 protocols; /* which are handled by this handler */
        int (*decode)(struct rc_dev *dev, struct ir_raw_event event);
+       int (*encode)(enum rc_type protocol, u32 scancode,
+                     struct ir_raw_event *events, unsigned int max);
 
        /* These two should only be used by the lirc decoder */
        int (*raw_register)(struct rc_dev *dev);
index 68dfe81..d1c9cbb 100644 (file)
@@ -238,6 +238,43 @@ static void ir_raw_disable_protocols(struct rc_dev *dev, u64 protocols)
        mutex_unlock(&dev->lock);
 }
 
+/**
+ * ir_raw_encode_scancode() - Encode a scancode as raw events
+ *
+ * @protocol:          protocol
+ * @scancode:          scancode filter describing a single scancode
+ * @events:            array of raw events to write into
+ * @max:               max number of raw events
+ *
+ * Attempts to encode the scancode as raw events.
+ *
+ * Returns:    The number of events written.
+ *             -ENOBUFS if there isn't enough space in the array to fit the
+ *             encoding. In this case all @max events will have been written.
+ *             -EINVAL if the scancode is ambiguous or invalid, or if no
+ *             compatible encoder was found.
+ */
+int ir_raw_encode_scancode(enum rc_type protocol, u32 scancode,
+                          struct ir_raw_event *events, unsigned int max)
+{
+       struct ir_raw_handler *handler;
+       int ret = -EINVAL;
+       u64 mask = 1ULL << 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->encode(protocol, scancode, events, max);
+                       if (ret >= 0 || ret == -ENOBUFS)
+                               break;
+               }
+       }
+       mutex_unlock(&ir_raw_handler_lock);
+
+       return ret;
+}
+EXPORT_SYMBOL(ir_raw_encode_scancode);
+
 /*
  * Used to (un)register raw event clients
  */
index af40093..62d69b1 100644 (file)
@@ -306,6 +306,8 @@ int ir_raw_event_store_edge(struct rc_dev *dev, enum raw_event_type type);
 int ir_raw_event_store_with_filter(struct rc_dev *dev,
                                struct ir_raw_event *ev);
 void ir_raw_event_set_idle(struct rc_dev *dev, bool idle);
+int ir_raw_encode_scancode(enum rc_type protocol, u32 scancode,
+                          struct ir_raw_event *events, unsigned int max);
 
 static inline void ir_raw_event_reset(struct rc_dev *dev)
 {