diff mbox

[RFC,4/4] DEBUG: rc: img-ir: raw: Add loopback on s_filter

Message ID 1391716763-2689-5-git-send-email-james.hogan@imgtec.com (mailing list archive)
State New, archived
Headers show

Commit Message

James Hogan Feb. 6, 2014, 7:59 p.m. UTC
Purely for the purposes of debugging the raw IR encode, add the s_filter
callback to the img-ir-raw driver, which instead of setting the filter
just feeds it back through the input device so that it can be verified.
---
 drivers/media/rc/img-ir/img-ir-raw.c | 30 ++++++++++++++++++++++++++++++
 1 file changed, 30 insertions(+)
diff mbox

Patch

diff --git a/drivers/media/rc/img-ir/img-ir-raw.c b/drivers/media/rc/img-ir/img-ir-raw.c
index cfb01d9..272767a 100644
--- a/drivers/media/rc/img-ir/img-ir-raw.c
+++ b/drivers/media/rc/img-ir/img-ir-raw.c
@@ -7,6 +7,7 @@ 
  * signal edges are reported and decoded by generic software decoders.
  */
 
+#include <linux/slab.h>
 #include <linux/spinlock.h>
 #include <media/rc-core.h>
 #include "img-ir.h"
@@ -95,6 +96,34 @@  void img_ir_setup_raw(struct img_ir_priv *priv)
 	spin_unlock_irq(&priv->lock);
 }
 
+static int img_ir_raw_set_filter(struct rc_dev *dev, enum rc_filter_type type,
+				 struct rc_scancode_filter *sc_filter)
+{
+	struct ir_raw_event *raw;
+	int ret;
+	int i;
+
+	/* fine to disable filter */
+	if (!sc_filter->mask)
+		return 0;
+	
+	raw = kmalloc(512 * sizeof(*raw), GFP_KERNEL);
+	ret = ir_raw_encode_scancode(dev->enabled_protocols, sc_filter, raw,
+				     512);
+	if (ret >= 0) {
+		/* loop back the scancode just for fun! */
+		for (i = 0; i < ret; ++i)
+			ir_raw_event_store(dev, &raw[i]);
+		ir_raw_event_handle(dev);
+
+		ret = 0;
+	}
+
+	kfree(raw);
+
+	return ret;
+}
+
 int img_ir_probe_raw(struct img_ir_priv *priv)
 {
 	struct img_ir_priv_raw *raw = &priv->raw;
@@ -114,6 +143,7 @@  int img_ir_probe_raw(struct img_ir_priv *priv)
 	rdev->map_name = RC_MAP_EMPTY;
 	rdev->input_name = "IMG Infrared Decoder Raw";
 	rdev->driver_type = RC_DRIVER_IR_RAW;
+	rdev->s_filter = img_ir_raw_set_filter;
 
 	/* Register raw decoder */
 	error = rc_register_device(rdev);