Skip to contentSkip to conversation

acpi: button: trigger wakeup key event

PATCH Applied Ken Xue 2 participants 2 messages Dec 25, 2023 – Dec 29, 2023 ACPI

lore
Share & tools
lore

Ken Xue

author
#0 lore raw

PATCH v6 1/1 acpi: button: trigger wakeup key event

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 resuming by default.

So, send 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.
V3->V4: refine coding style and commit message
V4->V5: add "select ACPI_BUTTON" to fix build error if CONFIG_ACPI_BUTTON=m. https://lore.kernel.org/oe-kbuild-all/[email protected]/
V5->V6: report WAKEUP event from button driver instead of acpi sleep.c

---
 drivers/acpi/button.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/acpi/button.c +10 -0
index 1e76a64cce0a..cc61020756be 100644
@@ -480,6 +480,7 @@ static int acpi_button_suspend(struct device *dev)
 
 static int acpi_button_resume(struct device *dev)
 {
+	struct input_dev *input;
 	struct acpi_device *device = to_acpi_device(dev);
 	struct acpi_button *button = acpi_driver_data(device);
 
@@ -489,6 +490,14 @@ static int acpi_button_resume(struct device *dev)
 		button->last_time = ktime_get();
 		acpi_lid_initialize_state(device);
 	}
+
+	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);
+	}
 	return 0;
 }
 #endif
@@ -579,6 +588,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:
Signature · 1 line
2.35.1
maintainer Applied
#1 lore raw
Quoted 54 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.

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 resuming by default.

So, send 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.
V3->V4: refine coding style and commit message
V4->V5: add "select ACPI_BUTTON" to fix build error if CONFIG_ACPI_BUTTON=m. https://lore.kernel.org/oe-kbuild-all/[email protected]/
V5->V6: report WAKEUP event from button driver instead of acpi sleep.c

---
 drivers/acpi/button.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/acpi/button.c +9 -0
index 1e76a64cce0a..cc61020756be 100644
@@ -480,6 +480,7 @@ static int acpi_button_suspend(struct device *dev)
 
 static int acpi_button_resume(struct device *dev)
 {
+       struct input_dev *input;
        struct acpi_device *device = to_acpi_device(dev);
        struct acpi_button *button = acpi_driver_data(device);
 
@@ -489,6 +490,14 @@ static int acpi_button_resume(struct device *dev)
                button->last_time = ktime_get();
                acpi_lid_initialize_state(device);
        }
+
+       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);
+       }
        return 0;
 }
 #endif

drivers/acpi/button.c static int acpi_button_add(struct acpi_device *device)

Quoted 8 lines
drivers/acpi/button.c +1 -1
@@ -579,6 +588,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:
--

Applied as 6.8 material with minor edits in the subject, thanks!