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