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
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>
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)
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)
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);
44 - printk(IBM_ERR "kmalloc(ibm->driver) failed\n");
46 + printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
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",
58 + ibm->driver_registered = 1;
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)
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);
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");
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");
114 + return (wan_supported)? 0 : 1;
117 static int wan_status(void)
118 @@ -775,6 +784,9 @@ static int video_init(void)
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)
130 video_supported = TPACPI_VIDEO_NEW;
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,
153 + return (light_supported)? 0 : 1;
156 static int light_read(char *p)
157 @@ -1044,9 +1060,6 @@ static int light_write(char *buf)
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);
193 + IBM_HANDLE_INIT(bay_ej);
194 + IBM_HANDLE_INIT(bay2);
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);
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)
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)
225 @@ -1281,6 +1320,8 @@ IBM_HANDLE(led, ec, "SLED", /* 570 */
227 static int led_init(void)
229 + IBM_HANDLE_INIT(led);
232 /* led not supported on R30, R31 */
233 led_supported = TPACPI_LED_NONE;
234 @@ -1294,7 +1335,7 @@ static int led_init(void)
236 led_supported = TPACPI_LED_NEW;
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)
257 @@ -1436,7 +1484,9 @@ static int thermal_init(void)
261 - int acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
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;
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);
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)
290 "ThinkPad ACPI EC access misbehaving, "
291 "fan status and control unavailable\n");
297 @@ -2041,7 +2095,9 @@ static int fan_init(void)
302 + return (fan_status_access_mode != TPACPI_FAN_NONE ||
303 + fan_control_access_mode != TPACPI_FAN_WR_NONE)?
307 static int fan_get_status(u8 *status)
308 @@ -2485,6 +2541,7 @@ static struct ibm_struct ibms[] = {
309 #ifdef CONFIG_THINKPAD_ACPI_DOCK
315 .notify = dock_notify,
316 @@ -2512,6 +2569,7 @@ static struct ibm_struct ibms[] = {
317 #endif /* CONFIG_THINKPAD_ACPI_BAY */
324 @@ -2523,6 +2581,7 @@ static struct ibm_struct ibms[] = {
332 @@ -2571,20 +2630,33 @@ static int __init ibm_init(struct ibm_struct *ibm)
333 if (ibm->experimental && !experimental)
337 - ret = register_tpacpi_subdriver(ibm);
340 - ibm->driver_registered = 1;
347 + return 0; /* probe failed */
350 ibm->init_called = 1;
354 + ret = register_tpacpi_subdriver(ibm);
360 + ret = setup_notify(ibm);
361 + if (ret == -ENODEV) {
362 + printk(IBM_NOTICE "disabling subdriver %s\n",
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)
376 printk(IBM_ERR "unable to create proc entry %s\n",
382 entry->owner = THIS_MODULE;
384 @@ -2602,36 +2675,36 @@ static int __init ibm_init(struct ibm_struct *ibm)
385 ibm->proc_created = 1;
389 - ret = setup_notify(ibm);
390 - if (ret == -ENODEV) {
391 - printk(IBM_NOTICE "disabling subdriver %s\n",
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,
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)
422 + ibm->proc_created = 0;
425 if (ibm->driver_registered) {
426 acpi_bus_unregister_driver(ibm->driver);
428 + ibm->driver = NULL;
429 + ibm->driver_registered = 0;
432 + if (ibm->init_called && ibm->exit) {
434 + ibm->init_called = 0;
438 @@ -2663,6 +2736,32 @@ static char* __init check_dmi_for_ec(void)
442 +static int __init probe_for_thinkpad(void)
450 + * Non-ancient models have better DMI tagging, but very old models
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);
460 + "Not yet supported ThinkPad detected!\n");
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)
477 + ret = probe_for_thinkpad();
481 - /* ec is required because many other handles are relative to it */
482 - IBM_HANDLE_INIT(ec);
484 - printk(IBM_ERR "ec object not found\n");
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);
502 - IBM_HANDLE_INIT(pci);
503 -#ifdef CONFIG_THINKPAD_ACPI_BAY
504 - IBM_HANDLE_INIT(bay);
506 - IBM_HANDLE_INIT(bay_ej);
507 - IBM_HANDLE_INIT(bay2);
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);
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);
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);