Skip to contentSkip to conversation

dm: button: add an uclass for button

PATCH New Philippe Reynes 2 participants 17 messages Jul 24, 2020 – Jul 28, 2020 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/8 dm: button: add an uclass for button

Add a new uclass for button that implements two functions:
- button_get_by_label
- button_get_status

---

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
drivers/Kconfig +2 -0
index 7a839fa..119e412 100644
@@ -16,6 +16,8 @@ source "drivers/block/Kconfig"
 
 source "drivers/bootcount/Kconfig"
 
+source "drivers/button/Kconfig"
+
 source "drivers/cache/Kconfig"
 
 source "drivers/clk/Kconfig"
drivers/Makefile +1 -0
index afd159e..2178871 100644
@@ -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/
drivers/button/Kconfig new file +12 -0
new file mode 100644
index 0000000..8301858
@@ -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
drivers/button/Makefile new file +5 -0
new file mode 100644
index 0000000..0b4c128
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (C) 2020 Philippe Reynes <[email protected]>
+
+obj-$(CONFIG_BUTTON) += button-uclass.o
drivers/button/button-uclass.c new file +43 -0

43 lines not on this page · raw message

include/button.h new file +59 -0

59 lines not on this page · raw message

include/dm/uclass-id.h +1 -0
index 7837d45..85c7149 100644
@@ -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 */
Signature · 1 line
2.7.4
#1 lore raw

PATCH v3 2/8 dm: button: add a driver for button driven by gpio

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

---
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
drivers/button/Kconfig +9 -0
index 8301858..6b3ec7e 100644
@@ -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
drivers/button/Makefile +1 -0
index 0b4c128..fcc10eb 100644
@@ -3,3 +3,4 @@
 # Copyright (C) 2020 Philippe Reynes <[email protected]>
 
 obj-$(CONFIG_BUTTON) += button-uclass.o
+obj-$(CONFIG_BUTTON_GPIO) += button-gpio.o
drivers/button/button-gpio.c new file +112 -0

112 lines not on this page · raw message

Signature · 1 line
2.7.4
#2 lore raw

PATCH v3 2/8 dm: button: add a driver for button driven by gpio

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

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

#3 lore raw

PATCH v3 3/8 cmd: button: add a new 'button' command

In reply to Philippe Reynes

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

---
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
cmd/Kconfig +11 -0
index bfe6c16..8ef87dc 100644
@@ -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
cmd/Makefile +1 -0
index 7952138..6e0086b 100644
@@ -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
cmd/button.c new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
2.7.4
#4 lore raw

PATCH v3 3/8 cmd: button: add a new 'button' command

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

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

#5 lore raw

PATCH v3 4/8 sandbox: dtsi: add buttons

In reply to Philippe Reynes

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

---
Changelog:
v3:
- update comptatible to "gpio-keys"
v2:
- no change

 arch/sandbox/dts/sandbox.dtsi | 14 ++++++++++++++
 1 file changed, 14 insertions(+)
arch/sandbox/dts/sandbox.dtsi +14 -0
index e1f68cd..c76ecc0 100644
@@ -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;
Signature · 1 line
2.7.4
#7 lore raw

PATCH v3 5/8 sandbox64: enable button

In reply to Philippe Reynes

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

---
Changelog:
v3:
- no change
v2:
- no change

 configs/sandbox64_defconfig | 2 ++
 1 file changed, 2 insertions(+)
configs/sandbox64_defconfig +2 -0
index dcf2f44..875a9dc 100644
@@ -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
Signature · 1 line
2.7.4
#9 lore raw

PATCH v3 6/8 sandbox: enable button

In reply to Philippe Reynes

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

---
Changelog:
v3:
- no change
v2:
- no change

 configs/sandbox_defconfig | 2 ++
 1 file changed, 2 insertions(+)
configs/sandbox_defconfig +2 -0
index 6059d66..18cecf5 100644
@@ -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
Signature · 1 line
2.7.4
#11 lore raw

PATCH v3 7/8 test/py: add tests for the button commands

In reply to Philippe Reynes

Adds tests for the button commands.

---
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
arch/sandbox/dts/test.dts +14 -0
index c3404c0..db8fa54 100644
@@ -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";
test/py/tests/test_button.py new file +19 -0
new file mode 100644
index 0000000..98067a9
@@ -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)
Signature · 1 line
2.7.4
#12 lore raw

PATCH v3 7/8 test/py: add tests for the button commands

Adds tests for the button commands.

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

#13 lore raw

PATCH v3 8/8 test: dm: add a test for class button

In reply to Philippe Reynes

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

---
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
test/dm/Makefile +1 -0
index b03c96d..42b46cc 100644
@@ -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
test/dm/button.c new file +74 -0

74 lines not on this page · raw message

Signature · 1 line
2.7.4
#14 lore raw

PATCH v3 8/8 test: dm: add a test for class button

Quoted 12 lines · Philippe Reynes

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

---
Changelog:
v3:
- no change
v2:
- new commit in the serie

Quoted 5 lines
 test/dm/Makefile |  1 +
 test/dm/button.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 test/dm/button.c
#15 lore raw

PATCH v3 1/8 dm: button: add an uclass for button

In reply to Philippe Reynes

Add a new uclass for button that implements two functions:
- button_get_by_label
- button_get_status

---

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!

A message that is not in the archive (sent off-list or not yet received): CAPnjgZ3=0cQAf3+u7JjVxWOfyoXb4_COjTnSUY9o9oY9DKc=5Q@mail.gmail.com

#17 lore raw

PATCH v3 8/8 test: dm: add a test for class button

Quoted 12 lines · Philippe Reynes

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

---
Changelog:
v3:
- no change
v2:
- new commit in the serie

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

Applied to u-boot-dm, thanks!