From b398a9a7fa47edd24de23d1fa8f06a44b942891d Mon Sep 17 00:00:00 2001 From: Joseph Chen Date: Mon, 18 Sep 2017 19:41:54 +0800 Subject: [PATCH] dm: input: add implementation of driver model key uclass Change-Id: I379b694dfaee14ed23cc7abfa05aff77933bb725 Signed-off-by: Joseph Chen --- drivers/input/Kconfig | 6 ++++++ drivers/input/Makefile | 1 + drivers/input/key-uclass.c | 23 +++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/key.h | 22 ++++++++++++++++++++++ 5 files changed, 53 insertions(+) create mode 100644 drivers/input/key-uclass.c create mode 100644 include/key.h diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig index b3873c140d..1ea90bf9d9 100644 --- a/drivers/input/Kconfig +++ b/drivers/input/Kconfig @@ -7,6 +7,12 @@ config DM_KEYBOARD includes methods to start/stop the device, check for available input and update LEDs if the keyboard has them. +config DM_KEY + bool "Enable driver model key support" + depends on DM + help + This adds a simple uclass for key. + config CROS_EC_KEYB bool "Enable Chrome OS EC keyboard support" help diff --git a/drivers/input/Makefile b/drivers/input/Makefile index 9109ac6dba..dfe46a037d 100644 --- a/drivers/input/Makefile +++ b/drivers/input/Makefile @@ -6,6 +6,7 @@ # obj-$(CONFIG_DM_KEYBOARD) += keyboard-uclass.o +obj-$(CONFIG_DM_KEY) += key-uclass.o obj-$(CONFIG_I8042_KEYB) += i8042.o obj-$(CONFIG_TEGRA_KEYBOARD) += tegra-kbc.o diff --git a/drivers/input/key-uclass.c b/drivers/input/key-uclass.c new file mode 100644 index 0000000000..0d38fbda81 --- /dev/null +++ b/drivers/input/key-uclass.c @@ -0,0 +1,23 @@ +/* + * (C) Copyright 2017 Rockchip Electronics Co., Ltd + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#include +#include + +int key_read(struct udevice *dev) +{ + const struct dm_key_ops *ops = dev_get_driver_ops(dev); + + if (!ops || !ops->read) + return -ENOSYS; + + return ops->read(dev); +} + +UCLASS_DRIVER(key) = { + .id = UCLASS_KEY, + .name = "key", +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index d3d11c86de..e3b9e5b0c9 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -90,6 +90,7 @@ enum uclass_id { UCLASS_VIDEO_CONSOLE, /* Text console driver for video device */ UCLASS_WDT, /* Watchdot Timer driver */ UCLASS_FG, + UCLASS_KEY, UCLASS_COUNT, UCLASS_INVALID = -1, diff --git a/include/key.h b/include/key.h new file mode 100644 index 0000000000..56ae16681f --- /dev/null +++ b/include/key.h @@ -0,0 +1,22 @@ +/* + * (C) Copyright 2017 Rockchip Electronics Co., Ltd + * + * SPDX-License-Identifier: GPL-2.0+ + */ + +#ifndef _KEY_H_ +#define _KEY_H_ + +enum key_state { + KEY_PRESS_NONE, + KEY_PRESS_UP, + KEY_PRESS_DOWN, +}; + +struct dm_key_ops { + int (*read)(struct udevice *dev); +}; + +int key_read(struct udevice *dev); + +#endif