dm: button: support remapping phone keys
authorCaleb Connolly <caleb.connolly@linaro.org>
Sun, 14 Jul 2024 19:49:19 +0000 (21:49 +0200)
committerTom Rini <trini@konsulko.com>
Sun, 17 Nov 2024 01:49:05 +0000 (19:49 -0600)
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>
drivers/button/Kconfig
drivers/button/button-uclass.c

index 3918b05..6cae16f 100644 (file)
@@ -9,6 +9,17 @@ config BUTTON
          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
index cda2433..729983d 100644 (file)
@@ -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) = {