Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
643f12db | 2 | * thinkpad_acpi.c - ThinkPad ACPI Extras |
1da177e4 LT |
3 | * |
4 | * | |
78f81cc4 | 5 | * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> |
a62bc916 | 6 | * Copyright (C) 2006-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br> |
1da177e4 LT |
7 | * |
8 | * This program is free software; you can redistribute it and/or modify | |
9 | * it under the terms of the GNU General Public License as published by | |
10 | * the Free Software Foundation; either version 2 of the License, or | |
11 | * (at your option) any later version. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
a62bc916 HMH |
20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
21 | * 02110-1301, USA. | |
78f81cc4 BD |
22 | */ |
23 | ||
3b0c6485 | 24 | #define IBM_VERSION "0.16" |
7fd40029 | 25 | #define TPACPI_SYSFS_VERSION 0x020000 |
78f81cc4 BD |
26 | |
27 | /* | |
1da177e4 | 28 | * Changelog: |
643f12db HMH |
29 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to |
30 | * drivers/misc. | |
f9ff43a6 HMH |
31 | * |
32 | * 2006-11-22 0.13 new maintainer | |
33 | * changelog now lives in git commit history, and will | |
34 | * not be updated further in-file. | |
837ca6dd | 35 | * |
78f81cc4 BD |
36 | * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels |
37 | * 2005-03-17 0.11 support for 600e, 770x | |
38 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> | |
39 | * support for 770e, G41 | |
40 | * G40 and G41 don't have a thinklight | |
41 | * temperatures no longer experimental | |
42 | * experimental brightness control | |
43 | * experimental volume control | |
44 | * experimental fan enable/disable | |
837ca6dd | 45 | * 2005-01-16 0.10 fix module loading on R30, R31 |
78f81cc4 BD |
46 | * 2005-01-16 0.9 support for 570, R30, R31 |
47 | * ultrabay support on A22p, A3x | |
48 | * limit arg for cmos, led, beep, drop experimental status | |
49 | * more capable led control on A21e, A22p, T20-22, X20 | |
50 | * experimental temperatures and fan speed | |
51 | * experimental embedded controller register dump | |
52 | * mark more functions as __init, drop incorrect __exit | |
53 | * use MODULE_VERSION | |
54 | * thanks to Henrik Brix Andersen <brix@gentoo.org> | |
55 | * fix parameter passing on module loading | |
56 | * thanks to Rusty Russell <rusty@rustcorp.com.au> | |
57 | * thanks to Jim Radford <radford@blackbean.org> | |
58 | * 2004-11-08 0.8 fix init error case, don't return from a macro | |
59 | * thanks to Chris Wright <chrisw@osdl.org> | |
60 | * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20 | |
61 | * fix led control on A21e | |
62 | * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device | |
1da177e4 LT |
63 | * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20 |
64 | * proc file format changed | |
65 | * video_switch command | |
66 | * experimental cmos control | |
67 | * experimental led control | |
68 | * experimental acpi sounds | |
78f81cc4 BD |
69 | * 2004-09-16 0.4 support for module parameters |
70 | * hotkey mask can be prefixed by 0x | |
71 | * video output switching | |
72 | * video expansion control | |
73 | * ultrabay eject support | |
74 | * removed lcd brightness/on/off control, didn't work | |
75 | * 2004-08-17 0.3 support for R40 | |
76 | * lcd off, brightness control | |
77 | * thinklight on/off | |
78 | * 2004-08-14 0.2 support for T series, X20 | |
79 | * bluetooth enable/disable | |
80 | * hotkey events disabled by default | |
81 | * removed fan control, currently useless | |
82 | * 2004-08-09 0.1 initial release, support for X series | |
1da177e4 LT |
83 | */ |
84 | ||
f21f85de | 85 | #include "thinkpad_acpi.h" |
1da177e4 | 86 | |
f9ff43a6 | 87 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); |
78f81cc4 BD |
88 | MODULE_DESCRIPTION(IBM_DESC); |
89 | MODULE_VERSION(IBM_VERSION); | |
90 | MODULE_LICENSE("GPL"); | |
91 | ||
d903ac54 HMH |
92 | /* Please remove this in year 2009 */ |
93 | MODULE_ALIAS("ibm_acpi"); | |
94 | ||
b964b437 HMH |
95 | /* |
96 | * DMI matching for module autoloading | |
97 | * | |
98 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs | |
99 | * See http://thinkwiki.org/wiki/BIOS_Upgrade_Downloads | |
100 | * | |
101 | * Only models listed in thinkwiki will be supported, so add yours | |
102 | * if it is not there yet. | |
103 | */ | |
104 | #define IBM_BIOS_MODULE_ALIAS(__type) \ | |
105 | MODULE_ALIAS("dmi:bvnIBM:bvr" __type "ET??WW") | |
106 | ||
107 | /* Non-ancient thinkpads */ | |
108 | MODULE_ALIAS("dmi:bvnIBM:*:svnIBM:*:pvrThinkPad*:rvnIBM:*"); | |
109 | MODULE_ALIAS("dmi:bvnLENOVO:*:svnLENOVO:*:pvrThinkPad*:rvnLENOVO:*"); | |
110 | ||
111 | /* Ancient thinkpad BIOSes have to be identified by | |
112 | * BIOS type or model number, and there are far less | |
113 | * BIOS types than model numbers... */ | |
114 | IBM_BIOS_MODULE_ALIAS("I[B,D,H,I,M,N,O,T,W,V,Y,Z]"); | |
115 | IBM_BIOS_MODULE_ALIAS("1[0,3,6,8,A-G,I,K,M-P,S,T]"); | |
116 | IBM_BIOS_MODULE_ALIAS("K[U,X-Z]"); | |
117 | ||
1da177e4 LT |
118 | #define __unused __attribute__ ((unused)) |
119 | ||
8fef502e HMH |
120 | static enum { |
121 | TPACPI_LIFE_INIT = 0, | |
122 | TPACPI_LIFE_RUNNING, | |
123 | TPACPI_LIFE_EXITING, | |
124 | } tpacpi_lifecycle; | |
125 | ||
56b6aeb0 HMH |
126 | /**************************************************************************** |
127 | **************************************************************************** | |
128 | * | |
129 | * ACPI Helpers and device model | |
130 | * | |
131 | **************************************************************************** | |
132 | ****************************************************************************/ | |
133 | ||
134 | /************************************************************************* | |
135 | * ACPI basic handles | |
136 | */ | |
1da177e4 | 137 | |
94954cc6 | 138 | static acpi_handle root_handle; |
1da177e4 LT |
139 | |
140 | #define IBM_HANDLE(object, parent, paths...) \ | |
141 | static acpi_handle object##_handle; \ | |
142 | static acpi_handle *object##_parent = &parent##_handle; \ | |
78f81cc4 | 143 | static char *object##_path; \ |
1da177e4 LT |
144 | static char *object##_paths[] = { paths } |
145 | ||
78f81cc4 BD |
146 | IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
147 | "\\_SB.PCI.ISA.EC", /* 570 */ | |
148 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ | |
149 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ | |
150 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ | |
151 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ | |
152 | "\\_SB.PCI0.LPC.EC", /* all others */ | |
56b6aeb0 | 153 | ); |
78f81cc4 | 154 | |
56b6aeb0 HMH |
155 | IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
156 | IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */ | |
78f81cc4 | 157 | |
56b6aeb0 HMH |
158 | |
159 | /************************************************************************* | |
160 | * Misc ACPI handles | |
161 | */ | |
78f81cc4 BD |
162 | |
163 | IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */ | |
164 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ | |
165 | "\\CMS", /* R40, R40e */ | |
56b6aeb0 | 166 | ); /* all others */ |
78f81cc4 BD |
167 | |
168 | IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ | |
169 | "^HKEY", /* R30, R31 */ | |
170 | "HKEY", /* all others */ | |
56b6aeb0 | 171 | ); /* 570 */ |
78f81cc4 | 172 | |
78f81cc4 | 173 | |
56b6aeb0 HMH |
174 | /************************************************************************* |
175 | * ACPI helpers | |
a8b7a662 HMH |
176 | */ |
177 | ||
1da177e4 LT |
178 | static int acpi_evalf(acpi_handle handle, |
179 | void *res, char *method, char *fmt, ...) | |
180 | { | |
181 | char *fmt0 = fmt; | |
78f81cc4 BD |
182 | struct acpi_object_list params; |
183 | union acpi_object in_objs[IBM_MAX_ACPI_ARGS]; | |
184 | struct acpi_buffer result, *resultp; | |
185 | union acpi_object out_obj; | |
186 | acpi_status status; | |
187 | va_list ap; | |
188 | char res_type; | |
189 | int success; | |
190 | int quiet; | |
1da177e4 LT |
191 | |
192 | if (!*fmt) { | |
193 | printk(IBM_ERR "acpi_evalf() called with empty format\n"); | |
194 | return 0; | |
195 | } | |
196 | ||
197 | if (*fmt == 'q') { | |
198 | quiet = 1; | |
199 | fmt++; | |
200 | } else | |
201 | quiet = 0; | |
202 | ||
203 | res_type = *(fmt++); | |
204 | ||
205 | params.count = 0; | |
206 | params.pointer = &in_objs[0]; | |
207 | ||
208 | va_start(ap, fmt); | |
209 | while (*fmt) { | |
210 | char c = *(fmt++); | |
211 | switch (c) { | |
212 | case 'd': /* int */ | |
213 | in_objs[params.count].integer.value = va_arg(ap, int); | |
214 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; | |
215 | break; | |
78f81cc4 | 216 | /* add more types as needed */ |
1da177e4 LT |
217 | default: |
218 | printk(IBM_ERR "acpi_evalf() called " | |
219 | "with invalid format character '%c'\n", c); | |
220 | return 0; | |
221 | } | |
222 | } | |
223 | va_end(ap); | |
224 | ||
78f81cc4 BD |
225 | if (res_type != 'v') { |
226 | result.length = sizeof(out_obj); | |
227 | result.pointer = &out_obj; | |
228 | resultp = &result; | |
229 | } else | |
230 | resultp = NULL; | |
1da177e4 | 231 | |
78f81cc4 | 232 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
1da177e4 LT |
233 | |
234 | switch (res_type) { | |
78f81cc4 | 235 | case 'd': /* int */ |
1da177e4 LT |
236 | if (res) |
237 | *(int *)res = out_obj.integer.value; | |
238 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; | |
239 | break; | |
78f81cc4 | 240 | case 'v': /* void */ |
1da177e4 LT |
241 | success = status == AE_OK; |
242 | break; | |
78f81cc4 | 243 | /* add more types as needed */ |
1da177e4 LT |
244 | default: |
245 | printk(IBM_ERR "acpi_evalf() called " | |
246 | "with invalid format character '%c'\n", res_type); | |
247 | return 0; | |
248 | } | |
249 | ||
56b6aeb0 HMH |
250 | if (!success && !quiet) |
251 | printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", | |
252 | method, fmt0, status); | |
253 | ||
254 | return success; | |
255 | } | |
256 | ||
257 | static void __unused acpi_print_int(acpi_handle handle, char *method) | |
258 | { | |
259 | int i; | |
260 | ||
261 | if (acpi_evalf(handle, &i, method, "d")) | |
262 | printk(IBM_INFO "%s = 0x%x\n", method, i); | |
263 | else | |
264 | printk(IBM_ERR "error calling %s\n", method); | |
265 | } | |
266 | ||
267 | static int acpi_ec_read(int i, u8 * p) | |
268 | { | |
269 | int v; | |
270 | ||
271 | if (ecrd_handle) { | |
272 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) | |
273 | return 0; | |
274 | *p = v; | |
275 | } else { | |
276 | if (ec_read(i, p) < 0) | |
277 | return 0; | |
278 | } | |
279 | ||
280 | return 1; | |
281 | } | |
282 | ||
283 | static int acpi_ec_write(int i, u8 v) | |
284 | { | |
285 | if (ecwr_handle) { | |
286 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) | |
287 | return 0; | |
288 | } else { | |
289 | if (ec_write(i, v) < 0) | |
290 | return 0; | |
291 | } | |
292 | ||
293 | return 1; | |
294 | } | |
295 | ||
296 | static int _sta(acpi_handle handle) | |
297 | { | |
298 | int status; | |
299 | ||
300 | if (!handle || !acpi_evalf(handle, &status, "_STA", "d")) | |
301 | status = 0; | |
302 | ||
303 | return status; | |
304 | } | |
305 | ||
c9bea99c HMH |
306 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
307 | { | |
308 | if (!cmos_handle) | |
309 | return -ENXIO; | |
310 | ||
311 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) | |
312 | return -EIO; | |
313 | ||
314 | return 0; | |
315 | } | |
316 | ||
56b6aeb0 HMH |
317 | /************************************************************************* |
318 | * ACPI device model | |
319 | */ | |
320 | ||
8d376cd6 | 321 | static void drv_acpi_handle_init(char *name, |
5fba344c HMH |
322 | acpi_handle *handle, acpi_handle parent, |
323 | char **paths, int num_paths, char **path) | |
56b6aeb0 HMH |
324 | { |
325 | int i; | |
326 | acpi_status status; | |
327 | ||
5ae930e6 HMH |
328 | vdbg_printk(TPACPI_DBG_INIT, "trying to locate ACPI handle for %s\n", |
329 | name); | |
330 | ||
56b6aeb0 HMH |
331 | for (i = 0; i < num_paths; i++) { |
332 | status = acpi_get_handle(parent, paths[i], handle); | |
333 | if (ACPI_SUCCESS(status)) { | |
334 | *path = paths[i]; | |
5ae930e6 HMH |
335 | dbg_printk(TPACPI_DBG_INIT, |
336 | "Found ACPI handle %s for %s\n", | |
337 | *path, name); | |
56b6aeb0 HMH |
338 | return; |
339 | } | |
340 | } | |
341 | ||
5ae930e6 HMH |
342 | vdbg_printk(TPACPI_DBG_INIT, "ACPI handle for %s not found\n", |
343 | name); | |
56b6aeb0 HMH |
344 | *handle = NULL; |
345 | } | |
346 | ||
8d376cd6 | 347 | static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data) |
56b6aeb0 HMH |
348 | { |
349 | struct ibm_struct *ibm = data; | |
350 | ||
8fef502e HMH |
351 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
352 | return; | |
353 | ||
8d376cd6 | 354 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
56b6aeb0 HMH |
355 | return; |
356 | ||
8d376cd6 | 357 | ibm->acpi->notify(ibm, event); |
56b6aeb0 HMH |
358 | } |
359 | ||
8d376cd6 | 360 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
56b6aeb0 HMH |
361 | { |
362 | acpi_status status; | |
5ae930e6 | 363 | int rc; |
56b6aeb0 | 364 | |
8d376cd6 HMH |
365 | BUG_ON(!ibm->acpi); |
366 | ||
367 | if (!*ibm->acpi->handle) | |
56b6aeb0 HMH |
368 | return 0; |
369 | ||
5ae930e6 | 370 | vdbg_printk(TPACPI_DBG_INIT, |
fe08bc4b HMH |
371 | "setting up ACPI notify for %s\n", ibm->name); |
372 | ||
5ae930e6 HMH |
373 | rc = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device); |
374 | if (rc < 0) { | |
375 | printk(IBM_ERR "acpi_bus_get_device(%s) failed: %d\n", | |
376 | ibm->name, rc); | |
56b6aeb0 HMH |
377 | return -ENODEV; |
378 | } | |
379 | ||
8d376cd6 HMH |
380 | acpi_driver_data(ibm->acpi->device) = ibm; |
381 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", | |
643f12db HMH |
382 | IBM_ACPI_EVENT_PREFIX, |
383 | ibm->name); | |
56b6aeb0 | 384 | |
8d376cd6 HMH |
385 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
386 | ibm->acpi->type, dispatch_acpi_notify, ibm); | |
56b6aeb0 HMH |
387 | if (ACPI_FAILURE(status)) { |
388 | if (status == AE_ALREADY_EXISTS) { | |
389 | printk(IBM_NOTICE "another device driver is already handling %s events\n", | |
390 | ibm->name); | |
391 | } else { | |
392 | printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n", | |
393 | ibm->name, status); | |
394 | } | |
395 | return -ENODEV; | |
396 | } | |
8d376cd6 | 397 | ibm->flags.acpi_notify_installed = 1; |
56b6aeb0 HMH |
398 | return 0; |
399 | } | |
400 | ||
8d376cd6 | 401 | static int __init tpacpi_device_add(struct acpi_device *device) |
56b6aeb0 HMH |
402 | { |
403 | return 0; | |
404 | } | |
405 | ||
6700121b | 406 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
56b6aeb0 | 407 | { |
5ae930e6 | 408 | int rc; |
56b6aeb0 | 409 | |
fe08bc4b HMH |
410 | dbg_printk(TPACPI_DBG_INIT, |
411 | "registering %s as an ACPI driver\n", ibm->name); | |
412 | ||
8d376cd6 HMH |
413 | BUG_ON(!ibm->acpi); |
414 | ||
415 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); | |
416 | if (!ibm->acpi->driver) { | |
5fba344c HMH |
417 | printk(IBM_ERR "kzalloc(ibm->driver) failed\n"); |
418 | return -ENOMEM; | |
56b6aeb0 HMH |
419 | } |
420 | ||
8d376cd6 HMH |
421 | sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name); |
422 | ibm->acpi->driver->ids = ibm->acpi->hid; | |
1ba90e3a | 423 | |
8d376cd6 | 424 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
56b6aeb0 | 425 | |
5ae930e6 HMH |
426 | rc = acpi_bus_register_driver(ibm->acpi->driver); |
427 | if (rc < 0) { | |
56b6aeb0 | 428 | printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
1ba90e3a | 429 | ibm->name, rc); |
8d376cd6 HMH |
430 | kfree(ibm->acpi->driver); |
431 | ibm->acpi->driver = NULL; | |
5ae930e6 | 432 | } else if (!rc) |
8d376cd6 | 433 | ibm->flags.acpi_driver_registered = 1; |
56b6aeb0 | 434 | |
5ae930e6 | 435 | return rc; |
56b6aeb0 HMH |
436 | } |
437 | ||
438 | ||
439 | /**************************************************************************** | |
440 | **************************************************************************** | |
441 | * | |
442 | * Procfs Helpers | |
443 | * | |
444 | **************************************************************************** | |
445 | ****************************************************************************/ | |
446 | ||
8d376cd6 HMH |
447 | static int dispatch_procfs_read(char *page, char **start, off_t off, |
448 | int count, int *eof, void *data) | |
56b6aeb0 HMH |
449 | { |
450 | struct ibm_struct *ibm = data; | |
451 | int len; | |
452 | ||
453 | if (!ibm || !ibm->read) | |
454 | return -EINVAL; | |
455 | ||
456 | len = ibm->read(page); | |
457 | if (len < 0) | |
458 | return len; | |
459 | ||
460 | if (len <= off + count) | |
461 | *eof = 1; | |
462 | *start = page + off; | |
463 | len -= off; | |
464 | if (len > count) | |
465 | len = count; | |
466 | if (len < 0) | |
467 | len = 0; | |
468 | ||
469 | return len; | |
470 | } | |
471 | ||
8d376cd6 HMH |
472 | static int dispatch_procfs_write(struct file *file, |
473 | const char __user * userbuf, | |
474 | unsigned long count, void *data) | |
56b6aeb0 HMH |
475 | { |
476 | struct ibm_struct *ibm = data; | |
477 | char *kernbuf; | |
478 | int ret; | |
479 | ||
480 | if (!ibm || !ibm->write) | |
481 | return -EINVAL; | |
482 | ||
483 | kernbuf = kmalloc(count + 2, GFP_KERNEL); | |
484 | if (!kernbuf) | |
485 | return -ENOMEM; | |
1da177e4 | 486 | |
56b6aeb0 HMH |
487 | if (copy_from_user(kernbuf, userbuf, count)) { |
488 | kfree(kernbuf); | |
489 | return -EFAULT; | |
490 | } | |
1da177e4 | 491 | |
56b6aeb0 HMH |
492 | kernbuf[count] = 0; |
493 | strcat(kernbuf, ","); | |
494 | ret = ibm->write(kernbuf); | |
495 | if (ret == 0) | |
496 | ret = count; | |
1da177e4 | 497 | |
56b6aeb0 HMH |
498 | kfree(kernbuf); |
499 | ||
500 | return ret; | |
1da177e4 LT |
501 | } |
502 | ||
503 | static char *next_cmd(char **cmds) | |
504 | { | |
505 | char *start = *cmds; | |
506 | char *end; | |
507 | ||
508 | while ((end = strchr(start, ',')) && end == start) | |
509 | start = end + 1; | |
510 | ||
511 | if (!end) | |
512 | return NULL; | |
513 | ||
514 | *end = 0; | |
515 | *cmds = end + 1; | |
516 | return start; | |
517 | } | |
518 | ||
56b6aeb0 | 519 | |
54ae1501 HMH |
520 | /**************************************************************************** |
521 | **************************************************************************** | |
522 | * | |
7f5d1cd6 | 523 | * Device model: input, hwmon and platform |
54ae1501 HMH |
524 | * |
525 | **************************************************************************** | |
526 | ****************************************************************************/ | |
527 | ||
94954cc6 | 528 | static struct platform_device *tpacpi_pdev; |
7fd40029 | 529 | static struct platform_device *tpacpi_sensors_pdev; |
94954cc6 | 530 | static struct class_device *tpacpi_hwmon; |
7f5d1cd6 | 531 | static struct input_dev *tpacpi_inputdev; |
8523ed6f | 532 | static struct mutex tpacpi_inputdev_send_mutex; |
54ae1501 | 533 | |
e295e850 HMH |
534 | |
535 | static int tpacpi_resume_handler(struct platform_device *pdev) | |
536 | { | |
537 | struct ibm_struct *ibm, *itmp; | |
538 | ||
539 | list_for_each_entry_safe(ibm, itmp, | |
540 | &tpacpi_all_drivers, | |
541 | all_drivers) { | |
542 | if (ibm->resume) | |
543 | (ibm->resume)(); | |
544 | } | |
545 | ||
546 | return 0; | |
547 | } | |
548 | ||
54ae1501 HMH |
549 | static struct platform_driver tpacpi_pdriver = { |
550 | .driver = { | |
551 | .name = IBM_DRVR_NAME, | |
552 | .owner = THIS_MODULE, | |
553 | }, | |
e295e850 | 554 | .resume = tpacpi_resume_handler, |
54ae1501 HMH |
555 | }; |
556 | ||
7fd40029 HMH |
557 | static struct platform_driver tpacpi_hwmon_pdriver = { |
558 | .driver = { | |
559 | .name = IBM_HWMON_DRVR_NAME, | |
560 | .owner = THIS_MODULE, | |
561 | }, | |
562 | }; | |
54ae1501 | 563 | |
176750d6 HMH |
564 | /************************************************************************* |
565 | * thinkpad-acpi driver attributes | |
566 | */ | |
567 | ||
568 | /* interface_version --------------------------------------------------- */ | |
569 | static ssize_t tpacpi_driver_interface_version_show( | |
570 | struct device_driver *drv, | |
571 | char *buf) | |
572 | { | |
573 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); | |
574 | } | |
575 | ||
576 | static DRIVER_ATTR(interface_version, S_IRUGO, | |
577 | tpacpi_driver_interface_version_show, NULL); | |
578 | ||
579 | /* debug_level --------------------------------------------------------- */ | |
580 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, | |
581 | char *buf) | |
582 | { | |
583 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); | |
584 | } | |
585 | ||
586 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, | |
587 | const char *buf, size_t count) | |
588 | { | |
589 | unsigned long t; | |
176750d6 | 590 | |
7252374a | 591 | if (parse_strtoul(buf, 0xffff, &t)) |
176750d6 HMH |
592 | return -EINVAL; |
593 | ||
594 | dbg_level = t; | |
595 | ||
596 | return count; | |
597 | } | |
598 | ||
599 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, | |
600 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); | |
601 | ||
602 | /* version ------------------------------------------------------------- */ | |
603 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, | |
604 | char *buf) | |
605 | { | |
606 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", IBM_DESC, IBM_VERSION); | |
607 | } | |
608 | ||
609 | static DRIVER_ATTR(version, S_IRUGO, | |
610 | tpacpi_driver_version_show, NULL); | |
611 | ||
612 | /* --------------------------------------------------------------------- */ | |
613 | ||
614 | static struct driver_attribute* tpacpi_driver_attributes[] = { | |
615 | &driver_attr_debug_level, &driver_attr_version, | |
616 | &driver_attr_interface_version, | |
617 | }; | |
618 | ||
619 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) | |
620 | { | |
621 | int i, res; | |
622 | ||
623 | i = 0; | |
624 | res = 0; | |
625 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { | |
626 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); | |
627 | i++; | |
628 | } | |
629 | ||
630 | return res; | |
631 | } | |
632 | ||
633 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) | |
634 | { | |
635 | int i; | |
636 | ||
637 | for(i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) | |
638 | driver_remove_file(drv, tpacpi_driver_attributes[i]); | |
639 | } | |
640 | ||
7252374a HMH |
641 | /************************************************************************* |
642 | * sysfs support helpers | |
643 | */ | |
644 | ||
645 | struct attribute_set_obj { | |
646 | struct attribute_set s; | |
647 | struct attribute *a; | |
648 | } __attribute__((packed)); | |
649 | ||
650 | static struct attribute_set *create_attr_set(unsigned int max_members, | |
651 | const char* name) | |
652 | { | |
653 | struct attribute_set_obj *sobj; | |
654 | ||
655 | if (max_members == 0) | |
656 | return NULL; | |
657 | ||
658 | /* Allocates space for implicit NULL at the end too */ | |
659 | sobj = kzalloc(sizeof(struct attribute_set_obj) + | |
660 | max_members * sizeof(struct attribute *), | |
661 | GFP_KERNEL); | |
662 | if (!sobj) | |
663 | return NULL; | |
664 | sobj->s.max_members = max_members; | |
665 | sobj->s.group.attrs = &sobj->a; | |
666 | sobj->s.group.name = name; | |
667 | ||
668 | return &sobj->s; | |
669 | } | |
670 | ||
671 | /* not multi-threaded safe, use it in a single thread per set */ | |
672 | static int add_to_attr_set(struct attribute_set* s, struct attribute *attr) | |
673 | { | |
674 | if (!s || !attr) | |
675 | return -EINVAL; | |
676 | ||
677 | if (s->members >= s->max_members) | |
678 | return -ENOMEM; | |
679 | ||
680 | s->group.attrs[s->members] = attr; | |
681 | s->members++; | |
682 | ||
683 | return 0; | |
684 | } | |
685 | ||
686 | static int add_many_to_attr_set(struct attribute_set* s, | |
687 | struct attribute **attr, | |
688 | unsigned int count) | |
689 | { | |
690 | int i, res; | |
691 | ||
692 | for (i = 0; i < count; i++) { | |
693 | res = add_to_attr_set(s, attr[i]); | |
694 | if (res) | |
695 | return res; | |
696 | } | |
697 | ||
698 | return 0; | |
699 | } | |
700 | ||
701 | static void delete_attr_set(struct attribute_set* s, struct kobject *kobj) | |
702 | { | |
703 | sysfs_remove_group(kobj, &s->group); | |
704 | destroy_attr_set(s); | |
705 | } | |
706 | ||
707 | static int parse_strtoul(const char *buf, | |
708 | unsigned long max, unsigned long *value) | |
709 | { | |
710 | char *endp; | |
711 | ||
712 | *value = simple_strtoul(buf, &endp, 0); | |
713 | while (*endp && isspace(*endp)) | |
714 | endp++; | |
715 | if (*endp || *value > max) | |
716 | return -EINVAL; | |
717 | ||
718 | return 0; | |
719 | } | |
720 | ||
56b6aeb0 HMH |
721 | /**************************************************************************** |
722 | **************************************************************************** | |
723 | * | |
724 | * Subdrivers | |
725 | * | |
726 | **************************************************************************** | |
727 | ****************************************************************************/ | |
728 | ||
729 | /************************************************************************* | |
142cfc90 | 730 | * thinkpad-acpi init subdriver |
56b6aeb0 HMH |
731 | */ |
732 | ||
a5763f22 | 733 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
1da177e4 LT |
734 | { |
735 | printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); | |
736 | printk(IBM_INFO "%s\n", IBM_URL); | |
737 | ||
d5a2f2f1 HMH |
738 | printk(IBM_INFO "ThinkPad BIOS %s, EC %s\n", |
739 | (thinkpad_id.bios_version_str) ? | |
740 | thinkpad_id.bios_version_str : "unknown", | |
741 | (thinkpad_id.ec_version_str) ? | |
742 | thinkpad_id.ec_version_str : "unknown"); | |
743 | ||
744 | if (thinkpad_id.vendor && thinkpad_id.model_str) | |
745 | printk(IBM_INFO "%s %s\n", | |
746 | (thinkpad_id.vendor == PCI_VENDOR_ID_IBM) ? | |
747 | "IBM" : ((thinkpad_id.vendor == | |
748 | PCI_VENDOR_ID_LENOVO) ? | |
749 | "Lenovo" : "Unknown vendor"), | |
750 | thinkpad_id.model_str); | |
3945ac36 | 751 | |
1da177e4 LT |
752 | return 0; |
753 | } | |
754 | ||
643f12db | 755 | static int thinkpad_acpi_driver_read(char *p) |
1da177e4 LT |
756 | { |
757 | int len = 0; | |
758 | ||
759 | len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC); | |
760 | len += sprintf(p + len, "version:\t%s\n", IBM_VERSION); | |
761 | ||
762 | return len; | |
763 | } | |
764 | ||
a5763f22 HMH |
765 | static struct ibm_struct thinkpad_acpi_driver_data = { |
766 | .name = "driver", | |
767 | .read = thinkpad_acpi_driver_read, | |
768 | }; | |
769 | ||
56b6aeb0 HMH |
770 | /************************************************************************* |
771 | * Hotkey subdriver | |
772 | */ | |
773 | ||
78f81cc4 | 774 | static int hotkey_orig_status; |
ae92bd17 | 775 | static u32 hotkey_orig_mask; |
9b010de5 | 776 | static u32 hotkey_all_mask; |
6a38abbf HMH |
777 | static u32 hotkey_reserved_mask; |
778 | ||
edf0e0e5 | 779 | static u16 *hotkey_keycode_map; |
78f81cc4 | 780 | |
94954cc6 | 781 | static struct attribute_set *hotkey_dev_attributes; |
a0416420 | 782 | |
74941a69 HMH |
783 | static int hotkey_get_wlsw(int *status) |
784 | { | |
785 | if (!acpi_evalf(hkey_handle, status, "WLSW", "d")) | |
786 | return -EIO; | |
787 | return 0; | |
788 | } | |
789 | ||
a0416420 HMH |
790 | /* sysfs hotkey enable ------------------------------------------------- */ |
791 | static ssize_t hotkey_enable_show(struct device *dev, | |
792 | struct device_attribute *attr, | |
793 | char *buf) | |
794 | { | |
ae92bd17 HMH |
795 | int res, status; |
796 | u32 mask; | |
a0416420 HMH |
797 | |
798 | res = hotkey_get(&status, &mask); | |
799 | if (res) | |
800 | return res; | |
801 | ||
802 | return snprintf(buf, PAGE_SIZE, "%d\n", status); | |
803 | } | |
804 | ||
805 | static ssize_t hotkey_enable_store(struct device *dev, | |
806 | struct device_attribute *attr, | |
807 | const char *buf, size_t count) | |
808 | { | |
809 | unsigned long t; | |
ae92bd17 HMH |
810 | int res, status; |
811 | u32 mask; | |
a0416420 HMH |
812 | |
813 | if (parse_strtoul(buf, 1, &t)) | |
814 | return -EINVAL; | |
815 | ||
816 | res = hotkey_get(&status, &mask); | |
817 | if (!res) | |
818 | res = hotkey_set(t, mask); | |
819 | ||
820 | return (res) ? res : count; | |
821 | } | |
822 | ||
823 | static struct device_attribute dev_attr_hotkey_enable = | |
cc4c24e1 | 824 | __ATTR(hotkey_enable, S_IWUSR | S_IRUGO, |
a0416420 HMH |
825 | hotkey_enable_show, hotkey_enable_store); |
826 | ||
827 | /* sysfs hotkey mask --------------------------------------------------- */ | |
828 | static ssize_t hotkey_mask_show(struct device *dev, | |
829 | struct device_attribute *attr, | |
830 | char *buf) | |
831 | { | |
ae92bd17 HMH |
832 | int res, status; |
833 | u32 mask; | |
a0416420 HMH |
834 | |
835 | res = hotkey_get(&status, &mask); | |
836 | if (res) | |
837 | return res; | |
838 | ||
ae92bd17 | 839 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", mask); |
a0416420 HMH |
840 | } |
841 | ||
842 | static ssize_t hotkey_mask_store(struct device *dev, | |
843 | struct device_attribute *attr, | |
844 | const char *buf, size_t count) | |
845 | { | |
846 | unsigned long t; | |
ae92bd17 HMH |
847 | int res, status; |
848 | u32 mask; | |
a0416420 | 849 | |
ae92bd17 | 850 | if (parse_strtoul(buf, 0xffffffffUL, &t)) |
a0416420 HMH |
851 | return -EINVAL; |
852 | ||
853 | res = hotkey_get(&status, &mask); | |
854 | if (!res) | |
855 | hotkey_set(status, t); | |
856 | ||
857 | return (res) ? res : count; | |
858 | } | |
859 | ||
860 | static struct device_attribute dev_attr_hotkey_mask = | |
cc4c24e1 | 861 | __ATTR(hotkey_mask, S_IWUSR | S_IRUGO, |
a0416420 HMH |
862 | hotkey_mask_show, hotkey_mask_store); |
863 | ||
864 | /* sysfs hotkey bios_enabled ------------------------------------------- */ | |
865 | static ssize_t hotkey_bios_enabled_show(struct device *dev, | |
866 | struct device_attribute *attr, | |
867 | char *buf) | |
868 | { | |
869 | return snprintf(buf, PAGE_SIZE, "%d\n", hotkey_orig_status); | |
870 | } | |
871 | ||
872 | static struct device_attribute dev_attr_hotkey_bios_enabled = | |
cc4c24e1 | 873 | __ATTR(hotkey_bios_enabled, S_IRUGO, hotkey_bios_enabled_show, NULL); |
a0416420 HMH |
874 | |
875 | /* sysfs hotkey bios_mask ---------------------------------------------- */ | |
876 | static ssize_t hotkey_bios_mask_show(struct device *dev, | |
877 | struct device_attribute *attr, | |
878 | char *buf) | |
879 | { | |
ae92bd17 | 880 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_orig_mask); |
a0416420 HMH |
881 | } |
882 | ||
883 | static struct device_attribute dev_attr_hotkey_bios_mask = | |
cc4c24e1 | 884 | __ATTR(hotkey_bios_mask, S_IRUGO, hotkey_bios_mask_show, NULL); |
a0416420 | 885 | |
9b010de5 HMH |
886 | /* sysfs hotkey all_mask ----------------------------------------------- */ |
887 | static ssize_t hotkey_all_mask_show(struct device *dev, | |
888 | struct device_attribute *attr, | |
889 | char *buf) | |
890 | { | |
891 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", hotkey_all_mask); | |
892 | } | |
893 | ||
894 | static struct device_attribute dev_attr_hotkey_all_mask = | |
895 | __ATTR(hotkey_all_mask, S_IRUGO, hotkey_all_mask_show, NULL); | |
896 | ||
897 | /* sysfs hotkey recommended_mask --------------------------------------- */ | |
898 | static ssize_t hotkey_recommended_mask_show(struct device *dev, | |
899 | struct device_attribute *attr, | |
900 | char *buf) | |
901 | { | |
902 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", | |
903 | hotkey_all_mask & ~hotkey_reserved_mask); | |
904 | } | |
905 | ||
906 | static struct device_attribute dev_attr_hotkey_recommended_mask = | |
907 | __ATTR(hotkey_recommended_mask, S_IRUGO, | |
908 | hotkey_recommended_mask_show, NULL); | |
909 | ||
74941a69 HMH |
910 | /* sysfs hotkey radio_sw ----------------------------------------------- */ |
911 | static ssize_t hotkey_radio_sw_show(struct device *dev, | |
912 | struct device_attribute *attr, | |
913 | char *buf) | |
914 | { | |
915 | int res, s; | |
916 | res = hotkey_get_wlsw(&s); | |
917 | if (res < 0) | |
918 | return res; | |
919 | ||
920 | return snprintf(buf, PAGE_SIZE, "%d\n", !!s); | |
921 | } | |
922 | ||
923 | static struct device_attribute dev_attr_hotkey_radio_sw = | |
924 | __ATTR(hotkey_radio_sw, S_IRUGO, hotkey_radio_sw_show, NULL); | |
925 | ||
ff80f137 HMH |
926 | /* sysfs hotkey report_mode -------------------------------------------- */ |
927 | static ssize_t hotkey_report_mode_show(struct device *dev, | |
928 | struct device_attribute *attr, | |
929 | char *buf) | |
930 | { | |
931 | return snprintf(buf, PAGE_SIZE, "%d\n", | |
932 | (hotkey_report_mode != 0) ? hotkey_report_mode : 1); | |
933 | } | |
934 | ||
935 | static struct device_attribute dev_attr_hotkey_report_mode = | |
936 | __ATTR(hotkey_report_mode, S_IRUGO, hotkey_report_mode_show, NULL); | |
937 | ||
a0416420 HMH |
938 | /* --------------------------------------------------------------------- */ |
939 | ||
ff80f137 HMH |
940 | static struct attribute *hotkey_attributes[] __initdata = { |
941 | &dev_attr_hotkey_enable.attr, | |
942 | &dev_attr_hotkey_report_mode.attr, | |
943 | }; | |
944 | ||
945 | static struct attribute *hotkey_mask_attributes[] __initdata = { | |
a0416420 HMH |
946 | &dev_attr_hotkey_mask.attr, |
947 | &dev_attr_hotkey_bios_enabled.attr, | |
948 | &dev_attr_hotkey_bios_mask.attr, | |
9b010de5 HMH |
949 | &dev_attr_hotkey_all_mask.attr, |
950 | &dev_attr_hotkey_recommended_mask.attr, | |
a0416420 HMH |
951 | }; |
952 | ||
a5763f22 | 953 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
56b6aeb0 | 954 | { |
edf0e0e5 HMH |
955 | |
956 | static u16 ibm_keycode_map[] __initdata = { | |
957 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ | |
958 | KEY_FN_F1, KEY_FN_F2, KEY_COFFEE, KEY_SLEEP, | |
959 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, | |
960 | KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, | |
961 | /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */ | |
962 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ | |
963 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ | |
964 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ | |
965 | KEY_RESERVED, /* 0x0F: FN+HOME (brightness up) */ | |
966 | /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */ | |
967 | KEY_RESERVED, /* 0x10: FN+END (brightness down) */ | |
968 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ | |
969 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ | |
970 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ | |
971 | KEY_RESERVED, /* 0x14: VOLUME UP */ | |
972 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ | |
973 | KEY_RESERVED, /* 0x16: MUTE */ | |
974 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ | |
975 | /* (assignments unknown, please report if found) */ | |
976 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | |
977 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | |
978 | }; | |
979 | static u16 lenovo_keycode_map[] __initdata = { | |
980 | /* Scan Codes 0x00 to 0x0B: ACPI HKEY FN+F1..F12 */ | |
981 | KEY_FN_F1, KEY_COFFEE, KEY_BATTERY, KEY_SLEEP, | |
982 | KEY_WLAN, KEY_FN_F6, KEY_SWITCHVIDEOMODE, KEY_FN_F8, | |
983 | KEY_FN_F9, KEY_FN_F10, KEY_FN_F11, KEY_SUSPEND, | |
984 | /* Scan codes 0x0C to 0x0F: Other ACPI HKEY hot keys */ | |
985 | KEY_UNKNOWN, /* 0x0C: FN+BACKSPACE */ | |
986 | KEY_UNKNOWN, /* 0x0D: FN+INSERT */ | |
987 | KEY_UNKNOWN, /* 0x0E: FN+DELETE */ | |
988 | KEY_BRIGHTNESSUP, /* 0x0F: FN+HOME (brightness up) */ | |
989 | /* Scan codes 0x10 to 0x1F: Extended ACPI HKEY hot keys */ | |
990 | KEY_BRIGHTNESSDOWN, /* 0x10: FN+END (brightness down) */ | |
991 | KEY_RESERVED, /* 0x11: FN+PGUP (thinklight toggle) */ | |
992 | KEY_UNKNOWN, /* 0x12: FN+PGDOWN */ | |
993 | KEY_ZOOM, /* 0x13: FN+SPACE (zoom) */ | |
994 | KEY_RESERVED, /* 0x14: VOLUME UP */ | |
995 | KEY_RESERVED, /* 0x15: VOLUME DOWN */ | |
996 | KEY_RESERVED, /* 0x16: MUTE */ | |
997 | KEY_VENDOR, /* 0x17: Thinkpad/AccessIBM/Lenovo */ | |
998 | /* (assignments unknown, please report if found) */ | |
999 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | |
1000 | KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, KEY_UNKNOWN, | |
1001 | }; | |
1002 | ||
1003 | #define TPACPI_HOTKEY_MAP_LEN ARRAY_SIZE(ibm_keycode_map) | |
1004 | #define TPACPI_HOTKEY_MAP_SIZE sizeof(ibm_keycode_map) | |
1005 | #define TPACPI_HOTKEY_MAP_TYPESIZE sizeof(ibm_keycode_map[0]) | |
1006 | ||
6a38abbf | 1007 | int res, i; |
74941a69 | 1008 | int status; |
1b6521dc | 1009 | int hkeyv; |
b86c4722 | 1010 | |
fe08bc4b HMH |
1011 | vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); |
1012 | ||
6a38abbf HMH |
1013 | BUG_ON(!tpacpi_inputdev); |
1014 | ||
8d376cd6 | 1015 | IBM_ACPIHANDLE_INIT(hkey); |
40ca9fdf | 1016 | mutex_init(&hotkey_mutex); |
5fba344c | 1017 | |
56b6aeb0 | 1018 | /* hotkey not supported on 570 */ |
d8fd94d9 | 1019 | tp_features.hotkey = hkey_handle != NULL; |
56b6aeb0 | 1020 | |
fe08bc4b | 1021 | vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n", |
d8fd94d9 | 1022 | str_supported(tp_features.hotkey)); |
fe08bc4b | 1023 | |
d8fd94d9 | 1024 | if (tp_features.hotkey) { |
ff80f137 | 1025 | hotkey_dev_attributes = create_attr_set(8, NULL); |
a0416420 HMH |
1026 | if (!hotkey_dev_attributes) |
1027 | return -ENOMEM; | |
ff80f137 HMH |
1028 | res = add_many_to_attr_set(hotkey_dev_attributes, |
1029 | hotkey_attributes, | |
1030 | ARRAY_SIZE(hotkey_attributes)); | |
a0416420 HMH |
1031 | if (res) |
1032 | return res; | |
1033 | ||
56b6aeb0 | 1034 | /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
1b6521dc HMH |
1035 | A30, R30, R31, T20-22, X20-21, X22-24. Detected by checking |
1036 | for HKEY interface version 0x100 */ | |
1037 | if (acpi_evalf(hkey_handle, &hkeyv, "MHKV", "qd")) { | |
1038 | if ((hkeyv >> 8) != 1) { | |
1039 | printk(IBM_ERR "unknown version of the " | |
1040 | "HKEY interface: 0x%x\n", hkeyv); | |
1041 | printk(IBM_ERR "please report this to %s\n", | |
1042 | IBM_MAIL); | |
1043 | } else { | |
1044 | /* | |
1045 | * MHKV 0x100 in A31, R40, R40e, | |
1046 | * T4x, X31, and later | |
1047 | * */ | |
1048 | tp_features.hotkey_mask = 1; | |
1049 | } | |
1050 | } | |
56b6aeb0 | 1051 | |
fe08bc4b | 1052 | vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n", |
d8fd94d9 | 1053 | str_supported(tp_features.hotkey_mask)); |
fe08bc4b | 1054 | |
9b010de5 | 1055 | if (tp_features.hotkey_mask) { |
9b010de5 | 1056 | if (!acpi_evalf(hkey_handle, &hotkey_all_mask, |
1b6521dc HMH |
1057 | "MHKA", "qd")) { |
1058 | printk(IBM_ERR | |
1059 | "missing MHKA handler, " | |
1060 | "please report this to %s\n", | |
1061 | IBM_MAIL); | |
9b010de5 | 1062 | hotkey_all_mask = 0x080cU; /* FN+F12, FN+F4, FN+F3 */ |
1b6521dc | 1063 | } |
9b010de5 HMH |
1064 | } |
1065 | ||
b86c4722 | 1066 | res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask); |
a0416420 HMH |
1067 | if (!res && tp_features.hotkey_mask) { |
1068 | res = add_many_to_attr_set(hotkey_dev_attributes, | |
1069 | hotkey_mask_attributes, | |
1070 | ARRAY_SIZE(hotkey_mask_attributes)); | |
1071 | } | |
74941a69 HMH |
1072 | |
1073 | /* Not all thinkpads have a hardware radio switch */ | |
1074 | if (!res && acpi_evalf(hkey_handle, &status, "WLSW", "qd")) { | |
1075 | tp_features.hotkey_wlsw = 1; | |
1076 | printk(IBM_INFO | |
1077 | "radio switch found; radios are %s\n", | |
1078 | enabled(status, 0)); | |
1079 | res = add_to_attr_set(hotkey_dev_attributes, | |
1080 | &dev_attr_hotkey_radio_sw.attr); | |
1081 | } | |
1082 | ||
a0416420 HMH |
1083 | if (!res) |
1084 | res = register_attr_set_with_sysfs( | |
1085 | hotkey_dev_attributes, | |
1086 | &tpacpi_pdev->dev.kobj); | |
b86c4722 HMH |
1087 | if (res) |
1088 | return res; | |
6a38abbf | 1089 | |
edf0e0e5 HMH |
1090 | /* Set up key map */ |
1091 | ||
1092 | hotkey_keycode_map = kmalloc(TPACPI_HOTKEY_MAP_SIZE, | |
1093 | GFP_KERNEL); | |
1094 | if (!hotkey_keycode_map) { | |
1095 | printk(IBM_ERR "failed to allocate memory for key map\n"); | |
1096 | return -ENOMEM; | |
1097 | } | |
1098 | ||
1099 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) { | |
1100 | dbg_printk(TPACPI_DBG_INIT, | |
1101 | "using Lenovo default hot key map\n"); | |
1102 | memcpy(hotkey_keycode_map, &lenovo_keycode_map, | |
1103 | TPACPI_HOTKEY_MAP_SIZE); | |
1104 | } else { | |
1105 | dbg_printk(TPACPI_DBG_INIT, | |
1106 | "using IBM default hot key map\n"); | |
1107 | memcpy(hotkey_keycode_map, &ibm_keycode_map, | |
1108 | TPACPI_HOTKEY_MAP_SIZE); | |
1109 | } | |
1110 | ||
6a38abbf HMH |
1111 | set_bit(EV_KEY, tpacpi_inputdev->evbit); |
1112 | set_bit(EV_MSC, tpacpi_inputdev->evbit); | |
1113 | set_bit(MSC_SCAN, tpacpi_inputdev->mscbit); | |
edf0e0e5 HMH |
1114 | tpacpi_inputdev->keycodesize = TPACPI_HOTKEY_MAP_TYPESIZE; |
1115 | tpacpi_inputdev->keycodemax = TPACPI_HOTKEY_MAP_LEN; | |
1116 | tpacpi_inputdev->keycode = hotkey_keycode_map; | |
1117 | for (i = 0; i < TPACPI_HOTKEY_MAP_LEN; i++) { | |
6a38abbf HMH |
1118 | if (hotkey_keycode_map[i] != KEY_RESERVED) { |
1119 | set_bit(hotkey_keycode_map[i], | |
1120 | tpacpi_inputdev->keybit); | |
1121 | } else { | |
1122 | if (i < sizeof(hotkey_reserved_mask)*8) | |
1123 | hotkey_reserved_mask |= 1 << i; | |
1124 | } | |
1125 | } | |
1126 | ||
5c29d58f HMH |
1127 | if (tp_features.hotkey_wlsw) { |
1128 | set_bit(EV_SW, tpacpi_inputdev->evbit); | |
1129 | set_bit(SW_RADIO, tpacpi_inputdev->swbit); | |
1130 | } | |
1131 | ||
1a343760 HMH |
1132 | dbg_printk(TPACPI_DBG_INIT, |
1133 | "enabling hot key handling\n"); | |
1134 | res = hotkey_set(1, (hotkey_all_mask & ~hotkey_reserved_mask) | |
1135 | | hotkey_orig_mask); | |
1136 | if (res) | |
1137 | return res; | |
ff80f137 HMH |
1138 | |
1139 | dbg_printk(TPACPI_DBG_INIT, | |
1140 | "legacy hot key reporting over procfs %s\n", | |
1141 | (hotkey_report_mode < 2) ? | |
1142 | "enabled" : "disabled"); | |
56b6aeb0 HMH |
1143 | } |
1144 | ||
d8fd94d9 | 1145 | return (tp_features.hotkey)? 0 : 1; |
56b6aeb0 HMH |
1146 | } |
1147 | ||
1148 | static void hotkey_exit(void) | |
1149 | { | |
b86c4722 HMH |
1150 | int res; |
1151 | ||
d8fd94d9 | 1152 | if (tp_features.hotkey) { |
fe08bc4b | 1153 | dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n"); |
b86c4722 HMH |
1154 | res = hotkey_set(hotkey_orig_status, hotkey_orig_mask); |
1155 | if (res) | |
1156 | printk(IBM_ERR "failed to restore hotkey to BIOS defaults\n"); | |
5fba344c | 1157 | } |
a0416420 HMH |
1158 | |
1159 | if (hotkey_dev_attributes) { | |
1160 | delete_attr_set(hotkey_dev_attributes, &tpacpi_pdev->dev.kobj); | |
1161 | hotkey_dev_attributes = NULL; | |
1162 | } | |
56b6aeb0 HMH |
1163 | } |
1164 | ||
6a38abbf HMH |
1165 | static void tpacpi_input_send_key(unsigned int scancode, |
1166 | unsigned int keycode) | |
1167 | { | |
1168 | if (keycode != KEY_RESERVED) { | |
8523ed6f HMH |
1169 | mutex_lock(&tpacpi_inputdev_send_mutex); |
1170 | ||
6a38abbf HMH |
1171 | input_report_key(tpacpi_inputdev, keycode, 1); |
1172 | if (keycode == KEY_UNKNOWN) | |
1173 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, | |
1174 | scancode); | |
1175 | input_sync(tpacpi_inputdev); | |
1176 | ||
1177 | input_report_key(tpacpi_inputdev, keycode, 0); | |
1178 | if (keycode == KEY_UNKNOWN) | |
1179 | input_event(tpacpi_inputdev, EV_MSC, MSC_SCAN, | |
1180 | scancode); | |
1181 | input_sync(tpacpi_inputdev); | |
8523ed6f HMH |
1182 | |
1183 | mutex_unlock(&tpacpi_inputdev_send_mutex); | |
6a38abbf HMH |
1184 | } |
1185 | } | |
1186 | ||
5c29d58f HMH |
1187 | static void tpacpi_input_send_radiosw(void) |
1188 | { | |
1189 | int wlsw; | |
1190 | ||
8523ed6f HMH |
1191 | mutex_lock(&tpacpi_inputdev_send_mutex); |
1192 | ||
f4e1e43c | 1193 | if (tp_features.hotkey_wlsw && !hotkey_get_wlsw(&wlsw)) { |
5c29d58f HMH |
1194 | input_report_switch(tpacpi_inputdev, |
1195 | SW_RADIO, !!wlsw); | |
f4e1e43c HMH |
1196 | input_sync(tpacpi_inputdev); |
1197 | } | |
8523ed6f HMH |
1198 | |
1199 | mutex_unlock(&tpacpi_inputdev_send_mutex); | |
5c29d58f HMH |
1200 | } |
1201 | ||
56b6aeb0 HMH |
1202 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
1203 | { | |
6a38abbf HMH |
1204 | u32 hkey; |
1205 | unsigned int keycode, scancode; | |
3eea123d | 1206 | int send_acpi_ev; |
3e5ce914 | 1207 | int ignore_acpi_ev; |
3eea123d HMH |
1208 | |
1209 | if (event != 0x80) { | |
1210 | printk(IBM_ERR "unknown HKEY notification event %d\n", event); | |
1211 | /* forward it to userspace, maybe it knows how to handle it */ | |
1212 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, | |
1213 | ibm->acpi->device->dev.bus_id, | |
1214 | event, 0); | |
1215 | return; | |
1216 | } | |
1217 | ||
1218 | while (1) { | |
1219 | if (!acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) { | |
1220 | printk(IBM_ERR "failed to retrieve HKEY event\n"); | |
1221 | return; | |
1222 | } | |
1223 | ||
1224 | if (hkey == 0) { | |
1225 | /* queue empty */ | |
1226 | return; | |
1227 | } | |
1228 | ||
1229 | send_acpi_ev = 0; | |
3e5ce914 | 1230 | ignore_acpi_ev = 0; |
56b6aeb0 | 1231 | |
ff80f137 HMH |
1232 | switch (hkey >> 12) { |
1233 | case 1: | |
1234 | /* 0x1000-0x1FFF: key presses */ | |
1235 | scancode = hkey & 0xfff; | |
1236 | if (scancode > 0 && scancode < 0x21) { | |
1237 | scancode--; | |
1238 | keycode = hotkey_keycode_map[scancode]; | |
1239 | tpacpi_input_send_key(scancode, keycode); | |
1240 | } else { | |
1241 | printk(IBM_ERR | |
1242 | "hotkey 0x%04x out of range for keyboard map\n", | |
1243 | hkey); | |
1244 | send_acpi_ev = 1; | |
1245 | } | |
1246 | break; | |
1247 | case 5: | |
1248 | /* 0x5000-0x5FFF: LID */ | |
1249 | /* we don't handle it through this path, just | |
1250 | * eat up known LID events */ | |
1251 | if (hkey != 0x5001 && hkey != 0x5002) { | |
1252 | printk(IBM_ERR | |
3eea123d HMH |
1253 | "unknown LID-related HKEY event: 0x%04x\n", |
1254 | hkey); | |
ff80f137 | 1255 | send_acpi_ev = 1; |
3e5ce914 HMH |
1256 | } else { |
1257 | ignore_acpi_ev = 1; | |
ff80f137 HMH |
1258 | } |
1259 | break; | |
1260 | case 7: | |
1261 | /* 0x7000-0x7FFF: misc */ | |
1262 | if (tp_features.hotkey_wlsw && hkey == 0x7000) { | |
1263 | tpacpi_input_send_radiosw(); | |
6a38abbf | 1264 | break; |
6a38abbf | 1265 | } |
ff80f137 HMH |
1266 | /* fallthrough to default */ |
1267 | default: | |
1268 | /* case 2: dock-related */ | |
1269 | /* 0x2305 - T43 waking up due to bay lever eject while aslept */ | |
1270 | /* case 3: ultra-bay related. maybe bay in dock? */ | |
1271 | /* 0x3003 - T43 after wake up by bay lever eject (0x2305) */ | |
1272 | printk(IBM_NOTICE "unhandled HKEY event 0x%04x\n", hkey); | |
1273 | send_acpi_ev = 1; | |
6a38abbf | 1274 | } |
ff80f137 | 1275 | |
3eea123d | 1276 | /* Legacy events */ |
3e5ce914 | 1277 | if (!ignore_acpi_ev && (send_acpi_ev || hotkey_report_mode < 2)) { |
3eea123d | 1278 | acpi_bus_generate_proc_event(ibm->acpi->device, event, hkey); |
3e5ce914 | 1279 | } |
ff80f137 | 1280 | |
3eea123d | 1281 | /* netlink events */ |
3e5ce914 | 1282 | if (!ignore_acpi_ev && send_acpi_ev) { |
3eea123d HMH |
1283 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
1284 | ibm->acpi->device->dev.bus_id, | |
1285 | event, hkey); | |
1286 | } | |
56b6aeb0 HMH |
1287 | } |
1288 | } | |
1289 | ||
5c29d58f HMH |
1290 | static void hotkey_resume(void) |
1291 | { | |
1292 | tpacpi_input_send_radiosw(); | |
1293 | } | |
1294 | ||
40ca9fdf HMH |
1295 | /* |
1296 | * Call with hotkey_mutex held | |
1297 | */ | |
ae92bd17 | 1298 | static int hotkey_get(int *status, u32 *mask) |
1da177e4 LT |
1299 | { |
1300 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) | |
b86c4722 | 1301 | return -EIO; |
78f81cc4 | 1302 | |
d8fd94d9 | 1303 | if (tp_features.hotkey_mask) |
78f81cc4 | 1304 | if (!acpi_evalf(hkey_handle, mask, "DHKN", "d")) |
b86c4722 | 1305 | return -EIO; |
78f81cc4 | 1306 | |
b86c4722 | 1307 | return 0; |
1da177e4 LT |
1308 | } |
1309 | ||
40ca9fdf HMH |
1310 | /* |
1311 | * Call with hotkey_mutex held | |
1312 | */ | |
ae92bd17 | 1313 | static int hotkey_set(int status, u32 mask) |
1da177e4 LT |
1314 | { |
1315 | int i; | |
1316 | ||
1317 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) | |
b86c4722 | 1318 | return -EIO; |
1da177e4 | 1319 | |
d8fd94d9 | 1320 | if (tp_features.hotkey_mask) |
78f81cc4 BD |
1321 | for (i = 0; i < 32; i++) { |
1322 | int bit = ((1 << i) & mask) != 0; | |
1323 | if (!acpi_evalf(hkey_handle, | |
1324 | NULL, "MHKM", "vdd", i + 1, bit)) | |
b86c4722 | 1325 | return -EIO; |
78f81cc4 | 1326 | } |
1da177e4 | 1327 | |
b86c4722 | 1328 | return 0; |
1da177e4 LT |
1329 | } |
1330 | ||
a0416420 | 1331 | /* procfs -------------------------------------------------------------- */ |
78f81cc4 | 1332 | static int hotkey_read(char *p) |
1da177e4 | 1333 | { |
ae92bd17 HMH |
1334 | int res, status; |
1335 | u32 mask; | |
1da177e4 LT |
1336 | int len = 0; |
1337 | ||
d8fd94d9 | 1338 | if (!tp_features.hotkey) { |
78f81cc4 BD |
1339 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
1340 | return len; | |
1341 | } | |
1342 | ||
40ca9fdf HMH |
1343 | res = mutex_lock_interruptible(&hotkey_mutex); |
1344 | if (res < 0) | |
1345 | return res; | |
b86c4722 | 1346 | res = hotkey_get(&status, &mask); |
40ca9fdf | 1347 | mutex_unlock(&hotkey_mutex); |
b86c4722 HMH |
1348 | if (res) |
1349 | return res; | |
1da177e4 LT |
1350 | |
1351 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); | |
d8fd94d9 | 1352 | if (tp_features.hotkey_mask) { |
ae92bd17 | 1353 | len += sprintf(p + len, "mask:\t\t0x%08x\n", mask); |
1da177e4 LT |
1354 | len += sprintf(p + len, |
1355 | "commands:\tenable, disable, reset, <mask>\n"); | |
1356 | } else { | |
1357 | len += sprintf(p + len, "mask:\t\tnot supported\n"); | |
1358 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); | |
1359 | } | |
1360 | ||
1361 | return len; | |
1362 | } | |
1363 | ||
78f81cc4 | 1364 | static int hotkey_write(char *buf) |
1da177e4 | 1365 | { |
ae92bd17 HMH |
1366 | int res, status; |
1367 | u32 mask; | |
1da177e4 LT |
1368 | char *cmd; |
1369 | int do_cmd = 0; | |
1370 | ||
d8fd94d9 | 1371 | if (!tp_features.hotkey) |
1da177e4 LT |
1372 | return -ENODEV; |
1373 | ||
40ca9fdf HMH |
1374 | res = mutex_lock_interruptible(&hotkey_mutex); |
1375 | if (res < 0) | |
1376 | return res; | |
1377 | ||
b86c4722 HMH |
1378 | res = hotkey_get(&status, &mask); |
1379 | if (res) | |
40ca9fdf | 1380 | goto errexit; |
78f81cc4 | 1381 | |
40ca9fdf | 1382 | res = 0; |
1da177e4 LT |
1383 | while ((cmd = next_cmd(&buf))) { |
1384 | if (strlencmp(cmd, "enable") == 0) { | |
1385 | status = 1; | |
1386 | } else if (strlencmp(cmd, "disable") == 0) { | |
1387 | status = 0; | |
1388 | } else if (strlencmp(cmd, "reset") == 0) { | |
78f81cc4 BD |
1389 | status = hotkey_orig_status; |
1390 | mask = hotkey_orig_mask; | |
1da177e4 LT |
1391 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
1392 | /* mask set */ | |
1393 | } else if (sscanf(cmd, "%x", &mask) == 1) { | |
1394 | /* mask set */ | |
40ca9fdf HMH |
1395 | } else { |
1396 | res = -EINVAL; | |
1397 | goto errexit; | |
1398 | } | |
1da177e4 LT |
1399 | do_cmd = 1; |
1400 | } | |
1401 | ||
40ca9fdf | 1402 | if (do_cmd) |
b86c4722 | 1403 | res = hotkey_set(status, mask); |
1da177e4 | 1404 | |
40ca9fdf HMH |
1405 | errexit: |
1406 | mutex_unlock(&hotkey_mutex); | |
1407 | return res; | |
78f81cc4 | 1408 | } |
1da177e4 | 1409 | |
1ba90e3a TR |
1410 | static const struct acpi_device_id ibm_htk_device_ids[] = { |
1411 | {IBM_HKEY_HID, 0}, | |
1412 | {"", 0}, | |
1413 | }; | |
1414 | ||
8d376cd6 | 1415 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
1ba90e3a | 1416 | .hid = ibm_htk_device_ids, |
8d376cd6 HMH |
1417 | .notify = hotkey_notify, |
1418 | .handle = &hkey_handle, | |
1419 | .type = ACPI_DEVICE_NOTIFY, | |
1420 | }; | |
1421 | ||
a5763f22 HMH |
1422 | static struct ibm_struct hotkey_driver_data = { |
1423 | .name = "hotkey", | |
a5763f22 HMH |
1424 | .read = hotkey_read, |
1425 | .write = hotkey_write, | |
1426 | .exit = hotkey_exit, | |
5c29d58f | 1427 | .resume = hotkey_resume, |
8d376cd6 | 1428 | .acpi = &ibm_hotkey_acpidriver, |
a5763f22 HMH |
1429 | }; |
1430 | ||
56b6aeb0 HMH |
1431 | /************************************************************************* |
1432 | * Bluetooth subdriver | |
1433 | */ | |
1da177e4 | 1434 | |
d3a6ade4 HMH |
1435 | /* sysfs bluetooth enable ---------------------------------------------- */ |
1436 | static ssize_t bluetooth_enable_show(struct device *dev, | |
1437 | struct device_attribute *attr, | |
1438 | char *buf) | |
1439 | { | |
1440 | int status; | |
1441 | ||
1442 | status = bluetooth_get_radiosw(); | |
1443 | if (status < 0) | |
1444 | return status; | |
1445 | ||
1446 | return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); | |
1447 | } | |
1448 | ||
1449 | static ssize_t bluetooth_enable_store(struct device *dev, | |
1450 | struct device_attribute *attr, | |
1451 | const char *buf, size_t count) | |
1452 | { | |
1453 | unsigned long t; | |
1454 | int res; | |
1455 | ||
1456 | if (parse_strtoul(buf, 1, &t)) | |
1457 | return -EINVAL; | |
1458 | ||
1459 | res = bluetooth_set_radiosw(t); | |
1460 | ||
1461 | return (res) ? res : count; | |
1462 | } | |
1463 | ||
1464 | static struct device_attribute dev_attr_bluetooth_enable = | |
cc4c24e1 | 1465 | __ATTR(bluetooth_enable, S_IWUSR | S_IRUGO, |
d3a6ade4 HMH |
1466 | bluetooth_enable_show, bluetooth_enable_store); |
1467 | ||
1468 | /* --------------------------------------------------------------------- */ | |
1469 | ||
1470 | static struct attribute *bluetooth_attributes[] = { | |
1471 | &dev_attr_bluetooth_enable.attr, | |
1472 | NULL | |
1473 | }; | |
1474 | ||
1475 | static const struct attribute_group bluetooth_attr_group = { | |
d3a6ade4 HMH |
1476 | .attrs = bluetooth_attributes, |
1477 | }; | |
1478 | ||
a5763f22 | 1479 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
1da177e4 | 1480 | { |
d3a6ade4 | 1481 | int res; |
d6fdd1e9 HMH |
1482 | int status = 0; |
1483 | ||
fe08bc4b HMH |
1484 | vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n"); |
1485 | ||
8d376cd6 | 1486 | IBM_ACPIHANDLE_INIT(hkey); |
5fba344c | 1487 | |
78f81cc4 BD |
1488 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
1489 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ | |
d8fd94d9 | 1490 | tp_features.bluetooth = hkey_handle && |
d6fdd1e9 HMH |
1491 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
1492 | ||
1493 | vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n", | |
1494 | str_supported(tp_features.bluetooth), | |
1495 | status); | |
1496 | ||
d3a6ade4 HMH |
1497 | if (tp_features.bluetooth) { |
1498 | if (!(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { | |
1499 | /* no bluetooth hardware present in system */ | |
1500 | tp_features.bluetooth = 0; | |
1501 | dbg_printk(TPACPI_DBG_INIT, | |
1502 | "bluetooth hardware not installed\n"); | |
1503 | } else { | |
1504 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, | |
1505 | &bluetooth_attr_group); | |
1506 | if (res) | |
1507 | return res; | |
1508 | } | |
d6fdd1e9 | 1509 | } |
fe08bc4b | 1510 | |
d8fd94d9 | 1511 | return (tp_features.bluetooth)? 0 : 1; |
1da177e4 LT |
1512 | } |
1513 | ||
d3a6ade4 HMH |
1514 | static void bluetooth_exit(void) |
1515 | { | |
1516 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, | |
1517 | &bluetooth_attr_group); | |
1518 | } | |
1519 | ||
d6fdd1e9 | 1520 | static int bluetooth_get_radiosw(void) |
1da177e4 LT |
1521 | { |
1522 | int status; | |
1523 | ||
d6fdd1e9 HMH |
1524 | if (!tp_features.bluetooth) |
1525 | return -ENODEV; | |
1da177e4 | 1526 | |
d6fdd1e9 HMH |
1527 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
1528 | return -EIO; | |
1529 | ||
1530 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0); | |
1531 | } | |
1532 | ||
1533 | static int bluetooth_set_radiosw(int radio_on) | |
1534 | { | |
1535 | int status; | |
1536 | ||
1537 | if (!tp_features.bluetooth) | |
1538 | return -ENODEV; | |
1539 | ||
1540 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) | |
1541 | return -EIO; | |
1542 | if (radio_on) | |
1543 | status |= TP_ACPI_BLUETOOTH_RADIOSSW; | |
1544 | else | |
1545 | status &= ~TP_ACPI_BLUETOOTH_RADIOSSW; | |
1546 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) | |
1547 | return -EIO; | |
1548 | ||
1549 | return 0; | |
1da177e4 LT |
1550 | } |
1551 | ||
d3a6ade4 | 1552 | /* procfs -------------------------------------------------------------- */ |
78f81cc4 | 1553 | static int bluetooth_read(char *p) |
1da177e4 LT |
1554 | { |
1555 | int len = 0; | |
d6fdd1e9 | 1556 | int status = bluetooth_get_radiosw(); |
1da177e4 | 1557 | |
d8fd94d9 | 1558 | if (!tp_features.bluetooth) |
1da177e4 | 1559 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
1da177e4 | 1560 | else { |
d6fdd1e9 HMH |
1561 | len += sprintf(p + len, "status:\t\t%s\n", |
1562 | (status)? "enabled" : "disabled"); | |
1da177e4 LT |
1563 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
1564 | } | |
1565 | ||
1566 | return len; | |
1567 | } | |
1568 | ||
78f81cc4 | 1569 | static int bluetooth_write(char *buf) |
1da177e4 | 1570 | { |
1da177e4 | 1571 | char *cmd; |
1da177e4 | 1572 | |
d8fd94d9 | 1573 | if (!tp_features.bluetooth) |
78f81cc4 | 1574 | return -ENODEV; |
1da177e4 LT |
1575 | |
1576 | while ((cmd = next_cmd(&buf))) { | |
1577 | if (strlencmp(cmd, "enable") == 0) { | |
d6fdd1e9 | 1578 | bluetooth_set_radiosw(1); |
1da177e4 | 1579 | } else if (strlencmp(cmd, "disable") == 0) { |
d6fdd1e9 | 1580 | bluetooth_set_radiosw(0); |
1da177e4 LT |
1581 | } else |
1582 | return -EINVAL; | |
1da177e4 LT |
1583 | } |
1584 | ||
1da177e4 LT |
1585 | return 0; |
1586 | } | |
1587 | ||
a5763f22 HMH |
1588 | static struct ibm_struct bluetooth_driver_data = { |
1589 | .name = "bluetooth", | |
1590 | .read = bluetooth_read, | |
1591 | .write = bluetooth_write, | |
d3a6ade4 | 1592 | .exit = bluetooth_exit, |
a5763f22 HMH |
1593 | }; |
1594 | ||
56b6aeb0 HMH |
1595 | /************************************************************************* |
1596 | * Wan subdriver | |
1597 | */ | |
1598 | ||
d3a6ade4 HMH |
1599 | /* sysfs wan enable ---------------------------------------------------- */ |
1600 | static ssize_t wan_enable_show(struct device *dev, | |
1601 | struct device_attribute *attr, | |
1602 | char *buf) | |
1603 | { | |
1604 | int status; | |
1605 | ||
1606 | status = wan_get_radiosw(); | |
1607 | if (status < 0) | |
1608 | return status; | |
1609 | ||
1610 | return snprintf(buf, PAGE_SIZE, "%d\n", status ? 1 : 0); | |
1611 | } | |
1612 | ||
1613 | static ssize_t wan_enable_store(struct device *dev, | |
1614 | struct device_attribute *attr, | |
1615 | const char *buf, size_t count) | |
1616 | { | |
1617 | unsigned long t; | |
1618 | int res; | |
1619 | ||
1620 | if (parse_strtoul(buf, 1, &t)) | |
1621 | return -EINVAL; | |
1622 | ||
1623 | res = wan_set_radiosw(t); | |
1624 | ||
1625 | return (res) ? res : count; | |
1626 | } | |
1627 | ||
1628 | static struct device_attribute dev_attr_wan_enable = | |
cc4c24e1 | 1629 | __ATTR(wwan_enable, S_IWUSR | S_IRUGO, |
d3a6ade4 HMH |
1630 | wan_enable_show, wan_enable_store); |
1631 | ||
1632 | /* --------------------------------------------------------------------- */ | |
1633 | ||
1634 | static struct attribute *wan_attributes[] = { | |
1635 | &dev_attr_wan_enable.attr, | |
1636 | NULL | |
1637 | }; | |
1638 | ||
1639 | static const struct attribute_group wan_attr_group = { | |
d3a6ade4 HMH |
1640 | .attrs = wan_attributes, |
1641 | }; | |
1642 | ||
a5763f22 | 1643 | static int __init wan_init(struct ibm_init_struct *iibm) |
42adb53c | 1644 | { |
d3a6ade4 | 1645 | int res; |
d6fdd1e9 HMH |
1646 | int status = 0; |
1647 | ||
fe08bc4b HMH |
1648 | vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n"); |
1649 | ||
8d376cd6 | 1650 | IBM_ACPIHANDLE_INIT(hkey); |
5fba344c | 1651 | |
d8fd94d9 | 1652 | tp_features.wan = hkey_handle && |
d6fdd1e9 HMH |
1653 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
1654 | ||
1655 | vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n", | |
1656 | str_supported(tp_features.wan), | |
1657 | status); | |
1658 | ||
d3a6ade4 HMH |
1659 | if (tp_features.wan) { |
1660 | if (!(status & TP_ACPI_WANCARD_HWPRESENT)) { | |
1661 | /* no wan hardware present in system */ | |
1662 | tp_features.wan = 0; | |
1663 | dbg_printk(TPACPI_DBG_INIT, | |
1664 | "wan hardware not installed\n"); | |
1665 | } else { | |
1666 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, | |
1667 | &wan_attr_group); | |
1668 | if (res) | |
1669 | return res; | |
1670 | } | |
d6fdd1e9 | 1671 | } |
fe08bc4b | 1672 | |
d8fd94d9 | 1673 | return (tp_features.wan)? 0 : 1; |
42adb53c JF |
1674 | } |
1675 | ||
d3a6ade4 HMH |
1676 | static void wan_exit(void) |
1677 | { | |
1678 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, | |
1679 | &wan_attr_group); | |
1680 | } | |
1681 | ||
d6fdd1e9 | 1682 | static int wan_get_radiosw(void) |
42adb53c JF |
1683 | { |
1684 | int status; | |
1685 | ||
d6fdd1e9 HMH |
1686 | if (!tp_features.wan) |
1687 | return -ENODEV; | |
42adb53c | 1688 | |
d6fdd1e9 HMH |
1689 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
1690 | return -EIO; | |
1691 | ||
1692 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0); | |
1693 | } | |
1694 | ||
1695 | static int wan_set_radiosw(int radio_on) | |
1696 | { | |
1697 | int status; | |
1698 | ||
1699 | if (!tp_features.wan) | |
1700 | return -ENODEV; | |
1701 | ||
1702 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) | |
1703 | return -EIO; | |
1704 | if (radio_on) | |
1705 | status |= TP_ACPI_WANCARD_RADIOSSW; | |
1706 | else | |
1707 | status &= ~TP_ACPI_WANCARD_RADIOSSW; | |
1708 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) | |
1709 | return -EIO; | |
1710 | ||
1711 | return 0; | |
42adb53c JF |
1712 | } |
1713 | ||
d3a6ade4 | 1714 | /* procfs -------------------------------------------------------------- */ |
42adb53c JF |
1715 | static int wan_read(char *p) |
1716 | { | |
1717 | int len = 0; | |
d6fdd1e9 | 1718 | int status = wan_get_radiosw(); |
42adb53c | 1719 | |
d8fd94d9 | 1720 | if (!tp_features.wan) |
42adb53c | 1721 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
42adb53c | 1722 | else { |
d6fdd1e9 HMH |
1723 | len += sprintf(p + len, "status:\t\t%s\n", |
1724 | (status)? "enabled" : "disabled"); | |
42adb53c JF |
1725 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
1726 | } | |
1727 | ||
1728 | return len; | |
1729 | } | |
1730 | ||
1731 | static int wan_write(char *buf) | |
1732 | { | |
42adb53c | 1733 | char *cmd; |
42adb53c | 1734 | |
d8fd94d9 | 1735 | if (!tp_features.wan) |
42adb53c JF |
1736 | return -ENODEV; |
1737 | ||
1738 | while ((cmd = next_cmd(&buf))) { | |
1739 | if (strlencmp(cmd, "enable") == 0) { | |
d6fdd1e9 | 1740 | wan_set_radiosw(1); |
42adb53c | 1741 | } else if (strlencmp(cmd, "disable") == 0) { |
d6fdd1e9 | 1742 | wan_set_radiosw(0); |
42adb53c JF |
1743 | } else |
1744 | return -EINVAL; | |
42adb53c JF |
1745 | } |
1746 | ||
42adb53c JF |
1747 | return 0; |
1748 | } | |
1749 | ||
a5763f22 HMH |
1750 | static struct ibm_struct wan_driver_data = { |
1751 | .name = "wan", | |
1752 | .read = wan_read, | |
1753 | .write = wan_write, | |
d3a6ade4 | 1754 | .exit = wan_exit, |
92641177 | 1755 | .flags.experimental = 1, |
a5763f22 HMH |
1756 | }; |
1757 | ||
56b6aeb0 HMH |
1758 | /************************************************************************* |
1759 | * Video subdriver | |
1760 | */ | |
1761 | ||
9a8e1738 HMH |
1762 | static enum video_access_mode video_supported; |
1763 | static int video_orig_autosw; | |
78f81cc4 | 1764 | |
56b6aeb0 HMH |
1765 | IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
1766 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ | |
1767 | "\\_SB.PCI0.VID0", /* 770e */ | |
1768 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ | |
1769 | "\\_SB.PCI0.AGP.VID", /* all others */ | |
1770 | ); /* R30, R31 */ | |
1771 | ||
1772 | IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ | |
1773 | ||
a5763f22 | 1774 | static int __init video_init(struct ibm_init_struct *iibm) |
1da177e4 | 1775 | { |
78f81cc4 BD |
1776 | int ivga; |
1777 | ||
fe08bc4b HMH |
1778 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
1779 | ||
8d376cd6 HMH |
1780 | IBM_ACPIHANDLE_INIT(vid); |
1781 | IBM_ACPIHANDLE_INIT(vid2); | |
5fba344c | 1782 | |
78f81cc4 BD |
1783 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
1784 | /* G41, assume IVGA doesn't change */ | |
1785 | vid_handle = vid2_handle; | |
1786 | ||
1787 | if (!vid_handle) | |
1788 | /* video switching not supported on R30, R31 */ | |
efa27145 | 1789 | video_supported = TPACPI_VIDEO_NONE; |
78f81cc4 BD |
1790 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
1791 | /* 570 */ | |
efa27145 | 1792 | video_supported = TPACPI_VIDEO_570; |
78f81cc4 BD |
1793 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
1794 | /* 600e/x, 770e, 770x */ | |
efa27145 | 1795 | video_supported = TPACPI_VIDEO_770; |
78f81cc4 BD |
1796 | else |
1797 | /* all others */ | |
efa27145 | 1798 | video_supported = TPACPI_VIDEO_NEW; |
1da177e4 | 1799 | |
fe08bc4b HMH |
1800 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
1801 | str_supported(video_supported != TPACPI_VIDEO_NONE), | |
1802 | video_supported); | |
1803 | ||
5fba344c | 1804 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
1da177e4 LT |
1805 | } |
1806 | ||
56b6aeb0 HMH |
1807 | static void video_exit(void) |
1808 | { | |
83f34724 HMH |
1809 | dbg_printk(TPACPI_DBG_EXIT, |
1810 | "restoring original video autoswitch mode\n"); | |
1811 | if (video_autosw_set(video_orig_autosw)) | |
1812 | printk(IBM_ERR "error while trying to restore original " | |
1813 | "video autoswitch mode\n"); | |
56b6aeb0 HMH |
1814 | } |
1815 | ||
83f34724 | 1816 | static int video_outputsw_get(void) |
1da177e4 LT |
1817 | { |
1818 | int status = 0; | |
1819 | int i; | |
1820 | ||
83f34724 HMH |
1821 | switch (video_supported) { |
1822 | case TPACPI_VIDEO_570: | |
1823 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", | |
1824 | TP_ACPI_VIDEO_570_PHSCMD)) | |
1825 | return -EIO; | |
1826 | status = i & TP_ACPI_VIDEO_570_PHSMASK; | |
1827 | break; | |
1828 | case TPACPI_VIDEO_770: | |
1829 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) | |
1830 | return -EIO; | |
1831 | if (i) | |
1832 | status |= TP_ACPI_VIDEO_S_LCD; | |
1833 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) | |
1834 | return -EIO; | |
1835 | if (i) | |
1836 | status |= TP_ACPI_VIDEO_S_CRT; | |
1837 | break; | |
1838 | case TPACPI_VIDEO_NEW: | |
1839 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || | |
1840 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) | |
1841 | return -EIO; | |
1842 | if (i) | |
1843 | status |= TP_ACPI_VIDEO_S_CRT; | |
1844 | ||
1845 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || | |
1846 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) | |
1847 | return -EIO; | |
1848 | if (i) | |
1849 | status |= TP_ACPI_VIDEO_S_LCD; | |
1850 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) | |
1851 | return -EIO; | |
1852 | if (i) | |
1853 | status |= TP_ACPI_VIDEO_S_DVI; | |
1854 | break; | |
1855 | default: | |
1856 | return -ENOSYS; | |
78f81cc4 BD |
1857 | } |
1858 | ||
1859 | return status; | |
1860 | } | |
1da177e4 | 1861 | |
83f34724 | 1862 | static int video_outputsw_set(int status) |
78f81cc4 | 1863 | { |
83f34724 HMH |
1864 | int autosw; |
1865 | int res = 0; | |
1866 | ||
1867 | switch (video_supported) { | |
1868 | case TPACPI_VIDEO_570: | |
1869 | res = acpi_evalf(NULL, NULL, | |
1870 | "\\_SB.PHS2", "vdd", | |
1871 | TP_ACPI_VIDEO_570_PHS2CMD, | |
1872 | status | TP_ACPI_VIDEO_570_PHS2SET); | |
1873 | break; | |
1874 | case TPACPI_VIDEO_770: | |
1875 | autosw = video_autosw_get(); | |
1876 | if (autosw < 0) | |
1877 | return autosw; | |
1da177e4 | 1878 | |
83f34724 HMH |
1879 | res = video_autosw_set(1); |
1880 | if (res) | |
1881 | return res; | |
1882 | res = acpi_evalf(vid_handle, NULL, | |
1883 | "ASWT", "vdd", status * 0x100, 0); | |
1884 | if (!autosw && video_autosw_set(autosw)) { | |
1885 | printk(IBM_ERR "video auto-switch left enabled due to error\n"); | |
1886 | return -EIO; | |
1887 | } | |
1888 | break; | |
1889 | case TPACPI_VIDEO_NEW: | |
1890 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && | |
1891 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); | |
1892 | break; | |
1893 | default: | |
1894 | return -ENOSYS; | |
1895 | } | |
1da177e4 | 1896 | |
83f34724 | 1897 | return (res)? 0 : -EIO; |
1da177e4 LT |
1898 | } |
1899 | ||
83f34724 | 1900 | static int video_autosw_get(void) |
78f81cc4 | 1901 | { |
83f34724 | 1902 | int autosw = 0; |
78f81cc4 | 1903 | |
83f34724 HMH |
1904 | switch (video_supported) { |
1905 | case TPACPI_VIDEO_570: | |
1906 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) | |
1907 | return -EIO; | |
1908 | break; | |
1909 | case TPACPI_VIDEO_770: | |
1910 | case TPACPI_VIDEO_NEW: | |
1911 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) | |
1912 | return -EIO; | |
1913 | break; | |
1914 | default: | |
1915 | return -ENOSYS; | |
1916 | } | |
78f81cc4 | 1917 | |
83f34724 | 1918 | return autosw & 1; |
78f81cc4 BD |
1919 | } |
1920 | ||
83f34724 | 1921 | static int video_autosw_set(int enable) |
78f81cc4 | 1922 | { |
83f34724 HMH |
1923 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
1924 | return -EIO; | |
1925 | return 0; | |
78f81cc4 BD |
1926 | } |
1927 | ||
83f34724 | 1928 | static int video_outputsw_cycle(void) |
78f81cc4 | 1929 | { |
83f34724 HMH |
1930 | int autosw = video_autosw_get(); |
1931 | int res; | |
78f81cc4 | 1932 | |
83f34724 HMH |
1933 | if (autosw < 0) |
1934 | return autosw; | |
78f81cc4 | 1935 | |
83f34724 HMH |
1936 | switch (video_supported) { |
1937 | case TPACPI_VIDEO_570: | |
1938 | res = video_autosw_set(1); | |
1939 | if (res) | |
1940 | return res; | |
1941 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); | |
1942 | break; | |
1943 | case TPACPI_VIDEO_770: | |
1944 | case TPACPI_VIDEO_NEW: | |
1945 | res = video_autosw_set(1); | |
1946 | if (res) | |
1947 | return res; | |
1948 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); | |
1949 | break; | |
1950 | default: | |
1951 | return -ENOSYS; | |
1952 | } | |
1953 | if (!autosw && video_autosw_set(autosw)) { | |
1954 | printk(IBM_ERR "video auto-switch left enabled due to error\n"); | |
1955 | return -EIO; | |
78f81cc4 BD |
1956 | } |
1957 | ||
83f34724 HMH |
1958 | return (res)? 0 : -EIO; |
1959 | } | |
1960 | ||
1961 | static int video_expand_toggle(void) | |
1962 | { | |
1963 | switch (video_supported) { | |
1964 | case TPACPI_VIDEO_570: | |
1965 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? | |
1966 | 0 : -EIO; | |
1967 | case TPACPI_VIDEO_770: | |
1968 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? | |
1969 | 0 : -EIO; | |
1970 | case TPACPI_VIDEO_NEW: | |
1971 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? | |
1972 | 0 : -EIO; | |
1973 | default: | |
1974 | return -ENOSYS; | |
1975 | } | |
1976 | /* not reached */ | |
78f81cc4 BD |
1977 | } |
1978 | ||
56b6aeb0 HMH |
1979 | static int video_read(char *p) |
1980 | { | |
83f34724 | 1981 | int status, autosw; |
56b6aeb0 HMH |
1982 | int len = 0; |
1983 | ||
83f34724 | 1984 | if (video_supported == TPACPI_VIDEO_NONE) { |
56b6aeb0 HMH |
1985 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
1986 | return len; | |
1987 | } | |
1988 | ||
83f34724 HMH |
1989 | status = video_outputsw_get(); |
1990 | if (status < 0) | |
1991 | return status; | |
1992 | ||
1993 | autosw = video_autosw_get(); | |
1994 | if (autosw < 0) | |
1995 | return autosw; | |
1996 | ||
56b6aeb0 HMH |
1997 | len += sprintf(p + len, "status:\t\tsupported\n"); |
1998 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); | |
1999 | len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1)); | |
efa27145 | 2000 | if (video_supported == TPACPI_VIDEO_NEW) |
56b6aeb0 HMH |
2001 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
2002 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); | |
2003 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); | |
2004 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); | |
efa27145 | 2005 | if (video_supported == TPACPI_VIDEO_NEW) |
56b6aeb0 HMH |
2006 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
2007 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); | |
2008 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); | |
2009 | ||
2010 | return len; | |
2011 | } | |
2012 | ||
78f81cc4 | 2013 | static int video_write(char *buf) |
1da177e4 LT |
2014 | { |
2015 | char *cmd; | |
2016 | int enable, disable, status; | |
83f34724 | 2017 | int res; |
1da177e4 | 2018 | |
83f34724 | 2019 | if (video_supported == TPACPI_VIDEO_NONE) |
78f81cc4 BD |
2020 | return -ENODEV; |
2021 | ||
83f34724 HMH |
2022 | enable = 0; |
2023 | disable = 0; | |
1da177e4 LT |
2024 | |
2025 | while ((cmd = next_cmd(&buf))) { | |
2026 | if (strlencmp(cmd, "lcd_enable") == 0) { | |
83f34724 | 2027 | enable |= TP_ACPI_VIDEO_S_LCD; |
1da177e4 | 2028 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
83f34724 | 2029 | disable |= TP_ACPI_VIDEO_S_LCD; |
1da177e4 | 2030 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
83f34724 | 2031 | enable |= TP_ACPI_VIDEO_S_CRT; |
1da177e4 | 2032 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
83f34724 | 2033 | disable |= TP_ACPI_VIDEO_S_CRT; |
efa27145 | 2034 | } else if (video_supported == TPACPI_VIDEO_NEW && |
78f81cc4 | 2035 | strlencmp(cmd, "dvi_enable") == 0) { |
83f34724 | 2036 | enable |= TP_ACPI_VIDEO_S_DVI; |
efa27145 | 2037 | } else if (video_supported == TPACPI_VIDEO_NEW && |
78f81cc4 | 2038 | strlencmp(cmd, "dvi_disable") == 0) { |
83f34724 | 2039 | disable |= TP_ACPI_VIDEO_S_DVI; |
1da177e4 | 2040 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
83f34724 HMH |
2041 | res = video_autosw_set(1); |
2042 | if (res) | |
2043 | return res; | |
1da177e4 | 2044 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
83f34724 HMH |
2045 | res = video_autosw_set(0); |
2046 | if (res) | |
2047 | return res; | |
1da177e4 | 2048 | } else if (strlencmp(cmd, "video_switch") == 0) { |
83f34724 HMH |
2049 | res = video_outputsw_cycle(); |
2050 | if (res) | |
2051 | return res; | |
1da177e4 | 2052 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
83f34724 HMH |
2053 | res = video_expand_toggle(); |
2054 | if (res) | |
2055 | return res; | |
1da177e4 LT |
2056 | } else |
2057 | return -EINVAL; | |
2058 | } | |
2059 | ||
2060 | if (enable || disable) { | |
83f34724 HMH |
2061 | status = video_outputsw_get(); |
2062 | if (status < 0) | |
2063 | return status; | |
2064 | res = video_outputsw_set((status & ~disable) | enable); | |
2065 | if (res) | |
2066 | return res; | |
1da177e4 LT |
2067 | } |
2068 | ||
2069 | return 0; | |
2070 | } | |
2071 | ||
a5763f22 HMH |
2072 | static struct ibm_struct video_driver_data = { |
2073 | .name = "video", | |
2074 | .read = video_read, | |
2075 | .write = video_write, | |
2076 | .exit = video_exit, | |
2077 | }; | |
2078 | ||
56b6aeb0 HMH |
2079 | /************************************************************************* |
2080 | * Light (thinklight) subdriver | |
2081 | */ | |
1da177e4 | 2082 | |
56b6aeb0 HMH |
2083 | IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
2084 | IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */ | |
2085 | ||
a5763f22 | 2086 | static int __init light_init(struct ibm_init_struct *iibm) |
1da177e4 | 2087 | { |
fe08bc4b HMH |
2088 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
2089 | ||
8d376cd6 HMH |
2090 | IBM_ACPIHANDLE_INIT(ledb); |
2091 | IBM_ACPIHANDLE_INIT(lght); | |
2092 | IBM_ACPIHANDLE_INIT(cmos); | |
5fba344c | 2093 | |
78f81cc4 | 2094 | /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */ |
d8fd94d9 | 2095 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
78f81cc4 | 2096 | |
d8fd94d9 | 2097 | if (tp_features.light) |
78f81cc4 BD |
2098 | /* light status not supported on |
2099 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ | |
d8fd94d9 HMH |
2100 | tp_features.light_status = |
2101 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); | |
1da177e4 | 2102 | |
fe08bc4b | 2103 | vdbg_printk(TPACPI_DBG_INIT, "light is %s\n", |
d8fd94d9 | 2104 | str_supported(tp_features.light)); |
fe08bc4b | 2105 | |
d8fd94d9 | 2106 | return (tp_features.light)? 0 : 1; |
1da177e4 LT |
2107 | } |
2108 | ||
78f81cc4 | 2109 | static int light_read(char *p) |
1da177e4 LT |
2110 | { |
2111 | int len = 0; | |
2112 | int status = 0; | |
2113 | ||
d8fd94d9 | 2114 | if (!tp_features.light) { |
78f81cc4 | 2115 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
d8fd94d9 | 2116 | } else if (!tp_features.light_status) { |
78f81cc4 BD |
2117 | len += sprintf(p + len, "status:\t\tunknown\n"); |
2118 | len += sprintf(p + len, "commands:\ton, off\n"); | |
2119 | } else { | |
1da177e4 LT |
2120 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
2121 | return -EIO; | |
2122 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); | |
78f81cc4 BD |
2123 | len += sprintf(p + len, "commands:\ton, off\n"); |
2124 | } | |
1da177e4 LT |
2125 | |
2126 | return len; | |
2127 | } | |
2128 | ||
78f81cc4 | 2129 | static int light_write(char *buf) |
1da177e4 LT |
2130 | { |
2131 | int cmos_cmd, lght_cmd; | |
2132 | char *cmd; | |
2133 | int success; | |
78f81cc4 | 2134 | |
d8fd94d9 | 2135 | if (!tp_features.light) |
78f81cc4 BD |
2136 | return -ENODEV; |
2137 | ||
1da177e4 LT |
2138 | while ((cmd = next_cmd(&buf))) { |
2139 | if (strlencmp(cmd, "on") == 0) { | |
2140 | cmos_cmd = 0x0c; | |
2141 | lght_cmd = 1; | |
2142 | } else if (strlencmp(cmd, "off") == 0) { | |
2143 | cmos_cmd = 0x0d; | |
2144 | lght_cmd = 0; | |
2145 | } else | |
2146 | return -EINVAL; | |
78f81cc4 | 2147 | |
1da177e4 | 2148 | success = cmos_handle ? |
78f81cc4 BD |
2149 | acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) : |
2150 | acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd); | |
1da177e4 LT |
2151 | if (!success) |
2152 | return -EIO; | |
2153 | } | |
2154 | ||
2155 | return 0; | |
2156 | } | |
2157 | ||
a5763f22 HMH |
2158 | static struct ibm_struct light_driver_data = { |
2159 | .name = "light", | |
2160 | .read = light_read, | |
2161 | .write = light_write, | |
2162 | }; | |
2163 | ||
56b6aeb0 HMH |
2164 | /************************************************************************* |
2165 | * Dock subdriver | |
2166 | */ | |
1da177e4 | 2167 | |
85998248 | 2168 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
56b6aeb0 HMH |
2169 | |
2170 | IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ | |
2171 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ | |
2172 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ | |
2173 | "\\_SB.PCI.ISA.SLCE", /* 570 */ | |
2174 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ | |
2175 | ||
5fba344c HMH |
2176 | /* don't list other alternatives as we install a notify handler on the 570 */ |
2177 | IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ | |
2178 | ||
1ba90e3a TR |
2179 | static const struct acpi_device_id ibm_pci_device_ids[] = { |
2180 | {PCI_ROOT_HID_STRING, 0}, | |
2181 | {"", 0}, | |
2182 | }; | |
2183 | ||
d94a7f16 HMH |
2184 | static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = { |
2185 | { | |
2186 | .notify = dock_notify, | |
2187 | .handle = &dock_handle, | |
2188 | .type = ACPI_SYSTEM_NOTIFY, | |
2189 | }, | |
2190 | { | |
996fba08 HMH |
2191 | /* THIS ONE MUST NEVER BE USED FOR DRIVER AUTOLOADING. |
2192 | * We just use it to get notifications of dock hotplug | |
2193 | * in very old thinkpads */ | |
1ba90e3a | 2194 | .hid = ibm_pci_device_ids, |
d94a7f16 HMH |
2195 | .notify = dock_notify, |
2196 | .handle = &pci_handle, | |
2197 | .type = ACPI_SYSTEM_NOTIFY, | |
2198 | }, | |
2199 | }; | |
2200 | ||
2201 | static struct ibm_struct dock_driver_data[2] = { | |
2202 | { | |
2203 | .name = "dock", | |
2204 | .read = dock_read, | |
2205 | .write = dock_write, | |
2206 | .acpi = &ibm_dock_acpidriver[0], | |
2207 | }, | |
2208 | { | |
2209 | .name = "dock", | |
2210 | .acpi = &ibm_dock_acpidriver[1], | |
2211 | }, | |
2212 | }; | |
2213 | ||
1da177e4 LT |
2214 | #define dock_docked() (_sta(dock_handle) & 1) |
2215 | ||
a5763f22 | 2216 | static int __init dock_init(struct ibm_init_struct *iibm) |
5fba344c | 2217 | { |
fe08bc4b HMH |
2218 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n"); |
2219 | ||
8d376cd6 | 2220 | IBM_ACPIHANDLE_INIT(dock); |
5fba344c | 2221 | |
fe08bc4b HMH |
2222 | vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n", |
2223 | str_supported(dock_handle != NULL)); | |
2224 | ||
5fba344c HMH |
2225 | return (dock_handle)? 0 : 1; |
2226 | } | |
2227 | ||
d94a7f16 HMH |
2228 | static int __init dock_init2(struct ibm_init_struct *iibm) |
2229 | { | |
2230 | int dock2_needed; | |
2231 | ||
2232 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver part 2\n"); | |
2233 | ||
2234 | if (dock_driver_data[0].flags.acpi_driver_registered && | |
2235 | dock_driver_data[0].flags.acpi_notify_installed) { | |
2236 | IBM_ACPIHANDLE_INIT(pci); | |
2237 | dock2_needed = (pci_handle != NULL); | |
2238 | vdbg_printk(TPACPI_DBG_INIT, | |
2239 | "dock PCI handler for the TP 570 is %s\n", | |
2240 | str_supported(dock2_needed)); | |
2241 | } else { | |
2242 | vdbg_printk(TPACPI_DBG_INIT, | |
2243 | "dock subdriver part 2 not required\n"); | |
2244 | dock2_needed = 0; | |
2245 | } | |
2246 | ||
2247 | return (dock2_needed)? 0 : 1; | |
2248 | } | |
2249 | ||
56b6aeb0 HMH |
2250 | static void dock_notify(struct ibm_struct *ibm, u32 event) |
2251 | { | |
2252 | int docked = dock_docked(); | |
1ba90e3a TR |
2253 | int pci = ibm->acpi->hid && ibm->acpi->device && |
2254 | acpi_match_device_ids(ibm->acpi->device, ibm_pci_device_ids); | |
962ce8ca | 2255 | int data; |
56b6aeb0 HMH |
2256 | |
2257 | if (event == 1 && !pci) /* 570 */ | |
962ce8ca | 2258 | data = 1; /* button */ |
56b6aeb0 | 2259 | else if (event == 1 && pci) /* 570 */ |
962ce8ca | 2260 | data = 3; /* dock */ |
56b6aeb0 | 2261 | else if (event == 3 && docked) |
962ce8ca | 2262 | data = 1; /* button */ |
56b6aeb0 | 2263 | else if (event == 3 && !docked) |
962ce8ca | 2264 | data = 2; /* undock */ |
56b6aeb0 | 2265 | else if (event == 0 && docked) |
962ce8ca | 2266 | data = 3; /* dock */ |
56b6aeb0 HMH |
2267 | else { |
2268 | printk(IBM_ERR "unknown dock event %d, status %d\n", | |
2269 | event, _sta(dock_handle)); | |
962ce8ca | 2270 | data = 0; /* unknown */ |
56b6aeb0 | 2271 | } |
14e04fb3 | 2272 | acpi_bus_generate_proc_event(ibm->acpi->device, event, data); |
962ce8ca ZR |
2273 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
2274 | ibm->acpi->device->dev.bus_id, | |
2275 | event, data); | |
56b6aeb0 HMH |
2276 | } |
2277 | ||
78f81cc4 | 2278 | static int dock_read(char *p) |
1da177e4 LT |
2279 | { |
2280 | int len = 0; | |
2281 | int docked = dock_docked(); | |
2282 | ||
2283 | if (!dock_handle) | |
2284 | len += sprintf(p + len, "status:\t\tnot supported\n"); | |
2285 | else if (!docked) | |
2286 | len += sprintf(p + len, "status:\t\tundocked\n"); | |
2287 | else { | |
2288 | len += sprintf(p + len, "status:\t\tdocked\n"); | |
2289 | len += sprintf(p + len, "commands:\tdock, undock\n"); | |
2290 | } | |
2291 | ||
2292 | return len; | |
2293 | } | |
2294 | ||
78f81cc4 | 2295 | static int dock_write(char *buf) |
1da177e4 LT |
2296 | { |
2297 | char *cmd; | |
2298 | ||
2299 | if (!dock_docked()) | |
78f81cc4 | 2300 | return -ENODEV; |
1da177e4 LT |
2301 | |
2302 | while ((cmd = next_cmd(&buf))) { | |
2303 | if (strlencmp(cmd, "undock") == 0) { | |
78f81cc4 BD |
2304 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) || |
2305 | !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1)) | |
56b6aeb0 HMH |
2306 | return -EIO; |
2307 | } else if (strlencmp(cmd, "dock") == 0) { | |
2308 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1)) | |
2309 | return -EIO; | |
2310 | } else | |
2311 | return -EINVAL; | |
1da177e4 | 2312 | } |
56b6aeb0 HMH |
2313 | |
2314 | return 0; | |
1da177e4 | 2315 | } |
56b6aeb0 | 2316 | |
85998248 | 2317 | #endif /* CONFIG_THINKPAD_ACPI_DOCK */ |
56b6aeb0 HMH |
2318 | |
2319 | /************************************************************************* | |
2320 | * Bay subdriver | |
2321 | */ | |
1da177e4 | 2322 | |
85998248 | 2323 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
56b6aeb0 HMH |
2324 | IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ |
2325 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ | |
2326 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ | |
2327 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ | |
2328 | ); /* A21e, R30, R31 */ | |
2329 | IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */ | |
2330 | "_EJ0", /* all others */ | |
2331 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ | |
2332 | IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */ | |
2333 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ | |
2334 | ); /* all others */ | |
2335 | IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ | |
2336 | "_EJ0", /* 770x */ | |
2337 | ); /* all others */ | |
2338 | ||
a5763f22 | 2339 | static int __init bay_init(struct ibm_init_struct *iibm) |
1da177e4 | 2340 | { |
fe08bc4b HMH |
2341 | vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n"); |
2342 | ||
8d376cd6 | 2343 | IBM_ACPIHANDLE_INIT(bay); |
5fba344c | 2344 | if (bay_handle) |
8d376cd6 HMH |
2345 | IBM_ACPIHANDLE_INIT(bay_ej); |
2346 | IBM_ACPIHANDLE_INIT(bay2); | |
5fba344c | 2347 | if (bay2_handle) |
8d376cd6 | 2348 | IBM_ACPIHANDLE_INIT(bay2_ej); |
5fba344c | 2349 | |
d8fd94d9 HMH |
2350 | tp_features.bay_status = bay_handle && |
2351 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); | |
2352 | tp_features.bay_status2 = bay2_handle && | |
2353 | acpi_evalf(bay2_handle, NULL, "_STA", "qv"); | |
78f81cc4 | 2354 | |
d8fd94d9 HMH |
2355 | tp_features.bay_eject = bay_handle && bay_ej_handle && |
2356 | (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental); | |
2357 | tp_features.bay_eject2 = bay2_handle && bay2_ej_handle && | |
2358 | (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental); | |
1da177e4 | 2359 | |
fe08bc4b HMH |
2360 | vdbg_printk(TPACPI_DBG_INIT, |
2361 | "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n", | |
d8fd94d9 HMH |
2362 | str_supported(tp_features.bay_status), |
2363 | str_supported(tp_features.bay_eject), | |
2364 | str_supported(tp_features.bay_status2), | |
2365 | str_supported(tp_features.bay_eject2)); | |
fe08bc4b | 2366 | |
d8fd94d9 HMH |
2367 | return (tp_features.bay_status || tp_features.bay_eject || |
2368 | tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1; | |
1da177e4 LT |
2369 | } |
2370 | ||
56b6aeb0 HMH |
2371 | static void bay_notify(struct ibm_struct *ibm, u32 event) |
2372 | { | |
14e04fb3 | 2373 | acpi_bus_generate_proc_event(ibm->acpi->device, event, 0); |
962ce8ca ZR |
2374 | acpi_bus_generate_netlink_event(ibm->acpi->device->pnp.device_class, |
2375 | ibm->acpi->device->dev.bus_id, | |
2376 | event, 0); | |
56b6aeb0 HMH |
2377 | } |
2378 | ||
78f81cc4 BD |
2379 | #define bay_occupied(b) (_sta(b##_handle) & 1) |
2380 | ||
2381 | static int bay_read(char *p) | |
1da177e4 LT |
2382 | { |
2383 | int len = 0; | |
78f81cc4 BD |
2384 | int occupied = bay_occupied(bay); |
2385 | int occupied2 = bay_occupied(bay2); | |
2386 | int eject, eject2; | |
2387 | ||
d8fd94d9 HMH |
2388 | len += sprintf(p + len, "status:\t\t%s\n", |
2389 | tp_features.bay_status ? | |
2390 | (occupied ? "occupied" : "unoccupied") : | |
2391 | "not supported"); | |
2392 | if (tp_features.bay_status2) | |
78f81cc4 BD |
2393 | len += sprintf(p + len, "status2:\t%s\n", occupied2 ? |
2394 | "occupied" : "unoccupied"); | |
2395 | ||
d8fd94d9 HMH |
2396 | eject = tp_features.bay_eject && occupied; |
2397 | eject2 = tp_features.bay_eject2 && occupied2; | |
78f81cc4 BD |
2398 | |
2399 | if (eject && eject2) | |
2400 | len += sprintf(p + len, "commands:\teject, eject2\n"); | |
2401 | else if (eject) | |
1da177e4 | 2402 | len += sprintf(p + len, "commands:\teject\n"); |
78f81cc4 BD |
2403 | else if (eject2) |
2404 | len += sprintf(p + len, "commands:\teject2\n"); | |
1da177e4 LT |
2405 | |
2406 | return len; | |
2407 | } | |
2408 | ||
78f81cc4 | 2409 | static int bay_write(char *buf) |
1da177e4 LT |
2410 | { |
2411 | char *cmd; | |
2412 | ||
d8fd94d9 | 2413 | if (!tp_features.bay_eject && !tp_features.bay_eject2) |
78f81cc4 BD |
2414 | return -ENODEV; |
2415 | ||
1da177e4 | 2416 | while ((cmd = next_cmd(&buf))) { |
d8fd94d9 | 2417 | if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) { |
78f81cc4 BD |
2418 | if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1)) |
2419 | return -EIO; | |
d8fd94d9 | 2420 | } else if (tp_features.bay_eject2 && |
78f81cc4 BD |
2421 | strlencmp(cmd, "eject2") == 0) { |
2422 | if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1)) | |
1da177e4 LT |
2423 | return -EIO; |
2424 | } else | |
2425 | return -EINVAL; | |
2426 | } | |
2427 | ||
2428 | return 0; | |
78f81cc4 | 2429 | } |
a5763f22 | 2430 | |
8d376cd6 HMH |
2431 | static struct tp_acpi_drv_struct ibm_bay_acpidriver = { |
2432 | .notify = bay_notify, | |
2433 | .handle = &bay_handle, | |
2434 | .type = ACPI_SYSTEM_NOTIFY, | |
2435 | }; | |
2436 | ||
a5763f22 HMH |
2437 | static struct ibm_struct bay_driver_data = { |
2438 | .name = "bay", | |
2439 | .read = bay_read, | |
2440 | .write = bay_write, | |
8d376cd6 | 2441 | .acpi = &ibm_bay_acpidriver, |
a5763f22 HMH |
2442 | }; |
2443 | ||
85998248 | 2444 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
1da177e4 | 2445 | |
56b6aeb0 HMH |
2446 | /************************************************************************* |
2447 | * CMOS subdriver | |
2448 | */ | |
2449 | ||
b616004c HMH |
2450 | /* sysfs cmos_command -------------------------------------------------- */ |
2451 | static ssize_t cmos_command_store(struct device *dev, | |
2452 | struct device_attribute *attr, | |
2453 | const char *buf, size_t count) | |
2454 | { | |
2455 | unsigned long cmos_cmd; | |
2456 | int res; | |
2457 | ||
2458 | if (parse_strtoul(buf, 21, &cmos_cmd)) | |
2459 | return -EINVAL; | |
2460 | ||
2461 | res = issue_thinkpad_cmos_command(cmos_cmd); | |
2462 | return (res)? res : count; | |
2463 | } | |
2464 | ||
2465 | static struct device_attribute dev_attr_cmos_command = | |
2466 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); | |
2467 | ||
2468 | /* --------------------------------------------------------------------- */ | |
2469 | ||
a5763f22 | 2470 | static int __init cmos_init(struct ibm_init_struct *iibm) |
5fba344c | 2471 | { |
b616004c HMH |
2472 | int res; |
2473 | ||
fe08bc4b HMH |
2474 | vdbg_printk(TPACPI_DBG_INIT, |
2475 | "initializing cmos commands subdriver\n"); | |
2476 | ||
8d376cd6 | 2477 | IBM_ACPIHANDLE_INIT(cmos); |
5fba344c | 2478 | |
fe08bc4b HMH |
2479 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
2480 | str_supported(cmos_handle != NULL)); | |
b616004c HMH |
2481 | |
2482 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); | |
2483 | if (res) | |
2484 | return res; | |
2485 | ||
5fba344c HMH |
2486 | return (cmos_handle)? 0 : 1; |
2487 | } | |
2488 | ||
b616004c HMH |
2489 | static void cmos_exit(void) |
2490 | { | |
2491 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); | |
2492 | } | |
2493 | ||
78f81cc4 | 2494 | static int cmos_read(char *p) |
1da177e4 LT |
2495 | { |
2496 | int len = 0; | |
2497 | ||
78f81cc4 BD |
2498 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
2499 | R30, R31, T20-22, X20-21 */ | |
1da177e4 LT |
2500 | if (!cmos_handle) |
2501 | len += sprintf(p + len, "status:\t\tnot supported\n"); | |
2502 | else { | |
2503 | len += sprintf(p + len, "status:\t\tsupported\n"); | |
78f81cc4 | 2504 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
1da177e4 LT |
2505 | } |
2506 | ||
2507 | return len; | |
2508 | } | |
2509 | ||
78f81cc4 | 2510 | static int cmos_write(char *buf) |
1da177e4 LT |
2511 | { |
2512 | char *cmd; | |
c9bea99c | 2513 | int cmos_cmd, res; |
1da177e4 LT |
2514 | |
2515 | while ((cmd = next_cmd(&buf))) { | |
78f81cc4 BD |
2516 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
2517 | cmos_cmd >= 0 && cmos_cmd <= 21) { | |
1da177e4 LT |
2518 | /* cmos_cmd set */ |
2519 | } else | |
2520 | return -EINVAL; | |
2521 | ||
c9bea99c HMH |
2522 | res = issue_thinkpad_cmos_command(cmos_cmd); |
2523 | if (res) | |
2524 | return res; | |
1da177e4 LT |
2525 | } |
2526 | ||
2527 | return 0; | |
78f81cc4 BD |
2528 | } |
2529 | ||
a5763f22 HMH |
2530 | static struct ibm_struct cmos_driver_data = { |
2531 | .name = "cmos", | |
2532 | .read = cmos_read, | |
2533 | .write = cmos_write, | |
b616004c | 2534 | .exit = cmos_exit, |
a5763f22 | 2535 | }; |
56b6aeb0 HMH |
2536 | |
2537 | /************************************************************************* | |
2538 | * LED subdriver | |
2539 | */ | |
2540 | ||
9a8e1738 | 2541 | static enum led_access_mode led_supported; |
78f81cc4 | 2542 | |
56b6aeb0 HMH |
2543 | IBM_HANDLE(led, ec, "SLED", /* 570 */ |
2544 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | |
2545 | "LED", /* all others */ | |
2546 | ); /* R30, R31 */ | |
2547 | ||
a5763f22 | 2548 | static int __init led_init(struct ibm_init_struct *iibm) |
78f81cc4 | 2549 | { |
fe08bc4b HMH |
2550 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
2551 | ||
8d376cd6 | 2552 | IBM_ACPIHANDLE_INIT(led); |
5fba344c | 2553 | |
78f81cc4 BD |
2554 | if (!led_handle) |
2555 | /* led not supported on R30, R31 */ | |
efa27145 | 2556 | led_supported = TPACPI_LED_NONE; |
78f81cc4 BD |
2557 | else if (strlencmp(led_path, "SLED") == 0) |
2558 | /* 570 */ | |
efa27145 | 2559 | led_supported = TPACPI_LED_570; |
78f81cc4 BD |
2560 | else if (strlencmp(led_path, "SYSL") == 0) |
2561 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ | |
efa27145 | 2562 | led_supported = TPACPI_LED_OLD; |
78f81cc4 BD |
2563 | else |
2564 | /* all others */ | |
efa27145 | 2565 | led_supported = TPACPI_LED_NEW; |
78f81cc4 | 2566 | |
fe08bc4b HMH |
2567 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
2568 | str_supported(led_supported), led_supported); | |
2569 | ||
5fba344c | 2570 | return (led_supported != TPACPI_LED_NONE)? 0 : 1; |
78f81cc4 BD |
2571 | } |
2572 | ||
2573 | #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking")) | |
2574 | ||
2575 | static int led_read(char *p) | |
1da177e4 LT |
2576 | { |
2577 | int len = 0; | |
2578 | ||
78f81cc4 BD |
2579 | if (!led_supported) { |
2580 | len += sprintf(p + len, "status:\t\tnot supported\n"); | |
2581 | return len; | |
2582 | } | |
2583 | len += sprintf(p + len, "status:\t\tsupported\n"); | |
2584 | ||
efa27145 | 2585 | if (led_supported == TPACPI_LED_570) { |
78f81cc4 BD |
2586 | /* 570 */ |
2587 | int i, status; | |
2588 | for (i = 0; i < 8; i++) { | |
2589 | if (!acpi_evalf(ec_handle, | |
2590 | &status, "GLED", "dd", 1 << i)) | |
2591 | return -EIO; | |
2592 | len += sprintf(p + len, "%d:\t\t%s\n", | |
2593 | i, led_status(status)); | |
2594 | } | |
2595 | } | |
2596 | ||
1da177e4 | 2597 | len += sprintf(p + len, "commands:\t" |
78f81cc4 | 2598 | "<led> on, <led> off, <led> blink (<led> is 0-7)\n"); |
1da177e4 LT |
2599 | |
2600 | return len; | |
2601 | } | |
2602 | ||
78f81cc4 BD |
2603 | /* off, on, blink */ |
2604 | static const int led_sled_arg1[] = { 0, 1, 3 }; | |
2605 | static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */ | |
2606 | static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */ | |
2607 | static const int led_led_arg1[] = { 0, 0x80, 0xc0 }; | |
2608 | ||
78f81cc4 | 2609 | static int led_write(char *buf) |
1da177e4 LT |
2610 | { |
2611 | char *cmd; | |
78f81cc4 BD |
2612 | int led, ind, ret; |
2613 | ||
2614 | if (!led_supported) | |
2615 | return -ENODEV; | |
1da177e4 LT |
2616 | |
2617 | while ((cmd = next_cmd(&buf))) { | |
78f81cc4 | 2618 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7) |
1da177e4 LT |
2619 | return -EINVAL; |
2620 | ||
78f81cc4 BD |
2621 | if (strstr(cmd, "off")) { |
2622 | ind = 0; | |
1da177e4 | 2623 | } else if (strstr(cmd, "on")) { |
78f81cc4 BD |
2624 | ind = 1; |
2625 | } else if (strstr(cmd, "blink")) { | |
2626 | ind = 2; | |
1da177e4 LT |
2627 | } else |
2628 | return -EINVAL; | |
78f81cc4 | 2629 | |
efa27145 | 2630 | if (led_supported == TPACPI_LED_570) { |
78f81cc4 BD |
2631 | /* 570 */ |
2632 | led = 1 << led; | |
1da177e4 | 2633 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
78f81cc4 | 2634 | led, led_sled_arg1[ind])) |
1da177e4 | 2635 | return -EIO; |
efa27145 | 2636 | } else if (led_supported == TPACPI_LED_OLD) { |
78f81cc4 BD |
2637 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
2638 | led = 1 << led; | |
efa27145 | 2639 | ret = ec_write(TPACPI_LED_EC_HLMS, led); |
78f81cc4 BD |
2640 | if (ret >= 0) |
2641 | ret = | |
efa27145 | 2642 | ec_write(TPACPI_LED_EC_HLBL, |
e062e034 | 2643 | led * led_exp_hlbl[ind]); |
78f81cc4 BD |
2644 | if (ret >= 0) |
2645 | ret = | |
efa27145 | 2646 | ec_write(TPACPI_LED_EC_HLCL, |
e062e034 | 2647 | led * led_exp_hlcl[ind]); |
78f81cc4 BD |
2648 | if (ret < 0) |
2649 | return ret; | |
2650 | } else { | |
2651 | /* all others */ | |
2652 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", | |
2653 | led, led_led_arg1[ind])) | |
1da177e4 | 2654 | return -EIO; |
78f81cc4 BD |
2655 | } |
2656 | } | |
2657 | ||
2658 | return 0; | |
2659 | } | |
2660 | ||
a5763f22 HMH |
2661 | static struct ibm_struct led_driver_data = { |
2662 | .name = "led", | |
2663 | .read = led_read, | |
2664 | .write = led_write, | |
2665 | }; | |
2666 | ||
56b6aeb0 HMH |
2667 | /************************************************************************* |
2668 | * Beep subdriver | |
2669 | */ | |
2670 | ||
2671 | IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ | |
2672 | ||
a5763f22 | 2673 | static int __init beep_init(struct ibm_init_struct *iibm) |
5fba344c | 2674 | { |
fe08bc4b HMH |
2675 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
2676 | ||
8d376cd6 | 2677 | IBM_ACPIHANDLE_INIT(beep); |
5fba344c | 2678 | |
fe08bc4b HMH |
2679 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
2680 | str_supported(beep_handle != NULL)); | |
2681 | ||
5fba344c HMH |
2682 | return (beep_handle)? 0 : 1; |
2683 | } | |
2684 | ||
78f81cc4 BD |
2685 | static int beep_read(char *p) |
2686 | { | |
2687 | int len = 0; | |
2688 | ||
2689 | if (!beep_handle) | |
2690 | len += sprintf(p + len, "status:\t\tnot supported\n"); | |
2691 | else { | |
2692 | len += sprintf(p + len, "status:\t\tsupported\n"); | |
2693 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); | |
2694 | } | |
2695 | ||
2696 | return len; | |
2697 | } | |
2698 | ||
2699 | static int beep_write(char *buf) | |
2700 | { | |
2701 | char *cmd; | |
2702 | int beep_cmd; | |
2703 | ||
2704 | if (!beep_handle) | |
2705 | return -ENODEV; | |
2706 | ||
2707 | while ((cmd = next_cmd(&buf))) { | |
2708 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && | |
2709 | beep_cmd >= 0 && beep_cmd <= 17) { | |
2710 | /* beep_cmd set */ | |
2711 | } else | |
2712 | return -EINVAL; | |
2713 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0)) | |
2714 | return -EIO; | |
2715 | } | |
2716 | ||
2717 | return 0; | |
2718 | } | |
2719 | ||
a5763f22 HMH |
2720 | static struct ibm_struct beep_driver_data = { |
2721 | .name = "beep", | |
2722 | .read = beep_read, | |
2723 | .write = beep_write, | |
2724 | }; | |
2725 | ||
56b6aeb0 HMH |
2726 | /************************************************************************* |
2727 | * Thermal subdriver | |
2728 | */ | |
78f81cc4 | 2729 | |
a26f878a | 2730 | static enum thermal_access_mode thermal_read_mode; |
78f81cc4 | 2731 | |
2c37aa4e HMH |
2732 | /* sysfs temp##_input -------------------------------------------------- */ |
2733 | ||
2734 | static ssize_t thermal_temp_input_show(struct device *dev, | |
2735 | struct device_attribute *attr, | |
2736 | char *buf) | |
2737 | { | |
2738 | struct sensor_device_attribute *sensor_attr = | |
2739 | to_sensor_dev_attr(attr); | |
2740 | int idx = sensor_attr->index; | |
2741 | s32 value; | |
2742 | int res; | |
2743 | ||
2744 | res = thermal_get_sensor(idx, &value); | |
2745 | if (res) | |
2746 | return res; | |
2747 | if (value == TP_EC_THERMAL_TMP_NA * 1000) | |
2748 | return -ENXIO; | |
2749 | ||
2750 | return snprintf(buf, PAGE_SIZE, "%d\n", value); | |
2751 | } | |
2752 | ||
2753 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ | |
2754 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB) | |
2755 | ||
2756 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { | |
2757 | THERMAL_SENSOR_ATTR_TEMP(1, 0), | |
2758 | THERMAL_SENSOR_ATTR_TEMP(2, 1), | |
2759 | THERMAL_SENSOR_ATTR_TEMP(3, 2), | |
2760 | THERMAL_SENSOR_ATTR_TEMP(4, 3), | |
2761 | THERMAL_SENSOR_ATTR_TEMP(5, 4), | |
2762 | THERMAL_SENSOR_ATTR_TEMP(6, 5), | |
2763 | THERMAL_SENSOR_ATTR_TEMP(7, 6), | |
2764 | THERMAL_SENSOR_ATTR_TEMP(8, 7), | |
2765 | THERMAL_SENSOR_ATTR_TEMP(9, 8), | |
2766 | THERMAL_SENSOR_ATTR_TEMP(10, 9), | |
2767 | THERMAL_SENSOR_ATTR_TEMP(11, 10), | |
2768 | THERMAL_SENSOR_ATTR_TEMP(12, 11), | |
2769 | THERMAL_SENSOR_ATTR_TEMP(13, 12), | |
2770 | THERMAL_SENSOR_ATTR_TEMP(14, 13), | |
2771 | THERMAL_SENSOR_ATTR_TEMP(15, 14), | |
2772 | THERMAL_SENSOR_ATTR_TEMP(16, 15), | |
2773 | }; | |
2774 | ||
2775 | #define THERMAL_ATTRS(X) \ | |
2776 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr | |
2777 | ||
2778 | static struct attribute *thermal_temp_input_attr[] = { | |
2779 | THERMAL_ATTRS(8), | |
2780 | THERMAL_ATTRS(9), | |
2781 | THERMAL_ATTRS(10), | |
2782 | THERMAL_ATTRS(11), | |
2783 | THERMAL_ATTRS(12), | |
2784 | THERMAL_ATTRS(13), | |
2785 | THERMAL_ATTRS(14), | |
2786 | THERMAL_ATTRS(15), | |
2787 | THERMAL_ATTRS(0), | |
2788 | THERMAL_ATTRS(1), | |
2789 | THERMAL_ATTRS(2), | |
2790 | THERMAL_ATTRS(3), | |
2791 | THERMAL_ATTRS(4), | |
2792 | THERMAL_ATTRS(5), | |
2793 | THERMAL_ATTRS(6), | |
2794 | THERMAL_ATTRS(7), | |
2795 | NULL | |
2796 | }; | |
2797 | ||
2798 | static const struct attribute_group thermal_temp_input16_group = { | |
2799 | .attrs = thermal_temp_input_attr | |
2800 | }; | |
2801 | ||
2802 | static const struct attribute_group thermal_temp_input8_group = { | |
2803 | .attrs = &thermal_temp_input_attr[8] | |
2804 | }; | |
2805 | ||
2806 | #undef THERMAL_SENSOR_ATTR_TEMP | |
2807 | #undef THERMAL_ATTRS | |
2808 | ||
2809 | /* --------------------------------------------------------------------- */ | |
2810 | ||
a5763f22 | 2811 | static int __init thermal_init(struct ibm_init_struct *iibm) |
78f81cc4 | 2812 | { |
60eb0b35 HMH |
2813 | u8 t, ta1, ta2; |
2814 | int i; | |
5fba344c | 2815 | int acpi_tmp7; |
2c37aa4e | 2816 | int res; |
5fba344c | 2817 | |
fe08bc4b HMH |
2818 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
2819 | ||
5fba344c | 2820 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
60eb0b35 | 2821 | |
3d6f99ca | 2822 | if (thinkpad_id.ec_model) { |
60eb0b35 HMH |
2823 | /* |
2824 | * Direct EC access mode: sensors at registers | |
2825 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for | |
2826 | * non-implemented, thermal sensors return 0x80 when | |
2827 | * not available | |
2828 | */ | |
78f81cc4 | 2829 | |
60eb0b35 HMH |
2830 | ta1 = ta2 = 0; |
2831 | for (i = 0; i < 8; i++) { | |
04cc862c | 2832 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
60eb0b35 HMH |
2833 | ta1 |= t; |
2834 | } else { | |
2835 | ta1 = 0; | |
2836 | break; | |
2837 | } | |
04cc862c | 2838 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
60eb0b35 HMH |
2839 | ta2 |= t; |
2840 | } else { | |
2841 | ta1 = 0; | |
2842 | break; | |
2843 | } | |
2844 | } | |
2845 | if (ta1 == 0) { | |
2846 | /* This is sheer paranoia, but we handle it anyway */ | |
2847 | if (acpi_tmp7) { | |
2848 | printk(IBM_ERR | |
2849 | "ThinkPad ACPI EC access misbehaving, " | |
2850 | "falling back to ACPI TMPx access mode\n"); | |
efa27145 | 2851 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
60eb0b35 HMH |
2852 | } else { |
2853 | printk(IBM_ERR | |
2854 | "ThinkPad ACPI EC access misbehaving, " | |
2855 | "disabling thermal sensors access\n"); | |
efa27145 | 2856 | thermal_read_mode = TPACPI_THERMAL_NONE; |
60eb0b35 HMH |
2857 | } |
2858 | } else { | |
2859 | thermal_read_mode = | |
2860 | (ta2 != 0) ? | |
efa27145 | 2861 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
60eb0b35 HMH |
2862 | } |
2863 | } else if (acpi_tmp7) { | |
a26f878a HMH |
2864 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
2865 | /* 600e/x, 770e, 770x */ | |
efa27145 | 2866 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
a26f878a HMH |
2867 | } else { |
2868 | /* Standard ACPI TMPx access, max 8 sensors */ | |
efa27145 | 2869 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
a26f878a HMH |
2870 | } |
2871 | } else { | |
2872 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ | |
efa27145 | 2873 | thermal_read_mode = TPACPI_THERMAL_NONE; |
a26f878a | 2874 | } |
78f81cc4 | 2875 | |
fe08bc4b HMH |
2876 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
2877 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), | |
2878 | thermal_read_mode); | |
2879 | ||
2c37aa4e HMH |
2880 | switch(thermal_read_mode) { |
2881 | case TPACPI_THERMAL_TPEC_16: | |
7fd40029 | 2882 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
2c37aa4e HMH |
2883 | &thermal_temp_input16_group); |
2884 | if (res) | |
2885 | return res; | |
2886 | break; | |
2887 | case TPACPI_THERMAL_TPEC_8: | |
2888 | case TPACPI_THERMAL_ACPI_TMP07: | |
2889 | case TPACPI_THERMAL_ACPI_UPDT: | |
7fd40029 | 2890 | res = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
2c37aa4e HMH |
2891 | &thermal_temp_input8_group); |
2892 | if (res) | |
2893 | return res; | |
2894 | break; | |
2895 | case TPACPI_THERMAL_NONE: | |
2896 | default: | |
2897 | return 1; | |
2898 | } | |
2899 | ||
2900 | return 0; | |
2901 | } | |
2902 | ||
2903 | static void thermal_exit(void) | |
2904 | { | |
2905 | switch(thermal_read_mode) { | |
2906 | case TPACPI_THERMAL_TPEC_16: | |
7fd40029 | 2907 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
2c37aa4e HMH |
2908 | &thermal_temp_input16_group); |
2909 | break; | |
2910 | case TPACPI_THERMAL_TPEC_8: | |
2911 | case TPACPI_THERMAL_ACPI_TMP07: | |
2912 | case TPACPI_THERMAL_ACPI_UPDT: | |
7fd40029 | 2913 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, |
2c37aa4e HMH |
2914 | &thermal_temp_input16_group); |
2915 | break; | |
2916 | case TPACPI_THERMAL_NONE: | |
2917 | default: | |
2918 | break; | |
2919 | } | |
78f81cc4 BD |
2920 | } |
2921 | ||
04cc862c HMH |
2922 | /* idx is zero-based */ |
2923 | static int thermal_get_sensor(int idx, s32 *value) | |
78f81cc4 | 2924 | { |
04cc862c | 2925 | int t; |
60eb0b35 | 2926 | s8 tmp; |
04cc862c | 2927 | char tmpi[5]; |
78f81cc4 | 2928 | |
04cc862c | 2929 | t = TP_EC_THERMAL_TMP0; |
78f81cc4 | 2930 | |
a26f878a | 2931 | switch (thermal_read_mode) { |
efa27145 HMH |
2932 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
2933 | case TPACPI_THERMAL_TPEC_16: | |
04cc862c HMH |
2934 | if (idx >= 8 && idx <= 15) { |
2935 | t = TP_EC_THERMAL_TMP8; | |
2936 | idx -= 8; | |
60eb0b35 HMH |
2937 | } |
2938 | /* fallthrough */ | |
2939 | #endif | |
efa27145 | 2940 | case TPACPI_THERMAL_TPEC_8: |
04cc862c HMH |
2941 | if (idx <= 7) { |
2942 | if (!acpi_ec_read(t + idx, &tmp)) | |
78f81cc4 | 2943 | return -EIO; |
04cc862c HMH |
2944 | *value = tmp * 1000; |
2945 | return 0; | |
60eb0b35 | 2946 | } |
04cc862c | 2947 | break; |
78f81cc4 | 2948 | |
efa27145 | 2949 | case TPACPI_THERMAL_ACPI_UPDT: |
04cc862c HMH |
2950 | if (idx <= 7) { |
2951 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); | |
2952 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) | |
2953 | return -EIO; | |
78f81cc4 BD |
2954 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
2955 | return -EIO; | |
04cc862c HMH |
2956 | *value = (t - 2732) * 100; |
2957 | return 0; | |
78f81cc4 | 2958 | } |
04cc862c | 2959 | break; |
78f81cc4 | 2960 | |
efa27145 | 2961 | case TPACPI_THERMAL_ACPI_TMP07: |
04cc862c HMH |
2962 | if (idx <= 7) { |
2963 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); | |
78f81cc4 BD |
2964 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
2965 | return -EIO; | |
a8fba3da HMH |
2966 | if (t > 127 || t < -127) |
2967 | t = TP_EC_THERMAL_TMP_NA; | |
04cc862c HMH |
2968 | *value = t * 1000; |
2969 | return 0; | |
78f81cc4 | 2970 | } |
04cc862c | 2971 | break; |
78f81cc4 | 2972 | |
efa27145 | 2973 | case TPACPI_THERMAL_NONE: |
a26f878a | 2974 | default: |
04cc862c HMH |
2975 | return -ENOSYS; |
2976 | } | |
2977 | ||
2978 | return -EINVAL; | |
2979 | } | |
2980 | ||
2981 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) | |
2982 | { | |
2983 | int res, i; | |
2984 | int n; | |
2985 | ||
2986 | n = 8; | |
2987 | i = 0; | |
2988 | ||
2989 | if (!s) | |
2990 | return -EINVAL; | |
2991 | ||
2992 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) | |
2993 | n = 16; | |
2994 | ||
2995 | for(i = 0 ; i < n; i++) { | |
2996 | res = thermal_get_sensor(i, &s->temp[i]); | |
2997 | if (res) | |
2998 | return res; | |
78f81cc4 | 2999 | } |
04cc862c HMH |
3000 | |
3001 | return n; | |
a26f878a HMH |
3002 | } |
3003 | ||
3004 | static int thermal_read(char *p) | |
3005 | { | |
3006 | int len = 0; | |
3007 | int n, i; | |
3008 | struct ibm_thermal_sensors_struct t; | |
3009 | ||
3010 | n = thermal_get_sensors(&t); | |
3011 | if (unlikely(n < 0)) | |
3012 | return n; | |
3013 | ||
3014 | len += sprintf(p + len, "temperatures:\t"); | |
3015 | ||
3016 | if (n > 0) { | |
3017 | for (i = 0; i < (n - 1); i++) | |
3018 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); | |
3019 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); | |
3020 | } else | |
3021 | len += sprintf(p + len, "not supported\n"); | |
78f81cc4 BD |
3022 | |
3023 | return len; | |
3024 | } | |
3025 | ||
a5763f22 HMH |
3026 | static struct ibm_struct thermal_driver_data = { |
3027 | .name = "thermal", | |
3028 | .read = thermal_read, | |
2c37aa4e | 3029 | .exit = thermal_exit, |
a5763f22 HMH |
3030 | }; |
3031 | ||
56b6aeb0 HMH |
3032 | /************************************************************************* |
3033 | * EC Dump subdriver | |
3034 | */ | |
3035 | ||
78f81cc4 BD |
3036 | static u8 ecdump_regs[256]; |
3037 | ||
3038 | static int ecdump_read(char *p) | |
3039 | { | |
3040 | int len = 0; | |
3041 | int i, j; | |
3042 | u8 v; | |
3043 | ||
3044 | len += sprintf(p + len, "EC " | |
3045 | " +00 +01 +02 +03 +04 +05 +06 +07" | |
3046 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); | |
3047 | for (i = 0; i < 256; i += 16) { | |
3048 | len += sprintf(p + len, "EC 0x%02x:", i); | |
3049 | for (j = 0; j < 16; j++) { | |
3050 | if (!acpi_ec_read(i + j, &v)) | |
3051 | break; | |
3052 | if (v != ecdump_regs[i + j]) | |
3053 | len += sprintf(p + len, " *%02x", v); | |
3054 | else | |
3055 | len += sprintf(p + len, " %02x", v); | |
3056 | ecdump_regs[i + j] = v; | |
3057 | } | |
3058 | len += sprintf(p + len, "\n"); | |
3059 | if (j != 16) | |
3060 | break; | |
3061 | } | |
3062 | ||
3063 | /* These are way too dangerous to advertise openly... */ | |
3064 | #if 0 | |
3065 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" | |
3066 | " (<offset> is 00-ff, <value> is 00-ff)\n"); | |
3067 | len += sprintf(p + len, "commands:\t0x<offset> <value> " | |
3068 | " (<offset> is 00-ff, <value> is 0-255)\n"); | |
3069 | #endif | |
3070 | return len; | |
3071 | } | |
3072 | ||
3073 | static int ecdump_write(char *buf) | |
3074 | { | |
3075 | char *cmd; | |
3076 | int i, v; | |
3077 | ||
3078 | while ((cmd = next_cmd(&buf))) { | |
3079 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { | |
3080 | /* i and v set */ | |
3081 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { | |
3082 | /* i and v set */ | |
3083 | } else | |
3084 | return -EINVAL; | |
3085 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { | |
3086 | if (!acpi_ec_write(i, v)) | |
1da177e4 LT |
3087 | return -EIO; |
3088 | } else | |
3089 | return -EINVAL; | |
3090 | } | |
3091 | ||
3092 | return 0; | |
78f81cc4 BD |
3093 | } |
3094 | ||
a5763f22 HMH |
3095 | static struct ibm_struct ecdump_driver_data = { |
3096 | .name = "ecdump", | |
3097 | .read = ecdump_read, | |
3098 | .write = ecdump_write, | |
92641177 | 3099 | .flags.experimental = 1, |
a5763f22 HMH |
3100 | }; |
3101 | ||
56b6aeb0 HMH |
3102 | /************************************************************************* |
3103 | * Backlight/brightness subdriver | |
3104 | */ | |
3105 | ||
94954cc6 | 3106 | static struct backlight_device *ibm_backlight_device; |
56b6aeb0 HMH |
3107 | |
3108 | static struct backlight_ops ibm_backlight_data = { | |
3109 | .get_brightness = brightness_get, | |
3110 | .update_status = brightness_update_status, | |
3111 | }; | |
3112 | ||
f432255e HMH |
3113 | static struct mutex brightness_mutex; |
3114 | ||
a5763f22 | 3115 | static int __init brightness_init(struct ibm_init_struct *iibm) |
56b6aeb0 HMH |
3116 | { |
3117 | int b; | |
3118 | ||
fe08bc4b HMH |
3119 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
3120 | ||
f432255e HMH |
3121 | mutex_init(&brightness_mutex); |
3122 | ||
24d3b774 HMH |
3123 | if (!brightness_mode) { |
3124 | if (thinkpad_id.vendor == PCI_VENDOR_ID_LENOVO) | |
3125 | brightness_mode = 2; | |
3126 | else | |
3127 | brightness_mode = 3; | |
3128 | ||
3129 | dbg_printk(TPACPI_DBG_INIT, "selected brightness_mode=%d\n", | |
3130 | brightness_mode); | |
3131 | } | |
3132 | ||
3133 | if (brightness_mode > 3) | |
3134 | return -EINVAL; | |
3135 | ||
56b6aeb0 HMH |
3136 | b = brightness_get(NULL); |
3137 | if (b < 0) | |
24d3b774 | 3138 | return 1; |
56b6aeb0 | 3139 | |
7d5a015e HMH |
3140 | ibm_backlight_device = backlight_device_register( |
3141 | TPACPI_BACKLIGHT_DEV_NAME, NULL, NULL, | |
3142 | &ibm_backlight_data); | |
56b6aeb0 HMH |
3143 | if (IS_ERR(ibm_backlight_device)) { |
3144 | printk(IBM_ERR "Could not register backlight device\n"); | |
3145 | return PTR_ERR(ibm_backlight_device); | |
3146 | } | |
fe08bc4b | 3147 | vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n"); |
56b6aeb0 HMH |
3148 | |
3149 | ibm_backlight_device->props.max_brightness = 7; | |
3150 | ibm_backlight_device->props.brightness = b; | |
3151 | backlight_update_status(ibm_backlight_device); | |
3152 | ||
3153 | return 0; | |
3154 | } | |
3155 | ||
3156 | static void brightness_exit(void) | |
3157 | { | |
3158 | if (ibm_backlight_device) { | |
fe08bc4b HMH |
3159 | vdbg_printk(TPACPI_DBG_EXIT, |
3160 | "calling backlight_device_unregister()\n"); | |
56b6aeb0 HMH |
3161 | backlight_device_unregister(ibm_backlight_device); |
3162 | ibm_backlight_device = NULL; | |
3163 | } | |
3164 | } | |
3165 | ||
3166 | static int brightness_update_status(struct backlight_device *bd) | |
3167 | { | |
3168 | return brightness_set( | |
3169 | (bd->props.fb_blank == FB_BLANK_UNBLANK && | |
3170 | bd->props.power == FB_BLANK_UNBLANK) ? | |
3171 | bd->props.brightness : 0); | |
3172 | } | |
3173 | ||
24d3b774 HMH |
3174 | /* |
3175 | * ThinkPads can read brightness from two places: EC 0x31, or | |
3176 | * CMOS NVRAM byte 0x5E, bits 0-3. | |
3177 | */ | |
8acb0250 HM |
3178 | static int brightness_get(struct backlight_device *bd) |
3179 | { | |
24d3b774 | 3180 | u8 lec = 0, lcmos = 0, level = 0; |
8acb0250 | 3181 | |
24d3b774 HMH |
3182 | if (brightness_mode & 1) { |
3183 | if (!acpi_ec_read(brightness_offset, &lec)) | |
3184 | return -EIO; | |
3185 | lec &= 7; | |
3186 | level = lec; | |
3187 | }; | |
3188 | if (brightness_mode & 2) { | |
3189 | lcmos = (nvram_read_byte(TP_NVRAM_ADDR_BRIGHTNESS) | |
3190 | & TP_NVRAM_MASK_LEVEL_BRIGHTNESS) | |
3191 | >> TP_NVRAM_POS_LEVEL_BRIGHTNESS; | |
3192 | level = lcmos; | |
3193 | } | |
3194 | ||
3195 | if (brightness_mode == 3 && lec != lcmos) { | |
3196 | printk(IBM_ERR | |
3197 | "CMOS NVRAM (%u) and EC (%u) do not agree " | |
3198 | "on display brightness level\n", | |
3199 | (unsigned int) lcmos, | |
3200 | (unsigned int) lec); | |
3201 | return -EIO; | |
3202 | } | |
fb87a811 | 3203 | |
8d297264 | 3204 | return level; |
8acb0250 HM |
3205 | } |
3206 | ||
8acb0250 | 3207 | static int brightness_set(int value) |
1da177e4 | 3208 | { |
f432255e HMH |
3209 | int cmos_cmd, inc, i, res; |
3210 | int current_value; | |
8acb0250 | 3211 | |
24d3b774 HMH |
3212 | if (value > 7) |
3213 | return -EINVAL; | |
8acb0250 | 3214 | |
f432255e HMH |
3215 | res = mutex_lock_interruptible(&brightness_mutex); |
3216 | if (res < 0) | |
3217 | return res; | |
3218 | ||
3219 | current_value = brightness_get(NULL); | |
3220 | if (current_value < 0) { | |
3221 | res = current_value; | |
3222 | goto errout; | |
3223 | } | |
3224 | ||
24d3b774 HMH |
3225 | cmos_cmd = value > current_value ? |
3226 | TP_CMOS_BRIGHTNESS_UP : | |
3227 | TP_CMOS_BRIGHTNESS_DOWN; | |
8acb0250 | 3228 | inc = value > current_value ? 1 : -1; |
24d3b774 | 3229 | |
f432255e | 3230 | res = 0; |
8acb0250 | 3231 | for (i = current_value; i != value; i += inc) { |
24d3b774 | 3232 | if ((brightness_mode & 2) && |
f432255e HMH |
3233 | issue_thinkpad_cmos_command(cmos_cmd)) { |
3234 | res = -EIO; | |
3235 | goto errout; | |
3236 | } | |
24d3b774 | 3237 | if ((brightness_mode & 1) && |
f432255e HMH |
3238 | !acpi_ec_write(brightness_offset, i + inc)) { |
3239 | res = -EIO; | |
3240 | goto errout;; | |
3241 | } | |
8acb0250 HM |
3242 | } |
3243 | ||
f432255e HMH |
3244 | errout: |
3245 | mutex_unlock(&brightness_mutex); | |
3246 | return res; | |
8acb0250 HM |
3247 | } |
3248 | ||
56b6aeb0 HMH |
3249 | static int brightness_read(char *p) |
3250 | { | |
3251 | int len = 0; | |
3252 | int level; | |
3253 | ||
3254 | if ((level = brightness_get(NULL)) < 0) { | |
3255 | len += sprintf(p + len, "level:\t\tunreadable\n"); | |
3256 | } else { | |
3257 | len += sprintf(p + len, "level:\t\t%d\n", level & 0x7); | |
3258 | len += sprintf(p + len, "commands:\tup, down\n"); | |
3259 | len += sprintf(p + len, "commands:\tlevel <level>" | |
3260 | " (<level> is 0-7)\n"); | |
3261 | } | |
3262 | ||
3263 | return len; | |
3264 | } | |
3265 | ||
8acb0250 HM |
3266 | static int brightness_write(char *buf) |
3267 | { | |
3268 | int level; | |
78f81cc4 | 3269 | int new_level; |
1da177e4 | 3270 | char *cmd; |
1da177e4 LT |
3271 | |
3272 | while ((cmd = next_cmd(&buf))) { | |
8acb0250 HM |
3273 | if ((level = brightness_get(NULL)) < 0) |
3274 | return level; | |
78f81cc4 BD |
3275 | level &= 7; |
3276 | ||
3277 | if (strlencmp(cmd, "up") == 0) { | |
3278 | new_level = level == 7 ? 7 : level + 1; | |
3279 | } else if (strlencmp(cmd, "down") == 0) { | |
3280 | new_level = level == 0 ? 0 : level - 1; | |
3281 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && | |
3282 | new_level >= 0 && new_level <= 7) { | |
3283 | /* new_level set */ | |
3284 | } else | |
3285 | return -EINVAL; | |
3286 | ||
8acb0250 | 3287 | brightness_set(new_level); |
78f81cc4 BD |
3288 | } |
3289 | ||
3290 | return 0; | |
3291 | } | |
3292 | ||
a5763f22 HMH |
3293 | static struct ibm_struct brightness_driver_data = { |
3294 | .name = "brightness", | |
3295 | .read = brightness_read, | |
3296 | .write = brightness_write, | |
3297 | .exit = brightness_exit, | |
3298 | }; | |
3299 | ||
56b6aeb0 HMH |
3300 | /************************************************************************* |
3301 | * Volume subdriver | |
3302 | */ | |
fb87a811 | 3303 | |
78f81cc4 BD |
3304 | static int volume_read(char *p) |
3305 | { | |
3306 | int len = 0; | |
3307 | u8 level; | |
3308 | ||
3309 | if (!acpi_ec_read(volume_offset, &level)) { | |
3310 | len += sprintf(p + len, "level:\t\tunreadable\n"); | |
3311 | } else { | |
3312 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); | |
3313 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); | |
3314 | len += sprintf(p + len, "commands:\tup, down, mute\n"); | |
3315 | len += sprintf(p + len, "commands:\tlevel <level>" | |
3316 | " (<level> is 0-15)\n"); | |
3317 | } | |
3318 | ||
3319 | return len; | |
3320 | } | |
3321 | ||
78f81cc4 BD |
3322 | static int volume_write(char *buf) |
3323 | { | |
3324 | int cmos_cmd, inc, i; | |
3325 | u8 level, mute; | |
3326 | int new_level, new_mute; | |
3327 | char *cmd; | |
3328 | ||
3329 | while ((cmd = next_cmd(&buf))) { | |
3330 | if (!acpi_ec_read(volume_offset, &level)) | |
3331 | return -EIO; | |
3332 | new_mute = mute = level & 0x40; | |
3333 | new_level = level = level & 0xf; | |
3334 | ||
3335 | if (strlencmp(cmd, "up") == 0) { | |
3336 | if (mute) | |
3337 | new_mute = 0; | |
3338 | else | |
3339 | new_level = level == 15 ? 15 : level + 1; | |
3340 | } else if (strlencmp(cmd, "down") == 0) { | |
3341 | if (mute) | |
3342 | new_mute = 0; | |
3343 | else | |
3344 | new_level = level == 0 ? 0 : level - 1; | |
3345 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && | |
3346 | new_level >= 0 && new_level <= 15) { | |
3347 | /* new_level set */ | |
3348 | } else if (strlencmp(cmd, "mute") == 0) { | |
3349 | new_mute = 0x40; | |
1da177e4 LT |
3350 | } else |
3351 | return -EINVAL; | |
3352 | ||
78f81cc4 | 3353 | if (new_level != level) { /* mute doesn't change */ |
56b6aeb0 | 3354 | cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
78f81cc4 BD |
3355 | inc = new_level > level ? 1 : -1; |
3356 | ||
c9bea99c | 3357 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || |
78f81cc4 BD |
3358 | !acpi_ec_write(volume_offset, level))) |
3359 | return -EIO; | |
3360 | ||
3361 | for (i = level; i != new_level; i += inc) | |
c9bea99c | 3362 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
78f81cc4 BD |
3363 | !acpi_ec_write(volume_offset, i + inc)) |
3364 | return -EIO; | |
3365 | ||
c9bea99c | 3366 | if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
78f81cc4 BD |
3367 | !acpi_ec_write(volume_offset, |
3368 | new_level + mute))) | |
3369 | return -EIO; | |
3370 | } | |
3371 | ||
3372 | if (new_mute != mute) { /* level doesn't change */ | |
56b6aeb0 | 3373 | cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
78f81cc4 | 3374 | |
c9bea99c | 3375 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
78f81cc4 BD |
3376 | !acpi_ec_write(volume_offset, level + new_mute)) |
3377 | return -EIO; | |
3378 | } | |
3379 | } | |
3380 | ||
3381 | return 0; | |
3382 | } | |
3383 | ||
a5763f22 HMH |
3384 | static struct ibm_struct volume_driver_data = { |
3385 | .name = "volume", | |
3386 | .read = volume_read, | |
3387 | .write = volume_write, | |
3388 | }; | |
56b6aeb0 HMH |
3389 | |
3390 | /************************************************************************* | |
3391 | * Fan subdriver | |
3392 | */ | |
3393 | ||
3394 | /* | |
3395 | * FAN ACCESS MODES | |
3396 | * | |
efa27145 | 3397 | * TPACPI_FAN_RD_ACPI_GFAN: |
56b6aeb0 HMH |
3398 | * ACPI GFAN method: returns fan level |
3399 | * | |
efa27145 | 3400 | * see TPACPI_FAN_WR_ACPI_SFAN |
f51d1a39 | 3401 | * EC 0x2f (HFSP) not available if GFAN exists |
56b6aeb0 | 3402 | * |
efa27145 | 3403 | * TPACPI_FAN_WR_ACPI_SFAN: |
56b6aeb0 HMH |
3404 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
3405 | * | |
f51d1a39 HMH |
3406 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
3407 | * it for writing. | |
56b6aeb0 | 3408 | * |
efa27145 | 3409 | * TPACPI_FAN_WR_TPEC: |
f51d1a39 HMH |
3410 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
3411 | * Supported on almost all ThinkPads | |
56b6aeb0 HMH |
3412 | * |
3413 | * Fan speed changes of any sort (including those caused by the | |
3414 | * disengaged mode) are usually done slowly by the firmware as the | |
3415 | * maximum ammount of fan duty cycle change per second seems to be | |
3416 | * limited. | |
3417 | * | |
3418 | * Reading is not available if GFAN exists. | |
3419 | * Writing is not available if SFAN exists. | |
3420 | * | |
3421 | * Bits | |
3422 | * 7 automatic mode engaged; | |
3423 | * (default operation mode of the ThinkPad) | |
3424 | * fan level is ignored in this mode. | |
f51d1a39 | 3425 | * 6 full speed mode (takes precedence over bit 7); |
56b6aeb0 | 3426 | * not available on all thinkpads. May disable |
f51d1a39 HMH |
3427 | * the tachometer while the fan controller ramps up |
3428 | * the speed (which can take up to a few *minutes*). | |
3429 | * Speeds up fan to 100% duty-cycle, which is far above | |
3430 | * the standard RPM levels. It is not impossible that | |
3431 | * it could cause hardware damage. | |
56b6aeb0 HMH |
3432 | * 5-3 unused in some models. Extra bits for fan level |
3433 | * in others, but still useless as all values above | |
3434 | * 7 map to the same speed as level 7 in these models. | |
3435 | * 2-0 fan level (0..7 usually) | |
3436 | * 0x00 = stop | |
3437 | * 0x07 = max (set when temperatures critical) | |
3438 | * Some ThinkPads may have other levels, see | |
efa27145 | 3439 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
56b6aeb0 HMH |
3440 | * |
3441 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at | |
3442 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT | |
3443 | * does so, its initial value is meaningless (0x07). | |
3444 | * | |
3445 | * For firmware bugs, refer to: | |
3446 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues | |
3447 | * | |
3448 | * ---- | |
3449 | * | |
3450 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): | |
3451 | * Main fan tachometer reading (in RPM) | |
3452 | * | |
3453 | * This register is present on all ThinkPads with a new-style EC, and | |
3454 | * it is known not to be present on the A21m/e, and T22, as there is | |
3455 | * something else in offset 0x84 according to the ACPI DSDT. Other | |
3456 | * ThinkPads from this same time period (and earlier) probably lack the | |
3457 | * tachometer as well. | |
3458 | * | |
3459 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare | |
3460 | * was never fixed by IBM to report the EC firmware version string | |
3461 | * probably support the tachometer (like the early X models), so | |
3462 | * detecting it is quite hard. We need more data to know for sure. | |
3463 | * | |
3464 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings | |
3465 | * might result. | |
3466 | * | |
f51d1a39 HMH |
3467 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
3468 | * mode. | |
56b6aeb0 HMH |
3469 | * |
3470 | * For firmware bugs, refer to: | |
3471 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues | |
3472 | * | |
efa27145 | 3473 | * TPACPI_FAN_WR_ACPI_FANS: |
56b6aeb0 HMH |
3474 | * ThinkPad X31, X40, X41. Not available in the X60. |
3475 | * | |
3476 | * FANS ACPI handle: takes three arguments: low speed, medium speed, | |
3477 | * high speed. ACPI DSDT seems to map these three speeds to levels | |
3478 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH | |
3479 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") | |
3480 | * | |
3481 | * The speeds are stored on handles | |
3482 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). | |
3483 | * | |
3484 | * There are three default speed sets, acessible as handles: | |
3485 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H | |
3486 | * | |
3487 | * ACPI DSDT switches which set is in use depending on various | |
3488 | * factors. | |
3489 | * | |
efa27145 | 3490 | * TPACPI_FAN_WR_TPEC is also available and should be used to |
56b6aeb0 HMH |
3491 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
3492 | * but the ACPI tables just mention level 7. | |
3493 | */ | |
3494 | ||
69ba91cb HMH |
3495 | static enum fan_status_access_mode fan_status_access_mode; |
3496 | static enum fan_control_access_mode fan_control_access_mode; | |
3497 | static enum fan_control_commands fan_control_commands; | |
78f81cc4 | 3498 | |
778b4d74 | 3499 | static u8 fan_control_initial_status; |
fe98a52c | 3500 | static u8 fan_control_desired_level; |
778b4d74 | 3501 | |
25c68a33 | 3502 | static void fan_watchdog_fire(struct work_struct *ignored); |
16663a87 | 3503 | static int fan_watchdog_maxinterval; |
25c68a33 | 3504 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
16663a87 | 3505 | |
56b6aeb0 HMH |
3506 | IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
3507 | IBM_HANDLE(gfan, ec, "GFAN", /* 570 */ | |
3508 | "\\FSPD", /* 600e/x, 770e, 770x */ | |
3509 | ); /* all others */ | |
3510 | IBM_HANDLE(sfan, ec, "SFAN", /* 570 */ | |
3511 | "JFNS", /* 770x-JL */ | |
3512 | ); /* all others */ | |
3513 | ||
fe98a52c HMH |
3514 | /* |
3515 | * SYSFS fan layout: hwmon compatible (device) | |
3516 | * | |
3517 | * pwm*_enable: | |
3518 | * 0: "disengaged" mode | |
3519 | * 1: manual mode | |
3520 | * 2: native EC "auto" mode (recommended, hardware default) | |
3521 | * | |
3522 | * pwm*: set speed in manual mode, ignored otherwise. | |
3523 | * 0 is level 0; 255 is level 7. Intermediate points done with linear | |
3524 | * interpolation. | |
3525 | * | |
3526 | * fan*_input: tachometer reading, RPM | |
3527 | * | |
3528 | * | |
3529 | * SYSFS fan layout: extensions | |
3530 | * | |
3531 | * fan_watchdog (driver): | |
3532 | * fan watchdog interval in seconds, 0 disables (default), max 120 | |
3533 | */ | |
3534 | ||
3535 | /* sysfs fan pwm1_enable ----------------------------------------------- */ | |
3536 | static ssize_t fan_pwm1_enable_show(struct device *dev, | |
3537 | struct device_attribute *attr, | |
3538 | char *buf) | |
3539 | { | |
3540 | int res, mode; | |
3541 | u8 status; | |
3542 | ||
3543 | res = fan_get_status_safe(&status); | |
3544 | if (res) | |
3545 | return res; | |
3546 | ||
3547 | if (unlikely(tp_features.fan_ctrl_status_undef)) { | |
3548 | if (status != fan_control_initial_status) { | |
3549 | tp_features.fan_ctrl_status_undef = 0; | |
3550 | } else { | |
3551 | /* Return most likely status. In fact, it | |
3552 | * might be the only possible status */ | |
3553 | status = TP_EC_FAN_AUTO; | |
3554 | } | |
3555 | } | |
3556 | ||
3557 | if (status & TP_EC_FAN_FULLSPEED) { | |
3558 | mode = 0; | |
3559 | } else if (status & TP_EC_FAN_AUTO) { | |
3560 | mode = 2; | |
3561 | } else | |
3562 | mode = 1; | |
3563 | ||
3564 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); | |
3565 | } | |
3566 | ||
3567 | static ssize_t fan_pwm1_enable_store(struct device *dev, | |
3568 | struct device_attribute *attr, | |
3569 | const char *buf, size_t count) | |
3570 | { | |
3571 | unsigned long t; | |
3572 | int res, level; | |
3573 | ||
3574 | if (parse_strtoul(buf, 2, &t)) | |
3575 | return -EINVAL; | |
3576 | ||
3577 | switch (t) { | |
3578 | case 0: | |
3579 | level = TP_EC_FAN_FULLSPEED; | |
3580 | break; | |
3581 | case 1: | |
3582 | level = TPACPI_FAN_LAST_LEVEL; | |
3583 | break; | |
3584 | case 2: | |
3585 | level = TP_EC_FAN_AUTO; | |
3586 | break; | |
3587 | case 3: | |
3588 | /* reserved for software-controlled auto mode */ | |
3589 | return -ENOSYS; | |
3590 | default: | |
3591 | return -EINVAL; | |
3592 | } | |
3593 | ||
3594 | res = fan_set_level_safe(level); | |
c573ddb9 HMH |
3595 | if (res == -ENXIO) |
3596 | return -EINVAL; | |
3597 | else if (res < 0) | |
fe98a52c HMH |
3598 | return res; |
3599 | ||
3600 | fan_watchdog_reset(); | |
3601 | ||
3602 | return count; | |
3603 | } | |
3604 | ||
3605 | static struct device_attribute dev_attr_fan_pwm1_enable = | |
3606 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, | |
3607 | fan_pwm1_enable_show, fan_pwm1_enable_store); | |
3608 | ||
3609 | /* sysfs fan pwm1 ------------------------------------------------------ */ | |
3610 | static ssize_t fan_pwm1_show(struct device *dev, | |
3611 | struct device_attribute *attr, | |
3612 | char *buf) | |
3613 | { | |
3614 | int res; | |
3615 | u8 status; | |
3616 | ||
3617 | res = fan_get_status_safe(&status); | |
3618 | if (res) | |
3619 | return res; | |
3620 | ||
3621 | if (unlikely(tp_features.fan_ctrl_status_undef)) { | |
3622 | if (status != fan_control_initial_status) { | |
3623 | tp_features.fan_ctrl_status_undef = 0; | |
3624 | } else { | |
3625 | status = TP_EC_FAN_AUTO; | |
3626 | } | |
3627 | } | |
3628 | ||
3629 | if ((status & | |
3630 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) | |
3631 | status = fan_control_desired_level; | |
3632 | ||
3633 | if (status > 7) | |
3634 | status = 7; | |
3635 | ||
3636 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); | |
3637 | } | |
3638 | ||
3639 | static ssize_t fan_pwm1_store(struct device *dev, | |
3640 | struct device_attribute *attr, | |
3641 | const char *buf, size_t count) | |
3642 | { | |
3643 | unsigned long s; | |
3644 | int rc; | |
3645 | u8 status, newlevel; | |
3646 | ||
3647 | if (parse_strtoul(buf, 255, &s)) | |
3648 | return -EINVAL; | |
3649 | ||
3650 | /* scale down from 0-255 to 0-7 */ | |
3651 | newlevel = (s >> 5) & 0x07; | |
3652 | ||
3653 | rc = mutex_lock_interruptible(&fan_mutex); | |
3654 | if (rc < 0) | |
3655 | return rc; | |
3656 | ||
3657 | rc = fan_get_status(&status); | |
3658 | if (!rc && (status & | |
3659 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { | |
3660 | rc = fan_set_level(newlevel); | |
c573ddb9 HMH |
3661 | if (rc == -ENXIO) |
3662 | rc = -EINVAL; | |
3663 | else if (!rc) { | |
fe98a52c | 3664 | fan_update_desired_level(newlevel); |
ca4ac2f4 HMH |
3665 | fan_watchdog_reset(); |
3666 | } | |
fe98a52c HMH |
3667 | } |
3668 | ||
3669 | mutex_unlock(&fan_mutex); | |
3670 | return (rc)? rc : count; | |
3671 | } | |
3672 | ||
3673 | static struct device_attribute dev_attr_fan_pwm1 = | |
3674 | __ATTR(pwm1, S_IWUSR | S_IRUGO, | |
3675 | fan_pwm1_show, fan_pwm1_store); | |
3676 | ||
3677 | /* sysfs fan fan1_input ------------------------------------------------ */ | |
3678 | static ssize_t fan_fan1_input_show(struct device *dev, | |
3679 | struct device_attribute *attr, | |
3680 | char *buf) | |
3681 | { | |
3682 | int res; | |
3683 | unsigned int speed; | |
3684 | ||
3685 | res = fan_get_speed(&speed); | |
3686 | if (res < 0) | |
3687 | return res; | |
3688 | ||
3689 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); | |
3690 | } | |
3691 | ||
3692 | static struct device_attribute dev_attr_fan_fan1_input = | |
3693 | __ATTR(fan1_input, S_IRUGO, | |
3694 | fan_fan1_input_show, NULL); | |
3695 | ||
7fd40029 | 3696 | /* sysfs fan fan_watchdog (hwmon driver) ------------------------------- */ |
fe98a52c HMH |
3697 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
3698 | char *buf) | |
3699 | { | |
3700 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); | |
3701 | } | |
3702 | ||
3703 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, | |
3704 | const char *buf, size_t count) | |
3705 | { | |
3706 | unsigned long t; | |
3707 | ||
3708 | if (parse_strtoul(buf, 120, &t)) | |
3709 | return -EINVAL; | |
3710 | ||
ecf2a80a HMH |
3711 | if (!fan_control_allowed) |
3712 | return -EPERM; | |
3713 | ||
fe98a52c HMH |
3714 | fan_watchdog_maxinterval = t; |
3715 | fan_watchdog_reset(); | |
3716 | ||
3717 | return count; | |
3718 | } | |
3719 | ||
3720 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, | |
3721 | fan_fan_watchdog_show, fan_fan_watchdog_store); | |
3722 | ||
3723 | /* --------------------------------------------------------------------- */ | |
3724 | static struct attribute *fan_attributes[] = { | |
3725 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, | |
3726 | &dev_attr_fan_fan1_input.attr, | |
3727 | NULL | |
3728 | }; | |
3729 | ||
3730 | static const struct attribute_group fan_attr_group = { | |
3731 | .attrs = fan_attributes, | |
3732 | }; | |
3733 | ||
a5763f22 | 3734 | static int __init fan_init(struct ibm_init_struct *iibm) |
78f81cc4 | 3735 | { |
fe98a52c HMH |
3736 | int rc; |
3737 | ||
fe08bc4b HMH |
3738 | vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n"); |
3739 | ||
40ca9fdf | 3740 | mutex_init(&fan_mutex); |
efa27145 HMH |
3741 | fan_status_access_mode = TPACPI_FAN_NONE; |
3742 | fan_control_access_mode = TPACPI_FAN_WR_NONE; | |
69ba91cb | 3743 | fan_control_commands = 0; |
16663a87 | 3744 | fan_watchdog_maxinterval = 0; |
d8fd94d9 | 3745 | tp_features.fan_ctrl_status_undef = 0; |
fe98a52c | 3746 | fan_control_desired_level = 7; |
78f81cc4 | 3747 | |
8d376cd6 HMH |
3748 | IBM_ACPIHANDLE_INIT(fans); |
3749 | IBM_ACPIHANDLE_INIT(gfan); | |
3750 | IBM_ACPIHANDLE_INIT(sfan); | |
5fba344c | 3751 | |
78f81cc4 BD |
3752 | if (gfan_handle) { |
3753 | /* 570, 600e/x, 770e, 770x */ | |
efa27145 | 3754 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
69ba91cb HMH |
3755 | } else { |
3756 | /* all other ThinkPads: note that even old-style | |
3757 | * ThinkPad ECs supports the fan control register */ | |
778b4d74 HMH |
3758 | if (likely(acpi_ec_read(fan_status_offset, |
3759 | &fan_control_initial_status))) { | |
efa27145 | 3760 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
778b4d74 HMH |
3761 | |
3762 | /* In some ThinkPads, neither the EC nor the ACPI | |
3763 | * DSDT initialize the fan status, and it ends up | |
3764 | * being set to 0x07 when it *could* be either | |
3765 | * 0x07 or 0x80. | |
3766 | * | |
3767 | * Enable for TP-1Y (T43), TP-78 (R51e), | |
3768 | * TP-76 (R52), TP-70 (T43, R52), which are known | |
3769 | * to be buggy. */ | |
d5a2f2f1 HMH |
3770 | if (fan_control_initial_status == 0x07) { |
3771 | switch (thinkpad_id.ec_model) { | |
3772 | case 0x5931: /* TP-1Y */ | |
3773 | case 0x3837: /* TP-78 */ | |
3774 | case 0x3637: /* TP-76 */ | |
3775 | case 0x3037: /* TP-70 */ | |
3776 | printk(IBM_NOTICE | |
3777 | "fan_init: initial fan status is " | |
3778 | "unknown, assuming it is in auto " | |
3779 | "mode\n"); | |
3780 | tp_features.fan_ctrl_status_undef = 1; | |
3781 | ;; | |
3782 | } | |
778b4d74 | 3783 | } |
69ba91cb HMH |
3784 | } else { |
3785 | printk(IBM_ERR | |
3786 | "ThinkPad ACPI EC access misbehaving, " | |
3787 | "fan status and control unavailable\n"); | |
5fba344c | 3788 | return 1; |
69ba91cb HMH |
3789 | } |
3790 | } | |
78f81cc4 | 3791 | |
69ba91cb HMH |
3792 | if (sfan_handle) { |
3793 | /* 570, 770x-JL */ | |
efa27145 | 3794 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
1c6a334e | 3795 | fan_control_commands |= |
efa27145 | 3796 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
78f81cc4 | 3797 | } else { |
69ba91cb HMH |
3798 | if (!gfan_handle) { |
3799 | /* gfan without sfan means no fan control */ | |
3800 | /* all other models implement TP EC 0x2f control */ | |
3801 | ||
3802 | if (fans_handle) { | |
a8b7a662 | 3803 | /* X31, X40, X41 */ |
69ba91cb | 3804 | fan_control_access_mode = |
efa27145 | 3805 | TPACPI_FAN_WR_ACPI_FANS; |
69ba91cb | 3806 | fan_control_commands |= |
efa27145 HMH |
3807 | TPACPI_FAN_CMD_SPEED | |
3808 | TPACPI_FAN_CMD_LEVEL | | |
3809 | TPACPI_FAN_CMD_ENABLE; | |
69ba91cb | 3810 | } else { |
efa27145 | 3811 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
a12095c2 | 3812 | fan_control_commands |= |
efa27145 HMH |
3813 | TPACPI_FAN_CMD_LEVEL | |
3814 | TPACPI_FAN_CMD_ENABLE; | |
69ba91cb HMH |
3815 | } |
3816 | } | |
3817 | } | |
3818 | ||
fe08bc4b HMH |
3819 | vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n", |
3820 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || | |
3821 | fan_control_access_mode != TPACPI_FAN_WR_NONE), | |
3822 | fan_status_access_mode, fan_control_access_mode); | |
3823 | ||
ecf2a80a HMH |
3824 | /* fan control master switch */ |
3825 | if (!fan_control_allowed) { | |
3826 | fan_control_access_mode = TPACPI_FAN_WR_NONE; | |
3827 | fan_control_commands = 0; | |
3828 | dbg_printk(TPACPI_DBG_INIT, | |
3829 | "fan control features disabled by parameter\n"); | |
3830 | } | |
3831 | ||
fe98a52c HMH |
3832 | /* update fan_control_desired_level */ |
3833 | if (fan_status_access_mode != TPACPI_FAN_NONE) | |
3834 | fan_get_status_safe(NULL); | |
3835 | ||
3836 | if (fan_status_access_mode != TPACPI_FAN_NONE || | |
3837 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { | |
7fd40029 | 3838 | rc = sysfs_create_group(&tpacpi_sensors_pdev->dev.kobj, |
fe98a52c HMH |
3839 | &fan_attr_group); |
3840 | if (!(rc < 0)) | |
7fd40029 | 3841 | rc = driver_create_file(&tpacpi_hwmon_pdriver.driver, |
fe98a52c HMH |
3842 | &driver_attr_fan_watchdog); |
3843 | if (rc < 0) | |
3844 | return rc; | |
3845 | return 0; | |
3846 | } else | |
3847 | return 1; | |
3848 | } | |
3849 | ||
3850 | /* | |
3851 | * Call with fan_mutex held | |
3852 | */ | |
3853 | static void fan_update_desired_level(u8 status) | |
3854 | { | |
3855 | if ((status & | |
3856 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { | |
3857 | if (status > 7) | |
3858 | fan_control_desired_level = 7; | |
3859 | else | |
3860 | fan_control_desired_level = status; | |
3861 | } | |
69ba91cb | 3862 | } |
78f81cc4 | 3863 | |
c52f0aa5 | 3864 | static int fan_get_status(u8 *status) |
78f81cc4 | 3865 | { |
c52f0aa5 | 3866 | u8 s; |
78f81cc4 | 3867 | |
a8b7a662 | 3868 | /* TODO: |
efa27145 | 3869 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
a8b7a662 | 3870 | |
3ef8a609 | 3871 | switch (fan_status_access_mode) { |
efa27145 | 3872 | case TPACPI_FAN_RD_ACPI_GFAN: |
78f81cc4 | 3873 | /* 570, 600e/x, 770e, 770x */ |
c52f0aa5 HMH |
3874 | |
3875 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) | |
1da177e4 | 3876 | return -EIO; |
78f81cc4 | 3877 | |
c52f0aa5 HMH |
3878 | if (likely(status)) |
3879 | *status = s & 0x07; | |
3ef8a609 HMH |
3880 | |
3881 | break; | |
3882 | ||
efa27145 | 3883 | case TPACPI_FAN_RD_TPEC: |
78f81cc4 | 3884 | /* all except 570, 600e/x, 770e, 770x */ |
c52f0aa5 | 3885 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
3ef8a609 | 3886 | return -EIO; |
78f81cc4 | 3887 | |
c52f0aa5 HMH |
3888 | if (likely(status)) |
3889 | *status = s; | |
3890 | ||
3891 | break; | |
3892 | ||
3893 | default: | |
3894 | return -ENXIO; | |
78f81cc4 BD |
3895 | } |
3896 | ||
c52f0aa5 HMH |
3897 | return 0; |
3898 | } | |
3899 | ||
fe98a52c HMH |
3900 | static int fan_get_status_safe(u8 *status) |
3901 | { | |
3902 | int rc; | |
3903 | u8 s; | |
3904 | ||
3905 | rc = mutex_lock_interruptible(&fan_mutex); | |
3906 | if (rc < 0) | |
3907 | return rc; | |
3908 | rc = fan_get_status(&s); | |
3909 | if (!rc) | |
3910 | fan_update_desired_level(s); | |
3911 | mutex_unlock(&fan_mutex); | |
3912 | ||
3913 | if (status) | |
3914 | *status = s; | |
3915 | ||
3916 | return rc; | |
3917 | } | |
3918 | ||
56b6aeb0 HMH |
3919 | static void fan_exit(void) |
3920 | { | |
99fba3f8 | 3921 | vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n"); |
fe98a52c HMH |
3922 | |
3923 | /* FIXME: can we really do this unconditionally? */ | |
7fd40029 HMH |
3924 | sysfs_remove_group(&tpacpi_sensors_pdev->dev.kobj, &fan_attr_group); |
3925 | driver_remove_file(&tpacpi_hwmon_pdriver.driver, &driver_attr_fan_watchdog); | |
fe98a52c | 3926 | |
56b6aeb0 HMH |
3927 | cancel_delayed_work(&fan_watchdog_task); |
3928 | flush_scheduled_work(); | |
3929 | } | |
3930 | ||
c52f0aa5 HMH |
3931 | static int fan_get_speed(unsigned int *speed) |
3932 | { | |
3933 | u8 hi, lo; | |
3934 | ||
3935 | switch (fan_status_access_mode) { | |
efa27145 | 3936 | case TPACPI_FAN_RD_TPEC: |
78f81cc4 | 3937 | /* all except 570, 600e/x, 770e, 770x */ |
3ef8a609 HMH |
3938 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
3939 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) | |
3940 | return -EIO; | |
3ef8a609 | 3941 | |
c52f0aa5 HMH |
3942 | if (likely(speed)) |
3943 | *speed = (hi << 8) | lo; | |
3944 | ||
3945 | break; | |
3946 | ||
3947 | default: | |
3948 | return -ENXIO; | |
3949 | } | |
3950 | ||
3951 | return 0; | |
3952 | } | |
3953 | ||
56b6aeb0 | 3954 | static void fan_watchdog_fire(struct work_struct *ignored) |
16663a87 | 3955 | { |
99fba3f8 HMH |
3956 | int rc; |
3957 | ||
8fef502e HMH |
3958 | if (tpacpi_lifecycle != TPACPI_LIFE_RUNNING) |
3959 | return; | |
3960 | ||
56b6aeb0 | 3961 | printk(IBM_NOTICE "fan watchdog: enabling fan\n"); |
99fba3f8 HMH |
3962 | rc = fan_set_enable(); |
3963 | if (rc < 0) { | |
3964 | printk(IBM_ERR "fan watchdog: error %d while enabling fan, " | |
3965 | "will try again later...\n", -rc); | |
56b6aeb0 HMH |
3966 | /* reschedule for later */ |
3967 | fan_watchdog_reset(); | |
3968 | } | |
16663a87 HMH |
3969 | } |
3970 | ||
3971 | static void fan_watchdog_reset(void) | |
3972 | { | |
94954cc6 | 3973 | static int fan_watchdog_active; |
16663a87 | 3974 | |
4985cd0a HMH |
3975 | if (fan_control_access_mode == TPACPI_FAN_WR_NONE) |
3976 | return; | |
3977 | ||
16663a87 HMH |
3978 | if (fan_watchdog_active) |
3979 | cancel_delayed_work(&fan_watchdog_task); | |
3980 | ||
8fef502e HMH |
3981 | if (fan_watchdog_maxinterval > 0 && |
3982 | tpacpi_lifecycle != TPACPI_LIFE_EXITING) { | |
16663a87 HMH |
3983 | fan_watchdog_active = 1; |
3984 | if (!schedule_delayed_work(&fan_watchdog_task, | |
3985 | msecs_to_jiffies(fan_watchdog_maxinterval | |
3986 | * 1000))) { | |
3987 | printk(IBM_ERR "failed to schedule the fan watchdog, " | |
3988 | "watchdog will not trigger\n"); | |
3989 | } | |
3990 | } else | |
3991 | fan_watchdog_active = 0; | |
3992 | } | |
3993 | ||
18ad7996 | 3994 | static int fan_set_level(int level) |
78f81cc4 | 3995 | { |
ecf2a80a HMH |
3996 | if (!fan_control_allowed) |
3997 | return -EPERM; | |
3998 | ||
18ad7996 | 3999 | switch (fan_control_access_mode) { |
efa27145 | 4000 | case TPACPI_FAN_WR_ACPI_SFAN: |
18ad7996 | 4001 | if (level >= 0 && level <= 7) { |
fe98a52c | 4002 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
78f81cc4 | 4003 | return -EIO; |
18ad7996 HMH |
4004 | } else |
4005 | return -EINVAL; | |
4006 | break; | |
4007 | ||
efa27145 HMH |
4008 | case TPACPI_FAN_WR_ACPI_FANS: |
4009 | case TPACPI_FAN_WR_TPEC: | |
4010 | if ((level != TP_EC_FAN_AUTO) && | |
4011 | (level != TP_EC_FAN_FULLSPEED) && | |
a12095c2 HMH |
4012 | ((level < 0) || (level > 7))) |
4013 | return -EINVAL; | |
4014 | ||
eaa7571b HMH |
4015 | /* safety net should the EC not support AUTO |
4016 | * or FULLSPEED mode bits and just ignore them */ | |
4017 | if (level & TP_EC_FAN_FULLSPEED) | |
4018 | level |= 7; /* safety min speed 7 */ | |
4019 | else if (level & TP_EC_FAN_FULLSPEED) | |
4020 | level |= 4; /* safety min speed 4 */ | |
4021 | ||
fe98a52c | 4022 | if (!acpi_ec_write(fan_status_offset, level)) |
a12095c2 | 4023 | return -EIO; |
778b4d74 | 4024 | else |
d8fd94d9 | 4025 | tp_features.fan_ctrl_status_undef = 0; |
a12095c2 HMH |
4026 | break; |
4027 | ||
18ad7996 HMH |
4028 | default: |
4029 | return -ENXIO; | |
4030 | } | |
4031 | return 0; | |
4032 | } | |
4033 | ||
fe98a52c HMH |
4034 | static int fan_set_level_safe(int level) |
4035 | { | |
4036 | int rc; | |
4037 | ||
ecf2a80a HMH |
4038 | if (!fan_control_allowed) |
4039 | return -EPERM; | |
4040 | ||
fe98a52c HMH |
4041 | rc = mutex_lock_interruptible(&fan_mutex); |
4042 | if (rc < 0) | |
4043 | return rc; | |
4044 | ||
4045 | if (level == TPACPI_FAN_LAST_LEVEL) | |
4046 | level = fan_control_desired_level; | |
4047 | ||
4048 | rc = fan_set_level(level); | |
4049 | if (!rc) | |
4050 | fan_update_desired_level(level); | |
4051 | ||
4052 | mutex_unlock(&fan_mutex); | |
4053 | return rc; | |
4054 | } | |
4055 | ||
18ad7996 HMH |
4056 | static int fan_set_enable(void) |
4057 | { | |
1c6a334e HMH |
4058 | u8 s; |
4059 | int rc; | |
4060 | ||
ecf2a80a HMH |
4061 | if (!fan_control_allowed) |
4062 | return -EPERM; | |
4063 | ||
40ca9fdf HMH |
4064 | rc = mutex_lock_interruptible(&fan_mutex); |
4065 | if (rc < 0) | |
4066 | return rc; | |
4067 | ||
18ad7996 | 4068 | switch (fan_control_access_mode) { |
efa27145 HMH |
4069 | case TPACPI_FAN_WR_ACPI_FANS: |
4070 | case TPACPI_FAN_WR_TPEC: | |
40ca9fdf HMH |
4071 | rc = fan_get_status(&s); |
4072 | if (rc < 0) | |
4073 | break; | |
1c6a334e HMH |
4074 | |
4075 | /* Don't go out of emergency fan mode */ | |
eaa7571b HMH |
4076 | if (s != 7) { |
4077 | s &= 0x07; | |
4078 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ | |
4079 | } | |
1c6a334e HMH |
4080 | |
4081 | if (!acpi_ec_write(fan_status_offset, s)) | |
40ca9fdf HMH |
4082 | rc = -EIO; |
4083 | else { | |
d8fd94d9 | 4084 | tp_features.fan_ctrl_status_undef = 0; |
40ca9fdf HMH |
4085 | rc = 0; |
4086 | } | |
1c6a334e HMH |
4087 | break; |
4088 | ||
efa27145 | 4089 | case TPACPI_FAN_WR_ACPI_SFAN: |
40ca9fdf HMH |
4090 | rc = fan_get_status(&s); |
4091 | if (rc < 0) | |
4092 | break; | |
1c6a334e HMH |
4093 | |
4094 | s &= 0x07; | |
4095 | ||
4096 | /* Set fan to at least level 4 */ | |
eaa7571b | 4097 | s |= 4; |
1c6a334e HMH |
4098 | |
4099 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) | |
40ca9fdf HMH |
4100 | rc= -EIO; |
4101 | else | |
4102 | rc = 0; | |
18ad7996 HMH |
4103 | break; |
4104 | ||
4105 | default: | |
40ca9fdf | 4106 | rc = -ENXIO; |
18ad7996 | 4107 | } |
40ca9fdf HMH |
4108 | |
4109 | mutex_unlock(&fan_mutex); | |
4110 | return rc; | |
18ad7996 HMH |
4111 | } |
4112 | ||
4113 | static int fan_set_disable(void) | |
4114 | { | |
40ca9fdf HMH |
4115 | int rc; |
4116 | ||
ecf2a80a HMH |
4117 | if (!fan_control_allowed) |
4118 | return -EPERM; | |
4119 | ||
40ca9fdf HMH |
4120 | rc = mutex_lock_interruptible(&fan_mutex); |
4121 | if (rc < 0) | |
4122 | return rc; | |
4123 | ||
4124 | rc = 0; | |
18ad7996 | 4125 | switch (fan_control_access_mode) { |
efa27145 HMH |
4126 | case TPACPI_FAN_WR_ACPI_FANS: |
4127 | case TPACPI_FAN_WR_TPEC: | |
18ad7996 | 4128 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
40ca9fdf | 4129 | rc = -EIO; |
fe98a52c HMH |
4130 | else { |
4131 | fan_control_desired_level = 0; | |
d8fd94d9 | 4132 | tp_features.fan_ctrl_status_undef = 0; |
fe98a52c | 4133 | } |
18ad7996 HMH |
4134 | break; |
4135 | ||
efa27145 | 4136 | case TPACPI_FAN_WR_ACPI_SFAN: |
1c6a334e | 4137 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
40ca9fdf | 4138 | rc = -EIO; |
fe98a52c HMH |
4139 | else |
4140 | fan_control_desired_level = 0; | |
1c6a334e HMH |
4141 | break; |
4142 | ||
18ad7996 | 4143 | default: |
40ca9fdf | 4144 | rc = -ENXIO; |
18ad7996 | 4145 | } |
40ca9fdf | 4146 | |
fe98a52c | 4147 | |
40ca9fdf HMH |
4148 | mutex_unlock(&fan_mutex); |
4149 | return rc; | |
56b6aeb0 HMH |
4150 | } |
4151 | ||
4152 | static int fan_set_speed(int speed) | |
4153 | { | |
40ca9fdf HMH |
4154 | int rc; |
4155 | ||
ecf2a80a HMH |
4156 | if (!fan_control_allowed) |
4157 | return -EPERM; | |
4158 | ||
40ca9fdf HMH |
4159 | rc = mutex_lock_interruptible(&fan_mutex); |
4160 | if (rc < 0) | |
4161 | return rc; | |
4162 | ||
4163 | rc = 0; | |
56b6aeb0 | 4164 | switch (fan_control_access_mode) { |
efa27145 | 4165 | case TPACPI_FAN_WR_ACPI_FANS: |
56b6aeb0 HMH |
4166 | if (speed >= 0 && speed <= 65535) { |
4167 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", | |
4168 | speed, speed, speed)) | |
40ca9fdf | 4169 | rc = -EIO; |
56b6aeb0 | 4170 | } else |
40ca9fdf | 4171 | rc = -EINVAL; |
56b6aeb0 HMH |
4172 | break; |
4173 | ||
4174 | default: | |
40ca9fdf | 4175 | rc = -ENXIO; |
56b6aeb0 | 4176 | } |
40ca9fdf HMH |
4177 | |
4178 | mutex_unlock(&fan_mutex); | |
4179 | return rc; | |
56b6aeb0 HMH |
4180 | } |
4181 | ||
4182 | static int fan_read(char *p) | |
4183 | { | |
4184 | int len = 0; | |
4185 | int rc; | |
4186 | u8 status; | |
4187 | unsigned int speed = 0; | |
4188 | ||
4189 | switch (fan_status_access_mode) { | |
efa27145 | 4190 | case TPACPI_FAN_RD_ACPI_GFAN: |
56b6aeb0 | 4191 | /* 570, 600e/x, 770e, 770x */ |
fe98a52c | 4192 | if ((rc = fan_get_status_safe(&status)) < 0) |
56b6aeb0 HMH |
4193 | return rc; |
4194 | ||
4195 | len += sprintf(p + len, "status:\t\t%s\n" | |
4196 | "level:\t\t%d\n", | |
4197 | (status != 0) ? "enabled" : "disabled", status); | |
4198 | break; | |
4199 | ||
efa27145 | 4200 | case TPACPI_FAN_RD_TPEC: |
56b6aeb0 | 4201 | /* all except 570, 600e/x, 770e, 770x */ |
fe98a52c | 4202 | if ((rc = fan_get_status_safe(&status)) < 0) |
56b6aeb0 HMH |
4203 | return rc; |
4204 | ||
d8fd94d9 | 4205 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
56b6aeb0 | 4206 | if (status != fan_control_initial_status) |
d8fd94d9 | 4207 | tp_features.fan_ctrl_status_undef = 0; |
56b6aeb0 HMH |
4208 | else |
4209 | /* Return most likely status. In fact, it | |
4210 | * might be the only possible status */ | |
efa27145 | 4211 | status = TP_EC_FAN_AUTO; |
56b6aeb0 HMH |
4212 | } |
4213 | ||
4214 | len += sprintf(p + len, "status:\t\t%s\n", | |
4215 | (status != 0) ? "enabled" : "disabled"); | |
4216 | ||
56b6aeb0 HMH |
4217 | if ((rc = fan_get_speed(&speed)) < 0) |
4218 | return rc; | |
4219 | ||
4220 | len += sprintf(p + len, "speed:\t\t%d\n", speed); | |
4221 | ||
efa27145 | 4222 | if (status & TP_EC_FAN_FULLSPEED) |
56b6aeb0 HMH |
4223 | /* Disengaged mode takes precedence */ |
4224 | len += sprintf(p + len, "level:\t\tdisengaged\n"); | |
efa27145 | 4225 | else if (status & TP_EC_FAN_AUTO) |
56b6aeb0 HMH |
4226 | len += sprintf(p + len, "level:\t\tauto\n"); |
4227 | else | |
4228 | len += sprintf(p + len, "level:\t\t%d\n", status); | |
4229 | break; | |
4230 | ||
efa27145 | 4231 | case TPACPI_FAN_NONE: |
56b6aeb0 HMH |
4232 | default: |
4233 | len += sprintf(p + len, "status:\t\tnot supported\n"); | |
4234 | } | |
4235 | ||
efa27145 | 4236 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
56b6aeb0 HMH |
4237 | len += sprintf(p + len, "commands:\tlevel <level>"); |
4238 | ||
4239 | switch (fan_control_access_mode) { | |
efa27145 | 4240 | case TPACPI_FAN_WR_ACPI_SFAN: |
56b6aeb0 HMH |
4241 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
4242 | break; | |
4243 | ||
4244 | default: | |
4245 | len += sprintf(p + len, " (<level> is 0-7, " | |
fe98a52c | 4246 | "auto, disengaged, full-speed)\n"); |
56b6aeb0 HMH |
4247 | break; |
4248 | } | |
4249 | } | |
18ad7996 | 4250 | |
efa27145 | 4251 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
56b6aeb0 HMH |
4252 | len += sprintf(p + len, "commands:\tenable, disable\n" |
4253 | "commands:\twatchdog <timeout> (<timeout> is 0 (off), " | |
4254 | "1-120 (seconds))\n"); | |
1da177e4 | 4255 | |
efa27145 | 4256 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
56b6aeb0 HMH |
4257 | len += sprintf(p + len, "commands:\tspeed <speed>" |
4258 | " (<speed> is 0-65535)\n"); | |
4259 | ||
4260 | return len; | |
78f81cc4 BD |
4261 | } |
4262 | ||
18ad7996 HMH |
4263 | static int fan_write_cmd_level(const char *cmd, int *rc) |
4264 | { | |
4265 | int level; | |
4266 | ||
a12095c2 | 4267 | if (strlencmp(cmd, "level auto") == 0) |
efa27145 | 4268 | level = TP_EC_FAN_AUTO; |
fe98a52c HMH |
4269 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
4270 | (strlencmp(cmd, "level full-speed") == 0)) | |
efa27145 | 4271 | level = TP_EC_FAN_FULLSPEED; |
a12095c2 | 4272 | else if (sscanf(cmd, "level %d", &level) != 1) |
18ad7996 HMH |
4273 | return 0; |
4274 | ||
fe98a52c | 4275 | if ((*rc = fan_set_level_safe(level)) == -ENXIO) |
18ad7996 HMH |
4276 | printk(IBM_ERR "level command accepted for unsupported " |
4277 | "access mode %d", fan_control_access_mode); | |
4278 | ||
4279 | return 1; | |
4280 | } | |
4281 | ||
4282 | static int fan_write_cmd_enable(const char *cmd, int *rc) | |
4283 | { | |
4284 | if (strlencmp(cmd, "enable") != 0) | |
4285 | return 0; | |
4286 | ||
4287 | if ((*rc = fan_set_enable()) == -ENXIO) | |
4288 | printk(IBM_ERR "enable command accepted for unsupported " | |
4289 | "access mode %d", fan_control_access_mode); | |
4290 | ||
4291 | return 1; | |
4292 | } | |
4293 | ||
4294 | static int fan_write_cmd_disable(const char *cmd, int *rc) | |
4295 | { | |
4296 | if (strlencmp(cmd, "disable") != 0) | |
4297 | return 0; | |
4298 | ||
4299 | if ((*rc = fan_set_disable()) == -ENXIO) | |
4300 | printk(IBM_ERR "disable command accepted for unsupported " | |
4301 | "access mode %d", fan_control_access_mode); | |
4302 | ||
4303 | return 1; | |
4304 | } | |
4305 | ||
4306 | static int fan_write_cmd_speed(const char *cmd, int *rc) | |
4307 | { | |
4308 | int speed; | |
4309 | ||
a8b7a662 HMH |
4310 | /* TODO: |
4311 | * Support speed <low> <medium> <high> ? */ | |
4312 | ||
18ad7996 HMH |
4313 | if (sscanf(cmd, "speed %d", &speed) != 1) |
4314 | return 0; | |
4315 | ||
4316 | if ((*rc = fan_set_speed(speed)) == -ENXIO) | |
4317 | printk(IBM_ERR "speed command accepted for unsupported " | |
4318 | "access mode %d", fan_control_access_mode); | |
4319 | ||
4320 | return 1; | |
4321 | } | |
4322 | ||
16663a87 HMH |
4323 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
4324 | { | |
4325 | int interval; | |
4326 | ||
4327 | if (sscanf(cmd, "watchdog %d", &interval) != 1) | |
4328 | return 0; | |
4329 | ||
4330 | if (interval < 0 || interval > 120) | |
4331 | *rc = -EINVAL; | |
4332 | else | |
4333 | fan_watchdog_maxinterval = interval; | |
4334 | ||
4335 | return 1; | |
4336 | } | |
4337 | ||
18ad7996 HMH |
4338 | static int fan_write(char *buf) |
4339 | { | |
4340 | char *cmd; | |
4341 | int rc = 0; | |
4342 | ||
4343 | while (!rc && (cmd = next_cmd(&buf))) { | |
efa27145 | 4344 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
18ad7996 | 4345 | fan_write_cmd_level(cmd, &rc)) && |
efa27145 | 4346 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
18ad7996 | 4347 | (fan_write_cmd_enable(cmd, &rc) || |
16663a87 HMH |
4348 | fan_write_cmd_disable(cmd, &rc) || |
4349 | fan_write_cmd_watchdog(cmd, &rc))) && | |
efa27145 | 4350 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
18ad7996 HMH |
4351 | fan_write_cmd_speed(cmd, &rc)) |
4352 | ) | |
4353 | rc = -EINVAL; | |
16663a87 HMH |
4354 | else if (!rc) |
4355 | fan_watchdog_reset(); | |
18ad7996 HMH |
4356 | } |
4357 | ||
4358 | return rc; | |
4359 | } | |
4360 | ||
a5763f22 HMH |
4361 | static struct ibm_struct fan_driver_data = { |
4362 | .name = "fan", | |
4363 | .read = fan_read, | |
4364 | .write = fan_write, | |
4365 | .exit = fan_exit, | |
a5763f22 HMH |
4366 | }; |
4367 | ||
56b6aeb0 HMH |
4368 | /**************************************************************************** |
4369 | **************************************************************************** | |
4370 | * | |
4371 | * Infrastructure | |
4372 | * | |
4373 | **************************************************************************** | |
4374 | ****************************************************************************/ | |
4375 | ||
7fd40029 HMH |
4376 | /* sysfs name ---------------------------------------------------------- */ |
4377 | static ssize_t thinkpad_acpi_pdev_name_show(struct device *dev, | |
4378 | struct device_attribute *attr, | |
4379 | char *buf) | |
4380 | { | |
4381 | return snprintf(buf, PAGE_SIZE, "%s\n", IBM_NAME); | |
4382 | } | |
4383 | ||
4384 | static struct device_attribute dev_attr_thinkpad_acpi_pdev_name = | |
4385 | __ATTR(name, S_IRUGO, thinkpad_acpi_pdev_name_show, NULL); | |
4386 | ||
4387 | /* --------------------------------------------------------------------- */ | |
4388 | ||
56b6aeb0 | 4389 | /* /proc support */ |
94954cc6 | 4390 | static struct proc_dir_entry *proc_dir; |
16663a87 | 4391 | |
56b6aeb0 | 4392 | /* Subdriver registry */ |
a5763f22 HMH |
4393 | static LIST_HEAD(tpacpi_all_drivers); |
4394 | ||
1da177e4 | 4395 | |
56b6aeb0 HMH |
4396 | /* |
4397 | * Module and infrastructure proble, init and exit handling | |
4398 | */ | |
1da177e4 | 4399 | |
fe08bc4b | 4400 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
a5763f22 | 4401 | static const char * __init str_supported(int is_supported) |
fe08bc4b | 4402 | { |
a5763f22 | 4403 | static char text_unsupported[] __initdata = "not supported"; |
fe08bc4b | 4404 | |
a5763f22 | 4405 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
fe08bc4b HMH |
4406 | } |
4407 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ | |
4408 | ||
a5763f22 | 4409 | static int __init ibm_init(struct ibm_init_struct *iibm) |
1da177e4 LT |
4410 | { |
4411 | int ret; | |
a5763f22 | 4412 | struct ibm_struct *ibm = iibm->data; |
1da177e4 LT |
4413 | struct proc_dir_entry *entry; |
4414 | ||
a5763f22 HMH |
4415 | BUG_ON(ibm == NULL); |
4416 | ||
4417 | INIT_LIST_HEAD(&ibm->all_drivers); | |
4418 | ||
92641177 | 4419 | if (ibm->flags.experimental && !experimental) |
1da177e4 LT |
4420 | return 0; |
4421 | ||
fe08bc4b HMH |
4422 | dbg_printk(TPACPI_DBG_INIT, |
4423 | "probing for %s\n", ibm->name); | |
4424 | ||
a5763f22 HMH |
4425 | if (iibm->init) { |
4426 | ret = iibm->init(iibm); | |
5fba344c HMH |
4427 | if (ret > 0) |
4428 | return 0; /* probe failed */ | |
4429 | if (ret) | |
1da177e4 | 4430 | return ret; |
a5763f22 | 4431 | |
92641177 | 4432 | ibm->flags.init_called = 1; |
1da177e4 LT |
4433 | } |
4434 | ||
8d376cd6 HMH |
4435 | if (ibm->acpi) { |
4436 | if (ibm->acpi->hid) { | |
4437 | ret = register_tpacpi_subdriver(ibm); | |
4438 | if (ret) | |
4439 | goto err_out; | |
4440 | } | |
5fba344c | 4441 | |
8d376cd6 HMH |
4442 | if (ibm->acpi->notify) { |
4443 | ret = setup_acpi_notify(ibm); | |
4444 | if (ret == -ENODEV) { | |
4445 | printk(IBM_NOTICE "disabling subdriver %s\n", | |
4446 | ibm->name); | |
4447 | ret = 0; | |
4448 | goto err_out; | |
4449 | } | |
4450 | if (ret < 0) | |
4451 | goto err_out; | |
5fba344c | 4452 | } |
5fba344c HMH |
4453 | } |
4454 | ||
fe08bc4b HMH |
4455 | dbg_printk(TPACPI_DBG_INIT, |
4456 | "%s installed\n", ibm->name); | |
4457 | ||
78f81cc4 BD |
4458 | if (ibm->read) { |
4459 | entry = create_proc_entry(ibm->name, | |
4460 | S_IFREG | S_IRUGO | S_IWUSR, | |
4461 | proc_dir); | |
4462 | if (!entry) { | |
4463 | printk(IBM_ERR "unable to create proc entry %s\n", | |
4464 | ibm->name); | |
5fba344c HMH |
4465 | ret = -ENODEV; |
4466 | goto err_out; | |
78f81cc4 BD |
4467 | } |
4468 | entry->owner = THIS_MODULE; | |
4469 | entry->data = ibm; | |
8d376cd6 | 4470 | entry->read_proc = &dispatch_procfs_read; |
78f81cc4 | 4471 | if (ibm->write) |
8d376cd6 | 4472 | entry->write_proc = &dispatch_procfs_write; |
92641177 | 4473 | ibm->flags.proc_created = 1; |
78f81cc4 | 4474 | } |
1da177e4 | 4475 | |
a5763f22 HMH |
4476 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
4477 | ||
1da177e4 | 4478 | return 0; |
5fba344c HMH |
4479 | |
4480 | err_out: | |
fe08bc4b HMH |
4481 | dbg_printk(TPACPI_DBG_INIT, |
4482 | "%s: at error exit path with result %d\n", | |
4483 | ibm->name, ret); | |
4484 | ||
5fba344c HMH |
4485 | ibm_exit(ibm); |
4486 | return (ret < 0)? ret : 0; | |
1da177e4 LT |
4487 | } |
4488 | ||
4489 | static void ibm_exit(struct ibm_struct *ibm) | |
4490 | { | |
fe08bc4b | 4491 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
a5763f22 HMH |
4492 | |
4493 | list_del_init(&ibm->all_drivers); | |
4494 | ||
8d376cd6 | 4495 | if (ibm->flags.acpi_notify_installed) { |
fe08bc4b HMH |
4496 | dbg_printk(TPACPI_DBG_EXIT, |
4497 | "%s: acpi_remove_notify_handler\n", ibm->name); | |
8d376cd6 HMH |
4498 | BUG_ON(!ibm->acpi); |
4499 | acpi_remove_notify_handler(*ibm->acpi->handle, | |
4500 | ibm->acpi->type, | |
4501 | dispatch_acpi_notify); | |
4502 | ibm->flags.acpi_notify_installed = 0; | |
4503 | ibm->flags.acpi_notify_installed = 0; | |
5fba344c | 4504 | } |
1da177e4 | 4505 | |
92641177 | 4506 | if (ibm->flags.proc_created) { |
fe08bc4b HMH |
4507 | dbg_printk(TPACPI_DBG_EXIT, |
4508 | "%s: remove_proc_entry\n", ibm->name); | |
1da177e4 | 4509 | remove_proc_entry(ibm->name, proc_dir); |
92641177 | 4510 | ibm->flags.proc_created = 0; |
5fba344c | 4511 | } |
1da177e4 | 4512 | |
8d376cd6 | 4513 | if (ibm->flags.acpi_driver_registered) { |
fe08bc4b HMH |
4514 | dbg_printk(TPACPI_DBG_EXIT, |
4515 | "%s: acpi_bus_unregister_driver\n", ibm->name); | |
8d376cd6 HMH |
4516 | BUG_ON(!ibm->acpi); |
4517 | acpi_bus_unregister_driver(ibm->acpi->driver); | |
4518 | kfree(ibm->acpi->driver); | |
4519 | ibm->acpi->driver = NULL; | |
4520 | ibm->flags.acpi_driver_registered = 0; | |
5fba344c HMH |
4521 | } |
4522 | ||
92641177 | 4523 | if (ibm->flags.init_called && ibm->exit) { |
5fba344c | 4524 | ibm->exit(); |
92641177 | 4525 | ibm->flags.init_called = 0; |
1da177e4 | 4526 | } |
a5763f22 HMH |
4527 | |
4528 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); | |
1da177e4 LT |
4529 | } |
4530 | ||
56b6aeb0 HMH |
4531 | /* Probing */ |
4532 | ||
d5a2f2f1 | 4533 | static void __init get_thinkpad_model_data(struct thinkpad_id_data *tp) |
1da177e4 | 4534 | { |
56b6aeb0 HMH |
4535 | struct dmi_device *dev = NULL; |
4536 | char ec_fw_string[18]; | |
1da177e4 | 4537 | |
d5a2f2f1 HMH |
4538 | if (!tp) |
4539 | return; | |
4540 | ||
4541 | memset(tp, 0, sizeof(*tp)); | |
4542 | ||
4543 | if (dmi_name_in_vendors("IBM")) | |
4544 | tp->vendor = PCI_VENDOR_ID_IBM; | |
4545 | else if (dmi_name_in_vendors("LENOVO")) | |
4546 | tp->vendor = PCI_VENDOR_ID_LENOVO; | |
4547 | else | |
4548 | return; | |
4549 | ||
4550 | tp->bios_version_str = kstrdup(dmi_get_system_info(DMI_BIOS_VERSION), | |
4551 | GFP_KERNEL); | |
4552 | if (!tp->bios_version_str) | |
4553 | return; | |
4554 | tp->bios_model = tp->bios_version_str[0] | |
4555 | | (tp->bios_version_str[1] << 8); | |
4556 | ||
56b6aeb0 HMH |
4557 | /* |
4558 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, | |
4559 | * X32 or newer, all Z series; Some models must have an | |
4560 | * up-to-date BIOS or they will not be detected. | |
4561 | * | |
4562 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs | |
4563 | */ | |
4564 | while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) { | |
4565 | if (sscanf(dev->name, | |
4566 | "IBM ThinkPad Embedded Controller -[%17c", | |
4567 | ec_fw_string) == 1) { | |
4568 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; | |
4569 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; | |
d5a2f2f1 HMH |
4570 | |
4571 | tp->ec_version_str = kstrdup(ec_fw_string, GFP_KERNEL); | |
4572 | tp->ec_model = ec_fw_string[0] | |
4573 | | (ec_fw_string[1] << 8); | |
4574 | break; | |
78f81cc4 | 4575 | } |
1da177e4 | 4576 | } |
d5a2f2f1 HMH |
4577 | |
4578 | tp->model_str = kstrdup(dmi_get_system_info(DMI_PRODUCT_VERSION), | |
4579 | GFP_KERNEL); | |
4580 | if (strnicmp(tp->model_str, "ThinkPad", 8) != 0) { | |
4581 | kfree(tp->model_str); | |
4582 | tp->model_str = NULL; | |
4583 | } | |
1da177e4 LT |
4584 | } |
4585 | ||
5fba344c HMH |
4586 | static int __init probe_for_thinkpad(void) |
4587 | { | |
4588 | int is_thinkpad; | |
4589 | ||
4590 | if (acpi_disabled) | |
4591 | return -ENODEV; | |
4592 | ||
4593 | /* | |
4594 | * Non-ancient models have better DMI tagging, but very old models | |
4595 | * don't. | |
4596 | */ | |
d5a2f2f1 | 4597 | is_thinkpad = (thinkpad_id.model_str != NULL); |
5fba344c HMH |
4598 | |
4599 | /* ec is required because many other handles are relative to it */ | |
8d376cd6 | 4600 | IBM_ACPIHANDLE_INIT(ec); |
5fba344c HMH |
4601 | if (!ec_handle) { |
4602 | if (is_thinkpad) | |
4603 | printk(IBM_ERR | |
4604 | "Not yet supported ThinkPad detected!\n"); | |
4605 | return -ENODEV; | |
4606 | } | |
4607 | ||
0dcef77c HMH |
4608 | /* |
4609 | * Risks a regression on very old machines, but reduces potential | |
4610 | * false positives a damn great deal | |
4611 | */ | |
4612 | if (!is_thinkpad) | |
d5a2f2f1 | 4613 | is_thinkpad = (thinkpad_id.vendor == PCI_VENDOR_ID_IBM); |
0dcef77c HMH |
4614 | |
4615 | if (!is_thinkpad && !force_load) | |
4616 | return -ENODEV; | |
4617 | ||
5fba344c HMH |
4618 | return 0; |
4619 | } | |
4620 | ||
4621 | ||
56b6aeb0 | 4622 | /* Module init, exit, parameters */ |
1da177e4 | 4623 | |
a5763f22 HMH |
4624 | static struct ibm_init_struct ibms_init[] __initdata = { |
4625 | { | |
4626 | .init = thinkpad_acpi_driver_init, | |
4627 | .data = &thinkpad_acpi_driver_data, | |
4628 | }, | |
4629 | { | |
4630 | .init = hotkey_init, | |
4631 | .data = &hotkey_driver_data, | |
4632 | }, | |
4633 | { | |
4634 | .init = bluetooth_init, | |
4635 | .data = &bluetooth_driver_data, | |
4636 | }, | |
4637 | { | |
4638 | .init = wan_init, | |
4639 | .data = &wan_driver_data, | |
4640 | }, | |
4641 | { | |
4642 | .init = video_init, | |
4643 | .data = &video_driver_data, | |
4644 | }, | |
4645 | { | |
4646 | .init = light_init, | |
4647 | .data = &light_driver_data, | |
4648 | }, | |
4649 | #ifdef CONFIG_THINKPAD_ACPI_DOCK | |
4650 | { | |
4651 | .init = dock_init, | |
4652 | .data = &dock_driver_data[0], | |
4653 | }, | |
4654 | { | |
d94a7f16 | 4655 | .init = dock_init2, |
a5763f22 HMH |
4656 | .data = &dock_driver_data[1], |
4657 | }, | |
4658 | #endif | |
4659 | #ifdef CONFIG_THINKPAD_ACPI_BAY | |
4660 | { | |
4661 | .init = bay_init, | |
4662 | .data = &bay_driver_data, | |
4663 | }, | |
4664 | #endif | |
4665 | { | |
4666 | .init = cmos_init, | |
4667 | .data = &cmos_driver_data, | |
4668 | }, | |
4669 | { | |
4670 | .init = led_init, | |
4671 | .data = &led_driver_data, | |
4672 | }, | |
4673 | { | |
4674 | .init = beep_init, | |
4675 | .data = &beep_driver_data, | |
4676 | }, | |
4677 | { | |
4678 | .init = thermal_init, | |
4679 | .data = &thermal_driver_data, | |
4680 | }, | |
4681 | { | |
4682 | .data = &ecdump_driver_data, | |
4683 | }, | |
4684 | { | |
4685 | .init = brightness_init, | |
4686 | .data = &brightness_driver_data, | |
4687 | }, | |
4688 | { | |
4689 | .data = &volume_driver_data, | |
4690 | }, | |
4691 | { | |
4692 | .init = fan_init, | |
4693 | .data = &fan_driver_data, | |
4694 | }, | |
4695 | }; | |
4696 | ||
3945ac36 | 4697 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
1da177e4 LT |
4698 | { |
4699 | unsigned int i; | |
a5763f22 | 4700 | struct ibm_struct *ibm; |
1da177e4 | 4701 | |
a5763f22 HMH |
4702 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
4703 | ibm = ibms_init[i].data; | |
4704 | BUG_ON(ibm == NULL); | |
4705 | ||
4706 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { | |
4707 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) | |
78f81cc4 | 4708 | return -ENOSPC; |
a5763f22 HMH |
4709 | strcpy(ibms_init[i].param, val); |
4710 | strcat(ibms_init[i].param, ","); | |
78f81cc4 BD |
4711 | return 0; |
4712 | } | |
a5763f22 | 4713 | } |
1da177e4 | 4714 | |
1da177e4 LT |
4715 | return -EINVAL; |
4716 | } | |
4717 | ||
56b6aeb0 HMH |
4718 | static int experimental; |
4719 | module_param(experimental, int, 0); | |
4720 | ||
132ce091 HMH |
4721 | static u32 dbg_level; |
4722 | module_param_named(debug, dbg_level, uint, 0); | |
4723 | ||
0dcef77c | 4724 | static int force_load; |
86cc9445 | 4725 | module_param(force_load, bool, 0); |
0dcef77c | 4726 | |
ecf2a80a | 4727 | static int fan_control_allowed; |
86cc9445 | 4728 | module_param_named(fan_control, fan_control_allowed, bool, 0); |
ecf2a80a | 4729 | |
24d3b774 HMH |
4730 | static int brightness_mode; |
4731 | module_param_named(brightness_mode, brightness_mode, int, 0); | |
4732 | ||
ff80f137 HMH |
4733 | static unsigned int hotkey_report_mode; |
4734 | module_param(hotkey_report_mode, uint, 0); | |
4735 | ||
1da177e4 LT |
4736 | #define IBM_PARAM(feature) \ |
4737 | module_param_call(feature, set_ibm_param, NULL, NULL, 0) | |
4738 | ||
78f81cc4 BD |
4739 | IBM_PARAM(hotkey); |
4740 | IBM_PARAM(bluetooth); | |
4741 | IBM_PARAM(video); | |
4742 | IBM_PARAM(light); | |
85998248 | 4743 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
78f81cc4 | 4744 | IBM_PARAM(dock); |
63e5f248 | 4745 | #endif |
85998248 | 4746 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
78f81cc4 | 4747 | IBM_PARAM(bay); |
85998248 | 4748 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
78f81cc4 BD |
4749 | IBM_PARAM(cmos); |
4750 | IBM_PARAM(led); | |
4751 | IBM_PARAM(beep); | |
4752 | IBM_PARAM(ecdump); | |
4753 | IBM_PARAM(brightness); | |
4754 | IBM_PARAM(volume); | |
4755 | IBM_PARAM(fan); | |
4756 | ||
1def7115 | 4757 | static int __init thinkpad_acpi_module_init(void) |
1da177e4 LT |
4758 | { |
4759 | int ret, i; | |
4760 | ||
8fef502e HMH |
4761 | tpacpi_lifecycle = TPACPI_LIFE_INIT; |
4762 | ||
ff80f137 HMH |
4763 | /* Parameter checking */ |
4764 | if (hotkey_report_mode > 2) | |
4765 | return -EINVAL; | |
4766 | ||
54ae1501 | 4767 | /* Driver-level probe */ |
d5a2f2f1 HMH |
4768 | |
4769 | get_thinkpad_model_data(&thinkpad_id); | |
5fba344c | 4770 | ret = probe_for_thinkpad(); |
d5a2f2f1 HMH |
4771 | if (ret) { |
4772 | thinkpad_acpi_module_exit(); | |
5fba344c | 4773 | return ret; |
d5a2f2f1 | 4774 | } |
1da177e4 | 4775 | |
54ae1501 | 4776 | /* Driver initialization */ |
d5a2f2f1 | 4777 | |
8d376cd6 HMH |
4778 | IBM_ACPIHANDLE_INIT(ecrd); |
4779 | IBM_ACPIHANDLE_INIT(ecwr); | |
1da177e4 | 4780 | |
8d376cd6 | 4781 | proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir); |
1da177e4 | 4782 | if (!proc_dir) { |
8d376cd6 | 4783 | printk(IBM_ERR "unable to create proc dir " IBM_PROC_DIR); |
1def7115 | 4784 | thinkpad_acpi_module_exit(); |
1da177e4 LT |
4785 | return -ENODEV; |
4786 | } | |
4787 | proc_dir->owner = THIS_MODULE; | |
78f81cc4 | 4788 | |
54ae1501 HMH |
4789 | ret = platform_driver_register(&tpacpi_pdriver); |
4790 | if (ret) { | |
7fd40029 | 4791 | printk(IBM_ERR "unable to register main platform driver\n"); |
54ae1501 HMH |
4792 | thinkpad_acpi_module_exit(); |
4793 | return ret; | |
4794 | } | |
ac36393d HMH |
4795 | tp_features.platform_drv_registered = 1; |
4796 | ||
7fd40029 HMH |
4797 | ret = platform_driver_register(&tpacpi_hwmon_pdriver); |
4798 | if (ret) { | |
4799 | printk(IBM_ERR "unable to register hwmon platform driver\n"); | |
4800 | thinkpad_acpi_module_exit(); | |
4801 | return ret; | |
4802 | } | |
4803 | tp_features.sensors_pdrv_registered = 1; | |
4804 | ||
176750d6 HMH |
4805 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
4806 | if (ret) { | |
4807 | printk(IBM_ERR "unable to create sysfs driver attributes\n"); | |
4808 | thinkpad_acpi_module_exit(); | |
4809 | return ret; | |
4810 | } | |
ac36393d | 4811 | tp_features.platform_drv_attrs_registered = 1; |
176750d6 | 4812 | |
54ae1501 HMH |
4813 | |
4814 | /* Device initialization */ | |
4815 | tpacpi_pdev = platform_device_register_simple(IBM_DRVR_NAME, -1, | |
4816 | NULL, 0); | |
4817 | if (IS_ERR(tpacpi_pdev)) { | |
4818 | ret = PTR_ERR(tpacpi_pdev); | |
4819 | tpacpi_pdev = NULL; | |
4820 | printk(IBM_ERR "unable to register platform device\n"); | |
4821 | thinkpad_acpi_module_exit(); | |
4822 | return ret; | |
4823 | } | |
7fd40029 HMH |
4824 | tpacpi_sensors_pdev = platform_device_register_simple( |
4825 | IBM_HWMON_DRVR_NAME, | |
4826 | -1, NULL, 0); | |
4827 | if (IS_ERR(tpacpi_sensors_pdev)) { | |
4828 | ret = PTR_ERR(tpacpi_sensors_pdev); | |
4829 | tpacpi_sensors_pdev = NULL; | |
4830 | printk(IBM_ERR "unable to register hwmon platform device\n"); | |
4831 | thinkpad_acpi_module_exit(); | |
4832 | return ret; | |
4833 | } | |
4834 | ret = device_create_file(&tpacpi_sensors_pdev->dev, | |
4835 | &dev_attr_thinkpad_acpi_pdev_name); | |
4836 | if (ret) { | |
4837 | printk(IBM_ERR | |
4838 | "unable to create sysfs hwmon device attributes\n"); | |
4839 | thinkpad_acpi_module_exit(); | |
4840 | return ret; | |
4841 | } | |
4842 | tp_features.sensors_pdev_attrs_registered = 1; | |
4843 | tpacpi_hwmon = hwmon_device_register(&tpacpi_sensors_pdev->dev); | |
54ae1501 HMH |
4844 | if (IS_ERR(tpacpi_hwmon)) { |
4845 | ret = PTR_ERR(tpacpi_hwmon); | |
4846 | tpacpi_hwmon = NULL; | |
4847 | printk(IBM_ERR "unable to register hwmon device\n"); | |
4848 | thinkpad_acpi_module_exit(); | |
4849 | return ret; | |
4850 | } | |
8523ed6f | 4851 | mutex_init(&tpacpi_inputdev_send_mutex); |
7f5d1cd6 HMH |
4852 | tpacpi_inputdev = input_allocate_device(); |
4853 | if (!tpacpi_inputdev) { | |
4854 | printk(IBM_ERR "unable to allocate input device\n"); | |
4855 | thinkpad_acpi_module_exit(); | |
4856 | return -ENOMEM; | |
4857 | } else { | |
4858 | /* Prepare input device, but don't register */ | |
4859 | tpacpi_inputdev->name = "ThinkPad Extra Buttons"; | |
4860 | tpacpi_inputdev->phys = IBM_DRVR_NAME "/input0"; | |
4861 | tpacpi_inputdev->id.bustype = BUS_HOST; | |
edf0e0e5 HMH |
4862 | tpacpi_inputdev->id.vendor = (thinkpad_id.vendor) ? |
4863 | thinkpad_id.vendor : | |
4864 | PCI_VENDOR_ID_IBM; | |
7f5d1cd6 HMH |
4865 | tpacpi_inputdev->id.product = TPACPI_HKEY_INPUT_PRODUCT; |
4866 | tpacpi_inputdev->id.version = TPACPI_HKEY_INPUT_VERSION; | |
4867 | } | |
a5763f22 HMH |
4868 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
4869 | ret = ibm_init(&ibms_init[i]); | |
4870 | if (ret >= 0 && *ibms_init[i].param) | |
4871 | ret = ibms_init[i].data->write(ibms_init[i].param); | |
1da177e4 | 4872 | if (ret < 0) { |
1def7115 | 4873 | thinkpad_acpi_module_exit(); |
1da177e4 LT |
4874 | return ret; |
4875 | } | |
4876 | } | |
7f5d1cd6 HMH |
4877 | ret = input_register_device(tpacpi_inputdev); |
4878 | if (ret < 0) { | |
4879 | printk(IBM_ERR "unable to register input device\n"); | |
4880 | thinkpad_acpi_module_exit(); | |
4881 | return ret; | |
4882 | } else { | |
4883 | tp_features.input_device_registered = 1; | |
4884 | } | |
1da177e4 | 4885 | |
8fef502e | 4886 | tpacpi_lifecycle = TPACPI_LIFE_RUNNING; |
1da177e4 LT |
4887 | return 0; |
4888 | } | |
4889 | ||
1def7115 | 4890 | static void thinkpad_acpi_module_exit(void) |
56b6aeb0 | 4891 | { |
a5763f22 HMH |
4892 | struct ibm_struct *ibm, *itmp; |
4893 | ||
8fef502e HMH |
4894 | tpacpi_lifecycle = TPACPI_LIFE_EXITING; |
4895 | ||
a5763f22 HMH |
4896 | list_for_each_entry_safe_reverse(ibm, itmp, |
4897 | &tpacpi_all_drivers, | |
4898 | all_drivers) { | |
4899 | ibm_exit(ibm); | |
4900 | } | |
56b6aeb0 | 4901 | |
a5763f22 | 4902 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
56b6aeb0 | 4903 | |
7f5d1cd6 HMH |
4904 | if (tpacpi_inputdev) { |
4905 | if (tp_features.input_device_registered) | |
4906 | input_unregister_device(tpacpi_inputdev); | |
4907 | else | |
4908 | input_free_device(tpacpi_inputdev); | |
4909 | } | |
4910 | ||
54ae1501 HMH |
4911 | if (tpacpi_hwmon) |
4912 | hwmon_device_unregister(tpacpi_hwmon); | |
4913 | ||
7fd40029 HMH |
4914 | if (tp_features.sensors_pdev_attrs_registered) |
4915 | device_remove_file(&tpacpi_sensors_pdev->dev, | |
4916 | &dev_attr_thinkpad_acpi_pdev_name); | |
4917 | if (tpacpi_sensors_pdev) | |
4918 | platform_device_unregister(tpacpi_sensors_pdev); | |
54ae1501 HMH |
4919 | if (tpacpi_pdev) |
4920 | platform_device_unregister(tpacpi_pdev); | |
4921 | ||
ac36393d HMH |
4922 | if (tp_features.platform_drv_attrs_registered) |
4923 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); | |
4924 | ||
7fd40029 HMH |
4925 | if (tp_features.sensors_pdrv_registered) |
4926 | platform_driver_unregister(&tpacpi_hwmon_pdriver); | |
4927 | ||
ac36393d HMH |
4928 | if (tp_features.platform_drv_registered) |
4929 | platform_driver_unregister(&tpacpi_pdriver); | |
54ae1501 | 4930 | |
56b6aeb0 | 4931 | if (proc_dir) |
8d376cd6 | 4932 | remove_proc_entry(IBM_PROC_DIR, acpi_root_dir); |
56b6aeb0 | 4933 | |
d5a2f2f1 HMH |
4934 | kfree(thinkpad_id.bios_version_str); |
4935 | kfree(thinkpad_id.ec_version_str); | |
4936 | kfree(thinkpad_id.model_str); | |
56b6aeb0 HMH |
4937 | } |
4938 | ||
1def7115 HMH |
4939 | module_init(thinkpad_acpi_module_init); |
4940 | module_exit(thinkpad_acpi_module_exit); |