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