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