Skip to content

Commit 0f10757

Browse files
joseph-lo-nvtwdtor
authored andcommitted
Input: gpio_keys - handle the missing key press event in resume phase
The GPIO key press event might be missed in the resume phase, if the key had been released before the system had been resumed to the stage that it could capture the press event. So we simulate the wakeup key press event in case the key had been released by the time we got interrupt handler to run. Signed-off-by: Joseph Lo <josephl@nvidia.com> Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com> Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
1 parent 49aac82 commit 0f10757

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

drivers/input/keyboard/gpio_keys.c

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct gpio_button_data {
4848
spinlock_t lock;
4949
bool disabled;
5050
bool key_pressed;
51+
bool suspended;
5152
};
5253

5354
struct gpio_keys_drvdata {
@@ -396,8 +397,20 @@ static irqreturn_t gpio_keys_gpio_isr(int irq, void *dev_id)
396397

397398
BUG_ON(irq != bdata->irq);
398399

399-
if (bdata->button->wakeup)
400+
if (bdata->button->wakeup) {
401+
const struct gpio_keys_button *button = bdata->button;
402+
400403
pm_stay_awake(bdata->input->dev.parent);
404+
if (bdata->suspended &&
405+
(button->type == 0 || button->type == EV_KEY)) {
406+
/*
407+
* Simulate wakeup key press in case the key has
408+
* already released by the time we got interrupt
409+
* handler to run.
410+
*/
411+
input_report_key(bdata->input, button->code, 1);
412+
}
413+
}
401414

402415
mod_delayed_work(system_wq,
403416
&bdata->work,
@@ -855,6 +868,7 @@ static int __maybe_unused gpio_keys_suspend(struct device *dev)
855868
struct gpio_button_data *bdata = &ddata->data[i];
856869
if (bdata->button->wakeup)
857870
enable_irq_wake(bdata->irq);
871+
bdata->suspended = true;
858872
}
859873
} else {
860874
mutex_lock(&input->mutex);
@@ -878,6 +892,7 @@ static int __maybe_unused gpio_keys_resume(struct device *dev)
878892
struct gpio_button_data *bdata = &ddata->data[i];
879893
if (bdata->button->wakeup)
880894
disable_irq_wake(bdata->irq);
895+
bdata->suspended = false;
881896
}
882897
} else {
883898
mutex_lock(&input->mutex);

0 commit comments

Comments
 (0)