[OpenWrt-Devel] [PATCH] gpio-button-hotplug: gpio-keys: read initial state
David Bauer
mail at david-bauer.net
Thu Jun 13 17:00:36 EDT 2019
This commit reads the initial state for interrupt triggered gpio-keys.
Without this commit, the switch to the initial stable input-state
triggers a button-event. Button events are now only triggered when the
button state differs fromt the initial state.
Effectively, this reverts commit 6c5bfaac84b0 ("gpio-button-hotplug:
gpio-keys: fix always missing first event"), but in addition, we read
the initial button state on driver probe. This commit caused some devices
to enter failsafe mode every time when booting.
Run-tested on devolo WiFi pro 1200e & 1200i.
Signed-off-by: David Bauer <mail at david-bauer.net>
---
.../src/gpio-button-hotplug.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c b/package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c
index daa4b2a4f7..5bc783e015 100644
--- a/package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c
+++ b/package/kernel/gpio-button-hotplug/src/gpio-button-hotplug.c
@@ -341,8 +341,16 @@ static void gpio_keys_irq_work_func(struct work_struct *work)
struct gpio_keys_button_data *bdata = container_of(work,
struct gpio_keys_button_data, work.work);
- button_hotplug_event(bdata, bdata->b->type ?: EV_KEY,
- gpio_button_get_value(bdata));
+ int state = gpio_button_get_value(bdata);
+
+ if (state != bdata->last_state) {
+ unsigned int type = bdata->b->type ?: EV_KEY;
+
+ if (bdata->last_state != -1 || type == EV_SW)
+ button_hotplug_event(bdata, type, state);
+
+ bdata->last_state = state;
+ }
}
static irqreturn_t button_handle_irq(int irq, void *_bdata)
@@ -607,6 +615,9 @@ static int gpio_keys_probe(struct platform_device *pdev)
INIT_DELAYED_WORK(&bdata->work, gpio_keys_irq_work_func);
+ schedule_delayed_work(&bdata->work,
+ msecs_to_jiffies(bdata->software_debounce));
+
ret = devm_request_threaded_irq(&pdev->dev,
bdata->irq, NULL, button_handle_irq,
irqflags, dev_name(&pdev->dev), bdata);
@@ -620,9 +631,6 @@ static int gpio_keys_probe(struct platform_device *pdev)
dev_dbg(&pdev->dev, "gpio:%d has irq:%d\n",
button->gpio, bdata->irq);
}
-
- if (bdata->b->type == EV_SW)
- button_hotplug_event(bdata, EV_SW, gpio_button_get_value(bdata));
}
return 0;
--
2.22.0
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list