aboutsummaryrefslogtreecommitdiff
path: root/drivers/input
diff options
context:
space:
mode:
authorSimon Glass2015-10-18 21:17:10 -0600
committerSimon Glass2015-11-19 20:13:39 -0700
commite84421d8f3fe4f4b6956c9045b22729383620442 (patch)
tree81d2d363b1b9e72e05987bcd673e53e38c43d327 /drivers/input
parent34ab37eef5a5f8023abc657ab38f7b9fe11c38b3 (diff)
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. Signed-off-by: Simon Glass <sjg@chromium.org> Reviewed-by: Marek Vasut <marex@denx.de> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Diffstat (limited to 'drivers/input')
-rw-r--r--drivers/input/Kconfig9
-rw-r--r--drivers/input/Makefile2
-rw-r--r--drivers/input/keyboard-uclass.c91
3 files changed, 102 insertions, 0 deletions
diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
index bb00de7c576..447c4c3d385 100644
--- a/drivers/input/Kconfig
+++ b/drivers/input/Kconfig
@@ -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
diff --git a/drivers/input/Makefile b/drivers/input/Makefile
index b1161c5e1b4..9388dfe700a 100644
--- a/drivers/input/Makefile
+++ b/drivers/input/Makefile
@@ -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
diff --git a/drivers/input/keyboard-uclass.c b/drivers/input/keyboard-uclass.c
new file mode 100644
index 00000000000..e2ce25c6891
--- /dev/null
+++ b/drivers/input/keyboard-uclass.c
@@ -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;
+ 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),
+};