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