libpayload/i8042: Add API to get/set kbd translation state
Change-Id: I49aa1c244cb60ea290df102f06f641c765f59fa5 Signed-off-by: Nico Huber <nico.h@gmx.de> Reviewed-on: https://review.coreboot.org/c/coreboot/+/47589 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Angel Pons <th3fanbus@gmail.com>
This commit is contained in:
parent
683c95e4ab
commit
0e1d19baa6
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include <libpayload-config.h>
|
||||
#include <libpayload.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include "i8042.h"
|
||||
|
@ -318,6 +319,24 @@ void i8042_write_data(u8 data)
|
|||
return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Send command & data to keyboard controller.
|
||||
*
|
||||
* @param cmd: The command to be sent.
|
||||
* @param data: The data to be sent.
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*/
|
||||
static int i8042_cmd_with_data(const u8 cmd, const u8 data)
|
||||
{
|
||||
const int ret = i8042_cmd(cmd);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
i8042_write_data(data);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/**
|
||||
* Probe for keyboard controller data and queue it.
|
||||
*/
|
||||
|
@ -408,3 +427,36 @@ int i8042_wait_read_aux(void)
|
|||
|
||||
return (retries <= 0) ? -1 : i8042_read_data_aux();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the keyboard scancode translation state.
|
||||
*
|
||||
* Returns: -1 on timeout, 1 if the controller translates
|
||||
* scancode set #2 to #1, and 0 if not.
|
||||
*/
|
||||
int i8042_get_kbd_translation(void)
|
||||
{
|
||||
const int cfg = i8042_cmd_with_response(I8042_CMD_RD_CMD_BYTE);
|
||||
if (cfg < 0)
|
||||
return cfg;
|
||||
|
||||
return !!(cfg & I8042_CMD_BYTE_XLATE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the keyboard scancode translation state.
|
||||
*
|
||||
* Returns: -1 on timeout, 0 otherwise.
|
||||
*/
|
||||
int i8042_set_kbd_translation(const bool xlate)
|
||||
{
|
||||
int cfg = i8042_cmd_with_response(I8042_CMD_RD_CMD_BYTE);
|
||||
if (cfg < 0)
|
||||
return cfg;
|
||||
|
||||
if (xlate)
|
||||
cfg |= I8042_CMD_BYTE_XLATE;
|
||||
else
|
||||
cfg &= ~I8042_CMD_BYTE_XLATE;
|
||||
return i8042_cmd_with_data(I8042_CMD_WR_CMD_BYTE, cfg);
|
||||
}
|
||||
|
|
|
@ -238,6 +238,9 @@ u8 i8042_read_data_aux(void);
|
|||
int i8042_wait_read_ps2(void);
|
||||
int i8042_wait_read_aux(void);
|
||||
|
||||
int i8042_get_kbd_translation(void);
|
||||
int i8042_set_kbd_translation(bool xlate);
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue