Add patches accepted for 2.6.22-rc1 (not released yet)
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / releases / upstream / 2.6.22-rc1 / 0019-ACPI-thinkpad-acpi-clean-up-probing-and-move-init.patch
blobc773c44e3fbc820203e37a30567c4453671588a8
1 From 5fba344cfdbaa79e6320da26c3db34dfb219a845 Mon Sep 17 00:00:00 2001
2 From: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
3 Date: Sat, 21 Apr 2007 11:08:31 -0300
4 Subject: ACPI: thinkpad-acpi: clean up probing and move init to subdrivers
6 Move most of the probing code to its own function, and most of the
7 subdriver-specific init code into subdriver init functions.
9 This allows us to not define pci_handle unless the dock subdriver is
10 enabled, as well.
12 This patch causes a minor userland interface change: if a subdriver doesn't
13 detect a capability, /proc entries for it are not created anymore (as
14 opposed to a /proc entry that just returned "unsupported").
16 Signed-off-by: Henrique de Moraes Holschuh <hmh@hmh.eng.br>
17 Signed-off-by: Len Brown <len.brown@intel.com>
18 ---
19 drivers/misc/thinkpad_acpi.c | 231 +++++++++++++++++++++++++++---------------
20 drivers/misc/thinkpad_acpi.h | 4 +-
21 2 files changed, 151 insertions(+), 84 deletions(-)
23 diff --git a/drivers/misc/thinkpad_acpi.c b/drivers/misc/thinkpad_acpi.c
24 index 7fa906f..eeab394 100644
25 --- a/drivers/misc/thinkpad_acpi.c
26 +++ b/drivers/misc/thinkpad_acpi.c
27 @@ -277,9 +277,9 @@ static int _sta(acpi_handle handle)
28 * ACPI device model
31 -static void __init ibm_handle_init(char *name,
32 - acpi_handle * handle, acpi_handle parent,
33 - char **paths, int num_paths, char **path)
34 +static void ibm_handle_init(char *name,
35 + acpi_handle *handle, acpi_handle parent,
36 + char **paths, int num_paths, char **path)
38 int i;
39 acpi_status status;
40 @@ -351,8 +351,8 @@ static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
42 ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
43 if (!ibm->driver) {
44 - printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
45 - return -1;
46 + printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
47 + return -ENOMEM;
50 sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name);
51 @@ -364,7 +364,9 @@ static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
52 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
53 ibm->hid, ret);
54 kfree(ibm->driver);
55 - }
56 + ibm->driver = NULL;
57 + } else if (!ret)
58 + ibm->driver_registered = 1;
60 return ret;
62 @@ -495,6 +497,8 @@ static int hotkey_orig_mask;
64 static int hotkey_init(void)
66 + IBM_HANDLE_INIT(hkey);
68 /* hotkey not supported on 570 */
69 hotkey_supported = hkey_handle != NULL;
71 @@ -508,13 +512,14 @@ static int hotkey_init(void)
72 return -ENODEV;
75 - return 0;
76 + return (hotkey_supported)? 0 : 1;
79 static void hotkey_exit(void)
81 - if (hotkey_supported)
82 + if (hotkey_supported) {
83 hotkey_set(hotkey_orig_status, hotkey_orig_mask);
84 + }
87 static void hotkey_notify(struct ibm_struct *ibm, u32 event)
88 @@ -628,12 +633,14 @@ static int bluetooth_supported;
90 static int bluetooth_init(void)
92 + IBM_HANDLE_INIT(hkey);
94 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
95 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
96 bluetooth_supported = hkey_handle &&
97 acpi_evalf(hkey_handle, NULL, "GBDC", "qv");
99 - return 0;
100 + return (bluetooth_supported)? 0 : 1;
103 static int bluetooth_status(void)
104 @@ -697,10 +704,12 @@ static int wan_supported;
106 static int wan_init(void)
108 + IBM_HANDLE_INIT(hkey);
110 wan_supported = hkey_handle &&
111 acpi_evalf(hkey_handle, NULL, "GWAN", "qv");
113 - return 0;
114 + return (wan_supported)? 0 : 1;
117 static int wan_status(void)
118 @@ -775,6 +784,9 @@ static int video_init(void)
120 int ivga;
122 + IBM_HANDLE_INIT(vid);
123 + IBM_HANDLE_INIT(vid2);
125 if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
126 /* G41, assume IVGA doesn't change */
127 vid_handle = vid2_handle;
128 @@ -792,7 +804,7 @@ static int video_init(void)
129 /* all others */
130 video_supported = TPACPI_VIDEO_NEW;
132 - return 0;
133 + return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
136 static void video_exit(void)
137 @@ -979,6 +991,10 @@ IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
139 static int light_init(void)
141 + IBM_HANDLE_INIT(ledb);
142 + IBM_HANDLE_INIT(lght);
143 + IBM_HANDLE_INIT(cmos);
145 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
146 light_supported = (cmos_handle || lght_handle) && !ledb_handle;
148 @@ -988,7 +1004,7 @@ static int light_init(void)
149 light_status_supported = acpi_evalf(ec_handle, NULL,
150 "KBLT", "qv");
152 - return 0;
153 + return (light_supported)? 0 : 1;
156 static int light_read(char *p)
157 @@ -1044,9 +1060,6 @@ static int light_write(char *buf)
158 * Dock subdriver
161 -/* don't list other alternatives as we install a notify handler on the 570 */
162 -IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
164 #ifdef CONFIG_THINKPAD_ACPI_DOCK
166 IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
167 @@ -1055,8 +1068,19 @@ IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
168 "\\_SB.PCI.ISA.SLCE", /* 570 */
169 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
171 +/* don't list other alternatives as we install a notify handler on the 570 */
172 +IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
174 #define dock_docked() (_sta(dock_handle) & 1)
176 +static int dock_init(void)
178 + IBM_HANDLE_INIT(dock);
179 + IBM_HANDLE_INIT(pci);
181 + return (dock_handle)? 0 : 1;
184 static void dock_notify(struct ibm_struct *ibm, u32 event)
186 int docked = dock_docked();
187 @@ -1147,6 +1171,13 @@ IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
189 static int bay_init(void)
191 + IBM_HANDLE_INIT(bay);
192 + if (bay_handle)
193 + IBM_HANDLE_INIT(bay_ej);
194 + IBM_HANDLE_INIT(bay2);
195 + if (bay2_handle)
196 + IBM_HANDLE_INIT(bay2_ej);
198 bay_status_supported = bay_handle &&
199 acpi_evalf(bay_handle, NULL, "_STA", "qv");
200 bay_status2_supported = bay2_handle &&
201 @@ -1157,7 +1188,8 @@ static int bay_init(void)
202 bay_eject2_supported = bay2_handle && bay2_ej_handle &&
203 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
205 - return 0;
206 + return (bay_status_supported || bay_eject_supported ||
207 + bay_status2_supported || bay_eject2_supported)? 0 : 1;
210 static void bay_notify(struct ibm_struct *ibm, u32 event)
211 @@ -1221,6 +1253,13 @@ static int bay_write(char *buf)
212 * CMOS subdriver
215 +static int cmos_init(void)
217 + IBM_HANDLE_INIT(cmos);
219 + return (cmos_handle)? 0 : 1;
222 static int cmos_eval(int cmos_cmd)
224 if (cmos_handle)
225 @@ -1281,6 +1320,8 @@ IBM_HANDLE(led, ec, "SLED", /* 570 */
227 static int led_init(void)
229 + IBM_HANDLE_INIT(led);
231 if (!led_handle)
232 /* led not supported on R30, R31 */
233 led_supported = TPACPI_LED_NONE;
234 @@ -1294,7 +1335,7 @@ static int led_init(void)
235 /* all others */
236 led_supported = TPACPI_LED_NEW;
238 - return 0;
239 + return (led_supported != TPACPI_LED_NONE)? 0 : 1;
242 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
243 @@ -1391,6 +1432,13 @@ static int led_write(char *buf)
245 IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
247 +static int beep_init(void)
249 + IBM_HANDLE_INIT(beep);
251 + return (beep_handle)? 0 : 1;
254 static int beep_read(char *p)
256 int len = 0;
257 @@ -1436,7 +1484,9 @@ static int thermal_init(void)
259 u8 t, ta1, ta2;
260 int i;
261 - int acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
262 + int acpi_tmp7;
264 + acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
266 if (ibm_thinkpad_ec_found && experimental) {
268 @@ -1492,7 +1542,7 @@ static int thermal_init(void)
269 thermal_read_mode = TPACPI_THERMAL_NONE;
272 - return 0;
273 + return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
276 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
277 @@ -1973,6 +2023,10 @@ static int fan_init(void)
278 fan_control_status_known = 1;
279 fan_watchdog_maxinterval = 0;
281 + IBM_HANDLE_INIT(fans);
282 + IBM_HANDLE_INIT(gfan);
283 + IBM_HANDLE_INIT(sfan);
285 if (gfan_handle) {
286 /* 570, 600e/x, 770e, 770x */
287 fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
288 @@ -2010,7 +2064,7 @@ static int fan_init(void)
289 printk(IBM_ERR
290 "ThinkPad ACPI EC access misbehaving, "
291 "fan status and control unavailable\n");
292 - return 0;
293 + return 1;
297 @@ -2041,7 +2095,9 @@ static int fan_init(void)
301 - return 0;
302 + return (fan_status_access_mode != TPACPI_FAN_NONE ||
303 + fan_control_access_mode != TPACPI_FAN_WR_NONE)?
304 + 0 : 1;
307 static int fan_get_status(u8 *status)
308 @@ -2485,6 +2541,7 @@ static struct ibm_struct ibms[] = {
309 #ifdef CONFIG_THINKPAD_ACPI_DOCK
311 .name = "dock",
312 + .init = dock_init,
313 .read = dock_read,
314 .write = dock_write,
315 .notify = dock_notify,
316 @@ -2512,6 +2569,7 @@ static struct ibm_struct ibms[] = {
317 #endif /* CONFIG_THINKPAD_ACPI_BAY */
319 .name = "cmos",
320 + .init = cmos_init,
321 .read = cmos_read,
322 .write = cmos_write,
324 @@ -2523,6 +2581,7 @@ static struct ibm_struct ibms[] = {
327 .name = "beep",
328 + .init = beep_init,
329 .read = beep_read,
330 .write = beep_write,
332 @@ -2571,20 +2630,33 @@ static int __init ibm_init(struct ibm_struct *ibm)
333 if (ibm->experimental && !experimental)
334 return 0;
336 - if (ibm->hid) {
337 - ret = register_tpacpi_subdriver(ibm);
338 - if (ret < 0)
339 - return ret;
340 - ibm->driver_registered = 1;
343 if (ibm->init) {
344 ret = ibm->init();
345 - if (ret != 0)
346 + if (ret > 0)
347 + return 0; /* probe failed */
348 + if (ret)
349 return ret;
350 ibm->init_called = 1;
353 + if (ibm->hid) {
354 + ret = register_tpacpi_subdriver(ibm);
355 + if (ret)
356 + goto err_out;
359 + if (ibm->notify) {
360 + ret = setup_notify(ibm);
361 + if (ret == -ENODEV) {
362 + printk(IBM_NOTICE "disabling subdriver %s\n",
363 + ibm->name);
364 + ret = 0;
365 + goto err_out;
367 + if (ret < 0)
368 + goto err_out;
371 if (ibm->read) {
372 entry = create_proc_entry(ibm->name,
373 S_IFREG | S_IRUGO | S_IWUSR,
374 @@ -2592,7 +2664,8 @@ static int __init ibm_init(struct ibm_struct *ibm)
375 if (!entry) {
376 printk(IBM_ERR "unable to create proc entry %s\n",
377 ibm->name);
378 - return -ENODEV;
379 + ret = -ENODEV;
380 + goto err_out;
382 entry->owner = THIS_MODULE;
383 entry->data = ibm;
384 @@ -2602,36 +2675,36 @@ static int __init ibm_init(struct ibm_struct *ibm)
385 ibm->proc_created = 1;
388 - if (ibm->notify) {
389 - ret = setup_notify(ibm);
390 - if (ret == -ENODEV) {
391 - printk(IBM_NOTICE "disabling subdriver %s\n",
392 - ibm->name);
393 - ibm_exit(ibm);
394 - return 0;
396 - if (ret < 0)
397 - return ret;
400 return 0;
402 +err_out:
403 + ibm_exit(ibm);
404 + return (ret < 0)? ret : 0;
407 static void ibm_exit(struct ibm_struct *ibm)
409 - if (ibm->notify_installed)
410 + if (ibm->notify_installed) {
411 acpi_remove_notify_handler(*ibm->handle, ibm->type,
412 dispatch_notify);
413 + ibm->notify_installed = 0;
416 - if (ibm->proc_created)
417 + if (ibm->proc_created) {
418 remove_proc_entry(ibm->name, proc_dir);
420 - if (ibm->init_called && ibm->exit)
421 - ibm->exit();
422 + ibm->proc_created = 0;
425 if (ibm->driver_registered) {
426 acpi_bus_unregister_driver(ibm->driver);
427 kfree(ibm->driver);
428 + ibm->driver = NULL;
429 + ibm->driver_registered = 0;
432 + if (ibm->init_called && ibm->exit) {
433 + ibm->exit();
434 + ibm->init_called = 0;
438 @@ -2663,6 +2736,32 @@ static char* __init check_dmi_for_ec(void)
439 return NULL;
442 +static int __init probe_for_thinkpad(void)
444 + int is_thinkpad;
446 + if (acpi_disabled)
447 + return -ENODEV;
449 + /*
450 + * Non-ancient models have better DMI tagging, but very old models
451 + * don't.
452 + */
453 + is_thinkpad = dmi_name_in_vendors("ThinkPad");
455 + /* ec is required because many other handles are relative to it */
456 + IBM_HANDLE_INIT(ec);
457 + if (!ec_handle) {
458 + if (is_thinkpad)
459 + printk(IBM_ERR
460 + "Not yet supported ThinkPad detected!\n");
461 + return -ENODEV;
464 + return 0;
468 /* Module init, exit, parameters */
470 static int __init set_ibm_param(const char *val, struct kernel_param *kp)
471 @@ -2712,45 +2811,13 @@ static int __init thinkpad_acpi_module_init(void)
473 int ret, i;
475 - if (acpi_disabled)
476 - return -ENODEV;
477 + ret = probe_for_thinkpad();
478 + if (ret)
479 + return ret;
481 - /* ec is required because many other handles are relative to it */
482 - IBM_HANDLE_INIT(ec);
483 - if (!ec_handle) {
484 - printk(IBM_ERR "ec object not found\n");
485 - return -ENODEV;
488 - /* Models with newer firmware report the EC in DMI */
489 ibm_thinkpad_ec_found = check_dmi_for_ec();
491 - /* these handles are not required */
492 - IBM_HANDLE_INIT(vid);
493 - IBM_HANDLE_INIT(vid2);
494 - IBM_HANDLE_INIT(ledb);
495 - IBM_HANDLE_INIT(led);
496 - IBM_HANDLE_INIT(hkey);
497 - IBM_HANDLE_INIT(lght);
498 - IBM_HANDLE_INIT(cmos);
499 -#ifdef CONFIG_THINKPAD_ACPI_DOCK
500 - IBM_HANDLE_INIT(dock);
501 -#endif
502 - IBM_HANDLE_INIT(pci);
503 -#ifdef CONFIG_THINKPAD_ACPI_BAY
504 - IBM_HANDLE_INIT(bay);
505 - if (bay_handle)
506 - IBM_HANDLE_INIT(bay_ej);
507 - IBM_HANDLE_INIT(bay2);
508 - if (bay2_handle)
509 - IBM_HANDLE_INIT(bay2_ej);
510 -#endif /* CONFIG_THINKPAD_ACPI_BAY */
511 - IBM_HANDLE_INIT(beep);
512 IBM_HANDLE_INIT(ecrd);
513 IBM_HANDLE_INIT(ecwr);
514 - IBM_HANDLE_INIT(fans);
515 - IBM_HANDLE_INIT(gfan);
516 - IBM_HANDLE_INIT(sfan);
518 proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir);
519 if (!proc_dir) {
520 diff --git a/drivers/misc/thinkpad_acpi.h b/drivers/misc/thinkpad_acpi.h
521 index b2348d7..06d4c38 100644
522 --- a/drivers/misc/thinkpad_acpi.h
523 +++ b/drivers/misc/thinkpad_acpi.h
524 @@ -104,7 +104,7 @@ static acpi_handle ecrd_handle, ecwr_handle; /* 570 EC access */
525 static acpi_handle cmos_handle, hkey_handle; /* basic thinkpad handles */
527 static void ibm_handle_init(char *name,
528 - acpi_handle * handle, acpi_handle parent,
529 + acpi_handle *handle, acpi_handle parent,
530 char **paths, int num_paths, char **path);
531 #define IBM_HANDLE_INIT(object) \
532 ibm_handle_init(#object, &object##_handle, *object##_parent, \
533 @@ -242,8 +242,8 @@ static int cmos_write(char *buf);
534 * Dock subdriver
537 -static acpi_handle pci_handle;
538 #ifdef CONFIG_THINKPAD_ACPI_DOCK
539 +static acpi_handle pci_handle;
540 static acpi_handle dock_handle;
542 static void dock_notify(struct ibm_struct *ibm, u32 event);
544 1.5.1