[PATCH 1/3] Input: gpio-keys - add support for wakeup interrupt trigger type

From: Jeffy Chen
Date: Fri Feb 09 2018 - 06:55:38 EST


Add support for specifying a different interrupt trigger type for wakeup
when using the gpio-keys input device as a wakeup source.

This would allow the device to configure when to wakeup the system. For
example a gpio-keys input device for pen insert, may only want to wakeup
the system when ejecting the pen.

Suggested-by: Brian Norris <briannorris@xxxxxxxxxxxx>
Signed-off-by: Jeffy Chen <jeffy.chen@xxxxxxxxxxxxxx>
---

drivers/input/keyboard/gpio_keys.c | 20 ++++++++++++++++++--
include/linux/gpio_keys.h | 2 ++
2 files changed, 20 insertions(+), 2 deletions(-)

diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 87e613dc33b8..5e5c93b75a71 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -45,6 +45,7 @@ struct gpio_button_data {
unsigned int software_debounce; /* in msecs, for GPIO-driven buttons */

unsigned int irq;
+ unsigned int irq_trigger_type;
spinlock_t lock;
bool disabled;
bool key_pressed;
@@ -618,6 +619,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
return error;
}

+ bdata->irq_trigger_type = irq_get_trigger_type(bdata->irq);
+
return 0;
}

@@ -718,6 +721,9 @@ gpio_keys_get_devtree_pdata(struct device *dev)
/* legacy name */
fwnode_property_read_bool(child, "gpio-key,wakeup");

+ fwnode_property_read_u32(child, "wakeup-trigger-type",
+ &button->wakeup_trigger_type);
+
button->can_disable =
fwnode_property_read_bool(child, "linux,can-disable");

@@ -854,7 +860,12 @@ static int __maybe_unused gpio_keys_suspend(struct device *dev)
if (device_may_wakeup(dev)) {
for (i = 0; i < ddata->pdata->nbuttons; i++) {
struct gpio_button_data *bdata = &ddata->data[i];
- if (bdata->button->wakeup)
+ const struct gpio_keys_button *button = bdata->button;
+
+ if (button->wakeup && button->wakeup_trigger_type)
+ irq_set_irq_type(bdata->irq,
+ button->wakeup_trigger_type);
+ if (button->wakeup)
enable_irq_wake(bdata->irq);
bdata->suspended = true;
}
@@ -878,7 +889,12 @@ static int __maybe_unused gpio_keys_resume(struct device *dev)
if (device_may_wakeup(dev)) {
for (i = 0; i < ddata->pdata->nbuttons; i++) {
struct gpio_button_data *bdata = &ddata->data[i];
- if (bdata->button->wakeup)
+ const struct gpio_keys_button *button = bdata->button;
+
+ if (button->wakeup && button->wakeup_trigger_type)
+ irq_set_irq_type(bdata->irq,
+ bdata->irq_trigger_type);
+ if (button->wakeup)
disable_irq_wake(bdata->irq);
bdata->suspended = false;
}
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index d06bf77400f1..9b7e7137f768 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -13,6 +13,7 @@ struct device;
* @desc: label that will be attached to button's gpio
* @type: input event type (%EV_KEY, %EV_SW, %EV_ABS)
* @wakeup: configure the button as a wake-up source
+ * @wakeup_trigger_type: wakeup interrupt trigger type
* @debounce_interval: debounce ticks interval in msecs
* @can_disable: %true indicates that userspace is allowed to
* disable button via sysfs
@@ -26,6 +27,7 @@ struct gpio_keys_button {
const char *desc;
unsigned int type;
int wakeup;
+ int wakeup_trigger_type;
int debounce_interval;
bool can_disable;
int value;
--
2.11.0