From: Ken Xue <Ken.Xue@amd.com>
To: <andriy.shevchenko@linux.intel.com>, <linux-acpi@vger.kernel.org>
Cc: <rafael@kernel.org>, <cwhuang@linux.org.tw>, Ken Xue <Ken.Xue@amd.com>
Subject: [PATCH V5] acpi: trigger wakeup key event from power button
Date: Sat, 7 Oct 2023 15:54:34 +0800 [thread overview]
Message-ID: <20231007075433.555715-1-Ken.Xue@amd.com> (raw)
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.
Signed-off-by: Ken Xue <Ken.Xue@amd.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
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/202309150947.YLjvs2Vv-lkp@intel.com/
---
drivers/acpi/Kconfig | 1 +
drivers/acpi/button.c | 17 +++++++++++++++++
drivers/acpi/sleep.c | 5 +++++
include/acpi/button.h | 4 ++++
4 files changed, 27 insertions(+)
diff --git a/drivers/acpi/Kconfig b/drivers/acpi/Kconfig
index 00dd309b6682..001da6233fcd 100644
--- a/drivers/acpi/Kconfig
+++ b/drivers/acpi/Kconfig
@@ -53,6 +53,7 @@ config ACPI_GENERIC_GSI
config ACPI_SYSTEM_POWER_STATES_SUPPORT
bool
+ select ACPI_BUTTON
config ACPI_CCA_REQUIRED
bool
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 1e76a64cce0a..3baddecd66c6 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -363,6 +363,22 @@ 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)
+ return;
+
+ 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 +595,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:
diff --git a/drivers/acpi/sleep.c b/drivers/acpi/sleep.c
index 808484d11209..f816606abd71 100644
--- a/drivers/acpi/sleep.c
+++ b/drivers/acpi/sleep.c
@@ -20,9 +20,13 @@
#include <linux/acpi.h>
#include <linux/module.h>
#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 +511,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);
}
diff --git a/include/acpi/button.h b/include/acpi/button.h
index af2fce5d2ee3..6126d665aa42 100644
--- a/include/acpi/button.h
+++ b/include/acpi/button.h
@@ -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
--
2.35.1
next reply other threads:[~2023-10-07 7:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-07 7:54 Ken Xue [this message]
2023-10-11 19:18 ` [PATCH V5] acpi: trigger wakeup key event from power button kernel test robot
2023-12-21 14:25 ` Rafael J. Wysocki
2023-12-25 5:56 ` Xue, Ken
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20231007075433.555715-1-Ken.Xue@amd.com \
--to=ken.xue@amd.com \
--cc=andriy.shevchenko@linux.intel.com \
--cc=cwhuang@linux.org.tw \
--cc=linux-acpi@vger.kernel.org \
--cc=rafael@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox