All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 1/8] dm: button: add an uclass for button
@ 2020-07-24 16:19 ` Philippe Reynes
  2020-07-24 16:19   ` [PATCH v3 2/8] dm: button: add a driver for button driven by gpio Philippe Reynes
                     ` (13 more replies)
  0 siblings, 14 replies; 17+ messages in thread
From: Philippe Reynes @ 2020-07-24 16:19 UTC (permalink / raw)
  To: u-boot

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>
---

Changelog:
v3:
- no change
v2:
- re-order include
- use uclass_id_foreach_dev
- add comments to enum button_state_t

 drivers/Kconfig                |  2 ++
 drivers/Makefile               |  1 +
 drivers/button/Kconfig         | 12 +++++++++
 drivers/button/Makefile        |  5 ++++
 drivers/button/button-uclass.c | 43 ++++++++++++++++++++++++++++++
 include/button.h               | 59 ++++++++++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h         |  1 +
 7 files changed, 123 insertions(+)
 create mode 100644 drivers/button/Kconfig
 create mode 100644 drivers/button/Makefile
 create mode 100644 drivers/button/button-uclass.c
 create mode 100644 include/button.h

diff --git a/drivers/Kconfig b/drivers/Kconfig
index 7a839fa..119e412 100644
--- a/drivers/Kconfig
+++ b/drivers/Kconfig
@@ -16,6 +16,8 @@ source "drivers/block/Kconfig"
 
 source "drivers/bootcount/Kconfig"
 
+source "drivers/button/Kconfig"
+
 source "drivers/cache/Kconfig"
 
 source "drivers/clk/Kconfig"
diff --git a/drivers/Makefile b/drivers/Makefile
index afd159e..2178871 100644
--- a/drivers/Makefile
+++ b/drivers/Makefile
@@ -1,5 +1,6 @@
 # SPDX-License-Identifier: GPL-2.0+
 
+obj-$(CONFIG_$(SPL_TPL_)BUTTON) += button/
 obj-$(CONFIG_$(SPL_TPL_)CACHE) += cache/
 obj-$(CONFIG_$(SPL_TPL_)CLK) += clk/
 obj-$(CONFIG_$(SPL_TPL_)DM) += core/
diff --git a/drivers/button/Kconfig b/drivers/button/Kconfig
new file mode 100644
index 0000000..8301858
--- /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 0000000..0b4c128
--- /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 0000000..1c742c2
--- /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),
+};
diff --git a/include/button.h b/include/button.h
new file mode 100644
index 0000000..688b63b
--- /dev/null
+++ b/include/button.h
@@ -0,0 +1,59 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
+ */
+
+#ifndef __BUTTON_H
+#define __BUTTON_H
+
+/**
+ * struct button_uc_plat - Platform data the uclass stores about each device
+ *
+ * @label:	Button label
+ */
+struct button_uc_plat {
+	const char *label;
+};
+
+/**
+ * enum button_state_t - State used for button
+ * - BUTTON_OFF - Button is not pressed
+ * - BUTTON_ON - Button is pressed
+ * - BUTTON_COUNT - Number of button state
+ */
+enum button_state_t {
+	BUTTON_OFF = 0,
+	BUTTON_ON = 1,
+	BUTTON_COUNT,
+};
+
+struct button_ops {
+	/**
+	 * get_state() - get the state of a button
+	 *
+	 * @dev:	button device to change
+	 * @return button state button_state_t, or -ve on error
+	 */
+	enum button_state_t (*get_state)(struct udevice *dev);
+};
+
+#define button_get_ops(dev)	((struct button_ops *)(dev)->driver->ops)
+
+/**
+ * button_get_by_label() - Find a button device by label
+ *
+ * @label:	button label to look up
+ * @devp:	Returns the associated device, if found
+ * @return 0 if found, -ENODEV if not found, other -ve on error
+ */
+int button_get_by_label(const char *label, struct udevice **devp);
+
+/**
+ * button_get_state() - get the state of a button
+ *
+ * @dev:	button device to change
+ * @return button state button_state_t, or -ve on error
+ */
+enum button_state_t button_get_state(struct udevice *dev);
+
+#endif
diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h
index 7837d45..85c7149 100644
--- a/include/dm/uclass-id.h
+++ b/include/dm/uclass-id.h
@@ -38,6 +38,7 @@ enum uclass_id {
 	UCLASS_BLK,		/* Block device */
 	UCLASS_BOARD,		/* Device information from hardware */
 	UCLASS_BOOTCOUNT,       /* Bootcount backing store */
+	UCLASS_BUTTON,		/* Button */
 	UCLASS_CACHE,		/* Cache controller */
 	UCLASS_CLK,		/* Clock source, e.g. used by peripherals */
 	UCLASS_CPU,		/* CPU, typically part of an SoC */
-- 
2.7.4

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

* [PATCH v3 2/8] dm: button: add a driver for button driven by gpio
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
@ 2020-07-24 16:19   ` Philippe Reynes
  2020-07-24 16:19   ` [PATCH v3 3/8] cmd: button: add a new 'button' command Philippe Reynes
                     ` (12 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Philippe Reynes @ 2020-07-24 16:19 UTC (permalink / raw)
  To: u-boot

Add a simple driver which allows use of buttons attached to GPIOs.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- change compatible to gpio-keys and gpio-keys-polled
  (feedback from Neil Armstrong)
v2:
- remove useless default in Kconfig
- re-order include
- fix condition in button_gpio_remove

 drivers/button/Kconfig       |   9 ++++
 drivers/button/Makefile      |   1 +
 drivers/button/button-gpio.c | 112 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 122 insertions(+)
 create mode 100644 drivers/button/button-gpio.c

diff --git a/drivers/button/Kconfig b/drivers/button/Kconfig
index 8301858..6b3ec7e 100644
--- a/drivers/button/Kconfig
+++ b/drivers/button/Kconfig
@@ -9,4 +9,13 @@ config BUTTON
 	  can provide access to board-specific buttons. Use of the device tree
 	  for configuration is encouraged.
 
+config BUTTON_GPIO
+	bool "Button gpio"
+	depends on BUTTON
+	help
+	  Enable support for buttons which are connected to GPIO lines. These
+	  GPIOs may be on the SoC or some other device which provides GPIOs.
+	  The GPIO driver must used driver model. Buttons are configured using
+	  the device tree.
+
 endmenu
diff --git a/drivers/button/Makefile b/drivers/button/Makefile
index 0b4c128..fcc10eb 100644
--- a/drivers/button/Makefile
+++ b/drivers/button/Makefile
@@ -3,3 +3,4 @@
 # Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
 
 obj-$(CONFIG_BUTTON) += button-uclass.o
+obj-$(CONFIG_BUTTON_GPIO) += button-gpio.o
diff --git a/drivers/button/button-gpio.c b/drivers/button/button-gpio.c
new file mode 100644
index 0000000..985ae7f
--- /dev/null
+++ b/drivers/button/button-gpio.c
@@ -0,0 +1,112 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
+ */
+
+#include <common.h>
+#include <button.h>
+#include <dm.h>
+#include <dm/lists.h>
+#include <dm/uclass-internal.h>
+#include <log.h>
+#include <asm/gpio.h>
+
+struct button_gpio_priv {
+	struct gpio_desc gpio;
+};
+
+static enum button_state_t button_gpio_get_state(struct udevice *dev)
+{
+	struct button_gpio_priv *priv = dev_get_priv(dev);
+	int ret;
+
+	if (!dm_gpio_is_valid(&priv->gpio))
+		return -EREMOTEIO;
+	ret = dm_gpio_get_value(&priv->gpio);
+	if (ret < 0)
+		return ret;
+
+	return ret ? BUTTON_ON : BUTTON_OFF;
+}
+
+static int button_gpio_probe(struct udevice *dev)
+{
+	struct button_uc_plat *uc_plat = dev_get_uclass_platdata(dev);
+	struct button_gpio_priv *priv = dev_get_priv(dev);
+	int ret;
+
+	/* Ignore the top-level button node */
+	if (!uc_plat->label)
+		return 0;
+
+	ret = gpio_request_by_name(dev, "gpios", 0, &priv->gpio, GPIOD_IS_IN);
+	if (ret)
+		return ret;
+
+	return 0;
+}
+
+static int button_gpio_remove(struct udevice *dev)
+{
+	/*
+	 * The GPIO driver may have already been removed. We will need to
+	 * address this more generally.
+	 */
+	if (!IS_ENABLED(CONFIG_SANDBOX)) {
+		struct button_gpio_priv *priv = dev_get_priv(dev);
+
+		if (dm_gpio_is_valid(&priv->gpio))
+			dm_gpio_free(dev, &priv->gpio);
+	}
+
+	return 0;
+}
+
+static int button_gpio_bind(struct udevice *parent)
+{
+	struct udevice *dev;
+	ofnode node;
+	int ret;
+
+	dev_for_each_subnode(node, parent) {
+		struct button_uc_plat *uc_plat;
+		const char *label;
+
+		label = ofnode_read_string(node, "label");
+		if (!label) {
+			debug("%s: node %s has no label\n", __func__,
+			      ofnode_get_name(node));
+			return -EINVAL;
+		}
+		ret = device_bind_driver_to_node(parent, "button_gpio",
+						 ofnode_get_name(node),
+						 node, &dev);
+		if (ret)
+			return ret;
+		uc_plat = dev_get_uclass_platdata(dev);
+		uc_plat->label = label;
+	}
+
+	return 0;
+}
+
+static const struct button_ops button_gpio_ops = {
+	.get_state	= button_gpio_get_state,
+};
+
+static const struct udevice_id button_gpio_ids[] = {
+	{ .compatible = "gpio-keys" },
+	{ .compatible = "gpio-keys-polled" },
+	{ }
+};
+
+U_BOOT_DRIVER(button_gpio) = {
+	.name		= "button_gpio",
+	.id		= UCLASS_BUTTON,
+	.of_match	= button_gpio_ids,
+	.ops		= &button_gpio_ops,
+	.priv_auto_alloc_size = sizeof(struct button_gpio_priv),
+	.bind		= button_gpio_bind,
+	.probe		= button_gpio_probe,
+	.remove		= button_gpio_remove,
+};
-- 
2.7.4

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

* [PATCH v3 3/8] cmd: button: add a new 'button' command
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
  2020-07-24 16:19   ` [PATCH v3 2/8] dm: button: add a driver for button driven by gpio Philippe Reynes
@ 2020-07-24 16:19   ` Philippe Reynes
  2020-07-24 16:19   ` [PATCH v3 4/8] sandbox: dtsi: add buttons Philippe Reynes
                     ` (11 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Philippe Reynes @ 2020-07-24 16:19 UTC (permalink / raw)
  To: u-boot

Adds a command 'button' that provides the list of buttons
supported by the board, and the state of a button.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- no change
v2
- no change

 cmd/Kconfig  | 11 ++++++++
 cmd/Makefile |  1 +
 cmd/button.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 98 insertions(+)
 create mode 100644 cmd/button.c

diff --git a/cmd/Kconfig b/cmd/Kconfig
index bfe6c16..8ef87dc 100644
--- a/cmd/Kconfig
+++ b/cmd/Kconfig
@@ -1679,6 +1679,17 @@ config CMD_BLOCK_CACHE
 	  during development, but also allows the cache to be disabled when
 	  it might hurt performance (e.g. when using the ums command).
 
+config CMD_BUTTON
+	bool "button"
+	depends on BUTTON
+	default y if BUTTON
+	help
+	  Enable the 'button' command which allows to get the status of
+	  buttons supported by the board. The buttonss can be listed with
+	  'button list' and state can be known with 'button <label>'.
+	  Any button drivers can be controlled with this command, e.g.
+	  button_gpio.
+
 config CMD_CACHE
 	bool "icache or dcache"
 	help
diff --git a/cmd/Makefile b/cmd/Makefile
index 7952138..6e0086b 100644
--- a/cmd/Makefile
+++ b/cmd/Makefile
@@ -33,6 +33,7 @@ obj-$(CONFIG_CMD_BOOTSTAGE) += bootstage.o
 obj-$(CONFIG_CMD_BOOTZ) += bootz.o
 obj-$(CONFIG_CMD_BOOTI) += booti.o
 obj-$(CONFIG_CMD_BTRFS) += btrfs.o
+obj-$(CONFIG_CMD_BUTTON) += button.o
 obj-$(CONFIG_CMD_CACHE) += cache.o
 obj-$(CONFIG_CMD_CBFS) += cbfs.o
 obj-$(CONFIG_CMD_CLK) += clk.o
diff --git a/cmd/button.c b/cmd/button.c
new file mode 100644
index 0000000..84ad165
--- /dev/null
+++ b/cmd/button.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
+ *
+ * Based on led.c
+ */
+
+#include <common.h>
+#include <command.h>
+#include <dm.h>
+#include <button.h>
+#include <dm/uclass-internal.h>
+
+static const char *const state_label[] = {
+	[BUTTON_OFF]	= "off",
+	[BUTTON_ON]	= "on",
+};
+
+static int show_button_state(struct udevice *dev)
+{
+	int ret;
+
+	ret = button_get_state(dev);
+	if (ret >= BUTTON_COUNT)
+		ret = -EINVAL;
+	if (ret >= 0)
+		printf("%s\n", state_label[ret]);
+
+	return ret;
+}
+
+static int list_buttons(void)
+{
+	struct udevice *dev;
+	int ret;
+
+	for (uclass_find_first_device(UCLASS_BUTTON, &dev);
+	     dev;
+	     uclass_find_next_device(&dev)) {
+		struct button_uc_plat *plat = dev_get_uclass_platdata(dev);
+
+		if (!plat->label)
+			continue;
+		printf("%-15s ", plat->label);
+		if (device_active(dev)) {
+			ret = show_button_state(dev);
+			if (ret < 0)
+				printf("Error %d\n", ret);
+		} else {
+			printf("<inactive>\n");
+		}
+	}
+
+	return 0;
+}
+
+int do_button(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+	const char *button_label;
+	struct udevice *dev;
+	int ret;
+
+	/* Validate arguments */
+	if (argc < 2)
+		return CMD_RET_USAGE;
+	button_label = argv[1];
+	if (strncmp(button_label, "list", 4) == 0)
+		return list_buttons();
+
+	ret = button_get_by_label(button_label, &dev);
+	if (ret) {
+		printf("Button '%s' not found (err=%d)\n", button_label, ret);
+		return CMD_RET_FAILURE;
+	}
+
+	ret = show_button_state(dev);
+
+	return 0;
+}
+
+U_BOOT_CMD(
+	button, 4, 1, do_button,
+	"manage buttons",
+	"<button_label> \tGet button state\n"
+	"button list\t\tShow a list of buttons"
+);
-- 
2.7.4

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

* [PATCH v3 4/8] sandbox: dtsi: add buttons
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
  2020-07-24 16:19   ` [PATCH v3 2/8] dm: button: add a driver for button driven by gpio Philippe Reynes
  2020-07-24 16:19   ` [PATCH v3 3/8] cmd: button: add a new 'button' command Philippe Reynes
@ 2020-07-24 16:19   ` Philippe Reynes
  2020-07-24 16:19   ` [PATCH v3 5/8] sandbox64: enable button Philippe Reynes
                     ` (10 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Philippe Reynes @ 2020-07-24 16:19 UTC (permalink / raw)
  To: u-boot

Adds two buttons on sandbox so button framework may be tested.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- update comptatible to "gpio-keys"
v2:
- no change

 arch/sandbox/dts/sandbox.dtsi | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/arch/sandbox/dts/sandbox.dtsi b/arch/sandbox/dts/sandbox.dtsi
index e1f68cd..c76ecc0 100644
--- a/arch/sandbox/dts/sandbox.dtsi
+++ b/arch/sandbox/dts/sandbox.dtsi
@@ -15,6 +15,20 @@
 		#sound-dai-cells = <1>;
 	};
 
+	buttons {
+		compatible = "gpio-keys";
+
+		summer {
+			gpios = <&gpio_a 3 0>;
+			label = "summer";
+		};
+
+		christmas {
+			gpios = <&gpio_a 4 0>;
+			label = "christmas";
+		};
+	};
+
 	gpio_a: gpios at 0 {
 		u-boot,dm-pre-reloc;
 		gpio-controller;
-- 
2.7.4

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

* [PATCH v3 5/8] sandbox64: enable button
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
                     ` (2 preceding siblings ...)
  2020-07-24 16:19   ` [PATCH v3 4/8] sandbox: dtsi: add buttons Philippe Reynes
@ 2020-07-24 16:19   ` Philippe Reynes
  2020-07-24 16:19   ` [PATCH v3 6/8] sandbox: " Philippe Reynes
                     ` (9 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Philippe Reynes @ 2020-07-24 16:19 UTC (permalink / raw)
  To: u-boot

Enable the support of button (driver and command) on sandbox64.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- no change
v2:
- no change

 configs/sandbox64_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig
index dcf2f44..875a9dc 100644
--- a/configs/sandbox64_defconfig
+++ b/configs/sandbox64_defconfig
@@ -92,6 +92,8 @@ CONFIG_ADC=y
 CONFIG_ADC_SANDBOX=y
 CONFIG_AXI=y
 CONFIG_AXI_SANDBOX=y
+CONFIG_BUTTON=y
+CONFIG_BUTTON_GPIO=y
 CONFIG_CLK=y
 CONFIG_CPU=y
 CONFIG_DM_DEMO=y
-- 
2.7.4

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

* [PATCH v3 6/8] sandbox: enable button
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
                     ` (3 preceding siblings ...)
  2020-07-24 16:19   ` [PATCH v3 5/8] sandbox64: enable button Philippe Reynes
@ 2020-07-24 16:19   ` Philippe Reynes
  2020-07-24 16:19   ` [PATCH v3 7/8] test/py: add tests for the button commands Philippe Reynes
                     ` (8 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Philippe Reynes @ 2020-07-24 16:19 UTC (permalink / raw)
  To: u-boot

Enable the support of button (driver and command) on sandbox.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- no change
v2:
- no change

 configs/sandbox_defconfig | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 6059d66..18cecf5 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -106,6 +106,8 @@ CONFIG_AXI_SANDBOX=y
 CONFIG_BOOTCOUNT_LIMIT=y
 CONFIG_DM_BOOTCOUNT=y
 CONFIG_DM_BOOTCOUNT_RTC=y
+CONFIG_BUTTON=y
+CONFIG_BUTTON_GPIO=y
 CONFIG_CLK=y
 CONFIG_CLK_COMPOSITE_CCF=y
 CONFIG_SANDBOX_CLK_CCF=y
-- 
2.7.4

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

* [PATCH v3 7/8] test/py: add tests for the button commands
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
                     ` (4 preceding siblings ...)
  2020-07-24 16:19   ` [PATCH v3 6/8] sandbox: " Philippe Reynes
@ 2020-07-24 16:19   ` Philippe Reynes
  2020-07-24 16:19   ` [PATCH v3 8/8] test: dm: add a test for class button Philippe Reynes
                     ` (7 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Philippe Reynes @ 2020-07-24 16:19 UTC (permalink / raw)
  To: u-boot

Adds tests for the button commands.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- update compatible to "gpio-keys"
v2:
- no change (button uclass test is added in another commit

 arch/sandbox/dts/test.dts    | 14 ++++++++++++++
 test/py/tests/test_button.py | 19 +++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 test/py/tests/test_button.py

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index c3404c0..db8fa54 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -51,6 +51,20 @@
 		#sound-dai-cells = <1>;
 	};
 
+	buttons {
+		compatible = "gpio-keys";
+
+		summer {
+			gpios = <&gpio_a 3 0>;
+			label = "summer";
+		};
+
+		christmas {
+			gpios = <&gpio_a 4 0>;
+			label = "christmas";
+		};
+	};
+
 	cros_ec: cros-ec {
 		reg = <0 0>;
 		compatible = "google,cros-ec-sandbox";
diff --git a/test/py/tests/test_button.py b/test/py/tests/test_button.py
new file mode 100644
index 0000000..98067a9
--- /dev/null
+++ b/test/py/tests/test_button.py
@@ -0,0 +1,19 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+import pytest
+
+ at pytest.mark.boardspec('sandbox')
+ at pytest.mark.buildconfigspec('cmd_button')
+def test_button_exit_statuses(u_boot_console):
+    """Test that non-input button commands correctly return the command
+    success/failure status."""
+
+    expected_response = 'rc:0'
+    response = u_boot_console.run_command('button list; echo rc:$?')
+    assert(expected_response in response)
+    response = u_boot_console.run_command('button summer; echo rc:$?')
+    assert(expected_response in response)
+
+    expected_response = 'rc:1'
+    response = u_boot_console.run_command('button nonexistent-button; echo rc:$?')
+    assert(expected_response in response)
-- 
2.7.4

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

* [PATCH v3 8/8] test: dm: add a test for class button
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
                     ` (5 preceding siblings ...)
  2020-07-24 16:19   ` [PATCH v3 7/8] test/py: add tests for the button commands Philippe Reynes
@ 2020-07-24 16:19   ` Philippe Reynes
  2020-07-28 18:57     ` Simon Glass
  2020-07-28 18:58     ` Simon Glass
  2020-07-28 18:57   ` [PATCH v3 7/8] test/py: add tests for the button commands Simon Glass
                     ` (6 subsequent siblings)
  13 siblings, 2 replies; 17+ messages in thread
From: Philippe Reynes @ 2020-07-24 16:19 UTC (permalink / raw)
  To: u-boot

Add a test to confirm that we can read button state
using the button-gpio driver.

Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- no change
v2:
- new commit in the serie

 test/dm/Makefile |  1 +
 test/dm/button.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 test/dm/button.c

diff --git a/test/dm/Makefile b/test/dm/Makefile
index b03c96d..42b46cc 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -19,6 +19,7 @@ obj-$(CONFIG_ACPIGEN) += acpi_dp.o
 obj-$(CONFIG_SOUND) += audio.o
 obj-$(CONFIG_BLK) += blk.o
 obj-$(CONFIG_BOARD) += board.o
+obj-$(CONFIG_BUTTON) += button.o
 obj-$(CONFIG_DM_BOOTCOUNT) += bootcount.o
 obj-$(CONFIG_CLK) += clk.o clk_ccf.o
 obj-$(CONFIG_DEVRES) += devres.o
diff --git a/test/dm/button.c b/test/dm/button.c
new file mode 100644
index 0000000..890f470
--- /dev/null
+++ b/test/dm/button.c
@@ -0,0 +1,74 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com>
+ *
+ * Based on led.c
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <button.h>
+#include <asm/gpio.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+/* Base test of the button uclass */
+static int dm_test_button_base(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+
+	/* Get the top-level device */
+	ut_assertok(uclass_get_device(UCLASS_BUTTON, 0, &dev));
+	ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, &dev));
+	ut_assertok(uclass_get_device(UCLASS_BUTTON, 2, &dev));
+	ut_asserteq(-ENODEV, uclass_get_device(UCLASS_BUTTON, 3, &dev));
+
+	return 0;
+}
+DM_TEST(dm_test_button_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test of the button uclass using the button_gpio driver */
+static int dm_test_button_gpio(struct unit_test_state *uts)
+{
+	const int offset = 3;
+	struct udevice *dev, *gpio;
+
+	/*
+	 * Check that we can manipulate an BUTTON. BUTTON 1 is connected to GPIO
+	 * bank gpio_a, offset 3.
+	 */
+	ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, &dev));
+	ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio));
+
+	ut_asserteq(0, sandbox_gpio_set_value(gpio, offset, 0));
+	ut_asserteq(0, sandbox_gpio_get_value(gpio, offset));
+	ut_asserteq(BUTTON_OFF, button_get_state(dev));
+
+	ut_asserteq(0, sandbox_gpio_set_value(gpio, offset, 1));
+	ut_asserteq(1, sandbox_gpio_get_value(gpio, offset));
+	ut_asserteq(BUTTON_ON, button_get_state(dev));
+
+	return 0;
+}
+DM_TEST(dm_test_button_gpio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test obtaining an BUTTON by label */
+static int dm_test_button_label(struct unit_test_state *uts)
+{
+	struct udevice *dev, *cmp;
+
+	ut_assertok(button_get_by_label("summer", &dev));
+	ut_asserteq(1, device_active(dev));
+	ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, &cmp));
+	ut_asserteq_ptr(dev, cmp);
+
+	ut_assertok(button_get_by_label("christmas", &dev));
+	ut_asserteq(1, device_active(dev));
+	ut_assertok(uclass_get_device(UCLASS_BUTTON, 2, &cmp));
+	ut_asserteq_ptr(dev, cmp);
+
+	ut_asserteq(-ENODEV, button_get_by_label("spring", &dev));
+
+	return 0;
+}
+DM_TEST(dm_test_button_label, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
-- 
2.7.4

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

* [PATCH v3 8/8] test: dm: add a test for class button
  2020-07-24 16:19   ` [PATCH v3 8/8] test: dm: add a test for class button Philippe Reynes
@ 2020-07-28 18:57     ` Simon Glass
  2020-07-28 18:58     ` Simon Glass
  1 sibling, 0 replies; 17+ messages in thread
From: Simon Glass @ 2020-07-28 18:57 UTC (permalink / raw)
  To: u-boot

On Fri, 24 Jul 2020 at 10:20, Philippe Reynes
<philippe.reynes@softathome.com> wrote:
>
> Add a test to confirm that we can read button state
> using the button-gpio driver.
>
> Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
> ---
> Changelog:
> v3:
> - no change
> v2:
> - new commit in the serie
>
>  test/dm/Makefile |  1 +
>  test/dm/button.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 75 insertions(+)
>  create mode 100644 test/dm/button.c
>

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

Applied to u-boot-dm, thanks!

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

* [PATCH v3 7/8] test/py: add tests for the button commands
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
                     ` (6 preceding siblings ...)
  2020-07-24 16:19   ` [PATCH v3 8/8] test: dm: add a test for class button Philippe Reynes
@ 2020-07-28 18:57   ` Simon Glass
  2020-07-28 18:57   ` [PATCH v3 6/8] sandbox: enable button Simon Glass
                     ` (5 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Simon Glass @ 2020-07-28 18:57 UTC (permalink / raw)
  To: u-boot

Adds tests for the button commands.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- update compatible to "gpio-keys"
v2:
- no change (button uclass test is added in another commit

 arch/sandbox/dts/test.dts    | 14 ++++++++++++++
 test/py/tests/test_button.py | 19 +++++++++++++++++++
 2 files changed, 33 insertions(+)
 create mode 100644 test/py/tests/test_button.py

Applied to u-boot-dm, thanks!

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

* [PATCH v3 6/8] sandbox: enable button
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
                     ` (7 preceding siblings ...)
  2020-07-28 18:57   ` [PATCH v3 7/8] test/py: add tests for the button commands Simon Glass
@ 2020-07-28 18:57   ` Simon Glass
  2020-07-28 18:57   ` [PATCH v3 5/8] sandbox64: " Simon Glass
                     ` (4 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Simon Glass @ 2020-07-28 18:57 UTC (permalink / raw)
  To: u-boot

Enable the support of button (driver and command) on sandbox.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- no change
v2:
- no change

 configs/sandbox_defconfig | 2 ++
 1 file changed, 2 insertions(+)

Applied to u-boot-dm, thanks!

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

* [PATCH v3 5/8] sandbox64: enable button
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
                     ` (8 preceding siblings ...)
  2020-07-28 18:57   ` [PATCH v3 6/8] sandbox: enable button Simon Glass
@ 2020-07-28 18:57   ` Simon Glass
  2020-07-28 18:57   ` [PATCH v3 4/8] sandbox: dtsi: add buttons Simon Glass
                     ` (3 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Simon Glass @ 2020-07-28 18:57 UTC (permalink / raw)
  To: u-boot

Enable the support of button (driver and command) on sandbox64.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- no change
v2:
- no change

 configs/sandbox64_defconfig | 2 ++
 1 file changed, 2 insertions(+)

Applied to u-boot-dm, thanks!

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

* [PATCH v3 4/8] sandbox: dtsi: add buttons
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
                     ` (9 preceding siblings ...)
  2020-07-28 18:57   ` [PATCH v3 5/8] sandbox64: " Simon Glass
@ 2020-07-28 18:57   ` Simon Glass
  2020-07-28 18:57   ` [PATCH v3 3/8] cmd: button: add a new 'button' command Simon Glass
                     ` (2 subsequent siblings)
  13 siblings, 0 replies; 17+ messages in thread
From: Simon Glass @ 2020-07-28 18:57 UTC (permalink / raw)
  To: u-boot

Adds two buttons on sandbox so button framework may be tested.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- update comptatible to "gpio-keys"
v2:
- no change

 arch/sandbox/dts/sandbox.dtsi | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

Applied to u-boot-dm, thanks!

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

* [PATCH v3 3/8] cmd: button: add a new 'button' command
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
                     ` (10 preceding siblings ...)
  2020-07-28 18:57   ` [PATCH v3 4/8] sandbox: dtsi: add buttons Simon Glass
@ 2020-07-28 18:57   ` Simon Glass
  2020-07-28 18:57   ` [PATCH v3 2/8] dm: button: add a driver for button driven by gpio Simon Glass
  2020-07-28 18:57   ` [PATCH v3 1/8] dm: button: add an uclass for button Simon Glass
  13 siblings, 0 replies; 17+ messages in thread
From: Simon Glass @ 2020-07-28 18:57 UTC (permalink / raw)
  To: u-boot

Adds a command 'button' that provides the list of buttons
supported by the board, and the state of a button.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- no change
v2
- no change

 cmd/Kconfig  | 11 ++++++++
 cmd/Makefile |  1 +
 cmd/button.c | 86 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 98 insertions(+)
 create mode 100644 cmd/button.c

Applied to u-boot-dm, thanks!

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

* [PATCH v3 2/8] dm: button: add a driver for button driven by gpio
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
                     ` (11 preceding siblings ...)
  2020-07-28 18:57   ` [PATCH v3 3/8] cmd: button: add a new 'button' command Simon Glass
@ 2020-07-28 18:57   ` Simon Glass
  2020-07-28 18:57   ` [PATCH v3 1/8] dm: button: add an uclass for button Simon Glass
  13 siblings, 0 replies; 17+ messages in thread
From: Simon Glass @ 2020-07-28 18:57 UTC (permalink / raw)
  To: u-boot

Add a simple driver which allows use of buttons attached to GPIOs.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
---
Changelog:
v3:
- change compatible to gpio-keys and gpio-keys-polled
  (feedback from Neil Armstrong)
v2:
- remove useless default in Kconfig
- re-order include
- fix condition in button_gpio_remove

 drivers/button/Kconfig       |   9 ++++
 drivers/button/Makefile      |   1 +
 drivers/button/button-gpio.c | 112 +++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 122 insertions(+)
 create mode 100644 drivers/button/button-gpio.c

Applied to u-boot-dm, thanks!

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

* [PATCH v3 1/8] dm: button: add an uclass for button
  2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
                     ` (12 preceding siblings ...)
  2020-07-28 18:57   ` [PATCH v3 2/8] dm: button: add a driver for button driven by gpio Simon Glass
@ 2020-07-28 18:57   ` Simon Glass
  13 siblings, 0 replies; 17+ messages in thread
From: Simon Glass @ 2020-07-28 18:57 UTC (permalink / raw)
  To: u-boot

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>
---

Changelog:
v3:
- no change
v2:
- re-order include
- use uclass_id_foreach_dev
- add comments to enum button_state_t

 drivers/Kconfig                |  2 ++
 drivers/Makefile               |  1 +
 drivers/button/Kconfig         | 12 +++++++++
 drivers/button/Makefile        |  5 ++++
 drivers/button/button-uclass.c | 43 ++++++++++++++++++++++++++++++
 include/button.h               | 59 ++++++++++++++++++++++++++++++++++++++++++
 include/dm/uclass-id.h         |  1 +
 7 files changed, 123 insertions(+)
 create mode 100644 drivers/button/Kconfig
 create mode 100644 drivers/button/Makefile
 create mode 100644 drivers/button/button-uclass.c
 create mode 100644 include/button.h

Applied to u-boot-dm, thanks!

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

* [PATCH v3 8/8] test: dm: add a test for class button
  2020-07-24 16:19   ` [PATCH v3 8/8] test: dm: add a test for class button Philippe Reynes
  2020-07-28 18:57     ` Simon Glass
@ 2020-07-28 18:58     ` Simon Glass
  1 sibling, 0 replies; 17+ messages in thread
From: Simon Glass @ 2020-07-28 18:58 UTC (permalink / raw)
  To: u-boot

On Fri, 24 Jul 2020 at 10:20, Philippe Reynes
<philippe.reynes@softathome.com> wrote:
>
> Add a test to confirm that we can read button state
> using the button-gpio driver.
>
> Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
> ---
> Changelog:
> v3:
> - no change
> v2:
> - new commit in the serie
>
>  test/dm/Makefile |  1 +
>  test/dm/button.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 75 insertions(+)
>  create mode 100644 test/dm/button.c
>

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

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

end of thread, other threads:[~2020-07-28 18:58 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <CAPnjgZ3=0cQAf3+u7JjVxWOfyoXb4_COjTnSUY9o9oY9DKc=5Q@mail.gmail.com>
2020-07-24 16:19 ` [PATCH v3 1/8] dm: button: add an uclass for button Philippe Reynes
2020-07-24 16:19   ` [PATCH v3 2/8] dm: button: add a driver for button driven by gpio Philippe Reynes
2020-07-24 16:19   ` [PATCH v3 3/8] cmd: button: add a new 'button' command Philippe Reynes
2020-07-24 16:19   ` [PATCH v3 4/8] sandbox: dtsi: add buttons Philippe Reynes
2020-07-24 16:19   ` [PATCH v3 5/8] sandbox64: enable button Philippe Reynes
2020-07-24 16:19   ` [PATCH v3 6/8] sandbox: " Philippe Reynes
2020-07-24 16:19   ` [PATCH v3 7/8] test/py: add tests for the button commands Philippe Reynes
2020-07-24 16:19   ` [PATCH v3 8/8] test: dm: add a test for class button Philippe Reynes
2020-07-28 18:57     ` Simon Glass
2020-07-28 18:58     ` Simon Glass
2020-07-28 18:57   ` [PATCH v3 7/8] test/py: add tests for the button commands Simon Glass
2020-07-28 18:57   ` [PATCH v3 6/8] sandbox: enable button Simon Glass
2020-07-28 18:57   ` [PATCH v3 5/8] sandbox64: " Simon Glass
2020-07-28 18:57   ` [PATCH v3 4/8] sandbox: dtsi: add buttons Simon Glass
2020-07-28 18:57   ` [PATCH v3 3/8] cmd: button: add a new 'button' command Simon Glass
2020-07-28 18:57   ` [PATCH v3 2/8] dm: button: add a driver for button driven by gpio Simon Glass
2020-07-28 18:57   ` [PATCH v3 1/8] dm: button: add an uclass for button Simon Glass

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