2 Copyright © 1995-2009, The AROS Development Team. All rights reserved.
5 Desc: PS/2 mouse driver.
10 #define TIMER_RPROK 3599597124UL
12 int kbd_wait_for_input(void);
14 static ULONG
usec2tick(ULONG usec
)
17 ULONG prok
= TIMER_RPROK
;
18 asm volatile("movl $0,%%eax; divl %2":"=a"(ret
):"d"(usec
),"m"(prok
));
22 static void mouse_usleep(LONG usec
)
25 usec
= usec2tick(usec
);
29 oldtick
+= inb(0x42) << 8;
35 tick
+= inb(0x42) << 8;
37 usec
-= (oldtick
- tick
);
38 if (tick
> oldtick
) usec
-= 0x10000;
44 unsigned char handle_kbd_event(void)
46 unsigned char status
= kbd_read_status();
47 unsigned int work
= 10000;
49 while (status
& KBD_STATUS_OBF
)
51 unsigned char scancode
;
53 scancode
= kbd_read_input();
55 status
= kbd_read_status();
58 //printf(KERN_ERR "pc_keyb: controller jammed (0x%02X).\n",status);
66 * Wait until we can write to a peripheral again. Any input that comes in
67 * while we're waiting is discarded.
71 ULONG timeout
= 1000; /* 1 sec should be enough */
75 unsigned char status
= handle_kbd_event();
76 if (! (status
& KBD_STATUS_IBF
))
84 void kbd_write_cmd(int cmd
)
87 kbd_write_command(KBD_CTRLCMD_WRITE_MODE
);
89 kbd_write_output(cmd
);
92 void aux_write_ack(int val
)
95 kbd_write_command(KBD_CTRLCMD_WRITE_MOUSE
);
97 kbd_write_output(val
);
101 void aux_write_noack(int val
)
104 kbd_write_command(KBD_CTRLCMD_WRITE_MOUSE
);
106 kbd_write_output(val
);
109 void kbd_write_output_w(int data
)
112 kbd_write_output(data
);
115 void kbd_write_command_w(int data
)
118 kbd_write_command(data
);
121 #define KBD_NO_DATA (-1)
122 #define KBD_BAD_DATA (-2)
124 int kbd_read_data(void)
126 LONG retval
= KBD_NO_DATA
;
129 status
= kbd_read_status();
130 if (status
& KBD_STATUS_OBF
)
132 UBYTE data
= kbd_read_input();
135 if (status
& (KBD_STATUS_GTO
| KBD_STATUS_PERR
))
136 retval
= KBD_BAD_DATA
;
142 int kbd_clear_input(void)
144 int maxread
= 100, code
, lastcode
= KBD_NO_DATA
;
149 status
= kbd_read_status();
150 if ((code
= kbd_read_data()) == KBD_NO_DATA
)
152 if (!(status
& KBD_STATUS_MOUSE_OBF
))
159 int kbd_wait_for_input(void)
161 ULONG timeout
= 1000;
165 int retval
= kbd_read_data();