[PATCH 3/3] dm: input: add button_kbd driver

Simon Glass sjg at chromium.org
Wed Jan 11 22:08:24 CET 2023


Hi Dzmitry,

On Wed, 11 Jan 2023 at 03:19, Dzmitry Sankouski <dsankouski at gmail.com> wrote:
>
> Bootmenu requires an input device with arrows and enter key.
> A common smartphone luckily has power, volume up/down buttons,
> which may be used for controlling bootmenu.
> To use driver, add 'button-kbd' to stdin.
>
> Signed-off-by: Dzmitry Sankouski <dsankouski at gmail.com>
> ---
>  drivers/input/Kconfig      |   9 +++
>  drivers/input/Makefile     |   1 +
>  drivers/input/button_kbd.c | 123 +++++++++++++++++++++++++++++++++++++
>  3 files changed, 133 insertions(+)
>  create mode 100644 drivers/input/button_kbd.c
>

Reviewed-by: Simon Glass <sjg at chromium.org>

nit below

> diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig
> index 1c534be005..b9a4e443a3 100644
> --- a/drivers/input/Kconfig
> +++ b/drivers/input/Kconfig
> @@ -46,6 +46,15 @@ config APPLE_SPI_KEYB
>           laptops based on Apple SoCs. These keyboards use an
>           Apple-specific HID-over-SPI protocol.
>
> +config BUTTON_KEYBOARD
> +       bool "Buttons as keyboard"
> +       depends on BUTTON_GPIO
> +       depends on DM_KEYBOARD
> +       help
> +         Enable support for mapping buttons to keycode events. Use linux,code button driver
> +         dt node to define button-event mapping.
> +         For example, an arrows and enter may be implemented to navigate boot menu.
> +
>  config CROS_EC_KEYB
>         bool "Enable Chrome OS EC keyboard support"
>         depends on INPUT
> diff --git a/drivers/input/Makefile b/drivers/input/Makefile
> index ded76bddb2..14c0ea7325 100644
> --- a/drivers/input/Makefile
> +++ b/drivers/input/Makefile
> @@ -6,6 +6,7 @@
>  obj-$(CONFIG_$(SPL_TPL_)CROS_EC_KEYB) += cros_ec_keyb.o
>  obj-$(CONFIG_$(SPL_TPL_)OF_CONTROL) += key_matrix.o
>  obj-$(CONFIG_$(SPL_TPL_)DM_KEYBOARD) += input.o keyboard-uclass.o
> +obj-$(CONFIG_BUTTON_KEYBOARD) += button_kbd.o
>
>  ifndef CONFIG_SPL_BUILD
>
> diff --git a/drivers/input/button_kbd.c b/drivers/input/button_kbd.c
> new file mode 100644
> index 0000000000..cacec5f699
> --- /dev/null
> +++ b/drivers/input/button_kbd.c
> @@ -0,0 +1,123 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +/*
> + * (C) Copyright 2023 Dzmitry Sankouski <dsankouski at gmail.com>
> + */
> +
> +#include <stdlib.h>
> +#include <common.h>
> +#include <dm.h>
> +#include <fdtdec.h>
> +#include <input.h>
> +#include <keyboard.h>
> +#include <button.h>
> +#include <dm/device-internal.h>
> +#include <log.h>
> +#include <asm/io.h>
> +#include <asm/gpio.h>
> +#include <linux/delay.h>
> +#include <linux/input.h>
> +
> +struct button_kbd_priv {
> +       struct input_config *input;
> +       u32 *keys;
> +       u32 keysize;
> +       u32 button_size;
> +       u32 *old_state;

Please add a comment for this struct

> +};
> +
> +static int button_kbd_start(struct udevice *dev)
> +{
> +       struct button_kbd_priv *priv = dev_get_priv(dev);
> +       int i = 0;
> +       struct udevice *button_gpio_devp;
> +
> +       uclass_foreach_dev_probe(UCLASS_BUTTON, button_gpio_devp) {
> +               struct button_uc_plat *uc_plat = dev_get_uclass_plat(button_gpio_devp);
> +               /* Ignore the top-level button node */
> +               if (!uc_plat->label)
> +                       continue;
> +               debug("Found button %s #%d - %s, probing...\n",
> +                     uc_plat->label, i, button_gpio_devp->name);
> +               i++;
> +       }
> +
> +       priv->button_size = i;
> +       priv->old_state = malloc(sizeof(int) * i);

You can use calloc() if you like

> +       priv->keysize = 0;
> +       priv->keys = malloc(sizeof(int) * i);
> +
> +       return 0;
> +}
> +

Regards,
Simon


More information about the U-Boot mailing list