Add a patch accepted in 2.6.24-rc1 that was forgotten
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / releases / upstream / 2.6.24-rc1 / 0012-ACPI-thinkpad-acpi-use-a-separate-platform-device.patch
bloba2b75cd66d915fc84f4e7fd4c2bee5748bc1f82c
1 From 7fd400297978a2cf7a74344fb22020e9479b4f69 Mon Sep 17 00:00:00 2001
2 From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
3 Date: Tue, 25 Sep 2007 06:38:03 -0300
4 Subject: [PATCH 11/23] ACPI: thinkpad-acpi: use a separate platform device for hwmon and name it (v2)
6 Use a separate platform device and driver ("thinkpad_hwmon") to attach
7 hwmon attributes and class, and add a name attribute of "thinkpad" to
8 it, which defines the hwmon device name for libsensors4.
10 This makes thinkpad-acpi compatible with libsensors4 from lm-sensors, and
11 the platform driver and device split will make it much easier to separate
12 hwmon functionality into its own module later on.
14 Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
15 Cc: Jean Delvare <khali@linux-fr.org>
16 Signed-off-by: Len Brown <len.brown@intel.com>
17 ---
18 Documentation/thinkpad-acpi.txt | 25 +++++++++---
19 drivers/misc/thinkpad_acpi.c | 79 +++++++++++++++++++++++++++++++++------
20 drivers/misc/thinkpad_acpi.h | 6 ++-
21 3 files changed, 91 insertions(+), 19 deletions(-)
23 diff --git a/Documentation/thinkpad-acpi.txt b/Documentation/thinkpad-acpi.txt
24 index 60953d6..3b95bba 100644
25 --- a/Documentation/thinkpad-acpi.txt
26 +++ b/Documentation/thinkpad-acpi.txt
27 @@ -105,10 +105,15 @@ The version of thinkpad-acpi's sysfs interface is exported by the driver
28 as a driver attribute (see below).
30 Sysfs driver attributes are on the driver's sysfs attribute space,
31 -for 2.6.20 this is /sys/bus/platform/drivers/thinkpad_acpi/.
32 +for 2.6.23 this is /sys/bus/platform/drivers/thinkpad_acpi/ and
33 +/sys/bus/platform/drivers/thinkpad_hwmon/
35 -Sysfs device attributes are on the driver's sysfs attribute space,
36 -for 2.6.20 this is /sys/devices/platform/thinkpad_acpi/.
37 +Sysfs device attributes are on the thinkpad_acpi device sysfs attribute
38 +space, for 2.6.23 this is /sys/devices/platform/thinkpad_acpi/.
40 +Sysfs device attributes for the sensors and fan are on the
41 +thinkpad_hwmon device's sysfs attribute space, but you should locate it
42 +looking for a hwmon device with the name attribute of "thinkpad".
44 Driver version
45 --------------
46 @@ -766,7 +771,7 @@ Temperature sensors
47 -------------------
49 procfs: /proc/acpi/ibm/thermal
50 -sysfs device attributes: (hwmon) temp*_input
51 +sysfs device attributes: (hwmon "thinkpad") temp*_input
53 Most ThinkPads include six or more separate temperature sensors but only
54 expose the CPU temperature through the standard ACPI methods. This
55 @@ -989,7 +994,9 @@ Fan control and monitoring: fan speed, fan enable/disable
56 ---------------------------------------------------------
58 procfs: /proc/acpi/ibm/fan
59 -sysfs device attributes: (hwmon) fan_input, pwm1, pwm1_enable
60 +sysfs device attributes: (hwmon "thinkpad") fan1_input, pwm1,
61 + pwm1_enable
62 +sysfs hwmon driver attributes: fan_watchdog
64 NOTE NOTE NOTE: fan control operations are disabled by default for
65 safety reasons. To enable them, the module parameter "fan_control=1"
66 @@ -1131,7 +1138,7 @@ hwmon device attribute fan1_input:
67 which can take up to two minutes. May return rubbish on older
68 ThinkPads.
70 -driver attribute fan_watchdog:
71 +hwmon driver attribute fan_watchdog:
72 Fan safety watchdog timer interval, in seconds. Minimum is
73 1 second, maximum is 120 seconds. 0 disables the watchdog.
75 @@ -1233,3 +1240,9 @@ Sysfs interface changelog:
76 layer, the radio switch generates input event EV_RADIO,
77 and the driver enables hot key handling by default in
78 the firmware.
80 +0x020000: ABI fix: added a separate hwmon platform device and
81 + driver, which must be located by name (thinkpad)
82 + and the hwmon class for libsensors4 (lm-sensors 3)
83 + compatibility. Moved all hwmon attributes to this
84 + new platform device.
85 diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
86 index 0a33c6e..d5fb93e 100644
87 --- a/drivers/misc/thinkpad_acpi.c
88 +++ b/drivers/misc/thinkpad_acpi.c
89 @@ -22,7 +22,7 @@
92 #define IBM_VERSION "0.16"
93 -#define TPACPI_SYSFS_VERSION 0x010000
94 +#define TPACPI_SYSFS_VERSION 0x020000
97 * Changelog:
98 @@ -526,6 +526,7 @@ static char *next_cmd(char **cmds)
99 ****************************************************************************/
101 static struct platform_device *tpacpi_pdev;
102 +static struct platform_device *tpacpi_sensors_pdev;
103 static struct class_device *tpacpi_hwmon;
104 static struct input_dev *tpacpi_inputdev;
105 static struct mutex tpacpi_inputdev_send_mutex;
106 @@ -553,6 +554,12 @@ static struct platform_driver tpacpi_pdriver = {
107 .resume = tpacpi_resume_handler,
110 +static struct platform_driver tpacpi_hwmon_pdriver = {
111 + .driver = {
112 + .name = IBM_HWMON_DRVR_NAME,
113 + .owner = THIS_MODULE,
114 + },
117 /*************************************************************************
118 * thinkpad-acpi driver attributes
119 @@ -2872,7 +2879,7 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
121 switch(thermal_read_mode) {
122 case TPACPI_THERMAL_TPEC_16:
123 - res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
124 + res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj,
125 &thermal_temp_input16_group);
126 if (res)
127 return res;
128 @@ -2880,7 +2887,7 @@ static int __init thermal_init(struct ibm_init_struct *iibm)
129 case TPACPI_THERMAL_TPEC_8:
130 case TPACPI_THERMAL_ACPI_TMP07:
131 case TPACPI_THERMAL_ACPI_UPDT:
132 - res = sysfs_create_group(&tpacpi_pdev->dev.kobj,
133 + res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj,
134 &thermal_temp_input8_group);
135 if (res)
136 return res;
137 @@ -2897,13 +2904,13 @@ static void thermal_exit(void)
139 switch(thermal_read_mode) {
140 case TPACPI_THERMAL_TPEC_16:
141 - sysfs_remove_group(&tpacpi_pdev->dev.kobj,
142 + sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj,
143 &thermal_temp_input16_group);
144 break;
145 case TPACPI_THERMAL_TPEC_8:
146 case TPACPI_THERMAL_ACPI_TMP07:
147 case TPACPI_THERMAL_ACPI_UPDT:
148 - sysfs_remove_group(&tpacpi_pdev->dev.kobj,
149 + sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj,
150 &thermal_temp_input16_group);
151 break;
152 case TPACPI_THERMAL_NONE:
153 @@ -3686,7 +3693,7 @@ static struct device_attribute dev_attr_fan_fan1_input =
154 __ATTR(fan1_input, S_IRUGO,
155 fan_fan1_input_show, NULL);
157 -/* sysfs fan fan_watchdog (driver) ------------------------------------- */
158 +/* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */
159 static ssize_t fan_fan_watchdog_show(struct device_driver *drv,
160 char *buf)
162 @@ -3828,10 +3835,10 @@ static int __init fan_init(struct ibm_init_struct *iibm)
164 if (fan_status_access_mode != TPACPI_FAN_NONE ||
165 fan_control_access_mode != TPACPI_FAN_WR_NONE) {
166 - rc = sysfs_create_group(&tpacpi_pdev->dev.kobj,
167 + rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj,
168 &fan_attr_group);
169 if (!(rc < 0))
170 - rc = driver_create_file(&tpacpi_pdriver.driver,
171 + rc = driver_create_file(&tpacpi_hwmon_pdriver.driver,
172 &driver_attr_fan_watchdog);
173 if (rc < 0)
174 return rc;
175 @@ -3914,8 +3921,8 @@ static void fan_exit(void)
176 vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n");
178 /* FIXME: can we really do this unconditionally? */
179 - sysfs_remove_group(&tpacpi_pdev->dev.kobj, &fan_attr_group);
180 - driver_remove_file(&tpacpi_pdriver.driver, &driver_attr_fan_watchdog);
181 + sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, &fan_attr_group);
182 + driver_remove_file(&tpacpi_hwmon_pdriver.driver, &driver_attr_fan_watchdog);
184 cancel_delayed_work(&fan_watchdog_task);
185 flush_scheduled_work();
186 @@ -4366,6 +4373,19 @@ static struct ibm_struct fan_driver_data = {
187 ****************************************************************************
188 ****************************************************************************/
190 +/* sysfs name ---------------------------------------------------------- */
191 +static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev,
192 + struct device_attribute *attr,
193 + char *buf)
195 + return snprintf(buf, PAGE_SIZE, "%s\n", IBM_NAME);
198 +static struct device_attribute dev_attr_thinkpad_acpi_pdev_name =
199 + __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL);
201 +/* --------------------------------------------------------------------- */
203 /* /proc support */
204 static struct proc_dir_entry *proc_dir;
206 @@ -4768,12 +4788,20 @@ static int __init thinkpad_acpi_module_init(void)
208 ret = platform_driver_register(&tpacpi_pdriver);
209 if (ret) {
210 - printk(IBM_ERR "unable to register platform driver\n");
211 + printk(IBM_ERR "unable to register main platform driver\n");
212 thinkpad_acpi_module_exit();
213 return ret;
215 tp_features.platform_drv_registered = 1;
217 + ret = platform_driver_register(&tpacpi_hwmon_pdriver);
218 + if (ret) {
219 + printk(IBM_ERR "unable to register hwmon platform driver\n");
220 + thinkpad_acpi_module_exit();
221 + return ret;
223 + tp_features.sensors_pdrv_registered = 1;
225 ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver);
226 if (ret) {
227 printk(IBM_ERR "unable to create sysfs driver attributes\n");
228 @@ -4793,7 +4821,26 @@ static int __init thinkpad_acpi_module_init(void)
229 thinkpad_acpi_module_exit();
230 return ret;
232 - tpacpi_hwmon = hwmon_device_register(&tpacpi_pdev->dev);
233 + tpacpi_sensors_pdev = platform_device_register_simple(
234 + IBM_HWMON_DRVR_NAME,
235 + -1, NULL, 0);
236 + if (IS_ERR(tpacpi_sensors_pdev)) {
237 + ret = PTR_ERR(tpacpi_sensors_pdev);
238 + tpacpi_sensors_pdev = NULL;
239 + printk(IBM_ERR "unable to register hwmon platform device\n");
240 + thinkpad_acpi_module_exit();
241 + return ret;
243 + ret = device_create_file(&tpacpi_sensors_pdev->dev,
244 + &dev_attr_thinkpad_acpi_pdev_name);
245 + if (ret) {
246 + printk(IBM_ERR
247 + "unable to create sysfs hwmon device attributes\n");
248 + thinkpad_acpi_module_exit();
249 + return ret;
251 + tp_features.sensors_pdev_attrs_registered = 1;
252 + tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev);
253 if (IS_ERR(tpacpi_hwmon)) {
254 ret = PTR_ERR(tpacpi_hwmon);
255 tpacpi_hwmon = NULL;
256 @@ -4864,12 +4911,20 @@ static void thinkpad_acpi_module_exit(void)
257 if (tpacpi_hwmon)
258 hwmon_device_unregister(tpacpi_hwmon);
260 + if (tp_features.sensors_pdev_attrs_registered)
261 + device_remove_file(&tpacpi_sensors_pdev->dev,
262 + &dev_attr_thinkpad_acpi_pdev_name);
263 + if (tpacpi_sensors_pdev)
264 + platform_device_unregister(tpacpi_sensors_pdev);
265 if (tpacpi_pdev)
266 platform_device_unregister(tpacpi_pdev);
268 if (tp_features.platform_drv_attrs_registered)
269 tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver);
271 + if (tp_features.sensors_pdrv_registered)
272 + platform_driver_unregister(&tpacpi_hwmon_pdriver);
274 if (tp_features.platform_drv_registered)
275 platform_driver_unregister(&tpacpi_pdriver);
277 diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h
278 index fa64ded..791b8ca 100644
279 --- a/drivers/misc/thinkpad_acpi.h
280 +++ b/drivers/misc/thinkpad_acpi.h
281 @@ -58,13 +58,14 @@
283 #define IBM_NAME "thinkpad"
284 #define IBM_DESC "ThinkPad ACPI Extras"
285 -#define IBM_FILE "thinkpad_acpi"
286 +#define IBM_FILE IBM_NAME "_acpi"
287 #define IBM_URL "http://ibm-acpi.sf.net/"
288 #define IBM_MAIL "ibm-acpi-devel@lists.sourceforge.net"
290 #define IBM_PROC_DIR "ibm"
291 #define IBM_ACPI_EVENT_PREFIX "ibm"
292 #define IBM_DRVR_NAME IBM_FILE
293 +#define IBM_HWMON_DRVR_NAME IBM_NAME "_hwmon"
295 #define IBM_LOG IBM_FILE ": "
296 #define IBM_ERR KERN_ERR IBM_LOG
297 @@ -171,6 +172,7 @@ static int parse_strtoul(const char *buf, unsigned long max,
299 /* Device model */
300 static struct platform_device *tpacpi_pdev;
301 +static struct platform_device *tpacpi_sensors_pdev;
302 static struct class_device *tpacpi_hwmon;
303 static struct platform_driver tpacpi_pdriver;
304 static struct input_dev *tpacpi_inputdev;
305 @@ -249,6 +251,8 @@ static struct {
306 u32 input_device_registered:1;
307 u32 platform_drv_registered:1;
308 u32 platform_drv_attrs_registered:1;
309 + u32 sensors_pdrv_registered:1;
310 + u32 sensors_pdev_attrs_registered:1;
311 } tp_features;
313 struct thinkpad_id_data {
315 1.5.3.4