Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ibm_acpi.c - IBM ThinkPad ACPI Extras |
| 3 | * |
| 4 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 5 | * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net> |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 6 | * Copyright (C) 2006 Henrique de Moraes Holschuh <hmh@hmh.eng.br> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 21 | */ |
| 22 | |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 23 | #define IBM_VERSION "0.13" |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 24 | |
| 25 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * Changelog: |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 27 | * |
| 28 | * 2006-11-22 0.13 new maintainer |
| 29 | * changelog now lives in git commit history, and will |
| 30 | * not be updated further in-file. |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 31 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 32 | * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels |
| 33 | * 2005-03-17 0.11 support for 600e, 770x |
| 34 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> |
| 35 | * support for 770e, G41 |
| 36 | * G40 and G41 don't have a thinklight |
| 37 | * temperatures no longer experimental |
| 38 | * experimental brightness control |
| 39 | * experimental volume control |
| 40 | * experimental fan enable/disable |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 41 | * 2005-01-16 0.10 fix module loading on R30, R31 |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 42 | * 2005-01-16 0.9 support for 570, R30, R31 |
| 43 | * ultrabay support on A22p, A3x |
| 44 | * limit arg for cmos, led, beep, drop experimental status |
| 45 | * more capable led control on A21e, A22p, T20-22, X20 |
| 46 | * experimental temperatures and fan speed |
| 47 | * experimental embedded controller register dump |
| 48 | * mark more functions as __init, drop incorrect __exit |
| 49 | * use MODULE_VERSION |
| 50 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
| 51 | * fix parameter passing on module loading |
| 52 | * thanks to Rusty Russell <rusty@rustcorp.com.au> |
| 53 | * thanks to Jim Radford <radford@blackbean.org> |
| 54 | * 2004-11-08 0.8 fix init error case, don't return from a macro |
| 55 | * thanks to Chris Wright <chrisw@osdl.org> |
| 56 | * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20 |
| 57 | * fix led control on A21e |
| 58 | * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20 |
| 60 | * proc file format changed |
| 61 | * video_switch command |
| 62 | * experimental cmos control |
| 63 | * experimental led control |
| 64 | * experimental acpi sounds |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 65 | * 2004-09-16 0.4 support for module parameters |
| 66 | * hotkey mask can be prefixed by 0x |
| 67 | * video output switching |
| 68 | * video expansion control |
| 69 | * ultrabay eject support |
| 70 | * removed lcd brightness/on/off control, didn't work |
| 71 | * 2004-08-17 0.3 support for R40 |
| 72 | * lcd off, brightness control |
| 73 | * thinklight on/off |
| 74 | * 2004-08-14 0.2 support for T series, X20 |
| 75 | * bluetooth enable/disable |
| 76 | * hotkey events disabled by default |
| 77 | * removed fan control, currently useless |
| 78 | * 2004-08-09 0.1 initial release, support for X series |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | */ |
| 80 | |
Henrique de Moraes Holschuh | 1406cdd | 2007-03-23 17:33:56 -0300 | [diff] [blame] | 81 | #include "ibm_acpi.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 83 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 84 | MODULE_DESCRIPTION(IBM_DESC); |
| 85 | MODULE_VERSION(IBM_VERSION); |
| 86 | MODULE_LICENSE("GPL"); |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #define __unused __attribute__ ((unused)) |
| 89 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 90 | /**************************************************************************** |
| 91 | **************************************************************************** |
| 92 | * |
| 93 | * ACPI Helpers and device model |
| 94 | * |
| 95 | **************************************************************************** |
| 96 | ****************************************************************************/ |
| 97 | |
| 98 | /************************************************************************* |
| 99 | * ACPI basic handles |
| 100 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
| 102 | static acpi_handle root_handle = NULL; |
| 103 | |
| 104 | #define IBM_HANDLE(object, parent, paths...) \ |
| 105 | static acpi_handle object##_handle; \ |
| 106 | static acpi_handle *object##_parent = &parent##_handle; \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 107 | static char *object##_path; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | static char *object##_paths[] = { paths } |
| 109 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 110 | IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
| 111 | "\\_SB.PCI.ISA.EC", /* 570 */ |
| 112 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
| 113 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
| 114 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ |
| 115 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ |
| 116 | "\\_SB.PCI0.LPC.EC", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 117 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 119 | IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 120 | IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 122 | |
| 123 | /************************************************************************* |
| 124 | * Misc ACPI handles |
| 125 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 127 | IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */ |
| 128 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 129 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 130 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 131 | |
| 132 | IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
| 133 | "^HKEY", /* R30, R31 */ |
| 134 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 135 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 136 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 137 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 138 | /************************************************************************* |
| 139 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 140 | */ |
| 141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | static int acpi_evalf(acpi_handle handle, |
| 143 | void *res, char *method, char *fmt, ...) |
| 144 | { |
| 145 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 146 | struct acpi_object_list params; |
| 147 | union acpi_object in_objs[IBM_MAX_ACPI_ARGS]; |
| 148 | struct acpi_buffer result, *resultp; |
| 149 | union acpi_object out_obj; |
| 150 | acpi_status status; |
| 151 | va_list ap; |
| 152 | char res_type; |
| 153 | int success; |
| 154 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | |
| 156 | if (!*fmt) { |
| 157 | printk(IBM_ERR "acpi_evalf() called with empty format\n"); |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | if (*fmt == 'q') { |
| 162 | quiet = 1; |
| 163 | fmt++; |
| 164 | } else |
| 165 | quiet = 0; |
| 166 | |
| 167 | res_type = *(fmt++); |
| 168 | |
| 169 | params.count = 0; |
| 170 | params.pointer = &in_objs[0]; |
| 171 | |
| 172 | va_start(ap, fmt); |
| 173 | while (*fmt) { |
| 174 | char c = *(fmt++); |
| 175 | switch (c) { |
| 176 | case 'd': /* int */ |
| 177 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 178 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 179 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 180 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | default: |
| 182 | printk(IBM_ERR "acpi_evalf() called " |
| 183 | "with invalid format character '%c'\n", c); |
| 184 | return 0; |
| 185 | } |
| 186 | } |
| 187 | va_end(ap); |
| 188 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 189 | if (res_type != 'v') { |
| 190 | result.length = sizeof(out_obj); |
| 191 | result.pointer = &out_obj; |
| 192 | resultp = &result; |
| 193 | } else |
| 194 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 196 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 199 | case 'd': /* int */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | if (res) |
| 201 | *(int *)res = out_obj.integer.value; |
| 202 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; |
| 203 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 204 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 205 | success = status == AE_OK; |
| 206 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 207 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | default: |
| 209 | printk(IBM_ERR "acpi_evalf() called " |
| 210 | "with invalid format character '%c'\n", res_type); |
| 211 | return 0; |
| 212 | } |
| 213 | |
| 214 | if (!success && !quiet) |
| 215 | printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
| 216 | method, fmt0, status); |
| 217 | |
| 218 | return success; |
| 219 | } |
| 220 | |
| 221 | static void __unused acpi_print_int(acpi_handle handle, char *method) |
| 222 | { |
| 223 | int i; |
| 224 | |
| 225 | if (acpi_evalf(handle, &i, method, "d")) |
| 226 | printk(IBM_INFO "%s = 0x%x\n", method, i); |
| 227 | else |
| 228 | printk(IBM_ERR "error calling %s\n", method); |
| 229 | } |
| 230 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 231 | static int acpi_ec_read(int i, u8 * p) |
| 232 | { |
| 233 | int v; |
| 234 | |
| 235 | if (ecrd_handle) { |
| 236 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 237 | return 0; |
| 238 | *p = v; |
| 239 | } else { |
| 240 | if (ec_read(i, p) < 0) |
| 241 | return 0; |
| 242 | } |
| 243 | |
| 244 | return 1; |
| 245 | } |
| 246 | |
| 247 | static int acpi_ec_write(int i, u8 v) |
| 248 | { |
| 249 | if (ecwr_handle) { |
| 250 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 251 | return 0; |
| 252 | } else { |
| 253 | if (ec_write(i, v) < 0) |
| 254 | return 0; |
| 255 | } |
| 256 | |
| 257 | return 1; |
| 258 | } |
| 259 | |
| 260 | static int _sta(acpi_handle handle) |
| 261 | { |
| 262 | int status; |
| 263 | |
| 264 | if (!handle || !acpi_evalf(handle, &status, "_STA", "d")) |
| 265 | status = 0; |
| 266 | |
| 267 | return status; |
| 268 | } |
| 269 | |
| 270 | /************************************************************************* |
| 271 | * ACPI device model |
| 272 | */ |
| 273 | |
| 274 | static void __init ibm_handle_init(char *name, |
| 275 | acpi_handle * handle, acpi_handle parent, |
| 276 | char **paths, int num_paths, char **path) |
| 277 | { |
| 278 | int i; |
| 279 | acpi_status status; |
| 280 | |
| 281 | for (i = 0; i < num_paths; i++) { |
| 282 | status = acpi_get_handle(parent, paths[i], handle); |
| 283 | if (ACPI_SUCCESS(status)) { |
| 284 | *path = paths[i]; |
| 285 | return; |
| 286 | } |
| 287 | } |
| 288 | |
| 289 | *handle = NULL; |
| 290 | } |
| 291 | |
| 292 | static void dispatch_notify(acpi_handle handle, u32 event, void *data) |
| 293 | { |
| 294 | struct ibm_struct *ibm = data; |
| 295 | |
| 296 | if (!ibm || !ibm->notify) |
| 297 | return; |
| 298 | |
| 299 | ibm->notify(ibm, event); |
| 300 | } |
| 301 | |
| 302 | static int __init setup_notify(struct ibm_struct *ibm) |
| 303 | { |
| 304 | acpi_status status; |
| 305 | int ret; |
| 306 | |
| 307 | if (!*ibm->handle) |
| 308 | return 0; |
| 309 | |
| 310 | ret = acpi_bus_get_device(*ibm->handle, &ibm->device); |
| 311 | if (ret < 0) { |
| 312 | printk(IBM_ERR "%s device not present\n", ibm->name); |
| 313 | return -ENODEV; |
| 314 | } |
| 315 | |
| 316 | acpi_driver_data(ibm->device) = ibm; |
| 317 | sprintf(acpi_device_class(ibm->device), "%s/%s", IBM_NAME, ibm->name); |
| 318 | |
| 319 | status = acpi_install_notify_handler(*ibm->handle, ibm->type, |
| 320 | dispatch_notify, ibm); |
| 321 | if (ACPI_FAILURE(status)) { |
| 322 | if (status == AE_ALREADY_EXISTS) { |
| 323 | printk(IBM_NOTICE "another device driver is already handling %s events\n", |
| 324 | ibm->name); |
| 325 | } else { |
| 326 | printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n", |
| 327 | ibm->name, status); |
| 328 | } |
| 329 | return -ENODEV; |
| 330 | } |
| 331 | ibm->notify_installed = 1; |
| 332 | return 0; |
| 333 | } |
| 334 | |
| 335 | static int __init ibm_device_add(struct acpi_device *device) |
| 336 | { |
| 337 | return 0; |
| 338 | } |
| 339 | |
| 340 | static int __init register_ibmacpi_subdriver(struct ibm_struct *ibm) |
| 341 | { |
| 342 | int ret; |
| 343 | |
| 344 | ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 345 | if (!ibm->driver) { |
| 346 | printk(IBM_ERR "kmalloc(ibm->driver) failed\n"); |
| 347 | return -1; |
| 348 | } |
| 349 | |
| 350 | sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name); |
| 351 | ibm->driver->ids = ibm->hid; |
| 352 | ibm->driver->ops.add = &ibm_device_add; |
| 353 | |
| 354 | ret = acpi_bus_register_driver(ibm->driver); |
| 355 | if (ret < 0) { |
| 356 | printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
| 357 | ibm->hid, ret); |
| 358 | kfree(ibm->driver); |
| 359 | } |
| 360 | |
| 361 | return ret; |
| 362 | } |
| 363 | |
| 364 | |
| 365 | /**************************************************************************** |
| 366 | **************************************************************************** |
| 367 | * |
| 368 | * Procfs Helpers |
| 369 | * |
| 370 | **************************************************************************** |
| 371 | ****************************************************************************/ |
| 372 | |
| 373 | static int dispatch_read(char *page, char **start, off_t off, int count, |
| 374 | int *eof, void *data) |
| 375 | { |
| 376 | struct ibm_struct *ibm = data; |
| 377 | int len; |
| 378 | |
| 379 | if (!ibm || !ibm->read) |
| 380 | return -EINVAL; |
| 381 | |
| 382 | len = ibm->read(page); |
| 383 | if (len < 0) |
| 384 | return len; |
| 385 | |
| 386 | if (len <= off + count) |
| 387 | *eof = 1; |
| 388 | *start = page + off; |
| 389 | len -= off; |
| 390 | if (len > count) |
| 391 | len = count; |
| 392 | if (len < 0) |
| 393 | len = 0; |
| 394 | |
| 395 | return len; |
| 396 | } |
| 397 | |
| 398 | static int dispatch_write(struct file *file, const char __user * userbuf, |
| 399 | unsigned long count, void *data) |
| 400 | { |
| 401 | struct ibm_struct *ibm = data; |
| 402 | char *kernbuf; |
| 403 | int ret; |
| 404 | |
| 405 | if (!ibm || !ibm->write) |
| 406 | return -EINVAL; |
| 407 | |
| 408 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 409 | if (!kernbuf) |
| 410 | return -ENOMEM; |
| 411 | |
| 412 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 413 | kfree(kernbuf); |
| 414 | return -EFAULT; |
| 415 | } |
| 416 | |
| 417 | kernbuf[count] = 0; |
| 418 | strcat(kernbuf, ","); |
| 419 | ret = ibm->write(kernbuf); |
| 420 | if (ret == 0) |
| 421 | ret = count; |
| 422 | |
| 423 | kfree(kernbuf); |
| 424 | |
| 425 | return ret; |
| 426 | } |
| 427 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | static char *next_cmd(char **cmds) |
| 429 | { |
| 430 | char *start = *cmds; |
| 431 | char *end; |
| 432 | |
| 433 | while ((end = strchr(start, ',')) && end == start) |
| 434 | start = end + 1; |
| 435 | |
| 436 | if (!end) |
| 437 | return NULL; |
| 438 | |
| 439 | *end = 0; |
| 440 | *cmds = end + 1; |
| 441 | return start; |
| 442 | } |
| 443 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 444 | |
| 445 | /**************************************************************************** |
| 446 | **************************************************************************** |
| 447 | * |
| 448 | * Subdrivers |
| 449 | * |
| 450 | **************************************************************************** |
| 451 | ****************************************************************************/ |
| 452 | |
| 453 | /************************************************************************* |
| 454 | * ibm-acpi init subdriver |
| 455 | */ |
| 456 | |
Adrian Bunk | 1f21782 | 2006-12-19 13:01:28 -0800 | [diff] [blame] | 457 | static int ibm_acpi_driver_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | { |
| 459 | printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); |
| 460 | printk(IBM_INFO "%s\n", IBM_URL); |
| 461 | |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 462 | if (ibm_thinkpad_ec_found) |
| 463 | printk(IBM_INFO "ThinkPad EC firmware %s\n", |
| 464 | ibm_thinkpad_ec_found); |
| 465 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | return 0; |
| 467 | } |
| 468 | |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 469 | static int ibm_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | { |
| 471 | int len = 0; |
| 472 | |
| 473 | len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC); |
| 474 | len += sprintf(p + len, "version:\t%s\n", IBM_VERSION); |
| 475 | |
| 476 | return len; |
| 477 | } |
| 478 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 479 | /************************************************************************* |
| 480 | * Hotkey subdriver |
| 481 | */ |
| 482 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 483 | static int hotkey_supported; |
| 484 | static int hotkey_mask_supported; |
| 485 | static int hotkey_orig_status; |
| 486 | static int hotkey_orig_mask; |
| 487 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 488 | static int hotkey_init(void) |
| 489 | { |
| 490 | /* hotkey not supported on 570 */ |
| 491 | hotkey_supported = hkey_handle != NULL; |
| 492 | |
| 493 | if (hotkey_supported) { |
| 494 | /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 495 | A30, R30, R31, T20-22, X20-21, X22-24 */ |
| 496 | hotkey_mask_supported = |
| 497 | acpi_evalf(hkey_handle, NULL, "DHKN", "qv"); |
| 498 | |
| 499 | if (!hotkey_get(&hotkey_orig_status, &hotkey_orig_mask)) |
| 500 | return -ENODEV; |
| 501 | } |
| 502 | |
| 503 | return 0; |
| 504 | } |
| 505 | |
| 506 | static void hotkey_exit(void) |
| 507 | { |
| 508 | if (hotkey_supported) |
| 509 | hotkey_set(hotkey_orig_status, hotkey_orig_mask); |
| 510 | } |
| 511 | |
| 512 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 513 | { |
| 514 | int hkey; |
| 515 | |
| 516 | if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) |
| 517 | acpi_bus_generate_event(ibm->device, event, hkey); |
| 518 | else { |
| 519 | printk(IBM_ERR "unknown hotkey event %d\n", event); |
| 520 | acpi_bus_generate_event(ibm->device, event, 0); |
| 521 | } |
| 522 | } |
| 523 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 524 | static int hotkey_get(int *status, int *mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | { |
| 526 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 527 | return 0; |
| 528 | |
| 529 | if (hotkey_mask_supported) |
| 530 | if (!acpi_evalf(hkey_handle, mask, "DHKN", "d")) |
| 531 | return 0; |
| 532 | |
| 533 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | } |
| 535 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 536 | static int hotkey_set(int status, int mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | { |
| 538 | int i; |
| 539 | |
| 540 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | return 0; |
| 542 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 543 | if (hotkey_mask_supported) |
| 544 | for (i = 0; i < 32; i++) { |
| 545 | int bit = ((1 << i) & mask) != 0; |
| 546 | if (!acpi_evalf(hkey_handle, |
| 547 | NULL, "MHKM", "vdd", i + 1, bit)) |
| 548 | return 0; |
| 549 | } |
| 550 | |
| 551 | return 1; |
| 552 | } |
| 553 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 554 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | { |
| 556 | int status, mask; |
| 557 | int len = 0; |
| 558 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 559 | if (!hotkey_supported) { |
| 560 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 561 | return len; |
| 562 | } |
| 563 | |
| 564 | if (!hotkey_get(&status, &mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | return -EIO; |
| 566 | |
| 567 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 568 | if (hotkey_mask_supported) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | len += sprintf(p + len, "mask:\t\t0x%04x\n", mask); |
| 570 | len += sprintf(p + len, |
| 571 | "commands:\tenable, disable, reset, <mask>\n"); |
| 572 | } else { |
| 573 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 574 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 575 | } |
| 576 | |
| 577 | return len; |
| 578 | } |
| 579 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 580 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | { |
| 582 | int status, mask; |
| 583 | char *cmd; |
| 584 | int do_cmd = 0; |
| 585 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 586 | if (!hotkey_supported) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | return -ENODEV; |
| 588 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 589 | if (!hotkey_get(&status, &mask)) |
| 590 | return -EIO; |
| 591 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | while ((cmd = next_cmd(&buf))) { |
| 593 | if (strlencmp(cmd, "enable") == 0) { |
| 594 | status = 1; |
| 595 | } else if (strlencmp(cmd, "disable") == 0) { |
| 596 | status = 0; |
| 597 | } else if (strlencmp(cmd, "reset") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 598 | status = hotkey_orig_status; |
| 599 | mask = hotkey_orig_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 601 | /* mask set */ |
| 602 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 603 | /* mask set */ |
| 604 | } else |
| 605 | return -EINVAL; |
| 606 | do_cmd = 1; |
| 607 | } |
| 608 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 609 | if (do_cmd && !hotkey_set(status, mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 610 | return -EIO; |
| 611 | |
| 612 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 613 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 615 | /************************************************************************* |
| 616 | * Bluetooth subdriver |
| 617 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 619 | static int bluetooth_supported; |
| 620 | |
| 621 | static int bluetooth_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 623 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 624 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
| 625 | bluetooth_supported = hkey_handle && |
| 626 | acpi_evalf(hkey_handle, NULL, "GBDC", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
| 628 | return 0; |
| 629 | } |
| 630 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 631 | static int bluetooth_status(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | { |
| 633 | int status; |
| 634 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 635 | if (!bluetooth_supported || |
| 636 | !acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | status = 0; |
| 638 | |
| 639 | return status; |
| 640 | } |
| 641 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 642 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | { |
| 644 | int len = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 645 | int status = bluetooth_status(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 647 | if (!bluetooth_supported) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 649 | else if (!(status & 1)) |
| 650 | len += sprintf(p + len, "status:\t\tnot installed\n"); |
| 651 | else { |
| 652 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1)); |
| 653 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 654 | } |
| 655 | |
| 656 | return len; |
| 657 | } |
| 658 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 659 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 661 | int status = bluetooth_status(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | char *cmd; |
| 663 | int do_cmd = 0; |
| 664 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 665 | if (!bluetooth_supported) |
| 666 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | |
| 668 | while ((cmd = next_cmd(&buf))) { |
| 669 | if (strlencmp(cmd, "enable") == 0) { |
| 670 | status |= 2; |
| 671 | } else if (strlencmp(cmd, "disable") == 0) { |
| 672 | status &= ~2; |
| 673 | } else |
| 674 | return -EINVAL; |
| 675 | do_cmd = 1; |
| 676 | } |
| 677 | |
| 678 | if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 679 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
| 681 | return 0; |
| 682 | } |
| 683 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 684 | /************************************************************************* |
| 685 | * Wan subdriver |
| 686 | */ |
| 687 | |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 688 | static int wan_supported; |
| 689 | |
| 690 | static int wan_init(void) |
| 691 | { |
| 692 | wan_supported = hkey_handle && |
| 693 | acpi_evalf(hkey_handle, NULL, "GWAN", "qv"); |
| 694 | |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | static int wan_status(void) |
| 699 | { |
| 700 | int status; |
| 701 | |
Henrique de Moraes Holschuh | 8d29726 | 2006-11-24 11:47:07 -0200 | [diff] [blame] | 702 | if (!wan_supported || !acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 703 | status = 0; |
| 704 | |
| 705 | return status; |
| 706 | } |
| 707 | |
| 708 | static int wan_read(char *p) |
| 709 | { |
| 710 | int len = 0; |
| 711 | int status = wan_status(); |
| 712 | |
| 713 | if (!wan_supported) |
| 714 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 715 | else if (!(status & 1)) |
| 716 | len += sprintf(p + len, "status:\t\tnot installed\n"); |
| 717 | else { |
| 718 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1)); |
| 719 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 720 | } |
| 721 | |
| 722 | return len; |
| 723 | } |
| 724 | |
| 725 | static int wan_write(char *buf) |
| 726 | { |
| 727 | int status = wan_status(); |
| 728 | char *cmd; |
| 729 | int do_cmd = 0; |
| 730 | |
| 731 | if (!wan_supported) |
| 732 | return -ENODEV; |
| 733 | |
| 734 | while ((cmd = next_cmd(&buf))) { |
| 735 | if (strlencmp(cmd, "enable") == 0) { |
| 736 | status |= 2; |
| 737 | } else if (strlencmp(cmd, "disable") == 0) { |
| 738 | status &= ~2; |
| 739 | } else |
| 740 | return -EINVAL; |
| 741 | do_cmd = 1; |
| 742 | } |
| 743 | |
| 744 | if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 745 | return -EIO; |
| 746 | |
| 747 | return 0; |
| 748 | } |
| 749 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 750 | /************************************************************************* |
| 751 | * Video subdriver |
| 752 | */ |
| 753 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 754 | static enum video_access_mode video_supported; |
| 755 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 756 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 757 | IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 758 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 759 | "\\_SB.PCI0.VID0", /* 770e */ |
| 760 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 761 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 762 | ); /* R30, R31 */ |
| 763 | |
| 764 | IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
| 765 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 766 | static int video_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 768 | int ivga; |
| 769 | |
| 770 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 771 | /* G41, assume IVGA doesn't change */ |
| 772 | vid_handle = vid2_handle; |
| 773 | |
| 774 | if (!vid_handle) |
| 775 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 776 | video_supported = IBMACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 777 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 778 | /* 570 */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 779 | video_supported = IBMACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 780 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 781 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 782 | video_supported = IBMACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 783 | else |
| 784 | /* all others */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 785 | video_supported = IBMACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | |
| 787 | return 0; |
| 788 | } |
| 789 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 790 | static void video_exit(void) |
| 791 | { |
| 792 | acpi_evalf(vid_handle, NULL, "_DOS", "vd", video_orig_autosw); |
| 793 | } |
| 794 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 795 | static int video_status(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | { |
| 797 | int status = 0; |
| 798 | int i; |
| 799 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 800 | if (video_supported == IBMACPI_VIDEO_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 801 | if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87)) |
| 802 | status = i & 3; |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 803 | } else if (video_supported == IBMACPI_VIDEO_770) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 804 | if (acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 805 | status |= 0x01 * i; |
| 806 | if (acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 807 | status |= 0x02 * i; |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 808 | } else if (video_supported == IBMACPI_VIDEO_NEW) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 809 | acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1); |
| 810 | if (acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 811 | status |= 0x02 * i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 813 | acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0); |
| 814 | if (acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 815 | status |= 0x01 * i; |
| 816 | if (acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 817 | status |= 0x08 * i; |
| 818 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 819 | |
| 820 | return status; |
| 821 | } |
| 822 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 823 | static int video_autosw(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 825 | int autosw = 0; |
| 826 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 827 | if (video_supported == IBMACPI_VIDEO_570) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 828 | acpi_evalf(vid_handle, &autosw, "SWIT", "d"); |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 829 | else if (video_supported == IBMACPI_VIDEO_770 || |
| 830 | video_supported == IBMACPI_VIDEO_NEW) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 831 | acpi_evalf(vid_handle, &autosw, "^VDEE", "d"); |
| 832 | |
| 833 | return autosw & 1; |
| 834 | } |
| 835 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 836 | static int video_switch(void) |
| 837 | { |
| 838 | int autosw = video_autosw(); |
| 839 | int ret; |
| 840 | |
| 841 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) |
| 842 | return -EIO; |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 843 | ret = video_supported == IBMACPI_VIDEO_570 ? |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 844 | acpi_evalf(ec_handle, NULL, "_Q16", "v") : |
| 845 | acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 846 | acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw); |
| 847 | |
| 848 | return ret; |
| 849 | } |
| 850 | |
| 851 | static int video_expand(void) |
| 852 | { |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 853 | if (video_supported == IBMACPI_VIDEO_570) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 854 | return acpi_evalf(ec_handle, NULL, "_Q17", "v"); |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 855 | else if (video_supported == IBMACPI_VIDEO_770) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 856 | return acpi_evalf(vid_handle, NULL, "VEXP", "v"); |
| 857 | else |
| 858 | return acpi_evalf(NULL, NULL, "\\VEXP", "v"); |
| 859 | } |
| 860 | |
| 861 | static int video_switch2(int status) |
| 862 | { |
| 863 | int ret; |
| 864 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 865 | if (video_supported == IBMACPI_VIDEO_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 866 | ret = acpi_evalf(NULL, NULL, |
| 867 | "\\_SB.PHS2", "vdd", 0x8b, status | 0x80); |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 868 | } else if (video_supported == IBMACPI_VIDEO_770) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 869 | int autosw = video_autosw(); |
| 870 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) |
| 871 | return -EIO; |
| 872 | |
| 873 | ret = acpi_evalf(vid_handle, NULL, |
| 874 | "ASWT", "vdd", status * 0x100, 0); |
| 875 | |
| 876 | acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw); |
| 877 | } else { |
| 878 | ret = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
| 879 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
| 880 | } |
| 881 | |
| 882 | return ret; |
| 883 | } |
| 884 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 885 | static int video_read(char *p) |
| 886 | { |
| 887 | int status = video_status(); |
| 888 | int autosw = video_autosw(); |
| 889 | int len = 0; |
| 890 | |
| 891 | if (!video_supported) { |
| 892 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 893 | return len; |
| 894 | } |
| 895 | |
| 896 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 897 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 898 | len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1)); |
| 899 | if (video_supported == IBMACPI_VIDEO_NEW) |
| 900 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 901 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 902 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 903 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
| 904 | if (video_supported == IBMACPI_VIDEO_NEW) |
| 905 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 906 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
| 907 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 908 | |
| 909 | return len; |
| 910 | } |
| 911 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 912 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | { |
| 914 | char *cmd; |
| 915 | int enable, disable, status; |
| 916 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 917 | if (!video_supported) |
| 918 | return -ENODEV; |
| 919 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | enable = disable = 0; |
| 921 | |
| 922 | while ((cmd = next_cmd(&buf))) { |
| 923 | if (strlencmp(cmd, "lcd_enable") == 0) { |
| 924 | enable |= 0x01; |
| 925 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
| 926 | disable |= 0x01; |
| 927 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
| 928 | enable |= 0x02; |
| 929 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
| 930 | disable |= 0x02; |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 931 | } else if (video_supported == IBMACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 932 | strlencmp(cmd, "dvi_enable") == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | enable |= 0x08; |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 934 | } else if (video_supported == IBMACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 935 | strlencmp(cmd, "dvi_disable") == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | disable |= 0x08; |
| 937 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
| 938 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) |
| 939 | return -EIO; |
| 940 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
| 941 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 0)) |
| 942 | return -EIO; |
| 943 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 944 | if (!video_switch()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | return -EIO; |
| 946 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 947 | if (!video_expand()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | return -EIO; |
| 949 | } else |
| 950 | return -EINVAL; |
| 951 | } |
| 952 | |
| 953 | if (enable || disable) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 954 | status = (video_status() & 0x0f & ~disable) | enable; |
| 955 | if (!video_switch2(status)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 956 | return -EIO; |
| 957 | } |
| 958 | |
| 959 | return 0; |
| 960 | } |
| 961 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 962 | /************************************************************************* |
| 963 | * Light (thinklight) subdriver |
| 964 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 966 | static int light_supported; |
| 967 | static int light_status_supported; |
| 968 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 969 | IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 970 | IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
| 971 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 972 | static int light_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 974 | /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */ |
| 975 | light_supported = (cmos_handle || lght_handle) && !ledb_handle; |
| 976 | |
| 977 | if (light_supported) |
| 978 | /* light status not supported on |
| 979 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
| 980 | light_status_supported = acpi_evalf(ec_handle, NULL, |
| 981 | "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | |
| 983 | return 0; |
| 984 | } |
| 985 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 986 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | { |
| 988 | int len = 0; |
| 989 | int status = 0; |
| 990 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 991 | if (!light_supported) { |
| 992 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 993 | } else if (!light_status_supported) { |
| 994 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 995 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 996 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 997 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 998 | return -EIO; |
| 999 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1000 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 1001 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | |
| 1003 | return len; |
| 1004 | } |
| 1005 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1006 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1007 | { |
| 1008 | int cmos_cmd, lght_cmd; |
| 1009 | char *cmd; |
| 1010 | int success; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1011 | |
| 1012 | if (!light_supported) |
| 1013 | return -ENODEV; |
| 1014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | while ((cmd = next_cmd(&buf))) { |
| 1016 | if (strlencmp(cmd, "on") == 0) { |
| 1017 | cmos_cmd = 0x0c; |
| 1018 | lght_cmd = 1; |
| 1019 | } else if (strlencmp(cmd, "off") == 0) { |
| 1020 | cmos_cmd = 0x0d; |
| 1021 | lght_cmd = 0; |
| 1022 | } else |
| 1023 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1025 | success = cmos_handle ? |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1026 | acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) : |
| 1027 | acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1028 | if (!success) |
| 1029 | return -EIO; |
| 1030 | } |
| 1031 | |
| 1032 | return 0; |
| 1033 | } |
| 1034 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1035 | /************************************************************************* |
| 1036 | * Dock subdriver |
| 1037 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1038 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1039 | /* don't list other alternatives as we install a notify handler on the 570 */ |
| 1040 | IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ |
Henrique de Moraes Holschuh | d2fadbb | 2007-01-11 02:58:15 -0500 | [diff] [blame] | 1041 | |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 1042 | #ifdef CONFIG_ACPI_IBM_DOCK |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1043 | |
| 1044 | IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ |
| 1045 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ |
| 1046 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ |
| 1047 | "\\_SB.PCI.ISA.SLCE", /* 570 */ |
| 1048 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ |
| 1049 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | #define dock_docked() (_sta(dock_handle) & 1) |
| 1051 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1052 | static void dock_notify(struct ibm_struct *ibm, u32 event) |
| 1053 | { |
| 1054 | int docked = dock_docked(); |
| 1055 | int pci = ibm->hid && strstr(ibm->hid, IBM_PCI_HID); |
| 1056 | |
| 1057 | if (event == 1 && !pci) /* 570 */ |
| 1058 | acpi_bus_generate_event(ibm->device, event, 1); /* button */ |
| 1059 | else if (event == 1 && pci) /* 570 */ |
| 1060 | acpi_bus_generate_event(ibm->device, event, 3); /* dock */ |
| 1061 | else if (event == 3 && docked) |
| 1062 | acpi_bus_generate_event(ibm->device, event, 1); /* button */ |
| 1063 | else if (event == 3 && !docked) |
| 1064 | acpi_bus_generate_event(ibm->device, event, 2); /* undock */ |
| 1065 | else if (event == 0 && docked) |
| 1066 | acpi_bus_generate_event(ibm->device, event, 3); /* dock */ |
| 1067 | else { |
| 1068 | printk(IBM_ERR "unknown dock event %d, status %d\n", |
| 1069 | event, _sta(dock_handle)); |
| 1070 | acpi_bus_generate_event(ibm->device, event, 0); /* unknown */ |
| 1071 | } |
| 1072 | } |
| 1073 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1074 | static int dock_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1075 | { |
| 1076 | int len = 0; |
| 1077 | int docked = dock_docked(); |
| 1078 | |
| 1079 | if (!dock_handle) |
| 1080 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1081 | else if (!docked) |
| 1082 | len += sprintf(p + len, "status:\t\tundocked\n"); |
| 1083 | else { |
| 1084 | len += sprintf(p + len, "status:\t\tdocked\n"); |
| 1085 | len += sprintf(p + len, "commands:\tdock, undock\n"); |
| 1086 | } |
| 1087 | |
| 1088 | return len; |
| 1089 | } |
| 1090 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1091 | static int dock_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | { |
| 1093 | char *cmd; |
| 1094 | |
| 1095 | if (!dock_docked()) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1096 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | |
| 1098 | while ((cmd = next_cmd(&buf))) { |
| 1099 | if (strlencmp(cmd, "undock") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1100 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) || |
| 1101 | !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | return -EIO; |
| 1103 | } else if (strlencmp(cmd, "dock") == 0) { |
| 1104 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1)) |
| 1105 | return -EIO; |
| 1106 | } else |
| 1107 | return -EINVAL; |
| 1108 | } |
| 1109 | |
| 1110 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1111 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1112 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1113 | #endif /* CONFIG_ACPI_IBM_DOCK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1115 | /************************************************************************* |
| 1116 | * Bay subdriver |
| 1117 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1118 | |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 1119 | #ifdef CONFIG_ACPI_IBM_BAY |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1120 | static int bay_status_supported; |
| 1121 | static int bay_status2_supported; |
| 1122 | static int bay_eject_supported; |
| 1123 | static int bay_eject2_supported; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1124 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1125 | IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ |
| 1126 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ |
| 1127 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ |
| 1128 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ |
| 1129 | ); /* A21e, R30, R31 */ |
| 1130 | IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */ |
| 1131 | "_EJ0", /* all others */ |
| 1132 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ |
| 1133 | IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */ |
| 1134 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ |
| 1135 | ); /* all others */ |
| 1136 | IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ |
| 1137 | "_EJ0", /* 770x */ |
| 1138 | ); /* all others */ |
| 1139 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1140 | static int bay_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1141 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1142 | bay_status_supported = bay_handle && |
| 1143 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); |
| 1144 | bay_status2_supported = bay2_handle && |
| 1145 | acpi_evalf(bay2_handle, NULL, "_STA", "qv"); |
| 1146 | |
| 1147 | bay_eject_supported = bay_handle && bay_ej_handle && |
| 1148 | (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental); |
| 1149 | bay_eject2_supported = bay2_handle && bay2_ej_handle && |
| 1150 | (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
| 1152 | return 0; |
| 1153 | } |
| 1154 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1155 | static void bay_notify(struct ibm_struct *ibm, u32 event) |
| 1156 | { |
| 1157 | acpi_bus_generate_event(ibm->device, event, 0); |
| 1158 | } |
| 1159 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1160 | #define bay_occupied(b) (_sta(b##_handle) & 1) |
| 1161 | |
| 1162 | static int bay_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | { |
| 1164 | int len = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1165 | int occupied = bay_occupied(bay); |
| 1166 | int occupied2 = bay_occupied(bay2); |
| 1167 | int eject, eject2; |
| 1168 | |
| 1169 | len += sprintf(p + len, "status:\t\t%s\n", bay_status_supported ? |
| 1170 | (occupied ? "occupied" : "unoccupied") : |
| 1171 | "not supported"); |
| 1172 | if (bay_status2_supported) |
| 1173 | len += sprintf(p + len, "status2:\t%s\n", occupied2 ? |
| 1174 | "occupied" : "unoccupied"); |
| 1175 | |
| 1176 | eject = bay_eject_supported && occupied; |
| 1177 | eject2 = bay_eject2_supported && occupied2; |
| 1178 | |
| 1179 | if (eject && eject2) |
| 1180 | len += sprintf(p + len, "commands:\teject, eject2\n"); |
| 1181 | else if (eject) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1182 | len += sprintf(p + len, "commands:\teject\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1183 | else if (eject2) |
| 1184 | len += sprintf(p + len, "commands:\teject2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | |
| 1186 | return len; |
| 1187 | } |
| 1188 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1189 | static int bay_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1190 | { |
| 1191 | char *cmd; |
| 1192 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1193 | if (!bay_eject_supported && !bay_eject2_supported) |
| 1194 | return -ENODEV; |
| 1195 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1196 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1197 | if (bay_eject_supported && strlencmp(cmd, "eject") == 0) { |
| 1198 | if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1)) |
| 1199 | return -EIO; |
| 1200 | } else if (bay_eject2_supported && |
| 1201 | strlencmp(cmd, "eject2") == 0) { |
| 1202 | if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | return -EIO; |
| 1204 | } else |
| 1205 | return -EINVAL; |
| 1206 | } |
| 1207 | |
| 1208 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1209 | } |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 1210 | #endif /* CONFIG_ACPI_IBM_BAY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1212 | /************************************************************************* |
| 1213 | * CMOS subdriver |
| 1214 | */ |
| 1215 | |
| 1216 | static int cmos_eval(int cmos_cmd) |
| 1217 | { |
| 1218 | if (cmos_handle) |
| 1219 | return acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd); |
| 1220 | else |
| 1221 | return 1; |
| 1222 | } |
| 1223 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1224 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1225 | { |
| 1226 | int len = 0; |
| 1227 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1228 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 1229 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | if (!cmos_handle) |
| 1231 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1232 | else { |
| 1233 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1234 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | return len; |
| 1238 | } |
| 1239 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1240 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1241 | { |
| 1242 | char *cmd; |
| 1243 | int cmos_cmd; |
| 1244 | |
| 1245 | if (!cmos_handle) |
| 1246 | return -EINVAL; |
| 1247 | |
| 1248 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1249 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 1250 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1251 | /* cmos_cmd set */ |
| 1252 | } else |
| 1253 | return -EINVAL; |
| 1254 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1255 | if (!cmos_eval(cmos_cmd)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1256 | return -EIO; |
| 1257 | } |
| 1258 | |
| 1259 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1262 | |
| 1263 | /************************************************************************* |
| 1264 | * LED subdriver |
| 1265 | */ |
| 1266 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1267 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1268 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1269 | IBM_HANDLE(led, ec, "SLED", /* 570 */ |
| 1270 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 1271 | "LED", /* all others */ |
| 1272 | ); /* R30, R31 */ |
| 1273 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1274 | static int led_init(void) |
| 1275 | { |
| 1276 | if (!led_handle) |
| 1277 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1278 | led_supported = IBMACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1279 | else if (strlencmp(led_path, "SLED") == 0) |
| 1280 | /* 570 */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1281 | led_supported = IBMACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1282 | else if (strlencmp(led_path, "SYSL") == 0) |
| 1283 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1284 | led_supported = IBMACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1285 | else |
| 1286 | /* all others */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1287 | led_supported = IBMACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1288 | |
| 1289 | return 0; |
| 1290 | } |
| 1291 | |
| 1292 | #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking")) |
| 1293 | |
| 1294 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1295 | { |
| 1296 | int len = 0; |
| 1297 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1298 | if (!led_supported) { |
| 1299 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1300 | return len; |
| 1301 | } |
| 1302 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 1303 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1304 | if (led_supported == IBMACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1305 | /* 570 */ |
| 1306 | int i, status; |
| 1307 | for (i = 0; i < 8; i++) { |
| 1308 | if (!acpi_evalf(ec_handle, |
| 1309 | &status, "GLED", "dd", 1 << i)) |
| 1310 | return -EIO; |
| 1311 | len += sprintf(p + len, "%d:\t\t%s\n", |
| 1312 | i, led_status(status)); |
| 1313 | } |
| 1314 | } |
| 1315 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | len += sprintf(p + len, "commands:\t" |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1317 | "<led> on, <led> off, <led> blink (<led> is 0-7)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | |
| 1319 | return len; |
| 1320 | } |
| 1321 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1322 | /* off, on, blink */ |
| 1323 | static const int led_sled_arg1[] = { 0, 1, 3 }; |
| 1324 | static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */ |
| 1325 | static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */ |
| 1326 | static const int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
| 1327 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1328 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1329 | { |
| 1330 | char *cmd; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1331 | int led, ind, ret; |
| 1332 | |
| 1333 | if (!led_supported) |
| 1334 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1335 | |
| 1336 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1337 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | return -EINVAL; |
| 1339 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1340 | if (strstr(cmd, "off")) { |
| 1341 | ind = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | } else if (strstr(cmd, "on")) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1343 | ind = 1; |
| 1344 | } else if (strstr(cmd, "blink")) { |
| 1345 | ind = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1346 | } else |
| 1347 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1348 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1349 | if (led_supported == IBMACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1350 | /* 570 */ |
| 1351 | led = 1 << led; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1353 | led, led_sled_arg1[ind])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | return -EIO; |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1355 | } else if (led_supported == IBMACPI_LED_OLD) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1356 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
| 1357 | led = 1 << led; |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1358 | ret = ec_write(IBMACPI_LED_EC_HLMS, led); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1359 | if (ret >= 0) |
| 1360 | ret = |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1361 | ec_write(IBMACPI_LED_EC_HLBL, |
| 1362 | led * led_exp_hlbl[ind]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1363 | if (ret >= 0) |
| 1364 | ret = |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1365 | ec_write(IBMACPI_LED_EC_HLCL, |
| 1366 | led * led_exp_hlcl[ind]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1367 | if (ret < 0) |
| 1368 | return ret; |
| 1369 | } else { |
| 1370 | /* all others */ |
| 1371 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 1372 | led, led_led_arg1[ind])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1374 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1375 | } |
| 1376 | |
| 1377 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1378 | } |
| 1379 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1380 | /************************************************************************* |
| 1381 | * Beep subdriver |
| 1382 | */ |
| 1383 | |
| 1384 | IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
| 1385 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1386 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | { |
| 1388 | int len = 0; |
| 1389 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1390 | if (!beep_handle) |
| 1391 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1392 | else { |
| 1393 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 1394 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 1395 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | |
| 1397 | return len; |
| 1398 | } |
| 1399 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1400 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | { |
| 1402 | char *cmd; |
| 1403 | int beep_cmd; |
| 1404 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1405 | if (!beep_handle) |
| 1406 | return -ENODEV; |
| 1407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1408 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1409 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 1410 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1411 | /* beep_cmd set */ |
| 1412 | } else |
| 1413 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1414 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | return -EIO; |
| 1416 | } |
| 1417 | |
| 1418 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1419 | } |
| 1420 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1421 | /************************************************************************* |
| 1422 | * Thermal subdriver |
| 1423 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1424 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1425 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1426 | |
| 1427 | static int thermal_init(void) |
| 1428 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1429 | u8 t, ta1, ta2; |
| 1430 | int i; |
| 1431 | int acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1432 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1433 | if (ibm_thinkpad_ec_found && experimental) { |
| 1434 | /* |
| 1435 | * Direct EC access mode: sensors at registers |
| 1436 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 1437 | * non-implemented, thermal sensors return 0x80 when |
| 1438 | * not available |
| 1439 | */ |
| 1440 | |
| 1441 | ta1 = ta2 = 0; |
| 1442 | for (i = 0; i < 8; i++) { |
| 1443 | if (likely(acpi_ec_read(0x78 + i, &t))) { |
| 1444 | ta1 |= t; |
| 1445 | } else { |
| 1446 | ta1 = 0; |
| 1447 | break; |
| 1448 | } |
| 1449 | if (likely(acpi_ec_read(0xC0 + i, &t))) { |
| 1450 | ta2 |= t; |
| 1451 | } else { |
| 1452 | ta1 = 0; |
| 1453 | break; |
| 1454 | } |
| 1455 | } |
| 1456 | if (ta1 == 0) { |
| 1457 | /* This is sheer paranoia, but we handle it anyway */ |
| 1458 | if (acpi_tmp7) { |
| 1459 | printk(IBM_ERR |
| 1460 | "ThinkPad ACPI EC access misbehaving, " |
| 1461 | "falling back to ACPI TMPx access mode\n"); |
| 1462 | thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07; |
| 1463 | } else { |
| 1464 | printk(IBM_ERR |
| 1465 | "ThinkPad ACPI EC access misbehaving, " |
| 1466 | "disabling thermal sensors access\n"); |
| 1467 | thermal_read_mode = IBMACPI_THERMAL_NONE; |
| 1468 | } |
| 1469 | } else { |
| 1470 | thermal_read_mode = |
| 1471 | (ta2 != 0) ? |
| 1472 | IBMACPI_THERMAL_TPEC_16 : IBMACPI_THERMAL_TPEC_8; |
| 1473 | } |
| 1474 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1475 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 1476 | /* 600e/x, 770e, 770x */ |
| 1477 | thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT; |
| 1478 | } else { |
| 1479 | /* Standard ACPI TMPx access, max 8 sensors */ |
| 1480 | thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07; |
| 1481 | } |
| 1482 | } else { |
| 1483 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
| 1484 | thermal_read_mode = IBMACPI_THERMAL_NONE; |
| 1485 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1486 | |
| 1487 | return 0; |
| 1488 | } |
| 1489 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1490 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 1491 | { |
| 1492 | int i, t; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1493 | s8 tmp; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1494 | char tmpi[] = "TMPi"; |
| 1495 | |
| 1496 | if (!s) |
| 1497 | return -EINVAL; |
| 1498 | |
| 1499 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1500 | #if IBMACPI_MAX_THERMAL_SENSORS >= 16 |
| 1501 | case IBMACPI_THERMAL_TPEC_16: |
| 1502 | for (i = 0; i < 8; i++) { |
| 1503 | if (!acpi_ec_read(0xC0 + i, &tmp)) |
| 1504 | return -EIO; |
| 1505 | s->temp[i + 8] = tmp * 1000; |
| 1506 | } |
| 1507 | /* fallthrough */ |
| 1508 | #endif |
| 1509 | case IBMACPI_THERMAL_TPEC_8: |
| 1510 | for (i = 0; i < 8; i++) { |
| 1511 | if (!acpi_ec_read(0x78 + i, &tmp)) |
| 1512 | return -EIO; |
| 1513 | s->temp[i] = tmp * 1000; |
| 1514 | } |
| 1515 | return (thermal_read_mode == IBMACPI_THERMAL_TPEC_16) ? 16 : 8; |
| 1516 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1517 | case IBMACPI_THERMAL_ACPI_UPDT: |
| 1518 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 1519 | return -EIO; |
| 1520 | for (i = 0; i < 8; i++) { |
| 1521 | tmpi[3] = '0' + i; |
| 1522 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 1523 | return -EIO; |
| 1524 | s->temp[i] = (t - 2732) * 100; |
| 1525 | } |
| 1526 | return 8; |
| 1527 | |
| 1528 | case IBMACPI_THERMAL_ACPI_TMP07: |
| 1529 | for (i = 0; i < 8; i++) { |
| 1530 | tmpi[3] = '0' + i; |
| 1531 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 1532 | return -EIO; |
| 1533 | s->temp[i] = t * 1000; |
| 1534 | } |
| 1535 | return 8; |
| 1536 | |
| 1537 | case IBMACPI_THERMAL_NONE: |
| 1538 | default: |
| 1539 | return 0; |
| 1540 | } |
| 1541 | } |
| 1542 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1543 | static int thermal_read(char *p) |
| 1544 | { |
| 1545 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1546 | int n, i; |
| 1547 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1548 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1549 | n = thermal_get_sensors(&t); |
| 1550 | if (unlikely(n < 0)) |
| 1551 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1552 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1553 | len += sprintf(p + len, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1554 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1555 | if (n > 0) { |
| 1556 | for (i = 0; i < (n - 1); i++) |
| 1557 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 1558 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 1559 | } else |
| 1560 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1561 | |
| 1562 | return len; |
| 1563 | } |
| 1564 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1565 | /************************************************************************* |
| 1566 | * EC Dump subdriver |
| 1567 | */ |
| 1568 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1569 | static u8 ecdump_regs[256]; |
| 1570 | |
| 1571 | static int ecdump_read(char *p) |
| 1572 | { |
| 1573 | int len = 0; |
| 1574 | int i, j; |
| 1575 | u8 v; |
| 1576 | |
| 1577 | len += sprintf(p + len, "EC " |
| 1578 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 1579 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 1580 | for (i = 0; i < 256; i += 16) { |
| 1581 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 1582 | for (j = 0; j < 16; j++) { |
| 1583 | if (!acpi_ec_read(i + j, &v)) |
| 1584 | break; |
| 1585 | if (v != ecdump_regs[i + j]) |
| 1586 | len += sprintf(p + len, " *%02x", v); |
| 1587 | else |
| 1588 | len += sprintf(p + len, " %02x", v); |
| 1589 | ecdump_regs[i + j] = v; |
| 1590 | } |
| 1591 | len += sprintf(p + len, "\n"); |
| 1592 | if (j != 16) |
| 1593 | break; |
| 1594 | } |
| 1595 | |
| 1596 | /* These are way too dangerous to advertise openly... */ |
| 1597 | #if 0 |
| 1598 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 1599 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 1600 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 1601 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 1602 | #endif |
| 1603 | return len; |
| 1604 | } |
| 1605 | |
| 1606 | static int ecdump_write(char *buf) |
| 1607 | { |
| 1608 | char *cmd; |
| 1609 | int i, v; |
| 1610 | |
| 1611 | while ((cmd = next_cmd(&buf))) { |
| 1612 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 1613 | /* i and v set */ |
| 1614 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 1615 | /* i and v set */ |
| 1616 | } else |
| 1617 | return -EINVAL; |
| 1618 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 1619 | if (!acpi_ec_write(i, v)) |
| 1620 | return -EIO; |
| 1621 | } else |
| 1622 | return -EINVAL; |
| 1623 | } |
| 1624 | |
| 1625 | return 0; |
| 1626 | } |
| 1627 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1628 | /************************************************************************* |
| 1629 | * Backlight/brightness subdriver |
| 1630 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1631 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1632 | static struct backlight_device *ibm_backlight_device = NULL; |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1633 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 1634 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 1635 | .get_brightness = brightness_get, |
| 1636 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 1637 | }; |
| 1638 | |
| 1639 | static int brightness_init(void) |
| 1640 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 1641 | int b; |
| 1642 | |
| 1643 | b = brightness_get(NULL); |
| 1644 | if (b < 0) |
| 1645 | return b; |
| 1646 | |
Yu Luming | 519ab5f | 2006-12-19 12:56:15 -0800 | [diff] [blame] | 1647 | ibm_backlight_device = backlight_device_register("ibm", NULL, NULL, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 1648 | &ibm_backlight_data); |
| 1649 | if (IS_ERR(ibm_backlight_device)) { |
| 1650 | printk(IBM_ERR "Could not register backlight device\n"); |
| 1651 | return PTR_ERR(ibm_backlight_device); |
| 1652 | } |
| 1653 | |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 1654 | ibm_backlight_device->props.max_brightness = 7; |
| 1655 | ibm_backlight_device->props.brightness = b; |
| 1656 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 1657 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 1658 | return 0; |
| 1659 | } |
| 1660 | |
| 1661 | static void brightness_exit(void) |
| 1662 | { |
| 1663 | if (ibm_backlight_device) { |
| 1664 | backlight_device_unregister(ibm_backlight_device); |
| 1665 | ibm_backlight_device = NULL; |
| 1666 | } |
| 1667 | } |
| 1668 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1669 | static int brightness_update_status(struct backlight_device *bd) |
| 1670 | { |
| 1671 | return brightness_set( |
| 1672 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 1673 | bd->props.power == FB_BLANK_UNBLANK) ? |
| 1674 | bd->props.brightness : 0); |
| 1675 | } |
| 1676 | |
| 1677 | static int brightness_get(struct backlight_device *bd) |
| 1678 | { |
| 1679 | u8 level; |
| 1680 | if (!acpi_ec_read(brightness_offset, &level)) |
| 1681 | return -EIO; |
| 1682 | |
| 1683 | level &= 0x7; |
| 1684 | |
| 1685 | return level; |
| 1686 | } |
| 1687 | |
| 1688 | static int brightness_set(int value) |
| 1689 | { |
| 1690 | int cmos_cmd, inc, i; |
| 1691 | int current_value = brightness_get(NULL); |
| 1692 | |
| 1693 | value &= 7; |
| 1694 | |
| 1695 | cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN; |
| 1696 | inc = value > current_value ? 1 : -1; |
| 1697 | for (i = current_value; i != value; i += inc) { |
| 1698 | if (!cmos_eval(cmos_cmd)) |
| 1699 | return -EIO; |
| 1700 | if (!acpi_ec_write(brightness_offset, i + inc)) |
| 1701 | return -EIO; |
| 1702 | } |
| 1703 | |
| 1704 | return 0; |
| 1705 | } |
| 1706 | |
| 1707 | static int brightness_read(char *p) |
| 1708 | { |
| 1709 | int len = 0; |
| 1710 | int level; |
| 1711 | |
| 1712 | if ((level = brightness_get(NULL)) < 0) { |
| 1713 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 1714 | } else { |
| 1715 | len += sprintf(p + len, "level:\t\t%d\n", level & 0x7); |
| 1716 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 1717 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 1718 | " (<level> is 0-7)\n"); |
| 1719 | } |
| 1720 | |
| 1721 | return len; |
| 1722 | } |
| 1723 | |
| 1724 | static int brightness_write(char *buf) |
| 1725 | { |
| 1726 | int level; |
| 1727 | int new_level; |
| 1728 | char *cmd; |
| 1729 | |
| 1730 | while ((cmd = next_cmd(&buf))) { |
| 1731 | if ((level = brightness_get(NULL)) < 0) |
| 1732 | return level; |
| 1733 | level &= 7; |
| 1734 | |
| 1735 | if (strlencmp(cmd, "up") == 0) { |
| 1736 | new_level = level == 7 ? 7 : level + 1; |
| 1737 | } else if (strlencmp(cmd, "down") == 0) { |
| 1738 | new_level = level == 0 ? 0 : level - 1; |
| 1739 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 1740 | new_level >= 0 && new_level <= 7) { |
| 1741 | /* new_level set */ |
| 1742 | } else |
| 1743 | return -EINVAL; |
| 1744 | |
| 1745 | brightness_set(new_level); |
| 1746 | } |
| 1747 | |
| 1748 | return 0; |
| 1749 | } |
| 1750 | |
| 1751 | /************************************************************************* |
| 1752 | * Volume subdriver |
| 1753 | */ |
| 1754 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1755 | static int volume_read(char *p) |
| 1756 | { |
| 1757 | int len = 0; |
| 1758 | u8 level; |
| 1759 | |
| 1760 | if (!acpi_ec_read(volume_offset, &level)) { |
| 1761 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 1762 | } else { |
| 1763 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); |
| 1764 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); |
| 1765 | len += sprintf(p + len, "commands:\tup, down, mute\n"); |
| 1766 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 1767 | " (<level> is 0-15)\n"); |
| 1768 | } |
| 1769 | |
| 1770 | return len; |
| 1771 | } |
| 1772 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1773 | static int volume_write(char *buf) |
| 1774 | { |
| 1775 | int cmos_cmd, inc, i; |
| 1776 | u8 level, mute; |
| 1777 | int new_level, new_mute; |
| 1778 | char *cmd; |
| 1779 | |
| 1780 | while ((cmd = next_cmd(&buf))) { |
| 1781 | if (!acpi_ec_read(volume_offset, &level)) |
| 1782 | return -EIO; |
| 1783 | new_mute = mute = level & 0x40; |
| 1784 | new_level = level = level & 0xf; |
| 1785 | |
| 1786 | if (strlencmp(cmd, "up") == 0) { |
| 1787 | if (mute) |
| 1788 | new_mute = 0; |
| 1789 | else |
| 1790 | new_level = level == 15 ? 15 : level + 1; |
| 1791 | } else if (strlencmp(cmd, "down") == 0) { |
| 1792 | if (mute) |
| 1793 | new_mute = 0; |
| 1794 | else |
| 1795 | new_level = level == 0 ? 0 : level - 1; |
| 1796 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 1797 | new_level >= 0 && new_level <= 15) { |
| 1798 | /* new_level set */ |
| 1799 | } else if (strlencmp(cmd, "mute") == 0) { |
| 1800 | new_mute = 0x40; |
| 1801 | } else |
| 1802 | return -EINVAL; |
| 1803 | |
| 1804 | if (new_level != level) { /* mute doesn't change */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1805 | cmos_cmd = new_level > level ? TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1806 | inc = new_level > level ? 1 : -1; |
| 1807 | |
| 1808 | if (mute && (!cmos_eval(cmos_cmd) || |
| 1809 | !acpi_ec_write(volume_offset, level))) |
| 1810 | return -EIO; |
| 1811 | |
| 1812 | for (i = level; i != new_level; i += inc) |
| 1813 | if (!cmos_eval(cmos_cmd) || |
| 1814 | !acpi_ec_write(volume_offset, i + inc)) |
| 1815 | return -EIO; |
| 1816 | |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1817 | if (mute && (!cmos_eval(TP_CMOS_VOLUME_MUTE) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1818 | !acpi_ec_write(volume_offset, |
| 1819 | new_level + mute))) |
| 1820 | return -EIO; |
| 1821 | } |
| 1822 | |
| 1823 | if (new_mute != mute) { /* level doesn't change */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1824 | cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1825 | |
| 1826 | if (!cmos_eval(cmos_cmd) || |
| 1827 | !acpi_ec_write(volume_offset, level + new_mute)) |
| 1828 | return -EIO; |
| 1829 | } |
| 1830 | } |
| 1831 | |
| 1832 | return 0; |
| 1833 | } |
| 1834 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1835 | |
| 1836 | /************************************************************************* |
| 1837 | * Fan subdriver |
| 1838 | */ |
| 1839 | |
| 1840 | /* |
| 1841 | * FAN ACCESS MODES |
| 1842 | * |
| 1843 | * IBMACPI_FAN_RD_ACPI_GFAN: |
| 1844 | * ACPI GFAN method: returns fan level |
| 1845 | * |
| 1846 | * see IBMACPI_FAN_WR_ACPI_SFAN |
| 1847 | * EC 0x2f not available if GFAN exists |
| 1848 | * |
| 1849 | * IBMACPI_FAN_WR_ACPI_SFAN: |
| 1850 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 1851 | * |
| 1852 | * EC 0x2f might be available *for reading*, but never for writing. |
| 1853 | * |
| 1854 | * IBMACPI_FAN_WR_TPEC: |
| 1855 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported |
| 1856 | * on almost all ThinkPads |
| 1857 | * |
| 1858 | * Fan speed changes of any sort (including those caused by the |
| 1859 | * disengaged mode) are usually done slowly by the firmware as the |
| 1860 | * maximum ammount of fan duty cycle change per second seems to be |
| 1861 | * limited. |
| 1862 | * |
| 1863 | * Reading is not available if GFAN exists. |
| 1864 | * Writing is not available if SFAN exists. |
| 1865 | * |
| 1866 | * Bits |
| 1867 | * 7 automatic mode engaged; |
| 1868 | * (default operation mode of the ThinkPad) |
| 1869 | * fan level is ignored in this mode. |
| 1870 | * 6 disengage mode (takes precedence over bit 7); |
| 1871 | * not available on all thinkpads. May disable |
| 1872 | * the tachometer, and speeds up fan to 100% duty-cycle, |
| 1873 | * which speeds it up far above the standard RPM |
| 1874 | * levels. It is not impossible that it could cause |
| 1875 | * hardware damage. |
| 1876 | * 5-3 unused in some models. Extra bits for fan level |
| 1877 | * in others, but still useless as all values above |
| 1878 | * 7 map to the same speed as level 7 in these models. |
| 1879 | * 2-0 fan level (0..7 usually) |
| 1880 | * 0x00 = stop |
| 1881 | * 0x07 = max (set when temperatures critical) |
| 1882 | * Some ThinkPads may have other levels, see |
| 1883 | * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
| 1884 | * |
| 1885 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 1886 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 1887 | * does so, its initial value is meaningless (0x07). |
| 1888 | * |
| 1889 | * For firmware bugs, refer to: |
| 1890 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 1891 | * |
| 1892 | * ---- |
| 1893 | * |
| 1894 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 1895 | * Main fan tachometer reading (in RPM) |
| 1896 | * |
| 1897 | * This register is present on all ThinkPads with a new-style EC, and |
| 1898 | * it is known not to be present on the A21m/e, and T22, as there is |
| 1899 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 1900 | * ThinkPads from this same time period (and earlier) probably lack the |
| 1901 | * tachometer as well. |
| 1902 | * |
| 1903 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare |
| 1904 | * was never fixed by IBM to report the EC firmware version string |
| 1905 | * probably support the tachometer (like the early X models), so |
| 1906 | * detecting it is quite hard. We need more data to know for sure. |
| 1907 | * |
| 1908 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 1909 | * might result. |
| 1910 | * |
| 1911 | * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this |
| 1912 | * register is not invalidated in ThinkPads that disable tachometer |
| 1913 | * readings. Thus, the tachometer readings go stale. |
| 1914 | * |
| 1915 | * For firmware bugs, refer to: |
| 1916 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 1917 | * |
| 1918 | * IBMACPI_FAN_WR_ACPI_FANS: |
| 1919 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 1920 | * |
| 1921 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 1922 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 1923 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 1924 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 1925 | * |
| 1926 | * The speeds are stored on handles |
| 1927 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 1928 | * |
| 1929 | * There are three default speed sets, acessible as handles: |
| 1930 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 1931 | * |
| 1932 | * ACPI DSDT switches which set is in use depending on various |
| 1933 | * factors. |
| 1934 | * |
| 1935 | * IBMACPI_FAN_WR_TPEC is also available and should be used to |
| 1936 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 1937 | * but the ACPI tables just mention level 7. |
| 1938 | */ |
| 1939 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1940 | static enum fan_status_access_mode fan_status_access_mode; |
| 1941 | static enum fan_control_access_mode fan_control_access_mode; |
| 1942 | static enum fan_control_commands fan_control_commands; |
| 1943 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1944 | static int fan_control_status_known; |
| 1945 | static u8 fan_control_initial_status; |
| 1946 | |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 1947 | static void fan_watchdog_fire(struct work_struct *ignored); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1948 | static int fan_watchdog_maxinterval; |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 1949 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1950 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 1951 | IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 1952 | IBM_HANDLE(gfan, ec, "GFAN", /* 570 */ |
| 1953 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 1954 | ); /* all others */ |
| 1955 | IBM_HANDLE(sfan, ec, "SFAN", /* 570 */ |
| 1956 | "JFNS", /* 770x-JL */ |
| 1957 | ); /* all others */ |
| 1958 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1959 | static int fan_init(void) |
| 1960 | { |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1961 | fan_status_access_mode = IBMACPI_FAN_NONE; |
| 1962 | fan_control_access_mode = IBMACPI_FAN_WR_NONE; |
| 1963 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1964 | fan_control_status_known = 1; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1965 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1966 | |
| 1967 | if (gfan_handle) { |
| 1968 | /* 570, 600e/x, 770e, 770x */ |
| 1969 | fan_status_access_mode = IBMACPI_FAN_RD_ACPI_GFAN; |
| 1970 | } else { |
| 1971 | /* all other ThinkPads: note that even old-style |
| 1972 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1973 | if (likely(acpi_ec_read(fan_status_offset, |
| 1974 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1975 | fan_status_access_mode = IBMACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1976 | |
| 1977 | /* In some ThinkPads, neither the EC nor the ACPI |
| 1978 | * DSDT initialize the fan status, and it ends up |
| 1979 | * being set to 0x07 when it *could* be either |
| 1980 | * 0x07 or 0x80. |
| 1981 | * |
| 1982 | * Enable for TP-1Y (T43), TP-78 (R51e), |
| 1983 | * TP-76 (R52), TP-70 (T43, R52), which are known |
| 1984 | * to be buggy. */ |
| 1985 | if (fan_control_initial_status == 0x07 && |
| 1986 | ibm_thinkpad_ec_found && |
| 1987 | ((ibm_thinkpad_ec_found[0] == '1' && |
| 1988 | ibm_thinkpad_ec_found[1] == 'Y') || |
| 1989 | (ibm_thinkpad_ec_found[0] == '7' && |
| 1990 | (ibm_thinkpad_ec_found[1] == '6' || |
| 1991 | ibm_thinkpad_ec_found[1] == '8' || |
| 1992 | ibm_thinkpad_ec_found[1] == '0')) |
| 1993 | )) { |
| 1994 | printk(IBM_NOTICE |
| 1995 | "fan_init: initial fan status is " |
| 1996 | "unknown, assuming it is in auto " |
| 1997 | "mode\n"); |
| 1998 | fan_control_status_known = 0; |
| 1999 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2000 | } else { |
| 2001 | printk(IBM_ERR |
| 2002 | "ThinkPad ACPI EC access misbehaving, " |
| 2003 | "fan status and control unavailable\n"); |
| 2004 | return 0; |
| 2005 | } |
| 2006 | } |
| 2007 | |
| 2008 | if (sfan_handle) { |
| 2009 | /* 570, 770x-JL */ |
| 2010 | fan_control_access_mode = IBMACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 2011 | fan_control_commands |= |
| 2012 | IBMACPI_FAN_CMD_LEVEL | IBMACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2013 | } else { |
| 2014 | if (!gfan_handle) { |
| 2015 | /* gfan without sfan means no fan control */ |
| 2016 | /* all other models implement TP EC 0x2f control */ |
| 2017 | |
| 2018 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2019 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2020 | fan_control_access_mode = |
| 2021 | IBMACPI_FAN_WR_ACPI_FANS; |
| 2022 | fan_control_commands |= |
| 2023 | IBMACPI_FAN_CMD_SPEED | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2024 | IBMACPI_FAN_CMD_LEVEL | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2025 | IBMACPI_FAN_CMD_ENABLE; |
| 2026 | } else { |
| 2027 | fan_control_access_mode = IBMACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2028 | fan_control_commands |= |
| 2029 | IBMACPI_FAN_CMD_LEVEL | |
| 2030 | IBMACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2031 | } |
| 2032 | } |
| 2033 | } |
| 2034 | |
| 2035 | return 0; |
| 2036 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2037 | |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 2038 | static int fan_get_status(u8 *status) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2039 | { |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 2040 | u8 s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2041 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2042 | /* TODO: |
| 2043 | * Add IBMACPI_FAN_RD_ACPI_FANS ? */ |
| 2044 | |
Henrique de Moraes Holschuh | 3ef8a60 | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 2045 | switch (fan_status_access_mode) { |
| 2046 | case IBMACPI_FAN_RD_ACPI_GFAN: |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2047 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 2048 | |
| 2049 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2050 | return -EIO; |
| 2051 | |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 2052 | if (likely(status)) |
| 2053 | *status = s & 0x07; |
| 2054 | |
| 2055 | break; |
| 2056 | |
| 2057 | case IBMACPI_FAN_RD_TPEC: |
| 2058 | /* all except 570, 600e/x, 770e, 770x */ |
| 2059 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 2060 | return -EIO; |
| 2061 | |
| 2062 | if (likely(status)) |
| 2063 | *status = s; |
| 2064 | |
| 2065 | break; |
| 2066 | |
| 2067 | default: |
| 2068 | return -ENXIO; |
| 2069 | } |
| 2070 | |
| 2071 | return 0; |
| 2072 | } |
| 2073 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 2074 | static void fan_exit(void) |
| 2075 | { |
| 2076 | cancel_delayed_work(&fan_watchdog_task); |
| 2077 | flush_scheduled_work(); |
| 2078 | } |
| 2079 | |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 2080 | static int fan_get_speed(unsigned int *speed) |
| 2081 | { |
| 2082 | u8 hi, lo; |
| 2083 | |
| 2084 | switch (fan_status_access_mode) { |
| 2085 | case IBMACPI_FAN_RD_TPEC: |
| 2086 | /* all except 570, 600e/x, 770e, 770x */ |
| 2087 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 2088 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 2089 | return -EIO; |
| 2090 | |
| 2091 | if (likely(speed)) |
| 2092 | *speed = (hi << 8) | lo; |
| 2093 | |
| 2094 | break; |
| 2095 | |
| 2096 | default: |
| 2097 | return -ENXIO; |
| 2098 | } |
| 2099 | |
| 2100 | return 0; |
| 2101 | } |
| 2102 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 2103 | static void fan_watchdog_fire(struct work_struct *ignored) |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2104 | { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 2105 | printk(IBM_NOTICE "fan watchdog: enabling fan\n"); |
| 2106 | if (fan_set_enable()) { |
| 2107 | printk(IBM_ERR "fan watchdog: error while enabling fan\n"); |
| 2108 | /* reschedule for later */ |
| 2109 | fan_watchdog_reset(); |
| 2110 | } |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2111 | } |
| 2112 | |
| 2113 | static void fan_watchdog_reset(void) |
| 2114 | { |
| 2115 | static int fan_watchdog_active = 0; |
| 2116 | |
| 2117 | if (fan_watchdog_active) |
| 2118 | cancel_delayed_work(&fan_watchdog_task); |
| 2119 | |
| 2120 | if (fan_watchdog_maxinterval > 0) { |
| 2121 | fan_watchdog_active = 1; |
| 2122 | if (!schedule_delayed_work(&fan_watchdog_task, |
| 2123 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 2124 | * 1000))) { |
| 2125 | printk(IBM_ERR "failed to schedule the fan watchdog, " |
| 2126 | "watchdog will not trigger\n"); |
| 2127 | } |
| 2128 | } else |
| 2129 | fan_watchdog_active = 0; |
| 2130 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2131 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2132 | static int fan_set_level(int level) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2133 | { |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2134 | switch (fan_control_access_mode) { |
| 2135 | case IBMACPI_FAN_WR_ACPI_SFAN: |
| 2136 | if (level >= 0 && level <= 7) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2137 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 2138 | return -EIO; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2139 | } else |
| 2140 | return -EINVAL; |
| 2141 | break; |
| 2142 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2143 | case IBMACPI_FAN_WR_ACPI_FANS: |
| 2144 | case IBMACPI_FAN_WR_TPEC: |
| 2145 | if ((level != IBMACPI_FAN_EC_AUTO) && |
| 2146 | (level != IBMACPI_FAN_EC_DISENGAGED) && |
| 2147 | ((level < 0) || (level > 7))) |
| 2148 | return -EINVAL; |
| 2149 | |
| 2150 | if (!acpi_ec_write(fan_status_offset, level)) |
| 2151 | return -EIO; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2152 | else |
| 2153 | fan_control_status_known = 1; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2154 | break; |
| 2155 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2156 | default: |
| 2157 | return -ENXIO; |
| 2158 | } |
| 2159 | return 0; |
| 2160 | } |
| 2161 | |
| 2162 | static int fan_set_enable(void) |
| 2163 | { |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 2164 | u8 s; |
| 2165 | int rc; |
| 2166 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2167 | switch (fan_control_access_mode) { |
| 2168 | case IBMACPI_FAN_WR_ACPI_FANS: |
| 2169 | case IBMACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 2170 | if ((rc = fan_get_status(&s)) < 0) |
| 2171 | return rc; |
| 2172 | |
| 2173 | /* Don't go out of emergency fan mode */ |
| 2174 | if (s != 7) |
| 2175 | s = IBMACPI_FAN_EC_AUTO; |
| 2176 | |
| 2177 | if (!acpi_ec_write(fan_status_offset, s)) |
| 2178 | return -EIO; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2179 | else |
| 2180 | fan_control_status_known = 1; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 2181 | break; |
| 2182 | |
| 2183 | case IBMACPI_FAN_WR_ACPI_SFAN: |
| 2184 | if ((rc = fan_get_status(&s)) < 0) |
| 2185 | return rc; |
| 2186 | |
| 2187 | s &= 0x07; |
| 2188 | |
| 2189 | /* Set fan to at least level 4 */ |
| 2190 | if (s < 4) |
| 2191 | s = 4; |
| 2192 | |
| 2193 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2194 | return -EIO; |
| 2195 | break; |
| 2196 | |
| 2197 | default: |
| 2198 | return -ENXIO; |
| 2199 | } |
| 2200 | return 0; |
| 2201 | } |
| 2202 | |
| 2203 | static int fan_set_disable(void) |
| 2204 | { |
| 2205 | switch (fan_control_access_mode) { |
| 2206 | case IBMACPI_FAN_WR_ACPI_FANS: |
| 2207 | case IBMACPI_FAN_WR_TPEC: |
| 2208 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 2209 | return -EIO; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2210 | else |
| 2211 | fan_control_status_known = 1; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2212 | break; |
| 2213 | |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 2214 | case IBMACPI_FAN_WR_ACPI_SFAN: |
| 2215 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 2216 | return -EIO; |
| 2217 | break; |
| 2218 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2219 | default: |
| 2220 | return -ENXIO; |
| 2221 | } |
| 2222 | return 0; |
| 2223 | } |
| 2224 | |
| 2225 | static int fan_set_speed(int speed) |
| 2226 | { |
| 2227 | switch (fan_control_access_mode) { |
| 2228 | case IBMACPI_FAN_WR_ACPI_FANS: |
| 2229 | if (speed >= 0 && speed <= 65535) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2230 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 2231 | speed, speed, speed)) |
| 2232 | return -EIO; |
| 2233 | } else |
| 2234 | return -EINVAL; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2235 | break; |
| 2236 | |
| 2237 | default: |
| 2238 | return -ENXIO; |
| 2239 | } |
| 2240 | return 0; |
| 2241 | } |
| 2242 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 2243 | static int fan_read(char *p) |
| 2244 | { |
| 2245 | int len = 0; |
| 2246 | int rc; |
| 2247 | u8 status; |
| 2248 | unsigned int speed = 0; |
| 2249 | |
| 2250 | switch (fan_status_access_mode) { |
| 2251 | case IBMACPI_FAN_RD_ACPI_GFAN: |
| 2252 | /* 570, 600e/x, 770e, 770x */ |
| 2253 | if ((rc = fan_get_status(&status)) < 0) |
| 2254 | return rc; |
| 2255 | |
| 2256 | len += sprintf(p + len, "status:\t\t%s\n" |
| 2257 | "level:\t\t%d\n", |
| 2258 | (status != 0) ? "enabled" : "disabled", status); |
| 2259 | break; |
| 2260 | |
| 2261 | case IBMACPI_FAN_RD_TPEC: |
| 2262 | /* all except 570, 600e/x, 770e, 770x */ |
| 2263 | if ((rc = fan_get_status(&status)) < 0) |
| 2264 | return rc; |
| 2265 | |
| 2266 | if (unlikely(!fan_control_status_known)) { |
| 2267 | if (status != fan_control_initial_status) |
| 2268 | fan_control_status_known = 1; |
| 2269 | else |
| 2270 | /* Return most likely status. In fact, it |
| 2271 | * might be the only possible status */ |
| 2272 | status = IBMACPI_FAN_EC_AUTO; |
| 2273 | } |
| 2274 | |
| 2275 | len += sprintf(p + len, "status:\t\t%s\n", |
| 2276 | (status != 0) ? "enabled" : "disabled"); |
| 2277 | |
| 2278 | /* No ThinkPad boots on disengaged mode, we can safely |
| 2279 | * assume the tachometer is online if fan control status |
| 2280 | * was unknown */ |
| 2281 | if ((rc = fan_get_speed(&speed)) < 0) |
| 2282 | return rc; |
| 2283 | |
| 2284 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
| 2285 | |
| 2286 | if (status & IBMACPI_FAN_EC_DISENGAGED) |
| 2287 | /* Disengaged mode takes precedence */ |
| 2288 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
| 2289 | else if (status & IBMACPI_FAN_EC_AUTO) |
| 2290 | len += sprintf(p + len, "level:\t\tauto\n"); |
| 2291 | else |
| 2292 | len += sprintf(p + len, "level:\t\t%d\n", status); |
| 2293 | break; |
| 2294 | |
| 2295 | case IBMACPI_FAN_NONE: |
| 2296 | default: |
| 2297 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 2298 | } |
| 2299 | |
| 2300 | if (fan_control_commands & IBMACPI_FAN_CMD_LEVEL) { |
| 2301 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 2302 | |
| 2303 | switch (fan_control_access_mode) { |
| 2304 | case IBMACPI_FAN_WR_ACPI_SFAN: |
| 2305 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 2306 | break; |
| 2307 | |
| 2308 | default: |
| 2309 | len += sprintf(p + len, " (<level> is 0-7, " |
| 2310 | "auto, disengaged)\n"); |
| 2311 | break; |
| 2312 | } |
| 2313 | } |
| 2314 | |
| 2315 | if (fan_control_commands & IBMACPI_FAN_CMD_ENABLE) |
| 2316 | len += sprintf(p + len, "commands:\tenable, disable\n" |
| 2317 | "commands:\twatchdog <timeout> (<timeout> is 0 (off), " |
| 2318 | "1-120 (seconds))\n"); |
| 2319 | |
| 2320 | if (fan_control_commands & IBMACPI_FAN_CMD_SPEED) |
| 2321 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 2322 | " (<speed> is 0-65535)\n"); |
| 2323 | |
| 2324 | return len; |
| 2325 | } |
| 2326 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2327 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 2328 | { |
| 2329 | int level; |
| 2330 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2331 | if (strlencmp(cmd, "level auto") == 0) |
| 2332 | level = IBMACPI_FAN_EC_AUTO; |
| 2333 | else if (strlencmp(cmd, "level disengaged") == 0) |
| 2334 | level = IBMACPI_FAN_EC_DISENGAGED; |
| 2335 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2336 | return 0; |
| 2337 | |
| 2338 | if ((*rc = fan_set_level(level)) == -ENXIO) |
| 2339 | printk(IBM_ERR "level command accepted for unsupported " |
| 2340 | "access mode %d", fan_control_access_mode); |
| 2341 | |
| 2342 | return 1; |
| 2343 | } |
| 2344 | |
| 2345 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 2346 | { |
| 2347 | if (strlencmp(cmd, "enable") != 0) |
| 2348 | return 0; |
| 2349 | |
| 2350 | if ((*rc = fan_set_enable()) == -ENXIO) |
| 2351 | printk(IBM_ERR "enable command accepted for unsupported " |
| 2352 | "access mode %d", fan_control_access_mode); |
| 2353 | |
| 2354 | return 1; |
| 2355 | } |
| 2356 | |
| 2357 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 2358 | { |
| 2359 | if (strlencmp(cmd, "disable") != 0) |
| 2360 | return 0; |
| 2361 | |
| 2362 | if ((*rc = fan_set_disable()) == -ENXIO) |
| 2363 | printk(IBM_ERR "disable command accepted for unsupported " |
| 2364 | "access mode %d", fan_control_access_mode); |
| 2365 | |
| 2366 | return 1; |
| 2367 | } |
| 2368 | |
| 2369 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 2370 | { |
| 2371 | int speed; |
| 2372 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2373 | /* TODO: |
| 2374 | * Support speed <low> <medium> <high> ? */ |
| 2375 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2376 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 2377 | return 0; |
| 2378 | |
| 2379 | if ((*rc = fan_set_speed(speed)) == -ENXIO) |
| 2380 | printk(IBM_ERR "speed command accepted for unsupported " |
| 2381 | "access mode %d", fan_control_access_mode); |
| 2382 | |
| 2383 | return 1; |
| 2384 | } |
| 2385 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2386 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 2387 | { |
| 2388 | int interval; |
| 2389 | |
| 2390 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 2391 | return 0; |
| 2392 | |
| 2393 | if (interval < 0 || interval > 120) |
| 2394 | *rc = -EINVAL; |
| 2395 | else |
| 2396 | fan_watchdog_maxinterval = interval; |
| 2397 | |
| 2398 | return 1; |
| 2399 | } |
| 2400 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2401 | static int fan_write(char *buf) |
| 2402 | { |
| 2403 | char *cmd; |
| 2404 | int rc = 0; |
| 2405 | |
| 2406 | while (!rc && (cmd = next_cmd(&buf))) { |
| 2407 | if (!((fan_control_commands & IBMACPI_FAN_CMD_LEVEL) && |
| 2408 | fan_write_cmd_level(cmd, &rc)) && |
| 2409 | !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) && |
| 2410 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2411 | fan_write_cmd_disable(cmd, &rc) || |
| 2412 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2413 | !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) && |
| 2414 | fan_write_cmd_speed(cmd, &rc)) |
| 2415 | ) |
| 2416 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2417 | else if (!rc) |
| 2418 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2419 | } |
| 2420 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2421 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2422 | } |
| 2423 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 2424 | /**************************************************************************** |
| 2425 | **************************************************************************** |
| 2426 | * |
| 2427 | * Infrastructure |
| 2428 | * |
| 2429 | **************************************************************************** |
| 2430 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2431 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 2432 | /* /proc support */ |
| 2433 | static struct proc_dir_entry *proc_dir = NULL; |
| 2434 | |
| 2435 | /* Subdriver registry */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2436 | static struct ibm_struct ibms[] = { |
| 2437 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2438 | .name = "driver", |
Adrian Bunk | 1f21782 | 2006-12-19 13:01:28 -0800 | [diff] [blame] | 2439 | .init = ibm_acpi_driver_init, |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 2440 | .read = ibm_acpi_driver_read, |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2441 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2442 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2443 | .name = "hotkey", |
| 2444 | .hid = IBM_HKEY_HID, |
| 2445 | .init = hotkey_init, |
| 2446 | .read = hotkey_read, |
| 2447 | .write = hotkey_write, |
| 2448 | .exit = hotkey_exit, |
| 2449 | .notify = hotkey_notify, |
| 2450 | .handle = &hkey_handle, |
| 2451 | .type = ACPI_DEVICE_NOTIFY, |
| 2452 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2453 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2454 | .name = "bluetooth", |
| 2455 | .init = bluetooth_init, |
| 2456 | .read = bluetooth_read, |
| 2457 | .write = bluetooth_write, |
| 2458 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2459 | { |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2460 | .name = "wan", |
| 2461 | .init = wan_init, |
| 2462 | .read = wan_read, |
| 2463 | .write = wan_write, |
| 2464 | .experimental = 1, |
| 2465 | }, |
| 2466 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2467 | .name = "video", |
| 2468 | .init = video_init, |
| 2469 | .read = video_read, |
| 2470 | .write = video_write, |
| 2471 | .exit = video_exit, |
| 2472 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2473 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2474 | .name = "light", |
| 2475 | .init = light_init, |
| 2476 | .read = light_read, |
| 2477 | .write = light_write, |
| 2478 | }, |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 2479 | #ifdef CONFIG_ACPI_IBM_DOCK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2481 | .name = "dock", |
| 2482 | .read = dock_read, |
| 2483 | .write = dock_write, |
| 2484 | .notify = dock_notify, |
| 2485 | .handle = &dock_handle, |
| 2486 | .type = ACPI_SYSTEM_NOTIFY, |
| 2487 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2488 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2489 | .name = "dock", |
| 2490 | .hid = IBM_PCI_HID, |
| 2491 | .notify = dock_notify, |
| 2492 | .handle = &pci_handle, |
| 2493 | .type = ACPI_SYSTEM_NOTIFY, |
| 2494 | }, |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 2495 | #endif |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 2496 | #ifdef CONFIG_ACPI_IBM_BAY |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2497 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2498 | .name = "bay", |
| 2499 | .init = bay_init, |
| 2500 | .read = bay_read, |
| 2501 | .write = bay_write, |
| 2502 | .notify = bay_notify, |
| 2503 | .handle = &bay_handle, |
| 2504 | .type = ACPI_SYSTEM_NOTIFY, |
| 2505 | }, |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 2506 | #endif /* CONFIG_ACPI_IBM_BAY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2508 | .name = "cmos", |
| 2509 | .read = cmos_read, |
| 2510 | .write = cmos_write, |
| 2511 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2512 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2513 | .name = "led", |
| 2514 | .init = led_init, |
| 2515 | .read = led_read, |
| 2516 | .write = led_write, |
| 2517 | }, |
| 2518 | { |
| 2519 | .name = "beep", |
| 2520 | .read = beep_read, |
| 2521 | .write = beep_write, |
| 2522 | }, |
| 2523 | { |
| 2524 | .name = "thermal", |
| 2525 | .init = thermal_init, |
| 2526 | .read = thermal_read, |
| 2527 | }, |
| 2528 | { |
| 2529 | .name = "ecdump", |
| 2530 | .read = ecdump_read, |
| 2531 | .write = ecdump_write, |
| 2532 | .experimental = 1, |
| 2533 | }, |
| 2534 | { |
| 2535 | .name = "brightness", |
| 2536 | .read = brightness_read, |
| 2537 | .write = brightness_write, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 2538 | .init = brightness_init, |
| 2539 | .exit = brightness_exit, |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2540 | }, |
| 2541 | { |
| 2542 | .name = "volume", |
| 2543 | .read = volume_read, |
| 2544 | .write = volume_write, |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2545 | }, |
| 2546 | { |
| 2547 | .name = "fan", |
| 2548 | .read = fan_read, |
| 2549 | .write = fan_write, |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2550 | .init = fan_init, |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2551 | .exit = fan_exit, |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2552 | .experimental = 1, |
| 2553 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2554 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2555 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 2556 | /* |
| 2557 | * Module and infrastructure proble, init and exit handling |
| 2558 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2559 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2560 | static int __init ibm_init(struct ibm_struct *ibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2561 | { |
| 2562 | int ret; |
| 2563 | struct proc_dir_entry *entry; |
| 2564 | |
| 2565 | if (ibm->experimental && !experimental) |
| 2566 | return 0; |
| 2567 | |
| 2568 | if (ibm->hid) { |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 2569 | ret = register_ibmacpi_subdriver(ibm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | if (ret < 0) |
| 2571 | return ret; |
| 2572 | ibm->driver_registered = 1; |
| 2573 | } |
| 2574 | |
| 2575 | if (ibm->init) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2576 | ret = ibm->init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2577 | if (ret != 0) |
| 2578 | return ret; |
| 2579 | ibm->init_called = 1; |
| 2580 | } |
| 2581 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2582 | if (ibm->read) { |
| 2583 | entry = create_proc_entry(ibm->name, |
| 2584 | S_IFREG | S_IRUGO | S_IWUSR, |
| 2585 | proc_dir); |
| 2586 | if (!entry) { |
| 2587 | printk(IBM_ERR "unable to create proc entry %s\n", |
| 2588 | ibm->name); |
| 2589 | return -ENODEV; |
| 2590 | } |
| 2591 | entry->owner = THIS_MODULE; |
| 2592 | entry->data = ibm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | entry->read_proc = &dispatch_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2594 | if (ibm->write) |
| 2595 | entry->write_proc = &dispatch_write; |
| 2596 | ibm->proc_created = 1; |
| 2597 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | |
| 2599 | if (ibm->notify) { |
| 2600 | ret = setup_notify(ibm); |
Henrique de Moraes Holschuh | 96e89af | 2007-03-15 16:15:06 -0300 | [diff] [blame] | 2601 | if (ret == -ENODEV) { |
| 2602 | printk(IBM_NOTICE "disabling subdriver %s\n", |
| 2603 | ibm->name); |
| 2604 | ibm_exit(ibm); |
| 2605 | return 0; |
| 2606 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2607 | if (ret < 0) |
| 2608 | return ret; |
| 2609 | } |
| 2610 | |
| 2611 | return 0; |
| 2612 | } |
| 2613 | |
| 2614 | static void ibm_exit(struct ibm_struct *ibm) |
| 2615 | { |
| 2616 | if (ibm->notify_installed) |
| 2617 | acpi_remove_notify_handler(*ibm->handle, ibm->type, |
| 2618 | dispatch_notify); |
| 2619 | |
| 2620 | if (ibm->proc_created) |
| 2621 | remove_proc_entry(ibm->name, proc_dir); |
| 2622 | |
| 2623 | if (ibm->init_called && ibm->exit) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2624 | ibm->exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2625 | |
| 2626 | if (ibm->driver_registered) { |
| 2627 | acpi_bus_unregister_driver(ibm->driver); |
| 2628 | kfree(ibm->driver); |
| 2629 | } |
| 2630 | } |
| 2631 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 2632 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 2634 | static char *ibm_thinkpad_ec_found = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2635 | |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2636 | static char* __init check_dmi_for_ec(void) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2637 | { |
| 2638 | struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2639 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2640 | |
| 2641 | /* |
| 2642 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 2643 | * X32 or newer, all Z series; Some models must have an |
| 2644 | * up-to-date BIOS or they will not be detected. |
| 2645 | * |
| 2646 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 2647 | */ |
| 2648 | while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) { |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2649 | if (sscanf(dev->name, |
| 2650 | "IBM ThinkPad Embedded Controller -[%17c", |
| 2651 | ec_fw_string) == 1) { |
| 2652 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 2653 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
| 2654 | return kstrdup(ec_fw_string, GFP_KERNEL); |
| 2655 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2656 | } |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2657 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2658 | } |
| 2659 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 2660 | /* Module init, exit, parameters */ |
| 2661 | |
| 2662 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 2663 | { |
| 2664 | unsigned int i; |
| 2665 | |
| 2666 | for (i = 0; i < ARRAY_SIZE(ibms); i++) |
| 2667 | if (strcmp(ibms[i].name, kp->name) == 0 && ibms[i].write) { |
| 2668 | if (strlen(val) > sizeof(ibms[i].param) - 2) |
| 2669 | return -ENOSPC; |
| 2670 | strcpy(ibms[i].param, val); |
| 2671 | strcat(ibms[i].param, ","); |
| 2672 | return 0; |
| 2673 | } |
| 2674 | |
| 2675 | return -EINVAL; |
| 2676 | } |
| 2677 | |
| 2678 | static int experimental; |
| 2679 | module_param(experimental, int, 0); |
| 2680 | |
| 2681 | #define IBM_PARAM(feature) \ |
| 2682 | module_param_call(feature, set_ibm_param, NULL, NULL, 0) |
| 2683 | |
| 2684 | IBM_PARAM(hotkey); |
| 2685 | IBM_PARAM(bluetooth); |
| 2686 | IBM_PARAM(video); |
| 2687 | IBM_PARAM(light); |
| 2688 | #ifdef CONFIG_ACPI_IBM_DOCK |
| 2689 | IBM_PARAM(dock); |
| 2690 | #endif |
| 2691 | #ifdef CONFIG_ACPI_IBM_BAY |
| 2692 | IBM_PARAM(bay); |
| 2693 | #endif /* CONFIG_ACPI_IBM_BAY */ |
| 2694 | IBM_PARAM(cmos); |
| 2695 | IBM_PARAM(led); |
| 2696 | IBM_PARAM(beep); |
| 2697 | IBM_PARAM(ecdump); |
| 2698 | IBM_PARAM(brightness); |
| 2699 | IBM_PARAM(volume); |
| 2700 | IBM_PARAM(fan); |
| 2701 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2702 | static int __init acpi_ibm_init(void) |
| 2703 | { |
| 2704 | int ret, i; |
| 2705 | |
| 2706 | if (acpi_disabled) |
| 2707 | return -ENODEV; |
| 2708 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2709 | /* ec is required because many other handles are relative to it */ |
| 2710 | IBM_HANDLE_INIT(ec); |
| 2711 | if (!ec_handle) { |
| 2712 | printk(IBM_ERR "ec object not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2713 | return -ENODEV; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2714 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2715 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2716 | /* Models with newer firmware report the EC in DMI */ |
| 2717 | ibm_thinkpad_ec_found = check_dmi_for_ec(); |
| 2718 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | /* these handles are not required */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2720 | IBM_HANDLE_INIT(vid); |
| 2721 | IBM_HANDLE_INIT(vid2); |
| 2722 | IBM_HANDLE_INIT(ledb); |
| 2723 | IBM_HANDLE_INIT(led); |
| 2724 | IBM_HANDLE_INIT(hkey); |
| 2725 | IBM_HANDLE_INIT(lght); |
| 2726 | IBM_HANDLE_INIT(cmos); |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 2727 | #ifdef CONFIG_ACPI_IBM_DOCK |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2728 | IBM_HANDLE_INIT(dock); |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 2729 | #endif |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2730 | IBM_HANDLE_INIT(pci); |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 2731 | #ifdef CONFIG_ACPI_IBM_BAY |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2732 | IBM_HANDLE_INIT(bay); |
| 2733 | if (bay_handle) |
| 2734 | IBM_HANDLE_INIT(bay_ej); |
| 2735 | IBM_HANDLE_INIT(bay2); |
| 2736 | if (bay2_handle) |
| 2737 | IBM_HANDLE_INIT(bay2_ej); |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 2738 | #endif /* CONFIG_ACPI_IBM_BAY */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2739 | IBM_HANDLE_INIT(beep); |
| 2740 | IBM_HANDLE_INIT(ecrd); |
| 2741 | IBM_HANDLE_INIT(ecwr); |
| 2742 | IBM_HANDLE_INIT(fans); |
| 2743 | IBM_HANDLE_INIT(gfan); |
| 2744 | IBM_HANDLE_INIT(sfan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2745 | |
| 2746 | proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir); |
| 2747 | if (!proc_dir) { |
| 2748 | printk(IBM_ERR "unable to create proc dir %s", IBM_DIR); |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 2749 | acpi_ibm_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2750 | return -ENODEV; |
| 2751 | } |
| 2752 | proc_dir->owner = THIS_MODULE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2753 | |
| 2754 | for (i = 0; i < ARRAY_SIZE(ibms); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | ret = ibm_init(&ibms[i]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2756 | if (ret >= 0 && *ibms[i].param) |
| 2757 | ret = ibms[i].write(ibms[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2758 | if (ret < 0) { |
| 2759 | acpi_ibm_exit(); |
| 2760 | return ret; |
| 2761 | } |
| 2762 | } |
| 2763 | |
| 2764 | return 0; |
| 2765 | } |
| 2766 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame^] | 2767 | static void acpi_ibm_exit(void) |
| 2768 | { |
| 2769 | int i; |
| 2770 | |
| 2771 | for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--) |
| 2772 | ibm_exit(&ibms[i]); |
| 2773 | |
| 2774 | if (proc_dir) |
| 2775 | remove_proc_entry(IBM_DIR, acpi_root_dir); |
| 2776 | |
| 2777 | if (ibm_thinkpad_ec_found) |
| 2778 | kfree(ibm_thinkpad_ec_found); |
| 2779 | } |
| 2780 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2781 | module_init(acpi_ibm_init); |
| 2782 | module_exit(acpi_ibm_exit); |