rc-main.c 48 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901
  1. // SPDX-License-Identifier: GPL-2.0
  2. // rc-main.c - Remote Controller core module
  3. //
  4. // Copyright (C) 2009-2010 by Mauro Carvalho Chehab
  5. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  6. #include <media/rc-core.h>
  7. #include <linux/bsearch.h>
  8. #include <linux/spinlock.h>
  9. #include <linux/delay.h>
  10. #include <linux/input.h>
  11. #include <linux/leds.h>
  12. #include <linux/slab.h>
  13. #include <linux/idr.h>
  14. #include <linux/device.h>
  15. #include <linux/module.h>
  16. #include "rc-core-priv.h"
  17. /* Sizes are in bytes, 256 bytes allows for 32 entries on x64 */
  18. #define IR_TAB_MIN_SIZE 256
  19. #define IR_TAB_MAX_SIZE 8192
  20. #define RC_DEV_MAX 256
  21. static const struct {
  22. const char *name;
  23. unsigned int repeat_period;
  24. unsigned int scancode_bits;
  25. } protocols[] = {
  26. [RC_PROTO_UNKNOWN] = { .name = "unknown", .repeat_period = 250 },
  27. [RC_PROTO_OTHER] = { .name = "other", .repeat_period = 250 },
  28. [RC_PROTO_RC5] = { .name = "rc-5",
  29. .scancode_bits = 0x1f7f, .repeat_period = 250 },
  30. [RC_PROTO_RC5X_20] = { .name = "rc-5x-20",
  31. .scancode_bits = 0x1f7f3f, .repeat_period = 250 },
  32. [RC_PROTO_RC5_SZ] = { .name = "rc-5-sz",
  33. .scancode_bits = 0x2fff, .repeat_period = 250 },
  34. [RC_PROTO_JVC] = { .name = "jvc",
  35. .scancode_bits = 0xffff, .repeat_period = 250 },
  36. [RC_PROTO_SONY12] = { .name = "sony-12",
  37. .scancode_bits = 0x1f007f, .repeat_period = 250 },
  38. [RC_PROTO_SONY15] = { .name = "sony-15",
  39. .scancode_bits = 0xff007f, .repeat_period = 250 },
  40. [RC_PROTO_SONY20] = { .name = "sony-20",
  41. .scancode_bits = 0x1fff7f, .repeat_period = 250 },
  42. [RC_PROTO_NEC] = { .name = "nec",
  43. .scancode_bits = 0xffff, .repeat_period = 250 },
  44. [RC_PROTO_NECX] = { .name = "nec-x",
  45. .scancode_bits = 0xffffff, .repeat_period = 250 },
  46. [RC_PROTO_NEC32] = { .name = "nec-32",
  47. .scancode_bits = 0xffffffff, .repeat_period = 250 },
  48. [RC_PROTO_SANYO] = { .name = "sanyo",
  49. .scancode_bits = 0x1fffff, .repeat_period = 250 },
  50. [RC_PROTO_MCIR2_KBD] = { .name = "mcir2-kbd",
  51. .scancode_bits = 0xffff, .repeat_period = 250 },
  52. [RC_PROTO_MCIR2_MSE] = { .name = "mcir2-mse",
  53. .scancode_bits = 0x1fffff, .repeat_period = 250 },
  54. [RC_PROTO_RC6_0] = { .name = "rc-6-0",
  55. .scancode_bits = 0xffff, .repeat_period = 250 },
  56. [RC_PROTO_RC6_6A_20] = { .name = "rc-6-6a-20",
  57. .scancode_bits = 0xfffff, .repeat_period = 250 },
  58. [RC_PROTO_RC6_6A_24] = { .name = "rc-6-6a-24",
  59. .scancode_bits = 0xffffff, .repeat_period = 250 },
  60. [RC_PROTO_RC6_6A_32] = { .name = "rc-6-6a-32",
  61. .scancode_bits = 0xffffffff, .repeat_period = 250 },
  62. [RC_PROTO_RC6_MCE] = { .name = "rc-6-mce",
  63. .scancode_bits = 0xffff7fff, .repeat_period = 250 },
  64. [RC_PROTO_SHARP] = { .name = "sharp",
  65. .scancode_bits = 0x1fff, .repeat_period = 250 },
  66. [RC_PROTO_XMP] = { .name = "xmp", .repeat_period = 250 },
  67. [RC_PROTO_CEC] = { .name = "cec", .repeat_period = 550 },
  68. };
  69. /* Used to keep track of known keymaps */
  70. static LIST_HEAD(rc_map_list);
  71. static DEFINE_SPINLOCK(rc_map_lock);
  72. static struct led_trigger *led_feedback;
  73. /* Used to keep track of rc devices */
  74. static DEFINE_IDA(rc_ida);
  75. static struct rc_map_list *seek_rc_map(const char *name)
  76. {
  77. struct rc_map_list *map = NULL;
  78. spin_lock(&rc_map_lock);
  79. list_for_each_entry(map, &rc_map_list, list) {
  80. if (!strcmp(name, map->map.name)) {
  81. spin_unlock(&rc_map_lock);
  82. return map;
  83. }
  84. }
  85. spin_unlock(&rc_map_lock);
  86. return NULL;
  87. }
  88. struct rc_map *rc_map_get(const char *name)
  89. {
  90. struct rc_map_list *map;
  91. map = seek_rc_map(name);
  92. #ifdef CONFIG_MODULES
  93. if (!map) {
  94. int rc = request_module("%s", name);
  95. if (rc < 0) {
  96. pr_err("Couldn't load IR keymap %s\n", name);
  97. return NULL;
  98. }
  99. msleep(20); /* Give some time for IR to register */
  100. map = seek_rc_map(name);
  101. }
  102. #endif
  103. if (!map) {
  104. pr_err("IR keymap %s not found\n", name);
  105. return NULL;
  106. }
  107. printk(KERN_INFO "Registered IR keymap %s\n", map->map.name);
  108. return &map->map;
  109. }
  110. EXPORT_SYMBOL_GPL(rc_map_get);
  111. int rc_map_register(struct rc_map_list *map)
  112. {
  113. spin_lock(&rc_map_lock);
  114. list_add_tail(&map->list, &rc_map_list);
  115. spin_unlock(&rc_map_lock);
  116. return 0;
  117. }
  118. EXPORT_SYMBOL_GPL(rc_map_register);
  119. void rc_map_unregister(struct rc_map_list *map)
  120. {
  121. spin_lock(&rc_map_lock);
  122. list_del(&map->list);
  123. spin_unlock(&rc_map_lock);
  124. }
  125. EXPORT_SYMBOL_GPL(rc_map_unregister);
  126. static struct rc_map_table empty[] = {
  127. { 0x2a, KEY_COFFEE },
  128. };
  129. static struct rc_map_list empty_map = {
  130. .map = {
  131. .scan = empty,
  132. .size = ARRAY_SIZE(empty),
  133. .rc_proto = RC_PROTO_UNKNOWN, /* Legacy IR type */
  134. .name = RC_MAP_EMPTY,
  135. }
  136. };
  137. /**
  138. * ir_create_table() - initializes a scancode table
  139. * @rc_map: the rc_map to initialize
  140. * @name: name to assign to the table
  141. * @rc_proto: ir type to assign to the new table
  142. * @size: initial size of the table
  143. *
  144. * This routine will initialize the rc_map and will allocate
  145. * memory to hold at least the specified number of elements.
  146. *
  147. * return: zero on success or a negative error code
  148. */
  149. static int ir_create_table(struct rc_map *rc_map,
  150. const char *name, u64 rc_proto, size_t size)
  151. {
  152. rc_map->name = kstrdup(name, GFP_KERNEL);
  153. if (!rc_map->name)
  154. return -ENOMEM;
  155. rc_map->rc_proto = rc_proto;
  156. rc_map->alloc = roundup_pow_of_two(size * sizeof(struct rc_map_table));
  157. rc_map->size = rc_map->alloc / sizeof(struct rc_map_table);
  158. rc_map->scan = kmalloc(rc_map->alloc, GFP_KERNEL);
  159. if (!rc_map->scan) {
  160. kfree(rc_map->name);
  161. rc_map->name = NULL;
  162. return -ENOMEM;
  163. }
  164. IR_dprintk(1, "Allocated space for %u keycode entries (%u bytes)\n",
  165. rc_map->size, rc_map->alloc);
  166. return 0;
  167. }
  168. /**
  169. * ir_free_table() - frees memory allocated by a scancode table
  170. * @rc_map: the table whose mappings need to be freed
  171. *
  172. * This routine will free memory alloctaed for key mappings used by given
  173. * scancode table.
  174. */
  175. static void ir_free_table(struct rc_map *rc_map)
  176. {
  177. rc_map->size = 0;
  178. kfree(rc_map->name);
  179. rc_map->name = NULL;
  180. kfree(rc_map->scan);
  181. rc_map->scan = NULL;
  182. }
  183. /**
  184. * ir_resize_table() - resizes a scancode table if necessary
  185. * @rc_map: the rc_map to resize
  186. * @gfp_flags: gfp flags to use when allocating memory
  187. *
  188. * This routine will shrink the rc_map if it has lots of
  189. * unused entries and grow it if it is full.
  190. *
  191. * return: zero on success or a negative error code
  192. */
  193. static int ir_resize_table(struct rc_map *rc_map, gfp_t gfp_flags)
  194. {
  195. unsigned int oldalloc = rc_map->alloc;
  196. unsigned int newalloc = oldalloc;
  197. struct rc_map_table *oldscan = rc_map->scan;
  198. struct rc_map_table *newscan;
  199. if (rc_map->size == rc_map->len) {
  200. /* All entries in use -> grow keytable */
  201. if (rc_map->alloc >= IR_TAB_MAX_SIZE)
  202. return -ENOMEM;
  203. newalloc *= 2;
  204. IR_dprintk(1, "Growing table to %u bytes\n", newalloc);
  205. }
  206. if ((rc_map->len * 3 < rc_map->size) && (oldalloc > IR_TAB_MIN_SIZE)) {
  207. /* Less than 1/3 of entries in use -> shrink keytable */
  208. newalloc /= 2;
  209. IR_dprintk(1, "Shrinking table to %u bytes\n", newalloc);
  210. }
  211. if (newalloc == oldalloc)
  212. return 0;
  213. newscan = kmalloc(newalloc, gfp_flags);
  214. if (!newscan) {
  215. IR_dprintk(1, "Failed to kmalloc %u bytes\n", newalloc);
  216. return -ENOMEM;
  217. }
  218. memcpy(newscan, rc_map->scan, rc_map->len * sizeof(struct rc_map_table));
  219. rc_map->scan = newscan;
  220. rc_map->alloc = newalloc;
  221. rc_map->size = rc_map->alloc / sizeof(struct rc_map_table);
  222. kfree(oldscan);
  223. return 0;
  224. }
  225. /**
  226. * ir_update_mapping() - set a keycode in the scancode->keycode table
  227. * @dev: the struct rc_dev device descriptor
  228. * @rc_map: scancode table to be adjusted
  229. * @index: index of the mapping that needs to be updated
  230. * @new_keycode: the desired keycode
  231. *
  232. * This routine is used to update scancode->keycode mapping at given
  233. * position.
  234. *
  235. * return: previous keycode assigned to the mapping
  236. *
  237. */
  238. static unsigned int ir_update_mapping(struct rc_dev *dev,
  239. struct rc_map *rc_map,
  240. unsigned int index,
  241. unsigned int new_keycode)
  242. {
  243. int old_keycode = rc_map->scan[index].keycode;
  244. int i;
  245. /* Did the user wish to remove the mapping? */
  246. if (new_keycode == KEY_RESERVED || new_keycode == KEY_UNKNOWN) {
  247. IR_dprintk(1, "#%d: Deleting scan 0x%04x\n",
  248. index, rc_map->scan[index].scancode);
  249. rc_map->len--;
  250. memmove(&rc_map->scan[index], &rc_map->scan[index+ 1],
  251. (rc_map->len - index) * sizeof(struct rc_map_table));
  252. } else {
  253. IR_dprintk(1, "#%d: %s scan 0x%04x with key 0x%04x\n",
  254. index,
  255. old_keycode == KEY_RESERVED ? "New" : "Replacing",
  256. rc_map->scan[index].scancode, new_keycode);
  257. rc_map->scan[index].keycode = new_keycode;
  258. __set_bit(new_keycode, dev->input_dev->keybit);
  259. }
  260. if (old_keycode != KEY_RESERVED) {
  261. /* A previous mapping was updated... */
  262. __clear_bit(old_keycode, dev->input_dev->keybit);
  263. /* ... but another scancode might use the same keycode */
  264. for (i = 0; i < rc_map->len; i++) {
  265. if (rc_map->scan[i].keycode == old_keycode) {
  266. __set_bit(old_keycode, dev->input_dev->keybit);
  267. break;
  268. }
  269. }
  270. /* Possibly shrink the keytable, failure is not a problem */
  271. ir_resize_table(rc_map, GFP_ATOMIC);
  272. }
  273. return old_keycode;
  274. }
  275. /**
  276. * ir_establish_scancode() - set a keycode in the scancode->keycode table
  277. * @dev: the struct rc_dev device descriptor
  278. * @rc_map: scancode table to be searched
  279. * @scancode: the desired scancode
  280. * @resize: controls whether we allowed to resize the table to
  281. * accommodate not yet present scancodes
  282. *
  283. * This routine is used to locate given scancode in rc_map.
  284. * If scancode is not yet present the routine will allocate a new slot
  285. * for it.
  286. *
  287. * return: index of the mapping containing scancode in question
  288. * or -1U in case of failure.
  289. */
  290. static unsigned int ir_establish_scancode(struct rc_dev *dev,
  291. struct rc_map *rc_map,
  292. unsigned int scancode,
  293. bool resize)
  294. {
  295. unsigned int i;
  296. /*
  297. * Unfortunately, some hardware-based IR decoders don't provide
  298. * all bits for the complete IR code. In general, they provide only
  299. * the command part of the IR code. Yet, as it is possible to replace
  300. * the provided IR with another one, it is needed to allow loading
  301. * IR tables from other remotes. So, we support specifying a mask to
  302. * indicate the valid bits of the scancodes.
  303. */
  304. if (dev->scancode_mask)
  305. scancode &= dev->scancode_mask;
  306. /* First check if we already have a mapping for this ir command */
  307. for (i = 0; i < rc_map->len; i++) {
  308. if (rc_map->scan[i].scancode == scancode)
  309. return i;
  310. /* Keytable is sorted from lowest to highest scancode */
  311. if (rc_map->scan[i].scancode >= scancode)
  312. break;
  313. }
  314. /* No previous mapping found, we might need to grow the table */
  315. if (rc_map->size == rc_map->len) {
  316. if (!resize || ir_resize_table(rc_map, GFP_ATOMIC))
  317. return -1U;
  318. }
  319. /* i is the proper index to insert our new keycode */
  320. if (i < rc_map->len)
  321. memmove(&rc_map->scan[i + 1], &rc_map->scan[i],
  322. (rc_map->len - i) * sizeof(struct rc_map_table));
  323. rc_map->scan[i].scancode = scancode;
  324. rc_map->scan[i].keycode = KEY_RESERVED;
  325. rc_map->len++;
  326. return i;
  327. }
  328. /**
  329. * ir_setkeycode() - set a keycode in the scancode->keycode table
  330. * @idev: the struct input_dev device descriptor
  331. * @ke: Input keymap entry
  332. * @old_keycode: result
  333. *
  334. * This routine is used to handle evdev EVIOCSKEY ioctl.
  335. *
  336. * return: -EINVAL if the keycode could not be inserted, otherwise zero.
  337. */
  338. static int ir_setkeycode(struct input_dev *idev,
  339. const struct input_keymap_entry *ke,
  340. unsigned int *old_keycode)
  341. {
  342. struct rc_dev *rdev = input_get_drvdata(idev);
  343. struct rc_map *rc_map = &rdev->rc_map;
  344. unsigned int index;
  345. unsigned int scancode;
  346. int retval = 0;
  347. unsigned long flags;
  348. spin_lock_irqsave(&rc_map->lock, flags);
  349. if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
  350. index = ke->index;
  351. if (index >= rc_map->len) {
  352. retval = -EINVAL;
  353. goto out;
  354. }
  355. } else {
  356. retval = input_scancode_to_scalar(ke, &scancode);
  357. if (retval)
  358. goto out;
  359. index = ir_establish_scancode(rdev, rc_map, scancode, true);
  360. if (index >= rc_map->len) {
  361. retval = -ENOMEM;
  362. goto out;
  363. }
  364. }
  365. *old_keycode = ir_update_mapping(rdev, rc_map, index, ke->keycode);
  366. out:
  367. spin_unlock_irqrestore(&rc_map->lock, flags);
  368. return retval;
  369. }
  370. /**
  371. * ir_setkeytable() - sets several entries in the scancode->keycode table
  372. * @dev: the struct rc_dev device descriptor
  373. * @from: the struct rc_map to copy entries from
  374. *
  375. * This routine is used to handle table initialization.
  376. *
  377. * return: -ENOMEM if all keycodes could not be inserted, otherwise zero.
  378. */
  379. static int ir_setkeytable(struct rc_dev *dev,
  380. const struct rc_map *from)
  381. {
  382. struct rc_map *rc_map = &dev->rc_map;
  383. unsigned int i, index;
  384. int rc;
  385. rc = ir_create_table(rc_map, from->name,
  386. from->rc_proto, from->size);
  387. if (rc)
  388. return rc;
  389. for (i = 0; i < from->size; i++) {
  390. index = ir_establish_scancode(dev, rc_map,
  391. from->scan[i].scancode, false);
  392. if (index >= rc_map->len) {
  393. rc = -ENOMEM;
  394. break;
  395. }
  396. ir_update_mapping(dev, rc_map, index,
  397. from->scan[i].keycode);
  398. }
  399. if (rc)
  400. ir_free_table(rc_map);
  401. return rc;
  402. }
  403. static int rc_map_cmp(const void *key, const void *elt)
  404. {
  405. const unsigned int *scancode = key;
  406. const struct rc_map_table *e = elt;
  407. if (*scancode < e->scancode)
  408. return -1;
  409. else if (*scancode > e->scancode)
  410. return 1;
  411. return 0;
  412. }
  413. /**
  414. * ir_lookup_by_scancode() - locate mapping by scancode
  415. * @rc_map: the struct rc_map to search
  416. * @scancode: scancode to look for in the table
  417. *
  418. * This routine performs binary search in RC keykeymap table for
  419. * given scancode.
  420. *
  421. * return: index in the table, -1U if not found
  422. */
  423. static unsigned int ir_lookup_by_scancode(const struct rc_map *rc_map,
  424. unsigned int scancode)
  425. {
  426. struct rc_map_table *res;
  427. res = bsearch(&scancode, rc_map->scan, rc_map->len,
  428. sizeof(struct rc_map_table), rc_map_cmp);
  429. if (!res)
  430. return -1U;
  431. else
  432. return res - rc_map->scan;
  433. }
  434. /**
  435. * ir_getkeycode() - get a keycode from the scancode->keycode table
  436. * @idev: the struct input_dev device descriptor
  437. * @ke: Input keymap entry
  438. *
  439. * This routine is used to handle evdev EVIOCGKEY ioctl.
  440. *
  441. * return: always returns zero.
  442. */
  443. static int ir_getkeycode(struct input_dev *idev,
  444. struct input_keymap_entry *ke)
  445. {
  446. struct rc_dev *rdev = input_get_drvdata(idev);
  447. struct rc_map *rc_map = &rdev->rc_map;
  448. struct rc_map_table *entry;
  449. unsigned long flags;
  450. unsigned int index;
  451. unsigned int scancode;
  452. int retval;
  453. spin_lock_irqsave(&rc_map->lock, flags);
  454. if (ke->flags & INPUT_KEYMAP_BY_INDEX) {
  455. index = ke->index;
  456. } else {
  457. retval = input_scancode_to_scalar(ke, &scancode);
  458. if (retval)
  459. goto out;
  460. index = ir_lookup_by_scancode(rc_map, scancode);
  461. }
  462. if (index < rc_map->len) {
  463. entry = &rc_map->scan[index];
  464. ke->index = index;
  465. ke->keycode = entry->keycode;
  466. ke->len = sizeof(entry->scancode);
  467. memcpy(ke->scancode, &entry->scancode, sizeof(entry->scancode));
  468. } else if (!(ke->flags & INPUT_KEYMAP_BY_INDEX)) {
  469. /*
  470. * We do not really know the valid range of scancodes
  471. * so let's respond with KEY_RESERVED to anything we
  472. * do not have mapping for [yet].
  473. */
  474. ke->index = index;
  475. ke->keycode = KEY_RESERVED;
  476. } else {
  477. retval = -EINVAL;
  478. goto out;
  479. }
  480. retval = 0;
  481. out:
  482. spin_unlock_irqrestore(&rc_map->lock, flags);
  483. return retval;
  484. }
  485. /**
  486. * rc_g_keycode_from_table() - gets the keycode that corresponds to a scancode
  487. * @dev: the struct rc_dev descriptor of the device
  488. * @scancode: the scancode to look for
  489. *
  490. * This routine is used by drivers which need to convert a scancode to a
  491. * keycode. Normally it should not be used since drivers should have no
  492. * interest in keycodes.
  493. *
  494. * return: the corresponding keycode, or KEY_RESERVED
  495. */
  496. u32 rc_g_keycode_from_table(struct rc_dev *dev, u32 scancode)
  497. {
  498. struct rc_map *rc_map = &dev->rc_map;
  499. unsigned int keycode;
  500. unsigned int index;
  501. unsigned long flags;
  502. spin_lock_irqsave(&rc_map->lock, flags);
  503. index = ir_lookup_by_scancode(rc_map, scancode);
  504. keycode = index < rc_map->len ?
  505. rc_map->scan[index].keycode : KEY_RESERVED;
  506. spin_unlock_irqrestore(&rc_map->lock, flags);
  507. if (keycode != KEY_RESERVED)
  508. IR_dprintk(1, "%s: scancode 0x%04x keycode 0x%02x\n",
  509. dev->device_name, scancode, keycode);
  510. return keycode;
  511. }
  512. EXPORT_SYMBOL_GPL(rc_g_keycode_from_table);
  513. /**
  514. * ir_do_keyup() - internal function to signal the release of a keypress
  515. * @dev: the struct rc_dev descriptor of the device
  516. * @sync: whether or not to call input_sync
  517. *
  518. * This function is used internally to release a keypress, it must be
  519. * called with keylock held.
  520. */
  521. static void ir_do_keyup(struct rc_dev *dev, bool sync)
  522. {
  523. if (!dev->keypressed)
  524. return;
  525. IR_dprintk(1, "keyup key 0x%04x\n", dev->last_keycode);
  526. input_report_key(dev->input_dev, dev->last_keycode, 0);
  527. led_trigger_event(led_feedback, LED_OFF);
  528. if (sync)
  529. input_sync(dev->input_dev);
  530. dev->keypressed = false;
  531. }
  532. /**
  533. * rc_keyup() - signals the release of a keypress
  534. * @dev: the struct rc_dev descriptor of the device
  535. *
  536. * This routine is used to signal that a key has been released on the
  537. * remote control.
  538. */
  539. void rc_keyup(struct rc_dev *dev)
  540. {
  541. unsigned long flags;
  542. spin_lock_irqsave(&dev->keylock, flags);
  543. ir_do_keyup(dev, true);
  544. spin_unlock_irqrestore(&dev->keylock, flags);
  545. }
  546. EXPORT_SYMBOL_GPL(rc_keyup);
  547. /**
  548. * ir_timer_keyup() - generates a keyup event after a timeout
  549. *
  550. * @t: a pointer to the struct timer_list
  551. *
  552. * This routine will generate a keyup event some time after a keydown event
  553. * is generated when no further activity has been detected.
  554. */
  555. static void ir_timer_keyup(struct timer_list *t)
  556. {
  557. struct rc_dev *dev = from_timer(dev, t, timer_keyup);
  558. unsigned long flags;
  559. /*
  560. * ir->keyup_jiffies is used to prevent a race condition if a
  561. * hardware interrupt occurs at this point and the keyup timer
  562. * event is moved further into the future as a result.
  563. *
  564. * The timer will then be reactivated and this function called
  565. * again in the future. We need to exit gracefully in that case
  566. * to allow the input subsystem to do its auto-repeat magic or
  567. * a keyup event might follow immediately after the keydown.
  568. */
  569. spin_lock_irqsave(&dev->keylock, flags);
  570. if (time_is_before_eq_jiffies(dev->keyup_jiffies))
  571. ir_do_keyup(dev, true);
  572. spin_unlock_irqrestore(&dev->keylock, flags);
  573. }
  574. /**
  575. * rc_repeat() - signals that a key is still pressed
  576. * @dev: the struct rc_dev descriptor of the device
  577. *
  578. * This routine is used by IR decoders when a repeat message which does
  579. * not include the necessary bits to reproduce the scancode has been
  580. * received.
  581. */
  582. void rc_repeat(struct rc_dev *dev)
  583. {
  584. unsigned long flags;
  585. unsigned int timeout = protocols[dev->last_protocol].repeat_period;
  586. spin_lock_irqsave(&dev->keylock, flags);
  587. if (!dev->keypressed)
  588. goto out;
  589. input_event(dev->input_dev, EV_MSC, MSC_SCAN, dev->last_scancode);
  590. input_sync(dev->input_dev);
  591. dev->keyup_jiffies = jiffies + msecs_to_jiffies(timeout);
  592. mod_timer(&dev->timer_keyup, dev->keyup_jiffies);
  593. out:
  594. spin_unlock_irqrestore(&dev->keylock, flags);
  595. }
  596. EXPORT_SYMBOL_GPL(rc_repeat);
  597. /**
  598. * ir_do_keydown() - internal function to process a keypress
  599. * @dev: the struct rc_dev descriptor of the device
  600. * @protocol: the protocol of the keypress
  601. * @scancode: the scancode of the keypress
  602. * @keycode: the keycode of the keypress
  603. * @toggle: the toggle value of the keypress
  604. *
  605. * This function is used internally to register a keypress, it must be
  606. * called with keylock held.
  607. */
  608. static void ir_do_keydown(struct rc_dev *dev, enum rc_proto protocol,
  609. u32 scancode, u32 keycode, u8 toggle)
  610. {
  611. bool new_event = (!dev->keypressed ||
  612. dev->last_protocol != protocol ||
  613. dev->last_scancode != scancode ||
  614. dev->last_toggle != toggle);
  615. if (new_event && dev->keypressed)
  616. ir_do_keyup(dev, false);
  617. input_event(dev->input_dev, EV_MSC, MSC_SCAN, scancode);
  618. if (new_event && keycode != KEY_RESERVED) {
  619. /* Register a keypress */
  620. dev->keypressed = true;
  621. dev->last_protocol = protocol;
  622. dev->last_scancode = scancode;
  623. dev->last_toggle = toggle;
  624. dev->last_keycode = keycode;
  625. IR_dprintk(1, "%s: key down event, key 0x%04x, protocol 0x%04x, scancode 0x%08x\n",
  626. dev->device_name, keycode, protocol, scancode);
  627. input_report_key(dev->input_dev, keycode, 1);
  628. led_trigger_event(led_feedback, LED_FULL);
  629. }
  630. input_sync(dev->input_dev);
  631. }
  632. /**
  633. * rc_keydown() - generates input event for a key press
  634. * @dev: the struct rc_dev descriptor of the device
  635. * @protocol: the protocol for the keypress
  636. * @scancode: the scancode for the keypress
  637. * @toggle: the toggle value (protocol dependent, if the protocol doesn't
  638. * support toggle values, this should be set to zero)
  639. *
  640. * This routine is used to signal that a key has been pressed on the
  641. * remote control.
  642. */
  643. void rc_keydown(struct rc_dev *dev, enum rc_proto protocol, u32 scancode,
  644. u8 toggle)
  645. {
  646. unsigned long flags;
  647. u32 keycode = rc_g_keycode_from_table(dev, scancode);
  648. spin_lock_irqsave(&dev->keylock, flags);
  649. ir_do_keydown(dev, protocol, scancode, keycode, toggle);
  650. if (dev->keypressed) {
  651. dev->keyup_jiffies = jiffies +
  652. msecs_to_jiffies(protocols[protocol].repeat_period);
  653. mod_timer(&dev->timer_keyup, dev->keyup_jiffies);
  654. }
  655. spin_unlock_irqrestore(&dev->keylock, flags);
  656. }
  657. EXPORT_SYMBOL_GPL(rc_keydown);
  658. /**
  659. * rc_keydown_notimeout() - generates input event for a key press without
  660. * an automatic keyup event at a later time
  661. * @dev: the struct rc_dev descriptor of the device
  662. * @protocol: the protocol for the keypress
  663. * @scancode: the scancode for the keypress
  664. * @toggle: the toggle value (protocol dependent, if the protocol doesn't
  665. * support toggle values, this should be set to zero)
  666. *
  667. * This routine is used to signal that a key has been pressed on the
  668. * remote control. The driver must manually call rc_keyup() at a later stage.
  669. */
  670. void rc_keydown_notimeout(struct rc_dev *dev, enum rc_proto protocol,
  671. u32 scancode, u8 toggle)
  672. {
  673. unsigned long flags;
  674. u32 keycode = rc_g_keycode_from_table(dev, scancode);
  675. spin_lock_irqsave(&dev->keylock, flags);
  676. ir_do_keydown(dev, protocol, scancode, keycode, toggle);
  677. spin_unlock_irqrestore(&dev->keylock, flags);
  678. }
  679. EXPORT_SYMBOL_GPL(rc_keydown_notimeout);
  680. /**
  681. * rc_validate_filter() - checks that the scancode and mask are valid and
  682. * provides sensible defaults
  683. * @dev: the struct rc_dev descriptor of the device
  684. * @filter: the scancode and mask
  685. *
  686. * return: 0 or -EINVAL if the filter is not valid
  687. */
  688. static int rc_validate_filter(struct rc_dev *dev,
  689. struct rc_scancode_filter *filter)
  690. {
  691. u32 mask, s = filter->data;
  692. enum rc_proto protocol = dev->wakeup_protocol;
  693. if (protocol >= ARRAY_SIZE(protocols))
  694. return -EINVAL;
  695. mask = protocols[protocol].scancode_bits;
  696. switch (protocol) {
  697. case RC_PROTO_NECX:
  698. if ((((s >> 16) ^ ~(s >> 8)) & 0xff) == 0)
  699. return -EINVAL;
  700. break;
  701. case RC_PROTO_NEC32:
  702. if ((((s >> 24) ^ ~(s >> 16)) & 0xff) == 0)
  703. return -EINVAL;
  704. break;
  705. case RC_PROTO_RC6_MCE:
  706. if ((s & 0xffff0000) != 0x800f0000)
  707. return -EINVAL;
  708. break;
  709. case RC_PROTO_RC6_6A_32:
  710. if ((s & 0xffff0000) == 0x800f0000)
  711. return -EINVAL;
  712. break;
  713. default:
  714. break;
  715. }
  716. filter->data &= mask;
  717. filter->mask &= mask;
  718. /*
  719. * If we have to raw encode the IR for wakeup, we cannot have a mask
  720. */
  721. if (dev->encode_wakeup && filter->mask != 0 && filter->mask != mask)
  722. return -EINVAL;
  723. return 0;
  724. }
  725. int rc_open(struct rc_dev *rdev)
  726. {
  727. int rval = 0;
  728. if (!rdev)
  729. return -EINVAL;
  730. mutex_lock(&rdev->lock);
  731. if (!rdev->users++ && rdev->open != NULL)
  732. rval = rdev->open(rdev);
  733. if (rval)
  734. rdev->users--;
  735. mutex_unlock(&rdev->lock);
  736. return rval;
  737. }
  738. static int ir_open(struct input_dev *idev)
  739. {
  740. struct rc_dev *rdev = input_get_drvdata(idev);
  741. return rc_open(rdev);
  742. }
  743. void rc_close(struct rc_dev *rdev)
  744. {
  745. if (rdev) {
  746. mutex_lock(&rdev->lock);
  747. if (!--rdev->users && rdev->close != NULL)
  748. rdev->close(rdev);
  749. mutex_unlock(&rdev->lock);
  750. }
  751. }
  752. static void ir_close(struct input_dev *idev)
  753. {
  754. struct rc_dev *rdev = input_get_drvdata(idev);
  755. rc_close(rdev);
  756. }
  757. /* class for /sys/class/rc */
  758. static char *rc_devnode(struct device *dev, umode_t *mode)
  759. {
  760. return kasprintf(GFP_KERNEL, "rc/%s", dev_name(dev));
  761. }
  762. static struct class rc_class = {
  763. .name = "rc",
  764. .devnode = rc_devnode,
  765. };
  766. /*
  767. * These are the protocol textual descriptions that are
  768. * used by the sysfs protocols file. Note that the order
  769. * of the entries is relevant.
  770. */
  771. static const struct {
  772. u64 type;
  773. const char *name;
  774. const char *module_name;
  775. } proto_names[] = {
  776. { RC_PROTO_BIT_NONE, "none", NULL },
  777. { RC_PROTO_BIT_OTHER, "other", NULL },
  778. { RC_PROTO_BIT_UNKNOWN, "unknown", NULL },
  779. { RC_PROTO_BIT_RC5 |
  780. RC_PROTO_BIT_RC5X_20, "rc-5", "ir-rc5-decoder" },
  781. { RC_PROTO_BIT_NEC |
  782. RC_PROTO_BIT_NECX |
  783. RC_PROTO_BIT_NEC32, "nec", "ir-nec-decoder" },
  784. { RC_PROTO_BIT_RC6_0 |
  785. RC_PROTO_BIT_RC6_6A_20 |
  786. RC_PROTO_BIT_RC6_6A_24 |
  787. RC_PROTO_BIT_RC6_6A_32 |
  788. RC_PROTO_BIT_RC6_MCE, "rc-6", "ir-rc6-decoder" },
  789. { RC_PROTO_BIT_JVC, "jvc", "ir-jvc-decoder" },
  790. { RC_PROTO_BIT_SONY12 |
  791. RC_PROTO_BIT_SONY15 |
  792. RC_PROTO_BIT_SONY20, "sony", "ir-sony-decoder" },
  793. { RC_PROTO_BIT_RC5_SZ, "rc-5-sz", "ir-rc5-decoder" },
  794. { RC_PROTO_BIT_SANYO, "sanyo", "ir-sanyo-decoder" },
  795. { RC_PROTO_BIT_SHARP, "sharp", "ir-sharp-decoder" },
  796. { RC_PROTO_BIT_MCIR2_KBD |
  797. RC_PROTO_BIT_MCIR2_MSE, "mce_kbd", "ir-mce_kbd-decoder" },
  798. { RC_PROTO_BIT_XMP, "xmp", "ir-xmp-decoder" },
  799. { RC_PROTO_BIT_CEC, "cec", NULL },
  800. };
  801. /**
  802. * struct rc_filter_attribute - Device attribute relating to a filter type.
  803. * @attr: Device attribute.
  804. * @type: Filter type.
  805. * @mask: false for filter value, true for filter mask.
  806. */
  807. struct rc_filter_attribute {
  808. struct device_attribute attr;
  809. enum rc_filter_type type;
  810. bool mask;
  811. };
  812. #define to_rc_filter_attr(a) container_of(a, struct rc_filter_attribute, attr)
  813. #define RC_FILTER_ATTR(_name, _mode, _show, _store, _type, _mask) \
  814. struct rc_filter_attribute dev_attr_##_name = { \
  815. .attr = __ATTR(_name, _mode, _show, _store), \
  816. .type = (_type), \
  817. .mask = (_mask), \
  818. }
  819. /**
  820. * show_protocols() - shows the current IR protocol(s)
  821. * @device: the device descriptor
  822. * @mattr: the device attribute struct
  823. * @buf: a pointer to the output buffer
  824. *
  825. * This routine is a callback routine for input read the IR protocol type(s).
  826. * it is trigged by reading /sys/class/rc/rc?/protocols.
  827. * It returns the protocol names of supported protocols.
  828. * Enabled protocols are printed in brackets.
  829. *
  830. * dev->lock is taken to guard against races between
  831. * store_protocols and show_protocols.
  832. */
  833. static ssize_t show_protocols(struct device *device,
  834. struct device_attribute *mattr, char *buf)
  835. {
  836. struct rc_dev *dev = to_rc_dev(device);
  837. u64 allowed, enabled;
  838. char *tmp = buf;
  839. int i;
  840. mutex_lock(&dev->lock);
  841. enabled = dev->enabled_protocols;
  842. allowed = dev->allowed_protocols;
  843. if (dev->raw && !allowed)
  844. allowed = ir_raw_get_allowed_protocols();
  845. mutex_unlock(&dev->lock);
  846. IR_dprintk(1, "%s: allowed - 0x%llx, enabled - 0x%llx\n",
  847. __func__, (long long)allowed, (long long)enabled);
  848. for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
  849. if (allowed & enabled & proto_names[i].type)
  850. tmp += sprintf(tmp, "[%s] ", proto_names[i].name);
  851. else if (allowed & proto_names[i].type)
  852. tmp += sprintf(tmp, "%s ", proto_names[i].name);
  853. if (allowed & proto_names[i].type)
  854. allowed &= ~proto_names[i].type;
  855. }
  856. #ifdef CONFIG_LIRC
  857. if (dev->driver_type == RC_DRIVER_IR_RAW)
  858. tmp += sprintf(tmp, "[lirc] ");
  859. #endif
  860. if (tmp != buf)
  861. tmp--;
  862. *tmp = '\n';
  863. return tmp + 1 - buf;
  864. }
  865. /**
  866. * parse_protocol_change() - parses a protocol change request
  867. * @protocols: pointer to the bitmask of current protocols
  868. * @buf: pointer to the buffer with a list of changes
  869. *
  870. * Writing "+proto" will add a protocol to the protocol mask.
  871. * Writing "-proto" will remove a protocol from protocol mask.
  872. * Writing "proto" will enable only "proto".
  873. * Writing "none" will disable all protocols.
  874. * Returns the number of changes performed or a negative error code.
  875. */
  876. static int parse_protocol_change(u64 *protocols, const char *buf)
  877. {
  878. const char *tmp;
  879. unsigned count = 0;
  880. bool enable, disable;
  881. u64 mask;
  882. int i;
  883. while ((tmp = strsep((char **)&buf, " \n")) != NULL) {
  884. if (!*tmp)
  885. break;
  886. if (*tmp == '+') {
  887. enable = true;
  888. disable = false;
  889. tmp++;
  890. } else if (*tmp == '-') {
  891. enable = false;
  892. disable = true;
  893. tmp++;
  894. } else {
  895. enable = false;
  896. disable = false;
  897. }
  898. for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
  899. if (!strcasecmp(tmp, proto_names[i].name)) {
  900. mask = proto_names[i].type;
  901. break;
  902. }
  903. }
  904. if (i == ARRAY_SIZE(proto_names)) {
  905. if (!strcasecmp(tmp, "lirc"))
  906. mask = 0;
  907. else {
  908. IR_dprintk(1, "Unknown protocol: '%s'\n", tmp);
  909. return -EINVAL;
  910. }
  911. }
  912. count++;
  913. if (enable)
  914. *protocols |= mask;
  915. else if (disable)
  916. *protocols &= ~mask;
  917. else
  918. *protocols = mask;
  919. }
  920. if (!count) {
  921. IR_dprintk(1, "Protocol not specified\n");
  922. return -EINVAL;
  923. }
  924. return count;
  925. }
  926. void ir_raw_load_modules(u64 *protocols)
  927. {
  928. u64 available;
  929. int i, ret;
  930. for (i = 0; i < ARRAY_SIZE(proto_names); i++) {
  931. if (proto_names[i].type == RC_PROTO_BIT_NONE ||
  932. proto_names[i].type & (RC_PROTO_BIT_OTHER |
  933. RC_PROTO_BIT_UNKNOWN))
  934. continue;
  935. available = ir_raw_get_allowed_protocols();
  936. if (!(*protocols & proto_names[i].type & ~available))
  937. continue;
  938. if (!proto_names[i].module_name) {
  939. pr_err("Can't enable IR protocol %s\n",
  940. proto_names[i].name);
  941. *protocols &= ~proto_names[i].type;
  942. continue;
  943. }
  944. ret = request_module("%s", proto_names[i].module_name);
  945. if (ret < 0) {
  946. pr_err("Couldn't load IR protocol module %s\n",
  947. proto_names[i].module_name);
  948. *protocols &= ~proto_names[i].type;
  949. continue;
  950. }
  951. msleep(20);
  952. available = ir_raw_get_allowed_protocols();
  953. if (!(*protocols & proto_names[i].type & ~available))
  954. continue;
  955. pr_err("Loaded IR protocol module %s, but protocol %s still not available\n",
  956. proto_names[i].module_name,
  957. proto_names[i].name);
  958. *protocols &= ~proto_names[i].type;
  959. }
  960. }
  961. /**
  962. * store_protocols() - changes the current/wakeup IR protocol(s)
  963. * @device: the device descriptor
  964. * @mattr: the device attribute struct
  965. * @buf: a pointer to the input buffer
  966. * @len: length of the input buffer
  967. *
  968. * This routine is for changing the IR protocol type.
  969. * It is trigged by writing to /sys/class/rc/rc?/[wakeup_]protocols.
  970. * See parse_protocol_change() for the valid commands.
  971. * Returns @len on success or a negative error code.
  972. *
  973. * dev->lock is taken to guard against races between
  974. * store_protocols and show_protocols.
  975. */
  976. static ssize_t store_protocols(struct device *device,
  977. struct device_attribute *mattr,
  978. const char *buf, size_t len)
  979. {
  980. struct rc_dev *dev = to_rc_dev(device);
  981. u64 *current_protocols;
  982. struct rc_scancode_filter *filter;
  983. u64 old_protocols, new_protocols;
  984. ssize_t rc;
  985. IR_dprintk(1, "Normal protocol change requested\n");
  986. current_protocols = &dev->enabled_protocols;
  987. filter = &dev->scancode_filter;
  988. if (!dev->change_protocol) {
  989. IR_dprintk(1, "Protocol switching not supported\n");
  990. return -EINVAL;
  991. }
  992. mutex_lock(&dev->lock);
  993. old_protocols = *current_protocols;
  994. new_protocols = old_protocols;
  995. rc = parse_protocol_change(&new_protocols, buf);
  996. if (rc < 0)
  997. goto out;
  998. rc = dev->change_protocol(dev, &new_protocols);
  999. if (rc < 0) {
  1000. IR_dprintk(1, "Error setting protocols to 0x%llx\n",
  1001. (long long)new_protocols);
  1002. goto out;
  1003. }
  1004. if (dev->driver_type == RC_DRIVER_IR_RAW)
  1005. ir_raw_load_modules(&new_protocols);
  1006. if (new_protocols != old_protocols) {
  1007. *current_protocols = new_protocols;
  1008. IR_dprintk(1, "Protocols changed to 0x%llx\n",
  1009. (long long)new_protocols);
  1010. }
  1011. /*
  1012. * If a protocol change was attempted the filter may need updating, even
  1013. * if the actual protocol mask hasn't changed (since the driver may have
  1014. * cleared the filter).
  1015. * Try setting the same filter with the new protocol (if any).
  1016. * Fall back to clearing the filter.
  1017. */
  1018. if (dev->s_filter && filter->mask) {
  1019. if (new_protocols)
  1020. rc = dev->s_filter(dev, filter);
  1021. else
  1022. rc = -1;
  1023. if (rc < 0) {
  1024. filter->data = 0;
  1025. filter->mask = 0;
  1026. dev->s_filter(dev, filter);
  1027. }
  1028. }
  1029. rc = len;
  1030. out:
  1031. mutex_unlock(&dev->lock);
  1032. return rc;
  1033. }
  1034. /**
  1035. * show_filter() - shows the current scancode filter value or mask
  1036. * @device: the device descriptor
  1037. * @attr: the device attribute struct
  1038. * @buf: a pointer to the output buffer
  1039. *
  1040. * This routine is a callback routine to read a scancode filter value or mask.
  1041. * It is trigged by reading /sys/class/rc/rc?/[wakeup_]filter[_mask].
  1042. * It prints the current scancode filter value or mask of the appropriate filter
  1043. * type in hexadecimal into @buf and returns the size of the buffer.
  1044. *
  1045. * Bits of the filter value corresponding to set bits in the filter mask are
  1046. * compared against input scancodes and non-matching scancodes are discarded.
  1047. *
  1048. * dev->lock is taken to guard against races between
  1049. * store_filter and show_filter.
  1050. */
  1051. static ssize_t show_filter(struct device *device,
  1052. struct device_attribute *attr,
  1053. char *buf)
  1054. {
  1055. struct rc_dev *dev = to_rc_dev(device);
  1056. struct rc_filter_attribute *fattr = to_rc_filter_attr(attr);
  1057. struct rc_scancode_filter *filter;
  1058. u32 val;
  1059. mutex_lock(&dev->lock);
  1060. if (fattr->type == RC_FILTER_NORMAL)
  1061. filter = &dev->scancode_filter;
  1062. else
  1063. filter = &dev->scancode_wakeup_filter;
  1064. if (fattr->mask)
  1065. val = filter->mask;
  1066. else
  1067. val = filter->data;
  1068. mutex_unlock(&dev->lock);
  1069. return sprintf(buf, "%#x\n", val);
  1070. }
  1071. /**
  1072. * store_filter() - changes the scancode filter value
  1073. * @device: the device descriptor
  1074. * @attr: the device attribute struct
  1075. * @buf: a pointer to the input buffer
  1076. * @len: length of the input buffer
  1077. *
  1078. * This routine is for changing a scancode filter value or mask.
  1079. * It is trigged by writing to /sys/class/rc/rc?/[wakeup_]filter[_mask].
  1080. * Returns -EINVAL if an invalid filter value for the current protocol was
  1081. * specified or if scancode filtering is not supported by the driver, otherwise
  1082. * returns @len.
  1083. *
  1084. * Bits of the filter value corresponding to set bits in the filter mask are
  1085. * compared against input scancodes and non-matching scancodes are discarded.
  1086. *
  1087. * dev->lock is taken to guard against races between
  1088. * store_filter and show_filter.
  1089. */
  1090. static ssize_t store_filter(struct device *device,
  1091. struct device_attribute *attr,
  1092. const char *buf, size_t len)
  1093. {
  1094. struct rc_dev *dev = to_rc_dev(device);
  1095. struct rc_filter_attribute *fattr = to_rc_filter_attr(attr);
  1096. struct rc_scancode_filter new_filter, *filter;
  1097. int ret;
  1098. unsigned long val;
  1099. int (*set_filter)(struct rc_dev *dev, struct rc_scancode_filter *filter);
  1100. ret = kstrtoul(buf, 0, &val);
  1101. if (ret < 0)
  1102. return ret;
  1103. if (fattr->type == RC_FILTER_NORMAL) {
  1104. set_filter = dev->s_filter;
  1105. filter = &dev->scancode_filter;
  1106. } else {
  1107. set_filter = dev->s_wakeup_filter;
  1108. filter = &dev->scancode_wakeup_filter;
  1109. }
  1110. if (!set_filter)
  1111. return -EINVAL;
  1112. mutex_lock(&dev->lock);
  1113. new_filter = *filter;
  1114. if (fattr->mask)
  1115. new_filter.mask = val;
  1116. else
  1117. new_filter.data = val;
  1118. if (fattr->type == RC_FILTER_WAKEUP) {
  1119. /*
  1120. * Refuse to set a filter unless a protocol is enabled
  1121. * and the filter is valid for that protocol
  1122. */
  1123. if (dev->wakeup_protocol != RC_PROTO_UNKNOWN)
  1124. ret = rc_validate_filter(dev, &new_filter);
  1125. else
  1126. ret = -EINVAL;
  1127. if (ret != 0)
  1128. goto unlock;
  1129. }
  1130. if (fattr->type == RC_FILTER_NORMAL && !dev->enabled_protocols &&
  1131. val) {
  1132. /* refuse to set a filter unless a protocol is enabled */
  1133. ret = -EINVAL;
  1134. goto unlock;
  1135. }
  1136. ret = set_filter(dev, &new_filter);
  1137. if (ret < 0)
  1138. goto unlock;
  1139. *filter = new_filter;
  1140. unlock:
  1141. mutex_unlock(&dev->lock);
  1142. return (ret < 0) ? ret : len;
  1143. }
  1144. /**
  1145. * show_wakeup_protocols() - shows the wakeup IR protocol
  1146. * @device: the device descriptor
  1147. * @mattr: the device attribute struct
  1148. * @buf: a pointer to the output buffer
  1149. *
  1150. * This routine is a callback routine for input read the IR protocol type(s).
  1151. * it is trigged by reading /sys/class/rc/rc?/wakeup_protocols.
  1152. * It returns the protocol names of supported protocols.
  1153. * The enabled protocols are printed in brackets.
  1154. *
  1155. * dev->lock is taken to guard against races between
  1156. * store_wakeup_protocols and show_wakeup_protocols.
  1157. */
  1158. static ssize_t show_wakeup_protocols(struct device *device,
  1159. struct device_attribute *mattr,
  1160. char *buf)
  1161. {
  1162. struct rc_dev *dev = to_rc_dev(device);
  1163. u64 allowed;
  1164. enum rc_proto enabled;
  1165. char *tmp = buf;
  1166. int i;
  1167. mutex_lock(&dev->lock);
  1168. allowed = dev->allowed_wakeup_protocols;
  1169. enabled = dev->wakeup_protocol;
  1170. mutex_unlock(&dev->lock);
  1171. IR_dprintk(1, "%s: allowed - 0x%llx, enabled - %d\n",
  1172. __func__, (long long)allowed, enabled);
  1173. for (i = 0; i < ARRAY_SIZE(protocols); i++) {
  1174. if (allowed & (1ULL << i)) {
  1175. if (i == enabled)
  1176. tmp += sprintf(tmp, "[%s] ", protocols[i].name);
  1177. else
  1178. tmp += sprintf(tmp, "%s ", protocols[i].name);
  1179. }
  1180. }
  1181. if (tmp != buf)
  1182. tmp--;
  1183. *tmp = '\n';
  1184. return tmp + 1 - buf;
  1185. }
  1186. /**
  1187. * store_wakeup_protocols() - changes the wakeup IR protocol(s)
  1188. * @device: the device descriptor
  1189. * @mattr: the device attribute struct
  1190. * @buf: a pointer to the input buffer
  1191. * @len: length of the input buffer
  1192. *
  1193. * This routine is for changing the IR protocol type.
  1194. * It is trigged by writing to /sys/class/rc/rc?/wakeup_protocols.
  1195. * Returns @len on success or a negative error code.
  1196. *
  1197. * dev->lock is taken to guard against races between
  1198. * store_wakeup_protocols and show_wakeup_protocols.
  1199. */
  1200. static ssize_t store_wakeup_protocols(struct device *device,
  1201. struct device_attribute *mattr,
  1202. const char *buf, size_t len)
  1203. {
  1204. struct rc_dev *dev = to_rc_dev(device);
  1205. enum rc_proto protocol;
  1206. ssize_t rc;
  1207. u64 allowed;
  1208. int i;
  1209. mutex_lock(&dev->lock);
  1210. allowed = dev->allowed_wakeup_protocols;
  1211. if (sysfs_streq(buf, "none")) {
  1212. protocol = RC_PROTO_UNKNOWN;
  1213. } else {
  1214. for (i = 0; i < ARRAY_SIZE(protocols); i++) {
  1215. if ((allowed & (1ULL << i)) &&
  1216. sysfs_streq(buf, protocols[i].name)) {
  1217. protocol = i;
  1218. break;
  1219. }
  1220. }
  1221. if (i == ARRAY_SIZE(protocols)) {
  1222. rc = -EINVAL;
  1223. goto out;
  1224. }
  1225. if (dev->encode_wakeup) {
  1226. u64 mask = 1ULL << protocol;
  1227. ir_raw_load_modules(&mask);
  1228. if (!mask) {
  1229. rc = -EINVAL;
  1230. goto out;
  1231. }
  1232. }
  1233. }
  1234. if (dev->wakeup_protocol != protocol) {
  1235. dev->wakeup_protocol = protocol;
  1236. IR_dprintk(1, "Wakeup protocol changed to %d\n", protocol);
  1237. if (protocol == RC_PROTO_RC6_MCE)
  1238. dev->scancode_wakeup_filter.data = 0x800f0000;
  1239. else
  1240. dev->scancode_wakeup_filter.data = 0;
  1241. dev->scancode_wakeup_filter.mask = 0;
  1242. rc = dev->s_wakeup_filter(dev, &dev->scancode_wakeup_filter);
  1243. if (rc == 0)
  1244. rc = len;
  1245. } else {
  1246. rc = len;
  1247. }
  1248. out:
  1249. mutex_unlock(&dev->lock);
  1250. return rc;
  1251. }
  1252. static void rc_dev_release(struct device *device)
  1253. {
  1254. struct rc_dev *dev = to_rc_dev(device);
  1255. kfree(dev);
  1256. }
  1257. #define ADD_HOTPLUG_VAR(fmt, val...) \
  1258. do { \
  1259. int err = add_uevent_var(env, fmt, val); \
  1260. if (err) \
  1261. return err; \
  1262. } while (0)
  1263. static int rc_dev_uevent(struct device *device, struct kobj_uevent_env *env)
  1264. {
  1265. struct rc_dev *dev = to_rc_dev(device);
  1266. if (dev->rc_map.name)
  1267. ADD_HOTPLUG_VAR("NAME=%s", dev->rc_map.name);
  1268. if (dev->driver_name)
  1269. ADD_HOTPLUG_VAR("DRV_NAME=%s", dev->driver_name);
  1270. if (dev->device_name)
  1271. ADD_HOTPLUG_VAR("DEV_NAME=%s", dev->device_name);
  1272. return 0;
  1273. }
  1274. /*
  1275. * Static device attribute struct with the sysfs attributes for IR's
  1276. */
  1277. static struct device_attribute dev_attr_ro_protocols =
  1278. __ATTR(protocols, 0444, show_protocols, NULL);
  1279. static struct device_attribute dev_attr_rw_protocols =
  1280. __ATTR(protocols, 0644, show_protocols, store_protocols);
  1281. static DEVICE_ATTR(wakeup_protocols, 0644, show_wakeup_protocols,
  1282. store_wakeup_protocols);
  1283. static RC_FILTER_ATTR(filter, S_IRUGO|S_IWUSR,
  1284. show_filter, store_filter, RC_FILTER_NORMAL, false);
  1285. static RC_FILTER_ATTR(filter_mask, S_IRUGO|S_IWUSR,
  1286. show_filter, store_filter, RC_FILTER_NORMAL, true);
  1287. static RC_FILTER_ATTR(wakeup_filter, S_IRUGO|S_IWUSR,
  1288. show_filter, store_filter, RC_FILTER_WAKEUP, false);
  1289. static RC_FILTER_ATTR(wakeup_filter_mask, S_IRUGO|S_IWUSR,
  1290. show_filter, store_filter, RC_FILTER_WAKEUP, true);
  1291. static struct attribute *rc_dev_rw_protocol_attrs[] = {
  1292. &dev_attr_rw_protocols.attr,
  1293. NULL,
  1294. };
  1295. static const struct attribute_group rc_dev_rw_protocol_attr_grp = {
  1296. .attrs = rc_dev_rw_protocol_attrs,
  1297. };
  1298. static struct attribute *rc_dev_ro_protocol_attrs[] = {
  1299. &dev_attr_ro_protocols.attr,
  1300. NULL,
  1301. };
  1302. static const struct attribute_group rc_dev_ro_protocol_attr_grp = {
  1303. .attrs = rc_dev_ro_protocol_attrs,
  1304. };
  1305. static struct attribute *rc_dev_filter_attrs[] = {
  1306. &dev_attr_filter.attr.attr,
  1307. &dev_attr_filter_mask.attr.attr,
  1308. NULL,
  1309. };
  1310. static const struct attribute_group rc_dev_filter_attr_grp = {
  1311. .attrs = rc_dev_filter_attrs,
  1312. };
  1313. static struct attribute *rc_dev_wakeup_filter_attrs[] = {
  1314. &dev_attr_wakeup_filter.attr.attr,
  1315. &dev_attr_wakeup_filter_mask.attr.attr,
  1316. &dev_attr_wakeup_protocols.attr,
  1317. NULL,
  1318. };
  1319. static const struct attribute_group rc_dev_wakeup_filter_attr_grp = {
  1320. .attrs = rc_dev_wakeup_filter_attrs,
  1321. };
  1322. static const struct device_type rc_dev_type = {
  1323. .release = rc_dev_release,
  1324. .uevent = rc_dev_uevent,
  1325. };
  1326. struct rc_dev *rc_allocate_device(enum rc_driver_type type)
  1327. {
  1328. struct rc_dev *dev;
  1329. dev = kzalloc(sizeof(*dev), GFP_KERNEL);
  1330. if (!dev)
  1331. return NULL;
  1332. if (type != RC_DRIVER_IR_RAW_TX) {
  1333. dev->input_dev = input_allocate_device();
  1334. if (!dev->input_dev) {
  1335. kfree(dev);
  1336. return NULL;
  1337. }
  1338. dev->input_dev->getkeycode = ir_getkeycode;
  1339. dev->input_dev->setkeycode = ir_setkeycode;
  1340. input_set_drvdata(dev->input_dev, dev);
  1341. timer_setup(&dev->timer_keyup, ir_timer_keyup, 0);
  1342. spin_lock_init(&dev->rc_map.lock);
  1343. spin_lock_init(&dev->keylock);
  1344. }
  1345. mutex_init(&dev->lock);
  1346. dev->dev.type = &rc_dev_type;
  1347. dev->dev.class = &rc_class;
  1348. device_initialize(&dev->dev);
  1349. dev->driver_type = type;
  1350. __module_get(THIS_MODULE);
  1351. return dev;
  1352. }
  1353. EXPORT_SYMBOL_GPL(rc_allocate_device);
  1354. void rc_free_device(struct rc_dev *dev)
  1355. {
  1356. if (!dev)
  1357. return;
  1358. input_free_device(dev->input_dev);
  1359. put_device(&dev->dev);
  1360. /* kfree(dev) will be called by the callback function
  1361. rc_dev_release() */
  1362. module_put(THIS_MODULE);
  1363. }
  1364. EXPORT_SYMBOL_GPL(rc_free_device);
  1365. static void devm_rc_alloc_release(struct device *dev, void *res)
  1366. {
  1367. rc_free_device(*(struct rc_dev **)res);
  1368. }
  1369. struct rc_dev *devm_rc_allocate_device(struct device *dev,
  1370. enum rc_driver_type type)
  1371. {
  1372. struct rc_dev **dr, *rc;
  1373. dr = devres_alloc(devm_rc_alloc_release, sizeof(*dr), GFP_KERNEL);
  1374. if (!dr)
  1375. return NULL;
  1376. rc = rc_allocate_device(type);
  1377. if (!rc) {
  1378. devres_free(dr);
  1379. return NULL;
  1380. }
  1381. rc->dev.parent = dev;
  1382. rc->managed_alloc = true;
  1383. *dr = rc;
  1384. devres_add(dev, dr);
  1385. return rc;
  1386. }
  1387. EXPORT_SYMBOL_GPL(devm_rc_allocate_device);
  1388. static int rc_prepare_rx_device(struct rc_dev *dev)
  1389. {
  1390. int rc;
  1391. struct rc_map *rc_map;
  1392. u64 rc_proto;
  1393. if (!dev->map_name)
  1394. return -EINVAL;
  1395. rc_map = rc_map_get(dev->map_name);
  1396. if (!rc_map)
  1397. rc_map = rc_map_get(RC_MAP_EMPTY);
  1398. if (!rc_map || !rc_map->scan || rc_map->size == 0)
  1399. return -EINVAL;
  1400. rc = ir_setkeytable(dev, rc_map);
  1401. if (rc)
  1402. return rc;
  1403. rc_proto = BIT_ULL(rc_map->rc_proto);
  1404. if (dev->driver_type == RC_DRIVER_SCANCODE && !dev->change_protocol)
  1405. dev->enabled_protocols = dev->allowed_protocols;
  1406. if (dev->change_protocol) {
  1407. rc = dev->change_protocol(dev, &rc_proto);
  1408. if (rc < 0)
  1409. goto out_table;
  1410. dev->enabled_protocols = rc_proto;
  1411. }
  1412. if (dev->driver_type == RC_DRIVER_IR_RAW)
  1413. ir_raw_load_modules(&rc_proto);
  1414. set_bit(EV_KEY, dev->input_dev->evbit);
  1415. set_bit(EV_REP, dev->input_dev->evbit);
  1416. set_bit(EV_MSC, dev->input_dev->evbit);
  1417. set_bit(MSC_SCAN, dev->input_dev->mscbit);
  1418. if (dev->open)
  1419. dev->input_dev->open = ir_open;
  1420. if (dev->close)
  1421. dev->input_dev->close = ir_close;
  1422. dev->input_dev->dev.parent = &dev->dev;
  1423. memcpy(&dev->input_dev->id, &dev->input_id, sizeof(dev->input_id));
  1424. dev->input_dev->phys = dev->input_phys;
  1425. dev->input_dev->name = dev->device_name;
  1426. return 0;
  1427. out_table:
  1428. ir_free_table(&dev->rc_map);
  1429. return rc;
  1430. }
  1431. static int rc_setup_rx_device(struct rc_dev *dev)
  1432. {
  1433. int rc;
  1434. /* rc_open will be called here */
  1435. rc = input_register_device(dev->input_dev);
  1436. if (rc)
  1437. return rc;
  1438. /*
  1439. * Default delay of 250ms is too short for some protocols, especially
  1440. * since the timeout is currently set to 250ms. Increase it to 500ms,
  1441. * to avoid wrong repetition of the keycodes. Note that this must be
  1442. * set after the call to input_register_device().
  1443. */
  1444. dev->input_dev->rep[REP_DELAY] = 500;
  1445. /*
  1446. * As a repeat event on protocols like RC-5 and NEC take as long as
  1447. * 110/114ms, using 33ms as a repeat period is not the right thing
  1448. * to do.
  1449. */
  1450. dev->input_dev->rep[REP_PERIOD] = 125;
  1451. return 0;
  1452. }
  1453. static void rc_free_rx_device(struct rc_dev *dev)
  1454. {
  1455. if (!dev)
  1456. return;
  1457. if (dev->input_dev) {
  1458. input_unregister_device(dev->input_dev);
  1459. dev->input_dev = NULL;
  1460. }
  1461. ir_free_table(&dev->rc_map);
  1462. }
  1463. int rc_register_device(struct rc_dev *dev)
  1464. {
  1465. const char *path;
  1466. int attr = 0;
  1467. int minor;
  1468. int rc;
  1469. if (!dev)
  1470. return -EINVAL;
  1471. minor = ida_simple_get(&rc_ida, 0, RC_DEV_MAX, GFP_KERNEL);
  1472. if (minor < 0)
  1473. return minor;
  1474. dev->minor = minor;
  1475. dev_set_name(&dev->dev, "rc%u", dev->minor);
  1476. dev_set_drvdata(&dev->dev, dev);
  1477. dev->dev.groups = dev->sysfs_groups;
  1478. if (dev->driver_type == RC_DRIVER_SCANCODE && !dev->change_protocol)
  1479. dev->sysfs_groups[attr++] = &rc_dev_ro_protocol_attr_grp;
  1480. else if (dev->driver_type != RC_DRIVER_IR_RAW_TX)
  1481. dev->sysfs_groups[attr++] = &rc_dev_rw_protocol_attr_grp;
  1482. if (dev->s_filter)
  1483. dev->sysfs_groups[attr++] = &rc_dev_filter_attr_grp;
  1484. if (dev->s_wakeup_filter)
  1485. dev->sysfs_groups[attr++] = &rc_dev_wakeup_filter_attr_grp;
  1486. dev->sysfs_groups[attr++] = NULL;
  1487. if (dev->driver_type == RC_DRIVER_IR_RAW) {
  1488. rc = ir_raw_event_prepare(dev);
  1489. if (rc < 0)
  1490. goto out_minor;
  1491. }
  1492. if (dev->driver_type != RC_DRIVER_IR_RAW_TX) {
  1493. rc = rc_prepare_rx_device(dev);
  1494. if (rc)
  1495. goto out_raw;
  1496. }
  1497. rc = device_add(&dev->dev);
  1498. if (rc)
  1499. goto out_rx_free;
  1500. path = kobject_get_path(&dev->dev.kobj, GFP_KERNEL);
  1501. dev_info(&dev->dev, "%s as %s\n",
  1502. dev->device_name ?: "Unspecified device", path ?: "N/A");
  1503. kfree(path);
  1504. if (dev->driver_type != RC_DRIVER_IR_RAW_TX) {
  1505. rc = rc_setup_rx_device(dev);
  1506. if (rc)
  1507. goto out_dev;
  1508. }
  1509. /* Ensure that the lirc kfifo is setup before we start the thread */
  1510. if (dev->driver_type != RC_DRIVER_SCANCODE) {
  1511. rc = ir_lirc_register(dev);
  1512. if (rc < 0)
  1513. goto out_rx;
  1514. }
  1515. if (dev->driver_type == RC_DRIVER_IR_RAW) {
  1516. rc = ir_raw_event_register(dev);
  1517. if (rc < 0)
  1518. goto out_lirc;
  1519. }
  1520. IR_dprintk(1, "Registered rc%u (driver: %s)\n",
  1521. dev->minor,
  1522. dev->driver_name ? dev->driver_name : "unknown");
  1523. return 0;
  1524. out_lirc:
  1525. if (dev->driver_type != RC_DRIVER_SCANCODE)
  1526. ir_lirc_unregister(dev);
  1527. out_rx:
  1528. rc_free_rx_device(dev);
  1529. out_dev:
  1530. device_del(&dev->dev);
  1531. out_rx_free:
  1532. ir_free_table(&dev->rc_map);
  1533. out_raw:
  1534. ir_raw_event_free(dev);
  1535. out_minor:
  1536. ida_simple_remove(&rc_ida, minor);
  1537. return rc;
  1538. }
  1539. EXPORT_SYMBOL_GPL(rc_register_device);
  1540. static void devm_rc_release(struct device *dev, void *res)
  1541. {
  1542. rc_unregister_device(*(struct rc_dev **)res);
  1543. }
  1544. int devm_rc_register_device(struct device *parent, struct rc_dev *dev)
  1545. {
  1546. struct rc_dev **dr;
  1547. int ret;
  1548. dr = devres_alloc(devm_rc_release, sizeof(*dr), GFP_KERNEL);
  1549. if (!dr)
  1550. return -ENOMEM;
  1551. ret = rc_register_device(dev);
  1552. if (ret) {
  1553. devres_free(dr);
  1554. return ret;
  1555. }
  1556. *dr = dev;
  1557. devres_add(parent, dr);
  1558. return 0;
  1559. }
  1560. EXPORT_SYMBOL_GPL(devm_rc_register_device);
  1561. void rc_unregister_device(struct rc_dev *dev)
  1562. {
  1563. if (!dev)
  1564. return;
  1565. del_timer_sync(&dev->timer_keyup);
  1566. if (dev->driver_type == RC_DRIVER_IR_RAW)
  1567. ir_raw_event_unregister(dev);
  1568. rc_free_rx_device(dev);
  1569. if (dev->driver_type != RC_DRIVER_SCANCODE)
  1570. ir_lirc_unregister(dev);
  1571. device_del(&dev->dev);
  1572. ida_simple_remove(&rc_ida, dev->minor);
  1573. if (!dev->managed_alloc)
  1574. rc_free_device(dev);
  1575. }
  1576. EXPORT_SYMBOL_GPL(rc_unregister_device);
  1577. /*
  1578. * Init/exit code for the module. Basically, creates/removes /sys/class/rc
  1579. */
  1580. static int __init rc_core_init(void)
  1581. {
  1582. int rc = class_register(&rc_class);
  1583. if (rc) {
  1584. pr_err("rc_core: unable to register rc class\n");
  1585. return rc;
  1586. }
  1587. rc = lirc_dev_init();
  1588. if (rc) {
  1589. pr_err("rc_core: unable to init lirc\n");
  1590. class_unregister(&rc_class);
  1591. return 0;
  1592. }
  1593. led_trigger_register_simple("rc-feedback", &led_feedback);
  1594. rc_map_register(&empty_map);
  1595. return 0;
  1596. }
  1597. static void __exit rc_core_exit(void)
  1598. {
  1599. lirc_dev_exit();
  1600. class_unregister(&rc_class);
  1601. led_trigger_unregister_simple(led_feedback);
  1602. rc_map_unregister(&empty_map);
  1603. }
  1604. subsys_initcall(rc_core_init);
  1605. module_exit(rc_core_exit);
  1606. int rc_core_debug; /* ir_debug level (0,1,2) */
  1607. EXPORT_SYMBOL_GPL(rc_core_debug);
  1608. module_param_named(debug, rc_core_debug, int, 0644);
  1609. MODULE_AUTHOR("Mauro Carvalho Chehab");
  1610. MODULE_LICENSE("GPL v2");