kernel: refresh patches
[openwrt/openwrt.git] / target / linux / sunxi / patches-3.14 / 284-ir-backports-from-3.15.patch
1 From 00942d1a1bd93ac108c1b92d504c568a37be1833 Mon Sep 17 00:00:00 2001
2 From: James Hogan <james.hogan@imgtec.com>
3 Date: Fri, 17 Jan 2014 10:58:49 -0300
4 Subject: [PATCH] [media] media: rc: add sysfs scancode filtering interface
5
6 Add and document a generic sysfs based scancode filtering interface for
7 making use of IR data matching hardware to filter out uninteresting
8 scancodes. Two filters exist, one for normal operation and one for
9 filtering scancodes which are permitted to wake the system from suspend.
10
11 The following files are added to /sys/class/rc/rc?/:
12 - filter: normal scancode filter value
13 - filter_mask: normal scancode filter mask
14 - wakeup_filter: wakeup scancode filter value
15 - wakeup_filter_mask: wakeup scancode filter mask
16
17 A new s_filter() driver callback is added which must arrange for the
18 specified filter to be applied at the right time. Drivers can convert
19 the scancode filter into a raw IR data filter, which can be applied
20 immediately or later (for wake up filters).
21
22 Signed-off-by: James Hogan <james.hogan@imgtec.com>
23 Cc: Mauro Carvalho Chehab <m.chehab@samsung.com>
24 Cc: linux-media@vger.kernel.org
25 Cc: Rob Landley <rob@landley.net>
26 Cc: linux-doc@vger.kernel.org
27 Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
28 ---
29 Documentation/ABI/testing/sysfs-class-rc | 58 +++++++++++++
30 drivers/media/rc/rc-main.c | 136 +++++++++++++++++++++++++++++++
31 include/media/rc-core.h | 29 +++++++
32 3 files changed, 223 insertions(+)
33
34 From 7b802ce7e8c67510389fdbbe29edd87a75df3a93 Mon Sep 17 00:00:00 2001
35 From: James Hogan <james.hogan@imgtec.com>
36 Date: Mon, 10 Feb 2014 18:31:56 -0300
37 Subject: [PATCH] [media] rc-main: store_filter: pass errors to userland
38 MIME-Version: 1.0
39 Content-Type: text/plain; charset=UTF-8
40 Content-Transfer-Encoding: 8bit
41
42 Propagate errors returned by drivers from the s_filter callback back to
43 userland when updating scancode filters. This allows userland to see
44 when the filter couldn't be updated, usually because it's not a valid
45 filter for the hardware.
46
47 Previously the filter was being updated conditionally on success of
48 s_filter, but the write always reported success back to userland.
49
50 Reported-by: Antti Seppälä <a.seppala@gmail.com>
51 Signed-off-by: James Hogan <james.hogan@imgtec.com>
52 Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
53 ---
54 drivers/media/rc/rc-main.c | 2 +-
55 1 file changed, 1 insertion(+), 1 deletion(-)
56
57 From b8c7d915087c97a21fa415fa0e860e59739da202 Mon Sep 17 00:00:00 2001
58 From: James Hogan <james.hogan@imgtec.com>
59 Date: Fri, 28 Feb 2014 20:17:02 -0300
60 Subject: [PATCH] [media] rc-main: add generic scancode filtering
61 MIME-Version: 1.0
62 Content-Type: text/plain; charset=UTF-8
63 Content-Transfer-Encoding: 8bit
64
65 Add generic scancode filtering of RC input events, and fall back to
66 permitting any RC_FILTER_NORMAL scancode filter to be set if no s_filter
67 callback exists. This allows raw IR decoder events to be filtered, and
68 potentially allows hardware decoders to set looser filters and rely on
69 generic code to filter out the corner cases.
70
71 Signed-off-by: James Hogan <james.hogan@imgtec.com>
72 Reviewed-by: Antti Seppälä <a.seppala@gmail.com>
73 Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
74 ---
75 drivers/media/rc/rc-main.c | 20 +++++++++++++-------
76 1 file changed, 13 insertions(+), 7 deletions(-)
77
78 From 1a1934fab0c920f0d3bceeb60c9fe2dae8a56be9 Mon Sep 17 00:00:00 2001
79 From: James Hogan <james.hogan@imgtec.com>
80 Date: Fri, 28 Feb 2014 20:17:03 -0300
81 Subject: [PATCH] [media] rc: abstract access to allowed/enabled protocols
82 MIME-Version: 1.0
83 Content-Type: text/plain; charset=UTF-8
84 Content-Transfer-Encoding: 8bit
85
86 The allowed and enabled protocol masks need to be expanded to be per
87 filter type in order to support wakeup filter protocol selection. To
88 ease that process abstract access to the rc_dev::allowed_protos and
89 rc_dev::enabled_protocols members with inline functions.
90
91 Signed-off-by: James Hogan <james.hogan@imgtec.com>
92 Reviewed-by: Antti Seppälä <a.seppala@gmail.com>
93 Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
94 ---
95 drivers/hid/hid-picolcd_cir.c | 2 +-
96 drivers/media/common/siano/smsir.c | 2 +-
97 drivers/media/i2c/ir-kbd-i2c.c | 4 ++--
98 drivers/media/pci/cx23885/cx23885-input.c | 2 +-
99 drivers/media/pci/cx88/cx88-input.c | 2 +-
100 drivers/media/rc/ati_remote.c | 2 +-
101 drivers/media/rc/ene_ir.c | 2 +-
102 drivers/media/rc/fintek-cir.c | 2 +-
103 drivers/media/rc/gpio-ir-recv.c | 4 ++--
104 drivers/media/rc/iguanair.c | 2 +-
105 drivers/media/rc/imon.c | 7 ++++---
106 drivers/media/rc/ir-jvc-decoder.c | 2 +-
107 drivers/media/rc/ir-lirc-codec.c | 2 +-
108 drivers/media/rc/ir-mce_kbd-decoder.c | 2 +-
109 drivers/media/rc/ir-nec-decoder.c | 2 +-
110 drivers/media/rc/ir-raw.c | 2 +-
111 drivers/media/rc/ir-rc5-decoder.c | 6 +++---
112 drivers/media/rc/ir-rc5-sz-decoder.c | 2 +-
113 drivers/media/rc/ir-rc6-decoder.c | 6 +++---
114 drivers/media/rc/ir-sanyo-decoder.c | 2 +-
115 drivers/media/rc/ir-sharp-decoder.c | 2 +-
116 drivers/media/rc/ir-sony-decoder.c | 10 +++++-----
117 drivers/media/rc/ite-cir.c | 2 +-
118 drivers/media/rc/mceusb.c | 2 +-
119 drivers/media/rc/nuvoton-cir.c | 2 +-
120 drivers/media/rc/rc-loopback.c | 2 +-
121 drivers/media/rc/redrat3.c | 2 +-
122 drivers/media/rc/st_rc.c | 2 +-
123 drivers/media/rc/streamzap.c | 2 +-
124 drivers/media/rc/ttusbir.c | 2 +-
125 drivers/media/rc/winbond-cir.c | 2 +-
126 drivers/media/usb/dvb-usb-v2/dvb_usb_core.c | 2 +-
127 drivers/media/usb/dvb-usb/dvb-usb-remote.c | 2 +-
128 drivers/media/usb/em28xx/em28xx-input.c | 8 ++++----
129 drivers/media/usb/tm6000/tm6000-input.c | 2 +-
130 include/media/rc-core.h | 22 ++++++++++++++++++++++
131 36 files changed, 73 insertions(+), 50 deletions(-)
132
133 From acff5f24732acc8a55d0a0f0ee1d19442267df63 Mon Sep 17 00:00:00 2001
134 From: James Hogan <james.hogan@imgtec.com>
135 Date: Fri, 28 Feb 2014 20:17:04 -0300
136 Subject: [PATCH] [media] rc: add allowed/enabled wakeup protocol masks
137 MIME-Version: 1.0
138 Content-Type: text/plain; charset=UTF-8
139 Content-Transfer-Encoding: 8bit
140
141 Only a single allowed and enabled protocol mask currently exists in
142 struct rc_dev, however to support a separate wakeup filter protocol two
143 of each are needed, ideally as an array.
144
145 Therefore make both rc_dev::allowed_protos and rc_dev::enabled_protocols
146 arrays, update all users to reference the first element
147 (RC_FILTER_NORMAL), and add a couple more helper functions for drivers
148 to use for setting the allowed and enabled wakeup protocols.
149
150 We also rename allowed_protos to allowed_protocols while we're at it,
151 which is more consistent with enabled_protocols.
152
153 Signed-off-by: James Hogan <james.hogan@imgtec.com>
154 Reviewed-by: Antti Seppälä <a.seppala@gmail.com>
155 Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
156 ---
157 drivers/media/rc/rc-main.c | 10 +++++-----
158 include/media/rc-core.h | 32 ++++++++++++++++++++++++--------
159 2 files changed, 29 insertions(+), 13 deletions(-)
160
161 From ab88c66deace78989aa71cb139284cf7fb227ba4 Mon Sep 17 00:00:00 2001
162 From: James Hogan <james.hogan@imgtec.com>
163 Date: Fri, 28 Feb 2014 20:17:05 -0300
164 Subject: [PATCH] [media] rc: add wakeup_protocols sysfs file
165 MIME-Version: 1.0
166 Content-Type: text/plain; charset=UTF-8
167 Content-Transfer-Encoding: 8bit
168
169 Add a wakeup_protocols sysfs file which controls the new
170 rc_dev::enabled_protocols[RC_FILTER_WAKEUP], which is the mask of
171 protocols that are used for the wakeup filter.
172
173 A new RC driver callback change_wakeup_protocol() is called to change
174 the wakeup protocol mask.
175
176 Signed-off-by: James Hogan <james.hogan@imgtec.com>
177 Reviewed-by: Antti Seppälä <a.seppala@gmail.com>
178 Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
179 ---
180 Documentation/ABI/testing/sysfs-class-rc | 23 +++++-
181 .../DocBook/media/v4l/remote_controllers.xml | 20 +++++-
182 drivers/media/rc/rc-main.c | 82 +++++++++++++---------
183 include/media/rc-core.h | 3 +
184 4 files changed, 90 insertions(+), 38 deletions(-)
185
186 From 6bea25af147fcddcd8fd4557f4184c847c5c6ffd Mon Sep 17 00:00:00 2001
187 From: James Hogan <james.hogan@imgtec.com>
188 Date: Fri, 28 Feb 2014 20:17:06 -0300
189 Subject: [PATCH] [media] rc-main: automatically refresh filter on protocol
190 change
191 MIME-Version: 1.0
192 Content-Type: text/plain; charset=UTF-8
193 Content-Transfer-Encoding: 8bit
194
195 When either of the normal or wakeup filter protocols are changed,
196 refresh the corresponding scancode filter, i.e. try and set the same
197 scancode filter with the new protocol. If that fails clear the filter
198 instead.
199
200 If no protocol was selected the filter is just cleared, and if no
201 s_filter callback exists the filter is left unmodified.
202
203 Similarly clear the filter mask when the filter is set if no protocol is
204 currently selected.
205
206 This simplifies driver code which no longer has to explicitly worry
207 about modifying the filter on a protocol change. This also allows the
208 change_wakeup_protocol callback to be omitted entirely if there is only
209 a single available wakeup protocol at a time, since selecting no
210 protocol will automatically clear the wakeup filter, disabling wakeup.
211
212 Signed-off-by: James Hogan <james.hogan@imgtec.com>
213 Reviewed-by: Antti Seppälä <a.seppala@gmail.com>
214 Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
215 ---
216 drivers/media/rc/rc-main.c | 41 +++++++++++++++++++++++++++++++++++++++--
217 1 file changed, 39 insertions(+), 2 deletions(-)
218
219 From 262912335c823a2bbcc87003ee55d62cc27f4e48 Mon Sep 17 00:00:00 2001
220 From: James Hogan <james.hogan@imgtec.com>
221 Date: Sat, 1 Mar 2014 19:52:25 -0300
222 Subject: [PATCH] [media] rc-main: fix missing unlock if no devno left
223
224 While playing with make coccicheck I noticed this message:
225 drivers/media/rc/rc-main.c:1245:3-9: preceding lock on line 1238
226
227 It was introduced by commit 587d1b06e07b ([media] rc-core: reuse device
228 numbers) which returns -ENOMEM after a mutex_lock without first
229 unlocking it when there are no more device numbers left. The added code
230 doesn't depend on the device lock, so move it before the lock is taken.
231
232 Signed-off-by: James Hogan <james.hogan@imgtec.com>
233 Signed-off-by: Mauro Carvalho Chehab <m.chehab@samsung.com>
234 ---
235 drivers/media/rc/rc-main.c | 16 ++++++++--------
236 1 file changed, 8 insertions(+), 8 deletions(-)
237
238 --- a/drivers/hid/hid-picolcd_cir.c
239 +++ b/drivers/hid/hid-picolcd_cir.c
240 @@ -114,7 +114,7 @@ int picolcd_init_cir(struct picolcd_data
241
242 rdev->priv = data;
243 rdev->driver_type = RC_DRIVER_IR_RAW;
244 - rdev->allowed_protos = RC_BIT_ALL;
245 + rc_set_allowed_protocols(rdev, RC_BIT_ALL);
246 rdev->open = picolcd_cir_open;
247 rdev->close = picolcd_cir_close;
248 rdev->input_name = data->hdev->name;
249 --- a/drivers/media/common/siano/smsir.c
250 +++ b/drivers/media/common/siano/smsir.c
251 @@ -88,7 +88,7 @@ int sms_ir_init(struct smscore_device_t
252
253 dev->priv = coredev;
254 dev->driver_type = RC_DRIVER_IR_RAW;
255 - dev->allowed_protos = RC_BIT_ALL;
256 + rc_set_allowed_protocols(dev, RC_BIT_ALL);
257 dev->map_name = sms_get_board(board_id)->rc_codes;
258 dev->driver_name = MODULE_NAME;
259
260 --- a/drivers/media/i2c/ir-kbd-i2c.c
261 +++ b/drivers/media/i2c/ir-kbd-i2c.c
262 @@ -431,8 +431,8 @@ static int ir_probe(struct i2c_client *c
263 * Initialize the other fields of rc_dev
264 */
265 rc->map_name = ir->ir_codes;
266 - rc->allowed_protos = rc_type;
267 - rc->enabled_protocols = rc_type;
268 + rc_set_allowed_protocols(rc, rc_type);
269 + rc_set_enabled_protocols(rc, rc_type);
270 if (!rc->driver_name)
271 rc->driver_name = MODULE_NAME;
272
273 --- a/drivers/media/pci/cx23885/cx23885-input.c
274 +++ b/drivers/media/pci/cx23885/cx23885-input.c
275 @@ -346,7 +346,7 @@ int cx23885_input_init(struct cx23885_de
276 }
277 rc->dev.parent = &dev->pci->dev;
278 rc->driver_type = driver_type;
279 - rc->allowed_protos = allowed_protos;
280 + rc_set_allowed_protocols(rc, allowed_protos);
281 rc->priv = kernel_ir;
282 rc->open = cx23885_input_ir_open;
283 rc->close = cx23885_input_ir_close;
284 --- a/drivers/media/pci/cx88/cx88-input.c
285 +++ b/drivers/media/pci/cx88/cx88-input.c
286 @@ -469,7 +469,7 @@ int cx88_ir_init(struct cx88_core *core,
287 dev->timeout = 10 * 1000 * 1000; /* 10 ms */
288 } else {
289 dev->driver_type = RC_DRIVER_SCANCODE;
290 - dev->allowed_protos = rc_type;
291 + rc_set_allowed_protocols(dev, rc_type);
292 }
293
294 ir->core = core;
295 --- a/drivers/media/rc/ati_remote.c
296 +++ b/drivers/media/rc/ati_remote.c
297 @@ -784,7 +784,7 @@ static void ati_remote_rc_init(struct at
298
299 rdev->priv = ati_remote;
300 rdev->driver_type = RC_DRIVER_SCANCODE;
301 - rdev->allowed_protos = RC_BIT_OTHER;
302 + rc_set_allowed_protocols(rdev, RC_BIT_OTHER);
303 rdev->driver_name = "ati_remote";
304
305 rdev->open = ati_remote_rc_open;
306 --- a/drivers/media/rc/ene_ir.c
307 +++ b/drivers/media/rc/ene_ir.c
308 @@ -1059,7 +1059,7 @@ static int ene_probe(struct pnp_dev *pnp
309 learning_mode_force = false;
310
311 rdev->driver_type = RC_DRIVER_IR_RAW;
312 - rdev->allowed_protos = RC_BIT_ALL;
313 + rc_set_allowed_protocols(rdev, RC_BIT_ALL);
314 rdev->priv = dev;
315 rdev->open = ene_open;
316 rdev->close = ene_close;
317 --- a/drivers/media/rc/fintek-cir.c
318 +++ b/drivers/media/rc/fintek-cir.c
319 @@ -541,7 +541,7 @@ static int fintek_probe(struct pnp_dev *
320 /* Set up the rc device */
321 rdev->priv = fintek;
322 rdev->driver_type = RC_DRIVER_IR_RAW;
323 - rdev->allowed_protos = RC_BIT_ALL;
324 + rc_set_allowed_protocols(rdev, RC_BIT_ALL);
325 rdev->open = fintek_open;
326 rdev->close = fintek_close;
327 rdev->input_name = FINTEK_DESCRIPTION;
328 --- a/drivers/media/rc/gpio-ir-recv.c
329 +++ b/drivers/media/rc/gpio-ir-recv.c
330 @@ -145,9 +145,9 @@ static int gpio_ir_recv_probe(struct pla
331 rcdev->dev.parent = &pdev->dev;
332 rcdev->driver_name = GPIO_IR_DRIVER_NAME;
333 if (pdata->allowed_protos)
334 - rcdev->allowed_protos = pdata->allowed_protos;
335 + rc_set_allowed_protocols(rcdev, pdata->allowed_protos);
336 else
337 - rcdev->allowed_protos = RC_BIT_ALL;
338 + rc_set_allowed_protocols(rcdev, RC_BIT_ALL);
339 rcdev->map_name = pdata->map_name ?: RC_MAP_EMPTY;
340
341 gpio_dev->rcdev = rcdev;
342 --- a/drivers/media/rc/iguanair.c
343 +++ b/drivers/media/rc/iguanair.c
344 @@ -494,7 +494,7 @@ static int iguanair_probe(struct usb_int
345 usb_to_input_id(ir->udev, &rc->input_id);
346 rc->dev.parent = &intf->dev;
347 rc->driver_type = RC_DRIVER_IR_RAW;
348 - rc->allowed_protos = RC_BIT_ALL;
349 + rc_set_allowed_protocols(rc, RC_BIT_ALL);
350 rc->priv = ir;
351 rc->open = iguanair_open;
352 rc->close = iguanair_close;
353 --- a/drivers/media/rc/imon.c
354 +++ b/drivers/media/rc/imon.c
355 @@ -1017,7 +1017,7 @@ static int imon_ir_change_protocol(struc
356 unsigned char ir_proto_packet[] = {
357 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 };
358
359 - if (*rc_type && !(*rc_type & rc->allowed_protos))
360 + if (*rc_type && !rc_protocols_allowed(rc, *rc_type))
361 dev_warn(dev, "Looks like you're trying to use an IR protocol "
362 "this device does not support\n");
363
364 @@ -1867,7 +1867,8 @@ static struct rc_dev *imon_init_rdev(str
365
366 rdev->priv = ictx;
367 rdev->driver_type = RC_DRIVER_SCANCODE;
368 - rdev->allowed_protos = RC_BIT_OTHER | RC_BIT_RC6_MCE; /* iMON PAD or MCE */
369 + /* iMON PAD or MCE */
370 + rc_set_allowed_protocols(rdev, RC_BIT_OTHER | RC_BIT_RC6_MCE);
371 rdev->change_protocol = imon_ir_change_protocol;
372 rdev->driver_name = MOD_NAME;
373
374 @@ -1880,7 +1881,7 @@ static struct rc_dev *imon_init_rdev(str
375
376 if (ictx->product == 0xffdc) {
377 imon_get_ffdc_type(ictx);
378 - rdev->allowed_protos = ictx->rc_type;
379 + rc_set_allowed_protocols(rdev, ictx->rc_type);
380 }
381
382 imon_set_display_type(ictx);
383 --- a/drivers/media/rc/ir-jvc-decoder.c
384 +++ b/drivers/media/rc/ir-jvc-decoder.c
385 @@ -47,7 +47,7 @@ static int ir_jvc_decode(struct rc_dev *
386 {
387 struct jvc_dec *data = &dev->raw->jvc;
388
389 - if (!(dev->enabled_protocols & RC_BIT_JVC))
390 + if (!rc_protocols_enabled(dev, RC_BIT_JVC))
391 return 0;
392
393 if (!is_timing_event(ev)) {
394 --- a/drivers/media/rc/ir-lirc-codec.c
395 +++ b/drivers/media/rc/ir-lirc-codec.c
396 @@ -35,7 +35,7 @@ static int ir_lirc_decode(struct rc_dev
397 struct lirc_codec *lirc = &dev->raw->lirc;
398 int sample;
399
400 - if (!(dev->enabled_protocols & RC_BIT_LIRC))
401 + if (!rc_protocols_enabled(dev, RC_BIT_LIRC))
402 return 0;
403
404 if (!dev->raw->lirc.drv || !dev->raw->lirc.drv->rbuf)
405 --- a/drivers/media/rc/ir-mce_kbd-decoder.c
406 +++ b/drivers/media/rc/ir-mce_kbd-decoder.c
407 @@ -216,7 +216,7 @@ static int ir_mce_kbd_decode(struct rc_d
408 u32 scancode;
409 unsigned long delay;
410
411 - if (!(dev->enabled_protocols & RC_BIT_MCE_KBD))
412 + if (!rc_protocols_enabled(dev, RC_BIT_MCE_KBD))
413 return 0;
414
415 if (!is_timing_event(ev)) {
416 --- a/drivers/media/rc/ir-nec-decoder.c
417 +++ b/drivers/media/rc/ir-nec-decoder.c
418 @@ -52,7 +52,7 @@ static int ir_nec_decode(struct rc_dev *
419 u8 address, not_address, command, not_command;
420 bool send_32bits = false;
421
422 - if (!(dev->enabled_protocols & RC_BIT_NEC))
423 + if (!rc_protocols_enabled(dev, RC_BIT_NEC))
424 return 0;
425
426 if (!is_timing_event(ev)) {
427 --- a/drivers/media/rc/ir-raw.c
428 +++ b/drivers/media/rc/ir-raw.c
429 @@ -256,7 +256,7 @@ int ir_raw_event_register(struct rc_dev
430 return -ENOMEM;
431
432 dev->raw->dev = dev;
433 - dev->enabled_protocols = ~0;
434 + rc_set_enabled_protocols(dev, ~0);
435 rc = kfifo_alloc(&dev->raw->kfifo,
436 sizeof(struct ir_raw_event) * MAX_IR_EVENT_SIZE,
437 GFP_KERNEL);
438 --- a/drivers/media/rc/ir-rc5-decoder.c
439 +++ b/drivers/media/rc/ir-rc5-decoder.c
440 @@ -52,7 +52,7 @@ static int ir_rc5_decode(struct rc_dev *
441 u8 toggle;
442 u32 scancode;
443
444 - if (!(dev->enabled_protocols & (RC_BIT_RC5 | RC_BIT_RC5X)))
445 + if (!rc_protocols_enabled(dev, RC_BIT_RC5 | RC_BIT_RC5X))
446 return 0;
447
448 if (!is_timing_event(ev)) {
449 @@ -128,7 +128,7 @@ again:
450 if (data->wanted_bits == RC5X_NBITS) {
451 /* RC5X */
452 u8 xdata, command, system;
453 - if (!(dev->enabled_protocols & RC_BIT_RC5X)) {
454 + if (!rc_protocols_enabled(dev, RC_BIT_RC5X)) {
455 data->state = STATE_INACTIVE;
456 return 0;
457 }
458 @@ -145,7 +145,7 @@ again:
459 } else {
460 /* RC5 */
461 u8 command, system;
462 - if (!(dev->enabled_protocols & RC_BIT_RC5)) {
463 + if (!rc_protocols_enabled(dev, RC_BIT_RC5)) {
464 data->state = STATE_INACTIVE;
465 return 0;
466 }
467 --- a/drivers/media/rc/ir-rc5-sz-decoder.c
468 +++ b/drivers/media/rc/ir-rc5-sz-decoder.c
469 @@ -48,7 +48,7 @@ static int ir_rc5_sz_decode(struct rc_de
470 u8 toggle, command, system;
471 u32 scancode;
472
473 - if (!(dev->enabled_protocols & RC_BIT_RC5_SZ))
474 + if (!rc_protocols_enabled(dev, RC_BIT_RC5_SZ))
475 return 0;
476
477 if (!is_timing_event(ev)) {
478 --- a/drivers/media/rc/ir-rc6-decoder.c
479 +++ b/drivers/media/rc/ir-rc6-decoder.c
480 @@ -89,9 +89,9 @@ static int ir_rc6_decode(struct rc_dev *
481 u32 scancode;
482 u8 toggle;
483
484 - if (!(dev->enabled_protocols &
485 - (RC_BIT_RC6_0 | RC_BIT_RC6_6A_20 | RC_BIT_RC6_6A_24 |
486 - RC_BIT_RC6_6A_32 | RC_BIT_RC6_MCE)))
487 + if (!rc_protocols_enabled(dev, RC_BIT_RC6_0 | RC_BIT_RC6_6A_20 |
488 + RC_BIT_RC6_6A_24 | RC_BIT_RC6_6A_32 |
489 + RC_BIT_RC6_MCE))
490 return 0;
491
492 if (!is_timing_event(ev)) {
493 --- a/drivers/media/rc/ir-sanyo-decoder.c
494 +++ b/drivers/media/rc/ir-sanyo-decoder.c
495 @@ -58,7 +58,7 @@ static int ir_sanyo_decode(struct rc_dev
496 u32 scancode;
497 u8 address, command, not_command;
498
499 - if (!(dev->enabled_protocols & RC_BIT_SANYO))
500 + if (!rc_protocols_enabled(dev, RC_BIT_SANYO))
501 return 0;
502
503 if (!is_timing_event(ev)) {
504 --- a/drivers/media/rc/ir-sony-decoder.c
505 +++ b/drivers/media/rc/ir-sony-decoder.c
506 @@ -45,8 +45,8 @@ static int ir_sony_decode(struct rc_dev
507 u32 scancode;
508 u8 device, subdevice, function;
509
510 - if (!(dev->enabled_protocols &
511 - (RC_BIT_SONY12 | RC_BIT_SONY15 | RC_BIT_SONY20)))
512 + if (!rc_protocols_enabled(dev, RC_BIT_SONY12 | RC_BIT_SONY15 |
513 + RC_BIT_SONY20))
514 return 0;
515
516 if (!is_timing_event(ev)) {
517 @@ -124,7 +124,7 @@ static int ir_sony_decode(struct rc_dev
518
519 switch (data->count) {
520 case 12:
521 - if (!(dev->enabled_protocols & RC_BIT_SONY12)) {
522 + if (!rc_protocols_enabled(dev, RC_BIT_SONY12)) {
523 data->state = STATE_INACTIVE;
524 return 0;
525 }
526 @@ -133,7 +133,7 @@ static int ir_sony_decode(struct rc_dev
527 function = bitrev8((data->bits >> 4) & 0xFE);
528 break;
529 case 15:
530 - if (!(dev->enabled_protocols & RC_BIT_SONY15)) {
531 + if (!rc_protocols_enabled(dev, RC_BIT_SONY15)) {
532 data->state = STATE_INACTIVE;
533 return 0;
534 }
535 @@ -142,7 +142,7 @@ static int ir_sony_decode(struct rc_dev
536 function = bitrev8((data->bits >> 7) & 0xFE);
537 break;
538 case 20:
539 - if (!(dev->enabled_protocols & RC_BIT_SONY20)) {
540 + if (!rc_protocols_enabled(dev, RC_BIT_SONY20)) {
541 data->state = STATE_INACTIVE;
542 return 0;
543 }
544 --- a/drivers/media/rc/ite-cir.c
545 +++ b/drivers/media/rc/ite-cir.c
546 @@ -1563,7 +1563,7 @@ static int ite_probe(struct pnp_dev *pde
547 /* set up ir-core props */
548 rdev->priv = itdev;
549 rdev->driver_type = RC_DRIVER_IR_RAW;
550 - rdev->allowed_protos = RC_BIT_ALL;
551 + rc_set_allowed_protocols(rdev, RC_BIT_ALL);
552 rdev->open = ite_open;
553 rdev->close = ite_close;
554 rdev->s_idle = ite_s_idle;
555 --- a/drivers/media/rc/mceusb.c
556 +++ b/drivers/media/rc/mceusb.c
557 @@ -1217,7 +1217,7 @@ static struct rc_dev *mceusb_init_rc_dev
558 rc->dev.parent = dev;
559 rc->priv = ir;
560 rc->driver_type = RC_DRIVER_IR_RAW;
561 - rc->allowed_protos = RC_BIT_ALL;
562 + rc_set_allowed_protocols(rc, RC_BIT_ALL);
563 rc->timeout = MS_TO_NS(100);
564 if (!ir->flags.no_tx) {
565 rc->s_tx_mask = mceusb_set_tx_mask;
566 --- a/drivers/media/rc/nuvoton-cir.c
567 +++ b/drivers/media/rc/nuvoton-cir.c
568 @@ -1042,7 +1042,7 @@ static int nvt_probe(struct pnp_dev *pde
569 /* Set up the rc device */
570 rdev->priv = nvt;
571 rdev->driver_type = RC_DRIVER_IR_RAW;
572 - rdev->allowed_protos = RC_BIT_ALL;
573 + rc_set_allowed_protocols(rdev, RC_BIT_ALL);
574 rdev->open = nvt_open;
575 rdev->close = nvt_close;
576 rdev->tx_ir = nvt_tx_ir;
577 --- a/drivers/media/rc/rc-loopback.c
578 +++ b/drivers/media/rc/rc-loopback.c
579 @@ -195,7 +195,7 @@ static int __init loop_init(void)
580 rc->map_name = RC_MAP_EMPTY;
581 rc->priv = &loopdev;
582 rc->driver_type = RC_DRIVER_IR_RAW;
583 - rc->allowed_protos = RC_BIT_ALL;
584 + rc_set_allowed_protocols(rc, RC_BIT_ALL);
585 rc->timeout = 100 * 1000 * 1000; /* 100 ms */
586 rc->min_timeout = 1;
587 rc->max_timeout = UINT_MAX;
588 --- a/drivers/media/rc/rc-main.c
589 +++ b/drivers/media/rc/rc-main.c
590 @@ -633,6 +633,7 @@ EXPORT_SYMBOL_GPL(rc_repeat);
591 static void ir_do_keydown(struct rc_dev *dev, int scancode,
592 u32 keycode, u8 toggle)
593 {
594 + struct rc_scancode_filter *filter;
595 bool new_event = !dev->keypressed ||
596 dev->last_scancode != scancode ||
597 dev->last_toggle != toggle;
598 @@ -640,6 +641,11 @@ static void ir_do_keydown(struct rc_dev
599 if (new_event && dev->keypressed)
600 ir_do_keyup(dev, false);
601
602 + /* Generic scancode filtering */
603 + filter = &dev->scancode_filters[RC_FILTER_NORMAL];
604 + if (filter->mask && ((scancode ^ filter->data) & filter->mask))
605 + return;
606 +
607 input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode);
608
609 if (new_event && keycode != KEY_RESERVED) {
610 @@ -795,13 +801,38 @@ static struct {
611 };
612
613 /**
614 - * show_protocols() - shows the current IR protocol(s)
615 + * struct rc_filter_attribute - Device attribute relating to a filter type.
616 + * @attr: Device attribute.
617 + * @type: Filter type.
618 + * @mask: false for filter value, true for filter mask.
619 + */
620 +struct rc_filter_attribute {
621 + struct device_attribute attr;
622 + enum rc_filter_type type;
623 + bool mask;
624 +};
625 +#define to_rc_filter_attr(a) container_of(a, struct rc_filter_attribute, attr)
626 +
627 +#define RC_PROTO_ATTR(_name, _mode, _show, _store, _type) \
628 + struct rc_filter_attribute dev_attr_##_name = { \
629 + .attr = __ATTR(_name, _mode, _show, _store), \
630 + .type = (_type), \
631 + }
632 +#define RC_FILTER_ATTR(_name, _mode, _show, _store, _type, _mask) \
633 + struct rc_filter_attribute dev_attr_##_name = { \
634 + .attr = __ATTR(_name, _mode, _show, _store), \
635 + .type = (_type), \
636 + .mask = (_mask), \
637 + }
638 +
639 +/**
640 + * show_protocols() - shows the current/wakeup IR protocol(s)
641 * @device: the device descriptor
642 * @mattr: the device attribute struct (unused)
643 * @buf: a pointer to the output buffer
644 *
645 * This routine is a callback routine for input read the IR protocol type(s).
646 - * it is trigged by reading /sys/class/rc/rc?/protocols.
647 + * it is trigged by reading /sys/class/rc/rc?/[wakeup_]protocols.
648 * It returns the protocol names of supported protocols.
649 * Enabled protocols are printed in brackets.
650 *
651 @@ -812,6 +843,7 @@ static ssize_t show_protocols(struct dev
652 struct device_attribute *mattr, char *buf)
653 {
654 struct rc_dev *dev = to_rc_dev(device);
655 + struct rc_filter_attribute *fattr = to_rc_filter_attr(mattr);
656 u64 allowed, enabled;
657 char *tmp = buf;
658 int i;
659 @@ -822,9 +854,10 @@ static ssize_t show_protocols(struct dev
660
661 mutex_lock(&dev->lock);
662
663 - enabled = dev->enabled_protocols;
664 - if (dev->driver_type == RC_DRIVER_SCANCODE)
665 - allowed = dev->allowed_protos;
666 + enabled = dev->enabled_protocols[fattr->type];
667 + if (dev->driver_type == RC_DRIVER_SCANCODE ||
668 + fattr->type == RC_FILTER_WAKEUP)
669 + allowed = dev->allowed_protocols[fattr->type];
670 else if (dev->raw)
671 allowed = ir_raw_get_allowed_protocols();
672 else {
673 @@ -856,14 +889,14 @@ static ssize_t show_protocols(struct dev
674 }
675
676 /**
677 - * store_protocols() - changes the current IR protocol(s)
678 + * store_protocols() - changes the current/wakeup IR protocol(s)
679 * @device: the device descriptor
680 * @mattr: the device attribute struct (unused)
681 * @buf: a pointer to the input buffer
682 * @len: length of the input buffer
683 *
684 * This routine is for changing the IR protocol type.
685 - * It is trigged by writing to /sys/class/rc/rc?/protocols.
686 + * It is trigged by writing to /sys/class/rc/rc?/[wakeup_]protocols.
687 * Writing "+proto" will add a protocol to the list of enabled protocols.
688 * Writing "-proto" will remove a protocol from the list of enabled protocols.
689 * Writing "proto" will enable only "proto".
690 @@ -880,12 +913,15 @@ static ssize_t store_protocols(struct de
691 size_t len)
692 {
693 struct rc_dev *dev = to_rc_dev(device);
694 + struct rc_filter_attribute *fattr = to_rc_filter_attr(mattr);
695 bool enable, disable;
696 const char *tmp;
697 - u64 type;
698 + u64 old_type, type;
699 u64 mask;
700 int rc, i, count = 0;
701 ssize_t ret;
702 + int (*change_protocol)(struct rc_dev *dev, u64 *rc_type);
703 + struct rc_scancode_filter local_filter, *filter;
704
705 /* Device is being removed */
706 if (!dev)
707 @@ -898,7 +934,8 @@ static ssize_t store_protocols(struct de
708 ret = -EINVAL;
709 goto out;
710 }
711 - type = dev->enabled_protocols;
712 + old_type = dev->enabled_protocols[fattr->type];
713 + type = old_type;
714
715 while ((tmp = strsep((char **) &data, " \n")) != NULL) {
716 if (!*tmp)
717 @@ -946,8 +983,10 @@ static ssize_t store_protocols(struct de
718 goto out;
719 }
720
721 - if (dev->change_protocol) {
722 - rc = dev->change_protocol(dev, &type);
723 + change_protocol = (fattr->type == RC_FILTER_NORMAL)
724 + ? dev->change_protocol : dev->change_wakeup_protocol;
725 + if (change_protocol) {
726 + rc = change_protocol(dev, &type);
727 if (rc < 0) {
728 IR_dprintk(1, "Error setting protocols to 0x%llx\n",
729 (long long)type);
730 @@ -956,10 +995,40 @@ static ssize_t store_protocols(struct de
731 }
732 }
733
734 - dev->enabled_protocols = type;
735 + dev->enabled_protocols[fattr->type] = type;
736 IR_dprintk(1, "Current protocol(s): 0x%llx\n",
737 (long long)type);
738
739 + /*
740 + * If the protocol is changed the filter needs updating.
741 + * Try setting the same filter with the new protocol (if any).
742 + * Fall back to clearing the filter.
743 + */
744 + filter = &dev->scancode_filters[fattr->type];
745 + if (old_type != type && filter->mask) {
746 + local_filter = *filter;
747 + if (!type) {
748 + /* no protocol => clear filter */
749 + ret = -1;
750 + } else if (!dev->s_filter) {
751 + /* generic filtering => accept any filter */
752 + ret = 0;
753 + } else {
754 + /* hardware filtering => try setting, otherwise clear */
755 + ret = dev->s_filter(dev, fattr->type, &local_filter);
756 + }
757 + if (ret < 0) {
758 + /* clear the filter */
759 + local_filter.data = 0;
760 + local_filter.mask = 0;
761 + if (dev->s_filter)
762 + dev->s_filter(dev, fattr->type, &local_filter);
763 + }
764 +
765 + /* commit the new filter */
766 + *filter = local_filter;
767 + }
768 +
769 ret = len;
770
771 out:
772 @@ -967,6 +1036,115 @@ out:
773 return ret;
774 }
775
776 +/**
777 + * show_filter() - shows the current scancode filter value or mask
778 + * @device: the device descriptor
779 + * @attr: the device attribute struct
780 + * @buf: a pointer to the output buffer
781 + *
782 + * This routine is a callback routine to read a scancode filter value or mask.
783 + * It is trigged by reading /sys/class/rc/rc?/[wakeup_]filter[_mask].
784 + * It prints the current scancode filter value or mask of the appropriate filter
785 + * type in hexadecimal into @buf and returns the size of the buffer.
786 + *
787 + * Bits of the filter value corresponding to set bits in the filter mask are
788 + * compared against input scancodes and non-matching scancodes are discarded.
789 + *
790 + * dev->lock is taken to guard against races between device registration,
791 + * store_filter and show_filter.
792 + */
793 +static ssize_t show_filter(struct device *device,
794 + struct device_attribute *attr,
795 + char *buf)
796 +{
797 + struct rc_dev *dev = to_rc_dev(device);
798 + struct rc_filter_attribute *fattr = to_rc_filter_attr(attr);
799 + u32 val;
800 +
801 + /* Device is being removed */
802 + if (!dev)
803 + return -EINVAL;
804 +
805 + mutex_lock(&dev->lock);
806 + if (fattr->mask)
807 + val = dev->scancode_filters[fattr->type].mask;
808 + else
809 + val = dev->scancode_filters[fattr->type].data;
810 + mutex_unlock(&dev->lock);
811 +
812 + return sprintf(buf, "%#x\n", val);
813 +}
814 +
815 +/**
816 + * store_filter() - changes the scancode filter value
817 + * @device: the device descriptor
818 + * @attr: the device attribute struct
819 + * @buf: a pointer to the input buffer
820 + * @len: length of the input buffer
821 + *
822 + * This routine is for changing a scancode filter value or mask.
823 + * It is trigged by writing to /sys/class/rc/rc?/[wakeup_]filter[_mask].
824 + * Returns -EINVAL if an invalid filter value for the current protocol was
825 + * specified or if scancode filtering is not supported by the driver, otherwise
826 + * returns @len.
827 + *
828 + * Bits of the filter value corresponding to set bits in the filter mask are
829 + * compared against input scancodes and non-matching scancodes are discarded.
830 + *
831 + * dev->lock is taken to guard against races between device registration,
832 + * store_filter and show_filter.
833 + */
834 +static ssize_t store_filter(struct device *device,
835 + struct device_attribute *attr,
836 + const char *buf,
837 + size_t count)
838 +{
839 + struct rc_dev *dev = to_rc_dev(device);
840 + struct rc_filter_attribute *fattr = to_rc_filter_attr(attr);
841 + struct rc_scancode_filter local_filter, *filter;
842 + int ret;
843 + unsigned long val;
844 +
845 + /* Device is being removed */
846 + if (!dev)
847 + return -EINVAL;
848 +
849 + ret = kstrtoul(buf, 0, &val);
850 + if (ret < 0)
851 + return ret;
852 +
853 + /* Scancode filter not supported (but still accept 0) */
854 + if (!dev->s_filter && fattr->type != RC_FILTER_NORMAL)
855 + return val ? -EINVAL : count;
856 +
857 + mutex_lock(&dev->lock);
858 +
859 + /* Tell the driver about the new filter */
860 + filter = &dev->scancode_filters[fattr->type];
861 + local_filter = *filter;
862 + if (fattr->mask)
863 + local_filter.mask = val;
864 + else
865 + local_filter.data = val;
866 + if (!dev->enabled_protocols[fattr->type] && local_filter.mask) {
867 + /* refuse to set a filter unless a protocol is enabled */
868 + ret = -EINVAL;
869 + goto unlock;
870 + }
871 + if (dev->s_filter) {
872 + ret = dev->s_filter(dev, fattr->type, &local_filter);
873 + if (ret < 0)
874 + goto unlock;
875 + }
876 +
877 + /* Success, commit the new filter */
878 + *filter = local_filter;
879 +
880 +unlock:
881 + mutex_unlock(&dev->lock);
882 + return (ret < 0) ? ret : count;
883 +}
884 +
885 static void rc_dev_release(struct device *device)
886 {
887 }
888 @@ -996,11 +1174,26 @@ static int rc_dev_uevent(struct device *
889 /*
890 * Static device attribute struct with the sysfs attributes for IR's
891 */
892 -static DEVICE_ATTR(protocols, S_IRUGO | S_IWUSR,
893 - show_protocols, store_protocols);
894 +static RC_PROTO_ATTR(protocols, S_IRUGO | S_IWUSR,
895 + show_protocols, store_protocols, RC_FILTER_NORMAL);
896 +static RC_PROTO_ATTR(wakeup_protocols, S_IRUGO | S_IWUSR,
897 + show_protocols, store_protocols, RC_FILTER_WAKEUP);
898 +static RC_FILTER_ATTR(filter, S_IRUGO|S_IWUSR,
899 + show_filter, store_filter, RC_FILTER_NORMAL, false);
900 +static RC_FILTER_ATTR(filter_mask, S_IRUGO|S_IWUSR,
901 + show_filter, store_filter, RC_FILTER_NORMAL, true);
902 +static RC_FILTER_ATTR(wakeup_filter, S_IRUGO|S_IWUSR,
903 + show_filter, store_filter, RC_FILTER_WAKEUP, false);
904 +static RC_FILTER_ATTR(wakeup_filter_mask, S_IRUGO|S_IWUSR,
905 + show_filter, store_filter, RC_FILTER_WAKEUP, true);
906
907 static struct attribute *rc_dev_attrs[] = {
908 - &dev_attr_protocols.attr,
909 + &dev_attr_protocols.attr.attr,
910 + &dev_attr_wakeup_protocols.attr.attr,
911 + &dev_attr_filter.attr.attr,
912 + &dev_attr_filter_mask.attr.attr,
913 + &dev_attr_wakeup_filter.attr.attr,
914 + &dev_attr_wakeup_filter_mask.attr.attr,
915 NULL,
916 };
917
918 @@ -1091,14 +1284,6 @@ int rc_register_device(struct rc_dev *de
919 if (dev->close)
920 dev->input_dev->close = ir_close;
921
922 - /*
923 - * Take the lock here, as the device sysfs node will appear
924 - * when device_add() is called, which may trigger an ir-keytable udev
925 - * rule, which will in turn call show_protocols and access
926 - * dev->enabled_protocols before it has been initialized.
927 - */
928 - mutex_lock(&dev->lock);
929 -
930 do {
931 devno = find_first_zero_bit(ir_core_dev_number,
932 IRRCV_NUM_DEVICES);
933 @@ -1107,6 +1292,14 @@ int rc_register_device(struct rc_dev *de
934 return -ENOMEM;
935 } while (test_and_set_bit(devno, ir_core_dev_number));
936
937 + /*
938 + * Take the lock here, as the device sysfs node will appear
939 + * when device_add() is called, which may trigger an ir-keytable udev
940 + * rule, which will in turn call show_protocols and access
941 + * dev->enabled_protocols before it has been initialized.
942 + */
943 + mutex_lock(&dev->lock);
944 +
945 dev->devno = devno;
946 dev_set_name(&dev->dev, "rc%ld", dev->devno);
947 dev_set_drvdata(&dev->dev, dev);
948 @@ -1172,7 +1365,7 @@ int rc_register_device(struct rc_dev *de
949 rc = dev->change_protocol(dev, &rc_type);
950 if (rc < 0)
951 goto out_raw;
952 - dev->enabled_protocols = rc_type;
953 + dev->enabled_protocols[RC_FILTER_NORMAL] = rc_type;
954 }
955
956 mutex_unlock(&dev->lock);
957 --- a/drivers/media/rc/redrat3.c
958 +++ b/drivers/media/rc/redrat3.c
959 @@ -922,7 +922,7 @@ static struct rc_dev *redrat3_init_rc_de
960 rc->dev.parent = dev;
961 rc->priv = rr3;
962 rc->driver_type = RC_DRIVER_IR_RAW;
963 - rc->allowed_protos = RC_BIT_ALL;
964 + rc_set_allowed_protocols(rc, RC_BIT_ALL);
965 rc->timeout = US_TO_NS(2750);
966 rc->tx_ir = redrat3_transmit_ir;
967 rc->s_tx_carrier = redrat3_set_tx_carrier;
968 --- a/drivers/media/rc/st_rc.c
969 +++ b/drivers/media/rc/st_rc.c
970 @@ -287,7 +287,7 @@ static int st_rc_probe(struct platform_d
971 st_rc_hardware_init(rc_dev);
972
973 rdev->driver_type = RC_DRIVER_IR_RAW;
974 - rdev->allowed_protos = RC_BIT_ALL;
975 + rc_set_allowed_protocols(rdev, RC_BIT_ALL);
976 /* rx sampling rate is 10Mhz */
977 rdev->rx_resolution = 100;
978 rdev->timeout = US_TO_NS(MAX_SYMB_TIME);
979 --- a/drivers/media/rc/streamzap.c
980 +++ b/drivers/media/rc/streamzap.c
981 @@ -322,7 +322,7 @@ static struct rc_dev *streamzap_init_rc_
982 rdev->dev.parent = dev;
983 rdev->priv = sz;
984 rdev->driver_type = RC_DRIVER_IR_RAW;
985 - rdev->allowed_protos = RC_BIT_ALL;
986 + rc_set_allowed_protocols(rdev, RC_BIT_ALL);
987 rdev->driver_name = DRIVER_NAME;
988 rdev->map_name = RC_MAP_STREAMZAP;
989
990 --- a/drivers/media/rc/ttusbir.c
991 +++ b/drivers/media/rc/ttusbir.c
992 @@ -318,7 +318,7 @@ static int ttusbir_probe(struct usb_inte
993 usb_to_input_id(tt->udev, &rc->input_id);
994 rc->dev.parent = &intf->dev;
995 rc->driver_type = RC_DRIVER_IR_RAW;
996 - rc->allowed_protos = RC_BIT_ALL;
997 + rc_set_allowed_protocols(rc, RC_BIT_ALL);
998 rc->priv = tt;
999 rc->driver_name = DRIVER_NAME;
1000 rc->map_name = RC_MAP_TT_1500;
1001 --- a/drivers/media/rc/winbond-cir.c
1002 +++ b/drivers/media/rc/winbond-cir.c
1003 @@ -1082,7 +1082,7 @@ wbcir_probe(struct pnp_dev *device, cons
1004 data->dev->dev.parent = &device->dev;
1005 data->dev->timeout = MS_TO_NS(100);
1006 data->dev->rx_resolution = US_TO_NS(2);
1007 - data->dev->allowed_protos = RC_BIT_ALL;
1008 + rc_set_allowed_protocols(data->dev, RC_BIT_ALL);
1009
1010 err = rc_register_device(data->dev);
1011 if (err)
1012 --- a/drivers/media/usb/dvb-usb/dvb-usb-remote.c
1013 +++ b/drivers/media/usb/dvb-usb/dvb-usb-remote.c
1014 @@ -272,7 +272,7 @@ static int rc_core_dvb_usb_remote_init(s
1015 dev->driver_name = d->props.rc.core.module_name;
1016 dev->map_name = d->props.rc.core.rc_codes;
1017 dev->change_protocol = d->props.rc.core.change_protocol;
1018 - dev->allowed_protos = d->props.rc.core.allowed_protos;
1019 + rc_set_allowed_protocols(dev, d->props.rc.core.allowed_protos);
1020 dev->driver_type = d->props.rc.core.driver_type;
1021 usb_to_input_id(d->udev, &dev->input_id);
1022 dev->input_name = "IR-receiver inside an USB DVB receiver";
1023 --- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
1024 +++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
1025 @@ -164,7 +164,7 @@ static int dvb_usbv2_remote_init(struct
1026 dev->driver_name = (char *) d->props->driver_name;
1027 dev->map_name = d->rc.map_name;
1028 dev->driver_type = d->rc.driver_type;
1029 - dev->allowed_protos = d->rc.allowed_protos;
1030 + rc_set_allowed_protocols(dev, d->rc.allowed_protos);
1031 dev->change_protocol = d->rc.change_protocol;
1032 dev->priv = d;
1033
1034 --- a/drivers/media/usb/em28xx/em28xx-input.c
1035 +++ b/drivers/media/usb/em28xx/em28xx-input.c
1036 @@ -725,7 +725,7 @@ static int em28xx_ir_init(struct em28xx
1037 case EM2820_BOARD_HAUPPAUGE_WINTV_USB_2:
1038 rc->map_name = RC_MAP_HAUPPAUGE;
1039 ir->get_key_i2c = em28xx_get_key_em_haup;
1040 - rc->allowed_protos = RC_BIT_RC5;
1041 + rc_set_allowed_protocols(rc, RC_BIT_RC5);
1042 break;
1043 case EM2820_BOARD_LEADTEK_WINFAST_USBII_DELUXE:
1044 rc->map_name = RC_MAP_WINFAST_USBII_DELUXE;
1045 @@ -741,7 +741,7 @@ static int em28xx_ir_init(struct em28xx
1046 switch (dev->chip_id) {
1047 case CHIP_ID_EM2860:
1048 case CHIP_ID_EM2883:
1049 - rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC;
1050 + rc_set_allowed_protocols(rc, RC_BIT_RC5 | RC_BIT_NEC);
1051 ir->get_key = default_polling_getkey;
1052 break;
1053 case CHIP_ID_EM2884:
1054 @@ -749,8 +749,8 @@ static int em28xx_ir_init(struct em28xx
1055 case CHIP_ID_EM28174:
1056 case CHIP_ID_EM28178:
1057 ir->get_key = em2874_polling_getkey;
1058 - rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC |
1059 - RC_BIT_RC6_0;
1060 + rc_set_allowed_protocols(rc, RC_BIT_RC5 | RC_BIT_NEC |
1061 + RC_BIT_RC6_0);
1062 break;
1063 default:
1064 err = -ENODEV;
1065 --- a/drivers/media/usb/tm6000/tm6000-input.c
1066 +++ b/drivers/media/usb/tm6000/tm6000-input.c
1067 @@ -422,7 +422,7 @@ int tm6000_ir_init(struct tm6000_core *d
1068 ir->rc = rc;
1069
1070 /* input setup */
1071 - rc->allowed_protos = RC_BIT_RC5 | RC_BIT_NEC;
1072 + rc_set_allowed_protocols(rc, RC_BIT_RC5 | RC_BIT_NEC);
1073 /* Neded, in order to support NEC remotes with 24 or 32 bits */
1074 rc->scanmask = 0xffff;
1075 rc->priv = ir;
1076 --- a/include/media/rc-core.h
1077 +++ b/include/media/rc-core.h
1078 @@ -35,6 +35,29 @@ enum rc_driver_type {
1079 };
1080
1081 /**
1082 + * struct rc_scancode_filter - Filter scan codes.
1083 + * @data: Scancode data to match.
1084 + * @mask: Mask of bits of scancode to compare.
1085 + */
1086 +struct rc_scancode_filter {
1087 + u32 data;
1088 + u32 mask;
1089 +};
1090 +
1091 +/**
1092 + * enum rc_filter_type - Filter type constants.
1093 + * @RC_FILTER_NORMAL: Filter for normal operation.
1094 + * @RC_FILTER_WAKEUP: Filter for waking from suspend.
1095 + * @RC_FILTER_MAX: Number of filter types.
1096 + */
1097 +enum rc_filter_type {
1098 + RC_FILTER_NORMAL = 0,
1099 + RC_FILTER_WAKEUP,
1100 +
1101 + RC_FILTER_MAX
1102 +};
1103 +
1104 +/**
1105 * struct rc_dev - represents a remote control device
1106 * @dev: driver model's view of this device
1107 * @input_name: name of the input child device
1108 @@ -50,8 +73,10 @@ enum rc_driver_type {
1109 * @input_dev: the input child device used to communicate events to userspace
1110 * @driver_type: specifies if protocol decoding is done in hardware or software
1111 * @idle: used to keep track of RX state
1112 - * @allowed_protos: bitmask with the supported RC_BIT_* protocols
1113 - * @enabled_protocols: bitmask with the enabled RC_BIT_* protocols
1114 + * @allowed_protocols: bitmask with the supported RC_BIT_* protocols for each
1115 + * filter type
1116 + * @enabled_protocols: bitmask with the enabled RC_BIT_* protocols for each
1117 + * filter type
1118 * @scanmask: some hardware decoders are not capable of providing the full
1119 * scancode to the application. As this is a hardware limit, we can't do
1120 * anything with it. Yet, as the same keycode table can be used with other
1121 @@ -70,7 +95,10 @@ enum rc_driver_type {
1122 * @max_timeout: maximum timeout supported by device
1123 * @rx_resolution : resolution (in ns) of input sampler
1124 * @tx_resolution: resolution (in ns) of output sampler
1125 + * @scancode_filters: scancode filters (indexed by enum rc_filter_type)
1126 * @change_protocol: allow changing the protocol used on hardware decoders
1127 + * @change_wakeup_protocol: allow changing the protocol used for wakeup
1128 + * filtering
1129 * @open: callback to allow drivers to enable polling/irq when IR input device
1130 * is opened.
1131 * @close: callback to allow drivers to disable polling/irq when IR input device
1132 @@ -84,6 +112,7 @@ enum rc_driver_type {
1133 * device doesn't interrupt host until it sees IR pulses
1134 * @s_learning_mode: enable wide band receiver used for learning
1135 * @s_carrier_report: enable carrier reports
1136 + * @s_filter: set the scancode filter of a given type
1137 */
1138 struct rc_dev {
1139 struct device dev;
1140 @@ -99,8 +128,8 @@ struct rc_dev {
1141 struct input_dev *input_dev;
1142 enum rc_driver_type driver_type;
1143 bool idle;
1144 - u64 allowed_protos;
1145 - u64 enabled_protocols;
1146 + u64 allowed_protocols[RC_FILTER_MAX];
1147 + u64 enabled_protocols[RC_FILTER_MAX];
1148 u32 users;
1149 u32 scanmask;
1150 void *priv;
1151 @@ -116,7 +145,9 @@ struct rc_dev {
1152 u32 max_timeout;
1153 u32 rx_resolution;
1154 u32 tx_resolution;
1155 + struct rc_scancode_filter scancode_filters[RC_FILTER_MAX];
1156 int (*change_protocol)(struct rc_dev *dev, u64 *rc_type);
1157 + int (*change_wakeup_protocol)(struct rc_dev *dev, u64 *rc_type);
1158 int (*open)(struct rc_dev *dev);
1159 void (*close)(struct rc_dev *dev);
1160 int (*s_tx_mask)(struct rc_dev *dev, u32 mask);
1161 @@ -127,10 +158,49 @@ struct rc_dev {
1162 void (*s_idle)(struct rc_dev *dev, bool enable);
1163 int (*s_learning_mode)(struct rc_dev *dev, int enable);
1164 int (*s_carrier_report) (struct rc_dev *dev, int enable);
1165 + int (*s_filter)(struct rc_dev *dev,
1166 + enum rc_filter_type type,
1167 + struct rc_scancode_filter *filter);
1168 };
1169
1170 #define to_rc_dev(d) container_of(d, struct rc_dev, dev)
1171
1172 +static inline bool rc_protocols_allowed(struct rc_dev *rdev, u64 protos)
1173 +{
1174 + return rdev->allowed_protocols[RC_FILTER_NORMAL] & protos;
1175 +}
1176 +
1177 +/* should be called prior to registration or with mutex held */
1178 +static inline void rc_set_allowed_protocols(struct rc_dev *rdev, u64 protos)
1179 +{
1180 + rdev->allowed_protocols[RC_FILTER_NORMAL] = protos;
1181 +}
1182 +
1183 +static inline bool rc_protocols_enabled(struct rc_dev *rdev, u64 protos)
1184 +{
1185 + return rdev->enabled_protocols[RC_FILTER_NORMAL] & protos;
1186 +}
1187 +
1188 +/* should be called prior to registration or with mutex held */
1189 +static inline void rc_set_enabled_protocols(struct rc_dev *rdev, u64 protos)
1190 +{
1191 + rdev->enabled_protocols[RC_FILTER_NORMAL] = protos;
1192 +}
1193 +
1194 +/* should be called prior to registration or with mutex held */
1195 +static inline void rc_set_allowed_wakeup_protocols(struct rc_dev *rdev,
1196 + u64 protos)
1197 +{
1198 + rdev->allowed_protocols[RC_FILTER_WAKEUP] = protos;
1199 +}
1200 +
1201 +/* should be called prior to registration or with mutex held */
1202 +static inline void rc_set_enabled_wakeup_protocols(struct rc_dev *rdev,
1203 + u64 protos)
1204 +{
1205 + rdev->enabled_protocols[RC_FILTER_WAKEUP] = protos;
1206 +}
1207 +
1208 /*
1209 * From rc-main.c
1210 * Those functions can be used on any type of Remote Controller. They