Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 094198c | 2009-07-21 21:24:22 +0000 | [diff] [blame] | 4 | * Copyright (C) 2009 coresystems GmbH |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 5 | * Copyright (C) 2008 Advanced Micro Devices, Inc. |
Stefan Reinauer | 094198c | 2009-07-21 21:24:22 +0000 | [diff] [blame] | 6 | * Copyright (C) 2003 Ollie Lo <ollielo@hotmail.com> |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 20 | */ |
| 21 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 22 | #include <console/console.h> |
| 23 | #include <pc80/keyboard.h> |
| 24 | #include <device/device.h> |
Ronald G. Minnich | ef5f218 | 2003-09-26 15:24:54 +0000 | [diff] [blame] | 25 | #include <arch/io.h> |
Stefan Reinauer | 094198c | 2009-07-21 21:24:22 +0000 | [diff] [blame] | 26 | #include <delay.h> |
Vladimir Serbinenko | 63e35f2 | 2014-01-26 03:55:01 +0100 | [diff] [blame] | 27 | #include <types.h> |
Martin Roth | 08637d3 | 2013-07-29 16:39:00 -0600 | [diff] [blame] | 28 | #include <arch/acpi.h> |
Stefan Reinauer | 094198c | 2009-07-21 21:24:22 +0000 | [diff] [blame] | 29 | |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 30 | #define KBD_DATA 0x60 |
| 31 | #define KBD_COMMAND 0x64 |
| 32 | #define KBD_STATUS 0x64 |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 33 | #define KBD_IBF (1 << 1) // 1: input buffer full (data ready for ec) |
| 34 | #define KBD_OBF (1 << 0) // 1: output buffer full (data ready for host) |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 35 | |
| 36 | // Keyboard Controller Commands |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 37 | #define KBC_CMD_READ_COMMAND 0x20 // Read command byte |
| 38 | #define KBC_CMD_WRITE_COMMAND 0x60 // Write command byte |
| 39 | #define KBC_CMD_SELF_TEST 0xAA // Controller self-test |
| 40 | #define KBC_CMD_KBD_TEST 0xAB // Keyboard Interface test |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 41 | |
| 42 | /* The Keyboard controller command byte |
| 43 | * BIT | Description |
| 44 | * ----+------------------------------------------------------- |
| 45 | * 7 | reserved, must be zero |
| 46 | * 6 | XT Translation, (1 = on, 0 = off) |
| 47 | * 5 | Disable Mouse Port (1 = disable, 0 = enable) |
| 48 | * 4 | Disable Keyboard Port (1 = disable, 0 = enable) |
| 49 | * 3 | reserved, must be zero |
| 50 | * 2 | System Flag (1 = self-test passed. DO NOT SET TO ZERO) |
| 51 | * 1 | Mouse Port Interrupts (1 = enable, 0 = disable) |
| 52 | * 0 | Keyboard Port Interrupts (1 = enable, 0 = disable) |
| 53 | */ |
| 54 | |
| 55 | // Keyboard Controller Replies |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 56 | #define KBC_REPLY_SELFTEST_OK 0x55 // controller self-test succeeded |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 57 | |
| 58 | // |
| 59 | // Keyboard Replies |
| 60 | // |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 61 | #define KBD_REPLY_POR 0xAA // Power on reset |
| 62 | #define KBD_REPLY_ACK 0xFA // Command ACK |
| 63 | #define KBD_REPLY_RESEND 0xFE // Command NACK, send command again |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 64 | |
Stefan Reinauer | d1149d7 | 2010-03-24 21:24:17 +0000 | [diff] [blame] | 65 | /* Wait 400ms for keyboard controller answers */ |
| 66 | #define KBC_TIMEOUT_IN_MS 400 |
Ronald G. Minnich | 430111b | 2003-09-26 16:12:23 +0000 | [diff] [blame] | 67 | |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 68 | static int kbc_input_buffer_empty(void) |
Eric Biederman | 029517c | 2004-11-11 11:56:00 +0000 | [diff] [blame] | 69 | { |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 70 | u32 timeout; |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 71 | for (timeout = KBC_TIMEOUT_IN_MS; |
| 72 | timeout && (inb(KBD_STATUS) & KBD_IBF); timeout--) |
Stefan Reinauer | 094198c | 2009-07-21 21:24:22 +0000 | [diff] [blame] | 73 | mdelay(1); |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 74 | |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 75 | if (!timeout) |
| 76 | printk(BIOS_WARNING, |
| 77 | "Unexpected Keyboard controller input buffer full\n"); |
Eric Biederman | 029517c | 2004-11-11 11:56:00 +0000 | [diff] [blame] | 78 | return !!timeout; |
| 79 | } |
| 80 | |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 81 | static int kbc_output_buffer_full(void) |
Eric Biederman | 029517c | 2004-11-11 11:56:00 +0000 | [diff] [blame] | 82 | { |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 83 | u32 timeout; |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 84 | for (timeout = KBC_TIMEOUT_IN_MS; |
| 85 | timeout && ((inb(KBD_STATUS) & KBD_OBF) == 0); timeout--) |
Stefan Reinauer | 094198c | 2009-07-21 21:24:22 +0000 | [diff] [blame] | 86 | mdelay(1); |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 87 | |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 88 | if (!timeout) |
| 89 | printk(BIOS_INFO, |
| 90 | "Keyboard controller output buffer result timeout\n"); |
Eric Biederman | 029517c | 2004-11-11 11:56:00 +0000 | [diff] [blame] | 91 | return !!timeout; |
| 92 | } |
| 93 | |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 94 | static int kbc_cleanup_buffers(void) |
| 95 | { |
| 96 | u32 timeout; |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 97 | for (timeout = KBC_TIMEOUT_IN_MS; |
| 98 | timeout && (inb(KBD_STATUS) & (KBD_OBF | KBD_IBF)); timeout--) { |
Stefan Reinauer | 094198c | 2009-07-21 21:24:22 +0000 | [diff] [blame] | 99 | mdelay(1); |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 100 | inb(KBD_DATA); |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | if (!timeout) { |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 104 | printk(BIOS_ERR, |
| 105 | "Couldn't cleanup the keyboard controller buffers\n"); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 106 | printk(BIOS_ERR, "Status (0x%x): 0x%x, Buffer (0x%x): 0x%x\n", |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 107 | KBD_STATUS, inb(KBD_STATUS), KBD_DATA, inb(KBD_DATA)); |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 108 | } |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 109 | |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 110 | return !!timeout; |
| 111 | } |
| 112 | |
Vladimir Serbinenko | 63e35f2 | 2014-01-26 03:55:01 +0100 | [diff] [blame] | 113 | static enum cb_err kbc_self_test(void) |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 114 | { |
| 115 | u8 self_test; |
| 116 | |
| 117 | /* Clean up any junk that might have been in the KBC. |
| 118 | * Both input and output buffers must be empty. |
| 119 | */ |
| 120 | if (!kbc_cleanup_buffers()) |
Vladimir Serbinenko | 63e35f2 | 2014-01-26 03:55:01 +0100 | [diff] [blame] | 121 | return CB_KBD_CONTROLLER_FAILURE; |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 122 | |
| 123 | /* reset/self test 8042 - send cmd 0xAA */ |
| 124 | outb(KBC_CMD_SELF_TEST, KBD_COMMAND); |
| 125 | |
| 126 | if (!kbc_output_buffer_full()) { |
| 127 | /* There probably is no keyboard controller. */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 128 | printk(BIOS_ERR, "Could not reset keyboard controller.\n"); |
Vladimir Serbinenko | 63e35f2 | 2014-01-26 03:55:01 +0100 | [diff] [blame] | 129 | return CB_KBD_CONTROLLER_FAILURE; |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | /* read self-test result, 0x55 is returned in the output buffer */ |
| 133 | self_test = inb(KBD_DATA); |
| 134 | |
| 135 | if (self_test != 0x55) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 136 | printk(BIOS_ERR, "Keyboard Controller self-test failed: 0x%x\n", |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 137 | self_test); |
Vladimir Serbinenko | 63e35f2 | 2014-01-26 03:55:01 +0100 | [diff] [blame] | 138 | return CB_KBD_CONTROLLER_FAILURE; |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 139 | } |
| 140 | |
Mathias Krause | 1c80cf0 | 2011-12-14 08:40:48 +0100 | [diff] [blame] | 141 | /* ensure the buffers are empty */ |
| 142 | kbc_cleanup_buffers(); |
| 143 | |
| 144 | /* keyboard interface test */ |
| 145 | outb(KBC_CMD_KBD_TEST, KBD_COMMAND); |
| 146 | |
| 147 | if (!kbc_output_buffer_full()) { |
| 148 | printk(BIOS_ERR, "Keyboard Interface test timed out.\n"); |
Vladimir Serbinenko | 63e35f2 | 2014-01-26 03:55:01 +0100 | [diff] [blame] | 149 | return CB_KBD_CONTROLLER_FAILURE; |
Mathias Krause | 1c80cf0 | 2011-12-14 08:40:48 +0100 | [diff] [blame] | 150 | } |
| 151 | |
| 152 | /* read test result, 0x00 should be returned in case of no failures */ |
| 153 | self_test = inb(KBD_DATA); |
| 154 | |
| 155 | if (self_test != 0x00) { |
| 156 | printk(BIOS_ERR, "Keyboard Interface test failed: 0x%x\n", |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 157 | self_test); |
Vladimir Serbinenko | 63e35f2 | 2014-01-26 03:55:01 +0100 | [diff] [blame] | 158 | return CB_KBD_INTERFACE_FAILURE; |
Mathias Krause | 1c80cf0 | 2011-12-14 08:40:48 +0100 | [diff] [blame] | 159 | } |
| 160 | |
Vladimir Serbinenko | 63e35f2 | 2014-01-26 03:55:01 +0100 | [diff] [blame] | 161 | return CB_SUCCESS; |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 162 | } |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 163 | |
| 164 | static u8 send_keyboard(u8 command) |
| 165 | { |
| 166 | u8 regval = 0; |
| 167 | u8 resend = 10; |
| 168 | |
| 169 | do { |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 170 | if (!kbc_input_buffer_empty()) |
| 171 | return 0; |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 172 | outb(command, KBD_DATA); |
Mathias Krause | 1c80cf0 | 2011-12-14 08:40:48 +0100 | [diff] [blame] | 173 | /* the reset command takes much longer then normal commands and |
| 174 | * even worse, some keyboards do send the ACK _after_ doing the |
| 175 | * reset */ |
| 176 | if (command == 0xFF) { |
| 177 | u8 retries; |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 178 | for (retries = 9; retries && !kbc_output_buffer_full(); |
| 179 | retries--) ; |
Mathias Krause | 1c80cf0 | 2011-12-14 08:40:48 +0100 | [diff] [blame] | 180 | } |
Stefan Reinauer | 094198c | 2009-07-21 21:24:22 +0000 | [diff] [blame] | 181 | if (!kbc_output_buffer_full()) { |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 182 | printk(BIOS_ERR, |
| 183 | "Could not send keyboard command %02x\n", |
| 184 | command); |
Stefan Reinauer | 094198c | 2009-07-21 21:24:22 +0000 | [diff] [blame] | 185 | return 0; |
| 186 | } |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 187 | regval = inb(KBD_DATA); |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 188 | --resend; |
Stefan Reinauer | 9c3e8b5 | 2010-02-28 19:12:37 +0000 | [diff] [blame] | 189 | } while (regval == KBD_REPLY_RESEND && resend > 0); |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 190 | |
| 191 | return regval; |
| 192 | } |
| 193 | |
Edward O'Callaghan | def00be | 2014-04-30 05:01:52 +1000 | [diff] [blame] | 194 | void pc_keyboard_init(void) |
Ronald G. Minnich | ef5f218 | 2003-09-26 15:24:54 +0000 | [diff] [blame] | 195 | { |
Mathias Krause | 1c80cf0 | 2011-12-14 08:40:48 +0100 | [diff] [blame] | 196 | u8 retries; |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 197 | u8 regval; |
Vladimir Serbinenko | 63e35f2 | 2014-01-26 03:55:01 +0100 | [diff] [blame] | 198 | enum cb_err err; |
| 199 | |
Kevin O'Connor | 9c35c84 | 2010-09-09 08:34:02 +0000 | [diff] [blame] | 200 | if (!CONFIG_DRIVERS_PS2_KEYBOARD) |
| 201 | return; |
Martin Roth | 08637d3 | 2013-07-29 16:39:00 -0600 | [diff] [blame] | 202 | |
Kyösti Mälkki | 6202aea | 2014-06-20 05:41:21 +0300 | [diff] [blame^] | 203 | if (acpi_is_wakeup_s3()) |
Martin Roth | 08637d3 | 2013-07-29 16:39:00 -0600 | [diff] [blame] | 204 | return; |
Martin Roth | 08637d3 | 2013-07-29 16:39:00 -0600 | [diff] [blame] | 205 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 206 | printk(BIOS_DEBUG, "Keyboard init...\n"); |
Ronald G. Minnich | ef5f218 | 2003-09-26 15:24:54 +0000 | [diff] [blame] | 207 | |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 208 | /* Run a keyboard controller self-test */ |
Vladimir Serbinenko | 63e35f2 | 2014-01-26 03:55:01 +0100 | [diff] [blame] | 209 | err = kbc_self_test(); |
| 210 | /* Ignore iterface failure as it's non-fatal. */ |
| 211 | if (err != CB_SUCCESS && err != CB_KBD_INTERFACE_FAILURE) |
Ronald G. Minnich | ef5f218 | 2003-09-26 15:24:54 +0000 | [diff] [blame] | 212 | return; |
Stefan Reinauer | 094198c | 2009-07-21 21:24:22 +0000 | [diff] [blame] | 213 | |
| 214 | /* Enable keyboard interface - No IRQ */ |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 215 | if (!kbc_input_buffer_empty()) |
| 216 | return; |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 217 | outb(0x60, KBD_COMMAND); |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 218 | if (!kbc_input_buffer_empty()) |
| 219 | return; |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 220 | outb(0x20, KBD_DATA); /* send cmd: enable keyboard */ |
Marc Jones | e59f2e1 | 2009-09-29 19:12:23 +0000 | [diff] [blame] | 221 | if (!kbc_input_buffer_empty()) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 222 | printk(BIOS_INFO, "Timeout while enabling keyboard\n"); |
Marc Jones | e59f2e1 | 2009-09-29 19:12:23 +0000 | [diff] [blame] | 223 | return; |
| 224 | } |
Ronald G. Minnich | ef5f218 | 2003-09-26 15:24:54 +0000 | [diff] [blame] | 225 | |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 226 | /* clean up any junk that might have been in the keyboard */ |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 227 | if (!kbc_cleanup_buffers()) |
| 228 | return; |
Ronald G. Minnich | ef5f218 | 2003-09-26 15:24:54 +0000 | [diff] [blame] | 229 | |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 230 | /* reset keyboard and self test (keyboard side) */ |
| 231 | regval = send_keyboard(0xFF); |
Stefan Reinauer | 9c3e8b5 | 2010-02-28 19:12:37 +0000 | [diff] [blame] | 232 | if (regval == KBD_REPLY_RESEND) { |
| 233 | /* keeps sending RESENDs, probably no keyboard. */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 234 | printk(BIOS_INFO, "No PS/2 keyboard detected.\n"); |
Stefan Reinauer | 9c3e8b5 | 2010-02-28 19:12:37 +0000 | [diff] [blame] | 235 | return; |
| 236 | } |
| 237 | |
| 238 | if (regval != KBD_REPLY_ACK) { |
Mathias Krause | 1c80cf0 | 2011-12-14 08:40:48 +0100 | [diff] [blame] | 239 | printk(BIOS_ERR, "Keyboard reset failed ACK: 0x%x\n", regval); |
Ronald G. Minnich | ef5f218 | 2003-09-26 15:24:54 +0000 | [diff] [blame] | 240 | return; |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 241 | } |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 242 | |
Mathias Krause | 1c80cf0 | 2011-12-14 08:40:48 +0100 | [diff] [blame] | 243 | /* the reset command takes some time, so wait a little longer */ |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 244 | for (retries = 9; retries && !kbc_output_buffer_full(); retries--) ; |
Mathias Krause | 1c80cf0 | 2011-12-14 08:40:48 +0100 | [diff] [blame] | 245 | |
Stefan Reinauer | 094198c | 2009-07-21 21:24:22 +0000 | [diff] [blame] | 246 | if (!kbc_output_buffer_full()) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 247 | printk(BIOS_ERR, "Timeout waiting for keyboard after reset.\n"); |
Stefan Reinauer | 094198c | 2009-07-21 21:24:22 +0000 | [diff] [blame] | 248 | return; |
| 249 | } |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 250 | |
| 251 | regval = inb(KBD_DATA); |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 252 | if (regval != 0xAA) { |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 253 | printk(BIOS_ERR, "Keyboard reset selftest failed: 0x%x\n", |
| 254 | regval); |
Ronald G. Minnich | ef5f218 | 2003-09-26 15:24:54 +0000 | [diff] [blame] | 255 | return; |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /* |
| 259 | * The following set scancode stuff is what normal BIOS do. It could be |
| 260 | * argued that coreboot shouldn't set the scan code..... |
| 261 | */ |
| 262 | |
| 263 | /* disable the keyboard */ |
| 264 | regval = send_keyboard(0xF5); |
Stefan Reinauer | 9c3e8b5 | 2010-02-28 19:12:37 +0000 | [diff] [blame] | 265 | if (regval != KBD_REPLY_ACK) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 266 | printk(BIOS_ERR, "Keyboard disable failed ACK: 0x%x\n", regval); |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 267 | return; |
| 268 | } |
| 269 | |
| 270 | /* Set scancode command */ |
| 271 | regval = send_keyboard(0xF0); |
Stefan Reinauer | 9c3e8b5 | 2010-02-28 19:12:37 +0000 | [diff] [blame] | 272 | if (regval != KBD_REPLY_ACK) { |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 273 | printk(BIOS_ERR, "Keyboard set scancode cmd failed ACK: 0x%x\n", |
| 274 | regval); |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 275 | return; |
| 276 | } |
| 277 | /* Set scancode mode 2 */ |
| 278 | regval = send_keyboard(0x02); |
Stefan Reinauer | 9c3e8b5 | 2010-02-28 19:12:37 +0000 | [diff] [blame] | 279 | if (regval != KBD_REPLY_ACK) { |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 280 | printk(BIOS_ERR, |
| 281 | "Keyboard set scancode mode failed ACK: 0x%x\n", regval); |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 282 | return; |
| 283 | } |
| 284 | |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 285 | /* All is well - enable keyboard interface */ |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 286 | if (!kbc_input_buffer_empty()) |
| 287 | return; |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 288 | outb(0x60, KBD_COMMAND); |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 289 | if (!kbc_input_buffer_empty()) |
| 290 | return; |
Mathias Krause | 1c80cf0 | 2011-12-14 08:40:48 +0100 | [diff] [blame] | 291 | outb(0x65, KBD_DATA); /* send cmd: enable keyboard and IRQ 1 */ |
Scott Duplichan | 9c934d1 | 2010-09-09 20:37:00 +0000 | [diff] [blame] | 292 | if (!kbc_input_buffer_empty()) { |
Mathias Krause | 1c80cf0 | 2011-12-14 08:40:48 +0100 | [diff] [blame] | 293 | printk(BIOS_ERR, "Timeout during keyboard enable\n"); |
| 294 | return; |
| 295 | } |
| 296 | |
| 297 | /* enable the keyboard */ |
| 298 | regval = send_keyboard(0xF4); |
| 299 | if (regval != KBD_REPLY_ACK) { |
| 300 | printk(BIOS_ERR, "Keyboard enable failed ACK: 0x%x\n", regval); |
Marc Jones | e59f2e1 | 2009-09-29 19:12:23 +0000 | [diff] [blame] | 301 | return; |
| 302 | } |
Ronald G. Minnich | ef5f218 | 2003-09-26 15:24:54 +0000 | [diff] [blame] | 303 | } |
| 304 | |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 305 | /* |
| 306 | * Support PS/2 mode - oddball SIOs(KBC) need this setup |
| 307 | * Not well documented. Google - 0xcb keyboard controller |
| 308 | * This is called before pc_keyboard_init(). |
| 309 | */ |
Stefan Reinauer | bbe29ee | 2009-05-23 22:02:31 +0000 | [diff] [blame] | 310 | void set_kbc_ps2_mode(void) |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 311 | { |
Vladimir Serbinenko | 63e35f2 | 2014-01-26 03:55:01 +0100 | [diff] [blame] | 312 | enum cb_err err; |
| 313 | |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 314 | /* Run a keyboard controller self-test */ |
Vladimir Serbinenko | 63e35f2 | 2014-01-26 03:55:01 +0100 | [diff] [blame] | 315 | err = kbc_self_test(); |
| 316 | /* Ignore iterface failure as it's non-fatal. */ |
| 317 | if (err != CB_SUCCESS && err != CB_KBD_INTERFACE_FAILURE) |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 318 | return; |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 319 | |
| 320 | /* Support PS/2 mode */ |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 321 | if (!kbc_input_buffer_empty()) |
| 322 | return; |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 323 | outb(0xcb, KBD_COMMAND); |
| 324 | |
Andrew Wu | e33d6ca | 2013-10-23 20:47:20 +0800 | [diff] [blame] | 325 | if (!kbc_input_buffer_empty()) |
| 326 | return; |
Stefan Reinauer | dd3e82a | 2009-10-24 18:15:07 +0000 | [diff] [blame] | 327 | outb(0x01, KBD_DATA); |
| 328 | |
Marc Jones | ecd176f | 2008-09-26 19:15:38 +0000 | [diff] [blame] | 329 | kbc_cleanup_buffers(); |
| 330 | } |