blob: e47eaf72763df65c29c0dfa99400973105f4c4c1 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -03002 * thinkpad_acpi.c - ThinkPad ACPI Extras
Linus Torvalds1da177e2005-04-16 15:20:36 -07003 *
4 *
Borislav Deianov78f81cc2005-08-17 00:00:00 -04005 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
Henrique de Moraes Holschuha62bc912007-03-23 17:33:58 -03006 * Copyright (C) 2006-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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
Henrique de Moraes Holschuha62bc912007-03-23 17:33:58 -030020 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 * 02110-1301, USA.
Borislav Deianov78f81cc2005-08-17 00:00:00 -040022 */
23
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -030024#define IBM_VERSION "0.14"
Borislav Deianov78f81cc2005-08-17 00:00:00 -040025
26/*
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 * Changelog:
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -030028 * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to
29 * drivers/misc.
Henrique de Moraes Holschuhf9ff43a2006-11-25 16:37:38 -020030 *
31 * 2006-11-22 0.13 new maintainer
32 * changelog now lives in git commit history, and will
33 * not be updated further in-file.
Henrique de Moraes Holschuh837ca6d2007-03-23 17:33:54 -030034 *
Borislav Deianov78f81cc2005-08-17 00:00:00 -040035 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
36 * 2005-03-17 0.11 support for 600e, 770x
37 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
38 * support for 770e, G41
39 * G40 and G41 don't have a thinklight
40 * temperatures no longer experimental
41 * experimental brightness control
42 * experimental volume control
43 * experimental fan enable/disable
Henrique de Moraes Holschuh837ca6d2007-03-23 17:33:54 -030044 * 2005-01-16 0.10 fix module loading on R30, R31
Borislav Deianov78f81cc2005-08-17 00:00:00 -040045 * 2005-01-16 0.9 support for 570, R30, R31
46 * ultrabay support on A22p, A3x
47 * limit arg for cmos, led, beep, drop experimental status
48 * more capable led control on A21e, A22p, T20-22, X20
49 * experimental temperatures and fan speed
50 * experimental embedded controller register dump
51 * mark more functions as __init, drop incorrect __exit
52 * use MODULE_VERSION
53 * thanks to Henrik Brix Andersen <brix@gentoo.org>
54 * fix parameter passing on module loading
55 * thanks to Rusty Russell <rusty@rustcorp.com.au>
56 * thanks to Jim Radford <radford@blackbean.org>
57 * 2004-11-08 0.8 fix init error case, don't return from a macro
58 * thanks to Chris Wright <chrisw@osdl.org>
59 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
60 * fix led control on A21e
61 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
63 * proc file format changed
64 * video_switch command
65 * experimental cmos control
66 * experimental led control
67 * experimental acpi sounds
Borislav Deianov78f81cc2005-08-17 00:00:00 -040068 * 2004-09-16 0.4 support for module parameters
69 * hotkey mask can be prefixed by 0x
70 * video output switching
71 * video expansion control
72 * ultrabay eject support
73 * removed lcd brightness/on/off control, didn't work
74 * 2004-08-17 0.3 support for R40
75 * lcd off, brightness control
76 * thinklight on/off
77 * 2004-08-14 0.2 support for T series, X20
78 * bluetooth enable/disable
79 * hotkey events disabled by default
80 * removed fan control, currently useless
81 * 2004-08-09 0.1 initial release, support for X series
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 */
83
Henrique de Moraes Holschuhf21f85d2007-03-29 01:58:40 -030084#include "thinkpad_acpi.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Henrique de Moraes Holschuhf9ff43a2006-11-25 16:37:38 -020086MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
Borislav Deianov78f81cc2005-08-17 00:00:00 -040087MODULE_DESCRIPTION(IBM_DESC);
88MODULE_VERSION(IBM_VERSION);
89MODULE_LICENSE("GPL");
90
Henrique de Moraes Holschuhd903ac52007-03-29 01:58:42 -030091/* Please remove this in year 2009 */
92MODULE_ALIAS("ibm_acpi");
93
Linus Torvalds1da177e2005-04-16 15:20:36 -070094#define __unused __attribute__ ((unused))
95
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -030096/****************************************************************************
97 ****************************************************************************
98 *
99 * ACPI Helpers and device model
100 *
101 ****************************************************************************
102 ****************************************************************************/
103
104/*************************************************************************
105 * ACPI basic handles
106 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108static acpi_handle root_handle = NULL;
109
110#define IBM_HANDLE(object, parent, paths...) \
111 static acpi_handle object##_handle; \
112 static acpi_handle *object##_parent = &parent##_handle; \
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400113 static char *object##_path; \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 static char *object##_paths[] = { paths }
115
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400116IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
117 "\\_SB.PCI.ISA.EC", /* 570 */
118 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
119 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
120 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
121 "\\_SB.PCI0.ICH3.EC0", /* R31 */
122 "\\_SB.PCI0.LPC.EC", /* all others */
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300123 );
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300125IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */
126IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300128
129/*************************************************************************
130 * Misc ACPI handles
131 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400133IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
134 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
135 "\\CMS", /* R40, R40e */
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300136 ); /* all others */
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400137
138IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
139 "^HKEY", /* R30, R31 */
140 "HKEY", /* all others */
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300141 ); /* 570 */
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400142
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400143
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300144/*************************************************************************
145 * ACPI helpers
Henrique de Moraes Holschuha8b7a662006-11-24 11:47:11 -0200146 */
147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148static int acpi_evalf(acpi_handle handle,
149 void *res, char *method, char *fmt, ...)
150{
151 char *fmt0 = fmt;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400152 struct acpi_object_list params;
153 union acpi_object in_objs[IBM_MAX_ACPI_ARGS];
154 struct acpi_buffer result, *resultp;
155 union acpi_object out_obj;
156 acpi_status status;
157 va_list ap;
158 char res_type;
159 int success;
160 int quiet;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
162 if (!*fmt) {
163 printk(IBM_ERR "acpi_evalf() called with empty format\n");
164 return 0;
165 }
166
167 if (*fmt == 'q') {
168 quiet = 1;
169 fmt++;
170 } else
171 quiet = 0;
172
173 res_type = *(fmt++);
174
175 params.count = 0;
176 params.pointer = &in_objs[0];
177
178 va_start(ap, fmt);
179 while (*fmt) {
180 char c = *(fmt++);
181 switch (c) {
182 case 'd': /* int */
183 in_objs[params.count].integer.value = va_arg(ap, int);
184 in_objs[params.count++].type = ACPI_TYPE_INTEGER;
185 break;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400186 /* add more types as needed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 default:
188 printk(IBM_ERR "acpi_evalf() called "
189 "with invalid format character '%c'\n", c);
190 return 0;
191 }
192 }
193 va_end(ap);
194
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400195 if (res_type != 'v') {
196 result.length = sizeof(out_obj);
197 result.pointer = &out_obj;
198 resultp = &result;
199 } else
200 resultp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400202 status = acpi_evaluate_object(handle, method, &params, resultp);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 switch (res_type) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400205 case 'd': /* int */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 if (res)
207 *(int *)res = out_obj.integer.value;
208 success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER;
209 break;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400210 case 'v': /* void */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 success = status == AE_OK;
212 break;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400213 /* add more types as needed */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 default:
215 printk(IBM_ERR "acpi_evalf() called "
216 "with invalid format character '%c'\n", res_type);
217 return 0;
218 }
219
220 if (!success && !quiet)
221 printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n",
222 method, fmt0, status);
223
224 return success;
225}
226
227static void __unused acpi_print_int(acpi_handle handle, char *method)
228{
229 int i;
230
231 if (acpi_evalf(handle, &i, method, "d"))
232 printk(IBM_INFO "%s = 0x%x\n", method, i);
233 else
234 printk(IBM_ERR "error calling %s\n", method);
235}
236
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300237static int acpi_ec_read(int i, u8 * p)
238{
239 int v;
240
241 if (ecrd_handle) {
242 if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i))
243 return 0;
244 *p = v;
245 } else {
246 if (ec_read(i, p) < 0)
247 return 0;
248 }
249
250 return 1;
251}
252
253static int acpi_ec_write(int i, u8 v)
254{
255 if (ecwr_handle) {
256 if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v))
257 return 0;
258 } else {
259 if (ec_write(i, v) < 0)
260 return 0;
261 }
262
263 return 1;
264}
265
266static int _sta(acpi_handle handle)
267{
268 int status;
269
270 if (!handle || !acpi_evalf(handle, &status, "_STA", "d"))
271 status = 0;
272
273 return status;
274}
275
Henrique de Moraes Holschuhc9bea992007-04-21 11:08:42 -0300276static int issue_thinkpad_cmos_command(int cmos_cmd)
277{
278 if (!cmos_handle)
279 return -ENXIO;
280
281 if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd))
282 return -EIO;
283
284 return 0;
285}
286
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300287/*************************************************************************
288 * ACPI device model
289 */
290
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300291static void drv_acpi_handle_init(char *name,
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -0300292 acpi_handle *handle, acpi_handle parent,
293 char **paths, int num_paths, char **path)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300294{
295 int i;
296 acpi_status status;
297
298 for (i = 0; i < num_paths; i++) {
299 status = acpi_get_handle(parent, paths[i], handle);
300 if (ACPI_SUCCESS(status)) {
301 *path = paths[i];
302 return;
303 }
304 }
305
306 *handle = NULL;
307}
308
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300309static void dispatch_acpi_notify(acpi_handle handle, u32 event, void *data)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300310{
311 struct ibm_struct *ibm = data;
312
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300313 if (!ibm || !ibm->acpi || !ibm->acpi->notify)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300314 return;
315
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300316 ibm->acpi->notify(ibm, event);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300317}
318
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300319static int __init setup_acpi_notify(struct ibm_struct *ibm)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300320{
321 acpi_status status;
322 int ret;
323
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300324 BUG_ON(!ibm->acpi);
325
326 if (!*ibm->acpi->handle)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300327 return 0;
328
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300329 dbg_printk(TPACPI_DBG_INIT,
330 "setting up ACPI notify for %s\n", ibm->name);
331
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300332 ret = acpi_bus_get_device(*ibm->acpi->handle, &ibm->acpi->device);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300333 if (ret < 0) {
334 printk(IBM_ERR "%s device not present\n", ibm->name);
335 return -ENODEV;
336 }
337
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300338 acpi_driver_data(ibm->acpi->device) = ibm;
339 sprintf(acpi_device_class(ibm->acpi->device), "%s/%s",
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -0300340 IBM_ACPI_EVENT_PREFIX,
341 ibm->name);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300342
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300343 status = acpi_install_notify_handler(*ibm->acpi->handle,
344 ibm->acpi->type, dispatch_acpi_notify, ibm);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300345 if (ACPI_FAILURE(status)) {
346 if (status == AE_ALREADY_EXISTS) {
347 printk(IBM_NOTICE "another device driver is already handling %s events\n",
348 ibm->name);
349 } else {
350 printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n",
351 ibm->name, status);
352 }
353 return -ENODEV;
354 }
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300355 ibm->flags.acpi_notify_installed = 1;
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300356 return 0;
357}
358
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300359static int __init tpacpi_device_add(struct acpi_device *device)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300360{
361 return 0;
362}
363
Henrique de Moraes Holschuh67001212007-04-21 11:08:25 -0300364static int __init register_tpacpi_subdriver(struct ibm_struct *ibm)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300365{
366 int ret;
367
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300368 dbg_printk(TPACPI_DBG_INIT,
369 "registering %s as an ACPI driver\n", ibm->name);
370
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300371 BUG_ON(!ibm->acpi);
372
373 ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL);
374 if (!ibm->acpi->driver) {
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -0300375 printk(IBM_ERR "kzalloc(ibm->driver) failed\n");
376 return -ENOMEM;
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300377 }
378
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300379 sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name);
380 ibm->acpi->driver->ids = ibm->acpi->hid;
381 ibm->acpi->driver->ops.add = &tpacpi_device_add;
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300382
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300383 ret = acpi_bus_register_driver(ibm->acpi->driver);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300384 if (ret < 0) {
385 printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n",
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300386 ibm->acpi->hid, ret);
387 kfree(ibm->acpi->driver);
388 ibm->acpi->driver = NULL;
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -0300389 } else if (!ret)
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300390 ibm->flags.acpi_driver_registered = 1;
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300391
392 return ret;
393}
394
395
396/****************************************************************************
397 ****************************************************************************
398 *
399 * Procfs Helpers
400 *
401 ****************************************************************************
402 ****************************************************************************/
403
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300404static int dispatch_procfs_read(char *page, char **start, off_t off,
405 int count, int *eof, void *data)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300406{
407 struct ibm_struct *ibm = data;
408 int len;
409
410 if (!ibm || !ibm->read)
411 return -EINVAL;
412
413 len = ibm->read(page);
414 if (len < 0)
415 return len;
416
417 if (len <= off + count)
418 *eof = 1;
419 *start = page + off;
420 len -= off;
421 if (len > count)
422 len = count;
423 if (len < 0)
424 len = 0;
425
426 return len;
427}
428
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300429static int dispatch_procfs_write(struct file *file,
430 const char __user * userbuf,
431 unsigned long count, void *data)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300432{
433 struct ibm_struct *ibm = data;
434 char *kernbuf;
435 int ret;
436
437 if (!ibm || !ibm->write)
438 return -EINVAL;
439
440 kernbuf = kmalloc(count + 2, GFP_KERNEL);
441 if (!kernbuf)
442 return -ENOMEM;
443
444 if (copy_from_user(kernbuf, userbuf, count)) {
445 kfree(kernbuf);
446 return -EFAULT;
447 }
448
449 kernbuf[count] = 0;
450 strcat(kernbuf, ",");
451 ret = ibm->write(kernbuf);
452 if (ret == 0)
453 ret = count;
454
455 kfree(kernbuf);
456
457 return ret;
458}
459
Linus Torvalds1da177e2005-04-16 15:20:36 -0700460static char *next_cmd(char **cmds)
461{
462 char *start = *cmds;
463 char *end;
464
465 while ((end = strchr(start, ',')) && end == start)
466 start = end + 1;
467
468 if (!end)
469 return NULL;
470
471 *end = 0;
472 *cmds = end + 1;
473 return start;
474}
475
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300476
477/****************************************************************************
478 ****************************************************************************
479 *
Henrique de Moraes Holschuh54ae1502007-04-24 11:48:12 -0300480 * Device model: hwmon and platform
481 *
482 ****************************************************************************
483 ****************************************************************************/
484
485static struct platform_device *tpacpi_pdev = NULL;
486static struct class_device *tpacpi_hwmon = NULL;
487
488static struct platform_driver tpacpi_pdriver = {
489 .driver = {
490 .name = IBM_DRVR_NAME,
491 .owner = THIS_MODULE,
492 },
493};
494
495
496/****************************************************************************
497 ****************************************************************************
498 *
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300499 * Subdrivers
500 *
501 ****************************************************************************
502 ****************************************************************************/
503
504/*************************************************************************
Henrique de Moraes Holschuh142cfc92007-04-21 11:08:26 -0300505 * thinkpad-acpi init subdriver
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300506 */
507
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -0300508static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509{
510 printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION);
511 printk(IBM_INFO "%s\n", IBM_URL);
512
Henrique de Moraes Holschuh3945ac32007-02-06 19:13:44 -0200513 if (ibm_thinkpad_ec_found)
514 printk(IBM_INFO "ThinkPad EC firmware %s\n",
515 ibm_thinkpad_ec_found);
516
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 return 0;
518}
519
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -0300520static int thinkpad_acpi_driver_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521{
522 int len = 0;
523
524 len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC);
525 len += sprintf(p + len, "version:\t%s\n", IBM_VERSION);
526
527 return len;
528}
529
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -0300530static struct ibm_struct thinkpad_acpi_driver_data = {
531 .name = "driver",
532 .read = thinkpad_acpi_driver_read,
533};
534
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300535/*************************************************************************
536 * Hotkey subdriver
537 */
538
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400539static int hotkey_orig_status;
540static int hotkey_orig_mask;
541
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -0300542static int __init hotkey_init(struct ibm_init_struct *iibm)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300543{
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300544 int res;
545
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300546 vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n");
547
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300548 IBM_ACPIHANDLE_INIT(hkey);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -0300549
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300550 /* hotkey not supported on 570 */
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300551 tp_features.hotkey = hkey_handle != NULL;
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300552
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300553 vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n",
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300554 str_supported(tp_features.hotkey));
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300555
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300556 if (tp_features.hotkey) {
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300557 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
558 A30, R30, R31, T20-22, X20-21, X22-24 */
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300559 tp_features.hotkey_mask =
560 acpi_evalf(hkey_handle, NULL, "DHKN", "qv");
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300561
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300562 vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n",
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300563 str_supported(tp_features.hotkey_mask));
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300564
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300565 res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask);
566 if (res)
567 return res;
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300568 }
569
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300570 return (tp_features.hotkey)? 0 : 1;
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300571}
572
573static void hotkey_exit(void)
574{
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300575 int res;
576
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300577 if (tp_features.hotkey) {
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300578 dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n");
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300579 res = hotkey_set(hotkey_orig_status, hotkey_orig_mask);
580 if (res)
581 printk(IBM_ERR "failed to restore hotkey to BIOS defaults\n");
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -0300582 }
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300583}
584
585static void hotkey_notify(struct ibm_struct *ibm, u32 event)
586{
587 int hkey;
588
589 if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d"))
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300590 acpi_bus_generate_event(ibm->acpi->device, event, hkey);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300591 else {
592 printk(IBM_ERR "unknown hotkey event %d\n", event);
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300593 acpi_bus_generate_event(ibm->acpi->device, event, 0);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300594 }
595}
596
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400597static int hotkey_get(int *status, int *mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598{
599 if (!acpi_evalf(hkey_handle, status, "DHKC", "d"))
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300600 return -EIO;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400601
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300602 if (tp_features.hotkey_mask)
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400603 if (!acpi_evalf(hkey_handle, mask, "DHKN", "d"))
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300604 return -EIO;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400605
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300606 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607}
608
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400609static int hotkey_set(int status, int mask)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700610{
611 int i;
612
613 if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status))
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300614 return -EIO;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300616 if (tp_features.hotkey_mask)
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400617 for (i = 0; i < 32; i++) {
618 int bit = ((1 << i) & mask) != 0;
619 if (!acpi_evalf(hkey_handle,
620 NULL, "MHKM", "vdd", i + 1, bit))
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300621 return -EIO;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400622 }
623
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300624 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400625}
626
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400627static int hotkey_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628{
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300629 int res, status, mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 int len = 0;
631
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300632 if (!tp_features.hotkey) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400633 len += sprintf(p + len, "status:\t\tnot supported\n");
634 return len;
635 }
636
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300637 res = hotkey_get(&status, &mask);
638 if (res)
639 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640
641 len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0));
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300642 if (tp_features.hotkey_mask) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700643 len += sprintf(p + len, "mask:\t\t0x%04x\n", mask);
644 len += sprintf(p + len,
645 "commands:\tenable, disable, reset, <mask>\n");
646 } else {
647 len += sprintf(p + len, "mask:\t\tnot supported\n");
648 len += sprintf(p + len, "commands:\tenable, disable, reset\n");
649 }
650
651 return len;
652}
653
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400654static int hotkey_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700655{
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300656 int res, status, mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 char *cmd;
658 int do_cmd = 0;
659
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300660 if (!tp_features.hotkey)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 return -ENODEV;
662
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300663 res = hotkey_get(&status, &mask);
664 if (res)
665 return res;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 while ((cmd = next_cmd(&buf))) {
668 if (strlencmp(cmd, "enable") == 0) {
669 status = 1;
670 } else if (strlencmp(cmd, "disable") == 0) {
671 status = 0;
672 } else if (strlencmp(cmd, "reset") == 0) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400673 status = hotkey_orig_status;
674 mask = hotkey_orig_mask;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700675 } else if (sscanf(cmd, "0x%x", &mask) == 1) {
676 /* mask set */
677 } else if (sscanf(cmd, "%x", &mask) == 1) {
678 /* mask set */
679 } else
680 return -EINVAL;
681 do_cmd = 1;
682 }
683
Henrique de Moraes Holschuhb86c4722007-04-21 11:08:39 -0300684 if (do_cmd) {
685 res = hotkey_set(status, mask);
686 if (res)
687 return res;
688 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689
690 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400691}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300693static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = {
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -0300694 .hid = IBM_HKEY_HID,
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -0300695 .notify = hotkey_notify,
696 .handle = &hkey_handle,
697 .type = ACPI_DEVICE_NOTIFY,
698};
699
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300700static struct ibm_struct hotkey_driver_data = {
701 .name = "hotkey",
702 .read = hotkey_read,
703 .write = hotkey_write,
704 .exit = hotkey_exit,
705 .acpi = &ibm_hotkey_acpidriver,
706};
707
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300708/*************************************************************************
709 * Bluetooth subdriver
710 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700711
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -0300712static int __init bluetooth_init(struct ibm_init_struct *iibm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713{
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300714 int status = 0;
715
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300716 vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n");
717
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300718 IBM_ACPIHANDLE_INIT(hkey);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -0300719
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400720 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
721 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300722 tp_features.bluetooth = hkey_handle &&
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300723 acpi_evalf(hkey_handle, &status, "GBDC", "qd");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300725 vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n",
726 str_supported(tp_features.bluetooth),
727 status);
728
729 if (tp_features.bluetooth &&
730 !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) {
731 /* no bluetooth hardware present in system */
732 tp_features.bluetooth = 0;
733 dbg_printk(TPACPI_DBG_INIT,
734 "bluetooth hardware not installed\n");
735 }
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300736
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300737 return (tp_features.bluetooth)? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738}
739
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300740static int bluetooth_get_radiosw(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741{
742 int status;
743
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300744 if (!tp_features.bluetooth)
745 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300747 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
748 return -EIO;
749
750 return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0);
751}
752
753static int bluetooth_set_radiosw(int radio_on)
754{
755 int status;
756
757 if (!tp_features.bluetooth)
758 return -ENODEV;
759
760 if (!acpi_evalf(hkey_handle, &status, "GBDC", "d"))
761 return -EIO;
762 if (radio_on)
763 status |= TP_ACPI_BLUETOOTH_RADIOSSW;
764 else
765 status &= ~TP_ACPI_BLUETOOTH_RADIOSSW;
766 if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status))
767 return -EIO;
768
769 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700770}
771
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400772static int bluetooth_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773{
774 int len = 0;
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300775 int status = bluetooth_get_radiosw();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300777 if (!tp_features.bluetooth)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778 len += sprintf(p + len, "status:\t\tnot supported\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 else {
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300780 len += sprintf(p + len, "status:\t\t%s\n",
781 (status)? "enabled" : "disabled");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 len += sprintf(p + len, "commands:\tenable, disable\n");
783 }
784
785 return len;
786}
787
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400788static int bluetooth_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700790 char *cmd;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300792 if (!tp_features.bluetooth)
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400793 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700794
795 while ((cmd = next_cmd(&buf))) {
796 if (strlencmp(cmd, "enable") == 0) {
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300797 bluetooth_set_radiosw(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 } else if (strlencmp(cmd, "disable") == 0) {
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300799 bluetooth_set_radiosw(0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700800 } else
801 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802 }
803
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 return 0;
805}
806
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -0300807static struct ibm_struct bluetooth_driver_data = {
808 .name = "bluetooth",
809 .read = bluetooth_read,
810 .write = bluetooth_write,
811};
812
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300813/*************************************************************************
814 * Wan subdriver
815 */
816
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -0300817static int __init wan_init(struct ibm_init_struct *iibm)
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400818{
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300819 int status = 0;
820
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300821 vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n");
822
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300823 IBM_ACPIHANDLE_INIT(hkey);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -0300824
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300825 tp_features.wan = hkey_handle &&
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300826 acpi_evalf(hkey_handle, &status, "GWAN", "qd");
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400827
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300828 vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n",
829 str_supported(tp_features.wan),
830 status);
831
832 if (tp_features.wan &&
833 !(status & TP_ACPI_WANCARD_HWPRESENT)) {
834 /* no wan hardware present in system */
835 tp_features.wan = 0;
836 dbg_printk(TPACPI_DBG_INIT,
837 "wan hardware not installed\n");
838 }
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300839
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300840 return (tp_features.wan)? 0 : 1;
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400841}
842
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300843static int wan_get_radiosw(void)
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400844{
845 int status;
846
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300847 if (!tp_features.wan)
848 return -ENODEV;
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400849
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300850 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
851 return -EIO;
852
853 return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0);
854}
855
856static int wan_set_radiosw(int radio_on)
857{
858 int status;
859
860 if (!tp_features.wan)
861 return -ENODEV;
862
863 if (!acpi_evalf(hkey_handle, &status, "GWAN", "d"))
864 return -EIO;
865 if (radio_on)
866 status |= TP_ACPI_WANCARD_RADIOSSW;
867 else
868 status &= ~TP_ACPI_WANCARD_RADIOSSW;
869 if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status))
870 return -EIO;
871
872 return 0;
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400873}
874
875static int wan_read(char *p)
876{
877 int len = 0;
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300878 int status = wan_get_radiosw();
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400879
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300880 if (!tp_features.wan)
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400881 len += sprintf(p + len, "status:\t\tnot supported\n");
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400882 else {
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300883 len += sprintf(p + len, "status:\t\t%s\n",
884 (status)? "enabled" : "disabled");
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400885 len += sprintf(p + len, "commands:\tenable, disable\n");
886 }
887
888 return len;
889}
890
891static int wan_write(char *buf)
892{
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400893 char *cmd;
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400894
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -0300895 if (!tp_features.wan)
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400896 return -ENODEV;
897
898 while ((cmd = next_cmd(&buf))) {
899 if (strlencmp(cmd, "enable") == 0) {
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300900 wan_set_radiosw(1);
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400901 } else if (strlencmp(cmd, "disable") == 0) {
Henrique de Moraes Holschuhd6fdd1e2007-04-21 11:08:40 -0300902 wan_set_radiosw(0);
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400903 } else
904 return -EINVAL;
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400905 }
906
Jeremy Fitzhardinge42adb532006-06-01 17:41:00 -0400907 return 0;
908}
909
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -0300910static struct ibm_struct wan_driver_data = {
911 .name = "wan",
912 .read = wan_read,
913 .write = wan_write,
Henrique de Moraes Holschuh92641172007-04-21 11:08:35 -0300914 .flags.experimental = 1,
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -0300915};
916
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300917/*************************************************************************
918 * Video subdriver
919 */
920
Henrique de Moraes Holschuh9a8e1732006-11-25 16:36:00 -0200921static enum video_access_mode video_supported;
922static int video_orig_autosw;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400923
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300924IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */
925 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
926 "\\_SB.PCI0.VID0", /* 770e */
927 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
928 "\\_SB.PCI0.AGP.VID", /* all others */
929 ); /* R30, R31 */
930
931IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */
932
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -0300933static int __init video_init(struct ibm_init_struct *iibm)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934{
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400935 int ivga;
936
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300937 vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n");
938
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -0300939 IBM_ACPIHANDLE_INIT(vid);
940 IBM_ACPIHANDLE_INIT(vid2);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -0300941
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400942 if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga)
943 /* G41, assume IVGA doesn't change */
944 vid_handle = vid2_handle;
945
946 if (!vid_handle)
947 /* video switching not supported on R30, R31 */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300948 video_supported = TPACPI_VIDEO_NONE;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400949 else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd"))
950 /* 570 */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300951 video_supported = TPACPI_VIDEO_570;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400952 else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd"))
953 /* 600e/x, 770e, 770x */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300954 video_supported = TPACPI_VIDEO_770;
Borislav Deianov78f81cc2005-08-17 00:00:00 -0400955 else
956 /* all others */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300957 video_supported = TPACPI_VIDEO_NEW;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -0300959 vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n",
960 str_supported(video_supported != TPACPI_VIDEO_NONE),
961 video_supported);
962
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -0300963 return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964}
965
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300966static void video_exit(void)
967{
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -0300968 dbg_printk(TPACPI_DBG_EXIT,
969 "restoring original video autoswitch mode\n");
970 if (video_autosw_set(video_orig_autosw))
971 printk(IBM_ERR "error while trying to restore original "
972 "video autoswitch mode\n");
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -0300973}
974
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -0300975static int video_outputsw_get(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
977 int status = 0;
978 int i;
979
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -0300980 switch (video_supported) {
981 case TPACPI_VIDEO_570:
982 if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd",
983 TP_ACPI_VIDEO_570_PHSCMD))
984 return -EIO;
985 status = i & TP_ACPI_VIDEO_570_PHSMASK;
986 break;
987 case TPACPI_VIDEO_770:
988 if (!acpi_evalf(NULL, &i, "\\VCDL", "d"))
989 return -EIO;
990 if (i)
991 status |= TP_ACPI_VIDEO_S_LCD;
992 if (!acpi_evalf(NULL, &i, "\\VCDC", "d"))
993 return -EIO;
994 if (i)
995 status |= TP_ACPI_VIDEO_S_CRT;
996 break;
997 case TPACPI_VIDEO_NEW:
998 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) ||
999 !acpi_evalf(NULL, &i, "\\VCDC", "d"))
1000 return -EIO;
1001 if (i)
1002 status |= TP_ACPI_VIDEO_S_CRT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001003
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001004 if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) ||
1005 !acpi_evalf(NULL, &i, "\\VCDL", "d"))
1006 return -EIO;
1007 if (i)
1008 status |= TP_ACPI_VIDEO_S_LCD;
1009 if (!acpi_evalf(NULL, &i, "\\VCDD", "d"))
1010 return -EIO;
1011 if (i)
1012 status |= TP_ACPI_VIDEO_S_DVI;
1013 break;
1014 default:
1015 return -ENOSYS;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001016 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017
1018 return status;
1019}
1020
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001021static int video_outputsw_set(int status)
1022{
1023 int autosw;
1024 int res = 0;
1025
1026 switch (video_supported) {
1027 case TPACPI_VIDEO_570:
1028 res = acpi_evalf(NULL, NULL,
1029 "\\_SB.PHS2", "vdd",
1030 TP_ACPI_VIDEO_570_PHS2CMD,
1031 status | TP_ACPI_VIDEO_570_PHS2SET);
1032 break;
1033 case TPACPI_VIDEO_770:
1034 autosw = video_autosw_get();
1035 if (autosw < 0)
1036 return autosw;
1037
1038 res = video_autosw_set(1);
1039 if (res)
1040 return res;
1041 res = acpi_evalf(vid_handle, NULL,
1042 "ASWT", "vdd", status * 0x100, 0);
1043 if (!autosw && video_autosw_set(autosw)) {
1044 printk(IBM_ERR "video auto-switch left enabled due to error\n");
1045 return -EIO;
1046 }
1047 break;
1048 case TPACPI_VIDEO_NEW:
1049 res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) &&
1050 acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1);
1051 break;
1052 default:
1053 return -ENOSYS;
1054 }
1055
1056 return (res)? 0 : -EIO;
1057}
1058
1059static int video_autosw_get(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001060{
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001061 int autosw = 0;
1062
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001063 switch (video_supported) {
1064 case TPACPI_VIDEO_570:
1065 if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d"))
1066 return -EIO;
1067 break;
1068 case TPACPI_VIDEO_770:
1069 case TPACPI_VIDEO_NEW:
1070 if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d"))
1071 return -EIO;
1072 break;
1073 default:
1074 return -ENOSYS;
1075 }
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001076
1077 return autosw & 1;
1078}
1079
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001080static int video_autosw_set(int enable)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001081{
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001082 if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0))
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001083 return -EIO;
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001084 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001085}
1086
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001087static int video_outputsw_cycle(void)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001088{
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001089 int autosw = video_autosw_get();
1090 int res;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001091
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001092 if (autosw < 0)
1093 return autosw;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001094
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001095 switch (video_supported) {
1096 case TPACPI_VIDEO_570:
1097 res = video_autosw_set(1);
1098 if (res)
1099 return res;
1100 res = acpi_evalf(ec_handle, NULL, "_Q16", "v");
1101 break;
1102 case TPACPI_VIDEO_770:
1103 case TPACPI_VIDEO_NEW:
1104 res = video_autosw_set(1);
1105 if (res)
1106 return res;
1107 res = acpi_evalf(vid_handle, NULL, "VSWT", "v");
1108 break;
1109 default:
1110 return -ENOSYS;
1111 }
1112 if (!autosw && video_autosw_set(autosw)) {
1113 printk(IBM_ERR "video auto-switch left enabled due to error\n");
1114 return -EIO;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001115 }
1116
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001117 return (res)? 0 : -EIO;
1118}
1119
1120static int video_expand_toggle(void)
1121{
1122 switch (video_supported) {
1123 case TPACPI_VIDEO_570:
1124 return acpi_evalf(ec_handle, NULL, "_Q17", "v")?
1125 0 : -EIO;
1126 case TPACPI_VIDEO_770:
1127 return acpi_evalf(vid_handle, NULL, "VEXP", "v")?
1128 0 : -EIO;
1129 case TPACPI_VIDEO_NEW:
1130 return acpi_evalf(NULL, NULL, "\\VEXP", "v")?
1131 0 : -EIO;
1132 default:
1133 return -ENOSYS;
1134 }
1135 /* not reached */
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001136}
1137
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001138static int video_read(char *p)
1139{
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001140 int status, autosw;
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001141 int len = 0;
1142
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001143 if (video_supported == TPACPI_VIDEO_NONE) {
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001144 len += sprintf(p + len, "status:\t\tnot supported\n");
1145 return len;
1146 }
1147
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001148 status = video_outputsw_get();
1149 if (status < 0)
1150 return status;
1151
1152 autosw = video_autosw_get();
1153 if (autosw < 0)
1154 return autosw;
1155
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001156 len += sprintf(p + len, "status:\t\tsupported\n");
1157 len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0));
1158 len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1));
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001159 if (video_supported == TPACPI_VIDEO_NEW)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001160 len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3));
1161 len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0));
1162 len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n");
1163 len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n");
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001164 if (video_supported == TPACPI_VIDEO_NEW)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001165 len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n");
1166 len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n");
1167 len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n");
1168
1169 return len;
1170}
1171
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001172static int video_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173{
1174 char *cmd;
1175 int enable, disable, status;
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001176 int res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001178 if (video_supported == TPACPI_VIDEO_NONE)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001179 return -ENODEV;
1180
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001181 enable = 0;
1182 disable = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001183
1184 while ((cmd = next_cmd(&buf))) {
1185 if (strlencmp(cmd, "lcd_enable") == 0) {
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001186 enable |= TP_ACPI_VIDEO_S_LCD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 } else if (strlencmp(cmd, "lcd_disable") == 0) {
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001188 disable |= TP_ACPI_VIDEO_S_LCD;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001189 } else if (strlencmp(cmd, "crt_enable") == 0) {
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001190 enable |= TP_ACPI_VIDEO_S_CRT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001191 } else if (strlencmp(cmd, "crt_disable") == 0) {
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001192 disable |= TP_ACPI_VIDEO_S_CRT;
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001193 } else if (video_supported == TPACPI_VIDEO_NEW &&
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001194 strlencmp(cmd, "dvi_enable") == 0) {
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001195 enable |= TP_ACPI_VIDEO_S_DVI;
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001196 } else if (video_supported == TPACPI_VIDEO_NEW &&
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001197 strlencmp(cmd, "dvi_disable") == 0) {
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001198 disable |= TP_ACPI_VIDEO_S_DVI;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199 } else if (strlencmp(cmd, "auto_enable") == 0) {
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001200 res = video_autosw_set(1);
1201 if (res)
1202 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001203 } else if (strlencmp(cmd, "auto_disable") == 0) {
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001204 res = video_autosw_set(0);
1205 if (res)
1206 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207 } else if (strlencmp(cmd, "video_switch") == 0) {
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001208 res = video_outputsw_cycle();
1209 if (res)
1210 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001211 } else if (strlencmp(cmd, "expand_toggle") == 0) {
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001212 res = video_expand_toggle();
1213 if (res)
1214 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001215 } else
1216 return -EINVAL;
1217 }
1218
1219 if (enable || disable) {
Henrique de Moraes Holschuh83f34722007-04-21 11:08:41 -03001220 status = video_outputsw_get();
1221 if (status < 0)
1222 return status;
1223 res = video_outputsw_set((status & ~disable) | enable);
1224 if (res)
1225 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001226 }
1227
1228 return 0;
1229}
1230
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001231static struct ibm_struct video_driver_data = {
1232 .name = "video",
1233 .read = video_read,
1234 .write = video_write,
1235 .exit = video_exit,
1236};
1237
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001238/*************************************************************************
1239 * Light (thinklight) subdriver
1240 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001241
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001242IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
1243IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */
1244
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001245static int __init light_init(struct ibm_init_struct *iibm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001246{
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001247 vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n");
1248
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001249 IBM_ACPIHANDLE_INIT(ledb);
1250 IBM_ACPIHANDLE_INIT(lght);
1251 IBM_ACPIHANDLE_INIT(cmos);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001252
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001253 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001254 tp_features.light = (cmos_handle || lght_handle) && !ledb_handle;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001255
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001256 if (tp_features.light)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001257 /* light status not supported on
1258 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001259 tp_features.light_status =
1260 acpi_evalf(ec_handle, NULL, "KBLT", "qv");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001261
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001262 vdbg_printk(TPACPI_DBG_INIT, "light is %s\n",
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001263 str_supported(tp_features.light));
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001264
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001265 return (tp_features.light)? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001266}
1267
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001268static int light_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001269{
1270 int len = 0;
1271 int status = 0;
1272
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001273 if (!tp_features.light) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001274 len += sprintf(p + len, "status:\t\tnot supported\n");
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001275 } else if (!tp_features.light_status) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001276 len += sprintf(p + len, "status:\t\tunknown\n");
1277 len += sprintf(p + len, "commands:\ton, off\n");
1278 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001279 if (!acpi_evalf(ec_handle, &status, "KBLT", "d"))
1280 return -EIO;
1281 len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0));
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001282 len += sprintf(p + len, "commands:\ton, off\n");
1283 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001284
1285 return len;
1286}
1287
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001288static int light_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001289{
1290 int cmos_cmd, lght_cmd;
1291 char *cmd;
1292 int success;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001293
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001294 if (!tp_features.light)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001295 return -ENODEV;
1296
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297 while ((cmd = next_cmd(&buf))) {
1298 if (strlencmp(cmd, "on") == 0) {
1299 cmos_cmd = 0x0c;
1300 lght_cmd = 1;
1301 } else if (strlencmp(cmd, "off") == 0) {
1302 cmos_cmd = 0x0d;
1303 lght_cmd = 0;
1304 } else
1305 return -EINVAL;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001306
Linus Torvalds1da177e2005-04-16 15:20:36 -07001307 success = cmos_handle ?
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001308 acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) :
1309 acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 if (!success)
1311 return -EIO;
1312 }
1313
1314 return 0;
1315}
1316
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001317static struct ibm_struct light_driver_data = {
1318 .name = "light",
1319 .read = light_read,
1320 .write = light_write,
1321};
1322
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001323/*************************************************************************
1324 * Dock subdriver
1325 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001326
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -03001327#ifdef CONFIG_THINKPAD_ACPI_DOCK
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001328
1329IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */
1330 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
1331 "\\_SB.PCI0.PCI1.DOCK", /* all others */
1332 "\\_SB.PCI.ISA.SLCE", /* 570 */
1333 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
1334
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001335/* don't list other alternatives as we install a notify handler on the 570 */
1336IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */
1337
Linus Torvalds1da177e2005-04-16 15:20:36 -07001338#define dock_docked() (_sta(dock_handle) & 1)
1339
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001340static int __init dock_init(struct ibm_init_struct *iibm)
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001341{
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001342 vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n");
1343
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001344 IBM_ACPIHANDLE_INIT(dock);
1345 IBM_ACPIHANDLE_INIT(pci);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001346
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001347 vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n",
1348 str_supported(dock_handle != NULL));
1349
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001350 return (dock_handle)? 0 : 1;
1351}
1352
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001353static void dock_notify(struct ibm_struct *ibm, u32 event)
1354{
1355 int docked = dock_docked();
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001356 int pci = ibm->acpi->hid && strstr(ibm->acpi->hid, IBM_PCI_HID);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001357
1358 if (event == 1 && !pci) /* 570 */
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001359 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001360 else if (event == 1 && pci) /* 570 */
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001361 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001362 else if (event == 3 && docked)
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001363 acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001364 else if (event == 3 && !docked)
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001365 acpi_bus_generate_event(ibm->acpi->device, event, 2); /* undock */
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001366 else if (event == 0 && docked)
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001367 acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001368 else {
1369 printk(IBM_ERR "unknown dock event %d, status %d\n",
1370 event, _sta(dock_handle));
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001371 acpi_bus_generate_event(ibm->acpi->device, event, 0); /* unknown */
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001372 }
1373}
1374
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001375static int dock_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001376{
1377 int len = 0;
1378 int docked = dock_docked();
1379
1380 if (!dock_handle)
1381 len += sprintf(p + len, "status:\t\tnot supported\n");
1382 else if (!docked)
1383 len += sprintf(p + len, "status:\t\tundocked\n");
1384 else {
1385 len += sprintf(p + len, "status:\t\tdocked\n");
1386 len += sprintf(p + len, "commands:\tdock, undock\n");
1387 }
1388
1389 return len;
1390}
1391
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001392static int dock_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393{
1394 char *cmd;
1395
1396 if (!dock_docked())
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001397 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001398
1399 while ((cmd = next_cmd(&buf))) {
1400 if (strlencmp(cmd, "undock") == 0) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001401 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) ||
1402 !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001403 return -EIO;
1404 } else if (strlencmp(cmd, "dock") == 0) {
1405 if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1))
1406 return -EIO;
1407 } else
1408 return -EINVAL;
1409 }
1410
1411 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001412}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001413
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001414static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = {
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001415 {
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001416 .notify = dock_notify,
1417 .handle = &dock_handle,
1418 .type = ACPI_SYSTEM_NOTIFY,
1419 },
1420 {
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001421 .hid = IBM_PCI_HID,
1422 .notify = dock_notify,
1423 .handle = &pci_handle,
1424 .type = ACPI_SYSTEM_NOTIFY,
1425 },
1426};
1427
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001428static struct ibm_struct dock_driver_data[2] = {
1429 {
1430 .name = "dock",
1431 .read = dock_read,
1432 .write = dock_write,
1433 .acpi = &ibm_dock_acpidriver[0],
1434 },
1435 {
1436 .name = "dock",
1437 .acpi = &ibm_dock_acpidriver[1],
1438 },
1439};
1440
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -03001441#endif /* CONFIG_THINKPAD_ACPI_DOCK */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001442
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001443/*************************************************************************
1444 * Bay subdriver
1445 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001446
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -03001447#ifdef CONFIG_THINKPAD_ACPI_BAY
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001448IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
1449 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
1450 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
1451 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
1452 ); /* A21e, R30, R31 */
1453IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */
1454 "_EJ0", /* all others */
1455 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
1456IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
1457 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
1458 ); /* all others */
1459IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */
1460 "_EJ0", /* 770x */
1461 ); /* all others */
1462
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001463static int __init bay_init(struct ibm_init_struct *iibm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001464{
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001465 vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n");
1466
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001467 IBM_ACPIHANDLE_INIT(bay);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001468 if (bay_handle)
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001469 IBM_ACPIHANDLE_INIT(bay_ej);
1470 IBM_ACPIHANDLE_INIT(bay2);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001471 if (bay2_handle)
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001472 IBM_ACPIHANDLE_INIT(bay2_ej);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001473
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001474 tp_features.bay_status = bay_handle &&
1475 acpi_evalf(bay_handle, NULL, "_STA", "qv");
1476 tp_features.bay_status2 = bay2_handle &&
1477 acpi_evalf(bay2_handle, NULL, "_STA", "qv");
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001478
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001479 tp_features.bay_eject = bay_handle && bay_ej_handle &&
1480 (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental);
1481 tp_features.bay_eject2 = bay2_handle && bay2_ej_handle &&
1482 (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001484 vdbg_printk(TPACPI_DBG_INIT,
1485 "bay 1: status %s, eject %s; bay 2: status %s, eject %s\n",
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001486 str_supported(tp_features.bay_status),
1487 str_supported(tp_features.bay_eject),
1488 str_supported(tp_features.bay_status2),
1489 str_supported(tp_features.bay_eject2));
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001490
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001491 return (tp_features.bay_status || tp_features.bay_eject ||
1492 tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493}
1494
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001495static void bay_notify(struct ibm_struct *ibm, u32 event)
1496{
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001497 acpi_bus_generate_event(ibm->acpi->device, event, 0);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001498}
1499
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001500#define bay_occupied(b) (_sta(b##_handle) & 1)
1501
1502static int bay_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503{
1504 int len = 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001505 int occupied = bay_occupied(bay);
1506 int occupied2 = bay_occupied(bay2);
1507 int eject, eject2;
1508
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001509 len += sprintf(p + len, "status:\t\t%s\n",
1510 tp_features.bay_status ?
1511 (occupied ? "occupied" : "unoccupied") :
1512 "not supported");
1513 if (tp_features.bay_status2)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001514 len += sprintf(p + len, "status2:\t%s\n", occupied2 ?
1515 "occupied" : "unoccupied");
1516
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001517 eject = tp_features.bay_eject && occupied;
1518 eject2 = tp_features.bay_eject2 && occupied2;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001519
1520 if (eject && eject2)
1521 len += sprintf(p + len, "commands:\teject, eject2\n");
1522 else if (eject)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001523 len += sprintf(p + len, "commands:\teject\n");
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001524 else if (eject2)
1525 len += sprintf(p + len, "commands:\teject2\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526
1527 return len;
1528}
1529
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001530static int bay_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531{
1532 char *cmd;
1533
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001534 if (!tp_features.bay_eject && !tp_features.bay_eject2)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001535 return -ENODEV;
1536
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 while ((cmd = next_cmd(&buf))) {
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001538 if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001539 if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1))
1540 return -EIO;
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03001541 } else if (tp_features.bay_eject2 &&
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001542 strlencmp(cmd, "eject2") == 0) {
1543 if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 return -EIO;
1545 } else
1546 return -EINVAL;
1547 }
1548
1549 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001550}
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001551
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001552static struct tp_acpi_drv_struct ibm_bay_acpidriver = {
1553 .notify = bay_notify,
1554 .handle = &bay_handle,
1555 .type = ACPI_SYSTEM_NOTIFY,
1556};
1557
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001558static struct ibm_struct bay_driver_data = {
1559 .name = "bay",
1560 .read = bay_read,
1561 .write = bay_write,
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001562 .acpi = &ibm_bay_acpidriver,
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001563};
1564
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -03001565#endif /* CONFIG_THINKPAD_ACPI_BAY */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001567/*************************************************************************
1568 * CMOS subdriver
1569 */
1570
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001571static int __init cmos_init(struct ibm_init_struct *iibm)
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001572{
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001573 vdbg_printk(TPACPI_DBG_INIT,
1574 "initializing cmos commands subdriver\n");
1575
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001576 IBM_ACPIHANDLE_INIT(cmos);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001577
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001578 vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n",
1579 str_supported(cmos_handle != NULL));
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001580 return (cmos_handle)? 0 : 1;
1581}
1582
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001583static int cmos_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584{
1585 int len = 0;
1586
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001587 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1588 R30, R31, T20-22, X20-21 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 if (!cmos_handle)
1590 len += sprintf(p + len, "status:\t\tnot supported\n");
1591 else {
1592 len += sprintf(p + len, "status:\t\tsupported\n");
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001593 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 }
1595
1596 return len;
1597}
1598
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001599static int cmos_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001600{
1601 char *cmd;
Henrique de Moraes Holschuhc9bea992007-04-21 11:08:42 -03001602 int cmos_cmd, res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001603
1604 while ((cmd = next_cmd(&buf))) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001605 if (sscanf(cmd, "%u", &cmos_cmd) == 1 &&
1606 cmos_cmd >= 0 && cmos_cmd <= 21) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607 /* cmos_cmd set */
1608 } else
1609 return -EINVAL;
1610
Henrique de Moraes Holschuhc9bea992007-04-21 11:08:42 -03001611 res = issue_thinkpad_cmos_command(cmos_cmd);
1612 if (res)
1613 return res;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001614 }
1615
1616 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001617}
1618
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001619static struct ibm_struct cmos_driver_data = {
1620 .name = "cmos",
1621 .read = cmos_read,
1622 .write = cmos_write,
1623};
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001624
1625/*************************************************************************
1626 * LED subdriver
1627 */
1628
Henrique de Moraes Holschuh9a8e1732006-11-25 16:36:00 -02001629static enum led_access_mode led_supported;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001630
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001631IBM_HANDLE(led, ec, "SLED", /* 570 */
1632 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1633 "LED", /* all others */
1634 ); /* R30, R31 */
1635
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001636static int __init led_init(struct ibm_init_struct *iibm)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001637{
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001638 vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n");
1639
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001640 IBM_ACPIHANDLE_INIT(led);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001641
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001642 if (!led_handle)
1643 /* led not supported on R30, R31 */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001644 led_supported = TPACPI_LED_NONE;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001645 else if (strlencmp(led_path, "SLED") == 0)
1646 /* 570 */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001647 led_supported = TPACPI_LED_570;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001648 else if (strlencmp(led_path, "SYSL") == 0)
1649 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001650 led_supported = TPACPI_LED_OLD;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001651 else
1652 /* all others */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001653 led_supported = TPACPI_LED_NEW;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001654
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001655 vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n",
1656 str_supported(led_supported), led_supported);
1657
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001658 return (led_supported != TPACPI_LED_NONE)? 0 : 1;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001659}
1660
1661#define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1662
1663static int led_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664{
1665 int len = 0;
1666
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001667 if (!led_supported) {
1668 len += sprintf(p + len, "status:\t\tnot supported\n");
1669 return len;
1670 }
1671 len += sprintf(p + len, "status:\t\tsupported\n");
1672
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001673 if (led_supported == TPACPI_LED_570) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001674 /* 570 */
1675 int i, status;
1676 for (i = 0; i < 8; i++) {
1677 if (!acpi_evalf(ec_handle,
1678 &status, "GLED", "dd", 1 << i))
1679 return -EIO;
1680 len += sprintf(p + len, "%d:\t\t%s\n",
1681 i, led_status(status));
1682 }
1683 }
1684
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 len += sprintf(p + len, "commands:\t"
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001686 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001687
1688 return len;
1689}
1690
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001691/* off, on, blink */
1692static const int led_sled_arg1[] = { 0, 1, 3 };
1693static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */
1694static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */
1695static const int led_led_arg1[] = { 0, 0x80, 0xc0 };
1696
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001697static int led_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698{
1699 char *cmd;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001700 int led, ind, ret;
1701
1702 if (!led_supported)
1703 return -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001704
1705 while ((cmd = next_cmd(&buf))) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001706 if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707 return -EINVAL;
1708
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001709 if (strstr(cmd, "off")) {
1710 ind = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001711 } else if (strstr(cmd, "on")) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001712 ind = 1;
1713 } else if (strstr(cmd, "blink")) {
1714 ind = 2;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001715 } else
1716 return -EINVAL;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001717
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001718 if (led_supported == TPACPI_LED_570) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001719 /* 570 */
1720 led = 1 << led;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001721 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001722 led, led_sled_arg1[ind]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 return -EIO;
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001724 } else if (led_supported == TPACPI_LED_OLD) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001725 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1726 led = 1 << led;
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001727 ret = ec_write(TPACPI_LED_EC_HLMS, led);
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001728 if (ret >= 0)
1729 ret =
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001730 ec_write(TPACPI_LED_EC_HLBL,
Henrique de Moraes Holschuhe062e032007-03-23 17:33:55 -03001731 led * led_exp_hlbl[ind]);
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001732 if (ret >= 0)
1733 ret =
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001734 ec_write(TPACPI_LED_EC_HLCL,
Henrique de Moraes Holschuhe062e032007-03-23 17:33:55 -03001735 led * led_exp_hlcl[ind]);
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001736 if (ret < 0)
1737 return ret;
1738 } else {
1739 /* all others */
1740 if (!acpi_evalf(led_handle, NULL, NULL, "vdd",
1741 led, led_led_arg1[ind]))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742 return -EIO;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001743 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001744 }
1745
1746 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001747}
1748
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001749static struct ibm_struct led_driver_data = {
1750 .name = "led",
1751 .read = led_read,
1752 .write = led_write,
1753};
1754
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001755/*************************************************************************
1756 * Beep subdriver
1757 */
1758
1759IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */
1760
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001761static int __init beep_init(struct ibm_init_struct *iibm)
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001762{
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001763 vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n");
1764
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03001765 IBM_ACPIHANDLE_INIT(beep);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001766
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001767 vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n",
1768 str_supported(beep_handle != NULL));
1769
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001770 return (beep_handle)? 0 : 1;
1771}
1772
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001773static int beep_read(char *p)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774{
1775 int len = 0;
1776
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001777 if (!beep_handle)
1778 len += sprintf(p + len, "status:\t\tnot supported\n");
1779 else {
1780 len += sprintf(p + len, "status:\t\tsupported\n");
1781 len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n");
1782 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783
1784 return len;
1785}
1786
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001787static int beep_write(char *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001788{
1789 char *cmd;
1790 int beep_cmd;
1791
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001792 if (!beep_handle)
1793 return -ENODEV;
1794
Linus Torvalds1da177e2005-04-16 15:20:36 -07001795 while ((cmd = next_cmd(&buf))) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001796 if (sscanf(cmd, "%u", &beep_cmd) == 1 &&
1797 beep_cmd >= 0 && beep_cmd <= 17) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 /* beep_cmd set */
1799 } else
1800 return -EINVAL;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001801 if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802 return -EIO;
1803 }
1804
1805 return 0;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001806}
1807
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001808static struct ibm_struct beep_driver_data = {
1809 .name = "beep",
1810 .read = beep_read,
1811 .write = beep_write,
1812};
1813
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001814/*************************************************************************
1815 * Thermal subdriver
1816 */
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001817
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001818static enum thermal_access_mode thermal_read_mode;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001819
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001820static int __init thermal_init(struct ibm_init_struct *iibm)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001821{
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001822 u8 t, ta1, ta2;
1823 int i;
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001824 int acpi_tmp7;
1825
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001826 vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n");
1827
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001828 acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv");
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001829
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001830 if (ibm_thinkpad_ec_found && experimental) {
1831 /*
1832 * Direct EC access mode: sensors at registers
1833 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1834 * non-implemented, thermal sensors return 0x80 when
1835 * not available
1836 */
1837
1838 ta1 = ta2 = 0;
1839 for (i = 0; i < 8; i++) {
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001840 if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) {
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001841 ta1 |= t;
1842 } else {
1843 ta1 = 0;
1844 break;
1845 }
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001846 if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) {
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001847 ta2 |= t;
1848 } else {
1849 ta1 = 0;
1850 break;
1851 }
1852 }
1853 if (ta1 == 0) {
1854 /* This is sheer paranoia, but we handle it anyway */
1855 if (acpi_tmp7) {
1856 printk(IBM_ERR
1857 "ThinkPad ACPI EC access misbehaving, "
1858 "falling back to ACPI TMPx access mode\n");
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001859 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001860 } else {
1861 printk(IBM_ERR
1862 "ThinkPad ACPI EC access misbehaving, "
1863 "disabling thermal sensors access\n");
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001864 thermal_read_mode = TPACPI_THERMAL_NONE;
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001865 }
1866 } else {
1867 thermal_read_mode =
1868 (ta2 != 0) ?
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001869 TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8;
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001870 }
1871 } else if (acpi_tmp7) {
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001872 if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) {
1873 /* 600e/x, 770e, 770x */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001874 thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001875 } else {
1876 /* Standard ACPI TMPx access, max 8 sensors */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001877 thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001878 }
1879 } else {
1880 /* temperatures not supported on 570, G4x, R30, R31, R32 */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001881 thermal_read_mode = TPACPI_THERMAL_NONE;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001882 }
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001883
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03001884 vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n",
1885 str_supported(thermal_read_mode != TPACPI_THERMAL_NONE),
1886 thermal_read_mode);
1887
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03001888 return (thermal_read_mode != TPACPI_THERMAL_NONE)? 0 : 1;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001889}
1890
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001891/* idx is zero-based */
1892static int thermal_get_sensor(int idx, s32 *value)
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001893{
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001894 int t;
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001895 s8 tmp;
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001896 char tmpi[5];
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001897
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001898 t = TP_EC_THERMAL_TMP0;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001899
1900 switch (thermal_read_mode) {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001901#if TPACPI_MAX_THERMAL_SENSORS >= 16
1902 case TPACPI_THERMAL_TPEC_16:
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001903 if (idx >= 8 && idx <= 15) {
1904 t = TP_EC_THERMAL_TMP8;
1905 idx -= 8;
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001906 }
1907 /* fallthrough */
1908#endif
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001909 case TPACPI_THERMAL_TPEC_8:
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001910 if (idx <= 7) {
1911 if (!acpi_ec_read(t + idx, &tmp))
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001912 return -EIO;
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001913 *value = tmp * 1000;
1914 return 0;
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001915 }
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001916 break;
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02001917
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001918 case TPACPI_THERMAL_ACPI_UPDT:
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001919 if (idx <= 7) {
1920 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
1921 if (!acpi_evalf(ec_handle, NULL, "UPDT", "v"))
1922 return -EIO;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001923 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1924 return -EIO;
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001925 *value = (t - 2732) * 100;
1926 return 0;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001927 }
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001928 break;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001929
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001930 case TPACPI_THERMAL_ACPI_TMP07:
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001931 if (idx <= 7) {
1932 snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx);
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001933 if (!acpi_evalf(ec_handle, &t, tmpi, "d"))
1934 return -EIO;
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001935 *value = t * 1000;
1936 return 0;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001937 }
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001938 break;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001939
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03001940 case TPACPI_THERMAL_NONE:
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001941 default:
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001942 return -ENOSYS;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001943 }
Henrique de Moraes Holschuh04cc8622007-04-21 11:08:43 -03001944
1945 return -EINVAL;
1946}
1947
1948static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s)
1949{
1950 int res, i;
1951 int n;
1952
1953 n = 8;
1954 i = 0;
1955
1956 if (!s)
1957 return -EINVAL;
1958
1959 if (thermal_read_mode == TPACPI_THERMAL_TPEC_16)
1960 n = 16;
1961
1962 for(i = 0 ; i < n; i++) {
1963 res = thermal_get_sensor(i, &s->temp[i]);
1964 if (res)
1965 return res;
1966 }
1967
1968 return n;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001969}
1970
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001971static int thermal_read(char *p)
1972{
1973 int len = 0;
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001974 int n, i;
1975 struct ibm_thermal_sensors_struct t;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001976
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001977 n = thermal_get_sensors(&t);
1978 if (unlikely(n < 0))
1979 return n;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001980
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001981 len += sprintf(p + len, "temperatures:\t");
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001982
Henrique de Moraes Holschuha26f8782006-11-24 11:47:08 -02001983 if (n > 0) {
1984 for (i = 0; i < (n - 1); i++)
1985 len += sprintf(p + len, "%d ", t.temp[i] / 1000);
1986 len += sprintf(p + len, "%d\n", t.temp[i] / 1000);
1987 } else
1988 len += sprintf(p + len, "not supported\n");
Borislav Deianov78f81cc2005-08-17 00:00:00 -04001989
1990 return len;
1991}
1992
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03001993static struct ibm_struct thermal_driver_data = {
1994 .name = "thermal",
1995 .read = thermal_read,
1996};
1997
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03001998/*************************************************************************
1999 * EC Dump subdriver
2000 */
2001
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002002static u8 ecdump_regs[256];
2003
2004static int ecdump_read(char *p)
2005{
2006 int len = 0;
2007 int i, j;
2008 u8 v;
2009
2010 len += sprintf(p + len, "EC "
2011 " +00 +01 +02 +03 +04 +05 +06 +07"
2012 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
2013 for (i = 0; i < 256; i += 16) {
2014 len += sprintf(p + len, "EC 0x%02x:", i);
2015 for (j = 0; j < 16; j++) {
2016 if (!acpi_ec_read(i + j, &v))
2017 break;
2018 if (v != ecdump_regs[i + j])
2019 len += sprintf(p + len, " *%02x", v);
2020 else
2021 len += sprintf(p + len, " %02x", v);
2022 ecdump_regs[i + j] = v;
2023 }
2024 len += sprintf(p + len, "\n");
2025 if (j != 16)
2026 break;
2027 }
2028
2029 /* These are way too dangerous to advertise openly... */
2030#if 0
2031 len += sprintf(p + len, "commands:\t0x<offset> 0x<value>"
2032 " (<offset> is 00-ff, <value> is 00-ff)\n");
2033 len += sprintf(p + len, "commands:\t0x<offset> <value> "
2034 " (<offset> is 00-ff, <value> is 0-255)\n");
2035#endif
2036 return len;
2037}
2038
2039static int ecdump_write(char *buf)
2040{
2041 char *cmd;
2042 int i, v;
2043
2044 while ((cmd = next_cmd(&buf))) {
2045 if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) {
2046 /* i and v set */
2047 } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) {
2048 /* i and v set */
2049 } else
2050 return -EINVAL;
2051 if (i >= 0 && i < 256 && v >= 0 && v < 256) {
2052 if (!acpi_ec_write(i, v))
2053 return -EIO;
2054 } else
2055 return -EINVAL;
2056 }
2057
2058 return 0;
2059}
2060
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002061static struct ibm_struct ecdump_driver_data = {
2062 .name = "ecdump",
2063 .read = ecdump_read,
2064 .write = ecdump_write,
Henrique de Moraes Holschuh92641172007-04-21 11:08:35 -03002065 .flags.experimental = 1,
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002066};
2067
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002068/*************************************************************************
2069 * Backlight/brightness subdriver
2070 */
Holger Macht8acb0252006-10-20 14:30:28 -07002071
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002072static struct backlight_device *ibm_backlight_device = NULL;
Holger Macht8acb0252006-10-20 14:30:28 -07002073
Richard Purdie599a52d2007-02-10 23:07:48 +00002074static struct backlight_ops ibm_backlight_data = {
Henrique de Moraes Holschuhfb87a812006-11-25 16:35:09 -02002075 .get_brightness = brightness_get,
2076 .update_status = brightness_update_status,
Henrique de Moraes Holschuhfb87a812006-11-25 16:35:09 -02002077};
2078
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002079static int __init brightness_init(struct ibm_init_struct *iibm)
Henrique de Moraes Holschuhfb87a812006-11-25 16:35:09 -02002080{
Henrique de Moraes Holschuhadb00582007-02-22 16:04:55 -02002081 int b;
2082
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03002083 vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n");
2084
Henrique de Moraes Holschuhadb00582007-02-22 16:04:55 -02002085 b = brightness_get(NULL);
2086 if (b < 0)
2087 return b;
2088
Yu Luming519ab5f2006-12-19 12:56:15 -08002089 ibm_backlight_device = backlight_device_register("ibm", NULL, NULL,
Henrique de Moraes Holschuhfb87a812006-11-25 16:35:09 -02002090 &ibm_backlight_data);
2091 if (IS_ERR(ibm_backlight_device)) {
2092 printk(IBM_ERR "Could not register backlight device\n");
2093 return PTR_ERR(ibm_backlight_device);
2094 }
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03002095 vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n");
Henrique de Moraes Holschuhfb87a812006-11-25 16:35:09 -02002096
Henrique de Moraes Holschuhadb00582007-02-22 16:04:55 -02002097 ibm_backlight_device->props.max_brightness = 7;
2098 ibm_backlight_device->props.brightness = b;
2099 backlight_update_status(ibm_backlight_device);
Richard Purdie599a52d2007-02-10 23:07:48 +00002100
Henrique de Moraes Holschuhfb87a812006-11-25 16:35:09 -02002101 return 0;
2102}
2103
2104static void brightness_exit(void)
2105{
2106 if (ibm_backlight_device) {
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03002107 vdbg_printk(TPACPI_DBG_EXIT,
2108 "calling backlight_device_unregister()\n");
Henrique de Moraes Holschuhfb87a812006-11-25 16:35:09 -02002109 backlight_device_unregister(ibm_backlight_device);
2110 ibm_backlight_device = NULL;
2111 }
2112}
2113
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002114static int brightness_update_status(struct backlight_device *bd)
2115{
2116 return brightness_set(
2117 (bd->props.fb_blank == FB_BLANK_UNBLANK &&
2118 bd->props.power == FB_BLANK_UNBLANK) ?
2119 bd->props.brightness : 0);
2120}
2121
2122static int brightness_get(struct backlight_device *bd)
2123{
2124 u8 level;
2125 if (!acpi_ec_read(brightness_offset, &level))
2126 return -EIO;
2127
2128 level &= 0x7;
2129
2130 return level;
2131}
2132
2133static int brightness_set(int value)
2134{
2135 int cmos_cmd, inc, i;
2136 int current_value = brightness_get(NULL);
2137
2138 value &= 7;
2139
2140 cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN;
2141 inc = value > current_value ? 1 : -1;
2142 for (i = current_value; i != value; i += inc) {
Henrique de Moraes Holschuhc9bea992007-04-21 11:08:42 -03002143 if (issue_thinkpad_cmos_command(cmos_cmd))
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002144 return -EIO;
2145 if (!acpi_ec_write(brightness_offset, i + inc))
2146 return -EIO;
2147 }
2148
2149 return 0;
2150}
2151
2152static int brightness_read(char *p)
2153{
2154 int len = 0;
2155 int level;
2156
2157 if ((level = brightness_get(NULL)) < 0) {
2158 len += sprintf(p + len, "level:\t\tunreadable\n");
2159 } else {
2160 len += sprintf(p + len, "level:\t\t%d\n", level & 0x7);
2161 len += sprintf(p + len, "commands:\tup, down\n");
2162 len += sprintf(p + len, "commands:\tlevel <level>"
2163 " (<level> is 0-7)\n");
2164 }
2165
2166 return len;
2167}
2168
2169static int brightness_write(char *buf)
2170{
2171 int level;
2172 int new_level;
2173 char *cmd;
2174
2175 while ((cmd = next_cmd(&buf))) {
2176 if ((level = brightness_get(NULL)) < 0)
2177 return level;
2178 level &= 7;
2179
2180 if (strlencmp(cmd, "up") == 0) {
2181 new_level = level == 7 ? 7 : level + 1;
2182 } else if (strlencmp(cmd, "down") == 0) {
2183 new_level = level == 0 ? 0 : level - 1;
2184 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
2185 new_level >= 0 && new_level <= 7) {
2186 /* new_level set */
2187 } else
2188 return -EINVAL;
2189
2190 brightness_set(new_level);
2191 }
2192
2193 return 0;
2194}
2195
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002196static struct ibm_struct brightness_driver_data = {
2197 .name = "brightness",
2198 .read = brightness_read,
2199 .write = brightness_write,
2200 .exit = brightness_exit,
2201};
2202
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002203/*************************************************************************
2204 * Volume subdriver
2205 */
2206
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002207static int volume_read(char *p)
2208{
2209 int len = 0;
2210 u8 level;
2211
2212 if (!acpi_ec_read(volume_offset, &level)) {
2213 len += sprintf(p + len, "level:\t\tunreadable\n");
2214 } else {
2215 len += sprintf(p + len, "level:\t\t%d\n", level & 0xf);
2216 len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6));
2217 len += sprintf(p + len, "commands:\tup, down, mute\n");
2218 len += sprintf(p + len, "commands:\tlevel <level>"
2219 " (<level> is 0-15)\n");
2220 }
2221
2222 return len;
2223}
2224
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002225static int volume_write(char *buf)
2226{
2227 int cmos_cmd, inc, i;
2228 u8 level, mute;
2229 int new_level, new_mute;
2230 char *cmd;
2231
2232 while ((cmd = next_cmd(&buf))) {
2233 if (!acpi_ec_read(volume_offset, &level))
2234 return -EIO;
2235 new_mute = mute = level & 0x40;
2236 new_level = level = level & 0xf;
2237
2238 if (strlencmp(cmd, "up") == 0) {
2239 if (mute)
2240 new_mute = 0;
2241 else
2242 new_level = level == 15 ? 15 : level + 1;
2243 } else if (strlencmp(cmd, "down") == 0) {
2244 if (mute)
2245 new_mute = 0;
2246 else
2247 new_level = level == 0 ? 0 : level - 1;
2248 } else if (sscanf(cmd, "level %d", &new_level) == 1 &&
2249 new_level >= 0 && new_level <= 15) {
2250 /* new_level set */
2251 } else if (strlencmp(cmd, "mute") == 0) {
2252 new_mute = 0x40;
2253 } else
2254 return -EINVAL;
2255
2256 if (new_level != level) { /* mute doesn't change */
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002257 cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002258 inc = new_level > level ? 1 : -1;
2259
Henrique de Moraes Holschuhc9bea992007-04-21 11:08:42 -03002260 if (mute && (issue_thinkpad_cmos_command(cmos_cmd) ||
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002261 !acpi_ec_write(volume_offset, level)))
2262 return -EIO;
2263
2264 for (i = level; i != new_level; i += inc)
Henrique de Moraes Holschuhc9bea992007-04-21 11:08:42 -03002265 if (issue_thinkpad_cmos_command(cmos_cmd) ||
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002266 !acpi_ec_write(volume_offset, i + inc))
2267 return -EIO;
2268
Henrique de Moraes Holschuhc9bea992007-04-21 11:08:42 -03002269 if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) ||
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002270 !acpi_ec_write(volume_offset,
2271 new_level + mute)))
2272 return -EIO;
2273 }
2274
2275 if (new_mute != mute) { /* level doesn't change */
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002276 cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002277
Henrique de Moraes Holschuhc9bea992007-04-21 11:08:42 -03002278 if (issue_thinkpad_cmos_command(cmos_cmd) ||
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002279 !acpi_ec_write(volume_offset, level + new_mute))
2280 return -EIO;
2281 }
2282 }
2283
2284 return 0;
2285}
2286
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002287static struct ibm_struct volume_driver_data = {
2288 .name = "volume",
2289 .read = volume_read,
2290 .write = volume_write,
2291};
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002292
2293/*************************************************************************
2294 * Fan subdriver
2295 */
2296
2297/*
2298 * FAN ACCESS MODES
2299 *
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002300 * TPACPI_FAN_RD_ACPI_GFAN:
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002301 * ACPI GFAN method: returns fan level
2302 *
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002303 * see TPACPI_FAN_WR_ACPI_SFAN
Henrique de Moraes Holschuhf51d1a32007-04-21 11:08:29 -03002304 * EC 0x2f (HFSP) not available if GFAN exists
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002305 *
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002306 * TPACPI_FAN_WR_ACPI_SFAN:
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002307 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
2308 *
Henrique de Moraes Holschuhf51d1a32007-04-21 11:08:29 -03002309 * EC 0x2f (HFSP) might be available *for reading*, but do not use
2310 * it for writing.
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002311 *
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002312 * TPACPI_FAN_WR_TPEC:
Henrique de Moraes Holschuhf51d1a32007-04-21 11:08:29 -03002313 * ThinkPad EC register 0x2f (HFSP): fan control loop mode
2314 * Supported on almost all ThinkPads
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002315 *
2316 * Fan speed changes of any sort (including those caused by the
2317 * disengaged mode) are usually done slowly by the firmware as the
2318 * maximum ammount of fan duty cycle change per second seems to be
2319 * limited.
2320 *
2321 * Reading is not available if GFAN exists.
2322 * Writing is not available if SFAN exists.
2323 *
2324 * Bits
2325 * 7 automatic mode engaged;
2326 * (default operation mode of the ThinkPad)
2327 * fan level is ignored in this mode.
Henrique de Moraes Holschuhf51d1a32007-04-21 11:08:29 -03002328 * 6 full speed mode (takes precedence over bit 7);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002329 * not available on all thinkpads. May disable
Henrique de Moraes Holschuhf51d1a32007-04-21 11:08:29 -03002330 * the tachometer while the fan controller ramps up
2331 * the speed (which can take up to a few *minutes*).
2332 * Speeds up fan to 100% duty-cycle, which is far above
2333 * the standard RPM levels. It is not impossible that
2334 * it could cause hardware damage.
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002335 * 5-3 unused in some models. Extra bits for fan level
2336 * in others, but still useless as all values above
2337 * 7 map to the same speed as level 7 in these models.
2338 * 2-0 fan level (0..7 usually)
2339 * 0x00 = stop
2340 * 0x07 = max (set when temperatures critical)
2341 * Some ThinkPads may have other levels, see
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002342 * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002343 *
2344 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
2345 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
2346 * does so, its initial value is meaningless (0x07).
2347 *
2348 * For firmware bugs, refer to:
2349 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2350 *
2351 * ----
2352 *
2353 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
2354 * Main fan tachometer reading (in RPM)
2355 *
2356 * This register is present on all ThinkPads with a new-style EC, and
2357 * it is known not to be present on the A21m/e, and T22, as there is
2358 * something else in offset 0x84 according to the ACPI DSDT. Other
2359 * ThinkPads from this same time period (and earlier) probably lack the
2360 * tachometer as well.
2361 *
2362 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
2363 * was never fixed by IBM to report the EC firmware version string
2364 * probably support the tachometer (like the early X models), so
2365 * detecting it is quite hard. We need more data to know for sure.
2366 *
2367 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
2368 * might result.
2369 *
Henrique de Moraes Holschuhf51d1a32007-04-21 11:08:29 -03002370 * FIRMWARE BUG: may go stale while the EC is switching to full speed
2371 * mode.
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002372 *
2373 * For firmware bugs, refer to:
2374 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
2375 *
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002376 * TPACPI_FAN_WR_ACPI_FANS:
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002377 * ThinkPad X31, X40, X41. Not available in the X60.
2378 *
2379 * FANS ACPI handle: takes three arguments: low speed, medium speed,
2380 * high speed. ACPI DSDT seems to map these three speeds to levels
2381 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
2382 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
2383 *
2384 * The speeds are stored on handles
2385 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
2386 *
2387 * There are three default speed sets, acessible as handles:
2388 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
2389 *
2390 * ACPI DSDT switches which set is in use depending on various
2391 * factors.
2392 *
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002393 * TPACPI_FAN_WR_TPEC is also available and should be used to
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002394 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
2395 * but the ACPI tables just mention level 7.
2396 */
2397
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002398static enum fan_status_access_mode fan_status_access_mode;
2399static enum fan_control_access_mode fan_control_access_mode;
2400static enum fan_control_commands fan_control_commands;
2401
Henrique de Moraes Holschuh778b4d72006-11-24 11:47:14 -02002402static u8 fan_control_initial_status;
2403
Len Brown25c68a32006-12-08 04:43:41 -05002404static void fan_watchdog_fire(struct work_struct *ignored);
Henrique de Moraes Holschuh16663a82006-11-24 11:47:14 -02002405static int fan_watchdog_maxinterval;
Len Brown25c68a32006-12-08 04:43:41 -05002406static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire);
Henrique de Moraes Holschuh16663a82006-11-24 11:47:14 -02002407
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002408IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */
2409IBM_HANDLE(gfan, ec, "GFAN", /* 570 */
2410 "\\FSPD", /* 600e/x, 770e, 770x */
2411 ); /* all others */
2412IBM_HANDLE(sfan, ec, "SFAN", /* 570 */
2413 "JFNS", /* 770x-JL */
2414 ); /* all others */
2415
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002416static int __init fan_init(struct ibm_init_struct *iibm)
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002417{
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03002418 vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n");
2419
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002420 fan_status_access_mode = TPACPI_FAN_NONE;
2421 fan_control_access_mode = TPACPI_FAN_WR_NONE;
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002422 fan_control_commands = 0;
Henrique de Moraes Holschuh16663a82006-11-24 11:47:14 -02002423 fan_watchdog_maxinterval = 0;
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03002424 tp_features.fan_ctrl_status_undef = 0;
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002425
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03002426 IBM_ACPIHANDLE_INIT(fans);
2427 IBM_ACPIHANDLE_INIT(gfan);
2428 IBM_ACPIHANDLE_INIT(sfan);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03002429
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002430 if (gfan_handle) {
2431 /* 570, 600e/x, 770e, 770x */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002432 fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN;
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002433 } else {
2434 /* all other ThinkPads: note that even old-style
2435 * ThinkPad ECs supports the fan control register */
Henrique de Moraes Holschuh778b4d72006-11-24 11:47:14 -02002436 if (likely(acpi_ec_read(fan_status_offset,
2437 &fan_control_initial_status))) {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002438 fan_status_access_mode = TPACPI_FAN_RD_TPEC;
Henrique de Moraes Holschuh778b4d72006-11-24 11:47:14 -02002439
2440 /* In some ThinkPads, neither the EC nor the ACPI
2441 * DSDT initialize the fan status, and it ends up
2442 * being set to 0x07 when it *could* be either
2443 * 0x07 or 0x80.
2444 *
2445 * Enable for TP-1Y (T43), TP-78 (R51e),
2446 * TP-76 (R52), TP-70 (T43, R52), which are known
2447 * to be buggy. */
2448 if (fan_control_initial_status == 0x07 &&
2449 ibm_thinkpad_ec_found &&
2450 ((ibm_thinkpad_ec_found[0] == '1' &&
2451 ibm_thinkpad_ec_found[1] == 'Y') ||
2452 (ibm_thinkpad_ec_found[0] == '7' &&
2453 (ibm_thinkpad_ec_found[1] == '6' ||
2454 ibm_thinkpad_ec_found[1] == '8' ||
2455 ibm_thinkpad_ec_found[1] == '0'))
2456 )) {
2457 printk(IBM_NOTICE
2458 "fan_init: initial fan status is "
2459 "unknown, assuming it is in auto "
2460 "mode\n");
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03002461 tp_features.fan_ctrl_status_undef = 1;
Henrique de Moraes Holschuh778b4d72006-11-24 11:47:14 -02002462 }
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002463 } else {
2464 printk(IBM_ERR
2465 "ThinkPad ACPI EC access misbehaving, "
2466 "fan status and control unavailable\n");
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03002467 return 1;
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002468 }
2469 }
2470
2471 if (sfan_handle) {
2472 /* 570, 770x-JL */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002473 fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN;
Henrique de Moraes Holschuh1c6a3342006-11-24 11:47:12 -02002474 fan_control_commands |=
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002475 TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE;
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002476 } else {
2477 if (!gfan_handle) {
2478 /* gfan without sfan means no fan control */
2479 /* all other models implement TP EC 0x2f control */
2480
2481 if (fans_handle) {
Henrique de Moraes Holschuha8b7a662006-11-24 11:47:11 -02002482 /* X31, X40, X41 */
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002483 fan_control_access_mode =
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002484 TPACPI_FAN_WR_ACPI_FANS;
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002485 fan_control_commands |=
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002486 TPACPI_FAN_CMD_SPEED |
2487 TPACPI_FAN_CMD_LEVEL |
2488 TPACPI_FAN_CMD_ENABLE;
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002489 } else {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002490 fan_control_access_mode = TPACPI_FAN_WR_TPEC;
Henrique de Moraes Holschuha12095c2006-11-24 11:47:13 -02002491 fan_control_commands |=
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002492 TPACPI_FAN_CMD_LEVEL |
2493 TPACPI_FAN_CMD_ENABLE;
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002494 }
2495 }
2496 }
2497
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03002498 vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n",
2499 str_supported(fan_status_access_mode != TPACPI_FAN_NONE ||
2500 fan_control_access_mode != TPACPI_FAN_WR_NONE),
2501 fan_status_access_mode, fan_control_access_mode);
2502
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03002503 return (fan_status_access_mode != TPACPI_FAN_NONE ||
2504 fan_control_access_mode != TPACPI_FAN_WR_NONE)?
2505 0 : 1;
Henrique de Moraes Holschuh69ba91c2006-11-24 11:47:09 -02002506}
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002507
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02002508static int fan_get_status(u8 *status)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002509{
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02002510 u8 s;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002511
Henrique de Moraes Holschuha8b7a662006-11-24 11:47:11 -02002512 /* TODO:
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002513 * Add TPACPI_FAN_RD_ACPI_FANS ? */
Henrique de Moraes Holschuha8b7a662006-11-24 11:47:11 -02002514
Henrique de Moraes Holschuh3ef8a602006-11-24 11:47:10 -02002515 switch (fan_status_access_mode) {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002516 case TPACPI_FAN_RD_ACPI_GFAN:
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002517 /* 570, 600e/x, 770e, 770x */
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02002518
2519 if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d")))
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002520 return -EIO;
2521
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02002522 if (likely(status))
2523 *status = s & 0x07;
2524
2525 break;
2526
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002527 case TPACPI_FAN_RD_TPEC:
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02002528 /* all except 570, 600e/x, 770e, 770x */
2529 if (unlikely(!acpi_ec_read(fan_status_offset, &s)))
2530 return -EIO;
2531
2532 if (likely(status))
2533 *status = s;
2534
2535 break;
2536
2537 default:
2538 return -ENXIO;
2539 }
2540
2541 return 0;
2542}
2543
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002544static void fan_exit(void)
2545{
Henrique de Moraes Holschuh99fba3f2007-04-21 11:08:44 -03002546 vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n");
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002547 cancel_delayed_work(&fan_watchdog_task);
2548 flush_scheduled_work();
2549}
2550
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02002551static int fan_get_speed(unsigned int *speed)
2552{
2553 u8 hi, lo;
2554
2555 switch (fan_status_access_mode) {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002556 case TPACPI_FAN_RD_TPEC:
Henrique de Moraes Holschuhc52f0aa2006-11-24 11:47:10 -02002557 /* all except 570, 600e/x, 770e, 770x */
2558 if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) ||
2559 !acpi_ec_read(fan_rpm_offset + 1, &hi)))
2560 return -EIO;
2561
2562 if (likely(speed))
2563 *speed = (hi << 8) | lo;
2564
2565 break;
2566
2567 default:
2568 return -ENXIO;
2569 }
2570
2571 return 0;
2572}
2573
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002574static void fan_watchdog_fire(struct work_struct *ignored)
Henrique de Moraes Holschuh16663a82006-11-24 11:47:14 -02002575{
Henrique de Moraes Holschuh99fba3f2007-04-21 11:08:44 -03002576 int rc;
2577
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002578 printk(IBM_NOTICE "fan watchdog: enabling fan\n");
Henrique de Moraes Holschuh99fba3f2007-04-21 11:08:44 -03002579 rc = fan_set_enable();
2580 if (rc < 0) {
2581 printk(IBM_ERR "fan watchdog: error %d while enabling fan, "
2582 "will try again later...\n", -rc);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002583 /* reschedule for later */
2584 fan_watchdog_reset();
2585 }
Henrique de Moraes Holschuh16663a82006-11-24 11:47:14 -02002586}
2587
2588static void fan_watchdog_reset(void)
2589{
2590 static int fan_watchdog_active = 0;
2591
2592 if (fan_watchdog_active)
2593 cancel_delayed_work(&fan_watchdog_task);
2594
2595 if (fan_watchdog_maxinterval > 0) {
2596 fan_watchdog_active = 1;
2597 if (!schedule_delayed_work(&fan_watchdog_task,
2598 msecs_to_jiffies(fan_watchdog_maxinterval
2599 * 1000))) {
2600 printk(IBM_ERR "failed to schedule the fan watchdog, "
2601 "watchdog will not trigger\n");
2602 }
2603 } else
2604 fan_watchdog_active = 0;
2605}
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002606
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002607static int fan_set_level(int level)
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002608{
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002609 switch (fan_control_access_mode) {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002610 case TPACPI_FAN_WR_ACPI_SFAN:
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002611 if (level >= 0 && level <= 7) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002612 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level))
2613 return -EIO;
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002614 } else
2615 return -EINVAL;
2616 break;
2617
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002618 case TPACPI_FAN_WR_ACPI_FANS:
2619 case TPACPI_FAN_WR_TPEC:
2620 if ((level != TP_EC_FAN_AUTO) &&
2621 (level != TP_EC_FAN_FULLSPEED) &&
Henrique de Moraes Holschuha12095c2006-11-24 11:47:13 -02002622 ((level < 0) || (level > 7)))
2623 return -EINVAL;
2624
2625 if (!acpi_ec_write(fan_status_offset, level))
2626 return -EIO;
Henrique de Moraes Holschuh778b4d72006-11-24 11:47:14 -02002627 else
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03002628 tp_features.fan_ctrl_status_undef = 0;
Henrique de Moraes Holschuha12095c2006-11-24 11:47:13 -02002629 break;
2630
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002631 default:
2632 return -ENXIO;
2633 }
2634 return 0;
2635}
2636
2637static int fan_set_enable(void)
2638{
Henrique de Moraes Holschuh1c6a3342006-11-24 11:47:12 -02002639 u8 s;
2640 int rc;
2641
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002642 switch (fan_control_access_mode) {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002643 case TPACPI_FAN_WR_ACPI_FANS:
2644 case TPACPI_FAN_WR_TPEC:
Henrique de Moraes Holschuh1c6a3342006-11-24 11:47:12 -02002645 if ((rc = fan_get_status(&s)) < 0)
2646 return rc;
2647
2648 /* Don't go out of emergency fan mode */
2649 if (s != 7)
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002650 s = TP_EC_FAN_AUTO;
Henrique de Moraes Holschuh1c6a3342006-11-24 11:47:12 -02002651
2652 if (!acpi_ec_write(fan_status_offset, s))
2653 return -EIO;
Henrique de Moraes Holschuh778b4d72006-11-24 11:47:14 -02002654 else
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03002655 tp_features.fan_ctrl_status_undef = 0;
Henrique de Moraes Holschuh1c6a3342006-11-24 11:47:12 -02002656 break;
2657
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002658 case TPACPI_FAN_WR_ACPI_SFAN:
Henrique de Moraes Holschuh1c6a3342006-11-24 11:47:12 -02002659 if ((rc = fan_get_status(&s)) < 0)
2660 return rc;
2661
2662 s &= 0x07;
2663
2664 /* Set fan to at least level 4 */
2665 if (s < 4)
2666 s = 4;
2667
2668 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s))
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002669 return -EIO;
2670 break;
2671
2672 default:
2673 return -ENXIO;
2674 }
2675 return 0;
2676}
2677
2678static int fan_set_disable(void)
2679{
2680 switch (fan_control_access_mode) {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002681 case TPACPI_FAN_WR_ACPI_FANS:
2682 case TPACPI_FAN_WR_TPEC:
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002683 if (!acpi_ec_write(fan_status_offset, 0x00))
2684 return -EIO;
Henrique de Moraes Holschuh778b4d72006-11-24 11:47:14 -02002685 else
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03002686 tp_features.fan_ctrl_status_undef = 0;
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002687 break;
2688
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002689 case TPACPI_FAN_WR_ACPI_SFAN:
Henrique de Moraes Holschuh1c6a3342006-11-24 11:47:12 -02002690 if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00))
2691 return -EIO;
2692 break;
2693
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002694 default:
2695 return -ENXIO;
2696 }
2697 return 0;
2698}
2699
2700static int fan_set_speed(int speed)
2701{
2702 switch (fan_control_access_mode) {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002703 case TPACPI_FAN_WR_ACPI_FANS:
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002704 if (speed >= 0 && speed <= 65535) {
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002705 if (!acpi_evalf(fans_handle, NULL, NULL, "vddd",
2706 speed, speed, speed))
2707 return -EIO;
2708 } else
2709 return -EINVAL;
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002710 break;
2711
2712 default:
2713 return -ENXIO;
2714 }
2715 return 0;
2716}
2717
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002718static int fan_read(char *p)
2719{
2720 int len = 0;
2721 int rc;
2722 u8 status;
2723 unsigned int speed = 0;
2724
2725 switch (fan_status_access_mode) {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002726 case TPACPI_FAN_RD_ACPI_GFAN:
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002727 /* 570, 600e/x, 770e, 770x */
2728 if ((rc = fan_get_status(&status)) < 0)
2729 return rc;
2730
2731 len += sprintf(p + len, "status:\t\t%s\n"
2732 "level:\t\t%d\n",
2733 (status != 0) ? "enabled" : "disabled", status);
2734 break;
2735
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002736 case TPACPI_FAN_RD_TPEC:
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002737 /* all except 570, 600e/x, 770e, 770x */
2738 if ((rc = fan_get_status(&status)) < 0)
2739 return rc;
2740
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03002741 if (unlikely(tp_features.fan_ctrl_status_undef)) {
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002742 if (status != fan_control_initial_status)
Henrique de Moraes Holschuhd8fd94d2007-04-21 11:08:36 -03002743 tp_features.fan_ctrl_status_undef = 0;
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002744 else
2745 /* Return most likely status. In fact, it
2746 * might be the only possible status */
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002747 status = TP_EC_FAN_AUTO;
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002748 }
2749
2750 len += sprintf(p + len, "status:\t\t%s\n",
2751 (status != 0) ? "enabled" : "disabled");
2752
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002753 if ((rc = fan_get_speed(&speed)) < 0)
2754 return rc;
2755
2756 len += sprintf(p + len, "speed:\t\t%d\n", speed);
2757
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002758 if (status & TP_EC_FAN_FULLSPEED)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002759 /* Disengaged mode takes precedence */
2760 len += sprintf(p + len, "level:\t\tdisengaged\n");
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002761 else if (status & TP_EC_FAN_AUTO)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002762 len += sprintf(p + len, "level:\t\tauto\n");
2763 else
2764 len += sprintf(p + len, "level:\t\t%d\n", status);
2765 break;
2766
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002767 case TPACPI_FAN_NONE:
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002768 default:
2769 len += sprintf(p + len, "status:\t\tnot supported\n");
2770 }
2771
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002772 if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) {
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002773 len += sprintf(p + len, "commands:\tlevel <level>");
2774
2775 switch (fan_control_access_mode) {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002776 case TPACPI_FAN_WR_ACPI_SFAN:
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002777 len += sprintf(p + len, " (<level> is 0-7)\n");
2778 break;
2779
2780 default:
2781 len += sprintf(p + len, " (<level> is 0-7, "
2782 "auto, disengaged)\n");
2783 break;
2784 }
2785 }
2786
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002787 if (fan_control_commands & TPACPI_FAN_CMD_ENABLE)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002788 len += sprintf(p + len, "commands:\tenable, disable\n"
2789 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2790 "1-120 (seconds))\n");
2791
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002792 if (fan_control_commands & TPACPI_FAN_CMD_SPEED)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002793 len += sprintf(p + len, "commands:\tspeed <speed>"
2794 " (<speed> is 0-65535)\n");
2795
2796 return len;
2797}
2798
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002799static int fan_write_cmd_level(const char *cmd, int *rc)
2800{
2801 int level;
2802
Henrique de Moraes Holschuha12095c2006-11-24 11:47:13 -02002803 if (strlencmp(cmd, "level auto") == 0)
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002804 level = TP_EC_FAN_AUTO;
Henrique de Moraes Holschuha12095c2006-11-24 11:47:13 -02002805 else if (strlencmp(cmd, "level disengaged") == 0)
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002806 level = TP_EC_FAN_FULLSPEED;
Henrique de Moraes Holschuha12095c2006-11-24 11:47:13 -02002807 else if (sscanf(cmd, "level %d", &level) != 1)
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002808 return 0;
2809
2810 if ((*rc = fan_set_level(level)) == -ENXIO)
2811 printk(IBM_ERR "level command accepted for unsupported "
2812 "access mode %d", fan_control_access_mode);
2813
2814 return 1;
2815}
2816
2817static int fan_write_cmd_enable(const char *cmd, int *rc)
2818{
2819 if (strlencmp(cmd, "enable") != 0)
2820 return 0;
2821
2822 if ((*rc = fan_set_enable()) == -ENXIO)
2823 printk(IBM_ERR "enable command accepted for unsupported "
2824 "access mode %d", fan_control_access_mode);
2825
2826 return 1;
2827}
2828
2829static int fan_write_cmd_disable(const char *cmd, int *rc)
2830{
2831 if (strlencmp(cmd, "disable") != 0)
2832 return 0;
2833
2834 if ((*rc = fan_set_disable()) == -ENXIO)
2835 printk(IBM_ERR "disable command accepted for unsupported "
2836 "access mode %d", fan_control_access_mode);
2837
2838 return 1;
2839}
2840
2841static int fan_write_cmd_speed(const char *cmd, int *rc)
2842{
2843 int speed;
2844
Henrique de Moraes Holschuha8b7a662006-11-24 11:47:11 -02002845 /* TODO:
2846 * Support speed <low> <medium> <high> ? */
2847
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002848 if (sscanf(cmd, "speed %d", &speed) != 1)
2849 return 0;
2850
2851 if ((*rc = fan_set_speed(speed)) == -ENXIO)
2852 printk(IBM_ERR "speed command accepted for unsupported "
2853 "access mode %d", fan_control_access_mode);
2854
2855 return 1;
2856}
2857
Henrique de Moraes Holschuh16663a82006-11-24 11:47:14 -02002858static int fan_write_cmd_watchdog(const char *cmd, int *rc)
2859{
2860 int interval;
2861
2862 if (sscanf(cmd, "watchdog %d", &interval) != 1)
2863 return 0;
2864
2865 if (interval < 0 || interval > 120)
2866 *rc = -EINVAL;
2867 else
2868 fan_watchdog_maxinterval = interval;
2869
2870 return 1;
2871}
2872
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002873static int fan_write(char *buf)
2874{
2875 char *cmd;
2876 int rc = 0;
2877
2878 while (!rc && (cmd = next_cmd(&buf))) {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002879 if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) &&
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002880 fan_write_cmd_level(cmd, &rc)) &&
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002881 !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) &&
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002882 (fan_write_cmd_enable(cmd, &rc) ||
Henrique de Moraes Holschuh16663a82006-11-24 11:47:14 -02002883 fan_write_cmd_disable(cmd, &rc) ||
2884 fan_write_cmd_watchdog(cmd, &rc))) &&
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -03002885 !((fan_control_commands & TPACPI_FAN_CMD_SPEED) &&
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002886 fan_write_cmd_speed(cmd, &rc))
2887 )
2888 rc = -EINVAL;
Henrique de Moraes Holschuh16663a82006-11-24 11:47:14 -02002889 else if (!rc)
2890 fan_watchdog_reset();
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002891 }
2892
Henrique de Moraes Holschuh18ad7992006-11-24 11:47:11 -02002893 return rc;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002894}
2895
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002896static struct ibm_struct fan_driver_data = {
2897 .name = "fan",
2898 .read = fan_read,
2899 .write = fan_write,
2900 .exit = fan_exit,
Henrique de Moraes Holschuh92641172007-04-21 11:08:35 -03002901 .flags.experimental = 1,
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002902};
2903
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002904/****************************************************************************
2905 ****************************************************************************
2906 *
2907 * Infrastructure
2908 *
2909 ****************************************************************************
2910 ****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002912/* /proc support */
2913static struct proc_dir_entry *proc_dir = NULL;
2914
2915/* Subdriver registry */
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002916static LIST_HEAD(tpacpi_all_drivers);
2917
Linus Torvalds1da177e2005-04-16 15:20:36 -07002918
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03002919/*
2920 * Module and infrastructure proble, init and exit handling
2921 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002922
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03002923#ifdef CONFIG_THINKPAD_ACPI_DEBUG
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002924static const char * __init str_supported(int is_supported)
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03002925{
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002926 static char text_unsupported[] __initdata = "not supported";
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03002927
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002928 return (is_supported)? &text_unsupported[4] : &text_unsupported[0];
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03002929}
2930#endif /* CONFIG_THINKPAD_ACPI_DEBUG */
2931
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002932static int __init ibm_init(struct ibm_init_struct *iibm)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933{
2934 int ret;
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002935 struct ibm_struct *ibm = iibm->data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936 struct proc_dir_entry *entry;
2937
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002938 BUG_ON(ibm == NULL);
2939
2940 INIT_LIST_HEAD(&ibm->all_drivers);
2941
Henrique de Moraes Holschuh92641172007-04-21 11:08:35 -03002942 if (ibm->flags.experimental && !experimental)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002943 return 0;
2944
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03002945 dbg_printk(TPACPI_DBG_INIT,
2946 "probing for %s\n", ibm->name);
2947
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002948 if (iibm->init) {
2949 ret = iibm->init(iibm);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03002950 if (ret > 0)
2951 return 0; /* probe failed */
2952 if (ret)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 return ret;
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002954
Henrique de Moraes Holschuh92641172007-04-21 11:08:35 -03002955 ibm->flags.init_called = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002956 }
2957
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03002958 if (ibm->acpi) {
2959 if (ibm->acpi->hid) {
2960 ret = register_tpacpi_subdriver(ibm);
2961 if (ret)
2962 goto err_out;
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03002963 }
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03002964
2965 if (ibm->acpi->notify) {
2966 ret = setup_acpi_notify(ibm);
2967 if (ret == -ENODEV) {
2968 printk(IBM_NOTICE "disabling subdriver %s\n",
2969 ibm->name);
2970 ret = 0;
2971 goto err_out;
2972 }
2973 if (ret < 0)
2974 goto err_out;
2975 }
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03002976 }
2977
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03002978 dbg_printk(TPACPI_DBG_INIT,
2979 "%s installed\n", ibm->name);
2980
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002981 if (ibm->read) {
2982 entry = create_proc_entry(ibm->name,
2983 S_IFREG | S_IRUGO | S_IWUSR,
2984 proc_dir);
2985 if (!entry) {
2986 printk(IBM_ERR "unable to create proc entry %s\n",
2987 ibm->name);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03002988 ret = -ENODEV;
2989 goto err_out;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002990 }
2991 entry->owner = THIS_MODULE;
2992 entry->data = ibm;
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03002993 entry->read_proc = &dispatch_procfs_read;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002994 if (ibm->write)
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03002995 entry->write_proc = &dispatch_procfs_write;
Henrique de Moraes Holschuh92641172007-04-21 11:08:35 -03002996 ibm->flags.proc_created = 1;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04002997 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03002999 list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers);
3000
Linus Torvalds1da177e2005-04-16 15:20:36 -07003001 return 0;
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03003002
3003err_out:
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03003004 dbg_printk(TPACPI_DBG_INIT,
3005 "%s: at error exit path with result %d\n",
3006 ibm->name, ret);
3007
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03003008 ibm_exit(ibm);
3009 return (ret < 0)? ret : 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003010}
3011
3012static void ibm_exit(struct ibm_struct *ibm)
3013{
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03003014 dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name);
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03003015
3016 list_del_init(&ibm->all_drivers);
3017
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03003018 if (ibm->flags.acpi_notify_installed) {
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03003019 dbg_printk(TPACPI_DBG_EXIT,
3020 "%s: acpi_remove_notify_handler\n", ibm->name);
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03003021 BUG_ON(!ibm->acpi);
3022 acpi_remove_notify_handler(*ibm->acpi->handle,
3023 ibm->acpi->type,
3024 dispatch_acpi_notify);
3025 ibm->flags.acpi_notify_installed = 0;
3026 ibm->flags.acpi_notify_installed = 0;
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03003027 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003028
Henrique de Moraes Holschuh92641172007-04-21 11:08:35 -03003029 if (ibm->flags.proc_created) {
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03003030 dbg_printk(TPACPI_DBG_EXIT,
3031 "%s: remove_proc_entry\n", ibm->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032 remove_proc_entry(ibm->name, proc_dir);
Henrique de Moraes Holschuh92641172007-04-21 11:08:35 -03003033 ibm->flags.proc_created = 0;
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03003034 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03003036 if (ibm->flags.acpi_driver_registered) {
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -03003037 dbg_printk(TPACPI_DBG_EXIT,
3038 "%s: acpi_bus_unregister_driver\n", ibm->name);
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03003039 BUG_ON(!ibm->acpi);
3040 acpi_bus_unregister_driver(ibm->acpi->driver);
3041 kfree(ibm->acpi->driver);
3042 ibm->acpi->driver = NULL;
3043 ibm->flags.acpi_driver_registered = 0;
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03003044 }
3045
Henrique de Moraes Holschuh92641172007-04-21 11:08:35 -03003046 if (ibm->flags.init_called && ibm->exit) {
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03003047 ibm->exit();
Henrique de Moraes Holschuh92641172007-04-21 11:08:35 -03003048 ibm->flags.init_called = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003049 }
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03003050
3051 dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052}
3053
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003054/* Probing */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003056static char *ibm_thinkpad_ec_found = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003057
Henrique de Moraes Holschuh49a13cd2006-11-24 11:47:13 -02003058static char* __init check_dmi_for_ec(void)
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02003059{
3060 struct dmi_device *dev = NULL;
Henrique de Moraes Holschuh49a13cd2006-11-24 11:47:13 -02003061 char ec_fw_string[18];
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02003062
3063 /*
3064 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
3065 * X32 or newer, all Z series; Some models must have an
3066 * up-to-date BIOS or they will not be detected.
3067 *
3068 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
3069 */
3070 while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
Henrique de Moraes Holschuh49a13cd2006-11-24 11:47:13 -02003071 if (sscanf(dev->name,
3072 "IBM ThinkPad Embedded Controller -[%17c",
3073 ec_fw_string) == 1) {
3074 ec_fw_string[sizeof(ec_fw_string) - 1] = 0;
3075 ec_fw_string[strcspn(ec_fw_string, " ]")] = 0;
3076 return kstrdup(ec_fw_string, GFP_KERNEL);
3077 }
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02003078 }
Henrique de Moraes Holschuh49a13cd2006-11-24 11:47:13 -02003079 return NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003080}
3081
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03003082static int __init probe_for_thinkpad(void)
3083{
3084 int is_thinkpad;
3085
3086 if (acpi_disabled)
3087 return -ENODEV;
3088
3089 /*
3090 * Non-ancient models have better DMI tagging, but very old models
3091 * don't.
3092 */
3093 is_thinkpad = dmi_name_in_vendors("ThinkPad");
3094
3095 /* ec is required because many other handles are relative to it */
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03003096 IBM_ACPIHANDLE_INIT(ec);
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03003097 if (!ec_handle) {
3098 if (is_thinkpad)
3099 printk(IBM_ERR
3100 "Not yet supported ThinkPad detected!\n");
3101 return -ENODEV;
3102 }
3103
Henrique de Moraes Holschuh0dcef772007-04-21 11:08:34 -03003104 /*
3105 * Risks a regression on very old machines, but reduces potential
3106 * false positives a damn great deal
3107 */
3108 if (!is_thinkpad)
3109 is_thinkpad = dmi_name_in_vendors("IBM");
3110
3111 if (!is_thinkpad && !force_load)
3112 return -ENODEV;
3113
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03003114 return 0;
3115}
3116
3117
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003118/* Module init, exit, parameters */
3119
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03003120static struct ibm_init_struct ibms_init[] __initdata = {
3121 {
3122 .init = thinkpad_acpi_driver_init,
3123 .data = &thinkpad_acpi_driver_data,
3124 },
3125 {
3126 .init = hotkey_init,
3127 .data = &hotkey_driver_data,
3128 },
3129 {
3130 .init = bluetooth_init,
3131 .data = &bluetooth_driver_data,
3132 },
3133 {
3134 .init = wan_init,
3135 .data = &wan_driver_data,
3136 },
3137 {
3138 .init = video_init,
3139 .data = &video_driver_data,
3140 },
3141 {
3142 .init = light_init,
3143 .data = &light_driver_data,
3144 },
3145#ifdef CONFIG_THINKPAD_ACPI_DOCK
3146 {
3147 .init = dock_init,
3148 .data = &dock_driver_data[0],
3149 },
3150 {
3151 .data = &dock_driver_data[1],
3152 },
3153#endif
3154#ifdef CONFIG_THINKPAD_ACPI_BAY
3155 {
3156 .init = bay_init,
3157 .data = &bay_driver_data,
3158 },
3159#endif
3160 {
3161 .init = cmos_init,
3162 .data = &cmos_driver_data,
3163 },
3164 {
3165 .init = led_init,
3166 .data = &led_driver_data,
3167 },
3168 {
3169 .init = beep_init,
3170 .data = &beep_driver_data,
3171 },
3172 {
3173 .init = thermal_init,
3174 .data = &thermal_driver_data,
3175 },
3176 {
3177 .data = &ecdump_driver_data,
3178 },
3179 {
3180 .init = brightness_init,
3181 .data = &brightness_driver_data,
3182 },
3183 {
3184 .data = &volume_driver_data,
3185 },
3186 {
3187 .init = fan_init,
3188 .data = &fan_driver_data,
3189 },
3190};
3191
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003192static int __init set_ibm_param(const char *val, struct kernel_param *kp)
3193{
3194 unsigned int i;
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03003195 struct ibm_struct *ibm;
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003196
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03003197 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
3198 ibm = ibms_init[i].data;
3199 BUG_ON(ibm == NULL);
3200
3201 if (strcmp(ibm->name, kp->name) == 0 && ibm->write) {
3202 if (strlen(val) > sizeof(ibms_init[i].param) - 2)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003203 return -ENOSPC;
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03003204 strcpy(ibms_init[i].param, val);
3205 strcat(ibms_init[i].param, ",");
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003206 return 0;
3207 }
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03003208 }
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003209
3210 return -EINVAL;
3211}
3212
3213static int experimental;
3214module_param(experimental, int, 0);
3215
Henrique de Moraes Holschuh132ce092007-04-21 11:08:30 -03003216static u32 dbg_level;
3217module_param_named(debug, dbg_level, uint, 0);
3218
Henrique de Moraes Holschuh0dcef772007-04-21 11:08:34 -03003219static int force_load;
3220module_param(force_load, int, 0);
3221
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003222#define IBM_PARAM(feature) \
3223 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
3224
3225IBM_PARAM(hotkey);
3226IBM_PARAM(bluetooth);
3227IBM_PARAM(video);
3228IBM_PARAM(light);
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -03003229#ifdef CONFIG_THINKPAD_ACPI_DOCK
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003230IBM_PARAM(dock);
3231#endif
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -03003232#ifdef CONFIG_THINKPAD_ACPI_BAY
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003233IBM_PARAM(bay);
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -03003234#endif /* CONFIG_THINKPAD_ACPI_BAY */
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003235IBM_PARAM(cmos);
3236IBM_PARAM(led);
3237IBM_PARAM(beep);
3238IBM_PARAM(ecdump);
3239IBM_PARAM(brightness);
3240IBM_PARAM(volume);
3241IBM_PARAM(fan);
3242
Henrique de Moraes Holschuh1def7112007-04-21 11:08:27 -03003243static int __init thinkpad_acpi_module_init(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003244{
3245 int ret, i;
3246
Henrique de Moraes Holschuh54ae1502007-04-24 11:48:12 -03003247 /* Driver-level probe */
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -03003248 ret = probe_for_thinkpad();
3249 if (ret)
3250 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003251
Henrique de Moraes Holschuh54ae1502007-04-24 11:48:12 -03003252 /* Driver initialization */
Henrique de Moraes Holschuh60eb0b32006-11-24 11:47:08 -02003253 ibm_thinkpad_ec_found = check_dmi_for_ec();
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03003254 IBM_ACPIHANDLE_INIT(ecrd);
3255 IBM_ACPIHANDLE_INIT(ecwr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003256
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03003257 proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003258 if (!proc_dir) {
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03003259 printk(IBM_ERR "unable to create proc dir " IBM_PROC_DIR);
Henrique de Moraes Holschuh1def7112007-04-21 11:08:27 -03003260 thinkpad_acpi_module_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003261 return -ENODEV;
3262 }
3263 proc_dir->owner = THIS_MODULE;
Borislav Deianov78f81cc2005-08-17 00:00:00 -04003264
Henrique de Moraes Holschuh54ae1502007-04-24 11:48:12 -03003265 ret = platform_driver_register(&tpacpi_pdriver);
3266 if (ret) {
3267 printk(IBM_ERR "unable to register platform driver\n");
3268 thinkpad_acpi_module_exit();
3269 return ret;
3270 }
3271
3272 /* Device initialization */
3273 tpacpi_pdev = platform_device_register_simple(IBM_DRVR_NAME, -1,
3274 NULL, 0);
3275 if (IS_ERR(tpacpi_pdev)) {
3276 ret = PTR_ERR(tpacpi_pdev);
3277 tpacpi_pdev = NULL;
3278 printk(IBM_ERR "unable to register platform device\n");
3279 thinkpad_acpi_module_exit();
3280 return ret;
3281 }
3282 tpacpi_hwmon = hwmon_device_register(&tpacpi_pdev->dev);
3283 if (IS_ERR(tpacpi_hwmon)) {
3284 ret = PTR_ERR(tpacpi_hwmon);
3285 tpacpi_hwmon = NULL;
3286 printk(IBM_ERR "unable to register hwmon device\n");
3287 thinkpad_acpi_module_exit();
3288 return ret;
3289 }
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03003290 for (i = 0; i < ARRAY_SIZE(ibms_init); i++) {
3291 ret = ibm_init(&ibms_init[i]);
3292 if (ret >= 0 && *ibms_init[i].param)
3293 ret = ibms_init[i].data->write(ibms_init[i].param);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 if (ret < 0) {
Henrique de Moraes Holschuh1def7112007-04-21 11:08:27 -03003295 thinkpad_acpi_module_exit();
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 return ret;
3297 }
3298 }
3299
3300 return 0;
3301}
3302
Henrique de Moraes Holschuh1def7112007-04-21 11:08:27 -03003303static void thinkpad_acpi_module_exit(void)
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003304{
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03003305 struct ibm_struct *ibm, *itmp;
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003306
Henrique de Moraes Holschuha5763f22007-04-21 11:08:33 -03003307 list_for_each_entry_safe_reverse(ibm, itmp,
3308 &tpacpi_all_drivers,
3309 all_drivers) {
3310 ibm_exit(ibm);
3311 }
3312
3313 dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n");
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003314
Henrique de Moraes Holschuh54ae1502007-04-24 11:48:12 -03003315 if (tpacpi_hwmon)
3316 hwmon_device_unregister(tpacpi_hwmon);
3317
3318 if (tpacpi_pdev)
3319 platform_device_unregister(tpacpi_pdev);
3320
3321 platform_driver_unregister(&tpacpi_pdriver);
3322
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003323 if (proc_dir)
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03003324 remove_proc_entry(IBM_PROC_DIR, acpi_root_dir);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003325
Henrique de Moraes Holschuh8d376cd2007-04-21 11:08:37 -03003326 kfree(ibm_thinkpad_ec_found);
Henrique de Moraes Holschuh56b6aeb2007-03-23 17:33:57 -03003327}
3328
Henrique de Moraes Holschuh1def7112007-04-21 11:08:27 -03003329module_init(thinkpad_acpi_module_init);
3330module_exit(thinkpad_acpi_module_exit);