Re: [PATCH 4/5] rc: img-ir: add philips rc5 decoder module

2014-12-08 Thread James Hogan
On 04/12/14 15:38, Sifan Naeem wrote:
 Add img-ir module for decoding Philips rc5 protocol.
 
 Signed-off-by: Sifan Naeem sifan.na...@imgtec.com
 ---
  drivers/media/rc/img-ir/Kconfig  |7 +++
  drivers/media/rc/img-ir/Makefile |1 +
  drivers/media/rc/img-ir/img-ir-hw.c  |3 ++
  drivers/media/rc/img-ir/img-ir-hw.h  |1 +
  drivers/media/rc/img-ir/img-ir-rc5.c |   88 
 ++
  5 files changed, 100 insertions(+)
  create mode 100644 drivers/media/rc/img-ir/img-ir-rc5.c
 
 diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
 index 03ba9fc..b5b114f 100644
 --- a/drivers/media/rc/img-ir/Kconfig
 +++ b/drivers/media/rc/img-ir/Kconfig
 @@ -59,3 +59,10 @@ config IR_IMG_SANYO
   help
  Say Y here to enable support for the Sanyo protocol (used by Sanyo,
  Aiwa, Chinon remotes) in the ImgTec infrared decoder block.
 +
 +config IR_IMG_RC5
 + bool Phillips RC5 protocol support

I think that should be Philips (if wikipedia is anything to go by).

Same elsewhere in this patch and patch 5.

Other than that,
Acked-by: James Hogan james.ho...@imgtec.com

(Note, I don't have RC-5/RC-6 capable hardware yet so can't test this
support)

