keyboard.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374
  1. /*
  2. * linux/drivers/char/keyboard.c
  3. *
  4. * Written for linux by Johan Myreen as a translation from
  5. * the assembly version by Linus (with diacriticals added)
  6. *
  7. * Some additional features added by Christoph Niemann (ChN), March 1993
  8. *
  9. * Loadable keymaps by Risto Kankkunen, May 1993
  10. *
  11. * Diacriticals redone & other small changes, aeb@cwi.nl, June 1993
  12. * Added decr/incr_console, dynamic keymaps, Unicode support,
  13. * dynamic function/string keys, led setting, Sept 1994
  14. * `Sticky' modifier keys, 951006.
  15. *
  16. * 11-11-96: SAK should now work in the raw mode (Martin Mares)
  17. *
  18. * Modified to provide 'generic' keyboard support by Hamish Macdonald
  19. * Merge with the m68k keyboard driver and split-off of the PC low-level
  20. * parts by Geert Uytterhoeven, May 1997
  21. *
  22. * 27-05-97: Added support for the Magic SysRq Key (Martin Mares)
  23. * 30-07-98: Dead keys redone, aeb@cwi.nl.
  24. * 21-08-02: Converted to input API, major cleanup. (Vojtech Pavlik)
  25. */
  26. #include <linux/module.h>
  27. #include <linux/sched.h>
  28. #include <linux/tty.h>
  29. #include <linux/tty_flip.h>
  30. #include <linux/mm.h>
  31. #include <linux/string.h>
  32. #include <linux/init.h>
  33. #include <linux/slab.h>
  34. #include <linux/irq.h>
  35. #include <linux/kbd_kern.h>
  36. #include <linux/kbd_diacr.h>
  37. #include <linux/vt_kern.h>
  38. #include <linux/sysrq.h>
  39. #include <linux/input.h>
  40. #include <linux/reboot.h>
  41. extern void ctrl_alt_del(void);
  42. /*
  43. * Exported functions/variables
  44. */
  45. #define KBD_DEFMODE ((1 << VC_REPEAT) | (1 << VC_META))
  46. /*
  47. * Some laptops take the 789uiojklm,. keys as number pad when NumLock is on.
  48. * This seems a good reason to start with NumLock off. On HIL keyboards
  49. * of PARISC machines however there is no NumLock key and everyone expects the keypad
  50. * to be used for numbers.
  51. */
  52. #if defined(CONFIG_PARISC) && (defined(CONFIG_KEYBOARD_HIL) || defined(CONFIG_KEYBOARD_HIL_OLD))
  53. #define KBD_DEFLEDS (1 << VC_NUMLOCK)
  54. #else
  55. #define KBD_DEFLEDS 0
  56. #endif
  57. #define KBD_DEFLOCK 0
  58. void compute_shiftstate(void);
  59. /*
  60. * Handler Tables.
  61. */
  62. #define K_HANDLERS\
  63. k_self, k_fn, k_spec, k_pad,\
  64. k_dead, k_cons, k_cur, k_shift,\
  65. k_meta, k_ascii, k_lock, k_lowercase,\
  66. k_slock, k_dead2, k_brl, k_ignore
  67. typedef void (k_handler_fn)(struct vc_data *vc, unsigned char value,
  68. char up_flag);
  69. static k_handler_fn K_HANDLERS;
  70. static k_handler_fn *k_handler[16] = { K_HANDLERS };
  71. #define FN_HANDLERS\
  72. fn_null, fn_enter, fn_show_ptregs, fn_show_mem,\
  73. fn_show_state, fn_send_intr, fn_lastcons, fn_caps_toggle,\
  74. fn_num, fn_hold, fn_scroll_forw, fn_scroll_back,\
  75. fn_boot_it, fn_caps_on, fn_compose, fn_SAK,\
  76. fn_dec_console, fn_inc_console, fn_spawn_con, fn_bare_num
  77. typedef void (fn_handler_fn)(struct vc_data *vc);
  78. static fn_handler_fn FN_HANDLERS;
  79. static fn_handler_fn *fn_handler[] = { FN_HANDLERS };
  80. /*
  81. * Variables exported for vt_ioctl.c
  82. */
  83. /* maximum values each key_handler can handle */
  84. const int max_vals[] = {
  85. 255, ARRAY_SIZE(func_table) - 1, ARRAY_SIZE(fn_handler) - 1, NR_PAD - 1,
  86. NR_DEAD - 1, 255, 3, NR_SHIFT - 1, 255, NR_ASCII - 1, NR_LOCK - 1,
  87. 255, NR_LOCK - 1, 255, NR_BRL - 1
  88. };
  89. const int NR_TYPES = ARRAY_SIZE(max_vals);
  90. struct kbd_struct kbd_table[MAX_NR_CONSOLES];
  91. static struct kbd_struct *kbd = kbd_table;
  92. struct vt_spawn_console vt_spawn_con = {
  93. .lock = __SPIN_LOCK_UNLOCKED(vt_spawn_con.lock),
  94. .pid = NULL,
  95. .sig = 0,
  96. };
  97. /*
  98. * Variables exported for vt.c
  99. */
  100. int shift_state = 0;
  101. /*
  102. * Internal Data.
  103. */
  104. static struct input_handler kbd_handler;
  105. static unsigned long key_down[NBITS(KEY_MAX)]; /* keyboard key bitmap */
  106. static unsigned char shift_down[NR_SHIFT]; /* shift state counters.. */
  107. static int dead_key_next;
  108. static int npadch = -1; /* -1 or number assembled on pad */
  109. static unsigned int diacr;
  110. static char rep; /* flag telling character repeat */
  111. static unsigned char ledstate = 0xff; /* undefined */
  112. static unsigned char ledioctl;
  113. static struct ledptr {
  114. unsigned int *addr;
  115. unsigned int mask;
  116. unsigned char valid:1;
  117. } ledptrs[3];
  118. /* Simple translation table for the SysRq keys */
  119. #ifdef CONFIG_MAGIC_SYSRQ
  120. unsigned char kbd_sysrq_xlate[KEY_MAX + 1] =
  121. "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */
  122. "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */
  123. "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */
  124. "bnm,./\000*\000 \000\201\202\203\204\205" /* 0x30 - 0x3f */
  125. "\206\207\210\211\212\000\000789-456+1" /* 0x40 - 0x4f */
  126. "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */
  127. "\r\000/"; /* 0x60 - 0x6f */
  128. static int sysrq_down;
  129. static int sysrq_alt_use;
  130. #endif
  131. static int sysrq_alt;
  132. /*
  133. * Translation of scancodes to keycodes. We set them on only the first
  134. * keyboard in the list that accepts the scancode and keycode.
  135. * Explanation for not choosing the first attached keyboard anymore:
  136. * USB keyboards for example have two event devices: one for all "normal"
  137. * keys and one for extra function keys (like "volume up", "make coffee",
  138. * etc.). So this means that scancodes for the extra function keys won't
  139. * be valid for the first event device, but will be for the second.
  140. */
  141. int getkeycode(unsigned int scancode)
  142. {
  143. struct input_handle *handle;
  144. int keycode;
  145. int error = -ENODEV;
  146. list_for_each_entry(handle, &kbd_handler.h_list, h_node) {
  147. error = handle->dev->getkeycode(handle->dev, scancode, &keycode);
  148. if (!error)
  149. return keycode;
  150. }
  151. return error;
  152. }
  153. int setkeycode(unsigned int scancode, unsigned int keycode)
  154. {
  155. struct input_handle *handle;
  156. int error = -ENODEV;
  157. list_for_each_entry(handle, &kbd_handler.h_list, h_node) {
  158. error = handle->dev->setkeycode(handle->dev, scancode, keycode);
  159. if (!error)
  160. break;
  161. }
  162. return error;
  163. }
  164. /*
  165. * Making beeps and bells.
  166. */
  167. static void kd_nosound(unsigned long ignored)
  168. {
  169. struct input_handle *handle;
  170. list_for_each_entry(handle, &kbd_handler.h_list, h_node) {
  171. if (test_bit(EV_SND, handle->dev->evbit)) {
  172. if (test_bit(SND_TONE, handle->dev->sndbit))
  173. input_inject_event(handle, EV_SND, SND_TONE, 0);
  174. if (test_bit(SND_BELL, handle->dev->sndbit))
  175. input_inject_event(handle, EV_SND, SND_BELL, 0);
  176. }
  177. }
  178. }
  179. static DEFINE_TIMER(kd_mksound_timer, kd_nosound, 0, 0);
  180. void kd_mksound(unsigned int hz, unsigned int ticks)
  181. {
  182. struct list_head *node;
  183. del_timer(&kd_mksound_timer);
  184. if (hz) {
  185. list_for_each_prev(node, &kbd_handler.h_list) {
  186. struct input_handle *handle = to_handle_h(node);
  187. if (test_bit(EV_SND, handle->dev->evbit)) {
  188. if (test_bit(SND_TONE, handle->dev->sndbit)) {
  189. input_inject_event(handle, EV_SND, SND_TONE, hz);
  190. break;
  191. }
  192. if (test_bit(SND_BELL, handle->dev->sndbit)) {
  193. input_inject_event(handle, EV_SND, SND_BELL, 1);
  194. break;
  195. }
  196. }
  197. }
  198. if (ticks)
  199. mod_timer(&kd_mksound_timer, jiffies + ticks);
  200. } else
  201. kd_nosound(0);
  202. }
  203. /*
  204. * Setting the keyboard rate.
  205. */
  206. int kbd_rate(struct kbd_repeat *rep)
  207. {
  208. struct list_head *node;
  209. unsigned int d = 0;
  210. unsigned int p = 0;
  211. list_for_each(node, &kbd_handler.h_list) {
  212. struct input_handle *handle = to_handle_h(node);
  213. struct input_dev *dev = handle->dev;
  214. if (test_bit(EV_REP, dev->evbit)) {
  215. if (rep->delay > 0)
  216. input_inject_event(handle, EV_REP, REP_DELAY, rep->delay);
  217. if (rep->period > 0)
  218. input_inject_event(handle, EV_REP, REP_PERIOD, rep->period);
  219. d = dev->rep[REP_DELAY];
  220. p = dev->rep[REP_PERIOD];
  221. }
  222. }
  223. rep->delay = d;
  224. rep->period = p;
  225. return 0;
  226. }
  227. /*
  228. * Helper Functions.
  229. */
  230. static void put_queue(struct vc_data *vc, int ch)
  231. {
  232. struct tty_struct *tty = vc->vc_tty;
  233. if (tty) {
  234. tty_insert_flip_char(tty, ch, 0);
  235. con_schedule_flip(tty);
  236. }
  237. }
  238. static void puts_queue(struct vc_data *vc, char *cp)
  239. {
  240. struct tty_struct *tty = vc->vc_tty;
  241. if (!tty)
  242. return;
  243. while (*cp) {
  244. tty_insert_flip_char(tty, *cp, 0);
  245. cp++;
  246. }
  247. con_schedule_flip(tty);
  248. }
  249. static void applkey(struct vc_data *vc, int key, char mode)
  250. {
  251. static char buf[] = { 0x1b, 'O', 0x00, 0x00 };
  252. buf[1] = (mode ? 'O' : '[');
  253. buf[2] = key;
  254. puts_queue(vc, buf);
  255. }
  256. /*
  257. * Many other routines do put_queue, but I think either
  258. * they produce ASCII, or they produce some user-assigned
  259. * string, and in both cases we might assume that it is
  260. * in utf-8 already. UTF-8 is defined for words of up to 31 bits,
  261. * but we need only 16 bits here
  262. */
  263. static void to_utf8(struct vc_data *vc, ushort c)
  264. {
  265. if (c < 0x80)
  266. /* 0******* */
  267. put_queue(vc, c);
  268. else if (c < 0x800) {
  269. /* 110***** 10****** */
  270. put_queue(vc, 0xc0 | (c >> 6));
  271. put_queue(vc, 0x80 | (c & 0x3f));
  272. } else {
  273. /* 1110**** 10****** 10****** */
  274. put_queue(vc, 0xe0 | (c >> 12));
  275. put_queue(vc, 0x80 | ((c >> 6) & 0x3f));
  276. put_queue(vc, 0x80 | (c & 0x3f));
  277. }
  278. }
  279. /*
  280. * Called after returning from RAW mode or when changing consoles - recompute
  281. * shift_down[] and shift_state from key_down[] maybe called when keymap is
  282. * undefined, so that shiftkey release is seen
  283. */
  284. void compute_shiftstate(void)
  285. {
  286. unsigned int i, j, k, sym, val;
  287. shift_state = 0;
  288. memset(shift_down, 0, sizeof(shift_down));
  289. for (i = 0; i < ARRAY_SIZE(key_down); i++) {
  290. if (!key_down[i])
  291. continue;
  292. k = i * BITS_PER_LONG;
  293. for (j = 0; j < BITS_PER_LONG; j++, k++) {
  294. if (!test_bit(k, key_down))
  295. continue;
  296. sym = U(key_maps[0][k]);
  297. if (KTYP(sym) != KT_SHIFT && KTYP(sym) != KT_SLOCK)
  298. continue;
  299. val = KVAL(sym);
  300. if (val == KVAL(K_CAPSSHIFT))
  301. val = KVAL(K_SHIFT);
  302. shift_down[val]++;
  303. shift_state |= (1 << val);
  304. }
  305. }
  306. }
  307. /*
  308. * We have a combining character DIACR here, followed by the character CH.
  309. * If the combination occurs in the table, return the corresponding value.
  310. * Otherwise, if CH is a space or equals DIACR, return DIACR.
  311. * Otherwise, conclude that DIACR was not combining after all,
  312. * queue it and return CH.
  313. */
  314. static unsigned int handle_diacr(struct vc_data *vc, unsigned int ch)
  315. {
  316. unsigned int d = diacr;
  317. unsigned int i;
  318. diacr = 0;
  319. if ((d & ~0xff) == BRL_UC_ROW) {
  320. if ((ch & ~0xff) == BRL_UC_ROW)
  321. return d | ch;
  322. } else {
  323. for (i = 0; i < accent_table_size; i++)
  324. if (accent_table[i].diacr == d && accent_table[i].base == ch)
  325. return accent_table[i].result;
  326. }
  327. if (ch == ' ' || ch == (BRL_UC_ROW|0) || ch == d)
  328. return d;
  329. if (kbd->kbdmode == VC_UNICODE)
  330. to_utf8(vc, d);
  331. else if (d < 0x100)
  332. put_queue(vc, d);
  333. return ch;
  334. }
  335. /*
  336. * Special function handlers
  337. */
  338. static void fn_enter(struct vc_data *vc)
  339. {
  340. if (diacr) {
  341. if (kbd->kbdmode == VC_UNICODE)
  342. to_utf8(vc, diacr);
  343. else if (diacr < 0x100)
  344. put_queue(vc, diacr);
  345. diacr = 0;
  346. }
  347. put_queue(vc, 13);
  348. if (vc_kbd_mode(kbd, VC_CRLF))
  349. put_queue(vc, 10);
  350. }
  351. static void fn_caps_toggle(struct vc_data *vc)
  352. {
  353. if (rep)
  354. return;
  355. chg_vc_kbd_led(kbd, VC_CAPSLOCK);
  356. }
  357. static void fn_caps_on(struct vc_data *vc)
  358. {
  359. if (rep)
  360. return;
  361. set_vc_kbd_led(kbd, VC_CAPSLOCK);
  362. }
  363. static void fn_show_ptregs(struct vc_data *vc)
  364. {
  365. struct pt_regs *regs = get_irq_regs();
  366. if (regs)
  367. show_regs(regs);
  368. }
  369. static void fn_hold(struct vc_data *vc)
  370. {
  371. struct tty_struct *tty = vc->vc_tty;
  372. if (rep || !tty)
  373. return;
  374. /*
  375. * Note: SCROLLOCK will be set (cleared) by stop_tty (start_tty);
  376. * these routines are also activated by ^S/^Q.
  377. * (And SCROLLOCK can also be set by the ioctl KDSKBLED.)
  378. */
  379. if (tty->stopped)
  380. start_tty(tty);
  381. else
  382. stop_tty(tty);
  383. }
  384. static void fn_num(struct vc_data *vc)
  385. {
  386. if (vc_kbd_mode(kbd,VC_APPLIC))
  387. applkey(vc, 'P', 1);
  388. else
  389. fn_bare_num(vc);
  390. }
  391. /*
  392. * Bind this to Shift-NumLock if you work in application keypad mode
  393. * but want to be able to change the NumLock flag.
  394. * Bind this to NumLock if you prefer that the NumLock key always
  395. * changes the NumLock flag.
  396. */
  397. static void fn_bare_num(struct vc_data *vc)
  398. {
  399. if (!rep)
  400. chg_vc_kbd_led(kbd, VC_NUMLOCK);
  401. }
  402. static void fn_lastcons(struct vc_data *vc)
  403. {
  404. /* switch to the last used console, ChN */
  405. set_console(last_console);
  406. }
  407. static void fn_dec_console(struct vc_data *vc)
  408. {
  409. int i, cur = fg_console;
  410. /* Currently switching? Queue this next switch relative to that. */
  411. if (want_console != -1)
  412. cur = want_console;
  413. for (i = cur - 1; i != cur; i--) {
  414. if (i == -1)
  415. i = MAX_NR_CONSOLES - 1;
  416. if (vc_cons_allocated(i))
  417. break;
  418. }
  419. set_console(i);
  420. }
  421. static void fn_inc_console(struct vc_data *vc)
  422. {
  423. int i, cur = fg_console;
  424. /* Currently switching? Queue this next switch relative to that. */
  425. if (want_console != -1)
  426. cur = want_console;
  427. for (i = cur+1; i != cur; i++) {
  428. if (i == MAX_NR_CONSOLES)
  429. i = 0;
  430. if (vc_cons_allocated(i))
  431. break;
  432. }
  433. set_console(i);
  434. }
  435. static void fn_send_intr(struct vc_data *vc)
  436. {
  437. struct tty_struct *tty = vc->vc_tty;
  438. if (!tty)
  439. return;
  440. tty_insert_flip_char(tty, 0, TTY_BREAK);
  441. con_schedule_flip(tty);
  442. }
  443. static void fn_scroll_forw(struct vc_data *vc)
  444. {
  445. scrollfront(vc, 0);
  446. }
  447. static void fn_scroll_back(struct vc_data *vc)
  448. {
  449. scrollback(vc, 0);
  450. }
  451. static void fn_show_mem(struct vc_data *vc)
  452. {
  453. show_mem();
  454. }
  455. static void fn_show_state(struct vc_data *vc)
  456. {
  457. show_state();
  458. }
  459. static void fn_boot_it(struct vc_data *vc)
  460. {
  461. ctrl_alt_del();
  462. }
  463. static void fn_compose(struct vc_data *vc)
  464. {
  465. dead_key_next = 1;
  466. }
  467. static void fn_spawn_con(struct vc_data *vc)
  468. {
  469. spin_lock(&vt_spawn_con.lock);
  470. if (vt_spawn_con.pid)
  471. if (kill_pid(vt_spawn_con.pid, vt_spawn_con.sig, 1)) {
  472. put_pid(vt_spawn_con.pid);
  473. vt_spawn_con.pid = NULL;
  474. }
  475. spin_unlock(&vt_spawn_con.lock);
  476. }
  477. static void fn_SAK(struct vc_data *vc)
  478. {
  479. struct work_struct *SAK_work = &vc_cons[fg_console].SAK_work;
  480. schedule_work(SAK_work);
  481. }
  482. static void fn_null(struct vc_data *vc)
  483. {
  484. compute_shiftstate();
  485. }
  486. /*
  487. * Special key handlers
  488. */
  489. static void k_ignore(struct vc_data *vc, unsigned char value, char up_flag)
  490. {
  491. }
  492. static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
  493. {
  494. if (up_flag)
  495. return;
  496. if (value >= ARRAY_SIZE(fn_handler))
  497. return;
  498. if ((kbd->kbdmode == VC_RAW ||
  499. kbd->kbdmode == VC_MEDIUMRAW) &&
  500. value != KVAL(K_SAK))
  501. return; /* SAK is allowed even in raw mode */
  502. fn_handler[value](vc);
  503. }
  504. static void k_lowercase(struct vc_data *vc, unsigned char value, char up_flag)
  505. {
  506. printk(KERN_ERR "keyboard.c: k_lowercase was called - impossible\n");
  507. }
  508. static void k_unicode(struct vc_data *vc, unsigned int value, char up_flag)
  509. {
  510. if (up_flag)
  511. return; /* no action, if this is a key release */
  512. if (diacr)
  513. value = handle_diacr(vc, value);
  514. if (dead_key_next) {
  515. dead_key_next = 0;
  516. diacr = value;
  517. return;
  518. }
  519. if (kbd->kbdmode == VC_UNICODE)
  520. to_utf8(vc, value);
  521. else if (value < 0x100)
  522. put_queue(vc, value);
  523. }
  524. /*
  525. * Handle dead key. Note that we now may have several
  526. * dead keys modifying the same character. Very useful
  527. * for Vietnamese.
  528. */
  529. static void k_deadunicode(struct vc_data *vc, unsigned int value, char up_flag)
  530. {
  531. if (up_flag)
  532. return;
  533. diacr = (diacr ? handle_diacr(vc, value) : value);
  534. }
  535. static void k_self(struct vc_data *vc, unsigned char value, char up_flag)
  536. {
  537. k_unicode(vc, value, up_flag);
  538. }
  539. static void k_dead2(struct vc_data *vc, unsigned char value, char up_flag)
  540. {
  541. k_deadunicode(vc, value, up_flag);
  542. }
  543. /*
  544. * Obsolete - for backwards compatibility only
  545. */
  546. static void k_dead(struct vc_data *vc, unsigned char value, char up_flag)
  547. {
  548. static const unsigned char ret_diacr[NR_DEAD] = {'`', '\'', '^', '~', '"', ',' };
  549. value = ret_diacr[value];
  550. k_deadunicode(vc, value, up_flag);
  551. }
  552. static void k_cons(struct vc_data *vc, unsigned char value, char up_flag)
  553. {
  554. if (up_flag)
  555. return;
  556. set_console(value);
  557. }
  558. static void k_fn(struct vc_data *vc, unsigned char value, char up_flag)
  559. {
  560. unsigned v;
  561. if (up_flag)
  562. return;
  563. v = value;
  564. if (v < ARRAY_SIZE(func_table)) {
  565. if (func_table[value])
  566. puts_queue(vc, func_table[value]);
  567. } else
  568. printk(KERN_ERR "k_fn called with value=%d\n", value);
  569. }
  570. static void k_cur(struct vc_data *vc, unsigned char value, char up_flag)
  571. {
  572. static const char cur_chars[] = "BDCA";
  573. if (up_flag)
  574. return;
  575. applkey(vc, cur_chars[value], vc_kbd_mode(kbd, VC_CKMODE));
  576. }
  577. static void k_pad(struct vc_data *vc, unsigned char value, char up_flag)
  578. {
  579. static const char pad_chars[] = "0123456789+-*/\015,.?()#";
  580. static const char app_map[] = "pqrstuvwxylSRQMnnmPQS";
  581. if (up_flag)
  582. return; /* no action, if this is a key release */
  583. /* kludge... shift forces cursor/number keys */
  584. if (vc_kbd_mode(kbd, VC_APPLIC) && !shift_down[KG_SHIFT]) {
  585. applkey(vc, app_map[value], 1);
  586. return;
  587. }
  588. if (!vc_kbd_led(kbd, VC_NUMLOCK))
  589. switch (value) {
  590. case KVAL(K_PCOMMA):
  591. case KVAL(K_PDOT):
  592. k_fn(vc, KVAL(K_REMOVE), 0);
  593. return;
  594. case KVAL(K_P0):
  595. k_fn(vc, KVAL(K_INSERT), 0);
  596. return;
  597. case KVAL(K_P1):
  598. k_fn(vc, KVAL(K_SELECT), 0);
  599. return;
  600. case KVAL(K_P2):
  601. k_cur(vc, KVAL(K_DOWN), 0);
  602. return;
  603. case KVAL(K_P3):
  604. k_fn(vc, KVAL(K_PGDN), 0);
  605. return;
  606. case KVAL(K_P4):
  607. k_cur(vc, KVAL(K_LEFT), 0);
  608. return;
  609. case KVAL(K_P6):
  610. k_cur(vc, KVAL(K_RIGHT), 0);
  611. return;
  612. case KVAL(K_P7):
  613. k_fn(vc, KVAL(K_FIND), 0);
  614. return;
  615. case KVAL(K_P8):
  616. k_cur(vc, KVAL(K_UP), 0);
  617. return;
  618. case KVAL(K_P9):
  619. k_fn(vc, KVAL(K_PGUP), 0);
  620. return;
  621. case KVAL(K_P5):
  622. applkey(vc, 'G', vc_kbd_mode(kbd, VC_APPLIC));
  623. return;
  624. }
  625. put_queue(vc, pad_chars[value]);
  626. if (value == KVAL(K_PENTER) && vc_kbd_mode(kbd, VC_CRLF))
  627. put_queue(vc, 10);
  628. }
  629. static void k_shift(struct vc_data *vc, unsigned char value, char up_flag)
  630. {
  631. int old_state = shift_state;
  632. if (rep)
  633. return;
  634. /*
  635. * Mimic typewriter:
  636. * a CapsShift key acts like Shift but undoes CapsLock
  637. */
  638. if (value == KVAL(K_CAPSSHIFT)) {
  639. value = KVAL(K_SHIFT);
  640. if (!up_flag)
  641. clr_vc_kbd_led(kbd, VC_CAPSLOCK);
  642. }
  643. if (up_flag) {
  644. /*
  645. * handle the case that two shift or control
  646. * keys are depressed simultaneously
  647. */
  648. if (shift_down[value])
  649. shift_down[value]--;
  650. } else
  651. shift_down[value]++;
  652. if (shift_down[value])
  653. shift_state |= (1 << value);
  654. else
  655. shift_state &= ~(1 << value);
  656. /* kludge */
  657. if (up_flag && shift_state != old_state && npadch != -1) {
  658. if (kbd->kbdmode == VC_UNICODE)
  659. to_utf8(vc, npadch & 0xffff);
  660. else
  661. put_queue(vc, npadch & 0xff);
  662. npadch = -1;
  663. }
  664. }
  665. static void k_meta(struct vc_data *vc, unsigned char value, char up_flag)
  666. {
  667. if (up_flag)
  668. return;
  669. if (vc_kbd_mode(kbd, VC_META)) {
  670. put_queue(vc, '\033');
  671. put_queue(vc, value);
  672. } else
  673. put_queue(vc, value | 0x80);
  674. }
  675. static void k_ascii(struct vc_data *vc, unsigned char value, char up_flag)
  676. {
  677. int base;
  678. if (up_flag)
  679. return;
  680. if (value < 10) {
  681. /* decimal input of code, while Alt depressed */
  682. base = 10;
  683. } else {
  684. /* hexadecimal input of code, while AltGr depressed */
  685. value -= 10;
  686. base = 16;
  687. }
  688. if (npadch == -1)
  689. npadch = value;
  690. else
  691. npadch = npadch * base + value;
  692. }
  693. static void k_lock(struct vc_data *vc, unsigned char value, char up_flag)
  694. {
  695. if (up_flag || rep)
  696. return;
  697. chg_vc_kbd_lock(kbd, value);
  698. }
  699. static void k_slock(struct vc_data *vc, unsigned char value, char up_flag)
  700. {
  701. k_shift(vc, value, up_flag);
  702. if (up_flag || rep)
  703. return;
  704. chg_vc_kbd_slock(kbd, value);
  705. /* try to make Alt, oops, AltGr and such work */
  706. if (!key_maps[kbd->lockstate ^ kbd->slockstate]) {
  707. kbd->slockstate = 0;
  708. chg_vc_kbd_slock(kbd, value);
  709. }
  710. }
  711. /* by default, 300ms interval for combination release */
  712. static unsigned brl_timeout = 300;
  713. MODULE_PARM_DESC(brl_timeout, "Braille keys release delay in ms (0 for commit on first key release)");
  714. module_param(brl_timeout, uint, 0644);
  715. static unsigned brl_nbchords = 1;
  716. MODULE_PARM_DESC(brl_nbchords, "Number of chords that produce a braille pattern (0 for dead chords)");
  717. module_param(brl_nbchords, uint, 0644);
  718. static void k_brlcommit(struct vc_data *vc, unsigned int pattern, char up_flag)
  719. {
  720. static unsigned long chords;
  721. static unsigned committed;
  722. if (!brl_nbchords)
  723. k_deadunicode(vc, BRL_UC_ROW | pattern, up_flag);
  724. else {
  725. committed |= pattern;
  726. chords++;
  727. if (chords == brl_nbchords) {
  728. k_unicode(vc, BRL_UC_ROW | committed, up_flag);
  729. chords = 0;
  730. committed = 0;
  731. }
  732. }
  733. }
  734. static void k_brl(struct vc_data *vc, unsigned char value, char up_flag)
  735. {
  736. static unsigned pressed,committing;
  737. static unsigned long releasestart;
  738. if (kbd->kbdmode != VC_UNICODE) {
  739. if (!up_flag)
  740. printk("keyboard mode must be unicode for braille patterns\n");
  741. return;
  742. }
  743. if (!value) {
  744. k_unicode(vc, BRL_UC_ROW, up_flag);
  745. return;
  746. }
  747. if (value > 8)
  748. return;
  749. if (up_flag) {
  750. if (brl_timeout) {
  751. if (!committing ||
  752. jiffies - releasestart > (brl_timeout * HZ) / 1000) {
  753. committing = pressed;
  754. releasestart = jiffies;
  755. }
  756. pressed &= ~(1 << (value - 1));
  757. if (!pressed) {
  758. if (committing) {
  759. k_brlcommit(vc, committing, 0);
  760. committing = 0;
  761. }
  762. }
  763. } else {
  764. if (committing) {
  765. k_brlcommit(vc, committing, 0);
  766. committing = 0;
  767. }
  768. pressed &= ~(1 << (value - 1));
  769. }
  770. } else {
  771. pressed |= 1 << (value - 1);
  772. if (!brl_timeout)
  773. committing = pressed;
  774. }
  775. }
  776. /*
  777. * The leds display either (i) the status of NumLock, CapsLock, ScrollLock,
  778. * or (ii) whatever pattern of lights people want to show using KDSETLED,
  779. * or (iii) specified bits of specified words in kernel memory.
  780. */
  781. unsigned char getledstate(void)
  782. {
  783. return ledstate;
  784. }
  785. void setledstate(struct kbd_struct *kbd, unsigned int led)
  786. {
  787. if (!(led & ~7)) {
  788. ledioctl = led;
  789. kbd->ledmode = LED_SHOW_IOCTL;
  790. } else
  791. kbd->ledmode = LED_SHOW_FLAGS;
  792. set_leds();
  793. }
  794. static inline unsigned char getleds(void)
  795. {
  796. struct kbd_struct *kbd = kbd_table + fg_console;
  797. unsigned char leds;
  798. int i;
  799. if (kbd->ledmode == LED_SHOW_IOCTL)
  800. return ledioctl;
  801. leds = kbd->ledflagstate;
  802. if (kbd->ledmode == LED_SHOW_MEM) {
  803. for (i = 0; i < 3; i++)
  804. if (ledptrs[i].valid) {
  805. if (*ledptrs[i].addr & ledptrs[i].mask)
  806. leds |= (1 << i);
  807. else
  808. leds &= ~(1 << i);
  809. }
  810. }
  811. return leds;
  812. }
  813. /*
  814. * This routine is the bottom half of the keyboard interrupt
  815. * routine, and runs with all interrupts enabled. It does
  816. * console changing, led setting and copy_to_cooked, which can
  817. * take a reasonably long time.
  818. *
  819. * Aside from timing (which isn't really that important for
  820. * keyboard interrupts as they happen often), using the software
  821. * interrupt routines for this thing allows us to easily mask
  822. * this when we don't want any of the above to happen.
  823. * This allows for easy and efficient race-condition prevention
  824. * for kbd_start => input_inject_event(dev, EV_LED, ...) => ...
  825. */
  826. static void kbd_bh(unsigned long dummy)
  827. {
  828. struct list_head *node;
  829. unsigned char leds = getleds();
  830. if (leds != ledstate) {
  831. list_for_each(node, &kbd_handler.h_list) {
  832. struct input_handle *handle = to_handle_h(node);
  833. input_inject_event(handle, EV_LED, LED_SCROLLL, !!(leds & 0x01));
  834. input_inject_event(handle, EV_LED, LED_NUML, !!(leds & 0x02));
  835. input_inject_event(handle, EV_LED, LED_CAPSL, !!(leds & 0x04));
  836. input_inject_event(handle, EV_SYN, SYN_REPORT, 0);
  837. }
  838. }
  839. ledstate = leds;
  840. }
  841. DECLARE_TASKLET_DISABLED(keyboard_tasklet, kbd_bh, 0);
  842. #if defined(CONFIG_X86) || defined(CONFIG_IA64) || defined(CONFIG_ALPHA) ||\
  843. defined(CONFIG_MIPS) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) ||\
  844. defined(CONFIG_PARISC) || defined(CONFIG_SUPERH) ||\
  845. (defined(CONFIG_ARM) && defined(CONFIG_KEYBOARD_ATKBD) && !defined(CONFIG_ARCH_RPC))
  846. #define HW_RAW(dev) (test_bit(EV_MSC, dev->evbit) && test_bit(MSC_RAW, dev->mscbit) &&\
  847. ((dev)->id.bustype == BUS_I8042) && ((dev)->id.vendor == 0x0001) && ((dev)->id.product == 0x0001))
  848. static const unsigned short x86_keycodes[256] =
  849. { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
  850. 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
  851. 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47,
  852. 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63,
  853. 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
  854. 80, 81, 82, 83, 84,118, 86, 87, 88,115,120,119,121,112,123, 92,
  855. 284,285,309, 0,312, 91,327,328,329,331,333,335,336,337,338,339,
  856. 367,288,302,304,350, 89,334,326,267,126,268,269,125,347,348,349,
  857. 360,261,262,263,268,376,100,101,321,316,373,286,289,102,351,355,
  858. 103,104,105,275,287,279,306,106,274,107,294,364,358,363,362,361,
  859. 291,108,381,281,290,272,292,305,280, 99,112,257,258,359,113,114,
  860. 264,117,271,374,379,265,266, 93, 94, 95, 85,259,375,260, 90,116,
  861. 377,109,111,277,278,282,283,295,296,297,299,300,301,293,303,307,
  862. 308,310,313,314,315,317,318,319,320,357,322,323,324,325,276,330,
  863. 332,340,365,342,343,344,345,346,356,270,341,368,369,370,371,372 };
  864. #ifdef CONFIG_MAC_EMUMOUSEBTN
  865. extern int mac_hid_mouse_emulate_buttons(int, int, int);
  866. #endif /* CONFIG_MAC_EMUMOUSEBTN */
  867. #ifdef CONFIG_SPARC
  868. static int sparc_l1_a_state = 0;
  869. extern void sun_do_break(void);
  870. #endif
  871. static int emulate_raw(struct vc_data *vc, unsigned int keycode,
  872. unsigned char up_flag)
  873. {
  874. int code;
  875. switch (keycode) {
  876. case KEY_PAUSE:
  877. put_queue(vc, 0xe1);
  878. put_queue(vc, 0x1d | up_flag);
  879. put_queue(vc, 0x45 | up_flag);
  880. break;
  881. case KEY_HANGEUL:
  882. if (!up_flag)
  883. put_queue(vc, 0xf2);
  884. break;
  885. case KEY_HANJA:
  886. if (!up_flag)
  887. put_queue(vc, 0xf1);
  888. break;
  889. case KEY_SYSRQ:
  890. /*
  891. * Real AT keyboards (that's what we're trying
  892. * to emulate here emit 0xe0 0x2a 0xe0 0x37 when
  893. * pressing PrtSc/SysRq alone, but simply 0x54
  894. * when pressing Alt+PrtSc/SysRq.
  895. */
  896. if (sysrq_alt) {
  897. put_queue(vc, 0x54 | up_flag);
  898. } else {
  899. put_queue(vc, 0xe0);
  900. put_queue(vc, 0x2a | up_flag);
  901. put_queue(vc, 0xe0);
  902. put_queue(vc, 0x37 | up_flag);
  903. }
  904. break;
  905. default:
  906. if (keycode > 255)
  907. return -1;
  908. code = x86_keycodes[keycode];
  909. if (!code)
  910. return -1;
  911. if (code & 0x100)
  912. put_queue(vc, 0xe0);
  913. put_queue(vc, (code & 0x7f) | up_flag);
  914. break;
  915. }
  916. return 0;
  917. }
  918. #else
  919. #define HW_RAW(dev) 0
  920. #warning "Cannot generate rawmode keyboard for your architecture yet."
  921. static int emulate_raw(struct vc_data *vc, unsigned int keycode, unsigned char up_flag)
  922. {
  923. if (keycode > 127)
  924. return -1;
  925. put_queue(vc, keycode | up_flag);
  926. return 0;
  927. }
  928. #endif
  929. static void kbd_rawcode(unsigned char data)
  930. {
  931. struct vc_data *vc = vc_cons[fg_console].d;
  932. kbd = kbd_table + fg_console;
  933. if (kbd->kbdmode == VC_RAW)
  934. put_queue(vc, data);
  935. }
  936. static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
  937. {
  938. struct vc_data *vc = vc_cons[fg_console].d;
  939. unsigned short keysym, *key_map;
  940. unsigned char type, raw_mode;
  941. struct tty_struct *tty;
  942. int shift_final;
  943. tty = vc->vc_tty;
  944. if (tty && (!tty->driver_data)) {
  945. /* No driver data? Strange. Okay we fix it then. */
  946. tty->driver_data = vc;
  947. }
  948. kbd = kbd_table + fg_console;
  949. if (keycode == KEY_LEFTALT || keycode == KEY_RIGHTALT)
  950. sysrq_alt = down ? keycode : 0;
  951. #ifdef CONFIG_SPARC
  952. if (keycode == KEY_STOP)
  953. sparc_l1_a_state = down;
  954. #endif
  955. rep = (down == 2);
  956. #ifdef CONFIG_MAC_EMUMOUSEBTN
  957. if (mac_hid_mouse_emulate_buttons(1, keycode, down))
  958. return;
  959. #endif /* CONFIG_MAC_EMUMOUSEBTN */
  960. if ((raw_mode = (kbd->kbdmode == VC_RAW)) && !hw_raw)
  961. if (emulate_raw(vc, keycode, !down << 7))
  962. if (keycode < BTN_MISC && printk_ratelimit())
  963. printk(KERN_WARNING "keyboard.c: can't emulate rawmode for keycode %d\n", keycode);
  964. #ifdef CONFIG_MAGIC_SYSRQ /* Handle the SysRq Hack */
  965. if (keycode == KEY_SYSRQ && (sysrq_down || (down == 1 && sysrq_alt))) {
  966. if (!sysrq_down) {
  967. sysrq_down = down;
  968. sysrq_alt_use = sysrq_alt;
  969. }
  970. return;
  971. }
  972. if (sysrq_down && !down && keycode == sysrq_alt_use)
  973. sysrq_down = 0;
  974. if (sysrq_down && down && !rep) {
  975. handle_sysrq(kbd_sysrq_xlate[keycode], tty);
  976. return;
  977. }
  978. #endif
  979. #ifdef CONFIG_SPARC
  980. if (keycode == KEY_A && sparc_l1_a_state) {
  981. sparc_l1_a_state = 0;
  982. sun_do_break();
  983. }
  984. #endif
  985. if (kbd->kbdmode == VC_MEDIUMRAW) {
  986. /*
  987. * This is extended medium raw mode, with keys above 127
  988. * encoded as 0, high 7 bits, low 7 bits, with the 0 bearing
  989. * the 'up' flag if needed. 0 is reserved, so this shouldn't
  990. * interfere with anything else. The two bytes after 0 will
  991. * always have the up flag set not to interfere with older
  992. * applications. This allows for 16384 different keycodes,
  993. * which should be enough.
  994. */
  995. if (keycode < 128) {
  996. put_queue(vc, keycode | (!down << 7));
  997. } else {
  998. put_queue(vc, !down << 7);
  999. put_queue(vc, (keycode >> 7) | 0x80);
  1000. put_queue(vc, keycode | 0x80);
  1001. }
  1002. raw_mode = 1;
  1003. }
  1004. if (down)
  1005. set_bit(keycode, key_down);
  1006. else
  1007. clear_bit(keycode, key_down);
  1008. if (rep &&
  1009. (!vc_kbd_mode(kbd, VC_REPEAT) ||
  1010. (tty && !L_ECHO(tty) && tty->driver->chars_in_buffer(tty)))) {
  1011. /*
  1012. * Don't repeat a key if the input buffers are not empty and the
  1013. * characters get aren't echoed locally. This makes key repeat
  1014. * usable with slow applications and under heavy loads.
  1015. */
  1016. return;
  1017. }
  1018. shift_final = (shift_state | kbd->slockstate) ^ kbd->lockstate;
  1019. key_map = key_maps[shift_final];
  1020. if (!key_map) {
  1021. compute_shiftstate();
  1022. kbd->slockstate = 0;
  1023. return;
  1024. }
  1025. if (keycode > NR_KEYS)
  1026. if (keycode >= KEY_BRL_DOT1 && keycode <= KEY_BRL_DOT8)
  1027. keysym = K(KT_BRL, keycode - KEY_BRL_DOT1 + 1);
  1028. else
  1029. return;
  1030. else
  1031. keysym = key_map[keycode];
  1032. type = KTYP(keysym);
  1033. if (type < 0xf0) {
  1034. if (down && !raw_mode)
  1035. to_utf8(vc, keysym);
  1036. return;
  1037. }
  1038. type -= 0xf0;
  1039. if (raw_mode && type != KT_SPEC && type != KT_SHIFT)
  1040. return;
  1041. if (type == KT_LETTER) {
  1042. type = KT_LATIN;
  1043. if (vc_kbd_led(kbd, VC_CAPSLOCK)) {
  1044. key_map = key_maps[shift_final ^ (1 << KG_SHIFT)];
  1045. if (key_map)
  1046. keysym = key_map[keycode];
  1047. }
  1048. }
  1049. (*k_handler[type])(vc, keysym & 0xff, !down);
  1050. if (type != KT_SLOCK)
  1051. kbd->slockstate = 0;
  1052. }
  1053. static void kbd_event(struct input_handle *handle, unsigned int event_type,
  1054. unsigned int event_code, int value)
  1055. {
  1056. if (event_type == EV_MSC && event_code == MSC_RAW && HW_RAW(handle->dev))
  1057. kbd_rawcode(value);
  1058. if (event_type == EV_KEY)
  1059. kbd_keycode(event_code, value, HW_RAW(handle->dev));
  1060. tasklet_schedule(&keyboard_tasklet);
  1061. do_poke_blanked_console = 1;
  1062. schedule_console_callback();
  1063. }
  1064. /*
  1065. * When a keyboard (or other input device) is found, the kbd_connect
  1066. * function is called. The function then looks at the device, and if it
  1067. * likes it, it can open it and get events from it. In this (kbd_connect)
  1068. * function, we should decide which VT to bind that keyboard to initially.
  1069. */
  1070. static int kbd_connect(struct input_handler *handler, struct input_dev *dev,
  1071. const struct input_device_id *id)
  1072. {
  1073. struct input_handle *handle;
  1074. int error;
  1075. int i;
  1076. for (i = KEY_RESERVED; i < BTN_MISC; i++)
  1077. if (test_bit(i, dev->keybit))
  1078. break;
  1079. if (i == BTN_MISC && !test_bit(EV_SND, dev->evbit))
  1080. return -ENODEV;
  1081. handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
  1082. if (!handle)
  1083. return -ENOMEM;
  1084. handle->dev = dev;
  1085. handle->handler = handler;
  1086. handle->name = "kbd";
  1087. error = input_register_handle(handle);
  1088. if (error)
  1089. goto err_free_handle;
  1090. error = input_open_device(handle);
  1091. if (error)
  1092. goto err_unregister_handle;
  1093. return 0;
  1094. err_unregister_handle:
  1095. input_unregister_handle(handle);
  1096. err_free_handle:
  1097. kfree(handle);
  1098. return error;
  1099. }
  1100. static void kbd_disconnect(struct input_handle *handle)
  1101. {
  1102. input_close_device(handle);
  1103. input_unregister_handle(handle);
  1104. kfree(handle);
  1105. }
  1106. /*
  1107. * Start keyboard handler on the new keyboard by refreshing LED state to
  1108. * match the rest of the system.
  1109. */
  1110. static void kbd_start(struct input_handle *handle)
  1111. {
  1112. unsigned char leds = ledstate;
  1113. tasklet_disable(&keyboard_tasklet);
  1114. if (leds != 0xff) {
  1115. input_inject_event(handle, EV_LED, LED_SCROLLL, !!(leds & 0x01));
  1116. input_inject_event(handle, EV_LED, LED_NUML, !!(leds & 0x02));
  1117. input_inject_event(handle, EV_LED, LED_CAPSL, !!(leds & 0x04));
  1118. input_inject_event(handle, EV_SYN, SYN_REPORT, 0);
  1119. }
  1120. tasklet_enable(&keyboard_tasklet);
  1121. }
  1122. static const struct input_device_id kbd_ids[] = {
  1123. {
  1124. .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
  1125. .evbit = { BIT(EV_KEY) },
  1126. },
  1127. {
  1128. .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
  1129. .evbit = { BIT(EV_SND) },
  1130. },
  1131. { }, /* Terminating entry */
  1132. };
  1133. MODULE_DEVICE_TABLE(input, kbd_ids);
  1134. static struct input_handler kbd_handler = {
  1135. .event = kbd_event,
  1136. .connect = kbd_connect,
  1137. .disconnect = kbd_disconnect,
  1138. .start = kbd_start,
  1139. .name = "kbd",
  1140. .id_table = kbd_ids,
  1141. };
  1142. int __init kbd_init(void)
  1143. {
  1144. int i;
  1145. int error;
  1146. for (i = 0; i < MAX_NR_CONSOLES; i++) {
  1147. kbd_table[i].ledflagstate = KBD_DEFLEDS;
  1148. kbd_table[i].default_ledflagstate = KBD_DEFLEDS;
  1149. kbd_table[i].ledmode = LED_SHOW_FLAGS;
  1150. kbd_table[i].lockstate = KBD_DEFLOCK;
  1151. kbd_table[i].slockstate = 0;
  1152. kbd_table[i].modeflags = KBD_DEFMODE;
  1153. kbd_table[i].kbdmode = VC_XLATE;
  1154. }
  1155. error = input_register_handler(&kbd_handler);
  1156. if (error)
  1157. return error;
  1158. tasklet_enable(&keyboard_tasklet);
  1159. tasklet_schedule(&keyboard_tasklet);
  1160. return 0;
  1161. }