ignatenkobrain / rpms / kernel

Forked from rpms/kernel 3 years ago
Clone
f2c60e
From 25bb14c1e78e641049fd1ee0c404a9ccd2755e44 Mon Sep 17 00:00:00 2001
f2c60e
From: Hans de Goede <hdegoede@redhat.com>
f2c60e
Date: Sat, 22 Jul 2017 13:00:05 +0200
f2c60e
Subject: [PATCH 1/2] Input: gpio_keys - Allow suppression of input events for
f2c60e
 wakeup button presses
f2c60e
f2c60e
In some cases it is undesirable for a wakeup button to send input events
f2c60e
to userspace if pressed to wakeup the system (if pressed during suspend).
f2c60e
f2c60e
A typical example of this is the power-button on laptops / tablets,
f2c60e
sending a KEY_POWER event to userspace when woken up with the power-button
f2c60e
will cause userspace to immediately suspend the system again which is
f2c60e
undesirable.
f2c60e
f2c60e
For power-buttons attached to a PMIC, or handled by e.g. ACPI, not sending
f2c60e
an input event in this case is take care of by the PMIC / ACPI hardware /
f2c60e
code. But in the case of a GPIO button we need to explicitly suppress the
f2c60e
sending of the input event.
f2c60e
f2c60e
This commit adds support for this by adding a no_wakeup_events bool to
f2c60e
struct gpio_keys_button, which platform code can set to suppress the
f2c60e
input events for presses of wakeup keys during suspend.
f2c60e
f2c60e
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
f2c60e
---
f2c60e
Changes in v2:
f2c60e
-This is a rewrite if my "Input: gpio_keys - Do not report wake button
f2c60e
 presses as evdev events" patch.
f2c60e
-Instead of unconditionally ignoring presses of all wake-up buttons during
f2c60e
 suspend, this rewrite makes this configurable per button
f2c60e
-This version uses a timer to delay clearing the suspended flag for software
f2c60e
 debouncing, rather then jiffy compare magic
f2c60e
---
f2c60e
 drivers/input/keyboard/gpio_keys.c | 33 +++++++++++++++++++++++++++++++--
f2c60e
 include/linux/gpio_keys.h          |  3 +++
f2c60e
 2 files changed, 34 insertions(+), 2 deletions(-)
f2c60e
f2c60e
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
f2c60e
index a047b9af8369..fa3a58620407 100644
f2c60e
--- a/drivers/input/keyboard/gpio_keys.c
f2c60e
+++ b/drivers/input/keyboard/gpio_keys.c
f2c60e
@@ -38,6 +38,7 @@ struct gpio_button_data {
f2c60e
 
f2c60e
 	unsigned short *code;
f2c60e
 
f2c60e
+	struct timer_list unsuspend_timer;
f2c60e
 	struct timer_list release_timer;
f2c60e
 	unsigned int release_delay;	/* in msecs, for IRQ-only buttons */
f2c60e
 
f2c60e
@@ -371,6 +372,9 @@ static void gpio_keys_gpio_report_event(struct gpio_button_data *bdata)
f2c60e
 		return;
f2c60e
 	}
f2c60e
 
