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