Skip to contentSkip to conversation

dm: input: Move keyboard drivers to driver model

PATCH Superseded Simon Glass 3 participants 56 messages Oct 19, 2015 – Oct 30, 2015

Subsystems (9)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover dm: input: Move keyboard drivers to driver model

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 v2:
- Add more debug info to input_init() for when it fails
- Support driver's tstc() and getc() methods in the uclass
- Update the comment for the tstc() method to indicate that an error can occur
- Add error checking to input_add_tables()
- Update commit message to explain what RTC means
- Fix extra space in commit message
- 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 (28):
dm: input: Create a keyboard uclass
input: Add a device pointer to the input config
input: Return -ENOSPC when there is not space
input: Add the keycode translation tables separately
cros_ec: Use udevice instead of cros_ec_dev for keyboard functions
dm: stdio: Plumb in the new keyboard uclass
dm: tegra: Convert keyboard driver to driver model
dm: cros_ec: Convert cros_ec keyboard driver to driver model
video: Drop unused console functions
i8042: Use functions to handle register access
i8042: Adjust kbd_reset() to collect all failures
i8042: Adjust keyboard init to assume success
input: Correct keycode for Ctrl-Y
input: Add a few more keyboard keycodes
input: Add a function to add a keycode to the existing set
input: Allow repeat filtering to be disabled
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                                   |  42 +-
 arch/arm/Kconfig                         |   1 +
 arch/arm/mach-tegra/Kconfig              |   1 +
 arch/sandbox/Kconfig                     |   3 +
 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             |   1 +
 board/mpl/pip405/README                  |   4 -
 common/stdio.c                           |  31 +-
 common/usb_kbd.c                         |   6 -
 doc/device-tree-bindings/input/i8042.txt |  10 +
 drivers/input/Kconfig                    |  19 +
 drivers/input/Makefile                   |   4 +-
 drivers/input/cros_ec_keyb.c             | 147 +++----
 drivers/input/i8042.c                    | 647 ++++++++-----------------------
 drivers/input/input.c                    | 222 +++++++++--
 drivers/input/keyboard-uclass.c          |  91 +++++
 drivers/input/keyboard.c                 | 290 ++------------
 drivers/input/tegra-kbc.c                | 242 ++++++------
 drivers/misc/cros_ec.c                   |  14 +-
 drivers/video/cfb_console.c              |  82 +---
 include/configs/MIP405.h                 |   5 -
 include/configs/MPC8536DS.h              |   1 -
 include/configs/MPC8544DS.h              |   1 -
 include/configs/MPC8572DS.h              |   1 -
 include/configs/MPC8641HPCN.h            |   1 -
 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/cros_ec.h                        |   4 +-
 include/fdtdec.h                         |   1 -
 include/i8042.h                          |   6 -
 include/input.h                          |  65 +++-
 include/keyboard.h                       |  84 ++++
 lib/fdtdec.c                             |   1 -
 40 files changed, 923 insertions(+), 1136 deletions(-)
 create mode 100644 arch/x86/dts/keyboard.dtsi
 create mode 100644 doc/device-tree-bindings/input/i8042.txt
 create mode 100644 drivers/input/keyboard-uclass.c
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#1 lore raw

PATCH v2 1/28 dm: input: Create a keyboard uclass

Add a uclass for keyboard input, mirroring the existing stdio methods. This is enabled by a new CONFIG_DM_KEYBOARD option.

---

Changes in v2:
- Add more debug info to input_init() for when it fails
- Support driver's tstc() and getc() methods in the uclass
- Update the comment for the tstc() method to indicate that an error can occur

 common/usb_kbd.c                |  6 ---
 drivers/input/Kconfig           |  9 ++++
 drivers/input/Makefile          |  2 +
 drivers/input/keyboard-uclass.c | 91 +++++++++++++++++++++++++++++++++++++++++
 include/keyboard.h              | 79 +++++++++++++++++++++++++++++++++++
 5 files changed, 181 insertions(+), 6 deletions(-)
 create mode 100644 drivers/input/keyboard-uclass.c
common/usb_kbd.c +0 -6
index 9b8e11e..e37d223 100644
@@ -649,12 +649,6 @@ U_BOOT_DRIVER(usb_kbd) = {
 	.probe = usb_kbd_probe,
 };
 
-/* TODO(sjg at chromium.org): Move this into a common location */
-UCLASS_DRIVER(keyboard) = {
-	.id		= UCLASS_KEYBOARD,
-	.name		= "keyboard",
-};
-
 static const struct usb_device_id kbd_id_table[] = {
 	{
 		.match_flags = USB_DEVICE_ID_MATCH_INT_CLASS |
drivers/input/Kconfig +9 -0
index bb00de7..447c4c3 100644
@@ -1,3 +1,12 @@
+config DM_KEYBOARD
+	bool "Enable driver model keyboard support"
+	depends on DM
+	help
+	  This adds a uclass for keyboards and implements keyboard support
+	  using driver model. The API is implemented by keyboard.h and
+	  includes methods to start/stop the device, check for available
+	  input and update LEDs if the keyboard has them.
+
 config CROS_EC_KEYB
 	bool "Enable Chrome OS EC keyboard support"
 	help
drivers/input/Makefile +2 -0
index b1161c5..9388dfe 100644
@@ -5,6 +5,8 @@
 # SPDX-License-Identifier:	GPL-2.0+
 #
 
+obj-$(CONFIG_DM_KEYBOARD) += keyboard-uclass.o
+
 obj-$(CONFIG_I8042_KBD) += i8042.o
 obj-$(CONFIG_TEGRA_KEYBOARD) += tegra-kbc.o
 obj-$(CONFIG_TWL4030_INPUT) += twl4030.o
drivers/input/keyboard-uclass.c new file +91 -0

91 lines not on this page · raw message

include/keyboard.h +79 -0

90 lines not on this page · raw message

Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#2 lore raw

PATCH v2 1/28 dm: input: Create a keyboard uclass

Quoted 254 lines · Simon Glass

Add a uclass for keyboard input, mirroring the existing stdio methods. This is enabled by a new CONFIG_DM_KEYBOARD option.

---

Changes in v2:
- Add more debug info to input_init() for when it fails
- Support driver's tstc() and getc() methods in the uclass
- Update the comment for the tstc() method to indicate that an error can occur

 common/usb_kbd.c                |  6 ---
 drivers/input/Kconfig           |  9 ++++
 drivers/input/Makefile          |  2 +
 drivers/input/keyboard-uclass.c | 91 +++++++++++++++++++++++++++++++++++++++++
 include/keyboard.h              | 79 +++++++++++++++++++++++++++++++++++
 5 files changed, 181 insertions(+), 6 deletions(-)
 create mode 100644 drivers/input/keyboard-uclass.c
common/usb_kbd.c +0 -6
index 9b8e11e..e37d223 100644
@@ -649,12 +649,6 @@ U_BOOT_DRIVER(usb_kbd) = {
        .probe = usb_kbd_probe,
 };
 
-/* TODO(sjg at chromium.org): Move this into a common location */
-UCLASS_DRIVER(keyboard) = {
-       .id             = UCLASS_KEYBOARD,
-       .name           = "keyboard",
-};
-
 static const struct usb_device_id kbd_id_table[] = {
        {
                .match_flags = USB_DEVICE_ID_MATCH_INT_CLASS |
drivers/input/Kconfig +9 -0
index bb00de7..447c4c3 100644
@@ -1,3 +1,12 @@
+config DM_KEYBOARD
+       bool "Enable driver model keyboard support"
+       depends on DM
+       help
+         This adds a uclass for keyboards and implements keyboard support
+         using driver model. The API is implemented by keyboard.h and
+         includes methods to start/stop the device, check for available
+         input and update LEDs if the keyboard has them.
+
 config CROS_EC_KEYB
        bool "Enable Chrome OS EC keyboard support"
        help
drivers/input/Makefile +2 -0
index b1161c5..9388dfe 100644
@@ -5,6 +5,8 @@
 # SPDX-License-Identifier:     GPL-2.0+
 #
 
+obj-$(CONFIG_DM_KEYBOARD) += keyboard-uclass.o
+
 obj-$(CONFIG_I8042_KBD) += i8042.o
 obj-$(CONFIG_TEGRA_KEYBOARD) += tegra-kbc.o
 obj-$(CONFIG_TWL4030_INPUT) += twl4030.o
drivers/input/keyboard-uclass.c new file +91 -0
new file mode 100644
index 0000000..4698773
@@ -0,0 +1,91 @@
+/*
+ * Copyright (c) 2015 Google, Inc
+ *
+ * SPDX-License-Identifier:    GPL-2.0+
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <keyboard.h>
+
+static int keyboard_start(struct stdio_dev *sdev)
+{
+       struct udevice *dev = sdev->priv;
+       struct keyboard_ops *ops = keyboard_get_ops(dev);
+
+       if (ops->start)
+               return ops->start(dev);
+
+       return 0;
+}
+
+static int keyboard_stop(struct stdio_dev *sdev)
+{
+       struct udevice *dev = sdev->priv;
+       struct keyboard_ops *ops = keyboard_get_ops(dev);
+
+       if (ops->stop)
+               return ops->stop(dev);
+
+       return 0;
+}
+
+static int keyboard_tstc(struct stdio_dev *sdev)
+{
+       struct udevice *dev = sdev->priv;
+       struct keyboard_priv *priv = dev_get_uclass_priv(dev);
+       struct keyboard_ops *ops = keyboard_get_ops(dev);
+
+       /* Just get input to do this for us if we can */
+       if (priv->input.dev)
+               return input_tstc(&priv->input);
+       else if (ops->tstc)
+               return ops->tstc(dev);
+
+       return -ENOSYS;
+}
+
+static int keyboard_getc(struct stdio_dev *sdev)
+{
+       struct udevice *dev = sdev->priv;
+       struct keyboard_priv *priv = dev_get_uclass_priv(dev);
+       struct keyboard_ops *ops = keyboard_get_ops(dev);
+
+       /* Just get input to do this for us if we can */
+       if (priv->input.dev)
+               return input_getc(&priv->input);
+       else if (ops->getc)
+               return ops->getc(dev);
+
+       return -ENOSYS;
+}
+
+static int keyboard_pre_probe(struct udevice *dev)
+{
+       struct keyboard_priv *priv = dev_get_uclass_priv(dev);
+       struct stdio_dev *sdev = &priv->sdev;
+       int ret;
+
+       strlcpy(sdev->name, dev->name, sizeof(sdev->name));
+       sdev->flags = DEV_FLAGS_INPUT | DEV_FLAGS_SYSTEM;
+       sdev->getc = keyboard_getc;
+       sdev->tstc = keyboard_tstc;
+       sdev->start = keyboard_start;
+       sdev->stop = keyboard_stop;
+       sdev->priv = dev;
+       ret = input_init(&priv->input, 0);
+       if (ret) {
+               debug("%s: Cannot set up input, ret=%d - please add DEBUG to drivers/input/input.c to figure out the cause\n",
+                     __func__, ret);
+               return ret;
+       }
+
+       return 0;
+}
+
+UCLASS_DRIVER(keyboard) = {
+       .id             = UCLASS_KEYBOARD,
+       .name           = "keyboard",
+       .pre_probe      = keyboard_pre_probe,
+       .per_device_auto_alloc_size = sizeof(struct keyboard_priv),
+};
include/keyboard.h +78 -0
index 88ae12b..5216d59 100644
@@ -1,6 +1,84 @@
 #ifndef __KEYBOARD_H
 #define __KEYBOARD_H
 
+#ifdef CONFIG_DM_KEYBOARD
+#include <input.h>
+#include <stdio_dev.h>
+
+/**
+ * struct keyboard_priv - information about a keyboard, for the uclass
+ *
+ * @sdev:      stdio device
+ * @input:     input configuration (the driver may use this if desired)
+ */
+struct keyboard_priv {
+       struct stdio_dev sdev;
+
+       /*
+        * This is set up by the uclass but will only be used if the driver
+        * sets input.dev to its device pointer (it is initially NULL).
+        */
+       struct input_config input;
+};
+
+/**
+ * struct keyboard_ops - keyboard device operations
+ */
+struct keyboard_ops {
+       /**
+        * start() - enable the keyboard ready for use
+        *
+        * @dev:        Device to enable
+        * @return 0 if OK, -ve on error
+        */
+       int (*start)(struct udevice *dev);
+
+       /**
+        * stop() - disable the keyboard when no-longer needed
+        *
+        * @dev:        Device to disable
+        * @return 0 if OK, -ve on error
+        */
+       int (*stop)(struct udevice *dev);
+
+       /**
+        * tstc() - check if a key is available
+        *
+        * @dev:        Device to check
+        * @return 0 if no key is available, 1 if a key is available, -ve on
+        *         error
+        */
+       int (*tstc)(struct udevice *dev);
+
+       /**
+        * getc() - get a key
+        *
+        * TODO(sjg at chromium.org): At present this method may wait if it calls
+        * input_getc().
+        *
+        * @dev:        Device to read from
+        * @return -EAGAIN if no key is available, otherwise key value read
+        *         (as ASCII).
+        */
+       int (*getc)(struct udevice *dev);
+
+       /**
+        * update_leds() - update keyboard LEDs
+        *
+        * This is called when the LEDs have changed and need to be updated.
+        * For example, if 'caps lock' is pressed then this method will be
+        * called with the new LED value.
+        *
+        * @dev:        Device to update
+        * @leds:       New LED mask (see INPUT_LED_... in input.h)
+        */
+       int (*update_leds)(struct udevice *dev, int leds);
+};
+
+#define keyboard_get_ops(dev)  ((struct keyboard_ops *)(dev)->driver->ops)
+
+#else
+
 #ifdef CONFIG_PS2MULT
 #include <ps2mult.h>
 #endif

include/keyboard.h extern int kbd_init (void);

Quoted 7 lines
include/keyboard.h +1 -1
@@ -18,5 +96,6 @@ extern int kbd_init (void);
 extern void handle_scancode(unsigned char scancode);
 extern int kbd_init_hw(void);
 extern void pckbd_leds(unsigned char leds);
+#endif /* !CONFIG_DM_KEYBOARD */
 
 #endif /* __KEYBOARD_H */
--
#3 lore raw

PATCH v2 1/28 dm: input: Create a keyboard uclass

Applied to u-boot-dm.

#4 lore raw

PATCH v2 2/28 input: Add a device pointer to the input config

In reply to Simon Glass

The read_keys() method in input is passed a struct input_config. Add a device pointer there so that we can find out the device that is referred to with driver model.

Once all drivers are converted we can update the input structure to use driver model instead.

---

Changes in v2: None

 include/input.h | 1 +
 1 file changed, 1 insertion(+)
include/input.h +1 -0
index 26e2ad7..7bccc8e 100644
@@ -36,6 +36,7 @@ struct input_key_xlate {
 };
 
 struct input_config {
+	struct udevice *dev;
 	uchar fifo[INPUT_BUFFER_LEN];
 	int fifo_in, fifo_out;
 
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#5 lore raw

PATCH v2 2/28 input: Add a device pointer to the input config

Quoted 7 lines · Simon Glass

The read_keys() method in input is passed a struct input_config. Add a device pointer there so that we can find out the device that is referred to with driver model.

Once all drivers are converted we can update the input structure to use driver model instead.

Quoted 9 lines

---

Changes in v2: None

 include/input.h | 1 +
 1 file changed, 1 insertion(+)

Applied to u-boot-dm.

#6 lore raw

PATCH v2 3/28 input: Return -ENOSPC when there is not space

In reply to Simon Glass

Return a useful error instead of -1 when something goes wrong.

---

Changes in v2: None

 drivers/input/input.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/input/input.c +2 -1
index 007b855..9033935 100644
@@ -8,6 +8,7 @@
  */
 
 #include <common.h>
+#include <errno.h>
 #include <stdio_dev.h>
 #include <input.h>
 #include <linux/input.h>
@@ -467,7 +468,7 @@ int input_init(struct input_config *config, int leds)
 		input_add_table(config, KEY_LEFTCTRL, KEY_RIGHTCTRL,
 			kbd_ctrl_xlate, ARRAY_SIZE(kbd_ctrl_xlate))) {
 		debug("%s: Could not add modifier tables\n", __func__);
-		return -1;
+		return -ENOSPC;
 	}
 
 	return 0;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#7 lore raw

PATCH v2 3/28 input: Return -ENOSPC when there is not space

Quoted 10 lines · Simon Glass

Return a useful error instead of -1 when something goes wrong.

---

Changes in v2: None

 drivers/input/input.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Applied to u-boot-dm.

#8 lore raw

PATCH v2 4/28 input: Add the keycode translation tables separately

In reply to Simon Glass

Require the caller to add the keycode translation tables separately so that it can select which ones to use. In a later patch we will add the option to add German tables.

---

Changes in v2:
- Add error checking to input_add_tables()

 board/kosagi/novena/novena.c |  1 +
 drivers/input/cros_ec_keyb.c |  1 +
 drivers/input/input.c        | 26 +++++++++++++++++---------
 drivers/input/tegra-kbc.c    |  1 +
 include/input.h              | 10 ++++++++++
 5 files changed, 30 insertions(+), 9 deletions(-)
board/kosagi/novena/novena.c +1 -0
index 69f5be3..48cbb0f 100644
@@ -88,6 +88,7 @@ int drv_keyboard_init(void)
 		debug("%s: Cannot set up input\n", __func__);
 		return -1;
 	}
+	input_add_tables(&button_input);
 	button_input.read_keys = novena_gpio_button_read_keys;
 
 	error = input_stdio_register(&dev);
drivers/input/cros_ec_keyb.c +1 -0
index a31aa77..eaab86f 100644
@@ -255,6 +255,7 @@ int drv_keyboard_init(void)
 		return -1;
 	}
 	config.input.read_keys = cros_ec_kbc_check;
+	input_add_tables(&config.input);
 
 	memset(&dev, '\0', sizeof(dev));
 	strcpy(dev.name, "cros-ec-keyb");
drivers/input/input.c +17 -9
index 9033935..82e8381 100644
@@ -457,19 +457,27 @@ void input_set_delays(struct input_config *config, int repeat_delay_ms,
 	config->repeat_rate_ms = repeat_rate_ms;
 }
 
+int input_add_tables(struct input_config *config)
+{
+	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));
+}
+
 int input_init(struct input_config *config, int leds)
 {
 	memset(config, '\0', sizeof(*config));
 	config->leds = leds;
-	if (input_add_table(config, -1, -1,
-			kbd_plain_xlate, ARRAY_SIZE(kbd_plain_xlate)) ||
-		input_add_table(config, KEY_LEFTSHIFT, KEY_RIGHTSHIFT,
-			kbd_shift_xlate, ARRAY_SIZE(kbd_shift_xlate)) ||
-		input_add_table(config, KEY_LEFTCTRL, KEY_RIGHTCTRL,
-			kbd_ctrl_xlate, ARRAY_SIZE(kbd_ctrl_xlate))) {
-		debug("%s: Could not add modifier tables\n", __func__);
-		return -ENOSPC;
-	}
 
 	return 0;
 }
