Add patches accepted for 2.6.22-rc4
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / releases / upstream / 2.6.22-rc1 / 0033-ACPI-thinkpad-acpi-register-with-the-device-model.patch
blob428a0de6716faad184f000401c17570e1440d688
1 From 54ae15014c306b3d7ad32c996fea9a5ac8560b60 Mon Sep 17 00:00:00 2001
2 From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
3 Date: Tue, 24 Apr 2007 11:48:12 -0300
4 Subject: ACPI: thinkpad-acpi: register with the device model
6 Register thinkpad-acpi platform driver and platform device for the device
7 model. Also register the platform device with the hwmon class.
9 Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
10 Signed-off-by: Len Brown <len.brown@intel.com>
11 ---
12 Documentation/thinkpad-acpi.txt | 40 ++++++++++++++++++++++++----
13 drivers/misc/Kconfig | 1 +
14 drivers/misc/thinkpad_acpi.c | 54 +++++++++++++++++++++++++++++++++++++++
15 drivers/misc/thinkpad_acpi.h | 8 ++++++
16 4 files changed, 97 insertions(+), 6 deletions(-)
18 diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt
19 index 1a42b77..0e4e053 100644
20 --- a/Documentation/thinkpad-acpi.txt
21 +++ b/Documentation/thinkpad-acpi.txt
22 @@ -1,7 +1,7 @@
23 ThinkPad ACPI Extras Driver
25 Version 0.14
26 - March 26th, 2007
27 + April 21st, 2007
29 Borislav Deianov <borislav@users.sf.net>
30 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
31 @@ -67,11 +67,39 @@ thinkpad-specific bay functionality.
32 Features
33 --------
35 -The driver creates the /proc/acpi/ibm directory. There is a file under
36 -that directory for each feature described below. Note that while the
37 -driver is still in the alpha stage, the exact proc file format and
38 -commands supported by the various features is guaranteed to change
39 -frequently.
40 +The driver exports two different interfaces to userspace, which can be
41 +used to access the features it provides. One is a legacy procfs-based
42 +interface, which will be removed at some time in the distant future.
43 +The other is a new sysfs-based interface which is not complete yet.
45 +The procfs interface creates the /proc/acpi/ibm directory. There is a
46 +file under that directory for each feature it supports. The procfs
47 +interface is mostly frozen, and will change very little if at all: it
48 +will not be extended to add any new functionality in the driver, instead
49 +all new functionality will be implemented on the sysfs interface.
51 +The sysfs interface tries to blend in the generic Linux sysfs subsystems
52 +and classes as much as possible. Since some of these subsystems are not
53 +yet ready or stabilized, it is expected that this interface will change,
54 +and any and all userspace programs must deal with it.
57 +Notes about the sysfs interface:
59 +Unlike what was done with the procfs interface, correctness when talking
60 +to the sysfs interfaces will be enforced, as will correctness in the
61 +thinkpad-acpi's implementation of sysfs interfaces.
63 +Also, any bugs in the thinkpad-acpi sysfs driver code or in the
64 +thinkpad-acpi's implementation of the sysfs interfaces will be fixed for
65 +maximum correctness, even if that means changing an interface in
66 +non-compatible ways. As these interfaces mature both in the kernel and
67 +in thinkpad-acpi, such changes should become quite rare.
69 +Applications interfacing to the thinkpad-acpi sysfs interfaces must
70 +follow all sysfs guidelines and correctly process all errors (the sysfs
71 +interface makes extensive use of errors). File descriptors and open /
72 +close operations to the sysfs inodes must also be properly implemented.
74 Driver version -- /proc/acpi/ibm/driver
75 ---------------------------------------
76 diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
77 index 44e4c8f..445c4b1 100644
78 --- a/drivers/misc/Kconfig
79 +++ b/drivers/misc/Kconfig
80 @@ -126,6 +126,7 @@ config THINKPAD_ACPI
81 tristate "ThinkPad ACPI Laptop Extras"
82 depends on X86 && ACPI
83 select BACKLIGHT_CLASS_DEVICE
84 + select HWMON
85 ---help---
86 This is a driver for the IBM and Lenovo ThinkPad laptops. It adds
87 support for Fn-Fx key combinations, Bluetooth control, video
88 diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
89 index 9b4eea4..e47eaf7 100644
90 --- a/drivers/misc/thinkpad_acpi.c
91 +++ b/drivers/misc/thinkpad_acpi.c
92 @@ -477,6 +477,25 @@ static char *next_cmd(char **cmds)
93 /****************************************************************************
94 ****************************************************************************
96 + * Device model: hwmon and platform
97 + *
98 + ****************************************************************************
99 + ****************************************************************************/
101 +static struct platform_device *tpacpi_pdev = NULL;
102 +static struct class_device *tpacpi_hwmon = NULL;
104 +static struct platform_driver tpacpi_pdriver = {
105 + .driver = {
106 + .name = IBM_DRVR_NAME,
107 + .owner = THIS_MODULE,
108 + },
112 +/****************************************************************************
113 + ****************************************************************************
115 * Subdrivers
117 ****************************************************************************
118 @@ -3225,10 +3244,12 @@ static int __init thinkpad_acpi_module_init(void)
120 int ret, i;
122 + /* Driver-level probe */
123 ret = probe_for_thinkpad();
124 if (ret)
125 return ret;
127 + /* Driver initialization */
128 ibm_thinkpad_ec_found = check_dmi_for_ec();
129 IBM_ACPIHANDLE_INIT(ecrd);
130 IBM_ACPIHANDLE_INIT(ecwr);
131 @@ -3241,6 +3262,31 @@ static int __init thinkpad_acpi_module_init(void)
133 proc_dir->owner = THIS_MODULE;
135 + ret = platform_driver_register(&tpacpi_pdriver);
136 + if (ret) {
137 + printk(IBM_ERR "unable to register platform driver\n");
138 + thinkpad_acpi_module_exit();
139 + return ret;
142 + /* Device initialization */
143 + tpacpi_pdev = platform_device_register_simple(IBM_DRVR_NAME, -1,
144 + NULL, 0);
145 + if (IS_ERR(tpacpi_pdev)) {
146 + ret = PTR_ERR(tpacpi_pdev);
147 + tpacpi_pdev = NULL;
148 + printk(IBM_ERR "unable to register platform device\n");
149 + thinkpad_acpi_module_exit();
150 + return ret;
152 + tpacpi_hwmon = hwmon_device_register(&tpacpi_pdev->dev);
153 + if (IS_ERR(tpacpi_hwmon)) {
154 + ret = PTR_ERR(tpacpi_hwmon);
155 + tpacpi_hwmon = NULL;
156 + printk(IBM_ERR "unable to register hwmon device\n");
157 + thinkpad_acpi_module_exit();
158 + return ret;
160 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
161 ret = ibm_init(&ibms_init[i]);
162 if (ret >= 0 && *ibms_init[i].param)
163 @@ -3266,6 +3312,14 @@ static void thinkpad_acpi_module_exit(void)
165 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
167 + if (tpacpi_hwmon)
168 + hwmon_device_unregister(tpacpi_hwmon);
170 + if (tpacpi_pdev)
171 + platform_device_unregister(tpacpi_pdev);
173 + platform_driver_unregister(&tpacpi_pdriver);
175 if (proc_dir)
176 remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);
178 diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h
179 index 6432b28..fea5809 100644
180 --- a/drivers/misc/thinkpad_acpi.h
181 +++ b/drivers/misc/thinkpad_acpi.h
182 @@ -34,6 +34,8 @@
183 #include <linux/proc_fs.h>
184 #include <linux/backlight.h>
185 #include <linux/fb.h>
186 +#include <linux/platform_device.h>
187 +#include <linux/hwmon.h>
188 #include <asm/uaccess.h>
190 #include <linux/dmi.h>
191 @@ -56,6 +58,7 @@
193 #define IBM_PROC_DIR "ibm"
194 #define IBM_ACPI_EVENT_PREFIX "ibm"
195 +#define IBM_DRVR_NAME IBM_FILE
197 #define IBM_LOG IBM_FILE ": "
198 #define IBM_ERR KERN_ERR IBM_LOG
199 @@ -130,6 +133,11 @@ static int dispatch_procfs_write(struct file *file,
200 unsigned long count, void *data);
201 static char *next_cmd(char **cmds);
203 +/* Device model */
204 +static struct platform_device *tpacpi_pdev;
205 +static struct class_device *tpacpi_hwmon;
206 +static struct platform_driver tpacpi_pdriver;
208 /* Module */
209 static int experimental;
210 static u32 dbg_level;
212 1.5.1