atkbd.c 45 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821
  1. /*
  2. * AT and PS/2 keyboard driver
  3. *
  4. * Copyright (c) 1999-2002 Vojtech Pavlik
  5. */
  6. /*
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published by
  9. * the Free Software Foundation.
  10. */
  11. /*
  12. * This driver can handle standard AT keyboards and PS/2 keyboards in
  13. * Translated and Raw Set 2 and Set 3, as well as AT keyboards on dumb
  14. * input-only controllers and AT keyboards connected over a one way RS232
  15. * converter.
  16. */
  17. #include <linux/delay.h>
  18. #include <linux/module.h>
  19. #include <linux/slab.h>
  20. #include <linux/interrupt.h>
  21. #include <linux/init.h>
  22. #include <linux/input.h>
  23. #include <linux/serio.h>
  24. #include <linux/workqueue.h>
  25. #include <linux/libps2.h>
  26. #include <linux/mutex.h>
  27. #include <linux/dmi.h>
  28. #define DRIVER_DESC "AT and PS/2 keyboard driver"
  29. MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
  30. MODULE_DESCRIPTION(DRIVER_DESC);
  31. MODULE_LICENSE("GPL");
  32. static int atkbd_set = 2;
  33. module_param_named(set, atkbd_set, int, 0);
  34. MODULE_PARM_DESC(set, "Select keyboard code set (2 = default, 3 = PS/2 native)");
  35. #if defined(__i386__) || defined(__x86_64__) || defined(__hppa__)
  36. static bool atkbd_reset;
  37. #else
  38. static bool atkbd_reset = true;
  39. #endif
  40. module_param_named(reset, atkbd_reset, bool, 0);
  41. MODULE_PARM_DESC(reset, "Reset keyboard during initialization");
  42. static bool atkbd_softrepeat;
  43. module_param_named(softrepeat, atkbd_softrepeat, bool, 0);
  44. MODULE_PARM_DESC(softrepeat, "Use software keyboard repeat");
  45. static bool atkbd_softraw = true;
  46. module_param_named(softraw, atkbd_softraw, bool, 0);
  47. MODULE_PARM_DESC(softraw, "Use software generated rawmode");
  48. static bool atkbd_scroll;
  49. module_param_named(scroll, atkbd_scroll, bool, 0);
  50. MODULE_PARM_DESC(scroll, "Enable scroll-wheel on MS Office and similar keyboards");
  51. static bool atkbd_extra;
  52. module_param_named(extra, atkbd_extra, bool, 0);
  53. MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards");
  54. static bool atkbd_terminal;
  55. module_param_named(terminal, atkbd_terminal, bool, 0);
  56. MODULE_PARM_DESC(terminal, "Enable break codes on an IBM Terminal keyboard connected via AT/PS2");
  57. /*
  58. * Scancode to keycode tables. These are just the default setting, and
  59. * are loadable via a userland utility.
  60. */
  61. #define ATKBD_KEYMAP_SIZE 512
  62. static const unsigned short atkbd_set2_keycode[ATKBD_KEYMAP_SIZE] = {
  63. #ifdef CONFIG_KEYBOARD_ATKBD_HP_KEYCODES
  64. /* XXX: need a more general approach */
  65. #include "hpps2atkbd.h" /* include the keyboard scancodes */
  66. #else
  67. 0, 67, 65, 63, 61, 59, 60, 88, 0, 68, 66, 64, 62, 15, 41,117,
  68. 0, 56, 42, 93, 29, 16, 2, 0, 0, 0, 44, 31, 30, 17, 3, 0,
  69. 0, 46, 45, 32, 18, 5, 4, 95, 0, 57, 47, 33, 20, 19, 6,183,
  70. 0, 49, 48, 35, 34, 21, 7,184, 0, 0, 50, 36, 22, 8, 9,185,
  71. 0, 51, 37, 23, 24, 11, 10, 0, 0, 52, 53, 38, 39, 25, 12, 0,
  72. 0, 89, 40, 0, 26, 13, 0, 0, 58, 54, 28, 27, 0, 43, 0, 85,
  73. 0, 86, 91, 90, 92, 0, 14, 94, 0, 79,124, 75, 71,121, 0, 0,
  74. 82, 83, 80, 76, 77, 72, 1, 69, 87, 78, 81, 74, 55, 73, 70, 99,
  75. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  76. 217,100,255, 0, 97,165, 0, 0,156, 0, 0, 0, 0, 0, 0,125,
  77. 173,114, 0,113, 0, 0, 0,126,128, 0, 0,140, 0, 0, 0,127,
  78. 159, 0,115, 0,164, 0, 0,116,158, 0,172,166, 0, 0, 0,142,
  79. 157, 0, 0, 0, 0, 0, 0, 0,155, 0, 98, 0, 0,163, 0, 0,
  80. 226, 0, 0, 0, 0, 0, 0, 0, 0,255, 96, 0, 0, 0,143, 0,
  81. 0, 0, 0, 0, 0, 0, 0, 0, 0,107, 0,105,102, 0, 0,112,
  82. 110,111,108,112,106,103, 0,119, 0,118,109, 0, 99,104,119, 0,
  83. 0, 0, 0, 65, 99,
  84. #endif
  85. };
  86. static const unsigned short atkbd_set3_keycode[ATKBD_KEYMAP_SIZE] = {
  87. 0, 0, 0, 0, 0, 0, 0, 59, 1,138,128,129,130, 15, 41, 60,
  88. 131, 29, 42, 86, 58, 16, 2, 61,133, 56, 44, 31, 30, 17, 3, 62,
  89. 134, 46, 45, 32, 18, 5, 4, 63,135, 57, 47, 33, 20, 19, 6, 64,
  90. 136, 49, 48, 35, 34, 21, 7, 65,137,100, 50, 36, 22, 8, 9, 66,
  91. 125, 51, 37, 23, 24, 11, 10, 67,126, 52, 53, 38, 39, 25, 12, 68,
  92. 113,114, 40, 43, 26, 13, 87, 99, 97, 54, 28, 27, 43, 43, 88, 70,
  93. 108,105,119,103,111,107, 14,110, 0, 79,106, 75, 71,109,102,104,
  94. 82, 83, 80, 76, 77, 72, 69, 98, 0, 96, 81, 0, 78, 73, 55,183,
  95. 184,185,186,187, 74, 94, 92, 93, 0, 0, 0,125,126,127,112, 0,
  96. 0,139,172,163,165,115,152,172,166,140,160,154,113,114,167,168,
  97. 148,149,147,140
  98. };
  99. static const unsigned short atkbd_unxlate_table[128] = {
  100. 0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13,
  101. 21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27,
  102. 35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42,
  103. 50, 49, 58, 65, 73, 74, 89,124, 17, 41, 88, 5, 6, 4, 12, 3,
  104. 11, 2, 10, 1, 9,119,126,108,117,125,123,107,115,116,121,105,
  105. 114,122,112,113,127, 96, 97,120, 7, 15, 23, 31, 39, 47, 55, 63,
  106. 71, 79, 86, 94, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 87,111,
  107. 19, 25, 57, 81, 83, 92, 95, 98, 99,100,101,103,104,106,109,110
  108. };
  109. #define ATKBD_CMD_SETLEDS 0x10ed
  110. #define ATKBD_CMD_GSCANSET 0x11f0
  111. #define ATKBD_CMD_SSCANSET 0x10f0
  112. #define ATKBD_CMD_GETID 0x02f2
  113. #define ATKBD_CMD_SETREP 0x10f3
  114. #define ATKBD_CMD_ENABLE 0x00f4
  115. #define ATKBD_CMD_RESET_DIS 0x00f5 /* Reset to defaults and disable */
  116. #define ATKBD_CMD_RESET_DEF 0x00f6 /* Reset to defaults */
  117. #define ATKBD_CMD_SETALL_MB 0x00f8 /* Set all keys to give break codes */
  118. #define ATKBD_CMD_SETALL_MBR 0x00fa /* ... and repeat */
  119. #define ATKBD_CMD_RESET_BAT 0x02ff
  120. #define ATKBD_CMD_RESEND 0x00fe
  121. #define ATKBD_CMD_EX_ENABLE 0x10ea
  122. #define ATKBD_CMD_EX_SETLEDS 0x20eb
  123. #define ATKBD_CMD_OK_GETID 0x02e8
  124. #define ATKBD_RET_ACK 0xfa
  125. #define ATKBD_RET_NAK 0xfe
  126. #define ATKBD_RET_BAT 0xaa
  127. #define ATKBD_RET_EMUL0 0xe0
  128. #define ATKBD_RET_EMUL1 0xe1
  129. #define ATKBD_RET_RELEASE 0xf0
  130. #define ATKBD_RET_HANJA 0xf1
  131. #define ATKBD_RET_HANGEUL 0xf2
  132. #define ATKBD_RET_ERR 0xff
  133. #define ATKBD_KEY_UNKNOWN 0
  134. #define ATKBD_KEY_NULL 255
  135. #define ATKBD_SCR_1 0xfffe
  136. #define ATKBD_SCR_2 0xfffd
  137. #define ATKBD_SCR_4 0xfffc
  138. #define ATKBD_SCR_8 0xfffb
  139. #define ATKBD_SCR_CLICK 0xfffa
  140. #define ATKBD_SCR_LEFT 0xfff9
  141. #define ATKBD_SCR_RIGHT 0xfff8
  142. #define ATKBD_SPECIAL ATKBD_SCR_RIGHT
  143. #define ATKBD_LED_EVENT_BIT 0
  144. #define ATKBD_REP_EVENT_BIT 1
  145. #define ATKBD_XL_ERR 0x01
  146. #define ATKBD_XL_BAT 0x02
  147. #define ATKBD_XL_ACK 0x04
  148. #define ATKBD_XL_NAK 0x08
  149. #define ATKBD_XL_HANGEUL 0x10
  150. #define ATKBD_XL_HANJA 0x20
  151. static const struct {
  152. unsigned short keycode;
  153. unsigned char set2;
  154. } atkbd_scroll_keys[] = {
  155. { ATKBD_SCR_1, 0xc5 },
  156. { ATKBD_SCR_2, 0x9d },
  157. { ATKBD_SCR_4, 0xa4 },
  158. { ATKBD_SCR_8, 0x9b },
  159. { ATKBD_SCR_CLICK, 0xe0 },
  160. { ATKBD_SCR_LEFT, 0xcb },
  161. { ATKBD_SCR_RIGHT, 0xd2 },
  162. };
  163. /*
  164. * The atkbd control structure
  165. */
  166. struct atkbd {
  167. struct ps2dev ps2dev;
  168. struct input_dev *dev;
  169. /* Written only during init */
  170. char name[64];
  171. char phys[32];
  172. unsigned short id;
  173. unsigned short keycode[ATKBD_KEYMAP_SIZE];
  174. DECLARE_BITMAP(force_release_mask, ATKBD_KEYMAP_SIZE);
  175. unsigned char set;
  176. bool translated;
  177. bool extra;
  178. bool write;
  179. bool softrepeat;
  180. bool softraw;
  181. bool scroll;
  182. bool enabled;
  183. /* Accessed only from interrupt */
  184. unsigned char emul;
  185. bool resend;
  186. bool release;
  187. unsigned long xl_bit;
  188. unsigned int last;
  189. unsigned long time;
  190. unsigned long err_count;
  191. struct delayed_work event_work;
  192. unsigned long event_jiffies;
  193. unsigned long event_mask;
  194. /* Serializes reconnect(), attr->set() and event work */
  195. struct mutex mutex;
  196. };
  197. /*
  198. * System-specific keymap fixup routine
  199. */
  200. static void (*atkbd_platform_fixup)(struct atkbd *, const void *data);
  201. static void *atkbd_platform_fixup_data;
  202. static unsigned int (*atkbd_platform_scancode_fixup)(struct atkbd *, unsigned int);
  203. /*
  204. * Certain keyboards to not like ATKBD_CMD_RESET_DIS and stop responding
  205. * to many commands until full reset (ATKBD_CMD_RESET_BAT) is performed.
  206. */
  207. static bool atkbd_skip_deactivate;
  208. static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf,
  209. ssize_t (*handler)(struct atkbd *, char *));
  210. static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t count,
  211. ssize_t (*handler)(struct atkbd *, const char *, size_t));
  212. #define ATKBD_DEFINE_ATTR(_name) \
  213. static ssize_t atkbd_show_##_name(struct atkbd *, char *); \
  214. static ssize_t atkbd_set_##_name(struct atkbd *, const char *, size_t); \
  215. static ssize_t atkbd_do_show_##_name(struct device *d, \
  216. struct device_attribute *attr, char *b) \
  217. { \
  218. return atkbd_attr_show_helper(d, b, atkbd_show_##_name); \
  219. } \
  220. static ssize_t atkbd_do_set_##_name(struct device *d, \
  221. struct device_attribute *attr, const char *b, size_t s) \
  222. { \
  223. return atkbd_attr_set_helper(d, b, s, atkbd_set_##_name); \
  224. } \
  225. static struct device_attribute atkbd_attr_##_name = \
  226. __ATTR(_name, S_IWUSR | S_IRUGO, atkbd_do_show_##_name, atkbd_do_set_##_name);
  227. ATKBD_DEFINE_ATTR(extra);
  228. ATKBD_DEFINE_ATTR(force_release);
  229. ATKBD_DEFINE_ATTR(scroll);
  230. ATKBD_DEFINE_ATTR(set);
  231. ATKBD_DEFINE_ATTR(softrepeat);
  232. ATKBD_DEFINE_ATTR(softraw);
  233. #define ATKBD_DEFINE_RO_ATTR(_name) \
  234. static ssize_t atkbd_show_##_name(struct atkbd *, char *); \
  235. static ssize_t atkbd_do_show_##_name(struct device *d, \
  236. struct device_attribute *attr, char *b) \
  237. { \
  238. return atkbd_attr_show_helper(d, b, atkbd_show_##_name); \
  239. } \
  240. static struct device_attribute atkbd_attr_##_name = \
  241. __ATTR(_name, S_IRUGO, atkbd_do_show_##_name, NULL);
  242. ATKBD_DEFINE_RO_ATTR(err_count);
  243. static struct attribute *atkbd_attributes[] = {
  244. &atkbd_attr_extra.attr,
  245. &atkbd_attr_force_release.attr,
  246. &atkbd_attr_scroll.attr,
  247. &atkbd_attr_set.attr,
  248. &atkbd_attr_softrepeat.attr,
  249. &atkbd_attr_softraw.attr,
  250. &atkbd_attr_err_count.attr,
  251. NULL
  252. };
  253. static struct attribute_group atkbd_attribute_group = {
  254. .attrs = atkbd_attributes,
  255. };
  256. static const unsigned int xl_table[] = {
  257. ATKBD_RET_BAT, ATKBD_RET_ERR, ATKBD_RET_ACK,
  258. ATKBD_RET_NAK, ATKBD_RET_HANJA, ATKBD_RET_HANGEUL,
  259. };
  260. /*
  261. * Checks if we should mangle the scancode to extract 'release' bit
  262. * in translated mode.
  263. */
  264. static bool atkbd_need_xlate(unsigned long xl_bit, unsigned char code)
  265. {
  266. int i;
  267. if (code == ATKBD_RET_EMUL0 || code == ATKBD_RET_EMUL1)
  268. return false;
  269. for (i = 0; i < ARRAY_SIZE(xl_table); i++)
  270. if (code == xl_table[i])
  271. return test_bit(i, &xl_bit);
  272. return true;
  273. }
  274. /*
  275. * Calculates new value of xl_bit so the driver can distinguish
  276. * between make/break pair of scancodes for select keys and PS/2
  277. * protocol responses.
  278. */
  279. static void atkbd_calculate_xl_bit(struct atkbd *atkbd, unsigned char code)
  280. {
  281. int i;
  282. for (i = 0; i < ARRAY_SIZE(xl_table); i++) {
  283. if (!((code ^ xl_table[i]) & 0x7f)) {
  284. if (code & 0x80)
  285. __clear_bit(i, &atkbd->xl_bit);
  286. else
  287. __set_bit(i, &atkbd->xl_bit);
  288. break;
  289. }
  290. }
  291. }
  292. /*
  293. * Encode the scancode, 0xe0 prefix, and high bit into a single integer,
  294. * keeping kernel 2.4 compatibility for set 2
  295. */
  296. static unsigned int atkbd_compat_scancode(struct atkbd *atkbd, unsigned int code)
  297. {
  298. if (atkbd->set == 3) {
  299. if (atkbd->emul == 1)
  300. code |= 0x100;
  301. } else {
  302. code = (code & 0x7f) | ((code & 0x80) << 1);
  303. if (atkbd->emul == 1)
  304. code |= 0x80;
  305. }
  306. return code;
  307. }
  308. /*
  309. * atkbd_interrupt(). Here takes place processing of data received from
  310. * the keyboard into events.
  311. */
  312. static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
  313. unsigned int flags)
  314. {
  315. struct atkbd *atkbd = serio_get_drvdata(serio);
  316. struct input_dev *dev = atkbd->dev;
  317. unsigned int code = data;
  318. int scroll = 0, hscroll = 0, click = -1;
  319. int value;
  320. unsigned short keycode;
  321. dev_dbg(&serio->dev, "Received %02x flags %02x\n", data, flags);
  322. #if !defined(__i386__) && !defined (__x86_64__)
  323. if ((flags & (SERIO_FRAME | SERIO_PARITY)) && (~flags & SERIO_TIMEOUT) && !atkbd->resend && atkbd->write) {
  324. dev_warn(&serio->dev, "Frame/parity error: %02x\n", flags);
  325. serio_write(serio, ATKBD_CMD_RESEND);
  326. atkbd->resend = true;
  327. goto out;
  328. }
  329. if (!flags && data == ATKBD_RET_ACK)
  330. atkbd->resend = false;
  331. #endif
  332. if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_ACK))
  333. if (ps2_handle_ack(&atkbd->ps2dev, data))
  334. goto out;
  335. if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_CMD))
  336. if (ps2_handle_response(&atkbd->ps2dev, data))
  337. goto out;
  338. if (!atkbd->enabled)
  339. goto out;
  340. input_event(dev, EV_MSC, MSC_RAW, code);
  341. if (atkbd_platform_scancode_fixup)
  342. code = atkbd_platform_scancode_fixup(atkbd, code);
  343. if (atkbd->translated) {
  344. if (atkbd->emul || atkbd_need_xlate(atkbd->xl_bit, code)) {
  345. atkbd->release = code >> 7;
  346. code &= 0x7f;
  347. }
  348. if (!atkbd->emul)
  349. atkbd_calculate_xl_bit(atkbd, data);
  350. }
  351. switch (code) {
  352. case ATKBD_RET_BAT:
  353. atkbd->enabled = false;
  354. serio_reconnect(atkbd->ps2dev.serio);
  355. goto out;
  356. case ATKBD_RET_EMUL0:
  357. atkbd->emul = 1;
  358. goto out;
  359. case ATKBD_RET_EMUL1:
  360. atkbd->emul = 2;
  361. goto out;
  362. case ATKBD_RET_RELEASE:
  363. atkbd->release = true;
  364. goto out;
  365. case ATKBD_RET_ACK:
  366. case ATKBD_RET_NAK:
  367. if (printk_ratelimit())
  368. dev_warn(&serio->dev,
  369. "Spurious %s on %s. "
  370. "Some program might be trying to access hardware directly.\n",
  371. data == ATKBD_RET_ACK ? "ACK" : "NAK", serio->phys);
  372. goto out;
  373. case ATKBD_RET_ERR:
  374. atkbd->err_count++;
  375. dev_dbg(&serio->dev, "Keyboard on %s reports too many keys pressed.\n",
  376. serio->phys);
  377. goto out;
  378. }
  379. code = atkbd_compat_scancode(atkbd, code);
  380. if (atkbd->emul && --atkbd->emul)
  381. goto out;
  382. keycode = atkbd->keycode[code];
  383. if (!(atkbd->release && test_bit(code, atkbd->force_release_mask)))
  384. if (keycode != ATKBD_KEY_NULL)
  385. input_event(dev, EV_MSC, MSC_SCAN, code);
  386. switch (keycode) {
  387. case ATKBD_KEY_NULL:
  388. break;
  389. case ATKBD_KEY_UNKNOWN:
  390. dev_warn(&serio->dev,
  391. "Unknown key %s (%s set %d, code %#x on %s).\n",
  392. atkbd->release ? "released" : "pressed",
  393. atkbd->translated ? "translated" : "raw",
  394. atkbd->set, code, serio->phys);
  395. dev_warn(&serio->dev,
  396. "Use 'setkeycodes %s%02x <keycode>' to make it known.\n",
  397. code & 0x80 ? "e0" : "", code & 0x7f);
  398. input_sync(dev);
  399. break;
  400. case ATKBD_SCR_1:
  401. scroll = 1;
  402. break;
  403. case ATKBD_SCR_2:
  404. scroll = 2;
  405. break;
  406. case ATKBD_SCR_4:
  407. scroll = 4;
  408. break;
  409. case ATKBD_SCR_8:
  410. scroll = 8;
  411. break;
  412. case ATKBD_SCR_CLICK:
  413. click = !atkbd->release;
  414. break;
  415. case ATKBD_SCR_LEFT:
  416. hscroll = -1;
  417. break;
  418. case ATKBD_SCR_RIGHT:
  419. hscroll = 1;
  420. break;
  421. default:
  422. if (atkbd->release) {
  423. value = 0;
  424. atkbd->last = 0;
  425. } else if (!atkbd->softrepeat && test_bit(keycode, dev->key)) {
  426. /* Workaround Toshiba laptop multiple keypress */
  427. value = time_before(jiffies, atkbd->time) && atkbd->last == code ? 1 : 2;
  428. } else {
  429. value = 1;
  430. atkbd->last = code;
  431. atkbd->time = jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]) / 2;
  432. }
  433. input_event(dev, EV_KEY, keycode, value);
  434. input_sync(dev);
  435. if (value && test_bit(code, atkbd->force_release_mask)) {
  436. input_event(dev, EV_MSC, MSC_SCAN, code);
  437. input_report_key(dev, keycode, 0);
  438. input_sync(dev);
  439. }
  440. }
  441. if (atkbd->scroll) {
  442. if (click != -1)
  443. input_report_key(dev, BTN_MIDDLE, click);
  444. input_report_rel(dev, REL_WHEEL,
  445. atkbd->release ? -scroll : scroll);
  446. input_report_rel(dev, REL_HWHEEL, hscroll);
  447. input_sync(dev);
  448. }
  449. atkbd->release = false;
  450. out:
  451. return IRQ_HANDLED;
  452. }
  453. static int atkbd_set_repeat_rate(struct atkbd *atkbd)
  454. {
  455. const short period[32] =
  456. { 33, 37, 42, 46, 50, 54, 58, 63, 67, 75, 83, 92, 100, 109, 116, 125,
  457. 133, 149, 167, 182, 200, 217, 232, 250, 270, 303, 333, 370, 400, 435, 470, 500 };
  458. const short delay[4] =
  459. { 250, 500, 750, 1000 };
  460. struct input_dev *dev = atkbd->dev;
  461. unsigned char param;
  462. int i = 0, j = 0;
  463. while (i < ARRAY_SIZE(period) - 1 && period[i] < dev->rep[REP_PERIOD])
  464. i++;
  465. dev->rep[REP_PERIOD] = period[i];
  466. while (j < ARRAY_SIZE(delay) - 1 && delay[j] < dev->rep[REP_DELAY])
  467. j++;
  468. dev->rep[REP_DELAY] = delay[j];
  469. param = i | (j << 5);
  470. return ps2_command(&atkbd->ps2dev, &param, ATKBD_CMD_SETREP);
  471. }
  472. static int atkbd_set_leds(struct atkbd *atkbd)
  473. {
  474. struct input_dev *dev = atkbd->dev;
  475. unsigned char param[2];
  476. param[0] = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0)
  477. | (test_bit(LED_NUML, dev->led) ? 2 : 0)
  478. | (test_bit(LED_CAPSL, dev->led) ? 4 : 0);
  479. if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS))
  480. return -1;
  481. if (atkbd->extra) {
  482. param[0] = 0;
  483. param[1] = (test_bit(LED_COMPOSE, dev->led) ? 0x01 : 0)
  484. | (test_bit(LED_SLEEP, dev->led) ? 0x02 : 0)
  485. | (test_bit(LED_SUSPEND, dev->led) ? 0x04 : 0)
  486. | (test_bit(LED_MISC, dev->led) ? 0x10 : 0)
  487. | (test_bit(LED_MUTE, dev->led) ? 0x20 : 0);
  488. if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_EX_SETLEDS))
  489. return -1;
  490. }
  491. return 0;
  492. }
  493. /*
  494. * atkbd_event_work() is used to complete processing of events that
  495. * can not be processed by input_event() which is often called from
  496. * interrupt context.
  497. */
  498. static void atkbd_event_work(struct work_struct *work)
  499. {
  500. struct atkbd *atkbd = container_of(work, struct atkbd, event_work.work);
  501. mutex_lock(&atkbd->mutex);
  502. if (!atkbd->enabled) {
  503. /*
  504. * Serio ports are resumed asynchronously so while driver core
  505. * thinks that device is already fully operational in reality
  506. * it may not be ready yet. In this case we need to keep
  507. * rescheduling till reconnect completes.
  508. */
  509. schedule_delayed_work(&atkbd->event_work,
  510. msecs_to_jiffies(100));
  511. } else {
  512. if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask))
  513. atkbd_set_leds(atkbd);
  514. if (test_and_clear_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask))
  515. atkbd_set_repeat_rate(atkbd);
  516. }
  517. mutex_unlock(&atkbd->mutex);
  518. }
  519. /*
  520. * Schedule switch for execution. We need to throttle requests,
  521. * otherwise keyboard may become unresponsive.
  522. */
  523. static void atkbd_schedule_event_work(struct atkbd *atkbd, int event_bit)
  524. {
  525. unsigned long delay = msecs_to_jiffies(50);
  526. if (time_after(jiffies, atkbd->event_jiffies + delay))
  527. delay = 0;
  528. atkbd->event_jiffies = jiffies;
  529. set_bit(event_bit, &atkbd->event_mask);
  530. mb();
  531. schedule_delayed_work(&atkbd->event_work, delay);
  532. }
  533. /*
  534. * Event callback from the input module. Events that change the state of
  535. * the hardware are processed here. If action can not be performed in
  536. * interrupt context it is offloaded to atkbd_event_work.
  537. */
  538. static int atkbd_event(struct input_dev *dev,
  539. unsigned int type, unsigned int code, int value)
  540. {
  541. struct atkbd *atkbd = input_get_drvdata(dev);
  542. if (!atkbd->write)
  543. return -1;
  544. switch (type) {
  545. case EV_LED:
  546. atkbd_schedule_event_work(atkbd, ATKBD_LED_EVENT_BIT);
  547. return 0;
  548. case EV_REP:
  549. if (!atkbd->softrepeat)
  550. atkbd_schedule_event_work(atkbd, ATKBD_REP_EVENT_BIT);
  551. return 0;
  552. default:
  553. return -1;
  554. }
  555. }
  556. /*
  557. * atkbd_enable() signals that interrupt handler is allowed to
  558. * generate input events.
  559. */
  560. static inline void atkbd_enable(struct atkbd *atkbd)
  561. {
  562. serio_pause_rx(atkbd->ps2dev.serio);
  563. atkbd->enabled = true;
  564. serio_continue_rx(atkbd->ps2dev.serio);
  565. }
  566. /*
  567. * atkbd_disable() tells input handler that all incoming data except
  568. * for ACKs and command response should be dropped.
  569. */
  570. static inline void atkbd_disable(struct atkbd *atkbd)
  571. {
  572. serio_pause_rx(atkbd->ps2dev.serio);
  573. atkbd->enabled = false;
  574. serio_continue_rx(atkbd->ps2dev.serio);
  575. }
  576. static int atkbd_activate(struct atkbd *atkbd)
  577. {
  578. struct ps2dev *ps2dev = &atkbd->ps2dev;
  579. /*
  580. * Enable the keyboard to receive keystrokes.
  581. */
  582. if (ps2_command(ps2dev, NULL, ATKBD_CMD_ENABLE)) {
  583. dev_err(&ps2dev->serio->dev,
  584. "Failed to enable keyboard on %s\n",
  585. ps2dev->serio->phys);
  586. return -1;
  587. }
  588. return 0;
  589. }
  590. /*
  591. * atkbd_deactivate() resets and disables the keyboard from sending
  592. * keystrokes.
  593. */
  594. static void atkbd_deactivate(struct atkbd *atkbd)
  595. {
  596. struct ps2dev *ps2dev = &atkbd->ps2dev;
  597. if (ps2_command(ps2dev, NULL, ATKBD_CMD_RESET_DIS))
  598. dev_err(&ps2dev->serio->dev,
  599. "Failed to deactivate keyboard on %s\n",
  600. ps2dev->serio->phys);
  601. }
  602. /*
  603. * atkbd_probe() probes for an AT keyboard on a serio port.
  604. */
  605. static int atkbd_probe(struct atkbd *atkbd)
  606. {
  607. struct ps2dev *ps2dev = &atkbd->ps2dev;
  608. unsigned char param[2];
  609. /*
  610. * Some systems, where the bit-twiddling when testing the io-lines of the
  611. * controller may confuse the keyboard need a full reset of the keyboard. On
  612. * these systems the BIOS also usually doesn't do it for us.
  613. */
  614. if (atkbd_reset)
  615. if (ps2_command(ps2dev, NULL, ATKBD_CMD_RESET_BAT))
  616. dev_warn(&ps2dev->serio->dev,
  617. "keyboard reset failed on %s\n",
  618. ps2dev->serio->phys);
  619. /*
  620. * Then we check the keyboard ID. We should get 0xab83 under normal conditions.
  621. * Some keyboards report different values, but the first byte is always 0xab or
  622. * 0xac. Some old AT keyboards don't report anything. If a mouse is connected, this
  623. * should make sure we don't try to set the LEDs on it.
  624. */
  625. param[0] = param[1] = 0xa5; /* initialize with invalid values */
  626. if (ps2_command(ps2dev, param, ATKBD_CMD_GETID)) {
  627. /*
  628. * If the get ID command failed, we check if we can at least set the LEDs on
  629. * the keyboard. This should work on every keyboard out there. It also turns
  630. * the LEDs off, which we want anyway.
  631. */
  632. param[0] = 0;
  633. if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS))
  634. return -1;
  635. atkbd->id = 0xabba;
  636. return 0;
  637. }
  638. if (!ps2_is_keyboard_id(param[0]))
  639. return -1;
  640. atkbd->id = (param[0] << 8) | param[1];
  641. if (atkbd->id == 0xaca1 && atkbd->translated) {
  642. dev_err(&ps2dev->serio->dev,
  643. "NCD terminal keyboards are only supported on non-translating controllers. "
  644. "Use i8042.direct=1 to disable translation.\n");
  645. return -1;
  646. }
  647. /*
  648. * Make sure nothing is coming from the keyboard and disturbs our
  649. * internal state.
  650. */
  651. if (!atkbd_skip_deactivate)
  652. atkbd_deactivate(atkbd);
  653. return 0;
  654. }
  655. /*
  656. * atkbd_select_set checks if a keyboard has a working Set 3 support, and
  657. * sets it into that. Unfortunately there are keyboards that can be switched
  658. * to Set 3, but don't work well in that (BTC Multimedia ...)
  659. */
  660. static int atkbd_select_set(struct atkbd *atkbd, int target_set, int allow_extra)
  661. {
  662. struct ps2dev *ps2dev = &atkbd->ps2dev;
  663. unsigned char param[2];
  664. atkbd->extra = false;
  665. /*
  666. * For known special keyboards we can go ahead and set the correct set.
  667. * We check for NCD PS/2 Sun, NorthGate OmniKey 101 and
  668. * IBM RapidAccess / IBM EzButton / Chicony KBP-8993 keyboards.
  669. */
  670. if (atkbd->translated)
  671. return 2;
  672. if (atkbd->id == 0xaca1) {
  673. param[0] = 3;
  674. ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET);
  675. return 3;
  676. }
  677. if (allow_extra) {
  678. param[0] = 0x71;
  679. if (!ps2_command(ps2dev, param, ATKBD_CMD_EX_ENABLE)) {
  680. atkbd->extra = true;
  681. return 2;
  682. }
  683. }
  684. if (atkbd_terminal) {
  685. ps2_command(ps2dev, param, ATKBD_CMD_SETALL_MB);
  686. return 3;
  687. }
  688. if (target_set != 3)
  689. return 2;
  690. if (!ps2_command(ps2dev, param, ATKBD_CMD_OK_GETID)) {
  691. atkbd->id = param[0] << 8 | param[1];
  692. return 2;
  693. }
  694. param[0] = 3;
  695. if (ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET))
  696. return 2;
  697. param[0] = 0;
  698. if (ps2_command(ps2dev, param, ATKBD_CMD_GSCANSET))
  699. return 2;
  700. if (param[0] != 3) {
  701. param[0] = 2;
  702. if (ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET))
  703. return 2;
  704. }
  705. ps2_command(ps2dev, param, ATKBD_CMD_SETALL_MBR);
  706. return 3;
  707. }
  708. static int atkbd_reset_state(struct atkbd *atkbd)
  709. {
  710. struct ps2dev *ps2dev = &atkbd->ps2dev;
  711. unsigned char param[1];
  712. /*
  713. * Set the LEDs to a predefined state (all off).
  714. */
  715. param[0] = 0;
  716. if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS))
  717. return -1;
  718. /*
  719. * Set autorepeat to fastest possible.
  720. */
  721. param[0] = 0;
  722. if (ps2_command(ps2dev, param, ATKBD_CMD_SETREP))
  723. return -1;
  724. return 0;
  725. }
  726. /*
  727. * atkbd_cleanup() restores the keyboard state so that BIOS is happy after a
  728. * reboot.
  729. */
  730. static void atkbd_cleanup(struct serio *serio)
  731. {
  732. struct atkbd *atkbd = serio_get_drvdata(serio);
  733. atkbd_disable(atkbd);
  734. ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_DEF);
  735. }
  736. /*
  737. * atkbd_disconnect() closes and frees.
  738. */
  739. static void atkbd_disconnect(struct serio *serio)
  740. {
  741. struct atkbd *atkbd = serio_get_drvdata(serio);
  742. sysfs_remove_group(&serio->dev.kobj, &atkbd_attribute_group);
  743. atkbd_disable(atkbd);
  744. input_unregister_device(atkbd->dev);
  745. /*
  746. * Make sure we don't have a command in flight.
  747. * Note that since atkbd->enabled is false event work will keep
  748. * rescheduling itself until it gets canceled and will not try
  749. * accessing freed input device or serio port.
  750. */
  751. cancel_delayed_work_sync(&atkbd->event_work);
  752. serio_close(serio);
  753. serio_set_drvdata(serio, NULL);
  754. kfree(atkbd);
  755. }
  756. /*
  757. * generate release events for the keycodes given in data
  758. */
  759. static void atkbd_apply_forced_release_keylist(struct atkbd* atkbd,
  760. const void *data)
  761. {
  762. const unsigned int *keys = data;
  763. unsigned int i;
  764. if (atkbd->set == 2)
  765. for (i = 0; keys[i] != -1U; i++)
  766. __set_bit(keys[i], atkbd->force_release_mask);
  767. }
  768. /*
  769. * Most special keys (Fn+F?) on Dell laptops do not generate release
  770. * events so we have to do it ourselves.
  771. */
  772. static unsigned int atkbd_dell_laptop_forced_release_keys[] = {
  773. 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8f, 0x93, -1U
  774. };
  775. /*
  776. * Perform fixup for HP system that doesn't generate release
  777. * for its video switch
  778. */
  779. static unsigned int atkbd_hp_forced_release_keys[] = {
  780. 0x94, -1U
  781. };
  782. /*
  783. * Samsung NC10,NC20 with Fn+F? key release not working
  784. */
  785. static unsigned int atkbd_samsung_forced_release_keys[] = {
  786. 0x82, 0x83, 0x84, 0x86, 0x88, 0x89, 0xb3, 0xf7, 0xf9, -1U
  787. };
  788. /*
  789. * Amilo Pi 3525 key release for Fn+Volume keys not working
  790. */
  791. static unsigned int atkbd_amilo_pi3525_forced_release_keys[] = {
  792. 0x20, 0xa0, 0x2e, 0xae, 0x30, 0xb0, -1U
  793. };
  794. /*
  795. * Amilo Xi 3650 key release for light touch bar not working
  796. */
  797. static unsigned int atkbd_amilo_xi3650_forced_release_keys[] = {
  798. 0x67, 0xed, 0x90, 0xa2, 0x99, 0xa4, 0xae, 0xb0, -1U
  799. };
  800. /*
  801. * Soltech TA12 system with broken key release on volume keys and mute key
  802. */
  803. static unsigned int atkdb_soltech_ta12_forced_release_keys[] = {
  804. 0xa0, 0xae, 0xb0, -1U
  805. };
  806. /*
  807. * Many notebooks don't send key release event for volume up/down
  808. * keys, with key list below common among them
  809. */
  810. static unsigned int atkbd_volume_forced_release_keys[] = {
  811. 0xae, 0xb0, -1U
  812. };
  813. /*
  814. * OQO 01+ multimedia keys (64--66) generate e0 6x upon release whereas
  815. * they should be generating e4-e6 (0x80 | code).
  816. */
  817. static unsigned int atkbd_oqo_01plus_scancode_fixup(struct atkbd *atkbd,
  818. unsigned int code)
  819. {
  820. if (atkbd->translated && atkbd->emul == 1 &&
  821. (code == 0x64 || code == 0x65 || code == 0x66)) {
  822. atkbd->emul = 0;
  823. code |= 0x80;
  824. }
  825. return code;
  826. }
  827. /*
  828. * atkbd_set_keycode_table() initializes keyboard's keycode table
  829. * according to the selected scancode set
  830. */
  831. static void atkbd_set_keycode_table(struct atkbd *atkbd)
  832. {
  833. unsigned int scancode;
  834. int i, j;
  835. memset(atkbd->keycode, 0, sizeof(atkbd->keycode));
  836. bitmap_zero(atkbd->force_release_mask, ATKBD_KEYMAP_SIZE);
  837. if (atkbd->translated) {
  838. for (i = 0; i < 128; i++) {
  839. scancode = atkbd_unxlate_table[i];
  840. atkbd->keycode[i] = atkbd_set2_keycode[scancode];
  841. atkbd->keycode[i | 0x80] = atkbd_set2_keycode[scancode | 0x80];
  842. if (atkbd->scroll)
  843. for (j = 0; j < ARRAY_SIZE(atkbd_scroll_keys); j++)
  844. if ((scancode | 0x80) == atkbd_scroll_keys[j].set2)
  845. atkbd->keycode[i | 0x80] = atkbd_scroll_keys[j].keycode;
  846. }
  847. } else if (atkbd->set == 3) {
  848. memcpy(atkbd->keycode, atkbd_set3_keycode, sizeof(atkbd->keycode));
  849. } else {
  850. memcpy(atkbd->keycode, atkbd_set2_keycode, sizeof(atkbd->keycode));
  851. if (atkbd->scroll)
  852. for (i = 0; i < ARRAY_SIZE(atkbd_scroll_keys); i++) {
  853. scancode = atkbd_scroll_keys[i].set2;
  854. atkbd->keycode[scancode] = atkbd_scroll_keys[i].keycode;
  855. }
  856. }
  857. /*
  858. * HANGEUL and HANJA keys do not send release events so we need to
  859. * generate such events ourselves
  860. */
  861. scancode = atkbd_compat_scancode(atkbd, ATKBD_RET_HANGEUL);
  862. atkbd->keycode[scancode] = KEY_HANGEUL;
  863. __set_bit(scancode, atkbd->force_release_mask);
  864. scancode = atkbd_compat_scancode(atkbd, ATKBD_RET_HANJA);
  865. atkbd->keycode[scancode] = KEY_HANJA;
  866. __set_bit(scancode, atkbd->force_release_mask);
  867. /*
  868. * Perform additional fixups
  869. */
  870. if (atkbd_platform_fixup)
  871. atkbd_platform_fixup(atkbd, atkbd_platform_fixup_data);
  872. }
  873. /*
  874. * atkbd_set_device_attrs() sets up keyboard's input device structure
  875. */
  876. static void atkbd_set_device_attrs(struct atkbd *atkbd)
  877. {
  878. struct input_dev *input_dev = atkbd->dev;
  879. int i;
  880. if (atkbd->extra)
  881. snprintf(atkbd->name, sizeof(atkbd->name),
  882. "AT Set 2 Extra keyboard");
  883. else
  884. snprintf(atkbd->name, sizeof(atkbd->name),
  885. "AT %s Set %d keyboard",
  886. atkbd->translated ? "Translated" : "Raw", atkbd->set);
  887. snprintf(atkbd->phys, sizeof(atkbd->phys),
  888. "%s/input0", atkbd->ps2dev.serio->phys);
  889. input_dev->name = atkbd->name;
  890. input_dev->phys = atkbd->phys;
  891. input_dev->id.bustype = BUS_I8042;
  892. input_dev->id.vendor = 0x0001;
  893. input_dev->id.product = atkbd->translated ? 1 : atkbd->set;
  894. input_dev->id.version = atkbd->id;
  895. input_dev->event = atkbd_event;
  896. input_dev->dev.parent = &atkbd->ps2dev.serio->dev;
  897. input_set_drvdata(input_dev, atkbd);
  898. input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP) |
  899. BIT_MASK(EV_MSC);
  900. if (atkbd->write) {
  901. input_dev->evbit[0] |= BIT_MASK(EV_LED);
  902. input_dev->ledbit[0] = BIT_MASK(LED_NUML) |
  903. BIT_MASK(LED_CAPSL) | BIT_MASK(LED_SCROLLL);
  904. }
  905. if (atkbd->extra)
  906. input_dev->ledbit[0] |= BIT_MASK(LED_COMPOSE) |
  907. BIT_MASK(LED_SUSPEND) | BIT_MASK(LED_SLEEP) |
  908. BIT_MASK(LED_MUTE) | BIT_MASK(LED_MISC);
  909. if (!atkbd->softrepeat) {
  910. input_dev->rep[REP_DELAY] = 250;
  911. input_dev->rep[REP_PERIOD] = 33;
  912. }
  913. input_dev->mscbit[0] = atkbd->softraw ? BIT_MASK(MSC_SCAN) :
  914. BIT_MASK(MSC_RAW) | BIT_MASK(MSC_SCAN);
  915. if (atkbd->scroll) {
  916. input_dev->evbit[0] |= BIT_MASK(EV_REL);
  917. input_dev->relbit[0] = BIT_MASK(REL_WHEEL) |
  918. BIT_MASK(REL_HWHEEL);
  919. __set_bit(BTN_MIDDLE, input_dev->keybit);
  920. }
  921. input_dev->keycode = atkbd->keycode;
  922. input_dev->keycodesize = sizeof(unsigned short);
  923. input_dev->keycodemax = ARRAY_SIZE(atkbd_set2_keycode);
  924. for (i = 0; i < ATKBD_KEYMAP_SIZE; i++) {
  925. if (atkbd->keycode[i] != KEY_RESERVED &&
  926. atkbd->keycode[i] != ATKBD_KEY_NULL &&
  927. atkbd->keycode[i] < ATKBD_SPECIAL) {
  928. __set_bit(atkbd->keycode[i], input_dev->keybit);
  929. }
  930. }
  931. }
  932. /*
  933. * atkbd_connect() is called when the serio module finds an interface
  934. * that isn't handled yet by an appropriate device driver. We check if
  935. * there is an AT keyboard out there and if yes, we register ourselves
  936. * to the input module.
  937. */
  938. static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
  939. {
  940. struct atkbd *atkbd;
  941. struct input_dev *dev;
  942. int err = -ENOMEM;
  943. atkbd = kzalloc(sizeof(struct atkbd), GFP_KERNEL);
  944. dev = input_allocate_device();
  945. if (!atkbd || !dev)
  946. goto fail1;
  947. atkbd->dev = dev;
  948. ps2_init(&atkbd->ps2dev, serio);
  949. INIT_DELAYED_WORK(&atkbd->event_work, atkbd_event_work);
  950. mutex_init(&atkbd->mutex);
  951. switch (serio->id.type) {
  952. case SERIO_8042_XL:
  953. atkbd->translated = true;
  954. /* Fall through */
  955. case SERIO_8042:
  956. if (serio->write)
  957. atkbd->write = true;
  958. break;
  959. }
  960. atkbd->softraw = atkbd_softraw;
  961. atkbd->softrepeat = atkbd_softrepeat;
  962. atkbd->scroll = atkbd_scroll;
  963. if (atkbd->softrepeat)
  964. atkbd->softraw = true;
  965. serio_set_drvdata(serio, atkbd);
  966. err = serio_open(serio, drv);
  967. if (err)
  968. goto fail2;
  969. if (atkbd->write) {
  970. if (atkbd_probe(atkbd)) {
  971. err = -ENODEV;
  972. goto fail3;
  973. }
  974. atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra);
  975. atkbd_reset_state(atkbd);
  976. } else {
  977. atkbd->set = 2;
  978. atkbd->id = 0xab00;
  979. }
  980. atkbd_set_keycode_table(atkbd);
  981. atkbd_set_device_attrs(atkbd);
  982. err = sysfs_create_group(&serio->dev.kobj, &atkbd_attribute_group);
  983. if (err)
  984. goto fail3;
  985. atkbd_enable(atkbd);
  986. if (serio->write)
  987. atkbd_activate(atkbd);
  988. err = input_register_device(atkbd->dev);
  989. if (err)
  990. goto fail4;
  991. return 0;
  992. fail4: sysfs_remove_group(&serio->dev.kobj, &atkbd_attribute_group);
  993. fail3: serio_close(serio);
  994. fail2: serio_set_drvdata(serio, NULL);
  995. fail1: input_free_device(dev);
  996. kfree(atkbd);
  997. return err;
  998. }
  999. /*
  1000. * atkbd_reconnect() tries to restore keyboard into a sane state and is
  1001. * most likely called on resume.
  1002. */
  1003. static int atkbd_reconnect(struct serio *serio)
  1004. {
  1005. struct atkbd *atkbd = serio_get_drvdata(serio);
  1006. struct serio_driver *drv = serio->drv;
  1007. int retval = -1;
  1008. if (!atkbd || !drv) {
  1009. dev_dbg(&serio->dev,
  1010. "reconnect request, but serio is disconnected, ignoring...\n");
  1011. return -1;
  1012. }
  1013. mutex_lock(&atkbd->mutex);
  1014. atkbd_disable(atkbd);
  1015. if (atkbd->write) {
  1016. if (atkbd_probe(atkbd))
  1017. goto out;
  1018. if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra))
  1019. goto out;
  1020. /*
  1021. * Restore LED state and repeat rate. While input core
  1022. * will do this for us at resume time reconnect may happen
  1023. * because user requested it via sysfs or simply because
  1024. * keyboard was unplugged and plugged in again so we need
  1025. * to do it ourselves here.
  1026. */
  1027. atkbd_set_leds(atkbd);
  1028. if (!atkbd->softrepeat)
  1029. atkbd_set_repeat_rate(atkbd);
  1030. }
  1031. /*
  1032. * Reset our state machine in case reconnect happened in the middle
  1033. * of multi-byte scancode.
  1034. */
  1035. atkbd->xl_bit = 0;
  1036. atkbd->emul = 0;
  1037. atkbd_enable(atkbd);
  1038. if (atkbd->write)
  1039. atkbd_activate(atkbd);
  1040. retval = 0;
  1041. out:
  1042. mutex_unlock(&atkbd->mutex);
  1043. return retval;
  1044. }
  1045. static struct serio_device_id atkbd_serio_ids[] = {
  1046. {
  1047. .type = SERIO_8042,
  1048. .proto = SERIO_ANY,
  1049. .id = SERIO_ANY,
  1050. .extra = SERIO_ANY,
  1051. },
  1052. {
  1053. .type = SERIO_8042_XL,
  1054. .proto = SERIO_ANY,
  1055. .id = SERIO_ANY,
  1056. .extra = SERIO_ANY,
  1057. },
  1058. {
  1059. .type = SERIO_RS232,
  1060. .proto = SERIO_PS2SER,
  1061. .id = SERIO_ANY,
  1062. .extra = SERIO_ANY,
  1063. },
  1064. { 0 }
  1065. };
  1066. MODULE_DEVICE_TABLE(serio, atkbd_serio_ids);
  1067. static struct serio_driver atkbd_drv = {
  1068. .driver = {
  1069. .name = "atkbd",
  1070. },
  1071. .description = DRIVER_DESC,
  1072. .id_table = atkbd_serio_ids,
  1073. .interrupt = atkbd_interrupt,
  1074. .connect = atkbd_connect,
  1075. .reconnect = atkbd_reconnect,
  1076. .disconnect = atkbd_disconnect,
  1077. .cleanup = atkbd_cleanup,
  1078. };
  1079. static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf,
  1080. ssize_t (*handler)(struct atkbd *, char *))
  1081. {
  1082. struct serio *serio = to_serio_port(dev);
  1083. struct atkbd *atkbd = serio_get_drvdata(serio);
  1084. return handler(atkbd, buf);
  1085. }
  1086. static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t count,
  1087. ssize_t (*handler)(struct atkbd *, const char *, size_t))
  1088. {
  1089. struct serio *serio = to_serio_port(dev);
  1090. struct atkbd *atkbd = serio_get_drvdata(serio);
  1091. int retval;
  1092. retval = mutex_lock_interruptible(&atkbd->mutex);
  1093. if (retval)
  1094. return retval;
  1095. atkbd_disable(atkbd);
  1096. retval = handler(atkbd, buf, count);
  1097. atkbd_enable(atkbd);
  1098. mutex_unlock(&atkbd->mutex);
  1099. return retval;
  1100. }
  1101. static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf)
  1102. {
  1103. return sprintf(buf, "%d\n", atkbd->extra ? 1 : 0);
  1104. }
  1105. static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count)
  1106. {
  1107. struct input_dev *old_dev, *new_dev;
  1108. unsigned int value;
  1109. int err;
  1110. bool old_extra;
  1111. unsigned char old_set;
  1112. if (!atkbd->write)
  1113. return -EIO;
  1114. err = kstrtouint(buf, 10, &value);
  1115. if (err)
  1116. return err;
  1117. if (value > 1)
  1118. return -EINVAL;
  1119. if (atkbd->extra != value) {
  1120. /*
  1121. * Since device's properties will change we need to
  1122. * unregister old device. But allocate and register
  1123. * new one first to make sure we have it.
  1124. */
  1125. old_dev = atkbd->dev;
  1126. old_extra = atkbd->extra;
  1127. old_set = atkbd->set;
  1128. new_dev = input_allocate_device();
  1129. if (!new_dev)
  1130. return -ENOMEM;
  1131. atkbd->dev = new_dev;
  1132. atkbd->set = atkbd_select_set(atkbd, atkbd->set, value);
  1133. atkbd_reset_state(atkbd);
  1134. atkbd_activate(atkbd);
  1135. atkbd_set_keycode_table(atkbd);
  1136. atkbd_set_device_attrs(atkbd);
  1137. err = input_register_device(atkbd->dev);
  1138. if (err) {
  1139. input_free_device(new_dev);
  1140. atkbd->dev = old_dev;
  1141. atkbd->set = atkbd_select_set(atkbd, old_set, old_extra);
  1142. atkbd_set_keycode_table(atkbd);
  1143. atkbd_set_device_attrs(atkbd);
  1144. return err;
  1145. }
  1146. input_unregister_device(old_dev);
  1147. }
  1148. return count;
  1149. }
  1150. static ssize_t atkbd_show_force_release(struct atkbd *atkbd, char *buf)
  1151. {
  1152. size_t len = scnprintf(buf, PAGE_SIZE - 1, "%*pbl",
  1153. ATKBD_KEYMAP_SIZE, atkbd->force_release_mask);
  1154. buf[len++] = '\n';
  1155. buf[len] = '\0';
  1156. return len;
  1157. }
  1158. static ssize_t atkbd_set_force_release(struct atkbd *atkbd,
  1159. const char *buf, size_t count)
  1160. {
  1161. /* 64 bytes on stack should be acceptable */
  1162. DECLARE_BITMAP(new_mask, ATKBD_KEYMAP_SIZE);
  1163. int err;
  1164. err = bitmap_parselist(buf, new_mask, ATKBD_KEYMAP_SIZE);
  1165. if (err)
  1166. return err;
  1167. memcpy(atkbd->force_release_mask, new_mask, sizeof(atkbd->force_release_mask));
  1168. return count;
  1169. }
  1170. static ssize_t atkbd_show_scroll(struct atkbd *atkbd, char *buf)
  1171. {
  1172. return sprintf(buf, "%d\n", atkbd->scroll ? 1 : 0);
  1173. }
  1174. static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count)
  1175. {
  1176. struct input_dev *old_dev, *new_dev;
  1177. unsigned int value;
  1178. int err;
  1179. bool old_scroll;
  1180. err = kstrtouint(buf, 10, &value);
  1181. if (err)
  1182. return err;
  1183. if (value > 1)
  1184. return -EINVAL;
  1185. if (atkbd->scroll != value) {
  1186. old_dev = atkbd->dev;
  1187. old_scroll = atkbd->scroll;
  1188. new_dev = input_allocate_device();
  1189. if (!new_dev)
  1190. return -ENOMEM;
  1191. atkbd->dev = new_dev;
  1192. atkbd->scroll = value;
  1193. atkbd_set_keycode_table(atkbd);
  1194. atkbd_set_device_attrs(atkbd);
  1195. err = input_register_device(atkbd->dev);
  1196. if (err) {
  1197. input_free_device(new_dev);
  1198. atkbd->scroll = old_scroll;
  1199. atkbd->dev = old_dev;
  1200. atkbd_set_keycode_table(atkbd);
  1201. atkbd_set_device_attrs(atkbd);
  1202. return err;
  1203. }
  1204. input_unregister_device(old_dev);
  1205. }
  1206. return count;
  1207. }
  1208. static ssize_t atkbd_show_set(struct atkbd *atkbd, char *buf)
  1209. {
  1210. return sprintf(buf, "%d\n", atkbd->set);
  1211. }
  1212. static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
  1213. {
  1214. struct input_dev *old_dev, *new_dev;
  1215. unsigned int value;
  1216. int err;
  1217. unsigned char old_set;
  1218. bool old_extra;
  1219. if (!atkbd->write)
  1220. return -EIO;
  1221. err = kstrtouint(buf, 10, &value);
  1222. if (err)
  1223. return err;
  1224. if (value != 2 && value != 3)
  1225. return -EINVAL;
  1226. if (atkbd->set != value) {
  1227. old_dev = atkbd->dev;
  1228. old_extra = atkbd->extra;
  1229. old_set = atkbd->set;
  1230. new_dev = input_allocate_device();
  1231. if (!new_dev)
  1232. return -ENOMEM;
  1233. atkbd->dev = new_dev;
  1234. atkbd->set = atkbd_select_set(atkbd, value, atkbd->extra);
  1235. atkbd_reset_state(atkbd);
  1236. atkbd_activate(atkbd);
  1237. atkbd_set_keycode_table(atkbd);
  1238. atkbd_set_device_attrs(atkbd);
  1239. err = input_register_device(atkbd->dev);
  1240. if (err) {
  1241. input_free_device(new_dev);
  1242. atkbd->dev = old_dev;
  1243. atkbd->set = atkbd_select_set(atkbd, old_set, old_extra);
  1244. atkbd_set_keycode_table(atkbd);
  1245. atkbd_set_device_attrs(atkbd);
  1246. return err;
  1247. }
  1248. input_unregister_device(old_dev);
  1249. }
  1250. return count;
  1251. }
  1252. static ssize_t atkbd_show_softrepeat(struct atkbd *atkbd, char *buf)
  1253. {
  1254. return sprintf(buf, "%d\n", atkbd->softrepeat ? 1 : 0);
  1255. }
  1256. static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count)
  1257. {
  1258. struct input_dev *old_dev, *new_dev;
  1259. unsigned int value;
  1260. int err;
  1261. bool old_softrepeat, old_softraw;
  1262. if (!atkbd->write)
  1263. return -EIO;
  1264. err = kstrtouint(buf, 10, &value);
  1265. if (err)
  1266. return err;
  1267. if (value > 1)
  1268. return -EINVAL;
  1269. if (atkbd->softrepeat != value) {
  1270. old_dev = atkbd->dev;
  1271. old_softrepeat = atkbd->softrepeat;
  1272. old_softraw = atkbd->softraw;
  1273. new_dev = input_allocate_device();
  1274. if (!new_dev)
  1275. return -ENOMEM;
  1276. atkbd->dev = new_dev;
  1277. atkbd->softrepeat = value;
  1278. if (atkbd->softrepeat)
  1279. atkbd->softraw = true;
  1280. atkbd_set_device_attrs(atkbd);
  1281. err = input_register_device(atkbd->dev);
  1282. if (err) {
  1283. input_free_device(new_dev);
  1284. atkbd->dev = old_dev;
  1285. atkbd->softrepeat = old_softrepeat;
  1286. atkbd->softraw = old_softraw;
  1287. atkbd_set_device_attrs(atkbd);
  1288. return err;
  1289. }
  1290. input_unregister_device(old_dev);
  1291. }
  1292. return count;
  1293. }
  1294. static ssize_t atkbd_show_softraw(struct atkbd *atkbd, char *buf)
  1295. {
  1296. return sprintf(buf, "%d\n", atkbd->softraw ? 1 : 0);
  1297. }
  1298. static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count)
  1299. {
  1300. struct input_dev *old_dev, *new_dev;
  1301. unsigned int value;
  1302. int err;
  1303. bool old_softraw;
  1304. err = kstrtouint(buf, 10, &value);
  1305. if (err)
  1306. return err;
  1307. if (value > 1)
  1308. return -EINVAL;
  1309. if (atkbd->softraw != value) {
  1310. old_dev = atkbd->dev;
  1311. old_softraw = atkbd->softraw;
  1312. new_dev = input_allocate_device();
  1313. if (!new_dev)
  1314. return -ENOMEM;
  1315. atkbd->dev = new_dev;
  1316. atkbd->softraw = value;
  1317. atkbd_set_device_attrs(atkbd);
  1318. err = input_register_device(atkbd->dev);
  1319. if (err) {
  1320. input_free_device(new_dev);
  1321. atkbd->dev = old_dev;
  1322. atkbd->softraw = old_softraw;
  1323. atkbd_set_device_attrs(atkbd);
  1324. return err;
  1325. }
  1326. input_unregister_device(old_dev);
  1327. }
  1328. return count;
  1329. }
  1330. static ssize_t atkbd_show_err_count(struct atkbd *atkbd, char *buf)
  1331. {
  1332. return sprintf(buf, "%lu\n", atkbd->err_count);
  1333. }
  1334. static int __init atkbd_setup_forced_release(const struct dmi_system_id *id)
  1335. {
  1336. atkbd_platform_fixup = atkbd_apply_forced_release_keylist;
  1337. atkbd_platform_fixup_data = id->driver_data;
  1338. return 1;
  1339. }
  1340. static int __init atkbd_setup_scancode_fixup(const struct dmi_system_id *id)
  1341. {
  1342. atkbd_platform_scancode_fixup = id->driver_data;
  1343. return 1;
  1344. }
  1345. static int __init atkbd_deactivate_fixup(const struct dmi_system_id *id)
  1346. {
  1347. atkbd_skip_deactivate = true;
  1348. return 1;
  1349. }
  1350. /*
  1351. * NOTE: do not add any more "force release" quirks to this table. The
  1352. * task of adjusting list of keys that should be "released" automatically
  1353. * by the driver is now delegated to userspace tools, such as udev, so
  1354. * submit such quirks there.
  1355. */
  1356. static const struct dmi_system_id atkbd_dmi_quirk_table[] __initconst = {
  1357. {
  1358. .matches = {
  1359. DMI_MATCH(DMI_SYS_VENDOR, "Dell Inc."),
  1360. DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
  1361. },
  1362. .callback = atkbd_setup_forced_release,
  1363. .driver_data = atkbd_dell_laptop_forced_release_keys,
  1364. },
  1365. {
  1366. .matches = {
  1367. DMI_MATCH(DMI_SYS_VENDOR, "Dell Computer Corporation"),
  1368. DMI_MATCH(DMI_CHASSIS_TYPE, "8"), /* Portable */
  1369. },
  1370. .callback = atkbd_setup_forced_release,
  1371. .driver_data = atkbd_dell_laptop_forced_release_keys,
  1372. },
  1373. {
  1374. .matches = {
  1375. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1376. DMI_MATCH(DMI_PRODUCT_NAME, "HP 2133"),
  1377. },
  1378. .callback = atkbd_setup_forced_release,
  1379. .driver_data = atkbd_hp_forced_release_keys,
  1380. },
  1381. {
  1382. .matches = {
  1383. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1384. DMI_MATCH(DMI_PRODUCT_NAME, "Pavilion ZV6100"),
  1385. },
  1386. .callback = atkbd_setup_forced_release,
  1387. .driver_data = atkbd_volume_forced_release_keys,
  1388. },
  1389. {
  1390. .matches = {
  1391. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1392. DMI_MATCH(DMI_PRODUCT_NAME, "Presario R4000"),
  1393. },
  1394. .callback = atkbd_setup_forced_release,
  1395. .driver_data = atkbd_volume_forced_release_keys,
  1396. },
  1397. {
  1398. .matches = {
  1399. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1400. DMI_MATCH(DMI_PRODUCT_NAME, "Presario R4100"),
  1401. },
  1402. .callback = atkbd_setup_forced_release,
  1403. .driver_data = atkbd_volume_forced_release_keys,
  1404. },
  1405. {
  1406. .matches = {
  1407. DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"),
  1408. DMI_MATCH(DMI_PRODUCT_NAME, "Presario R4200"),
  1409. },
  1410. .callback = atkbd_setup_forced_release,
  1411. .driver_data = atkbd_volume_forced_release_keys,
  1412. },
  1413. {
  1414. /* Inventec Symphony */
  1415. .matches = {
  1416. DMI_MATCH(DMI_SYS_VENDOR, "INVENTEC"),
  1417. DMI_MATCH(DMI_PRODUCT_NAME, "SYMPHONY 6.0/7.0"),
  1418. },
  1419. .callback = atkbd_setup_forced_release,
  1420. .driver_data = atkbd_volume_forced_release_keys,
  1421. },
  1422. {
  1423. /* Samsung NC10 */
  1424. .matches = {
  1425. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  1426. DMI_MATCH(DMI_PRODUCT_NAME, "NC10"),
  1427. },
  1428. .callback = atkbd_setup_forced_release,
  1429. .driver_data = atkbd_samsung_forced_release_keys,
  1430. },
  1431. {
  1432. /* Samsung NC20 */
  1433. .matches = {
  1434. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  1435. DMI_MATCH(DMI_PRODUCT_NAME, "NC20"),
  1436. },
  1437. .callback = atkbd_setup_forced_release,
  1438. .driver_data = atkbd_samsung_forced_release_keys,
  1439. },
  1440. {
  1441. /* Samsung SQ45S70S */
  1442. .matches = {
  1443. DMI_MATCH(DMI_SYS_VENDOR, "SAMSUNG ELECTRONICS CO., LTD."),
  1444. DMI_MATCH(DMI_PRODUCT_NAME, "SQ45S70S"),
  1445. },
  1446. .callback = atkbd_setup_forced_release,
  1447. .driver_data = atkbd_samsung_forced_release_keys,
  1448. },
  1449. {
  1450. /* Fujitsu Amilo PA 1510 */
  1451. .matches = {
  1452. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  1453. DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pa 1510"),
  1454. },
  1455. .callback = atkbd_setup_forced_release,
  1456. .driver_data = atkbd_volume_forced_release_keys,
  1457. },
  1458. {
  1459. /* Fujitsu Amilo Pi 3525 */
  1460. .matches = {
  1461. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  1462. DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Pi 3525"),
  1463. },
  1464. .callback = atkbd_setup_forced_release,
  1465. .driver_data = atkbd_amilo_pi3525_forced_release_keys,
  1466. },
  1467. {
  1468. /* Fujitsu Amilo Xi 3650 */
  1469. .matches = {
  1470. DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
  1471. DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Xi 3650"),
  1472. },
  1473. .callback = atkbd_setup_forced_release,
  1474. .driver_data = atkbd_amilo_xi3650_forced_release_keys,
  1475. },
  1476. {
  1477. .matches = {
  1478. DMI_MATCH(DMI_SYS_VENDOR, "Soltech Corporation"),
  1479. DMI_MATCH(DMI_PRODUCT_NAME, "TA12"),
  1480. },
  1481. .callback = atkbd_setup_forced_release,
  1482. .driver_data = atkdb_soltech_ta12_forced_release_keys,
  1483. },
  1484. {
  1485. /* OQO Model 01+ */
  1486. .matches = {
  1487. DMI_MATCH(DMI_SYS_VENDOR, "OQO"),
  1488. DMI_MATCH(DMI_PRODUCT_NAME, "ZEPTO"),
  1489. },
  1490. .callback = atkbd_setup_scancode_fixup,
  1491. .driver_data = atkbd_oqo_01plus_scancode_fixup,
  1492. },
  1493. {
  1494. .matches = {
  1495. DMI_MATCH(DMI_SYS_VENDOR, "LG Electronics"),
  1496. },
  1497. .callback = atkbd_deactivate_fixup,
  1498. },
  1499. { }
  1500. };
  1501. static int __init atkbd_init(void)
  1502. {
  1503. dmi_check_system(atkbd_dmi_quirk_table);
  1504. return serio_register_driver(&atkbd_drv);
  1505. }
  1506. static void __exit atkbd_exit(void)
  1507. {
  1508. serio_unregister_driver(&atkbd_drv);
  1509. }
  1510. module_init(atkbd_init);
  1511. module_exit(atkbd_exit);