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