All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model
@ 2015-11-11 17:05 Simon Glass
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 01/12] input: Support the German keymap Simon Glass
                   ` (12 more replies)
  0 siblings, 13 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

This series adds a new uclass for keyboards and converts some drivers
over to use it.

This series includes some work to remove code duplication in the keyboard
drivers by updating them to use the input library (input.c). This unifies
the keycode decoding logic in one place. In order to do this some
enhancements are needed to the input library and these are also included.

The cros_ec and tegra_kbc drivers are converted to use driver model.

The i8042 driver is converted also, after various tidy-ups. The driver has
some strange interactions with the cfb_console driver. This is removed in
this series which is possible because the only user is x86. Some i8042
features have been dropped (the only deliberate one is the flashing cursor
which does not seem to be used by any board).

Also the i8042 driver currently has its own keycode-decoding logic. This
series removes it in favour of the input library. Therefore testing of this
new driver would be appreciated. So far I have only been able to test on
link, which does not have a full keyboard. Also, while German keyboard
support is implemented, I am unable to test that either.

These changes can be considered the first step towards moving stdio to
driver model. For that to be useful we need to convert LCD and video also.

Note: This series is missing the code to call the update_leds() method when
the LEDs change. This needs to be added to keyboard_tstc() and
keyboard_getc(). If someone is able to test this I can send a patch for that
also.

This series is available at u-boot-dm branch input-working.

Changes in v3:
- Refactor the German keyboard code to use data rather than code
- Drop unrelated cros_keyb change
- Fix 'QUICK' typo
- Fix missing 'use' word
- Drop patches already applied

Changes in v2:
- Update input_add_tables() to add error checking
- Convert two multi-line comments to single-line comments
- Correct call to input_init()
- Drop CONFIG_VGA_AS_SINGLE_DEVICE from all x86 board config files
- Use device tree to handle this quirk

Simon Glass (12):
  input: Support the German keymap
  input: Adjust structure of code in process_modifier()
  input: Handle caps lock
  input: Allow updating of keyboard LEDs
  input: i8042: Convert to use the input library
  input: Add a Kconfig option for the i8042 keyboard
  x86: Add an i8042 device for boards that have it
  Drop CONFIG_ISA_KEYBOARD
  input: Convert i8042 to driver model
  i8042: Handle a duplicate power-on-reset response
  video: input: Clean up after i8042 conversion
  input: Convert 'keyboard' driver to use input library

 README                                   |  30 +-
 arch/x86/Kconfig                         |   6 +
 arch/x86/dts/bayleybay.dts               |   1 +
 arch/x86/dts/chromebook_link.dts         |   5 +
 arch/x86/dts/keyboard.dtsi               |   5 +
 board/kosagi/novena/novena.c             |   2 +-
 board/mpl/pip405/README                  |   4 -
 doc/device-tree-bindings/input/i8042.txt |  10 +
 drivers/input/Kconfig                    |  10 +
 drivers/input/Makefile                   |   2 +-
 drivers/input/cros_ec_keyb.c             |   2 +-
 drivers/input/i8042.c                    | 563 ++++++++-----------------------
 drivers/input/input.c                    | 158 +++++++--
 drivers/input/keyboard.c                 | 290 +++-------------
 drivers/input/tegra-kbc.c                |   2 +-
 drivers/video/cfb_console.c              |  20 +-
 include/configs/MIP405.h                 |   5 -
 include/configs/PIP405.h                 |   5 -
 include/configs/bayleybay.h              |   3 -
 include/configs/chromebox_panther.h      |   2 -
 include/configs/minnowmax.h              |   1 -
 include/configs/x86-chromebook.h         |   2 +-
 include/configs/x86-common.h             |   2 +-
 include/i8042.h                          |   6 -
 include/input.h                          |  17 +-
 include/keyboard.h                       |   5 +
 26 files changed, 376 insertions(+), 782 deletions(-)
 create mode 100644 arch/x86/dts/keyboard.dtsi
 create mode 100644 doc/device-tree-bindings/input/i8042.txt

-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 01/12] input: Support the German keymap
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
@ 2015-11-11 17:05 ` Simon Glass
  2015-11-12  3:51   ` Bin Meng
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 02/12] input: Adjust structure of code in process_modifier() Simon Glass
                   ` (11 subsequent siblings)
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

Add support for the German keymap, taken from i8042.c. This can be selected
when the input library it initialised.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3:
- Refactor the German keyboard code to use data rather than code

Changes in v2:
- Update input_add_tables() to add error checking

 board/kosagi/novena/novena.c |   2 +-
 drivers/input/cros_ec_keyb.c |   2 +-
 drivers/input/input.c        | 109 ++++++++++++++++++++++++++++++++++++++-----
 drivers/input/tegra-kbc.c    |   2 +-
 include/input.h              |   3 +-
 5 files changed, 102 insertions(+), 16 deletions(-)

diff --git a/board/kosagi/novena/novena.c b/board/kosagi/novena/novena.c
index 4a9f724..babba85 100644
--- a/board/kosagi/novena/novena.c
+++ b/board/kosagi/novena/novena.c
@@ -88,7 +88,7 @@ int drv_keyboard_init(void)
 		debug("%s: Cannot set up input\n", __func__);
 		return -1;
 	}
-	input_add_tables(&button_input);
+	input_add_tables(&button_input, false);
 	button_input.read_keys = novena_gpio_button_read_keys;
 
 	error = input_stdio_register(&dev);
diff --git a/drivers/input/cros_ec_keyb.c b/drivers/input/cros_ec_keyb.c
index fe5caea..9bc4555 100644
--- a/drivers/input/cros_ec_keyb.c
+++ b/drivers/input/cros_ec_keyb.c
@@ -211,7 +211,7 @@ static int cros_ec_kbd_probe(struct udevice *dev)
 
 	priv->input = input;
 	input->dev = dev;
-	input_add_tables(input);
+	input_add_tables(input, false);
 	input->read_keys = cros_ec_kbc_check;
 	strcpy(sdev->name, "cros-ec-keyb");
 
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 9e552f3..96fc195 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -79,6 +79,88 @@ static unsigned char kbd_ctrl_xlate[] = {
 	'\r', 0xff, '/',  '*',
 };
 
+static const uchar kbd_plain_xlate_german[] = {
+	0xff, 0x1b,  '1',  '2',  '3',  '4',  '5',  '6', /* scan 00-07 */
+	 '7',  '8',  '9',  '0', 0xe1, '\'', 0x08, '\t', /* scan 08-0F */
+	 'q',  'w',  'e',  'r',  't',  'z',  'u',  'i', /* scan 10-17 */
+	 'o',  'p', 0x81,  '+', '\r', 0xff,  'a',  's', /* scan 18-1F */
+	 'd',  'f',  'g',  'h',  'j',  'k',  'l', 0x94, /* scan 20-27 */
+	0x84,  '^', 0xff,  '#',  'y',  'x',  'c',  'v', /* scan 28-2F */
+	 'b',  'n',  'm',  ',',  '.',  '-', 0xff,  '*', /* scan 30-37 */
+	 ' ',  ' ', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,  '7', /* scan 40-47 */
+	 '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1', /* scan 48-4F */
+	 '2',  '3',  '0',  ',', 0xff, 0xff,  '<', 0xff, /* scan 50-57 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
+	'\r', 0xff,  '/',  '*',
+};
+
+static unsigned char kbd_shift_xlate_german[] = {
+	   0xff, 0x1b,  '!',  '"', 0x15,  '$',  '%',  '&', /* scan 00-07 */
+	 '/',  '(',  ')',  '=',  '?',  '`', 0x08, '\t', /* scan 08-0F */
+	 'Q',  'W',  'E',  'R',  'T',  'Z',  'U',  'I', /* scan 10-17 */
+	 'O',  'P', 0x9a,  '*', '\r', 0xff,  'A',  'S', /* scan 18-1F */
+	 'D',  'F',  'G',  'H',  'J',  'K',  'L', 0x99, /* scan 20-27 */
+	0x8e, 0xf8, 0xff, '\'',  'Y',  'X',  'C',  'V', /* scan 28-2F */
+	 'B',  'N',  'M',  ';',  ':',  '_', 0xff,  '*', /* scan 30-37 */
+	 ' ',  ' ', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,  '7', /* scan 40-47 */
+	 '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1', /* scan 48-4F */
+	 '2',  '3',  '0',  ',', 0xff, 0xff,  '>', 0xff, /* scan 50-57 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
+	'\r', 0xff,  '/',  '*',
+};
+
+static unsigned char kbd_right_alt_xlate_german[] = {
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */
+	 '{',  '[',  ']',  '}', '\\', 0xff, 0xff, 0xff, /* scan 08-0F */
+	 '@', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10-17 */
+	0xff, 0xff, 0xff,  '~', 0xff, 0xff, 0xff, 0xff, /* scan 18-1F */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20-27 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28-2F */
+	0xff, 0xff, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30-37 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40-47 */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
+	0xff, 0xff, 0xff, 0xff, 0xff, 0xff,  '|', 0xff, /* scan 50-57 */
+};
+
+enum kbd_mask {
+	KBD_ENGLISH	= 1 << 0,
+	KBD_GERMAN	= 1 << 1,
+};
+
+static struct kbd_entry {
+	int kbd_mask;		/* Which languages this is for */
+	int left_keycode;	/* Left keycode to select this map */
+	int right_keycode;	/* Right keycode to select this map */
+	const uchar *xlate;	/* Ascii code for each keycode */
+	int num_entries;	/* Number of entries in xlate */
+} kbd_entry[] = {
+	{ KBD_ENGLISH, -1, -1,
+		kbd_plain_xlate, ARRAY_SIZE(kbd_plain_xlate) },
+	{ KBD_GERMAN, -1, -1,
+		kbd_plain_xlate_german, ARRAY_SIZE(kbd_plain_xlate_german) },
+	{ KBD_ENGLISH, KEY_LEFTSHIFT, KEY_RIGHTSHIFT,
+		kbd_shift_xlate, ARRAY_SIZE(kbd_shift_xlate) },
+	{ KBD_GERMAN, KEY_LEFTSHIFT, KEY_RIGHTSHIFT,
+		kbd_shift_xlate_german, ARRAY_SIZE(kbd_shift_xlate_german) },
+	{ KBD_ENGLISH | KBD_GERMAN, KEY_LEFTCTRL, KEY_RIGHTCTRL,
+		kbd_ctrl_xlate, ARRAY_SIZE(kbd_ctrl_xlate) },
+	{ KBD_GERMAN, -1, KEY_RIGHTALT,
+		kbd_right_alt_xlate_german,
+		ARRAY_SIZE(kbd_right_alt_xlate_german) },
+	{},
+};
+
 /*
  * Scan key code to ANSI 3.64 escape sequence table.  This table is
  * incomplete in that it does not include all possible extra keys.
@@ -501,21 +583,24 @@ void input_allow_repeats(struct input_config *config, bool allow_repeats)
 	config->allow_repeats = allow_repeats;
 }
 
-int input_add_tables(struct input_config *config)
+int input_add_tables(struct input_config *config, bool german)
 {
+	struct kbd_entry *entry;
+	int mask;
 	int ret;
 
-	ret = input_add_table(config, -1, -1,
-			      kbd_plain_xlate, ARRAY_SIZE(kbd_plain_xlate));
-	if (ret)
-		return ret;
-	ret = input_add_table(config, KEY_LEFTSHIFT, KEY_RIGHTSHIFT,
-			      kbd_shift_xlate, ARRAY_SIZE(kbd_shift_xlate));
-	if (ret)
-		return ret;
-
-	return input_add_table(config, KEY_LEFTCTRL, KEY_RIGHTCTRL,
-			       kbd_ctrl_xlate, ARRAY_SIZE(kbd_ctrl_xlate));
+	mask = german ? KBD_GERMAN : KBD_ENGLISH;
+	for (entry = kbd_entry; entry->kbd_mask; entry++) {
+		if (!(mask & entry->kbd_mask))
+			continue;
+		ret = input_add_table(config, entry->left_keycode,
+				      entry->right_keycode, entry->xlate,
+			entry->num_entries);
+		if (ret)
+			return ret;
+	}
+
+	return 0;
 }
 
 int input_init(struct input_config *config, int leds)
diff --git a/drivers/input/tegra-kbc.c b/drivers/input/tegra-kbc.c
index a7137f1..951cbb4 100644
--- a/drivers/input/tegra-kbc.c
+++ b/drivers/input/tegra-kbc.c
@@ -326,7 +326,7 @@ static int tegra_kbd_probe(struct udevice *dev)
 	priv->input = input;
 	input->dev = dev;
 	input->read_keys = tegra_kbc_check;
-	input_add_tables(input);
+	input_add_tables(input, false);
 	strcpy(sdev->name, "tegra-kbc");
 	ret = input_stdio_register(sdev);
 	if (ret) {
diff --git a/include/input.h b/include/input.h
index e56f500..c1af259 100644
--- a/include/input.h
+++ b/include/input.h
@@ -167,9 +167,10 @@ void input_allow_repeats(struct input_config *config, bool allow_repeats);
  * This must be called after input_init() or keycode decoding will not work.
  *
  * @param config	Input state
+ * @param german	true to use German keyboard layout, false for US
  * @return 0 if ok, -1 on error
  */
-int input_add_tables(struct input_config *config);
+int input_add_tables(struct input_config *config, bool german);
 
 /**
  * Set up the input handler with basic key maps.
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 02/12] input: Adjust structure of code in process_modifier()
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 01/12] input: Support the German keymap Simon Glass
@ 2015-11-11 17:05 ` Simon Glass
  2015-11-12 13:39   ` Bin Meng
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 03/12] input: Handle caps lock Simon Glass
                   ` (10 subsequent siblings)
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

Move all the '!release' code into one block so that it is clear that it only
applies on key release.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3: None
Changes in v2: None

 drivers/input/input.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index 96fc195..7513226 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -237,7 +237,6 @@ static struct input_key_xlate *process_modifier(struct input_config *config,
 						int key, int release)
 {
 	struct input_key_xlate *table;
-	int flip = -1;
 	int i;
 
 	/* Start with the main table, and see what modifiers change it */
