linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Benjamin Tissoires <benjamin.tissoires@redhat.com>
To: Lv Zheng <lv.zheng@intel.com>,
	"Rafael J . Wysocki" <rafael.j.wysocki@intel.com>,
	"Rafael J . Wysocki" <rjw@rjwysocki.net>,
	Len Brown <len.brown@intel.com>, Lv Zheng <zetalog@gmail.com>,
	Peter Hutterer <peter.hutterer@who-t.net>
Cc: linux-acpi@vger.kernel.org,
	Benjamin Tissoires <benjamin.tissoires@redhat.com>,
	systemd-devel@lists.freedesktop.org,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org
Subject: [WIP PATCH 1/4] ACPI: button: extract input creation/destruction helpers
Date: Thu,  1 Jun 2017 20:46:29 +0200	[thread overview]
Message-ID: <20170601184632.2980-2-benjamin.tissoires@redhat.com> (raw)
In-Reply-To: <20170601184632.2980-1-benjamin.tissoires@redhat.com>

When the LID switch ACPI implementation is unreliable, we might want
to remove the device when we are not sure about the state. This should
prevent any suspend/resume loops given that in that case, there will be
no more LID switch input node.

This patch prepares the dynamic creation/destruction of the input node.

Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
---
 drivers/acpi/button.c | 90 ++++++++++++++++++++++++++++++++-------------------
 1 file changed, 57 insertions(+), 33 deletions(-)

diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index 9ad8cdb..48bcdca 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -448,10 +448,61 @@ static int acpi_button_resume(struct device *dev)
 }
 #endif
 
+static void acpi_button_remove_input(struct acpi_device *device)
+{
+	struct acpi_button *button = acpi_driver_data(device);
+
+	input_unregister_device(button->input);
+	button->input = NULL;
+}
+
+static int acpi_button_add_input(struct acpi_device *device)
+{
+	struct acpi_button *button = acpi_driver_data(device);
+	struct input_dev *input;
+	int error;
+
+	button->input = input = input_allocate_device();
+	if (!input) {
+		error = -ENOMEM;
+		goto err;
+	}
+
+	input->name = acpi_device_name(device);
+	input->phys = button->phys;
+	input->id.bustype = BUS_HOST;
+	input->id.product = button->type;
+	input->dev.parent = &device->dev;
+
+	switch (button->type) {
+	case ACPI_BUTTON_TYPE_POWER:
+		input_set_capability(input, EV_KEY, KEY_POWER);
+		break;
+
+	case ACPI_BUTTON_TYPE_SLEEP:
+		input_set_capability(input, EV_KEY, KEY_SLEEP);
+		break;
+
+	case ACPI_BUTTON_TYPE_LID:
+		input_set_capability(input, EV_SW, SW_LID);
+		break;
+	}
+
+	error = input_register_device(input);
+	if (error)
+		goto err;
+
+	return 0;
+
+ err:
+	input_free_device(input);
+	button->input = NULL;
+	return error;
+}
+
 static int acpi_button_add(struct acpi_device *device)
 {
 	struct acpi_button *button;
-	struct input_dev *input;
 	const char *hid = acpi_device_hid(device);
 	char *name, *class;
 	int error;
@@ -462,12 +513,6 @@ static int acpi_button_add(struct acpi_device *device)
 
 	device->driver_data = button;
 
-	button->input = input = input_allocate_device();
-	if (!input) {
-		error = -ENOMEM;
-		goto err_free_button;
-	}
-
 	name = acpi_device_name(device);
 	class = acpi_device_class(device);
 
@@ -493,38 +538,19 @@ static int acpi_button_add(struct acpi_device *device)
 	} else {
 		printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", hid);
 		error = -ENODEV;
-		goto err_free_input;
+		goto err_free_button;
 	}
 
 	error = acpi_button_add_fs(device);
 	if (error)
-		goto err_free_input;
+		goto err_free_button;
 
 	snprintf(button->phys, sizeof(button->phys), "%s/button/input0", hid);
 
