From 6fe09193512f241473a536f56c01fdab09bdf7b9 Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Mon, 14 Oct 2024 16:08:22 +0100 Subject: [PATCH] input: gpio_keys: add a no-disconnect property Add a no-disconnect property that skips the call to disconnect the pin during suspend, this is useful as not all gpio controllers supports pin disconnection, and right now using the gpio-keys driver on one of those results in a failed initialization if PM runtime is enabled. Signed-off-by: Fabio Baltieri --- drivers/input/input_gpio_keys.c | 22 ++++++++++++++-------- dts/bindings/input/gpio-keys.yaml | 6 ++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/drivers/input/input_gpio_keys.c b/drivers/input/input_gpio_keys.c index be35e12ef56083..6d306ace4e5929 100644 --- a/drivers/input/input_gpio_keys.c +++ b/drivers/input/input_gpio_keys.c @@ -44,6 +44,7 @@ struct gpio_keys_config { struct gpio_keys_pin_data *pin_data; k_work_handler_t handler; bool polling_mode; + bool no_disconnect; }; struct gpio_keys_data { @@ -238,10 +239,12 @@ static int gpio_keys_pm_action(const struct device *dev, } } - ret = gpio_pin_configure_dt(gpio, GPIO_DISCONNECTED); - if (ret != 0) { - LOG_ERR("Pin %d configuration failed: %d", i, ret); - return ret; + if (!cfg->no_disconnect) { + ret = gpio_pin_configure_dt(gpio, GPIO_DISCONNECTED); + if (ret != 0) { + LOG_ERR("Pin %d configuration failed: %d", i, ret); + return ret; + } } } @@ -252,10 +255,12 @@ static int gpio_keys_pm_action(const struct device *dev, for (int i = 0; i < cfg->num_keys; i++) { const struct gpio_dt_spec *gpio = &cfg->pin_cfg[i].spec; - ret = gpio_pin_configure_dt(gpio, GPIO_INPUT); - if (ret != 0) { - LOG_ERR("Pin %d configuration failed: %d", i, ret); - return ret; + if (!cfg->no_disconnect) { + ret = gpio_pin_configure_dt(gpio, GPIO_INPUT); + if (ret != 0) { + LOG_ERR("Pin %d configuration failed: %d", i, ret); + return ret; + } } if (cfg->polling_mode) { @@ -304,6 +309,7 @@ static int gpio_keys_pm_action(const struct device *dev, .handler = COND_CODE_1(DT_INST_PROP(i, polling_mode), \ (gpio_keys_poll_pins), (gpio_keys_change_deferred)), \ .polling_mode = DT_INST_PROP(i, polling_mode), \ + .no_disconnect = DT_INST_PROP(i, no_disconnect), \ }; \ \ static struct gpio_keys_data gpio_keys_data_##i; \ diff --git a/dts/bindings/input/gpio-keys.yaml b/dts/bindings/input/gpio-keys.yaml index f2776bbda9d807..a04806086fbca8 100644 --- a/dts/bindings/input/gpio-keys.yaml +++ b/dts/bindings/input/gpio-keys.yaml @@ -41,6 +41,12 @@ properties: Do not use interrupts for the key GPIOs, poll the pin periodically at the specified debounce-interval-ms instead. + no-disconnect: + type: boolean + description: | + Do not try to disconnect the pin on suspend. Can be used if the GPIO + controller does not support the GPIO_DISCONNECTED flag. + child-binding: description: GPIO KEYS child node properties: