atkbd.c 47 KB

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