diff options
author | David Härdeman <david@hardeman.nu> | 2010-06-13 16:29:36 -0400 |
---|---|---|
committer | Mauro Carvalho Chehab <mchehab@redhat.com> | 2010-08-02 13:55:15 -0400 |
commit | c216369e61fae586cd48c0913cca2a37fbfeb912 (patch) | |
tree | c4dfc55e6b4673a2e5698bd1f8aa8ae3919f57f7 /drivers/media/IR | |
parent | de8592bd539b2bb8da2b55b1007562eb1abd1fe6 (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')
-rw-r--r-- | drivers/media/IR/ir-core-priv.h | 38 | ||||
-rw-r--r-- | drivers/media/IR/ir-jvc-decoder.c | 91 | ||||
-rw-r--r-- | drivers/media/IR/ir-nec-decoder.c | 90 | ||||
-rw-r--r-- | drivers/media/IR/ir-raw-event.c | 73 | ||||
-rw-r--r-- | drivers/media/IR/ir-rc5-decoder.c | 104 | ||||
-rw-r--r-- | drivers/media/IR/ir-rc6-decoder.c | 92 | ||||
-rw-r--r-- | drivers/media/IR/ir-sony-decoder.c | 94 |
7 files changed, 118 insertions, 464 deletions
diff --git a/drivers/media/IR/ir-core-priv.h b/drivers/media/IR/ir-core-priv.h index 5111dc23909a..0a82b22d3828 100644 --- a/drivers/media/IR/ir-core-priv.h +++ b/drivers/media/IR/ir-core-priv.h | |||
@@ -24,17 +24,55 @@ struct ir_raw_handler { | |||
24 | 24 | ||
25 | u64 protocols; /* which are handled by this handler */ | 25 | u64 protocols; /* which are handled by this handler */ |
26 | int (*decode)(struct input_dev *input_dev, struct ir_raw_event event); | 26 | int (*decode)(struct input_dev *input_dev, struct ir_raw_event event); |
27 | |||
28 | /* These two should only be used by the lirc decoder */ | ||
27 | int (*raw_register)(struct input_dev *input_dev); | 29 | int (*raw_register)(struct input_dev *input_dev); |
28 | int (*raw_unregister)(struct input_dev *input_dev); | 30 | int (*raw_unregister)(struct input_dev *input_dev); |
29 | }; | 31 | }; |
30 | 32 | ||
31 | struct ir_raw_event_ctrl { | 33 | struct ir_raw_event_ctrl { |
34 | struct list_head list; /* to keep track of raw clients */ | ||
32 | struct work_struct rx_work; /* for the rx decoding workqueue */ | 35 | struct work_struct rx_work; /* for the rx decoding workqueue */ |
33 | struct kfifo kfifo; /* fifo for the pulse/space durations */ | 36 | struct kfifo kfifo; /* fifo for the pulse/space durations */ |
34 | ktime_t last_event; /* when last event occurred */ | 37 | ktime_t last_event; /* when last event occurred */ |
35 | enum raw_event_type last_type; /* last event type */ | 38 | enum raw_event_type last_type; /* last event type */ |
36 | struct input_dev *input_dev; /* pointer to the parent input_dev */ | 39 | struct input_dev *input_dev; /* pointer to the parent input_dev */ |
37 | u64 enabled_protocols; /* enabled raw protocol decoders */ | 40 | u64 enabled_protocols; /* enabled raw protocol decoders */ |
41 | |||
42 | /* raw decoder state follows */ | ||
43 | struct ir_raw_event prev_ev; | ||
44 | struct nec_dec { | ||
45 | int state; | ||
46 | unsigned count; | ||
47 | u32 bits; | ||
48 | } nec; | ||
49 | struct rc5_dec { | ||
50 | int state; | ||
51 | u32 bits; | ||
52 | unsigned count; | ||
53 | unsigned wanted_bits; | ||
54 | } rc5; | ||
55 | struct rc6_dec { | ||
56 | int state; | ||
57 | u8 header; | ||
58 | u32 body; | ||
59 | bool toggle; | ||
60 | unsigned count; | ||
61 | unsigned wanted_bits; | ||
62 | } rc6; | ||
63 | struct sony_dec { | ||
64 | int state; | ||
65 | u32 bits; | ||
66 | unsigned count; | ||
67 | } sony; | ||
68 | struct jvc_dec { | ||
69 | int state; | ||
70 | u16 bits; | ||
71 | u16 old_bits; | ||
72 | unsigned count; | ||
73 | bool first; | ||
74 | bool toggle; | ||
75 | } jvc; | ||
38 | }; | 76 | }; |
39 | 77 | ||
40 | /* macros for IR decoders */ | 78 | /* macros for IR decoders */ |
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 */ | ||
29 | static LIST_HEAD(decoder_list); | ||
30 | DEFINE_SPINLOCK(decoder_lock); | ||
31 | |||
32 | enum jvc_state { | 28 | enum 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 | ||
41 | struct 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 | */ | ||
61 | static 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 | */ |
81 | static int ir_jvc_decode(struct input_dev *input_dev, struct ir_raw_event ev) | 44 | static 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 | ||
204 | static 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 | |||
222 | static 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 | |||
238 | static struct ir_raw_handler jvc_handler = { | 163 | static 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 | ||
245 | static int __init ir_jvc_decode_init(void) | 168 | static int __init ir_jvc_decode_init(void) |
diff --git a/drivers/media/IR/ir-nec-decoder.c b/drivers/media/IR/ir-nec-decoder.c index db62c652dfc5..52e0f378ae3d 100644 --- a/drivers/media/IR/ir-nec-decoder.c +++ b/drivers/media/IR/ir-nec-decoder.c | |||
@@ -27,10 +27,6 @@ | |||
27 | #define NEC_TRAILER_PULSE (1 * NEC_UNIT) | 27 | #define NEC_TRAILER_PULSE (1 * NEC_UNIT) |
28 | #define NEC_TRAILER_SPACE (10 * NEC_UNIT) /* even longer in reality */ | 28 | #define NEC_TRAILER_SPACE (10 * NEC_UNIT) /* even longer in reality */ |
29 | 29 | ||
30 | /* Used to register nec_decoder clients */ | ||
31 | static LIST_HEAD(decoder_list); | ||
32 | static DEFINE_SPINLOCK(decoder_lock); | ||
33 | |||
34 | enum nec_state { | 30 | enum nec_state { |
35 | STATE_INACTIVE, | 31 | STATE_INACTIVE, |
36 | STATE_HEADER_SPACE, | 32 | STATE_HEADER_SPACE, |
@@ -40,36 +36,6 @@ enum nec_state { | |||
40 | STATE_TRAILER_SPACE, | 36 | STATE_TRAILER_SPACE, |
41 | }; | 37 | }; |
42 | 38 | ||
43 | struct decoder_data { | ||
44 | struct list_head list; | ||
45 | struct ir_input_dev *ir_dev; | ||
46 | |||
47 | /* State machine control */ | ||
48 | enum nec_state state; | ||
49 | u32 nec_bits; | ||
50 | unsigned count; | ||
51 | }; | ||
52 | |||
53 | |||
54 | /** | ||
55 | * get_decoder_data() - gets decoder data | ||
56 | * @input_dev: input device | ||
57 | * | ||
58 | * Returns the struct decoder_data that corresponds to a device | ||
59 | */ | ||
60 | static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev) | ||
61 | { | ||
62 | struct decoder_data *data = NULL; | ||
63 | |||
64 | spin_lock(&decoder_lock); | ||
65 | list_for_each_entry(data, &decoder_list, list) { | ||
66 | if (data->ir_dev == ir_dev) | ||
67 | break; | ||
68 | } | ||
69 | spin_unlock(&decoder_lock); | ||
70 | return data; | ||
71 | } | ||
72 | |||
73 | /** | 39 | /** |
74 | * ir_nec_decode() - Decode one NEC pulse or space | 40 | * ir_nec_decode() - Decode one NEC pulse or space |
75 | * @input_dev: the struct input_dev descriptor of the device | 41 | * @input_dev: the struct input_dev descriptor of the device |
@@ -79,15 +45,11 @@ static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev) | |||
79 | */ | 45 | */ |
80 | static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) | 46 | static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) |
81 | { | 47 | { |
82 | struct decoder_data *data; | ||
83 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | 48 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); |
49 | struct nec_dec *data = &ir_dev->raw->nec; | ||
84 | u32 scancode; | 50 | u32 scancode; |
85 | u8 address, not_address, command, not_command; | 51 | u8 address, not_address, command, not_command; |
86 | 52 | ||
87 | data = get_decoder_data(ir_dev); | ||
88 | if (!data) | ||
89 | return -EINVAL; | ||
90 | |||
91 | if (!(ir_dev->raw->enabled_protocols & IR_TYPE_NEC)) | 53 | if (!(ir_dev->raw->enabled_protocols & IR_TYPE_NEC)) |
92 | return 0; | 54 | return 0; |
93 | 55 | ||
@@ -143,9 +105,9 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) | |||
143 | if (ev.pulse) | 105 | if (ev.pulse) |
144 | break; | 106 | break; |
145 | 107 | ||
146 | data->nec_bits <<= 1; | 108 | data->bits <<= 1; |
147 | if (eq_margin(ev.duration, NEC_BIT_1_SPACE, NEC_UNIT / 2)) | 109 | if (eq_margin(ev.duration, NEC_BIT_1_SPACE, NEC_UNIT / 2)) |
148 | data->nec_bits |= 1; | 110 | data->bits |= 1; |
149 | else if (!eq_margin(ev.duration, NEC_BIT_0_SPACE, NEC_UNIT / 2)) | 111 | else if (!eq_margin(ev.duration, NEC_BIT_0_SPACE, NEC_UNIT / 2)) |
150 | break; | 112 | break; |
151 | data->count++; | 113 | data->count++; |
@@ -174,14 +136,14 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) | |||
174 | if (!geq_margin(ev.duration, NEC_TRAILER_SPACE, NEC_UNIT / 2)) | 136 | if (!geq_margin(ev.duration, NEC_TRAILER_SPACE, NEC_UNIT / 2)) |
175 | break; | 137 | break; |
176 | 138 | ||
177 | address = bitrev8((data->nec_bits >> 24) & 0xff); | 139 | address = bitrev8((data->bits >> 24) & 0xff); |
178 | not_address = bitrev8((data->nec_bits >> 16) & 0xff); | 140 | not_address = bitrev8((data->bits >> 16) & 0xff); |
179 | command = bitrev8((data->nec_bits >> 8) & 0xff); | 141 | command = bitrev8((data->bits >> 8) & 0xff); |
180 | not_command = bitrev8((data->nec_bits >> 0) & 0xff); | 142 | not_command = bitrev8((data->bits >> 0) & 0xff); |
181 | 143 | ||
182 | if ((command ^ not_command) != 0xff) { | 144 | if ((command ^ not_command) != 0xff) { |
183 | IR_dprintk(1, "NEC checksum error: received 0x%08x\n", | 145 | IR_dprintk(1, "NEC checksum error: received 0x%08x\n", |
184 | data->nec_bits); | 146 | data->bits); |
185 | break; | 147 | break; |
186 | } | 148 | } |
187 | 149 | ||
@@ -208,45 +170,9 @@ static int ir_nec_decode(struct input_dev *input_dev, struct ir_raw_event ev) | |||
208 | return -EINVAL; | 170 | return -EINVAL; |
209 | } | 171 | } |
210 | 172 | ||
211 | static int ir_nec_register(struct input_dev *input_dev) | ||
212 | { | ||
213 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
214 | struct decoder_data *data; | ||
215 | |||
216 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
217 | if (!data) | ||
218 | return -ENOMEM; | ||
219 | |||
220 | data->ir_dev = ir_dev; | ||
221 | |||
222 | spin_lock(&decoder_lock); | ||
223 | list_add_tail(&data->list, &decoder_list); | ||
224 | spin_unlock(&decoder_lock); | ||
225 | |||
226 | return 0; | ||
227 | } | ||
228 | |||
229 | static int ir_nec_unregister(struct input_dev *input_dev) | ||
230 | { | ||
231 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
232 | static struct decoder_data *data; | ||
233 | |||
234 | data = get_decoder_data(ir_dev); | ||
235 | if (!data) | ||
236 | return 0; | ||
237 | |||
238 | spin_lock(&decoder_lock); | ||
239 | list_del(&data->list); | ||
240 | spin_unlock(&decoder_lock); | ||
241 | |||
242 | return 0; | ||
243 | } | ||
244 | |||
245 | static struct ir_raw_handler nec_handler = { | 173 | static struct ir_raw_handler nec_handler = { |
246 | .protocols = IR_TYPE_NEC, | 174 | .protocols = IR_TYPE_NEC, |
247 | .decode = ir_nec_decode, | 175 | .decode = ir_nec_decode, |
248 | .raw_register = ir_nec_register, | ||
249 | .raw_unregister = ir_nec_unregister, | ||
250 | }; | 176 | }; |
251 | 177 | ||
252 | static int __init ir_nec_decode_init(void) | 178 | static int __init ir_nec_decode_init(void) |
diff --git a/drivers/media/IR/ir-raw-event.c b/drivers/media/IR/ir-raw-event.c index fb3336c37191..5f98ab823057 100644 --- a/drivers/media/IR/ir-raw-event.c +++ b/drivers/media/IR/ir-raw-event.c | |||
@@ -20,36 +20,14 @@ | |||
20 | /* Define the max number of pulse/space transitions to buffer */ | 20 | /* Define the max number of pulse/space transitions to buffer */ |
21 | #define MAX_IR_EVENT_SIZE 512 | 21 | #define MAX_IR_EVENT_SIZE 512 |
22 | 22 | ||
23 | /* Used to keep track of IR raw clients, protected by ir_raw_handler_lock */ | ||
24 | static LIST_HEAD(ir_raw_client_list); | ||
25 | |||
23 | /* Used to handle IR raw handler extensions */ | 26 | /* Used to handle IR raw handler extensions */ |
24 | static DEFINE_SPINLOCK(ir_raw_handler_lock); | 27 | static DEFINE_SPINLOCK(ir_raw_handler_lock); |
25 | static LIST_HEAD(ir_raw_handler_list); | 28 | static LIST_HEAD(ir_raw_handler_list); |
26 | static u64 available_protocols; | 29 | static u64 available_protocols; |
27 | 30 | ||
28 | /** | ||
29 | * RUN_DECODER() - runs an operation on all IR decoders | ||
30 | * @ops: IR raw handler operation to be called | ||
31 | * @arg: arguments to be passed to the callback | ||
32 | * | ||
33 | * Calls ir_raw_handler::ops for all registered IR handlers. It prevents | ||
34 | * new decode addition/removal while running, by locking ir_raw_handler_lock | ||
35 | * mutex. If an error occurs, we keep going, as in the decode case, each | ||
36 | * decoder must have a crack at decoding the data. We return a sum of the | ||
37 | * return codes, which will be either 0 or negative for current callers. | ||
38 | */ | ||
39 | #define RUN_DECODER(ops, ...) ({ \ | ||
40 | struct ir_raw_handler *_ir_raw_handler; \ | ||
41 | int _sumrc = 0, _rc; \ | ||
42 | spin_lock(&ir_raw_handler_lock); \ | ||
43 | list_for_each_entry(_ir_raw_handler, &ir_raw_handler_list, list) { \ | ||
44 | if (_ir_raw_handler->ops) { \ | ||
45 | _rc = _ir_raw_handler->ops(__VA_ARGS__); \ | ||
46 | _sumrc += _rc; \ | ||
47 | } \ | ||
48 | } \ | ||
49 | spin_unlock(&ir_raw_handler_lock); \ | ||
50 | _sumrc; \ | ||
51 | }) | ||
52 | |||
53 | #ifdef MODULE | 31 | #ifdef MODULE |
54 | /* Used to load the decoders */ | 32 | /* Used to load the decoders */ |
55 | static struct work_struct wq_load; | 33 | static struct work_struct wq_load; |
@@ -58,11 +36,17 @@ static struct work_struct wq_load; | |||
58 | static void ir_raw_event_work(struct work_struct *work) | 36 | static void ir_raw_event_work(struct work_struct *work) |
59 | { | 37 | { |
60 | struct ir_raw_event ev; | 38 | struct ir_raw_event ev; |
39 | struct ir_raw_handler *handler; | ||
61 | struct ir_raw_event_ctrl *raw = | 40 | struct ir_raw_event_ctrl *raw = |
62 | container_of(work, struct ir_raw_event_ctrl, rx_work); | 41 | container_of(work, struct ir_raw_event_ctrl, rx_work); |
63 | 42 | ||
64 | while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) | 43 | while (kfifo_out(&raw->kfifo, &ev, sizeof(ev)) == sizeof(ev)) { |
65 | RUN_DECODER(decode, raw->input_dev, ev); | 44 | spin_lock(&ir_raw_handler_lock); |
45 | list_for_each_entry(handler, &ir_raw_handler_list, list) | ||
46 | handler->decode(raw->input_dev, ev); | ||
47 | spin_unlock(&ir_raw_handler_lock); | ||
48 | raw->prev_ev = ev; | ||
49 | } | ||
66 | } | 50 | } |
67 | 51 | ||
68 | /** | 52 | /** |
@@ -176,6 +160,7 @@ int ir_raw_event_register(struct input_dev *input_dev) | |||
176 | { | 160 | { |
177 | struct ir_input_dev *ir = input_get_drvdata(input_dev); | 161 | struct ir_input_dev *ir = input_get_drvdata(input_dev); |
178 | int rc; | 162 | int rc; |
163 | struct ir_raw_handler *handler; | ||
179 | 164 | ||
180 | ir->raw = kzalloc(sizeof(*ir->raw), GFP_KERNEL); | 165 | ir->raw = kzalloc(sizeof(*ir->raw), GFP_KERNEL); |
181 | if (!ir->raw) | 166 | if (!ir->raw) |
@@ -192,26 +177,32 @@ int ir_raw_event_register(struct input_dev *input_dev) | |||
192 | return rc; | 177 | return rc; |
193 | } | 178 | } |
194 | 179 | ||
195 | rc = RUN_DECODER(raw_register, input_dev); | 180 | spin_lock(&ir_raw_handler_lock); |
196 | if (rc < 0) { | 181 | list_add_tail(&ir->raw->list, &ir_raw_client_list); |
197 | kfifo_free(&ir->raw->kfifo); | 182 | list_for_each_entry(handler, &ir_raw_handler_list, list) |
198 | kfree(ir->raw); | 183 | if (handler->raw_register) |
199 | ir->raw = NULL; | 184 | handler->raw_register(ir->raw->input_dev); |
200 | return rc; | 185 | spin_unlock(&ir_raw_handler_lock); |
201 | } | ||
202 | 186 | ||
203 | return rc; | 187 | return 0; |
204 | } | 188 | } |
205 | 189 | ||
206 | void ir_raw_event_unregister(struct input_dev *input_dev) | 190 | void ir_raw_event_unregister(struct input_dev *input_dev) |
207 | { | 191 | { |
208 | struct ir_input_dev *ir = input_get_drvdata(input_dev); | 192 | struct ir_input_dev *ir = input_get_drvdata(input_dev); |
193 | struct ir_raw_handler *handler; | ||
209 | 194 | ||
210 | if (!ir->raw) | 195 | if (!ir->raw) |
211 | return; | 196 | return; |
212 | 197 | ||
213 | cancel_work_sync(&ir->raw->rx_work); | 198 | cancel_work_sync(&ir->raw->rx_work); |
214 | RUN_DECODER(raw_unregister, input_dev); | 199 | |
200 | spin_lock(&ir_raw_handler_lock); | ||
201 | list_del(&ir->raw->list); | ||
202 | list_for_each_entry(handler, &ir_raw_handler_list, list) | ||
203 | if (handler->raw_unregister) | ||
204 | handler->raw_unregister(ir->raw->input_dev); | ||
205 | spin_unlock(&ir_raw_handler_lock); | ||
215 | 206 | ||
216 | kfifo_free(&ir->raw->kfifo); | 207 | kfifo_free(&ir->raw->kfifo); |
217 | kfree(ir->raw); | 208 | kfree(ir->raw); |
@@ -224,8 +215,13 @@ void ir_raw_event_unregister(struct input_dev *input_dev) | |||
224 | 215 | ||
225 | int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler) | 216 | int ir_raw_handler_register(struct ir_raw_handler *ir_raw_handler) |
226 | { | 217 | { |
218 | struct ir_raw_event_ctrl *raw; | ||
219 | |||
227 | spin_lock(&ir_raw_handler_lock); | 220 | spin_lock(&ir_raw_handler_lock); |
228 | list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list); | 221 | list_add_tail(&ir_raw_handler->list, &ir_raw_handler_list); |
222 | if (ir_raw_handler->raw_register) | ||
223 | list_for_each_entry(raw, &ir_raw_client_list, list) | ||
224 | ir_raw_handler->raw_register(raw->input_dev); | ||
229 | available_protocols |= ir_raw_handler->protocols; | 225 | available_protocols |= ir_raw_handler->protocols; |
230 | spin_unlock(&ir_raw_handler_lock); | 226 | spin_unlock(&ir_raw_handler_lock); |
231 | 227 | ||
@@ -235,8 +231,13 @@ EXPORT_SYMBOL(ir_raw_handler_register); | |||
235 | 231 | ||
236 | void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler) | 232 | void ir_raw_handler_unregister(struct ir_raw_handler *ir_raw_handler) |
237 | { | 233 | { |
234 | struct ir_raw_event_ctrl *raw; | ||
235 | |||
238 | spin_lock(&ir_raw_handler_lock); | 236 | spin_lock(&ir_raw_handler_lock); |
239 | list_del(&ir_raw_handler->list); | 237 | list_del(&ir_raw_handler->list); |
238 | if (ir_raw_handler->raw_unregister) | ||
239 | list_for_each_entry(raw, &ir_raw_client_list, list) | ||
240 | ir_raw_handler->raw_unregister(raw->input_dev); | ||
240 | available_protocols &= ~ir_raw_handler->protocols; | 241 | available_protocols &= ~ir_raw_handler->protocols; |
241 | spin_unlock(&ir_raw_handler_lock); | 242 | spin_unlock(&ir_raw_handler_lock); |
242 | } | 243 | } |
diff --git a/drivers/media/IR/ir-rc5-decoder.c b/drivers/media/IR/ir-rc5-decoder.c index bdfa404a6537..df4770d978ad 100644 --- a/drivers/media/IR/ir-rc5-decoder.c +++ b/drivers/media/IR/ir-rc5-decoder.c | |||
@@ -30,10 +30,6 @@ | |||
30 | #define RC5_BIT_END (1 * RC5_UNIT) | 30 | #define RC5_BIT_END (1 * RC5_UNIT) |
31 | #define RC5X_SPACE (4 * RC5_UNIT) | 31 | #define RC5X_SPACE (4 * RC5_UNIT) |
32 | 32 | ||
33 | /* Used to register rc5_decoder clients */ | ||
34 | static LIST_HEAD(decoder_list); | ||
35 | static DEFINE_SPINLOCK(decoder_lock); | ||
36 | |||
37 | enum rc5_state { | 33 | enum rc5_state { |
38 | STATE_INACTIVE, | 34 | STATE_INACTIVE, |
39 | STATE_BIT_START, | 35 | STATE_BIT_START, |
@@ -42,39 +38,6 @@ enum rc5_state { | |||
42 | STATE_FINISHED, | 38 | STATE_FINISHED, |
43 | }; | 39 | }; |
44 | 40 | ||
45 | struct decoder_data { | ||
46 | struct list_head list; | ||
47 | struct ir_input_dev *ir_dev; | ||
48 | |||
49 | /* State machine control */ | ||
50 | enum rc5_state state; | ||
51 | u32 rc5_bits; | ||
52 | struct ir_raw_event prev_ev; | ||
53 | unsigned count; | ||
54 | unsigned wanted_bits; | ||
55 | }; | ||
56 | |||
57 | |||
58 | /** | ||
59 | * get_decoder_data() - gets decoder data | ||
60 | * @input_dev: input device | ||
61 | * | ||
62 | * Returns the struct decoder_data that corresponds to a device | ||
63 | */ | ||
64 | |||
65 | static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev) | ||
66 | { | ||
67 | struct decoder_data *data = NULL; | ||
68 | |||
69 | spin_lock(&decoder_lock); | ||
70 | list_for_each_entry(data, &decoder_list, list) { | ||
71 | if (data->ir_dev == ir_dev) | ||
72 | break; | ||
73 | } | ||
74 | spin_unlock(&decoder_lock); | ||
75 | return data; | ||
76 | } | ||
77 | |||
78 | /** | 41 | /** |
79 | * ir_rc5_decode() - Decode one RC-5 pulse or space | 42 | * ir_rc5_decode() - Decode one RC-5 pulse or space |
80 | * @input_dev: the struct input_dev descriptor of the device | 43 | * @input_dev: the struct input_dev descriptor of the device |
@@ -84,15 +47,11 @@ static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev) | |||
84 | */ | 47 | */ |
85 | static int ir_rc5_decode(struct input_dev *input_dev, struct ir_raw_event ev) | 48 | static int ir_rc5_decode(struct input_dev *input_dev, struct ir_raw_event ev) |
86 | { | 49 | { |
87 | struct decoder_data *data; | ||
88 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | 50 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); |
51 | struct rc5_dec *data = &ir_dev->raw->rc5; | ||
89 | u8 toggle; | 52 | u8 toggle; |
90 | u32 scancode; | 53 | u32 scancode; |
91 | 54 | ||
92 | data = get_decoder_data(ir_dev); | ||
93 | if (!data) | ||
94 | return -EINVAL; | ||
95 | |||
96 | if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC5)) | 55 | if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC5)) |
97 | return 0; | 56 | return 0; |
98 | 57 | ||
@@ -128,16 +87,15 @@ again: | |||
128 | if (!eq_margin(ev.duration, RC5_BIT_START, RC5_UNIT / 2)) | 87 | if (!eq_margin(ev.duration, RC5_BIT_START, RC5_UNIT / 2)) |
129 | break; | 88 | break; |
130 | 89 | ||
131 | data->rc5_bits <<= 1; | 90 | data->bits <<= 1; |
132 | if (!ev.pulse) | 91 | if (!ev.pulse) |
133 | data->rc5_bits |= 1; | 92 | data->bits |= 1; |
134 | data->count++; | 93 | data->count++; |
135 | data->prev_ev = ev; | ||
136 | data->state = STATE_BIT_END; | 94 | data->state = STATE_BIT_END; |
137 | return 0; | 95 | return 0; |
138 | 96 | ||
139 | case STATE_BIT_END: | 97 | case STATE_BIT_END: |
140 | if (!is_transition(&ev, &data->prev_ev)) | 98 | if (!is_transition(&ev, &ir_dev->raw->prev_ev)) |
141 | break; | 99 | break; |
142 | 100 | ||
143 | if (data->count == data->wanted_bits) | 101 | if (data->count == data->wanted_bits) |
@@ -169,11 +127,11 @@ again: | |||
169 | if (data->wanted_bits == RC5X_NBITS) { | 127 | if (data->wanted_bits == RC5X_NBITS) { |
170 | /* RC5X */ | 128 | /* RC5X */ |
171 | u8 xdata, command, system; | 129 | u8 xdata, command, system; |
172 | xdata = (data->rc5_bits & 0x0003F) >> 0; | 130 | xdata = (data->bits & 0x0003F) >> 0; |
173 | command = (data->rc5_bits & 0x00FC0) >> 6; | 131 | command = (data->bits & 0x00FC0) >> 6; |
174 | system = (data->rc5_bits & 0x1F000) >> 12; | 132 | system = (data->bits & 0x1F000) >> 12; |
175 | toggle = (data->rc5_bits & 0x20000) ? 1 : 0; | 133 | toggle = (data->bits & 0x20000) ? 1 : 0; |
176 | command += (data->rc5_bits & 0x01000) ? 0 : 0x40; | 134 | command += (data->bits & 0x01000) ? 0 : 0x40; |
177 | scancode = system << 16 | command << 8 | xdata; | 135 | scancode = system << 16 | command << 8 | xdata; |
178 | 136 | ||
179 | IR_dprintk(1, "RC5X scancode 0x%06x (toggle: %u)\n", | 137 | IR_dprintk(1, "RC5X scancode 0x%06x (toggle: %u)\n", |
@@ -182,10 +140,10 @@ again: | |||
182 | } else { | 140 | } else { |
183 | /* RC5 */ | 141 | /* RC5 */ |
184 | u8 command, system; | 142 | u8 command, system; |
185 | command = (data->rc5_bits & 0x0003F) >> 0; | 143 | command = (data->bits & 0x0003F) >> 0; |
186 | system = (data->rc5_bits & 0x007C0) >> 6; | 144 | system = (data->bits & 0x007C0) >> 6; |
187 | toggle = (data->rc5_bits & 0x00800) ? 1 : 0; | 145 | toggle = (data->bits & 0x00800) ? 1 : 0; |
188 | command += (data->rc5_bits & 0x01000) ? 0 : 0x40; | 146 | command += (data->bits & 0x01000) ? 0 : 0x40; |
189 | scancode = system << 8 | command; | 147 | scancode = system << 8 | command; |
190 | 148 | ||
191 | IR_dprintk(1, "RC5 scancode 0x%04x (toggle: %u)\n", | 149 | IR_dprintk(1, "RC5 scancode 0x%04x (toggle: %u)\n", |
@@ -204,45 +162,9 @@ out: | |||
204 | return -EINVAL; | 162 | return -EINVAL; |
205 | } | 163 | } |
206 | 164 | ||
207 | static int ir_rc5_register(struct input_dev *input_dev) | ||
208 | { | ||
209 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
210 | struct decoder_data *data; | ||
211 | |||
212 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
213 | if (!data) | ||
214 | return -ENOMEM; | ||
215 | |||
216 | data->ir_dev = ir_dev; | ||
217 | |||
218 | spin_lock(&decoder_lock); | ||
219 | list_add_tail(&data->list, &decoder_list); | ||
220 | spin_unlock(&decoder_lock); | ||
221 | |||
222 | return 0; | ||
223 | } | ||
224 | |||
225 | static int ir_rc5_unregister(struct input_dev *input_dev) | ||
226 | { | ||
227 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
228 | static struct decoder_data *data; | ||
229 | |||
230 | data = get_decoder_data(ir_dev); | ||
231 | if (!data) | ||
232 | return 0; | ||
233 | |||
234 | spin_lock(&decoder_lock); | ||
235 | list_del(&data->list); | ||
236 | spin_unlock(&decoder_lock); | ||
237 | |||
238 | return 0; | ||
239 | } | ||
240 | |||
241 | static struct ir_raw_handler rc5_handler = { | 165 | static struct ir_raw_handler rc5_handler = { |
242 | .protocols = IR_TYPE_RC5, | 166 | .protocols = IR_TYPE_RC5, |
243 | .decode = ir_rc5_decode, | 167 | .decode = ir_rc5_decode, |
244 | .raw_register = ir_rc5_register, | ||
245 | .raw_unregister = ir_rc5_unregister, | ||
246 | }; | 168 | }; |
247 | 169 | ||
248 | static int __init ir_rc5_decode_init(void) | 170 | static int __init ir_rc5_decode_init(void) |
diff --git a/drivers/media/IR/ir-rc6-decoder.c b/drivers/media/IR/ir-rc6-decoder.c index 2ebd4ea69538..f1624b8279bc 100644 --- a/drivers/media/IR/ir-rc6-decoder.c +++ b/drivers/media/IR/ir-rc6-decoder.c | |||
@@ -36,10 +36,6 @@ | |||
36 | #define RC6_STARTBIT_MASK 0x08 /* for the header bits */ | 36 | #define RC6_STARTBIT_MASK 0x08 /* for the header bits */ |
37 | #define RC6_6A_MCE_TOGGLE_MASK 0x8000 /* for the body bits */ | 37 | #define RC6_6A_MCE_TOGGLE_MASK 0x8000 /* for the body bits */ |
38 | 38 | ||
39 | /* Used to register rc6_decoder clients */ | ||
40 | static LIST_HEAD(decoder_list); | ||
41 | static DEFINE_SPINLOCK(decoder_lock); | ||
42 | |||
43 | enum rc6_mode { | 39 | enum rc6_mode { |
44 | RC6_MODE_0, | 40 | RC6_MODE_0, |
45 | RC6_MODE_6A, | 41 | RC6_MODE_6A, |
@@ -58,41 +54,8 @@ enum rc6_state { | |||
58 | STATE_FINISHED, | 54 | STATE_FINISHED, |
59 | }; | 55 | }; |
60 | 56 | ||
61 | struct decoder_data { | 57 | static enum rc6_mode rc6_mode(struct rc6_dec *data) |
62 | struct list_head list; | ||
63 | struct ir_input_dev *ir_dev; | ||
64 | |||
65 | /* State machine control */ | ||
66 | enum rc6_state state; | ||
67 | u8 header; | ||
68 | u32 body; | ||
69 | struct ir_raw_event prev_ev; | ||
70 | bool toggle; | ||
71 | unsigned count; | ||
72 | unsigned wanted_bits; | ||
73 | }; | ||
74 | |||
75 | |||
76 | /** | ||
77 | * get_decoder_data() - gets decoder data | ||
78 | * @input_dev: input device | ||
79 | * | ||
80 | * Returns the struct decoder_data that corresponds to a device | ||
81 | */ | ||
82 | static struct decoder_data *get_decoder_data(struct ir_input_dev *ir_dev) | ||
83 | { | 58 | { |
84 | struct decoder_data *data = NULL; | ||
85 | |||
86 | spin_lock(&decoder_lock); | ||
87 | list_for_each_entry(data, &decoder_list, list) { | ||
88 | if (data->ir_dev == ir_dev) | ||
89 | break; | ||
90 | } | ||
91 | spin_unlock(&decoder_lock); | ||
92 | return data; | ||
93 | } | ||
94 | |||
95 | static enum rc6_mode rc6_mode(struct decoder_data *data) { | ||
96 | switch (data->header & RC6_MODE_MASK) { | 59 | switch (data->header & RC6_MODE_MASK) { |
97 | case 0: | 60 | case 0: |
98 | return RC6_MODE_0; | 61 | return RC6_MODE_0; |
@@ -114,15 +77,11 @@ static enum rc6_mode rc6_mode(struct decoder_data *data) { | |||
114 | */ | 77 | */ |
115 | static int ir_rc6_decode(struct input_dev *input_dev, struct ir_raw_event ev) | 78 | static int ir_rc6_decode(struct input_dev *input_dev, struct ir_raw_event ev) |
116 | { | 79 | { |
117 | struct decoder_data *data; | ||
118 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | 80 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); |
81 | struct rc6_dec *data = &ir_dev->raw->rc6; | ||
119 | u32 scancode; | 82 | u32 scancode; |
120 | u8 toggle; | 83 | u8 toggle; |
121 | 84 | ||
122 | data = get_decoder_data(ir_dev); | ||
123 | if (!data) | ||
124 | return -EINVAL; | ||
125 | |||
126 | if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC6)) | 85 | if (!(ir_dev->raw->enabled_protocols & IR_TYPE_RC6)) |
127 | return 0; | 86 | return 0; |
128 | 87 | ||
@@ -175,12 +134,11 @@ again: | |||
175 | if (ev.pulse) | 134 | if (ev.pulse) |
176 | data->header |= 1; | 135 | data->header |= 1; |
177 | data->count++; | 136 | data->count++; |
178 | data->prev_ev = ev; | ||
179 | data->state = STATE_HEADER_BIT_END; | 137 | data->state = STATE_HEADER_BIT_END; |
180 | return 0; | 138 | return 0; |
181 | 139 | ||
182 | case STATE_HEADER_BIT_END: | 140 | case STATE_HEADER_BIT_END: |
183 | if (!is_transition(&ev, &data->prev_ev)) | 141 | if (!is_transition(&ev, &ir_dev->raw->prev_ev)) |
184 | break; | 142 | break; |
185 | 143 | ||
186 | if (data->count == RC6_HEADER_NBITS) | 144 | if (data->count == RC6_HEADER_NBITS) |
@@ -196,12 +154,11 @@ again: | |||
196 | break; | 154 | break; |
197 | 155 | ||
198 | data->toggle = ev.pulse; | 156 | data->toggle = ev.pulse; |
199 | data->prev_ev = ev; | ||
200 | data->state = STATE_TOGGLE_END; | 157 | data->state = STATE_TOGGLE_END; |
201 | return 0; | 158 | return 0; |
202 | 159 | ||
203 | case STATE_TOGGLE_END: | 160 | case STATE_TOGGLE_END: |
204 | if (!is_transition(&ev, &data->prev_ev) || | 161 | if (!is_transition(&ev, &ir_dev->raw->prev_ev) || |
205 | !geq_margin(ev.duration, RC6_TOGGLE_END, RC6_UNIT / 2)) | 162 | !geq_margin(ev.duration, RC6_TOGGLE_END, RC6_UNIT / 2)) |
206 | break; | 163 | break; |
207 | 164 | ||
@@ -211,7 +168,6 @@ again: | |||
211 | } | 168 | } |
212 | 169 | ||
213 | data->state = STATE_BODY_BIT_START; | 170 | data->state = STATE_BODY_BIT_START; |
214 | data->prev_ev = ev; | ||
215 | decrease_duration(&ev, RC6_TOGGLE_END); | 171 | decrease_duration(&ev, RC6_TOGGLE_END); |
216 | data->count = 0; | 172 | data->count = 0; |
217 | 173 | ||
@@ -243,13 +199,11 @@ again: | |||
243 | if (ev.pulse) | 199 | if (ev.pulse) |
244 | data->body |= 1; | 200 | data->body |= 1; |
245 | data->count++; | 201 | data->count++; |
246 | data->prev_ev = ev; | ||
247 | |||
248 | data->state = STATE_BODY_BIT_END; | 202 | data->state = STATE_BODY_BIT_END; |
249 | return 0; | 203 | return 0; |
250 | 204 | ||
251 | case STATE_BODY_BIT_END: | 205 | case STATE_BODY_BIT_END: |
252 | if (!is_transition(&ev, &data->prev_ev)) | 206 | if (!is_transition(&ev, &ir_dev->raw->prev_ev)) |
253 | break; | 207 | break; |
254 | 208 | ||
255 | if (data->count == data->wanted_bits) | 209 | if (data->count == data->wanted_bits) |
@@ -300,45 +254,9 @@ out: | |||
300 | return -EINVAL; | 254 | return -EINVAL; |
301 | } | 255 | } |
302 | 256 | ||
303 | static int ir_rc6_register(struct input_dev *input_dev) | ||
304 | { | ||
305 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
306 | struct decoder_data *data; | ||
307 | |||
308 | data = kzalloc(sizeof(*data), GFP_KERNEL); | ||
309 | if (!data) | ||
310 | return -ENOMEM; | ||
311 | |||
312 | data->ir_dev = ir_dev; | ||
313 | |||
314 | spin_lock(&decoder_lock); | ||
315 | list_add_tail(&data->list, &decoder_list); | ||
316 | spin_unlock(&decoder_lock); | ||
317 | |||
318 | return 0; | ||
319 | } | ||
320 | |||
321 | static int ir_rc6_unregister(struct input_dev *input_dev) | ||
322 | { | ||
323 | struct ir_input_dev *ir_dev = input_get_drvdata(input_dev); | ||
324 | static struct decoder_data *data; | ||
325 | |||
326 | data = get_decoder_data(ir_dev); | ||
327 | if (!data) | ||
328 | return 0; | ||
329 | |||
330 | spin_lock(&decoder_lock); | ||
331 | list_del(&data->list); | ||
332 | spin_unlock(&decoder_lock); | ||
333 | |||
334 | return 0; | ||
335 | } | ||
336 | |||
337 | static struct ir_raw_handler rc6_handler = { | 257 | static struct ir_raw_handler rc6_handler = { |
338 | .protocols = IR_TYPE_RC6, | 258 | .protocols = IR_TYPE_RC6, |
339 | .decode = ir_rc6_decode, | 259 | .decode = ir_rc6_decode, |
340 | .raw_register = ir_rc6_register, | ||
341 | .raw_unregister = ir_rc6_unregister, | ||
342 | }; | 260 | }; |
343 | 261 | ||
344 | static int __init ir_rc6_decode_init(void) | 262 | static int __init ir_rc6_decode_init(void) |
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 */ | ||
27 | static LIST_HEAD(decoder_list); | ||
28 | static DEFINE_SPINLOCK(decoder_lock); | ||
29 | |||
30 | enum sony_state { | 26 | enum 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 | ||
38 | struct 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 | */ | ||
55 | static 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 | */ |
75 | static int ir_sony_decode(struct input_dev *input_dev, struct ir_raw_event ev) | 41 | static 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 | ||
196 | static 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 | |||
214 | static 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 | |||
230 | static struct ir_raw_handler sony_handler = { | 158 | static 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 | ||
237 | static int __init ir_sony_decode_init(void) | 163 | static int __init ir_sony_decode_init(void) |