public inbox for linux-acpi@vger.kernel.org
 help / color / mirror / Atom feed
From: "Rafael J. Wysocki" <rjw@rjwysocki.net>
To: Linux ACPI <linux-acpi@vger.kernel.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Michal Wilczynski <michal.wilczynski@intel.com>
Subject: [RFT][PATCH v1 2/4] ACPI: button: Use different notify handlers for lid and buttons
Date: Sun, 04 Jun 2023 17:20:27 +0200	[thread overview]
Message-ID: <2438693.jE0xQCEvom@kreacher> (raw)
In-Reply-To: <1847933.atdPhlSkOF@kreacher>

From: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

Since the lid handling in acpi_button_notify() is special, introduce
acpi_lid_notify() specifically for handling lid notifications.

Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
---
 drivers/acpi/button.c |   33 ++++++++++++++++++++++++---------
 1 file changed, 24 insertions(+), 9 deletions(-)

Index: linux-pm/drivers/acpi/button.c
===================================================================
--- linux-pm.orig/drivers/acpi/button.c
+++ linux-pm/drivers/acpi/button.c
@@ -407,12 +407,10 @@ static void acpi_lid_initialize_state(st
 	button->lid_state_initialized = true;
 }
 
-static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
+static void acpi_lid_notify(acpi_handle handle, u32 event, void *data)
 {
 	struct acpi_device *device = data;
 	struct acpi_button *button;
-	struct input_dev *input;
-	int keycode;
 
 	if (event != ACPI_BUTTON_NOTIFY_STATUS) {
 		acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n",
@@ -421,16 +419,28 @@ static void acpi_button_notify(acpi_hand
 	}
 
 	button = acpi_driver_data(device);
+	if (!button->lid_state_initialized)
+		return;
 
-	if (button->type == ACPI_BUTTON_TYPE_LID) {
-		if (button->lid_state_initialized)
-			acpi_lid_update_state(device, true);
+	acpi_lid_update_state(device, true);
+}
 
+static void acpi_button_notify(acpi_handle handle, u32 event, void *data)
+{
+	struct acpi_device *device = data;
+	struct acpi_button *button;
+	struct input_dev *input;
+	int keycode;
+
+	if (event != ACPI_BUTTON_NOTIFY_STATUS) {
+		acpi_handle_debug(device->handle, "Unsupported event [0x%x]\n",
+				  event);
 		return;
 	}
 
 	acpi_pm_wakeup_event(&device->dev);
 
+	button = acpi_driver_data(device);
 	if (button->suspended)
 		return;
 
@@ -497,6 +507,7 @@ static int acpi_lid_input_open(struct in
 
 static int acpi_button_add(struct acpi_device *device)
 {
+	acpi_notify_handler handler;
 	struct acpi_button *button;
 	struct input_dev *input;
 	const char *hid = acpi_device_hid(device);
@@ -526,17 +537,20 @@ static int acpi_button_add(struct acpi_d
 	if (!strcmp(hid, ACPI_BUTTON_HID_POWER) ||
 	    !strcmp(hid, ACPI_BUTTON_HID_POWERF)) {
 		button->type = ACPI_BUTTON_TYPE_POWER;
+		handler = acpi_button_notify;
 		strcpy(name, ACPI_BUTTON_DEVICE_NAME_POWER);
 		sprintf(class, "%s/%s",
 			ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_POWER);
 	} else if (!strcmp(hid, ACPI_BUTTON_HID_SLEEP) ||
 		   !strcmp(hid, ACPI_BUTTON_HID_SLEEPF)) {
 		button->type = ACPI_BUTTON_TYPE_SLEEP;
+		handler = acpi_button_notify;
 		strcpy(name, ACPI_BUTTON_DEVICE_NAME_SLEEP);
 		sprintf(class, "%s/%s",
 			ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_SLEEP);
 	} else if (!strcmp(hid, ACPI_BUTTON_HID_LID)) {
 		button->type = ACPI_BUTTON_TYPE_LID;
+		handler = acpi_lid_notify;
 		strcpy(name, ACPI_BUTTON_DEVICE_NAME_LID);
 		sprintf(class, "%s/%s",
 			ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
@@ -594,8 +608,7 @@ static int acpi_button_add(struct acpi_d
 		break;
 	default:
 		status = acpi_install_notify_handler(device->handle,
-						     ACPI_DEVICE_NOTIFY,
-						     acpi_button_notify,
+						     ACPI_DEVICE_NOTIFY, handler,
 						     device);
 		break;
 	}
@@ -640,7 +653,9 @@ static void acpi_button_remove(struct ac
 		break;
 	default:
 		acpi_remove_notify_handler(device->handle, ACPI_DEVICE_NOTIFY,
-					   acpi_button_notify);
+					   button->type == ACPI_BUTTON_TYPE_LID ?
+					   	acpi_lid_notify :
+					   	acpi_button_notify);
 		break;
 	}
 	acpi_os_wait_events_complete();




  parent reply	other threads:[~2023-06-04 15:24 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-04 15:17 [RFT][PATCH v1 0/4] ACPI: Install notify or event handlers in ACPI button drivers Rafael J. Wysocki
2023-06-04 15:19 ` [RFT][PATCH v1 1/4] ACPI: button: Eliminate the driver notify callback Rafael J. Wysocki
2023-06-09 17:44   ` Wilczynski, Michal
2023-06-04 15:20 ` Rafael J. Wysocki [this message]
2023-06-04 15:22 ` [RFT][PATCH v1 3/4] ACPI: tiny-power-button: " Rafael J. Wysocki
2023-06-04 15:23 ` [RFT][PATCH v1 4/4] ACPI: bus: Simplify installation and removal of " Rafael J. Wysocki

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=2438693.jE0xQCEvom@kreacher \
    --to=rjw@rjwysocki.net \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michal.wilczynski@intel.com \
    /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