/* * Send two-byte command to the device on a primary port. */ int i8042_kbd_command (int cmd, int param) { int count; unsigned char ack; /* Send command and wait for an ack response. */ /*debug_printf ("keyboard: command %02x-%02x\n", cmd, param);*/ i8042_kbd_write (cmd); if (! i8042_read (&ack) || ack != KBDR_ACK) { /*debug_printf ("keyboard: no ACK after command\n");*/ return 0; } /* Send a parameter and wait for an ack response. */ i8042_kbd_write (param); for (count=0; count<100; ++count) { if (! i8042_read (&ack)) continue; if (ack == KBDR_ACK) { return 1; } /*debug_printf ("keyboard: %02x (%d)\n", ack, count);*/ } /*debug_printf ("keyboard: no ACK\n", cmd, param);*/ return 0; }
/* * Look to see if we can find a device on the primary port. */ int i8042_kbd_probe () { int count; unsigned char ack; /* Send a reset and wait for an ack response. */ i8042_kbd_write (KBDK_RESET); if (! i8042_read (&ack) || ack != KBDR_ACK) { /*debug_printf ("keyboard: probe: no ACK after reset\n");*/ return 0; } /* Ensure that we see a basic assurance test response. */ for (count=0; count<1000; ++count) { if (! i8042_read (&ack)) continue; /*debug_printf ("keyboard: probe: %02x (%d)\n", ack, count);*/ if (ack == KBDR_TEST_OK) { return 1; } } /*debug_printf ("keyboard: probe: no BAT after reset\n");*/ return 0; }
static int ps2_sendbyte(int aux, u8 command, int timeout) { dprintf(7, "ps2_sendbyte aux=%d cmd=%x\n", aux, command); int ret; if (aux) ret = i8042_aux_write(command); else ret = i8042_kbd_write(command); if (ret) return ret; // Read ack. ret = ps2_recvbyte(aux, 1, timeout); if (ret < 0) return ret; if (ret != PS2_RET_ACK) return -1; return 0; }