Wait on the correct bit in the lower half of kbc_get8042cmd(); and some other

mostly stylistic changes.  Based on suggestions from John Hood.
This commit is contained in:
mycroft 1994-10-16 15:46:13 +00:00
parent 06b14c27fd
commit d00c05633a
1 changed files with 43 additions and 20 deletions

View File

@ -35,7 +35,7 @@
* SUCH DAMAGE.
*
* from: @(#)pccons.c 5.11 (Berkeley) 5/21/91
* $Id: pccons.c,v 1.67 1994/10/09 09:28:54 mycroft Exp $
* $Id: pccons.c,v 1.68 1994/10/16 15:46:13 mycroft Exp $
*/
/*
@ -156,7 +156,7 @@ extern pcopen(dev_t, int, int, struct proc *);
{ u_char x = inb(0x84); }
static inline int
kbd_wait()
kbd_wait_output()
{
u_int i;
@ -168,6 +168,32 @@ kbd_wait()
return 0;
}
static inline int
kbd_wait_input()
{
u_int i;
for (i = 100000; i; i--)
if ((inb(KBSTATP) & KBS_DIB) != 0) {
KBD_DELAY;
return 1;
}
return 0;
}
static inline void
kbd_flush_input()
{
u_int i;
for (i = 10; i; i--) {
if ((inb(KBSTATP) & KBS_DIB) == 0)
return;
KBD_DELAY;
(void) inb(KBDATAP);
}
}
#if 1
/*
* Get the current command byte.
@ -176,10 +202,10 @@ static u_char
kbc_get8042cmd()
{
if (!kbd_wait())
if (!kbd_wait_output())
return -1;
outb(KBCMDP, K_RDCMDBYTE);
if (!kbd_wait())
if (!kbd_wait_input())
return -1;
return inb(KBDATAP);
}
@ -193,10 +219,10 @@ kbc_put8042cmd(val)
u_char val;
{
if (!kbd_wait())
if (!kbd_wait_output())
return 0;
outb(KBCMDP, K_LDCMDBYTE);
if (!kbd_wait())
if (!kbd_wait_output())
return 0;
outb(KBOUTP, val);
return 1;
@ -214,7 +240,7 @@ kbd_cmd(val, polling)
register u_int i;
do {
if (!kbd_wait())
if (!kbd_wait_output())
return 0;
ack = nak = 0;
outb(KBOUTP, val);
@ -240,7 +266,7 @@ kbd_cmd(val, polling)
}
else
for (i = 100000; i; i--) {
inb(KBSTATP);
(void) inb(KBSTATP);
if (ack)
return 1;
if (nak)
@ -331,7 +357,7 @@ pcprobe(parent, self, aux)
void *aux;
{
struct isa_attach_args *ia = aux;
u_char c;
u_int i;
/* Enable interrupts and keyboard, etc. */
if (!kbc_put8042cmd(CMDBYTE)) {
@ -341,18 +367,18 @@ pcprobe(parent, self, aux)
#if 1
/* Flush any garbage. */
while (inb(KBSTATP) & KBS_DIB) {
KBD_DELAY;
(void) inb(KBDATAP);
}
kbd_flush_input();
/* Reset the keyboard. */
if (!kbd_cmd(KBC_RESET, 1)) {
printf("pcprobe: reset error %d\n", 1);
goto lose;
}
while ((inb(KBSTATP) & KBS_DIB) == 0);
KBD_DELAY;
if (inb(KBDATAP) != KBR_RSTDONE) {
for (i = 600000; i; i--)
if ((inb(KBSTATP) & KBS_DIB) != 0) {
KBD_DELAY;
break;
}
if (i == 0 || inb(KBDATAP) != KBR_RSTDONE) {
printf("pcprobe: reset error %d\n", 2);
goto lose;
}
@ -361,10 +387,7 @@ pcprobe(parent, self, aux)
* This is kind of stupid, but we account for them anyway by just
* flushing the buffer.
*/
while (inb(KBSTATP) & KBS_DIB) {
KBD_DELAY;
(void) inb(KBDATAP);
}
kbd_flush_input();
/* Just to be sure. */
if (!kbd_cmd(KBC_ENABLE, 1)) {
printf("pcprobe: reset error %d\n", 3);