Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 ELTEC Elektronik AG |
| 4 | * Frank Gottschling <fgottschling@eltec.de> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* i8042.c - Intel 8042 keyboard driver routines */ |
| 8 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 9 | #include <common.h> |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 10 | #include <dm.h> |
Simon Glass | 7b51b57 | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 11 | #include <env.h> |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 12 | #include <errno.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 13 | #include <i8042.h> |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 14 | #include <input.h> |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 15 | #include <keyboard.h> |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 16 | #include <asm/io.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 17 | |
Simon Glass | 011d89d | 2015-11-11 10:05:46 -0700 | [diff] [blame] | 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 20 | /* defines */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 21 | #define in8(p) inb(p) |
| 22 | #define out8(p, v) outb(v, p) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 23 | |
Simon Glass | 011d89d | 2015-11-11 10:05:46 -0700 | [diff] [blame] | 24 | enum { |
| 25 | QUIRK_DUP_POR = 1 << 0, |
| 26 | }; |
| 27 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 28 | /* locals */ |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 29 | struct i8042_kbd_priv { |
| 30 | bool extended; /* true if an extended keycode is expected next */ |
Simon Glass | 011d89d | 2015-11-11 10:05:46 -0700 | [diff] [blame] | 31 | int quirks; /* quirks that we support */ |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 32 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 33 | |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 34 | static unsigned char ext_key_map[] = { |
| 35 | 0x1c, /* keypad enter */ |
| 36 | 0x1d, /* right control */ |
| 37 | 0x35, /* keypad slash */ |
| 38 | 0x37, /* print screen */ |
| 39 | 0x38, /* right alt */ |
| 40 | 0x46, /* break */ |
| 41 | 0x47, /* editpad home */ |
| 42 | 0x48, /* editpad up */ |
| 43 | 0x49, /* editpad pgup */ |
| 44 | 0x4b, /* editpad left */ |
| 45 | 0x4d, /* editpad right */ |
| 46 | 0x4f, /* editpad end */ |
| 47 | 0x50, /* editpad dn */ |
| 48 | 0x51, /* editpad pgdn */ |
| 49 | 0x52, /* editpad ins */ |
| 50 | 0x53, /* editpad del */ |
| 51 | 0x00 /* map end */ |
| 52 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 53 | |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 54 | static int kbd_input_empty(void) |
| 55 | { |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 56 | int kbd_timeout = KBD_TIMEOUT * 1000; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 57 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 58 | while ((in8(I8042_STS_REG) & STATUS_IBF) && kbd_timeout--) |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 59 | udelay(1); |
| 60 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 61 | return kbd_timeout != -1; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 62 | } |
| 63 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 64 | static int kbd_output_full(void) |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 65 | { |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 66 | int kbd_timeout = KBD_TIMEOUT * 1000; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 67 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 68 | while (((in8(I8042_STS_REG) & STATUS_OBF) == 0) && kbd_timeout--) |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 69 | udelay(1); |
| 70 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 71 | return kbd_timeout != -1; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 72 | } |
| 73 | |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 74 | /** |
| 75 | * check_leds() - Check the keyboard LEDs and update them it needed |
| 76 | * |
| 77 | * @ret: Value to return |
| 78 | * @return value of @ret |
| 79 | */ |
| 80 | static int i8042_kbd_update_leds(struct udevice *dev, int leds) |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 81 | { |
| 82 | kbd_input_empty(); |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 83 | out8(I8042_DATA_REG, CMD_SET_KBD_LED); |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 84 | kbd_input_empty(); |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 85 | out8(I8042_DATA_REG, leds & 0x7); |
| 86 | |
| 87 | return 0; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Simon Glass | 31d38ee | 2015-10-18 21:17:19 -0600 | [diff] [blame] | 90 | static int kbd_write(int reg, int value) |
| 91 | { |
| 92 | if (!kbd_input_empty()) |
| 93 | return -1; |
| 94 | out8(reg, value); |
| 95 | |
| 96 | return 0; |
| 97 | } |
| 98 | |
| 99 | static int kbd_read(int reg) |
| 100 | { |
| 101 | if (!kbd_output_full()) |
| 102 | return -1; |
| 103 | |
| 104 | return in8(reg); |
| 105 | } |
| 106 | |
| 107 | static int kbd_cmd_read(int cmd) |
| 108 | { |
| 109 | if (kbd_write(I8042_CMD_REG, cmd)) |
| 110 | return -1; |
| 111 | |
| 112 | return kbd_read(I8042_DATA_REG); |
| 113 | } |
| 114 | |
| 115 | static int kbd_cmd_write(int cmd, int data) |
| 116 | { |
| 117 | if (kbd_write(I8042_CMD_REG, cmd)) |
| 118 | return -1; |
| 119 | |
| 120 | return kbd_write(I8042_DATA_REG, data); |
| 121 | } |
| 122 | |
Simon Glass | 011d89d | 2015-11-11 10:05:46 -0700 | [diff] [blame] | 123 | static int kbd_reset(int quirk) |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 124 | { |
Simon Glass | 31d38ee | 2015-10-18 21:17:19 -0600 | [diff] [blame] | 125 | int config; |
Bin Meng | 7d96166 | 2015-08-24 01:00:06 -0700 | [diff] [blame] | 126 | |
| 127 | /* controller self test */ |
Simon Glass | 31d38ee | 2015-10-18 21:17:19 -0600 | [diff] [blame] | 128 | if (kbd_cmd_read(CMD_SELF_TEST) != KBC_TEST_OK) |
Simon Glass | 4f087ba | 2015-10-18 21:17:20 -0600 | [diff] [blame] | 129 | goto err; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 130 | |
Bin Meng | 7d96166 | 2015-08-24 01:00:06 -0700 | [diff] [blame] | 131 | /* keyboard reset */ |
Simon Glass | 31d38ee | 2015-10-18 21:17:19 -0600 | [diff] [blame] | 132 | if (kbd_write(I8042_DATA_REG, CMD_RESET_KBD) || |
| 133 | kbd_read(I8042_DATA_REG) != KBD_ACK || |
| 134 | kbd_read(I8042_DATA_REG) != KBD_POR) |
Simon Glass | 4f087ba | 2015-10-18 21:17:20 -0600 | [diff] [blame] | 135 | goto err; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 136 | |
Simon Glass | 8226a3e | 2016-03-11 22:06:50 -0700 | [diff] [blame] | 137 | if (kbd_write(I8042_DATA_REG, CMD_DRAIN_OUTPUT) || |
| 138 | kbd_read(I8042_DATA_REG) != KBD_ACK) |
| 139 | goto err; |
| 140 | |
Bin Meng | 7d96166 | 2015-08-24 01:00:06 -0700 | [diff] [blame] | 141 | /* set AT translation and disable irq */ |
Simon Glass | 31d38ee | 2015-10-18 21:17:19 -0600 | [diff] [blame] | 142 | config = kbd_cmd_read(CMD_RD_CONFIG); |
| 143 | if (config == -1) |
Simon Glass | 4f087ba | 2015-10-18 21:17:20 -0600 | [diff] [blame] | 144 | goto err; |
Simon Glass | 31d38ee | 2015-10-18 21:17:19 -0600 | [diff] [blame] | 145 | |
Simon Glass | 011d89d | 2015-11-11 10:05:46 -0700 | [diff] [blame] | 146 | /* Sometimes get a second byte */ |
| 147 | else if ((quirk & QUIRK_DUP_POR) && config == KBD_POR) |
| 148 | config = kbd_cmd_read(CMD_RD_CONFIG); |
| 149 | |
Bin Meng | 7d96166 | 2015-08-24 01:00:06 -0700 | [diff] [blame] | 150 | config |= CONFIG_AT_TRANS; |
| 151 | config &= ~(CONFIG_KIRQ_EN | CONFIG_MIRQ_EN); |
Simon Glass | 31d38ee | 2015-10-18 21:17:19 -0600 | [diff] [blame] | 152 | if (kbd_cmd_write(CMD_WR_CONFIG, config)) |
Simon Glass | 4f087ba | 2015-10-18 21:17:20 -0600 | [diff] [blame] | 153 | goto err; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 154 | |
Bin Meng | 7d96166 | 2015-08-24 01:00:06 -0700 | [diff] [blame] | 155 | /* enable keyboard */ |
Simon Glass | 31d38ee | 2015-10-18 21:17:19 -0600 | [diff] [blame] | 156 | if (kbd_write(I8042_CMD_REG, CMD_KBD_EN) || |
| 157 | !kbd_input_empty()) |
Simon Glass | 4f087ba | 2015-10-18 21:17:20 -0600 | [diff] [blame] | 158 | goto err; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 159 | |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 160 | return 0; |
Simon Glass | 4f087ba | 2015-10-18 21:17:20 -0600 | [diff] [blame] | 161 | err: |
| 162 | debug("%s: Keyboard failure\n", __func__); |
| 163 | return -1; |
Bin Meng | 3928d66 | 2015-08-24 01:00:04 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Gabe Black | 22e0f5a | 2011-11-14 20:18:12 +0000 | [diff] [blame] | 166 | static int kbd_controller_present(void) |
| 167 | { |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 168 | return in8(I8042_STS_REG) != 0xff; |
Gabe Black | 22e0f5a | 2011-11-14 20:18:12 +0000 | [diff] [blame] | 169 | } |
| 170 | |
Simon Glass | 165be50 | 2018-11-23 21:29:38 -0700 | [diff] [blame] | 171 | /** Flush all buffer from keyboard controller to host*/ |
| 172 | static void i8042_flush(void) |
Louis Yung-Chieh Lo | 45fe668 | 2012-10-11 15:15:51 +0000 | [diff] [blame] | 173 | { |
| 174 | int timeout; |
| 175 | |
| 176 | /* |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 177 | * The delay is to give the keyboard controller some time |
| 178 | * to fill the next byte. |
Louis Yung-Chieh Lo | 45fe668 | 2012-10-11 15:15:51 +0000 | [diff] [blame] | 179 | */ |
| 180 | while (1) { |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 181 | timeout = 100; /* wait for no longer than 100us */ |
| 182 | while (timeout > 0 && !(in8(I8042_STS_REG) & STATUS_OBF)) { |
Louis Yung-Chieh Lo | 45fe668 | 2012-10-11 15:15:51 +0000 | [diff] [blame] | 183 | udelay(1); |
| 184 | timeout--; |
| 185 | } |
| 186 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 187 | /* Try to pull next byte if not timeout */ |
| 188 | if (in8(I8042_STS_REG) & STATUS_OBF) |
Louis Yung-Chieh Lo | 45fe668 | 2012-10-11 15:15:51 +0000 | [diff] [blame] | 189 | in8(I8042_DATA_REG); |
| 190 | else |
| 191 | break; |
| 192 | } |
| 193 | } |
| 194 | |
Simon Glass | 165be50 | 2018-11-23 21:29:38 -0700 | [diff] [blame] | 195 | /** |
| 196 | * Disables the keyboard so that key strokes no longer generate scancodes to |
| 197 | * the host. |
| 198 | * |
| 199 | * @return 0 if ok, -1 if keyboard input was found while disabling |
| 200 | */ |
| 201 | static int i8042_disable(void) |
Louis Yung-Chieh Lo | 45fe668 | 2012-10-11 15:15:51 +0000 | [diff] [blame] | 202 | { |
| 203 | if (kbd_input_empty() == 0) |
| 204 | return -1; |
| 205 | |
| 206 | /* Disable keyboard */ |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 207 | out8(I8042_CMD_REG, CMD_KBD_DIS); |
Louis Yung-Chieh Lo | 45fe668 | 2012-10-11 15:15:51 +0000 | [diff] [blame] | 208 | |
| 209 | if (kbd_input_empty() == 0) |
| 210 | return -1; |
| 211 | |
| 212 | return 0; |
| 213 | } |
| 214 | |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 215 | static int i8042_kbd_check(struct input_config *input) |
| 216 | { |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 217 | struct i8042_kbd_priv *priv = dev_get_priv(input->dev); |
| 218 | |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 219 | if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) { |
| 220 | return 0; |
| 221 | } else { |
| 222 | bool release = false; |
| 223 | int scan_code; |
| 224 | int i; |
| 225 | |
| 226 | scan_code = in8(I8042_DATA_REG); |
| 227 | if (scan_code == 0xfa) { |
| 228 | return 0; |
| 229 | } else if (scan_code == 0xe0) { |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 230 | priv->extended = true; |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 231 | return 0; |
| 232 | } |
| 233 | if (scan_code & 0x80) { |
| 234 | scan_code &= 0x7f; |
| 235 | release = true; |
| 236 | } |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 237 | if (priv->extended) { |
| 238 | priv->extended = false; |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 239 | for (i = 0; ext_key_map[i]; i++) { |
| 240 | if (ext_key_map[i] == scan_code) { |
| 241 | scan_code = 0x60 + i; |
| 242 | break; |
| 243 | } |
| 244 | } |
| 245 | /* not found ? */ |
| 246 | if (!ext_key_map[i]) |
| 247 | return 0; |
| 248 | } |
| 249 | |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 250 | input_add_keycode(input, scan_code, release); |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 251 | return 1; |
| 252 | } |
| 253 | } |
| 254 | |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 255 | /* i8042_kbd_init - reset keyboard and init state flags */ |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 256 | static int i8042_start(struct udevice *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 257 | { |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 258 | struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 011d89d | 2015-11-11 10:05:46 -0700 | [diff] [blame] | 259 | struct i8042_kbd_priv *priv = dev_get_priv(dev); |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 260 | struct input_config *input = &uc_priv->input; |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 261 | int keymap, try; |
| 262 | char *penv; |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 263 | int ret; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 264 | |
Simon Glass | 165be50 | 2018-11-23 21:29:38 -0700 | [diff] [blame] | 265 | if (!kbd_controller_present()) { |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 266 | debug("i8042 keyboard controller is not present\n"); |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 267 | return -ENOENT; |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 268 | } |
Gabe Black | 22e0f5a | 2011-11-14 20:18:12 +0000 | [diff] [blame] | 269 | |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 270 | /* Init keyboard device (default US layout) */ |
| 271 | keymap = KBD_US; |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 272 | penv = env_get("keymap"); |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 273 | if (penv != NULL) { |
| 274 | if (strncmp(penv, "de", 3) == 0) |
| 275 | keymap = KBD_GER; |
| 276 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 277 | |
Simon Glass | 011d89d | 2015-11-11 10:05:46 -0700 | [diff] [blame] | 278 | for (try = 0; kbd_reset(priv->quirks) != 0; try++) { |
Simon Glass | c5d257f | 2015-10-18 21:17:21 -0600 | [diff] [blame] | 279 | if (try >= KBD_RESET_TRIES) |
| 280 | return -1; |
Gabe Black | dd4a5b2 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 281 | } |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 282 | |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 283 | ret = input_add_tables(input, keymap == KBD_GER); |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 284 | if (ret) |
| 285 | return ret; |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 286 | |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 287 | i8042_kbd_update_leds(dev, NORMAL); |
| 288 | debug("%s: started\n", __func__); |
Simon Glass | c5d257f | 2015-10-18 21:17:21 -0600 | [diff] [blame] | 289 | |
| 290 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 291 | } |
| 292 | |
Simon Glass | 165be50 | 2018-11-23 21:29:38 -0700 | [diff] [blame] | 293 | static int i8042_kbd_remove(struct udevice *dev) |
| 294 | { |
| 295 | if (i8042_disable()) |
| 296 | log_debug("i8042_disable() failed. fine, continue.\n"); |
| 297 | i8042_flush(); |
| 298 | |
| 299 | return 0; |
| 300 | } |
| 301 | |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 302 | /** |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 303 | * Set up the i8042 keyboard. This is called by the stdio device handler |
Bin Meng | 835dd00 | 2015-08-24 01:00:05 -0700 | [diff] [blame] | 304 | * |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 305 | * We want to do this init when the keyboard is actually used rather than |
| 306 | * at start-up, since keyboard input may not currently be selected. |
| 307 | * |
| 308 | * Once the keyboard starts there will be a period during which we must |
| 309 | * wait for the keyboard to init. We do this only when a key is first |
| 310 | * read - see kbd_wait_for_fifo_init(). |
| 311 | * |
| 312 | * @return 0 if ok, -ve on error |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 313 | */ |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 314 | static int i8042_kbd_probe(struct udevice *dev) |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 315 | { |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 316 | struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev); |
Simon Glass | 011d89d | 2015-11-11 10:05:46 -0700 | [diff] [blame] | 317 | struct i8042_kbd_priv *priv = dev_get_priv(dev); |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 318 | struct stdio_dev *sdev = &uc_priv->sdev; |
| 319 | struct input_config *input = &uc_priv->input; |
| 320 | int ret; |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 321 | |
Simon Glass | e160f7d | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 322 | if (fdtdec_get_bool(gd->fdt_blob, dev_of_offset(dev), |
Simon Glass | 011d89d | 2015-11-11 10:05:46 -0700 | [diff] [blame] | 323 | "intel,duplicate-por")) |
| 324 | priv->quirks |= QUIRK_DUP_POR; |
| 325 | |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 326 | /* Register the device. i8042_start() will be called soon */ |
| 327 | input->dev = dev; |
| 328 | input->read_keys = i8042_kbd_check; |
| 329 | input_allow_repeats(input, true); |
| 330 | strcpy(sdev->name, "i8042-kbd"); |
| 331 | ret = input_stdio_register(sdev); |
| 332 | if (ret) { |
| 333 | debug("%s: input_stdio_register() failed\n", __func__); |
| 334 | return ret; |
| 335 | } |
| 336 | debug("%s: ready\n", __func__); |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 337 | |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 338 | return 0; |
Simon Glass | 2ec739d | 2015-11-11 10:05:41 -0700 | [diff] [blame] | 339 | } |
| 340 | |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 341 | static const struct keyboard_ops i8042_kbd_ops = { |
| 342 | .start = i8042_start, |
| 343 | .update_leds = i8042_kbd_update_leds, |
| 344 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 345 | |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 346 | static const struct udevice_id i8042_kbd_ids[] = { |
| 347 | { .compatible = "intel,i8042-keyboard" }, |
| 348 | { } |
| 349 | }; |
| 350 | |
| 351 | U_BOOT_DRIVER(i8042_kbd) = { |
| 352 | .name = "i8042_kbd", |
| 353 | .id = UCLASS_KEYBOARD, |
| 354 | .of_match = i8042_kbd_ids, |
| 355 | .probe = i8042_kbd_probe, |
Simon Glass | 165be50 | 2018-11-23 21:29:38 -0700 | [diff] [blame] | 356 | .remove = i8042_kbd_remove, |
Simon Glass | dcbf825 | 2015-11-11 10:05:45 -0700 | [diff] [blame] | 357 | .ops = &i8042_kbd_ops, |
| 358 | .priv_auto_alloc_size = sizeof(struct i8042_kbd_priv), |
| 359 | }; |