X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=src%2Fps2port.c;h=1f042999047ed818e7a5b458c0c03716b9b4cc0d;hb=refs%2Fheads%2Fcoreboot;hp=47dfd49bad846fd79cbf1b6c5047a2a63a54d960;hpb=f628244eb322da79d6a8bffdb35e6d0e5111892a;p=seabios.git diff --git a/src/ps2port.c b/src/ps2port.c index 47dfd49..1f04299 100644 --- a/src/ps2port.c +++ b/src/ps2port.c @@ -7,8 +7,9 @@ #include "ioport.h" // inb #include "util.h" // dprintf +#include "paravirt.h" // romfile_loadint #include "biosvar.h" // GET_EBDA -#include "ps2port.h" // kbd_command +#include "ps2port.h" // ps2_kbd_command #include "pic.h" // eoi_pic1 @@ -51,7 +52,7 @@ i8042_wait_write(void) return -1; } -int +static int i8042_flush(void) { dprintf(7, "i8042_flush\n"); @@ -102,7 +103,7 @@ __i8042_command(int command, u8 *param) return 0; } -int +static int i8042_command(int command, u8 *param) { dprintf(7, "i8042_command cmd=%x\n", command); @@ -128,6 +129,20 @@ i8042_aux_write(u8 c) return i8042_command(I8042_CMD_AUX_SEND, &c); } +void +i8042_reboot(void) +{ + if (! CONFIG_PS2PORT) + return; + int i; + for (i=0; i<10; i++) { + i8042_wait_write(); + udelay(50); + outb(0xfe, PORT_PS2_STATUS); /* pulse reset low */ + udelay(50); + } +} + /**************************************************************** * Device commands. @@ -161,7 +176,7 @@ ps2_recvbyte(int aux, int needack, int timeout) dprintf(1, "Discarding ps2 data %02x (status=%02x)\n", data, status); } - if (check_time(end)) { + if (check_tsc(end)) { // Don't warn on second byte of a reset if (timeout > 100) warn_timeout(); @@ -194,7 +209,7 @@ ps2_sendbyte(int aux, u8 command, int timeout) } static int -ps2_command(int aux, int command, u8 *param) +__ps2_command(int aux, int command, u8 *param) { int ret2; int receive = (command >> 8) & 0xf; @@ -296,24 +311,42 @@ fail: return ret; } -int -kbd_command(int command, u8 *param) +static int +ps2_command(int aux, int command, u8 *param) { - dprintf(7, "kbd_command cmd=%x\n", command); - int ret = ps2_command(0, command, param); + dprintf(7, "ps2_command aux=%d cmd=%x\n", aux, command); + int ret = __ps2_command(aux, command, param); if (ret) - dprintf(2, "keyboard command %x failed\n", command); + dprintf(2, "ps2 command %x failed (aux=%d)\n", command, aux); return ret; } int -aux_command(int command, u8 *param) +ps2_kbd_command(int command, u8 *param) { - dprintf(7, "aux_command cmd=%x\n", command); - int ret = ps2_command(1, command, param); - if (ret) - dprintf(2, "mouse command %x failed\n", command); - return ret; + if (! CONFIG_PS2PORT) + return -1; + return ps2_command(0, command, param); +} + +int +ps2_mouse_command(int command, u8 *param) +{ + if (! CONFIG_PS2PORT) + return -1; + + // Update ps2ctr for mouse enable/disable. + if (command == PSMOUSE_CMD_ENABLE || command == PSMOUSE_CMD_DISABLE) { + u16 ebda_seg = get_ebda_seg(); + u8 ps2ctr = GET_EBDA2(ebda_seg, ps2ctr); + if (command == PSMOUSE_CMD_ENABLE) + ps2ctr = (ps2ctr | I8042_CTR_AUXINT) & ~I8042_CTR_AUXDIS; + else + ps2ctr = (ps2ctr | I8042_CTR_AUXDIS) & ~I8042_CTR_AUXINT; + SET_EBDA2(ebda_seg, ps2ctr, ps2ctr); + } + + return ps2_command(1, command, param); } @@ -413,22 +446,32 @@ keyboard_init(void *data) /* ------------------- keyboard side ------------------------*/ /* reset keyboard and self test (keyboard side) */ - ret = kbd_command(ATKBD_CMD_RESET_BAT, param); - if (ret) - return; + int spinupdelay = romfile_loadint("etc/ps2-keyboard-spinup", 0); + u64 end = calc_future_tsc(spinupdelay); + for (;;) { + ret = ps2_kbd_command(ATKBD_CMD_RESET_BAT, param); + if (!ret) + break; + if (check_tsc(end)) { + if (spinupdelay) + warn_timeout(); + return; + } + yield(); + } if (param[0] != 0xaa) { dprintf(1, "keyboard self test failed (got %x not 0xaa)\n", param[0]); return; } /* Disable keyboard */ - ret = kbd_command(ATKBD_CMD_RESET_DIS, NULL); + ret = ps2_kbd_command(ATKBD_CMD_RESET_DIS, NULL); if (ret) return; // Set scancode command (mode 2) param[0] = 0x02; - ret = kbd_command(ATKBD_CMD_SSCANSET, param); + ret = ps2_kbd_command(ATKBD_CMD_SSCANSET, param); if (ret) return; @@ -436,7 +479,7 @@ keyboard_init(void *data) SET_EBDA(ps2ctr, I8042_CTR_AUXDIS | I8042_CTR_XLATE | I8042_CTR_KBDINT); /* Enable keyboard */ - ret = kbd_command(ATKBD_CMD_ENABLE, NULL); + ret = ps2_kbd_command(ATKBD_CMD_ENABLE, NULL); if (ret) return; @@ -451,8 +494,8 @@ ps2port_setup(void) return; dprintf(3, "init ps2port\n"); - enable_hwirq(1, entry_09); - enable_hwirq(12, entry_74); + enable_hwirq(1, FUNC16(entry_09)); + enable_hwirq(12, FUNC16(entry_74)); run_thread(keyboard_init, NULL); }