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