[PATCH] dm: button: support remapping phone keys

Caleb Connolly caleb.connolly at linaro.org
Mon Sep 9 12:40:36 CEST 2024


Hi all,

There's been some interesting discussion around this (thanks everyone
who has chipped in).

To summarise, it seems like a more elegant solution to this problem
would be to introduce a new devicetree property "bootph,keys" (or
u-boot,keys?) to denote the keycodes which should be send when a key is
pressed in the bootloader stage, rather than the OS.

This does seem like an elegant solution, but it would also require
changing all the devicetree files for all the devices where this
matters. Considering the lack of other usecases for this, I'm not sure
if a generic solution like that is really worth it compared to what I'm
proposing here. I also don't think that accepting this patch is mutually
exclusive with implementing a "proper" generic solution later on.

Does anyone have further thoughts? Can we go ahead with this patch?

I'd be happy to re-send it, and go ahead with Quentin's suggestion to
make the funtion weak so that boards can override it (though maybe that
could be done in a future patch if there is some usecase for it).

Thanks and regards,

On 14/07/2024 21:49, Caleb Connolly wrote:
> We don't have audio support in U-Boot, but we do have boot menus. Add an
> option to re-map the volume and power buttons to up/down/enter so that
> in situations where these are the only available buttons (such as on
> mobile phones) it's still possible to navigate menus built in U-Boot or
> an external EFI app like GRUB or systemd-boot.
> 
> Signed-off-by: Caleb Connolly <caleb.connolly at linaro.org>
> ---
> Cc: u-boot-qcom at groups.io
> ---
>  drivers/button/Kconfig         | 11 +++++++++++
>  drivers/button/button-uclass.c | 22 +++++++++++++++++++++-
>  2 files changed, 32 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/button/Kconfig b/drivers/button/Kconfig
> index 3918b05ae03e..6cae16fcc8bf 100644
> --- a/drivers/button/Kconfig
> +++ b/drivers/button/Kconfig
> @@ -8,8 +8,19 @@ config BUTTON
>  	  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.
>  
> +config BUTTON_REMAP_PHONE_KEYS
> +	bool "Remap phone keys for navigation"
> +	depends on BUTTON
> +	help
> +	  Enable remapping of phone keys to navigation keys. This is useful for
> +	  devices with phone keys that are not used in U-Boot. The phone keys
> +	  are remapped to the following navigation keys:
> +	  - Volume up: Up
> +	  - Volume down: Down
> +	  - Power: Enter
> +
>  config BUTTON_ADC
>  	bool "Button adc"
>  	depends on BUTTON
>  	depends on ADC
> diff --git a/drivers/button/button-uclass.c b/drivers/button/button-uclass.c
> index cda243389df3..729983d58701 100644
> --- a/drivers/button/button-uclass.c
> +++ b/drivers/button/button-uclass.c
> @@ -9,8 +9,9 @@
>  
>  #include <button.h>
>  #include <dm.h>
>  #include <dm/uclass-internal.h>
> +#include <dt-bindings/input/linux-event-codes.h>
>  
>  int button_get_by_label(const char *label, struct udevice **devp)
>  {
>  	struct udevice *dev;
> @@ -36,16 +37,35 @@ enum button_state_t button_get_state(struct udevice *dev)
>  
>  	return ops->get_state(dev);
>  }
>  
> +static int button_remap_phone_keys(int code)
> +{
> +	switch (code) {
> +	case KEY_VOLUMEUP:
> +		return KEY_UP;
> +	case KEY_VOLUMEDOWN:
> +		return KEY_DOWN;
> +	case KEY_POWER:
> +		return KEY_ENTER;
> +	default:
> +		return code;
> +	}
> +}
> +
>  int button_get_code(struct udevice *dev)
>  {
>  	struct button_ops *ops = button_get_ops(dev);
> +	int code;
>  
>  	if (!ops->get_code)
>  		return -ENOSYS;
>  
> -	return ops->get_code(dev);
> +	code = ops->get_code(dev);
> +	if (CONFIG_IS_ENABLED(BUTTON_REMAP_PHONE_KEYS))
> +		return button_remap_phone_keys(code);
> +	else
> +		return code;
>  }
>  
>  UCLASS_DRIVER(button) = {
>  	.id		= UCLASS_BUTTON,

-- 
// Caleb (they/them)


More information about the U-Boot mailing list