@@ -252,6 +251,8 @@ static struct input_key_xlate *process_modifier(struct input_config *config,
 
 	/* Handle the lighted keys */
 	if (!release) {
+		int flip = -1;
+
 		switch (key) {
 		case KEY_SCROLLLOCK:
 			flip = FLAG_SCROLL_LOCK;
@@ -263,19 +264,19 @@ static struct input_key_xlate *process_modifier(struct input_config *config,
 			flip = FLAG_CAPS_LOCK;
 			break;
 		}
-	}
 
-	if (flip != -1) {
-		int leds = 0;
-
-		config->leds ^= flip;
-		if (config->flags & FLAG_NUM_LOCK)
-			leds |= INPUT_LED_NUM;
-		if (config->flags & FLAG_CAPS_LOCK)
-			leds |= INPUT_LED_CAPS;
-		if (config->flags & FLAG_SCROLL_LOCK)
-			leds |= INPUT_LED_SCROLL;
-		config->leds = leds;
+		if (flip != -1) {
+			int leds = 0;
+
+			config->leds ^= flip;
+			if (config->flags & FLAG_NUM_LOCK)
+				leds |= INPUT_LED_NUM;
+			if (config->flags & FLAG_CAPS_LOCK)
+				leds |= INPUT_LED_CAPS;
+			if (config->flags & FLAG_SCROLL_LOCK)
+				leds |= INPUT_LED_SCROLL;
+			config->leds = leds;
+		}
 	}
 
 	return table;
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 03/12] input: Handle caps lock
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 01/12] input: Support the German keymap Simon Glass
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 02/12] input: Adjust structure of code in process_modifier() Simon Glass
@ 2015-11-11 17:05 ` Simon Glass
  2015-11-12 13:50   ` Bin Meng
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 04/12] input: Allow updating of keyboard LEDs Simon Glass
                   ` (9 subsequent siblings)
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

When caps lock is enabled we should convert lower case to upper case. Add
this to the input key processing so that caps lock works correctly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3: None
Changes in v2: None

 drivers/input/input.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index 7513226..a8a15c9 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -453,16 +453,19 @@ static int input_keycodes_to_ascii(struct input_config *config,
 	/* Start conversion by looking for the first new keycode (by same). */
 	for (i = same; i < num_keycodes; i++) {
 		int key = keycode[i];
-		int ch = (key < table->num_entries) ? table->xlate[key] : 0xff;
+		int ch;
 
 		/*
 		 * For a normal key (with an ASCII value), add it; otherwise
 		 * translate special key to escape sequence if possible.
 		 */
-		if (ch != 0xff) {
-			if (ch_count < max_chars)
-				output_ch[ch_count] = (uchar)ch;
-			ch_count++;
+		if (key < table->num_entries) {
+			ch = table->xlate[key];
+			if ((config->flags & FLAG_CAPS_LOCK) &&
+			    ch >= 'a' && ch <= 'z')
+				ch -= 'a' - 'A';
+			if (ch_count < max_chars && ch != 0xff)
+				output_ch[ch_count++] = (uchar)ch;
 		} else {
 			ch_count += input_keycode_to_ansi364(config, key,
 						output_ch, max_chars);
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 04/12] input: Allow updating of keyboard LEDs
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
                   ` (2 preceding siblings ...)
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 03/12] input: Handle caps lock Simon Glass
@ 2015-11-11 17:05 ` Simon Glass
  2015-11-12 13:50   ` Bin Meng
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 05/12] input: i8042: Convert to use the input library Simon Glass
                   ` (8 subsequent siblings)
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

Add a function which returns a new keyboard LED value when the LEDs need
updating.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3: None
Changes in v2: None

 drivers/input/input.c |  9 +++++++++
 include/input.h       | 14 +++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)

diff --git a/drivers/input/input.c b/drivers/input/input.c
index a8a15c9..bf1acdc 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -276,6 +276,7 @@ static struct input_key_xlate *process_modifier(struct input_config *config,
 			if (config->flags & FLAG_SCROLL_LOCK)
 				leds |= INPUT_LED_SCROLL;
 			config->leds = leds;
+			config->leds_changed = flip;
 		}
 	}
 
@@ -587,6 +588,14 @@ void input_allow_repeats(struct input_config *config, bool allow_repeats)
 	config->allow_repeats = allow_repeats;
 }
 
+int input_leds_changed(struct input_config *config)
+{
+	if (config->leds_changed)
+		return config->leds;
+
+	return -1;
+}
+
 int input_add_tables(struct input_config *config, bool german)
 {
 	struct kbd_entry *entry;
diff --git a/include/input.h b/include/input.h
index c1af259..ad120e4 100644
--- a/include/input.h
+++ b/include/input.h
@@ -43,7 +43,8 @@ struct input_config {
 	/* Which modifiers are active (1 bit for each MOD_... value) */
 	uchar modifiers;
 	uchar flags;		/* active state keys (FLAGS_...) */
-	uchar leds;		/* active LEDS (INPUT_LED_...) */
+	uchar leds;		/* active LEDs (INPUT_LED_...) */
+	uchar leds_changed;	/* LEDs that just changed */
 	uchar num_tables;	/* number of modifier tables */
 	int prev_keycodes[INPUT_BUFFER_LEN];	/* keys held last time */
 	int num_prev_keycodes;	/* number of prev keys */
@@ -162,6 +163,17 @@ void input_set_delays(struct input_config *config, int repeat_delay_ms,
 void input_allow_repeats(struct input_config *config, bool allow_repeats);
 
 /**
+ * Check if keyboard LEDs need to be updated
+ *
+ * This can be called after input_tstc() to see if keyboard LEDs need
+ * updating.
+ *
+ * @param config	Input state
+ * @return -1 if no LEDs need updating, other value if they do
+ */
+int input_leds_changed(struct input_config *config);
+
+/**
  * Set up the key map tables
  *
  * This must be called after input_init() or keycode decoding will not work.
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 05/12] input: i8042: Convert to use the input library
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
                   ` (3 preceding siblings ...)
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 04/12] input: Allow updating of keyboard LEDs Simon Glass
@ 2015-11-11 17:05 ` Simon Glass
  2015-11-12 13:50   ` Bin Meng
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 06/12] input: Add a Kconfig option for the i8042 keyboard Simon Glass
                   ` (7 subsequent siblings)
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

At present the i8042 driver has its own logic and keymaps. In an effort to
unify the code, move it over to use the input library. This changes most of
the keycode-processing logic since it is now in that library. The main
responsibilities of the driver are now to handle the LEDs, deal with the
PS/2 extended keycodes and initialise the the keyboard.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3: None
Changes in v2:
- Convert two multi-line comments to single-line comments
- Correct call to input_init()

 drivers/input/i8042.c | 493 +++++++-------------------------------------------
 1 file changed, 69 insertions(+), 424 deletions(-)

diff --git a/drivers/input/i8042.c b/drivers/input/i8042.c
index b1ada86..270805b 100644
--- a/drivers/input/i8042.c
+++ b/drivers/input/i8042.c
@@ -7,251 +7,18 @@
 
 /* i8042.c - Intel 8042 keyboard driver routines */
 
-/* includes */
-
 #include <common.h>
-#include <asm/io.h>
 #include <i8042.h>
+#include <input.h>
+#include <asm/io.h>
 
 /* defines */
 #define in8(p)		inb(p)
 #define out8(p, v)	outb(v, p)
 
 /* locals */
-
-static int kbd_input = -1;		/* no input yet */
-static int kbd_mapping = KBD_US;	/* default US keyboard */
-static int kbd_flags = NORMAL;		/* after reset */
-static int kbd_state;			/* unshift code */
-
-static unsigned char kbd_fct_map[144] = {
-	/* kbd_fct_map table for scan code */
-	 0,  AS,  AS,  AS,  AS,  AS,  AS,  AS, /* scan 00-07 */
-	AS,  AS,  AS,  AS,  AS,  AS,  AS,  AS, /* scan 08-0F */
-	AS,  AS,  AS,  AS,  AS,  AS,  AS,  AS, /* scan 10-17 */
-	AS,  AS,  AS,  AS,  AS,  CN,  AS,  AS, /* scan 18-1F */
-	AS,  AS,  AS,  AS,  AS,  AS,  AS,  AS, /* scan 20-27 */
-	AS,  AS,  SH,  AS,  AS,  AS,  AS,  AS, /* scan 28-2F */
-	AS,  AS,  AS,  AS,  AS,  AS,  SH,  AS, /* scan 30-37 */
-	AS,  AS,  CP,   0,   0,   0,   0,   0, /* scan 38-3F */
-	 0,   0,   0,   0,   0,  NM,  ST,  ES, /* scan 40-47 */
-	ES,  ES,  ES,  ES,  ES,  ES,  ES,  ES, /* scan 48-4F */
-	ES,  ES,  ES,  ES,   0,   0,  AS,   0, /* scan 50-57 */
-	 0,   0,   0,   0,   0,   0,   0,   0, /* scan 58-5F */
-	 0,   0,   0,   0,   0,   0,   0,   0, /* scan 60-67 */
-	 0,   0,   0,   0,   0,   0,   0,   0, /* scan 68-6F */
-	AS,   0,   0,  AS,   0,   0,  AS,   0, /* scan 70-77 */
-	 0,  AS,   0,   0,   0,  AS,   0,   0, /* scan 78-7F */
-	AS,  CN,  AS,  AS,  AK,  ST,  EX,  EX, /* enhanced */
-	AS,  EX,  EX,  AS,  EX,  AS,  EX,  EX  /* enhanced */
-	};
-
-static unsigned char kbd_key_map[2][5][144] = {
-	{ /* US keyboard */
-	{ /* unshift code */
-	   0, 0x1b,  '1',  '2',  '3',  '4',  '5',  '6', /* scan 00-07 */
-	 '7',  '8',  '9',  '0',  '-',  '=', 0x08, '\t', /* scan 08-0F */
-	 'q',  'w',  'e',  'r',  't',  'y',  'u',  'i', /* scan 10-17 */
-	 'o',  'p',  '[',  ']', '\r',   CN,  'a',  's', /* scan 18-1F */
-	 'd',  'f',  'g',  'h',  'j',  'k',  'l',  ';', /* scan 20-27 */
-	'\'',  '`',   SH, '\\',  'z',  'x',  'c',  'v', /* scan 28-2F */
-	 'b',  'n',  'm',  ',',  '.',  '/',   SH,  '*', /* scan 30-37 */
-	 ' ',  ' ',   CP,    0,    0,    0,    0,    0, /* scan 38-3F */
-	   0,    0,    0,    0,    0,   NM,   ST,  '7', /* scan 40-47 */
-	 '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1', /* scan 48-4F */
-	 '2',  '3',  '0',  '.',    0,    0,    0,    0, /* scan 50-57 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 58-5F */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 60-67 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 68-6F */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 70-77 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 78-7F */
-	'\r',   CN,  '/',  '*',  ' ',   ST,  'F',  'A', /* extended */
-	   0,  'D',  'C',    0,  'B',    0,  '@',  'P'  /* extended */
-	},
-	{ /* shift code */
-	   0, 0x1b,  '!',  '@',  '#',  '$',  '%',  '^', /* scan 00-07 */
-	 '&',  '*',  '(',  ')',  '_',  '+', 0x08, '\t', /* scan 08-0F */
-	 'Q',  'W',  'E',  'R',  'T',  'Y',  'U',  'I', /* scan 10-17 */
-	 'O',  'P',  '{',  '}', '\r',   CN,  'A',  'S', /* scan 18-1F */
-	 'D',  'F',  'G',  'H',  'J',  'K',  'L',  ':', /* scan 20-27 */
-	 '"',  '~',   SH,  '|',  'Z',  'X',  'C',  'V', /* scan 28-2F */
-	 'B',  'N',  'M',  '<',  '>',  '?',   SH,  '*', /* scan 30-37 */
-	 ' ',  ' ',   CP,    0,    0,    0,    0,    0, /* scan 38-3F */
-	   0,    0,    0,    0,    0,   NM,   ST,  '7', /* scan 40-47 */
-	 '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1', /* scan 48-4F */
-	 '2',  '3',  '0',  '.',    0,    0,    0,    0, /* scan 50-57 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 58-5F */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 60-67 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 68-6F */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 70-77 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 78-7F */
-	'\r',   CN,  '/',  '*',  ' ',   ST,  'F',  'A', /* extended */
-	   0,  'D',  'C',    0,  'B',    0,  '@',  'P'  /* extended */
-	},
-	{ /* control code */
-	0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */
-	0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 08-0F */
-	0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */
-	0x0f, 0x10, 0x1b, 0x1d, '\r',   CN, 0x01, 0x13, /* scan 18-1F */
-	0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */
-	0xff, 0x1c,   SH, 0xff, 0x1a, 0x18, 0x03, 0x16, /* scan 28-2F */
-	0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff,   SH, 0xff, /* scan 30-37 */
-	0xff, 0xff,   CP, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
-	0xff, 0xff, 0xff, 0xff, 0xff,   NM,   ST, 0xff, /* scan 40-47 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
-	'\r',   CN,  '/',  '*',  ' ',   ST, 0xff, 0xff, /* extended */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff  /* extended */
-	},
-	{ /* non numeric code */
-	   0, 0x1b,  '1',  '2',  '3',  '4',  '5',  '6', /* scan 00-07 */
-	 '7',  '8',  '9',  '0',  '-',  '=', 0x08, '\t', /* scan 08-0F */
-	 'q',  'w',  'e',  'r',  't',  'y',  'u',  'i', /* scan 10-17 */
-	 'o',  'p',  '[',  ']', '\r',   CN,  'a',  's', /* scan 18-1F */
-	 'd',  'f',  'g',  'h',  'j',  'k',  'l',  ';', /* scan 20-27 */
-	'\'',  '`',   SH, '\\',  'z',  'x',  'c',  'v', /* scan 28-2F */
-	 'b',  'n',  'm',  ',',  '.',  '/',   SH,  '*', /* scan 30-37 */
-	 ' ',  ' ',   CP,    0,    0,    0,    0,    0, /* scan 38-3F */
-	   0,    0,    0,    0,    0,   NM,   ST,  'w', /* scan 40-47 */
-	 'x',  'y',  'l',  't',  'u',  'v',  'm',  'q', /* scan 48-4F */
-	 'r',  's',  'p',  'n',    0,    0,    0,    0, /* scan 50-57 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 58-5F */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 60-67 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 68-6F */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 70-77 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 78-7F */
-	'\r',   CN,  '/',  '*',  ' ',   ST,  'F',  'A', /* extended */
-	   0,  'D',  'C',    0,  'B',    0,  '@',  'P'  /* extended */
-	},
-	{ /* right alt mode - not used in US keyboard */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 08-0F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10-17 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 18-1F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20-27 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28-2F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30-37 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40-47 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff  /* extended */
-	}
-	},
-	{ /* German keyboard */
-	{ /* unshift code */
-	   0, 0x1b,  '1',  '2',  '3',  '4',  '5',  '6', /* scan 00-07 */
-	 '7',  '8',  '9',  '0', 0xe1, '\'', 0x08, '\t', /* scan 08-0F */
-	 'q',  'w',  'e',  'r',  't',  'z',  'u',  'i', /* scan 10-17 */
-	 'o',  'p', 0x81,  '+', '\r',   CN,  'a',  's', /* scan 18-1F */
-	 'd',  'f',  'g',  'h',  'j',  'k',  'l', 0x94, /* scan 20-27 */
-	0x84,  '^',   SH,  '#',  'y',  'x',  'c',  'v', /* scan 28-2F */
-	 'b',  'n',  'm',  ',',  '.',  '-',   SH,  '*', /* scan 30-37 */
-	 ' ',  ' ',   CP,    0,    0,    0,    0,    0, /* scan 38-3F */
-	   0,    0,    0,    0,    0,   NM,   ST,  '7', /* scan 40-47 */
-	 '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1', /* scan 48-4F */
-	 '2',  '3',  '0',  ',',    0,    0,  '<',    0, /* scan 50-57 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 58-5F */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 60-67 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 68-6F */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 70-77 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 78-7F */
-	'\r',   CN,  '/',  '*',  ' ',   ST,  'F',  'A', /* extended */
-	   0,  'D',  'C',    0,  'B',    0,  '@',  'P'  /* extended */
-	},
-	{ /* shift code */
-	   0, 0x1b,  '!',  '"', 0x15,  '$',  '%',  '&', /* scan 00-07 */
-	 '/',  '(',  ')',  '=',  '?',  '`', 0x08, '\t', /* scan 08-0F */
-	 'Q',  'W',  'E',  'R',  'T',  'Z',  'U',  'I', /* scan 10-17 */
-	 'O',  'P', 0x9a,  '*', '\r',   CN,  'A',  'S', /* scan 18-1F */
-	 'D',  'F',  'G',  'H',  'J',  'K',  'L', 0x99, /* scan 20-27 */
-	0x8e, 0xf8,   SH, '\'',  'Y',  'X',  'C',  'V', /* scan 28-2F */
-	 'B',  'N',  'M',  ';',  ':',  '_',   SH,  '*', /* scan 30-37 */
-	 ' ',  ' ',   CP,    0,    0,    0,    0,    0, /* scan 38-3F */
-	   0,    0,    0,    0,    0,   NM,   ST,  '7', /* scan 40-47 */
-	 '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1', /* scan 48-4F */
-	 '2',  '3',  '0',  ',',    0,    0,  '>',    0, /* scan 50-57 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 58-5F */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 60-67 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 68-6F */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 70-77 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 78-7F */
-	'\r',   CN,  '/',  '*',  ' ',   ST,  'F',  'A', /* extended */
-	   0,  'D',  'C',    0,  'B',    0,  '@',  'P'  /* extended */
-	},
-	{ /* control code */
-	0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */
-	0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 08-0F */
-	0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */
-	0x0f, 0x10, 0x1b, 0x1d, '\r',   CN, 0x01, 0x13, /* scan 18-1F */
-	0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */
-	0xff, 0x1c,   SH, 0xff, 0x1a, 0x18, 0x03, 0x16, /* scan 28-2F */
-	0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff,   SH, 0xff, /* scan 30-37 */
-	0xff, 0xff,   CP, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
-	0xff, 0xff, 0xff, 0xff, 0xff,   NM,   ST, 0xff, /* scan 40-47 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
-	'\r',   CN,  '/',  '*',  ' ',   ST, 0xff, 0xff, /* extended */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff  /* extended */
-	},
-	{ /* non numeric code */
-	   0, 0x1b,  '1',  '2',  '3',  '4',  '5',  '6', /* scan 00-07 */
-	 '7',  '8',  '9',  '0', 0xe1, '\'', 0x08, '\t', /* scan 08-0F */
-	 'q',  'w',  'e',  'r',  't',  'z',  'u',  'i', /* scan 10-17 */
-	 'o',  'p', 0x81,  '+', '\r',   CN,  'a',  's', /* scan 18-1F */
-	 'd',  'f',  'g',  'h',  'j',  'k',  'l', 0x94, /* scan 20-27 */
-	0x84,  '^',   SH,    0,  'y',  'x',  'c',  'v', /* scan 28-2F */
-	 'b',  'n',  'm',  ',',  '.',  '-',   SH,  '*', /* scan 30-37 */
-	 ' ',  ' ',   CP,    0,    0,    0,    0,    0, /* scan 38-3F */
-	   0,    0,    0,    0,    0,   NM,   ST,  'w', /* scan 40-47 */
-	 'x',  'y',  'l',  't',  'u',  'v',  'm',  'q', /* scan 48-4F */
-	 'r',  's',  'p',  'n',    0,    0,  '<',    0, /* scan 50-57 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 58-5F */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 60-67 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 68-6F */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 70-77 */
-	   0,    0,    0,    0,    0,    0,    0,    0, /* scan 78-7F */
-	'\r',   CN,  '/',  '*',  ' ',   ST,  'F',  'A', /* extended */
-	   0,  'D',  'C',    0,  'B',    0,  '@',  'P'  /* extended */
-	},
-	{ /* right alt mode - is used in German keyboard */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */
-	 '{',  '[',  ']',  '}', '\\', 0xff, 0xff, 0xff, /* scan 08-0F */
-	 '@', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10-17 */
-	0xff, 0xff, 0xff,  '~', 0xff, 0xff, 0xff, 0xff, /* scan 18-1F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20-27 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28-2F */
-	0xff, 0xff, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30-37 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40-47 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff,  '|', 0xff, /* scan 50-57 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */
-	0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff  /* extended */
-	}
-	}
-	};
+static struct input_config config;
+static bool extended;
 
 static unsigned char ext_key_map[] = {
 	0x1c, /* keypad enter */
@@ -293,157 +60,12 @@ static int kbd_output_full(void)
 	return kbd_timeout != -1;
 }
 
-static void kbd_led_set(void)
+static void kbd_led_set(int flags)
 {
 	kbd_input_empty();
 	out8(I8042_DATA_REG, CMD_SET_KBD_LED);
 	kbd_input_empty();
-	out8(I8042_DATA_REG, (kbd_flags & 0x7));
-}
-
-static void kbd_normal(unsigned char scan_code)
-{
-	unsigned char chr;
-
-	if ((kbd_flags & BRK) == NORMAL) {
-		chr = kbd_key_map[kbd_mapping][kbd_state][scan_code];
-		if ((chr == 0xff) || (chr == 0x00))
-			return;
-
-		/* if caps lock convert upper to lower */
-		if (((kbd_flags & CAPS) == CAPS) &&
-		    (chr >= 'a' && chr <= 'z')) {
-			chr -= 'a' - 'A';
-		}
-		kbd_input = chr;
-	}
-}
-
-static void kbd_shift(unsigned char scan_code)
-{
-	if ((kbd_flags & BRK) == BRK) {
-		kbd_state = AS;
-		kbd_flags &= (~SHIFT);
-	} else {
-		kbd_state = SH;
-		kbd_flags |= SHIFT;
-	}
-}
-
-static void kbd_ctrl(unsigned char scan_code)
-{
-	if ((kbd_flags & BRK) == BRK) {
-		kbd_state = AS;
-		kbd_flags &= (~CTRL);
-	} else {
-		kbd_state = CN;
-		kbd_flags |= CTRL;
-	}
-}
-
-static void kbd_num(unsigned char scan_code)
-{
-	if ((kbd_flags & BRK) == NORMAL) {
-		kbd_flags ^= NUM;
-		kbd_state = (kbd_flags & NUM) ? AS : NM;
-		kbd_led_set();
-	}
-}
-
-static void kbd_alt(unsigned char scan_code)
-{
-	if ((kbd_flags & BRK) == BRK) {
-		kbd_state = AS;
-		kbd_flags &= (~ALT);
-	} else {
-		kbd_state = AK;
-		kbd_flags &= ALT;
-	}
-}
-
-static void kbd_caps(unsigned char scan_code)
-{
-	if ((kbd_flags & BRK) == NORMAL) {
-		kbd_flags ^= CAPS;
-		kbd_led_set();
-	}
-}
-
-static void kbd_scroll(unsigned char scan_code)
-{
-	if ((kbd_flags & BRK) == NORMAL) {
-		kbd_flags ^= STP;
-		kbd_led_set();
-		if (kbd_flags & STP)
-			kbd_input = 0x13;
-		else
-			kbd_input = 0x11;
-	}
-}
-
-static void kbd_conv_char(unsigned char scan_code)
-{
-	if (scan_code == 0xe0) {
-		kbd_flags |= EXT;
-		return;
-	}
-
-	/* if high bit of scan_code, set break flag */
-	if (scan_code & 0x80)
-		kbd_flags |=  BRK;
-	else
-		kbd_flags &= ~BRK;
-
-	if ((scan_code == 0xe1) || (kbd_flags & E1)) {
-		if (scan_code == 0xe1) {
-			kbd_flags ^= BRK;	/* reset the break flag */
-			kbd_flags ^= E1;	/* bitwise EXOR with E1 flag */
-		}
-		return;
-	}
-
-	scan_code &= 0x7f;
-
-	if (kbd_flags & EXT) {
-		int i;
-
-		kbd_flags ^= EXT;
-		for (i = 0; ext_key_map[i]; i++) {
-			if (ext_key_map[i] == scan_code) {
-				scan_code = 0x80 + i;
-				break;
-			}
-		}
-		/* not found ? */
-		if (!ext_key_map[i])
-			return;
-	}
-
-	switch (kbd_fct_map[scan_code]) {
-	case AS:
-		kbd_normal(scan_code);
-		break;
-	case SH:
-		kbd_shift(scan_code);
-		break;
-	case CN:
-		kbd_ctrl(scan_code);
-		break;
-	case NM:
-		kbd_num(scan_code);
-		break;
-	case AK:
-		kbd_alt(scan_code);
-		break;
-	case CP:
-		kbd_caps(scan_code);
-		break;
-	case ST:
-		kbd_scroll(scan_code);
-		break;
-	}
-
-	return;
+	out8(I8042_DATA_REG, flags & 0x7);
 }
 
 static int kbd_write(int reg, int value)
@@ -566,11 +188,50 @@ int i8042_disable(void)
 	return 0;
 }
 
+static int i8042_kbd_check(struct input_config *input)
+{
+	if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
+		return 0;
+	} else {
+		bool release = false;
+		int scan_code;
+		int i;
+
+		scan_code = in8(I8042_DATA_REG);
+		if (scan_code == 0xfa) {
+			return 0;
+		} else if (scan_code == 0xe0) {
+			extended = true;
+			return 0;
+		}
+		if (scan_code & 0x80) {
+			scan_code &= 0x7f;
+			release = true;
+		}
+		if (extended) {
+			extended = false;
+			for (i = 0; ext_key_map[i]; i++) {
+				if (ext_key_map[i] == scan_code) {
+					scan_code = 0x60 + i;
+					break;
+				}
+			}
+			/* not found ? */
+			if (!ext_key_map[i])
+				return 0;
+		}
+
+		input_add_keycode(&config, scan_code, release);
+		return 1;
+	}
+}
+
 /* i8042_kbd_init - reset keyboard and init state flags */
 int i8042_kbd_init(void)
 {
 	int keymap, try;
 	char *penv;
+	int ret;
 
 	if (!kbd_controller_present() || board_i8042_skip()) {
 		debug("i8042 keyboard controller is not present\n");
@@ -590,58 +251,42 @@ int i8042_kbd_init(void)
 			return -1;
 	}
 
-	kbd_mapping = keymap;
-	kbd_flags   = NORMAL;
-	kbd_state   = 0;
-	kbd_led_set();
+	ret = input_init(&config, keymap == KBD_GER);
+	if (ret)
+		return ret;
+	config.read_keys = i8042_kbd_check;
+	input_allow_repeats(&config, true);
+
+	kbd_led_set(NORMAL);
 
 	return 0;
 }
 
-/*
- * i8042_tstc - test if keyboard input is available
+/**
+ * check_leds() - Check the keyboard LEDs and update them it needed
  *
- * option: cursor blinking if called in a loop
+ * @ret:	Value to return
+ * @return value of @ret
  */
-int i8042_tstc(struct stdio_dev *dev)
+static int check_leds(int ret)
 {
-	unsigned char scan_code = 0;
+	int leds;
 
-	if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
-		return 0;
-	} else {
-		scan_code = in8(I8042_DATA_REG);
-		if (scan_code == 0xfa)
-			return 0;
-
-		kbd_conv_char(scan_code);
+	leds = input_leds_changed(&config);
+	if (leds >= 0)
+		kbd_led_set(leds);
 
-		if (kbd_input != -1)
-			return 1;
-	}
+	return ret;
+}
 
-	return 0;
+/* i8042_tstc - test if keyboard input is available */
+int i8042_tstc(struct stdio_dev *dev)
+{
+	return check_leds(input_tstc(&config));
 }
 
-/*
- * i8042_getc - wait till keyboard input is available
- *
- * option: turn on/off cursor while waiting
- */
+/* i8042_getc - wait till keyboard input is available */
 int i8042_getc(struct stdio_dev *dev)
 {
-	int ret_chr;
-	unsigned char scan_code;
-
-	while (kbd_input == -1) {
-		while ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
-		}
-		scan_code = in8(I8042_DATA_REG);
-		if (scan_code != 0xfa)
-			kbd_conv_char(scan_code);
-	}
-	ret_chr = kbd_input;
-	kbd_input = -1;
-
-	return ret_chr;
+	return check_leds(input_getc(&config));
 }
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 06/12] input: Add a Kconfig option for the i8042 keyboard
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
                   ` (4 preceding siblings ...)
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 05/12] input: i8042: Convert to use the input library Simon Glass
@ 2015-11-11 17:05 ` Simon Glass
  2015-11-14  2:04   ` Simon Glass
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 07/12] x86: Add an i8042 device for boards that have it Simon Glass
                   ` (6 subsequent siblings)
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

Add a new option CONFIG_I8042_KEYB which will replace the current
CONFIG_I8042_KBD. This new name fits better with existing drivers.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

Changes in v3: None
Changes in v2: None

 drivers/input/Kconfig | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index 447c4c3..d560328 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -13,3 +13,13 @@ config CROS_EC_KEYB
 	  Most ARM Chromebooks use an EC to provide access to the keyboard.
 	  Messages are used to request key scans from the EC and these are
 	  then decoded into keys by this driver.
+
+config I8042_KEYB
+	bool "Enable Intel i8042 keyboard support"
+	depends on DM_KEYBOARD
+	help
+	  This adds a driver for the i8042 keyboard controller, allowing the
+	  keyboard to be used on devices which support this controller. The
+	  driver handles English and German keyboards - set the environment
+	  variable 'keymap' to "de" to select German. Keyboard repeat is
+	  handled by the keyboard itself.
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 07/12] x86: Add an i8042 device for boards that have it
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
                   ` (5 preceding siblings ...)
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 06/12] input: Add a Kconfig option for the i8042 keyboard Simon Glass
@ 2015-11-11 17:05 ` Simon Glass
  2015-11-14  2:04   ` Simon Glass
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 08/12] Drop CONFIG_ISA_KEYBOARD Simon Glass
                   ` (5 subsequent siblings)
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

Some boards have an i8042 device. Enable the driver for all x86 boards, and
add a device tree node for those which may have this keyboard.

Also adjust the configuration so that i8042 is always separate from the VGA,
and rename the stdin driver accordingly. With this commit the keyboard will
not work, but it is fixed in the next commit.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

Changes in v3: None
Changes in v2:
- Drop CONFIG_VGA_AS_SINGLE_DEVICE from all x86 board config files

 arch/x86/Kconfig                         |  6 ++++++
 arch/x86/dts/bayleybay.dts               |  1 +
 arch/x86/dts/chromebook_link.dts         |  5 +++++
 arch/x86/dts/keyboard.dtsi               |  5 +++++
 doc/device-tree-bindings/input/i8042.txt | 10 ++++++++++
 include/configs/bayleybay.h              |  3 ---
 include/configs/chromebox_panther.h      |  2 --
 include/configs/minnowmax.h              |  1 -
 include/configs/x86-chromebook.h         |  2 +-
 include/configs/x86-common.h             |  2 +-
 10 files changed, 29 insertions(+), 8 deletions(-)
 create mode 100644 arch/x86/dts/keyboard.dtsi
 create mode 100644 doc/device-tree-bindings/input/i8042.txt

diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index f92082d..d8aeaaf 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -420,6 +420,12 @@ config PCIE_ECAM_SIZE
 	  so a default 0x10000000 size covers all of the 256 buses which is the
 	  maximum number of PCI buses as defined by the PCI specification.
 
+config I8042_KEYB
+	default y
+
+config DM_KEYBOARD
+	default y
+
 source "arch/x86/lib/efi/Kconfig"
 
 endmenu
diff --git a/arch/x86/dts/bayleybay.dts b/arch/x86/dts/bayleybay.dts
index 52d0999..aa86387 100644
--- a/arch/x86/dts/bayleybay.dts
+++ b/arch/x86/dts/bayleybay.dts
@@ -10,6 +10,7 @@
 #include <dt-bindings/interrupt-router/intel-irq.h>
 
 /include/ "skeleton.dtsi"
+/include/ "keyboard.dtsi"
 /include/ "serial.dtsi"
 /include/ "rtc.dtsi"
 
diff --git a/arch/x86/dts/chromebook_link.dts b/arch/x86/dts/chromebook_link.dts
index f27263a..7870bb1 100644
--- a/arch/x86/dts/chromebook_link.dts
+++ b/arch/x86/dts/chromebook_link.dts
@@ -1,6 +1,7 @@
 /dts-v1/;
 
 /include/ "skeleton.dtsi"
+/include/ "keyboard.dtsi"
 /include/ "serial.dtsi"
 /include/ "rtc.dtsi"
 
@@ -41,6 +42,10 @@
 		stdout-path = "/serial";
 	};
 
+	keyboard {
+		intel,duplicate-por;
+	};
+
 	spd {
 		compatible = "memory-spd";
 		#address-cells = <1>;
diff --git a/arch/x86/dts/keyboard.dtsi b/arch/x86/dts/keyboard.dtsi
new file mode 100644
index 0000000..000751b
--- /dev/null
+++ b/arch/x86/dts/keyboard.dtsi
@@ -0,0 +1,5 @@
+/ {
+	keyboard {
+		compatible = "intel,i8042-keyboard";
+	};
+};
diff --git a/doc/device-tree-bindings/input/i8042.txt b/doc/device-tree-bindings/input/i8042.txt
new file mode 100644
index 0000000..cd079c2
--- /dev/null
+++ b/doc/device-tree-bindings/input/i8042.txt
@@ -0,0 +1,10 @@
+i8042 Keyboard
+
+The Intel i8042 is a keyboard controller used on many x86 PCs.
+
+Required properties:
+- compatible: "intel,i8042-keyboard"
+
+Optional properties:
+- intel,duplicate-por: Indicates that a keyboard reset may result in a
+  duplicate POR byte, which should be ignored.
diff --git a/include/configs/bayleybay.h b/include/configs/bayleybay.h
index 1ba2998..ac6b45b 100644
--- a/include/configs/bayleybay.h
+++ b/include/configs/bayleybay.h
@@ -33,9 +33,6 @@
 #define CONFIG_MMC_SDMA
 #define CONFIG_CMD_MMC
 
-/* BayTrail IGD support */
-#define CONFIG_VGA_AS_SINGLE_DEVICE
-
 /* Environment configuration */
 #define CONFIG_ENV_SECT_SIZE		0x1000
 #define CONFIG_ENV_OFFSET		0x006ff000
diff --git a/include/configs/chromebox_panther.h b/include/configs/chromebox_panther.h
index dc732b8..00fe26d 100644
--- a/include/configs/chromebox_panther.h
+++ b/include/configs/chromebox_panther.h
@@ -14,6 +14,4 @@
 /* Avoid a warning in the Realtek Ethernet driver */
 #define CONFIG_SYS_CACHELINE_SIZE 16
 
-#define CONFIG_VGA_AS_SINGLE_DEVICE
-
 #endif	/* __CONFIG_H */
diff --git a/include/configs/minnowmax.h b/include/configs/minnowmax.h
index 53d86a2..c90af40 100644
--- a/include/configs/minnowmax.h
+++ b/include/configs/minnowmax.h
@@ -43,7 +43,6 @@
 
 #define VIDEO_IO_OFFSET				0
 #define CONFIG_X86EMU_RAW_IO
-#define CONFIG_VGA_AS_SINGLE_DEVICE
 
 #define CONFIG_FIT_SIGNATURE
 #define CONFIG_RSA
diff --git a/include/configs/x86-chromebook.h b/include/configs/x86-chromebook.h
index 2be8850..4ff8b94 100644
--- a/include/configs/x86-chromebook.h
+++ b/include/configs/x86-chromebook.h
@@ -51,7 +51,7 @@
 #define CONFIG_ENV_IS_IN_SPI_FLASH
 #define CONFIG_ENV_OFFSET		0x003f8000
 
-#define CONFIG_STD_DEVICES_SETTINGS     "stdin=usbkbd,vga,serial\0" \
+#define CONFIG_STD_DEVICES_SETTINGS     "stdin=usbkbd,i8042-kbd,serial\0" \
 					"stdout=vga,serial\0" \
 					"stderr=vga,serial\0"
 
diff --git a/include/configs/x86-common.h b/include/configs/x86-common.h
index faadab8..302985a 100644
--- a/include/configs/x86-common.h
+++ b/include/configs/x86-common.h
@@ -146,7 +146,7 @@
 #define CONFIG_VIDEO
 #define CONFIG_VIDEO_SW_CURSOR
 #define VIDEO_FB_16BPP_WORD_SWAP
-#define CONFIG_I8042_KBD
+#define CONFIG_VGA_AS_SINGLE_DEVICE
 #define CONFIG_CFB_CONSOLE
 #define CONFIG_CONSOLE_SCROLL_LINES 5
 
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 08/12] Drop CONFIG_ISA_KEYBOARD
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
                   ` (6 preceding siblings ...)
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 07/12] x86: Add an i8042 device for boards that have it Simon Glass
@ 2015-11-11 17:05 ` Simon Glass
  2015-11-14  2:04   ` Simon Glass
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 09/12] input: Convert i8042 to driver model Simon Glass
                   ` (4 subsequent siblings)
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

This option is mentioned but does not do anything. Drop it.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

Changes in v3:
- Drop unrelated cros_keyb change

Changes in v2: None

 README                   | 5 -----
 board/mpl/pip405/README  | 4 ----
 include/configs/MIP405.h | 5 -----
 include/configs/PIP405.h | 5 -----
 4 files changed, 19 deletions(-)

diff --git a/README b/README
index e69e73f..fd8b6b6 100644
--- a/README
+++ b/README
@@ -1767,11 +1767,6 @@ CBFS (Coreboot Filesystem) support
 		a default value of 65536 will be defined.
 
 - Keyboard Support:
-		CONFIG_ISA_KEYBOARD
-
-		Define this to enable standard (PC-Style) keyboard
-		support
-
 		CONFIG_I8042_KBD
 		Standard PC keyboard driver with US (is default) and
 		GERMAN key layout (switch via environment 'keymap=de') support.
diff --git a/board/mpl/pip405/README b/board/mpl/pip405/README
index 012db1c..1b73dbe 100644
--- a/board/mpl/pip405/README
+++ b/board/mpl/pip405/README
@@ -114,10 +114,6 @@ RTC
 ----
 CONFIG_RTC_MC146818		MC146818 RTC support
 
-Keyboard:
----------
-CONFIG_ISA_KEYBOARD		Standard (PC-Style) Keyboard support
-
 Video:
 ------
 CONFIG_VIDEO_CT69000		Enable Chips & Technologies 69000 Video chip
diff --git a/include/configs/MIP405.h b/include/configs/MIP405.h
index ec62c8a..ba93c18 100644
--- a/include/configs/MIP405.h
+++ b/include/configs/MIP405.h
@@ -362,11 +362,6 @@
 #define CONFIG_ISO_PARTITION /* Experimental */
 
 /************************************************************
- * Keyboard support
- ************************************************************/
-#undef CONFIG_ISA_KEYBOARD
-
-/************************************************************
  * Video support
  ************************************************************/
 #define CONFIG_VIDEO			/*To enable video controller support */
diff --git a/include/configs/PIP405.h b/include/configs/PIP405.h
index 45eecc4..aac5a4d 100644
--- a/include/configs/PIP405.h
+++ b/include/configs/PIP405.h
@@ -319,11 +319,6 @@
 #define CONFIG_ISO_PARTITION /* Experimental */
 
 /************************************************************
- * Keyboard support
- ************************************************************/
-#define CONFIG_ISA_KEYBOARD
-
-/************************************************************
  * Video support
  ************************************************************/
 #define CONFIG_VIDEO			/*To enable video controller support */
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 09/12] input: Convert i8042 to driver model
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
                   ` (7 preceding siblings ...)
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 08/12] Drop CONFIG_ISA_KEYBOARD Simon Glass
@ 2015-11-11 17:05 ` Simon Glass
  2015-11-12 13:50   ` Bin Meng
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 10/12] i8042: Handle a duplicate power-on-reset response Simon Glass
                   ` (3 subsequent siblings)
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

Adjust this driver to support driver model. The only users are x86 boards
so this should be safe.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3: None
Changes in v2: None

 drivers/input/Makefile |   2 +-
 drivers/input/i8042.c  | 109 ++++++++++++++++++++++++++++++++++---------------
 include/i8042.h        |   6 ---
 3 files changed, 76 insertions(+), 41 deletions(-)

diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index 9388dfe..5f15265 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -7,7 +7,7 @@
 
 obj-$(CONFIG_DM_KEYBOARD) += keyboard-uclass.o
 
-obj-$(CONFIG_I8042_KBD) += i8042.o
+obj-$(CONFIG_I8042_KEYB) += i8042.o
 obj-$(CONFIG_TEGRA_KEYBOARD) += tegra-kbc.o
 obj-$(CONFIG_TWL4030_INPUT) += twl4030.o
 obj-$(CONFIG_CROS_EC_KEYB) += cros_ec_keyb.o
diff --git a/drivers/input/i8042.c b/drivers/input/i8042.c
index 270805b..e5e2926 100644
--- a/drivers/input/i8042.c
+++ b/drivers/input/i8042.c
@@ -8,8 +8,11 @@
 /* i8042.c - Intel 8042 keyboard driver routines */
 
 #include <common.h>
+#include <dm.h>
+#include <errno.h>
 #include <i8042.h>
 #include <input.h>
+#include <keyboard.h>
 #include <asm/io.h>
 
 /* defines */
@@ -17,8 +20,9 @@
 #define out8(p, v)	outb(v, p)
 
 /* locals */
-static struct input_config config;
-static bool extended;
+struct i8042_kbd_priv {
+	bool extended;	/* true if an extended keycode is expected next */
+};
 
 static unsigned char ext_key_map[] = {
 	0x1c, /* keypad enter */
@@ -60,12 +64,20 @@ static int kbd_output_full(void)
 	return kbd_timeout != -1;
 }
 
-static void kbd_led_set(int flags)
+/**
+ * check_leds() - Check the keyboard LEDs and update them it needed
+ *
+ * @ret:	Value to return
+ * @return value of @ret
+ */
+static int i8042_kbd_update_leds(struct udevice *dev, int leds)
 {
 	kbd_input_empty();
 	out8(I8042_DATA_REG, CMD_SET_KBD_LED);
 	kbd_input_empty();
-	out8(I8042_DATA_REG, flags & 0x7);
+	out8(I8042_DATA_REG, leds & 0x7);
+
+	return 0;
 }
 
 static int kbd_write(int reg, int value)
@@ -144,6 +156,8 @@ static int kbd_controller_present(void)
 /*
  * Implement a weak default function for boards that optionally
  * need to skip the i8042 initialization.
+ *
+ * TODO(sjg at chromium.org): Use device tree for this?
  */
 int __weak board_i8042_skip(void)
 {
@@ -190,6 +204,8 @@ int i8042_disable(void)
 
 static int i8042_kbd_check(struct input_config *input)
 {
+	struct i8042_kbd_priv *priv = dev_get_priv(input->dev);
+
 	if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
 		return 0;
 	} else {
@@ -201,15 +217,15 @@ static int i8042_kbd_check(struct input_config *input)
 		if (scan_code == 0xfa) {
 			return 0;
 		} else if (scan_code == 0xe0) {
-			extended = true;
+			priv->extended = true;
 			return 0;
 		}
 		if (scan_code & 0x80) {
 			scan_code &= 0x7f;
 			release = true;
 		}
-		if (extended) {
-			extended = false;
+		if (priv->extended) {
+			priv->extended = false;
 			for (i = 0; ext_key_map[i]; i++) {
 				if (ext_key_map[i] == scan_code) {
 					scan_code = 0x60 + i;
@@ -221,21 +237,23 @@ static int i8042_kbd_check(struct input_config *input)
 				return 0;
 		}
 
-		input_add_keycode(&config, scan_code, release);
+		input_add_keycode(input, scan_code, release);
 		return 1;
 	}
 }
 
 /* i8042_kbd_init - reset keyboard and init state flags */
-int i8042_kbd_init(void)
+static int i8042_start(struct udevice *dev)
 {
+	struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct input_config *input = &uc_priv->input;
 	int keymap, try;
 	char *penv;
 	int ret;
 
 	if (!kbd_controller_present() || board_i8042_skip()) {
 		debug("i8042 keyboard controller is not present\n");
-		return -1;
+		return -ENOENT;
 	}
 
 	/* Init keyboard device (default US layout) */
@@ -251,42 +269,65 @@ int i8042_kbd_init(void)
 			return -1;
 	}
 
-	ret = input_init(&config, keymap == KBD_GER);
+	ret = input_add_tables(input, keymap == KBD_GER);
 	if (ret)
 		return ret;
-	config.read_keys = i8042_kbd_check;
-	input_allow_repeats(&config, true);
 
-	kbd_led_set(NORMAL);
+	i8042_kbd_update_leds(dev, NORMAL);
+	debug("%s: started\n", __func__);
 
 	return 0;
 }
 
 /**
- * check_leds() - Check the keyboard LEDs and update them it needed
+ * Set up the i8042 keyboard. This is called by the stdio device handler
  *
- * @ret:	Value to return
- * @return value of @ret
+ * We want to do this init when the keyboard is actually used rather than
+ * at start-up, since keyboard input may not currently be selected.
+ *
+ * Once the keyboard starts there will be a period during which we must
+ * wait for the keyboard to init. We do this only when a key is first
+ * read - see kbd_wait_for_fifo_init().
+ *
+ * @return 0 if ok, -ve on error
  */
-static int check_leds(int ret)
+static int i8042_kbd_probe(struct udevice *dev)
 {
-	int leds;
-
-	leds = input_leds_changed(&config);
-	if (leds >= 0)
-		kbd_led_set(leds);
+	struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct stdio_dev *sdev = &uc_priv->sdev;
+	struct input_config *input = &uc_priv->input;
+	int ret;
 
-	return ret;
-}
+	/* Register the device. i8042_start() will be called soon */
+	input->dev = dev;
+	input->read_keys = i8042_kbd_check;
+	input_allow_repeats(input, true);
+	strcpy(sdev->name, "i8042-kbd");
+	ret = input_stdio_register(sdev);
+	if (ret) {
+		debug("%s: input_stdio_register() failed\n", __func__);
+		return ret;
+	}
+	debug("%s: ready\n", __func__);
 
-/* i8042_tstc - test if keyboard input is available */
-int i8042_tstc(struct stdio_dev *dev)
-{
-	return check_leds(input_tstc(&config));
+	return 0;
 }
 
-/* i8042_getc - wait till keyboard input is available */
-int i8042_getc(struct stdio_dev *dev)
-{
-	return check_leds(input_getc(&config));
-}
+static const struct keyboard_ops i8042_kbd_ops = {
+	.start	= i8042_start,
+	.update_leds	= i8042_kbd_update_leds,
+};
+
+static const struct udevice_id i8042_kbd_ids[] = {
+	{ .compatible = "intel,i8042-keyboard" },
+	{ }
+};
+
+U_BOOT_DRIVER(i8042_kbd) = {
+	.name	= "i8042_kbd",
+	.id	= UCLASS_KEYBOARD,
+	.of_match = i8042_kbd_ids,
+	.probe = i8042_kbd_probe,
+	.ops	= &i8042_kbd_ops,
+	.priv_auto_alloc_size = sizeof(struct i8042_kbd_priv),
+};
diff --git a/include/i8042.h b/include/i8042.h
index e0afce1..9723b6a 100644
--- a/include/i8042.h
+++ b/include/i8042.h
@@ -87,10 +87,4 @@ void i8042_flush(void);
  */
 int i8042_disable(void);
 
-struct stdio_dev;
-
-int i8042_kbd_init(void);
-int i8042_tstc(struct stdio_dev *dev);
-int i8042_getc(struct stdio_dev *dev);
-
 #endif /* _I8042_H_ */
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 10/12] i8042: Handle a duplicate power-on-reset response
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
                   ` (8 preceding siblings ...)
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 09/12] input: Convert i8042 to driver model Simon Glass
@ 2015-11-11 17:05 ` Simon Glass
  2015-11-14  2:04   ` Simon Glass
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 11/12] video: input: Clean up after i8042 conversion Simon Glass
                   ` (2 subsequent siblings)
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

Sometimes we seem to get 0xaa twice which causes the config read to fail.
This causes chromebook_link to fail to set up the keyboard.

Add a check for this and read the config again when detected.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

Changes in v3:
- Fix 'QUICK' typo

Changes in v2:
- Use device tree to handle this quirk

 drivers/input/i8042.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/input/i8042.c b/drivers/input/i8042.c
index e5e2926..661d7fd 100644
--- a/drivers/input/i8042.c
+++ b/drivers/input/i8042.c
@@ -15,13 +15,20 @@
 #include <keyboard.h>
 #include <asm/io.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /* defines */
 #define in8(p)		inb(p)
 #define out8(p, v)	outb(v, p)
 
+enum {
+	QUIRK_DUP_POR	= 1 << 0,
+};
+
 /* locals */
 struct i8042_kbd_priv {
 	bool extended;	/* true if an extended keycode is expected next */
+	int quirks;	/* quirks that we support */
 };
 
 static unsigned char ext_key_map[] = {
@@ -113,7 +120,7 @@ static int kbd_cmd_write(int cmd, int data)
 	return kbd_write(I8042_DATA_REG, data);
 }
 
-static int kbd_reset(void)
+static int kbd_reset(int quirk)
 {
 	int config;
 
@@ -132,6 +139,10 @@ static int kbd_reset(void)
 	if (config == -1)
 		goto err;
 
+	/* Sometimes get a second byte */
+	else if ((quirk & QUIRK_DUP_POR) && config == KBD_POR)
+		config = kbd_cmd_read(CMD_RD_CONFIG);
+
 	config |= CONFIG_AT_TRANS;
 	config &= ~(CONFIG_KIRQ_EN | CONFIG_MIRQ_EN);
 	if (kbd_cmd_write(CMD_WR_CONFIG, config))
@@ -246,6 +257,7 @@ static int i8042_kbd_check(struct input_config *input)
 static int i8042_start(struct udevice *dev)
 {
 	struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct i8042_kbd_priv *priv = dev_get_priv(dev);
 	struct input_config *input = &uc_priv->input;
 	int keymap, try;
 	char *penv;
@@ -264,7 +276,7 @@ static int i8042_start(struct udevice *dev)
 			keymap = KBD_GER;
 	}
 
-	for (try = 0; kbd_reset() != 0; try++) {
+	for (try = 0; kbd_reset(priv->quirks) != 0; try++) {
 		if (try >= KBD_RESET_TRIES)
 			return -1;
 	}
@@ -294,10 +306,15 @@ static int i8042_start(struct udevice *dev)
 static int i8042_kbd_probe(struct udevice *dev)
 {
 	struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
+	struct i8042_kbd_priv *priv = dev_get_priv(dev);
 	struct stdio_dev *sdev = &uc_priv->sdev;
 	struct input_config *input = &uc_priv->input;
 	int ret;
 
+	if (fdtdec_get_bool(gd->fdt_blob, dev->of_offset,
+			    "intel,duplicate-por"))
+		priv->quirks |= QUIRK_DUP_POR;
+
 	/* Register the device. i8042_start() will be called soon */
 	input->dev = dev;
 	input->read_keys = i8042_kbd_check;
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 11/12] video: input: Clean up after i8042 conversion
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
                   ` (9 preceding siblings ...)
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 10/12] i8042: Handle a duplicate power-on-reset response Simon Glass
@ 2015-11-11 17:05 ` Simon Glass
  2015-11-14  2:04   ` Simon Glass
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 12/12] input: Convert 'keyboard' driver to use input library Simon Glass
  2015-11-11 21:56 ` [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

Now that i8042 uses driver model, adjust other mentions of it and remove old
code that is no-longer used. Update the README and unify the keyboard text
into one place.

Signed-off-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
---

Changes in v3:
- Fix missing 'use' word

Changes in v2: None

 README                      | 29 ++++++++++++-----------------
 drivers/video/cfb_console.c | 20 ++++----------------
 2 files changed, 16 insertions(+), 33 deletions(-)

diff --git a/README b/README
index fd8b6b6..abd31d5 100644
--- a/README
+++ b/README
@@ -867,11 +867,11 @@ The following options need to be configured:
 						(0-5, cf. cfb_console.c)
 			VIDEO_FB_ADRS		framebuffer address
 			VIDEO_KBD_INIT_FCT	keyboard int fct
-						(i.e. i8042_kbd_init())
+						(i.e. rx51_kp_init())
 			VIDEO_TSTC_FCT		test char fct
-						(i.e. i8042_tstc)
+						(i.e. rx51_kp_tstc)
 			VIDEO_GETC_FCT		get char fct
-						(i.e. i8042_getc)
+						(i.e. rx51_kp_getc)
 			CONFIG_VIDEO_LOGO	display Linux logo in
 						upper left corner
 			CONFIG_VIDEO_BMP_LOGO	use bmp_logo.h instead of
@@ -1767,11 +1767,15 @@ CBFS (Coreboot Filesystem) support
 		a default value of 65536 will be defined.
 
 - Keyboard Support:
-		CONFIG_I8042_KBD
-		Standard PC keyboard driver with US (is default) and
-		GERMAN key layout (switch via environment 'keymap=de') support.
-		Export function i8042_kbd_init, i8042_tstc and i8042_getc
-		for cfb_console. Supports cursor blinking.
+		See Kconfig help for available keyboard drivers.
+
+		CONFIG_KEYBOARD
+
+		Define this to enable a custom keyboard support.
+		This simply calls drv_keyboard_init() which must be
+		defined in your board-specific files. This option is deprecated
+		and is only used by novena. For new boards, use driver model
+		instead.
 
 - Video support:
 		CONFIG_VIDEO
@@ -1832,15 +1836,6 @@ CBFS (Coreboot Filesystem) support
 		boot.  See the documentation file README.video for a
 		description of this variable.
 
-
-- Keyboard Support:
-		CONFIG_KEYBOARD
-
-		Define this to enable a custom keyboard support.
-		This simply calls drv_keyboard_init() which must be
-		defined in your board-specific files.
-		The only board using this so far is RBC823.
-
 - LCD Support:	CONFIG_LCD
 
 		Define this to enable LCD support (for output to LCD
diff --git a/drivers/video/cfb_console.c b/drivers/video/cfb_console.c
index f191392..f15c964 100644
--- a/drivers/video/cfb_console.c
+++ b/drivers/video/cfb_console.c
@@ -15,8 +15,10 @@
  * logo can be placed in the upper left corner and additional board
  * information strings (that normally goes to serial port) can be drawn.
  *
- * The console driver can use the standard PC keyboard interface (i8042)
- * for character input. Character output goes to a memory mapped video
+ * The console driver can use a keyboard interface for character input
+ * but this is deprecated. Only rk51 uses it.
+ *
+ * Character output goes to a memory-mapped video
  * framebuffer with little or big-endian organisation.
  * With environment setting 'console=serial' the console i/o can be
  * forced to serial port.
@@ -38,7 +40,6 @@
  * VIDEO_DATA_FORMAT	      - graphical data format GDF
  * VIDEO_FB_ADRS	      - start of video memory
  *
- * CONFIG_I8042_KBD	      - AT Keyboard driver for i8042
  * VIDEO_KBD_INIT_FCT	      - init function for keyboard
  * VIDEO_TSTC_FCT	      - keyboard_tstc function
  * VIDEO_GETC_FCT	      - keyboard_getc function
@@ -158,19 +159,6 @@
 #define VIDEO_FB_ADRS		(pGD->frameAdrs)
 
 /*
- * Console device defines with i8042 keyboard controller
- * Any other keyboard controller must change this section
- */
-
-#ifdef	CONFIG_I8042_KBD
-#include <i8042.h>
-
-#define VIDEO_KBD_INIT_FCT	i8042_kbd_init()
-#define VIDEO_TSTC_FCT		i8042_tstc
-#define VIDEO_GETC_FCT		i8042_getc
-#endif
-
-/*
  * Console device
  */
 
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 12/12] input: Convert 'keyboard' driver to use input library
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
                   ` (10 preceding siblings ...)
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 11/12] video: input: Clean up after i8042 conversion Simon Glass
@ 2015-11-11 17:05 ` Simon Glass
  2015-11-14  2:04   ` Simon Glass
  2015-11-11 21:56 ` [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 17:05 UTC (permalink / raw)
  To: u-boot

This has duplicated scan code tables and logic. We can use the input
library to implement most of the features here.

This needs testing. The only supported board appears to be TQM5200.
Unfortunately no maintainer is listed for this board.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v3:
- Drop patches already applied

Changes in v2: None

 drivers/input/keyboard.c | 290 +++++++----------------------------------------
 include/keyboard.h       |   5 +
 2 files changed, 43 insertions(+), 252 deletions(-)

diff --git a/drivers/input/keyboard.c b/drivers/input/keyboard.c
index eec8c27..b31efbf 100644
--- a/drivers/input/keyboard.c
+++ b/drivers/input/keyboard.c
@@ -10,290 +10,76 @@
 
 #include <common.h>
 #include <console.h>
-
-#include <stdio_dev.h>
+#include <input.h>
 #include <keyboard.h>
+#include <stdio_dev.h>
 
-#undef KBG_DEBUG
-
-#ifdef KBG_DEBUG
-#define	PRINTF(fmt,args...)	printf (fmt ,##args)
-#else
-#define PRINTF(fmt,args...)
-#endif
-
-
-#define	DEVNAME			"kbd"
-
-#define	LED_SCR			0x01	/* scroll lock led */
-#define	LED_CAP			0x04	/* caps lock led */
-#define	LED_NUM			0x02	/* num lock led */
-
-#define	KBD_BUFFER_LEN		0x20  /* size of the keyboardbuffer */
+static struct input_config config;
 
-#if defined(CONFIG_MPC5xxx) || defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || defined(CONFIG_MPC8555)
-int ps2ser_check(void);
+static int kbd_read_keys(struct input_config *config)
+{
+#if defined(CONFIG_MPC5xxx) || defined(CONFIG_MPC8540) || \
+		defined(CONFIG_MPC8541) || defined(CONFIG_MPC8555)
+	/* no ISR is used, so received chars must be polled */
+	ps2ser_check();
 #endif
 
-static volatile char kbd_buffer[KBD_BUFFER_LEN];
-static volatile int in_pointer = 0;
-static volatile int out_pointer = 0;
+	return 1;
+}
 
-static unsigned char leds = 0;
-static unsigned char num_lock = 0;
-static unsigned char caps_lock = 0;
-static unsigned char scroll_lock = 0;
-static unsigned char shift = 0;
-static unsigned char ctrl = 0;
-static unsigned char alt = 0;
-static unsigned char e0 = 0;
+static int check_leds(int ret)
+{
+	int leds;
 
-/******************************************************************
- * Queue handling
- ******************************************************************/
+	leds = input_leds_changed(&config);
+	if (leds >= 0)
+		pckbd_leds(leds);
 
-/* puts character in the queue and sets up the in and out pointer */
-static void kbd_put_queue(char data)
-{
-	if((in_pointer+1)==KBD_BUFFER_LEN) {
-		if(out_pointer==0) {
-			return; /* buffer full */
-		} else{
-			in_pointer=0;
-		}
-	} else {
-		if((in_pointer+1)==out_pointer)
-			return; /* buffer full */
-		in_pointer++;
-	}
-	kbd_buffer[in_pointer]=data;
-	return;
+	return ret;
 }
 
 /* test if a character is in the queue */
 static int kbd_testc(struct stdio_dev *dev)
 {
-#if defined(CONFIG_MPC5xxx) || defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || defined(CONFIG_MPC8555)
-	/* no ISR is used, so received chars must be polled */
-	ps2ser_check();
-#endif
-	if(in_pointer==out_pointer)
-		return(0); /* no data */
-	else
-		return(1);
+	return check_leds(input_tstc(&config));
 }
 
 /* gets the character from the queue */
 static int kbd_getc(struct stdio_dev *dev)
 {
-	char c;
-	while(in_pointer==out_pointer) {
-#if defined(CONFIG_MPC5xxx) || defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || defined(CONFIG_MPC8555)
-	/* no ISR is used, so received chars must be polled */
-	ps2ser_check();
-#endif
-	;}
-	if((out_pointer+1)==KBD_BUFFER_LEN)
-		out_pointer=0;
-	else
-		out_pointer++;
-	c=kbd_buffer[out_pointer];
-	return (int)c;
-
+	return check_leds(input_getc(&config));
 }
 
-/* Simple translation table for the keys */
-
-static unsigned char kbd_plain_xlate[] = {
-	0xff,0x1b, '1', '2', '3', '4', '5', '6', '7', '8', '9', '0', '-', '=','\b','\t',	/* 0x00 - 0x0f */
-	 'q', 'w', 'e', 'r', 't', 'y', 'u', 'i', 'o', 'p', '[', ']','\r',0xff, 'a', 's',	/* 0x10 - 0x1f */
-	 'd', 'f', 'g', 'h', 'j', 'k', 'l', ';','\'', '`',0xff,'\\', 'z', 'x', 'c', 'v',	/* 0x20 - 0x2f */
-	 'b', 'n', 'm', ',', '.', '/',0xff,0xff,0xff, ' ',0xff,0xff,0xff,0xff,0xff,0xff,	/* 0x30 - 0x3f */
-	0xff,0xff,0xff,0xff,0xff,0xff,0xff, '7', '8', '9', '-', '4', '5', '6', '+', '1',	/* 0x40 - 0x4f */
-	 '2', '3', '0', '.',0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,  /* 0x50 - 0x5F */
-	'\r',0xff,0xff
-	};
-
-static unsigned char kbd_shift_xlate[] = {
-	0xff,0x1b, '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', '_', '+','\b','\t',	/* 0x00 - 0x0f */
-	 'Q', 'W', 'E', 'R', 'T', 'Y', 'U', 'I', 'O', 'P', '{', '}','\r',0xff, 'A', 'S',	/* 0x10 - 0x1f */
-	 'D', 'F', 'G', 'H', 'J', 'K', 'L', ':', '"', '~',0xff, '|', 'Z', 'X', 'C', 'V',	/* 0x20 - 0x2f */
-	 'B', 'N', 'M', '<', '>', '?',0xff,0xff,0xff, ' ',0xff,0xff,0xff,0xff,0xff,0xff,	/* 0x30 - 0x3f */
-	0xff,0xff,0xff,0xff,0xff,0xff,0xff, '7', '8', '9', '-', '4', '5', '6', '+', '1',	/* 0x40 - 0x4f */
-	 '2', '3', '0', '.',0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,  /* 0x50 - 0x5F */
-	'\r',0xff,0xff
-	};
-
-static unsigned char kbd_ctrl_xlate[] = {
-	0xff,0x1b, '1',0x00, '3', '4', '5',0x1E, '7', '8', '9', '0',0x1F, '=','\b','\t',	/* 0x00 - 0x0f */
-	0x11,0x17,0x05,0x12,0x14,0x18,0x15,0x09,0x0f,0x10,0x1b,0x1d,'\n',0xff,0x01,0x13,	/* 0x10 - 0x1f */
-	0x04,0x06,0x08,0x09,0x0a,0x0b,0x0c, ';','\'', '~',0x00,0x1c,0x1a,0x18,0x03,0x16,	/* 0x20 - 0x2f */
-	0x02,0x0e,0x0d, '<', '>', '?',0xff,0xff,0xff,0x00,0xff,0xff,0xff,0xff,0xff,0xff,	/* 0x30 - 0x3f */
-	0xff,0xff,0xff,0xff,0xff,0xff,0xff, '7', '8', '9', '-', '4', '5', '6', '+', '1',	/* 0x40 - 0x4f */
-	 '2', '3', '0', '.',0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,0xff,  /* 0x50 - 0x5F */
-	'\r',0xff,0xff
-	};
-
-
-void handle_scancode(unsigned char scancode)
+void handle_scancode(unsigned char scan_code)
 {
-	unsigned char keycode;
+	bool release = false;
 
-	/*  Convert scancode to keycode */
-	PRINTF("scancode %x\n",scancode);
-	if(scancode==0xe0) {
-		e0=1; /* special charakters */
-		return;
-	}
-	if(e0==1) {
-		e0=0; /* delete flag */
-		if(!(	((scancode&0x7F)==0x38)|| /* the right ctrl key */
-					((scancode&0x7F)==0x1D)|| /* the right alt key */
-					((scancode&0x7F)==0x35)||	/* the right '/' key */
-					((scancode&0x7F)==0x1C) ))  /* the right enter key */
-			/* we swallow unknown e0 codes */
-			return;
-	}
-	/* special cntrl keys */
-	switch(scancode) {
-	case 0x2A:
-	case 0x36: /* shift pressed */
-		shift=1;
-		return; /* do nothing else */
-	case 0xAA:
-	case 0xB6: /* shift released */
-		shift=0;
-		return; /* do nothing else */
-	case 0x38: /* alt pressed */
-		alt=1;
-		return; /* do nothing else */
-	case 0xB8: /* alt released */
-		alt=0;
-		return; /* do nothing else */
-	case 0x1d: /* ctrl pressed */
-		ctrl=1;
-		return; /* do nothing else */
-	case 0x9d: /* ctrl released */
-		ctrl=0;
-		return; /* do nothing else */
-	case 0x46: /* scrollock pressed */
-		scroll_lock=~scroll_lock;
-		if(scroll_lock==0)
-			leds&=~LED_SCR; /* switch LED off */
-		else
-			leds|=LED_SCR; /* switch on LED */
-		pckbd_leds(leds);
-		return; /* do nothing else */
-	case 0x3A: /* capslock pressed */
-		caps_lock=~caps_lock;
-		if(caps_lock==0)
-			leds&=~LED_CAP; /* switch caps_lock off */
-		else
-			leds|=LED_CAP; /* switch on LED */
-		pckbd_leds(leds);
-		return;
-	case 0x45: /* numlock pressed */
-		num_lock=~num_lock;
-		if(num_lock==0)
-			leds&=~LED_NUM; /* switch LED off */
-		else
-			leds|=LED_NUM;  /* switch on LED */
-		pckbd_leds(leds);
-		return;
-	case 0xC6: /* scroll lock released */
-	case 0xC5: /* num lock released */
-	case 0xBA: /* caps lock released */
-		return; /* just swallow */
-	}
-#if 1
-	if((scancode&0x80)==0x80) /* key released */
-		return;
-#else
-	if((scancode&0x80)==0x00) /* key pressed */
-		return;
-	scancode &= ~0x80;
-#endif
-	/* now, decide which table we need */
-	if(scancode > (sizeof(kbd_plain_xlate)/sizeof(kbd_plain_xlate[0]))) { /* scancode not in list */
-		PRINTF("unkown scancode %X\n",scancode);
-		return; /* swallow it */
-	}
-	/* setup plain code first */
-	keycode=kbd_plain_xlate[scancode];
-	if(caps_lock==1) { /* caps_lock is pressed, overwrite plain code */
-		if(scancode > (sizeof(kbd_shift_xlate)/sizeof(kbd_shift_xlate[0]))) { /* scancode not in list */
-			PRINTF("unkown caps-locked scancode %X\n",scancode);
-			return; /* swallow it */
-		}
-		keycode=kbd_shift_xlate[scancode];
-		if(keycode<'A') { /* we only want the alphas capital */
-			keycode=kbd_plain_xlate[scancode];
-		}
-	}
-	if(shift==1) { /* shift overwrites caps_lock */
-		if(scancode > (sizeof(kbd_shift_xlate)/sizeof(kbd_shift_xlate[0]))) { /* scancode not in list */
-			PRINTF("unkown shifted scancode %X\n",scancode);
-			return; /* swallow it */
-		}
-		keycode=kbd_shift_xlate[scancode];
-	}
-	if(ctrl==1) { /* ctrl overwrites caps_lock and shift */
-		if(scancode > (sizeof(kbd_ctrl_xlate)/sizeof(kbd_ctrl_xlate[0]))) { /* scancode not in list */
-			PRINTF("unkown ctrl scancode %X\n",scancode);
-			return; /* swallow it */
-		}
-		keycode=kbd_ctrl_xlate[scancode];
-	}
-	/* check if valid keycode */
-	if(keycode==0xff) {
-		PRINTF("unkown scancode %X\n",scancode);
-		return; /* swallow unknown codes */
+	/* Compare with i8042_kbd_check() in i8042.c if some logic is missing */
+	if (scan_code & 0x80) {
+		scan_code &= 0x7f;
+		release = true;
 	}
 
-	kbd_put_queue(keycode);
-	PRINTF("%x\n",keycode);
+	input_add_keycode(&config, scan_code, release);
 }
 
-/******************************************************************
- * Init
- ******************************************************************/
-
-#ifdef CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE
-extern int overwrite_console (void);
-#define OVERWRITE_CONSOLE overwrite_console ()
-#else
-#define OVERWRITE_CONSOLE 0
-#endif /* CONFIG_SYS_CONSOLE_OVERWRITE_ROUTINE */
-
+/* TODO: convert to driver model */
 int kbd_init (void)
 {
-	int error;
-	struct stdio_dev kbddev ;
-	char *stdinname  = getenv ("stdin");
+	struct stdio_dev kbddev;
+	struct input_config *input = &config;
 
 	if(kbd_init_hw()==-1)
 		return -1;
 	memset (&kbddev, 0, sizeof(kbddev));
-	strcpy(kbddev.name, DEVNAME);
+	strcpy(kbddev.name, "kbd");
 	kbddev.flags =  DEV_FLAGS_INPUT;
-	kbddev.getc = kbd_getc ;
-	kbddev.tstc = kbd_testc ;
+	kbddev.getc = kbd_getc;
+	kbddev.tstc = kbd_testc;
 
-	error = stdio_register (&kbddev);
-	if(error==0) {
-		/* check if this is the standard input device */
-		if(strcmp(stdinname,DEVNAME)==0) {
-			/* reassign the console */
-			if(OVERWRITE_CONSOLE) {
-				return 1;
-			}
-			error=console_assign(stdin,DEVNAME);
-			if(error==0)
-				return 1;
-			else
-				return error;
-		}
-		return 1;
-	}
-	return error;
+	input_init(input, 0);
+	input->read_keys = kbd_read_keys;
+	input_add_tables(input, true);
+
+	return input_stdio_register(&kbddev);
 }
diff --git a/include/keyboard.h b/include/keyboard.h
index 5216d59..6725e48 100644
--- a/include/keyboard.h
+++ b/include/keyboard.h
@@ -98,4 +98,9 @@ extern int kbd_init_hw(void);
 extern void pckbd_leds(unsigned char leds);
 #endif /* !CONFIG_DM_KEYBOARD */
 
+#if defined(CONFIG_MPC5xxx) || defined(CONFIG_MPC8540) || \
+		defined(CONFIG_MPC8541) || defined(CONFIG_MPC8555)
+int ps2ser_check(void);
+#endif
+
 #endif /* __KEYBOARD_H */
-- 
2.6.0.rc2.230.g3dd15c0

^ permalink raw reply related	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model
  2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
                   ` (11 preceding siblings ...)
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 12/12] input: Convert 'keyboard' driver to use input library Simon Glass
@ 2015-11-11 21:56 ` Simon Glass
  2015-11-12  3:56   ` Bin Meng
  12 siblings, 1 reply; 35+ messages in thread
From: Simon Glass @ 2015-11-11 21:56 UTC (permalink / raw)
  To: u-boot

Hi Bin,

On 11 November 2015 at 10:05, Simon Glass <sjg@chromium.org> wrote:
> This series adds a new uclass for keyboards and converts some drivers
> over to use it.
>
> This series includes some work to remove code duplication in the keyboard
> drivers by updating them to use the input library (input.c). This unifies
> the keycode decoding logic in one place. In order to do this some
> enhancements are needed to the input library and these are also included.
>
> The cros_ec and tegra_kbc drivers are converted to use driver model.
>
> The i8042 driver is converted also, after various tidy-ups. The driver has
> some strange interactions with the cfb_console driver. This is removed in
> this series which is possible because the only user is x86. Some i8042
> features have been dropped (the only deliberate one is the flashing cursor
> which does not seem to be used by any board).
>
> Also the i8042 driver currently has its own keycode-decoding logic. This
> series removes it in favour of the input library. Therefore testing of this
> new driver would be appreciated. So far I have only been able to test on
> link, which does not have a full keyboard. Also, while German keyboard
> support is implemented, I am unable to test that either.
>
> These changes can be considered the first step towards moving stdio to
> driver model. For that to be useful we need to convert LCD and video also.
>
> Note: This series is missing the code to call the update_leds() method when
> the LEDs change. This needs to be added to keyboard_tstc() and
> keyboard_getc(). If someone is able to test this I can send a patch for that
> also.
>
> This series is available at u-boot-dm branch input-working.

Can you please try testing this for your crash when pressing 'caps
lock'? I'm not sure what is going on there and I don't have hardware
to test with.

>
> Changes in v3:
> - Refactor the German keyboard code to use data rather than code
> - Drop unrelated cros_keyb change
> - Fix 'QUICK' typo
> - Fix missing 'use' word
> - Drop patches already applied
>
> Changes in v2:
> - Update input_add_tables() to add error checking
> - Convert two multi-line comments to single-line comments
> - Correct call to input_init()
> - Drop CONFIG_VGA_AS_SINGLE_DEVICE from all x86 board config files
> - Use device tree to handle this quirk
>
> Simon Glass (12):
>   input: Support the German keymap
>   input: Adjust structure of code in process_modifier()
>   input: Handle caps lock
>   input: Allow updating of keyboard LEDs
>   input: i8042: Convert to use the input library
>   input: Add a Kconfig option for the i8042 keyboard
>   x86: Add an i8042 device for boards that have it
>   Drop CONFIG_ISA_KEYBOARD
>   input: Convert i8042 to driver model
>   i8042: Handle a duplicate power-on-reset response
>   video: input: Clean up after i8042 conversion
>   input: Convert 'keyboard' driver to use input library
>
>  README                                   |  30 +-
>  arch/x86/Kconfig                         |   6 +
>  arch/x86/dts/bayleybay.dts               |   1 +
>  arch/x86/dts/chromebook_link.dts         |   5 +
>  arch/x86/dts/keyboard.dtsi               |   5 +
>  board/kosagi/novena/novena.c             |   2 +-
>  board/mpl/pip405/README                  |   4 -
>  doc/device-tree-bindings/input/i8042.txt |  10 +
>  drivers/input/Kconfig                    |  10 +
>  drivers/input/Makefile                   |   2 +-
>  drivers/input/cros_ec_keyb.c             |   2 +-
>  drivers/input/i8042.c                    | 563 ++++++++-----------------------
>  drivers/input/input.c                    | 158 +++++++--
>  drivers/input/keyboard.c                 | 290 +++-------------
>  drivers/input/tegra-kbc.c                |   2 +-
>  drivers/video/cfb_console.c              |  20 +-
>  include/configs/MIP405.h                 |   5 -
>  include/configs/PIP405.h                 |   5 -
>  include/configs/bayleybay.h              |   3 -
>  include/configs/chromebox_panther.h      |   2 -
>  include/configs/minnowmax.h              |   1 -
>  include/configs/x86-chromebook.h         |   2 +-
>  include/configs/x86-common.h             |   2 +-
>  include/i8042.h                          |   6 -
>  include/input.h                          |  17 +-
>  include/keyboard.h                       |   5 +
>  26 files changed, 376 insertions(+), 782 deletions(-)
>  create mode 100644 arch/x86/dts/keyboard.dtsi
>  create mode 100644 doc/device-tree-bindings/input/i8042.txt
>
> --
> 2.6.0.rc2.230.g3dd15c0
>

Regards,
Simon

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 01/12] input: Support the German keymap
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 01/12] input: Support the German keymap Simon Glass
@ 2015-11-12  3:51   ` Bin Meng
  2015-11-14  2:04     ` Simon Glass
  0 siblings, 1 reply; 35+ messages in thread
From: Bin Meng @ 2015-11-12  3:51 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Thu, Nov 12, 2015 at 1:05 AM, Simon Glass <sjg@chromium.org> wrote:
> Add support for the German keymap, taken from i8042.c. This can be selected
> when the input library it initialised.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

Please check one nits below.

> Changes in v3:
> - Refactor the German keyboard code to use data rather than code
>
> Changes in v2:
> - Update input_add_tables() to add error checking
>
>  board/kosagi/novena/novena.c |   2 +-
>  drivers/input/cros_ec_keyb.c |   2 +-
>  drivers/input/input.c        | 109 ++++++++++++++++++++++++++++++++++++++-----
>  drivers/input/tegra-kbc.c    |   2 +-
>  include/input.h              |   3 +-
>  5 files changed, 102 insertions(+), 16 deletions(-)
>
> diff --git a/board/kosagi/novena/novena.c b/board/kosagi/novena/novena.c
> index 4a9f724..babba85 100644
> --- a/board/kosagi/novena/novena.c
> +++ b/board/kosagi/novena/novena.c
> @@ -88,7 +88,7 @@ int drv_keyboard_init(void)
>                 debug("%s: Cannot set up input\n", __func__);
>                 return -1;
>         }
> -       input_add_tables(&button_input);
> +       input_add_tables(&button_input, false);
>         button_input.read_keys = novena_gpio_button_read_keys;
>
>         error = input_stdio_register(&dev);
> diff --git a/drivers/input/cros_ec_keyb.c b/drivers/input/cros_ec_keyb.c
> index fe5caea..9bc4555 100644
> --- a/drivers/input/cros_ec_keyb.c
> +++ b/drivers/input/cros_ec_keyb.c
> @@ -211,7 +211,7 @@ static int cros_ec_kbd_probe(struct udevice *dev)
>
>         priv->input = input;
>         input->dev = dev;
> -       input_add_tables(input);
> +       input_add_tables(input, false);
>         input->read_keys = cros_ec_kbc_check;
>         strcpy(sdev->name, "cros-ec-keyb");
>
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index 9e552f3..96fc195 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -79,6 +79,88 @@ static unsigned char kbd_ctrl_xlate[] = {
>         '\r', 0xff, '/',  '*',
>  };
>
> +static const uchar kbd_plain_xlate_german[] = {
> +       0xff, 0x1b,  '1',  '2',  '3',  '4',  '5',  '6', /* scan 00-07 */
> +        '7',  '8',  '9',  '0', 0xe1, '\'', 0x08, '\t', /* scan 08-0F */
> +        'q',  'w',  'e',  'r',  't',  'z',  'u',  'i', /* scan 10-17 */
> +        'o',  'p', 0x81,  '+', '\r', 0xff,  'a',  's', /* scan 18-1F */
> +        'd',  'f',  'g',  'h',  'j',  'k',  'l', 0x94, /* scan 20-27 */
> +       0x84,  '^', 0xff,  '#',  'y',  'x',  'c',  'v', /* scan 28-2F */
> +        'b',  'n',  'm',  ',',  '.',  '-', 0xff,  '*', /* scan 30-37 */
> +        ' ',  ' ', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,  '7', /* scan 40-47 */
> +        '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1', /* scan 48-4F */
> +        '2',  '3',  '0',  ',', 0xff, 0xff,  '<', 0xff, /* scan 50-57 */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
> +       '\r', 0xff,  '/',  '*',
> +};
> +
> +static unsigned char kbd_shift_xlate_german[] = {
> +          0xff, 0x1b,  '!',  '"', 0x15,  '$',  '%',  '&', /* scan 00-07 */
> +        '/',  '(',  ')',  '=',  '?',  '`', 0x08, '\t', /* scan 08-0F */
> +        'Q',  'W',  'E',  'R',  'T',  'Z',  'U',  'I', /* scan 10-17 */
> +        'O',  'P', 0x9a,  '*', '\r', 0xff,  'A',  'S', /* scan 18-1F */
> +        'D',  'F',  'G',  'H',  'J',  'K',  'L', 0x99, /* scan 20-27 */
> +       0x8e, 0xf8, 0xff, '\'',  'Y',  'X',  'C',  'V', /* scan 28-2F */
> +        'B',  'N',  'M',  ';',  ':',  '_', 0xff,  '*', /* scan 30-37 */
> +        ' ',  ' ', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,  '7', /* scan 40-47 */
> +        '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1', /* scan 48-4F */
> +        '2',  '3',  '0',  ',', 0xff, 0xff,  '>', 0xff, /* scan 50-57 */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
> +       '\r', 0xff,  '/',  '*',
> +};
> +
> +static unsigned char kbd_right_alt_xlate_german[] = {
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */
> +        '{',  '[',  ']',  '}', '\\', 0xff, 0xff, 0xff, /* scan 08-0F */
> +        '@', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10-17 */
> +       0xff, 0xff, 0xff,  '~', 0xff, 0xff, 0xff, 0xff, /* scan 18-1F */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20-27 */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28-2F */
> +       0xff, 0xff, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30-37 */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40-47 */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
> +       0xff, 0xff, 0xff, 0xff, 0xff, 0xff,  '|', 0xff, /* scan 50-57 */
> +};
> +
> +enum kbd_mask {
> +       KBD_ENGLISH     = 1 << 0,
> +       KBD_GERMAN      = 1 << 1,
> +};
> +
> +static struct kbd_entry {
> +       int kbd_mask;           /* Which languages this is for */
> +       int left_keycode;       /* Left keycode to select this map */
> +       int right_keycode;      /* Right keycode to select this map */
> +       const uchar *xlate;     /* Ascii code for each keycode */
> +       int num_entries;        /* Number of entries in xlate */
> +} kbd_entry[] = {
> +       { KBD_ENGLISH, -1, -1,
> +               kbd_plain_xlate, ARRAY_SIZE(kbd_plain_xlate) },
> +       { KBD_GERMAN, -1, -1,
> +               kbd_plain_xlate_german, ARRAY_SIZE(kbd_plain_xlate_german) },
> +       { KBD_ENGLISH, KEY_LEFTSHIFT, KEY_RIGHTSHIFT,
> +               kbd_shift_xlate, ARRAY_SIZE(kbd_shift_xlate) },
> +       { KBD_GERMAN, KEY_LEFTSHIFT, KEY_RIGHTSHIFT,
> +               kbd_shift_xlate_german, ARRAY_SIZE(kbd_shift_xlate_german) },
> +       { KBD_ENGLISH | KBD_GERMAN, KEY_LEFTCTRL, KEY_RIGHTCTRL,
> +               kbd_ctrl_xlate, ARRAY_SIZE(kbd_ctrl_xlate) },
> +       { KBD_GERMAN, -1, KEY_RIGHTALT,
> +               kbd_right_alt_xlate_german,
> +               ARRAY_SIZE(kbd_right_alt_xlate_german) },
> +       {},
> +};
> +
>  /*
>   * Scan key code to ANSI 3.64 escape sequence table.  This table is
>   * incomplete in that it does not include all possible extra keys.
> @@ -501,21 +583,24 @@ void input_allow_repeats(struct input_config *config, bool allow_repeats)
>         config->allow_repeats = allow_repeats;
>  }
>
> -int input_add_tables(struct input_config *config)
> +int input_add_tables(struct input_config *config, bool german)
>  {
> +       struct kbd_entry *entry;
> +       int mask;
>         int ret;
>
> -       ret = input_add_table(config, -1, -1,
> -                             kbd_plain_xlate, ARRAY_SIZE(kbd_plain_xlate));
> -       if (ret)
> -               return ret;
> -       ret = input_add_table(config, KEY_LEFTSHIFT, KEY_RIGHTSHIFT,
> -                             kbd_shift_xlate, ARRAY_SIZE(kbd_shift_xlate));
> -       if (ret)
> -               return ret;
> -
> -       return input_add_table(config, KEY_LEFTCTRL, KEY_RIGHTCTRL,
> -                              kbd_ctrl_xlate, ARRAY_SIZE(kbd_ctrl_xlate));
> +       mask = german ? KBD_GERMAN : KBD_ENGLISH;
> +       for (entry = kbd_entry; entry->kbd_mask; entry++) {
> +               if (!(mask & entry->kbd_mask))
> +                       continue;
> +               ret = input_add_table(config, entry->left_keycode,
> +                                     entry->right_keycode, entry->xlate,
> +                       entry->num_entries);

Nits: looks the indention of the above line is wrong.

> +               if (ret)
> +                       return ret;
> +       }
> +
> +       return 0;
>  }
>
>  int input_init(struct input_config *config, int leds)
> diff --git a/drivers/input/tegra-kbc.c b/drivers/input/tegra-kbc.c
> index a7137f1..951cbb4 100644
> --- a/drivers/input/tegra-kbc.c
> +++ b/drivers/input/tegra-kbc.c
> @@ -326,7 +326,7 @@ static int tegra_kbd_probe(struct udevice *dev)
>         priv->input = input;
>         input->dev = dev;
>         input->read_keys = tegra_kbc_check;
> -       input_add_tables(input);
> +       input_add_tables(input, false);
>         strcpy(sdev->name, "tegra-kbc");
>         ret = input_stdio_register(sdev);
>         if (ret) {
> diff --git a/include/input.h b/include/input.h
> index e56f500..c1af259 100644
> --- a/include/input.h
> +++ b/include/input.h
> @@ -167,9 +167,10 @@ void input_allow_repeats(struct input_config *config, bool allow_repeats);
>   * This must be called after input_init() or keycode decoding will not work.
>   *
>   * @param config       Input state
> + * @param german       true to use German keyboard layout, false for US
>   * @return 0 if ok, -1 on error
>   */
> -int input_add_tables(struct input_config *config);
> +int input_add_tables(struct input_config *config, bool german);
>
>  /**
>   * Set up the input handler with basic key maps.
> --

Regards,
Bin

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model
  2015-11-11 21:56 ` [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
@ 2015-11-12  3:56   ` Bin Meng
  2015-11-12 13:33     ` Bin Meng
  0 siblings, 1 reply; 35+ messages in thread
From: Bin Meng @ 2015-11-12  3:56 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Thu, Nov 12, 2015 at 5:56 AM, Simon Glass <sjg@chromium.org> wrote:
> Hi Bin,
>
> On 11 November 2015 at 10:05, Simon Glass <sjg@chromium.org> wrote:
>> This series adds a new uclass for keyboards and converts some drivers
>> over to use it.
>>
>> This series includes some work to remove code duplication in the keyboard
>> drivers by updating them to use the input library (input.c). This unifies
>> the keycode decoding logic in one place. In order to do this some
>> enhancements are needed to the input library and these are also included.
>>
>> The cros_ec and tegra_kbc drivers are converted to use driver model.
>>
>> The i8042 driver is converted also, after various tidy-ups. The driver has
>> some strange interactions with the cfb_console driver. This is removed in
>> this series which is possible because the only user is x86. Some i8042
>> features have been dropped (the only deliberate one is the flashing cursor
>> which does not seem to be used by any board).
>>
>> Also the i8042 driver currently has its own keycode-decoding logic. This
>> series removes it in favour of the input library. Therefore testing of this
>> new driver would be appreciated. So far I have only been able to test on
>> link, which does not have a full keyboard. Also, while German keyboard
>> support is implemented, I am unable to test that either.
>>
>> These changes can be considered the first step towards moving stdio to
>> driver model. For that to be useful we need to convert LCD and video also.
>>
>> Note: This series is missing the code to call the update_leds() method when
>> the LEDs change. This needs to be added to keyboard_tstc() and
>> keyboard_getc(). If someone is able to test this I can send a patch for that
>> also.
>>
>> This series is available at u-boot-dm branch input-working.
>
> Can you please try testing this for your crash when pressing 'caps
> lock'? I'm not sure what is going on there and I don't have hardware
> to test with.

I've tested the v3 patch. Looks the behavior is the same as v2. Note
the crash when pressing 'caps lock' only happens in v1. Starting from
v2, pressing 'caps lock' does not light the LED, and the characters
typed is still lower case. This is the same as the 'num lock' as I
reported before.

[snip]

Regards,
Bin

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model
  2015-11-12  3:56   ` Bin Meng
@ 2015-11-12 13:33     ` Bin Meng
  2015-11-12 19:57       ` Simon Glass
  0 siblings, 1 reply; 35+ messages in thread
From: Bin Meng @ 2015-11-12 13:33 UTC (permalink / raw)
  To: u-boot

Hi Simon,

On Thu, Nov 12, 2015 at 11:56 AM, Bin Meng <bmeng.cn@gmail.com> wrote:
> Hi Simon,
>
> On Thu, Nov 12, 2015 at 5:56 AM, Simon Glass <sjg@chromium.org> wrote:
>> Hi Bin,
>>
>> On 11 November 2015 at 10:05, Simon Glass <sjg@chromium.org> wrote:
>>> This series adds a new uclass for keyboards and converts some drivers
>>> over to use it.
>>>
>>> This series includes some work to remove code duplication in the keyboard
>>> drivers by updating them to use the input library (input.c). This unifies
>>> the keycode decoding logic in one place. In order to do this some
>>> enhancements are needed to the input library and these are also included.
>>>
>>> The cros_ec and tegra_kbc drivers are converted to use driver model.
>>>
>>> The i8042 driver is converted also, after various tidy-ups. The driver has
>>> some strange interactions with the cfb_console driver. This is removed in
>>> this series which is possible because the only user is x86. Some i8042
>>> features have been dropped (the only deliberate one is the flashing cursor
>>> which does not seem to be used by any board).
>>>
>>> Also the i8042 driver currently has its own keycode-decoding logic. This
>>> series removes it in favour of the input library. Therefore testing of this
>>> new driver would be appreciated. So far I have only been able to test on
>>> link, which does not have a full keyboard. Also, while German keyboard
>>> support is implemented, I am unable to test that either.
>>>
>>> These changes can be considered the first step towards moving stdio to
>>> driver model. For that to be useful we need to convert LCD and video also.
>>>
>>> Note: This series is missing the code to call the update_leds() method when
>>> the LEDs change. This needs to be added to keyboard_tstc() and
>>> keyboard_getc(). If someone is able to test this I can send a patch for that
>>> also.
>>>
>>> This series is available at u-boot-dm branch input-working.
>>
>> Can you please try testing this for your crash when pressing 'caps
>> lock'? I'm not sure what is going on there and I don't have hardware
>> to test with.
>
> I've tested the v3 patch. Looks the behavior is the same as v2. Note
> the crash when pressing 'caps lock' only happens in v1. Starting from
> v2, pressing 'caps lock' does not light the LED, and the characters
> typed is still lower case. This is the same as the 'num lock' as I
> reported before.
>

I've spent some time to debug this today, and have fixed all of these
issues I reported so far. Please check my patch series @
http://patchwork.ozlabs.org/patch/543339/

Regards,
Bin

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 02/12] input: Adjust structure of code in process_modifier()
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 02/12] input: Adjust structure of code in process_modifier() Simon Glass
@ 2015-11-12 13:39   ` Bin Meng
  2015-11-14  2:04     ` Simon Glass
  0 siblings, 1 reply; 35+ messages in thread
From: Bin Meng @ 2015-11-12 13:39 UTC (permalink / raw)
  To: u-boot

On Thu, Nov 12, 2015 at 1:05 AM, Simon Glass <sjg@chromium.org> wrote:
> Move all the '!release' code into one block so that it is clear that it only
> applies on key release.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v3: None
> Changes in v2: None
>
>  drivers/input/input.c | 27 ++++++++++++++-------------
>  1 file changed, 14 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index 96fc195..7513226 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -237,7 +237,6 @@ static struct input_key_xlate *process_modifier(struct input_config *config,
>                                                 int key, int release)
>  {
>         struct input_key_xlate *table;
> -       int flip = -1;
>         int i;
>
>         /* Start with the main table, and see what modifiers change it */
> @@ -252,6 +251,8 @@ static struct input_key_xlate *process_modifier(struct input_config *config,
>
>         /* Handle the lighted keys */
>         if (!release) {
> +               int flip = -1;
> +
>                 switch (key) {
>                 case KEY_SCROLLLOCK:
>                         flip = FLAG_SCROLL_LOCK;
> @@ -263,19 +264,19 @@ static struct input_key_xlate *process_modifier(struct input_config *config,
>                         flip = FLAG_CAPS_LOCK;
>                         break;
>                 }
> -       }
>
> -       if (flip != -1) {
> -               int leds = 0;
> -
> -               config->leds ^= flip;
> -               if (config->flags & FLAG_NUM_LOCK)
> -                       leds |= INPUT_LED_NUM;
> -               if (config->flags & FLAG_CAPS_LOCK)
> -                       leds |= INPUT_LED_CAPS;
> -               if (config->flags & FLAG_SCROLL_LOCK)
> -                       leds |= INPUT_LED_SCROLL;
> -               config->leds = leds;
> +               if (flip != -1) {
> +                       int leds = 0;
> +
> +                       config->leds ^= flip;
> +                       if (config->flags & FLAG_NUM_LOCK)
> +                               leds |= INPUT_LED_NUM;
> +                       if (config->flags & FLAG_CAPS_LOCK)
> +                               leds |= INPUT_LED_CAPS;
> +                       if (config->flags & FLAG_SCROLL_LOCK)
> +                               leds |= INPUT_LED_SCROLL;
> +                       config->leds = leds;
> +               }
>         }
>
>         return table;
> --

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 03/12] input: Handle caps lock
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 03/12] input: Handle caps lock Simon Glass
@ 2015-11-12 13:50   ` Bin Meng
  2015-11-14  2:04     ` Simon Glass
  0 siblings, 1 reply; 35+ messages in thread
From: Bin Meng @ 2015-11-12 13:50 UTC (permalink / raw)
  To: u-boot

On Thu, Nov 12, 2015 at 1:05 AM, Simon Glass <sjg@chromium.org> wrote:
> When caps lock is enabled we should convert lower case to upper case. Add
> this to the input key processing so that caps lock works correctly.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v3: None
> Changes in v2: None
>
>  drivers/input/input.c | 13 ++++++++-----
>  1 file changed, 8 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index 7513226..a8a15c9 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -453,16 +453,19 @@ static int input_keycodes_to_ascii(struct input_config *config,
>         /* Start conversion by looking for the first new keycode (by same). */
>         for (i = same; i < num_keycodes; i++) {
>                 int key = keycode[i];
> -               int ch = (key < table->num_entries) ? table->xlate[key] : 0xff;
> +               int ch;
>
>                 /*
>                  * For a normal key (with an ASCII value), add it; otherwise
>                  * translate special key to escape sequence if possible.
>                  */
> -               if (ch != 0xff) {
> -                       if (ch_count < max_chars)
> -                               output_ch[ch_count] = (uchar)ch;
> -                       ch_count++;
> +               if (key < table->num_entries) {
> +                       ch = table->xlate[key];
> +                       if ((config->flags & FLAG_CAPS_LOCK) &&
> +                           ch >= 'a' && ch <= 'z')
> +                               ch -= 'a' - 'A';
> +                       if (ch_count < max_chars && ch != 0xff)
> +                               output_ch[ch_count++] = (uchar)ch;
>                 } else {
>                         ch_count += input_keycode_to_ansi364(config, key,
>                                                 output_ch, max_chars);
> --

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 04/12] input: Allow updating of keyboard LEDs
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 04/12] input: Allow updating of keyboard LEDs Simon Glass
@ 2015-11-12 13:50   ` Bin Meng
  2015-11-14  2:04     ` Simon Glass
  0 siblings, 1 reply; 35+ messages in thread
From: Bin Meng @ 2015-11-12 13:50 UTC (permalink / raw)
  To: u-boot

On Thu, Nov 12, 2015 at 1:05 AM, Simon Glass <sjg@chromium.org> wrote:
> Add a function which returns a new keyboard LED value when the LEDs need
> updating.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
> Changes in v3: None
> Changes in v2: None
>
>  drivers/input/input.c |  9 +++++++++
>  include/input.h       | 14 +++++++++++++-
>  2 files changed, 22 insertions(+), 1 deletion(-)
>
> diff --git a/drivers/input/input.c b/drivers/input/input.c
> index a8a15c9..bf1acdc 100644
> --- a/drivers/input/input.c
> +++ b/drivers/input/input.c
> @@ -276,6 +276,7 @@ static struct input_key_xlate *process_modifier(struct input_config *config,
>                         if (config->flags & FLAG_SCROLL_LOCK)
>                                 leds |= INPUT_LED_SCROLL;
>                         config->leds = leds;
> +                       config->leds_changed = flip;
>                 }
>         }
>
> @@ -587,6 +588,14 @@ void input_allow_repeats(struct input_config *config, bool allow_repeats)
>         config->allow_repeats = allow_repeats;
>  }
>
> +int input_leds_changed(struct input_config *config)
> +{
> +       if (config->leds_changed)
> +               return config->leds;
> +
> +       return -1;
> +}
> +
>  int input_add_tables(struct input_config *config, bool german)
>  {
>         struct kbd_entry *entry;
> diff --git a/include/input.h b/include/input.h
> index c1af259..ad120e4 100644
> --- a/include/input.h
> +++ b/include/input.h
> @@ -43,7 +43,8 @@ struct input_config {
>         /* Which modifiers are active (1 bit for each MOD_... value) */
>         uchar modifiers;
>         uchar flags;            /* active state keys (FLAGS_...) */
> -       uchar leds;             /* active LEDS (INPUT_LED_...) */
> +       uchar leds;             /* active LEDs (INPUT_LED_...) */
> +       uchar leds_changed;     /* LEDs that just changed */
>         uchar num_tables;       /* number of modifier tables */
>         int prev_keycodes[INPUT_BUFFER_LEN];    /* keys held last time */
>         int num_prev_keycodes;  /* number of prev keys */
> @@ -162,6 +163,17 @@ void input_set_delays(struct input_config *config, int repeat_delay_ms,
>  void input_allow_repeats(struct input_config *config, bool allow_repeats);
>
>  /**
> + * Check if keyboard LEDs need to be updated
> + *
> + * This can be called after input_tstc() to see if keyboard LEDs need
> + * updating.
> + *
> + * @param config       Input state
> + * @return -1 if no LEDs need updating, other value if they do
> + */
> +int input_leds_changed(struct input_config *config);
> +
> +/**
>   * Set up the key map tables
>   *
>   * This must be called after input_init() or keycode decoding will not work.
> --

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 05/12] input: i8042: Convert to use the input library
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 05/12] input: i8042: Convert to use the input library Simon Glass
@ 2015-11-12 13:50   ` Bin Meng
  2015-11-14  2:04     ` Simon Glass
  0 siblings, 1 reply; 35+ messages in thread
From: Bin Meng @ 2015-11-12 13:50 UTC (permalink / raw)
  To: u-boot

On Thu, Nov 12, 2015 at 1:05 AM, Simon Glass <sjg@chromium.org> wrote:
> At present the i8042 driver has its own logic and keymaps. In an effort to
> unify the code, move it over to use the input library. This changes most of
> the keycode-processing logic since it is now in that library. The main
> responsibilities of the driver are now to handle the LEDs, deal with the
> PS/2 extended keycodes and initialise the the keyboard.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

> Changes in v3: None
> Changes in v2:
> - Convert two multi-line comments to single-line comments
> - Correct call to input_init()
>
>  drivers/input/i8042.c | 493 +++++++-------------------------------------------
>  1 file changed, 69 insertions(+), 424 deletions(-)
>
> diff --git a/drivers/input/i8042.c b/drivers/input/i8042.c
> index b1ada86..270805b 100644
> --- a/drivers/input/i8042.c
> +++ b/drivers/input/i8042.c
> @@ -7,251 +7,18 @@
>
>  /* i8042.c - Intel 8042 keyboard driver routines */
>
> -/* includes */
> -
>  #include <common.h>
> -#include <asm/io.h>
>  #include <i8042.h>
> +#include <input.h>
> +#include <asm/io.h>
>
>  /* defines */
>  #define in8(p)         inb(p)
>  #define out8(p, v)     outb(v, p)
>
>  /* locals */
> -
> -static int kbd_input = -1;             /* no input yet */
> -static int kbd_mapping = KBD_US;       /* default US keyboard */
> -static int kbd_flags = NORMAL;         /* after reset */
> -static int kbd_state;                  /* unshift code */
> -
> -static unsigned char kbd_fct_map[144] = {
> -       /* kbd_fct_map table for scan code */
> -        0,  AS,  AS,  AS,  AS,  AS,  AS,  AS, /* scan 00-07 */
> -       AS,  AS,  AS,  AS,  AS,  AS,  AS,  AS, /* scan 08-0F */
> -       AS,  AS,  AS,  AS,  AS,  AS,  AS,  AS, /* scan 10-17 */
> -       AS,  AS,  AS,  AS,  AS,  CN,  AS,  AS, /* scan 18-1F */
> -       AS,  AS,  AS,  AS,  AS,  AS,  AS,  AS, /* scan 20-27 */
> -       AS,  AS,  SH,  AS,  AS,  AS,  AS,  AS, /* scan 28-2F */
> -       AS,  AS,  AS,  AS,  AS,  AS,  SH,  AS, /* scan 30-37 */
> -       AS,  AS,  CP,   0,   0,   0,   0,   0, /* scan 38-3F */
> -        0,   0,   0,   0,   0,  NM,  ST,  ES, /* scan 40-47 */
> -       ES,  ES,  ES,  ES,  ES,  ES,  ES,  ES, /* scan 48-4F */
> -       ES,  ES,  ES,  ES,   0,   0,  AS,   0, /* scan 50-57 */
> -        0,   0,   0,   0,   0,   0,   0,   0, /* scan 58-5F */
> -        0,   0,   0,   0,   0,   0,   0,   0, /* scan 60-67 */
> -        0,   0,   0,   0,   0,   0,   0,   0, /* scan 68-6F */
> -       AS,   0,   0,  AS,   0,   0,  AS,   0, /* scan 70-77 */
> -        0,  AS,   0,   0,   0,  AS,   0,   0, /* scan 78-7F */
> -       AS,  CN,  AS,  AS,  AK,  ST,  EX,  EX, /* enhanced */
> -       AS,  EX,  EX,  AS,  EX,  AS,  EX,  EX  /* enhanced */
> -       };
> -
> -static unsigned char kbd_key_map[2][5][144] = {
> -       { /* US keyboard */
> -       { /* unshift code */
> -          0, 0x1b,  '1',  '2',  '3',  '4',  '5',  '6', /* scan 00-07 */
> -        '7',  '8',  '9',  '0',  '-',  '=', 0x08, '\t', /* scan 08-0F */
> -        'q',  'w',  'e',  'r',  't',  'y',  'u',  'i', /* scan 10-17 */
> -        'o',  'p',  '[',  ']', '\r',   CN,  'a',  's', /* scan 18-1F */
> -        'd',  'f',  'g',  'h',  'j',  'k',  'l',  ';', /* scan 20-27 */
> -       '\'',  '`',   SH, '\\',  'z',  'x',  'c',  'v', /* scan 28-2F */
> -        'b',  'n',  'm',  ',',  '.',  '/',   SH,  '*', /* scan 30-37 */
> -        ' ',  ' ',   CP,    0,    0,    0,    0,    0, /* scan 38-3F */
> -          0,    0,    0,    0,    0,   NM,   ST,  '7', /* scan 40-47 */
> -        '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1', /* scan 48-4F */
> -        '2',  '3',  '0',  '.',    0,    0,    0,    0, /* scan 50-57 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 58-5F */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 60-67 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 68-6F */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 70-77 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 78-7F */
> -       '\r',   CN,  '/',  '*',  ' ',   ST,  'F',  'A', /* extended */
> -          0,  'D',  'C',    0,  'B',    0,  '@',  'P'  /* extended */
> -       },
> -       { /* shift code */
> -          0, 0x1b,  '!',  '@',  '#',  '$',  '%',  '^', /* scan 00-07 */
> -        '&',  '*',  '(',  ')',  '_',  '+', 0x08, '\t', /* scan 08-0F */
> -        'Q',  'W',  'E',  'R',  'T',  'Y',  'U',  'I', /* scan 10-17 */
> -        'O',  'P',  '{',  '}', '\r',   CN,  'A',  'S', /* scan 18-1F */
> -        'D',  'F',  'G',  'H',  'J',  'K',  'L',  ':', /* scan 20-27 */
> -        '"',  '~',   SH,  '|',  'Z',  'X',  'C',  'V', /* scan 28-2F */
> -        'B',  'N',  'M',  '<',  '>',  '?',   SH,  '*', /* scan 30-37 */
> -        ' ',  ' ',   CP,    0,    0,    0,    0,    0, /* scan 38-3F */
> -          0,    0,    0,    0,    0,   NM,   ST,  '7', /* scan 40-47 */
> -        '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1', /* scan 48-4F */
> -        '2',  '3',  '0',  '.',    0,    0,    0,    0, /* scan 50-57 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 58-5F */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 60-67 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 68-6F */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 70-77 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 78-7F */
> -       '\r',   CN,  '/',  '*',  ' ',   ST,  'F',  'A', /* extended */
> -          0,  'D',  'C',    0,  'B',    0,  '@',  'P'  /* extended */
> -       },
> -       { /* control code */
> -       0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */
> -       0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 08-0F */
> -       0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */
> -       0x0f, 0x10, 0x1b, 0x1d, '\r',   CN, 0x01, 0x13, /* scan 18-1F */
> -       0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */
> -       0xff, 0x1c,   SH, 0xff, 0x1a, 0x18, 0x03, 0x16, /* scan 28-2F */
> -       0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff,   SH, 0xff, /* scan 30-37 */
> -       0xff, 0xff,   CP, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
> -       0xff, 0xff, 0xff, 0xff, 0xff,   NM,   ST, 0xff, /* scan 40-47 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
> -       '\r',   CN,  '/',  '*',  ' ',   ST, 0xff, 0xff, /* extended */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff  /* extended */
> -       },
> -       { /* non numeric code */
> -          0, 0x1b,  '1',  '2',  '3',  '4',  '5',  '6', /* scan 00-07 */
> -        '7',  '8',  '9',  '0',  '-',  '=', 0x08, '\t', /* scan 08-0F */
> -        'q',  'w',  'e',  'r',  't',  'y',  'u',  'i', /* scan 10-17 */
> -        'o',  'p',  '[',  ']', '\r',   CN,  'a',  's', /* scan 18-1F */
> -        'd',  'f',  'g',  'h',  'j',  'k',  'l',  ';', /* scan 20-27 */
> -       '\'',  '`',   SH, '\\',  'z',  'x',  'c',  'v', /* scan 28-2F */
> -        'b',  'n',  'm',  ',',  '.',  '/',   SH,  '*', /* scan 30-37 */
> -        ' ',  ' ',   CP,    0,    0,    0,    0,    0, /* scan 38-3F */
> -          0,    0,    0,    0,    0,   NM,   ST,  'w', /* scan 40-47 */
> -        'x',  'y',  'l',  't',  'u',  'v',  'm',  'q', /* scan 48-4F */
> -        'r',  's',  'p',  'n',    0,    0,    0,    0, /* scan 50-57 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 58-5F */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 60-67 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 68-6F */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 70-77 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 78-7F */
> -       '\r',   CN,  '/',  '*',  ' ',   ST,  'F',  'A', /* extended */
> -          0,  'D',  'C',    0,  'B',    0,  '@',  'P'  /* extended */
> -       },
> -       { /* right alt mode - not used in US keyboard */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 08-0F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10-17 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 18-1F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20-27 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28-2F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30-37 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40-47 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff  /* extended */
> -       }
> -       },
> -       { /* German keyboard */
> -       { /* unshift code */
> -          0, 0x1b,  '1',  '2',  '3',  '4',  '5',  '6', /* scan 00-07 */
> -        '7',  '8',  '9',  '0', 0xe1, '\'', 0x08, '\t', /* scan 08-0F */
> -        'q',  'w',  'e',  'r',  't',  'z',  'u',  'i', /* scan 10-17 */
> -        'o',  'p', 0x81,  '+', '\r',   CN,  'a',  's', /* scan 18-1F */
> -        'd',  'f',  'g',  'h',  'j',  'k',  'l', 0x94, /* scan 20-27 */
> -       0x84,  '^',   SH,  '#',  'y',  'x',  'c',  'v', /* scan 28-2F */
> -        'b',  'n',  'm',  ',',  '.',  '-',   SH,  '*', /* scan 30-37 */
> -        ' ',  ' ',   CP,    0,    0,    0,    0,    0, /* scan 38-3F */
> -          0,    0,    0,    0,    0,   NM,   ST,  '7', /* scan 40-47 */
> -        '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1', /* scan 48-4F */
> -        '2',  '3',  '0',  ',',    0,    0,  '<',    0, /* scan 50-57 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 58-5F */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 60-67 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 68-6F */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 70-77 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 78-7F */
> -       '\r',   CN,  '/',  '*',  ' ',   ST,  'F',  'A', /* extended */
> -          0,  'D',  'C',    0,  'B',    0,  '@',  'P'  /* extended */
> -       },
> -       { /* shift code */
> -          0, 0x1b,  '!',  '"', 0x15,  '$',  '%',  '&', /* scan 00-07 */
> -        '/',  '(',  ')',  '=',  '?',  '`', 0x08, '\t', /* scan 08-0F */
> -        'Q',  'W',  'E',  'R',  'T',  'Z',  'U',  'I', /* scan 10-17 */
> -        'O',  'P', 0x9a,  '*', '\r',   CN,  'A',  'S', /* scan 18-1F */
> -        'D',  'F',  'G',  'H',  'J',  'K',  'L', 0x99, /* scan 20-27 */
> -       0x8e, 0xf8,   SH, '\'',  'Y',  'X',  'C',  'V', /* scan 28-2F */
> -        'B',  'N',  'M',  ';',  ':',  '_',   SH,  '*', /* scan 30-37 */
> -        ' ',  ' ',   CP,    0,    0,    0,    0,    0, /* scan 38-3F */
> -          0,    0,    0,    0,    0,   NM,   ST,  '7', /* scan 40-47 */
> -        '8',  '9',  '-',  '4',  '5',  '6',  '+',  '1', /* scan 48-4F */
> -        '2',  '3',  '0',  ',',    0,    0,  '>',    0, /* scan 50-57 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 58-5F */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 60-67 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 68-6F */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 70-77 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 78-7F */
> -       '\r',   CN,  '/',  '*',  ' ',   ST,  'F',  'A', /* extended */
> -          0,  'D',  'C',    0,  'B',    0,  '@',  'P'  /* extended */
> -       },
> -       { /* control code */
> -       0xff, 0x1b, 0xff, 0x00, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */
> -       0x1e, 0xff, 0xff, 0xff, 0x1f, 0xff, 0xff, '\t', /* scan 08-0F */
> -       0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 0x15, 0x09, /* scan 10-17 */
> -       0x0f, 0x10, 0x1b, 0x1d, '\r',   CN, 0x01, 0x13, /* scan 18-1F */
> -       0x04, 0x06, 0x07, 0x08, 0x0a, 0x0b, 0x0c, 0xff, /* scan 20-27 */
> -       0xff, 0x1c,   SH, 0xff, 0x1a, 0x18, 0x03, 0x16, /* scan 28-2F */
> -       0x02, 0x0e, 0x0d, 0xff, 0xff, 0xff,   SH, 0xff, /* scan 30-37 */
> -       0xff, 0xff,   CP, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
> -       0xff, 0xff, 0xff, 0xff, 0xff,   NM,   ST, 0xff, /* scan 40-47 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 50-57 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
> -       '\r',   CN,  '/',  '*',  ' ',   ST, 0xff, 0xff, /* extended */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff  /* extended */
> -       },
> -       { /* non numeric code */
> -          0, 0x1b,  '1',  '2',  '3',  '4',  '5',  '6', /* scan 00-07 */
> -        '7',  '8',  '9',  '0', 0xe1, '\'', 0x08, '\t', /* scan 08-0F */
> -        'q',  'w',  'e',  'r',  't',  'z',  'u',  'i', /* scan 10-17 */
> -        'o',  'p', 0x81,  '+', '\r',   CN,  'a',  's', /* scan 18-1F */
> -        'd',  'f',  'g',  'h',  'j',  'k',  'l', 0x94, /* scan 20-27 */
> -       0x84,  '^',   SH,    0,  'y',  'x',  'c',  'v', /* scan 28-2F */
> -        'b',  'n',  'm',  ',',  '.',  '-',   SH,  '*', /* scan 30-37 */
> -        ' ',  ' ',   CP,    0,    0,    0,    0,    0, /* scan 38-3F */
> -          0,    0,    0,    0,    0,   NM,   ST,  'w', /* scan 40-47 */
> -        'x',  'y',  'l',  't',  'u',  'v',  'm',  'q', /* scan 48-4F */
> -        'r',  's',  'p',  'n',    0,    0,  '<',    0, /* scan 50-57 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 58-5F */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 60-67 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 68-6F */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 70-77 */
> -          0,    0,    0,    0,    0,    0,    0,    0, /* scan 78-7F */
> -       '\r',   CN,  '/',  '*',  ' ',   ST,  'F',  'A', /* extended */
> -          0,  'D',  'C',    0,  'B',    0,  '@',  'P'  /* extended */
> -       },
> -       { /* right alt mode - is used in German keyboard */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 00-07 */
> -        '{',  '[',  ']',  '}', '\\', 0xff, 0xff, 0xff, /* scan 08-0F */
> -        '@', 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 10-17 */
> -       0xff, 0xff, 0xff,  '~', 0xff, 0xff, 0xff, 0xff, /* scan 18-1F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 20-27 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 28-2F */
> -       0xff, 0xff, 0xe6, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 30-37 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 38-3F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 40-47 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 48-4F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff,  '|', 0xff, /* scan 50-57 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 58-5F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 60-67 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 68-6F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 70-77 */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* scan 78-7F */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, /* extended */
> -       0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff  /* extended */
> -       }
> -       }
> -       };
> +static struct input_config config;
> +static bool extended;
>
>  static unsigned char ext_key_map[] = {
>         0x1c, /* keypad enter */
> @@ -293,157 +60,12 @@ static int kbd_output_full(void)
>         return kbd_timeout != -1;
>  }
>
> -static void kbd_led_set(void)
> +static void kbd_led_set(int flags)
>  {
>         kbd_input_empty();
>         out8(I8042_DATA_REG, CMD_SET_KBD_LED);
>         kbd_input_empty();
> -       out8(I8042_DATA_REG, (kbd_flags & 0x7));
> -}
> -
> -static void kbd_normal(unsigned char scan_code)
> -{
> -       unsigned char chr;
> -
> -       if ((kbd_flags & BRK) == NORMAL) {
> -               chr = kbd_key_map[kbd_mapping][kbd_state][scan_code];
> -               if ((chr == 0xff) || (chr == 0x00))
> -                       return;
> -
> -               /* if caps lock convert upper to lower */
> -               if (((kbd_flags & CAPS) == CAPS) &&
> -                   (chr >= 'a' && chr <= 'z')) {
> -                       chr -= 'a' - 'A';
> -               }
> -               kbd_input = chr;
> -       }
> -}
> -
> -static void kbd_shift(unsigned char scan_code)
> -{
> -       if ((kbd_flags & BRK) == BRK) {
> -               kbd_state = AS;
> -               kbd_flags &= (~SHIFT);
> -       } else {
> -               kbd_state = SH;
> -               kbd_flags |= SHIFT;
> -       }
> -}
> -
> -static void kbd_ctrl(unsigned char scan_code)
> -{
> -       if ((kbd_flags & BRK) == BRK) {
> -               kbd_state = AS;
> -               kbd_flags &= (~CTRL);
> -       } else {
> -               kbd_state = CN;
> -               kbd_flags |= CTRL;
> -       }
> -}
> -
> -static void kbd_num(unsigned char scan_code)
> -{
> -       if ((kbd_flags & BRK) == NORMAL) {
> -               kbd_flags ^= NUM;
> -               kbd_state = (kbd_flags & NUM) ? AS : NM;
> -               kbd_led_set();
> -       }
> -}
> -
> -static void kbd_alt(unsigned char scan_code)
> -{
> -       if ((kbd_flags & BRK) == BRK) {
> -               kbd_state = AS;
> -               kbd_flags &= (~ALT);
> -       } else {
> -               kbd_state = AK;
> -               kbd_flags &= ALT;
> -       }
> -}
> -
> -static void kbd_caps(unsigned char scan_code)
> -{
> -       if ((kbd_flags & BRK) == NORMAL) {
> -               kbd_flags ^= CAPS;
> -               kbd_led_set();
> -       }
> -}
> -
> -static void kbd_scroll(unsigned char scan_code)
> -{
> -       if ((kbd_flags & BRK) == NORMAL) {
> -               kbd_flags ^= STP;
> -               kbd_led_set();
> -               if (kbd_flags & STP)
> -                       kbd_input = 0x13;
> -               else
> -                       kbd_input = 0x11;
> -       }
> -}
> -
> -static void kbd_conv_char(unsigned char scan_code)
> -{
> -       if (scan_code == 0xe0) {
> -               kbd_flags |= EXT;
> -               return;
> -       }
> -
> -       /* if high bit of scan_code, set break flag */
> -       if (scan_code & 0x80)
> -               kbd_flags |=  BRK;
> -       else
> -               kbd_flags &= ~BRK;
> -
> -       if ((scan_code == 0xe1) || (kbd_flags & E1)) {
> -               if (scan_code == 0xe1) {
> -                       kbd_flags ^= BRK;       /* reset the break flag */
> -                       kbd_flags ^= E1;        /* bitwise EXOR with E1 flag */
> -               }
> -               return;
> -       }
> -
> -       scan_code &= 0x7f;
> -
> -       if (kbd_flags & EXT) {
> -               int i;
> -
> -               kbd_flags ^= EXT;
> -               for (i = 0; ext_key_map[i]; i++) {
> -                       if (ext_key_map[i] == scan_code) {
> -                               scan_code = 0x80 + i;
> -                               break;
> -                       }
> -               }
> -               /* not found ? */
> -               if (!ext_key_map[i])
> -                       return;
> -       }
> -
> -       switch (kbd_fct_map[scan_code]) {
> -       case AS:
> -               kbd_normal(scan_code);
> -               break;
> -       case SH:
> -               kbd_shift(scan_code);
> -               break;
> -       case CN:
> -               kbd_ctrl(scan_code);
> -               break;
> -       case NM:
> -               kbd_num(scan_code);
> -               break;
> -       case AK:
> -               kbd_alt(scan_code);
> -               break;
> -       case CP:
> -               kbd_caps(scan_code);
> -               break;
> -       case ST:
> -               kbd_scroll(scan_code);
> -               break;
> -       }
> -
> -       return;
> +       out8(I8042_DATA_REG, flags & 0x7);
>  }
>
>  static int kbd_write(int reg, int value)
> @@ -566,11 +188,50 @@ int i8042_disable(void)
>         return 0;
>  }
>
> +static int i8042_kbd_check(struct input_config *input)
> +{
> +       if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
> +               return 0;
> +       } else {
> +               bool release = false;
> +               int scan_code;
> +               int i;
> +
> +               scan_code = in8(I8042_DATA_REG);
> +               if (scan_code == 0xfa) {
> +                       return 0;
> +               } else if (scan_code == 0xe0) {
> +                       extended = true;
> +                       return 0;
> +               }
> +               if (scan_code & 0x80) {
> +                       scan_code &= 0x7f;
> +                       release = true;
> +               }
> +               if (extended) {
> +                       extended = false;
> +                       for (i = 0; ext_key_map[i]; i++) {
> +                               if (ext_key_map[i] == scan_code) {
> +                                       scan_code = 0x60 + i;
> +                                       break;
> +                               }
> +                       }
> +                       /* not found ? */
> +                       if (!ext_key_map[i])
> +                               return 0;
> +               }
> +
> +               input_add_keycode(&config, scan_code, release);
> +               return 1;
> +       }
> +}
> +
>  /* i8042_kbd_init - reset keyboard and init state flags */
>  int i8042_kbd_init(void)
>  {
>         int keymap, try;
>         char *penv;
> +       int ret;
>
>         if (!kbd_controller_present() || board_i8042_skip()) {
>                 debug("i8042 keyboard controller is not present\n");
> @@ -590,58 +251,42 @@ int i8042_kbd_init(void)
>                         return -1;
>         }
>
> -       kbd_mapping = keymap;
> -       kbd_flags   = NORMAL;
> -       kbd_state   = 0;
> -       kbd_led_set();
> +       ret = input_init(&config, keymap == KBD_GER);
> +       if (ret)
> +               return ret;
> +       config.read_keys = i8042_kbd_check;
> +       input_allow_repeats(&config, true);
> +
> +       kbd_led_set(NORMAL);
>
>         return 0;
>  }
>
> -/*
> - * i8042_tstc - test if keyboard input is available
> +/**
> + * check_leds() - Check the keyboard LEDs and update them it needed
>   *
> - * option: cursor blinking if called in a loop
> + * @ret:       Value to return
> + * @return value of @ret
>   */
> -int i8042_tstc(struct stdio_dev *dev)
> +static int check_leds(int ret)
>  {
> -       unsigned char scan_code = 0;
> +       int leds;
>
> -       if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
> -               return 0;
> -       } else {
> -               scan_code = in8(I8042_DATA_REG);
> -               if (scan_code == 0xfa)
> -                       return 0;
> -
> -               kbd_conv_char(scan_code);
> +       leds = input_leds_changed(&config);
> +       if (leds >= 0)
> +               kbd_led_set(leds);
>
> -               if (kbd_input != -1)
> -                       return 1;
> -       }
> +       return ret;
> +}
>
> -       return 0;
> +/* i8042_tstc - test if keyboard input is available */
> +int i8042_tstc(struct stdio_dev *dev)
> +{
> +       return check_leds(input_tstc(&config));
>  }
>
> -/*
> - * i8042_getc - wait till keyboard input is available
> - *
> - * option: turn on/off cursor while waiting
> - */
> +/* i8042_getc - wait till keyboard input is available */
>  int i8042_getc(struct stdio_dev *dev)
>  {
> -       int ret_chr;
> -       unsigned char scan_code;
> -
> -       while (kbd_input == -1) {
> -               while ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
> -               }
> -               scan_code = in8(I8042_DATA_REG);
> -               if (scan_code != 0xfa)
> -                       kbd_conv_char(scan_code);
> -       }
> -       ret_chr = kbd_input;
> -       kbd_input = -1;
> -
> -       return ret_chr;
> +       return check_leds(input_getc(&config));
>  }
> --
> 2.6.0.rc2.230.g3dd15c0
>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 09/12] input: Convert i8042 to driver model
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 09/12] input: Convert i8042 to driver model Simon Glass
@ 2015-11-12 13:50   ` Bin Meng
  2015-11-14  2:04     ` Simon Glass
  0 siblings, 1 reply; 35+ messages in thread
From: Bin Meng @ 2015-11-12 13:50 UTC (permalink / raw)
  To: u-boot

On Thu, Nov 12, 2015 at 1:05 AM, Simon Glass <sjg@chromium.org> wrote:
> Adjust this driver to support driver model. The only users are x86 boards
> so this should be safe.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>

Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Tested-by: Bin Meng <bmeng.cn@gmail.com>

> Changes in v3: None
> Changes in v2: None
>
>  drivers/input/Makefile |   2 +-
>  drivers/input/i8042.c  | 109 ++++++++++++++++++++++++++++++++++---------------
>  include/i8042.h        |   6 ---
>  3 files changed, 76 insertions(+), 41 deletions(-)
>
> diff --git a/drivers/input/Makefile b/drivers/input/Makefile
> index 9388dfe..5f15265 100644
> --- a/drivers/input/Makefile
> +++ b/drivers/input/Makefile
> @@ -7,7 +7,7 @@
>
>  obj-$(CONFIG_DM_KEYBOARD) += keyboard-uclass.o
>
> -obj-$(CONFIG_I8042_KBD) += i8042.o
> +obj-$(CONFIG_I8042_KEYB) += i8042.o
>  obj-$(CONFIG_TEGRA_KEYBOARD) += tegra-kbc.o
>  obj-$(CONFIG_TWL4030_INPUT) += twl4030.o
>  obj-$(CONFIG_CROS_EC_KEYB) += cros_ec_keyb.o
> diff --git a/drivers/input/i8042.c b/drivers/input/i8042.c
> index 270805b..e5e2926 100644
> --- a/drivers/input/i8042.c
> +++ b/drivers/input/i8042.c
> @@ -8,8 +8,11 @@
>  /* i8042.c - Intel 8042 keyboard driver routines */
>
>  #include <common.h>
> +#include <dm.h>
> +#include <errno.h>
>  #include <i8042.h>
>  #include <input.h>
> +#include <keyboard.h>
>  #include <asm/io.h>
>
>  /* defines */
> @@ -17,8 +20,9 @@
>  #define out8(p, v)     outb(v, p)
>
>  /* locals */
> -static struct input_config config;
> -static bool extended;
> +struct i8042_kbd_priv {
> +       bool extended;  /* true if an extended keycode is expected next */
> +};
>
>  static unsigned char ext_key_map[] = {
>         0x1c, /* keypad enter */
> @@ -60,12 +64,20 @@ static int kbd_output_full(void)
>         return kbd_timeout != -1;
>  }
>
> -static void kbd_led_set(int flags)
> +/**
> + * check_leds() - Check the keyboard LEDs and update them it needed
> + *
> + * @ret:       Value to return
> + * @return value of @ret
> + */
> +static int i8042_kbd_update_leds(struct udevice *dev, int leds)
>  {
>         kbd_input_empty();
>         out8(I8042_DATA_REG, CMD_SET_KBD_LED);
>         kbd_input_empty();
> -       out8(I8042_DATA_REG, flags & 0x7);
> +       out8(I8042_DATA_REG, leds & 0x7);
> +
> +       return 0;
>  }
>
>  static int kbd_write(int reg, int value)
> @@ -144,6 +156,8 @@ static int kbd_controller_present(void)
>  /*
>   * Implement a weak default function for boards that optionally
>   * need to skip the i8042 initialization.
> + *
> + * TODO(sjg at chromium.org): Use device tree for this?
>   */
>  int __weak board_i8042_skip(void)
>  {
> @@ -190,6 +204,8 @@ int i8042_disable(void)
>
>  static int i8042_kbd_check(struct input_config *input)
>  {
> +       struct i8042_kbd_priv *priv = dev_get_priv(input->dev);
> +
>         if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
>                 return 0;
>         } else {
> @@ -201,15 +217,15 @@ static int i8042_kbd_check(struct input_config *input)
>                 if (scan_code == 0xfa) {
>                         return 0;
>                 } else if (scan_code == 0xe0) {
> -                       extended = true;
> +                       priv->extended = true;
>                         return 0;
>                 }
>                 if (scan_code & 0x80) {
>                         scan_code &= 0x7f;
>                         release = true;
>                 }
> -               if (extended) {
> -                       extended = false;
> +               if (priv->extended) {
> +                       priv->extended = false;
>                         for (i = 0; ext_key_map[i]; i++) {
>                                 if (ext_key_map[i] == scan_code) {
>                                         scan_code = 0x60 + i;
> @@ -221,21 +237,23 @@ static int i8042_kbd_check(struct input_config *input)
>                                 return 0;
>                 }
>
> -               input_add_keycode(&config, scan_code, release);
> +               input_add_keycode(input, scan_code, release);
>                 return 1;
>         }
>  }
>
>  /* i8042_kbd_init - reset keyboard and init state flags */
> -int i8042_kbd_init(void)
> +static int i8042_start(struct udevice *dev)
>  {
> +       struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
> +       struct input_config *input = &uc_priv->input;
>         int keymap, try;
>         char *penv;
>         int ret;
>
>         if (!kbd_controller_present() || board_i8042_skip()) {
>                 debug("i8042 keyboard controller is not present\n");
> -               return -1;
> +               return -ENOENT;
>         }
>
>         /* Init keyboard device (default US layout) */
> @@ -251,42 +269,65 @@ int i8042_kbd_init(void)
>                         return -1;
>         }
>
> -       ret = input_init(&config, keymap == KBD_GER);
> +       ret = input_add_tables(input, keymap == KBD_GER);
>         if (ret)
>                 return ret;
> -       config.read_keys = i8042_kbd_check;
> -       input_allow_repeats(&config, true);
>
> -       kbd_led_set(NORMAL);
> +       i8042_kbd_update_leds(dev, NORMAL);
> +       debug("%s: started\n", __func__);
>
>         return 0;
>  }
>
>  /**
> - * check_leds() - Check the keyboard LEDs and update them it needed
> + * Set up the i8042 keyboard. This is called by the stdio device handler
>   *
> - * @ret:       Value to return
> - * @return value of @ret
> + * We want to do this init when the keyboard is actually used rather than
> + * at start-up, since keyboard input may not currently be selected.
> + *
> + * Once the keyboard starts there will be a period during which we must
> + * wait for the keyboard to init. We do this only when a key is first
> + * read - see kbd_wait_for_fifo_init().
> + *
> + * @return 0 if ok, -ve on error
>   */
> -static int check_leds(int ret)
> +static int i8042_kbd_probe(struct udevice *dev)
>  {
> -       int leds;
> -
> -       leds = input_leds_changed(&config);
> -       if (leds >= 0)
> -               kbd_led_set(leds);
> +       struct keyboard_priv *uc_priv = dev_get_uclass_priv(dev);
> +       struct stdio_dev *sdev = &uc_priv->sdev;
> +       struct input_config *input = &uc_priv->input;
> +       int ret;
>
> -       return ret;
> -}
> +       /* Register the device. i8042_start() will be called soon */
> +       input->dev = dev;
> +       input->read_keys = i8042_kbd_check;
> +       input_allow_repeats(input, true);
> +       strcpy(sdev->name, "i8042-kbd");
> +       ret = input_stdio_register(sdev);
> +       if (ret) {
> +               debug("%s: input_stdio_register() failed\n", __func__);
> +               return ret;
> +       }
> +       debug("%s: ready\n", __func__);
>
> -/* i8042_tstc - test if keyboard input is available */
> -int i8042_tstc(struct stdio_dev *dev)
> -{
> -       return check_leds(input_tstc(&config));
> +       return 0;
>  }
>
> -/* i8042_getc - wait till keyboard input is available */
> -int i8042_getc(struct stdio_dev *dev)
> -{
> -       return check_leds(input_getc(&config));
> -}
> +static const struct keyboard_ops i8042_kbd_ops = {
> +       .start  = i8042_start,
> +       .update_leds    = i8042_kbd_update_leds,
> +};
> +
> +static const struct udevice_id i8042_kbd_ids[] = {
> +       { .compatible = "intel,i8042-keyboard" },
> +       { }
> +};
> +
> +U_BOOT_DRIVER(i8042_kbd) = {
> +       .name   = "i8042_kbd",
> +       .id     = UCLASS_KEYBOARD,
> +       .of_match = i8042_kbd_ids,
> +       .probe = i8042_kbd_probe,
> +       .ops    = &i8042_kbd_ops,
> +       .priv_auto_alloc_size = sizeof(struct i8042_kbd_priv),
> +};
> diff --git a/include/i8042.h b/include/i8042.h
> index e0afce1..9723b6a 100644
> --- a/include/i8042.h
> +++ b/include/i8042.h
> @@ -87,10 +87,4 @@ void i8042_flush(void);
>   */
>  int i8042_disable(void);
>
> -struct stdio_dev;
> -
> -int i8042_kbd_init(void);
> -int i8042_tstc(struct stdio_dev *dev);
> -int i8042_getc(struct stdio_dev *dev);
> -
>  #endif /* _I8042_H_ */
> --
> 2.6.0.rc2.230.g3dd15c0
>

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model
  2015-11-12 13:33     ` Bin Meng
@ 2015-11-12 19:57       ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-12 19:57 UTC (permalink / raw)
  To: u-boot

Hi Bin,

On 12 November 2015 at 06:33, Bin Meng <bmeng.cn@gmail.com> wrote:
> Hi Simon,
>
> On Thu, Nov 12, 2015 at 11:56 AM, Bin Meng <bmeng.cn@gmail.com> wrote:
>> Hi Simon,
>>
>> On Thu, Nov 12, 2015 at 5:56 AM, Simon Glass <sjg@chromium.org> wrote:
>>> Hi Bin,
>>>
>>> On 11 November 2015 at 10:05, Simon Glass <sjg@chromium.org> wrote:
>>>> This series adds a new uclass for keyboards and converts some drivers
>>>> over to use it.
>>>>
>>>> This series includes some work to remove code duplication in the keyboard
>>>> drivers by updating them to use the input library (input.c). This unifies
>>>> the keycode decoding logic in one place. In order to do this some
>>>> enhancements are needed to the input library and these are also included.
>>>>
>>>> The cros_ec and tegra_kbc drivers are converted to use driver model.
>>>>
>>>> The i8042 driver is converted also, after various tidy-ups. The driver has
>>>> some strange interactions with the cfb_console driver. This is removed in
>>>> this series which is possible because the only user is x86. Some i8042
>>>> features have been dropped (the only deliberate one is the flashing cursor
>>>> which does not seem to be used by any board).
>>>>
>>>> Also the i8042 driver currently has its own keycode-decoding logic. This
>>>> series removes it in favour of the input library. Therefore testing of this
>>>> new driver would be appreciated. So far I have only been able to test on
>>>> link, which does not have a full keyboard. Also, while German keyboard
>>>> support is implemented, I am unable to test that either.
>>>>
>>>> These changes can be considered the first step towards moving stdio to
>>>> driver model. For that to be useful we need to convert LCD and video also.
>>>>
>>>> Note: This series is missing the code to call the update_leds() method when
>>>> the LEDs change. This needs to be added to keyboard_tstc() and
>>>> keyboard_getc(). If someone is able to test this I can send a patch for that
>>>> also.
>>>>
>>>> This series is available at u-boot-dm branch input-working.
>>>
>>> Can you please try testing this for your crash when pressing 'caps
>>> lock'? I'm not sure what is going on there and I don't have hardware
>>> to test with.
>>
>> I've tested the v3 patch. Looks the behavior is the same as v2. Note
>> the crash when pressing 'caps lock' only happens in v1. Starting from
>> v2, pressing 'caps lock' does not light the LED, and the characters
>> typed is still lower case. This is the same as the 'num lock' as I
>> reported before.
>>
>
> I've spent some time to debug this today, and have fixed all of these
> issues I reported so far. Please check my patch series @
> http://patchwork.ozlabs.org/patch/543339/

That's great! Thanks for all the testing and patches. It's really hard
to refactor code without hardware to test - lucky that you have it.

Regards,
Simon

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 01/12] input: Support the German keymap
  2015-11-12  3:51   ` Bin Meng
@ 2015-11-14  2:04     ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-14  2:04 UTC (permalink / raw)
  To: u-boot

On 11 November 2015 at 20:51, Bin Meng <bmeng.cn@gmail.com> wrote:
> Hi Simon,
>
> On Thu, Nov 12, 2015 at 1:05 AM, Simon Glass <sjg@chromium.org> wrote:
>> Add support for the German keymap, taken from i8042.c. This can be selected
>> when the input library it initialised.
>>
>> Signed-off-by: Simon Glass <sjg@chromium.org>
>> ---
>>
>
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
>
> Please check one nits below.
>
>> Changes in v3:
>> - Refactor the German keyboard code to use data rather than code
>>
>> Changes in v2:
>> - Update input_add_tables() to add error checking
>>
>>  board/kosagi/novena/novena.c |   2 +-
>>  drivers/input/cros_ec_keyb.c |   2 +-
>>  drivers/input/input.c        | 109 ++++++++++++++++++++++++++++++++++++++-----
>>  drivers/input/tegra-kbc.c    |   2 +-
>>  include/input.h              |   3 +-
>>  5 files changed, 102 insertions(+), 16 deletions(-)

Fixed nit and

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 02/12] input: Adjust structure of code in process_modifier()
  2015-11-12 13:39   ` Bin Meng
@ 2015-11-14  2:04     ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-14  2:04 UTC (permalink / raw)
  To: u-boot

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 03/12] input: Handle caps lock
  2015-11-12 13:50   ` Bin Meng
@ 2015-11-14  2:04     ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-14  2:04 UTC (permalink / raw)
  To: u-boot

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 04/12] input: Allow updating of keyboard LEDs
  2015-11-12 13:50   ` Bin Meng
@ 2015-11-14  2:04     ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-14  2:04 UTC (permalink / raw)
  To: u-boot

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 05/12] input: i8042: Convert to use the input library
  2015-11-12 13:50   ` Bin Meng
@ 2015-11-14  2:04     ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-14  2:04 UTC (permalink / raw)
  To: u-boot

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 06/12] input: Add a Kconfig option for the i8042 keyboard
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 06/12] input: Add a Kconfig option for the i8042 keyboard Simon Glass
@ 2015-11-14  2:04   ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-14  2:04 UTC (permalink / raw)
  To: u-boot

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 07/12] x86: Add an i8042 device for boards that have it
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 07/12] x86: Add an i8042 device for boards that have it Simon Glass
@ 2015-11-14  2:04   ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-14  2:04 UTC (permalink / raw)
  To: u-boot

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 08/12] Drop CONFIG_ISA_KEYBOARD
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 08/12] Drop CONFIG_ISA_KEYBOARD Simon Glass
@ 2015-11-14  2:04   ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-14  2:04 UTC (permalink / raw)
  To: u-boot

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 09/12] input: Convert i8042 to driver model
  2015-11-12 13:50   ` Bin Meng
@ 2015-11-14  2:04     ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-14  2:04 UTC (permalink / raw)
  To: u-boot

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 11/12] video: input: Clean up after i8042 conversion
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 11/12] video: input: Clean up after i8042 conversion Simon Glass
@ 2015-11-14  2:04   ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-14  2:04 UTC (permalink / raw)
  To: u-boot

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 10/12] i8042: Handle a duplicate power-on-reset response
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 10/12] i8042: Handle a duplicate power-on-reset response Simon Glass
@ 2015-11-14  2:04   ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-14  2:04 UTC (permalink / raw)
  To: u-boot

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 35+ messages in thread

* [U-Boot] [PATCH v3 12/12] input: Convert 'keyboard' driver to use input library
  2015-11-11 17:05 ` [U-Boot] [PATCH v3 12/12] input: Convert 'keyboard' driver to use input library Simon Glass
