libpayload/drivers/i8042: Add AT translated Keyboard support

Wilco device uses the AT translated keyboard and doesn't need to set
scancode set. Remove the ignore flag and put into translation mode
instead.

BUG=b:145130110
TEST=Draillion keyboard is usable on every boot.

Signed-off-by: Eric Lai <ericr_lai@compal.corp-partner.google.com>
Change-Id: Ie1053e24e44c5bad28b56cc92d091e24f3d9b6fd
Reviewed-on: https://review.coreboot.org/c/coreboot/+/37594
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Mathew King <mathewk@chromium.org>
This commit is contained in:
Eric Lai 2019-12-09 15:05:12 +08:00 committed by Patrick Georgi
parent 6cfda93c6c
commit b643d3df8a
3 changed files with 62 additions and 29 deletions

View File

@ -347,6 +347,10 @@ config PC_KEYBOARD_IGNORE_INIT_FAILURE
bool "Ignore keyboard failures during init and always add input device" bool "Ignore keyboard failures during init and always add input device"
default n default n
config PC_KEYBOARD_AT_TRANSLATED
bool "AT Translation keyboard device"
default n
config PC_KEYBOARD_LAYOUT_US config PC_KEYBOARD_LAYOUT_US
bool "English (US) keyboard layout" bool "English (US) keyboard layout"
depends on PC_KEYBOARD depends on PC_KEYBOARD

View File

@ -33,6 +33,7 @@
/* Port 0x64 commands */ /* Port 0x64 commands */
#define I8042_CMD_RD_CMD_BYTE 0x20 #define I8042_CMD_RD_CMD_BYTE 0x20
#define I8042_CMD_WR_CMD_BYTE 0x60 #define I8042_CMD_WR_CMD_BYTE 0x60
#define I8042_CMD_BYTE_XLATE (1 << 6)
#define I8042_CMD_DIS_AUX 0xa7 #define I8042_CMD_DIS_AUX 0xa7
#define I8042_CMD_EN_AUX 0xa8 #define I8042_CMD_EN_AUX 0xa8
#define I8042_CMD_AUX_TEST 0xa9 #define I8042_CMD_AUX_TEST 0xa9

View File

@ -312,9 +312,59 @@ static struct console_input_driver cons = {
.input_type = CONSOLE_INPUT_TYPE_EC, .input_type = CONSOLE_INPUT_TYPE_EC,
}; };
void keyboard_init(void) /* Enable keyboard translated */
static int enable_translated(void)
{
if (!i8042_cmd(I8042_CMD_RD_CMD_BYTE)) {
int cmd = i8042_read_data_ps2();
cmd |= I8042_CMD_BYTE_XLATE;
if (!i8042_cmd(I8042_CMD_WR_CMD_BYTE))
i8042_write_data(cmd);
} else {
printf("ERROR: Keyboard i8042_cmd failed!\n");
return 0;
}
return 1;
}
/* Set scancode set 1 */
static int set_scancode_set(void)
{ {
unsigned int ret; unsigned int ret;
ret = keyboard_cmd(I8042_KBCMD_SET_SCANCODE);
if (!ret) {
printf("ERROR: Keyboard set scancode failed!\n");
return ret;
}
ret = keyboard_cmd(I8042_SCANCODE_SET_1);
if (!ret) {
printf("ERROR: Keyboard scancode set#1 failed!\n");
return ret;
}
/*
* Set default parameters.
* Fix for broken QEMU ps/2 make scancodes.
*/
ret = keyboard_cmd(I8042_KBCMD_SET_DEFAULT);
if (!ret) {
printf("ERROR: Keyboard set default params failed!\n");
return ret;
}
/* Enable scanning */
ret = keyboard_cmd(I8042_KBCMD_EN);
if (!ret) {
printf("ERROR: Keyboard enable scanning failed!\n");
return ret;
}
return ret;
}
void keyboard_init(void)
{
map = &keyboard_layouts[0]; map = &keyboard_layouts[0];
/* Initialized keyboard controller. */ /* Initialized keyboard controller. */
@ -328,34 +378,12 @@ void keyboard_init(void)
/* Enable first PS/2 port */ /* Enable first PS/2 port */
i8042_cmd(I8042_CMD_EN_KB); i8042_cmd(I8042_CMD_EN_KB);
/* Set scancode set 1 */ if (CONFIG(LP_PC_KEYBOARD_AT_TRANSLATED)) {
ret = keyboard_cmd(I8042_KBCMD_SET_SCANCODE); if (!enable_translated())
if (!ret && !CONFIG(LP_PC_KEYBOARD_IGNORE_INIT_FAILURE)) { return;
printf("ERROR: Keyboard set scancode failed!\n"); } else {
return; if (!set_scancode_set())
} return;
ret = keyboard_cmd(I8042_SCANCODE_SET_1);
if (!ret && !CONFIG(LP_PC_KEYBOARD_IGNORE_INIT_FAILURE)) {
printf("ERROR: Keyboard scancode set#1 failed!\n");
return;
}
/*
* Set default parameters.
* Fix for broken QEMU ps/2 make scancodes.
*/
ret = keyboard_cmd(0xf6);
if (!ret) {
printf("ERROR: Keyboard set default params failed!\n");
return;
}
/* Enable scanning */
ret = keyboard_cmd(I8042_KBCMD_EN);
if (!ret && !CONFIG(LP_PC_KEYBOARD_IGNORE_INIT_FAILURE)) {
printf("ERROR: Keyboard enable scanning failed!\n");
return;
} }
console_add_input_driver(&cons); console_add_input_driver(&cons);