i8042.c 33 KB

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