@ 2015-11-14  2:04   ` Simon Glass
  0 siblings, 0 replies; 35+ messages in thread
From: Simon Glass @ 2015-11-14  2:04 UTC (permalink / raw)
  To: u-boot

Applied to u-boot-dm.

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2015-11-14  2:04 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-11 17:05 [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
2015-11-11 17:05 ` [U-Boot] [PATCH v3 01/12] input: Support the German keymap Simon Glass
2015-11-12  3:51   ` Bin Meng
2015-11-14  2:04     ` Simon Glass
2015-11-11 17:05 ` [U-Boot] [PATCH v3 02/12] input: Adjust structure of code in process_modifier() Simon Glass
2015-11-12 13:39   ` Bin Meng
2015-11-14  2:04     ` Simon Glass
2015-11-11 17:05 ` [U-Boot] [PATCH v3 03/12] input: Handle caps lock Simon Glass
2015-11-12 13:50   ` Bin Meng
2015-11-14  2:04     ` Simon Glass
2015-11-11 17:05 ` [U-Boot] [PATCH v3 04/12] input: Allow updating of keyboard LEDs Simon Glass
2015-11-12 13:50   ` Bin Meng
2015-11-14  2:04     ` Simon Glass
2015-11-11 17:05 ` [U-Boot] [PATCH v3 05/12] input: i8042: Convert to use the input library Simon Glass
2015-11-12 13:50   ` Bin Meng
2015-11-14  2:04     ` Simon Glass
2015-11-11 17:05 ` [U-Boot] [PATCH v3 06/12] input: Add a Kconfig option for the i8042 keyboard Simon Glass
2015-11-14  2:04   ` Simon Glass
2015-11-11 17:05 ` [U-Boot] [PATCH v3 07/12] x86: Add an i8042 device for boards that have it Simon Glass
2015-11-14  2:04   ` Simon Glass
2015-11-11 17:05 ` [U-Boot] [PATCH v3 08/12] Drop CONFIG_ISA_KEYBOARD Simon Glass
2015-11-14  2:04   ` Simon Glass
2015-11-11 17:05 ` [U-Boot] [PATCH v3 09/12] input: Convert i8042 to driver model Simon Glass
2015-11-12 13:50   ` Bin Meng
2015-11-14  2:04     ` Simon Glass
2015-11-11 17:05 ` [U-Boot] [PATCH v3 10/12] i8042: Handle a duplicate power-on-reset response Simon Glass
2015-11-14  2:04   ` Simon Glass
2015-11-11 17:05 ` [U-Boot] [PATCH v3 11/12] video: input: Clean up after i8042 conversion Simon Glass
2015-11-14  2:04   ` Simon Glass
2015-11-11 17:05 ` [U-Boot] [PATCH v3 12/12] input: Convert 'keyboard' driver to use input library Simon Glass
2015-11-14  2:04   ` Simon Glass
2015-11-11 21:56 ` [U-Boot] [PATCH v3 00/12] dm: input: Move keyboard drivers to driver model Simon Glass
2015-11-12  3:56   ` Bin Meng
2015-11-12 13:33     ` Bin Meng
2015-11-12 19:57       ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.