drivers/input/tegra-kbc.c +1 -0
index c9c9fac..3310f84 100644
@@ -355,6 +355,7 @@ int drv_keyboard_init(void)
 		return -1;
 	}
 	config.input.read_keys = tegra_kbc_check;
+	input_add_tables(input);
 
 	memset(&dev, '\0', sizeof(dev));
 	strcpy(dev.name, "tegra-kbc");
include/input.h +10 -0
index 7bccc8e..71f3538 100644
@@ -123,6 +123,16 @@ void input_set_delays(struct input_config *config, int repeat_delay_ms,
 	       int repeat_rate_ms);
 
 /**
+ * Set up the key map tables
+ *
+ * This must be called after input_init() or keycode decoding will not work.
+ *
+ * @param config	Input state
+ * @return 0 if ok, -1 on error
+ */
+int input_add_tables(struct input_config *config);
+
+/**
  * Set up the input handler with basic key maps.
  *
  * @param config	Input state
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#9 lore raw

PATCH v2 4/28 input: Add the keycode translation tables separately

Quoted 106 lines · Simon Glass

Require the caller to add the keycode translation tables separately so that it can select which ones to use. In a later patch we will add the option to add German tables.

---

Changes in v2:
- Add error checking to input_add_tables()

 board/kosagi/novena/novena.c |  1 +
 drivers/input/cros_ec_keyb.c |  1 +
 drivers/input/input.c        | 26 +++++++++++++++++---------
 drivers/input/tegra-kbc.c    |  1 +
 include/input.h              | 10 ++++++++++
 5 files changed, 30 insertions(+), 9 deletions(-)
board/kosagi/novena/novena.c +1 -0
index 69f5be3..48cbb0f 100644
@@ -88,6 +88,7 @@ int drv_keyboard_init(void)
                debug("%s: Cannot set up input\n", __func__);
                return -1;
        }
+       input_add_tables(&button_input);
        button_input.read_keys = novena_gpio_button_read_keys;
 
        error = input_stdio_register(&dev);
drivers/input/cros_ec_keyb.c +1 -0
index a31aa77..eaab86f 100644
@@ -255,6 +255,7 @@ int drv_keyboard_init(void)
                return -1;
        }
        config.input.read_keys = cros_ec_kbc_check;
+       input_add_tables(&config.input);
 
        memset(&dev, '\0', sizeof(dev));
        strcpy(dev.name, "cros-ec-keyb");
drivers/input/input.c +17 -9
index 9033935..82e8381 100644
@@ -457,19 +457,27 @@ void input_set_delays(struct input_config *config, int repeat_delay_ms,
        config->repeat_rate_ms = repeat_rate_ms;
 }
 
+int input_add_tables(struct input_config *config)
+{
+       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));
+}
+
 int input_init(struct input_config *config, int leds)
 {
        memset(config, '\0', sizeof(*config));
        config->leds = leds;
-       if (input_add_table(config, -1, -1,
-                       kbd_plain_xlate, ARRAY_SIZE(kbd_plain_xlate)) ||
-               input_add_table(config, KEY_LEFTSHIFT, KEY_RIGHTSHIFT,
-                       kbd_shift_xlate, ARRAY_SIZE(kbd_shift_xlate)) ||
-               input_add_table(config, KEY_LEFTCTRL, KEY_RIGHTCTRL,
-                       kbd_ctrl_xlate, ARRAY_SIZE(kbd_ctrl_xlate))) {
-               debug("%s: Could not add modifier tables\n", __func__);
-               return -ENOSPC;
-       }
 
        return 0;
 }
drivers/input/tegra-kbc.c +1 -0
index c9c9fac..3310f84 100644
@@ -355,6 +355,7 @@ int drv_keyboard_init(void)
                return -1;
        }
        config.input.read_keys = tegra_kbc_check;
+       input_add_tables(input);
 
        memset(&dev, '\0', sizeof(dev));
        strcpy(dev.name, "tegra-kbc");
include/input.h +4 -0
index 7bccc8e..71f3538 100644
@@ -123,6 +123,16 @@ void input_set_delays(struct input_config *config, int repeat_delay_ms,
               int repeat_rate_ms);
 
 /**
+ * Set up the key map tables
+ *
+ * This must be called after input_init() or keycode decoding will not work.
+ *

include/input.h void input_set_delays(struct input_config *config, int repeat_delay_ms,

Quoted 10 lines
include/input.h +6 -1
+ * @param config       Input state
+ * @return 0 if ok, -1 on error
+ */
+int input_add_tables(struct input_config *config);
+
+/**
  * Set up the input handler with basic key maps.
  *
  * @param config       Input state
--
#10 lore raw

PATCH v2 4/28 input: Add the keycode translation tables separately

Applied to u-boot-dm.

#11 lore raw

PATCH v2 5/28 cros_ec: Use udevice instead of cros_ec_dev for keyboard functions

In reply to Simon Glass

In preparation for converting the cros_ec keyboard driver to driver model, adjust the cros_ec functions it will use to use a normal struct udevice.

---

Changes in v2: None

 drivers/input/cros_ec_keyb.c |  4 ++--
 drivers/misc/cros_ec.c       | 14 +++++++++-----
 include/cros_ec.h            |  4 ++--
 3 files changed, 13 insertions(+), 9 deletions(-)
drivers/input/cros_ec_keyb.c +2 -2
index eaab86f..88397b0 100644
@@ -54,7 +54,7 @@ static int check_for_keys(struct keyb *config,
 	unsigned int row, col, bit, data;
 	int num_keys;
 
-	if (cros_ec_scan_keyboard(config->dev, &scan)) {
+	if (cros_ec_scan_keyboard(config->dev->dev, &scan)) {
 		debug("%s: keyboard scan failed\n", __func__);
 		return -EIO;
 	}
@@ -139,7 +139,7 @@ int cros_ec_kbc_check(struct input_config *input)
 	 * may return 0 before all keys have been read from the EC.
 	 */
 	do {
-		irq_pending = cros_ec_interrupt_pending(config.dev);
+		irq_pending = cros_ec_interrupt_pending(config.dev->dev);
 		if (irq_pending) {
 			num_keys = check_for_keys(&config, keys, KBC_MAX_KEYS,
 						  &same);
drivers/misc/cros_ec.c +9 -5
index ba36795..e3229ef 100644
@@ -358,9 +358,11 @@ static int ec_command(struct cros_ec_dev *dev, uint8_t cmd, int cmd_version,
 	return len;
 }
 
-int cros_ec_scan_keyboard(struct cros_ec_dev *dev, struct mbkp_keyscan *scan)
+int cros_ec_scan_keyboard(struct udevice *dev, struct mbkp_keyscan *scan)
 {
-	if (ec_command(dev, EC_CMD_MKBP_STATE, 0, NULL, 0, scan,
+	struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
+
+	if (ec_command(cdev, EC_CMD_MKBP_STATE, 0, NULL, 0, scan,
 		       sizeof(scan->data)) != sizeof(scan->data))
 		return -1;
 
@@ -549,13 +551,15 @@ int cros_ec_reboot(struct cros_ec_dev *dev, enum ec_reboot_cmd cmd,
 	return 0;
 }
 
-int cros_ec_interrupt_pending(struct cros_ec_dev *dev)
+int cros_ec_interrupt_pending(struct udevice *dev)
 {
+	struct cros_ec_dev *cdev = dev_get_uclass_priv(dev);
+
 	/* no interrupt support : always poll */
-	if (!dm_gpio_is_valid(&dev->ec_int))
+	if (!dm_gpio_is_valid(&cdev->ec_int))
 		return -ENOENT;
 
-	return dm_gpio_get_value(&dev->ec_int);
+	return dm_gpio_get_value(&cdev->ec_int);
 }
 
 int cros_ec_info(struct cros_ec_dev *dev, struct ec_response_mkbp_info *info)
include/cros_ec.h +2 -2
index b926934..5fa5f6f 100644
@@ -81,7 +81,7 @@ int cros_ec_read_id(struct cros_ec_dev *dev, char *id, int maxlen);
  * @param scan		Place to put the scan results
  * @return 0 if ok, -1 on error
  */
-int cros_ec_scan_keyboard(struct cros_ec_dev *dev, struct mbkp_keyscan *scan);
+int cros_ec_scan_keyboard(struct udevice *dev, struct mbkp_keyscan *scan);
 
 /**
  * Read which image is currently running on the CROS-EC device.
@@ -125,7 +125,7 @@ int cros_ec_reboot(struct cros_ec_dev *dev, enum ec_reboot_cmd cmd,
  * @param dev		CROS-EC device
  * @return 0 if no interrupt is pending
  */
-int cros_ec_interrupt_pending(struct cros_ec_dev *dev);
+int cros_ec_interrupt_pending(struct udevice *dev);
 
 enum {
 	CROS_EC_OK,
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#12 lore raw

PATCH v2 5/28 cros_ec: Use udevice instead of cros_ec_dev for keyboard functions

Applied to u-boot-dm.

#13 lore raw

PATCH v2 6/28 dm: stdio: Plumb in the new keyboard uclass

In reply to Simon Glass

When driver model is used for keyboards we must scan the available keyboards and register them with stdio. Add code to do this.

At some point (once LCD/video is converted) we should be able to convert stdio to driver model and avoid these dual data structures.

---

Changes in v2: None

 common/stdio.c | 31 ++++++++++++++++++++++++++++++-
 1 file changed, 30 insertions(+), 1 deletion(-)
common/stdio.c +30 -1
index adbfc89..71cc32e 100644
@@ -11,6 +11,7 @@
 
 #include <config.h>
 #include <common.h>
+#include <dm.h>
 #include <errno.h>
 #include <stdarg.h>
 #include <malloc.h>
@@ -24,6 +25,8 @@
 #include <i2c.h>
 #endif
 
+#include <dm/device-internal.h>
+
 DECLARE_GLOBAL_DATA_PTR;
 
 static struct stdio_dev devs;
@@ -245,6 +248,32 @@ int stdio_init_tables(void)
 
 int stdio_add_devices(void)
 {
+#ifdef CONFIG_DM_KEYBOARD
+	struct udevice *dev;
+	struct uclass *uc;
+	int ret;
+
+	/*
+	 * For now we probe all the devices here. At some point this should be
+	 * done only when the devices are required - e.g. we have a list of
+	 * input devices to start up in the stdin environment variable. That
+	 * work probably makes more sense when stdio itself is converted to
+	 * driver model.
+	 *
+	 * TODO(sjg at chromium.org): Convert changing uclass_first_device() etc.
+	 * to return the device even on error. Then we could use that here.
+	 */
+	ret = uclass_get(UCLASS_KEYBOARD, &uc);
+	if (ret)
+		return ret;
+
+	/* Don't report errors to the caller - assume that they are non-fatal */
+	uclass_foreach_dev(dev, uc) {
+		ret = device_probe(dev);
+		if (ret)
+			printf("Failed to probe keyboard '%s'\n", dev->name);
+	}
+#endif
 #ifdef CONFIG_SYS_I2C
 	i2c_init_all();
 #else
@@ -258,7 +287,7 @@ int stdio_add_devices(void)
 #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
 	drv_video_init ();
 #endif
-#ifdef CONFIG_KEYBOARD
+#if defined(CONFIG_KEYBOARD) && !defined(CONFIG_DM_KEYBOARD)
 	drv_keyboard_init ();
 #endif
 #ifdef CONFIG_LOGBUFFER
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#14 lore raw

PATCH v2 7/28 dm: tegra: Convert keyboard driver to driver model

In reply to Simon Glass

Adjust the tegra keyboard driver to support driver model, using the new uclass. Make this the default for all Tegra boards so that those that use a keyboard will build correctly with this driver.

---

Changes in v2: None

 arch/arm/mach-tegra/Kconfig |   1 +
 drivers/input/tegra-kbc.c   | 243 ++++++++++++++++++++------------------------
 include/fdtdec.h            |   1 -
 lib/fdtdec.c                |   1 -
 4 files changed, 112 insertions(+), 134 deletions(-)
arch/arm/mach-tegra/Kconfig +1 -0
index a5b7e0d..de2454e 100644
@@ -12,6 +12,7 @@ config TEGRA_ARMV7_COMMON
 	select DM_I2C
 	select DM_SPI
 	select DM_GPIO
+	select DM_KEYBOARD
 
 choice
 	prompt "Tegra SoC select"
drivers/input/tegra-kbc.c +111 -132

391 lines not on this page · raw message

include/fdtdec.h +0 -1
index 2de6dda..0db5918 100644
@@ -118,7 +118,6 @@ enum fdt_compat_id {
 	COMPAT_UNKNOWN,
 	COMPAT_NVIDIA_TEGRA20_EMC,	/* Tegra20 memory controller */
 	COMPAT_NVIDIA_TEGRA20_EMC_TABLE, /* Tegra20 memory timing table */
-	COMPAT_NVIDIA_TEGRA20_KBC,	/* Tegra20 Keyboard */
 	COMPAT_NVIDIA_TEGRA20_NAND,	/* Tegra2 NAND controller */
 	COMPAT_NVIDIA_TEGRA20_PWM,	/* Tegra 2 PWM controller */
 	COMPAT_NVIDIA_TEGRA124_DC,	/* Tegra 124 Display controller */
lib/fdtdec.c +0 -1
index 1a86369..22de5be 100644
@@ -24,7 +24,6 @@ static const char * const compat_names[COMPAT_COUNT] = {
 	COMPAT(UNKNOWN, "<none>"),
 	COMPAT(NVIDIA_TEGRA20_EMC, "nvidia,tegra20-emc"),
 	COMPAT(NVIDIA_TEGRA20_EMC_TABLE, "nvidia,tegra20-emc-table"),
-	COMPAT(NVIDIA_TEGRA20_KBC, "nvidia,tegra20-kbc"),
 	COMPAT(NVIDIA_TEGRA20_NAND, "nvidia,tegra20-nand"),
 	COMPAT(NVIDIA_TEGRA20_PWM, "nvidia,tegra20-pwm"),
 	COMPAT(NVIDIA_TEGRA124_DC, "nvidia,tegra124-dc"),
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#15 lore raw

PATCH v2 7/28 dm: tegra: Convert keyboard driver to driver model

Applied to u-boot-dm.

#16 lore raw

PATCH v2 8/28 dm: cros_ec: Convert cros_ec keyboard driver to driver model

In reply to Simon Glass

Adjust the cros_ec keyboard driver to support driver model. Make this the default for all Exynos boards so that those that use a keyboard will build correctly with this driver.

---

Changes in v2: None

 README                       |   5 --
 arch/arm/Kconfig             |   1 +
 arch/sandbox/Kconfig         |   3 +
 drivers/input/cros_ec_keyb.c | 148 +++++++++++++++++--------------------------
 4 files changed, 62 insertions(+), 95 deletions(-)
README +0 -5
index ca49225..d381422 100644
@@ -1793,11 +1793,6 @@ CBFS (Coreboot Filesystem) support
 		Export function i8042_kbd_init, i8042_tstc and i8042_getc
 		for cfb_console. Supports cursor blinking.
 
-		CONFIG_CROS_EC_KEYB
-		Enables a Chrome OS keyboard using the CROS_EC interface.
-		This uses CROS_EC to communicate with a second microcontroller
-		which provides key scans on request.
-
 - Video support:
 		CONFIG_VIDEO
 
arch/arm/Kconfig +1 -0
index 7981355..f29febe 100644
@@ -420,6 +420,7 @@ config ARCH_EXYNOS
 	select DM_SERIAL
 	select DM_SPI
 	select DM_GPIO
+	select DM_KEYBOARD
 
 config ARCH_S5PC1XX
 	bool "Samsung S5PC1XX"
arch/sandbox/Kconfig +3 -0
index f078c9e..25e316c 100644
@@ -17,4 +17,7 @@ config PCI
 	  used on some devices to allow the CPU to communicate with its
 	  peripherals.
 
+config DM_KEYBOARD
+	default y
+
 endmenu
drivers/input/cros_ec_keyb.c +58 -90

239 lines not on this page · raw message

Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#17 lore raw

PATCH v2 8/28 dm: cros_ec: Convert cros_ec keyboard driver to driver model

Applied to u-boot-dm.

#18 lore raw

PATCH v2 9/28 video: Drop unused console functions

In reply to Simon Glass

CONFIG_CONSOLE_CURSOR, CONFIG_SYS_CONSOLE_BLINK_COUNT and CONFIG_CONSOLE_TIME are not used by any board. The implementation is not great and stands in the way of a refactor of i8042. Drop these for now. They can be re-introduced quite easily later, perhaps with driver-model real-time-clock (RTC) support.

When reintroducing, it might be useful to make a few changes:
- Blink time would be more useful than blink count
- The confusing #ifdefs should be avoided
- The time functions should support driver model
- It would be best keyed off console_tstc() or some similar idle loop rather than a particular input driver (i8042 in this case)

---

Changes in v2:
- Update commit message to explain what RTC means

 README                        |  7 -----
 drivers/input/i8042.c         | 23 ----------------
 drivers/video/cfb_console.c   | 62 +++++++------------------------------------
 include/configs/MPC8536DS.h   |  1 -
 include/configs/MPC8544DS.h   |  1 -
 include/configs/MPC8572DS.h   |  1 -
 include/configs/MPC8641HPCN.h |  1 -
 7 files changed, 9 insertions(+), 87 deletions(-)
README +0 -7
index d381422..99f2b97 100644
@@ -880,13 +880,6 @@ The following options need to be configured:
 						(i.e. i8042_tstc)
 			VIDEO_GETC_FCT		get char fct
 						(i.e. i8042_getc)
-			CONFIG_CONSOLE_CURSOR	cursor drawing on/off
-						(requires blink timer
-						cf. i8042.c)
-			CONFIG_SYS_CONSOLE_BLINK_COUNT blink interval (cf. i8042.c)
-			CONFIG_CONSOLE_TIME	display time/date info in
-						upper right corner
-						(requires CONFIG_CMD_DATE)
 			CONFIG_VIDEO_LOGO	display Linux logo in
 						upper left corner
 			CONFIG_VIDEO_BMP_LOGO	use bmp_logo.h instead of
drivers/input/i8042.c +0 -23
index 9b5fa32..7b95b21 100644
@@ -17,12 +17,6 @@
 #define in8(p)		inb(p)
 #define out8(p, v)	outb(v, p)
 
-#ifdef CONFIG_CONSOLE_CURSOR
-extern void console_cursor(int state);
-static int blink_count = CONFIG_SYS_CONSOLE_BLINK_COUNT;
-static int cursor_state;
-#endif
-
 /* locals */
 
 static int kbd_input = -1;		/* no input yet */
@@ -598,15 +592,6 @@ int i8042_tstc(struct stdio_dev *dev)
 {
 	unsigned char scan_code = 0;
 
-#ifdef CONFIG_CONSOLE_CURSOR
-	if (--blink_count == 0) {
-		cursor_state ^= 1;
-		console_cursor(cursor_state);
-		blink_count = CONFIG_SYS_CONSOLE_BLINK_COUNT;
-		udelay(10);
-	}
-#endif
-
 	if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
 		return 0;
 	} else {
@@ -635,14 +620,6 @@ int i8042_getc(struct stdio_dev *dev)
 
 	while (kbd_input == -1) {
 		while ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
-#ifdef CONFIG_CONSOLE_CURSOR
-			if (--blink_count == 0) {
-				cursor_state ^= 1;
-				console_cursor(cursor_state);
-				blink_count = CONFIG_SYS_CONSOLE_BLINK_COUNT;
-			}
-			udelay(10);
-#endif
 		}
 		scan_code = in8(I8042_DATA_REG);
 		if (scan_code != 0xfa)
drivers/video/cfb_console.c +9 -53

107 lines not on this page · raw message

include/configs/MPC8536DS.h +0 -1
index 1312438..fad7215 100644
@@ -533,7 +533,6 @@
 #define CONFIG_VGA_AS_SINGLE_DEVICE
 #define CONFIG_ATI_RADEON_FB
 #define CONFIG_VIDEO_LOGO
-/*#define CONFIG_CONSOLE_CURSOR*/
 #define CONFIG_SYS_ISA_IO_BASE_ADDRESS CONFIG_SYS_PCIE3_IO_VIRT
 #endif
 
include/configs/MPC8544DS.h +0 -1
index 67fac70..79f402e 100644
@@ -298,7 +298,6 @@ extern unsigned long get_board_sys_clk(unsigned long dummy);
 #define CONFIG_VGA_AS_SINGLE_DEVICE
 #define CONFIG_ATI_RADEON_FB
 #define CONFIG_VIDEO_LOGO
-/*#define CONFIG_CONSOLE_CURSOR*/
 #define CONFIG_SYS_ISA_IO_BASE_ADDRESS VIDEO_IO_OFFSET
 #endif
 
include/configs/MPC8572DS.h +0 -1
index f3334ad..d1f2e66 100644
@@ -496,7 +496,6 @@
 #define CONFIG_VGA_AS_SINGLE_DEVICE
 #define CONFIG_ATI_RADEON_FB
 #define CONFIG_VIDEO_LOGO
-/*#define CONFIG_CONSOLE_CURSOR*/
 #define CONFIG_SYS_ISA_IO_BASE_ADDRESS VIDEO_IO_OFFSET
 #endif
 
include/configs/MPC8641HPCN.h +0 -1
index f20ee79..3e23bcf 100644
@@ -404,7 +404,6 @@ extern unsigned long get_board_sys_clk(unsigned long dummy);
 #define CONFIG_VGA_AS_SINGLE_DEVICE
 #define CONFIG_ATI_RADEON_FB
 #define CONFIG_VIDEO_LOGO
-/*#define CONFIG_CONSOLE_CURSOR*/
 #define CONFIG_SYS_ISA_IO_BASE_ADDRESS CONFIG_SYS_PCIE2_IO_VIRT
 #endif
 
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#19 lore raw

PATCH v2 9/28 video: Drop unused console functions

Quoted 251 lines · Simon Glass

CONFIG_CONSOLE_CURSOR, CONFIG_SYS_CONSOLE_BLINK_COUNT and CONFIG_CONSOLE_TIME are not used by any board. The implementation is not great and stands in the way of a refactor of i8042. Drop these for now. They can be re-introduced quite easily later, perhaps with driver-model real-time-clock (RTC) support.

When reintroducing, it might be useful to make a few changes:
- Blink time would be more useful than blink count
- The confusing #ifdefs should be avoided
- The time functions should support driver model
- It would be best keyed off console_tstc() or some similar idle loop rather than a particular input driver (i8042 in this case)

---

Changes in v2:
- Update commit message to explain what RTC means

 README                        |  7 -----
 drivers/input/i8042.c         | 23 ----------------
 drivers/video/cfb_console.c   | 62 +++++++------------------------------------
 include/configs/MPC8536DS.h   |  1 -
 include/configs/MPC8544DS.h   |  1 -
 include/configs/MPC8572DS.h   |  1 -
 include/configs/MPC8641HPCN.h |  1 -
 7 files changed, 9 insertions(+), 87 deletions(-)
README +0 -7
index d381422..99f2b97 100644
@@ -880,13 +880,6 @@ The following options need to be configured:
                                                (i.e. i8042_tstc)
                        VIDEO_GETC_FCT          get char fct
                                                (i.e. i8042_getc)
-                       CONFIG_CONSOLE_CURSOR   cursor drawing on/off
-                                               (requires blink timer
-                                               cf. i8042.c)
-                       CONFIG_SYS_CONSOLE_BLINK_COUNT blink interval (cf. i8042.c)
-                       CONFIG_CONSOLE_TIME     display time/date info in
-                                               upper right corner
-                                               (requires CONFIG_CMD_DATE)
                        CONFIG_VIDEO_LOGO       display Linux logo in
                                                upper left corner
                        CONFIG_VIDEO_BMP_LOGO   use bmp_logo.h instead of
drivers/input/i8042.c +0 -23
index 9b5fa32..7b95b21 100644
@@ -17,12 +17,6 @@
 #define in8(p)         inb(p)
 #define out8(p, v)     outb(v, p)
 
-#ifdef CONFIG_CONSOLE_CURSOR
-extern void console_cursor(int state);
-static int blink_count = CONFIG_SYS_CONSOLE_BLINK_COUNT;
-static int cursor_state;
-#endif
-
 /* locals */
 
 static int kbd_input = -1;             /* no input yet */
@@ -598,15 +592,6 @@ int i8042_tstc(struct stdio_dev *dev)
 {
        unsigned char scan_code = 0;
 
-#ifdef CONFIG_CONSOLE_CURSOR
-       if (--blink_count == 0) {
-               cursor_state ^= 1;
-               console_cursor(cursor_state);
-               blink_count = CONFIG_SYS_CONSOLE_BLINK_COUNT;
-               udelay(10);
-       }
-#endif
-
        if ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
                return 0;
        } else {
@@ -635,14 +620,6 @@ int i8042_getc(struct stdio_dev *dev)
 
        while (kbd_input == -1) {
                while ((in8(I8042_STS_REG) & STATUS_OBF) == 0) {
-#ifdef CONFIG_CONSOLE_CURSOR
-                       if (--blink_count == 0) {
-                               cursor_state ^= 1;
-                               console_cursor(cursor_state);
-                               blink_count = CONFIG_SYS_CONSOLE_BLINK_COUNT;
-                       }
-                       udelay(10);
-#endif
                }
                scan_code = in8(I8042_DATA_REG);
                if (scan_code != 0xfa)
drivers/video/cfb_console.c +9 -53
index aa7ca86..1b5c3e0 100644
@@ -43,13 +43,6 @@
  * VIDEO_TSTC_FCT            - keyboard_tstc function
  * VIDEO_GETC_FCT            - keyboard_getc function
  *
- * CONFIG_CONSOLE_CURSOR      - on/off drawing cursor is done with
- *                             delay loop in VIDEO_TSTC_FCT (i8042)
- *
- * CONFIG_SYS_CONSOLE_BLINK_COUNT - value for delay loop - blink rate
- * CONFIG_CONSOLE_TIME       - display time/date in upper right
- *                             corner, needs CONFIG_CMD_DATE and
- *                             CONFIG_CONSOLE_CURSOR
  * CONFIG_VIDEO_LOGO         - display Linux Logo in upper left corner.
  *                             Use CONFIG_SPLASH_SCREEN_ALIGN with
  *                             environment variable "splashpos" to place
@@ -198,9 +191,6 @@
 
 /*
  * Cursor definition:
- * CONFIG_CONSOLE_CURSOR:  Uses a timer function (see drivers/input/i8042.c)
- *                        to let the cursor blink. Uses the macros
- *                        CURSOR_OFF and CURSOR_ON.
  * CONFIG_VIDEO_SW_CURSOR: Draws a cursor after the last character. No
  *                        blinking is provided. Uses the macros CURSOR_SET
  *                        and CURSOR_OFF.
@@ -210,42 +200,29 @@
  *                        must disable the hardware register of the graphic
  *                        chip. Otherwise a blinking field is displayed
  */
-#if !defined(CONFIG_CONSOLE_CURSOR) && \
-    !defined(CONFIG_VIDEO_SW_CURSOR) && \
-    !defined(CONFIG_VIDEO_HW_CURSOR)
+#if !defined(CONFIG_VIDEO_SW_CURSOR) && !defined(CONFIG_VIDEO_HW_CURSOR)
 /* no Cursor defined */
 #define CURSOR_ON
 #define CURSOR_OFF
 #define CURSOR_SET
 #endif
 
-#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
-#if defined(CURSOR_ON) || \
-       (defined(CONFIG_CONSOLE_CURSOR) && defined(CONFIG_VIDEO_SW_CURSOR))
-#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
-       or CONFIG_VIDEO_HW_CURSOR can be defined
+#if defined(CONFIG_VIDEO_SW_CURSOR)
+#if defined(CONFIG_VIDEO_HW_CURSOR)
+#error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
+       defined
 #endif
 void console_cursor(int state);
 
 #define CURSOR_ON  console_cursor(1)
 #define CURSOR_OFF console_cursor(0)
 #define CURSOR_SET video_set_cursor()
-#endif /* CONFIG_CONSOLE_CURSOR || CONFIG_VIDEO_SW_CURSOR */
-
-#ifdef CONFIG_CONSOLE_CURSOR
-#ifndef        CONFIG_CONSOLE_TIME
-#error CONFIG_CONSOLE_CURSOR must be defined for CONFIG_CONSOLE_TIME
-#endif
-#ifndef CONFIG_I8042_KBD
-#warning Cursor drawing on/off needs timer function s.a. drivers/input/i8042.c
-#endif
-#endif /* CONFIG_CONSOLE_CURSOR */
-
+#endif /* CONFIG_VIDEO_SW_CURSOR */
 
 #ifdef CONFIG_VIDEO_HW_CURSOR
 #ifdef CURSOR_ON
-#error only one of CONFIG_CONSOLE_CURSOR, CONFIG_VIDEO_SW_CURSOR, \
-       or CONFIG_VIDEO_HW_CURSOR can be defined
+#error only one of CONFIG_VIDEO_SW_CURSOR or CONFIG_VIDEO_HW_CURSOR can be \
+       defined
 #endif
 #define CURSOR_ON
 #define CURSOR_OFF
@@ -626,7 +603,7 @@ static void video_putchar(int xx, int yy, unsigned char c)
        video_drawchars(xx, yy + video_logo_height, &c, 1);
 }
 
-#if defined(CONFIG_CONSOLE_CURSOR) || defined(CONFIG_VIDEO_SW_CURSOR)
+#if defined(CONFIG_VIDEO_SW_CURSOR)
 static void video_set_cursor(void)
 {
        if (cursor_state)
@@ -651,27 +628,6 @@ static void video_invertchar(int xx, int yy)
 
 void console_cursor(int state)
 {
-#ifdef CONFIG_CONSOLE_TIME
-       struct rtc_time tm;
-       char info[16];
-
-       /* time update only if cursor is on (faster scroll) */
-       if (state) {
-               rtc_get(&tm);
-
-               sprintf(info, " %02d:%02d:%02d ", tm.tm_hour, tm.tm_min,
-                       tm.tm_sec);
-               video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
-                                VIDEO_INFO_Y, (uchar *) info);
-
-               sprintf(info, "%02d.%02d.%04d", tm.tm_mday, tm.tm_mon,
-                       tm.tm_year);
-               video_drawstring(VIDEO_VISIBLE_COLS - 10 * VIDEO_FONT_WIDTH,
-                                VIDEO_INFO_Y + 1 * VIDEO_FONT_HEIGHT,
-                                (uchar *) info);
-       }
-#endif
-
        if (cursor_state != state) {
                if (cursor_state) {
                        /* turn off the cursor */
include/configs/MPC8536DS.h +0 -1
index 1312438..fad7215 100644
@@ -533,7 +533,6 @@
 #define CONFIG_VGA_AS_SINGLE_DEVICE
 #define CONFIG_ATI_RADEON_FB
 #define CONFIG_VIDEO_LOGO
-/*#define CONFIG_CONSOLE_CURSOR*/
 #define CONFIG_SYS_ISA_IO_BASE_ADDRESS CONFIG_SYS_PCIE3_IO_VIRT
 #endif
 
include/configs/MPC8544DS.h +0 -1
index 67fac70..79f402e 100644
@@ -298,7 +298,6 @@ extern unsigned long get_board_sys_clk(unsigned long dummy);
 #define CONFIG_VGA_AS_SINGLE_DEVICE
 #define CONFIG_ATI_RADEON_FB
 #define CONFIG_VIDEO_LOGO
-/*#define CONFIG_CONSOLE_CURSOR*/
 #define CONFIG_SYS_ISA_IO_BASE_ADDRESS VIDEO_IO_OFFSET
 #endif
 
include/configs/MPC8572DS.h +0 -1
index f3334ad..d1f2e66 100644
@@ -496,7 +496,6 @@
 #define CONFIG_VGA_AS_SINGLE_DEVICE
 #define CONFIG_ATI_RADEON_FB
 #define CONFIG_VIDEO_LOGO
-/*#define CONFIG_CONSOLE_CURSOR*/
 #define CONFIG_SYS_ISA_IO_BASE_ADDRESS VIDEO_IO_OFFSET
 #endif
 
include/configs/MPC8641HPCN.h +0 -0
index f20ee79..3e23bcf 100644

include/configs/MPC8641HPCN.h extern unsigned long get_board_sys_clk(unsigned long dummy);

Quoted 8 lines
include/configs/MPC8641HPCN.h +0 -2
@@ -404,7 +404,6 @@ extern unsigned long get_board_sys_clk(unsigned long dummy);
 #define CONFIG_VGA_AS_SINGLE_DEVICE
 #define CONFIG_ATI_RADEON_FB
 #define CONFIG_VIDEO_LOGO
-/*#define CONFIG_CONSOLE_CURSOR*/
 #define CONFIG_SYS_ISA_IO_BASE_ADDRESS CONFIG_SYS_PCIE2_IO_VIRT
 #endif
 
--
#20 lore raw

PATCH v2 9/28 video: Drop unused console functions

Applied to u-boot-dm.

#21 lore raw

PATCH v2 10/28 i8042: Use functions to handle register access

In reply to Simon Glass

At present the register access in kbd_reset() is quite primitive. This makes it hard to follow.

Create functions to read and write data, both to a single register, and via the command/data approach.

Tested-on: Intel Crown Bay and QEMU

---

Changes in v2: None

 drivers/input/i8042.c | 75 ++++++++++++++++++++++++++++++---------------------
 1 file changed, 44 insertions(+), 31 deletions(-)
drivers/input/i8042.c +44 -31
index 7b95b21..dbd4b00 100644
@@ -446,53 +446,66 @@ static void kbd_conv_char(unsigned char scan_code)
 	return;
 }
 
-static int kbd_reset(void)
+static int kbd_write(int reg, int value)
 {
-	u8 config;
-
-	/* controller self test */
-	if (kbd_input_empty() == 0)
-		return -1;
-	out8(I8042_CMD_REG, CMD_SELF_TEST);
-	if (kbd_output_full() == 0)
-		return -1;
-	if (in8(I8042_DATA_REG) != KBC_TEST_OK)
+	if (!kbd_input_empty())
 		return -1;
+	out8(reg, value);
 
-	/* keyboard reset */
-	if (kbd_input_empty() == 0)
+	return 0;
+}
+
+static int kbd_read(int reg)
+{
+	if (!kbd_output_full())
 		return -1;
-	out8(I8042_DATA_REG, CMD_RESET_KBD);
-	if (kbd_output_full() == 0)
+
+	return in8(reg);
+}
+
+static int kbd_cmd_read(int cmd)
+{
+	if (kbd_write(I8042_CMD_REG, cmd))
 		return -1;
-	if (in8(I8042_DATA_REG) != KBD_ACK)
+
+	return kbd_read(I8042_DATA_REG);
+}
+
+static int kbd_cmd_write(int cmd, int data)
+{
+	if (kbd_write(I8042_CMD_REG, cmd))
 		return -1;
-	if (kbd_output_full() == 0)
+
+	return kbd_write(I8042_DATA_REG, data);
+}
+
+static int kbd_reset(void)
+{
+	int config;
+
+	/* controller self test */
+	if (kbd_cmd_read(CMD_SELF_TEST) != KBC_TEST_OK)
 		return -1;
-	if (in8(I8042_DATA_REG) != KBD_POR)
+
+	/* keyboard reset */
+	if (kbd_write(I8042_DATA_REG, CMD_RESET_KBD) ||
+	    kbd_read(I8042_DATA_REG) != KBD_ACK ||
+	    kbd_read(I8042_DATA_REG) != KBD_POR)
 		return -1;
 
 	/* set AT translation and disable irq */
-	if (kbd_input_empty() == 0)
-		return -1;
-	out8(I8042_CMD_REG, CMD_RD_CONFIG);
-	if (kbd_output_full() == 0)
+	config = kbd_cmd_read(CMD_RD_CONFIG);
+	if (config == -1)
 		return -1;
-	config = in8(I8042_DATA_REG);
+
 	config |= CONFIG_AT_TRANS;
 	config &= ~(CONFIG_KIRQ_EN | CONFIG_MIRQ_EN);
-	if (kbd_input_empty() == 0)
+	if (kbd_cmd_write(CMD_WR_CONFIG, config))
 		return -1;
-	out8(I8042_CMD_REG, CMD_WR_CONFIG);
-	if (kbd_input_empty() == 0)
-		return -1;
-	out8(I8042_DATA_REG, config);
 
 	/* enable keyboard */
-	if (kbd_input_empty() == 0)
-		return -1;
-	out8(I8042_CMD_REG, CMD_KBD_EN);
-	if (kbd_input_empty() == 0)
+	if (kbd_write(I8042_CMD_REG, CMD_KBD_EN) ||
+	    !kbd_input_empty())
 		return -1;
 
 	return 0;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#22 lore raw

PATCH v2 10/28 i8042: Use functions to handle register access

Applied to u-boot-dm.

#23 lore raw

PATCH v2 11/28 i8042: Adjust kbd_reset() to collect all failures

In reply to Simon Glass

Rather than lots of 'return' statements, use goto to a single return.

---

Changes in v2: None

 drivers/input/i8042.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/input/i8042.c +8 -5
index dbd4b00..4c887f4 100644
@@ -485,30 +485,33 @@ static int kbd_reset(void)
 
 	/* controller self test */
 	if (kbd_cmd_read(CMD_SELF_TEST) != KBC_TEST_OK)
-		return -1;
+		goto err;
 
 	/* keyboard reset */
 	if (kbd_write(I8042_DATA_REG, CMD_RESET_KBD) ||
 	    kbd_read(I8042_DATA_REG) != KBD_ACK ||
 	    kbd_read(I8042_DATA_REG) != KBD_POR)
-		return -1;
+		goto err;
 
 	/* set AT translation and disable irq */
 	config = kbd_cmd_read(CMD_RD_CONFIG);
 	if (config == -1)
-		return -1;
+		goto err;
 
 	config |= CONFIG_AT_TRANS;
 	config &= ~(CONFIG_KIRQ_EN | CONFIG_MIRQ_EN);
 	if (kbd_cmd_write(CMD_WR_CONFIG, config))
-		return -1;
+		goto err;
 
 	/* enable keyboard */
 	if (kbd_write(I8042_CMD_REG, CMD_KBD_EN) ||
 	    !kbd_input_empty())
-		return -1;
+		goto err;
 
 	return 0;
+err:
+	debug("%s: Keyboard failure\n", __func__);
+	return -1;
 }
 
 static int kbd_controller_present(void)
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#24 lore raw

PATCH v2 11/28 i8042: Adjust kbd_reset() to collect all failures

Applied to u-boot-dm.

#25 lore raw

PATCH v2 12/28 i8042: Adjust keyboard init to assume success

In reply to Simon Glass

Modify i8042_kbd_init() so that the normal pass is sucessful init and failure exits early. This will make the code easier to extend and is easier to read.

---

Changes in v2: None

 drivers/input/i8042.c | 19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)
drivers/input/i8042.c +9 -10
index 4c887f4..b1ada86 100644
@@ -585,18 +585,17 @@ int i8042_kbd_init(void)
 			keymap = KBD_GER;
 	}
 
-	for (try = 0; try < KBD_RESET_TRIES; try++) {
-		if (kbd_reset() == 0) {
-			kbd_mapping = keymap;
-			kbd_flags   = NORMAL;
-			kbd_state   = 0;
-			kbd_led_set();
-
-			return 0;
-		}
+	for (try = 0; kbd_reset() != 0; try++) {
+		if (try >= KBD_RESET_TRIES)
+			return -1;
 	}
 
-	return -1;
+	kbd_mapping = keymap;
+	kbd_flags   = NORMAL;
+	kbd_state   = 0;
+	kbd_led_set();
+
+	return 0;
 }
 
 /*
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#26 lore raw

PATCH v2 12/28 i8042: Adjust keyboard init to assume success

Applied to u-boot-dm.

#27 lore raw

PATCH v2 13/28 input: Correct keycode for Ctrl-Y

In reply to Simon Glass

This code is currently incorrect, perhaps due to a typo. Fix it.

---

Changes in v2: None

 drivers/input/input.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/input/input.c +1 -1
index 82e8381..a6834cf 100644
@@ -65,7 +65,7 @@ static unsigned char kbd_shift_xlate[] = {
 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,
+	0x11, 0x17, 0x05, 0x12, 0x14, 0x19, 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 */
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#28 lore raw

PATCH v2 13/28 input: Correct keycode for Ctrl-Y

Applied to u-boot-dm.

#29 lore raw

PATCH v2 14/28 input: Add a few more keyboard keycodes

In reply to Simon Glass

The slash and * are missing from the keycode tables. Add these so that these keypad keys can be used.

---

Changes in v2:
- Fix extra space in commit message

 drivers/input/input.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/input/input.c +3 -3
index a6834cf..e65942e 100644
@@ -43,7 +43,7 @@ static const uchar kbd_plain_xlate[] = {
 	'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
+	'\r', 0xff, '/',  '*',
 };
 
 static unsigned char kbd_shift_xlate[] = {
@@ -59,7 +59,7 @@ static unsigned char kbd_shift_xlate[] = {
 	'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
+	'\r', 0xff, '/',  '*',
 };
 
 static unsigned char kbd_ctrl_xlate[] = {
@@ -75,7 +75,7 @@ static unsigned char kbd_ctrl_xlate[] = {
 	'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
+	'\r', 0xff, '/',  '*',
 };
 
 /*
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#30 lore raw

PATCH v2 14/28 input: Add a few more keyboard keycodes

Applied to u-boot-dm.

#31 lore raw

PATCH v2 15/28 input: Add a function to add a keycode to the existing set

In reply to Simon Glass

Most keyboards can be scanned to produce a list of the keycodes which are depressed. With the i8042 keyboard this scanning is done internally and only the processed results are returned.

In this case, when a key is pressed, a 'make' code is sent. When the key is released an 'unmake' code is sent. This means that the driver needs to keep track of which keys are pressed. It also means that any protocol error can lead to stuck keys.

In order to support this type of keyboard, add a function when can be used to provide a single keycode and either add it to the list of what is pressed or remove it from the list. Then the normal input_send_keycodes() function can be used to actually do the decoding work.

Add debugging to display the ASCII characters written to the input queue also.

---

Changes in v2: None

 drivers/input/input.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
 include/input.h       | 20 ++++++++++++++++++++
 2 files changed, 62 insertions(+), 4 deletions(-)
drivers/input/input.c +42 -4
index e65942e..530bf51 100644
@@ -107,6 +107,7 @@ static int input_queue_ascii(struct input_config *config, int ch)
 			return -1; /* buffer full */
 		config->fifo_in++;
 	}
+	debug(" {%02x} ", ch);
 	config->fifo[config->fifo_in] = (uchar)ch;
 
 	return 0;
@@ -394,8 +395,8 @@ static int input_keycodes_to_ascii(struct input_config *config,
 	return ch_count;
 }
 
-int input_send_keycodes(struct input_config *config,
-			int keycode[], int num_keycodes)
+static int _input_send_keycodes(struct input_config *config, int keycode[],
+				int num_keycodes, bool do_send)
 {
 	char ch[num_keycodes * ANSI_CHAR_MAX];
 	int count, i, same = 0;
@@ -420,8 +421,10 @@ int input_send_keycodes(struct input_config *config,
 
 	count = input_keycodes_to_ascii(config, keycode, num_keycodes,
 					ch, sizeof(ch), is_repeat ? 0 : same);
-	for (i = 0; i < count; i++)
-		input_queue_ascii(config, ch[i]);
+	if (do_send) {
+		for (i = 0; i < count; i++)
+			input_queue_ascii(config, ch[i]);
+	}
 	delay_ms = is_repeat ?
 			config->repeat_rate_ms :
 			config->repeat_delay_ms;
@@ -431,6 +434,41 @@ int input_send_keycodes(struct input_config *config,
 	return count;
 }
 
+int input_send_keycodes(struct input_config *config, int keycode[],
+			int num_keycodes)
+{
+	return _input_send_keycodes(config, keycode, num_keycodes, true);
+}
+
+int input_add_keycode(struct input_config *config, int new_keycode,
+		      bool release)
+{
+	int keycode[INPUT_MAX_MODIFIERS + 1];
+	int count, i;
+
+	/* Add the old keycodes which are not removed by this new one */
+	for (i = 0, count = 0; i < config->num_prev_keycodes; i++) {
+		int code = config->prev_keycodes[i];
+
+		if (new_keycode == code) {
+			if (release)
+				continue;
+			new_keycode = -1;
+		}
+		keycode[count++] = code;
+	}
+
+	if (!release && new_keycode != -1)
+		keycode[count++] = new_keycode;
+	debug("\ncodes for %02x/%d: ", new_keycode, release);
+	for (i = 0; i < count; i++)
+		debug("%02x ", keycode[i]);
+	debug("\n");
+
+	/* Don't output any ASCII characters if this is a key release */
+	return _input_send_keycodes(config, keycode, count, !release);
+}
+
 int input_add_table(struct input_config *config, int left_keycode,
 		    int right_keycode, const uchar *xlate, int num_entries)
 {
include/input.h +20 -0
index 71f3538..9942d6f 100644
@@ -76,6 +76,26 @@ struct stdio_dev;
 int input_send_keycodes(struct input_config *config, int keycode[], int count);
 
 /**
+ * Add a new keycode to an existing list of keycodes
+ *
+ * This can be used to handle keyboards which do their own scanning. An
+ * internal list of depressed keys is maintained by the input library. Then
+ * this function is called to add a new key to the list (when a 'make code' is
+ * received), or remove a key (when a 'break code' is received).
+ *
+ * This function looks after maintenance of the list of active keys, and calls
+ * input_send_keycodes() with its updated list.
+ *
+ * @param config	Input state
+ * @param new_keycode	New keycode to add/remove
+ * @param release	true if this key was released, false if depressed
+ * @return number of ascii characters sent, or 0 if none, or -1 for an
+ *	internal error
+ */
+int input_add_keycode(struct input_config *config, int new_keycode,
+		      bool release);
+
+/**
  * Add a new key translation table to the input
  *
  * @param config	Input state
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#32 lore raw

PATCH v2 15/28 input: Add a function to add a keycode to the existing set

Hi Simon,

Quoted 6 lines · Simon Glass

Most keyboards can be scanned to produce a list of the keycodes which are depressed. With the i8042 keyboard this scanning is done internally and only the processed results are returned.

In this case, when a key is pressed, a 'make' code is sent. When the key is released an 'unmake' code is sent. This means that the driver needs to

nits: 'unmake' -> 'break'

Quoted 8 lines

keep track of which keys are pressed. It also means that any protocol error can lead to stuck keys.

In order to support this type of keyboard, add a function when can be used to provide a single keycode and either add it to the list of what is pressed or remove it from the list. Then the normal input_send_keycodes() function can be used to actually do the decoding work.

Quoted 5 lines

Add debugging to display the ASCII characters written to the input queue also.

---

Quoted 107 lines

Changes in v2: None

 drivers/input/input.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
 include/input.h       | 20 ++++++++++++++++++++
 2 files changed, 62 insertions(+), 4 deletions(-)
drivers/input/input.c +42 -4
index e65942e..530bf51 100644
@@ -107,6 +107,7 @@ static int input_queue_ascii(struct input_config *config, int ch)
                        return -1; /* buffer full */
                config->fifo_in++;
        }
+       debug(" {%02x} ", ch);
        config->fifo[config->fifo_in] = (uchar)ch;
 
        return 0;
@@ -394,8 +395,8 @@ static int input_keycodes_to_ascii(struct input_config *config,
        return ch_count;
 }
 
-int input_send_keycodes(struct input_config *config,
-                       int keycode[], int num_keycodes)
+static int _input_send_keycodes(struct input_config *config, int keycode[],
+                               int num_keycodes, bool do_send)
 {
        char ch[num_keycodes * ANSI_CHAR_MAX];
        int count, i, same = 0;
@@ -420,8 +421,10 @@ int input_send_keycodes(struct input_config *config,
 
        count = input_keycodes_to_ascii(config, keycode, num_keycodes,
                                        ch, sizeof(ch), is_repeat ? 0 : same);
-       for (i = 0; i < count; i++)
-               input_queue_ascii(config, ch[i]);
+       if (do_send) {
+               for (i = 0; i < count; i++)
+                       input_queue_ascii(config, ch[i]);
+       }
        delay_ms = is_repeat ?
                        config->repeat_rate_ms :
                        config->repeat_delay_ms;
@@ -431,6 +434,41 @@ int input_send_keycodes(struct input_config *config,
        return count;
 }
 
+int input_send_keycodes(struct input_config *config, int keycode[],
+                       int num_keycodes)
+{
+       return _input_send_keycodes(config, keycode, num_keycodes, true);
+}
+
+int input_add_keycode(struct input_config *config, int new_keycode,
+                     bool release)
+{
+       int keycode[INPUT_MAX_MODIFIERS + 1];
+       int count, i;
+
+       /* Add the old keycodes which are not removed by this new one */
+       for (i = 0, count = 0; i < config->num_prev_keycodes; i++) {
+               int code = config->prev_keycodes[i];
+
+               if (new_keycode == code) {
+                       if (release)
+                               continue;
+                       new_keycode = -1;
+               }
+               keycode[count++] = code;
+       }
+
+       if (!release && new_keycode != -1)
+               keycode[count++] = new_keycode;
+       debug("\ncodes for %02x/%d: ", new_keycode, release);
+       for (i = 0; i < count; i++)
+               debug("%02x ", keycode[i]);
+       debug("\n");
+
+       /* Don't output any ASCII characters if this is a key release */
+       return _input_send_keycodes(config, keycode, count, !release);
+}
+
 int input_add_table(struct input_config *config, int left_keycode,
                    int right_keycode, const uchar *xlate, int num_entries)
 {
include/input.h +14 -0
index 71f3538..9942d6f 100644
@@ -76,6 +76,26 @@ struct stdio_dev;
 int input_send_keycodes(struct input_config *config, int keycode[], int count);
 
 /**
+ * Add a new keycode to an existing list of keycodes
+ *
+ * This can be used to handle keyboards which do their own scanning. An
+ * internal list of depressed keys is maintained by the input library. Then
+ * this function is called to add a new key to the list (when a 'make code' is
+ * received), or remove a key (when a 'break code' is received).
+ *
+ * This function looks after maintenance of the list of active keys, and calls
+ * input_send_keycodes() with its updated list.
+ *
+ * @param config       Input state
+ * @param new_keycode  New keycode to add/remove
+ * @param release      true if this key was released, false if depressed
+ * @return number of ascii characters sent, or 0 if none, or -1 for an

include/input.h struct stdio_dev;

Quoted 10 lines
include/input.h +6 -1
+ *     internal error
+ */
+int input_add_keycode(struct input_config *config, int new_keycode,
+                     bool release);
+
+/**
  * Add a new key translation table to the input
  *
  * @param config       Input state
--

Regards,
Bin

#33 lore raw

PATCH v2 15/28 input: Add a function to add a keycode to the existing set

Quoted 11 lines · Bin Meng

Hi Simon,

Quoted 6 lines · Simon Glass

Most keyboards can be scanned to produce a list of the keycodes which are depressed. With the i8042 keyboard this scanning is done internally and only the processed results are returned.

In this case, when a key is pressed, a 'make' code is sent. When the key is released an 'unmake' code is sent. This means that the driver needs to

nits: 'unmake' -> 'break'

Fixed.

Applied to u-boot-dm.

Quoted 23 lines
Quoted 9 lines

keep track of which keys are pressed. It also means that any protocol error can lead to stuck keys.

In order to support this type of keyboard, add a function when can be used to provide a single keycode and either add it to the list of what is pressed or remove it from the list. Then the normal input_send_keycodes() function can be used to actually do the decoding work.

Quoted 5 lines

Add debugging to display the ASCII characters written to the input queue also.

---

Quoted 6 lines

Changes in v2: None

 drivers/input/input.c | 46 ++++++++++++++++++++++++++++++++++++++++++----
 include/input.h       | 20 ++++++++++++++++++++
 2 files changed, 62 insertions(+), 4 deletions(-)
#34 lore raw

PATCH v2 16/28 input: Allow repeat filtering to be disabled

In reply to Simon Glass

Generally the input library handles processing of a list of scanned keys. Repeated keys need to be generated based on a timer in this case, since all that is provided is a list of keys current depressed.

Keyboards which do their own scanning will resend codes when they want to inject a repeating key. Provide a function which tells the input library to accept repeating keys and not to try to second-guess the caller.

---

Changes in v2: None

 drivers/input/input.c |  9 +++++++--
 include/input.h       | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
drivers/input/input.c +7 -2
index 530bf51..fc1c45c 100644
@@ -413,8 +413,8 @@ static int _input_send_keycodes(struct input_config *config, int keycode[],
 		 * insert another character if we later realise that we
 		 * have missed a repeat slot.
 		 */
-		is_repeat = config->repeat_rate_ms &&
-			(int)get_timer(config->next_repeat_ms) >= 0;
+		is_repeat = config->allow_repeats || (config->repeat_rate_ms &&
+			(int)get_timer(config->next_repeat_ms) >= 0);
 		if (!is_repeat)
 			return 0;
 	}
@@ -495,6 +495,11 @@ void input_set_delays(struct input_config *config, int repeat_delay_ms,
 	config->repeat_rate_ms = repeat_rate_ms;
 }
 
+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 ret;
include/input.h +19 -0
index 9942d6f..e56f500 100644
@@ -57,6 +57,7 @@ struct input_config {
 	 *		unknown
 	 */
 	int (*read_keys)(struct input_config *config);
+	bool allow_repeats;		/* Don't filter out repeats */
 	unsigned int next_repeat_ms;	/* Next time we repeat a key */
 	unsigned int repeat_delay_ms;	/* Time before autorepeat starts */
 	unsigned int repeat_rate_ms;	/* Autorepeat rate in ms */
@@ -143,6 +144,24 @@ void input_set_delays(struct input_config *config, int repeat_delay_ms,
 	       int repeat_rate_ms);
 
 /**
+ * Tell the input layer whether to allow the caller to determine repeats
+ *
+ * Generally the input library handles processing of a list of scanned keys.
+ * Repeated keys need to be generated based on a timer in this case, since all
+ * that is provided is a list of keys current depressed.
+ *
+ * Keyboards which do their own scanning will resend codes when they want to
+ * inject a repeating key. This function can be called at start-up to select
+ * this behaviour.
+ *
+ * @param config	Input state
+ * @param allow_repeats	true to repeat depressed keys every time
+ *			input_send_keycodes() is called, false to do normal
+ *			keyboard repeat processing with a timer.
+ */
+void input_allow_repeats(struct input_config *config, bool allow_repeats);
+
+/**
  * Set up the key map tables
  *
  * This must be called after input_init() or keycode decoding will not work.
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#35 lore raw

PATCH v2 16/28 input: Allow repeat filtering to be disabled

Quoted 72 lines · Simon Glass

Generally the input library handles processing of a list of scanned keys. Repeated keys need to be generated based on a timer in this case, since all that is provided is a list of keys current depressed.

Keyboards which do their own scanning will resend codes when they want to inject a repeating key. Provide a function which tells the input library to accept repeating keys and not to try to second-guess the caller.

---

Changes in v2: None

 drivers/input/input.c |  9 +++++++--
 include/input.h       | 19 +++++++++++++++++++
 2 files changed, 26 insertions(+), 2 deletions(-)
drivers/input/input.c +7 -2
index 530bf51..fc1c45c 100644
@@ -413,8 +413,8 @@ static int _input_send_keycodes(struct input_config *config, int keycode[],
                 * insert another character if we later realise that we
                 * have missed a repeat slot.
                 */
-               is_repeat = config->repeat_rate_ms &&
-                       (int)get_timer(config->next_repeat_ms) >= 0;
+               is_repeat = config->allow_repeats || (config->repeat_rate_ms &&
+                       (int)get_timer(config->next_repeat_ms) >= 0);
                if (!is_repeat)
                        return 0;
        }
@@ -495,6 +495,11 @@ void input_set_delays(struct input_config *config, int repeat_delay_ms,
        config->repeat_rate_ms = repeat_rate_ms;
 }
 
+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 ret;
include/input.h +13 -0
index 9942d6f..e56f500 100644
@@ -57,6 +57,7 @@ struct input_config {
         *              unknown
         */
        int (*read_keys)(struct input_config *config);
+       bool allow_repeats;             /* Don't filter out repeats */
        unsigned int next_repeat_ms;    /* Next time we repeat a key */
        unsigned int repeat_delay_ms;   /* Time before autorepeat starts */
        unsigned int repeat_rate_ms;    /* Autorepeat rate in ms */
@@ -143,6 +144,24 @@ void input_set_delays(struct input_config *config, int repeat_delay_ms,
               int repeat_rate_ms);
 
 /**
+ * Tell the input layer whether to allow the caller to determine repeats
+ *
+ * Generally the input library handles processing of a list of scanned keys.
+ * Repeated keys need to be generated based on a timer in this case, since all
+ * that is provided is a list of keys current depressed.
+ *
+ * Keyboards which do their own scanning will resend codes when they want to
+ * inject a repeating key. This function can be called at start-up to select
+ * this behaviour.
+ *
+ * @param config       Input state
+ * @param allow_repeats        true to repeat depressed keys every time

include/input.h void input_set_delays(struct input_config *config, int repeat_delay_ms,

Quoted 10 lines
include/input.h +6 -1
+ *                     input_send_keycodes() is called, false to do normal
+ *                     keyboard repeat processing with a timer.
+ */
+void input_allow_repeats(struct input_config *config, bool allow_repeats);
+
+/**
  * Set up the key map tables
  *
  * This must be called after input_init() or keycode decoding will not work.
--
#37 lore raw

PATCH v2 17/28 input: Support the German keymap

In reply to Simon Glass

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

---

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        | 107 ++++++++++++++++++++++++++++++++++++++-----
 drivers/input/tegra-kbc.c    |   2 +-
 include/input.h              |   3 +-
 5 files changed, 100 insertions(+), 16 deletions(-)
board/kosagi/novena/novena.c +1 -1
index 48cbb0f..0b61365 100644
@@ -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);
drivers/input/cros_ec_keyb.c +1 -1
index fe5caea..9bc4555 100644
@@ -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");
 
drivers/input/input.c +95 -12

122 lines not on this page · raw message

drivers/input/tegra-kbc.c +1 -1
index a7137f1..951cbb4 100644
@@ -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) {
include/input.h +2 -1
index e56f500..c1af259 100644
@@ -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.
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#38 lore raw

PATCH v2 17/28 input: Support the German keymap

Hi Simon,

Quoted 152 lines · Simon Glass

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

---

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        | 107 ++++++++++++++++++++++++++++++++++++++-----
 drivers/input/tegra-kbc.c    |   2 +-
 include/input.h              |   3 +-
 5 files changed, 100 insertions(+), 16 deletions(-)
board/kosagi/novena/novena.c +1 -1
index 48cbb0f..0b61365 100644
@@ -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);
drivers/input/cros_ec_keyb.c +1 -1
index fe5caea..9bc4555 100644
@@ -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");
 
drivers/input/input.c +80 -12
index fc1c45c..d0258a9 100644
@@ -78,6 +78,60 @@ 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 */
+};
+
 /*
  * Scan key code to ANSI 3.64 escape sequence table.  This table is
  * incomplete in that it does not include all possible extra keys.
@@ -500,21 +554,50 @@ 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)
 {
        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));
+       if (german) {
+               ret = input_add_table(config, -1, -1,
+                                     kbd_plain_xlate_german,
+                                     ARRAY_SIZE(kbd_plain_xlate_german));
+               if (ret)
+                       return ret;
+               ret = input_add_table(config, KEY_LEFTSHIFT, KEY_RIGHTSHIFT,
+                                     kbd_shift_xlate_german,
+                                     ARRAY_SIZE(kbd_shift_xlate_german));
+               if (ret)
+                       return ret;
+               ret = input_add_table(config, KEY_LEFTCTRL, KEY_RIGHTCTRL,
+                                     kbd_ctrl_xlate,
+                                     ARRAY_SIZE(kbd_ctrl_xlate));
+               if (ret)
+                       return ret;
+       } else {
+               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));

drivers/input/input.c void input_allow_repeats(struct input_config *config, bool allow_repeats) · line 595

Quoted 10 lines
drivers/input/input.c +10 -0
+               if (ret)
+                       return ret;
+               ret = input_add_table(config, KEY_LEFTCTRL, KEY_RIGHTCTRL,
+                                     kbd_ctrl_xlate,
+                                     ARRAY_SIZE(kbd_ctrl_xlate));
+               if (ret)
+                       return ret;
+               ret = input_add_table(config, -1, KEY_RIGHTALT,
+                                     kbd_right_alt_xlate_german,
+                                     ARRAY_SIZE(kbd_right_alt_xlate_german));

Why german tables are used here? A rebase conflict?

drivers/input/input.c void input_allow_repeats(struct input_config *config, bool allow_repeats) · line 597

Quoted 2 lines
drivers/input/input.c +2 -0
+               if (ret)
+                       return ret;

The above codes look quite verbose. Can we create another routine with these keymap tables as its parameter, and just call that routine here with US and German tables?

Quoted 26 lines
drivers/input/input.c +3 -0
+       }
+
+       return 0;
 }
 
 int input_init(struct input_config *config, int leds)
drivers/input/tegra-kbc.c +1 -1
index a7137f1..951cbb4 100644
@@ -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) {
include/input.h +0 -0
index e56f500..c1af259 100644
@@ -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.
  *

include/input.h void input_allow_repeats(struct input_config *config, bool allow_repeats);

Quoted 10 lines
include/input.h +2 -2
  * @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

#39 lore raw

PATCH v2 18/28 input: Adjust structure of code in process_modifier()

In reply to Simon Glass

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

---

Changes in v2: None

 drivers/input/input.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
drivers/input/input.c +14 -13
index d0258a9..3120d1e 100644
@@ -208,7 +208,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 */
@@ -223,6 +222,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;
@@ -234,19 +235,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;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#40 lore raw

PATCH v2 19/28 input: Handle caps lock

In reply to Simon Glass

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.

---

Changes in v2: None

 drivers/input/input.c | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
drivers/input/input.c +8 -5
index 3120d1e..0cb117f 100644
@@ -424,16 +424,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);
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#41 lore raw

PATCH v2 20/28 input: Allow updating of keyboard LEDs

In reply to Simon Glass

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

---

Changes in v2: None

 drivers/input/input.c |  9 +++++++++
 include/input.h       | 14 +++++++++++++-
 2 files changed, 22 insertions(+), 1 deletion(-)
drivers/input/input.c +9 -0
index 0cb117f..0f3495f 100644
@@ -247,6 +247,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;
 		}
 	}
 
@@ -558,6 +559,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)
 {
 	int ret;
include/input.h +13 -1
index c1af259..ad120e4 100644
@@ -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.
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#42 lore raw

PATCH v2 21/28 input: i8042: Convert to use the input library

In reply to Simon Glass

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.

---

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(-)
drivers/input/i8042.c +69 -424
index b1ada86..270805b 100644
@@ -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));
 }
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#43 lore raw

PATCH v2 22/28 input: Add a Kconfig option for the i8042 keyboard

In reply to Simon Glass

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

---

Changes in v2: None

 drivers/input/Kconfig | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/input/Kconfig +10 -0
index 447c4c3..d560328 100644
@@ -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.
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#44 lore raw

PATCH v2 23/28 x86: Add an i8042 device for boards that have it

In reply to Simon Glass

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.

---

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
arch/x86/Kconfig +6 -0
index 5e42d7d..72a66ea 100644
@@ -401,6 +401,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
arch/x86/dts/bayleybay.dts +1 -0
index d646987..58d97c8 100644
@@ -10,6 +10,7 @@
 #include <dt-bindings/interrupt-router/intel-irq.h>
 
 /include/ "skeleton.dtsi"
+/include/ "keyboard.dtsi"
 /include/ "serial.dtsi"
 /include/ "rtc.dtsi"
 
arch/x86/dts/chromebook_link.dts +5 -0
index 4291141..f09868b 100644
@@ -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>;
arch/x86/dts/keyboard.dtsi new file +5 -0
new file mode 100644
index 0000000..000751b
@@ -0,0 +1,5 @@
+/ {
+	keyboard {
+		compatible = "intel,i8042-keyboard";
+	};
+};
doc/device-tree-bindings/input/i8042.txt new file +10 -0
new file mode 100644
index 0000000..cd079c2
@@ -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.
include/configs/bayleybay.h +0 -3
index 1ba2998..ac6b45b 100644
@@ -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
include/configs/chromebox_panther.h +0 -2
index dc732b8..00fe26d 100644
@@ -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 */
include/configs/minnowmax.h +0 -1
index 53d86a2..c90af40 100644
@@ -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
include/configs/x86-chromebook.h +1 -1
index 2be8850..4ff8b94 100644
@@ -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"
 
include/configs/x86-common.h +1 -1
index 3f153f2..ff8fe0f 100644
@@ -147,7 +147,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
 
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#45 lore raw

PATCH v2 23/28 x86: Add an i8042 device for boards that have it

Quoted 161 lines · Simon Glass

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.

---

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
arch/x86/Kconfig +6 -0
index 5e42d7d..72a66ea 100644
@@ -401,6 +401,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
arch/x86/dts/bayleybay.dts +1 -0
index d646987..58d97c8 100644
@@ -10,6 +10,7 @@
 #include <dt-bindings/interrupt-router/intel-irq.h>
 
 /include/ "skeleton.dtsi"
+/include/ "keyboard.dtsi"
 /include/ "serial.dtsi"
 /include/ "rtc.dtsi"
 
arch/x86/dts/chromebook_link.dts +5 -0
index 4291141..f09868b 100644
@@ -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>;
arch/x86/dts/keyboard.dtsi new file +5 -0
new file mode 100644
index 0000000..000751b
@@ -0,0 +1,5 @@
+/ {
+       keyboard {
+               compatible = "intel,i8042-keyboard";
+       };
+};
doc/device-tree-bindings/input/i8042.txt new file +10 -0
new file mode 100644
index 0000000..cd079c2
@@ -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.
include/configs/bayleybay.h +0 -3
index 1ba2998..ac6b45b 100644
@@ -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
include/configs/chromebox_panther.h +0 -2
index dc732b8..00fe26d 100644
@@ -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 */
include/configs/minnowmax.h +0 -1
index 53d86a2..c90af40 100644
@@ -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
include/configs/x86-chromebook.h +1 -1
index 2be8850..4ff8b94 100644
@@ -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"
 
include/configs/x86-common.h +0 -0
index 3f153f2..ff8fe0f 100644

include/configs/x86-common.h

Quoted 9 lines
include/configs/x86-common.h +1 -2
@@ -147,7 +147,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
 
--
#46 lore raw

PATCH v2 24/28 Drop CONFIG_ISA_KEYBOARD

In reply to Simon Glass

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

---

Changes in v2: None

 README                   | 11 ++++++-----
 board/mpl/pip405/README  |  4 ----
 include/configs/MIP405.h |  5 -----
 include/configs/PIP405.h |  5 -----
 4 files changed, 6 insertions(+), 19 deletions(-)
README +6 -5
index 99f2b97..6cdf2f0 100644
@@ -1775,17 +1775,18 @@ 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.
 		Export function i8042_kbd_init, i8042_tstc and i8042_getc
 		for cfb_console. Supports cursor blinking.
 
+		CONFIG_CROS_EC_KEYB
+		Enables a Chrome OS keyboard using the CROS_EC interface.
+		This uses CROS_EC to communicate with a second microcontroller
+		which provides key scans on request.
+		See Kconfig help for available keyboard drivers.
+
 - Video support:
 		CONFIG_VIDEO
 
board/mpl/pip405/README +0 -4
index 012db1c..1b73dbe 100644
@@ -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
include/configs/MIP405.h +0 -5
index cb21b73..5bbc0de 100644
@@ -364,11 +364,6 @@
 #define CONFIG_ISO_PARTITION /* Experimental */
 
 /************************************************************
- * Keyboard support
- ************************************************************/
-#undef CONFIG_ISA_KEYBOARD
-
-/************************************************************
  * Video support
  ************************************************************/
 #define CONFIG_VIDEO			/*To enable video controller support */
include/configs/PIP405.h +0 -5
index c9d08e6..265fa12 100644
@@ -321,11 +321,6 @@
 #define CONFIG_ISO_PARTITION /* Experimental */
 
 /************************************************************
- * Keyboard support
- ************************************************************/
-#define CONFIG_ISA_KEYBOARD
-
-/************************************************************
  * Video support
  ************************************************************/
 #define CONFIG_VIDEO			/*To enable video controller support */
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#47 lore raw

PATCH v2 24/28 Drop CONFIG_ISA_KEYBOARD

README CBFS (Coreboot Filesystem) support · line 1788

Quoted 5 lines · Simon Glass
README +5 -0
+               CONFIG_CROS_EC_KEYB
+               Enables a Chrome OS keyboard using the CROS_EC interface.
+               This uses CROS_EC to communicate with a second microcontroller
+               which provides key scans on request.
+               See Kconfig help for available keyboard drivers.

This looks like an unrelated change.

#48 lore raw

PATCH v2 25/28 input: Convert i8042 to driver model

In reply to Simon Glass

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

---

Changes in v2: None

 drivers/input/Makefile |   2 +-
 drivers/input/i8042.c  | 109 ++++++++++++++++++++++++++++++++++---------------
 include/i8042.h        |   6 ---
 3 files changed, 76 insertions(+), 41 deletions(-)
drivers/input/Makefile +1 -1
index 9388dfe..5f15265 100644
@@ -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
drivers/input/i8042.c +75 -34

193 lines not on this page · raw message

include/i8042.h +0 -6
index e0afce1..9723b6a 100644
@@ -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_ */
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#49 lore raw

PATCH v2 26/28 i8042: Handle a duplicate power-on-reset response

In reply to Simon Glass

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.

---

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

 drivers/input/i8042.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/input/i8042.c +19 -2
index e5e2926..6d358b7 100644
@@ -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 {
+	QUICK_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 & QUICK_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 |= QUICK_DUP_POR;
+
 	/* Register the device. i8042_start() will be called soon */
 	input->dev = dev;
 	input->read_keys = i8042_kbd_check;
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#50 lore raw

PATCH v2 26/28 i8042: Handle a duplicate power-on-reset response

Hi Simon,

Quoted 6 lines · Simon Glass

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.

Other than one typo below:

Quoted 14 lines

---

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

 drivers/input/i8042.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/input/i8042.c +0 -0
index e5e2926..6d358b7 100644
@@ -15,13 +15,20 @@
 #include <keyboard.h>

drivers/input/i8042.c line 25

Quoted 10 lines
drivers/input/i8042.c +4 -0
 #include <asm/io.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /* defines */
 #define in8(p)         inb(p)
 #define out8(p, v)     outb(v, p)
 
+enum {
+       QUICK_DUP_POR   = 1 << 0,

typo: QUIRK

Quoted 53 lines
drivers/input/i8042.c +11 -2
+};
+
 /* 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 & QUICK_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;

drivers/input/i8042.c static int i8042_start(struct udevice *dev)

Quoted 10 lines
drivers/input/i8042.c +4 -1
        int ret;
 
+       if (fdtdec_get_bool(gd->fdt_blob, dev->of_offset,
+                           "intel,duplicate-por"))
+               priv->quirks |= QUICK_DUP_POR;
+
        /* Register the device. i8042_start() will be called soon */
        input->dev = dev;
        input->read_keys = i8042_kbd_check;
--

Regards,
Bin

#51 lore raw

PATCH v2 27/28 video: input: Clean up after i8042 conversion

In reply to Simon Glass

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.

---

Changes in v2: None

 README                      | 33 +++++++++++----------------------
 drivers/video/cfb_console.c | 20 ++++----------------
 2 files changed, 15 insertions(+), 38 deletions(-)
README +11 -22
index 6cdf2f0..6436fa4 100644
@@ -875,11 +875,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
@@ -1775,18 +1775,16 @@ 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.
-
-		CONFIG_CROS_EC_KEYB
-		Enables a Chrome OS keyboard using the CROS_EC interface.
-		This uses CROS_EC to communicate with a second microcontroller
-		which provides key scans on request.
 		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, driver model
+		instead.
+
 - Video support:
 		CONFIG_VIDEO
 
@@ -1846,15 +1844,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
drivers/video/cfb_console.c +4 -16
index 1b5c3e0..fde0bd4 100644
@@ -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
  */
 
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#52 lore raw

PATCH v2 28/28 input: Convert 'keyboard' driver to use input library

In reply to Simon Glass

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.

---

Changes in v2: None

 drivers/input/keyboard.c | 290 +++++++----------------------------------------
 include/keyboard.h       |   5 +
 2 files changed, 43 insertions(+), 252 deletions(-)
drivers/input/keyboard.c +38 -252
index be0f333..0836c63 100644
@@ -9,290 +9,76 @@
  ***********************************************************************/
 
 #include <common.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 | DEV_FLAGS_SYSTEM;
-	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);
 }
include/keyboard.h +5 -0
index 5216d59..6725e48 100644
@@ -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 */
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
#53 lore raw

v2 cover dm: input: Move keyboard drivers to driver model

In reply to Simon Glass

Hi Simon,

Quoted 22 lines · Simon Glass

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.

Quoted 7 lines

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.

With the v2 patch, the i8042 keyboard works on Intel Crown Bay. Besides the LEDs changes, I found the 'Caps Lock' and 'Num Lock' does not work. Is this related to missing update_leds()?

Quoted 3 lines

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

[snip]

Regards,
Bin

#54 lore raw

v2 cover dm: input: Move keyboard drivers to driver model

Hi Simon,

Quoted 28 lines · Bin Meng

Hi Simon,

Quoted 25 lines · Simon Glass

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.

Quoted 8 lines
Quoted 4 lines

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.

With the v2 patch, the i8042 keyboard works on Intel Crown Bay. Besides the LEDs changes, I found the 'Caps Lock' and 'Num Lock' does not work. Is this related to missing update_leds()?

To be more specific, the symptom is:

After pressing 'Caps Lock', the 'Caps Lock' LED does not light up. Pressing 'A' shows 'a' on the U-Boot serial console. After pressing 'Num Lock', the 'Num Lock' LED does not light up. Pressing any of the the digit numbers (0-9) buttons on the numeric keypad can show the numbers on the U-Boot serial console. I believe the correct behavior is that when 'Num Lock' is not lighted, pressing (0-9) should return nothing.

Quoted 7 lines
Quoted 4 lines

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

[snip]

Regards,
Bin

#55 lore raw

v2 cover dm: input: Move keyboard drivers to driver model

Hi Bin,

Quoted 42 lines · Bin Meng

Hi Simon,

Quoted 28 lines · Bin Meng

Hi Simon,

Quoted 25 lines · Simon Glass

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.

Quoted 8 lines
Quoted 4 lines

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.

With the v2 patch, the i8042 keyboard works on Intel Crown Bay. Besides the LEDs changes, I found the 'Caps Lock' and 'Num Lock' does not work. Is this related to missing update_leds()?

To be more specific, the symptom is:

Quoted 7 lines

After pressing 'Caps Lock', the 'Caps Lock' LED does not light up. Pressing 'A' shows 'a' on the U-Boot serial console. After pressing 'Num Lock', the 'Num Lock' LED does not light up. Pressing any of the the digit numbers (0-9) buttons on the numeric keypad can show the numbers on the U-Boot serial console. I believe the correct behavior is that when 'Num Lock' is not lighted, pressing (0-9) should return nothing.

I'm going to have another look at this but I don't have hardware to test with. My current plan is to merge the first half of the patches and then come back to you help resolve this bug.

Quoted 11 lines
Quoted 8 lines
Quoted 5 lines

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

[snip]

Regards,
Bin

Regards,
Simon