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>
35 #include <asm/keyboard.h>
36 #include <asm/bitops.h>
37 #include <asm/uaccess.h>
39 #include <asm/system.h>
43 /* Some configuration switches are present in the include file... */
45 #include <linux/pc_keyb.h>
47 /* Simple translation table for the SysRq keys */
49 #ifdef CONFIG_MAGIC_SYSRQ
50 unsigned char pckbd_sysrq_xlate
[128] =
51 "\000\0331234567890-=\177\t" /* 0x00 - 0x0f */
52 "qwertyuiop[]\r\000as" /* 0x10 - 0x1f */
53 "dfghjkl;'`\000\\zxcv" /* 0x20 - 0x2f */
54 "bnm,./\000*\000 \000\201\202\203\204\205" /* 0x30 - 0x3f */
55 "\206\207\210\211\212\000\000789-456+1" /* 0x40 - 0x4f */
56 "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */
57 "\r\000/"; /* 0x60 - 0x6f */
60 static void kbd_write_command_w(int data
);
61 static void kbd_write_output_w(int data
);
63 static void aux_write_ack(int val
);
66 spinlock_t kbd_controller_lock
= SPIN_LOCK_UNLOCKED
;
67 static unsigned char handle_kbd_event(void);
69 /* used only by send_data - set by keyboard_interrupt */
70 static volatile unsigned char reply_expected
= 0;
71 static volatile unsigned char acknowledge
= 0;
72 static volatile unsigned char resend
= 0;
75 #if defined CONFIG_PSMOUSE
77 * PS/2 Auxiliary Device
80 static int __init
psaux_init(void);
82 #define AUX_RECONNECT 170 /* scancode when ps2 device is plugged (back) in */
84 static struct aux_queue
*queue
; /* Mouse data buffer. */
85 static int aux_count
= 0;
86 /* used when we send commands to the mouse that expect an ACK. */
87 static unsigned char mouse_reply_expected
= 0;
89 #define AUX_INTS_OFF (KBD_MODE_KCC | KBD_MODE_DISABLE_MOUSE | KBD_MODE_SYS | KBD_MODE_KBD_INT)
90 #define AUX_INTS_ON (KBD_MODE_KCC | KBD_MODE_SYS | KBD_MODE_MOUSE_INT | KBD_MODE_KBD_INT)
92 #define MAX_RETRIES 60 /* some aux operations take long time*/
93 #endif /* CONFIG_PSMOUSE */
96 * Wait for keyboard controller input buffer to drain.
98 * Don't use 'jiffies' so that we don't depend on
101 * Quote from PS/2 System Reference Manual:
103 * "Address hex 0060 and address hex 0064 should be written only when
104 * the input-buffer-full bit and output-buffer-full bit in the
105 * Controller Status register are set 0."
108 static void kb_wait(void)
110 unsigned long timeout
= KBC_TIMEOUT
;
114 * "handle_kbd_event()" will handle any incoming events
115 * while we wait - keypresses or mouse movement.
117 unsigned char status
= handle_kbd_event();
119 if (! (status
& KBD_STAT_IBF
))
124 #ifdef KBD_REPORT_TIMEOUTS
125 printk(KERN_WARNING
"Keyboard timed out[1]\n");
130 * Translation of escaped scancodes to keycodes.
131 * This is now user-settable.
132 * The keycodes 1-88,96-111,119 are fairly standard, and
133 * should probably not be changed - changing might confuse X.
134 * X also interprets scancode 0x5d (KEY_Begin).
136 * For 1-88 keycode equals scancode.
139 #define E0_KPENTER 96
141 #define E0_KPSLASH 98
144 #define E0_BREAK 101 /* (control-pause) */
159 * The keycodes below are randomly located in 89-95,112-118,120-127.
160 * They could be thrown away (and all occurrences below replaced by 0),
161 * but that would force many users to use the `setkeycodes' utility, where
162 * they needed not before. It does not matter that there are duplicates, as
163 * long as no duplication occurs for any single keyboard.
167 #define FOCUS_PF1 85 /* actual code! */
175 #define FOCUS_PF9 120
176 #define FOCUS_PF10 121
177 #define FOCUS_PF11 122
178 #define FOCUS_PF12 123
181 /* tfj@olivia.ping.dk:
182 * The four keys are located over the numeric keypad, and are
183 * labelled A1-A4. It's an rc930 keyboard, from
184 * Regnecentralen/RC International, Now ICL.
185 * Scancodes: 59, 5a, 5b, 5c.
192 static unsigned char high_keys
[128 - SC_LIM
] = {
193 RGN1
, RGN2
, RGN3
, RGN4
, 0, 0, 0, /* 0x59-0x5f */
194 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x67 */
195 0, 0, 0, 0, 0, FOCUS_PF11
, 0, FOCUS_PF12
, /* 0x68-0x6f */
196 0, 0, 0, FOCUS_PF2
, FOCUS_PF9
, 0, 0, FOCUS_PF3
, /* 0x70-0x77 */
197 FOCUS_PF4
, FOCUS_PF5
, FOCUS_PF6
, FOCUS_PF7
, /* 0x78-0x7b */
198 FOCUS_PF8
, JAP_86
, FOCUS_PF10
, 0 /* 0x7c-0x7f */
209 #define E0_KPMINPLUS 118
211 * My OmniKey generates e0 4c for the "OMNI" key and the
212 * right alt key does nada. [kkoller@nyx10.cs.du.edu]
216 * New microsoft keyboard is rumoured to have
217 * e0 5b (left window button), e0 5c (right window button),
218 * e0 5d (menu button). [or: LBANNER, RBANNER, RMENU]
219 * [or: Windows_L, Windows_R, TaskMan]
225 static unsigned char e0_keys
[128] = {
226 0, 0, 0, 0, 0, 0, 0, 0, /* 0x00-0x07 */
227 0, 0, 0, 0, 0, 0, 0, 0, /* 0x08-0x0f */
228 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10-0x17 */
229 0, 0, 0, 0, E0_KPENTER
, E0_RCTRL
, 0, 0, /* 0x18-0x1f */
230 0, 0, 0, 0, 0, 0, 0, 0, /* 0x20-0x27 */
231 0, 0, 0, 0, 0, 0, 0, 0, /* 0x28-0x2f */
232 0, 0, 0, 0, 0, E0_KPSLASH
, 0, E0_PRSCR
, /* 0x30-0x37 */
233 E0_RALT
, 0, 0, 0, 0, E0_F13
, E0_F14
, E0_HELP
, /* 0x38-0x3f */
234 E0_DO
, E0_F17
, 0, 0, 0, 0, E0_BREAK
, E0_HOME
, /* 0x40-0x47 */
235 E0_UP
, E0_PGUP
, 0, E0_LEFT
, E0_OK
, E0_RIGHT
, E0_KPMINPLUS
, E0_END
,/* 0x48-0x4f */
236 E0_DOWN
, E0_PGDN
, E0_INS
, E0_DEL
, 0, 0, 0, 0, /* 0x50-0x57 */
237 0, 0, 0, E0_MSLW
, E0_MSRW
, E0_MSTM
, 0, 0, /* 0x58-0x5f */
238 0, 0, 0, 0, 0, 0, 0, 0, /* 0x60-0x67 */
239 0, 0, 0, 0, 0, 0, 0, E0_MACRO
, /* 0x68-0x6f */
240 0, 0, 0, 0, 0, 0, 0, 0, /* 0x70-0x77 */
241 0, 0, 0, 0, 0, 0, 0, 0 /* 0x78-0x7f */
244 int pckbd_setkeycode(unsigned int scancode
, unsigned int keycode
)
246 if (scancode
< SC_LIM
|| scancode
> 255 || keycode
> 127)
249 high_keys
[scancode
- SC_LIM
] = keycode
;
251 e0_keys
[scancode
- 128] = keycode
;
255 int pckbd_getkeycode(unsigned int scancode
)
258 (scancode
< SC_LIM
|| scancode
> 255) ? -EINVAL
:
259 (scancode
< 128) ? high_keys
[scancode
- SC_LIM
] :
260 e0_keys
[scancode
- 128];
263 static int do_acknowledge(unsigned char scancode
)
265 if (reply_expected
) {
266 /* Unfortunately, we must recognise these codes only if we know they
267 * are known to be valid (i.e., after sending a command), because there
268 * are some brain-damaged keyboards (yes, FOCUS 9000 again) which have
269 * keys with such codes :(
271 if (scancode
== KBD_REPLY_ACK
) {
275 } else if (scancode
== KBD_REPLY_RESEND
) {
280 /* Should not happen... */
282 printk(KERN_DEBUG
"keyboard reply expected - got %02x\n",
289 int pckbd_translate(unsigned char scancode
, unsigned char *keycode
,
292 static int prev_scancode
= 0;
294 /* special prefix scancodes.. */
295 if (scancode
== 0xe0 || scancode
== 0xe1) {
296 prev_scancode
= scancode
;
300 /* 0xFF is sent by a few keyboards, ignore it. 0x00 is error */
301 if (scancode
== 0x00 || scancode
== 0xff) {
310 * usually it will be 0xe0, but a Pause key generates
311 * e1 1d 45 e1 9d c5 when pressed, and nothing when released
313 if (prev_scancode
!= 0xe0) {
314 if (prev_scancode
== 0xe1 && scancode
== 0x1d) {
315 prev_scancode
= 0x100;
317 } else if (prev_scancode
== 0x100 && scancode
== 0x45) {
321 #ifdef KBD_REPORT_UNKN
323 printk(KERN_INFO
"keyboard: unknown e1 escape sequence\n");
331 * The keyboard maintains its own internal caps lock and
332 * num lock statuses. In caps lock mode E0 AA precedes make
333 * code and E0 2A follows break code. In num lock mode,
334 * E0 2A precedes make code and E0 AA follows break code.
335 * We do our own book-keeping, so we will just ignore these.
338 * For my keyboard there is no caps lock mode, but there are
339 * both Shift-L and Shift-R modes. The former mode generates
340 * E0 2A / E0 AA pairs, the latter E0 B6 / E0 36 pairs.
341 * So, we should also ignore the latter. - aeb@cwi.nl
343 if (scancode
== 0x2a || scancode
== 0x36)
346 if (e0_keys
[scancode
])
347 *keycode
= e0_keys
[scancode
];
349 #ifdef KBD_REPORT_UNKN
351 printk(KERN_INFO
"keyboard: unknown scancode e0 %02x\n",
357 } else if (scancode
>= SC_LIM
) {
358 /* This happens with the FOCUS 9000 keyboard
359 Its keys PF1..PF12 are reported to generate
360 55 73 77 78 79 7a 7b 7c 74 7e 6d 6f
361 Moreover, unless repeated, they do not generate
362 key-down events, so we have to zero up_flag below */
363 /* Also, Japanese 86/106 keyboards are reported to
364 generate 0x73 and 0x7d for \ - and \ | respectively. */
365 /* Also, some Brazilian keyboard is reported to produce
366 0x73 and 0x7e for \ ? and KP-dot, respectively. */
368 *keycode
= high_keys
[scancode
- SC_LIM
];
372 #ifdef KBD_REPORT_UNKN
373 printk(KERN_INFO
"keyboard: unrecognized scancode (%02x)"
374 " - ignored\n", scancode
);
384 char pckbd_unexpected_up(unsigned char keycode
)
386 /* unexpected, but this can happen: maybe this was a key release for a
387 FOCUS 9000 PF key; if we want to see it, we have to clear up_flag */
388 if (keycode
>= SC_LIM
|| keycode
== 85)
394 static inline void handle_mouse_event(unsigned char scancode
)
396 #ifdef CONFIG_PSMOUSE
397 if (mouse_reply_expected
) {
398 if (scancode
== AUX_ACK
) {
399 mouse_reply_expected
--;
402 mouse_reply_expected
= 0;
404 else if(scancode
== AUX_RECONNECT
){
405 queue
->head
= queue
->tail
= 0; /* Flush input queue */
406 aux_write_ack(AUX_ENABLE_DEV
); /* ping the mouse :) */
410 add_mouse_randomness(scancode
);
412 int head
= queue
->head
;
414 queue
->buf
[head
] = scancode
;
415 head
= (head
+ 1) & (AUX_BUF_SIZE
-1);
416 if (head
!= queue
->tail
) {
418 kill_fasync(&queue
->fasync
, SIGIO
, POLL_IN
);
419 wake_up_interruptible(&queue
->proc_list
);
425 static unsigned char kbd_exists
= 1;
427 static inline void handle_keyboard_event(unsigned char scancode
)
431 if (do_acknowledge(scancode
))
432 handle_scancode(scancode
, !(scancode
& 0x80));
434 tasklet_schedule(&keyboard_tasklet
);
438 * This reads the keyboard status port, and does the
439 * appropriate action.
441 * It requires that we hold the keyboard controller
444 static unsigned char handle_kbd_event(void)
446 unsigned char status
= kbd_read_status();
447 unsigned int work
= 10000;
449 while (status
& KBD_STAT_OBF
) {
450 unsigned char scancode
;
452 scancode
= kbd_read_input();
454 /* Error bytes must be ignored to make the
455 Synaptics touchpads compaq use work */
457 /* Ignore error bytes */
458 if (!(status
& (KBD_STAT_GTO
| KBD_STAT_PERR
)))
461 if (status
& KBD_STAT_MOUSE_OBF
)
462 handle_mouse_event(scancode
);
464 handle_keyboard_event(scancode
);
467 status
= kbd_read_status();
470 printk(KERN_ERR
"pc_keyb: controller jammed (0x%02X).\n",
480 static void keyboard_interrupt(int irq
, void *dev_id
, struct pt_regs
*regs
)
487 spin_lock_irqsave(&kbd_controller_lock
, flags
);
489 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
493 * send_data sends a character to the keyboard and waits
494 * for an acknowledge, possibly retrying if asked to. Returns
495 * the success status.
497 * Don't use 'jiffies', so that we don't depend on interrupts
499 static int send_data(unsigned char data
)
504 unsigned long timeout
= KBD_TIMEOUT
;
506 acknowledge
= 0; /* Set by interrupt routine on receipt of ACK. */
509 kbd_write_output_w(data
);
517 #ifdef KBD_REPORT_TIMEOUTS
518 printk(KERN_WARNING
"keyboard: Timeout - AT keyboard not present?\n");
523 } while (retries
-- > 0);
524 #ifdef KBD_REPORT_TIMEOUTS
525 printk(KERN_WARNING
"keyboard: Too many NACKs -- noisy kbd cable?\n");
530 void pckbd_leds(unsigned char leds
)
532 if (kbd_exists
&& (!send_data(KBD_CMD_SET_LEDS
) || !send_data(leds
))) {
533 send_data(KBD_CMD_ENABLE
); /* re-enable kbd if any errors */
539 * In case we run on a non-x86 hardware we need to initialize both the
540 * keyboard controller and the keyboard. On a x86, the BIOS will
541 * already have initialized them.
543 * Some x86 BIOSes do not correctly initialize the keyboard, so the
544 * "kbd-reset" command line options can be given to force a reset.
548 int kbd_startup_reset __initdata
= 0;
550 int kbd_startup_reset __initdata
= 1;
553 /* for "kbd-reset" cmdline param */
554 static int __init
kbd_reset_setup(char *str
)
556 kbd_startup_reset
= 1;
560 __setup("kbd-reset", kbd_reset_setup
);
562 #define KBD_NO_DATA (-1) /* No data */
563 #define KBD_BAD_DATA (-2) /* Parity or other error */
565 static int __init
kbd_read_data(void)
567 int retval
= KBD_NO_DATA
;
568 unsigned char status
;
570 status
= kbd_read_status();
571 if (status
& KBD_STAT_OBF
) {
572 unsigned char data
= kbd_read_input();
575 if (status
& (KBD_STAT_GTO
| KBD_STAT_PERR
))
576 retval
= KBD_BAD_DATA
;
581 static void __init
kbd_clear_input(void)
583 int maxread
= 100; /* Random number */
586 if (kbd_read_data() == KBD_NO_DATA
)
591 static int __init
kbd_wait_for_input(void)
593 long timeout
= KBD_INIT_TIMEOUT
;
596 int retval
= kbd_read_data();
604 static void kbd_write_command_w(int data
)
608 spin_lock_irqsave(&kbd_controller_lock
, flags
);
610 kbd_write_command(data
);
611 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
614 static void kbd_write_output_w(int data
)
618 spin_lock_irqsave(&kbd_controller_lock
, flags
);
620 kbd_write_output(data
);
621 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
624 #if defined CONFIG_PSMOUSE
625 static void kbd_write_cmd(int cmd
)
629 spin_lock_irqsave(&kbd_controller_lock
, flags
);
631 kbd_write_command(KBD_CCMD_WRITE_MODE
);
633 kbd_write_output(cmd
);
634 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
636 #endif /* CONFIG_PSMOUSE */
638 static char * __init
initialize_kbd(void)
643 * Test the keyboard interface.
644 * This seems to be the only way to get it going.
645 * If the test is successful a x55 is placed in the input buffer.
647 kbd_write_command_w(KBD_CCMD_SELF_TEST
);
648 if (kbd_wait_for_input() != 0x55)
649 return "Keyboard failed self test";
652 * Perform a keyboard interface test. This causes the controller
653 * to test the keyboard clock and data lines. The results of the
654 * test are placed in the input buffer.
656 kbd_write_command_w(KBD_CCMD_KBD_TEST
);
657 if (kbd_wait_for_input() != 0x00)
658 return "Keyboard interface failed self test";
661 * Enable the keyboard by allowing the keyboard clock to run.
663 kbd_write_command_w(KBD_CCMD_KBD_ENABLE
);
666 * Reset keyboard. If the read times out
667 * then the assumption is that no keyboard is
668 * plugged into the machine.
669 * This defaults the keyboard to scan-code set 2.
671 * Set up to try again if the keyboard asks for RESEND.
674 kbd_write_output_w(KBD_CMD_RESET
);
675 status
= kbd_wait_for_input();
676 if (status
== KBD_REPLY_ACK
)
678 if (status
!= KBD_REPLY_RESEND
)
679 return "Keyboard reset failed, no ACK";
682 if (kbd_wait_for_input() != KBD_REPLY_POR
)
683 return "Keyboard reset failed, no POR";
686 * Set keyboard controller mode. During this, the keyboard should be
687 * in the disabled state.
689 * Set up to try again if the keyboard asks for RESEND.
692 kbd_write_output_w(KBD_CMD_DISABLE
);
693 status
= kbd_wait_for_input();
694 if (status
== KBD_REPLY_ACK
)
696 if (status
!= KBD_REPLY_RESEND
)
697 return "Disable keyboard: no ACK";
700 kbd_write_command_w(KBD_CCMD_WRITE_MODE
);
701 kbd_write_output_w(KBD_MODE_KBD_INT
703 | KBD_MODE_DISABLE_MOUSE
706 /* ibm powerpc portables need this to use scan-code set 1 -- Cort */
707 kbd_write_command_w(KBD_CCMD_READ_MODE
);
708 if (!(kbd_wait_for_input() & KBD_MODE_KCC
)) {
710 * If the controller does not support conversion,
711 * Set the keyboard to scan-code set 1.
713 kbd_write_output_w(0xF0);
714 kbd_wait_for_input();
715 kbd_write_output_w(0x01);
716 kbd_wait_for_input();
720 kbd_write_output_w(KBD_CMD_ENABLE
);
721 if (kbd_wait_for_input() != KBD_REPLY_ACK
)
722 return "Enable keyboard: no ACK";
725 * Finally, set the typematic rate to maximum.
727 kbd_write_output_w(KBD_CMD_SET_RATE
);
728 if (kbd_wait_for_input() != KBD_REPLY_ACK
)
729 return "Set rate: no ACK";
730 kbd_write_output_w(0x00);
731 if (kbd_wait_for_input() != KBD_REPLY_ACK
)
732 return "Set rate: no ACK";
737 void __init
pckbd_init_hw(void)
739 kbd_request_region();
741 /* Flush any pending input. */
744 if (kbd_startup_reset
) {
745 char *msg
= initialize_kbd();
747 printk(KERN_WARNING
"initialize_kbd: %s\n", msg
);
750 #if defined CONFIG_PSMOUSE
754 /* Ok, finally allocate the IRQ, and off we go.. */
755 kbd_request_irq(keyboard_interrupt
);
758 #if defined CONFIG_PSMOUSE
761 * Check if this is a dual port controller.
763 static int __init
detect_auxiliary_port(void)
769 /* Check if the BIOS detected a device on the auxiliary port. */
770 if (aux_device_present
== 0xaa)
773 spin_lock_irqsave(&kbd_controller_lock
, flags
);
775 /* Put the value 0x5A in the output buffer using the "Write
776 * Auxiliary Device Output Buffer" command (0xD3). Poll the
777 * Status Register for a while to see if the value really
778 * turns up in the Data Register. If the KBD_STAT_MOUSE_OBF
779 * bit is also set to 1 in the Status Register, we assume this
780 * controller has an Auxiliary Port (a.k.a. Mouse Port).
783 kbd_write_command(KBD_CCMD_WRITE_AUX_OBUF
);
786 kbd_write_output(0x5a); /* 0x5a is a random dummy value. */
789 unsigned char status
= kbd_read_status();
791 if (status
& KBD_STAT_OBF
) {
792 (void) kbd_read_input();
793 if (status
& KBD_STAT_MOUSE_OBF
) {
794 printk(KERN_INFO
"Detected PS/2 Mouse Port.\n");
801 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
807 * Send a byte to the mouse.
809 static void aux_write_dev(int val
)
813 spin_lock_irqsave(&kbd_controller_lock
, flags
);
815 kbd_write_command(KBD_CCMD_WRITE_MOUSE
);
817 kbd_write_output(val
);
818 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
822 * Send a byte to the mouse & handle returned ack
824 static void aux_write_ack(int val
)
828 spin_lock_irqsave(&kbd_controller_lock
, flags
);
830 kbd_write_command(KBD_CCMD_WRITE_MOUSE
);
832 kbd_write_output(val
);
833 /* we expect an ACK in response. */
834 mouse_reply_expected
++;
836 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
839 static unsigned char get_from_queue(void)
841 unsigned char result
;
844 spin_lock_irqsave(&kbd_controller_lock
, flags
);
845 result
= queue
->buf
[queue
->tail
];
846 queue
->tail
= (queue
->tail
+ 1) & (AUX_BUF_SIZE
-1);
847 spin_unlock_irqrestore(&kbd_controller_lock
, flags
);
852 static inline int queue_empty(void)
854 return queue
->head
== queue
->tail
;
857 static int fasync_aux(int fd
, struct file
*filp
, int on
)
861 retval
= fasync_helper(fd
, filp
, on
, &queue
->fasync
);
869 * Random magic cookie for the aux device
871 #define AUX_DEV ((void *)queue)
873 static int release_aux(struct inode
* inode
, struct file
* file
)
875 fasync_aux(-1, file
, 0);
878 kbd_write_cmd(AUX_INTS_OFF
); /* Disable controller ints */
879 kbd_write_command_w(KBD_CCMD_MOUSE_DISABLE
);
880 aux_free_irq(AUX_DEV
);
885 * Install interrupt handler.
886 * Enable auxiliary device.
889 static int open_aux(struct inode
* inode
, struct file
* file
)
894 queue
->head
= queue
->tail
= 0; /* Flush input queue */
895 if (aux_request_irq(keyboard_interrupt
, AUX_DEV
)) {
899 kbd_write_command_w(KBD_CCMD_MOUSE_ENABLE
); /* Enable the
902 aux_write_ack(AUX_ENABLE_DEV
); /* Enable aux device */
903 kbd_write_cmd(AUX_INTS_ON
); /* Enable controller ints */
905 send_data(KBD_CMD_ENABLE
); /* try to workaround toshiba4030cdt problem */
911 * Put bytes from input queue to buffer.
914 static ssize_t
read_aux(struct file
* file
, char * buffer
,
915 size_t count
, loff_t
*ppos
)
917 DECLARE_WAITQUEUE(wait
, current
);
922 if (file
->f_flags
& O_NONBLOCK
)
924 add_wait_queue(&queue
->proc_list
, &wait
);
926 set_current_state(TASK_INTERRUPTIBLE
);
927 if (queue_empty() && !signal_pending(current
)) {
931 current
->state
= TASK_RUNNING
;
932 remove_wait_queue(&queue
->proc_list
, &wait
);
934 while (i
> 0 && !queue_empty()) {
935 c
= get_from_queue();
936 put_user(c
, buffer
++);
940 file
->f_dentry
->d_inode
->i_atime
= CURRENT_TIME
;
943 if (signal_pending(current
))
949 * Write to the aux device.
952 static ssize_t
write_aux(struct file
* file
, const char * buffer
,
953 size_t count
, loff_t
*ppos
)
961 count
= 32; /* Limit to 32 bytes. */
964 get_user(c
, buffer
++);
971 file
->f_dentry
->d_inode
->i_mtime
= CURRENT_TIME
;
978 /* No kernel lock held - fine */
979 static unsigned int aux_poll(struct file
*file
, poll_table
* wait
)
981 poll_wait(file
, &queue
->proc_list
, wait
);
983 return POLLIN
| POLLRDNORM
;
987 struct file_operations psaux_fops
= {
992 release
: release_aux
,
999 static struct miscdevice psaux_mouse
= {
1000 PSMOUSE_MINOR
, "psaux", &psaux_fops
1003 static int __init
psaux_init(void)
1005 if (!detect_auxiliary_port())
1008 misc_register(&psaux_mouse
);
1009 queue
= (struct aux_queue
*) kmalloc(sizeof(*queue
), GFP_KERNEL
);
1010 memset(queue
, 0, sizeof(*queue
));
1011 queue
->head
= queue
->tail
= 0;
1012 init_waitqueue_head(&queue
->proc_list
);
1014 #ifdef INITIALIZE_MOUSE
1015 kbd_write_command_w(KBD_CCMD_MOUSE_ENABLE
); /* Enable Aux. */
1016 aux_write_ack(AUX_SET_SAMPLE
);
1017 aux_write_ack(100); /* 100 samples/sec */
1018 aux_write_ack(AUX_SET_RES
);
1019 aux_write_ack(3); /* 8 counts per mm */
1020 aux_write_ack(AUX_SET_SCALE21
); /* 2:1 scaling */
1021 #endif /* INITIALIZE_MOUSE */
1022 kbd_write_command(KBD_CCMD_MOUSE_DISABLE
); /* Disable aux device. */
1023 kbd_write_cmd(AUX_INTS_OFF
); /* Disable controller ints. */
1028 #endif /* CONFIG_PSMOUSE */