i8042.c 32 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423
  1. /*
  2. * i8042 keyboard and mouse controller driver for Linux
  3. *
  4. * Copyright (c) 1999-2004 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. #include <linux/types.h>
  12. #include <linux/delay.h>
  13. #include <linux/module.h>
  14. #include <linux/interrupt.h>
  15. #include <linux/ioport.h>
  16. #include <linux/init.h>
  17. #include <linux/serio.h>
  18. #include <linux/err.h>
  19. #include <linux/rcupdate.h>
  20. #include <linux/platform_device.h>
  21. #include <linux/i8042.h>
  22. #include <asm/io.h>
  23. MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
  24. MODULE_DESCRIPTION("i8042 keyboard and mouse controller driver");
  25. MODULE_LICENSE("GPL");
  26. static bool i8042_nokbd;
  27. module_param_named(nokbd, i8042_nokbd, bool, 0);
  28. MODULE_PARM_DESC(nokbd, "Do not probe or use KBD port.");
  29. static bool i8042_noaux;
  30. module_param_named(noaux, i8042_noaux, bool, 0);
  31. MODULE_PARM_DESC(noaux, "Do not probe or use AUX (mouse) port.");
  32. static bool i8042_nomux;
  33. module_param_named(nomux, i8042_nomux, bool, 0);
  34. MODULE_PARM_DESC(nomux, "Do not check whether an active multiplexing conrtoller is present.");
  35. static bool i8042_unlock;
  36. module_param_named(unlock, i8042_unlock, bool, 0);
  37. MODULE_PARM_DESC(unlock, "Ignore keyboard lock.");
  38. static bool i8042_reset;
  39. module_param_named(reset, i8042_reset, bool, 0);
  40. MODULE_PARM_DESC(reset, "Reset controller during init and cleanup.");
  41. static bool i8042_direct;
  42. module_param_named(direct, i8042_direct, bool, 0);
  43. MODULE_PARM_DESC(direct, "Put keyboard port into non-translated mode.");
  44. static bool i8042_dumbkbd;
  45. module_param_named(dumbkbd, i8042_dumbkbd, bool, 0);
  46. MODULE_PARM_DESC(dumbkbd, "Pretend that controller can only read data from keyboard");
  47. static bool i8042_noloop;
  48. module_param_named(noloop, i8042_noloop, bool, 0);
  49. MODULE_PARM_DESC(noloop, "Disable the AUX Loopback command while probing for the AUX port");
  50. static unsigned int i8042_blink_frequency = 500;
  51. module_param_named(panicblink, i8042_blink_frequency, uint, 0600);
  52. MODULE_PARM_DESC(panicblink, "Frequency with which keyboard LEDs should blink when kernel panics");
  53. #ifdef CONFIG_X86
  54. static bool i8042_dritek;
  55. module_param_named(dritek, i8042_dritek, bool, 0);
  56. MODULE_PARM_DESC(dritek, "Force enable the Dritek keyboard extension");
  57. #endif
  58. #ifdef CONFIG_PNP
  59. static bool i8042_nopnp;
  60. module_param_named(nopnp, i8042_nopnp, bool, 0);
  61. MODULE_PARM_DESC(nopnp, "Do not use PNP to detect controller settings");
  62. #endif
  63. #define DEBUG
  64. #ifdef DEBUG
  65. static bool i8042_debug;
  66. module_param_named(debug, i8042_debug, bool, 0600);
  67. MODULE_PARM_DESC(debug, "Turn i8042 debugging mode on and off");
  68. #endif
  69. static bool i8042_bypass_aux_irq_test;
  70. #include "i8042.h"
  71. /*
  72. * i8042_lock protects serialization between i8042_command and
  73. * the interrupt handler.
  74. */
  75. static DEFINE_SPINLOCK(i8042_lock);
  76. /*
  77. * Writers to AUX and KBD ports as well as users issuing i8042_command
  78. * directly should acquire i8042_mutex (by means of calling
  79. * i8042_lock_chip() and i8042_unlock_ship() helpers) to ensure that
  80. * they do not disturb each other (unfortunately in many i8042
  81. * implementations write to one of the ports will immediately abort
  82. * command that is being processed by another port).
  83. */
  84. static DEFINE_MUTEX(i8042_mutex);
  85. struct i8042_port {
  86. struct serio *serio;
  87. int irq;
  88. bool exists;
  89. signed char mux;
  90. };
  91. #define I8042_KBD_PORT_NO 0
  92. #define I8042_AUX_PORT_NO 1
  93. #define I8042_MUX_PORT_NO 2
  94. #define I8042_NUM_PORTS (I8042_NUM_MUX_PORTS + 2)
  95. static struct i8042_port i8042_ports[I8042_NUM_PORTS];
  96. static unsigned char i8042_initial_ctr;
  97. static unsigned char i8042_ctr;
  98. static bool i8042_mux_present;
  99. static bool i8042_kbd_irq_registered;
  100. static bool i8042_aux_irq_registered;
  101. static unsigned char i8042_suppress_kbd_ack;
  102. static struct platform_device *i8042_platform_device;
  103. static irqreturn_t i8042_interrupt(int irq, void *dev_id);
  104. void i8042_lock_chip(void)
  105. {
  106. mutex_lock(&i8042_mutex);
  107. }
  108. EXPORT_SYMBOL(i8042_lock_chip);
  109. void i8042_unlock_chip(void)
  110. {
  111. mutex_unlock(&i8042_mutex);
  112. }
  113. EXPORT_SYMBOL(i8042_unlock_chip);
  114. /*
  115. * The i8042_wait_read() and i8042_wait_write functions wait for the i8042 to
  116. * be ready for reading values from it / writing values to it.
  117. * Called always with i8042_lock held.
  118. */
  119. static int i8042_wait_read(void)
  120. {
  121. int i = 0;
  122. while ((~i8042_read_status() & I8042_STR_OBF) && (i < I8042_CTL_TIMEOUT)) {
  123. udelay(50);
  124. i++;
  125. }
  126. return -(i == I8042_CTL_TIMEOUT);
  127. }
  128. static int i8042_wait_write(void)
  129. {
  130. int i = 0;
  131. while ((i8042_read_status() & I8042_STR_IBF) && (i < I8042_CTL_TIMEOUT)) {
  132. udelay(50);
  133. i++;
  134. }
  135. return -(i == I8042_CTL_TIMEOUT);
  136. }
  137. /*
  138. * i8042_flush() flushes all data that may be in the keyboard and mouse buffers
  139. * of the i8042 down the toilet.
  140. */
  141. static int i8042_flush(void)
  142. {
  143. unsigned long flags;
  144. unsigned char data, str;
  145. int i = 0;
  146. spin_lock_irqsave(&i8042_lock, flags);
  147. while (((str = i8042_read_status()) & I8042_STR_OBF) && (i < I8042_BUFFER_SIZE)) {
  148. udelay(50);
  149. data = i8042_read_data();
  150. i++;
  151. dbg("%02x <- i8042 (flush, %s)", data,
  152. str & I8042_STR_AUXDATA ? "aux" : "kbd");
  153. }
  154. spin_unlock_irqrestore(&i8042_lock, flags);
  155. return i;
  156. }
  157. /*
  158. * i8042_command() executes a command on the i8042. It also sends the input
  159. * parameter(s) of the commands to it, and receives the output value(s). The
  160. * parameters are to be stored in the param array, and the output is placed
  161. * into the same array. The number of the parameters and output values is
  162. * encoded in bits 8-11 of the command number.
  163. */
  164. static int __i8042_command(unsigned char *param, int command)
  165. {
  166. int i, error;
  167. if (i8042_noloop && command == I8042_CMD_AUX_LOOP)
  168. return -1;
  169. error = i8042_wait_write();
  170. if (error)
  171. return error;
  172. dbg("%02x -> i8042 (command)", command & 0xff);
  173. i8042_write_command(command & 0xff);
  174. for (i = 0; i < ((command >> 12) & 0xf); i++) {
  175. error = i8042_wait_write();
  176. if (error)
  177. return error;
  178. dbg("%02x -> i8042 (parameter)", param[i]);
  179. i8042_write_data(param[i]);
  180. }
  181. for (i = 0; i < ((command >> 8) & 0xf); i++) {
  182. error = i8042_wait_read();
  183. if (error) {
  184. dbg(" -- i8042 (timeout)");
  185. return error;
  186. }
  187. if (command == I8042_CMD_AUX_LOOP &&
  188. !(i8042_read_status() & I8042_STR_AUXDATA)) {
  189. dbg(" -- i8042 (auxerr)");
  190. return -1;
  191. }
  192. param[i] = i8042_read_data();
  193. dbg("%02x <- i8042 (return)", param[i]);
  194. }
  195. return 0;
  196. }
  197. int i8042_command(unsigned char *param, int command)
  198. {
  199. unsigned long flags;
  200. int retval;
  201. spin_lock_irqsave(&i8042_lock, flags);
  202. retval = __i8042_command(param, command);
  203. spin_unlock_irqrestore(&i8042_lock, flags);
  204. return retval;
  205. }
  206. EXPORT_SYMBOL(i8042_command);
  207. /*
  208. * i8042_kbd_write() sends a byte out through the keyboard interface.
  209. */
  210. static int i8042_kbd_write(struct serio *port, unsigned char c)
  211. {
  212. unsigned long flags;
  213. int retval = 0;
  214. spin_lock_irqsave(&i8042_lock, flags);
  215. if (!(retval = i8042_wait_write())) {
  216. dbg("%02x -> i8042 (kbd-data)", c);
  217. i8042_write_data(c);
  218. }
  219. spin_unlock_irqrestore(&i8042_lock, flags);
  220. return retval;
  221. }
  222. /*
  223. * i8042_aux_write() sends a byte out through the aux interface.
  224. */
  225. static int i8042_aux_write(struct serio *serio, unsigned char c)
  226. {
  227. struct i8042_port *port = serio->port_data;
  228. return i8042_command(&c, port->mux == -1 ?
  229. I8042_CMD_AUX_SEND :
  230. I8042_CMD_MUX_SEND + port->mux);
  231. }
  232. /*
  233. * i8042_aux_close attempts to clear AUX or KBD port state by disabling
  234. * and then re-enabling it.
  235. */
  236. static void i8042_port_close(struct serio *serio)
  237. {
  238. int irq_bit;
  239. int disable_bit;
  240. const char *port_name;
  241. if (serio == i8042_ports[I8042_AUX_PORT_NO].serio) {
  242. irq_bit = I8042_CTR_AUXINT;
  243. disable_bit = I8042_CTR_AUXDIS;
  244. port_name = "AUX";
  245. } else {
  246. irq_bit = I8042_CTR_KBDINT;
  247. disable_bit = I8042_CTR_KBDDIS;
  248. port_name = "KBD";
  249. }
  250. i8042_ctr &= ~irq_bit;
  251. if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR))
  252. printk(KERN_WARNING
  253. "i8042.c: Can't write CTR while closing %s port.\n",
  254. port_name);
  255. udelay(50);
  256. i8042_ctr &= ~disable_bit;
  257. i8042_ctr |= irq_bit;
  258. if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR))
  259. printk(KERN_ERR "i8042.c: Can't reactivate %s port.\n",
  260. port_name);
  261. /*
  262. * See if there is any data appeared while we were messing with
  263. * port state.
  264. */
  265. i8042_interrupt(0, NULL);
  266. }
  267. /*
  268. * i8042_start() is called by serio core when port is about to finish
  269. * registering. It will mark port as existing so i8042_interrupt can
  270. * start sending data through it.
  271. */
  272. static int i8042_start(struct serio *serio)
  273. {
  274. struct i8042_port *port = serio->port_data;
  275. port->exists = true;
  276. mb();
  277. return 0;
  278. }
  279. /*
  280. * i8042_stop() marks serio port as non-existing so i8042_interrupt
  281. * will not try to send data to the port that is about to go away.
  282. * The function is called by serio core as part of unregister procedure.
  283. */
  284. static void i8042_stop(struct serio *serio)
  285. {
  286. struct i8042_port *port = serio->port_data;
  287. port->exists = false;
  288. /*
  289. * We synchronize with both AUX and KBD IRQs because there is
  290. * a (very unlikely) chance that AUX IRQ is raised for KBD port
  291. * and vice versa.
  292. */
  293. synchronize_irq(I8042_AUX_IRQ);
  294. synchronize_irq(I8042_KBD_IRQ);
  295. port->serio = NULL;
  296. }
  297. /*
  298. * i8042_interrupt() is the most important function in this driver -
  299. * it handles the interrupts from the i8042, and sends incoming bytes
  300. * to the upper layers.
  301. */
  302. static irqreturn_t i8042_interrupt(int irq, void *dev_id)
  303. {
  304. struct i8042_port *port;
  305. unsigned long flags;
  306. unsigned char str, data;
  307. unsigned int dfl;
  308. unsigned int port_no;
  309. int ret = 1;
  310. spin_lock_irqsave(&i8042_lock, flags);
  311. str = i8042_read_status();
  312. if (unlikely(~str & I8042_STR_OBF)) {
  313. spin_unlock_irqrestore(&i8042_lock, flags);
  314. if (irq) dbg("Interrupt %d, without any data", irq);
  315. ret = 0;
  316. goto out;
  317. }
  318. data = i8042_read_data();
  319. spin_unlock_irqrestore(&i8042_lock, flags);
  320. if (i8042_mux_present && (str & I8042_STR_AUXDATA)) {
  321. static unsigned long last_transmit;
  322. static unsigned char last_str;
  323. dfl = 0;
  324. if (str & I8042_STR_MUXERR) {
  325. dbg("MUX error, status is %02x, data is %02x", str, data);
  326. /*
  327. * When MUXERR condition is signalled the data register can only contain
  328. * 0xfd, 0xfe or 0xff if implementation follows the spec. Unfortunately
  329. * it is not always the case. Some KBCs also report 0xfc when there is
  330. * nothing connected to the port while others sometimes get confused which
  331. * port the data came from and signal error leaving the data intact. They
  332. * _do not_ revert to legacy mode (actually I've never seen KBC reverting
  333. * to legacy mode yet, when we see one we'll add proper handling).
  334. * Anyway, we process 0xfc, 0xfd, 0xfe and 0xff as timeouts, and for the
  335. * rest assume that the data came from the same serio last byte
  336. * was transmitted (if transmission happened not too long ago).
  337. */
  338. switch (data) {
  339. default:
  340. if (time_before(jiffies, last_transmit + HZ/10)) {
  341. str = last_str;
  342. break;
  343. }
  344. /* fall through - report timeout */
  345. case 0xfc:
  346. case 0xfd:
  347. case 0xfe: dfl = SERIO_TIMEOUT; data = 0xfe; break;
  348. case 0xff: dfl = SERIO_PARITY; data = 0xfe; break;
  349. }
  350. }
  351. port_no = I8042_MUX_PORT_NO + ((str >> 6) & 3);
  352. last_str = str;
  353. last_transmit = jiffies;
  354. } else {
  355. dfl = ((str & I8042_STR_PARITY) ? SERIO_PARITY : 0) |
  356. ((str & I8042_STR_TIMEOUT) ? SERIO_TIMEOUT : 0);
  357. port_no = (str & I8042_STR_AUXDATA) ?
  358. I8042_AUX_PORT_NO : I8042_KBD_PORT_NO;
  359. }
  360. port = &i8042_ports[port_no];
  361. dbg("%02x <- i8042 (interrupt, %d, %d%s%s)",
  362. data, port_no, irq,
  363. dfl & SERIO_PARITY ? ", bad parity" : "",
  364. dfl & SERIO_TIMEOUT ? ", timeout" : "");
  365. if (unlikely(i8042_suppress_kbd_ack))
  366. if (port_no == I8042_KBD_PORT_NO &&
  367. (data == 0xfa || data == 0xfe)) {
  368. i8042_suppress_kbd_ack--;
  369. goto out;
  370. }
  371. if (likely(port->exists))
  372. serio_interrupt(port->serio, data, dfl);
  373. out:
  374. return IRQ_RETVAL(ret);
  375. }
  376. /*
  377. * i8042_enable_kbd_port enables keyboard port on chip
  378. */
  379. static int i8042_enable_kbd_port(void)
  380. {
  381. i8042_ctr &= ~I8042_CTR_KBDDIS;
  382. i8042_ctr |= I8042_CTR_KBDINT;
  383. if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
  384. i8042_ctr &= ~I8042_CTR_KBDINT;
  385. i8042_ctr |= I8042_CTR_KBDDIS;
  386. printk(KERN_ERR "i8042.c: Failed to enable KBD port.\n");
  387. return -EIO;
  388. }
  389. return 0;
  390. }
  391. /*
  392. * i8042_enable_aux_port enables AUX (mouse) port on chip
  393. */
  394. static int i8042_enable_aux_port(void)
  395. {
  396. i8042_ctr &= ~I8042_CTR_AUXDIS;
  397. i8042_ctr |= I8042_CTR_AUXINT;
  398. if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
  399. i8042_ctr &= ~I8042_CTR_AUXINT;
  400. i8042_ctr |= I8042_CTR_AUXDIS;
  401. printk(KERN_ERR "i8042.c: Failed to enable AUX port.\n");
  402. return -EIO;
  403. }
  404. return 0;
  405. }
  406. /*
  407. * i8042_enable_mux_ports enables 4 individual AUX ports after
  408. * the controller has been switched into Multiplexed mode
  409. */
  410. static int i8042_enable_mux_ports(void)
  411. {
  412. unsigned char param;
  413. int i;
  414. for (i = 0; i < I8042_NUM_MUX_PORTS; i++) {
  415. i8042_command(&param, I8042_CMD_MUX_PFX + i);
  416. i8042_command(&param, I8042_CMD_AUX_ENABLE);
  417. }
  418. return i8042_enable_aux_port();
  419. }
  420. /*
  421. * i8042_set_mux_mode checks whether the controller has an
  422. * active multiplexor and puts the chip into Multiplexed (true)
  423. * or Legacy (false) mode.
  424. */
  425. static int i8042_set_mux_mode(bool multiplex, unsigned char *mux_version)
  426. {
  427. unsigned char param, val;
  428. /*
  429. * Get rid of bytes in the queue.
  430. */
  431. i8042_flush();
  432. /*
  433. * Internal loopback test - send three bytes, they should come back from the
  434. * mouse interface, the last should be version.
  435. */
  436. param = val = 0xf0;
  437. if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != val)
  438. return -1;
  439. param = val = multiplex ? 0x56 : 0xf6;
  440. if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param != val)
  441. return -1;
  442. param = val = multiplex ? 0xa4 : 0xa5;
  443. if (i8042_command(&param, I8042_CMD_AUX_LOOP) || param == val)
  444. return -1;
  445. /*
  446. * Workaround for interference with USB Legacy emulation
  447. * that causes a v10.12 MUX to be found.
  448. */
  449. if (param == 0xac)
  450. return -1;
  451. if (mux_version)
  452. *mux_version = param;
  453. return 0;
  454. }
  455. /*
  456. * i8042_check_mux() checks whether the controller supports the PS/2 Active
  457. * Multiplexing specification by Synaptics, Phoenix, Insyde and
  458. * LCS/Telegraphics.
  459. */
  460. static int __init i8042_check_mux(void)
  461. {
  462. unsigned char mux_version;
  463. if (i8042_set_mux_mode(true, &mux_version))
  464. return -1;
  465. printk(KERN_INFO "i8042.c: Detected active multiplexing controller, rev %d.%d.\n",
  466. (mux_version >> 4) & 0xf, mux_version & 0xf);
  467. /*
  468. * Disable all muxed ports by disabling AUX.
  469. */
  470. i8042_ctr |= I8042_CTR_AUXDIS;
  471. i8042_ctr &= ~I8042_CTR_AUXINT;
  472. if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
  473. printk(KERN_ERR "i8042.c: Failed to disable AUX port, can't use MUX.\n");
  474. return -EIO;
  475. }
  476. i8042_mux_present = true;
  477. return 0;
  478. }
  479. /*
  480. * The following is used to test AUX IRQ delivery.
  481. */
  482. static struct completion i8042_aux_irq_delivered __initdata;
  483. static bool i8042_irq_being_tested __initdata;
  484. static irqreturn_t __init i8042_aux_test_irq(int irq, void *dev_id)
  485. {
  486. unsigned long flags;
  487. unsigned char str, data;
  488. int ret = 0;
  489. spin_lock_irqsave(&i8042_lock, flags);
  490. str = i8042_read_status();
  491. if (str & I8042_STR_OBF) {
  492. data = i8042_read_data();
  493. dbg("%02x <- i8042 (aux_test_irq, %s)",
  494. data, str & I8042_STR_AUXDATA ? "aux" : "kbd");
  495. if (i8042_irq_being_tested &&
  496. data == 0xa5 && (str & I8042_STR_AUXDATA))
  497. complete(&i8042_aux_irq_delivered);
  498. ret = 1;
  499. }
  500. spin_unlock_irqrestore(&i8042_lock, flags);
  501. return IRQ_RETVAL(ret);
  502. }
  503. /*
  504. * i8042_toggle_aux - enables or disables AUX port on i8042 via command and
  505. * verifies success by readinng CTR. Used when testing for presence of AUX
  506. * port.
  507. */
  508. static int __init i8042_toggle_aux(bool on)
  509. {
  510. unsigned char param;
  511. int i;
  512. if (i8042_command(&param,
  513. on ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE))
  514. return -1;
  515. /* some chips need some time to set the I8042_CTR_AUXDIS bit */
  516. for (i = 0; i < 100; i++) {
  517. udelay(50);
  518. if (i8042_command(&param, I8042_CMD_CTL_RCTR))
  519. return -1;
  520. if (!(param & I8042_CTR_AUXDIS) == on)
  521. return 0;
  522. }
  523. return -1;
  524. }
  525. /*
  526. * i8042_check_aux() applies as much paranoia as it can at detecting
  527. * the presence of an AUX interface.
  528. */
  529. static int __init i8042_check_aux(void)
  530. {
  531. int retval = -1;
  532. bool irq_registered = false;
  533. bool aux_loop_broken = false;
  534. unsigned long flags;
  535. unsigned char param;
  536. /*
  537. * Get rid of bytes in the queue.
  538. */
  539. i8042_flush();
  540. /*
  541. * Internal loopback test - filters out AT-type i8042's. Unfortunately
  542. * SiS screwed up and their 5597 doesn't support the LOOP command even
  543. * though it has an AUX port.
  544. */
  545. param = 0x5a;
  546. retval = i8042_command(&param, I8042_CMD_AUX_LOOP);
  547. if (retval || param != 0x5a) {
  548. /*
  549. * External connection test - filters out AT-soldered PS/2 i8042's
  550. * 0x00 - no error, 0x01-0x03 - clock/data stuck, 0xff - general error
  551. * 0xfa - no error on some notebooks which ignore the spec
  552. * Because it's common for chipsets to return error on perfectly functioning
  553. * AUX ports, we test for this only when the LOOP command failed.
  554. */
  555. if (i8042_command(&param, I8042_CMD_AUX_TEST) ||
  556. (param && param != 0xfa && param != 0xff))
  557. return -1;
  558. /*
  559. * If AUX_LOOP completed without error but returned unexpected data
  560. * mark it as broken
  561. */
  562. if (!retval)
  563. aux_loop_broken = true;
  564. }
  565. /*
  566. * Bit assignment test - filters out PS/2 i8042's in AT mode
  567. */
  568. if (i8042_toggle_aux(false)) {
  569. printk(KERN_WARNING "Failed to disable AUX port, but continuing anyway... Is this a SiS?\n");
  570. printk(KERN_WARNING "If AUX port is really absent please use the 'i8042.noaux' option.\n");
  571. }
  572. if (i8042_toggle_aux(true))
  573. return -1;
  574. /*
  575. * Test AUX IRQ delivery to make sure BIOS did not grab the IRQ and
  576. * used it for a PCI card or somethig else.
  577. */
  578. if (i8042_noloop || i8042_bypass_aux_irq_test || aux_loop_broken) {
  579. /*
  580. * Without LOOP command we can't test AUX IRQ delivery. Assume the port
  581. * is working and hope we are right.
  582. */
  583. retval = 0;
  584. goto out;
  585. }
  586. if (request_irq(I8042_AUX_IRQ, i8042_aux_test_irq, IRQF_SHARED,
  587. "i8042", i8042_platform_device))
  588. goto out;
  589. irq_registered = true;
  590. if (i8042_enable_aux_port())
  591. goto out;
  592. spin_lock_irqsave(&i8042_lock, flags);
  593. init_completion(&i8042_aux_irq_delivered);
  594. i8042_irq_being_tested = true;
  595. param = 0xa5;
  596. retval = __i8042_command(&param, I8042_CMD_AUX_LOOP & 0xf0ff);
  597. spin_unlock_irqrestore(&i8042_lock, flags);
  598. if (retval)
  599. goto out;
  600. if (wait_for_completion_timeout(&i8042_aux_irq_delivered,
  601. msecs_to_jiffies(250)) == 0) {
  602. /*
  603. * AUX IRQ was never delivered so we need to flush the controller to
  604. * get rid of the byte we put there; otherwise keyboard may not work.
  605. */
  606. dbg(" -- i8042 (aux irq test timeout)");
  607. i8042_flush();
  608. retval = -1;
  609. }
  610. out:
  611. /*
  612. * Disable the interface.
  613. */
  614. i8042_ctr |= I8042_CTR_AUXDIS;
  615. i8042_ctr &= ~I8042_CTR_AUXINT;
  616. if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR))
  617. retval = -1;
  618. if (irq_registered)
  619. free_irq(I8042_AUX_IRQ, i8042_platform_device);
  620. return retval;
  621. }
  622. static int i8042_controller_check(void)
  623. {
  624. if (i8042_flush() == I8042_BUFFER_SIZE) {
  625. printk(KERN_ERR "i8042.c: No controller found.\n");
  626. return -ENODEV;
  627. }
  628. return 0;
  629. }
  630. static int i8042_controller_selftest(void)
  631. {
  632. unsigned char param;
  633. int i = 0;
  634. if (!i8042_reset)
  635. return 0;
  636. /*
  637. * We try this 5 times; on some really fragile systems this does not
  638. * take the first time...
  639. */
  640. do {
  641. if (i8042_command(&param, I8042_CMD_CTL_TEST)) {
  642. printk(KERN_ERR "i8042.c: i8042 controller self test timeout.\n");
  643. return -ENODEV;
  644. }
  645. if (param == I8042_RET_CTL_TEST)
  646. return 0;
  647. printk(KERN_ERR "i8042.c: i8042 controller selftest failed. (%#x != %#x)\n",
  648. param, I8042_RET_CTL_TEST);
  649. msleep(50);
  650. } while (i++ < 5);
  651. #ifdef CONFIG_X86
  652. /*
  653. * On x86, we don't fail entire i8042 initialization if controller
  654. * reset fails in hopes that keyboard port will still be functional
  655. * and user will still get a working keyboard. This is especially
  656. * important on netbooks. On other arches we trust hardware more.
  657. */
  658. printk(KERN_INFO
  659. "i8042: giving up on controller selftest, continuing anyway...\n");
  660. return 0;
  661. #else
  662. return -EIO;
  663. #endif
  664. }
  665. /*
  666. * i8042_controller init initializes the i8042 controller, and,
  667. * most importantly, sets it into non-xlated mode if that's
  668. * desired.
  669. */
  670. static int i8042_controller_init(void)
  671. {
  672. unsigned long flags;
  673. int n = 0;
  674. unsigned char ctr[2];
  675. /*
  676. * Save the CTR for restore on unload / reboot.
  677. */
  678. do {
  679. if (n >= 10) {
  680. printk(KERN_ERR
  681. "i8042.c: Unable to get stable CTR read.\n");
  682. return -EIO;
  683. }
  684. if (n != 0)
  685. udelay(50);
  686. if (i8042_command(&ctr[n++ % 2], I8042_CMD_CTL_RCTR)) {
  687. printk(KERN_ERR
  688. "i8042.c: Can't read CTR while initializing i8042.\n");
  689. return -EIO;
  690. }
  691. } while (n < 2 || ctr[0] != ctr[1]);
  692. i8042_initial_ctr = i8042_ctr = ctr[0];
  693. /*
  694. * Disable the keyboard interface and interrupt.
  695. */
  696. i8042_ctr |= I8042_CTR_KBDDIS;
  697. i8042_ctr &= ~I8042_CTR_KBDINT;
  698. /*
  699. * Handle keylock.
  700. */
  701. spin_lock_irqsave(&i8042_lock, flags);
  702. if (~i8042_read_status() & I8042_STR_KEYLOCK) {
  703. if (i8042_unlock)
  704. i8042_ctr |= I8042_CTR_IGNKEYLOCK;
  705. else
  706. printk(KERN_WARNING "i8042.c: Warning: Keylock active.\n");
  707. }
  708. spin_unlock_irqrestore(&i8042_lock, flags);
  709. /*
  710. * If the chip is configured into nontranslated mode by the BIOS, don't
  711. * bother enabling translating and be happy.
  712. */
  713. if (~i8042_ctr & I8042_CTR_XLATE)
  714. i8042_direct = true;
  715. /*
  716. * Set nontranslated mode for the kbd interface if requested by an option.
  717. * After this the kbd interface becomes a simple serial in/out, like the aux
  718. * interface is. We don't do this by default, since it can confuse notebook
  719. * BIOSes.
  720. */
  721. if (i8042_direct)
  722. i8042_ctr &= ~I8042_CTR_XLATE;
  723. /*
  724. * Write CTR back.
  725. */
  726. if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
  727. printk(KERN_ERR "i8042.c: Can't write CTR while initializing i8042.\n");
  728. return -EIO;
  729. }
  730. /*
  731. * Flush whatever accumulated while we were disabling keyboard port.
  732. */
  733. i8042_flush();
  734. return 0;
  735. }
  736. /*
  737. * Reset the controller and reset CRT to the original value set by BIOS.
  738. */
  739. static void i8042_controller_reset(void)
  740. {
  741. i8042_flush();
  742. /*
  743. * Disable both KBD and AUX interfaces so they don't get in the way
  744. */
  745. i8042_ctr |= I8042_CTR_KBDDIS | I8042_CTR_AUXDIS;
  746. i8042_ctr &= ~(I8042_CTR_KBDINT | I8042_CTR_AUXINT);
  747. if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR))
  748. printk(KERN_WARNING "i8042.c: Can't write CTR while resetting.\n");
  749. /*
  750. * Disable MUX mode if present.
  751. */
  752. if (i8042_mux_present)
  753. i8042_set_mux_mode(false, NULL);
  754. /*
  755. * Reset the controller if requested.
  756. */
  757. i8042_controller_selftest();
  758. /*
  759. * Restore the original control register setting.
  760. */
  761. if (i8042_command(&i8042_initial_ctr, I8042_CMD_CTL_WCTR))
  762. printk(KERN_WARNING "i8042.c: Can't restore CTR.\n");
  763. }
  764. /*
  765. * i8042_panic_blink() will flash the keyboard LEDs and is called when
  766. * kernel panics. Flashing LEDs is useful for users running X who may
  767. * not see the console and will help distingushing panics from "real"
  768. * lockups.
  769. *
  770. * Note that DELAY has a limit of 10ms so we will not get stuck here
  771. * waiting for KBC to free up even if KBD interrupt is off
  772. */
  773. #define DELAY do { mdelay(1); if (++delay > 10) return delay; } while(0)
  774. static long i8042_panic_blink(long count)
  775. {
  776. long delay = 0;
  777. static long last_blink;
  778. static char led;
  779. /*
  780. * We expect frequency to be about 1/2s. KDB uses about 1s.
  781. * Make sure they are different.
  782. */
  783. if (!i8042_blink_frequency)
  784. return 0;
  785. if (count - last_blink < i8042_blink_frequency)
  786. return 0;
  787. led ^= 0x01 | 0x04;
  788. while (i8042_read_status() & I8042_STR_IBF)
  789. DELAY;
  790. dbg("%02x -> i8042 (panic blink)", 0xed);
  791. i8042_suppress_kbd_ack = 2;
  792. i8042_write_data(0xed); /* set leds */
  793. DELAY;
  794. while (i8042_read_status() & I8042_STR_IBF)
  795. DELAY;
  796. DELAY;
  797. dbg("%02x -> i8042 (panic blink)", led);
  798. i8042_write_data(led);
  799. DELAY;
  800. last_blink = count;
  801. return delay;
  802. }
  803. #undef DELAY
  804. #ifdef CONFIG_X86
  805. static void i8042_dritek_enable(void)
  806. {
  807. char param = 0x90;
  808. int error;
  809. error = i8042_command(&param, 0x1059);
  810. if (error)
  811. printk(KERN_WARNING
  812. "Failed to enable DRITEK extension: %d\n",
  813. error);
  814. }
  815. #endif
  816. #ifdef CONFIG_PM
  817. /*
  818. * Here we try to restore the original BIOS settings to avoid
  819. * upsetting it.
  820. */
  821. static int i8042_pm_reset(struct device *dev)
  822. {
  823. i8042_controller_reset();
  824. return 0;
  825. }
  826. /*
  827. * Here we try to reset everything back to a state we had
  828. * before suspending.
  829. */
  830. static int i8042_pm_restore(struct device *dev)
  831. {
  832. int error;
  833. error = i8042_controller_check();
  834. if (error)
  835. return error;
  836. error = i8042_controller_selftest();
  837. if (error)
  838. return error;
  839. /*
  840. * Restore original CTR value and disable all ports
  841. */
  842. i8042_ctr = i8042_initial_ctr;
  843. if (i8042_direct)
  844. i8042_ctr &= ~I8042_CTR_XLATE;
  845. i8042_ctr |= I8042_CTR_AUXDIS | I8042_CTR_KBDDIS;
  846. i8042_ctr &= ~(I8042_CTR_AUXINT | I8042_CTR_KBDINT);
  847. if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
  848. printk(KERN_WARNING "i8042: Can't write CTR to resume, retrying...\n");
  849. msleep(50);
  850. if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) {
  851. printk(KERN_ERR "i8042: CTR write retry failed\n");
  852. return -EIO;
  853. }
  854. }
  855. #ifdef CONFIG_X86
  856. if (i8042_dritek)
  857. i8042_dritek_enable();
  858. #endif
  859. if (i8042_mux_present) {
  860. if (i8042_set_mux_mode(true, NULL) || i8042_enable_mux_ports())
  861. printk(KERN_WARNING
  862. "i8042: failed to resume active multiplexor, "
  863. "mouse won't work.\n");
  864. } else if (i8042_ports[I8042_AUX_PORT_NO].serio)
  865. i8042_enable_aux_port();
  866. if (i8042_ports[I8042_KBD_PORT_NO].serio)
  867. i8042_enable_kbd_port();
  868. i8042_interrupt(0, NULL);
  869. return 0;
  870. }
  871. static const struct dev_pm_ops i8042_pm_ops = {
  872. .suspend = i8042_pm_reset,
  873. .resume = i8042_pm_restore,
  874. .poweroff = i8042_pm_reset,
  875. .restore = i8042_pm_restore,
  876. };
  877. #endif /* CONFIG_PM */
  878. /*
  879. * We need to reset the 8042 back to original mode on system shutdown,
  880. * because otherwise BIOSes will be confused.
  881. */
  882. static void i8042_shutdown(struct platform_device *dev)
  883. {
  884. i8042_controller_reset();
  885. }
  886. static int __init i8042_create_kbd_port(void)
  887. {
  888. struct serio *serio;
  889. struct i8042_port *port = &i8042_ports[I8042_KBD_PORT_NO];
  890. serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
  891. if (!serio)
  892. return -ENOMEM;
  893. serio->id.type = i8042_direct ? SERIO_8042 : SERIO_8042_XL;
  894. serio->write = i8042_dumbkbd ? NULL : i8042_kbd_write;
  895. serio->start = i8042_start;
  896. serio->stop = i8042_stop;
  897. serio->close = i8042_port_close;
  898. serio->port_data = port;
  899. serio->dev.parent = &i8042_platform_device->dev;
  900. strlcpy(serio->name, "i8042 KBD port", sizeof(serio->name));
  901. strlcpy(serio->phys, I8042_KBD_PHYS_DESC, sizeof(serio->phys));
  902. port->serio = serio;
  903. port->irq = I8042_KBD_IRQ;
  904. return 0;
  905. }
  906. static int __init i8042_create_aux_port(int idx)
  907. {
  908. struct serio *serio;
  909. int port_no = idx < 0 ? I8042_AUX_PORT_NO : I8042_MUX_PORT_NO + idx;
  910. struct i8042_port *port = &i8042_ports[port_no];
  911. serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
  912. if (!serio)
  913. return -ENOMEM;
  914. serio->id.type = SERIO_8042;
  915. serio->write = i8042_aux_write;
  916. serio->start = i8042_start;
  917. serio->stop = i8042_stop;
  918. serio->port_data = port;
  919. serio->dev.parent = &i8042_platform_device->dev;
  920. if (idx < 0) {
  921. strlcpy(serio->name, "i8042 AUX port", sizeof(serio->name));
  922. strlcpy(serio->phys, I8042_AUX_PHYS_DESC, sizeof(serio->phys));
  923. serio->close = i8042_port_close;
  924. } else {
  925. snprintf(serio->name, sizeof(serio->name), "i8042 AUX%d port", idx);
  926. snprintf(serio->phys, sizeof(serio->phys), I8042_MUX_PHYS_DESC, idx + 1);
  927. }
  928. port->serio = serio;
  929. port->mux = idx;
  930. port->irq = I8042_AUX_IRQ;
  931. return 0;
  932. }
  933. static void __init i8042_free_kbd_port(void)
  934. {
  935. kfree(i8042_ports[I8042_KBD_PORT_NO].serio);
  936. i8042_ports[I8042_KBD_PORT_NO].serio = NULL;
  937. }
  938. static void __init i8042_free_aux_ports(void)
  939. {
  940. int i;
  941. for (i = I8042_AUX_PORT_NO; i < I8042_NUM_PORTS; i++) {
  942. kfree(i8042_ports[i].serio);
  943. i8042_ports[i].serio = NULL;
  944. }
  945. }
  946. static void __init i8042_register_ports(void)
  947. {
  948. int i;
  949. for (i = 0; i < I8042_NUM_PORTS; i++) {
  950. if (i8042_ports[i].serio) {
  951. printk(KERN_INFO "serio: %s at %#lx,%#lx irq %d\n",
  952. i8042_ports[i].serio->name,
  953. (unsigned long) I8042_DATA_REG,
  954. (unsigned long) I8042_COMMAND_REG,
  955. i8042_ports[i].irq);
  956. serio_register_port(i8042_ports[i].serio);
  957. }
  958. }
  959. }
  960. static void __devexit i8042_unregister_ports(void)
  961. {
  962. int i;
  963. for (i = 0; i < I8042_NUM_PORTS; i++) {
  964. if (i8042_ports[i].serio) {
  965. serio_unregister_port(i8042_ports[i].serio);
  966. i8042_ports[i].serio = NULL;
  967. }
  968. }
  969. }
  970. /*
  971. * Checks whether port belongs to i8042 controller.
  972. */
  973. bool i8042_check_port_owner(const struct serio *port)
  974. {
  975. int i;
  976. for (i = 0; i < I8042_NUM_PORTS; i++)
  977. if (i8042_ports[i].serio == port)
  978. return true;
  979. return false;
  980. }
  981. EXPORT_SYMBOL(i8042_check_port_owner);
  982. static void i8042_free_irqs(void)
  983. {
  984. if (i8042_aux_irq_registered)
  985. free_irq(I8042_AUX_IRQ, i8042_platform_device);
  986. if (i8042_kbd_irq_registered)
  987. free_irq(I8042_KBD_IRQ, i8042_platform_device);
  988. i8042_aux_irq_registered = i8042_kbd_irq_registered = false;
  989. }
  990. static int __init i8042_setup_aux(void)
  991. {
  992. int (*aux_enable)(void);
  993. int error;
  994. int i;
  995. if (i8042_check_aux())
  996. return -ENODEV;
  997. if (i8042_nomux || i8042_check_mux()) {
  998. error = i8042_create_aux_port(-1);
  999. if (error)
  1000. goto err_free_ports;
  1001. aux_enable = i8042_enable_aux_port;
  1002. } else {
  1003. for (i = 0; i < I8042_NUM_MUX_PORTS; i++) {
  1004. error = i8042_create_aux_port(i);
  1005. if (error)
  1006. goto err_free_ports;
  1007. }
  1008. aux_enable = i8042_enable_mux_ports;
  1009. }
  1010. error = request_irq(I8042_AUX_IRQ, i8042_interrupt, IRQF_SHARED,
  1011. "i8042", i8042_platform_device);
  1012. if (error)
  1013. goto err_free_ports;
  1014. if (aux_enable())
  1015. goto err_free_irq;
  1016. i8042_aux_irq_registered = true;
  1017. return 0;
  1018. err_free_irq:
  1019. free_irq(I8042_AUX_IRQ, i8042_platform_device);
  1020. err_free_ports:
  1021. i8042_free_aux_ports();
  1022. return error;
  1023. }
  1024. static int __init i8042_setup_kbd(void)
  1025. {
  1026. int error;
  1027. error = i8042_create_kbd_port();
  1028. if (error)
  1029. return error;
  1030. error = request_irq(I8042_KBD_IRQ, i8042_interrupt, IRQF_SHARED,
  1031. "i8042", i8042_platform_device);
  1032. if (error)
  1033. goto err_free_port;
  1034. error = i8042_enable_kbd_port();
  1035. if (error)
  1036. goto err_free_irq;
  1037. i8042_kbd_irq_registered = true;
  1038. return 0;
  1039. err_free_irq:
  1040. free_irq(I8042_KBD_IRQ, i8042_platform_device);
  1041. err_free_port:
  1042. i8042_free_kbd_port();
  1043. return error;
  1044. }
  1045. static int __init i8042_probe(struct platform_device *dev)
  1046. {
  1047. int error;
  1048. error = i8042_controller_selftest();
  1049. if (error)
  1050. return error;
  1051. error = i8042_controller_init();
  1052. if (error)
  1053. return error;
  1054. #ifdef CONFIG_X86
  1055. if (i8042_dritek)
  1056. i8042_dritek_enable();
  1057. #endif
  1058. if (!i8042_noaux) {
  1059. error = i8042_setup_aux();
  1060. if (error && error != -ENODEV && error != -EBUSY)
  1061. goto out_fail;
  1062. }
  1063. if (!i8042_nokbd) {
  1064. error = i8042_setup_kbd();
  1065. if (error)
  1066. goto out_fail;
  1067. }
  1068. /*
  1069. * Ok, everything is ready, let's register all serio ports
  1070. */
  1071. i8042_register_ports();
  1072. return 0;
  1073. out_fail:
  1074. i8042_free_aux_ports(); /* in case KBD failed but AUX not */
  1075. i8042_free_irqs();
  1076. i8042_controller_reset();
  1077. return error;
  1078. }
  1079. static int __devexit i8042_remove(struct platform_device *dev)
  1080. {
  1081. i8042_unregister_ports();
  1082. i8042_free_irqs();
  1083. i8042_controller_reset();
  1084. return 0;
  1085. }
  1086. static struct platform_driver i8042_driver = {
  1087. .driver = {
  1088. .name = "i8042",
  1089. .owner = THIS_MODULE,
  1090. #ifdef CONFIG_PM
  1091. .pm = &i8042_pm_ops,
  1092. #endif
  1093. },
  1094. .remove = __devexit_p(i8042_remove),
  1095. .shutdown = i8042_shutdown,
  1096. };
  1097. static int __init i8042_init(void)
  1098. {
  1099. int err;
  1100. dbg_init();
  1101. err = i8042_platform_init();
  1102. if (err)
  1103. return err;
  1104. err = i8042_controller_check();
  1105. if (err)
  1106. goto err_platform_exit;
  1107. i8042_platform_device = platform_device_alloc("i8042", -1);
  1108. if (!i8042_platform_device) {
  1109. err = -ENOMEM;
  1110. goto err_platform_exit;
  1111. }
  1112. err = platform_device_add(i8042_platform_device);
  1113. if (err)
  1114. goto err_free_device;
  1115. err = platform_driver_probe(&i8042_driver, i8042_probe);
  1116. if (err)
  1117. goto err_del_device;
  1118. panic_blink = i8042_panic_blink;
  1119. return 0;
  1120. err_del_device:
  1121. platform_device_del(i8042_platform_device);
  1122. err_free_device:
  1123. platform_device_put(i8042_platform_device);
  1124. err_platform_exit:
  1125. i8042_platform_exit();
  1126. return err;
  1127. }
  1128. static void __exit i8042_exit(void)
  1129. {
  1130. platform_driver_unregister(&i8042_driver);
  1131. platform_device_unregister(i8042_platform_device);
  1132. i8042_platform_exit();
  1133. panic_blink = NULL;
  1134. }
  1135. module_init(i8042_init);
  1136. module_exit(i8042_exit);