[PATCH #3355] Add sysfs support for powering down the OLPC 88W8838 wireless chip.
Chris Ball
cjb at laptop.org
Fri Jun 13 20:05:47 EDT 2008
Hi Deepak,
> I think the preffered way to do this is via sscanf() of the
> incoming buffer as you can catch errors such as non-integer
> input. simple_stroul() will just return 0 which is not what we
> want.
> I'd also change the mode to 0400 as this is a write-only bit.
> My preffered option is to make it r/w, call it wlan_enabled and
> than we could check the state via the file too by storing the
> current setting.
All applied in the replacement patch below. Thanks!
- Chris.
From: Chris Ball <cjb at laptop.org>
Date: Fri, 13 Jun 2008 19:53:30 -0400
Subject: [PATCH #3355] Add sysfs support for powering down the OLPC 88W8838 wireless chip.
This uses the OLPC EC 0x35/0x25 interface.
Signed-off-by: Chris Ball <cjb at laptop.org>
---
arch/x86/kernel/olpc-pm.c | 32 ++++++++++++++++++++++++++++++++
1 files changed, 32 insertions(+), 0 deletions(-)
diff --git a/arch/x86/kernel/olpc-pm.c b/arch/x86/kernel/olpc-pm.c
index e99a464..bc6c160 100644
--- a/arch/x86/kernel/olpc-pm.c
+++ b/arch/x86/kernel/olpc-pm.c
@@ -43,6 +43,8 @@
/* These, and the battery EC commands, should be in an olpc.h. */
#define EC_WRITE_SCI_MASK 0x1b
#define EC_READ_SCI_MASK 0x1c
+#define EC_WLAN_ENTER_RESET 0x35
+#define EC_WLAN_LEAVE_RESET 0x25
extern void do_olpc_suspend_lowlevel(void);
@@ -69,6 +71,8 @@ static u16 olpc_wakeup_mask = 0;
static unsigned int test_timeout = 0;
static char *wackup_source = "none";
+static unsigned int wlan_enabled = 1;
+
struct platform_device olpc_powerbutton_dev = {
.name = "powerbutton",
.id = -1,
@@ -661,6 +665,30 @@ static ssize_t wackup_show(struct kobject *s, struct kobj_attribute *attr,
return sprintf(buf, "%s\n", wackup_source ? wackup_source : "none");
}
+static ssize_t wlan_enabled_show(struct kobject *s, struct kobj_attribute *attr,
+ char *buf)
+{
+ return sprintf(buf, "%u\n", wlan_enabled);
+}
+
+static ssize_t wlan_enabled_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;
+ }
+ if (val == 1) {
+ olpc_ec_cmd(EC_WLAN_LEAVE_RESET, NULL, 0, NULL, 0);
+ wlan_enabled = 1;
+ }
+ else if (val == 0) {
+ olpc_ec_cmd(EC_WLAN_ENTER_RESET, NULL, 0, NULL, 0);
+ wlan_enabled = 0;
+ }
+ return n;
+}
+
static struct kobj_attribute control_attr =
__ATTR(olpc-pm, 0644, control_show, control_store);
@@ -670,10 +698,14 @@ static struct kobj_attribute test_attr =
static struct kobj_attribute wackup_attr =
__ATTR(wakeup-source, 0400, wackup_show, NULL);
+static struct kobj_attribute wlanenabled_attr =
+ __ATTR(wlan-enabled, 0644, wlan_enabled_show, wlan_enabled_store);
+
static struct attribute * olpc_attributes[] = {
&control_attr.attr,
&test_attr.attr,
&wackup_attr.attr,
+ &wlanenabled_attr.attr,
NULL
};
--
1.5.4.3
More information about the Devel
mailing list