mirror of
https://github.com/brain-hackers/u-boot-brain
synced 2024-09-28 07:30:26 +09:00
input: Convert i8042 to driver model
Adjust this driver to support driver model. The only users are x86 boards so this should be safe. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Bin Meng <bmeng.cn@gmail.com> Tested-by: Bin Meng <bmeng.cn@gmail.com>
This commit is contained in:
parent
51a8a72dc5
commit
dcbf825714
@ -7,7 +7,7 @@
|
|||||||
|
|
||||||
obj-$(CONFIG_DM_KEYBOARD) += keyboard-uclass.o
|
obj-$(CONFIG_DM_KEYBOARD) += keyboard-uclass.o
|
||||||
|
|
||||||
obj-$(CONFIG_I8042_KBD) += i8042.o
|
obj-$(CONFIG_I8042_KEYB) += i8042.o
|
||||||
obj-$(CONFIG_TEGRA_KEYBOARD) += tegra-kbc.o
|
obj-$(CONFIG_TEGRA_KEYBOARD) += tegra-kbc.o
|
||||||
obj-$(CONFIG_TWL4030_INPUT) += twl4030.o
|
obj-$(CONFIG_TWL4030_INPUT) += twl4030.o
|
||||||
obj-$(CONFIG_CROS_EC_KEYB) += cros_ec_keyb.o
|
obj-$(CONFIG_CROS_EC_KEYB) += cros_ec_keyb.o
|
||||||
|
@ -8,8 +8,11 @@
|
|||||||
/* i8042.c - Intel 8042 keyboard driver routines */
|
/* i8042.c - Intel 8042 keyboard driver routines */
|
||||||
|
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
|
#include <dm.h>
|
||||||
|
#include <errno.h>
|
||||||
#include <i8042.h>
|
#include <i8042.h>
|
||||||
#include <input.h>
|
#include <input.h>
|
||||||
|
#include <keyboard.h>
|
||||||
#include <asm/io.h>
|
#include <asm/io.h>
|
||||||
|
|
||||||
/* defines */
|
/* defines */
|
||||||
@ -17,8 +20,9 @@
|
|||||||
#define out8(p, v) outb(v, p)
|
#define out8(p, v) outb(v, p)
|
||||||
|
|
||||||
/* locals */
|
/* locals */
|
||||||
static struct input_config config;
|
struct i8042_kbd_priv {
|
||||||
static bool extended;
|
bool extended; /* true if an extended keycode is expected next */
|
||||||
|
};
|
||||||
|
|
||||||
static unsigned char ext_key_map[] = {
|
static unsigned char ext_key_map[] = {
|
||||||
0x1c, /* keypad enter */
|
0x1c, /* keypad enter */
|
||||||
@ -60,12 +64,20 @@ static int kbd_output_full(void)
|
|||||||
return kbd_timeout != -1;
|
return kbd_timeout != -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void kbd_led_set(int flags)
|
/**
|
||||||
|
* check_leds() - Check the keyboard LEDs and update them it needed
|
||||||
|
*
|
||||||
|
* @ret: Value to return
|
||||||
|
* @return value of @ret
|
||||||
|
*/
|
||||||
|
static int i8042_kbd_update_leds(struct udevice *dev, int leds)
|
||||||
{
|
{
|
||||||
kbd_input_empty();
|
kbd_input_empty();
|
||||||
out8(I8042_DATA_REG, CMD_SET_KBD_LED);
|
out8(I8042_DATA_REG, CMD_SET_KBD_LED);
|
||||||
kbd_input_empty();
|
kbd_input_empty();
|
||||||
out8(I8042_DATA_REG, flags & 0x7);
|
out8(I8042_DATA_REG, leds & 0x7);
|
||||||
|
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int kbd_write(int reg, int value)
|
static int kbd_write(int reg, int value)
|
||||||
@ -144,6 +156,8 @@ static int kbd_controller_present(void)
|
|||||||
/*
|
/*
|
||||||
* Implement a weak default function for boards that optionally
|
* Implement a weak default function for boards that optionally
|
||||||
* need to skip the i8042 initialization.
|
* need to skip the i8042 initialization.
|
||||||
|
*
|
||||||
|
* TODO(sjg@chromium.org): Use device tree for this?
|
||||||
*/
|
*/
|
||||||
int __weak board_i8042_skip(void)
|
int __weak board_i8042_skip(void)
|
||||||
{
|
{
|
||||||
@ -190,6 +204,8 @@ int i8042_disable(void)
|
|||||||
|
|
||||||
static int i8042_kbd_check(struct input_config *input)
|
static int i8042_kbd_check(struct input_config *input)
|
||||||
{
|
{
|
||||||
|
struct i8042_kbd_priv *priv = dev_get_priv(input->dev);
|
||||||
|
|
||||||
if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
|
if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
|
||||||
return 0;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
@ -201,15 +217,15 @@ static int i8042_kbd_check(struct input_config *input)
|
|||||||
if (scan_code == 0xfa) {
|
if (scan_code == 0xfa) {
|
||||||
return 0;
|
return 0;
|
||||||
} else if (scan_code == 0xe0) {
|
} else if (scan_code == 0xe0) {
|
||||||
extended = true;
|
priv->extended = true;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (scan_code & 0x80) {
|
if (scan_code & 0x80) {
|
||||||
scan_code &= 0x7f;
|
scan_code &= 0x7f;
|
||||||
release = true;
|
release = true;
|
||||||
}
|
}
|
||||||
if (extended) {
|
if (priv->extended) {
|
||||||
extended = false;
|
priv->extended = false;
|
||||||
for (i = 0; ext_key_map[i]; i++) {
|
for (i = 0; ext_key_map[i]; i++) {
|
||||||
if (ext_key_map[i] == scan_code) {
|
if (ext_key_map[i] == scan_code) {
|
||||||
scan_code = 0x60 + i;
|
scan_code = 0x60 + i;
|
||||||
@ -221,21 +237,23 @@ static int i8042_kbd_check(struct input_config *input)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
input_add_keycode(&config, scan_code, release);
|
input_add_keycode(input, scan_code, release);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* i8042_kbd_init - reset keyboard and init state flags */
|
/* i8042_kbd_init - reset keyboard and init state flags */
|
||||||
int i8042_kbd_init(void)
|
static int i8042_start(struct udevice *dev)
|
||||||
{
|
{
|
||||||
|
struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
|
||||||
|
struct input_config *input = &uc_priv->input;
|
||||||
int keymap, try;
|
int keymap, try;
|
||||||
char *penv;
|
char *penv;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!kbd_controller_present() || board_i8042_skip()) {
|
if (!kbd_controller_present() || board_i8042_skip()) {
|
||||||
debug("i8042 keyboard controller is not present\n");
|
debug("i8042 keyboard controller is not present\n");
|
||||||
return -1;
|
return -ENOENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Init keyboard device (default US layout) */
|
/* Init keyboard device (default US layout) */
|
||||||
@ -251,42 +269,65 @@ int i8042_kbd_init(void)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = input_init(&config, keymap == KBD_GER);
|
ret = input_add_tables(input, keymap == KBD_GER);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
config.read_keys = i8042_kbd_check;
|
|
||||||
input_allow_repeats(&config, true);
|
|
||||||
|
|
||||||
kbd_led_set(NORMAL);
|
i8042_kbd_update_leds(dev, NORMAL);
|
||||||
|
debug("%s: started\n", __func__);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check_leds() - Check the keyboard LEDs and update them it needed
|
* Set up the i8042 keyboard. This is called by the stdio device handler
|
||||||
*
|
*
|
||||||
* @ret: Value to return
|
* We want to do this init when the keyboard is actually used rather than
|
||||||
* @return value of @ret
|
* at start-up, since keyboard input may not currently be selected.
|
||||||
|
*
|
||||||
|
* Once the keyboard starts there will be a period during which we must
|
||||||
|
* wait for the keyboard to init. We do this only when a key is first
|
||||||
|
* read - see kbd_wait_for_fifo_init().
|
||||||
|
*
|
||||||
|
* @return 0 if ok, -ve on error
|
||||||
*/
|
*/
|
||||||
static int check_leds(int ret)
|
static int i8042_kbd_probe(struct udevice *dev)
|
||||||
{
|
{
|
||||||
int leds;
|
struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
|
||||||
|
struct stdio_dev *sdev = &uc_priv->sdev;
|
||||||
|
struct input_config *input = &uc_priv->input;
|
||||||
|
int ret;
|
||||||
|
|
||||||
leds = input_leds_changed(&config);
|
/* Register the device. i8042_start() will be called soon */
|
||||||
if (leds >= 0)
|
input->dev = dev;
|
||||||
kbd_led_set(leds);
|
input->read_keys = i8042_kbd_check;
|
||||||
|
input_allow_repeats(input, true);
|
||||||
|
strcpy(sdev->name, "i8042-kbd");
|
||||||
|
ret = input_stdio_register(sdev);
|
||||||
|
if (ret) {
|
||||||
|
debug("%s: input_stdio_register() failed\n", __func__);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
debug("%s: ready\n", __func__);
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* i8042_tstc - test if keyboard input is available */
|
static const struct keyboard_ops i8042_kbd_ops = {
|
||||||
int i8042_tstc(struct stdio_dev *dev)
|
.start = i8042_start,
|
||||||
{
|
.update_leds = i8042_kbd_update_leds,
|
||||||
return check_leds(input_tstc(&config));
|
};
|
||||||
}
|
|
||||||
|
|
||||||
/* i8042_getc - wait till keyboard input is available */
|
static const struct udevice_id i8042_kbd_ids[] = {
|
||||||
int i8042_getc(struct stdio_dev *dev)
|
{ .compatible = "intel,i8042-keyboard" },
|
||||||
{
|
{ }
|
||||||
return check_leds(input_getc(&config));
|
};
|
||||||
}
|
|
||||||
|
U_BOOT_DRIVER(i8042_kbd) = {
|
||||||
|
.name = "i8042_kbd",
|
||||||
|
.id = UCLASS_KEYBOARD,
|
||||||
|
.of_match = i8042_kbd_ids,
|
||||||
|
.probe = i8042_kbd_probe,
|
||||||
|
.ops = &i8042_kbd_ops,
|
||||||
|
.priv_auto_alloc_size = sizeof(struct i8042_kbd_priv),
|
||||||
|
};
|
||||||
|
@ -87,10 +87,4 @@ void i8042_flush(void);
|
|||||||
*/
|
*/
|
||||||
int i8042_disable(void);
|
int i8042_disable(void);
|
||||||
|
|
||||||
struct stdio_dev;
|
|
||||||
|
|
||||||
int i8042_kbd_init(void);
|
|
||||||
int i8042_tstc(struct stdio_dev *dev);
|
|
||||||
int i8042_getc(struct stdio_dev *dev);
|
|
||||||
|
|
||||||
#endif /* _I8042_H_ */
|
#endif /* _I8042_H_ */
|
||||||
|
Loading…
Reference in New Issue
Block a user