Skip to content

Commit

Permalink
ACPI/PM: Propagate power button event to user space when device wakes up
Browse files Browse the repository at this point in the history
Sometimes power button does not wake up the systemm and we get suspends
event right after that. Here Android needs to see KEY_POWER at resume.
Otherwise, its opportunistic suspend will kick in shortly.

However, other OS such as Ubuntu doesn't like KEY_POWER at resume.
So add a knob "/sys/module/button/parameters/key_power_at_resume" for
users to select.

Signed-off-by: Kaushlendra Kumar <[email protected]>
  • Loading branch information
kaushlen committed Sep 17, 2024
1 parent 2517f05 commit 067478a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
6 changes: 5 additions & 1 deletion drivers/acpi/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@
#define ACPI_BUTTON_DEVICE_NAME_LID "Lid Switch"
#define ACPI_BUTTON_TYPE_LID 0x05

/* does userspace want to see KEY_POWER at resume? */
static bool __read_mostly key_power_at_resume = true;
module_param(key_power_at_resume, bool, 0644);

enum {
ACPI_BUTTON_LID_INIT_IGNORE,
ACPI_BUTTON_LID_INIT_OPEN,
Expand Down Expand Up @@ -441,7 +445,7 @@ static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
acpi_pm_wakeup_event(&device->dev);

button = acpi_driver_data(device);
if (button->suspended)
if (button->suspended && !key_power_at_resume)
return;

input = button->input;
Expand Down
7 changes: 7 additions & 0 deletions drivers/acpi/sleep.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,6 +454,12 @@ static int acpi_pm_prepare(void)
return error;
}

static void pwr_btn_notify(struct acpi_device *device)
{
struct acpi_driver *acpi_drv = to_acpi_driver(device->dev.driver);
acpi_drv->ops.notify(device, ACPI_FIXED_HARDWARE_EVENT);
}

/**
* acpi_pm_finish - Instruct the platform to leave a sleep state.
*
Expand Down Expand Up @@ -496,6 +502,7 @@ static void acpi_pm_finish(void)
NULL, -1);
if (pwr_btn_adev) {
pm_wakeup_event(&pwr_btn_adev->dev, 0);
pwr_btn_notify(pwr_btn_adev);
acpi_dev_put(pwr_btn_adev);
}
}
Expand Down

0 comments on commit 067478a

Please sign in to comment.