Thanks
James

 + depends on IR_IMG_HW
 + help
 +Say Y here to enable support for the RC5 protocol in the ImgTec
 +infrared decoder block.
 diff --git a/drivers/media/rc/img-ir/Makefile 
 b/drivers/media/rc/img-ir/Makefile
 index 92a459d..898b1b8 100644
 --- a/drivers/media/rc/img-ir/Makefile
 +++ b/drivers/media/rc/img-ir/Makefile
 @@ -6,6 +6,7 @@ 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-$(CONFIG_IR_IMG_SANYO)+= img-ir-sanyo.o
 +img-ir-$(CONFIG_IR_IMG_RC5)  += img-ir-rc5.o
  img-ir-objs  := $(img-ir-y)
  
  obj-$(CONFIG_IR_IMG) += img-ir.o
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
 b/drivers/media/rc/img-ir/img-ir-hw.c
 index a977467..322cdf8 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.c
 +++ b/drivers/media/rc/img-ir/img-ir-hw.c
 @@ -42,6 +42,9 @@ static struct img_ir_decoder *img_ir_decoders[] = {
  #ifdef CONFIG_IR_IMG_SANYO
   img_ir_sanyo,
  #endif
 +#ifdef CONFIG_IR_IMG_RC5
 + img_ir_rc5,
 +#endif
   NULL
  };
  
 diff --git a/drivers/media/rc/img-ir/img-ir-hw.h 
 b/drivers/media/rc/img-ir/img-ir-hw.h
 index 8578aa7..f124ec5 100644
 --- a/drivers/media/rc/img-ir/img-ir-hw.h
 +++ b/drivers/media/rc/img-ir/img-ir-hw.h
 @@ -187,6 +187,7 @@ extern struct img_ir_decoder img_ir_jvc;
  extern struct img_ir_decoder img_ir_sony;
  extern struct img_ir_decoder img_ir_sharp;
  extern struct img_ir_decoder img_ir_sanyo;
 +extern struct img_ir_decoder img_ir_rc5;
  
  /**
   * struct img_ir_reg_timings - Reg values for decoder timings at clock rate.
 diff --git a/drivers/media/rc/img-ir/img-ir-rc5.c 
 b/drivers/media/rc/img-ir/img-ir-rc5.c
 new file mode 100644
 index 000..e1a0829
 --- /dev/null
 +++ b/drivers/media/rc/img-ir/img-ir-rc5.c
 @@ -0,0 +1,88 @@
 +/*
 + * ImgTec IR Decoder setup for Phillips RC-5 protocol.
 + *
 + * Copyright 2012-2014 Imagination Technologies Ltd.
 + *
 + * This program is free software; you can redistribute it and/or modify
 + * it under the terms of the GNU General Public License as published by the
 + * Free Software Foundation; either version 2 of the License, or (at your
 + * option) any later version.
 + */
 +
 +#include img-ir-hw.h
 +
 +/* Convert RC5 data to a scancode */
 +static int img_ir_rc5_scancode(int len, u64 raw, u64 enabled_protocols,
 + struct img_ir_scancode_req *request)
 +{
 + unsigned int addr, cmd, tgl, start;
 +
 + /* Quirk in the decoder shifts everything by 2 to the left. */
 + raw   = 2;
 +
 + start   =  (raw  13)   0x01;
 + tgl =  (raw  11)   0x01;
 + addr=  (raw   6)   0x1f;
 + cmd =   raw  0x3f;
 + /*
 +  * 12th bit is used to extend the command in extended RC5 and has
 +  * no effect on standard RC5.
 +  */
 + cmd += ((raw  12)  0x01) ? 0 : 0x40;
 +
 + if (!start)
 + return -EINVAL;
 +
 + request-protocol = RC_TYPE_RC5;
 + request-scancode = addr  8 | cmd;
 + request-toggle   = tgl;
 + return IMG_IR_SCANCODE;
 +}
 +
 +/* Convert RC5 scancode to RC5 data filter */
 +static int img_ir_rc5_filter(const struct rc_scancode_filter *in,
 +  struct img_ir_filter *out, u64 protocols)
 +{
 + /* Not supported by the hw. */
 + return -EINVAL;
 +}
 +
 +/*
 + * RC-5 decoder
 + * see http://www.sbprojects.com/knowledge/ir/rc5.php
 + */
 +struct img_ir_decoder img_ir_rc5 = {
 + .type  = RC_BIT_RC5,
 + .control   = {
 + .bitoriend2 = 1,
 + .code_type  = IMG_IR_CODETYPE_BIPHASE,
 + .decodend2  = 1,
 + },
 + /* main timings */
 

[PATCH 4/5] rc: img-ir: add philips rc5 decoder module

2014-12-04 Thread Sifan Naeem
Add img-ir module for decoding Philips rc5 protocol.

Signed-off-by: Sifan Naeem sifan.na...@imgtec.com
---
 drivers/media/rc/img-ir/Kconfig  |7 +++
 drivers/media/rc/img-ir/Makefile |1 +
 drivers/media/rc/img-ir/img-ir-hw.c  |3 ++
 drivers/media/rc/img-ir/img-ir-hw.h  |1 +
 drivers/media/rc/img-ir/img-ir-rc5.c |   88 ++
 5 files changed, 100 insertions(+)
 create mode 100644 drivers/media/rc/img-ir/img-ir-rc5.c

diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
index 03ba9fc..b5b114f 100644
--- a/drivers/media/rc/img-ir/Kconfig
+++ b/drivers/media/rc/img-ir/Kconfig
@@ -59,3 +59,10 @@ config IR_IMG_SANYO
help
   Say Y here to enable support for the Sanyo protocol (used by Sanyo,
   Aiwa, Chinon remotes) in the ImgTec infrared decoder block.
+
+config IR_IMG_RC5
+   bool Phillips RC5 protocol support
+   depends on IR_IMG_HW
+   help
+  Say Y here to enable support for the RC5 protocol in the ImgTec
+  infrared decoder block.
diff --git a/drivers/media/rc/img-ir/Makefile b/drivers/media/rc/img-ir/Makefile
index 92a459d..898b1b8 100644
--- a/drivers/media/rc/img-ir/Makefile
+++ b/drivers/media/rc/img-ir/Makefile
@@ -6,6 +6,7 @@ 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-$(CONFIG_IR_IMG_SANYO)  += img-ir-sanyo.o
+img-ir-$(CONFIG_IR_IMG_RC5)+= img-ir-rc5.o
 img-ir-objs:= $(img-ir-y)
 
 obj-$(CONFIG_IR_IMG)   += img-ir.o
diff --git a/drivers/media/rc/img-ir/img-ir-hw.c 
b/drivers/media/rc/img-ir/img-ir-hw.c
index a977467..322cdf8 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -42,6 +42,9 @@ static struct img_ir_decoder *img_ir_decoders[] = {
 #ifdef CONFIG_IR_IMG_SANYO
img_ir_sanyo,
 #endif
+#ifdef CONFIG_IR_IMG_RC5
+   img_ir_rc5,
+#endif
NULL
 };
 
diff --git a/drivers/media/rc/img-ir/img-ir-hw.h 
b/drivers/media/rc/img-ir/img-ir-hw.h
index 8578aa7..f124ec5 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.h
+++ b/drivers/media/rc/img-ir/img-ir-hw.h
@@ -187,6 +187,7 @@ extern struct img_ir_decoder img_ir_jvc;
 extern struct img_ir_decoder img_ir_sony;
 extern struct img_ir_decoder img_ir_sharp;
 extern struct img_ir_decoder img_ir_sanyo;
+extern struct img_ir_decoder img_ir_rc5;
 
 /**
  * struct img_ir_reg_timings - Reg values for decoder timings at clock rate.
diff --git a/drivers/media/rc/img-ir/img-ir-rc5.c 
b/drivers/media/rc/img-ir/img-ir-rc5.c
new file mode 100644
index 000..e1a0829
--- /dev/null
+++ b/drivers/media/rc/img-ir/img-ir-rc5.c
@@ -0,0 +1,88 @@
+/*
+ * ImgTec IR Decoder setup for Phillips RC-5 protocol.
+ *
+ * Copyright 2012-2014 Imagination Technologies Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ */
+
+#include img-ir-hw.h
+
+/* Convert RC5 data to a scancode */
+static int img_ir_rc5_scancode(int len, u64 raw, u64 enabled_protocols,
+   struct img_ir_scancode_req *request)
+{
+   unsigned int addr, cmd, tgl, start;
+
+   /* Quirk in the decoder shifts everything by 2 to the left. */
+   raw   = 2;
+
+   start   =  (raw  13)   0x01;
+   tgl =  (raw  11)   0x01;
+   addr=  (raw   6)   0x1f;
+   cmd =   raw  0x3f;
+   /*
+* 12th bit is used to extend the command in extended RC5 and has
+* no effect on standard RC5.
+*/
+   cmd += ((raw  12)  0x01) ? 0 : 0x40;
+
+   if (!start)
+   return -EINVAL;
+
+   request-protocol = RC_TYPE_RC5;
+   request-scancode = addr  8 | cmd;
+   request-toggle   = tgl;
+   return IMG_IR_SCANCODE;
+}
+
+/* Convert RC5 scancode to RC5 data filter */
+static int img_ir_rc5_filter(const struct rc_scancode_filter *in,
+struct img_ir_filter *out, u64 protocols)
+{
+   /* Not supported by the hw. */
+   return -EINVAL;
+}
+
+/*
+ * RC-5 decoder
+ * see http://www.sbprojects.com/knowledge/ir/rc5.php
+ */
+struct img_ir_decoder img_ir_rc5 = {
+   .type  = RC_BIT_RC5,
+   .control   = {
+   .bitoriend2 = 1,
+   .code_type  = IMG_IR_CODETYPE_BIPHASE,
+   .decodend2  = 1,
+   },
+   /* main timings */
+   .tolerance  = 16,
+   .unit   = 88, /* 1/36k*32=888.888microseconds */
+   .timings= {
+   /* 10 symbol */
+   .s10 = {
+   .pulse  = { 1 },
+   .space  = { 1 },
+   },
+
+   /* 11 symbol */
+   .s11 = {
+