Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

input: gpio_keys: add a no-disconnect property #79828

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 14 additions & 8 deletions drivers/input/input_gpio_keys.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
struct gpio_keys_pin_data *pin_data;
k_work_handler_t handler;
bool polling_mode;
bool no_disconnect;
};

struct gpio_keys_data {
Expand Down Expand Up @@ -238,10 +239,12 @@
}
}

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;
}
}
}

Expand All @@ -252,10 +255,12 @@
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) {
Expand Down Expand Up @@ -304,6 +309,7 @@
.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; \
Expand All @@ -313,5 +319,5 @@
DEVICE_DT_INST_DEFINE(i, &gpio_keys_init, PM_DEVICE_DT_INST_GET(i), \
&gpio_keys_data_##i, &gpio_keys_config_##i, \
POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL);

Check notice on line 322 in drivers/input/input_gpio_keys.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

You may want to run clang-format on this change

drivers/input/input_gpio_keys.c:322 - \ + \ static const struct gpio_keys_pin_config gpio_keys_pin_config_##i[] = { \ - DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(i, GPIO_KEYS_CFG_DEF, (,))}; \ - \ + DT_INST_FOREACH_CHILD_STATUS_OKAY_SEP(i, GPIO_KEYS_CFG_DEF, (, ))}; \ + \ static struct gpio_keys_pin_data \ gpio_keys_pin_data_##i[ARRAY_SIZE(gpio_keys_pin_config_##i)]; \ - \ + \ static const struct gpio_keys_config gpio_keys_config_##i = { \ .debounce_interval_ms = DT_INST_PROP(i, debounce_interval_ms), \ .num_keys = ARRAY_SIZE(gpio_keys_pin_config_##i), \ .pin_cfg = gpio_keys_pin_config_##i, \ .pin_data = gpio_keys_pin_data_##i, \ .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), \ + (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; \ - \ + \ PM_DEVICE_DT_INST_DEFINE(i, gpio_keys_pm_action); \ - \ - DEVICE_DT_INST_DEFINE(i, &gpio_keys_init, PM_DEVICE_DT_INST_GET(i), \ - &gpio_keys_data_##i, &gpio_keys_config_##i, \ - POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, NULL); + \ + DEVICE_DT_INST_DEFINE(i, &gpio_keys_init, PM_DEVICE_DT_INST_GET(i), &gpio_keys_data_##i, \ + &gpio_keys_config_##i, POST_KERNEL, CONFIG_INPUT_INIT_PRIORITY, \ + NULL);
DT_INST_FOREACH_STATUS_OKAY(GPIO_KEYS_INIT)
6 changes: 6 additions & 0 deletions dts/bindings/input/gpio-keys.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading