button: adc: implement get_code()
PATCH v2 1/1 button: adc: implement get_code()
Implement .get_code in button_adc_ops and add linux_code to button_adc_priv.
The consumer in this case is the PinePhone Pro platform with the volume up and down keys for selection in bootmenu.
---
The keys on PinePhone Pro are not registered as Volume Up and Down as the keys are not wired to normal GPIO but to ADC and use different resistors to tell them apart.
However, button_adc_ops never sets .get_code unlike button-gpio. As a result button_get_code() returns -ENOSYS for ADC buttons.
The patch reads linux,code and returns it from .get_code mirroring button-gpio.
---
Changes in v2:
- extended the sandbox test for KEY_F3/F4/F5 in 'test/dm/button.c'
- switched to dev_read_u32_default() instead of ofnode_read_u32_default()
- the commit message now lists the PinePhone Pro as consumer
- Link to v1: https://patch.msgid.link/[email protected]
--- drivers/button/button-adc.c | 14 ++++++++++++++ test/dm/button.c | 3 +++ 2 files changed, 17 insertions(+)
drivers/button/button-adc.c +14 -0
@@ -20,12 +20,14 @@* @channel: channel of the ADC device to probe the button state. * @min: minimal uV value to consider button as pressed. * @max: maximal uV value to consider button as pressed. +* @linux_code: linux,code devicetree property for this button, or 0 if unset. */ struct button_adc_priv {struct udevice *adc;int channel;int min;int max; +int linux_code; };static enum button_state_t button_adc_get_state (struct udevice *dev)
@@ -49,6 +51,16 @@ static enum button_state_t button_adc_get_state(struct udevice *dev)return (uV >= priv->min && uV < priv->max) ?BUTTON_ON :BUTTON_OFF ; } +static int button_adc_get_code (struct udevice *dev) +{ +struct button_adc_priv *priv =dev_get_priv (dev); + +if (!priv->linux_code) +return -ENODATA ; + +return priv->linux_code; +} +static int button_adc_of_to_plat (struct udevice *dev) {struct button_uc_plat *uc_plat =dev_get_uclass_plat (dev);
@@ -93,6 +105,7 @@ static int button_adc_of_to_plat(struct udevice *dev) } priv->channel = args.args[0 ]; + priv->linux_code =dev_read_u32_default (dev,"linux,code" ,0 );/* * Define the voltage range such that the button is only pressed
@@ -138,6 +151,7 @@ static int button_adc_bind(struct udevice *parent)static const struct button_ops button_adc_ops = { .get_state = button_adc_get_state, + .get_code = button_adc_get_code, };static const struct udevice_id button_adc_ids[] = {
test/dm/button.c +3 -0
@@ -123,10 +123,13 @@ static int dm_test_button_keys_adc(struct unit_test_state *uts)*/ ut_assertok (button_get_by_label ("button3" , &dev));ut_asserteq (BUTTON_OFF ,button_get_state (dev)); +ut_asserteq (KEY_F3 ,button_get_code (dev));ut_assertok (button_get_by_label ("button4" , &dev));ut_asserteq (BUTTON_OFF ,button_get_state (dev)); +ut_asserteq (KEY_F4 ,button_get_code (dev));ut_assertok (button_get_by_label ("button5" , &dev));ut_asserteq (BUTTON_ON ,button_get_state (dev)); +ut_asserteq (KEY_F5 ,button_get_code (dev));return 0 ; }
---
base-commit: ece349ade2973e220f524ce59e59711cc919263f
change-id: 20261010-b4-button-adc-get-code-056f3d455daa
Best regards,
Signature · 1 line
Petr Hodina <[email protected]>
Quoted 5 lines · On 2026-10-13T16:13:23, Petr Hodina via B4 Relay…
button: adc: implement
get_code()Implement .get_code in
button_adc_opsand addlinux_codetobutton_adc_priv.
Quoted 8 lines
The consumer in this case is the PinePhone Pro platform with the volume up and down keys for selection in bootmenu.
Signed-off-by Petr Hodina <[email protected]>drivers/button/button-adc.c | 14 ++++++++++++++ test/dm/button.c | 3 +++ 2 files changed, 17 insertions(+)
Quoted 8 lines · Petr Hodina
Implement .get_code in
button_adc_opsand addlinux_codetobutton_adc_priv.The consumer in this case is the PinePhone Pro platform with the volume up and down keys for selection in bootmenu.
[...]
Applied to u-boot/main, thanks!
[1/1] button: adc: implement get_code()
commit: 2899fc52dcf58849b51ccd140641bc523fb7e033
Signature · 1 line
Tom