Skip to content

Commit e8ffda7

Browse files
shawnguo2mchehab
authored andcommitted
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 <[email protected]> Signed-off-by: Sean Young <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent a2df9d0 commit e8ffda7

File tree

2 files changed

+34
-29
lines changed

2 files changed

+34
-29
lines changed

drivers/media/rc/ir-nec-decoder.c

Lines changed: 3 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ static int ir_nec_decode(struct rc_dev *dev, struct ir_raw_event ev)
5151
u32 scancode;
5252
enum rc_type rc_type;
5353
u8 address, not_address, command, not_command;
54-
bool send_32bits = false;
5554

5655
if (!is_timing_event(ev)) {
5756
if (ev.reset)
@@ -157,34 +156,9 @@ static int ir_nec_decode(struct rc_dev *dev, struct ir_raw_event ev)
157156
command = bitrev8((data->bits >> 8) & 0xff);
158157
not_command = bitrev8((data->bits >> 0) & 0xff);
159158

160-
if ((command ^ not_command) != 0xff) {
161-
IR_dprintk(1, "NEC checksum error: received 0x%08x\n",
162-
data->bits);
163-
send_32bits = true;
164-
}
165-
166-
if (send_32bits) {
167-
/* NEC transport, but modified protocol, used by at
168-
* least Apple and TiVo remotes */
169-
scancode = not_address << 24 |
170-
address << 16 |
171-
not_command << 8 |
172-
command;
173-
IR_dprintk(1, "NEC (modified) scancode 0x%08x\n", scancode);
174-
rc_type = RC_TYPE_NEC32;
175-
} else if ((address ^ not_address) != 0xff) {
176-
/* Extended NEC */
177-
scancode = address << 16 |
178-
not_address << 8 |
179-
command;
180-
IR_dprintk(1, "NEC (Ext) scancode 0x%06x\n", scancode);
181-
rc_type = RC_TYPE_NECX;
182-
} else {
183-
/* Normal NEC */
184-
scancode = address << 8 | command;
185-
IR_dprintk(1, "NEC scancode 0x%04x\n", scancode);
186-
rc_type = RC_TYPE_NEC;
187-
}
159+
scancode = ir_nec_bytes_to_scancode(address, not_address,
160+
command, not_command,
161+
&rc_type);
188162

189163
if (data->is_nec_x)
190164
data->necx_repeat = true;

include/media/rc-core.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,4 +340,35 @@ static inline u32 ir_extract_bits(u32 data, u32 mask)
340340
return value;
341341
}
342342

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+
343374
#endif /* _RC_CORE */

0 commit comments

Comments
 (0)