2008-03-20 00:56:58 +01:00
|
|
|
/*
|
|
|
|
* This file is part of the libpayload project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2008 Advanced Micro Devices, Inc.
|
2017-02-04 17:44:17 +01:00
|
|
|
* Copyright (C) 2017 Patrick Rudolph <siro@das-labor.org>
|
2008-03-20 00:56:58 +01:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2013-03-12 23:44:56 +01:00
|
|
|
#include <keycodes.h>
|
2008-11-24 18:54:46 +01:00
|
|
|
#include <libpayload-config.h>
|
2008-03-20 00:56:58 +01:00
|
|
|
#include <libpayload.h>
|
|
|
|
|
2018-06-29 18:24:54 +02:00
|
|
|
#include "i8042.h"
|
|
|
|
|
2017-01-13 18:40:39 +01:00
|
|
|
#define POWER_BUTTON 0x90
|
2019-11-06 02:51:58 +01:00
|
|
|
#define MEDIA_KEY_PREFIX 0xE0
|
2013-07-27 00:31:21 +02:00
|
|
|
|
2008-09-26 20:37:26 +02:00
|
|
|
struct layout_maps {
|
2011-04-21 18:57:16 +02:00
|
|
|
const char *country;
|
2019-04-08 22:14:57 +02:00
|
|
|
const unsigned short map[4][0x59];
|
2008-09-26 20:37:26 +02:00
|
|
|
};
|
|
|
|
|
2010-03-25 19:52:24 +01:00
|
|
|
static struct layout_maps *map;
|
2017-03-05 17:29:18 +01:00
|
|
|
static int modifier = 0;
|
2019-11-06 02:51:58 +01:00
|
|
|
int (*media_key_mapping_callback)(char ch);
|
2008-09-26 20:37:26 +02:00
|
|
|
|
2010-03-25 19:52:24 +01:00
|
|
|
static struct layout_maps keyboard_layouts[] = {
|
2019-03-06 01:55:15 +01:00
|
|
|
#if CONFIG(LP_PC_KEYBOARD_LAYOUT_US)
|
2008-09-26 20:37:26 +02:00
|
|
|
{ .country = "us", .map = {
|
2008-09-17 20:12:46 +02:00
|
|
|
{ /* No modifier */
|
2008-03-20 20:54:59 +01:00
|
|
|
0x00, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
|
|
|
|
0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x08, 0x09,
|
|
|
|
0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69,
|
|
|
|
0x6F, 0x70, 0x5B, 0x5D, 0x0A, 0x00, 0x61, 0x73,
|
|
|
|
0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B,
|
|
|
|
0x27, 0x60, 0x00, 0x5C, 0x7A, 0x78, 0x63, 0x76,
|
|
|
|
0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x00, 0x2A,
|
2008-09-18 09:48:59 +02:00
|
|
|
0x00, 0x20, 0x00, KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5),
|
|
|
|
KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10), 0x00, 0x00, KEY_HOME,
|
2008-09-17 20:12:46 +02:00
|
|
|
KEY_UP, KEY_NPAGE, 0x00, KEY_LEFT, 0x00, KEY_RIGHT, 0x00, KEY_END,
|
2019-04-08 22:14:57 +02:00
|
|
|
KEY_DOWN, KEY_PPAGE, 0x00, KEY_DC, 0x00, 0x00, 0x00, KEY_F(11),
|
|
|
|
KEY_F(12),
|
2008-03-20 20:54:59 +01:00
|
|
|
},
|
2008-09-17 20:12:46 +02:00
|
|
|
{ /* Shift */
|
2008-03-20 20:54:59 +01:00
|
|
|
0x00, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E,
|
|
|
|
0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x08, 0x00,
|
|
|
|
0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49,
|
|
|
|
0x4F, 0x50, 0x7B, 0x7D, 0x0A, 0x00, 0x41, 0x53,
|
|
|
|
0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A,
|
|
|
|
0x22, 0x7E, 0x00, 0x7C, 0x5A, 0x58, 0x43, 0x56,
|
|
|
|
0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x00, 0x2A,
|
2008-09-18 09:48:59 +02:00
|
|
|
0x00, 0x20, 0x00, KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5),
|
|
|
|
KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10), 0x00, 0x00, KEY_HOME,
|
2008-09-17 20:12:46 +02:00
|
|
|
KEY_UP, KEY_NPAGE, 0x00, KEY_LEFT, 0x00, KEY_RIGHT, 0x00, KEY_END,
|
2019-04-08 22:14:57 +02:00
|
|
|
KEY_DOWN, KEY_PPAGE, 0x00, KEY_DC, 0x00, 0x00, 0x00, KEY_F(11),
|
|
|
|
KEY_F(12),
|
2008-09-17 20:12:46 +02:00
|
|
|
},
|
|
|
|
{ /* ALT */
|
|
|
|
0x00, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
|
|
|
|
0x37, 0x38, 0x39, 0x30, 0x2D, 0x3D, 0x08, 0x09,
|
|
|
|
0x71, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69,
|
|
|
|
0x6F, 0x70, 0x5B, 0x5D, 0x0A, 0x00, 0x61, 0x73,
|
|
|
|
0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B,
|
|
|
|
0x27, 0x60, 0x00, 0x5C, 0x7A, 0x78, 0x63, 0x76,
|
|
|
|
0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x00, 0x2A,
|
2008-09-18 09:48:59 +02:00
|
|
|
0x00, 0x20, 0x00, KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5),
|
|
|
|
KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10), 0x00, 0x00, KEY_HOME,
|
2008-09-17 20:12:46 +02:00
|
|
|
KEY_UP, KEY_NPAGE, 0x00, KEY_LEFT, 0x00, KEY_RIGHT, 0x00, KEY_END,
|
2019-04-08 22:14:57 +02:00
|
|
|
KEY_DOWN, KEY_PPAGE, 0x00, KEY_DC, 0x00, 0x00, 0x00, KEY_F(11),
|
|
|
|
KEY_F(12),
|
2008-09-17 20:12:46 +02:00
|
|
|
},
|
|
|
|
{ /* Shift-ALT */
|
|
|
|
0x00, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E,
|
|
|
|
0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x08, 0x00,
|
|
|
|
0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49,
|
|
|
|
0x4F, 0x50, 0x7B, 0x7D, 0x0A, 0x00, 0x41, 0x53,
|
|
|
|
0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A,
|
|
|
|
0x22, 0x7E, 0x00, 0x7C, 0x5A, 0x58, 0x43, 0x56,
|
|
|
|
0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x00, 0x2A,
|
2008-09-18 09:48:59 +02:00
|
|
|
0x00, 0x20, 0x00, KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5),
|
|
|
|
KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10), 0x00, 0x00, KEY_HOME,
|
2008-09-17 20:12:46 +02:00
|
|
|
KEY_UP, KEY_NPAGE, 0x00, KEY_LEFT, 0x00, KEY_RIGHT, 0x00, KEY_END,
|
2019-04-08 22:14:57 +02:00
|
|
|
KEY_DOWN, KEY_PPAGE, 0x00, KEY_DC, 0x00, 0x00, 0x00, KEY_F(11),
|
|
|
|
KEY_F(12),
|
2008-03-20 20:54:59 +01:00
|
|
|
}
|
2008-09-26 20:37:26 +02:00
|
|
|
}},
|
|
|
|
#endif
|
2019-03-06 01:55:15 +01:00
|
|
|
#if CONFIG(LP_PC_KEYBOARD_LAYOUT_DE)
|
2008-09-26 20:37:26 +02:00
|
|
|
{ .country = "de", .map = {
|
|
|
|
{ /* No modifier */
|
|
|
|
0x00, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
|
|
|
|
0x37, 0x38, 0x39, 0x30, 0x00, 0x27, 0x08, 0x09,
|
|
|
|
0x71, 0x77, 0x65, 0x72, 0x74, 0x7A, 0x75, 0x69,
|
|
|
|
0x6F, 0x70, 0x00, 0x2B, 0x0A, 0x00, 0x61, 0x73,
|
|
|
|
0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x00,
|
|
|
|
0x00, 0x5E, 0x00, 0x23, 0x79, 0x78, 0x63, 0x76,
|
|
|
|
0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2D, 0x00, 0x2A,
|
|
|
|
0x00, 0x20, 0x00, KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5),
|
|
|
|
KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10), 0x00, 0x00, KEY_HOME,
|
|
|
|
KEY_UP, KEY_NPAGE, 0x00, KEY_LEFT, 0x00, KEY_RIGHT, 0x00, KEY_END,
|
2019-04-08 22:14:57 +02:00
|
|
|
KEY_DOWN, KEY_PPAGE, 0x00, KEY_DC, 0x00, 0x00, 0x3C, KEY_F(11),
|
|
|
|
KEY_F(12),
|
2008-09-26 20:37:26 +02:00
|
|
|
},
|
|
|
|
{ /* Shift */
|
|
|
|
0x00, 0x1B, 0x21, 0x22, 0xA7, 0x24, 0x25, 0x26,
|
|
|
|
0x2F, 0x28, 0x29, 0x3D, 0x3F, 0x60, 0x08, 0x00,
|
|
|
|
0x51, 0x57, 0x45, 0x52, 0x54, 0x5A, 0x55, 0x49,
|
|
|
|
0x4F, 0x50, 0x00, 0x2A, 0x0A, 0x00, 0x41, 0x53,
|
|
|
|
0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x00,
|
|
|
|
0x00, 0x7E, 0x00, 0x27, 0x59, 0x58, 0x43, 0x56,
|
|
|
|
0x42, 0x4E, 0x4D, 0x3B, 0x3A, 0x5F, 0x00, 0x2A,
|
|
|
|
0x00, 0x20, 0x00, KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5),
|
|
|
|
KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10), 0x00, 0x00, KEY_HOME,
|
|
|
|
KEY_UP, KEY_NPAGE, 0x00, KEY_LEFT, 0x00, KEY_RIGHT, 0x00, KEY_END,
|
2019-04-08 22:14:57 +02:00
|
|
|
KEY_DOWN, KEY_PPAGE, 0x00, KEY_DC, 0x00, 0x00, 0x3E, KEY_F(11),
|
|
|
|
KEY_F(12),
|
2008-09-26 20:37:26 +02:00
|
|
|
},
|
|
|
|
{ /* ALT */
|
|
|
|
0x00, 0x1B, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36,
|
|
|
|
0x7B, 0x5B, 0x5D, 0x7D, 0x5C, 0x3D, 0x08, 0x09,
|
|
|
|
0x40, 0x77, 0x65, 0x72, 0x74, 0x79, 0x75, 0x69,
|
|
|
|
0x6F, 0x70, 0x5B, 0x7E, 0x0A, 0x00, 0x61, 0x73,
|
|
|
|
0x64, 0x66, 0x67, 0x68, 0x6A, 0x6B, 0x6C, 0x3B,
|
|
|
|
0x27, 0x60, 0x00, 0x5C, 0x7A, 0x78, 0x63, 0x76,
|
|
|
|
0x62, 0x6E, 0x6D, 0x2C, 0x2E, 0x2F, 0x00, 0x2A,
|
|
|
|
0x00, 0x20, 0x00, KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5),
|
|
|
|
KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10), 0x00, 0x00, KEY_HOME,
|
|
|
|
KEY_UP, KEY_NPAGE, 0x00, KEY_LEFT, 0x00, KEY_RIGHT, 0x00, KEY_END,
|
2019-04-08 22:14:57 +02:00
|
|
|
KEY_DOWN, KEY_PPAGE, 0x00, KEY_DC, 0x00, 0x00, 0x7C, KEY_F(11),
|
|
|
|
KEY_F(12),
|
2008-09-26 20:37:26 +02:00
|
|
|
},
|
|
|
|
{ /* Shift-ALT */
|
|
|
|
/* copied from US */
|
|
|
|
0x00, 0x1B, 0x21, 0x40, 0x23, 0x24, 0x25, 0x5E,
|
|
|
|
0x26, 0x2A, 0x28, 0x29, 0x5F, 0x2B, 0x08, 0x00,
|
|
|
|
0x51, 0x57, 0x45, 0x52, 0x54, 0x59, 0x55, 0x49,
|
|
|
|
0x4F, 0x50, 0x7B, 0x7D, 0x0A, 0x00, 0x41, 0x53,
|
|
|
|
0x44, 0x46, 0x47, 0x48, 0x4A, 0x4B, 0x4C, 0x3A,
|
|
|
|
0x22, 0x7E, 0x00, 0x7C, 0x5A, 0x58, 0x43, 0x56,
|
|
|
|
0x42, 0x4E, 0x4D, 0x3C, 0x3E, 0x3F, 0x00, 0x2A,
|
|
|
|
0x00, 0x20, 0x00, KEY_F(1), KEY_F(2), KEY_F(3), KEY_F(4), KEY_F(5),
|
|
|
|
KEY_F(6), KEY_F(7), KEY_F(8), KEY_F(9), KEY_F(10), 0x00, 0x00, KEY_HOME,
|
|
|
|
KEY_UP, KEY_NPAGE, 0x00, KEY_LEFT, 0x00, KEY_RIGHT, 0x00, KEY_END,
|
2019-04-08 22:14:57 +02:00
|
|
|
KEY_DOWN, KEY_PPAGE, 0x00, KEY_DC, 0x00, 0x00, 0x00, KEY_F(11),
|
|
|
|
KEY_F(12),
|
2008-09-26 20:37:26 +02:00
|
|
|
}
|
|
|
|
}},
|
|
|
|
#endif
|
2008-03-20 00:56:58 +01:00
|
|
|
};
|
|
|
|
|
2017-02-04 17:44:17 +01:00
|
|
|
static unsigned char keyboard_cmd(unsigned char cmd)
|
2008-09-26 20:37:26 +02:00
|
|
|
{
|
2017-02-04 17:44:17 +01:00
|
|
|
i8042_write_data(cmd);
|
2011-11-10 15:48:37 +01:00
|
|
|
|
2019-06-06 11:00:36 +02:00
|
|
|
return i8042_wait_read_ps2() == 0xfa;
|
2008-09-26 20:37:26 +02:00
|
|
|
}
|
|
|
|
|
2008-03-20 00:56:58 +01:00
|
|
|
int keyboard_havechar(void)
|
|
|
|
{
|
2017-02-04 17:44:17 +01:00
|
|
|
return i8042_data_ready_ps2();
|
2008-03-20 00:56:58 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char keyboard_get_scancode(void)
|
|
|
|
{
|
|
|
|
unsigned char ch;
|
|
|
|
|
2008-03-20 20:54:59 +01:00
|
|
|
while (!keyboard_havechar()) ;
|
2008-03-20 00:56:58 +01:00
|
|
|
|
2017-03-05 17:29:18 +01:00
|
|
|
ch = i8042_read_data_ps2();
|
2008-03-20 00:56:58 +01:00
|
|
|
|
2008-03-20 20:54:59 +01:00
|
|
|
switch (ch) {
|
2008-03-20 00:56:58 +01:00
|
|
|
case 0x36:
|
|
|
|
case 0x2a:
|
2017-03-05 17:29:18 +01:00
|
|
|
modifier |= KB_MOD_SHIFT;
|
2008-03-20 00:56:58 +01:00
|
|
|
break;
|
|
|
|
case 0x80 | 0x36:
|
|
|
|
case 0x80 | 0x2a:
|
2017-03-05 17:29:18 +01:00
|
|
|
modifier &= ~KB_MOD_SHIFT;
|
2008-08-12 16:19:40 +02:00
|
|
|
break;
|
2008-09-17 20:12:46 +02:00
|
|
|
case 0x38:
|
2017-03-05 17:29:18 +01:00
|
|
|
modifier |= KB_MOD_ALT;
|
2008-09-17 20:12:46 +02:00
|
|
|
break;
|
|
|
|
case 0x80 | 0x38:
|
2017-03-05 17:29:18 +01:00
|
|
|
modifier &= ~KB_MOD_ALT;
|
2008-09-17 20:12:46 +02:00
|
|
|
break;
|
2008-03-20 00:56:58 +01:00
|
|
|
case 0x1d:
|
2017-03-05 17:29:18 +01:00
|
|
|
modifier |= KB_MOD_CTRL;
|
2008-03-20 00:56:58 +01:00
|
|
|
break;
|
|
|
|
case 0x80 | 0x1d:
|
2017-03-05 17:29:18 +01:00
|
|
|
modifier &= ~KB_MOD_CTRL;
|
2008-03-20 00:56:58 +01:00
|
|
|
break;
|
|
|
|
case 0x3a:
|
2017-03-05 17:29:18 +01:00
|
|
|
if (modifier & KB_MOD_CAPSLOCK) {
|
|
|
|
modifier &= ~KB_MOD_CAPSLOCK;
|
2018-06-29 18:24:54 +02:00
|
|
|
if (keyboard_cmd(I8042_KBCMD_SET_MODE_IND))
|
|
|
|
keyboard_cmd(I8042_MODE_CAPS_LOCK_OFF);
|
2008-09-26 20:37:26 +02:00
|
|
|
} else {
|
2017-03-05 17:29:18 +01:00
|
|
|
modifier |= KB_MOD_CAPSLOCK;
|
2018-06-29 18:24:54 +02:00
|
|
|
if (keyboard_cmd(I8042_KBCMD_SET_MODE_IND))
|
|
|
|
keyboard_cmd(I8042_MODE_CAPS_LOCK_ON);
|
2008-09-26 20:37:26 +02:00
|
|
|
}
|
2008-03-20 00:56:58 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-03-05 17:29:18 +01:00
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
int keyboard_getmodifier(void)
|
|
|
|
{
|
|
|
|
return modifier;
|
|
|
|
}
|
|
|
|
|
2019-11-06 02:51:58 +01:00
|
|
|
void initialize_keyboard_media_key_mapping_callback(int (*media_key_mapper)(char))
|
|
|
|
{
|
|
|
|
media_key_mapping_callback = media_key_mapper;
|
|
|
|
}
|
|
|
|
|
2017-03-05 17:29:18 +01:00
|
|
|
int keyboard_getchar(void)
|
|
|
|
{
|
|
|
|
unsigned char ch;
|
|
|
|
int shift;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
while (!keyboard_havechar()) ;
|
|
|
|
|
|
|
|
ch = keyboard_get_scancode();
|
2019-11-06 02:51:58 +01:00
|
|
|
if ((media_key_mapping_callback != NULL) && (ch == MEDIA_KEY_PREFIX)) {
|
|
|
|
ch = keyboard_get_scancode();
|
|
|
|
return media_key_mapping_callback(ch);
|
|
|
|
}
|
2017-03-05 17:29:18 +01:00
|
|
|
|
2019-04-08 22:14:57 +02:00
|
|
|
if (!(ch & 0x80) && ch < 0x59) {
|
2008-03-20 20:54:59 +01:00
|
|
|
shift =
|
2017-03-05 17:29:18 +01:00
|
|
|
(modifier & KB_MOD_SHIFT) ^ (modifier & KB_MOD_CAPSLOCK) ? 1 : 0;
|
2008-09-17 20:12:46 +02:00
|
|
|
|
2017-03-05 17:29:18 +01:00
|
|
|
if (modifier & KB_MOD_ALT)
|
2008-09-17 20:12:46 +02:00
|
|
|
shift += 2;
|
|
|
|
|
2008-09-26 20:37:26 +02:00
|
|
|
ret = map->map[shift][ch];
|
|
|
|
|
2017-03-05 17:29:18 +01:00
|
|
|
if (modifier & KB_MOD_CTRL) {
|
2008-09-26 20:37:26 +02:00
|
|
|
switch (ret) {
|
|
|
|
case 'a' ... 'z':
|
|
|
|
ret &= 0x1f;
|
|
|
|
break;
|
|
|
|
case KEY_DC:
|
|
|
|
/* vulcan nerve pinch */
|
2017-03-05 17:29:18 +01:00
|
|
|
if ((modifier & KB_MOD_ALT) && reset_handler)
|
2008-09-26 20:37:26 +02:00
|
|
|
reset_handler();
|
2019-05-11 01:29:48 +02:00
|
|
|
/* fallthrough */
|
2008-09-26 20:37:26 +02:00
|
|
|
default:
|
|
|
|
ret = 0;
|
|
|
|
}
|
|
|
|
}
|
2008-03-20 00:56:58 +01:00
|
|
|
}
|
|
|
|
|
2017-01-13 18:40:39 +01:00
|
|
|
if (ch == 0x5e)
|
|
|
|
ret = POWER_BUTTON;
|
|
|
|
|
2008-03-20 00:56:58 +01:00
|
|
|
return ret;
|
|
|
|
}
|
2008-04-26 01:09:39 +02:00
|
|
|
|
2008-09-26 20:37:26 +02:00
|
|
|
/**
|
|
|
|
* Set keyboard layout
|
2010-04-27 08:56:47 +02:00
|
|
|
* @param country string describing the keyboard layout language.
|
2008-10-16 21:20:51 +02:00
|
|
|
* Valid values are "us", "de".
|
2008-09-26 20:37:26 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
int keyboard_set_layout(char *country)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i=0; i<ARRAY_SIZE(keyboard_layouts); i++) {
|
|
|
|
if (strncmp(keyboard_layouts[i].country, country,
|
|
|
|
strlen(keyboard_layouts[i].country)))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* Found, changing keyboard layout */
|
|
|
|
map = &keyboard_layouts[i];
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Nothing found, not changed */
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2008-10-21 17:08:18 +02:00
|
|
|
static struct console_input_driver cons = {
|
|
|
|
.havekey = keyboard_havechar,
|
2019-04-22 22:38:13 +02:00
|
|
|
.getchar = keyboard_getchar,
|
|
|
|
.input_type = CONSOLE_INPUT_TYPE_EC,
|
2008-10-21 17:08:18 +02:00
|
|
|
};
|
|
|
|
|
2019-12-09 08:05:12 +01:00
|
|
|
/* Enable keyboard translated */
|
|
|
|
static int enable_translated(void)
|
2008-04-26 01:09:39 +02:00
|
|
|
{
|
2019-12-09 08:05:12 +01:00
|
|
|
if (!i8042_cmd(I8042_CMD_RD_CMD_BYTE)) {
|
|
|
|
int cmd = i8042_read_data_ps2();
|
|
|
|
cmd |= I8042_CMD_BYTE_XLATE;
|
2019-12-12 06:15:30 +01:00
|
|
|
if (!i8042_cmd(I8042_CMD_WR_CMD_BYTE)) {
|
2019-12-09 08:05:12 +01:00
|
|
|
i8042_write_data(cmd);
|
2019-12-12 06:15:30 +01:00
|
|
|
} else {
|
|
|
|
printf("ERROR: i8042_cmd WR_CMD failed!\n");
|
|
|
|
return 0;
|
|
|
|
}
|
2019-12-09 08:05:12 +01:00
|
|
|
} else {
|
2019-12-12 06:15:30 +01:00
|
|
|
printf("ERROR: i8042_cmd RD_CMD failed!\n");
|
2019-12-09 08:05:12 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return 1;
|
|
|
|
}
|
2017-02-04 17:44:17 +01:00
|
|
|
|
2019-12-09 08:05:12 +01:00
|
|
|
/* Set scancode set 1 */
|
|
|
|
static int set_scancode_set(void)
|
|
|
|
{
|
|
|
|
unsigned int ret;
|
2018-06-29 18:24:54 +02:00
|
|
|
ret = keyboard_cmd(I8042_KBCMD_SET_SCANCODE);
|
2019-12-09 08:05:12 +01:00
|
|
|
if (!ret) {
|
2019-06-04 04:02:31 +02:00
|
|
|
printf("ERROR: Keyboard set scancode failed!\n");
|
2019-12-09 08:05:12 +01:00
|
|
|
return ret;
|
2019-06-04 04:02:31 +02:00
|
|
|
}
|
2017-02-04 17:44:17 +01:00
|
|
|
|
2018-06-29 18:24:54 +02:00
|
|
|
ret = keyboard_cmd(I8042_SCANCODE_SET_1);
|
2019-12-09 08:05:12 +01:00
|
|
|
if (!ret) {
|
2019-06-04 04:02:31 +02:00
|
|
|
printf("ERROR: Keyboard scancode set#1 failed!\n");
|
2019-12-09 08:05:12 +01:00
|
|
|
return ret;
|
2019-06-04 04:02:31 +02:00
|
|
|
}
|
2017-02-04 17:44:17 +01:00
|
|
|
|
2018-01-16 18:59:54 +01:00
|
|
|
/*
|
|
|
|
* Set default parameters.
|
|
|
|
* Fix for broken QEMU ps/2 make scancodes.
|
|
|
|
*/
|
2019-12-09 08:05:12 +01:00
|
|
|
ret = keyboard_cmd(I8042_KBCMD_SET_DEFAULT);
|
2019-06-04 04:02:31 +02:00
|
|
|
if (!ret) {
|
|
|
|
printf("ERROR: Keyboard set default params failed!\n");
|
2019-12-09 08:05:12 +01:00
|
|
|
return ret;
|
2019-06-04 04:02:31 +02:00
|
|
|
}
|
2018-01-16 18:59:54 +01:00
|
|
|
|
2017-02-04 17:44:17 +01:00
|
|
|
/* Enable scanning */
|
2018-06-29 18:24:54 +02:00
|
|
|
ret = keyboard_cmd(I8042_KBCMD_EN);
|
2019-12-09 08:05:12 +01:00
|
|
|
if (!ret) {
|
2019-06-04 04:02:31 +02:00
|
|
|
printf("ERROR: Keyboard enable scanning failed!\n");
|
2019-12-09 08:05:12 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void keyboard_init(void)
|
|
|
|
{
|
|
|
|
map = &keyboard_layouts[0];
|
|
|
|
|
|
|
|
/* Initialized keyboard controller. */
|
|
|
|
if (!i8042_probe() || !i8042_has_ps2())
|
2008-10-20 19:07:26 +02:00
|
|
|
return;
|
2019-12-09 08:05:12 +01:00
|
|
|
|
|
|
|
/* Empty keyboard buffer */
|
|
|
|
while (keyboard_havechar())
|
|
|
|
keyboard_getchar();
|
|
|
|
|
|
|
|
/* Enable first PS/2 port */
|
|
|
|
i8042_cmd(I8042_CMD_EN_KB);
|
|
|
|
|
|
|
|
if (CONFIG(LP_PC_KEYBOARD_AT_TRANSLATED)) {
|
|
|
|
if (!enable_translated())
|
|
|
|
return;
|
|
|
|
} else {
|
|
|
|
if (!set_scancode_set())
|
|
|
|
return;
|
2019-06-04 04:02:31 +02:00
|
|
|
}
|
2008-10-20 19:07:26 +02:00
|
|
|
|
2008-10-21 17:08:18 +02:00
|
|
|
console_add_input_driver(&cons);
|
2008-04-26 01:09:39 +02:00
|
|
|
}
|
|
|
|
|
2013-07-27 00:31:21 +02:00
|
|
|
void keyboard_disconnect(void)
|
|
|
|
{
|
|
|
|
/* If 0x64 returns 0xff, then we have no keyboard
|
|
|
|
* controller */
|
|
|
|
if (inb(0x64) == 0xFF)
|
|
|
|
return;
|
|
|
|
|
2018-05-27 18:58:25 +02:00
|
|
|
if (!i8042_has_ps2())
|
|
|
|
return;
|
|
|
|
|
2013-07-27 00:31:21 +02:00
|
|
|
/* Empty keyboard buffer */
|
|
|
|
while (keyboard_havechar())
|
|
|
|
keyboard_getchar();
|
|
|
|
|
2018-06-29 18:29:43 +02:00
|
|
|
/* Disable scanning */
|
|
|
|
keyboard_cmd(I8042_KBCMD_DEFAULT_DIS);
|
|
|
|
|
2013-07-27 00:31:21 +02:00
|
|
|
/* Send keyboard disconnect command */
|
2017-02-04 17:44:17 +01:00
|
|
|
i8042_cmd(I8042_CMD_DIS_KB);
|
2013-07-27 00:31:21 +02:00
|
|
|
|
|
|
|
/* Hand off with empty buffer */
|
|
|
|
while (keyboard_havechar())
|
|
|
|
keyboard_getchar();
|
2017-02-04 17:44:17 +01:00
|
|
|
|
|
|
|
/* Release keyboard controller driver */
|
|
|
|
i8042_close();
|
2013-07-27 00:31:21 +02:00
|
|
|
}
|