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