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