atkbd.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  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/moduleparam.h>
  20. #include <linux/slab.h>
  21. #include <linux/interrupt.h>
  22. #include <linux/init.h>
  23. #include <linux/input.h>
  24. #include <linux/serio.h>
  25. #include <linux/workqueue.h>
  26. #include <linux/libps2.h>
  27. #include <linux/mutex.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 int atkbd_reset;
  37. #else
  38. static int atkbd_reset = 1;
  39. #endif
  40. module_param_named(reset, atkbd_reset, bool, 0);
  41. MODULE_PARM_DESC(reset, "Reset keyboard during initialization");
  42. static int atkbd_softrepeat;
  43. module_param_named(softrepeat, atkbd_softrepeat, bool, 0);
  44. MODULE_PARM_DESC(softrepeat, "Use software keyboard repeat");
  45. static int atkbd_softraw = 1;
  46. module_param_named(softraw, atkbd_softraw, bool, 0);
  47. MODULE_PARM_DESC(softraw, "Use software generated rawmode");
  48. static int atkbd_scroll = 0;
  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 int 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. __obsolete_setup("atkbd_set=");
  55. __obsolete_setup("atkbd_reset");
  56. __obsolete_setup("atkbd_softrepeat=");
  57. /*
  58. * Scancode to keycode tables. These are just the default setting, and
  59. * are loadable via an userland utility.
  60. */
  61. static unsigned char atkbd_set2_keycode[512] = {
  62. #ifdef CONFIG_KEYBOARD_ATKBD_HP_KEYCODES
  63. /* XXX: need a more general approach */
  64. #include "hpps2atkbd.h" /* include the keyboard scancodes */
  65. #else
  66. 0, 67, 65, 63, 61, 59, 60, 88, 0, 68, 66, 64, 62, 15, 41,117,
  67. 0, 56, 42, 93, 29, 16, 2, 0, 0, 0, 44, 31, 30, 17, 3, 0,
  68. 0, 46, 45, 32, 18, 5, 4, 95, 0, 57, 47, 33, 20, 19, 6,183,
  69. 0, 49, 48, 35, 34, 21, 7,184, 0, 0, 50, 36, 22, 8, 9,185,
  70. 0, 51, 37, 23, 24, 11, 10, 0, 0, 52, 53, 38, 39, 25, 12, 0,
  71. 0, 89, 40, 0, 26, 13, 0, 0, 58, 54, 28, 27, 0, 43, 0, 85,
  72. 0, 86, 91, 90, 92, 0, 14, 94, 0, 79,124, 75, 71,121, 0, 0,
  73. 82, 83, 80, 76, 77, 72, 1, 69, 87, 78, 81, 74, 55, 73, 70, 99,
  74. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  75. 217,100,255, 0, 97,165, 0, 0,156, 0, 0, 0, 0, 0, 0,125,
  76. 173,114, 0,113, 0, 0, 0,126,128, 0, 0,140, 0, 0, 0,127,
  77. 159, 0,115, 0,164, 0, 0,116,158, 0,150,166, 0, 0, 0,142,
  78. 157, 0, 0, 0, 0, 0, 0, 0,155, 0, 98, 0, 0,163, 0, 0,
  79. 226, 0, 0, 0, 0, 0, 0, 0, 0,255, 96, 0, 0, 0,143, 0,
  80. 0, 0, 0, 0, 0, 0, 0, 0, 0,107, 0,105,102, 0, 0,112,
  81. 110,111,108,112,106,103, 0,119, 0,118,109, 0, 99,104,119, 0,
  82. 0, 0, 0, 65, 99,
  83. #endif
  84. };
  85. static unsigned char atkbd_set3_keycode[512] = {
  86. 0, 0, 0, 0, 0, 0, 0, 59, 1,138,128,129,130, 15, 41, 60,
  87. 131, 29, 42, 86, 58, 16, 2, 61,133, 56, 44, 31, 30, 17, 3, 62,
  88. 134, 46, 45, 32, 18, 5, 4, 63,135, 57, 47, 33, 20, 19, 6, 64,
  89. 136, 49, 48, 35, 34, 21, 7, 65,137,100, 50, 36, 22, 8, 9, 66,
  90. 125, 51, 37, 23, 24, 11, 10, 67,126, 52, 53, 38, 39, 25, 12, 68,
  91. 113,114, 40, 43, 26, 13, 87, 99, 97, 54, 28, 27, 43, 43, 88, 70,
  92. 108,105,119,103,111,107, 14,110, 0, 79,106, 75, 71,109,102,104,
  93. 82, 83, 80, 76, 77, 72, 69, 98, 0, 96, 81, 0, 78, 73, 55,183,
  94. 184,185,186,187, 74, 94, 92, 93, 0, 0, 0,125,126,127,112, 0,
  95. 0,139,150,163,165,115,152,150,166,140,160,154,113,114,167,168,
  96. 148,149,147,140
  97. };
  98. static unsigned char atkbd_unxlate_table[128] = {
  99. 0,118, 22, 30, 38, 37, 46, 54, 61, 62, 70, 69, 78, 85,102, 13,
  100. 21, 29, 36, 45, 44, 53, 60, 67, 68, 77, 84, 91, 90, 20, 28, 27,
  101. 35, 43, 52, 51, 59, 66, 75, 76, 82, 14, 18, 93, 26, 34, 33, 42,
  102. 50, 49, 58, 65, 73, 74, 89,124, 17, 41, 88, 5, 6, 4, 12, 3,
  103. 11, 2, 10, 1, 9,119,126,108,117,125,123,107,115,116,121,105,
  104. 114,122,112,113,127, 96, 97,120, 7, 15, 23, 31, 39, 47, 55, 63,
  105. 71, 79, 86, 94, 8, 16, 24, 32, 40, 48, 56, 64, 72, 80, 87,111,
  106. 19, 25, 57, 81, 83, 92, 95, 98, 99,100,101,103,104,106,109,110
  107. };
  108. #define ATKBD_CMD_SETLEDS 0x10ed
  109. #define ATKBD_CMD_GSCANSET 0x11f0
  110. #define ATKBD_CMD_SSCANSET 0x10f0
  111. #define ATKBD_CMD_GETID 0x02f2
  112. #define ATKBD_CMD_SETREP 0x10f3
  113. #define ATKBD_CMD_ENABLE 0x00f4
  114. #define ATKBD_CMD_RESET_DIS 0x00f5
  115. #define ATKBD_CMD_SETALL_MBR 0x00fa
  116. #define ATKBD_CMD_RESET_BAT 0x02ff
  117. #define ATKBD_CMD_RESEND 0x00fe
  118. #define ATKBD_CMD_EX_ENABLE 0x10ea
  119. #define ATKBD_CMD_EX_SETLEDS 0x20eb
  120. #define ATKBD_CMD_OK_GETID 0x02e8
  121. #define ATKBD_RET_ACK 0xfa
  122. #define ATKBD_RET_NAK 0xfe
  123. #define ATKBD_RET_BAT 0xaa
  124. #define ATKBD_RET_EMUL0 0xe0
  125. #define ATKBD_RET_EMUL1 0xe1
  126. #define ATKBD_RET_RELEASE 0xf0
  127. #define ATKBD_RET_HANGUEL 0xf1
  128. #define ATKBD_RET_HANJA 0xf2
  129. #define ATKBD_RET_ERR 0xff
  130. #define ATKBD_KEY_UNKNOWN 0
  131. #define ATKBD_KEY_NULL 255
  132. #define ATKBD_SCR_1 254
  133. #define ATKBD_SCR_2 253
  134. #define ATKBD_SCR_4 252
  135. #define ATKBD_SCR_8 251
  136. #define ATKBD_SCR_CLICK 250
  137. #define ATKBD_SCR_LEFT 249
  138. #define ATKBD_SCR_RIGHT 248
  139. #define ATKBD_SPECIAL 248
  140. #define ATKBD_LED_EVENT_BIT 0
  141. #define ATKBD_REP_EVENT_BIT 1
  142. static struct {
  143. unsigned char keycode;
  144. unsigned char set2;
  145. } atkbd_scroll_keys[] = {
  146. { ATKBD_SCR_1, 0xc5 },
  147. { ATKBD_SCR_2, 0x9d },
  148. { ATKBD_SCR_4, 0xa4 },
  149. { ATKBD_SCR_8, 0x9b },
  150. { ATKBD_SCR_CLICK, 0xe0 },
  151. { ATKBD_SCR_LEFT, 0xcb },
  152. { ATKBD_SCR_RIGHT, 0xd2 },
  153. };
  154. /*
  155. * The atkbd control structure
  156. */
  157. struct atkbd {
  158. struct ps2dev ps2dev;
  159. struct input_dev *dev;
  160. /* Written only during init */
  161. char name[64];
  162. char phys[32];
  163. unsigned short id;
  164. unsigned char keycode[512];
  165. unsigned char set;
  166. unsigned char translated;
  167. unsigned char extra;
  168. unsigned char write;
  169. unsigned char softrepeat;
  170. unsigned char softraw;
  171. unsigned char scroll;
  172. unsigned char enabled;
  173. /* Accessed only from interrupt */
  174. unsigned char emul;
  175. unsigned char resend;
  176. unsigned char release;
  177. unsigned char bat_xl;
  178. unsigned char err_xl;
  179. unsigned int last;
  180. unsigned long time;
  181. struct work_struct event_work;
  182. struct mutex event_mutex;
  183. unsigned long event_mask;
  184. };
  185. static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf,
  186. ssize_t (*handler)(struct atkbd *, char *));
  187. static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t count,
  188. ssize_t (*handler)(struct atkbd *, const char *, size_t));
  189. #define ATKBD_DEFINE_ATTR(_name) \
  190. static ssize_t atkbd_show_##_name(struct atkbd *, char *); \
  191. static ssize_t atkbd_set_##_name(struct atkbd *, const char *, size_t); \
  192. static ssize_t atkbd_do_show_##_name(struct device *d, struct device_attribute *attr, char *b) \
  193. { \
  194. return atkbd_attr_show_helper(d, b, atkbd_show_##_name); \
  195. } \
  196. static ssize_t atkbd_do_set_##_name(struct device *d, struct device_attribute *attr, const char *b, size_t s) \
  197. { \
  198. return atkbd_attr_set_helper(d, b, s, atkbd_set_##_name); \
  199. } \
  200. static struct device_attribute atkbd_attr_##_name = \
  201. __ATTR(_name, S_IWUSR | S_IRUGO, atkbd_do_show_##_name, atkbd_do_set_##_name);
  202. ATKBD_DEFINE_ATTR(extra);
  203. ATKBD_DEFINE_ATTR(scroll);
  204. ATKBD_DEFINE_ATTR(set);
  205. ATKBD_DEFINE_ATTR(softrepeat);
  206. ATKBD_DEFINE_ATTR(softraw);
  207. static void atkbd_report_key(struct input_dev *dev, struct pt_regs *regs, int code, int value)
  208. {
  209. input_regs(dev, regs);
  210. if (value == 3) {
  211. input_report_key(dev, code, 1);
  212. input_sync(dev);
  213. input_report_key(dev, code, 0);
  214. } else
  215. input_event(dev, EV_KEY, code, value);
  216. input_sync(dev);
  217. }
  218. /*
  219. * atkbd_interrupt(). Here takes place processing of data received from
  220. * the keyboard into events.
  221. */
  222. static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
  223. unsigned int flags, struct pt_regs *regs)
  224. {
  225. struct atkbd *atkbd = serio_get_drvdata(serio);
  226. unsigned int code = data;
  227. int scroll = 0, hscroll = 0, click = -1;
  228. int value;
  229. #ifdef ATKBD_DEBUG
  230. printk(KERN_DEBUG "atkbd.c: Received %02x flags %02x\n", data, flags);
  231. #endif
  232. #if !defined(__i386__) && !defined (__x86_64__)
  233. if ((flags & (SERIO_FRAME | SERIO_PARITY)) && (~flags & SERIO_TIMEOUT) && !atkbd->resend && atkbd->write) {
  234. printk(KERN_WARNING "atkbd.c: frame/parity error: %02x\n", flags);
  235. serio_write(serio, ATKBD_CMD_RESEND);
  236. atkbd->resend = 1;
  237. goto out;
  238. }
  239. if (!flags && data == ATKBD_RET_ACK)
  240. atkbd->resend = 0;
  241. #endif
  242. if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_ACK))
  243. if (ps2_handle_ack(&atkbd->ps2dev, data))
  244. goto out;
  245. if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_CMD))
  246. if (ps2_handle_response(&atkbd->ps2dev, data))
  247. goto out;
  248. if (!atkbd->enabled)
  249. goto out;
  250. input_event(atkbd->dev, EV_MSC, MSC_RAW, code);
  251. if (atkbd->translated) {
  252. if (atkbd->emul ||
  253. (code != ATKBD_RET_EMUL0 && code != ATKBD_RET_EMUL1 &&
  254. code != ATKBD_RET_HANGUEL && code != ATKBD_RET_HANJA &&
  255. (code != ATKBD_RET_ERR || atkbd->err_xl) &&
  256. (code != ATKBD_RET_BAT || atkbd->bat_xl))) {
  257. atkbd->release = code >> 7;
  258. code &= 0x7f;
  259. }
  260. if (!atkbd->emul) {
  261. if ((code & 0x7f) == (ATKBD_RET_BAT & 0x7f))
  262. atkbd->bat_xl = !(data >> 7);
  263. if ((code & 0x7f) == (ATKBD_RET_ERR & 0x7f))
  264. atkbd->err_xl = !(data >> 7);
  265. }
  266. }
  267. switch (code) {
  268. case ATKBD_RET_BAT:
  269. atkbd->enabled = 0;
  270. serio_reconnect(atkbd->ps2dev.serio);
  271. goto out;
  272. case ATKBD_RET_EMUL0:
  273. atkbd->emul = 1;
  274. goto out;
  275. case ATKBD_RET_EMUL1:
  276. atkbd->emul = 2;
  277. goto out;
  278. case ATKBD_RET_RELEASE:
  279. atkbd->release = 1;
  280. goto out;
  281. case ATKBD_RET_HANGUEL:
  282. atkbd_report_key(atkbd->dev, regs, KEY_HANGUEL, 3);
  283. goto out;
  284. case ATKBD_RET_HANJA:
  285. atkbd_report_key(atkbd->dev, regs, KEY_HANJA, 3);
  286. goto out;
  287. case ATKBD_RET_ERR:
  288. printk(KERN_DEBUG "atkbd.c: Keyboard on %s reports too many keys pressed.\n", serio->phys);
  289. goto out;
  290. }
  291. if (atkbd->set != 3)
  292. code = (code & 0x7f) | ((code & 0x80) << 1);
  293. if (atkbd->emul) {
  294. if (--atkbd->emul)
  295. goto out;
  296. code |= (atkbd->set != 3) ? 0x80 : 0x100;
  297. }
  298. if (atkbd->keycode[code] != ATKBD_KEY_NULL)
  299. input_event(atkbd->dev, EV_MSC, MSC_SCAN, code);
  300. switch (atkbd->keycode[code]) {
  301. case ATKBD_KEY_NULL:
  302. break;
  303. case ATKBD_KEY_UNKNOWN:
  304. if (data == ATKBD_RET_ACK || data == ATKBD_RET_NAK) {
  305. printk(KERN_WARNING "atkbd.c: Spurious %s on %s. Some program, "
  306. "like XFree86, might be trying access hardware directly.\n",
  307. data == ATKBD_RET_ACK ? "ACK" : "NAK", serio->phys);
  308. } else {
  309. printk(KERN_WARNING "atkbd.c: Unknown key %s "
  310. "(%s set %d, code %#x on %s).\n",
  311. atkbd->release ? "released" : "pressed",
  312. atkbd->translated ? "translated" : "raw",
  313. atkbd->set, code, serio->phys);
  314. printk(KERN_WARNING "atkbd.c: Use 'setkeycodes %s%02x <keycode>' "
  315. "to make it known.\n",
  316. code & 0x80 ? "e0" : "", code & 0x7f);
  317. }
  318. input_sync(atkbd->dev);
  319. break;
  320. case ATKBD_SCR_1:
  321. scroll = 1 - atkbd->release * 2;
  322. break;
  323. case ATKBD_SCR_2:
  324. scroll = 2 - atkbd->release * 4;
  325. break;
  326. case ATKBD_SCR_4:
  327. scroll = 4 - atkbd->release * 8;
  328. break;
  329. case ATKBD_SCR_8:
  330. scroll = 8 - atkbd->release * 16;
  331. break;
  332. case ATKBD_SCR_CLICK:
  333. click = !atkbd->release;
  334. break;
  335. case ATKBD_SCR_LEFT:
  336. hscroll = -1;
  337. break;
  338. case ATKBD_SCR_RIGHT:
  339. hscroll = 1;
  340. break;
  341. default:
  342. value = atkbd->release ? 0 :
  343. (1 + (!atkbd->softrepeat && test_bit(atkbd->keycode[code], atkbd->dev->key)));
  344. switch (value) { /* Workaround Toshiba laptop multiple keypress */
  345. case 0:
  346. atkbd->last = 0;
  347. break;
  348. case 1:
  349. atkbd->last = code;
  350. atkbd->time = jiffies + msecs_to_jiffies(atkbd->dev->rep[REP_DELAY]) / 2;
  351. break;
  352. case 2:
  353. if (!time_after(jiffies, atkbd->time) && atkbd->last == code)
  354. value = 1;
  355. break;
  356. }
  357. atkbd_report_key(atkbd->dev, regs, atkbd->keycode[code], value);
  358. }
  359. if (atkbd->scroll) {
  360. input_regs(atkbd->dev, regs);
  361. if (click != -1)
  362. input_report_key(atkbd->dev, BTN_MIDDLE, click);
  363. input_report_rel(atkbd->dev, REL_WHEEL, scroll);
  364. input_report_rel(atkbd->dev, REL_HWHEEL, hscroll);
  365. input_sync(atkbd->dev);
  366. }
  367. atkbd->release = 0;
  368. out:
  369. return IRQ_HANDLED;
  370. }
  371. /*
  372. * atkbd_event_work() is used to complete processing of events that
  373. * can not be processed by input_event() which is often called from
  374. * interrupt context.
  375. */
  376. static void atkbd_event_work(void *data)
  377. {
  378. const short period[32] =
  379. { 33, 37, 42, 46, 50, 54, 58, 63, 67, 75, 83, 92, 100, 109, 116, 125,
  380. 133, 149, 167, 182, 200, 217, 232, 250, 270, 303, 333, 370, 400, 435, 470, 500 };
  381. const short delay[4] =
  382. { 250, 500, 750, 1000 };
  383. struct atkbd *atkbd = data;
  384. struct input_dev *dev = atkbd->dev;
  385. unsigned char param[2];
  386. int i, j;
  387. mutex_lock(&atkbd->event_mutex);
  388. if (test_and_clear_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask)) {
  389. param[0] = (test_bit(LED_SCROLLL, dev->led) ? 1 : 0)
  390. | (test_bit(LED_NUML, dev->led) ? 2 : 0)
  391. | (test_bit(LED_CAPSL, dev->led) ? 4 : 0);
  392. ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS);
  393. if (atkbd->extra) {
  394. param[0] = 0;
  395. param[1] = (test_bit(LED_COMPOSE, dev->led) ? 0x01 : 0)
  396. | (test_bit(LED_SLEEP, dev->led) ? 0x02 : 0)
  397. | (test_bit(LED_SUSPEND, dev->led) ? 0x04 : 0)
  398. | (test_bit(LED_MISC, dev->led) ? 0x10 : 0)
  399. | (test_bit(LED_MUTE, dev->led) ? 0x20 : 0);
  400. ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_EX_SETLEDS);
  401. }
  402. }
  403. if (test_and_clear_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask)) {
  404. i = j = 0;
  405. while (i < 31 && period[i] < dev->rep[REP_PERIOD])
  406. i++;
  407. while (j < 3 && delay[j] < dev->rep[REP_DELAY])
  408. j++;
  409. dev->rep[REP_PERIOD] = period[i];
  410. dev->rep[REP_DELAY] = delay[j];
  411. param[0] = i | (j << 5);
  412. ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETREP);
  413. }
  414. mutex_unlock(&atkbd->event_mutex);
  415. }
  416. /*
  417. * Event callback from the input module. Events that change the state of
  418. * the hardware are processed here. If action can not be performed in
  419. * interrupt context it is offloaded to atkbd_event_work.
  420. */
  421. static int atkbd_event(struct input_dev *dev, unsigned int type, unsigned int code, int value)
  422. {
  423. struct atkbd *atkbd = dev->private;
  424. if (!atkbd->write)
  425. return -1;
  426. switch (type) {
  427. case EV_LED:
  428. set_bit(ATKBD_LED_EVENT_BIT, &atkbd->event_mask);
  429. wmb();
  430. schedule_work(&atkbd->event_work);
  431. return 0;
  432. case EV_REP:
  433. if (!atkbd->softrepeat) {
  434. set_bit(ATKBD_REP_EVENT_BIT, &atkbd->event_mask);
  435. wmb();
  436. schedule_work(&atkbd->event_work);
  437. }
  438. return 0;
  439. }
  440. return -1;
  441. }
  442. /*
  443. * atkbd_enable() signals that interrupt handler is allowed to
  444. * generate input events.
  445. */
  446. static inline void atkbd_enable(struct atkbd *atkbd)
  447. {
  448. serio_pause_rx(atkbd->ps2dev.serio);
  449. atkbd->enabled = 1;
  450. serio_continue_rx(atkbd->ps2dev.serio);
  451. }
  452. /*
  453. * atkbd_disable() tells input handler that all incoming data except
  454. * for ACKs and command response should be dropped.
  455. */
  456. static inline void atkbd_disable(struct atkbd *atkbd)
  457. {
  458. serio_pause_rx(atkbd->ps2dev.serio);
  459. atkbd->enabled = 0;
  460. serio_continue_rx(atkbd->ps2dev.serio);
  461. }
  462. /*
  463. * atkbd_probe() probes for an AT keyboard on a serio port.
  464. */
  465. static int atkbd_probe(struct atkbd *atkbd)
  466. {
  467. struct ps2dev *ps2dev = &atkbd->ps2dev;
  468. unsigned char param[2];
  469. /*
  470. * Some systems, where the bit-twiddling when testing the io-lines of the
  471. * controller may confuse the keyboard need a full reset of the keyboard. On
  472. * these systems the BIOS also usually doesn't do it for us.
  473. */
  474. if (atkbd_reset)
  475. if (ps2_command(ps2dev, NULL, ATKBD_CMD_RESET_BAT))
  476. printk(KERN_WARNING "atkbd.c: keyboard reset failed on %s\n", ps2dev->serio->phys);
  477. /*
  478. * Then we check the keyboard ID. We should get 0xab83 under normal conditions.
  479. * Some keyboards report different values, but the first byte is always 0xab or
  480. * 0xac. Some old AT keyboards don't report anything. If a mouse is connected, this
  481. * should make sure we don't try to set the LEDs on it.
  482. */
  483. param[0] = param[1] = 0xa5; /* initialize with invalid values */
  484. if (ps2_command(ps2dev, param, ATKBD_CMD_GETID)) {
  485. /*
  486. * If the get ID command failed, we check if we can at least set the LEDs on
  487. * the keyboard. This should work on every keyboard out there. It also turns
  488. * the LEDs off, which we want anyway.
  489. */
  490. param[0] = 0;
  491. if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS))
  492. return -1;
  493. atkbd->id = 0xabba;
  494. return 0;
  495. }
  496. if (param[0] != 0xab && param[0] != 0xac && /* Regular and NCD Sun keyboards */
  497. param[0] != 0x2b && param[0] != 0x5d && /* Trust keyboard, raw and translated */
  498. param[0] != 0x60 && param[0] != 0x47) /* NMB SGI keyboard, raw and translated */
  499. return -1;
  500. atkbd->id = (param[0] << 8) | param[1];
  501. if (atkbd->id == 0xaca1 && atkbd->translated) {
  502. printk(KERN_ERR "atkbd.c: NCD terminal keyboards are only supported on non-translating\n");
  503. printk(KERN_ERR "atkbd.c: controllers. Use i8042.direct=1 to disable translation.\n");
  504. return -1;
  505. }
  506. return 0;
  507. }
  508. /*
  509. * atkbd_select_set checks if a keyboard has a working Set 3 support, and
  510. * sets it into that. Unfortunately there are keyboards that can be switched
  511. * to Set 3, but don't work well in that (BTC Multimedia ...)
  512. */
  513. static int atkbd_select_set(struct atkbd *atkbd, int target_set, int allow_extra)
  514. {
  515. struct ps2dev *ps2dev = &atkbd->ps2dev;
  516. unsigned char param[2];
  517. atkbd->extra = 0;
  518. /*
  519. * For known special keyboards we can go ahead and set the correct set.
  520. * We check for NCD PS/2 Sun, NorthGate OmniKey 101 and
  521. * IBM RapidAccess / IBM EzButton / Chicony KBP-8993 keyboards.
  522. */
  523. if (atkbd->translated)
  524. return 2;
  525. if (atkbd->id == 0xaca1) {
  526. param[0] = 3;
  527. ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET);
  528. return 3;
  529. }
  530. if (allow_extra) {
  531. param[0] = 0x71;
  532. if (!ps2_command(ps2dev, param, ATKBD_CMD_EX_ENABLE)) {
  533. atkbd->extra = 1;
  534. return 2;
  535. }
  536. }
  537. if (target_set != 3)
  538. return 2;
  539. if (!ps2_command(ps2dev, param, ATKBD_CMD_OK_GETID)) {
  540. atkbd->id = param[0] << 8 | param[1];
  541. return 2;
  542. }
  543. param[0] = 3;
  544. if (ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET))
  545. return 2;
  546. param[0] = 0;
  547. if (ps2_command(ps2dev, param, ATKBD_CMD_GSCANSET))
  548. return 2;
  549. if (param[0] != 3) {
  550. param[0] = 2;
  551. if (ps2_command(ps2dev, param, ATKBD_CMD_SSCANSET))
  552. return 2;
  553. }
  554. ps2_command(ps2dev, param, ATKBD_CMD_SETALL_MBR);
  555. return 3;
  556. }
  557. static int atkbd_activate(struct atkbd *atkbd)
  558. {
  559. struct ps2dev *ps2dev = &atkbd->ps2dev;
  560. unsigned char param[1];
  561. /*
  562. * Set the LEDs to a defined state.
  563. */
  564. param[0] = 0;
  565. if (ps2_command(ps2dev, param, ATKBD_CMD_SETLEDS))
  566. return -1;
  567. /*
  568. * Set autorepeat to fastest possible.
  569. */
  570. param[0] = 0;
  571. if (ps2_command(ps2dev, param, ATKBD_CMD_SETREP))
  572. return -1;
  573. /*
  574. * Enable the keyboard to receive keystrokes.
  575. */
  576. if (ps2_command(ps2dev, NULL, ATKBD_CMD_ENABLE)) {
  577. printk(KERN_ERR "atkbd.c: Failed to enable keyboard on %s\n",
  578. ps2dev->serio->phys);
  579. return -1;
  580. }
  581. return 0;
  582. }
  583. /*
  584. * atkbd_cleanup() restores the keyboard state so that BIOS is happy after a
  585. * reboot.
  586. */
  587. static void atkbd_cleanup(struct serio *serio)
  588. {
  589. struct atkbd *atkbd = serio_get_drvdata(serio);
  590. ps2_command(&atkbd->ps2dev, NULL, ATKBD_CMD_RESET_BAT);
  591. }
  592. /*
  593. * atkbd_disconnect() closes and frees.
  594. */
  595. static void atkbd_disconnect(struct serio *serio)
  596. {
  597. struct atkbd *atkbd = serio_get_drvdata(serio);
  598. atkbd_disable(atkbd);
  599. /* make sure we don't have a command in flight */
  600. synchronize_sched(); /* Allow atkbd_interrupt()s to complete. */
  601. flush_scheduled_work();
  602. device_remove_file(&serio->dev, &atkbd_attr_extra);
  603. device_remove_file(&serio->dev, &atkbd_attr_scroll);
  604. device_remove_file(&serio->dev, &atkbd_attr_set);
  605. device_remove_file(&serio->dev, &atkbd_attr_softrepeat);
  606. device_remove_file(&serio->dev, &atkbd_attr_softraw);
  607. input_unregister_device(atkbd->dev);
  608. serio_close(serio);
  609. serio_set_drvdata(serio, NULL);
  610. kfree(atkbd);
  611. }
  612. /*
  613. * atkbd_set_keycode_table() initializes keyboard's keycode table
  614. * according to the selected scancode set
  615. */
  616. static void atkbd_set_keycode_table(struct atkbd *atkbd)
  617. {
  618. int i, j;
  619. memset(atkbd->keycode, 0, sizeof(atkbd->keycode));
  620. if (atkbd->translated) {
  621. for (i = 0; i < 128; i++) {
  622. atkbd->keycode[i] = atkbd_set2_keycode[atkbd_unxlate_table[i]];
  623. atkbd->keycode[i | 0x80] = atkbd_set2_keycode[atkbd_unxlate_table[i] | 0x80];
  624. if (atkbd->scroll)
  625. for (j = 0; j < ARRAY_SIZE(atkbd_scroll_keys); j++)
  626. if ((atkbd_unxlate_table[i] | 0x80) == atkbd_scroll_keys[j].set2)
  627. atkbd->keycode[i | 0x80] = atkbd_scroll_keys[j].keycode;
  628. }
  629. } else if (atkbd->set == 3) {
  630. memcpy(atkbd->keycode, atkbd_set3_keycode, sizeof(atkbd->keycode));
  631. } else {
  632. memcpy(atkbd->keycode, atkbd_set2_keycode, sizeof(atkbd->keycode));
  633. if (atkbd->scroll)
  634. for (i = 0; i < ARRAY_SIZE(atkbd_scroll_keys); i++)
  635. atkbd->keycode[atkbd_scroll_keys[i].set2] = atkbd_scroll_keys[i].keycode;
  636. }
  637. }
  638. /*
  639. * atkbd_set_device_attrs() sets up keyboard's input device structure
  640. */
  641. static void atkbd_set_device_attrs(struct atkbd *atkbd)
  642. {
  643. struct input_dev *input_dev = atkbd->dev;
  644. int i;
  645. if (atkbd->extra)
  646. sprintf(atkbd->name, "AT Set 2 Extra keyboard");
  647. else
  648. sprintf(atkbd->name, "AT %s Set %d keyboard",
  649. atkbd->translated ? "Translated" : "Raw", atkbd->set);
  650. sprintf(atkbd->phys, "%s/input0", atkbd->ps2dev.serio->phys);
  651. input_dev->name = atkbd->name;
  652. input_dev->phys = atkbd->phys;
  653. input_dev->id.bustype = BUS_I8042;
  654. input_dev->id.vendor = 0x0001;
  655. input_dev->id.product = atkbd->translated ? 1 : atkbd->set;
  656. input_dev->id.version = atkbd->id;
  657. input_dev->event = atkbd_event;
  658. input_dev->private = atkbd;
  659. input_dev->cdev.dev = &atkbd->ps2dev.serio->dev;
  660. input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP) | BIT(EV_MSC);
  661. if (atkbd->write) {
  662. input_dev->evbit[0] |= BIT(EV_LED);
  663. input_dev->ledbit[0] = BIT(LED_NUML) | BIT(LED_CAPSL) | BIT(LED_SCROLLL);
  664. }
  665. if (atkbd->extra)
  666. input_dev->ledbit[0] |= BIT(LED_COMPOSE) | BIT(LED_SUSPEND) |
  667. BIT(LED_SLEEP) | BIT(LED_MUTE) | BIT(LED_MISC);
  668. if (!atkbd->softrepeat) {
  669. input_dev->rep[REP_DELAY] = 250;
  670. input_dev->rep[REP_PERIOD] = 33;
  671. }
  672. input_dev->mscbit[0] = atkbd->softraw ? BIT(MSC_SCAN) : BIT(MSC_RAW) | BIT(MSC_SCAN);
  673. if (atkbd->scroll) {
  674. input_dev->evbit[0] |= BIT(EV_REL);
  675. input_dev->relbit[0] = BIT(REL_WHEEL) | BIT(REL_HWHEEL);
  676. set_bit(BTN_MIDDLE, input_dev->keybit);
  677. }
  678. input_dev->keycode = atkbd->keycode;
  679. input_dev->keycodesize = sizeof(unsigned char);
  680. input_dev->keycodemax = ARRAY_SIZE(atkbd_set2_keycode);
  681. for (i = 0; i < 512; i++)
  682. if (atkbd->keycode[i] && atkbd->keycode[i] < ATKBD_SPECIAL)
  683. set_bit(atkbd->keycode[i], input_dev->keybit);
  684. }
  685. /*
  686. * atkbd_connect() is called when the serio module finds an interface
  687. * that isn't handled yet by an appropriate device driver. We check if
  688. * there is an AT keyboard out there and if yes, we register ourselves
  689. * to the input module.
  690. */
  691. static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
  692. {
  693. struct atkbd *atkbd;
  694. struct input_dev *dev;
  695. int err = -ENOMEM;
  696. atkbd = kzalloc(sizeof(struct atkbd), GFP_KERNEL);
  697. dev = input_allocate_device();
  698. if (!atkbd || !dev)
  699. goto fail;
  700. atkbd->dev = dev;
  701. ps2_init(&atkbd->ps2dev, serio);
  702. INIT_WORK(&atkbd->event_work, atkbd_event_work, atkbd);
  703. mutex_init(&atkbd->event_mutex);
  704. switch (serio->id.type) {
  705. case SERIO_8042_XL:
  706. atkbd->translated = 1;
  707. case SERIO_8042:
  708. if (serio->write)
  709. atkbd->write = 1;
  710. break;
  711. }
  712. atkbd->softraw = atkbd_softraw;
  713. atkbd->softrepeat = atkbd_softrepeat;
  714. atkbd->scroll = atkbd_scroll;
  715. if (atkbd->softrepeat)
  716. atkbd->softraw = 1;
  717. serio_set_drvdata(serio, atkbd);
  718. err = serio_open(serio, drv);
  719. if (err)
  720. goto fail;
  721. if (atkbd->write) {
  722. if (atkbd_probe(atkbd)) {
  723. serio_close(serio);
  724. err = -ENODEV;
  725. goto fail;
  726. }
  727. atkbd->set = atkbd_select_set(atkbd, atkbd_set, atkbd_extra);
  728. atkbd_activate(atkbd);
  729. } else {
  730. atkbd->set = 2;
  731. atkbd->id = 0xab00;
  732. }
  733. atkbd_set_keycode_table(atkbd);
  734. atkbd_set_device_attrs(atkbd);
  735. device_create_file(&serio->dev, &atkbd_attr_extra);
  736. device_create_file(&serio->dev, &atkbd_attr_scroll);
  737. device_create_file(&serio->dev, &atkbd_attr_set);
  738. device_create_file(&serio->dev, &atkbd_attr_softrepeat);
  739. device_create_file(&serio->dev, &atkbd_attr_softraw);
  740. atkbd_enable(atkbd);
  741. input_register_device(atkbd->dev);
  742. return 0;
  743. fail: serio_set_drvdata(serio, NULL);
  744. input_free_device(dev);
  745. kfree(atkbd);
  746. return err;
  747. }
  748. /*
  749. * atkbd_reconnect() tries to restore keyboard into a sane state and is
  750. * most likely called on resume.
  751. */
  752. static int atkbd_reconnect(struct serio *serio)
  753. {
  754. struct atkbd *atkbd = serio_get_drvdata(serio);
  755. struct serio_driver *drv = serio->drv;
  756. unsigned char param[1];
  757. if (!atkbd || !drv) {
  758. printk(KERN_DEBUG "atkbd: reconnect request, but serio is disconnected, ignoring...\n");
  759. return -1;
  760. }
  761. atkbd_disable(atkbd);
  762. if (atkbd->write) {
  763. param[0] = (test_bit(LED_SCROLLL, atkbd->dev->led) ? 1 : 0)
  764. | (test_bit(LED_NUML, atkbd->dev->led) ? 2 : 0)
  765. | (test_bit(LED_CAPSL, atkbd->dev->led) ? 4 : 0);
  766. if (atkbd_probe(atkbd))
  767. return -1;
  768. if (atkbd->set != atkbd_select_set(atkbd, atkbd->set, atkbd->extra))
  769. return -1;
  770. atkbd_activate(atkbd);
  771. if (ps2_command(&atkbd->ps2dev, param, ATKBD_CMD_SETLEDS))
  772. return -1;
  773. }
  774. atkbd_enable(atkbd);
  775. return 0;
  776. }
  777. static struct serio_device_id atkbd_serio_ids[] = {
  778. {
  779. .type = SERIO_8042,
  780. .proto = SERIO_ANY,
  781. .id = SERIO_ANY,
  782. .extra = SERIO_ANY,
  783. },
  784. {
  785. .type = SERIO_8042_XL,
  786. .proto = SERIO_ANY,
  787. .id = SERIO_ANY,
  788. .extra = SERIO_ANY,
  789. },
  790. {
  791. .type = SERIO_RS232,
  792. .proto = SERIO_PS2SER,
  793. .id = SERIO_ANY,
  794. .extra = SERIO_ANY,
  795. },
  796. { 0 }
  797. };
  798. MODULE_DEVICE_TABLE(serio, atkbd_serio_ids);
  799. static struct serio_driver atkbd_drv = {
  800. .driver = {
  801. .name = "atkbd",
  802. },
  803. .description = DRIVER_DESC,
  804. .id_table = atkbd_serio_ids,
  805. .interrupt = atkbd_interrupt,
  806. .connect = atkbd_connect,
  807. .reconnect = atkbd_reconnect,
  808. .disconnect = atkbd_disconnect,
  809. .cleanup = atkbd_cleanup,
  810. };
  811. static ssize_t atkbd_attr_show_helper(struct device *dev, char *buf,
  812. ssize_t (*handler)(struct atkbd *, char *))
  813. {
  814. struct serio *serio = to_serio_port(dev);
  815. int retval;
  816. retval = serio_pin_driver(serio);
  817. if (retval)
  818. return retval;
  819. if (serio->drv != &atkbd_drv) {
  820. retval = -ENODEV;
  821. goto out;
  822. }
  823. retval = handler((struct atkbd *)serio_get_drvdata(serio), buf);
  824. out:
  825. serio_unpin_driver(serio);
  826. return retval;
  827. }
  828. static ssize_t atkbd_attr_set_helper(struct device *dev, const char *buf, size_t count,
  829. ssize_t (*handler)(struct atkbd *, const char *, size_t))
  830. {
  831. struct serio *serio = to_serio_port(dev);
  832. struct atkbd *atkbd;
  833. int retval;
  834. retval = serio_pin_driver(serio);
  835. if (retval)
  836. return retval;
  837. if (serio->drv != &atkbd_drv) {
  838. retval = -ENODEV;
  839. goto out;
  840. }
  841. atkbd = serio_get_drvdata(serio);
  842. atkbd_disable(atkbd);
  843. retval = handler(atkbd, buf, count);
  844. atkbd_enable(atkbd);
  845. out:
  846. serio_unpin_driver(serio);
  847. return retval;
  848. }
  849. static ssize_t atkbd_show_extra(struct atkbd *atkbd, char *buf)
  850. {
  851. return sprintf(buf, "%d\n", atkbd->extra ? 1 : 0);
  852. }
  853. static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t count)
  854. {
  855. struct input_dev *new_dev;
  856. unsigned long value;
  857. char *rest;
  858. if (!atkbd->write)
  859. return -EIO;
  860. value = simple_strtoul(buf, &rest, 10);
  861. if (*rest || value > 1)
  862. return -EINVAL;
  863. if (atkbd->extra != value) {
  864. /*
  865. * Since device's properties will change we need to
  866. * unregister old device. But allocate new one first
  867. * to make sure we have it.
  868. */
  869. if (!(new_dev = input_allocate_device()))
  870. return -ENOMEM;
  871. input_unregister_device(atkbd->dev);
  872. atkbd->dev = new_dev;
  873. atkbd->set = atkbd_select_set(atkbd, atkbd->set, value);
  874. atkbd_activate(atkbd);
  875. atkbd_set_device_attrs(atkbd);
  876. input_register_device(atkbd->dev);
  877. }
  878. return count;
  879. }
  880. static ssize_t atkbd_show_scroll(struct atkbd *atkbd, char *buf)
  881. {
  882. return sprintf(buf, "%d\n", atkbd->scroll ? 1 : 0);
  883. }
  884. static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t count)
  885. {
  886. struct input_dev *new_dev;
  887. unsigned long value;
  888. char *rest;
  889. value = simple_strtoul(buf, &rest, 10);
  890. if (*rest || value > 1)
  891. return -EINVAL;
  892. if (atkbd->scroll != value) {
  893. if (!(new_dev = input_allocate_device()))
  894. return -ENOMEM;
  895. input_unregister_device(atkbd->dev);
  896. atkbd->dev = new_dev;
  897. atkbd->scroll = value;
  898. atkbd_set_keycode_table(atkbd);
  899. atkbd_set_device_attrs(atkbd);
  900. input_register_device(atkbd->dev);
  901. }
  902. return count;
  903. }
  904. static ssize_t atkbd_show_set(struct atkbd *atkbd, char *buf)
  905. {
  906. return sprintf(buf, "%d\n", atkbd->set);
  907. }
  908. static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
  909. {
  910. struct input_dev *new_dev;
  911. unsigned long value;
  912. char *rest;
  913. if (!atkbd->write)
  914. return -EIO;
  915. value = simple_strtoul(buf, &rest, 10);
  916. if (*rest || (value != 2 && value != 3))
  917. return -EINVAL;
  918. if (atkbd->set != value) {
  919. if (!(new_dev = input_allocate_device()))
  920. return -ENOMEM;
  921. input_unregister_device(atkbd->dev);
  922. atkbd->dev = new_dev;
  923. atkbd->set = atkbd_select_set(atkbd, value, atkbd->extra);
  924. atkbd_activate(atkbd);
  925. atkbd_set_keycode_table(atkbd);
  926. atkbd_set_device_attrs(atkbd);
  927. input_register_device(atkbd->dev);
  928. }
  929. return count;
  930. }
  931. static ssize_t atkbd_show_softrepeat(struct atkbd *atkbd, char *buf)
  932. {
  933. return sprintf(buf, "%d\n", atkbd->softrepeat ? 1 : 0);
  934. }
  935. static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t count)
  936. {
  937. struct input_dev *new_dev;
  938. unsigned long value;
  939. char *rest;
  940. if (!atkbd->write)
  941. return -EIO;
  942. value = simple_strtoul(buf, &rest, 10);
  943. if (*rest || value > 1)
  944. return -EINVAL;
  945. if (atkbd->softrepeat != value) {
  946. if (!(new_dev = input_allocate_device()))
  947. return -ENOMEM;
  948. input_unregister_device(atkbd->dev);
  949. atkbd->dev = new_dev;
  950. atkbd->softrepeat = value;
  951. if (atkbd->softrepeat)
  952. atkbd->softraw = 1;
  953. atkbd_set_device_attrs(atkbd);
  954. input_register_device(atkbd->dev);
  955. }
  956. return count;
  957. }
  958. static ssize_t atkbd_show_softraw(struct atkbd *atkbd, char *buf)
  959. {
  960. return sprintf(buf, "%d\n", atkbd->softraw ? 1 : 0);
  961. }
  962. static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t count)
  963. {
  964. struct input_dev *new_dev;
  965. unsigned long value;
  966. char *rest;
  967. value = simple_strtoul(buf, &rest, 10);
  968. if (*rest || value > 1)
  969. return -EINVAL;
  970. if (atkbd->softraw != value) {
  971. if (!(new_dev = input_allocate_device()))
  972. return -ENOMEM;
  973. input_unregister_device(atkbd->dev);
  974. atkbd->dev = new_dev;
  975. atkbd->softraw = value;
  976. atkbd_set_device_attrs(atkbd);
  977. input_register_device(atkbd->dev);
  978. }
  979. return count;
  980. }
  981. static int __init atkbd_init(void)
  982. {
  983. serio_register_driver(&atkbd_drv);
  984. return 0;
  985. }
  986. static void __exit atkbd_exit(void)
  987. {
  988. serio_unregister_driver(&atkbd_drv);
  989. }
  990. module_init(atkbd_init);
  991. module_exit(atkbd_exit);