-	input->name = name;
-	input->phys = button->phys;
-	input->id.bustype = BUS_HOST;
-	input->id.product = button->type;
-	input->dev.parent = &device->dev;
-
-	switch (button->type) {
-	case ACPI_BUTTON_TYPE_POWER:
-		input_set_capability(input, EV_KEY, KEY_POWER);
-		break;
-
-	case ACPI_BUTTON_TYPE_SLEEP:
-		input_set_capability(input, EV_KEY, KEY_SLEEP);
-		break;
-
-	case ACPI_BUTTON_TYPE_LID:
-		input_set_capability(input, EV_SW, SW_LID);
-		break;
-	}
-
-	error = input_register_device(input);
+	error = acpi_button_add_input(device);
 	if (error)
 		goto err_remove_fs;
+
 	if (button->type == ACPI_BUTTON_TYPE_LID) {
 		acpi_lid_initialize_state(device);
 		/*
@@ -540,8 +566,6 @@ static int acpi_button_add(struct acpi_device *device)
 
  err_remove_fs:
 	acpi_button_remove_fs(device);
- err_free_input:
-	input_free_device(input);
  err_free_button:
 	kfree(button);
 	return error;
@@ -552,7 +576,7 @@ static int acpi_button_remove(struct acpi_device *device)
 	struct acpi_button *button = acpi_driver_data(device);
 
 	acpi_button_remove_fs(device);
-	input_unregister_device(button->input);
+	acpi_button_remove_input(device);
 	kfree(button);
 	return 0;
 }
-- 
2.9.4

_______________________________________________
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/systemd-devel

  reply	other threads:[~2017-06-01 18:46 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-01 18:46 [WIP PATCH 0/4] Rework the unreliable LID switch exported by ACPI Benjamin Tissoires
2017-06-01 18:46 ` Benjamin Tissoires [this message]
2017-06-01 18:46 ` [WIP PATCH 2/4] ACPI: button: remove the LID input node when the state is unknown Benjamin Tissoires
2017-06-05  3:19   ` Zheng, Lv
2017-06-06 10:22     ` Benjamin Tissoires
2017-06-07  1:27       ` Peter Hutterer
2017-06-07  9:56       ` Zheng, Lv
2017-06-01 18:46 ` [WIP PATCH 3/4] ACPI: button: Let input filter out the LID events Benjamin Tissoires
2017-06-05  4:28   ` Zheng, Lv
2017-06-06 10:31     ` Benjamin Tissoires
2017-06-01 18:46 ` [WIP PATCH 4/4] ACPI: button: Fix lid notification locks Benjamin Tissoires
2017-06-05  3:33   ` Zheng, Lv
2017-06-06 10:29     ` Benjamin Tissoires
2017-06-07  9:47       ` Zheng, Lv
2017-06-01 21:43 ` [WIP PATCH 0/4] Rework the unreliable LID switch exported by ACPI Bastien Nocera
2017-06-02  7:24   ` Benjamin Tissoires
2017-06-05  2:25 ` Zheng, Lv
2017-06-07  7:48 ` Lennart Poettering
2017-06-13 10:06   ` Benjamin Tissoires
2017-06-15  2:52     ` [systemd-devel] " Zheng, Lv
2017-06-15  6:47       ` Peter Hutterer
2017-06-15  7:33         ` Zheng, Lv
2017-06-15  7:57           ` Peter Hutterer
2017-06-16  5:37             ` Zheng, Lv
2017-06-16  7:23               ` Benjamin Tissoires
2017-06-16  7:45                 ` Zheng, Lv
2017-06-16  8:09                   ` Benjamin Tissoires
2017-06-16  8:53                     ` [systemd-devel] " Zheng, Lv
2017-06-16  9:06                       ` Bastien Nocera
2017-06-16 16:32                         ` Lennart Poettering
2017-06-19  2:16                           ` Zheng, Lv
2017-06-19  1:43                         ` Zheng, Lv
2017-06-19 22:08                           ` Bastien Nocera
2017-06-20  2:45                             ` [systemd-devel] " Zheng, Lv
2017-06-21 10:23                               ` Bastien Nocera
2017-06-22  3:16                                 ` Zheng, Lv
2017-06-14 23:50   ` Zheng, Lv

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=20170601184632.2980-2-benjamin.tissoires@redhat.com \
    --to=benjamin.tissoires@redhat.com \
    --cc=len.brown@intel.com \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lv.zheng@intel.com \
    --cc=peter.hutterer@who-t.net \
    --cc=rafael.j.wysocki@intel.com \
    --cc=rjw@rjwysocki.net \
    --cc=systemd-devel@lists.freedesktop.org \
    --cc=zetalog@gmail.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;
as well as URLs for NNTP newsgroup(s).