1 #include <linux/keyboard.h>
3 #include "defkeymap.c" /* yeah I know it's bad -- Cort */
6 unsigned char shfts
, ctls
, alts
, caps
;
8 #define KBDATAP 0x60 /* kbd data port */
9 #define KBSTATUSPORT 0x61 /* kbd status */
10 #define KBSTATP 0x64 /* kbd status port */
14 extern unsigned char inb(int port
);
15 extern void outb(int port
, char val
);
16 extern void puts(const char *);
17 extern void puthex(unsigned long val
);
18 extern void udelay(long x
);
20 static int kbd(int noblock
)
22 unsigned char dt
, brk
, val
;
26 if ((inb(KBSTATP
) & KBINRDY
) == 0)
28 } else while((inb(KBSTATP
) & KBINRDY
) == 0) ;
32 brk
= dt
& 0x80; /* brk == 1 on key release */
33 dt
= dt
& 0x7f; /* keycode */
43 switch (KTYP(code
) & 0x0f) {
49 if (val
== 0x7f) /* map delete to backspace */
63 if (val
== KVAL(K_CAPS
))
65 else if (val
== KVAL(K_ENTER
)) {
66 enter
: /* Wait for key up */
68 while((inb(KBSTATP
) & KBINRDY
) == 0) ;
70 if (dt
& 0x80) /* key up */ break;
81 if (val
== KVAL(K_PENTER
))
126 if (brk
) return (-1); /* Ignore initial 'key up' codes */
130 static int __kbdreset(void)
135 /* flush input queue */
137 while ((inb(KBSTATP
) & KBINRDY
))
145 while (inb(KBSTATP
) & KBOUTRDY
)
150 while ((inb(KBSTATP
) & KBINRDY
) == 0) /* wait input ready */
153 if ((c
= inb(KBDATAP
)) != 0x55)
155 puts("Keyboard self test failed - result:");
159 /* Enable interrupts and keyboard controller */
161 while (inb(KBSTATP
) & KBOUTRDY
)
162 if (--t
== 0) return 4;
165 while (inb(KBSTATP
) & KBOUTRDY
)
166 if (--t
== 0) return 5;
168 for (i
= 0; i
< 10000; i
++) udelay(1);
171 while (inb(KBSTATP
) & KBOUTRDY
)
172 if (--t
== 0) return 6;
175 while ((inb(KBSTATP
) & KBINRDY
) == 0) /* wait input ready */
176 if (--t
== 0) return 7;
177 if (! (inb(KBDATAP
) & 0x40)) {
179 * Quote from PS/2 System Reference Manual:
181 * "Address hex 0060 and address hex 0064 should be
182 * written only when the input-buffer-full bit and
183 * output-buffer-full bit in the Controller Status
184 * register are set 0." (KBINRDY and KBOUTRDY)
187 while (inb(KBSTATP
) & (KBINRDY
| KBOUTRDY
))
188 if (--t
== 0) return 8;
191 while (inb(KBSTATP
) & (KBINRDY
| KBOUTRDY
))
192 if (--t
== 0) return 9;
196 while (inb(KBSTATP
) & KBOUTRDY
)
197 if (--t
== 0) return 10;
202 static void kbdreset(void)
204 int ret
= __kbdreset();
207 puts("__kbdreset failed: ");
213 /* We have to actually read the keyboard when CRT_tstc is called,
214 * since the pending data might be a key release code, and therefore
215 * not valid data. In this case, kbd() will return -1, even though there's
216 * data to be read. Of course, we might actually read a valid key press,
217 * in which case it gets queued into key_pending for use by CRT_getc.
220 static int kbd_reset
= 0;
222 static int key_pending
= -1;
227 if (!kbd_reset
) {kbdreset(); kbd_reset
++; }
229 if (key_pending
!= -1) {
234 while ((c
= kbd(0)) == 0) ;
241 if (!kbd_reset
) {kbdreset(); kbd_reset
++; }
243 while (key_pending
== -1 && ((inb(KBSTATP
) & KBINRDY
) != 0)) {
244 key_pending
= kbd(1);
247 return (key_pending
!= -1);