From 6fe4bd731db59bb01cc0ce3cbd2412434ea053c6 Mon Sep 17 00:00:00 2001 From: Hans de Goede Date: Sun, 10 Aug 2025 16:58:01 +0200 Subject: [PATCH] Input: gpio-keys - Allow directly passing a gpio_desc instead of a GPIO number Using GPIO numbers is deprecated. Allow code passing GPIO-keys info through platform-data (struct gpio_keys_button) to directly pass a gpio_desc instead of a GPIO number. Note requesting / releasing the gpio_desc will be the responsibility of the code passing in the platform-data. Signed-off-by: Hans de Goede --- drivers/input/keyboard/gpio_keys.c | 2 ++ include/linux/gpio_keys.h | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c index f9db86da0818..323247f63a7e 100644 --- a/drivers/input/keyboard/gpio_keys.c +++ b/drivers/input/keyboard/gpio_keys.c @@ -528,6 +528,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev, */ bdata->gpiod = NULL; } + } else if (button->gpiod) { + bdata->gpiod = button->gpiod; } else if (gpio_is_valid(button->gpio)) { /* * Legacy GPIO number, so request the GPIO here and diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h index 80fa930b04c6..7c32c3a0695f 100644 --- a/include/linux/gpio_keys.h +++ b/include/linux/gpio_keys.h @@ -5,11 +5,13 @@ #include struct device; +struct gpio_desc; /** * struct gpio_keys_button - configuration parameters * @code: input event code (KEY_*, SW_*) - * @gpio: %-1 if this key does not support gpio + * @gpio: %-1 if this key does not support gpio (deprecated use gpiod) + * @gpiod: gpio_desc for the GPIO, NULL if this key does not support gpio * @active_low: %true indicates that button is considered * depressed when gpio is low * @desc: label that will be attached to button's gpio @@ -26,6 +28,7 @@ struct device; struct gpio_keys_button { unsigned int code; int gpio; + struct gpio_desc *gpiod; int active_low; const char *desc; unsigned int type; -- 2.49.0