media: rc: ir-nec-decoder: move scancode composing code into a shared function
authorShawn Guo <shawn.guo@linaro.org>
Sun, 30 Jul 2017 13:23:11 +0000 (09:23 -0400)
committerMauro Carvalho Chehab <mchehab@s-opensource.com>
Sun, 20 Aug 2017 13:49:18 +0000 (09:49 -0400)
The NEC scancode composing and protocol type detection in
ir_nec_decode() is generic enough to be a shared function.  Let's create
an inline function in rc-core.h, so that other remote control drivers
can reuse this function to save some code.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Signed-off-by: Sean Young <sean@mess.org>
Signed-off-by: Mauro Carvalho Chehab <mchehab@s-opensource.com>
drivers/media/rc/ir-nec-decoder.c
include/media/rc-core.h

index 75b9137f6faf976aa9df6091fbd054419b6de033..23d2bc8c190d095a19d9cb43fee5e215e2b9d46a 100644 (file)
@@ -51,7 +51,6 @@ static int ir_nec_decode(struct rc_dev *dev, struct ir_raw_event ev)
        u32 scancode;
        enum rc_type rc_type;
        u8 address, not_address, command, not_command;
-       bool send_32bits = false;
 
        if (!is_timing_event(ev)) {
                if (ev.reset)
@@ -157,34 +156,9 @@ static int ir_nec_decode(struct rc_dev *dev, struct ir_raw_event ev)
                command     = bitrev8((data->bits >>  8) & 0xff);
                not_command = bitrev8((data->bits >>  0) & 0xff);
 
-               if ((command ^ not_command) != 0xff) {
-                       IR_dprintk(1, "NEC checksum error: received 0x%08x\n",
-                                  data->bits);
-                       send_32bits = true;
-               }
-
-               if (send_32bits) {
-                       /* NEC transport, but modified protocol, used by at
-                        * least Apple and TiVo remotes */
-                       scancode = not_address << 24 |
-                               address     << 16 |
-                               not_command <<  8 |
-                               command;
-                       IR_dprintk(1, "NEC (modified) scancode 0x%08x\n", scancode);
-                       rc_type = RC_TYPE_NEC32;
-               } else if ((address ^ not_address) != 0xff) {
-                       /* Extended NEC */
-                       scancode = address     << 16 |
-                                  not_address <<  8 |
-                                  command;
-                       IR_dprintk(1, "NEC (Ext) scancode 0x%06x\n", scancode);
-                       rc_type = RC_TYPE_NECX;
-               } else {
-                       /* Normal NEC */
-                       scancode = address << 8 | command;
-                       IR_dprintk(1, "NEC scancode 0x%04x\n", scancode);
-                       rc_type = RC_TYPE_NEC;
-               }
+               scancode = ir_nec_bytes_to_scancode(address, not_address,
+                                                   command, not_command,
+                                                   &rc_type);
 
                if (data->is_nec_x)
                        data->necx_repeat = true;
index 16bd89caa22ddec1276582c7b39a576a023233ac..b6c18840d12552f3475cf30c2b5b5845748e5bbb 100644 (file)
@@ -340,4 +340,35 @@ static inline u32 ir_extract_bits(u32 data, u32 mask)
        return value;
 }
 
+/* Get NEC scancode and protocol type from address and command bytes */
+static inline u32 ir_nec_bytes_to_scancode(u8 address, u8 not_address,
+                                          u8 command, u8 not_command,
+                                          enum rc_type *protocol)
+{
+       u32 scancode;
+
+       if ((command ^ not_command) != 0xff) {
+               /* NEC transport, but modified protocol, used by at
+                * least Apple and TiVo remotes
+                */
+               scancode = not_address << 24 |
+                       address     << 16 |
+                       not_command <<  8 |
+                       command;
+               *protocol = RC_TYPE_NEC32;
+       } else if ((address ^ not_address) != 0xff) {
+               /* Extended NEC */
+               scancode = address     << 16 |
+                          not_address <<  8 |
+                          command;
+               *protocol = RC_TYPE_NECX;
+       } else {
+               /* Normal NEC */
+               scancode = address << 8 | command;
+               *protocol = RC_TYPE_NEC;
+       }
+
+       return scancode;
+}
+
 #endif /* _RC_CORE */