Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

media: rc: ir-nec-decoder: move scancode composing code into a shared function

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>

authored by

Shawn Guo and committed by
Mauro Carvalho Chehab
e8ffda78 a2df9d06

+34 -29
+3 -29
drivers/media/rc/ir-nec-decoder.c
··· 51 51 u32 scancode; 52 52 enum rc_type rc_type; 53 53 u8 address, not_address, command, not_command; 54 - bool send_32bits = false; 55 54 56 55 if (!is_timing_event(ev)) { 57 56 if (ev.reset) ··· 156 157 command = bitrev8((data->bits >> 8) & 0xff); 157 158 not_command = bitrev8((data->bits >> 0) & 0xff); 158 159 159 - if ((command ^ not_command) != 0xff) { 160 - IR_dprintk(1, "NEC checksum error: received 0x%08x\n", 161 - data->bits); 162 - send_32bits = true; 163 - } 164 - 165 - if (send_32bits) { 166 - /* NEC transport, but modified protocol, used by at 167 - * least Apple and TiVo remotes */ 168 - scancode = not_address << 24 | 169 - address << 16 | 170 - not_command << 8 | 171 - command; 172 - IR_dprintk(1, "NEC (modified) scancode 0x%08x\n", scancode); 173 - rc_type = RC_TYPE_NEC32; 174 - } else if ((address ^ not_address) != 0xff) { 175 - /* Extended NEC */ 176 - scancode = address << 16 | 177 - not_address << 8 | 178 - command; 179 - IR_dprintk(1, "NEC (Ext) scancode 0x%06x\n", scancode); 180 - rc_type = RC_TYPE_NECX; 181 - } else { 182 - /* Normal NEC */ 183 - scancode = address << 8 | command; 184 - IR_dprintk(1, "NEC scancode 0x%04x\n", scancode); 185 - rc_type = RC_TYPE_NEC; 186 - } 160 + scancode = ir_nec_bytes_to_scancode(address, not_address, 161 + command, not_command, 162 + &rc_type); 187 163 188 164 if (data->is_nec_x) 189 165 data->necx_repeat = true;
+31
include/media/rc-core.h
··· 340 340 return value; 341 341 } 342 342 343 + /* Get NEC scancode and protocol type from address and command bytes */ 344 + static inline u32 ir_nec_bytes_to_scancode(u8 address, u8 not_address, 345 + u8 command, u8 not_command, 346 + enum rc_type *protocol) 347 + { 348 + u32 scancode; 349 + 350 + if ((command ^ not_command) != 0xff) { 351 + /* NEC transport, but modified protocol, used by at 352 + * least Apple and TiVo remotes 353 + */ 354 + scancode = not_address << 24 | 355 + address << 16 | 356 + not_command << 8 | 357 + command; 358 + *protocol = RC_TYPE_NEC32; 359 + } else if ((address ^ not_address) != 0xff) { 360 + /* Extended NEC */ 361 + scancode = address << 16 | 362 + not_address << 8 | 363 + command; 364 + *protocol = RC_TYPE_NECX; 365 + } else { 366 + /* Normal NEC */ 367 + scancode = address << 8 | command; 368 + *protocol = RC_TYPE_NEC; 369 + } 370 + 371 + return scancode; 372 + } 373 + 343 374 #endif /* _RC_CORE */