mirror of
https://github.com/Fishwaldo/u-boot.git
synced 2025-03-21 14:41:31 +00:00
i8042: Use functions to handle register access
At present the register access in kbd_reset() is quite primitive. This makes it hard to follow. Create functions to read and write data, both to a single register, and via the command/data approach. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-on: Intel Crown Bay and QEMU Tested-by: Bin Meng <bmeng.cn@gmail.com>
This commit is contained in:
parent
7fe0933c58
commit
31d38ee66d
1 changed files with 44 additions and 31 deletions
|
@ -446,53 +446,66 @@ static void kbd_conv_char(unsigned char scan_code)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int kbd_write(int reg, int value)
|
||||||
|
{
|
||||||
|
if (!kbd_input_empty())
|
||||||
|
return -1;
|
||||||
|
out8(reg, value);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int kbd_read(int reg)
|
||||||
|
{
|
||||||
|
if (!kbd_output_full())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return in8(reg);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int kbd_cmd_read(int cmd)
|
||||||
|
{
|
||||||
|
if (kbd_write(I8042_CMD_REG, cmd))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return kbd_read(I8042_DATA_REG);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int kbd_cmd_write(int cmd, int data)
|
||||||
|
{
|
||||||
|
if (kbd_write(I8042_CMD_REG, cmd))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return kbd_write(I8042_DATA_REG, data);
|
||||||
|
}
|
||||||
|
|
||||||
static int kbd_reset(void)
|
static int kbd_reset(void)
|
||||||
{
|
{
|
||||||
u8 config;
|
int config;
|
||||||
|
|
||||||
/* controller self test */
|
/* controller self test */
|
||||||
if (kbd_input_empty() == 0)
|
if (kbd_cmd_read(CMD_SELF_TEST) != KBC_TEST_OK)
|
||||||
return -1;
|
|
||||||
out8(I8042_CMD_REG, CMD_SELF_TEST);
|
|
||||||
if (kbd_output_full() == 0)
|
|
||||||
return -1;
|
|
||||||
if (in8(I8042_DATA_REG) != KBC_TEST_OK)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* keyboard reset */
|
/* keyboard reset */
|
||||||
if (kbd_input_empty() == 0)
|
if (kbd_write(I8042_DATA_REG, CMD_RESET_KBD) ||
|
||||||
return -1;
|
kbd_read(I8042_DATA_REG) != KBD_ACK ||
|
||||||
out8(I8042_DATA_REG, CMD_RESET_KBD);
|
kbd_read(I8042_DATA_REG) != KBD_POR)
|
||||||
if (kbd_output_full() == 0)
|
|
||||||
return -1;
|
|
||||||
if (in8(I8042_DATA_REG) != KBD_ACK)
|
|
||||||
return -1;
|
|
||||||
if (kbd_output_full() == 0)
|
|
||||||
return -1;
|
|
||||||
if (in8(I8042_DATA_REG) != KBD_POR)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
/* set AT translation and disable irq */
|
/* set AT translation and disable irq */
|
||||||
if (kbd_input_empty() == 0)
|
config = kbd_cmd_read(CMD_RD_CONFIG);
|
||||||
|
if (config == -1)
|
||||||
return -1;
|
return -1;
|
||||||
out8(I8042_CMD_REG, CMD_RD_CONFIG);
|
|
||||||
if (kbd_output_full() == 0)
|
|
||||||
return -1;
|
|
||||||
config = in8(I8042_DATA_REG);
|
|
||||||
config |= CONFIG_AT_TRANS;
|
config |= CONFIG_AT_TRANS;
|
||||||
config &= ~(CONFIG_KIRQ_EN | CONFIG_MIRQ_EN);
|
config &= ~(CONFIG_KIRQ_EN | CONFIG_MIRQ_EN);
|
||||||
if (kbd_input_empty() == 0)
|
if (kbd_cmd_write(CMD_WR_CONFIG, config))
|
||||||
return -1;
|
return -1;
|
||||||
out8(I8042_CMD_REG, CMD_WR_CONFIG);
|
|
||||||
if (kbd_input_empty() == 0)
|
|
||||||
return -1;
|
|
||||||
out8(I8042_DATA_REG, config);
|
|
||||||
|
|
||||||
/* enable keyboard */
|
/* enable keyboard */
|
||||||
if (kbd_input_empty() == 0)
|
if (kbd_write(I8042_CMD_REG, CMD_KBD_EN) ||
|
||||||
return -1;
|
!kbd_input_empty())
|
||||||
out8(I8042_CMD_REG, CMD_KBD_EN);
|
|
||||||
if (kbd_input_empty() == 0)
|
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
Loading…
Add table
Reference in a new issue