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