From: Mattia Dongili <malattia@linux.it>
To: Matthew Garrett <mjg@redhat.com>
Cc: platform-driver-x86@vger.kernel.org, Mattia Dongili <malattia@linux.it>
Subject: [PATCH 6/8] sony-laptop: cache handles and report them via sysfs
Date: Sat, 19 Feb 2011 11:52:30 +0900 [thread overview]
Message-ID: <1298083952-22493-7-git-send-email-malattia@linux.it> (raw)
In-Reply-To: <1298083952-22493-1-git-send-email-malattia@linux.it>
Avoid calling into acpi each time we need to lookup a method handle
and report the available handles to ease collection of information when
debugging issues. Also move initialization of the platform driver
earlier to allow adding files from other setup functions.
Signed-off-by: Mattia Dongili <malattia@linux.it>
---
drivers/platform/x86/sony-laptop.c | 97 ++++++++++++++++++++++++++++++------
1 files changed, 81 insertions(+), 16 deletions(-)
diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
index 22519a4..1585d37 100644
--- a/drivers/platform/x86/sony-laptop.c
+++ b/drivers/platform/x86/sony-laptop.c
@@ -727,20 +727,79 @@ static int acpi_callsetfunc(acpi_handle handle, char *name, int value,
return -1;
}
-static int sony_find_snc_handle(int handle)
+struct sony_nc_handles {
+ u16 cap[0x10];
+ struct device_attribute devattr;
+};
+
+struct sony_nc_handles *handles;
+
+static ssize_t sony_nc_handles_show(struct device *dev,
+ struct device_attribute *attr, char *buffer)
+{
+ ssize_t len = 0;
+ int i;
+
+ for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
+ len += snprintf(buffer + len, PAGE_SIZE - len, "0x%.4x ",
+ handles->cap[i]);
+ }
+ len += snprintf(buffer + len, PAGE_SIZE - len, "\n");
+
+ return len;
+}
+
+static int sony_nc_handles_setup(struct platform_device *pd)
{
int i;
int result;
- for (i = 0x20; i < 0x30; i++) {
- acpi_callsetfunc(sony_nc_acpi_handle, "SN00", i, &result);
- if (result == handle) {
- dprintk("found handle 0x%.4x (offset: 0x%.2x)\n",
- handle, i - 0x20);
- return i-0x20;
+ handles = kzalloc(sizeof(*handles), GFP_KERNEL);
+
+ sysfs_attr_init(handles->devattr);
+ handles->devattr.attr.name = "handles";
+ handles->devattr.attr.mode = S_IRUGO;
+ handles->devattr.show = sony_nc_handles_show;
+
+ for (i = 0; i < ARRAY_SIZE(handles->cap); i++) {
+ if (!acpi_callsetfunc(sony_nc_acpi_handle,
+ "SN00", i + 0x20, &result)) {
+ dprintk("caching handle 0x%.4x (offset: 0x%.2x)\n",
+ result, i);
+ handles->cap[i] = result;
}
}
+ /* allow reading capabilities via sysfs */
+ if (device_create_file(&pd->dev, &handles->devattr)) {
+ kfree(handles);
+ handles = NULL;
+ return -1;
+ }
+
+ return 0;
+}
+
+static int sony_nc_handles_cleanup(struct platform_device *pd)
+{
+ if (handles) {
+ device_remove_file(&pd->dev, &handles->devattr);
+ kfree(handles);
+ handles = NULL;
+ }
+ return 0;
+}
+
+static int sony_find_snc_handle(int handle)
+{
+ int i;
+ for (i = 0; i < 0x10; i++) {
+ if (handles->cap[i] == handle) {
+ dprintk("found handle 0x%.4x (offset: 0x%.2x)\n",
+ handle, i);
+ return i;
+ }
+ }
dprintk("handle 0x%.4x not found\n", handle);
return -1;
}
@@ -1274,6 +1333,10 @@ static int sony_nc_add(struct acpi_device *device)
goto outwalk;
}
+ result = sony_pf_add();
+ if (result)
+ goto outpresent;
+
if (debug) {
status = acpi_walk_namespace(ACPI_TYPE_METHOD,
sony_nc_acpi_handle, 1, sony_walk_callback,
@@ -1281,7 +1344,7 @@ static int sony_nc_add(struct acpi_device *device)
if (ACPI_FAILURE(status)) {
pr_warn(DRV_PFX "unable to walk acpi resources\n");
result = -ENODEV;
- goto outwalk;
+ goto outpresent;
}
}
@@ -1294,6 +1357,8 @@ static int sony_nc_add(struct acpi_device *device)
if (ACPI_SUCCESS(acpi_get_handle(sony_nc_acpi_handle, "SN00",
&handle))) {
dprintk("Doing SNC setup\n");
+ if (sony_nc_handles_setup(sony_pf_device))
+ goto outpresent;
sony_nc_function_setup(device);
sony_nc_rfkill_setup(device);
}
@@ -1302,7 +1367,7 @@ static int sony_nc_add(struct acpi_device *device)
result = sony_laptop_setup_input(device);
if (result) {
pr_err(DRV_PFX "Unable to create input devices.\n");
- goto outwalk;
+ goto outsnc;
}
if (acpi_video_backlight_support()) {
@@ -1329,10 +1394,6 @@ static int sony_nc_add(struct acpi_device *device)
}
- result = sony_pf_add();
- if (result)
- goto outbacklight;
-
/* create sony_pf sysfs attributes related to the SNC device */
for (item = sony_nc_values; item->name; ++item) {
@@ -1378,14 +1439,17 @@ static int sony_nc_add(struct acpi_device *device)
for (item = sony_nc_values; item->name; ++item) {
device_remove_file(&sony_pf_device->dev, &item->devattr);
}
- sony_pf_remove();
-
- outbacklight:
if (sony_backlight_device)
backlight_device_unregister(sony_backlight_device);
sony_laptop_remove_input();
+ outsnc:
+ sony_nc_handles_cleanup(sony_pf_device);
+
+ outpresent:
+ sony_pf_remove();
+
outwalk:
sony_nc_rfkill_cleanup();
return result;
@@ -1404,6 +1468,7 @@ static int sony_nc_remove(struct acpi_device *device, int type)
device_remove_file(&sony_pf_device->dev, &item->devattr);
}
+ sony_nc_handles_cleanup(sony_pf_device);
sony_pf_remove();
sony_laptop_remove_input();
sony_nc_rfkill_cleanup();
--
1.7.2.3
next prev parent reply other threads:[~2011-02-19 3:00 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-02-19 2:52 [0/8] sony-laptop for 2.6.39 Mattia Dongili
2011-02-19 2:52 ` [PATCH 1/8] sony-laptop: add some debug printk useful for bug reports Mattia Dongili
2011-02-19 2:52 ` [PATCH 2/8] sony-laptop: documentation updates Mattia Dongili
2011-02-19 2:52 ` [PATCH 3/8] sony-laptop: ignore hard switch rfkill events (SPIC) Mattia Dongili
2011-02-19 3:06 ` Matthew Garrett
2011-02-19 12:46 ` Mattia Dongili
2011-02-19 12:52 ` Thomas Klose
2011-02-19 16:00 ` Matthew Garrett
2011-02-20 3:13 ` Mattia Dongili
2011-02-19 2:52 ` [PATCH 4/8] sony-laptop: use pr_<level> for messages Mattia Dongili
2011-02-19 2:52 ` [PATCH 5/8] sony-laptop: remove unused Type4 define Mattia Dongili
2011-02-19 2:52 ` Mattia Dongili [this message]
2011-02-19 2:52 ` [PATCH 7/8] sony-laptop: implement keyboard backlight support Mattia Dongili
2011-02-19 2:52 ` [PATCH 8/8] sony-laptop: implement new backlight control method Mattia Dongili
2011-02-21 20:51 ` [0/8] sony-laptop for 2.6.39 Matthew Garrett
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=1298083952-22493-7-git-send-email-malattia@linux.it \
--to=malattia@linux.it \
--cc=mjg@redhat.com \
--cc=platform-driver-x86@vger.kernel.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.