2004-03-11 16:01:31 +01:00
|
|
|
#include <console/console.h>
|
|
|
|
#include <pc80/keyboard.h>
|
|
|
|
#include <device/device.h>
|
2003-09-26 17:24:54 +02:00
|
|
|
#include <arch/io.h>
|
2003-09-26 18:12:23 +02:00
|
|
|
|
2004-11-11 12:56:00 +01:00
|
|
|
static int kbd_empty_input_buffer(void)
|
|
|
|
{
|
|
|
|
unsigned long timeout;
|
|
|
|
for(timeout = 1000000; timeout && (inb(0x64) & 0x02); timeout--) {
|
|
|
|
post_code(0);
|
|
|
|
}
|
|
|
|
return !!timeout;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int kbd_empty_output_buffer(void)
|
|
|
|
{
|
|
|
|
unsigned long timeout;
|
|
|
|
for(timeout = 1000000; timeout && ((inb(0x64) & 0x01) == 0); timeout--) {
|
|
|
|
post_code(0);
|
|
|
|
}
|
|
|
|
return !!timeout;
|
|
|
|
}
|
|
|
|
|
2003-09-26 17:24:54 +02:00
|
|
|
/* much better keyboard init courtesy ollie@sis.com.tw
|
|
|
|
TODO: Typematic Setting, the keyboard is too slow for me */
|
2004-11-11 07:53:24 +01:00
|
|
|
static void pc_keyboard_init(struct pc_keyboard *keyboard)
|
2003-09-26 17:24:54 +02:00
|
|
|
{
|
2004-11-11 12:56:00 +01:00
|
|
|
unsigned char regval;
|
2003-09-26 17:24:54 +02:00
|
|
|
|
|
|
|
/* send cmd = 0xAA, self test 8042 */
|
|
|
|
outb(0xaa, 0x64);
|
|
|
|
|
|
|
|
/* empty input buffer or any other command/data will be lost */
|
2004-11-11 12:56:00 +01:00
|
|
|
if (!kbd_empty_input_buffer()) {
|
|
|
|
printk_err("Keyboard input buffer would not empty\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2003-09-26 17:24:54 +02:00
|
|
|
/* empty output buffer or any other command/data will be lost */
|
2004-11-11 12:56:00 +01:00
|
|
|
if (!kbd_empty_output_buffer()) {
|
|
|
|
printk_err("Keyboard output buffer would not empty\n");
|
|
|
|
return;
|
|
|
|
}
|
2003-09-26 17:24:54 +02:00
|
|
|
|
|
|
|
/* read self-test result, 0x55 should be returned form 0x60 */
|
2007-05-24 15:55:45 +02:00
|
|
|
if ((regval = inb(0x60) != 0x55)) {
|
|
|
|
printk_err("Keyboard selftest failed\n");
|
2003-09-26 17:24:54 +02:00
|
|
|
return;
|
2007-05-24 15:55:45 +02:00
|
|
|
}
|
2003-09-26 17:24:54 +02:00
|
|
|
|
|
|
|
/* enable keyboard interface */
|
|
|
|
outb(0x60, 0x64);
|
2004-11-11 12:56:00 +01:00
|
|
|
kbd_empty_input_buffer();
|
2003-09-26 17:24:54 +02:00
|
|
|
|
|
|
|
/* send cmd: enable IRQ 1 */
|
|
|
|
outb(0x61, 0x60);
|
2004-11-11 12:56:00 +01:00
|
|
|
kbd_empty_input_buffer();
|
2003-09-26 17:24:54 +02:00
|
|
|
|
|
|
|
/* reset kerboard and self test (keyboard side) */
|
|
|
|
outb(0xff, 0x60);
|
|
|
|
|
|
|
|
/* empty inut bufferm or any other command/data will be lost */
|
2004-11-11 12:56:00 +01:00
|
|
|
kbd_empty_input_buffer();
|
|
|
|
|
2003-09-26 17:24:54 +02:00
|
|
|
/* empty output buffer or any other command/data will be lost */
|
2004-11-11 12:56:00 +01:00
|
|
|
kbd_empty_output_buffer();
|
2003-09-26 17:24:54 +02:00
|
|
|
|
|
|
|
if ((regval = inb(0x60) != 0xfa))
|
|
|
|
return;
|
|
|
|
|
2004-11-11 12:56:00 +01:00
|
|
|
kbd_empty_output_buffer();
|
2003-09-26 17:24:54 +02:00
|
|
|
if ((regval = inb(0x60) != 0xaa))
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2004-03-11 16:01:31 +01:00
|
|
|
void init_pc_keyboard(unsigned port0, unsigned port1, struct pc_keyboard *kbd)
|
|
|
|
{
|
|
|
|
if ((port0 == 0x60) && (port1 == 0x64)) {
|
|
|
|
pc_keyboard_init(kbd);
|
|
|
|
}
|
|
|
|
}
|