[media] rc: img-ir: add Sharp decoder module
authorJames Hogan <james.hogan@imgtec.com>
Fri, 28 Feb 2014 23:28:59 +0000 (20:28 -0300)
committerMauro Carvalho Chehab <m.chehab@samsung.com>
Tue, 11 Mar 2014 18:47:55 +0000 (15:47 -0300)
Add an img-ir module for decoding the Sharp infrared protocol.

Signed-off-by: James Hogan <james.hogan@imgtec.com>
Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
drivers/media/rc/img-ir/Kconfig
drivers/media/rc/img-ir/Makefile
drivers/media/rc/img-ir/img-ir-hw.c
drivers/media/rc/img-ir/img-ir-sharp.c [new file with mode: 0644]

index ab365778b5d270cd39cffbaff1907eb5b1462842..48627f9741be3b1428cc26ccc4343919177cad78 100644 (file)
@@ -45,3 +45,10 @@ config IR_IMG_SONY
        help
           Say Y here to enable support for the Sony protocol in the ImgTec
           infrared decoder block.
+
+config IR_IMG_SHARP
+       bool "Sharp protocol support"
+       depends on IR_IMG_HW
+       help
+          Say Y here to enable support for the Sharp protocol in the ImgTec
+          infrared decoder block.
index 978c0c6713abd28ecc15f906511a7c947247c7b6..792a3c4bc38f119cecb4ee15f242ba6b194a65be 100644 (file)
@@ -4,6 +4,7 @@ img-ir-$(CONFIG_IR_IMG_HW)      += img-ir-hw.o
 img-ir-$(CONFIG_IR_IMG_NEC)    += img-ir-nec.o
 img-ir-$(CONFIG_IR_IMG_JVC)    += img-ir-jvc.o
 img-ir-$(CONFIG_IR_IMG_SONY)   += img-ir-sony.o
+img-ir-$(CONFIG_IR_IMG_SHARP)  += img-ir-sharp.o
 img-ir-objs                    := $(img-ir-y)
 
 obj-$(CONFIG_IR_IMG)           += img-ir.o
index 0d4f9211f9f272d0fec28f6ab5b2fc72df97903b..9931dfaeb6adf7bf56cf6d417ad35f39ab005de1 100644 (file)
@@ -23,6 +23,7 @@ static DEFINE_SPINLOCK(img_ir_decoders_lock);
 extern struct img_ir_decoder img_ir_nec;
 extern struct img_ir_decoder img_ir_jvc;
 extern struct img_ir_decoder img_ir_sony;
+extern struct img_ir_decoder img_ir_sharp;
 
 static bool img_ir_decoders_preprocessed;
 static struct img_ir_decoder *img_ir_decoders[] = {
@@ -34,6 +35,9 @@ static struct img_ir_decoder *img_ir_decoders[] = {
 #endif
 #ifdef CONFIG_IR_IMG_SONY
        &img_ir_sony,
+#endif
+#ifdef CONFIG_IR_IMG_SHARP
+       &img_ir_sharp,
 #endif
        NULL
 };
diff --git a/drivers/media/rc/img-ir/img-ir-sharp.c b/drivers/media/rc/img-ir/img-ir-sharp.c
new file mode 100644 (file)
index 0000000..3397cc5
--- /dev/null
@@ -0,0 +1,99 @@
+/*
+ * ImgTec IR Decoder setup for Sharp protocol.
+ *
+ * Copyright 2012-2014 Imagination Technologies Ltd.
+ */
+
+#include "img-ir-hw.h"
+
+/* Convert Sharp data to a scancode */
+static int img_ir_sharp_scancode(int len, u64 raw, int *scancode, u64 protocols)
+{
+       unsigned int addr, cmd, exp, chk;
+
+       if (len != 15)
+               return -EINVAL;
+
+       addr = (raw >>   0) & 0x1f;
+       cmd  = (raw >>   5) & 0xff;
+       exp  = (raw >>  13) &  0x1;
+       chk  = (raw >>  14) &  0x1;
+
+       /* validate data */
+       if (!exp)
+               return -EINVAL;
+       if (chk)
+               /* probably the second half of the message */
+               return -EINVAL;
+
+       *scancode = addr << 8 | cmd;
+       return IMG_IR_SCANCODE;
+}
+
+/* Convert Sharp scancode to Sharp data filter */
+static int img_ir_sharp_filter(const struct rc_scancode_filter *in,
+                              struct img_ir_filter *out, u64 protocols)
+{
+       unsigned int addr, cmd, exp = 0, chk = 0;
+       unsigned int addr_m, cmd_m, exp_m = 0, chk_m = 0;
+
+       addr   = (in->data >> 8) & 0x1f;
+       addr_m = (in->mask >> 8) & 0x1f;
+       cmd    = (in->data >> 0) & 0xff;
+       cmd_m  = (in->mask >> 0) & 0xff;
+       if (cmd_m) {
+               /* if filtering commands, we can only match the first part */
+               exp   = 1;
+               exp_m = 1;
+               chk   = 0;
+               chk_m = 1;
+       }
+
+       out->data = addr        |
+                   cmd   <<  5 |
+                   exp   << 13 |
+                   chk   << 14;
+       out->mask = addr_m      |
+                   cmd_m <<  5 |
+                   exp_m << 13 |
+                   chk_m << 14;
+
+       return 0;
+}
+
+/*
+ * Sharp decoder
+ * See also http://www.sbprojects.com/knowledge/ir/sharp.php
+ */
+struct img_ir_decoder img_ir_sharp = {
+       .type = RC_BIT_SHARP,
+       .control = {
+               .decoden = 0,
+               .decodend2 = 1,
+               .code_type = IMG_IR_CODETYPE_PULSEDIST,
+               .d1validsel = 1,
+       },
+       /* main timings */
+       .tolerance = 20,        /* 20% */
+       .timings = {
+               /* 0 symbol */
+               .s10 = {
+                       .pulse = { 320  /* 320 us */ },
+                       .space = { 680  /* 1 ms period */ },
+               },
+               /* 1 symbol */
+               .s11 = {
+                       .pulse = { 320  /* 320 us */ },
+                       .space = { 1680 /* 2 ms period */ },
+               },
+               /* free time */
+               .ft = {
+                       .minlen = 15,
+                       .maxlen = 15,
+                       .ft_min = 5000, /* 5 ms */
+               },
+       },
+       /* scancode logic */
+       .scancode = img_ir_sharp_scancode,
+       .filter = img_ir_sharp_filter,
+};