aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/media/IR/ir-sony-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-sony-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-sony-decoder.c')
-rw-r--r--drivers/media/IR/ir-sony-decoder.c94
1 files changed, 10 insertions, 84 deletions
diff --git a/drivers/media/IR/ir-sony-decoder.c b/drivers/media/IR/ir-sony-decoder.c
index e15db3334998..b9074f07c7a0 100644
--- a/drivers/media/IR/ir-sony-decoder.c
+++ b/drivers/media/IR/ir-sony-decoder.c
@@ -23,10 +23,6 @@
23#define SONY_BIT_SPACE (1 * SONY_UNIT) 23#define SONY_BIT_SPACE (1 * SONY_UNIT)
24#define SONY_TRAILER_SPACE (10 * SONY_UNIT) /* minimum */ 24#define SONY_TRAILER_SPACE (10 * SONY_UNIT) /* minimum */
25 25
26/* Used to register sony_decoder clients */
27static LIST_HEAD(decoder_list);
28static DEFINE_SPINLOCK(decoder_lock);
29
30enum sony_state { 26enum sony_state {
31 STATE_INACTIVE, 27 STATE_INACTIVE,
32 STATE_HEADER_SPACE, 28 STATE_HEADER_SPACE,
@@ -35,36 +31,6 @@ enum sony_state {
35 STATE_FINISHED, 31 STATE_FINISHED,
36}; 32};
37 33
38struct decoder_data {
39 struct list_head list;
40 struct ir_input_dev *ir_dev;
41
42 /* State machine control */
43 enum sony_state state;
44 u32 sony_bits;
45 unsigned count;
46};
47
48
49/**
50 * get_decoder_data() - gets decoder data
51 * @input_dev: input device
52 *
53 * Returns the struct decoder_data that corresponds to a device
54 */
55static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev)
56{
57 struct decoder_data *data = NULL;
58
59 spin_lock(&decoder_lock);
60 list_for_each_entry(data, &decoder_list, list) {
61 if (data->ir_dev == ir_dev)
62 break;
63 }
64 spin_unlock(&decoder_lock);
65 return data;
66}
67
68/** 34/**
69 * ir_sony_decode() - Decode one Sony pulse or space 35 * ir_sony_decode() - Decode one Sony pulse or space
70 * @input_dev: the struct input_dev descriptor of the device 36 * @input_dev: the struct input_dev descriptor of the device
@@ -74,15 +40,11 @@ static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev)
74 */ 40 */
75static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev) 41static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev)
76{ 42{
77 struct decoder_data *data;
78 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); 43 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
44 struct sony_dec *data = &ir_dev->raw->sony;
79 u32 scancode; 45 u32 scancode;
80 u8 device, subdevice, function; 46 u8 device, subdevice, function;
81 47
82 data = get_decoder_data(ir_dev);
83 if (!data)
84 return -EINVAL;
85
86 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_SONY)) 48 if (!(ir_dev->raw->enabled_protocols & IR_TYPE_SONY))
87 return 0; 49 return 0;
88 50
@@ -124,9 +86,9 @@ static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev)
124 if (!ev.pulse) 86 if (!ev.pulse)
125 break; 87 break;
126 88
127 data->sony_bits <<= 1; 89 data->bits <<= 1;
128 if (eq_margin(ev.duration, SONY_BIT_1_PULSE, SONY_UNIT / 2)) 90 if (eq_margin(ev.duration, SONY_BIT_1_PULSE, SONY_UNIT / 2))
129 data->sony_bits |= 1; 91 data->bits |= 1;
130 else if (!eq_margin(ev.duration, SONY_BIT_0_PULSE, SONY_UNIT / 2)) 92 else if (!eq_margin(ev.duration, SONY_BIT_0_PULSE, SONY_UNIT / 2))
131 break; 93 break;
132 94
@@ -160,19 +122,19 @@ static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev)
160 122
161 switch (data->count) { 123 switch (data->count) {
162 case 12: 124 case 12:
163 device = bitrev8((data->sony_bits << 3) & 0xF8); 125 device = bitrev8((data->bits << 3) & 0xF8);
164 subdevice = 0; 126 subdevice = 0;
165 function = bitrev8((data->sony_bits >> 4) & 0xFE); 127 function = bitrev8((data->bits >> 4) & 0xFE);
166 break; 128 break;
167 case 15: 129 case 15:
168 device = bitrev8((data->sony_bits >> 0) & 0xFF); 130 device = bitrev8((data->bits >> 0) & 0xFF);
169 subdevice = 0; 131 subdevice = 0;
170 function = bitrev8((data->sony_bits >> 7) & 0xFD); 132 function = bitrev8((data->bits >> 7) & 0xFD);
171 break; 133 break;
172 case 20: 134 case 20:
173 device = bitrev8((data->sony_bits >> 5) & 0xF8); 135 device = bitrev8((data->bits >> 5) & 0xF8);
174 subdevice = bitrev8((data->sony_bits >> 0) & 0xFF); 136 subdevice = bitrev8((data->bits >> 0) & 0xFF);
175 function = bitrev8((data->sony_bits >> 12) & 0xFE); 137 function = bitrev8((data->bits >> 12) & 0xFE);
176 break; 138 break;
177 default: 139 default:
178 IR_dprintk(1, "Sony invalid bitcount %u\n", data->count); 140 IR_dprintk(1, "Sony invalid bitcount %u\n", data->count);
@@ -193,45 +155,9 @@ out:
193 return -EINVAL; 155 return -EINVAL;
194} 156}
195 157
196static int ir_sony_register(struct input_dev *input_dev)
197{
198 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
199 struct decoder_data *data;
200
201 data = kzalloc(sizeof(*data), GFP_KERNEL);
202 if (!data)
203 return -ENOMEM;
204
205 data->ir_dev = ir_dev;
206
207 spin_lock(&decoder_lock);
208 list_add_tail(&data->list, &decoder_list);
209 spin_unlock(&decoder_lock);
210
211 return 0;
212}
213
214static int ir_sony_unregister(struct input_dev *input_dev)
215{
216 struct ir_input_dev *ir_dev = input_get_drvdata(input_dev);
217 static struct decoder_data *data;
218
219 data = get_decoder_data(ir_dev);
220 if (!data)
221 return 0;
222
223 spin_lock(&decoder_lock);
224 list_del(&data->list);
225 spin_unlock(&decoder_lock);
226
227 return 0;
228}
229
230static struct ir_raw_handler sony_handler = { 158static struct ir_raw_handler sony_handler = {
231 .protocols = IR_TYPE_SONY, 159 .protocols = IR_TYPE_SONY,
232 .decode = ir_sony_decode, 160 .decode = ir_sony_decode,
233 .raw_register = ir_sony_register,
234 .raw_unregister = ir_sony_unregister,
235}; 161};
236 162
237static int __init ir_sony_decode_init(void) 163static int __init ir_sony_decode_init(void)