2 * i8042 keyboard and mouse controller driver for Linux
4 * Copyright (c) 1999-2004 Vojtech Pavlik
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.
13 #include <linux/delay.h>
14 #include <linux/module.h>
15 #include <linux/moduleparam.h>
16 #include <linux/interrupt.h>
17 #include <linux/ioport.h>
18 #include <linux/config.h>
19 #include <linux/reboot.h>
20 #include <linux/init.h>
21 #include <linux/sysdev.h>
23 #include <linux/serio.h>
24 #include <linux/err.h>
28 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
29 MODULE_DESCRIPTION("i8042 keyboard and mouse controller driver");
30 MODULE_LICENSE("GPL");
32 static unsigned int i8042_noaux
;
33 module_param_named(noaux
, i8042_noaux
, bool, 0);
34 MODULE_PARM_DESC(noaux
, "Do not probe or use AUX (mouse) port.");
36 static unsigned int i8042_nomux
;
37 module_param_named(nomux
, i8042_nomux
, bool, 0);
38 MODULE_PARM_DESC(nomux
, "Do not check whether an active multiplexing conrtoller is present.");
40 static unsigned int i8042_unlock
;
41 module_param_named(unlock
, i8042_unlock
, bool, 0);
42 MODULE_PARM_DESC(unlock
, "Ignore keyboard lock.");
44 static unsigned int i8042_reset
;
45 module_param_named(reset
, i8042_reset
, bool, 0);
46 MODULE_PARM_DESC(reset
, "Reset controller during init and cleanup.");
48 static unsigned int i8042_direct
;
49 module_param_named(direct
, i8042_direct
, bool, 0);
50 MODULE_PARM_DESC(direct
, "Put keyboard port into non-translated mode.");
52 static unsigned int i8042_dumbkbd
;
53 module_param_named(dumbkbd
, i8042_dumbkbd
, bool, 0);
54 MODULE_PARM_DESC(dumbkbd
, "Pretend that controller can only read data from keyboard");
56 static unsigned int i8042_noloop
;
57 module_param_named(noloop
, i8042_noloop
, bool, 0);
58 MODULE_PARM_DESC(dumbkbd
, "Disable the AUX Loopback command while probing for the AUX port");
60 __obsolete_setup("i8042_noaux");
61 __obsolete_setup("i8042_nomux");
62 __obsolete_setup("i8042_unlock");
63 __obsolete_setup("i8042_reset");
64 __obsolete_setup("i8042_direct");
65 __obsolete_setup("i8042_dumbkbd");
70 spinlock_t i8042_lock
= SPIN_LOCK_UNLOCKED
;
74 unsigned char disable
;
81 static struct i8042_values i8042_kbd_values
= {
82 .disable
= I8042_CTR_KBDDIS
,
83 .irqen
= I8042_CTR_KBDINT
,
88 static struct i8042_values i8042_aux_values
= {
89 .disable
= I8042_CTR_AUXDIS
,
90 .irqen
= I8042_CTR_AUXINT
,
95 static struct i8042_values i8042_mux_values
[I8042_NUM_MUX_PORTS
];
97 static struct serio
*i8042_kbd_port
;
98 static struct serio
*i8042_aux_port
;
99 static struct serio
*i8042_mux_port
[I8042_NUM_MUX_PORTS
];
100 static unsigned char i8042_initial_ctr
;
101 static unsigned char i8042_ctr
;
102 static unsigned char i8042_mux_open
;
103 static unsigned char i8042_mux_present
;
104 static struct pm_dev
*i8042_pm_dev
;
105 static struct timer_list i8042_timer
;
106 static struct platform_device
*i8042_platform_device
;
109 * Shared IRQ's require a device pointer, but this driver doesn't support
112 #define i8042_request_irq_cookie (&i8042_timer)
114 static irqreturn_t
i8042_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
);
117 * The i8042_wait_read() and i8042_wait_write functions wait for the i8042 to
118 * be ready for reading values from it / writing values to it.
119 * Called always with i8042_lock held.
122 static int i8042_wait_read(void)
125 while ((~i8042_read_status() & I8042_STR_OBF
) && (i
< I8042_CTL_TIMEOUT
)) {
129 return -(i
== I8042_CTL_TIMEOUT
);
132 static int i8042_wait_write(void)
135 while ((i8042_read_status() & I8042_STR_IBF
) && (i
< I8042_CTL_TIMEOUT
)) {
139 return -(i
== I8042_CTL_TIMEOUT
);
143 * i8042_flush() flushes all data that may be in the keyboard and mouse buffers
144 * of the i8042 down the toilet.
147 static int i8042_flush(void)
153 spin_lock_irqsave(&i8042_lock
, flags
);
155 while ((i8042_read_status() & I8042_STR_OBF
) && (i
++ < I8042_BUFFER_SIZE
)) {
157 data
= i8042_read_data();
158 dbg("%02x <- i8042 (flush, %s)", data
,
159 i8042_read_status() & I8042_STR_AUXDATA
? "aux" : "kbd");
162 spin_unlock_irqrestore(&i8042_lock
, flags
);
168 * i8042_command() executes a command on the i8042. It also sends the input
169 * parameter(s) of the commands to it, and receives the output value(s). The
170 * parameters are to be stored in the param array, and the output is placed
171 * into the same array. The number of the parameters and output values is
172 * encoded in bits 8-11 of the command number.
175 static int i8042_command(unsigned char *param
, int command
)
178 int retval
= 0, i
= 0;
180 if (i8042_noloop
&& command
== I8042_CMD_AUX_LOOP
)
183 spin_lock_irqsave(&i8042_lock
, flags
);
185 retval
= i8042_wait_write();
187 dbg("%02x -> i8042 (command)", command
& 0xff);
188 i8042_write_command(command
& 0xff);
192 for (i
= 0; i
< ((command
>> 12) & 0xf); i
++) {
193 if ((retval
= i8042_wait_write())) break;
194 dbg("%02x -> i8042 (parameter)", param
[i
]);
195 i8042_write_data(param
[i
]);
199 for (i
= 0; i
< ((command
>> 8) & 0xf); i
++) {
200 if ((retval
= i8042_wait_read())) break;
201 if (i8042_read_status() & I8042_STR_AUXDATA
)
202 param
[i
] = ~i8042_read_data();
204 param
[i
] = i8042_read_data();
205 dbg("%02x <- i8042 (return)", param
[i
]);
208 spin_unlock_irqrestore(&i8042_lock
, flags
);
211 dbg(" -- i8042 (timeout)");
217 * i8042_kbd_write() sends a byte out through the keyboard interface.
220 static int i8042_kbd_write(struct serio
*port
, unsigned char c
)
225 spin_lock_irqsave(&i8042_lock
, flags
);
227 if(!(retval
= i8042_wait_write())) {
228 dbg("%02x -> i8042 (kbd-data)", c
);
232 spin_unlock_irqrestore(&i8042_lock
, flags
);
238 * i8042_aux_write() sends a byte out through the aux interface.
241 static int i8042_aux_write(struct serio
*port
, unsigned char c
)
243 struct i8042_values
*values
= port
->port_data
;
250 if (values
->mux
== -1)
251 retval
= i8042_command(&c
, I8042_CMD_AUX_SEND
);
253 retval
= i8042_command(&c
, I8042_CMD_MUX_SEND
+ values
->mux
);
256 * Make sure the interrupt happens and the character is received even
257 * in the case the IRQ isn't wired, so that we can receive further
261 i8042_interrupt(0, NULL
, NULL
);
266 * i8042_activate_port() enables port on a chip.
269 static int i8042_activate_port(struct serio
*port
)
271 struct i8042_values
*values
= port
->port_data
;
276 * Enable port again here because it is disabled if we are
277 * resuming (normally it is enabled already).
279 i8042_ctr
&= ~values
->disable
;
281 i8042_ctr
|= values
->irqen
;
283 if (i8042_command(&i8042_ctr
, I8042_CMD_CTL_WCTR
)) {
284 i8042_ctr
&= ~values
->irqen
;
293 * i8042_open() is called when a port is open by the higher layer.
294 * It allocates the interrupt and calls i8042_enable_port.
297 static int i8042_open(struct serio
*port
)
299 struct i8042_values
*values
= port
->port_data
;
301 if (values
->mux
!= -1)
302 if (i8042_mux_open
++)
305 if (request_irq(values
->irq
, i8042_interrupt
,
306 SA_SHIRQ
, "i8042", i8042_request_irq_cookie
)) {
307 printk(KERN_ERR
"i8042.c: Can't get irq %d for %s, unregistering the port.\n", values
->irq
, values
->name
);
311 if (i8042_activate_port(port
)) {
312 printk(KERN_ERR
"i8042.c: Can't activate %s, unregistering the port\n", values
->name
);
316 i8042_interrupt(0, NULL
, NULL
);
321 free_irq(values
->irq
, i8042_request_irq_cookie
);
325 serio_unregister_port_delayed(port
);
331 * i8042_close() frees the interrupt, so that it can possibly be used
332 * by another driver. We never know - if the user doesn't have a mouse,
333 * the BIOS could have used the AUX interrupt for PCI.
336 static void i8042_close(struct serio
*port
)
338 struct i8042_values
*values
= port
->port_data
;
340 if (values
->mux
!= -1)
341 if (--i8042_mux_open
)
344 i8042_ctr
&= ~values
->irqen
;
346 if (i8042_command(&i8042_ctr
, I8042_CMD_CTL_WCTR
)) {
347 printk(KERN_ERR
"i8042.c: Can't write CTR while closing %s.\n", values
->name
);
351 free_irq(values
->irq
, i8042_request_irq_cookie
);
357 * i8042_interrupt() is the most important function in this driver -
358 * it handles the interrupts from the i8042, and sends incoming bytes
359 * to the upper layers.
362 static irqreturn_t
i8042_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
365 unsigned char str
, data
= 0;
367 unsigned int aux_idx
;
370 mod_timer(&i8042_timer
, jiffies
+ I8042_POLL_PERIOD
);
372 spin_lock_irqsave(&i8042_lock
, flags
);
373 str
= i8042_read_status();
374 if (str
& I8042_STR_OBF
)
375 data
= i8042_read_data();
376 spin_unlock_irqrestore(&i8042_lock
, flags
);
378 if (~str
& I8042_STR_OBF
) {
379 if (irq
) dbg("Interrupt %d, without any data", irq
);
384 if (i8042_mux_present
&& (str
& I8042_STR_AUXDATA
)) {
385 static unsigned long last_transmit
;
386 static unsigned char last_str
;
389 if (str
& I8042_STR_MUXERR
) {
390 dbg("MUX error, status is %02x, data is %02x", str
, data
);
394 * When MUXERR condition is signalled the data register can only contain
395 * 0xfd, 0xfe or 0xff if implementation follows the spec. Unfortunately
396 * it is not always the case. Some KBC just get confused which port the
397 * data came from and signal error leaving the data intact. They _do not_
398 * revert to legacy mode (actually I've never seen KBC reverting to legacy
399 * mode yet, when we see one we'll add proper handling).
400 * Anyway, we will assume that the data came from the same serio last byte
401 * was transmitted (if transmission happened not too long ago).
403 if (time_before(jiffies
, last_transmit
+ HZ
/10)) {
407 /* fall through - report timeout */
409 case 0xfe: dfl
= SERIO_TIMEOUT
; data
= 0xfe; break;
410 case 0xff: dfl
= SERIO_PARITY
; data
= 0xfe; break;
414 aux_idx
= (str
>> 6) & 3;
416 dbg("%02x <- i8042 (interrupt, aux%d, %d%s%s)",
418 dfl
& SERIO_PARITY
? ", bad parity" : "",
419 dfl
& SERIO_TIMEOUT
? ", timeout" : "");
421 if (likely(i8042_mux_values
[aux_idx
].exists
))
422 serio_interrupt(i8042_mux_port
[aux_idx
], data
, dfl
, regs
);
425 last_transmit
= jiffies
;
429 dfl
= ((str
& I8042_STR_PARITY
) ? SERIO_PARITY
: 0) |
430 ((str
& I8042_STR_TIMEOUT
) ? SERIO_TIMEOUT
: 0);
432 dbg("%02x <- i8042 (interrupt, %s, %d%s%s)",
433 data
, (str
& I8042_STR_AUXDATA
) ? "aux" : "kbd", irq
,
434 dfl
& SERIO_PARITY
? ", bad parity" : "",
435 dfl
& SERIO_TIMEOUT
? ", timeout" : "");
438 if (str
& I8042_STR_AUXDATA
) {
439 if (likely(i8042_aux_values
.exists
))
440 serio_interrupt(i8042_aux_port
, data
, dfl
, regs
);
442 if (likely(i8042_kbd_values
.exists
))
443 serio_interrupt(i8042_kbd_port
, data
, dfl
, regs
);
449 return IRQ_RETVAL(ret
);
453 * i8042_enable_mux_mode checks whether the controller has an active
454 * multiplexor and puts the chip into Multiplexed (as opposed to
458 static int i8042_enable_mux_mode(struct i8042_values
*values
, unsigned char *mux_version
)
463 * Get rid of bytes in the queue.
469 * Internal loopback test - send three bytes, they should come back from the
470 * mouse interface, the last should be version. Note that we negate mouseport
471 * command responses for the i8042_check_aux() routine.
475 if (i8042_command(¶m
, I8042_CMD_AUX_LOOP
) || param
!= 0x0f)
478 if (i8042_command(¶m
, I8042_CMD_AUX_LOOP
) || param
!= 0xa9)
481 if (i8042_command(¶m
, I8042_CMD_AUX_LOOP
) || param
== 0x5b)
485 *mux_version
= ~param
;
492 * i8042_enable_mux_ports enables 4 individual AUX ports after
493 * the controller has been switched into Multiplexed mode
496 static int i8042_enable_mux_ports(struct i8042_values
*values
)
501 * Disable all muxed ports by disabling AUX.
504 i8042_ctr
|= I8042_CTR_AUXDIS
;
505 i8042_ctr
&= ~I8042_CTR_AUXINT
;
507 if (i8042_command(&i8042_ctr
, I8042_CMD_CTL_WCTR
)) {
508 printk(KERN_ERR
"i8042.c: Failed to disable AUX port, can't use MUX.\n");
513 * Enable all muxed ports.
516 for (i
= 0; i
< 4; i
++) {
517 i8042_command(¶m
, I8042_CMD_MUX_PFX
+ i
);
518 i8042_command(¶m
, I8042_CMD_AUX_ENABLE
);
526 * i8042_check_mux() checks whether the controller supports the PS/2 Active
527 * Multiplexing specification by Synaptics, Phoenix, Insyde and
531 static int __init
i8042_check_mux(struct i8042_values
*values
)
533 unsigned char mux_version
;
535 if (i8042_enable_mux_mode(values
, &mux_version
))
538 /* Workaround for broken chips which seem to support MUX, but in reality don't. */
539 /* They all report version 10.12 */
540 if (mux_version
== 0xAC)
543 printk(KERN_INFO
"i8042.c: Detected active multiplexing controller, rev %d.%d.\n",
544 (mux_version
>> 4) & 0xf, mux_version
& 0xf);
546 if (i8042_enable_mux_ports(values
))
549 i8042_mux_present
= 1;
555 * i8042_check_aux() applies as much paranoia as it can at detecting
556 * the presence of an AUX interface.
559 static int __init
i8042_check_aux(struct i8042_values
*values
)
562 static int i8042_check_aux_cookie
;
565 * Check if AUX irq is available. If it isn't, then there is no point
566 * in trying to detect AUX presence.
569 if (request_irq(values
->irq
, i8042_interrupt
, SA_SHIRQ
,
570 "i8042", &i8042_check_aux_cookie
))
572 free_irq(values
->irq
, &i8042_check_aux_cookie
);
575 * Get rid of bytes in the queue.
581 * Internal loopback test - filters out AT-type i8042's. Unfortunately
582 * SiS screwed up and their 5597 doesn't support the LOOP command even
583 * though it has an AUX port.
587 if (i8042_command(¶m
, I8042_CMD_AUX_LOOP
) || param
!= 0xa5) {
590 * External connection test - filters out AT-soldered PS/2 i8042's
591 * 0x00 - no error, 0x01-0x03 - clock/data stuck, 0xff - general error
592 * 0xfa - no error on some notebooks which ignore the spec
593 * Because it's common for chipsets to return error on perfectly functioning
594 * AUX ports, we test for this only when the LOOP command failed.
597 if (i8042_command(¶m
, I8042_CMD_AUX_TEST
)
598 || (param
&& param
!= 0xfa && param
!= 0xff))
603 * Bit assignment test - filters out PS/2 i8042's in AT mode
606 if (i8042_command(¶m
, I8042_CMD_AUX_DISABLE
))
608 if (i8042_command(¶m
, I8042_CMD_CTL_RCTR
) || (~param
& I8042_CTR_AUXDIS
)) {
609 printk(KERN_WARNING
"Failed to disable AUX port, but continuing anyway... Is this a SiS?\n");
610 printk(KERN_WARNING
"If AUX port is really absent please use the 'i8042.noaux' option.\n");
613 if (i8042_command(¶m
, I8042_CMD_AUX_ENABLE
))
615 if (i8042_command(¶m
, I8042_CMD_CTL_RCTR
) || (param
& I8042_CTR_AUXDIS
))
619 * Disable the interface.
622 i8042_ctr
|= I8042_CTR_AUXDIS
;
623 i8042_ctr
&= ~I8042_CTR_AUXINT
;
625 if (i8042_command(&i8042_ctr
, I8042_CMD_CTL_WCTR
))
633 * i8042_port_register() marks the device as existing,
634 * registers it, and reports to the user.
637 static int __init
i8042_port_register(struct serio
*port
)
639 struct i8042_values
*values
= port
->port_data
;
643 i8042_ctr
&= ~values
->disable
;
645 if (i8042_command(&i8042_ctr
, I8042_CMD_CTL_WCTR
)) {
646 printk(KERN_WARNING
"i8042.c: Can't write CTR while registering.\n");
651 printk(KERN_INFO
"serio: i8042 %s port at %#lx,%#lx irq %d\n",
653 (unsigned long) I8042_DATA_REG
,
654 (unsigned long) I8042_COMMAND_REG
,
657 serio_register_port(port
);
663 static void i8042_timer_func(unsigned long data
)
665 i8042_interrupt(0, NULL
, NULL
);
670 * i8042_controller init initializes the i8042 controller, and,
671 * most importantly, sets it into non-xlated mode if that's
675 static int i8042_controller_init(void)
680 * Test the i8042. We need to know if it thinks it's working correctly
681 * before doing anything else.
690 if (i8042_command(¶m
, I8042_CMD_CTL_TEST
)) {
691 printk(KERN_ERR
"i8042.c: i8042 controller self test timeout.\n");
695 if (param
!= I8042_RET_CTL_TEST
) {
696 printk(KERN_ERR
"i8042.c: i8042 controller selftest failed. (%#x != %#x)\n",
697 param
, I8042_RET_CTL_TEST
);
703 * Save the CTR for restoral on unload / reboot.
706 if (i8042_command(&i8042_ctr
, I8042_CMD_CTL_RCTR
)) {
707 printk(KERN_ERR
"i8042.c: Can't read CTR while initializing i8042.\n");
711 i8042_initial_ctr
= i8042_ctr
;
714 * Disable the keyboard interface and interrupt.
717 i8042_ctr
|= I8042_CTR_KBDDIS
;
718 i8042_ctr
&= ~I8042_CTR_KBDINT
;
724 spin_lock_irqsave(&i8042_lock
, flags
);
725 if (~i8042_read_status() & I8042_STR_KEYLOCK
) {
727 i8042_ctr
|= I8042_CTR_IGNKEYLOCK
;
729 printk(KERN_WARNING
"i8042.c: Warning: Keylock active.\n");
731 spin_unlock_irqrestore(&i8042_lock
, flags
);
734 * If the chip is configured into nontranslated mode by the BIOS, don't
735 * bother enabling translating and be happy.
738 if (~i8042_ctr
& I8042_CTR_XLATE
)
742 * Set nontranslated mode for the kbd interface if requested by an option.
743 * After this the kbd interface becomes a simple serial in/out, like the aux
744 * interface is. We don't do this by default, since it can confuse notebook
749 i8042_ctr
&= ~I8042_CTR_XLATE
;
755 if (i8042_command(&i8042_ctr
, I8042_CMD_CTL_WCTR
)) {
756 printk(KERN_ERR
"i8042.c: Can't write CTR while initializing i8042.\n");
765 * Reset the controller.
767 void i8042_controller_reset(void)
772 if (i8042_command(¶m
, I8042_CMD_CTL_TEST
))
773 printk(KERN_ERR
"i8042.c: i8042 controller reset timeout.\n");
777 * Restore the original control register setting.
780 i8042_ctr
= i8042_initial_ctr
;
782 if (i8042_command(&i8042_ctr
, I8042_CMD_CTL_WCTR
))
783 printk(KERN_WARNING
"i8042.c: Can't restore CTR.\n");
788 * Here we try to reset everything back to a state in which the BIOS will be
789 * able to talk to the hardware when rebooting.
792 void i8042_controller_cleanup(void)
799 * Reset anything that is connected to the ports.
802 if (i8042_kbd_values
.exists
)
803 serio_cleanup(i8042_kbd_port
);
805 if (i8042_aux_values
.exists
)
806 serio_cleanup(i8042_aux_port
);
808 for (i
= 0; i
< I8042_NUM_MUX_PORTS
; i
++)
809 if (i8042_mux_values
[i
].exists
)
810 serio_cleanup(i8042_mux_port
[i
]);
812 i8042_controller_reset();
817 * Here we try to restore the original BIOS settings
820 static int i8042_controller_suspend(void)
822 del_timer_sync(&i8042_timer
);
823 i8042_controller_reset();
830 * Here we try to reset everything back to a state in which suspended
833 static int i8042_controller_resume(void)
837 if (i8042_controller_init()) {
838 printk(KERN_ERR
"i8042: resume failed\n");
842 if (i8042_mux_present
)
843 if (i8042_enable_mux_mode(&i8042_aux_values
, NULL
) ||
844 i8042_enable_mux_ports(&i8042_aux_values
)) {
845 printk(KERN_WARNING
"i8042: failed to resume active multiplexor, mouse won't work.\n");
849 * Reconnect anything that was connected to the ports.
852 if (i8042_kbd_values
.exists
&& i8042_activate_port(i8042_kbd_port
) == 0)
853 serio_reconnect(i8042_kbd_port
);
855 if (i8042_aux_values
.exists
&& i8042_activate_port(i8042_aux_port
) == 0)
856 serio_reconnect(i8042_aux_port
);
858 for (i
= 0; i
< I8042_NUM_MUX_PORTS
; i
++)
859 if (i8042_mux_values
[i
].exists
&& i8042_activate_port(i8042_mux_port
[i
]) == 0)
860 serio_reconnect(i8042_mux_port
[i
]);
862 * Restart timer (for polling "stuck" data)
864 mod_timer(&i8042_timer
, jiffies
+ I8042_POLL_PERIOD
);
871 * We need to reset the 8042 back to original mode on system shutdown,
872 * because otherwise BIOSes will be confused.
875 static int i8042_notify_sys(struct notifier_block
*this, unsigned long code
,
878 if (code
== SYS_DOWN
|| code
== SYS_HALT
)
879 i8042_controller_cleanup();
883 static struct notifier_block i8042_notifier
=
891 * Suspend/resume handlers for the new PM scheme (driver model)
893 static int i8042_suspend(struct device
*dev
, u32 state
, u32 level
)
895 return level
== SUSPEND_DISABLE
? i8042_controller_suspend() : 0;
898 static int i8042_resume(struct device
*dev
, u32 level
)
900 return level
== RESUME_ENABLE
? i8042_controller_resume() : 0;
903 static void i8042_shutdown(struct device
*dev
)
905 i8042_controller_cleanup();
908 static struct device_driver i8042_driver
= {
910 .bus
= &platform_bus_type
,
911 .suspend
= i8042_suspend
,
912 .resume
= i8042_resume
,
913 .shutdown
= i8042_shutdown
,
917 * Suspend/resume handler for the old PM scheme (APM)
919 static int i8042_pm_callback(struct pm_dev
*dev
, pm_request_t request
, void *dummy
)
923 return i8042_controller_suspend();
926 return i8042_controller_resume();
932 static struct serio
* __init
i8042_allocate_kbd_port(void)
936 serio
= kmalloc(sizeof(struct serio
), GFP_KERNEL
);
938 memset(serio
, 0, sizeof(struct serio
));
939 serio
->type
= i8042_direct
? SERIO_8042
: SERIO_8042_XL
,
940 serio
->write
= i8042_dumbkbd
? NULL
: i8042_kbd_write
,
941 serio
->open
= i8042_open
,
942 serio
->close
= i8042_close
,
943 serio
->port_data
= &i8042_kbd_values
,
944 serio
->dev
.parent
= &i8042_platform_device
->dev
;
945 strlcpy(serio
->name
, "i8042 Kbd Port", sizeof(serio
->name
));
946 strlcpy(serio
->phys
, I8042_KBD_PHYS_DESC
, sizeof(serio
->phys
));
952 static struct serio
* __init
i8042_allocate_aux_port(void)
956 serio
= kmalloc(sizeof(struct serio
), GFP_KERNEL
);
958 memset(serio
, 0, sizeof(struct serio
));
959 serio
->type
= SERIO_8042
;
960 serio
->write
= i8042_aux_write
;
961 serio
->open
= i8042_open
;
962 serio
->close
= i8042_close
;
963 serio
->port_data
= &i8042_aux_values
,
964 serio
->dev
.parent
= &i8042_platform_device
->dev
;
965 strlcpy(serio
->name
, "i8042 Aux Port", sizeof(serio
->name
));
966 strlcpy(serio
->phys
, I8042_AUX_PHYS_DESC
, sizeof(serio
->phys
));
972 static struct serio
* __init
i8042_allocate_mux_port(int index
)
975 struct i8042_values
*values
= &i8042_mux_values
[index
];
977 serio
= kmalloc(sizeof(struct serio
), GFP_KERNEL
);
979 *values
= i8042_aux_values
;
980 snprintf(values
->name
, sizeof(values
->name
), "AUX%d", index
);
983 memset(serio
, 0, sizeof(struct serio
));
984 serio
->type
= SERIO_8042
;
985 serio
->write
= i8042_aux_write
;
986 serio
->open
= i8042_open
;
987 serio
->close
= i8042_close
;
988 serio
->port_data
= values
;
989 serio
->dev
.parent
= &i8042_platform_device
->dev
;
990 snprintf(serio
->name
, sizeof(serio
->name
), "i8042 Aux-%d Port", index
);
991 snprintf(serio
->phys
, sizeof(serio
->phys
), I8042_MUX_PHYS_DESC
, index
+ 1);
997 int __init
i8042_init(void)
1004 init_timer(&i8042_timer
);
1005 i8042_timer
.function
= i8042_timer_func
;
1007 if (i8042_platform_init())
1010 i8042_aux_values
.irq
= I8042_AUX_IRQ
;
1011 i8042_kbd_values
.irq
= I8042_KBD_IRQ
;
1013 if (i8042_controller_init())
1016 err
= driver_register(&i8042_driver
);
1020 i8042_platform_device
= platform_device_register_simple("i8042", -1, NULL
, 0);
1021 if (IS_ERR(i8042_platform_device
)) {
1022 driver_unregister(&i8042_driver
);
1023 return PTR_ERR(i8042_platform_device
);
1026 if (!i8042_noaux
&& !i8042_check_aux(&i8042_aux_values
)) {
1027 if (!i8042_nomux
&& !i8042_check_mux(&i8042_aux_values
))
1028 for (i
= 0; i
< I8042_NUM_MUX_PORTS
; i
++) {
1029 i8042_mux_port
[i
] = i8042_allocate_mux_port(i
);
1030 if (i8042_mux_port
[i
])
1031 i8042_port_register(i8042_mux_port
[i
]);
1034 i8042_aux_port
= i8042_allocate_aux_port();
1036 i8042_port_register(i8042_aux_port
);
1040 i8042_kbd_port
= i8042_allocate_kbd_port();
1042 i8042_port_register(i8042_kbd_port
);
1044 mod_timer(&i8042_timer
, jiffies
+ I8042_POLL_PERIOD
);
1046 i8042_pm_dev
= pm_register(PM_SYS_DEV
, PM_SYS_UNKNOWN
, i8042_pm_callback
);
1048 register_reboot_notifier(&i8042_notifier
);
1053 void __exit
i8042_exit(void)
1057 unregister_reboot_notifier(&i8042_notifier
);
1060 pm_unregister(i8042_pm_dev
);
1062 i8042_controller_cleanup();
1064 if (i8042_kbd_values
.exists
)
1065 serio_unregister_port(i8042_kbd_port
);
1067 if (i8042_aux_values
.exists
)
1068 serio_unregister_port(i8042_aux_port
);
1070 for (i
= 0; i
< I8042_NUM_MUX_PORTS
; i
++)
1071 if (i8042_mux_values
[i
].exists
)
1072 serio_unregister_port(i8042_mux_port
[i
]);
1074 del_timer_sync(&i8042_timer
);
1076 platform_device_unregister(i8042_platform_device
);
1077 driver_unregister(&i8042_driver
);
1079 i8042_platform_exit();
1082 module_init(i8042_init
);
1083 module_exit(i8042_exit
);