Skip to contentSkip to conversation

acpi: trigger wakeup key event from power button

PATCH Superseded Ken Xue 2 participants 3 messages Sep 12, 2023 – Sep 13, 2023

Subsystems (2)

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Ken Xue

author
#0 lore raw

PATCH v3 1/1 acpi: trigger wakeup key event from power button

Andorid can wakeup from various wakeup sources, but only several wakeup sources can wake up screen with right events(POWER, WAKEUP) from input device.

Regarding pressing acpi power button, it can resume system and ACPI_BITMASK_WAKE_STATUS and ACPI_BITMASK_POWER_BUTTON_STATUS are set in pm1a_sts, but kernel does not report any key event to user space during resume by default.

So, trigger wakeup key event to user space during resume from power button.

---
V1->V2: fix some compile warning/error caused by lack of
"struct acpi_device" declaration by including acpi.h.
V2->V3: use "forward declaration" to fix compile warning/error.

 drivers/acpi/button.c | 16 ++++++++++++++++
 drivers/acpi/sleep.c  |  2 ++
 include/acpi/button.h |  4 ++++
 3 files changed, 22 insertions(+)
drivers/acpi/button.c +16 -0
index 1e76a64cce0a..3b8aa071732b 100644
@@ -363,6 +363,21 @@ static int acpi_button_remove_fs(struct acpi_device *device)
 	return 0;
 }
 
