2 * linux/drivers/char/pc_keyb.c
4 * Separation of the PC low-level part by Geert Uytterhoeven, May 1997
5 * See keyboard.c for the whole history.
7 * Major cleanup by Martin Mares, May 1997
9 * Combined the keyboard and PS/2 mouse handling into one file,
10 * because they share the same hardware.
11 * Johan Myreen <jem@iki.fi> 1998-10-08.
13 * Code fixes to handle mouse ACKs properly.
14 * C. Scott Ananian <cananian@alumni.princeton.edu> 1999-01-29.
18 #include <linux/config.h>
20 #include <linux/spinlock.h>
21 #include <linux/sched.h>
22 #include <linux/interrupt.h>
23 #include <linux/tty.h>
25 #include <linux/signal.h>
26 #include <linux/init.h>
27 #include <linux/kbd_ll.h>
28 #include <linux/delay.h>
29 #include <linux/random.h>
30 #include <linux/poll.h>
31 #include <linux/miscdevice.h>
32 #include <linux/malloc.h>
33 #include <linux/kbd_kern.h>
34 #include <linux/smp_lock.h>
36 #include <asm/keyboard.h>
37 #include <asm/bitops.h>
38 #include <asm/uaccess.h>
40 #include <asm/system.h>
44 /* Some configuration switches are present in the include file... */
46 #include <linux/pc_keyb.h>
48 /* Simple translation table for the SysRq keys */
50 #ifdef CONFIG_MAGIC_SYSRQ
51 unsigned char pckbd_sysrq_xlate
[128] =
52 "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */
53 "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */
54 "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */
55 "bnm,./\000*\000 \000\201\202\203\204\205" /* 0x30 - 0x3f */
56 "\206\207\210\211\212\000\000789-456+1" /* 0x40 - 0x4f */
57 "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */
58 "\r\000/"; /* 0x60 - 0x6f */
61 static void kbd_write_command_w(int data
);
62 static void kbd_write_output_w(int data
);
64 static void aux_write_ack(int val
);
65 static void __aux_write_ack(int val
);
68 spinlock_t kbd_controller_lock
= SPIN_LOCK_UNLOCKED
;
69 static unsigned char handle_kbd_event(void);
71 /* used only by send_data - set by keyboard_interrupt */
72 static volatile unsigned char reply_expected
;
73 static volatile unsigned char acknowledge
;
74 static volatile unsigned char resend
;
77 #if defined CONFIG_PSMOUSE
79 * PS/2 Auxiliary Device
82 static int __init
psaux_init(void);
84 #define AUX_RECONNECT 170 /* scancode when ps2 device is plugged (back) in */
86 static struct aux_queue
*queue
; /* Mouse data buffer. */
88 /* used when we send commands to the mouse that expect an ACK. */
89 static unsigned char mouse_reply_expected
;
91 #define AUX_INTS_OFF (KBD_MODE_KCC | KBD_MODE_DISABLE_MOUSE | KBD_MODE_SYS | KBD_MODE_KBD_INT)
92 #define AUX_INTS_ON (KBD_MODE_KCC | KBD_MODE_SYS | KBD_MODE_MOUSE_INT | KBD_MODE_KBD_INT)
94 #define MAX_RETRIES 60 /* some aux operations take long time*/
95 #endif /* CONFIG_PSMOUSE */
98 * Wait for keyboard controller input buffer to drain.
100 * Don't use 'jiffies' so that we don't depend on
103 * Quote from PS/2 System Reference Manual:
105 * "Address hex 0060 and address hex 0064 should be written only when
106 * the input-buffer-full bit and output-buffer-full bit in the
107 * Controller Status register are set 0."
110 static void kb_wait(void)
112 unsigned long timeout
= KBC_TIMEOUT
;
116 * "handle_kbd_event()" will handle any incoming events
117 * while we wait - keypresses or mouse movement.
119 unsigned char status
= handle_kbd_event();
121 if (! (status
& KBD_STAT_IBF
))
126 #ifdef KBD_REPORT_TIMEOUTS
127 printk(KERN_WARNING
"Keyboard timed out[1]\n");
132 * Translation of escaped scancodes to keycodes.
133 * This is now user-settable.
134 * The keycodes 1-88,96-111,119 are fairly standard, and
135 * should probably not be changed - changing might confuse X.
136 * X also interprets scancode 0x5d (KEY_Begin).
138 * For 1-88 keycode equals scancode.
141 #define E0_KPENTER 96
143 #define E0_KPSLASH 98
146 #define E0_BREAK 101 /* (control-pause) */
161 * The keycodes below are randomly located in 89-95,112-118,120-127.
162 * They could be thrown away (and all occurrences below replaced by 0),
163 * but that would force many users to use the `setkeycodes' utility, where
164 * they needed not before. It does not matter that there are duplicates, as
165 * long as no duplication occurs for any single keyboard.
169 #define FOCUS_PF1 85 /* actual code! */
177 #define FOCUS_PF9 120
178 #define FOCUS_PF10 121
179 #define FOCUS_PF11 122
180 #define FOCUS_PF12 123
183 /* tfj@olivia.ping.dk:
184 * The four keys are located over the numeric keypad, and are
185 * labelled A1-A4. It's an rc930 keyboard, from
186 * Regnecentralen/RC International, Now ICL.
187 * Scancodes: 59, 5a, 5b, 5c.
194 static unsigned char high_keys
[128 - SC_LIM
] = {
195 RGN1
, RGN2
, RGN3
, RGN4
, 0, 0, 0, /* 0x59-0x5f */
196 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x67 */
197 0, 0, 0, 0, 0, FOCUS_PF11
, 0, FOCUS_PF12
, /* 0x68-0x6f */
198 0, 0, 0, FOCUS_PF2
, FOCUS_PF9
, 0, 0, FOCUS_PF3
, /* 0x70-0x77 */
199 FOCUS_PF4
, FOCUS_PF5
, FOCUS_PF6
, FOCUS_PF7
, /* 0x78-0x7b */
200 FOCUS_PF8
, JAP_86
, FOCUS_PF10
, 0 /* 0x7c-0x7f */
211 #define E0_KPMINPLUS 118
213 * My OmniKey generates e0 4c for the "OMNI" key and the
214 * right alt key does nada. [kkoller@nyx10.cs.du.edu]
218 * New microsoft keyboard is rumoured to have
219 * e0 5b (left window button), e0 5c (right window button),
220 * e0 5d (menu button). [or: LBANNER, RBANNER, RMENU]
221 * [or: Windows_L, Windows_R, TaskMan]
227 static unsigned char e0_keys
[128] = {
228 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00-0x07 */
229 0, 0, 0, 0, 0, 0, 0, 0, /* 0x08-0x0f */
230 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10-0x17 */
231 0, 0, 0, 0, E0_KPENTER
, E0_RCTRL
, 0, 0, /* 0x18-0x1f */
232 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20-0x27 */
233 0, 0, 0, 0, 0, 0, 0, 0, /* 0x28-0x2f */
234 0, 0, 0, 0, 0, E0_KPSLASH
, 0, E0_PRSCR
, /* 0x30-0x37 */
235 E0_RALT
, 0, 0, 0, 0, E0_F13
, E0_F14
, E0_HELP
, /* 0x38-0x3f */
236 E0_DO
, E0_F17
, 0, 0, 0, 0, E0_BREAK
, E0_HOME
, /* 0x40-0x47 */
237 E0_UP
, E0_PGUP
, 0, E0_LEFT
, E0_OK
, E0_RIGHT
, E0_KPMINPLUS
, E0_END
,/* 0x48-0x4f */
238 E0_DOWN
, E0_PGDN
, E0_INS
, E0_DEL
, 0, 0, 0, 0, /* 0x50-0x57 */
239 0, 0, 0, E0_MSLW
, E0_MSRW
, E0_MSTM
, 0, 0, /* 0x58-0x5f */
240 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x67 */
241 0, 0, 0, 0, 0, 0, 0, E0_MACRO
, /* 0x68-0x6f */
242 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70-0x77 */
243 0, 0, 0, 0, 0, 0, 0, 0 /* 0x78-0x7f */
246 int pckbd_setkeycode(unsigned int scancode
, unsigned int keycode
)
248 if (scancode
< SC_LIM
|| scancode
> 255 || keycode
> 127)
251 high_keys
[scancode
- SC_LIM
] = keycode
;
253 e0_keys
[scancode
- 128] = keycode
;
257 int pckbd_getkeycode(unsigned int scancode
)
260 (scancode
< SC_LIM
|| scancode
> 255) ? -EINVAL
:
261 (scancode
< 128) ? high_keys
[scancode
- SC_LIM
] :
262 e0_keys
[scancode
- 128];
265 static int do_acknowledge(unsigned char scancode
)
267 if (reply_expected
) {
268 /* Unfortunately, we must recognise these codes only if we know they
269 * are known to be valid (i.e., after sending a command), because there
270 * are some brain-damaged keyboards (yes, FOCUS 9000 again) which have
271 * keys with such codes :(
273 if (scancode
== KBD_REPLY_ACK
) {
277 } else if (scancode
== KBD_REPLY_RESEND
) {
282 /* Should not happen... */
284 printk(KERN_DEBUG
"keyboard reply expected - got %02x\n",
291 int pckbd_translate(unsigned char scancode
, unsigned char *keycode
,
294 static int prev_scancode
;
296 /* special prefix scancodes.. */
297 if (scancode
== 0xe0 || scancode
== 0xe1) {
298 prev_scancode
= scancode
;
302 /* 0xFF is sent by a few keyboards, ignore it. 0x00 is error */
303 if (scancode
== 0x00 || scancode
== 0xff) {
312 * usually it will be 0xe0, but a Pause key generates
313 * e1 1d 45 e1 9d c5 when pressed, and nothing when released
315 if (prev_scancode
!= 0xe0) {
316 if (prev_scancode
== 0xe1 && scancode
== 0x1d) {
317 prev_scancode
= 0x100;
319 } else if (prev_scancode
== 0x100 && scancode
== 0x45) {
323 #ifdef KBD_REPORT_UNKN
325 printk(KERN_INFO
"keyboard: unknown e1 escape sequence\n");
333 * The keyboard maintains its own internal caps lock and
334 * num lock statuses. In caps lock mode E0 AA precedes make
335 * code and E0 2A follows break code. In num lock mode,
336 * E0 2A precedes make code and E0 AA follows break code.
337 * We do our own book-keeping, so we will just ignore these.
340 * For my keyboard there is no caps lock mode, but there are
341 * both Shift-L and Shift-R modes. The former mode generates
342 * E0 2A / E0 AA pairs, the latter E0 B6 / E0 36 pairs.
343 * So, we should also ignore the latter. - aeb@cwi.nl
345 if (scancode
== 0x2a || scancode
== 0x36)
348 if (e0_keys
[scancode
])
349 *keycode
= e0_keys
[scancode
];
351 #ifdef KBD_REPORT_UNKN
353 printk(KERN_INFO
"keyboard: unknown scancode e0 %02x\n",
359 } else if (scancode
>= SC_LIM
) {
360 /* This happens with the FOCUS 9000 keyboard
361 Its keys PF1..PF12 are reported to generate
362 55 73 77 78 79 7a 7b 7c 74 7e 6d 6f
363 Moreover, unless repeated, they do not generate
364 key-down events, so we have to zero up_flag below */
365 /* Also, Japanese 86/106 keyboards are reported to
366 generate 0x73 and 0x7d for \ - and \ | respectively. */
367 /* Also, some Brazilian keyboard is reported to produce
368 0x73 and 0x7e for \ ? and KP-dot, respectively. */
370 *keycode
= high_keys
[scancode
- SC_LIM
];
374 #ifdef KBD_REPORT_UNKN
375 printk(KERN_INFO
"keyboard: unrecognized scancode (%02x)"
376 " - ignored\n", scancode
);
386 char pckbd_unexpected_up(unsigned char keycode
)
388 /* unexpected, but this can happen: maybe this was a key release for a
389 FOCUS 9000 PF key; if we want to see it, we have to clear up_flag */
390 if (keycode
>= SC_LIM
|| keycode
== 85)
396 static inline void handle_mouse_event(unsigned char scancode
)
398 #ifdef CONFIG_PSMOUSE
399 if (mouse_reply_expected
) {
400 if (scancode
== AUX_ACK
) {
401 mouse_reply_expected
--;
404 mouse_reply_expected
= 0;
406 else if(scancode
== AUX_RECONNECT
){
407 queue
->head
= queue
->tail
= 0; /* Flush input queue */
408 __aux_write_ack(AUX_ENABLE_DEV
); /* ping the mouse :) */
412 add_mouse_randomness(scancode
);
414 int head
= queue
->head
;
416 queue
->buf
[head
] = scancode
;
417 head
= (head
+ 1) & (AUX_BUF_SIZE
-1);
418 if (head
!= queue
->tail
) {
420 kill_fasync(&queue
->fasync
, SIGIO
, POLL_IN
);
421 wake_up_interruptible(&queue
->proc_list
);
427 static unsigned char kbd_exists
= 1;
429 static inline void handle_keyboard_event(unsigned char scancode
)
433 if (do_acknowledge(scancode
))
434 handle_scancode(scancode
, !(scancode
& 0x80));
436 tasklet_schedule(&keyboard_tasklet
);
440 * This reads the keyboard status port, and does the
441 * appropriate action.
443 * It requires that we hold the keyboard controller
446 static unsigned char handle_kbd_event(void)
448 unsigned char status
= kbd_read_status();
449 unsigned int work
= 10000;
451 while (status
& KBD_STAT_OBF
) {
452 unsigned char scancode
;
454 scancode
= kbd_read_input();
456 /* Error bytes must be ignored to make the
457 Synaptics touchpads compaq use work */
459 /* Ignore error bytes */
460 if (!(status
& (KBD_STAT_GTO
| KBD_STAT_PERR
)))
463 if (status
& KBD_STAT_MOUSE_OBF
)
464 handle_mouse_event(scancode
);
466 handle_keyboard_event(scancode
);
469 status
= kbd_read_status();
472 printk(KERN_ERR
"pc_keyb: controller jammed (0x%02X).\n",
482 static void keyboard_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
489 spin_lock_irqsave(&kbd_controller_lock
, flags
);
491 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
495 * send_data sends a character to the keyboard and waits
496 * for an acknowledge, possibly retrying if asked to. Returns
497 * the success status.
499 * Don't use 'jiffies', so that we don't depend on interrupts
501 static int send_data(unsigned char data
)
506 unsigned long timeout
= KBD_TIMEOUT
;
508 acknowledge
= 0; /* Set by interrupt routine on receipt of ACK. */
511 kbd_write_output_w(data
);
519 #ifdef KBD_REPORT_TIMEOUTS
520 printk(KERN_WARNING
"keyboard: Timeout - AT keyboard not present?\n");
525 } while (retries
-- > 0);
526 #ifdef KBD_REPORT_TIMEOUTS
527 printk(KERN_WARNING
"keyboard: Too many NACKs -- noisy kbd cable?\n");
532 void pckbd_leds(unsigned char leds
)
534 if (kbd_exists
&& (!send_data(KBD_CMD_SET_LEDS
) || !send_data(leds
))) {
535 send_data(KBD_CMD_ENABLE
); /* re-enable kbd if any errors */
541 * In case we run on a non-x86 hardware we need to initialize both the
542 * keyboard controller and the keyboard. On a x86, the BIOS will
543 * already have initialized them.
545 * Some x86 BIOSes do not correctly initialize the keyboard, so the
546 * "kbd-reset" command line options can be given to force a reset.
550 int kbd_startup_reset __initdata
= 0;
552 int kbd_startup_reset __initdata
= 1;
555 /* for "kbd-reset" cmdline param */
556 static int __init
kbd_reset_setup(char *str
)
558 kbd_startup_reset
= 1;
562 __setup("kbd-reset", kbd_reset_setup
);
564 #define KBD_NO_DATA (-1) /* No data */
565 #define KBD_BAD_DATA (-2) /* Parity or other error */
567 static int __init
kbd_read_data(void)
569 int retval
= KBD_NO_DATA
;
570 unsigned char status
;
572 status
= kbd_read_status();
573 if (status
& KBD_STAT_OBF
) {
574 unsigned char data
= kbd_read_input();
577 if (status
& (KBD_STAT_GTO
| KBD_STAT_PERR
))
578 retval
= KBD_BAD_DATA
;
583 static void __init
kbd_clear_input(void)
585 int maxread
= 100; /* Random number */
588 if (kbd_read_data() == KBD_NO_DATA
)
593 static int __init
kbd_wait_for_input(void)
595 long timeout
= KBD_INIT_TIMEOUT
;
598 int retval
= kbd_read_data();
606 static void kbd_write_command_w(int data
)
610 spin_lock_irqsave(&kbd_controller_lock
, flags
);
612 kbd_write_command(data
);
613 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
616 static void kbd_write_output_w(int data
)
620 spin_lock_irqsave(&kbd_controller_lock
, flags
);
622 kbd_write_output(data
);
623 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
626 #if defined CONFIG_PSMOUSE
627 static void kbd_write_cmd(int cmd
)
631 spin_lock_irqsave(&kbd_controller_lock
, flags
);
633 kbd_write_command(KBD_CCMD_WRITE_MODE
);
635 kbd_write_output(cmd
);
636 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
638 #endif /* CONFIG_PSMOUSE */
640 static char * __init
initialize_kbd(void)
645 * Test the keyboard interface.
646 * This seems to be the only way to get it going.
647 * If the test is successful a x55 is placed in the input buffer.
649 kbd_write_command_w(KBD_CCMD_SELF_TEST
);
650 if (kbd_wait_for_input() != 0x55)
651 return "Keyboard failed self test";
654 * Perform a keyboard interface test. This causes the controller
655 * to test the keyboard clock and data lines. The results of the
656 * test are placed in the input buffer.
658 kbd_write_command_w(KBD_CCMD_KBD_TEST
);
659 if (kbd_wait_for_input() != 0x00)
660 return "Keyboard interface failed self test";
663 * Enable the keyboard by allowing the keyboard clock to run.
665 kbd_write_command_w(KBD_CCMD_KBD_ENABLE
);
668 * Reset keyboard. If the read times out
669 * then the assumption is that no keyboard is
670 * plugged into the machine.
671 * This defaults the keyboard to scan-code set 2.
673 * Set up to try again if the keyboard asks for RESEND.
676 kbd_write_output_w(KBD_CMD_RESET
);
677 status
= kbd_wait_for_input();
678 if (status
== KBD_REPLY_ACK
)
680 if (status
!= KBD_REPLY_RESEND
)
681 return "Keyboard reset failed, no ACK";
684 if (kbd_wait_for_input() != KBD_REPLY_POR
)
685 return "Keyboard reset failed, no POR";
688 * Set keyboard controller mode. During this, the keyboard should be
689 * in the disabled state.
691 * Set up to try again if the keyboard asks for RESEND.
694 kbd_write_output_w(KBD_CMD_DISABLE
);
695 status
= kbd_wait_for_input();
696 if (status
== KBD_REPLY_ACK
)
698 if (status
!= KBD_REPLY_RESEND
)
699 return "Disable keyboard: no ACK";
702 kbd_write_command_w(KBD_CCMD_WRITE_MODE
);
703 kbd_write_output_w(KBD_MODE_KBD_INT
705 | KBD_MODE_DISABLE_MOUSE
708 /* ibm powerpc portables need this to use scan-code set 1 -- Cort */
709 kbd_write_command_w(KBD_CCMD_READ_MODE
);
710 if (!(kbd_wait_for_input() & KBD_MODE_KCC
)) {
712 * If the controller does not support conversion,
713 * Set the keyboard to scan-code set 1.
715 kbd_write_output_w(0xF0);
716 kbd_wait_for_input();
717 kbd_write_output_w(0x01);
718 kbd_wait_for_input();
722 kbd_write_output_w(KBD_CMD_ENABLE
);
723 if (kbd_wait_for_input() != KBD_REPLY_ACK
)
724 return "Enable keyboard: no ACK";
727 * Finally, set the typematic rate to maximum.
729 kbd_write_output_w(KBD_CMD_SET_RATE
);
730 if (kbd_wait_for_input() != KBD_REPLY_ACK
)
731 return "Set rate: no ACK";
732 kbd_write_output_w(0x00);
733 if (kbd_wait_for_input() != KBD_REPLY_ACK
)
734 return "Set rate: no ACK";
739 void __init
pckbd_init_hw(void)
741 kbd_request_region();
743 /* Flush any pending input. */
746 if (kbd_startup_reset
) {
747 char *msg
= initialize_kbd();
749 printk(KERN_WARNING
"initialize_kbd: %s\n", msg
);
752 #if defined CONFIG_PSMOUSE
756 /* Ok, finally allocate the IRQ, and off we go.. */
757 kbd_request_irq(keyboard_interrupt
);
760 #if defined CONFIG_PSMOUSE
763 * Check if this is a dual port controller.
765 static int __init
detect_auxiliary_port(void)
771 /* Check if the BIOS detected a device on the auxiliary port. */
772 if (aux_device_present
== 0xaa)
775 spin_lock_irqsave(&kbd_controller_lock
, flags
);
777 /* Put the value 0x5A in the output buffer using the "Write
778 * Auxiliary Device Output Buffer" command (0xD3). Poll the
779 * Status Register for a while to see if the value really
780 * turns up in the Data Register. If the KBD_STAT_MOUSE_OBF
781 * bit is also set to 1 in the Status Register, we assume this
782 * controller has an Auxiliary Port (a.k.a. Mouse Port).
785 kbd_write_command(KBD_CCMD_WRITE_AUX_OBUF
);
788 kbd_write_output(0x5a); /* 0x5a is a random dummy value. */
791 unsigned char status
= kbd_read_status();
793 if (status
& KBD_STAT_OBF
) {
794 (void) kbd_read_input();
795 if (status
& KBD_STAT_MOUSE_OBF
) {
796 printk(KERN_INFO
"Detected PS/2 Mouse Port.\n");
803 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
809 * Send a byte to the mouse.
811 static void aux_write_dev(int val
)
815 spin_lock_irqsave(&kbd_controller_lock
, flags
);
817 kbd_write_command(KBD_CCMD_WRITE_MOUSE
);
819 kbd_write_output(val
);
820 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
824 * Send a byte to the mouse & handle returned ack
826 static void __aux_write_ack(int val
)
829 kbd_write_command(KBD_CCMD_WRITE_MOUSE
);
831 kbd_write_output(val
);
832 /* we expect an ACK in response. */
833 mouse_reply_expected
++;
837 static void aux_write_ack(int val
)
841 spin_lock_irqsave(&kbd_controller_lock
, flags
);
842 __aux_write_ack(val
);
843 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
846 static unsigned char get_from_queue(void)
848 unsigned char result
;
851 spin_lock_irqsave(&kbd_controller_lock
, flags
);
852 result
= queue
->buf
[queue
->tail
];
853 queue
->tail
= (queue
->tail
+ 1) & (AUX_BUF_SIZE
-1);
854 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
859 static inline int queue_empty(void)
861 return queue
->head
== queue
->tail
;
864 static int fasync_aux(int fd
, struct file
*filp
, int on
)
868 retval
= fasync_helper(fd
, filp
, on
, &queue
->fasync
);
876 * Random magic cookie for the aux device
878 #define AUX_DEV ((void *)queue)
880 static int release_aux(struct inode
* inode
, struct file
* file
)
883 fasync_aux(-1, file
, 0);
888 kbd_write_cmd(AUX_INTS_OFF
); /* Disable controller ints */
889 kbd_write_command_w(KBD_CCMD_MOUSE_DISABLE
);
890 aux_free_irq(AUX_DEV
);
896 * Install interrupt handler.
897 * Enable auxiliary device.
900 static int open_aux(struct inode
* inode
, struct file
* file
)
905 queue
->head
= queue
->tail
= 0; /* Flush input queue */
906 if (aux_request_irq(keyboard_interrupt
, AUX_DEV
)) {
910 kbd_write_command_w(KBD_CCMD_MOUSE_ENABLE
); /* Enable the
913 aux_write_ack(AUX_ENABLE_DEV
); /* Enable aux device */
914 kbd_write_cmd(AUX_INTS_ON
); /* Enable controller ints */
916 send_data(KBD_CMD_ENABLE
); /* try to workaround toshiba4030cdt problem */
922 * Put bytes from input queue to buffer.
925 static ssize_t
read_aux(struct file
* file
, char * buffer
,
926 size_t count
, loff_t
*ppos
)
928 DECLARE_WAITQUEUE(wait
, current
);
933 if (file
->f_flags
& O_NONBLOCK
)
935 add_wait_queue(&queue
->proc_list
, &wait
);
937 set_current_state(TASK_INTERRUPTIBLE
);
938 if (queue_empty() && !signal_pending(current
)) {
942 current
->state
= TASK_RUNNING
;
943 remove_wait_queue(&queue
->proc_list
, &wait
);
945 while (i
> 0 && !queue_empty()) {
946 c
= get_from_queue();
947 put_user(c
, buffer
++);
951 file
->f_dentry
->d_inode
->i_atime
= CURRENT_TIME
;
954 if (signal_pending(current
))
960 * Write to the aux device.
963 static ssize_t
write_aux(struct file
* file
, const char * buffer
,
964 size_t count
, loff_t
*ppos
)
972 count
= 32; /* Limit to 32 bytes. */
975 get_user(c
, buffer
++);
982 file
->f_dentry
->d_inode
->i_mtime
= CURRENT_TIME
;
989 /* No kernel lock held - fine */
990 static unsigned int aux_poll(struct file
*file
, poll_table
* wait
)
992 poll_wait(file
, &queue
->proc_list
, wait
);
994 return POLLIN
| POLLRDNORM
;
998 struct file_operations psaux_fops
= {
1003 release
: release_aux
,
1008 * Initialize driver.
1010 static struct miscdevice psaux_mouse
= {
1011 PSMOUSE_MINOR
, "psaux", &psaux_fops
1014 static int __init
psaux_init(void)
1016 if (!detect_auxiliary_port())
1019 misc_register(&psaux_mouse
);
1020 queue
= (struct aux_queue
*) kmalloc(sizeof(*queue
), GFP_KERNEL
);
1021 memset(queue
, 0, sizeof(*queue
));
1022 queue
->head
= queue
->tail
= 0;
1023 init_waitqueue_head(&queue
->proc_list
);
1025 #ifdef INITIALIZE_MOUSE
1026 kbd_write_command_w(KBD_CCMD_MOUSE_ENABLE
); /* Enable Aux. */
1027 aux_write_ack(AUX_SET_SAMPLE
);
1028 aux_write_ack(100); /* 100 samples/sec */
1029 aux_write_ack(AUX_SET_RES
);
1030 aux_write_ack(3); /* 8 counts per mm */
1031 aux_write_ack(AUX_SET_SCALE21
); /* 2:1 scaling */
1032 #endif /* INITIALIZE_MOUSE */
1033 kbd_write_command(KBD_CCMD_MOUSE_DISABLE
); /* Disable aux device. */
1034 kbd_write_cmd(AUX_INTS_OFF
); /* Disable controller ints. */
1039 #endif /* CONFIG_PSMOUSE */