dm: button: add an uclass for button
PATCH v2 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:
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
@@ -14,6 +14,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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v2 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:
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 | 111 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 drivers/button/button-gpio.c
drivers/button/Kconfig +9 -0
@@ -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
@@ -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 +111 -0
111 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v2 2/8 dm: button: add a driver for button driven by gpio
Quoted 17 lines · Philippe Reynes
Add a simple driver which allows use of buttons attached to GPIOs.
Reviewed-by Simon Glass <[email protected]>Signed-off-by Philippe Reynes <[email protected]>---
Changelog:
v2:
- remove useless default inKconfig
- re-order include
- fix condition inbutton_gpio_removedrivers/button/Kconfig | 9 ++++ drivers/button/Makefile | 1 + drivers/button/button-gpio.c | 111 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 121 insertions(+) create mode 100644 drivers/button/button-gpio.c
[...]
Quoted 7 lines
drivers/button/button-gpio.c new file +6
-0+ +static const struct udevice_id button_gpio_ids[] = { + { .compatible ="button-gpio" }, + { } +}; +
drivers/button/button-gpio.c line 111
Quoted 10 lines
drivers/button/button-gpio.c new file +10
-0+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, +};
Can't you use the gpio-keys/gpio-keys-polled compatible instead of inventing a bindings ?
Neil
PATCH v2 3/8 cmd: button: add a new 'button' command
In reply to Philippe ReynesAdds a command 'button' that provides the list of buttons supported by the board, and the state of a button.
---
Changelog:
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
@@ -1664,6 +1664,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
@@ -32,6 +32,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
PATCH v2 4/8 sandbox: dtsi: add buttons
In reply to Philippe ReynesAdds two buttons on sandbox so button framework may be tested.
---
Changelog:
v2:
- no change
arch/sandbox/dts/sandbox.dtsi | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
arch/sandbox/dts/sandbox.dtsi +14 -0
@@ -15,6 +15,20 @@ #sound-dai-cells = <1>; }; + buttons { + compatible = "button-gpio"; + + 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
PATCH v2 5/8 sandbox64: enable button
In reply to Philippe ReynesEnable the support of button (driver and command) on sandbox64.
---
Changelog:
v2:
- no change
configs/sandbox64_defconfig | 2 ++ 1 file changed, 2 insertions(+)
configs/sandbox64_defconfig +2 -0
@@ -90,6 +90,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
PATCH v2 6/8 sandbox: enable button
In reply to Philippe ReynesEnable the support of button (driver and command) on sandbox.
---
Changelog:
v2:
- no change
configs/sandbox_defconfig | 2 ++ 1 file changed, 2 insertions(+)
configs/sandbox_defconfig +2 -0
@@ -102,6 +102,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
PATCH v2 7/8 test/py: add tests for the button commands
In reply to Philippe ReynesAdds tests for the button commands.
---
Changelog:
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
@@ -51,6 +51,20 @@ #sound-dai-cells = <1>; }; + buttons { + compatible = "button-gpio"; + + 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
@@ -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
PATCH v2 8/8 test: dm: add a test for class button
In reply to Philippe ReynesAdd a test to confirm that we can read button state using the button-gpio driver.
---
Changelog:
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
@@ -17,6 +17,7 @@ obj-$(CONFIG_ACPIGEN) += acpi.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
PATCH v2 8/8 test: dm: add a test for class button
Hi Philippe,
Quoted 10 lines · Philippe Reynes
Add a test to confirm that we can read button state using the button-gpio driver.
Signed-off-by Philippe Reynes <[email protected]>---
Changelog:
v2:
- new commit in the serie
Quoted 4 lines
test/dm/Makefile | 1 + test/dm/button.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 test/dm/button.c
This seems to fail with 'make qcheck'. Can you please take a look? I've left it unapplied for now.
Regards,
Simon
PATCH v2 8/8 test: dm: add a test for class button
Hi Simon,
Quoted 14 lines
Hi Philippe,
Quoted 10 lines · Philippe Reynes
Add a test to confirm that we can read button state using the button-gpio driver.
Signed-off-by Philippe Reynes <[email protected]>---
Changelog:
v2:
- new commit in the serie
Quoted 7 lines
Quoted 4 lines
test/dm/Makefile | 1 +
test/dm/button.c| 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++2 files changed, 75 insertions(+)create mode 100644
test/dm/button.cThis seems to fail with 'make qcheck'. Can you please take a look? I've left it unapplied for now.
I've tried to reproduce this issue, but make qcheck don't work for me. I have some issues with test for binman, patman, and dtoc.
Could you provide me the log of the issue with 'make qcheck' please ?
Quoted 2 lines
Regards,
Simon
Regards,
Philippe
PATCH v2 8/8 test: dm: add a test for class button
Hi Philippe,
Quoted 22 lines · Philippe REYNES
Hi Simon,
Quoted 19 lines
Hi Philippe,
Quoted 14 lines · Philippe Reynes
Add a test to confirm that we can read button state using the button-gpio driver.
Signed-off-by Philippe Reynes <[email protected]>---
Changelog:
v2:
- new commit in the serietest/dm/Makefile | 1 +
test/dm/button.c| 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++2 files changed, 75 insertions(+)create mode 100644
test/dm/button.c
Quoted 7 lines
Quoted 2 lines
This seems to fail with 'make qcheck'. Can you please take a look? I've left it unapplied for now.
I've tried to reproduce this issue, but make qcheck don't work for me. I have some issues with test for binman, patman, and dtoc.
Could you provide me the log of the issue with 'make qcheck' please ?
See below. What sort of issues are you seeing? I wonder if we should have a script to set up for running these tests fully.
======================================================= FAILURES
=======================================================
______________________________________________test_button_exit_statuses
_______________________________________________
u_boot_console = <u_boot_console_sandbox.ConsoleSandbox object at 0x7fe1121eef60>
@pytest.mark.boardspec('sandbox') @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:$?')
Quoted 1 line
assert(expected_response in response)
E assert 'rc:0' in "Button 'summer' not found (err=-16)\r\r\nrc:1"
test/py/tests/test_button.py:15: AssertionError ------------------------------------------------- Captured stdout call
-------------------------------------------------
=> button list; echo rc:$?
summer <inactive>
christmas <inactive>
rc:0
=> => button summer; echo rc:$?
Button 'summer' not found (err=-16)
rc:1
=>
============================== 1 failed, 512 passed, 59 skipped, 105 deselected in 43.38s ==============================
Regards,
Simon
PATCH v2 8/8 test: dm: add a test for class button
Hi Simon,
Quoted 60 lines
Hi Philippe,
Quoted 22 lines · Philippe REYNES
Hi Simon,
Quoted 19 lines
Hi Philippe,
Quoted 14 lines · Philippe Reynes
Add a test to confirm that we can read button state using the button-gpio driver.
Signed-off-by Philippe Reynes <[email protected]>---
Changelog:
v2:
- new commit in the serietest/dm/Makefile | 1 +
test/dm/button.c| 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++2 files changed, 75 insertions(+)create mode 100644
test/dm/button.cQuoted 7 lines
Quoted 2 lines
This seems to fail with 'make qcheck'. Can you please take a look? I've left it unapplied for now.
I've tried to reproduce this issue, but make qcheck don't work for me. I have some issues with test for binman, patman, and dtoc.
Could you provide me the log of the issue with 'make qcheck' please ?
See below. What sort of issues are you seeing? I wonder if we should have a script to set up for running these tests fully.
======================================================= FAILURES
=======================================================
______________________________________________test_button_exit_statuses
_______________________________________________
u_boot_console= <u_boot_console_sandbox.ConsoleSandbox object at0x7fe1121eef60>@pytest.mark.boardspec('sandbox') @pytest.mark.buildconfigspec('cmd_button')
deftest_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:$?')Quoted 1 line
assert(expected_response in response)E assert 'rc:0' in "Button 'summer' not found (err=-16)\r\r\nrc:1"
Quoted 13 lines
test/py/tests/test_button.py:15: AssertionError ------------------------------------------------- Captured stdout call
-------------------------------------------------
=> button list; echo rc:$?
summer <inactive>
christmas <inactive>
rc:0
=> => button summer; echo rc:$?
Button 'summer' not found (err=-16)
rc:1
=>
============================== 1 failed, 512 passed, 59 skipped, 105 deselected in 43.38s ==============================
I think I have found the issue. This issue only appears after the commit 9ba84329dc45 ("sandbox, test: add test for GPIO_HOG function") that uses gpio_a 0, 1, 2 and 3.
I've sent a patch do change the gpio used for hog on sandbox. With this patch, I don't reproduce this issue.
Quoted 2 lines
Regards,
Simon
Regards,
Philippe