diff options
author | Caleb Connolly <caleb.connolly@linaro.org> | 2024-07-14 21:49:19 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2024-11-16 19:49:05 -0600 |
commit | cae243927f67f81ff7456906bb6018b93e1c28f3 (patch) | |
tree | c47e11a64d9fed207719d50092f7360efad82c97 /drivers/button/button-uclass.c | |
parent | c71d451033db9ed1ea3ac46fa81a09ec9c58918c (diff) |
dm: button: support remapping phone keys
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@linaro.org>
Reviewed-by: Dragan Simic <dsimic@manjaro.org>
Diffstat (limited to 'drivers/button/button-uclass.c')
-rw-r--r-- | drivers/button/button-uclass.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/drivers/button/button-uclass.c b/drivers/button/button-uclass.c index cda243389df..729983d5870 100644 --- a/drivers/button/button-uclass.c +++ b/drivers/button/button-uclass.c @@ -10,6 +10,7 @@ #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) { @@ -37,14 +38,33 @@ 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) = { |