wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2002 ELTEC Elektronik AG |
| 3 | * Frank Gottschling <fgottschling@eltec.de> |
| 4 | * |
Wolfgang Denk | bd8ec7e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 5 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | /* i8042.c - Intel 8042 keyboard driver routines */ |
| 9 | |
| 10 | /* includes */ |
| 11 | |
| 12 | #include <common.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 13 | #include <i8042.h> |
| 14 | |
| 15 | /* defines */ |
| 16 | |
| 17 | #ifdef CONFIG_CONSOLE_CURSOR |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 18 | extern void console_cursor(int state); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 19 | static int blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT; |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 20 | static int cursor_state; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 21 | #endif |
| 22 | |
| 23 | /* locals */ |
| 24 | |
Wolfgang Denk | 67777b9 | 2006-03-06 13:03:37 +0100 | [diff] [blame] | 25 | static int kbd_input = -1; /* no input yet */ |
| 26 | static int kbd_mapping = KBD_US; /* default US keyboard */ |
| 27 | static int kbd_flags = NORMAL; /* after reset */ |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 28 | static int kbd_state; /* unshift code */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 29 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 30 | static void kbd_conv_char(unsigned char scan_code); |
| 31 | static void kbd_led_set(void); |
| 32 | static void kbd_normal(unsigned char scan_code); |
| 33 | static void kbd_shift(unsigned char scan_code); |
| 34 | static void kbd_ctrl(unsigned char scan_code); |
| 35 | static void kbd_num(unsigned char scan_code); |
| 36 | static void kbd_caps(unsigned char scan_code); |
| 37 | static void kbd_scroll(unsigned char scan_code); |
| 38 | static void kbd_alt(unsigned char scan_code); |
| 39 | static int kbd_input_empty(void); |
| 40 | static int kbd_reset(void); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 41 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 42 | static unsigned char kbd_fct_map[144] = { |
| 43 | /* kbd_fct_map table for scan code */ |
| 44 | 0, AS, AS, AS, AS, AS, AS, AS, /* scan 0- 7 */ |
| 45 | AS, AS, AS, AS, AS, AS, AS, AS, /* scan 8- F */ |
| 46 | AS, AS, AS, AS, AS, AS, AS, AS, /* scan 10-17 */ |
| 47 | AS, AS, AS, AS, AS, CN, AS, AS, /* scan 18-1F */ |
| 48 | AS, AS, AS, AS, AS, AS, AS, AS, /* scan 20-27 */ |
| 49 | AS, AS, SH, AS, AS, AS, AS, AS, /* scan 28-2F */ |
| 50 | AS, AS, AS, AS, AS, AS, SH, AS, /* scan 30-37 */ |
| 51 | AS, AS, CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 52 | 0, 0, 0, 0, 0, NM, ST, ES, /* scan 40-47 */ |
| 53 | ES, ES, ES, ES, ES, ES, ES, ES, /* scan 48-4F */ |
| 54 | ES, ES, ES, ES, 0, 0, AS, 0, /* scan 50-57 */ |
| 55 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 56 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 57 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 58 | AS, 0, 0, AS, 0, 0, AS, 0, /* scan 70-77 */ |
| 59 | 0, AS, 0, 0, 0, AS, 0, 0, /* scan 78-7F */ |
| 60 | AS, CN, AS, AS, AK, ST, EX, EX, /* enhanced */ |
| 61 | AS, EX, EX, AS, EX, AS, EX, EX /* enhanced */ |
| 62 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 63 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 64 | static unsigned char kbd_key_map[2][5][144] = { |
| 65 | { /* US keyboard */ |
| 66 | { /* unshift code */ |
| 67 | 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */ |
| 68 | '7', '8', '9', '0', '-', '=', 0x08, '\t', /* scan 8- F */ |
| 69 | 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* scan 10-17 */ |
| 70 | 'o', 'p', '[', ']', '\r', CN, 'a', 's', /* scan 18-1F */ |
| 71 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* scan 20-27 */ |
| 72 | '\'', '`', SH, '\\', 'z', 'x', 'c', 'v', /* scan 28-2F */ |
| 73 | 'b', 'n', 'm', ',', '.', '/', SH, '*', /* scan 30-37 */ |
| 74 | ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 75 | 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */ |
| 76 | '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */ |
| 77 | '2', '3', '0', '.', 0, 0, 0, 0, /* scan 50-57 */ |
| 78 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 79 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 80 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 81 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */ |
| 82 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */ |
| 83 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
| 84 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
| 85 | }, |
| 86 | { /* shift code */ |
| 87 | 0, 0x1b, '!', '@', '#', '$', '%', '^', /* scan 0- 7 */ |
| 88 | '&', '*', '(', ')', '_', '+', 0x08, '\t', /* scan 8- F */ |
| 89 | 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', /* scan 10-17 */ |
| 90 | 'O', 'P', '{', '}', '\r', CN, 'A', 'S', /* scan 18-1F */ |
| 91 | 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', /* scan 20-27 */ |
| 92 | '"', '~', SH, '|', 'Z', 'X', 'C', 'V', /* scan 28-2F */ |
| 93 | 'B', 'N', 'M', '<', '>', '?', SH, '*', /* scan 30-37 */ |
| 94 | ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 95 | 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */ |
| 96 | '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */ |
| 97 | '2', '3', '0', '.', 0, 0, 0, 0, /* scan 50-57 */ |
| 98 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 99 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 100 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 101 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */ |
| 102 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */ |
| 103 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
| 104 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
| 105 | }, |
| 106 | { /* control code */ |
| 107 | 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 0- 7 */ |
| 108 | 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 8- F */ |
| 109 | 0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */ |
| 110 | 0x0f, 0x10, 0x1b, 0x1d, '\r', CN, 0x01, 0x13, /* scan 18-1F */ |
| 111 | 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */ |
| 112 | 0xff, 0x1c, SH, 0xff, 0x1a, 0x18, 0x03, 0x16, /* scan 28-2F */ |
| 113 | 0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff, SH, 0xff, /* scan 30-37 */ |
| 114 | 0xff, 0xff, CP, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */ |
| 115 | 0xff, 0xff, 0xff, 0xff, 0xff, NM, ST, 0xff, /* scan 40-47 */ |
| 116 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */ |
| 117 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */ |
| 118 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */ |
| 119 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */ |
| 120 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */ |
| 121 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */ |
| 122 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */ |
| 123 | '\r', CN, '/', '*', ' ', ST, 0xff, 0xff, /* extended */ |
| 124 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */ |
| 125 | }, |
| 126 | { /* non numeric code */ |
| 127 | 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */ |
| 128 | '7', '8', '9', '0', '-', '=', 0x08, '\t', /* scan 8- F */ |
| 129 | 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', /* scan 10-17 */ |
| 130 | 'o', 'p', '[', ']', '\r', CN, 'a', 's', /* scan 18-1F */ |
| 131 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';', /* scan 20-27 */ |
| 132 | '\'', '`', SH, '\\', 'z', 'x', 'c', 'v', /* scan 28-2F */ |
| 133 | 'b', 'n', 'm', ',', '.', '/', SH, '*', /* scan 30-37 */ |
| 134 | ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 135 | 0, 0, 0, 0, 0, NM, ST, 'w', /* scan 40-47 */ |
| 136 | 'x', 'y', 'l', 't', 'u', 'v', 'm', 'q', /* scan 48-4F */ |
| 137 | 'r', 's', 'p', 'n', 0, 0, 0, 0, /* scan 50-57 */ |
| 138 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 139 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 140 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 141 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */ |
| 142 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */ |
| 143 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
| 144 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
| 145 | }, |
| 146 | { /* right alt mode - not used in US keyboard */ |
| 147 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 0 - 7 */ |
| 148 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 8 - F */ |
| 149 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10 -17 */ |
| 150 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 18 -1F */ |
| 151 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20 -27 */ |
| 152 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28 -2F */ |
| 153 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30 -37 */ |
| 154 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38 -3F */ |
| 155 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40 -47 */ |
| 156 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48 -4F */ |
| 157 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50 -57 */ |
| 158 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58 -5F */ |
| 159 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60 -67 */ |
| 160 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68 -6F */ |
| 161 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70 -77 */ |
| 162 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78 -7F */ |
| 163 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */ |
| 164 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */ |
| 165 | } |
| 166 | }, |
| 167 | { /* german keyboard */ |
| 168 | { /* unshift code */ |
| 169 | 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */ |
| 170 | '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 8- F */ |
| 171 | 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', /* scan 10-17 */ |
| 172 | 'o', 'p', 0x81, '+', '\r', CN, 'a', 's', /* scan 18-1F */ |
| 173 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */ |
| 174 | 0x84, '^', SH, '#', 'y', 'x', 'c', 'v', /* scan 28-2F */ |
| 175 | 'b', 'n', 'm', ',', '.', '-', SH, '*', /* scan 30-37 */ |
| 176 | ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 177 | 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */ |
| 178 | '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */ |
| 179 | '2', '3', '0', ',', 0, 0, '<', 0, /* scan 50-57 */ |
| 180 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 181 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 182 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 183 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */ |
| 184 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */ |
| 185 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
| 186 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
| 187 | }, |
| 188 | { /* shift code */ |
| 189 | 0, 0x1b, '!', '"', 0x15, '$', '%', '&', /* scan 0- 7 */ |
| 190 | '/', '(', ')', '=', '?', '`', 0x08, '\t', /* scan 8- F */ |
| 191 | 'Q', 'W', 'E', 'R', 'T', 'Z', 'U', 'I', /* scan 10-17 */ |
| 192 | 'O', 'P', 0x9a, '*', '\r', CN, 'A', 'S', /* scan 18-1F */ |
| 193 | 'D', 'F', 'G', 'H', 'J', 'K', 'L', 0x99, /* scan 20-27 */ |
| 194 | 0x8e, 0xf8, SH, '\'', 'Y', 'X', 'C', 'V', /* scan 28-2F */ |
| 195 | 'B', 'N', 'M', ';', ':', '_', SH, '*', /* scan 30-37 */ |
| 196 | ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 197 | 0, 0, 0, 0, 0, NM, ST, '7', /* scan 40-47 */ |
| 198 | '8', '9', '-', '4', '5', '6', '+', '1', /* scan 48-4F */ |
| 199 | '2', '3', '0', ',', 0, 0, '>', 0, /* scan 50-57 */ |
| 200 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 201 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 202 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 203 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */ |
| 204 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */ |
| 205 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
| 206 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
| 207 | }, |
| 208 | { /* control code */ |
| 209 | 0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 0- 7 */ |
| 210 | 0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 8- F */ |
| 211 | 0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */ |
| 212 | 0x0f, 0x10, 0x1b, 0x1d, '\r', CN, 0x01, 0x13, /* scan 18-1F */ |
| 213 | 0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */ |
| 214 | 0xff, 0x1c, SH, 0xff, 0x1a, 0x18, 0x03, 0x16, /* scan 28-2F */ |
| 215 | 0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff, SH, 0xff, /* scan 30-37 */ |
| 216 | 0xff, 0xff, CP, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */ |
| 217 | 0xff, 0xff, 0xff, 0xff, 0xff, NM, ST, 0xff, /* scan 40-47 */ |
| 218 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */ |
| 219 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */ |
| 220 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */ |
| 221 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */ |
| 222 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */ |
| 223 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */ |
| 224 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */ |
| 225 | '\r', CN, '/', '*', ' ', ST, 0xff, 0xff, /* extended */ |
| 226 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */ |
| 227 | }, |
| 228 | { /* non numeric code */ |
| 229 | 0, 0x1b, '1', '2', '3', '4', '5', '6', /* scan 0- 7 */ |
| 230 | '7', '8', '9', '0', 0xe1, '\'', 0x08, '\t', /* scan 8- F */ |
| 231 | 'q', 'w', 'e', 'r', 't', 'z', 'u', 'i', /* scan 10-17 */ |
| 232 | 'o', 'p', 0x81, '+', '\r', CN, 'a', 's', /* scan 18-1F */ |
| 233 | 'd', 'f', 'g', 'h', 'j', 'k', 'l', 0x94, /* scan 20-27 */ |
| 234 | 0x84, '^', SH, 0, 'y', 'x', 'c', 'v', /* scan 28-2F */ |
| 235 | 'b', 'n', 'm', ',', '.', '-', SH, '*', /* scan 30-37 */ |
| 236 | ' ', ' ', CP, 0, 0, 0, 0, 0, /* scan 38-3F */ |
| 237 | 0, 0, 0, 0, 0, NM, ST, 'w', /* scan 40-47 */ |
| 238 | 'x', 'y', 'l', 't', 'u', 'v', 'm', 'q', /* scan 48-4F */ |
| 239 | 'r', 's', 'p', 'n', 0, 0, '<', 0, /* scan 50-57 */ |
| 240 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 58-5F */ |
| 241 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 60-67 */ |
| 242 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 68-6F */ |
| 243 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 70-77 */ |
| 244 | 0, 0, 0, 0, 0, 0, 0, 0, /* scan 78-7F */ |
| 245 | '\r', CN, '/', '*', ' ', ST, 'F', 'A', /* extended */ |
| 246 | 0, 'D', 'C', 0, 'B', 0, '@', 'P' /* extended */ |
| 247 | }, |
| 248 | { /* Right alt mode - is used in German keyboard */ |
| 249 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 0 - 7 */ |
| 250 | '{', '[', ']', '}', '\\', 0xff, 0xff, 0xff, /* scan 8 - F */ |
| 251 | '@', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10 -17 */ |
| 252 | 0xff, 0xff, 0xff, '~', 0xff, 0xff, 0xff, 0xff, /* scan 18 -1F */ |
| 253 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20 -27 */ |
| 254 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28 -2F */ |
| 255 | 0xff, 0xff, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30 -37 */ |
| 256 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38 -3F */ |
| 257 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40 -47 */ |
| 258 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48 -4F */ |
| 259 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, '|', 0xff, /* scan 50 -57 */ |
| 260 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58 -5F */ |
| 261 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60 -67 */ |
| 262 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68 -6F */ |
| 263 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70 -77 */ |
| 264 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78 -7F */ |
| 265 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */ |
| 266 | 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff /* extended */ |
| 267 | } |
| 268 | } |
| 269 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 270 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 271 | static unsigned char ext_key_map[] = { |
| 272 | 0x1c, /* keypad enter */ |
| 273 | 0x1d, /* right control */ |
| 274 | 0x35, /* keypad slash */ |
| 275 | 0x37, /* print screen */ |
| 276 | 0x38, /* right alt */ |
| 277 | 0x46, /* break */ |
| 278 | 0x47, /* editpad home */ |
| 279 | 0x48, /* editpad up */ |
| 280 | 0x49, /* editpad pgup */ |
| 281 | 0x4b, /* editpad left */ |
| 282 | 0x4d, /* editpad right */ |
| 283 | 0x4f, /* editpad end */ |
| 284 | 0x50, /* editpad dn */ |
| 285 | 0x51, /* editpad pgdn */ |
| 286 | 0x52, /* editpad ins */ |
| 287 | 0x53, /* editpad del */ |
| 288 | 0x00 /* map end */ |
| 289 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 290 | |
Gabe Black | 15bbe8d | 2011-11-14 20:18:12 +0000 | [diff] [blame] | 291 | /******************************************************************************/ |
| 292 | |
| 293 | static int kbd_controller_present(void) |
| 294 | { |
| 295 | return in8(I8042_STATUS_REG) != 0xff; |
| 296 | } |
| 297 | |
Gabe Black | 1370230 | 2012-10-12 14:02:02 +0000 | [diff] [blame] | 298 | /* |
| 299 | * Implement a weak default function for boards that optionally |
| 300 | * need to skip the i8042 initialization. |
| 301 | */ |
| 302 | int __weak board_i8042_skip(void) |
| 303 | { |
| 304 | /* As default, don't skip */ |
| 305 | return 0; |
| 306 | } |
| 307 | |
Louis Yung-Chieh Lo | 46d579c | 2012-10-11 15:15:51 +0000 | [diff] [blame] | 308 | void i8042_flush(void) |
| 309 | { |
| 310 | int timeout; |
| 311 | |
| 312 | /* |
| 313 | * The delay is to give the keyboard controller some time to fill the |
| 314 | * next byte. |
| 315 | */ |
| 316 | while (1) { |
| 317 | timeout = 100; /* wait for no longer than 100us */ |
| 318 | while (timeout > 0 && !(in8(I8042_STATUS_REG) & 0x01)) { |
| 319 | udelay(1); |
| 320 | timeout--; |
| 321 | } |
| 322 | |
| 323 | /* Try to pull next byte if not timeout. */ |
| 324 | if (in8(I8042_STATUS_REG) & 0x01) |
| 325 | in8(I8042_DATA_REG); |
| 326 | else |
| 327 | break; |
| 328 | } |
| 329 | } |
| 330 | |
| 331 | int i8042_disable(void) |
| 332 | { |
| 333 | if (kbd_input_empty() == 0) |
| 334 | return -1; |
| 335 | |
| 336 | /* Disable keyboard */ |
| 337 | out8(I8042_COMMAND_REG, 0xad); |
| 338 | |
| 339 | if (kbd_input_empty() == 0) |
| 340 | return -1; |
| 341 | |
| 342 | return 0; |
| 343 | } |
| 344 | |
| 345 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 346 | /******************************************************************************* |
| 347 | * |
| 348 | * i8042_kbd_init - reset keyboard and init state flags |
| 349 | */ |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 350 | int i8042_kbd_init(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 351 | { |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 352 | int keymap, try; |
| 353 | char *penv; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 354 | |
Gabe Black | 1370230 | 2012-10-12 14:02:02 +0000 | [diff] [blame] | 355 | if (!kbd_controller_present() || board_i8042_skip()) |
Gabe Black | 15bbe8d | 2011-11-14 20:18:12 +0000 | [diff] [blame] | 356 | return -1; |
| 357 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 358 | /* Init keyboard device (default US layout) */ |
| 359 | keymap = KBD_US; |
| 360 | penv = getenv("keymap"); |
| 361 | if (penv != NULL) { |
| 362 | if (strncmp(penv, "de", 3) == 0) |
| 363 | keymap = KBD_GER; |
| 364 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 365 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 366 | for (try = 0; try < KBD_RESET_TRIES; try++) { |
| 367 | if (kbd_reset() == 0) { |
| 368 | kbd_mapping = keymap; |
| 369 | kbd_flags = NORMAL; |
| 370 | kbd_state = 0; |
| 371 | kbd_led_set(); |
| 372 | return 0; |
| 373 | } |
| 374 | } |
| 375 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | |
| 379 | /******************************************************************************* |
| 380 | * |
| 381 | * i8042_tstc - test if keyboard input is available |
Wolfgang Denk | 67777b9 | 2006-03-06 13:03:37 +0100 | [diff] [blame] | 382 | * option: cursor blinking if called in a loop |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 383 | */ |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 384 | int i8042_tstc(struct stdio_dev *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 385 | { |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 386 | unsigned char scan_code = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 387 | |
| 388 | #ifdef CONFIG_CONSOLE_CURSOR |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 389 | if (--blinkCount == 0) { |
| 390 | cursor_state ^= 1; |
| 391 | console_cursor(cursor_state); |
| 392 | blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT; |
| 393 | udelay(10); |
| 394 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 395 | #endif |
| 396 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 397 | if ((in8(I8042_STATUS_REG) & 0x01) == 0) { |
| 398 | return 0; |
| 399 | } else { |
| 400 | scan_code = in8(I8042_DATA_REG); |
| 401 | if (scan_code == 0xfa) |
| 402 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 403 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 404 | kbd_conv_char(scan_code); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 405 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 406 | if (kbd_input != -1) |
| 407 | return 1; |
| 408 | } |
| 409 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 410 | } |
| 411 | |
| 412 | |
| 413 | /******************************************************************************* |
| 414 | * |
| 415 | * i8042_getc - wait till keyboard input is available |
Wolfgang Denk | 67777b9 | 2006-03-06 13:03:37 +0100 | [diff] [blame] | 416 | * option: turn on/off cursor while waiting |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 417 | */ |
Simon Glass | 0d1e1f7 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 418 | int i8042_getc(struct stdio_dev *dev) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 419 | { |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 420 | int ret_chr; |
| 421 | unsigned char scan_code; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 422 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 423 | while (kbd_input == -1) { |
| 424 | while ((in8(I8042_STATUS_REG) & 0x01) == 0) { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 425 | #ifdef CONFIG_CONSOLE_CURSOR |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 426 | if (--blinkCount == 0) { |
| 427 | cursor_state ^= 1; |
| 428 | console_cursor(cursor_state); |
| 429 | blinkCount = CONFIG_SYS_CONSOLE_BLINK_COUNT; |
| 430 | } |
| 431 | udelay(10); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 432 | #endif |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 433 | } |
| 434 | scan_code = in8(I8042_DATA_REG); |
| 435 | if (scan_code != 0xfa) |
| 436 | kbd_conv_char (scan_code); |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 437 | } |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 438 | ret_chr = kbd_input; |
| 439 | kbd_input = -1; |
| 440 | return ret_chr; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 441 | } |
| 442 | |
| 443 | |
| 444 | /******************************************************************************/ |
| 445 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 446 | static void kbd_conv_char(unsigned char scan_code) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 447 | { |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 448 | if (scan_code == 0xe0) { |
| 449 | kbd_flags |= EXT; |
| 450 | return; |
| 451 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 452 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 453 | /* if high bit of scan_code, set break flag */ |
| 454 | if (scan_code & 0x80) |
| 455 | kbd_flags |= BRK; |
| 456 | else |
| 457 | kbd_flags &= ~BRK; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 458 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 459 | if ((scan_code == 0xe1) || (kbd_flags & E1)) { |
| 460 | if (scan_code == 0xe1) { |
| 461 | kbd_flags ^= BRK; /* reset the break flag */ |
| 462 | kbd_flags ^= E1; /* bitwise EXOR with E1 flag */ |
| 463 | } |
| 464 | return; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 465 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 466 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 467 | scan_code &= 0x7f; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 468 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 469 | if (kbd_flags & EXT) { |
| 470 | int i; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 471 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 472 | kbd_flags ^= EXT; |
| 473 | for (i = 0; ext_key_map[i]; i++) { |
| 474 | if (ext_key_map[i] == scan_code) { |
| 475 | scan_code = 0x80 + i; |
| 476 | break; |
| 477 | } |
| 478 | } |
| 479 | /* not found ? */ |
| 480 | if (!ext_key_map[i]) |
| 481 | return; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 482 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 483 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 484 | switch (kbd_fct_map[scan_code]) { |
| 485 | case AS: |
| 486 | kbd_normal(scan_code); |
| 487 | break; |
| 488 | case SH: |
| 489 | kbd_shift(scan_code); |
| 490 | break; |
| 491 | case CN: |
| 492 | kbd_ctrl(scan_code); |
| 493 | break; |
| 494 | case NM: |
| 495 | kbd_num(scan_code); |
| 496 | break; |
| 497 | case CP: |
| 498 | kbd_caps(scan_code); |
| 499 | break; |
| 500 | case ST: |
| 501 | kbd_scroll(scan_code); |
| 502 | break; |
| 503 | case AK: |
| 504 | kbd_alt(scan_code); |
| 505 | break; |
| 506 | } |
| 507 | return; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 508 | } |
| 509 | |
| 510 | |
| 511 | /******************************************************************************/ |
| 512 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 513 | static void kbd_normal(unsigned char scan_code) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 514 | { |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 515 | unsigned char chr; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 516 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 517 | if ((kbd_flags & BRK) == NORMAL) { |
| 518 | chr = kbd_key_map[kbd_mapping][kbd_state][scan_code]; |
| 519 | if ((chr == 0xff) || (chr == 0x00)) |
| 520 | return; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 521 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 522 | /* if caps lock convert upper to lower */ |
| 523 | if (((kbd_flags & CAPS) == CAPS) && |
| 524 | (chr >= 'a' && chr <= 'z')) { |
| 525 | chr -= 'a' - 'A'; |
| 526 | } |
| 527 | kbd_input = chr; |
| 528 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | |
| 532 | /******************************************************************************/ |
| 533 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 534 | static void kbd_shift(unsigned char scan_code) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 535 | { |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 536 | if ((kbd_flags & BRK) == BRK) { |
| 537 | kbd_state = AS; |
| 538 | kbd_flags &= (~SHIFT); |
| 539 | } else { |
| 540 | kbd_state = SH; |
| 541 | kbd_flags |= SHIFT; |
| 542 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 543 | } |
| 544 | |
| 545 | |
| 546 | /******************************************************************************/ |
| 547 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 548 | static void kbd_ctrl(unsigned char scan_code) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 549 | { |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 550 | if ((kbd_flags & BRK) == BRK) { |
| 551 | kbd_state = AS; |
| 552 | kbd_flags &= (~CTRL); |
| 553 | } else { |
| 554 | kbd_state = CN; |
| 555 | kbd_flags |= CTRL; |
| 556 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 557 | } |
| 558 | |
| 559 | |
| 560 | /******************************************************************************/ |
| 561 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 562 | static void kbd_caps(unsigned char scan_code) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 563 | { |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 564 | if ((kbd_flags & BRK) == NORMAL) { |
| 565 | kbd_flags ^= CAPS; |
| 566 | kbd_led_set(); /* update keyboard LED */ |
| 567 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | |
| 571 | /******************************************************************************/ |
| 572 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 573 | static void kbd_num(unsigned char scan_code) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 574 | { |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 575 | if ((kbd_flags & BRK) == NORMAL) { |
| 576 | kbd_flags ^= NUM; |
| 577 | kbd_state = (kbd_flags & NUM) ? AS : NM; |
| 578 | kbd_led_set(); /* update keyboard LED */ |
| 579 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 580 | } |
| 581 | |
| 582 | |
| 583 | /******************************************************************************/ |
| 584 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 585 | static void kbd_scroll(unsigned char scan_code) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 586 | { |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 587 | if ((kbd_flags & BRK) == NORMAL) { |
| 588 | kbd_flags ^= STP; |
| 589 | kbd_led_set(); /* update keyboard LED */ |
| 590 | if (kbd_flags & STP) |
| 591 | kbd_input = 0x13; |
| 592 | else |
| 593 | kbd_input = 0x11; |
| 594 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 595 | } |
| 596 | |
| 597 | /******************************************************************************/ |
| 598 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 599 | static void kbd_alt(unsigned char scan_code) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 600 | { |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 601 | if ((kbd_flags & BRK) == BRK) { |
| 602 | kbd_state = AS; |
| 603 | kbd_flags &= (~ALT); |
| 604 | } else { |
| 605 | kbd_state = AK; |
| 606 | kbd_flags &= ALT; |
| 607 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 608 | } |
| 609 | |
| 610 | |
| 611 | /******************************************************************************/ |
| 612 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 613 | static void kbd_led_set(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 614 | { |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 615 | kbd_input_empty(); |
| 616 | out8(I8042_DATA_REG, 0xed); /* SET LED command */ |
| 617 | kbd_input_empty(); |
| 618 | out8(I8042_DATA_REG, (kbd_flags & 0x7)); /* LED bits only */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 619 | } |
| 620 | |
| 621 | |
| 622 | /******************************************************************************/ |
| 623 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 624 | static int kbd_input_empty(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 625 | { |
Gabe Black | c4459cb | 2012-10-12 14:02:01 +0000 | [diff] [blame] | 626 | int kbdTimeout = KBD_TIMEOUT * 1000; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 627 | |
Gabe Black | c4459cb | 2012-10-12 14:02:01 +0000 | [diff] [blame] | 628 | while ((in8(I8042_STATUS_REG) & I8042_STATUS_IN_DATA) && kbdTimeout--) |
| 629 | udelay(1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 630 | |
Gabe Black | 15bbe8d | 2011-11-14 20:18:12 +0000 | [diff] [blame] | 631 | return kbdTimeout != -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 632 | } |
| 633 | |
| 634 | /******************************************************************************/ |
| 635 | |
Marc Jones | 84f8db6 | 2012-10-11 15:15:52 +0000 | [diff] [blame] | 636 | static int wait_until_kbd_output_full(void) |
| 637 | { |
| 638 | int kbdTimeout = KBD_TIMEOUT * 1000; |
| 639 | |
| 640 | while (((in8(I8042_STATUS_REG) & 0x01) == 0) && kbdTimeout--) |
| 641 | udelay(1); |
| 642 | |
| 643 | return kbdTimeout != -1; |
| 644 | } |
| 645 | |
| 646 | /******************************************************************************/ |
| 647 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 648 | static int kbd_reset(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 649 | { |
Marc Jones | 84f8db6 | 2012-10-11 15:15:52 +0000 | [diff] [blame] | 650 | /* KB Reset */ |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 651 | if (kbd_input_empty() == 0) |
| 652 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 653 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 654 | out8(I8042_DATA_REG, 0xff); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 655 | |
Marc Jones | 84f8db6 | 2012-10-11 15:15:52 +0000 | [diff] [blame] | 656 | if (wait_until_kbd_output_full() == 0) |
| 657 | return -1; |
| 658 | |
| 659 | if (in8(I8042_DATA_REG) != 0xfa) /* ACK */ |
| 660 | return -1; |
| 661 | |
| 662 | if (wait_until_kbd_output_full() == 0) |
| 663 | return -1; |
| 664 | |
| 665 | if (in8(I8042_DATA_REG) != 0xaa) /* Test Pass*/ |
| 666 | return -1; |
| 667 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 668 | if (kbd_input_empty() == 0) |
| 669 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 670 | |
Marc Jones | 84f8db6 | 2012-10-11 15:15:52 +0000 | [diff] [blame] | 671 | /* Set KBC mode */ |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 672 | out8(I8042_COMMAND_REG, 0x60); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 673 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 674 | if (kbd_input_empty() == 0) |
| 675 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 676 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 677 | out8(I8042_DATA_REG, 0x45); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 678 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 679 | if (kbd_input_empty() == 0) |
| 680 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 681 | |
Marc Jones | 84f8db6 | 2012-10-11 15:15:52 +0000 | [diff] [blame] | 682 | /* Enable Keyboard */ |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 683 | out8(I8042_COMMAND_REG, 0xae); |
Simon Glass | 2d1e029 | 2015-03-26 09:29:41 -0600 | [diff] [blame] | 684 | if (kbd_input_empty() == 0) |
| 685 | return -1; |
| 686 | |
| 687 | out8(I8042_COMMAND_REG, 0x60); |
| 688 | if (kbd_input_empty() == 0) |
| 689 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 690 | |
Simon Glass | 2d1e029 | 2015-03-26 09:29:41 -0600 | [diff] [blame] | 691 | out8(I8042_DATA_REG, 0xf4); |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 692 | if (kbd_input_empty() == 0) |
| 693 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 694 | |
Gabe Black | 76a5d32 | 2011-11-14 19:24:14 +0000 | [diff] [blame] | 695 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 696 | } |