+void acpi_power_button_wakeup(struct acpi_device *dev)
+{
+	struct acpi_button *button = acpi_driver_data(dev);
+	struct input_dev *input;
+
+	if (button->type == ACPI_BUTTON_TYPE_POWER) {
+		input = button->input;
+		input_report_key(input, KEY_WAKEUP, 1);
+		input_sync(input);
+		input_report_key(input, KEY_WAKEUP, 0);
+		input_sync(input);
+	}
+}
+EXPORT_SYMBOL(acpi_power_button_wakeup);
+
 /* Driver Interface */
 int acpi_lid_open(void)
 {
@@ -579,6 +594,7 @@ static int acpi_button_add(struct acpi_device *device)
 	switch (button->type) {
 	case ACPI_BUTTON_TYPE_POWER:
 		input_set_capability(input, EV_KEY, KEY_POWER);
+		input_set_capability(input, EV_KEY, KEY_WAKEUP);
 		break;
 
 	case ACPI_BUTTON_TYPE_SLEEP:
drivers/acpi/sleep.c +2 -0
index 808484d11209..dcd5d0237eeb 100644
@@ -22,6 +22,7 @@
 #include <linux/syscore_ops.h>
 #include <asm/io.h>
 #include <trace/events/power.h>
+#include <acpi/button.h>
 
 #include "internal.h"
 #include "sleep.h"
@@ -507,6 +508,7 @@ static void acpi_pm_finish(void)
 	pwr_btn_adev = acpi_dev_get_first_match_dev(ACPI_BUTTON_HID_POWERF,
 						    NULL, -1);
 	if (pwr_btn_adev) {
+		acpi_power_button_wakeup(pwr_btn_adev);
 		pm_wakeup_event(&pwr_btn_adev->dev, 0);
 		acpi_dev_put(pwr_btn_adev);
 	}
include/acpi/button.h +4 -0
index af2fce5d2ee3..6126d665aa42 100644
@@ -2,17 +2,21 @@
 #ifndef ACPI_BUTTON_H
 #define ACPI_BUTTON_H
 
+struct acpi_device;
+
 #define ACPI_BUTTON_HID_POWER	"PNP0C0C"
 #define ACPI_BUTTON_HID_LID	"PNP0C0D"
 #define ACPI_BUTTON_HID_SLEEP	"PNP0C0E"
 
 #if IS_ENABLED(CONFIG_ACPI_BUTTON)
 extern int acpi_lid_open(void);
+extern void acpi_power_button_wakeup(struct acpi_device *dev);
 #else
 static inline int acpi_lid_open(void)
 {
 	return 1;
 }
+static inline void acpi_power_button_wakeup(struct acpi_device *dev) {}
 #endif /* IS_ENABLED(CONFIG_ACPI_BUTTON) */
 
 #endif /* ACPI_BUTTON_H */

base-commit: b483d3b8a54a544ab8854ca6dbb8d99c423b3ba4

Signature · 1 line
2.35.1
#1 lore raw
Quoted 3 lines · Ken Xue

Andorid can wakeup from various wakeup sources, but only several wakeup sources can wake up screen with right events(POWER, WAKEUP) from input device.

You still have a room for 10+ characters on each line in the above paragraph. Why not use them?

Quoted 9 lines

Regarding pressing acpi power button, it can resume system and ACPI_BITMASK_WAKE_STATUS and ACPI_BITMASK_POWER_BUTTON_STATUS are set in pm1a_sts, but kernel does not report any key event to user space during resume by default.

So, trigger wakeup key event to user space during resume from power button.

...

drivers/acpi/button.c static int acpi_button_remove_fs(struct acpi_device *device) · line 371

Quoted 6 lines
drivers/acpi/button.c +5 -0
+void acpi_power_button_wakeup(struct acpi_device *dev)
+{
+	struct acpi_button *button = acpi_driver_data(dev);
+	struct input_dev *input;
 
+	if (button->type == ACPI_BUTTON_TYPE_POWER) {

It seems you missed the suggestion and I haven't heard an objection on written the above as

	if (button->type != ACPI_BUTTON_TYPE_POWER)
		return;
Quoted 7 lines
drivers/acpi/button.c +7 -0
+		input = button->input;
+		input_report_key(input, KEY_WAKEUP, 1);
+		input_sync(input);
+		input_report_key(input, KEY_WAKEUP, 0);
+		input_sync(input);
+	}
+}

...

Quoted 4 lines

#include <linux/syscore_ops.h>
#include <asm/io.h>
#include <trace/events/power.h>
+#include <acpi/button.h>

While at it, I would add a blank line here to distinguish groups of header inclusions.

  #include <linux/syscore_ops.h>
  #include <asm/io.h>
  #include <trace/events/power.h>

  #include <acpi/button.h>

Or even

  #include <linux/syscore_ops.h>

  #include <asm/io.h>

  #include <trace/events/power.h>

  #include <acpi/button.h>
Signature · 2 lines
With Best Regards,
Andy Shevchenko
author
#2 lore raw
Quoted 8 lines · Andy Shevchenko
Quoted 3 lines · Ken Xue

Andorid can wakeup from various wakeup sources, but only several wakeup sources can wake up screen with right events(POWER, WAKEUP) from input device.

You still have a room for 10+ characters on each line in the above paragraph. Why not use them?

ACK

Quoted 19 lines
Quoted 9 lines

Regarding pressing acpi power button, it can resume system and ACPI_BITMASK_WAKE_STATUS and ACPI_BITMASK_POWER_BUTTON_STATUS are set in pm1a_sts, but kernel does not report any key event to user space during resume by default.

So, trigger wakeup key event to user space during resume from power button.

...

drivers/acpi/button.c static int acpi_button_remove_fs(struct acpi_device *device) · line 371

Quoted 5 lines
drivers/acpi/button.c +5 -0
+void acpi_power_button_wakeup(struct acpi_device *dev)
+{
+	struct acpi_button *button = acpi_driver_data(dev);
+	struct input_dev *input;
+	if (button->type == ACPI_BUTTON_TYPE_POWER) {

It seems you missed the suggestion and I haven't heard an objection on written the above as

Quoted 2 lines
	if (button->type != ACPI_BUTTON_TYPE_POWER)
		return;

ACK. sorry that I do missed the suggestion at first place.

Quoted 24 lines
Quoted 7 lines
drivers/acpi/button.c +7 -0
+		input = button->input;
+		input_report_key(input, KEY_WAKEUP, 1);
+		input_sync(input);
+		input_report_key(input, KEY_WAKEUP, 0);
+		input_sync(input);
+	}
+}

...

Quoted 4 lines

#include <linux/syscore_ops.h>
#include <asm/io.h>
#include <trace/events/power.h>
+#include <acpi/button.h>

While at it, I would add a blank line here to distinguish groups of header inclusions.

   #include <linux/syscore_ops.h>
   #include <asm/io.h>
   #include <trace/events/power.h>

   #include <acpi/button.h>

Or even

Quoted 8 lines
   #include <linux/syscore_ops.h>

   #include <asm/io.h>

   #include <trace/events/power.h>

   #include <acpi/button.h>

ACK