* [PATCH resend 2] x86, olpc-xo15-sci: Enable lid close wakeup control through sysfs
@ 2011-11-29 22:24 Daniel Drake
2011-11-30 23:15 ` Andrew Morton
0 siblings, 1 reply; 5+ messages in thread
From: Daniel Drake @ 2011-11-29 22:24 UTC (permalink / raw)
To: akpm, x86, mingo, hpa, tglx; +Cc: dilinger, linux-kernel, linux-acpi
Like most systems, OLPC's ACPI LID switch wakes up the system when the
lid is opened, but not when it is closed.
Under OLPC's opportunistic suspend model, the lid may be closed while
the system was oportunistically suspended with the screen running.
In this event, we want to wake up to turn the screen off.
Enable control of normal ACPI wakeups through lid close events through
a new sysfs attribute "lid_wake_on_closed". When set, and when
LID wakeups are enabled through ACPI, the system will wake up on both
open and close lid events.
Signed-off-by: Daniel Drake <dsd@laptop.org>
---
arch/x86/platform/olpc/olpc-xo15-sci.c | 55 ++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
Resending after 6 weeks with no feedback.
diff --git a/arch/x86/platform/olpc/olpc-xo15-sci.c b/arch/x86/platform/olpc/olpc-xo15-sci.c
index 2b235b7..649230c 100644
--- a/arch/x86/platform/olpc/olpc-xo15-sci.c
+++ b/arch/x86/platform/olpc/olpc-xo15-sci.c
@@ -24,6 +24,50 @@
#define XO15_SCI_DEVICE_NAME "OLPC XO-1.5 SCI"
static unsigned long xo15_sci_gpe;
+static bool lid_wake_on_close;
+
+static int set_lid_wake_behavior(bool wake_on_close)
+{
+ struct acpi_object_list arg_list;
+ union acpi_object arg;
+ acpi_status status;
+
+ arg_list.count = 1;
+ arg_list.pointer = &arg;
+ arg.type = ACPI_TYPE_INTEGER;
+ arg.integer.value = wake_on_close;
+ status = acpi_evaluate_object(NULL, "\\_SB.PCI0.LID.LIDW", &arg_list,
+ NULL);
+ if (ACPI_FAILURE(status)) {
+ pr_warning(PFX "failed to set lid behaviour\n");
+ return 1;
+ }
+
+ lid_wake_on_close = wake_on_close;
+ return 0;
+}
+
+static ssize_t lid_wake_on_close_show(struct kobject *s,
+ struct kobj_attribute *attr, char *buf)
+{
+ return sprintf(buf, "%u\n", lid_wake_on_close);
+}
+
+static ssize_t lid_wake_on_close_store(struct kobject *s,
+ struct kobj_attribute *attr,
+ const char *buf, size_t n)
+{
+ unsigned int val;
+ if (!sscanf(buf, "%u", &val) == 1)
+ return -EINVAL;
+
+ set_lid_wake_behavior(!!val);
+ return n;
+}
+
+static struct kobj_attribute lid_wake_on_close_attr =
+ __ATTR(lid_wake_on_close, 0644,
+ lid_wake_on_close_show, lid_wake_on_close_store);
static void battery_status_changed(void)
{
@@ -91,6 +135,7 @@ static int xo15_sci_add(struct acpi_device *device)
{
unsigned long long tmp;
acpi_status status;
+ int r;
if (!device)
return -EINVAL;
@@ -112,6 +157,10 @@ static int xo15_sci_add(struct acpi_device *device)
dev_info(&device->dev, "Initialized, GPE = 0x%lx\n", xo15_sci_gpe);
+ r = sysfs_create_file(&device->dev.kobj, &lid_wake_on_close_attr.attr);
+ if (r)
+ goto err_sysfs;
+
/* Flush queue, and enable all SCI events */
process_sci_queue();
olpc_ec_mask_write(EC_SCI_SRC_ALL);
@@ -123,6 +172,11 @@ static int xo15_sci_add(struct acpi_device *device)
device_init_wakeup(&device->dev, true);
return 0;
+
+err_sysfs:
+ acpi_remove_gpe_handler(NULL, xo15_sci_gpe, xo15_sci_gpe_handler);
+ cancel_work_sync(&sci_work);
+ return r;
}
static int xo15_sci_remove(struct acpi_device *device, int type)
@@ -130,6 +184,7 @@ static int xo15_sci_remove(struct acpi_device *device, int type)
acpi_disable_gpe(NULL, xo15_sci_gpe);
acpi_remove_gpe_handler(NULL, xo15_sci_gpe, xo15_sci_gpe_handler);
cancel_work_sync(&sci_work);
+ sysfs_remove_file(&device->dev.kobj, &lid_wake_on_close_attr.attr);
return 0;
}
--
1.7.7.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH resend 2] x86, olpc-xo15-sci: Enable lid close wakeup control through sysfs
@ 2011-11-29 22:24 Daniel Drake
0 siblings, 0 replies; 5+ messages in thread
From: Daniel Drake @ 2011-11-29 22:24 UTC (permalink / raw)
To: akpm, x86, mingo, hpa, tglx; +Cc: dilinger, linux-kernel, linux-acpi
Like most systems, OLPC's ACPI LID switch wakes up the system when the
lid is opened, but not when it is closed.
Under OLPC's opportunistic suspend model, the lid may be closed while
the system was oportunistically suspended with the screen running.
In this event, we want to wake up to turn the screen off.
Enable control of normal ACPI wakeups through lid close events through
a new sysfs attribute "lid_wake_on_closed". When set, and when
LID wakeups are enabled through ACPI, the system will wake up on both
open and close lid events.
Signed-off-by: Daniel Drake <dsd@laptop.org>
---
arch/x86/platform/olpc/olpc-xo15-sci.c | 55 ++++++++++++++++++++++++++++++++
1 files changed, 55 insertions(+), 0 deletions(-)
Resending after 6 weeks with no feedback.
diff --git a/arch/x86/platform/olpc/olpc-xo15-sci.c b/arch/x86/platform/olpc/olpc-xo15-sci.c
index 2b235b7..649230c 100644
--- a/arch/x86/platform/olpc/olpc-xo15-sci.c
+++ b/arch/x86/platform/olpc/olpc-xo15-sci.c
@@ -24,6 +24,50 @@
#define XO15_SCI_DEVICE_NAME "OLPC XO-1.5 SCI"
static unsigned long xo15_sci_gpe;
+static bool lid_wake_on_close;
+
+static int set_lid_wake_behavior(bool wake_on_close)
+{
+ struct acpi_object_list arg_list;
+ union acpi_object arg;
+ acpi_status status;
+
+ arg_list.count = 1;
+ arg_list.pointer = &arg;
+ arg.type = ACPI_TYPE_INTEGER;
+ arg.integer.value = wake_on_close;
+ status = acpi_evaluate_object(NULL, "\\_SB.PCI0.LID.LIDW", &arg_list,
+ NULL);
+ if (ACPI_FAILURE(status)) {
+ pr_warning(PFX "failed to set lid behaviour\n");
+ return 1;
+ }
+
+ lid_wake_on_close = wake_on_close;
+ return 0;
+}
+
+static ssize_t lid_wake_on_close_show(struct kobject *s,
+ struct kobj_attribute *attr, char *buf)
+{
+ return sprintf(buf, "%u\n", lid_wake_on_close);
+}
+
+static ssize_t lid_wake_on_close_store(struct kobject *s,
+ struct kobj_attribute *attr,
+ const char *buf, size_t n)
+{
+ unsigned int val;
+ if (!sscanf(buf, "%u", &val) == 1)
+ return -EINVAL;
+
+ set_lid_wake_behavior(!!val);
+ return n;
+}
+
+static struct kobj_attribute lid_wake_on_close_attr =
+ __ATTR(lid_wake_on_close, 0644,
+ lid_wake_on_close_show, lid_wake_on_close_store);
static void battery_status_changed(void)
{
@@ -91,6 +135,7 @@ static int xo15_sci_add(struct acpi_device *device)
{
unsigned long long tmp;
acpi_status status;
+ int r;
if (!device)
return -EINVAL;
@@ -112,6 +157,10 @@ static int xo15_sci_add(struct acpi_device *device)
dev_info(&device->dev, "Initialized, GPE = 0x%lx\n", xo15_sci_gpe);
+ r = sysfs_create_file(&device->dev.kobj, &lid_wake_on_close_attr.attr);
+ if (r)
+ goto err_sysfs;
+
/* Flush queue, and enable all SCI events */
process_sci_queue();
olpc_ec_mask_write(EC_SCI_SRC_ALL);
@@ -123,6 +172,11 @@ static int xo15_sci_add(struct acpi_device *device)
device_init_wakeup(&device->dev, true);
return 0;
+
+err_sysfs:
+ acpi_remove_gpe_handler(NULL, xo15_sci_gpe, xo15_sci_gpe_handler);
+ cancel_work_sync(&sci_work);
+ return r;
}
static int xo15_sci_remove(struct acpi_device *device, int type)
@@ -130,6 +184,7 @@ static int xo15_sci_remove(struct acpi_device *device, int type)
acpi_disable_gpe(NULL, xo15_sci_gpe);
acpi_remove_gpe_handler(NULL, xo15_sci_gpe, xo15_sci_gpe_handler);
cancel_work_sync(&sci_work);
+ sysfs_remove_file(&device->dev.kobj, &lid_wake_on_close_attr.attr);
return 0;
}
--
1.7.7.3
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH resend 2] x86, olpc-xo15-sci: Enable lid close wakeup control through sysfs
2011-11-29 22:24 [PATCH resend 2] x86, olpc-xo15-sci: Enable lid close wakeup control through sysfs Daniel Drake
@ 2011-11-30 23:15 ` Andrew Morton
2011-12-04 11:50 ` Alan Jenkins
0 siblings, 1 reply; 5+ messages in thread
From: Andrew Morton @ 2011-11-30 23:15 UTC (permalink / raw)
To: Daniel Drake; +Cc: x86, mingo, hpa, tglx, dilinger, linux-kernel, linux-acpi
On Tue, 29 Nov 2011 22:24:47 +0000 (GMT)
Daniel Drake <dsd@laptop.org> wrote:
> Like most systems, OLPC's ACPI LID switch wakes up the system when the
> lid is opened, but not when it is closed.
>
> Under OLPC's opportunistic suspend model, the lid may be closed while
> the system was oportunistically suspended with the screen running.
> In this event, we want to wake up to turn the screen off.
>
> Enable control of normal ACPI wakeups through lid close events through
> a new sysfs attribute "lid_wake_on_closed". When set, and when
> LID wakeups are enabled through ACPI, the system will wake up on both
> open and close lid events.
>
> Signed-off-by: Daniel Drake <dsd@laptop.org>
> ---
> arch/x86/platform/olpc/olpc-xo15-sci.c | 55 ++++++++++++++++++++++++++++++++
> 1 files changed, 55 insertions(+), 0 deletions(-)
>
> Resending after 6 weeks with no feedback.
>
> diff --git a/arch/x86/platform/olpc/olpc-xo15-sci.c b/arch/x86/platform/olpc/olpc-xo15-sci.c
> index 2b235b7..649230c 100644
> --- a/arch/x86/platform/olpc/olpc-xo15-sci.c
> +++ b/arch/x86/platform/olpc/olpc-xo15-sci.c
> @@ -24,6 +24,50 @@
> #define XO15_SCI_DEVICE_NAME "OLPC XO-1.5 SCI"
>
> static unsigned long xo15_sci_gpe;
> +static bool lid_wake_on_close;
I'd have thought that a few code comments which describe what all this
is doing wouldn't hurt. Oh well.
> +static int set_lid_wake_behavior(bool wake_on_close)
> +{
> + struct acpi_object_list arg_list;
> + union acpi_object arg;
> + acpi_status status;
> +
> + arg_list.count = 1;
> + arg_list.pointer = &arg;
> + arg.type = ACPI_TYPE_INTEGER;
> + arg.integer.value = wake_on_close;
> + status = acpi_evaluate_object(NULL, "\\_SB.PCI0.LID.LIDW", &arg_list,
> + NULL);
> + if (ACPI_FAILURE(status)) {
> + pr_warning(PFX "failed to set lid behaviour\n");
> + return 1;
> + }
> +
> + lid_wake_on_close = wake_on_close;
> + return 0;
> +}
> +
> +static ssize_t lid_wake_on_close_show(struct kobject *s,
> + struct kobj_attribute *attr, char *buf)
> +{
> + return sprintf(buf, "%u\n", lid_wake_on_close);
> +}
> +
> +static ssize_t lid_wake_on_close_store(struct kobject *s,
> + struct kobj_attribute *attr,
> + const char *buf, size_t n)
> +{
> + unsigned int val;
> + if (!sscanf(buf, "%u", &val) == 1)
> + return -EINVAL;
> +
> + set_lid_wake_behavior(!!val);
> + return n;
> +}
Let me fix that for you.
--- a/arch/x86/platform/olpc/olpc-xo15-sci.c~x86-olpc-xo15-sci-enable-lid-close-wakeup-control-through-sysfs-fix
+++ a/arch/x86/platform/olpc/olpc-xo15-sci.c
@@ -58,7 +58,8 @@ static ssize_t lid_wake_on_close_store(s
const char *buf, size_t n)
{
unsigned int val;
- if (!sscanf(buf, "%u", &val) == 1)
+
+ if (sscanf(buf, "%u", &val) != 1)
return -EINVAL;
set_lid_wake_behavior(!!val);
It's kinda irritating that this will cheerfully accept bogus input of
the form "42foo". This happens about eleven billion times in sysfs
write() handlers but afaik we've never implemented a nice
sysfs_int_from_buffer() thingy which handles all the possible errors.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: Re: [PATCH resend 2] x86, olpc-xo15-sci: Enable lid close wakeup control through sysfs
2011-11-30 23:15 ` Andrew Morton
@ 2011-12-04 11:50 ` Alan Jenkins
2011-12-05 5:42 ` Andrew Morton
0 siblings, 1 reply; 5+ messages in thread
From: Alan Jenkins @ 2011-12-04 11:50 UTC (permalink / raw)
To: Andrew Morton, Daniel Drake
Cc: x86, mingo, hpa, tglx, dilinger, linux-kernel, linux-acpi
On 01/-10/37 20:59, Andrew Morton wrote:
> Let me fix that for you.
>
> --- a/arch/x86/platform/olpc/olpc-xo15-sci.c~x86-olpc-xo15-sci-enable-lid-close-wakeup-control-through-sysfs-fix
> +++ a/arch/x86/platform/olpc/olpc-xo15-sci.c
> @@ -58,7 +58,8 @@ static ssize_t lid_wake_on_close_store(s
> const char *buf, size_t n)
> {
> unsigned int val;
> - if (!sscanf(buf, "%u",&val) == 1)
> +
> + if (sscanf(buf, "%u",&val) != 1)
> return -EINVAL;
>
> set_lid_wake_behavior(!!val);
>
> It's kinda irritating that this will cheerfully accept bogus input of
> the form "42foo". This happens about eleven billion times in sysfs
> write() handlers but afaik we've never implemented a nice
> sysfs_int_from_buffer() thingy which handles all the possible errors.
I thought there was.
strict_strtoul() ?
Alan
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH resend 2] x86, olpc-xo15-sci: Enable lid close wakeup control through sysfs
2011-12-04 11:50 ` Alan Jenkins
@ 2011-12-05 5:42 ` Andrew Morton
0 siblings, 0 replies; 5+ messages in thread
From: Andrew Morton @ 2011-12-05 5:42 UTC (permalink / raw)
To: Alan Jenkins
Cc: Daniel Drake, x86, mingo, hpa, tglx, dilinger, linux-kernel,
linux-acpi
On Sun, 04 Dec 2011 11:50:08 +0000 Alan Jenkins <alan.christopher.jenkins@googlemail.com> wrote:
> On 01/-10/37 20:59, Andrew Morton wrote:
> > Let me fix that for you.
> >
> > --- a/arch/x86/platform/olpc/olpc-xo15-sci.c~x86-olpc-xo15-sci-enable-lid-close-wakeup-control-through-sysfs-fix
> > +++ a/arch/x86/platform/olpc/olpc-xo15-sci.c
> > @@ -58,7 +58,8 @@ static ssize_t lid_wake_on_close_store(s
> > const char *buf, size_t n)
> > {
> > unsigned int val;
> > - if (!sscanf(buf, "%u",&val) == 1)
> > +
> > + if (sscanf(buf, "%u",&val) != 1)
> > return -EINVAL;
> >
> > set_lid_wake_behavior(!!val);
> >
> > It's kinda irritating that this will cheerfully accept bogus input of
> > the form "42foo". This happens about eleven billion times in sysfs
> > write() handlers but afaik we've never implemented a nice
> > sysfs_int_from_buffer() thingy which handles all the possible errors.
>
> I thought there was.
>
> strict_strtoul() ?
>
(that was replaced by kstrto*())
I was more thinking of the trailing \n problem. But ksrtto*() appears
to treat "42\n" as "42" so yup, that's good.
(One could argue that a sysfs string handler should also strip leading
and trailing white space. I'd disagree!)
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2011-12-05 5:41 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-11-29 22:24 [PATCH resend 2] x86, olpc-xo15-sci: Enable lid close wakeup control through sysfs Daniel Drake
2011-11-30 23:15 ` Andrew Morton
2011-12-04 11:50 ` Alan Jenkins
2011-12-05 5:42 ` Andrew Morton
-- strict thread matches above, loose matches on Subject: below --
2011-11-29 22:24 Daniel Drake
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).