aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/IR/ir-jvc-decoder.c
diff options
context:
space:
mode:
authorDavid Härdeman <david@hardeman.nu>2010-06-13 16:29:36 -0400
committerMauro Carvalho Chehab <mchehab@redhat.com>2010-08-02 13:55:15 -0400
commitc216369e61fae586cd48c0913cca2a37fbfeb912 (patch)
treec4dfc55e6b4673a2e5698bd1f8aa8ae3919f57f7 /drivers/media/IR/ir-jvc-decoder.c
parentde8592bd539b2bb8da2b55b1007562eb1abd1fe6 (diff)
V4L/DVB: ir-core: move decoding state to ir_raw_event_ctrl
This patch moves the state from each raw decoder into the ir_raw_event_ctrl struct. This allows the removal of code like this: spin_lock(&decoder_lock); list_for_each_entry(data, &decoder_list, list) { if (data->ir_dev == ir_dev) break; } spin_unlock(&decoder_lock); return data; which is currently run for each decoder on each event in order to get the client-specific decoding state data. In addition, ir decoding modules and ir driver module load order is now independent. Centralizing the data also allows for a nice code reduction of about 30% per raw decoder as client lists and client registration callbacks are no longer necessary (but still kept around for the benefit of the lirc decoder). Out-of-tree modules can still use a similar trick to what the raw decoders did before this patch until they are merged. Signed-off-by: David Härdeman <david@hardeman.nu> Acked-by: Jarod Wilson <jarod@redhat.com> Tested-by: Jarod Wilson <jarod@redhat.com> Signed-off-by: Mauro Carvalho Chehab <mchehab@redhat.com>
Diffstat (limited to 'drivers/media/IR/ir-jvc-decoder.c')
-rw-r--r--drivers/media/IR/ir-jvc-decoder.c91
1 files changed, 7 insertions, 84 deletions
diff --git a/drivers/media/IR/ir-jvc-decoder.c b/drivers/media/IR/ir-jvc-decoder.c
index b1f935884d30..8894d8b36048 100644
--- a/drivers/media/IR/ir-jvc-decoder.c
+++ b/drivers/media/IR/ir-jvc-decoder.c
@@ -25,10 +25,6 @@
25#define JVC_TRAILER_PULSE (1 * JVC_UNIT) 25#define JVC_TRAILER_PULSE (1 * JVC_UNIT)
26#define JVC_TRAILER_SPACE (35 * JVC_UNIT) 26#define JVC_TRAILER_SPACE (35 * JVC_UNIT)
27 27
28/* Used to register jvc_decoder clients */
29static LIST_HEAD(decoder_list);
30DEFINE_SPINLOCK(decoder_lock);
31
32enum jvc_state { 28enum jvc_state {
33 STATE_INACTIVE, 29 STATE_INACTIVE,
34 STATE_HEADER_SPACE, 30 STATE_HEADER_SPACE,
@@ -38,39 +34,6 @@ enum jvc_state {
38 STATE_TRAILER_SPACE, 34 STATE_TRAILER_SPACE,
39}; 35};
40 36
41struct decoder_data {
42 struct list_head list;
43 struct ir_input_dev *ir_dev;
44
45 /* State machine control */
46 enum jvc_state state;
47 u16 jvc_bits;
48 u16 jvc_old_bits;
49 unsigned count;
50 bool first;
51 bool toggle;
52};
53
54
55/**
56 * get_decoder_data() - gets decoder data
57 * @input_dev: input device
58 *
59 * Returns the struct decoder_data that corresponds to a device
60 */
61static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev)
62{
63 struct decoder_data *data = NULL;
64
65 spin_lock(&decoder_lock);
66 list_for_each_entry(data, &decoder_list, list) {
67 if (data->ir_dev == ir_dev)
68 break;
69 }
70 spin_unlock(&decoder_lock);
71 return data;
72}
73
74/** 37/**
75 * ir_jvc_decode() - Decode one JVC pulse or space 38 * ir_jvc_decode() - Decode one JVC pulse or space
76 * @input_dev: the struct input_dev descriptor of the device 39 * @input_dev: the struct input_dev descriptor of the device
@@ -80,12 +43,8 @@ static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev)
80 */ 43 */
81static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev) 44static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
82{ 45{
83 struct decoder_data *data;
84 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 46 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
85 47 struct jvc_dec *data = &ir_dev->raw->jvc;
86 data = get_decoder_data(ir_dev);
87 if (!data)
88 return -EINVAL;
89 48
90 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_JVC)) 49 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_JVC))
91 return 0; 50 return 0;
@@ -140,9 +99,9 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
140 if (ev.pulse) 99 if (ev.pulse)
141 break; 100 break;
142 101
143 data->jvc_bits <<= 1; 102 data->bits <<= 1;
144 if (eq_margin(ev.duration, JVC_BIT_1_SPACE, JVC_UNIT / 2)) { 103 if (eq_margin(ev.duration, JVC_BIT_1_SPACE, JVC_UNIT / 2)) {
145 data->jvc_bits |= 1; 104 data->bits |= 1;
146 decrease_duration(&ev, JVC_BIT_1_SPACE); 105 decrease_duration(&ev, JVC_BIT_1_SPACE);
147 } else if (eq_margin(ev.duration, JVC_BIT_0_SPACE, JVC_UNIT / 2)) 106 } else if (eq_margin(ev.duration, JVC_BIT_0_SPACE, JVC_UNIT / 2))
148 decrease_duration(&ev, JVC_BIT_0_SPACE); 107 decrease_duration(&ev, JVC_BIT_0_SPACE);
@@ -175,13 +134,13 @@ static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev)
175 134
176 if (data->first) { 135 if (data->first) {
177 u32 scancode; 136 u32 scancode;
178 scancode = (bitrev8((data->jvc_bits >> 8) & 0xff) << 8) | 137 scancode = (bitrev8((data->bits >> 8) & 0xff) << 8) |
179 (bitrev8((data->jvc_bits >> 0) & 0xff) << 0); 138 (bitrev8((data->bits >> 0) & 0xff) << 0);
180 IR_dprintk(1, "JVC scancode 0x%04x\n", scancode); 139 IR_dprintk(1, "JVC scancode 0x%04x\n", scancode);
181 ir_keydown(input_dev, scancode, data->toggle); 140 ir_keydown(input_dev, scancode, data->toggle);
182 data->first = false; 141 data->first = false;
183 data->jvc_old_bits = data->jvc_bits; 142 data->old_bits = data->bits;
184 } else if (data->jvc_bits == data->jvc_old_bits) { 143 } else if (data->bits == data->old_bits) {
185 IR_dprintk(1, "JVC repeat\n"); 144 IR_dprintk(1, "JVC repeat\n");
186 ir_repeat(input_dev); 145 ir_repeat(input_dev);
187 } else { 146 } else {
@@ -201,45 +160,9 @@ out:
201 return -EINVAL; 160 return -EINVAL;
202} 161}
203 162
204static int ir_jvc_register(struct input_dev *input_dev)
205{
206 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
207 struct decoder_data *data;
208
209 data = kzalloc(sizeof(*data), GFP_KERNEL);
210 if (!data)
211 return -ENOMEM;
212
213 data->ir_dev = ir_dev;
214
215 spin_lock(&decoder_lock);
216 list_add_tail(&data->list, &decoder_list);
217 spin_unlock(&decoder_lock);
218
219 return 0;
220}
221
222static int ir_jvc_unregister(struct input_dev *input_dev)
223{
224 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
225 static struct decoder_data *data;
226
227 data = get_decoder_data(ir_dev);
228 if (!data)
229 return 0;
230
231 spin_lock(&decoder_lock);
232 list_del(&data->list);
233 spin_unlock(&decoder_lock);
234
235 return 0;
236}
237
238static struct ir_raw_handler jvc_handler = { 163static struct ir_raw_handler jvc_handler = {
239 .protocols = IR_TYPE_JVC, 164 .protocols = IR_TYPE_JVC,
240 .decode = ir_jvc_decode, 165 .decode = ir_jvc_decode,
241 .raw_register = ir_jvc_register,
242 .raw_unregister = ir_jvc_unregister,
243}; 166};
244 167
245static int __init ir_jvc_decode_init(void) 168static int __init ir_jvc_decode_init(void)