PS/2 keyboard check availability
This commit is contained in:
@@ -15,10 +15,13 @@
|
|||||||
#include <sync/spin_lock.h>
|
#include <sync/spin_lock.h>
|
||||||
#include <sys/debug.h>
|
#include <sys/debug.h>
|
||||||
#include <sys/smp.h>
|
#include <sys/smp.h>
|
||||||
|
#include <sys/stall.h>
|
||||||
|
|
||||||
#define KB_CTL_STATUS 0x64
|
#define KB_CTL_STATUS 0x64
|
||||||
#define KB_DATA_IN_BUF 0x01
|
#define KB_DATA_IN_BUF 0x01
|
||||||
#define KB_DATA 0x60
|
#define KB_DATA 0x60
|
||||||
|
#define KB_IDENTIFY 0xF2
|
||||||
|
#define KB_ACK 0xFA
|
||||||
|
|
||||||
#define PS2KB_RINGBUFFER_MAX 2048
|
#define PS2KB_RINGBUFFER_MAX 2048
|
||||||
|
|
||||||
@@ -225,7 +228,34 @@ static void ps2kb_set_typematic(uint8_t delay, uint8_t rate) {
|
|||||||
outb(KB_DATA, (delay << 5) | (rate & 0x1F));
|
outb(KB_DATA, (delay << 5) | (rate & 0x1F));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static bool ps2kb_check(void) {
|
||||||
|
while (inb(KB_CTL_STATUS) & KB_DATA_IN_BUF)
|
||||||
|
inb(KB_DATA);
|
||||||
|
|
||||||
|
while (inb(KB_CTL_STATUS) & 0x02)
|
||||||
|
;
|
||||||
|
|
||||||
|
outb(KB_DATA, KB_IDENTIFY);
|
||||||
|
|
||||||
|
for (int i = 0; i < 1000; i++) {
|
||||||
|
if (inb(KB_CTL_STATUS) & KB_DATA_IN_BUF) {
|
||||||
|
uint8_t response = inb(KB_DATA);
|
||||||
|
if (response == KB_ACK)
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
stall_ms(2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
DEFINE_DEVICE_INIT(ps2kb_init) {
|
DEFINE_DEVICE_INIT(ps2kb_init) {
|
||||||
|
if (!ps2kb_check()) {
|
||||||
|
DEBUG("PS/2 keyboard not detected!\n");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
ioapic_route_irq(INTR_PS2KB, 1, 0, thiscpu->lapic_id);
|
ioapic_route_irq(INTR_PS2KB, 1, 0, thiscpu->lapic_id);
|
||||||
irq_attach(&ps2kb_irq, NULL, INTR_PS2KB);
|
irq_attach(&ps2kb_irq, NULL, INTR_PS2KB);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user