f2c60e
+	if (state && bdata->button->no_wakeup_events && bdata->suspended)
f2c60e
+		return;
f2c60e
+
f2c60e
 	if (type == EV_ABS) {
f2c60e
 		if (state)
f2c60e
 			input_event(input, type, button->code, button->value);
f2c60e
@@ -400,6 +404,9 @@ static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id)
f2c60e
 	if (bdata->button->wakeup) {
f2c60e
 		const struct gpio_keys_button *button = bdata->button;
f2c60e
 
f2c60e
+		if (bdata->button->no_wakeup_events && bdata->suspended)
f2c60e
+			return IRQ_HANDLED;
f2c60e
+
f2c60e
 		pm_stay_awake(bdata->input->dev.parent);
f2c60e
 		if (bdata->suspended  &&
f2c60e
 		    (button->type == 0 || button->type == EV_KEY)) {
f2c60e
@@ -445,9 +452,13 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id)
f2c60e
 	spin_lock_irqsave(&bdata->lock, flags);
f2c60e
 
f2c60e
 	if (!bdata->key_pressed) {
f2c60e
-		if (bdata->button->wakeup)
f2c60e
+		if (bdata->button->wakeup) {
f2c60e
 			pm_wakeup_event(bdata->input->dev.parent, 0);
f2c60e
 
f2c60e
+			if (bdata->button->no_wakeup_events && bdata->suspended)
f2c60e
+				goto out;
f2c60e
+		}
f2c60e
+
f2c60e
 		input_event(input, EV_KEY, *bdata->code, 1);
f2c60e
 		input_sync(input);
f2c60e
 
f2c60e
@@ -468,6 +479,13 @@ static irqreturn_t gpio_keys_irq_isr(int irq, void *dev_id)
f2c60e
 	return IRQ_HANDLED;
f2c60e
 }
f2c60e
 
f2c60e
+static void gpio_keys_unsuspend_timer(unsigned long _data)
f2c60e
+{
f2c60e
+	struct gpio_button_data *bdata = (struct gpio_button_data *)_data;
f2c60e
+
f2c60e
+	bdata->suspended = false;
f2c60e
+}
f2c60e
+
f2c60e
 static void gpio_keys_quiesce_key(void *data)
f2c60e
 {
f2c60e
 	struct gpio_button_data *bdata = data;
f2c60e
@@ -476,6 +494,8 @@ static void gpio_keys_quiesce_key(void *data)
f2c60e
 		cancel_delayed_work_sync(&bdata->work);
f2c60e
 	else
f2c60e
 		del_timer_sync(&bdata->release_timer);
f2c60e
+
f2c60e
+	del_timer_sync(&bdata->unsuspend_timer);
f2c60e
 }
f2c60e
 
f2c60e
 static int gpio_keys_setup_key(struct platform_device *pdev,
f2c60e
@@ -496,6 +516,8 @@ static int gpio_keys_setup_key(struct platform_device *pdev,
f2c60e
 	bdata->input = input;
f2c60e
 	bdata->button = button;
f2c60e
 	spin_lock_init(&bdata->lock);
f2c60e
+	setup_timer(&bdata->unsuspend_timer, gpio_keys_unsuspend_timer,
f2c60e
+		    (unsigned long)bdata);
f2c60e
 
f2c60e
 	if (child) {
f2c60e
 		bdata->gpiod = devm_fwnode_get_gpiod_from_child(dev, NULL,
f2c60e
@@ -868,6 +890,7 @@ static int __maybe_unused gpio_keys_suspend(struct device *dev)
f2c60e
 			struct gpio_button_data *bdata = &ddata->data[i];
f2c60e
 			if (bdata->button->wakeup)
f2c60e
 				enable_irq_wake(bdata->irq);
f2c60e
+			del_timer_sync(&bdata->unsuspend_timer);
f2c60e
 			bdata->suspended = true;
f2c60e
 		}
f2c60e
 	} else {
f2c60e
@@ -892,7 +915,13 @@ static int __maybe_unused gpio_keys_resume(struct device *dev)
f2c60e
 			struct gpio_button_data *bdata = &ddata->data[i];
f2c60e
 			if (bdata->button->wakeup)
f2c60e
 				disable_irq_wake(bdata->irq);
f2c60e
-			bdata->suspended = false;
f2c60e
+			if (bdata->button->no_wakeup_events) {
f2c60e
+				mod_timer(&bdata->unsuspend_timer, jiffies +
f2c60e
+					  msecs_to_jiffies(
f2c60e
+						    bdata->software_debounce));
f2c60e
+			} else {
f2c60e
+				bdata->suspended = false;
f2c60e
+			}
f2c60e
 		}
f2c60e
 	} else {
f2c60e
 		mutex_lock(&input->mutex);
f2c60e
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
f2c60e
index 0b71024c082c..d8a85e52b6bb 100644
f2c60e
--- a/include/linux/gpio_keys.h
f2c60e
+++ b/include/linux/gpio_keys.h
f2c60e
@@ -15,6 +15,8 @@ struct device;
f2c60e
  * @debounce_interval:	debounce ticks interval in msecs
f2c60e
  * @can_disable:	%true indicates that userspace is allowed to
f2c60e
  *			disable button via sysfs
f2c60e
+ * @no_wakeup_events:	For wake-up source buttons only, if %true then no input
f2c60e
+ *			events will be generated if pressed while suspended
f2c60e
  * @value:		axis value for %EV_ABS
f2c60e
  * @irq:		Irq number in case of interrupt keys
f2c60e
  */
f2c60e
@@ -27,6 +29,7 @@ struct gpio_keys_button {
f2c60e
 	int wakeup;
f2c60e
 	int debounce_interval;
f2c60e
 	bool can_disable;
f2c60e
+	bool no_wakeup_events;
f2c60e
 	int value;
f2c60e
 	unsigned int irq;
f2c60e
 };
f2c60e
-- 
f2c60e
2.13.4
f2c60e