Skip to content

Commit e87b540

Browse files
Alphixmchehab
authored andcommitted
[media] rc-core: merge rc5 and streamzap decoders
Now that the protocol is part of the scancode, it is pretty easy to merge the rc5 and streamzap decoders. An additional advantage is that the decoder is now stricter as it waits for the trailing silence before determining that a command is a valid rc5/streamzap command (which avoids collisions that I've seen with e.g. Sony protocols). Signed-off-by: David Härdeman <david@hardeman.nu> Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
1 parent 9d2f1d3 commit e87b540

7 files changed

Lines changed: 43 additions & 218 deletions

File tree

‎drivers/media/rc/Kconfig‎

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,6 @@ config IR_SONY_DECODER
8484
Enable this option if you have an infrared remote control which
8585
uses the Sony protocol, and you need software decoding support.
8686

87-
config IR_RC5_SZ_DECODER
88-
tristate "Enable IR raw decoder for the RC-5 (streamzap) protocol"
89-
depends on RC_CORE
90-
select BITREVERSE
91-
default y
92-
93-
---help---
94-
Enable this option if you have IR with RC-5 (streamzap) protocol,
95-
and if the IR is decoded in software. (The Streamzap PC Remote
96-
uses an IR protocol that is almost standard RC-5, but not quite,
97-
as it uses an additional bit).
98-
9987
config IR_SANYO_DECODER
10088
tristate "Enable IR raw decoder for the Sanyo protocol"
10189
depends on RC_CORE

‎drivers/media/rc/Makefile‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ obj-$(CONFIG_IR_RC5_DECODER) += ir-rc5-decoder.o
99
obj-$(CONFIG_IR_RC6_DECODER) += ir-rc6-decoder.o
1010
obj-$(CONFIG_IR_JVC_DECODER) += ir-jvc-decoder.o
1111
obj-$(CONFIG_IR_SONY_DECODER) += ir-sony-decoder.o
12-
obj-$(CONFIG_IR_RC5_SZ_DECODER) += ir-rc5-sz-decoder.o
1312
obj-$(CONFIG_IR_SANYO_DECODER) += ir-sanyo-decoder.o
1413
obj-$(CONFIG_IR_SHARP_DECODER) += ir-sharp-decoder.o
1514
obj-$(CONFIG_IR_MCE_KBD_DECODER) += ir-mce_kbd-decoder.o

‎drivers/media/rc/ir-rc5-decoder.c‎

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
/* ir-rc5-decoder.c - handle RC5(x) IR Pulse/Space protocol
1+
/* ir-rc5-decoder.c - decoder for RC5(x) and StreamZap protocols
22
*
33
* Copyright (C) 2010 by Mauro Carvalho Chehab
4+
* Copyright (C) 2010 by Jarod Wilson <jarod@redhat.com>
45
*
56
* This program is free software; you can redistribute it and/or modify
67
* it under the terms of the GNU General Public License as published by
@@ -13,23 +14,22 @@
1314
*/
1415

1516
/*
16-
* This code handles 14 bits RC5 protocols and 20 bits RC5x protocols.
17-
* There are other variants that use a different number of bits.
18-
* This is currently unsupported.
19-
* It considers a carrier of 36 kHz, with a total of 14/20 bits, where
20-
* the first two bits are start bits, and a third one is a filing bit
17+
* This decoder handles the 14 bit RC5 protocol, 15 bit "StreamZap" protocol
18+
* and 20 bit RC5x protocol.
2119
*/
2220

2321
#include "rc-core-priv.h"
2422
#include <linux/module.h>
2523

2624
#define RC5_NBITS 14
25+
#define RC5_SZ_NBITS 15
2726
#define RC5X_NBITS 20
2827
#define CHECK_RC5X_NBITS 8
2928
#define RC5_UNIT 888888 /* ns */
3029
#define RC5_BIT_START (1 * RC5_UNIT)
3130
#define RC5_BIT_END (1 * RC5_UNIT)
3231
#define RC5X_SPACE (4 * RC5_UNIT)
32+
#define RC5_TRAILER (10 * RC5_UNIT) /* In reality, approx 100 */
3333

3434
enum rc5_state {
3535
STATE_INACTIVE,
@@ -66,7 +66,7 @@ static int ir_rc5_decode(struct rc_dev *dev, struct ir_raw_event ev)
6666
goto out;
6767

6868
again:
69-
IR_dprintk(2, "RC5(x) decode started at state %i (%uus %s)\n",
69+
IR_dprintk(2, "RC5(x/sz) decode started at state %i (%uus %s)\n",
7070
data->state, TO_US(ev.duration), TO_STR(ev.pulse));
7171

7272
if (!geq_margin(ev.duration, RC5_UNIT, RC5_UNIT / 2))
@@ -80,12 +80,15 @@ static int ir_rc5_decode(struct rc_dev *dev, struct ir_raw_event ev)
8080

8181
data->state = STATE_BIT_START;
8282
data->count = 1;
83-
/* We just need enough bits to get to STATE_CHECK_RC5X */
84-
data->wanted_bits = RC5X_NBITS;
8583
decrease_duration(&ev, RC5_BIT_START);
8684
goto again;
8785

8886
case STATE_BIT_START:
87+
if (!ev.pulse && geq_margin(ev.duration, RC5_TRAILER, RC5_UNIT / 2)) {
88+
data->state = STATE_FINISHED;
89+
goto again;
90+
}
91+
8992
if (!eq_margin(ev.duration, RC5_BIT_START, RC5_UNIT / 2))
9093
break;
9194

@@ -100,9 +103,7 @@ static int ir_rc5_decode(struct rc_dev *dev, struct ir_raw_event ev)
100103
if (!is_transition(&ev, &dev->raw->prev_ev))
101104
break;
102105

103-
if (data->count == data->wanted_bits)
104-
data->state = STATE_FINISHED;
105-
else if (data->count == CHECK_RC5X_NBITS)
106+
if (data->count == CHECK_RC5X_NBITS)
106107
data->state = STATE_CHECK_RC5X;
107108
else
108109
data->state = STATE_BIT_START;
@@ -112,21 +113,18 @@ static int ir_rc5_decode(struct rc_dev *dev, struct ir_raw_event ev)
112113

113114
case STATE_CHECK_RC5X:
114115
if (!ev.pulse && geq_margin(ev.duration, RC5X_SPACE, RC5_UNIT / 2)) {
115-
/* RC5X */
116-
data->wanted_bits = RC5X_NBITS;
116+
data->is_rc5x = true;
117117
decrease_duration(&ev, RC5X_SPACE);
118-
} else {
119-
/* RC5 */
120-
data->wanted_bits = RC5_NBITS;
121-
}
118+
} else
119+
data->is_rc5x = false;
122120
data->state = STATE_BIT_START;
123121
goto again;
124122

125123
case STATE_FINISHED:
126124
if (ev.pulse)
127125
break;
128126

129-
if (data->wanted_bits == RC5X_NBITS) {
127+
if (data->is_rc5x && data->count == RC5X_NBITS) {
130128
/* RC5X */
131129
u8 xdata, command, system;
132130
if (!(dev->enabled_protocols & RC_BIT_RC5X)) {
@@ -141,10 +139,7 @@ static int ir_rc5_decode(struct rc_dev *dev, struct ir_raw_event ev)
141139
scancode = system << 16 | command << 8 | xdata;
142140
protocol = RC_TYPE_RC5X;
143141

144-
IR_dprintk(1, "RC5X scancode 0x%06x (toggle: %u)\n",
145-
scancode, toggle);
146-
147-
} else {
142+
} else if (!data->is_rc5x && data->count == RC5_NBITS) {
148143
/* RC5 */
149144
u8 command, system;
150145
if (!(dev->enabled_protocols & RC_BIT_RC5)) {
@@ -158,32 +153,47 @@ static int ir_rc5_decode(struct rc_dev *dev, struct ir_raw_event ev)
158153
scancode = system << 8 | command;
159154
protocol = RC_TYPE_RC5;
160155

161-
IR_dprintk(1, "RC5 scancode 0x%04x (toggle: %u)\n",
162-
scancode, toggle);
163-
}
156+
} else if (!data->is_rc5x && data->count == RC5_SZ_NBITS) {
157+
/* RC5 StreamZap */
158+
u8 command, system;
159+
if (!(dev->enabled_protocols & RC_BIT_RC5_SZ)) {
160+
data->state = STATE_INACTIVE;
161+
return 0;
162+
}
163+
command = (data->bits & 0x0003F) >> 0;
164+
system = (data->bits & 0x02FC0) >> 6;
165+
toggle = (data->bits & 0x01000) ? 1 : 0;
166+
scancode = system << 6 | command;
167+
protocol = RC_TYPE_RC5_SZ;
168+
169+
} else
170+
break;
171+
172+
IR_dprintk(1, "RC5(x/sz) scancode 0x%06x (p: %u, t: %u)\n",
173+
scancode, protocol, toggle);
164174

165175
rc_keydown(dev, protocol, scancode, toggle);
166176
data->state = STATE_INACTIVE;
167177
return 0;
168178
}
169179

170180
out:
171-
IR_dprintk(1, "RC5(x) decode failed at state %i (%uus %s)\n",
181+
IR_dprintk(1, "RC5(x/sz) decode failed at state %i (%uus %s)\n",
172182
data->state, TO_US(ev.duration), TO_STR(ev.pulse));
173183
data->state = STATE_INACTIVE;
174184
return -EINVAL;
175185
}
176186

177187
static struct ir_raw_handler rc5_handler = {
178-
.protocols = RC_BIT_RC5 | RC_BIT_RC5X,
188+
.protocols = RC_BIT_RC5 | RC_BIT_RC5X | RC_BIT_RC5_SZ,
179189
.decode = ir_rc5_decode,
180190
};
181191

182192
static int __init ir_rc5_decode_init(void)
183193
{
184194
ir_raw_handler_register(&rc5_handler);
185195

186-
printk(KERN_INFO "IR RC5(x) protocol handler initialized\n");
196+
printk(KERN_INFO "IR RC5(x/sz) protocol handler initialized\n");
187197
return 0;
188198
}
189199

@@ -196,6 +206,6 @@ module_init(ir_rc5_decode_init);
196206
module_exit(ir_rc5_decode_exit);
197207

198208
MODULE_LICENSE("GPL");
199-
MODULE_AUTHOR("Mauro Carvalho Chehab");
209+
MODULE_AUTHOR("Mauro Carvalho Chehab and Jarod Wilson");
200210
MODULE_AUTHOR("Red Hat Inc. (http://www.redhat.com)");
201-
MODULE_DESCRIPTION("RC5(x) IR protocol decoder");
211+
MODULE_DESCRIPTION("RC5(x/sz) IR protocol decoder");

‎drivers/media/rc/ir-rc5-sz-decoder.c‎

Lines changed: 0 additions & 154 deletions
This file was deleted.

‎drivers/media/rc/keymaps/rc-streamzap.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,7 @@
1515
static struct rc_map_table streamzap[] = {
1616
/*
1717
* The Streamzap remote is almost, but not quite, RC-5, as it has an extra
18-
* bit in it, which throws the in-kernel RC-5 decoder for a loop. Currently,
19-
* an additional RC-5-sz decoder is being deployed to support it, but it
20-
* may be possible to merge it back with the standard RC-5 decoder.
18+
* bit in it.
2119
*/
2220
{ 0x28c0, KEY_NUMERIC_0 },
2321
{ 0x28c1, KEY_NUMERIC_1 },

‎drivers/media/rc/rc-core-priv.h‎

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ struct ir_raw_event_ctrl {
5454
int state;
5555
u32 bits;
5656
unsigned count;
57-
unsigned wanted_bits;
57+
bool is_rc5x;
5858
} rc5;
5959
struct rc6_dec {
6060
int state;
@@ -77,12 +77,6 @@ struct ir_raw_event_ctrl {
7777
bool first;
7878
bool toggle;
7979
} jvc;
80-
struct rc5_sz_dec {
81-
int state;
82-
u32 bits;
83-
unsigned count;
84-
unsigned wanted_bits;
85-
} rc5_sz;
8680
struct sanyo_dec {
8781
int state;
8882
unsigned count;

0 commit comments

Comments
 (0)