Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1659606 > unrolled thread
| Started by | Lv Zheng <lv.zheng@intel.com> |
|---|---|
| First post | 2017-06-07 11:50 +0200 |
| Last post | 2017-06-07 12:10 +0200 |
| Articles | 3 — 1 participant |
Back to article view | Back to linux.kernel
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
[RFC PATCH 0/2] ACPI: button: Fix button.lid_init_state=method mode Lv Zheng <lv.zheng@intel.com> - 2017-06-07 11:50 +0200
[RFC PATCH v5 2/2] ACPI: button: Add a quirk mode for Surface Pro 1 like laptop Lv Zheng <lv.zheng@intel.com> - 2017-06-07 11:50 +0200
[RFC PATCH v5 1/2] ACPI: button: Fix issue that button notify cannot report stateful SW_LID state Lv Zheng <lv.zheng@intel.com> - 2017-06-07 12:10 +0200
| From | Lv Zheng <lv.zheng@intel.com> |
|---|---|
| Date | 2017-06-07 11:50 +0200 |
| Subject | [RFC PATCH 0/2] ACPI: button: Fix button.lid_init_state=method mode |
| Message-ID | <tPFLb-4SX-1@gated-at.bofh.it> |
The following approach fixes button.lid_init_state=method mode for
systemd 233:
https://patchwork.kernel.org/patch/9756457/
https://patchwork.kernel.org/patch/9756467/
But it is not working well with old systemd 229. This solution tries to
make a more comfortable approach for systemd 229.
There are platform variations implementing ACPI lid device in different
way:
1. Some platforms send "open" events to OS and the events arrive before
button driver is resumed;
2. Some platforms send "open" events to OS, but the events arrive after
button driver is resumed, ex., Samsung N210+;
3. Some platforms never send "open" events to OS, but send "open" events to
update the cached _LID return value, and the update events arrive before
button driver is resumed;
4. Some platforms never send "open" events to OS, but send "open" events to
update the cached _LID return value, but the update events arrive after
button driver is resumed, ex., Surface Pro 3;
5. Some platforms never send "open" events, _LID returns value sticks to
"close", ex., Surface Pro 1.
[PATCH 1] tries to fix case 2,4, making them working with any systemd.
[PATCH 2] tries to fix case 5, making it working with systemd 233.
This is also a replacement of the following solution:
https://patchwork.kernel.org/patch/9760867/
It seems adding/removing input node and requesting systemd to
change again is unnecessary for such platforms, so this patch
simply converts "lid_unreliable" into
"button.lid_init_state=ignore".
This material is just sent to demonstrate solutions and issues, the
final solution is not determined yet. So marking them as RFC.
Lv Zheng (2):
ACPI: button: Fix issue that button notify cannot report stateful
SW_LID state
ACPI: button: Add a quirk mode for Surface Pro 1 like laptop
drivers/acpi/button.c | 188 ++++++++++++++++++++++++--------------------------
1 file changed, 89 insertions(+), 99 deletions(-)
--
2.7.4
[toc] | [next] | [standalone]
| From | Lv Zheng <lv.zheng@intel.com> |
|---|---|
| Date | 2017-06-07 11:50 +0200 |
| Subject | [RFC PATCH v5 2/2] ACPI: button: Add a quirk mode for Surface Pro 1 like laptop |
| Message-ID | <tPFLd-4SX-51@gated-at.bofh.it> |
| In reply to | #1659606 |
Some platforms never send "open" events, _LID returns value sticks to
"close", ex., Surface Pro 1.
Such platforms cannot work well with systemd 229 in
button.lid_init_state=method mode, but button.lid_init_state=open
workaround is available for them to work with systemd 229 and they can work
perfectly with systemd 233 in button.lid_init_state=ignore mode.
This patch introduces a boot parameter to mark such platform lid device as
unreliable to replace old button.lid_init_state=ignore mode. So that users
can use this quirk to make such platforms working with systemd 233. Since
such platform only sends "close", old complicated "open" complement event
mechanism is replaced by a simpler one of always prepending "open" before
any events.
Cc: <systemd-devel@lists.freedesktop.org>
Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
---
drivers/acpi/button.c | 164 ++++++++++++++++++++------------------------------
1 file changed, 66 insertions(+), 98 deletions(-)
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index fd8eff6..02b85c1 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -56,9 +56,8 @@
#define ACPI_BUTTON_DEVICE_NAME_LID "Lid Switch"
#define ACPI_BUTTON_TYPE_LID 0x05
-#define ACPI_BUTTON_LID_INIT_IGNORE 0x00
+#define ACPI_BUTTON_LID_INIT_METHOD 0x00
#define ACPI_BUTTON_LID_INIT_OPEN 0x01
-#define ACPI_BUTTON_LID_INIT_METHOD 0x02
#define _COMPONENT ACPI_BUTTON_COMPONENT
ACPI_MODULE_NAME("button");
@@ -109,23 +108,20 @@ struct acpi_button {
struct timer_list lid_timer;
char phys[32]; /* for input device */
unsigned long pushed;
- int last_state;
- ktime_t last_time;
bool suspended;
};
+static DEFINE_MUTEX(lid_device_lock);
static BLOCKING_NOTIFIER_HEAD(acpi_lid_notifier);
static struct acpi_device *lid_device;
static u8 lid_init_state = ACPI_BUTTON_LID_INIT_METHOD;
-static unsigned long lid_report_interval __read_mostly = 500;
-module_param(lid_report_interval, ulong, 0644);
-MODULE_PARM_DESC(lid_report_interval, "Interval (ms) between lid key events");
-
static unsigned long lid_update_interval __read_mostly = 10 * MSEC_PER_SEC;
module_param(lid_update_interval, ulong, 0644);
MODULE_PARM_DESC(lid_update_interval, "Interval (ms) between lid state updates");
+static bool lid_unreliable __read_mostly = false;
+
/* --------------------------------------------------------------------------
FS Interface (/proc)
-------------------------------------------------------------------------- */
@@ -149,79 +145,12 @@ static int acpi_lid_notify_state(struct acpi_device *device, int state)
{
struct acpi_button *button = acpi_driver_data(device);
int ret;
- ktime_t next_report;
- bool do_update;
-
- /*
- * In lid_init_state=ignore mode, if user opens/closes lid
- * frequently with "open" missing, and "last_time" is also updated
- * frequently, "close" cannot be delivered to the userspace.
- * So "last_time" is only updated after a timeout or an actual
- * switch.
- */
- if (lid_init_state != ACPI_BUTTON_LID_INIT_IGNORE ||
- button->last_state != !!state)
- do_update = true;
- else
- do_update = false;
-
- next_report = ktime_add(button->last_time,
- ms_to_ktime(lid_report_interval));
- if (button->last_state == !!state &&
- ktime_after(ktime_get(), next_report)) {
- /* Complain the buggy firmware */
- pr_warn_once("The lid device is not compliant to SW_LID.\n");
- /*
- * Send the unreliable complement switch event:
- *
- * On most platforms, the lid device is reliable. However
- * there are exceptions:
- * 1. Platforms returning initial lid state as "close" by
- * default after booting/resuming:
- * https://bugzilla.kernel.org/show_bug.cgi?id=89211
- * https://bugzilla.kernel.org/show_bug.cgi?id=106151
- * 2. Platforms never reporting "open" events:
- * https://bugzilla.kernel.org/show_bug.cgi?id=106941
- * On these buggy platforms, the usage model of the ACPI
- * lid device actually is:
- * 1. The initial returning value of _LID may not be
- * reliable.
- * 2. The open event may not be reliable.
- * 3. The close event is reliable.
- *
- * But SW_LID is typed as input switch event, the input
- * layer checks if the event is redundant. Hence if the
- * state is not switched, the userspace cannot see this
- * platform triggered reliable event. By inserting a
- * complement switch event, it then is guaranteed that the
- * platform triggered reliable one can always be seen by
- * the userspace.
- */
- if (lid_init_state == ACPI_BUTTON_LID_INIT_IGNORE) {
- do_update = true;
- /*
- * Do generate complement switch event for "close"
- * as "close" is reliable and wrong "open" won't
- * trigger unexpected behaviors.
- * Do not generate complement switch event for
- * "open" as "open" is not reliable and wrong
- * "close" will trigger unexpected behaviors.
- */
- if (!state) {
- input_report_switch(button->input,
- SW_LID, state);
- input_sync(button->input);
- }
- }
- }
- /* Send the platform triggered reliable event */
- if (do_update) {
- input_report_switch(button->input, SW_LID, !state);
- input_sync(button->input);
- button->last_state = !!state;
- button->last_time = ktime_get();
- }
+ if (lid_unreliable)
+ input_report_switch(button->input, SW_LID, 0);
+
+ input_report_switch(button->input, SW_LID, !state);
+ input_sync(button->input);
if (state)
pm_wakeup_event(&device->dev, 0);
@@ -382,22 +311,25 @@ static void acpi_lid_tick(struct acpi_device *device)
{
struct acpi_button *button = acpi_driver_data(device);
- mod_timer(&button->lid_timer,
- jiffies + msecs_to_jiffies(lid_update_interval));
+ if (!lid_unreliable)
+ mod_timer(&button->lid_timer,
+ jiffies + msecs_to_jiffies(lid_update_interval));
}
static void acpi_lid_timeout(ulong arg)
{
struct acpi_device *device = (struct acpi_device *)arg;
- switch (lid_init_state) {
- case ACPI_BUTTON_LID_INIT_OPEN:
- (void)acpi_lid_notify_state(device, 1);
- break;
- case ACPI_BUTTON_LID_INIT_METHOD:
- acpi_lid_update_state(device);
- acpi_lid_tick(device);
- break;
+ if (!lid_unreliable) {
+ switch (lid_init_state) {
+ case ACPI_BUTTON_LID_INIT_OPEN:
+ (void)acpi_lid_notify_state(device, 1);
+ break;
+ case ACPI_BUTTON_LID_INIT_METHOD:
+ acpi_lid_update_state(device);
+ acpi_lid_tick(device);
+ break;
+ }
}
}
@@ -506,8 +438,6 @@ static int acpi_button_add(struct acpi_device *device)
strcpy(name, ACPI_BUTTON_DEVICE_NAME_LID);
sprintf(class, "%s/%s",
ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
- button->last_state = !!acpi_lid_evaluate_state(device);
- button->last_time = ktime_get();
setup_timer(&button->lid_timer,
acpi_lid_timeout, (ulong)device);
} else {
@@ -551,7 +481,10 @@ static int acpi_button_add(struct acpi_device *device)
* This assumes there's only one lid device, or if there are
* more we only care about the last one...
*/
+ mutex_lock(&lid_device_lock);
+ get_device(&device->dev);
lid_device = device;
+ mutex_unlock(&lid_device_lock);
}
printk(KERN_INFO PREFIX "%s [%s]\n", name, acpi_device_bid(device));
@@ -570,8 +503,15 @@ static int acpi_button_remove(struct acpi_device *device)
{
struct acpi_button *button = acpi_driver_data(device);
- if (button->type == ACPI_BUTTON_TYPE_LID)
+ if (button->type == ACPI_BUTTON_TYPE_LID) {
del_timer(&button->lid_timer);
+ mutex_lock(&lid_device_lock);
+ if (device == lid_device) {
+ put_device(&device->dev);
+ lid_device = NULL;
+ }
+ mutex_unlock(&lid_device_lock);
+ }
acpi_button_remove_fs(device);
input_unregister_device(button->input);
kfree(button);
@@ -588,9 +528,6 @@ static int param_set_lid_init_state(const char *val, struct kernel_param *kp)
} else if (!strncmp(val, "method", sizeof("method") - 1)) {
lid_init_state = ACPI_BUTTON_LID_INIT_METHOD;
pr_info("Notify initial lid state with _LID return value\n");
- } else if (!strncmp(val, "ignore", sizeof("ignore") - 1)) {
- lid_init_state = ACPI_BUTTON_LID_INIT_IGNORE;
- pr_info("Do not notify initial lid state\n");
} else
result = -EINVAL;
return result;
@@ -603,17 +540,48 @@ static int param_get_lid_init_state(char *buffer, struct kernel_param *kp)
return sprintf(buffer, "open");
case ACPI_BUTTON_LID_INIT_METHOD:
return sprintf(buffer, "method");
- case ACPI_BUTTON_LID_INIT_IGNORE:
- return sprintf(buffer, "ignore");
default:
return sprintf(buffer, "invalid");
}
return 0;
}
+static int param_set_lid_unreliable(const char *val, struct kernel_param *kp)
+{
+ int result = 0;
+ struct device *dev;
+ struct acpi_device *device;
+ struct acpi_button *button;
+
+ result = param_set_bool(val, kp);
+ if (result)
+ return result;
+
+ mutex_lock(&lid_device_lock);
+ if (lid_device) {
+ dev = get_device(&lid_device->dev);
+ mutex_unlock(&lid_device_lock);
+ device = to_acpi_device(dev);
+ button = acpi_driver_data(device);
+ if (lid_unreliable)
+ del_timer(&button->lid_timer);
+ else
+ acpi_lid_tick(device);
+ put_device(&device->dev);
+ mutex_lock(&lid_device_lock);
+ }
+ mutex_unlock(&lid_device_lock);
+ return result;
+}
+
module_param_call(lid_init_state,
param_set_lid_init_state, param_get_lid_init_state,
NULL, 0644);
MODULE_PARM_DESC(lid_init_state, "Behavior for reporting LID initial state");
+module_param_call(lid_unreliable,
+ param_set_lid_unreliable, param_get_bool,
+ &lid_unreliable, 0644);
+MODULE_PARM_DESC(lid_unreliable, "Mark lid device as unreliable");
+
module_acpi_driver(acpi_button_driver);
--
2.7.4
[toc] | [prev] | [next] | [standalone]
| From | Lv Zheng <lv.zheng@intel.com> |
|---|---|
| Date | 2017-06-07 12:10 +0200 |
| Subject | [RFC PATCH v5 1/2] ACPI: button: Fix issue that button notify cannot report stateful SW_LID state |
| Message-ID | <tPG4x-5f5-3@gated-at.bofh.it> |
| In reply to | #1659606 |
There are platform variations implementing ACPI lid device in different
ways:
1. Some platforms send "open" events to OS and the events arrive before
button driver is resumed;
2. Some platforms send "open" events to OS, but the events arrive after
button driver is resumed, ex., Samsung N210+;
3. Some platforms never send "open" events to OS, but send "open" events to
update the cached _LID return value, and the update events arrive before
button driver is resumed;
4. Some platforms never send "open" events to OS, but send "open" events to
update the cached _LID return value, but the update events arrive after
button driver is resumed, ex., Surface Pro 3;
5. Some platforms never send "open" events, _LID returns value sticks to
"close", ex., Surface Pro 1.
Currently, only case 1,3 works fine with systemd 229.
Case 2,4 can be treated as an order issue. This patch first fixes this
issue by defer sending initial lid state 10 seconds later after resume,
which ensures acpi_ec_resume() is always invoked before
acpi_button_resume().
However we can see different problems due to systemd bugs:
systemd won't suspend right after seeing "close" event, it has a timeout,
within the timeout, user may opens lid again. But even lid
firmware/driver properly deliver this "open" to user space, when the
timeout tickes, systemd still suspends the platform.
Then user has to close/open again to wake the system up. Noticing that
the first close event will remain in firmware, after resume, user space
can still see a "close" followed by "open", and nothing can stop systemd
from suspending again.
This problem can only be fixed by continously updating lid state. Thus
this patch doesn't kill the timer after seeing the BIOS notification, but
continously sending _LID return value to the input layer for
button.lid_init_state=method mode.
The users can configure update interval via button.lid_update_interval.
Cc: <systemd-devel@lists.freedesktop.org>
Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: Peter Hutterer <peter.hutterer@who-t.net>
Signed-off-by: Lv Zheng <lv.zheng@intel.com>
---
drivers/acpi/button.c | 36 +++++++++++++++++++++++++++++-------
1 file changed, 29 insertions(+), 7 deletions(-)
diff --git a/drivers/acpi/button.c b/drivers/acpi/button.c
index e19f530..fd8eff6 100644
--- a/drivers/acpi/button.c
+++ b/drivers/acpi/button.c
@@ -28,6 +28,7 @@
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
#include <linux/input.h>
+#include <linux/timer.h>
#include <linux/slab.h>
#include <linux/acpi.h>
#include <acpi/button.h>
@@ -79,6 +80,7 @@ MODULE_DEVICE_TABLE(acpi, button_device_ids);
static int acpi_button_add(struct acpi_device *device);
static int acpi_button_remove(struct acpi_device *device);
static void acpi_button_notify(struct acpi_device *device, u32 event);
+static void acpi_lid_timeout(ulong arg);
#ifdef CONFIG_PM_SLEEP
static int acpi_button_suspend(struct device *dev);
@@ -104,6 +106,7 @@ static struct acpi_driver acpi_button_driver = {
struct acpi_button {
unsigned int type;
struct input_dev *input;
+ struct timer_list lid_timer;
char phys[32]; /* for input device */
unsigned long pushed;
int last_state;
@@ -119,6 +122,10 @@ static unsigned long lid_report_interval __read_mostly = 500;
module_param(lid_report_interval, ulong, 0644);
MODULE_PARM_DESC(lid_report_interval, "Interval (ms) between lid key events");
+static unsigned long lid_update_interval __read_mostly = 10 * MSEC_PER_SEC;
+module_param(lid_update_interval, ulong, 0644);
+MODULE_PARM_DESC(lid_update_interval, "Interval (ms) between lid state updates");
+
/* --------------------------------------------------------------------------
FS Interface (/proc)
-------------------------------------------------------------------------- */
@@ -371,17 +378,25 @@ static int acpi_lid_update_state(struct acpi_device *device)
return acpi_lid_notify_state(device, state);
}
-static void acpi_lid_initialize_state(struct acpi_device *device)
+static void acpi_lid_tick(struct acpi_device *device)
+{
+ struct acpi_button *button = acpi_driver_data(device);
+
+ mod_timer(&button->lid_timer,
+ jiffies + msecs_to_jiffies(lid_update_interval));
+}
+
+static void acpi_lid_timeout(ulong arg)
{
+ struct acpi_device *device = (struct acpi_device *)arg;
+
switch (lid_init_state) {
case ACPI_BUTTON_LID_INIT_OPEN:
(void)acpi_lid_notify_state(device, 1);
break;
case ACPI_BUTTON_LID_INIT_METHOD:
- (void)acpi_lid_update_state(device);
- break;
- case ACPI_BUTTON_LID_INIT_IGNORE:
- default:
+ acpi_lid_update_state(device);
+ acpi_lid_tick(device);
break;
}
}
@@ -432,6 +447,8 @@ static int acpi_button_suspend(struct device *dev)
struct acpi_device *device = to_acpi_device(dev);
struct acpi_button *button = acpi_driver_data(device);
+ if (button->type == ACPI_BUTTON_TYPE_LID)
+ del_timer(&button->lid_timer);
button->suspended = true;
return 0;
}
@@ -443,7 +460,7 @@ static int acpi_button_resume(struct device *dev)
button->suspended = false;
if (button->type == ACPI_BUTTON_TYPE_LID)
- acpi_lid_initialize_state(device);
+ acpi_lid_tick(device);
return 0;
}
#endif
@@ -467,6 +484,7 @@ static int acpi_button_add(struct acpi_device *device)
error = -ENOMEM;
goto err_free_button;
}
+ init_timer(&button->lid_timer);
name = acpi_device_name(device);
class = acpi_device_class(device);
@@ -490,6 +508,8 @@ static int acpi_button_add(struct acpi_device *device)
ACPI_BUTTON_CLASS, ACPI_BUTTON_SUBCLASS_LID);
button->last_state = !!acpi_lid_evaluate_state(device);
button->last_time = ktime_get();
+ setup_timer(&button->lid_timer,
+ acpi_lid_timeout, (ulong)device);
} else {
printk(KERN_ERR PREFIX "Unsupported hid [%s]\n", hid);
error = -ENODEV;
@@ -526,7 +546,7 @@ static int acpi_button_add(struct acpi_device *device)
if (error)
goto err_remove_fs;
if (button->type == ACPI_BUTTON_TYPE_LID) {
- acpi_lid_initialize_state(device);
+ acpi_lid_tick(device);
/*
* This assumes there's only one lid device, or if there are
* more we only care about the last one...
@@ -550,6 +570,8 @@ static int acpi_button_remove(struct acpi_device *device)
{
struct acpi_button *button = acpi_driver_data(device);
+ if (button->type == ACPI_BUTTON_TYPE_LID)
+ del_timer(&button->lid_timer);
acpi_button_remove_fs(device);
input_unregister_device(button->input);
kfree(button);
--
2.7.4
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web