blob: ccec00488c1ccda1377bec86db54cc11094ce9af (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#include <console/console.h>
#include <pc80/keyboard.h>
#include <device/device.h>
#include <arch/io.h>
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;
}
/* much better keyboard init courtesy ollie@sis.com.tw
TODO: Typematic Setting, the keyboard is too slow for me */
static void pc_keyboard_init(struct pc_keyboard *keyboard)
{
unsigned char regval;
/* send cmd = 0xAA, self test 8042 */
outb(0xaa, 0x64);
/* empty input buffer or any other command/data will be lost */
if (!kbd_empty_input_buffer()) {
printk_err("Keyboard input buffer would not empty\n");
return;
}
/* empty output buffer or any other command/data will be lost */
if (!kbd_empty_output_buffer()) {
printk_err("Keyboard output buffer would not empty\n");
return;
}
/* read self-test result, 0x55 should be returned form 0x60 */
if ((regval = inb(0x60) != 0x55))
return;
/* enable keyboard interface */
outb(0x60, 0x64);
kbd_empty_input_buffer();
/* send cmd: enable IRQ 1 */
outb(0x61, 0x60);
kbd_empty_input_buffer();
/* reset kerboard and self test (keyboard side) */
outb(0xff, 0x60);
/* empty inut bufferm or any other command/data will be lost */
kbd_empty_input_buffer();
/* empty output buffer or any other command/data will be lost */
kbd_empty_output_buffer();
if ((regval = inb(0x60) != 0xfa))
return;
kbd_empty_output_buffer();
if ((regval = inb(0x60) != 0xaa))
return;
}
void init_pc_keyboard(unsigned port0, unsigned port1, struct pc_keyboard *kbd)
{
if ((port0 == 0x60) && (port1 == 0x64)) {
pc_keyboard_init(kbd);
}
}
|