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