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 | /* |
| 372 | * i8042_interrupt() is the most important function in this driver - |
| 373 | * it handles the interrupts from the i8042, and sends incoming bytes |
| 374 | * to the upper layers. |
| 375 | */ |
| 376 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 377 | static irqreturn_t i8042_interrupt(int irq, void *dev_id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 378 | { |
| 379 | struct i8042_port *port; |
| 380 | unsigned long flags; |
| 381 | unsigned char str, data; |
| 382 | unsigned int dfl; |
| 383 | unsigned int port_no; |
Dmitry Torokhov | 817e6ba | 2006-10-11 01:44:28 -0400 | [diff] [blame] | 384 | int ret = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | spin_lock_irqsave(&i8042_lock, flags); |
| 387 | str = i8042_read_status(); |
| 388 | if (unlikely(~str & I8042_STR_OBF)) { |
| 389 | spin_unlock_irqrestore(&i8042_lock, flags); |
| 390 | if (irq) dbg("Interrupt %d, without any data", irq); |
| 391 | ret = 0; |
| 392 | goto out; |
| 393 | } |
| 394 | data = i8042_read_data(); |
| 395 | spin_unlock_irqrestore(&i8042_lock, flags); |
| 396 | |
| 397 | if (i8042_mux_present && (str & I8042_STR_AUXDATA)) { |
| 398 | static unsigned long last_transmit; |
| 399 | static unsigned char last_str; |
| 400 | |
| 401 | dfl = 0; |
| 402 | if (str & I8042_STR_MUXERR) { |
| 403 | dbg("MUX error, status is %02x, data is %02x", str, data); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | /* |
| 405 | * When MUXERR condition is signalled the data register can only contain |
| 406 | * 0xfd, 0xfe or 0xff if implementation follows the spec. Unfortunately |
Dmitry Torokhov | a216a4b | 2006-11-17 01:07:06 -0500 | [diff] [blame] | 407 | * it is not always the case. Some KBCs also report 0xfc when there is |
| 408 | * nothing connected to the port while others sometimes get confused which |
| 409 | * port the data came from and signal error leaving the data intact. They |
| 410 | * _do not_ revert to legacy mode (actually I've never seen KBC reverting |
| 411 | * to legacy mode yet, when we see one we'll add proper handling). |
| 412 | * Anyway, we process 0xfc, 0xfd, 0xfe and 0xff as timeouts, and for the |
| 413 | * rest assume that the data came from the same serio last byte |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | * was transmitted (if transmission happened not too long ago). |
| 415 | */ |
Dmitry Torokhov | a216a4b | 2006-11-17 01:07:06 -0500 | [diff] [blame] | 416 | |
| 417 | switch (data) { |
| 418 | default: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | if (time_before(jiffies, last_transmit + HZ/10)) { |
| 420 | str = last_str; |
| 421 | break; |
| 422 | } |
| 423 | /* fall through - report timeout */ |
Dmitry Torokhov | a216a4b | 2006-11-17 01:07:06 -0500 | [diff] [blame] | 424 | case 0xfc: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | case 0xfd: |
| 426 | case 0xfe: dfl = SERIO_TIMEOUT; data = 0xfe; break; |
| 427 | case 0xff: dfl = SERIO_PARITY; data = 0xfe; break; |
| 428 | } |
| 429 | } |
| 430 | |
| 431 | port_no = I8042_MUX_PORT_NO + ((str >> 6) & 3); |
| 432 | last_str = str; |
| 433 | last_transmit = jiffies; |
| 434 | } else { |
| 435 | |
| 436 | dfl = ((str & I8042_STR_PARITY) ? SERIO_PARITY : 0) | |
| 437 | ((str & I8042_STR_TIMEOUT) ? SERIO_TIMEOUT : 0); |
| 438 | |
| 439 | port_no = (str & I8042_STR_AUXDATA) ? |
| 440 | I8042_AUX_PORT_NO : I8042_KBD_PORT_NO; |
| 441 | } |
| 442 | |
| 443 | port = &i8042_ports[port_no]; |
| 444 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 445 | dbg("%02x <- i8042 (interrupt, %d, %d%s%s)", |
| 446 | data, port_no, irq, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | dfl & SERIO_PARITY ? ", bad parity" : "", |
| 448 | dfl & SERIO_TIMEOUT ? ", timeout" : ""); |
| 449 | |
Dmitry Torokhov | 817e6ba | 2006-10-11 01:44:28 -0400 | [diff] [blame] | 450 | if (unlikely(i8042_suppress_kbd_ack)) |
| 451 | if (port_no == I8042_KBD_PORT_NO && |
| 452 | (data == 0xfa || data == 0xfe)) { |
Dmitry Torokhov | 19f3c3e | 2007-01-18 00:42:31 -0500 | [diff] [blame] | 453 | i8042_suppress_kbd_ack--; |
Dmitry Torokhov | 817e6ba | 2006-10-11 01:44:28 -0400 | [diff] [blame] | 454 | goto out; |
| 455 | } |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | if (likely(port->exists)) |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 458 | serio_interrupt(port->serio, data, dfl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 460 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | return IRQ_RETVAL(ret); |
| 462 | } |
| 463 | |
| 464 | /* |
Dmitry Torokhov | 5ddbc77 | 2009-09-09 19:08:15 -0700 | [diff] [blame] | 465 | * i8042_enable_kbd_port enables keyboard port on chip |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 466 | */ |
| 467 | |
| 468 | static int i8042_enable_kbd_port(void) |
| 469 | { |
| 470 | i8042_ctr &= ~I8042_CTR_KBDDIS; |
| 471 | i8042_ctr |= I8042_CTR_KBDINT; |
| 472 | |
| 473 | if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) { |
Markus Armbruster | 018db6b | 2007-07-18 01:20:41 -0400 | [diff] [blame] | 474 | i8042_ctr &= ~I8042_CTR_KBDINT; |
| 475 | i8042_ctr |= I8042_CTR_KBDDIS; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 476 | printk(KERN_ERR "i8042.c: Failed to enable KBD port.\n"); |
| 477 | return -EIO; |
| 478 | } |
| 479 | |
| 480 | return 0; |
| 481 | } |
| 482 | |
| 483 | /* |
| 484 | * i8042_enable_aux_port enables AUX (mouse) port on chip |
| 485 | */ |
| 486 | |
| 487 | static int i8042_enable_aux_port(void) |
| 488 | { |
| 489 | i8042_ctr &= ~I8042_CTR_AUXDIS; |
| 490 | i8042_ctr |= I8042_CTR_AUXINT; |
| 491 | |
| 492 | if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) { |
Markus Armbruster | 018db6b | 2007-07-18 01:20:41 -0400 | [diff] [blame] | 493 | i8042_ctr &= ~I8042_CTR_AUXINT; |
| 494 | i8042_ctr |= I8042_CTR_AUXDIS; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 495 | printk(KERN_ERR "i8042.c: Failed to enable AUX port.\n"); |
| 496 | return -EIO; |
| 497 | } |
| 498 | |
| 499 | return 0; |
| 500 | } |
| 501 | |
| 502 | /* |
| 503 | * i8042_enable_mux_ports enables 4 individual AUX ports after |
| 504 | * the controller has been switched into Multiplexed mode |
| 505 | */ |
| 506 | |
| 507 | static int i8042_enable_mux_ports(void) |
| 508 | { |
| 509 | unsigned char param; |
| 510 | int i; |
| 511 | |
| 512 | for (i = 0; i < I8042_NUM_MUX_PORTS; i++) { |
| 513 | i8042_command(¶m, I8042_CMD_MUX_PFX + i); |
| 514 | i8042_command(¶m, I8042_CMD_AUX_ENABLE); |
| 515 | } |
| 516 | |
| 517 | return i8042_enable_aux_port(); |
| 518 | } |
| 519 | |
| 520 | /* |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 521 | * i8042_set_mux_mode checks whether the controller has an |
| 522 | * active multiplexor and puts the chip into Multiplexed (true) |
| 523 | * or Legacy (false) mode. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | */ |
| 525 | |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 526 | static int i8042_set_mux_mode(bool multiplex, unsigned char *mux_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | { |
| 528 | |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 529 | unsigned char param, val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | /* |
| 531 | * Get rid of bytes in the queue. |
| 532 | */ |
| 533 | |
| 534 | i8042_flush(); |
| 535 | |
| 536 | /* |
| 537 | * Internal loopback test - send three bytes, they should come back from the |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 538 | * mouse interface, the last should be version. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | */ |
| 540 | |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 541 | param = val = 0xf0; |
| 542 | if (i8042_command(¶m, I8042_CMD_AUX_LOOP) || param != val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | return -1; |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 544 | param = val = multiplex ? 0x56 : 0xf6; |
| 545 | if (i8042_command(¶m, I8042_CMD_AUX_LOOP) || param != val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | return -1; |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 547 | param = val = multiplex ? 0xa4 : 0xa5; |
| 548 | if (i8042_command(¶m, I8042_CMD_AUX_LOOP) || param == val) |
| 549 | return -1; |
| 550 | |
| 551 | /* |
| 552 | * Workaround for interference with USB Legacy emulation |
| 553 | * that causes a v10.12 MUX to be found. |
| 554 | */ |
| 555 | if (param == 0xac) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | return -1; |
| 557 | |
| 558 | if (mux_version) |
Dmitry Torokhov | 463a4f7 | 2005-07-15 01:51:56 -0500 | [diff] [blame] | 559 | *mux_version = param; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
| 561 | return 0; |
| 562 | } |
| 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | /* |
| 565 | * i8042_check_mux() checks whether the controller supports the PS/2 Active |
| 566 | * Multiplexing specification by Synaptics, Phoenix, Insyde and |
| 567 | * LCS/Telegraphics. |
| 568 | */ |
| 569 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 570 | static int __init i8042_check_mux(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | { |
| 572 | unsigned char mux_version; |
| 573 | |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 574 | if (i8042_set_mux_mode(true, &mux_version)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 575 | return -1; |
| 576 | |
| 577 | printk(KERN_INFO "i8042.c: Detected active multiplexing controller, rev %d.%d.\n", |
| 578 | (mux_version >> 4) & 0xf, mux_version & 0xf); |
| 579 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 580 | /* |
| 581 | * Disable all muxed ports by disabling AUX. |
| 582 | */ |
| 583 | i8042_ctr |= I8042_CTR_AUXDIS; |
| 584 | i8042_ctr &= ~I8042_CTR_AUXINT; |
| 585 | |
| 586 | if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) { |
| 587 | printk(KERN_ERR "i8042.c: Failed to disable AUX port, can't use MUX.\n"); |
| 588 | return -EIO; |
| 589 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 591 | i8042_mux_present = true; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | return 0; |
| 594 | } |
| 595 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 596 | /* |
| 597 | * The following is used to test AUX IRQ delivery. |
| 598 | */ |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 599 | static struct completion i8042_aux_irq_delivered __initdata; |
| 600 | static bool i8042_irq_being_tested __initdata; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 601 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 602 | 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] | 603 | { |
| 604 | unsigned long flags; |
| 605 | unsigned char str, data; |
Fernando Luis Vázquez Cao | e3758b2 | 2007-08-30 00:04:15 -0400 | [diff] [blame] | 606 | int ret = 0; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 607 | |
| 608 | spin_lock_irqsave(&i8042_lock, flags); |
| 609 | str = i8042_read_status(); |
| 610 | if (str & I8042_STR_OBF) { |
| 611 | data = i8042_read_data(); |
| 612 | if (i8042_irq_being_tested && |
| 613 | data == 0xa5 && (str & I8042_STR_AUXDATA)) |
| 614 | complete(&i8042_aux_irq_delivered); |
Fernando Luis Vázquez Cao | e3758b2 | 2007-08-30 00:04:15 -0400 | [diff] [blame] | 615 | ret = 1; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 616 | } |
| 617 | spin_unlock_irqrestore(&i8042_lock, flags); |
| 618 | |
Fernando Luis Vázquez Cao | e3758b2 | 2007-08-30 00:04:15 -0400 | [diff] [blame] | 619 | return IRQ_RETVAL(ret); |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 620 | } |
| 621 | |
Roland Scheidegger | d2ada55 | 2007-05-08 01:31:40 -0400 | [diff] [blame] | 622 | /* |
| 623 | * i8042_toggle_aux - enables or disables AUX port on i8042 via command and |
| 624 | * verifies success by readinng CTR. Used when testing for presence of AUX |
| 625 | * port. |
| 626 | */ |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 627 | static int __init i8042_toggle_aux(bool on) |
Roland Scheidegger | d2ada55 | 2007-05-08 01:31:40 -0400 | [diff] [blame] | 628 | { |
| 629 | unsigned char param; |
| 630 | int i; |
| 631 | |
| 632 | if (i8042_command(¶m, |
| 633 | on ? I8042_CMD_AUX_ENABLE : I8042_CMD_AUX_DISABLE)) |
| 634 | return -1; |
| 635 | |
| 636 | /* some chips need some time to set the I8042_CTR_AUXDIS bit */ |
| 637 | for (i = 0; i < 100; i++) { |
| 638 | udelay(50); |
| 639 | |
| 640 | if (i8042_command(¶m, I8042_CMD_CTL_RCTR)) |
| 641 | return -1; |
| 642 | |
| 643 | if (!(param & I8042_CTR_AUXDIS) == on) |
| 644 | return 0; |
| 645 | } |
| 646 | |
| 647 | return -1; |
| 648 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 | |
| 650 | /* |
| 651 | * i8042_check_aux() applies as much paranoia as it can at detecting |
| 652 | * the presence of an AUX interface. |
| 653 | */ |
| 654 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 655 | static int __init i8042_check_aux(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | { |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 657 | int retval = -1; |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 658 | bool irq_registered = false; |
| 659 | bool aux_loop_broken = false; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 660 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | unsigned char param; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | |
| 663 | /* |
| 664 | * Get rid of bytes in the queue. |
| 665 | */ |
| 666 | |
| 667 | i8042_flush(); |
| 668 | |
| 669 | /* |
| 670 | * Internal loopback test - filters out AT-type i8042's. Unfortunately |
| 671 | * SiS screwed up and their 5597 doesn't support the LOOP command even |
| 672 | * though it has an AUX port. |
| 673 | */ |
| 674 | |
| 675 | param = 0x5a; |
Dmitry Torokhov | 3ca5de6 | 2007-03-07 23:20:55 -0500 | [diff] [blame] | 676 | retval = i8042_command(¶m, I8042_CMD_AUX_LOOP); |
| 677 | if (retval || param != 0x5a) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | |
| 679 | /* |
| 680 | * External connection test - filters out AT-soldered PS/2 i8042's |
| 681 | * 0x00 - no error, 0x01-0x03 - clock/data stuck, 0xff - general error |
| 682 | * 0xfa - no error on some notebooks which ignore the spec |
| 683 | * Because it's common for chipsets to return error on perfectly functioning |
| 684 | * AUX ports, we test for this only when the LOOP command failed. |
| 685 | */ |
| 686 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 687 | if (i8042_command(¶m, I8042_CMD_AUX_TEST) || |
| 688 | (param && param != 0xfa && param != 0xff)) |
| 689 | return -1; |
Dmitry Torokhov | 1e4865f | 2007-02-10 01:29:53 -0500 | [diff] [blame] | 690 | |
Dmitry Torokhov | 3ca5de6 | 2007-03-07 23:20:55 -0500 | [diff] [blame] | 691 | /* |
| 692 | * If AUX_LOOP completed without error but returned unexpected data |
| 693 | * mark it as broken |
| 694 | */ |
| 695 | if (!retval) |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 696 | aux_loop_broken = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | /* |
| 700 | * Bit assignment test - filters out PS/2 i8042's in AT mode |
| 701 | */ |
| 702 | |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 703 | if (i8042_toggle_aux(false)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | printk(KERN_WARNING "Failed to disable AUX port, but continuing anyway... Is this a SiS?\n"); |
| 705 | printk(KERN_WARNING "If AUX port is really absent please use the 'i8042.noaux' option.\n"); |
| 706 | } |
| 707 | |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 708 | if (i8042_toggle_aux(true)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | return -1; |
| 710 | |
| 711 | /* |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 712 | * Test AUX IRQ delivery to make sure BIOS did not grab the IRQ and |
| 713 | * used it for a PCI card or somethig else. |
| 714 | */ |
| 715 | |
Dmitry Torokhov | 1c7827a | 2009-09-03 21:45:34 -0700 | [diff] [blame] | 716 | if (i8042_noloop || i8042_bypass_aux_irq_test || aux_loop_broken) { |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 717 | /* |
| 718 | * Without LOOP command we can't test AUX IRQ delivery. Assume the port |
| 719 | * is working and hope we are right. |
| 720 | */ |
| 721 | retval = 0; |
| 722 | goto out; |
| 723 | } |
| 724 | |
| 725 | if (request_irq(I8042_AUX_IRQ, i8042_aux_test_irq, IRQF_SHARED, |
| 726 | "i8042", i8042_platform_device)) |
| 727 | goto out; |
| 728 | |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 729 | irq_registered = true; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 730 | |
| 731 | if (i8042_enable_aux_port()) |
| 732 | goto out; |
| 733 | |
| 734 | spin_lock_irqsave(&i8042_lock, flags); |
| 735 | |
| 736 | init_completion(&i8042_aux_irq_delivered); |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 737 | i8042_irq_being_tested = true; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 738 | |
| 739 | param = 0xa5; |
| 740 | retval = __i8042_command(¶m, I8042_CMD_AUX_LOOP & 0xf0ff); |
| 741 | |
| 742 | spin_unlock_irqrestore(&i8042_lock, flags); |
| 743 | |
| 744 | if (retval) |
| 745 | goto out; |
| 746 | |
| 747 | if (wait_for_completion_timeout(&i8042_aux_irq_delivered, |
| 748 | msecs_to_jiffies(250)) == 0) { |
| 749 | /* |
| 750 | * AUX IRQ was never delivered so we need to flush the controller to |
| 751 | * get rid of the byte we put there; otherwise keyboard may not work. |
| 752 | */ |
| 753 | i8042_flush(); |
| 754 | retval = -1; |
| 755 | } |
| 756 | |
| 757 | out: |
| 758 | |
| 759 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | * Disable the interface. |
| 761 | */ |
| 762 | |
| 763 | i8042_ctr |= I8042_CTR_AUXDIS; |
| 764 | i8042_ctr &= ~I8042_CTR_AUXINT; |
| 765 | |
| 766 | if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 767 | retval = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 769 | if (irq_registered) |
| 770 | free_irq(I8042_AUX_IRQ, i8042_platform_device); |
| 771 | |
| 772 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | } |
| 774 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 775 | static int i8042_controller_check(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | { |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 777 | if (i8042_flush() == I8042_BUFFER_SIZE) { |
| 778 | printk(KERN_ERR "i8042.c: No controller found.\n"); |
| 779 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | } |
| 781 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | return 0; |
| 783 | } |
| 784 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 785 | static int i8042_controller_selftest(void) |
Vojtech Pavlik | 2673c836 | 2005-05-28 02:11:27 -0500 | [diff] [blame] | 786 | { |
| 787 | unsigned char param; |
Arjan van de Ven | 5ea2fc6 | 2009-04-09 11:36:50 -0700 | [diff] [blame] | 788 | int i = 0; |
Vojtech Pavlik | 2673c836 | 2005-05-28 02:11:27 -0500 | [diff] [blame] | 789 | |
| 790 | if (!i8042_reset) |
| 791 | return 0; |
| 792 | |
Arjan van de Ven | 5ea2fc6 | 2009-04-09 11:36:50 -0700 | [diff] [blame] | 793 | /* |
| 794 | * We try this 5 times; on some really fragile systems this does not |
| 795 | * take the first time... |
| 796 | */ |
| 797 | do { |
Vojtech Pavlik | 2673c836 | 2005-05-28 02:11:27 -0500 | [diff] [blame] | 798 | |
Arjan van de Ven | 5ea2fc6 | 2009-04-09 11:36:50 -0700 | [diff] [blame] | 799 | if (i8042_command(¶m, I8042_CMD_CTL_TEST)) { |
| 800 | printk(KERN_ERR "i8042.c: i8042 controller self test timeout.\n"); |
| 801 | return -ENODEV; |
| 802 | } |
| 803 | |
| 804 | if (param == I8042_RET_CTL_TEST) |
| 805 | return 0; |
| 806 | |
Vojtech Pavlik | 2673c836 | 2005-05-28 02:11:27 -0500 | [diff] [blame] | 807 | 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] | 808 | param, I8042_RET_CTL_TEST); |
| 809 | msleep(50); |
| 810 | } while (i++ < 5); |
Vojtech Pavlik | 2673c836 | 2005-05-28 02:11:27 -0500 | [diff] [blame] | 811 | |
Arjan van de Ven | 5ea2fc6 | 2009-04-09 11:36:50 -0700 | [diff] [blame] | 812 | #ifdef CONFIG_X86 |
| 813 | /* |
| 814 | * On x86, we don't fail entire i8042 initialization if controller |
| 815 | * reset fails in hopes that keyboard port will still be functional |
| 816 | * and user will still get a working keyboard. This is especially |
| 817 | * important on netbooks. On other arches we trust hardware more. |
| 818 | */ |
| 819 | printk(KERN_INFO |
| 820 | "i8042: giving up on controller selftest, continuing anyway...\n"); |
Vojtech Pavlik | 2673c836 | 2005-05-28 02:11:27 -0500 | [diff] [blame] | 821 | return 0; |
Arjan van de Ven | 5ea2fc6 | 2009-04-09 11:36:50 -0700 | [diff] [blame] | 822 | #else |
| 823 | return -EIO; |
| 824 | #endif |
Vojtech Pavlik | 2673c836 | 2005-05-28 02:11:27 -0500 | [diff] [blame] | 825 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | |
| 827 | /* |
| 828 | * i8042_controller init initializes the i8042 controller, and, |
| 829 | * most importantly, sets it into non-xlated mode if that's |
| 830 | * desired. |
| 831 | */ |
| 832 | |
| 833 | static int i8042_controller_init(void) |
| 834 | { |
| 835 | unsigned long flags; |
| 836 | |
| 837 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | * Save the CTR for restoral on unload / reboot. |
| 839 | */ |
| 840 | |
| 841 | if (i8042_command(&i8042_ctr, I8042_CMD_CTL_RCTR)) { |
| 842 | printk(KERN_ERR "i8042.c: Can't read CTR while initializing i8042.\n"); |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 843 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | } |
| 845 | |
| 846 | i8042_initial_ctr = i8042_ctr; |
| 847 | |
| 848 | /* |
| 849 | * Disable the keyboard interface and interrupt. |
| 850 | */ |
| 851 | |
| 852 | i8042_ctr |= I8042_CTR_KBDDIS; |
| 853 | i8042_ctr &= ~I8042_CTR_KBDINT; |
| 854 | |
| 855 | /* |
| 856 | * Handle keylock. |
| 857 | */ |
| 858 | |
| 859 | spin_lock_irqsave(&i8042_lock, flags); |
| 860 | if (~i8042_read_status() & I8042_STR_KEYLOCK) { |
| 861 | if (i8042_unlock) |
| 862 | i8042_ctr |= I8042_CTR_IGNKEYLOCK; |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 863 | else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | printk(KERN_WARNING "i8042.c: Warning: Keylock active.\n"); |
| 865 | } |
| 866 | spin_unlock_irqrestore(&i8042_lock, flags); |
| 867 | |
| 868 | /* |
| 869 | * If the chip is configured into nontranslated mode by the BIOS, don't |
| 870 | * bother enabling translating and be happy. |
| 871 | */ |
| 872 | |
| 873 | if (~i8042_ctr & I8042_CTR_XLATE) |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 874 | i8042_direct = true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | |
| 876 | /* |
| 877 | * Set nontranslated mode for the kbd interface if requested by an option. |
| 878 | * After this the kbd interface becomes a simple serial in/out, like the aux |
| 879 | * interface is. We don't do this by default, since it can confuse notebook |
| 880 | * BIOSes. |
| 881 | */ |
| 882 | |
| 883 | if (i8042_direct) |
| 884 | i8042_ctr &= ~I8042_CTR_XLATE; |
| 885 | |
| 886 | /* |
| 887 | * Write CTR back. |
| 888 | */ |
| 889 | |
| 890 | if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) { |
| 891 | 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] | 892 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 893 | } |
| 894 | |
| 895 | return 0; |
| 896 | } |
| 897 | |
| 898 | |
| 899 | /* |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 900 | * 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] | 901 | */ |
| 902 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 903 | static void i8042_controller_reset(void) |
| 904 | { |
| 905 | i8042_flush(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | |
| 907 | /* |
Dmitry Torokhov | 8d04ddb | 2007-04-12 01:32:09 -0400 | [diff] [blame] | 908 | * Disable both KBD and AUX interfaces so they don't get in the way |
| 909 | */ |
| 910 | |
| 911 | i8042_ctr |= I8042_CTR_KBDDIS | I8042_CTR_AUXDIS; |
| 912 | i8042_ctr &= ~(I8042_CTR_KBDINT | I8042_CTR_AUXINT); |
| 913 | |
Dmitry Torokhov | 5ddbc77 | 2009-09-09 19:08:15 -0700 | [diff] [blame] | 914 | if (i8042_command(&i8042_initial_ctr, I8042_CMD_CTL_WCTR)) |
| 915 | printk(KERN_WARNING "i8042.c: Can't write CTR while resetting.\n"); |
| 916 | |
Dmitry Torokhov | 8d04ddb | 2007-04-12 01:32:09 -0400 | [diff] [blame] | 917 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | * Disable MUX mode if present. |
| 919 | */ |
| 920 | |
| 921 | if (i8042_mux_present) |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 922 | i8042_set_mux_mode(false, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | |
| 924 | /* |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 925 | * Reset the controller if requested. |
| 926 | */ |
| 927 | |
| 928 | i8042_controller_selftest(); |
| 929 | |
| 930 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 931 | * Restore the original control register setting. |
| 932 | */ |
| 933 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 934 | if (i8042_command(&i8042_initial_ctr, I8042_CMD_CTL_WCTR)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | printk(KERN_WARNING "i8042.c: Can't restore CTR.\n"); |
| 936 | } |
| 937 | |
| 938 | |
| 939 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | * i8042_panic_blink() will flash the keyboard LEDs and is called when |
| 941 | * kernel panics. Flashing LEDs is useful for users running X who may |
| 942 | * not see the console and will help distingushing panics from "real" |
| 943 | * lockups. |
| 944 | * |
| 945 | * Note that DELAY has a limit of 10ms so we will not get stuck here |
| 946 | * waiting for KBC to free up even if KBD interrupt is off |
| 947 | */ |
| 948 | |
| 949 | #define DELAY do { mdelay(1); if (++delay > 10) return delay; } while(0) |
| 950 | |
| 951 | static long i8042_panic_blink(long count) |
| 952 | { |
| 953 | long delay = 0; |
| 954 | static long last_blink; |
| 955 | static char led; |
| 956 | |
| 957 | /* |
| 958 | * We expect frequency to be about 1/2s. KDB uses about 1s. |
| 959 | * Make sure they are different. |
| 960 | */ |
| 961 | if (!i8042_blink_frequency) |
| 962 | return 0; |
| 963 | if (count - last_blink < i8042_blink_frequency) |
| 964 | return 0; |
| 965 | |
| 966 | led ^= 0x01 | 0x04; |
| 967 | while (i8042_read_status() & I8042_STR_IBF) |
| 968 | DELAY; |
Dmitry Torokhov | 19f3c3e | 2007-01-18 00:42:31 -0500 | [diff] [blame] | 969 | dbg("%02x -> i8042 (panic blink)", 0xed); |
| 970 | i8042_suppress_kbd_ack = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | i8042_write_data(0xed); /* set leds */ |
| 972 | DELAY; |
| 973 | while (i8042_read_status() & I8042_STR_IBF) |
| 974 | DELAY; |
| 975 | DELAY; |
Dmitry Torokhov | 19f3c3e | 2007-01-18 00:42:31 -0500 | [diff] [blame] | 976 | dbg("%02x -> i8042 (panic blink)", led); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | i8042_write_data(led); |
| 978 | DELAY; |
| 979 | last_blink = count; |
| 980 | return delay; |
| 981 | } |
| 982 | |
| 983 | #undef DELAY |
| 984 | |
Bruno Prémont | d35895d | 2008-05-27 01:36:04 -0400 | [diff] [blame] | 985 | #ifdef CONFIG_X86 |
| 986 | static void i8042_dritek_enable(void) |
| 987 | { |
| 988 | char param = 0x90; |
| 989 | int error; |
| 990 | |
| 991 | error = i8042_command(¶m, 0x1059); |
| 992 | if (error) |
| 993 | printk(KERN_WARNING |
| 994 | "Failed to enable DRITEK extension: %d\n", |
| 995 | error); |
| 996 | } |
| 997 | #endif |
| 998 | |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 999 | #ifdef CONFIG_PM |
Dmitry Torokhov | 7e044e0 | 2009-05-09 16:08:05 -0700 | [diff] [blame] | 1000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | /* |
Dmitry Torokhov | ebd7768 | 2009-07-22 21:51:32 -0700 | [diff] [blame] | 1002 | * Here we try to restore the original BIOS settings to avoid |
| 1003 | * upsetting it. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | */ |
| 1005 | |
Dmitry Torokhov | ebd7768 | 2009-07-22 21:51:32 -0700 | [diff] [blame] | 1006 | static int i8042_pm_reset(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | { |
Dmitry Torokhov | ebd7768 | 2009-07-22 21:51:32 -0700 | [diff] [blame] | 1008 | i8042_controller_reset(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | |
| 1010 | return 0; |
| 1011 | } |
| 1012 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1013 | /* |
Dmitry Torokhov | ebd7768 | 2009-07-22 21:51:32 -0700 | [diff] [blame] | 1014 | * Here we try to reset everything back to a state we had |
| 1015 | * before suspending. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | */ |
| 1017 | |
Dmitry Torokhov | ebd7768 | 2009-07-22 21:51:32 -0700 | [diff] [blame] | 1018 | static int i8042_pm_restore(struct device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | { |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1020 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1021 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1022 | error = i8042_controller_check(); |
| 1023 | if (error) |
| 1024 | return error; |
Vojtech Pavlik | 2673c836 | 2005-05-28 02:11:27 -0500 | [diff] [blame] | 1025 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1026 | error = i8042_controller_selftest(); |
| 1027 | if (error) |
| 1028 | return error; |
| 1029 | |
| 1030 | /* |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 1031 | * Restore original CTR value and disable all ports |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1032 | */ |
| 1033 | |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 1034 | i8042_ctr = i8042_initial_ctr; |
| 1035 | if (i8042_direct) |
| 1036 | i8042_ctr &= ~I8042_CTR_XLATE; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1037 | i8042_ctr |= I8042_CTR_AUXDIS | I8042_CTR_KBDDIS; |
| 1038 | i8042_ctr &= ~(I8042_CTR_AUXINT | I8042_CTR_KBDINT); |
Vojtech Pavlik | 2673c836 | 2005-05-28 02:11:27 -0500 | [diff] [blame] | 1039 | if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) { |
Jiri Kosina | 2f6a77d | 2008-06-17 11:47:27 -0400 | [diff] [blame] | 1040 | printk(KERN_WARNING "i8042: Can't write CTR to resume, retrying...\n"); |
| 1041 | msleep(50); |
| 1042 | if (i8042_command(&i8042_ctr, I8042_CMD_CTL_WCTR)) { |
| 1043 | printk(KERN_ERR "i8042: CTR write retry failed\n"); |
| 1044 | return -EIO; |
| 1045 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
Bruno Prémont | d35895d | 2008-05-27 01:36:04 -0400 | [diff] [blame] | 1048 | |
| 1049 | #ifdef CONFIG_X86 |
| 1050 | if (i8042_dritek) |
| 1051 | i8042_dritek_enable(); |
| 1052 | #endif |
| 1053 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1054 | if (i8042_mux_present) { |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 1055 | if (i8042_set_mux_mode(true, NULL) || i8042_enable_mux_ports()) |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1056 | printk(KERN_WARNING |
| 1057 | "i8042: failed to resume active multiplexor, " |
| 1058 | "mouse won't work.\n"); |
| 1059 | } else if (i8042_ports[I8042_AUX_PORT_NO].serio) |
| 1060 | i8042_enable_aux_port(); |
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 | if (i8042_ports[I8042_KBD_PORT_NO].serio) |
| 1063 | i8042_enable_kbd_port(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 1065 | i8042_interrupt(0, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | |
| 1067 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | } |
Dmitry Torokhov | ebd7768 | 2009-07-22 21:51:32 -0700 | [diff] [blame] | 1069 | |
| 1070 | static const struct dev_pm_ops i8042_pm_ops = { |
| 1071 | .suspend = i8042_pm_reset, |
| 1072 | .resume = i8042_pm_restore, |
| 1073 | .poweroff = i8042_pm_reset, |
| 1074 | .restore = i8042_pm_restore, |
| 1075 | }; |
| 1076 | |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 1077 | #endif /* CONFIG_PM */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | |
| 1079 | /* |
| 1080 | * We need to reset the 8042 back to original mode on system shutdown, |
| 1081 | * because otherwise BIOSes will be confused. |
| 1082 | */ |
| 1083 | |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1084 | static void i8042_shutdown(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | { |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 1086 | i8042_controller_reset(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1087 | } |
| 1088 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 1089 | static int __init i8042_create_kbd_port(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | { |
| 1091 | struct serio *serio; |
| 1092 | struct i8042_port *port = &i8042_ports[I8042_KBD_PORT_NO]; |
| 1093 | |
Dmitry Torokhov | d39969d | 2005-09-10 12:04:42 -0500 | [diff] [blame] | 1094 | serio = kzalloc(sizeof(struct serio), GFP_KERNEL); |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1095 | if (!serio) |
| 1096 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1098 | serio->id.type = i8042_direct ? SERIO_8042 : SERIO_8042_XL; |
| 1099 | serio->write = i8042_dumbkbd ? NULL : i8042_kbd_write; |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1100 | serio->start = i8042_start; |
| 1101 | serio->stop = i8042_stop; |
Dmitry Torokhov | 5ddbc77 | 2009-09-09 19:08:15 -0700 | [diff] [blame] | 1102 | serio->close = i8042_port_close; |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1103 | serio->port_data = port; |
| 1104 | serio->dev.parent = &i8042_platform_device->dev; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1105 | strlcpy(serio->name, "i8042 KBD port", sizeof(serio->name)); |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1106 | strlcpy(serio->phys, I8042_KBD_PHYS_DESC, sizeof(serio->phys)); |
| 1107 | |
| 1108 | port->serio = serio; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1109 | port->irq = I8042_KBD_IRQ; |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1110 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1111 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | } |
| 1113 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 1114 | static int __init i8042_create_aux_port(int idx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1115 | { |
| 1116 | struct serio *serio; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1117 | int port_no = idx < 0 ? I8042_AUX_PORT_NO : I8042_MUX_PORT_NO + idx; |
| 1118 | struct i8042_port *port = &i8042_ports[port_no]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | |
Dmitry Torokhov | d39969d | 2005-09-10 12:04:42 -0500 | [diff] [blame] | 1120 | serio = kzalloc(sizeof(struct serio), GFP_KERNEL); |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1121 | if (!serio) |
| 1122 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1124 | serio->id.type = SERIO_8042; |
| 1125 | serio->write = i8042_aux_write; |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1126 | serio->start = i8042_start; |
| 1127 | serio->stop = i8042_stop; |
| 1128 | serio->port_data = port; |
| 1129 | serio->dev.parent = &i8042_platform_device->dev; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1130 | if (idx < 0) { |
| 1131 | strlcpy(serio->name, "i8042 AUX port", sizeof(serio->name)); |
| 1132 | strlcpy(serio->phys, I8042_AUX_PHYS_DESC, sizeof(serio->phys)); |
Dmitry Torokhov | 5ddbc77 | 2009-09-09 19:08:15 -0700 | [diff] [blame] | 1133 | serio->close = i8042_port_close; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1134 | } else { |
| 1135 | snprintf(serio->name, sizeof(serio->name), "i8042 AUX%d port", idx); |
| 1136 | snprintf(serio->phys, sizeof(serio->phys), I8042_MUX_PHYS_DESC, idx + 1); |
| 1137 | } |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1138 | |
| 1139 | port->serio = serio; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1140 | port->mux = idx; |
| 1141 | port->irq = I8042_AUX_IRQ; |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1142 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1143 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | } |
| 1145 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 1146 | static void __init i8042_free_kbd_port(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1147 | { |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1148 | kfree(i8042_ports[I8042_KBD_PORT_NO].serio); |
| 1149 | i8042_ports[I8042_KBD_PORT_NO].serio = NULL; |
| 1150 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 1152 | static void __init i8042_free_aux_ports(void) |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1153 | { |
| 1154 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1156 | for (i = I8042_AUX_PORT_NO; i < I8042_NUM_PORTS; i++) { |
| 1157 | kfree(i8042_ports[i].serio); |
| 1158 | i8042_ports[i].serio = NULL; |
| 1159 | } |
| 1160 | } |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1161 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 1162 | static void __init i8042_register_ports(void) |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1163 | { |
| 1164 | int i; |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1165 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1166 | for (i = 0; i < I8042_NUM_PORTS; i++) { |
| 1167 | if (i8042_ports[i].serio) { |
| 1168 | printk(KERN_INFO "serio: %s at %#lx,%#lx irq %d\n", |
| 1169 | i8042_ports[i].serio->name, |
| 1170 | (unsigned long) I8042_DATA_REG, |
| 1171 | (unsigned long) I8042_COMMAND_REG, |
| 1172 | i8042_ports[i].irq); |
| 1173 | serio_register_port(i8042_ports[i].serio); |
| 1174 | } |
| 1175 | } |
| 1176 | } |
| 1177 | |
Ralf Baechle | 7a1904c | 2007-09-04 23:16:31 -0400 | [diff] [blame] | 1178 | static void __devexit i8042_unregister_ports(void) |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1179 | { |
| 1180 | int i; |
| 1181 | |
| 1182 | for (i = 0; i < I8042_NUM_PORTS; i++) { |
| 1183 | if (i8042_ports[i].serio) { |
| 1184 | serio_unregister_port(i8042_ports[i].serio); |
| 1185 | i8042_ports[i].serio = NULL; |
| 1186 | } |
| 1187 | } |
| 1188 | } |
| 1189 | |
Dmitry Torokhov | 181d683 | 2009-09-16 01:06:43 -0700 | [diff] [blame^] | 1190 | /* |
| 1191 | * Checks whether port belongs to i8042 controller. |
| 1192 | */ |
| 1193 | bool i8042_check_port_owner(const struct serio *port) |
| 1194 | { |
| 1195 | int i; |
| 1196 | |
| 1197 | for (i = 0; i < I8042_NUM_PORTS; i++) |
| 1198 | if (i8042_ports[i].serio == port) |
| 1199 | return true; |
| 1200 | |
| 1201 | return false; |
| 1202 | } |
| 1203 | EXPORT_SYMBOL(i8042_check_port_owner); |
| 1204 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1205 | static void i8042_free_irqs(void) |
| 1206 | { |
| 1207 | if (i8042_aux_irq_registered) |
| 1208 | free_irq(I8042_AUX_IRQ, i8042_platform_device); |
| 1209 | if (i8042_kbd_irq_registered) |
| 1210 | free_irq(I8042_KBD_IRQ, i8042_platform_device); |
| 1211 | |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 1212 | i8042_aux_irq_registered = i8042_kbd_irq_registered = false; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1213 | } |
| 1214 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 1215 | static int __init i8042_setup_aux(void) |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1216 | { |
| 1217 | int (*aux_enable)(void); |
| 1218 | int error; |
| 1219 | int i; |
| 1220 | |
| 1221 | if (i8042_check_aux()) |
| 1222 | return -ENODEV; |
| 1223 | |
| 1224 | if (i8042_nomux || i8042_check_mux()) { |
| 1225 | error = i8042_create_aux_port(-1); |
| 1226 | if (error) |
| 1227 | goto err_free_ports; |
| 1228 | aux_enable = i8042_enable_aux_port; |
| 1229 | } else { |
| 1230 | for (i = 0; i < I8042_NUM_MUX_PORTS; i++) { |
| 1231 | error = i8042_create_aux_port(i); |
| 1232 | if (error) |
| 1233 | goto err_free_ports; |
| 1234 | } |
| 1235 | aux_enable = i8042_enable_mux_ports; |
| 1236 | } |
| 1237 | |
| 1238 | error = request_irq(I8042_AUX_IRQ, i8042_interrupt, IRQF_SHARED, |
| 1239 | "i8042", i8042_platform_device); |
| 1240 | if (error) |
| 1241 | goto err_free_ports; |
| 1242 | |
| 1243 | if (aux_enable()) |
| 1244 | goto err_free_irq; |
| 1245 | |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 1246 | i8042_aux_irq_registered = true; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1247 | return 0; |
| 1248 | |
| 1249 | err_free_irq: |
| 1250 | free_irq(I8042_AUX_IRQ, i8042_platform_device); |
| 1251 | err_free_ports: |
| 1252 | i8042_free_aux_ports(); |
| 1253 | return error; |
| 1254 | } |
| 1255 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 1256 | static int __init i8042_setup_kbd(void) |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1257 | { |
| 1258 | int error; |
| 1259 | |
| 1260 | error = i8042_create_kbd_port(); |
| 1261 | if (error) |
| 1262 | return error; |
| 1263 | |
| 1264 | error = request_irq(I8042_KBD_IRQ, i8042_interrupt, IRQF_SHARED, |
| 1265 | "i8042", i8042_platform_device); |
| 1266 | if (error) |
| 1267 | goto err_free_port; |
| 1268 | |
| 1269 | error = i8042_enable_kbd_port(); |
| 1270 | if (error) |
| 1271 | goto err_free_irq; |
| 1272 | |
Dmitry Torokhov | 386b384 | 2009-09-09 19:08:16 -0700 | [diff] [blame] | 1273 | i8042_kbd_irq_registered = true; |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1274 | return 0; |
| 1275 | |
| 1276 | err_free_irq: |
| 1277 | free_irq(I8042_KBD_IRQ, i8042_platform_device); |
| 1278 | err_free_port: |
| 1279 | i8042_free_kbd_port(); |
| 1280 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | } |
| 1282 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 1283 | static int __init i8042_probe(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1284 | { |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1285 | int error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1287 | error = i8042_controller_selftest(); |
| 1288 | if (error) |
| 1289 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1290 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1291 | error = i8042_controller_init(); |
| 1292 | if (error) |
| 1293 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | |
Bruno Prémont | d35895d | 2008-05-27 01:36:04 -0400 | [diff] [blame] | 1295 | #ifdef CONFIG_X86 |
| 1296 | if (i8042_dritek) |
| 1297 | i8042_dritek_enable(); |
| 1298 | #endif |
| 1299 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1300 | if (!i8042_noaux) { |
| 1301 | error = i8042_setup_aux(); |
| 1302 | if (error && error != -ENODEV && error != -EBUSY) |
| 1303 | goto out_fail; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | } |
| 1305 | |
Dmitry Torokhov | 945ef0d | 2005-09-04 01:42:00 -0500 | [diff] [blame] | 1306 | if (!i8042_nokbd) { |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1307 | error = i8042_setup_kbd(); |
| 1308 | if (error) |
| 1309 | goto out_fail; |
Dmitry Torokhov | 945ef0d | 2005-09-04 01:42:00 -0500 | [diff] [blame] | 1310 | } |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1311 | /* |
| 1312 | * Ok, everything is ready, let's register all serio ports |
| 1313 | */ |
| 1314 | i8042_register_ports(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | return 0; |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1317 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1318 | out_fail: |
| 1319 | i8042_free_aux_ports(); /* in case KBD failed but AUX not */ |
| 1320 | i8042_free_irqs(); |
| 1321 | i8042_controller_reset(); |
Dmitry Torokhov | 0854e52 | 2005-09-04 01:41:27 -0500 | [diff] [blame] | 1322 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1323 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1324 | } |
| 1325 | |
Dmitry Torokhov | 87fd631 | 2005-12-28 01:25:11 -0500 | [diff] [blame] | 1326 | static int __devexit i8042_remove(struct platform_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1327 | { |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1328 | i8042_unregister_ports(); |
| 1329 | i8042_free_irqs(); |
| 1330 | i8042_controller_reset(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | |
Dmitry Torokhov | 87fd631 | 2005-12-28 01:25:11 -0500 | [diff] [blame] | 1332 | return 0; |
| 1333 | } |
| 1334 | |
| 1335 | static struct platform_driver i8042_driver = { |
| 1336 | .driver = { |
| 1337 | .name = "i8042", |
| 1338 | .owner = THIS_MODULE, |
Dmitry Torokhov | ebd7768 | 2009-07-22 21:51:32 -0700 | [diff] [blame] | 1339 | #ifdef CONFIG_PM |
| 1340 | .pm = &i8042_pm_ops, |
| 1341 | #endif |
Dmitry Torokhov | 87fd631 | 2005-12-28 01:25:11 -0500 | [diff] [blame] | 1342 | }, |
Dmitry Torokhov | 87fd631 | 2005-12-28 01:25:11 -0500 | [diff] [blame] | 1343 | .remove = __devexit_p(i8042_remove), |
Dmitry Torokhov | 82dd9ef | 2007-02-18 01:40:30 -0500 | [diff] [blame] | 1344 | .shutdown = i8042_shutdown, |
Dmitry Torokhov | 87fd631 | 2005-12-28 01:25:11 -0500 | [diff] [blame] | 1345 | }; |
| 1346 | |
| 1347 | static int __init i8042_init(void) |
| 1348 | { |
| 1349 | int err; |
| 1350 | |
| 1351 | dbg_init(); |
| 1352 | |
| 1353 | err = i8042_platform_init(); |
| 1354 | if (err) |
| 1355 | return err; |
| 1356 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1357 | err = i8042_controller_check(); |
| 1358 | if (err) |
| 1359 | goto err_platform_exit; |
Dmitry Torokhov | 87fd631 | 2005-12-28 01:25:11 -0500 | [diff] [blame] | 1360 | |
Dmitry Torokhov | 87fd631 | 2005-12-28 01:25:11 -0500 | [diff] [blame] | 1361 | i8042_platform_device = platform_device_alloc("i8042", -1); |
| 1362 | if (!i8042_platform_device) { |
| 1363 | err = -ENOMEM; |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 1364 | goto err_platform_exit; |
Dmitry Torokhov | 87fd631 | 2005-12-28 01:25:11 -0500 | [diff] [blame] | 1365 | } |
| 1366 | |
| 1367 | err = platform_device_add(i8042_platform_device); |
| 1368 | if (err) |
| 1369 | goto err_free_device; |
| 1370 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 1371 | err = platform_driver_probe(&i8042_driver, i8042_probe); |
| 1372 | if (err) |
| 1373 | goto err_del_device; |
| 1374 | |
Dmitry Torokhov | de9ce70 | 2006-09-10 21:57:21 -0400 | [diff] [blame] | 1375 | panic_blink = i8042_panic_blink; |
| 1376 | |
Dmitry Torokhov | 87fd631 | 2005-12-28 01:25:11 -0500 | [diff] [blame] | 1377 | return 0; |
| 1378 | |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 1379 | err_del_device: |
| 1380 | platform_device_del(i8042_platform_device); |
Dmitry Torokhov | 87fd631 | 2005-12-28 01:25:11 -0500 | [diff] [blame] | 1381 | err_free_device: |
| 1382 | platform_device_put(i8042_platform_device); |
Dmitry Torokhov | 87fd631 | 2005-12-28 01:25:11 -0500 | [diff] [blame] | 1383 | err_platform_exit: |
| 1384 | i8042_platform_exit(); |
| 1385 | |
| 1386 | return err; |
| 1387 | } |
| 1388 | |
| 1389 | static void __exit i8042_exit(void) |
| 1390 | { |
Russell King | 3ae5eae | 2005-11-09 22:32:44 +0000 | [diff] [blame] | 1391 | platform_driver_unregister(&i8042_driver); |
Dmitry Torokhov | f811341 | 2009-09-09 19:08:17 -0700 | [diff] [blame] | 1392 | platform_device_unregister(i8042_platform_device); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | i8042_platform_exit(); |
| 1394 | |
| 1395 | panic_blink = NULL; |
| 1396 | } |
| 1397 | |
| 1398 | module_init(i8042_init); |
| 1399 | module_exit(i8042_exit); |