platform-driver-x86.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: chris@cnpbagwell.com
To: platform-driver-x86@vger.kernel.org,
	acpi4asus-user@lists.sourceforge.net, yong.y.wang@intel.com
Cc: Chris Bagwell <chris@cnpbagwell.com>
Subject: [PATCH 2/2] eeepc-wmi: Add cpufv sysfs interface
Date: Sun, 10 Oct 2010 20:48:22 -0500	[thread overview]
Message-ID: <1286761702-4304-2-git-send-email-chris@cnpbagwell.com> (raw)
In-Reply-To: <1286761702-4304-1-git-send-email-chris@cnpbagwell.com>

From: Chris Bagwell <chris@cnpbagwell.com>

eeepc-laptop provides a sysfs interface to read and control what it
calls cpufv.  When WMI is enabled, the ACPI interface changes slightly
and becames a write-only control with only 3 valid values.

Write-only is OK because same DSDT's will ignore duplicate values
and even invalid values will be treated same as "0" value.

Expose cpufv again to allow for user space utils that can extended battery
life noticably and come a little closer to parity with eeepc-laptop.

This was tested with EEE PC 1005PE by monitoring powertop output while
writing values of "0", "1", and "2" and by reviewing the decompiled DSDT of
an 1201NL and comparing it to 1005PE's DSDT.

Signed-off-by: Chris Bagwell <chris@cnpbagwell.com>
---
 drivers/platform/x86/eeepc-wmi.c |   51 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 51 insertions(+), 0 deletions(-)

diff --git a/drivers/platform/x86/eeepc-wmi.c b/drivers/platform/x86/eeepc-wmi.c
index 441b000..988b16c 100644
--- a/drivers/platform/x86/eeepc-wmi.c
+++ b/drivers/platform/x86/eeepc-wmi.c
@@ -57,6 +57,7 @@ MODULE_ALIAS("wmi:"EEEPC_WMI_MGMT_GUID);
 
 #define EEEPC_WMI_METHODID_DEVS	0x53564544
 #define EEEPC_WMI_METHODID_DSTS	0x53544344
+#define EEEPC_WMI_METHODID_CFVS	0x53564643
 
 #define EEEPC_WMI_DEVID_BACKLIGHT	0x00050012
 
@@ -307,6 +308,49 @@ static void eeepc_wmi_notify(u32 value, void *context)
 	kfree(obj);
 }
 
+static int store_cpufv(struct device *dev, struct device_attribute *attr,
+		       const char *buf, size_t count)
+{
+	int value;
+	struct acpi_buffer input = { (acpi_size)sizeof(value), &value };
+	acpi_status status;
+
+	if (!count || sscanf(buf, "%i", &value) != 1)
+		return -EINVAL;
+	if (value < 0 || value > 2)
+		return -EINVAL;
+
+	status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID,
+				     1, EEEPC_WMI_METHODID_CFVS, &input, NULL);
+
+	if (ACPI_FAILURE(status))
+		return -EIO;
+	else
+		return count;
+}
+
+static DEVICE_ATTR(cpufv, S_IRUGO | S_IWUSR, NULL, store_cpufv);
+
+static void eeepc_wmi_sysfs_exit(struct platform_device *device)
+{
+	device_remove_file(&device->dev, &dev_attr_cpufv);
+}
+
+static int eeepc_wmi_sysfs_init(struct platform_device *device)
+{
+	int retval = -ENOMEM;
+
+	retval = device_create_file(&device->dev, &dev_attr_cpufv);
+	if (retval)
+		goto error_sysfs;
+
+	return 0;
+
+error_sysfs:
+	eeepc_wmi_sysfs_exit(platform_device);
+	return retval;
+}
+
 static int __devinit eeepc_wmi_platform_probe(struct platform_device *device)
 {
 	struct eeepc_wmi *eeepc;
@@ -402,8 +446,14 @@ static int __init eeepc_wmi_init(void)
 		goto del_dev;
 	}
 
+	err = eeepc_wmi_sysfs_init(platform_device);
+	if (err)
+		goto del_sysfs;
+
 	return 0;
 
+del_sysfs:
+	eeepc_wmi_sysfs_exit(platform_device);
 del_dev:
 	platform_device_del(platform_device);
 put_dev:
@@ -418,6 +468,7 @@ static void __exit eeepc_wmi_exit(void)
 {
 	struct eeepc_wmi *eeepc;
 
+	eeepc_wmi_sysfs_exit(platform_device);
 	eeepc = platform_get_drvdata(platform_device);
 	platform_driver_unregister(&platform_driver);
 	platform_device_unregister(platform_device);
-- 
1.7.3.1

  reply	other threads:[~2010-10-11  1:49 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-10-11  1:48 [PATCH 1/2] eeepc-wmi: add additional hotkeys chris
2010-10-11  1:48 ` chris [this message]
2010-10-11  6:44   ` [PATCH 2/2] eeepc-wmi: Add cpufv sysfs interface Corentin Chary
2010-10-11 13:29     ` Chris Bagwell
2010-10-11  6:26 ` [PATCH 1/2] eeepc-wmi: add additional hotkeys Corentin Chary
2010-10-11 13:25   ` Chris Bagwell
2010-10-11 13:57     ` Corentin Chary
     [not found]   ` <AANLkTin3J3oOaYD8G=YSrBr0AKzw7mY7v0BQssw5z2Z6-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-10-11 17:10     ` Dmitry Torokhov
2010-11-06  3:02       ` Chris Bagwell
2010-11-06  7:42         ` Corentin Chary
2010-11-06  9:39           ` Dmitry Torokhov

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=1286761702-4304-2-git-send-email-chris@cnpbagwell.com \
    --to=chris@cnpbagwell.com \
    --cc=acpi4asus-user@lists.sourceforge.net \
    --cc=platform-driver-x86@vger.kernel.org \
    --cc=yong.y.wang@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;
as well as URLs for NNTP newsgroup(s).