linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sean Young <sean@mess.org>
To: linux-media@vger.kernel.org
Cc: "James Hogan" <james@albanarts.com>,
	"Antti Seppälä" <a.seppala@gmail.com>,
	"David Härdeman" <david@hardeman.nu>
Subject: [PATCH v4 05/13] [media] rc: rc-ir-raw: Add scancode encoder callback
Date: Tue,  6 Dec 2016 10:19:13 +0000	[thread overview]
Message-ID: <649b9b8c136cc1df0e4e084853f60e68ebb949ee.1481019109.git.sean@mess.org> (raw)
In-Reply-To: <cover.1481019109.git.sean@mess.org>
In-Reply-To: <cover.1481019109.git.sean@mess.org>

From: James Hogan <james@albanarts.com>

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 filter 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>
---
 drivers/media/rc/rc-core-priv.h |  3 +++
 drivers/media/rc/rc-ir-raw.c    | 37 +++++++++++++++++++++++++++++++++++++
 include/media/rc-core.h         |  3 +++
 3 files changed, 43 insertions(+)

diff --git a/drivers/media/rc/rc-core-priv.h b/drivers/media/rc/rc-core-priv.h
index 585d5e5..98cc0cf 100644
--- a/drivers/media/rc/rc-core-priv.h
+++ b/drivers/media/rc/rc-core-priv.h
@@ -28,6 +28,9 @@ 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,
+		      const struct rc_scancode_filter *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);
diff --git a/drivers/media/rc/rc-ir-raw.c b/drivers/media/rc/rc-ir-raw.c
index 171bdba..1b229ef 100644
--- a/drivers/media/rc/rc-ir-raw.c
+++ b/drivers/media/rc/rc-ir-raw.c
@@ -249,6 +249,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,
+			   const struct rc_scancode_filter *scancode,
+			   struct ir_raw_event *events, unsigned int max)
+{
+	struct ir_raw_handler *handler;
+	int ret = -EINVAL;
+
+	mutex_lock(&ir_raw_handler_lock);
+	list_for_each_entry(handler, &ir_raw_handler_list, list) {
+		if (handler->protocols & (1 << protocol) && 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
  */
diff --git a/include/media/rc-core.h b/include/media/rc-core.h
index 3c34cac..0a72e17 100644
--- a/include/media/rc-core.h
+++ b/include/media/rc-core.h
@@ -307,6 +307,9 @@ 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,
+			   const struct rc_scancode_filter *scancode,
+			   struct ir_raw_event *events, unsigned int max);
 
 static inline void ir_raw_event_reset(struct rc_dev *dev)
 {
-- 
2.9.3


  parent reply	other threads:[~2016-12-06 10:19 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-06 10:19 [PATCH v4 00/13] Use sysfs filter for winbond & nuvoton wakeup Sean Young
2016-12-06 10:19 ` [PATCH v4 01/13] [media] rc: change wakeup_protocols to list all protocol variants Sean Young
2016-12-06 10:19 ` [PATCH v4 02/13] [media] rc: Add scancode validation Sean Young
2016-12-06 10:19 ` [PATCH v4 03/13] [media] winbond-cir: use sysfs wakeup filter Sean Young
2016-12-06 10:19 ` [PATCH v4 04/13] [media] rc: raw IR drivers cannot handle cec, unknown or other Sean Young
2016-12-06 10:19 ` Sean Young [this message]
2016-12-06 10:19 ` [PATCH v4 06/13] [media] rc: rc-ir-raw: Add Manchester encoder (phase encoder) helper Sean Young
2016-12-06 10:19 ` [PATCH v4 07/13] [media] rc: rc-ir-raw: Add pulse-distance modulation helper Sean Young
2016-12-06 10:19 ` [PATCH v4 08/13] [media] rc: ir-rc5-decoder: Add encode capability Sean Young
2016-12-06 10:19 ` [PATCH v4 09/13] [media] rc: ir-rc6-decoder: " Sean Young
2016-12-06 10:19 ` [PATCH v4 10/13] [media] rc: ir-nec-decoder: " Sean Young
2016-12-06 10:19 ` [PATCH v4 11/13] [media] rc: rc-core: Add support for encode_wakeup drivers Sean Young
2016-12-06 10:19 ` [PATCH v4 12/13] [media] rc: rc-loopback: Add loopback of filter scancodes Sean Young
2016-12-06 10:19 ` [PATCH v4 13/13] [media] rc: nuvoton-cir: Add support wakeup via sysfs filter callback Sean Young
2016-12-07 10:45 ` [PATCH v4 00/13] Use sysfs filter for winbond & nuvoton wakeup Sean Young

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=649b9b8c136cc1df0e4e084853f60e68ebb949ee.1481019109.git.sean@mess.org \
    --to=sean@mess.org \
    --cc=a.seppala@gmail.com \
    --cc=david@hardeman.nu \
    --cc=james@albanarts.com \
    --cc=linux-media@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).