summaryrefslogtreecommitdiff
path: root/drivers/button
diff options
context:
space:
mode:
authorPhilippe Reynes <philippe.reynes@softathome.com>2020-07-24 18:19:45 +0200
committerSimon Glass <sjg@chromium.org>2020-07-28 19:30:39 -0600
commit30d66db78725e8396a3bd255cc51592c6cd7879d (patch)
tree90d70ab789bfb6e85522a989ca9631174bf45a60 /drivers/button
parent037a56d6b1e2a2ce45454b2629800ee5e7f6b46e (diff)
dm: button: add an uclass for button
Add a new uclass for button that implements two functions: - button_get_by_label - button_get_status Reviewed-by: Simon Glass <sjg@chromium.org> Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Diffstat (limited to 'drivers/button')
-rw-r--r--drivers/button/Kconfig12
-rw-r--r--drivers/button/Makefile5
-rw-r--r--drivers/button/button-uclass.c43
3 files changed, 60 insertions, 0 deletions
diff --git a/drivers/button/Kconfig b/drivers/button/Kconfig
new file mode 100644
index 0000000000..83018589e5
--- /dev/null
+++ b/drivers/button/Kconfig
@@ -0,0 +1,12 @@
+menu "Button Support"
+
+config BUTTON
+ bool "Enable button support"
+ depends on DM
+ help
+ Many boards have buttons which can be used to change behaviour (reset, ...).
+ U-Boot provides a uclass API to implement this feature. Button drivers
+ can provide access to board-specific buttons. Use of the device tree
+ for configuration is encouraged.
+
+endmenu
diff --git a/drivers/button/Makefile b/drivers/button/Makefile
new file mode 100644
index 0000000000..0b4c128cff
--- /dev/null
+++ b/drivers/button/Makefile
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
+
+obj-$(CONFIG_BUTTON) += button-uclass.o
diff --git a/drivers/button/button-uclass.c b/drivers/button/button-uclass.c
new file mode 100644
index 0000000000..1c742c265c
--- /dev/null
+++ b/drivers/button/button-uclass.c
@@ -0,0 +1,43 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
+ *
+ * Based on led-uclass.c
+ */
+
+#include <common.h>
+#include <button.h>
+#include <dm.h>
+#include <dm/uclass-internal.h>
+
+int button_get_by_label(const char *label, struct udevice **devp)
+{
+ struct udevice *dev;
+ struct uclass *uc;
+
+ uclass_id_foreach_dev(UCLASS_BUTTON, dev, uc) {
+ struct button_uc_plat *uc_plat = dev_get_uclass_platdata(dev);
+
+ /* Ignore the top-level button node */
+ if (uc_plat->label && !strcmp(label, uc_plat->label))
+ return uclass_get_device_tail(dev, 0, devp);
+ }
+
+ return -ENODEV;
+}
+
+enum button_state_t button_get_state(struct udevice *dev)
+{
+ struct button_ops *ops = button_get_ops(dev);
+
+ if (!ops->get_state)
+ return -ENOSYS;
+
+ return ops->get_state(dev);
+}
+
+UCLASS_DRIVER(button) = {
+ .id = UCLASS_BUTTON,
+ .name = "button",
+ .per_device_platdata_auto_alloc_size = sizeof(struct button_uc_plat),
+};