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/ioport.h>
27 #include <linux/init.h>
28 #include <linux/kbd_ll.h>
29 #include <linux/delay.h>
30 #include <linux/random.h>
31 #include <linux/poll.h>
32 #include <linux/miscdevice.h>
33 #include <linux/malloc.h>
35 #include <asm/keyboard.h>
36 #include <asm/bitops.h>
38 #include <asm/uaccess.h>
40 #include <asm/system.h>
42 /* Some configuration switches are present in the include file... */
46 /* Simple translation table for the SysRq keys */
48 #ifdef CONFIG_MAGIC_SYSRQ
49 unsigned char pckbd_sysrq_xlate
[128] =
50 "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */
51 "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */
52 "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */
53 "bnm,./\000*\000 \000\201\202\203\204\205" /* 0x30 - 0x3f */
54 "\206\207\210\211\212\000\000789-456+1" /* 0x40 - 0x4f */
55 "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */
56 "\r\000/"; /* 0x60 - 0x6f */
59 static void kbd_write(int address
, int data
);
60 static unsigned char handle_kbd_event(void);
62 spinlock_t kbd_controller_lock
= SPIN_LOCK_UNLOCKED
;
64 /* used only by send_data - set by keyboard_interrupt */
65 static volatile unsigned char reply_expected
= 0;
66 static volatile unsigned char acknowledge
= 0;
67 static volatile unsigned char resend
= 0;
70 #if defined CONFIG_PSMOUSE
72 * PS/2 Auxiliary Device
75 static int __init
psaux_init(void);
77 static struct aux_queue
*queue
; /* Mouse data buffer. */
78 static int aux_count
= 0;
79 /* used when we send commands to the mouse that expect an ACK. */
80 static unsigned char mouse_reply_expected
= 0;
82 #define AUX_INTS_OFF (KBD_MODE_KCC | KBD_MODE_DISABLE_MOUSE | KBD_MODE_SYS | KBD_MODE_KBD_INT)
83 #define AUX_INTS_ON (KBD_MODE_KCC | KBD_MODE_SYS | KBD_MODE_MOUSE_INT | KBD_MODE_KBD_INT)
85 #define MAX_RETRIES 60 /* some aux operations take long time*/
91 #endif /* CONFIG_PSMOUSE */
94 * Wait for keyboard controller input buffer to drain.
96 * Don't use 'jiffies' so that we don't depend on
99 * Quote from PS/2 System Reference Manual:
101 * "Address hex 0060 and address hex 0064 should be written only when
102 * the input-buffer-full bit and output-buffer-full bit in the
103 * Controller Status register are set 0."
106 static void kb_wait(void)
108 unsigned long timeout
= KBC_TIMEOUT
;
112 * "handle_kbd_event()" will handle any incoming events
113 * while we wait - keypresses or mouse movement.
115 unsigned char status
= handle_kbd_event();
117 if (! (status
& KBD_STAT_IBF
))
122 #ifdef KBD_REPORT_TIMEOUTS
123 printk(KERN_WARNING
"Keyboard timed out[1]\n");
128 * Translation of escaped scancodes to keycodes.
129 * This is now user-settable.
130 * The keycodes 1-88,96-111,119 are fairly standard, and
131 * should probably not be changed - changing might confuse X.
132 * X also interprets scancode 0x5d (KEY_Begin).
134 * For 1-88 keycode equals scancode.
137 #define E0_KPENTER 96
139 #define E0_KPSLASH 98
142 #define E0_BREAK 101 /* (control-pause) */
157 * The keycodes below are randomly located in 89-95,112-118,120-127.
158 * They could be thrown away (and all occurrences below replaced by 0),
159 * but that would force many users to use the `setkeycodes' utility, where
160 * they needed not before. It does not matter that there are duplicates, as
161 * long as no duplication occurs for any single keyboard.
165 #define FOCUS_PF1 85 /* actual code! */
173 #define FOCUS_PF9 120
174 #define FOCUS_PF10 121
175 #define FOCUS_PF11 122
176 #define FOCUS_PF12 123
179 /* tfj@olivia.ping.dk:
180 * The four keys are located over the numeric keypad, and are
181 * labelled A1-A4. It's an rc930 keyboard, from
182 * Regnecentralen/RC International, Now ICL.
183 * Scancodes: 59, 5a, 5b, 5c.
190 static unsigned char high_keys
[128 - SC_LIM
] = {
191 RGN1
, RGN2
, RGN3
, RGN4
, 0, 0, 0, /* 0x59-0x5f */
192 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x67 */
193 0, 0, 0, 0, 0, FOCUS_PF11
, 0, FOCUS_PF12
, /* 0x68-0x6f */
194 0, 0, 0, FOCUS_PF2
, FOCUS_PF9
, 0, 0, FOCUS_PF3
, /* 0x70-0x77 */
195 FOCUS_PF4
, FOCUS_PF5
, FOCUS_PF6
, FOCUS_PF7
, /* 0x78-0x7b */
196 FOCUS_PF8
, JAP_86
, FOCUS_PF10
, 0 /* 0x7c-0x7f */
207 #define E0_KPMINPLUS 118
209 * My OmniKey generates e0 4c for the "OMNI" key and the
210 * right alt key does nada. [kkoller@nyx10.cs.du.edu]
214 * New microsoft keyboard is rumoured to have
215 * e0 5b (left window button), e0 5c (right window button),
216 * e0 5d (menu button). [or: LBANNER, RBANNER, RMENU]
217 * [or: Windows_L, Windows_R, TaskMan]
223 static unsigned char e0_keys
[128] = {
224 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00-0x07 */
225 0, 0, 0, 0, 0, 0, 0, 0, /* 0x08-0x0f */
226 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10-0x17 */
227 0, 0, 0, 0, E0_KPENTER
, E0_RCTRL
, 0, 0, /* 0x18-0x1f */
228 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20-0x27 */
229 0, 0, 0, 0, 0, 0, 0, 0, /* 0x28-0x2f */
230 0, 0, 0, 0, 0, E0_KPSLASH
, 0, E0_PRSCR
, /* 0x30-0x37 */
231 E0_RALT
, 0, 0, 0, 0, E0_F13
, E0_F14
, E0_HELP
, /* 0x38-0x3f */
232 E0_DO
, E0_F17
, 0, 0, 0, 0, E0_BREAK
, E0_HOME
, /* 0x40-0x47 */
233 E0_UP
, E0_PGUP
, 0, E0_LEFT
, E0_OK
, E0_RIGHT
, E0_KPMINPLUS
, E0_END
,/* 0x48-0x4f */
234 E0_DOWN
, E0_PGDN
, E0_INS
, E0_DEL
, 0, 0, 0, 0, /* 0x50-0x57 */
235 0, 0, 0, E0_MSLW
, E0_MSRW
, E0_MSTM
, 0, 0, /* 0x58-0x5f */
236 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x67 */
237 0, 0, 0, 0, 0, 0, 0, E0_MACRO
, /* 0x68-0x6f */
238 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70-0x77 */
239 0, 0, 0, 0, 0, 0, 0, 0 /* 0x78-0x7f */
242 int pckbd_setkeycode(unsigned int scancode
, unsigned int keycode
)
244 if (scancode
< SC_LIM
|| scancode
> 255 || keycode
> 127)
247 high_keys
[scancode
- SC_LIM
] = keycode
;
249 e0_keys
[scancode
- 128] = keycode
;
253 int pckbd_getkeycode(unsigned int scancode
)
256 (scancode
< SC_LIM
|| scancode
> 255) ? -EINVAL
:
257 (scancode
< 128) ? high_keys
[scancode
- SC_LIM
] :
258 e0_keys
[scancode
- 128];
261 static int do_acknowledge(unsigned char scancode
)
263 if (reply_expected
) {
264 /* Unfortunately, we must recognise these codes only if we know they
265 * are known to be valid (i.e., after sending a command), because there
266 * are some brain-damaged keyboards (yes, FOCUS 9000 again) which have
267 * keys with such codes :(
269 if (scancode
== KBD_REPLY_ACK
) {
273 } else if (scancode
== KBD_REPLY_RESEND
) {
278 /* Should not happen... */
280 printk(KERN_DEBUG
"keyboard reply expected - got %02x\n",
287 int pckbd_translate(unsigned char scancode
, unsigned char *keycode
,
290 static int prev_scancode
= 0;
292 /* special prefix scancodes.. */
293 if (scancode
== 0xe0 || scancode
== 0xe1) {
294 prev_scancode
= scancode
;
298 /* 0xFF is sent by a few keyboards, ignore it. 0x00 is error */
299 if (scancode
== 0x00 || scancode
== 0xff) {
308 * usually it will be 0xe0, but a Pause key generates
309 * e1 1d 45 e1 9d c5 when pressed, and nothing when released
311 if (prev_scancode
!= 0xe0) {
312 if (prev_scancode
== 0xe1 && scancode
== 0x1d) {
313 prev_scancode
= 0x100;
315 } else if (prev_scancode
== 0x100 && scancode
== 0x45) {
319 #ifdef KBD_REPORT_UNKN
321 printk(KERN_INFO
"keyboard: unknown e1 escape sequence\n");
329 * The keyboard maintains its own internal caps lock and
330 * num lock statuses. In caps lock mode E0 AA precedes make
331 * code and E0 2A follows break code. In num lock mode,
332 * E0 2A precedes make code and E0 AA follows break code.
333 * We do our own book-keeping, so we will just ignore these.
336 * For my keyboard there is no caps lock mode, but there are
337 * both Shift-L and Shift-R modes. The former mode generates
338 * E0 2A / E0 AA pairs, the latter E0 B6 / E0 36 pairs.
339 * So, we should also ignore the latter. - aeb@cwi.nl
341 if (scancode
== 0x2a || scancode
== 0x36)
344 if (e0_keys
[scancode
])
345 *keycode
= e0_keys
[scancode
];
347 #ifdef KBD_REPORT_UNKN
349 printk(KERN_INFO
"keyboard: unknown scancode e0 %02x\n",
355 } else if (scancode
>= SC_LIM
) {
356 /* This happens with the FOCUS 9000 keyboard
357 Its keys PF1..PF12 are reported to generate
358 55 73 77 78 79 7a 7b 7c 74 7e 6d 6f
359 Moreover, unless repeated, they do not generate
360 key-down events, so we have to zero up_flag below */
361 /* Also, Japanese 86/106 keyboards are reported to
362 generate 0x73 and 0x7d for \ - and \ | respectively. */
363 /* Also, some Brazilian keyboard is reported to produce
364 0x73 and 0x7e for \ ? and KP-dot, respectively. */
366 *keycode
= high_keys
[scancode
- SC_LIM
];
370 #ifdef KBD_REPORT_UNKN
371 printk(KERN_INFO
"keyboard: unrecognized scancode (%02x)"
372 " - ignored\n", scancode
);
382 char pckbd_unexpected_up(unsigned char keycode
)
384 /* unexpected, but this can happen: maybe this was a key release for a
385 FOCUS 9000 PF key; if we want to see it, we have to clear up_flag */
386 if (keycode
>= SC_LIM
|| keycode
== 85)
392 static inline void handle_mouse_event(unsigned char scancode
)
394 #ifdef CONFIG_PSMOUSE
395 if (mouse_reply_expected
) {
396 if (scancode
== AUX_ACK
) {
397 mouse_reply_expected
--;
400 mouse_reply_expected
= 0;
403 add_mouse_randomness(scancode
);
405 int head
= queue
->head
;
407 queue
->buf
[head
] = scancode
;
408 head
= (head
+ 1) & (AUX_BUF_SIZE
-1);
409 if (head
!= queue
->tail
) {
412 kill_fasync(queue
->fasync
, SIGIO
);
413 wake_up_interruptible(&queue
->proc_list
);
420 * This reads the keyboard status port, and does the
421 * appropriate action.
423 * It requires that we hold the keyboard controller
426 static unsigned char handle_kbd_event(void)
428 unsigned char status
= inb(KBD_STATUS_REG
);
430 while (status
& KBD_STAT_OBF
) {
431 unsigned char scancode
;
433 scancode
= inb(KBD_DATA_REG
);
435 if (status
& KBD_STAT_MOUSE_OBF
) {
436 handle_mouse_event(scancode
);
438 if (do_acknowledge(scancode
))
439 handle_scancode(scancode
, !(scancode
& 0x80));
440 mark_bh(KEYBOARD_BH
);
443 status
= inb(KBD_STATUS_REG
);
450 static void keyboard_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
456 spin_lock_irqsave(&kbd_controller_lock
, flags
);
458 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
462 * send_data sends a character to the keyboard and waits
463 * for an acknowledge, possibly retrying if asked to. Returns
464 * the success status.
466 * Don't use 'jiffies', so that we don't depend on interrupts
468 static int send_data(unsigned char data
)
473 unsigned long timeout
= KBD_TIMEOUT
;
475 acknowledge
= 0; /* Set by interrupt routine on receipt of ACK. */
478 kbd_write(KBD_DATA_REG
, data
);
486 #ifdef KBD_REPORT_TIMEOUTS
487 printk(KERN_WARNING
"Keyboard timeout[2]\n");
492 } while (retries
-- > 0);
493 #ifdef KBD_REPORT_TIMEOUTS
494 printk(KERN_WARNING
"keyboard: Too many NACKs -- noisy kbd cable?\n");
499 void pckbd_leds(unsigned char leds
)
501 if (!send_data(KBD_CMD_SET_LEDS
) || !send_data(leds
))
502 send_data(KBD_CMD_ENABLE
); /* re-enable kbd if any errors */
506 * In case we run on a non-x86 hardware we need to initialize both the
507 * keyboard controller and the keyboard. On a x86, the BIOS will
508 * already have initialized them.
510 * Some x86 BIOSes do not correctly initialize the keyboard, so the
511 * "kbd-reset" command line options can be given to force a reset.
515 int kbd_startup_reset __initdata
= 0;
517 int kbd_startup_reset __initdata
= 1;
520 /* for "kbd-reset" cmdline param */
521 static int __init
kbd_reset_setup(char *str
)
523 kbd_startup_reset
= 1;
527 __setup("kbd-reset", kbd_reset_setup
);
529 #define KBD_NO_DATA (-1) /* No data */
530 #define KBD_BAD_DATA (-2) /* Parity or other error */
532 static int __init
kbd_read_input(void)
534 int retval
= KBD_NO_DATA
;
535 unsigned char status
;
537 status
= inb(KBD_STATUS_REG
);
538 if (status
& KBD_STAT_OBF
) {
539 unsigned char data
= inb(KBD_DATA_REG
);
542 if (status
& (KBD_STAT_GTO
| KBD_STAT_PERR
))
543 retval
= KBD_BAD_DATA
;
548 static void __init
kbd_clear_input(void)
550 int maxread
= 100; /* Random number */
553 if (kbd_read_input() == KBD_NO_DATA
)
558 static int __init
kbd_wait_for_input(void)
560 long timeout
= KBD_INIT_TIMEOUT
;
563 int retval
= kbd_read_input();
571 static void kbd_write(int address
, int data
)
575 spin_lock_irqsave(&kbd_controller_lock
, flags
);
578 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
581 #if defined CONFIG_PSMOUSE
582 static void kbd_write_cmd(int cmd
)
586 spin_lock_irqsave(&kbd_controller_lock
, flags
);
588 outb(KBD_CCMD_WRITE_MODE
, KBD_CNTL_REG
);
590 outb(cmd
, KBD_DATA_REG
);
591 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
593 #endif /* CONFIG_PSMOUSE */
595 static char * __init
initialize_kbd(void)
600 * Test the keyboard interface.
601 * This seems to be the only way to get it going.
602 * If the test is successful a x55 is placed in the input buffer.
604 kbd_write(KBD_CNTL_REG
, KBD_CCMD_SELF_TEST
);
605 if (kbd_wait_for_input() != 0x55)
606 return "Keyboard failed self test";
609 * Perform a keyboard interface test. This causes the controller
610 * to test the keyboard clock and data lines. The results of the
611 * test are placed in the input buffer.
613 kbd_write(KBD_CNTL_REG
, KBD_CCMD_KBD_TEST
);
614 if (kbd_wait_for_input() != 0x00)
615 return "Keyboard interface failed self test";
618 * Enable the keyboard by allowing the keyboard clock to run.
620 kbd_write(KBD_CNTL_REG
, KBD_CCMD_KBD_ENABLE
);
623 * Reset keyboard. If the read times out
624 * then the assumption is that no keyboard is
625 * plugged into the machine.
626 * This defaults the keyboard to scan-code set 2.
628 * Set up to try again if the keyboard asks for RESEND.
631 kbd_write(KBD_DATA_REG
, KBD_CMD_RESET
);
632 status
= kbd_wait_for_input();
633 if (status
== KBD_REPLY_ACK
)
635 if (status
!= KBD_REPLY_RESEND
)
636 return "Keyboard reset failed, no ACK";
639 if (kbd_wait_for_input() != KBD_REPLY_POR
)
640 return "Keyboard reset failed, no POR";
643 * Set keyboard controller mode. During this, the keyboard should be
644 * in the disabled state.
646 * Set up to try again if the keyboard asks for RESEND.
649 kbd_write(KBD_DATA_REG
, KBD_CMD_DISABLE
);
650 status
= kbd_wait_for_input();
651 if (status
== KBD_REPLY_ACK
)
653 if (status
!= KBD_REPLY_RESEND
)
654 return "Disable keyboard: no ACK";
657 kbd_write(KBD_CNTL_REG
, KBD_CCMD_WRITE_MODE
);
658 kbd_write(KBD_DATA_REG
, KBD_MODE_KBD_INT
660 | KBD_MODE_DISABLE_MOUSE
663 /* ibm powerpc portables need this to use scan-code set 1 -- Cort */
664 kbd_write(KBD_CNTL_REG
, KBD_CCMD_READ_MODE
);
665 if (!(kbd_wait_for_input() & KBD_MODE_KCC
)) {
667 * If the controller does not support conversion,
668 * Set the keyboard to scan-code set 1.
670 kbd_write(KBD_DATA_REG
, 0xF0);
671 kbd_wait_for_input();
672 kbd_write(KBD_DATA_REG
, 0x01);
673 kbd_wait_for_input();
677 kbd_write(KBD_DATA_REG
, KBD_CMD_ENABLE
);
678 if (kbd_wait_for_input() != KBD_REPLY_ACK
)
679 return "Enable keyboard: no ACK";
682 * Finally, set the typematic rate to maximum.
684 kbd_write(KBD_DATA_REG
, KBD_CMD_SET_RATE
);
685 if (kbd_wait_for_input() != KBD_REPLY_ACK
)
686 return "Set rate: no ACK";
687 kbd_write(KBD_DATA_REG
, 0x00);
688 if (kbd_wait_for_input() != KBD_REPLY_ACK
)
689 return "Set rate: no ACK";
694 void __init
pckbd_init_hw(void)
696 /* Flush any pending input. */
699 if (kbd_startup_reset
) {
700 char *msg
= initialize_kbd();
702 printk(KERN_WARNING
"initialize_kbd: %s\n", msg
);
705 #if defined CONFIG_PSMOUSE
709 /* Ok, finally allocate the IRQ, and off we go.. */
710 request_irq(KEYBOARD_IRQ
, keyboard_interrupt
, 0, "keyboard", NULL
);
713 #if defined CONFIG_PSMOUSE
716 * Check if this is a dual port controller.
718 static int __init
detect_auxiliary_port(void)
724 spin_lock_irqsave(&kbd_controller_lock
, flags
);
726 /* Put the value 0x5A in the output buffer using the "Write
727 * Auxiliary Device Output Buffer" command (0xD3). Poll the
728 * Status Register for a while to see if the value really
729 * turns up in the Data Register. If the KBD_STAT_MOUSE_OBF
730 * bit is also set to 1 in the Status Register, we assume this
731 * controller has an Auxiliary Port (a.k.a. Mouse Port).
734 outb(KBD_CCMD_WRITE_AUX_OBUF
, KBD_CNTL_REG
);
737 outb(0x5a, KBD_DATA_REG
); /* 0x5a is a random dummy value. */
740 unsigned char status
= inb(KBD_STATUS_REG
);
742 if (status
& KBD_STAT_OBF
) {
743 (void) inb(KBD_DATA_REG
);
744 if (status
& KBD_STAT_MOUSE_OBF
) {
745 printk(KERN_INFO
"Detected PS/2 Mouse Port.\n");
752 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
758 * Send a byte to the mouse.
760 static void aux_write_dev(int val
)
764 spin_lock_irqsave(&kbd_controller_lock
, flags
);
766 outb(KBD_CCMD_WRITE_MOUSE
, KBD_CNTL_REG
);
768 outb(val
, KBD_DATA_REG
);
769 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
773 * Send a byte to the mouse & handle returned ack
775 static void aux_write_ack(int val
)
779 spin_lock_irqsave(&kbd_controller_lock
, flags
);
781 outb(KBD_CCMD_WRITE_MOUSE
, KBD_CNTL_REG
);
783 outb(val
, KBD_DATA_REG
);
784 /* we expect an ACK in response. */
785 mouse_reply_expected
++;
787 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
790 static unsigned char get_from_queue(void)
792 unsigned char result
;
795 spin_lock_irqsave(&kbd_controller_lock
, flags
);
796 result
= queue
->buf
[queue
->tail
];
797 queue
->tail
= (queue
->tail
+ 1) & (AUX_BUF_SIZE
-1);
798 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
803 static inline int queue_empty(void)
805 return queue
->head
== queue
->tail
;
808 static int fasync_aux(int fd
, struct file
*filp
, int on
)
812 retval
= fasync_helper(fd
, filp
, on
, &queue
->fasync
);
820 * Random magic cookie for the aux device
822 #define AUX_DEV ((void *)queue)
824 static int release_aux(struct inode
* inode
, struct file
* file
)
826 fasync_aux(-1, file
, 0);
829 kbd_write_cmd(AUX_INTS_OFF
); /* Disable controller ints */
830 kbd_write(KBD_CNTL_REG
, KBD_CCMD_MOUSE_DISABLE
);
831 free_irq(AUX_IRQ
, AUX_DEV
);
836 * Install interrupt handler.
837 * Enable auxiliary device.
840 static int open_aux(struct inode
* inode
, struct file
* file
)
845 queue
->head
= queue
->tail
= 0; /* Flush input queue */
846 if (request_irq(AUX_IRQ
, keyboard_interrupt
, SA_SHIRQ
, "PS/2 Mouse", AUX_DEV
)) {
850 kbd_write(KBD_CNTL_REG
, KBD_CCMD_MOUSE_ENABLE
); /* Enable the
853 aux_write_ack(AUX_ENABLE_DEV
); /* Enable aux device */
854 kbd_write_cmd(AUX_INTS_ON
); /* Enable controller ints */
860 * Put bytes from input queue to buffer.
863 static ssize_t
read_aux(struct file
* file
, char * buffer
,
864 size_t count
, loff_t
*ppos
)
866 DECLARE_WAITQUEUE(wait
, current
);
871 if (file
->f_flags
& O_NONBLOCK
)
873 add_wait_queue(&queue
->proc_list
, &wait
);
875 set_current_state(TASK_INTERRUPTIBLE
);
876 if (queue_empty() && !signal_pending(current
)) {
880 current
->state
= TASK_RUNNING
;
881 remove_wait_queue(&queue
->proc_list
, &wait
);
883 while (i
> 0 && !queue_empty()) {
884 c
= get_from_queue();
885 put_user(c
, buffer
++);
889 file
->f_dentry
->d_inode
->i_atime
= CURRENT_TIME
;
892 if (signal_pending(current
))
898 * Write to the aux device.
901 static ssize_t
write_aux(struct file
* file
, const char * buffer
,
902 size_t count
, loff_t
*ppos
)
910 count
= 32; /* Limit to 32 bytes. */
913 get_user(c
, buffer
++);
920 file
->f_dentry
->d_inode
->i_mtime
= CURRENT_TIME
;
927 static unsigned int aux_poll(struct file
*file
, poll_table
* wait
)
929 poll_wait(file
, &queue
->proc_list
, wait
);
931 return POLLIN
| POLLRDNORM
;
935 struct file_operations psaux_fops
= {
953 static struct miscdevice psaux_mouse
= {
954 PSMOUSE_MINOR
, "psaux", &psaux_fops
957 static int __init
psaux_init(void)
959 if (!detect_auxiliary_port())
962 misc_register(&psaux_mouse
);
963 queue
= (struct aux_queue
*) kmalloc(sizeof(*queue
), GFP_KERNEL
);
964 memset(queue
, 0, sizeof(*queue
));
965 queue
->head
= queue
->tail
= 0;
966 init_waitqueue_head(&queue
->proc_list
);
968 #ifdef INITIALIZE_MOUSE
969 kbd_write(KBD_CNTL_REG
, KBD_CCMD_MOUSE_ENABLE
); /* Enable Aux. */
970 aux_write_ack(AUX_SET_SAMPLE
);
971 aux_write_ack(100); /* 100 samples/sec */
972 aux_write_ack(AUX_SET_RES
);
973 aux_write_ack(3); /* 8 counts per mm */
974 aux_write_ack(AUX_SET_SCALE21
); /* 2:1 scaling */
975 #endif /* INITIALIZE_MOUSE */
976 kbd_write(KBD_CNTL_REG
, KBD_CCMD_MOUSE_DISABLE
); /* Disable aux device. */
977 kbd_write_cmd(AUX_INTS_OFF
); /* Disable controller ints. */
982 #endif /* CONFIG_PSMOUSE */