284-ir-backports-from-3.15.patch 43 KB

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