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" |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 25 | #define TPACPI_SYSFS_VERSION 0x000100 |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 26 | |
| 27 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * Changelog: |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 29 | * 2007-03-27 0.14 renamed to thinkpad_acpi and moved to |
| 30 | * drivers/misc. |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 31 | * |
| 32 | * 2006-11-22 0.13 new maintainer |
| 33 | * changelog now lives in git commit history, and will |
| 34 | * not be updated further in-file. |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 35 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 36 | * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels |
| 37 | * 2005-03-17 0.11 support for 600e, 770x |
| 38 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> |
| 39 | * support for 770e, G41 |
| 40 | * G40 and G41 don't have a thinklight |
| 41 | * temperatures no longer experimental |
| 42 | * experimental brightness control |
| 43 | * experimental volume control |
| 44 | * experimental fan enable/disable |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 45 | * 2005-01-16 0.10 fix module loading on R30, R31 |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 46 | * 2005-01-16 0.9 support for 570, R30, R31 |
| 47 | * ultrabay support on A22p, A3x |
| 48 | * limit arg for cmos, led, beep, drop experimental status |
| 49 | * more capable led control on A21e, A22p, T20-22, X20 |
| 50 | * experimental temperatures and fan speed |
| 51 | * experimental embedded controller register dump |
| 52 | * mark more functions as __init, drop incorrect __exit |
| 53 | * use MODULE_VERSION |
| 54 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
| 55 | * fix parameter passing on module loading |
| 56 | * thanks to Rusty Russell <rusty@rustcorp.com.au> |
| 57 | * thanks to Jim Radford <radford@blackbean.org> |
| 58 | * 2004-11-08 0.8 fix init error case, don't return from a macro |
| 59 | * thanks to Chris Wright <chrisw@osdl.org> |
| 60 | * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20 |
| 61 | * fix led control on A21e |
| 62 | * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20 |
| 64 | * proc file format changed |
| 65 | * video_switch command |
| 66 | * experimental cmos control |
| 67 | * experimental led control |
| 68 | * experimental acpi sounds |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 69 | * 2004-09-16 0.4 support for module parameters |
| 70 | * hotkey mask can be prefixed by 0x |
| 71 | * video output switching |
| 72 | * video expansion control |
| 73 | * ultrabay eject support |
| 74 | * removed lcd brightness/on/off control, didn't work |
| 75 | * 2004-08-17 0.3 support for R40 |
| 76 | * lcd off, brightness control |
| 77 | * thinklight on/off |
| 78 | * 2004-08-14 0.2 support for T series, X20 |
| 79 | * bluetooth enable/disable |
| 80 | * hotkey events disabled by default |
| 81 | * removed fan control, currently useless |
| 82 | * 2004-08-09 0.1 initial release, support for X series |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | */ |
| 84 | |
Henrique de Moraes Holschuh | f21f85d | 2007-03-29 01:58:40 -0300 | [diff] [blame] | 85 | #include "thinkpad_acpi.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 87 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 88 | MODULE_DESCRIPTION(IBM_DESC); |
| 89 | MODULE_VERSION(IBM_VERSION); |
| 90 | MODULE_LICENSE("GPL"); |
| 91 | |
Henrique de Moraes Holschuh | d903ac5 | 2007-03-29 01:58:42 -0300 | [diff] [blame] | 92 | /* Please remove this in year 2009 */ |
| 93 | MODULE_ALIAS("ibm_acpi"); |
| 94 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #define __unused __attribute__ ((unused)) |
| 96 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 97 | /**************************************************************************** |
| 98 | **************************************************************************** |
| 99 | * |
| 100 | * ACPI Helpers and device model |
| 101 | * |
| 102 | **************************************************************************** |
| 103 | ****************************************************************************/ |
| 104 | |
| 105 | /************************************************************************* |
| 106 | * ACPI basic handles |
| 107 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | static acpi_handle root_handle = NULL; |
| 110 | |
| 111 | #define IBM_HANDLE(object, parent, paths...) \ |
| 112 | static acpi_handle object##_handle; \ |
| 113 | static acpi_handle *object##_parent = &parent##_handle; \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 114 | static char *object##_path; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | static char *object##_paths[] = { paths } |
| 116 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 117 | IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
| 118 | "\\_SB.PCI.ISA.EC", /* 570 */ |
| 119 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
| 120 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
| 121 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ |
| 122 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ |
| 123 | "\\_SB.PCI0.LPC.EC", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 124 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 126 | IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 127 | IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 129 | |
| 130 | /************************************************************************* |
| 131 | * Misc ACPI handles |
| 132 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 134 | IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */ |
| 135 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 136 | "\\CMS", /* R40, R40e */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 137 | ); /* all others */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 138 | |
| 139 | IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
| 140 | "^HKEY", /* R30, R31 */ |
| 141 | "HKEY", /* all others */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 142 | ); /* 570 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 143 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 144 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 145 | /************************************************************************* |
| 146 | * ACPI helpers |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 147 | */ |
| 148 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | static int acpi_evalf(acpi_handle handle, |
| 150 | void *res, char *method, char *fmt, ...) |
| 151 | { |
| 152 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 153 | struct acpi_object_list params; |
| 154 | union acpi_object in_objs[IBM_MAX_ACPI_ARGS]; |
| 155 | struct acpi_buffer result, *resultp; |
| 156 | union acpi_object out_obj; |
| 157 | acpi_status status; |
| 158 | va_list ap; |
| 159 | char res_type; |
| 160 | int success; |
| 161 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
| 163 | if (!*fmt) { |
| 164 | printk(IBM_ERR "acpi_evalf() called with empty format\n"); |
| 165 | return 0; |
| 166 | } |
| 167 | |
| 168 | if (*fmt == 'q') { |
| 169 | quiet = 1; |
| 170 | fmt++; |
| 171 | } else |
| 172 | quiet = 0; |
| 173 | |
| 174 | res_type = *(fmt++); |
| 175 | |
| 176 | params.count = 0; |
| 177 | params.pointer = &in_objs[0]; |
| 178 | |
| 179 | va_start(ap, fmt); |
| 180 | while (*fmt) { |
| 181 | char c = *(fmt++); |
| 182 | switch (c) { |
| 183 | case 'd': /* int */ |
| 184 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 185 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 186 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 187 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | default: |
| 189 | printk(IBM_ERR "acpi_evalf() called " |
| 190 | "with invalid format character '%c'\n", c); |
| 191 | return 0; |
| 192 | } |
| 193 | } |
| 194 | va_end(ap); |
| 195 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 196 | if (res_type != 'v') { |
| 197 | result.length = sizeof(out_obj); |
| 198 | result.pointer = &out_obj; |
| 199 | resultp = &result; |
| 200 | } else |
| 201 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 203 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 206 | case 'd': /* int */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | if (res) |
| 208 | *(int *)res = out_obj.integer.value; |
| 209 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; |
| 210 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 211 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | success = status == AE_OK; |
| 213 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 214 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | default: |
| 216 | printk(IBM_ERR "acpi_evalf() called " |
| 217 | "with invalid format character '%c'\n", res_type); |
| 218 | return 0; |
| 219 | } |
| 220 | |
| 221 | if (!success && !quiet) |
| 222 | printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
| 223 | method, fmt0, status); |
| 224 | |
| 225 | return success; |
| 226 | } |
| 227 | |
| 228 | static void __unused acpi_print_int(acpi_handle handle, char *method) |
| 229 | { |
| 230 | int i; |
| 231 | |
| 232 | if (acpi_evalf(handle, &i, method, "d")) |
| 233 | printk(IBM_INFO "%s = 0x%x\n", method, i); |
| 234 | else |
| 235 | printk(IBM_ERR "error calling %s\n", method); |
| 236 | } |
| 237 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 238 | static int acpi_ec_read(int i, u8 * p) |
| 239 | { |
| 240 | int v; |
| 241 | |
| 242 | if (ecrd_handle) { |
| 243 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 244 | return 0; |
| 245 | *p = v; |
| 246 | } else { |
| 247 | if (ec_read(i, p) < 0) |
| 248 | return 0; |
| 249 | } |
| 250 | |
| 251 | return 1; |
| 252 | } |
| 253 | |
| 254 | static int acpi_ec_write(int i, u8 v) |
| 255 | { |
| 256 | if (ecwr_handle) { |
| 257 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 258 | return 0; |
| 259 | } else { |
| 260 | if (ec_write(i, v) < 0) |
| 261 | return 0; |
| 262 | } |
| 263 | |
| 264 | return 1; |
| 265 | } |
| 266 | |
| 267 | static int _sta(acpi_handle handle) |
| 268 | { |
| 269 | int status; |
| 270 | |
| 271 | if (!handle || !acpi_evalf(handle, &status, "_STA", "d")) |
| 272 | status = 0; |
| 273 | |
| 274 | return status; |
| 275 | } |
| 276 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 277 | static int issue_thinkpad_cmos_command(int cmos_cmd) |
| 278 | { |
| 279 | if (!cmos_handle) |
| 280 | return -ENXIO; |
| 281 | |
| 282 | if (!acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd)) |
| 283 | return -EIO; |
| 284 | |
| 285 | return 0; |
| 286 | } |
| 287 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 288 | /************************************************************************* |
| 289 | * ACPI device model |
| 290 | */ |
| 291 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 292 | static void drv_acpi_handle_init(char *name, |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 293 | acpi_handle *handle, acpi_handle parent, |
| 294 | char **paths, int num_paths, char **path) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 295 | { |
| 296 | int i; |
| 297 | acpi_status status; |
| 298 | |
| 299 | for (i = 0; i < num_paths; i++) { |
| 300 | status = acpi_get_handle(parent, paths[i], handle); |
| 301 | if (ACPI_SUCCESS(status)) { |
| 302 | *path = paths[i]; |
| 303 | return; |
| 304 | } |
| 305 | } |
| 306 | |
| 307 | *handle = NULL; |
| 308 | } |
| 309 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 310 | 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] | 311 | { |
| 312 | struct ibm_struct *ibm = data; |
| 313 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 314 | if (!ibm || !ibm->acpi || !ibm->acpi->notify) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 315 | return; |
| 316 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 317 | ibm->acpi->notify(ibm, event); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 318 | } |
| 319 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 320 | static int __init setup_acpi_notify(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 321 | { |
| 322 | acpi_status status; |
| 323 | int ret; |
| 324 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 325 | BUG_ON(!ibm->acpi); |
| 326 | |
| 327 | if (!*ibm->acpi->handle) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 328 | return 0; |
| 329 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 330 | dbg_printk(TPACPI_DBG_INIT, |
| 331 | "setting up ACPI notify for %s\n", ibm->name); |
| 332 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 333 | 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] | 334 | if (ret < 0) { |
| 335 | printk(IBM_ERR "%s device not present\n", ibm->name); |
| 336 | return -ENODEV; |
| 337 | } |
| 338 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 339 | acpi_driver_data(ibm->acpi->device) = ibm; |
| 340 | sprintf(acpi_device_class(ibm->acpi->device), "%s/%s", |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 341 | IBM_ACPI_EVENT_PREFIX, |
| 342 | ibm->name); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 343 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 344 | status = acpi_install_notify_handler(*ibm->acpi->handle, |
| 345 | ibm->acpi->type, dispatch_acpi_notify, ibm); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 346 | if (ACPI_FAILURE(status)) { |
| 347 | if (status == AE_ALREADY_EXISTS) { |
| 348 | printk(IBM_NOTICE "another device driver is already handling %s events\n", |
| 349 | ibm->name); |
| 350 | } else { |
| 351 | printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n", |
| 352 | ibm->name, status); |
| 353 | } |
| 354 | return -ENODEV; |
| 355 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 356 | ibm->flags.acpi_notify_installed = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 357 | return 0; |
| 358 | } |
| 359 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 360 | static int __init tpacpi_device_add(struct acpi_device *device) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 361 | { |
| 362 | return 0; |
| 363 | } |
| 364 | |
Henrique de Moraes Holschuh | 6700121 | 2007-04-21 11:08:25 -0300 | [diff] [blame] | 365 | static int __init register_tpacpi_subdriver(struct ibm_struct *ibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 366 | { |
| 367 | int ret; |
| 368 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 369 | dbg_printk(TPACPI_DBG_INIT, |
| 370 | "registering %s as an ACPI driver\n", ibm->name); |
| 371 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 372 | BUG_ON(!ibm->acpi); |
| 373 | |
| 374 | ibm->acpi->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
| 375 | if (!ibm->acpi->driver) { |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 376 | printk(IBM_ERR "kzalloc(ibm->driver) failed\n"); |
| 377 | return -ENOMEM; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 378 | } |
| 379 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 380 | sprintf(ibm->acpi->driver->name, "%s_%s", IBM_NAME, ibm->name); |
| 381 | ibm->acpi->driver->ids = ibm->acpi->hid; |
| 382 | ibm->acpi->driver->ops.add = &tpacpi_device_add; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 383 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 384 | ret = acpi_bus_register_driver(ibm->acpi->driver); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 385 | if (ret < 0) { |
| 386 | 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] | 387 | ibm->acpi->hid, ret); |
| 388 | kfree(ibm->acpi->driver); |
| 389 | ibm->acpi->driver = NULL; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 390 | } else if (!ret) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 391 | ibm->flags.acpi_driver_registered = 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 392 | |
| 393 | return ret; |
| 394 | } |
| 395 | |
| 396 | |
| 397 | /**************************************************************************** |
| 398 | **************************************************************************** |
| 399 | * |
| 400 | * Procfs Helpers |
| 401 | * |
| 402 | **************************************************************************** |
| 403 | ****************************************************************************/ |
| 404 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 405 | static int dispatch_procfs_read(char *page, char **start, off_t off, |
| 406 | int count, int *eof, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 407 | { |
| 408 | struct ibm_struct *ibm = data; |
| 409 | int len; |
| 410 | |
| 411 | if (!ibm || !ibm->read) |
| 412 | return -EINVAL; |
| 413 | |
| 414 | len = ibm->read(page); |
| 415 | if (len < 0) |
| 416 | return len; |
| 417 | |
| 418 | if (len <= off + count) |
| 419 | *eof = 1; |
| 420 | *start = page + off; |
| 421 | len -= off; |
| 422 | if (len > count) |
| 423 | len = count; |
| 424 | if (len < 0) |
| 425 | len = 0; |
| 426 | |
| 427 | return len; |
| 428 | } |
| 429 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 430 | static int dispatch_procfs_write(struct file *file, |
| 431 | const char __user * userbuf, |
| 432 | unsigned long count, void *data) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 433 | { |
| 434 | struct ibm_struct *ibm = data; |
| 435 | char *kernbuf; |
| 436 | int ret; |
| 437 | |
| 438 | if (!ibm || !ibm->write) |
| 439 | return -EINVAL; |
| 440 | |
| 441 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 442 | if (!kernbuf) |
| 443 | return -ENOMEM; |
| 444 | |
| 445 | if (copy_from_user(kernbuf, userbuf, count)) { |
| 446 | kfree(kernbuf); |
| 447 | return -EFAULT; |
| 448 | } |
| 449 | |
| 450 | kernbuf[count] = 0; |
| 451 | strcat(kernbuf, ","); |
| 452 | ret = ibm->write(kernbuf); |
| 453 | if (ret == 0) |
| 454 | ret = count; |
| 455 | |
| 456 | kfree(kernbuf); |
| 457 | |
| 458 | return ret; |
| 459 | } |
| 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | static char *next_cmd(char **cmds) |
| 462 | { |
| 463 | char *start = *cmds; |
| 464 | char *end; |
| 465 | |
| 466 | while ((end = strchr(start, ',')) && end == start) |
| 467 | start = end + 1; |
| 468 | |
| 469 | if (!end) |
| 470 | return NULL; |
| 471 | |
| 472 | *end = 0; |
| 473 | *cmds = end + 1; |
| 474 | return start; |
| 475 | } |
| 476 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 477 | |
| 478 | /**************************************************************************** |
| 479 | **************************************************************************** |
| 480 | * |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 481 | * Device model: hwmon and platform |
| 482 | * |
| 483 | **************************************************************************** |
| 484 | ****************************************************************************/ |
| 485 | |
| 486 | static struct platform_device *tpacpi_pdev = NULL; |
| 487 | static struct class_device *tpacpi_hwmon = NULL; |
| 488 | |
| 489 | static struct platform_driver tpacpi_pdriver = { |
| 490 | .driver = { |
| 491 | .name = IBM_DRVR_NAME, |
| 492 | .owner = THIS_MODULE, |
| 493 | }, |
| 494 | }; |
| 495 | |
| 496 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 497 | /************************************************************************* |
| 498 | * thinkpad-acpi driver attributes |
| 499 | */ |
| 500 | |
| 501 | /* interface_version --------------------------------------------------- */ |
| 502 | static ssize_t tpacpi_driver_interface_version_show( |
| 503 | struct device_driver *drv, |
| 504 | char *buf) |
| 505 | { |
| 506 | return snprintf(buf, PAGE_SIZE, "0x%08x\n", TPACPI_SYSFS_VERSION); |
| 507 | } |
| 508 | |
| 509 | static DRIVER_ATTR(interface_version, S_IRUGO, |
| 510 | tpacpi_driver_interface_version_show, NULL); |
| 511 | |
| 512 | /* debug_level --------------------------------------------------------- */ |
| 513 | static ssize_t tpacpi_driver_debug_show(struct device_driver *drv, |
| 514 | char *buf) |
| 515 | { |
| 516 | return snprintf(buf, PAGE_SIZE, "0x%04x\n", dbg_level); |
| 517 | } |
| 518 | |
| 519 | static ssize_t tpacpi_driver_debug_store(struct device_driver *drv, |
| 520 | const char *buf, size_t count) |
| 521 | { |
| 522 | unsigned long t; |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 523 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 524 | if (parse_strtoul(buf, 0xffff, &t)) |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 525 | return -EINVAL; |
| 526 | |
| 527 | dbg_level = t; |
| 528 | |
| 529 | return count; |
| 530 | } |
| 531 | |
| 532 | static DRIVER_ATTR(debug_level, S_IWUSR | S_IRUGO, |
| 533 | tpacpi_driver_debug_show, tpacpi_driver_debug_store); |
| 534 | |
| 535 | /* version ------------------------------------------------------------- */ |
| 536 | static ssize_t tpacpi_driver_version_show(struct device_driver *drv, |
| 537 | char *buf) |
| 538 | { |
| 539 | return snprintf(buf, PAGE_SIZE, "%s v%s\n", IBM_DESC, IBM_VERSION); |
| 540 | } |
| 541 | |
| 542 | static DRIVER_ATTR(version, S_IRUGO, |
| 543 | tpacpi_driver_version_show, NULL); |
| 544 | |
| 545 | /* --------------------------------------------------------------------- */ |
| 546 | |
| 547 | static struct driver_attribute* tpacpi_driver_attributes[] = { |
| 548 | &driver_attr_debug_level, &driver_attr_version, |
| 549 | &driver_attr_interface_version, |
| 550 | }; |
| 551 | |
| 552 | static int __init tpacpi_create_driver_attributes(struct device_driver *drv) |
| 553 | { |
| 554 | int i, res; |
| 555 | |
| 556 | i = 0; |
| 557 | res = 0; |
| 558 | while (!res && i < ARRAY_SIZE(tpacpi_driver_attributes)) { |
| 559 | res = driver_create_file(drv, tpacpi_driver_attributes[i]); |
| 560 | i++; |
| 561 | } |
| 562 | |
| 563 | return res; |
| 564 | } |
| 565 | |
| 566 | static void tpacpi_remove_driver_attributes(struct device_driver *drv) |
| 567 | { |
| 568 | int i; |
| 569 | |
| 570 | for(i = 0; i < ARRAY_SIZE(tpacpi_driver_attributes); i++) |
| 571 | driver_remove_file(drv, tpacpi_driver_attributes[i]); |
| 572 | } |
| 573 | |
Henrique de Moraes Holschuh | 7252374 | 2007-04-24 11:48:14 -0300 | [diff] [blame] | 574 | /************************************************************************* |
| 575 | * sysfs support helpers |
| 576 | */ |
| 577 | |
| 578 | struct attribute_set_obj { |
| 579 | struct attribute_set s; |
| 580 | struct attribute *a; |
| 581 | } __attribute__((packed)); |
| 582 | |
| 583 | static struct attribute_set *create_attr_set(unsigned int max_members, |
| 584 | const char* name) |
| 585 | { |
| 586 | struct attribute_set_obj *sobj; |
| 587 | |
| 588 | if (max_members == 0) |
| 589 | return NULL; |
| 590 | |
| 591 | /* Allocates space for implicit NULL at the end too */ |
| 592 | sobj = kzalloc(sizeof(struct attribute_set_obj) + |
| 593 | max_members * sizeof(struct attribute *), |
| 594 | GFP_KERNEL); |
| 595 | if (!sobj) |
| 596 | return NULL; |
| 597 | sobj->s.max_members = max_members; |
| 598 | sobj->s.group.attrs = &sobj->a; |
| 599 | sobj->s.group.name = name; |
| 600 | |
| 601 | return &sobj->s; |
| 602 | } |
| 603 | |
| 604 | /* not multi-threaded safe, use it in a single thread per set */ |
| 605 | static int add_to_attr_set(struct attribute_set* s, struct attribute *attr) |
| 606 | { |
| 607 | if (!s || !attr) |
| 608 | return -EINVAL; |
| 609 | |
| 610 | if (s->members >= s->max_members) |
| 611 | return -ENOMEM; |
| 612 | |
| 613 | s->group.attrs[s->members] = attr; |
| 614 | s->members++; |
| 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | static int add_many_to_attr_set(struct attribute_set* s, |
| 620 | struct attribute **attr, |
| 621 | unsigned int count) |
| 622 | { |
| 623 | int i, res; |
| 624 | |
| 625 | for (i = 0; i < count; i++) { |
| 626 | res = add_to_attr_set(s, attr[i]); |
| 627 | if (res) |
| 628 | return res; |
| 629 | } |
| 630 | |
| 631 | return 0; |
| 632 | } |
| 633 | |
| 634 | static void delete_attr_set(struct attribute_set* s, struct kobject *kobj) |
| 635 | { |
| 636 | sysfs_remove_group(kobj, &s->group); |
| 637 | destroy_attr_set(s); |
| 638 | } |
| 639 | |
| 640 | static int parse_strtoul(const char *buf, |
| 641 | unsigned long max, unsigned long *value) |
| 642 | { |
| 643 | char *endp; |
| 644 | |
| 645 | *value = simple_strtoul(buf, &endp, 0); |
| 646 | while (*endp && isspace(*endp)) |
| 647 | endp++; |
| 648 | if (*endp || *value > max) |
| 649 | return -EINVAL; |
| 650 | |
| 651 | return 0; |
| 652 | } |
| 653 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 654 | /**************************************************************************** |
| 655 | **************************************************************************** |
| 656 | * |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 657 | * Subdrivers |
| 658 | * |
| 659 | **************************************************************************** |
| 660 | ****************************************************************************/ |
| 661 | |
| 662 | /************************************************************************* |
Henrique de Moraes Holschuh | 142cfc9 | 2007-04-21 11:08:26 -0300 | [diff] [blame] | 663 | * thinkpad-acpi init subdriver |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 664 | */ |
| 665 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 666 | static int __init thinkpad_acpi_driver_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | { |
| 668 | printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); |
| 669 | printk(IBM_INFO "%s\n", IBM_URL); |
| 670 | |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 671 | if (ibm_thinkpad_ec_found) |
| 672 | printk(IBM_INFO "ThinkPad EC firmware %s\n", |
| 673 | ibm_thinkpad_ec_found); |
| 674 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | return 0; |
| 676 | } |
| 677 | |
Henrique de Moraes Holschuh | 643f12d | 2007-03-29 01:58:43 -0300 | [diff] [blame] | 678 | static int thinkpad_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | { |
| 680 | int len = 0; |
| 681 | |
| 682 | len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC); |
| 683 | len += sprintf(p + len, "version:\t%s\n", IBM_VERSION); |
| 684 | |
| 685 | return len; |
| 686 | } |
| 687 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 688 | static struct ibm_struct thinkpad_acpi_driver_data = { |
| 689 | .name = "driver", |
| 690 | .read = thinkpad_acpi_driver_read, |
| 691 | }; |
| 692 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 693 | /************************************************************************* |
| 694 | * Hotkey subdriver |
| 695 | */ |
| 696 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 697 | static int hotkey_orig_status; |
| 698 | static int hotkey_orig_mask; |
| 699 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 700 | static int __init hotkey_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 701 | { |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 702 | int res; |
| 703 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 704 | vdbg_printk(TPACPI_DBG_INIT, "initializing hotkey subdriver\n"); |
| 705 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 706 | IBM_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 707 | mutex_init(&hotkey_mutex); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 708 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 709 | /* hotkey not supported on 570 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 710 | tp_features.hotkey = hkey_handle != NULL; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 711 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 712 | vdbg_printk(TPACPI_DBG_INIT, "hotkeys are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 713 | str_supported(tp_features.hotkey)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 714 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 715 | if (tp_features.hotkey) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 716 | /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 717 | A30, R30, R31, T20-22, X20-21, X22-24 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 718 | tp_features.hotkey_mask = |
| 719 | acpi_evalf(hkey_handle, NULL, "DHKN", "qv"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 720 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 721 | vdbg_printk(TPACPI_DBG_INIT, "hotkey masks are %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 722 | str_supported(tp_features.hotkey_mask)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 723 | |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 724 | res = hotkey_get(&hotkey_orig_status, &hotkey_orig_mask); |
| 725 | if (res) |
| 726 | return res; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 727 | } |
| 728 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 729 | return (tp_features.hotkey)? 0 : 1; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | static void hotkey_exit(void) |
| 733 | { |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 734 | int res; |
| 735 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 736 | if (tp_features.hotkey) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 737 | dbg_printk(TPACPI_DBG_EXIT, "restoring original hotkey mask\n"); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 738 | res = hotkey_set(hotkey_orig_status, hotkey_orig_mask); |
| 739 | if (res) |
| 740 | 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] | 741 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 742 | } |
| 743 | |
| 744 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 745 | { |
| 746 | int hkey; |
| 747 | |
| 748 | if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 749 | acpi_bus_generate_event(ibm->acpi->device, event, hkey); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 750 | else { |
| 751 | printk(IBM_ERR "unknown hotkey event %d\n", event); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 752 | acpi_bus_generate_event(ibm->acpi->device, event, 0); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 753 | } |
| 754 | } |
| 755 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 756 | /* |
| 757 | * Call with hotkey_mutex held |
| 758 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 759 | static int hotkey_get(int *status, int *mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | { |
| 761 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 762 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 763 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 764 | if (tp_features.hotkey_mask) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 765 | if (!acpi_evalf(hkey_handle, mask, "DHKN", "d")) |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 766 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 767 | |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 768 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | } |
| 770 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 771 | /* |
| 772 | * Call with hotkey_mutex held |
| 773 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 774 | static int hotkey_set(int status, int mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | { |
| 776 | int i; |
| 777 | |
| 778 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 779 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 781 | if (tp_features.hotkey_mask) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 782 | for (i = 0; i < 32; i++) { |
| 783 | int bit = ((1 << i) & mask) != 0; |
| 784 | if (!acpi_evalf(hkey_handle, |
| 785 | NULL, "MHKM", "vdd", i + 1, bit)) |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 786 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 787 | } |
| 788 | |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 789 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 790 | } |
| 791 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 792 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | { |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 794 | int res, status, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | int len = 0; |
| 796 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 797 | if (!tp_features.hotkey) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 798 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 799 | return len; |
| 800 | } |
| 801 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 802 | res = mutex_lock_interruptible(&hotkey_mutex); |
| 803 | if (res < 0) |
| 804 | return res; |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 805 | res = hotkey_get(&status, &mask); |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 806 | mutex_unlock(&hotkey_mutex); |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 807 | if (res) |
| 808 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | |
| 810 | 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] | 811 | if (tp_features.hotkey_mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | len += sprintf(p + len, "mask:\t\t0x%04x\n", mask); |
| 813 | len += sprintf(p + len, |
| 814 | "commands:\tenable, disable, reset, <mask>\n"); |
| 815 | } else { |
| 816 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 817 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 818 | } |
| 819 | |
| 820 | return len; |
| 821 | } |
| 822 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 823 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | { |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 825 | int res, status, mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 826 | char *cmd; |
| 827 | int do_cmd = 0; |
| 828 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 829 | if (!tp_features.hotkey) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 830 | return -ENODEV; |
| 831 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 832 | res = mutex_lock_interruptible(&hotkey_mutex); |
| 833 | if (res < 0) |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 834 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 835 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 836 | res = hotkey_get(&status, &mask); |
| 837 | if (res) |
| 838 | goto errexit; |
| 839 | |
| 840 | res = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | while ((cmd = next_cmd(&buf))) { |
| 842 | if (strlencmp(cmd, "enable") == 0) { |
| 843 | status = 1; |
| 844 | } else if (strlencmp(cmd, "disable") == 0) { |
| 845 | status = 0; |
| 846 | } else if (strlencmp(cmd, "reset") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 847 | status = hotkey_orig_status; |
| 848 | mask = hotkey_orig_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 850 | /* mask set */ |
| 851 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 852 | /* mask set */ |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 853 | } else { |
| 854 | res = -EINVAL; |
| 855 | goto errexit; |
| 856 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | do_cmd = 1; |
| 858 | } |
| 859 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 860 | if (do_cmd) |
Henrique de Moraes Holschuh | b86c472 | 2007-04-21 11:08:39 -0300 | [diff] [blame] | 861 | res = hotkey_set(status, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 862 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 863 | errexit: |
| 864 | mutex_unlock(&hotkey_mutex); |
| 865 | return res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 866 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 868 | static struct tp_acpi_drv_struct ibm_hotkey_acpidriver = { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 869 | .hid = IBM_HKEY_HID, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 870 | .notify = hotkey_notify, |
| 871 | .handle = &hkey_handle, |
| 872 | .type = ACPI_DEVICE_NOTIFY, |
| 873 | }; |
| 874 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 875 | static struct ibm_struct hotkey_driver_data = { |
| 876 | .name = "hotkey", |
| 877 | .read = hotkey_read, |
| 878 | .write = hotkey_write, |
| 879 | .exit = hotkey_exit, |
| 880 | .acpi = &ibm_hotkey_acpidriver, |
| 881 | }; |
| 882 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 883 | /************************************************************************* |
| 884 | * Bluetooth subdriver |
| 885 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 887 | static int __init bluetooth_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 889 | int status = 0; |
| 890 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 891 | vdbg_printk(TPACPI_DBG_INIT, "initializing bluetooth subdriver\n"); |
| 892 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 893 | IBM_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 894 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 895 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 896 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 897 | tp_features.bluetooth = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 898 | acpi_evalf(hkey_handle, &status, "GBDC", "qd"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 900 | vdbg_printk(TPACPI_DBG_INIT, "bluetooth is %s, status 0x%02x\n", |
| 901 | str_supported(tp_features.bluetooth), |
| 902 | status); |
| 903 | |
| 904 | if (tp_features.bluetooth && |
| 905 | !(status & TP_ACPI_BLUETOOTH_HWPRESENT)) { |
| 906 | /* no bluetooth hardware present in system */ |
| 907 | tp_features.bluetooth = 0; |
| 908 | dbg_printk(TPACPI_DBG_INIT, |
| 909 | "bluetooth hardware not installed\n"); |
| 910 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 911 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 912 | return (tp_features.bluetooth)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 913 | } |
| 914 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 915 | static int bluetooth_get_radiosw(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | { |
| 917 | int status; |
| 918 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 919 | if (!tp_features.bluetooth) |
| 920 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 922 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 923 | return -EIO; |
| 924 | |
| 925 | return ((status & TP_ACPI_BLUETOOTH_RADIOSSW) != 0); |
| 926 | } |
| 927 | |
| 928 | static int bluetooth_set_radiosw(int radio_on) |
| 929 | { |
| 930 | int status; |
| 931 | |
| 932 | if (!tp_features.bluetooth) |
| 933 | return -ENODEV; |
| 934 | |
| 935 | if (!acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
| 936 | return -EIO; |
| 937 | if (radio_on) |
| 938 | status |= TP_ACPI_BLUETOOTH_RADIOSSW; |
| 939 | else |
| 940 | status &= ~TP_ACPI_BLUETOOTH_RADIOSSW; |
| 941 | if (!acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
| 942 | return -EIO; |
| 943 | |
| 944 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | } |
| 946 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 947 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | { |
| 949 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 950 | int status = bluetooth_get_radiosw(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 952 | if (!tp_features.bluetooth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 953 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 955 | len += sprintf(p + len, "status:\t\t%s\n", |
| 956 | (status)? "enabled" : "disabled"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 958 | } |
| 959 | |
| 960 | return len; |
| 961 | } |
| 962 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 963 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 964 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | char *cmd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 966 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 967 | if (!tp_features.bluetooth) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 968 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | |
| 970 | while ((cmd = next_cmd(&buf))) { |
| 971 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 972 | bluetooth_set_radiosw(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 973 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 974 | bluetooth_set_radiosw(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | } else |
| 976 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 977 | } |
| 978 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | return 0; |
| 980 | } |
| 981 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 982 | static struct ibm_struct bluetooth_driver_data = { |
| 983 | .name = "bluetooth", |
| 984 | .read = bluetooth_read, |
| 985 | .write = bluetooth_write, |
| 986 | }; |
| 987 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 988 | /************************************************************************* |
| 989 | * Wan subdriver |
| 990 | */ |
| 991 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 992 | static int __init wan_init(struct ibm_init_struct *iibm) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 993 | { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 994 | int status = 0; |
| 995 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 996 | vdbg_printk(TPACPI_DBG_INIT, "initializing wan subdriver\n"); |
| 997 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 998 | IBM_ACPIHANDLE_INIT(hkey); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 999 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1000 | tp_features.wan = hkey_handle && |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 1001 | acpi_evalf(hkey_handle, &status, "GWAN", "qd"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1002 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 1003 | vdbg_printk(TPACPI_DBG_INIT, "wan is %s, status 0x%02x\n", |
| 1004 | str_supported(tp_features.wan), |
| 1005 | status); |
| 1006 | |
| 1007 | if (tp_features.wan && |
| 1008 | !(status & TP_ACPI_WANCARD_HWPRESENT)) { |
| 1009 | /* no wan hardware present in system */ |
| 1010 | tp_features.wan = 0; |
| 1011 | dbg_printk(TPACPI_DBG_INIT, |
| 1012 | "wan hardware not installed\n"); |
| 1013 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1014 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1015 | return (tp_features.wan)? 0 : 1; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1016 | } |
| 1017 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 1018 | static int wan_get_radiosw(void) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1019 | { |
| 1020 | int status; |
| 1021 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 1022 | if (!tp_features.wan) |
| 1023 | return -ENODEV; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1024 | |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 1025 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 1026 | return -EIO; |
| 1027 | |
| 1028 | return ((status & TP_ACPI_WANCARD_RADIOSSW) != 0); |
| 1029 | } |
| 1030 | |
| 1031 | static int wan_set_radiosw(int radio_on) |
| 1032 | { |
| 1033 | int status; |
| 1034 | |
| 1035 | if (!tp_features.wan) |
| 1036 | return -ENODEV; |
| 1037 | |
| 1038 | if (!acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
| 1039 | return -EIO; |
| 1040 | if (radio_on) |
| 1041 | status |= TP_ACPI_WANCARD_RADIOSSW; |
| 1042 | else |
| 1043 | status &= ~TP_ACPI_WANCARD_RADIOSSW; |
| 1044 | if (!acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 1045 | return -EIO; |
| 1046 | |
| 1047 | return 0; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | static int wan_read(char *p) |
| 1051 | { |
| 1052 | int len = 0; |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 1053 | int status = wan_get_radiosw(); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1054 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1055 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1056 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1057 | else { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 1058 | len += sprintf(p + len, "status:\t\t%s\n", |
| 1059 | (status)? "enabled" : "disabled"); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1060 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 1061 | } |
| 1062 | |
| 1063 | return len; |
| 1064 | } |
| 1065 | |
| 1066 | static int wan_write(char *buf) |
| 1067 | { |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1068 | char *cmd; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1069 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1070 | if (!tp_features.wan) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1071 | return -ENODEV; |
| 1072 | |
| 1073 | while ((cmd = next_cmd(&buf))) { |
| 1074 | if (strlencmp(cmd, "enable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 1075 | wan_set_radiosw(1); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1076 | } else if (strlencmp(cmd, "disable") == 0) { |
Henrique de Moraes Holschuh | d6fdd1e | 2007-04-21 11:08:40 -0300 | [diff] [blame] | 1077 | wan_set_radiosw(0); |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1078 | } else |
| 1079 | return -EINVAL; |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1080 | } |
| 1081 | |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 1082 | return 0; |
| 1083 | } |
| 1084 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1085 | static struct ibm_struct wan_driver_data = { |
| 1086 | .name = "wan", |
| 1087 | .read = wan_read, |
| 1088 | .write = wan_write, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 1089 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1090 | }; |
| 1091 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1092 | /************************************************************************* |
| 1093 | * Video subdriver |
| 1094 | */ |
| 1095 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1096 | static enum video_access_mode video_supported; |
| 1097 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1098 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1099 | IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 1100 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 1101 | "\\_SB.PCI0.VID0", /* 770e */ |
| 1102 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 1103 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 1104 | ); /* R30, R31 */ |
| 1105 | |
| 1106 | IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
| 1107 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1108 | static int __init video_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1110 | int ivga; |
| 1111 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1112 | vdbg_printk(TPACPI_DBG_INIT, "initializing video subdriver\n"); |
| 1113 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1114 | IBM_ACPIHANDLE_INIT(vid); |
| 1115 | IBM_ACPIHANDLE_INIT(vid2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1116 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1117 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 1118 | /* G41, assume IVGA doesn't change */ |
| 1119 | vid_handle = vid2_handle; |
| 1120 | |
| 1121 | if (!vid_handle) |
| 1122 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1123 | video_supported = TPACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1124 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 1125 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1126 | video_supported = TPACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1127 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 1128 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1129 | video_supported = TPACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1130 | else |
| 1131 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1132 | video_supported = TPACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1133 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1134 | vdbg_printk(TPACPI_DBG_INIT, "video is %s, mode %d\n", |
| 1135 | str_supported(video_supported != TPACPI_VIDEO_NONE), |
| 1136 | video_supported); |
| 1137 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1138 | return (video_supported != TPACPI_VIDEO_NONE)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | } |
| 1140 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1141 | static void video_exit(void) |
| 1142 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1143 | dbg_printk(TPACPI_DBG_EXIT, |
| 1144 | "restoring original video autoswitch mode\n"); |
| 1145 | if (video_autosw_set(video_orig_autosw)) |
| 1146 | printk(IBM_ERR "error while trying to restore original " |
| 1147 | "video autoswitch mode\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1148 | } |
| 1149 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1150 | static int video_outputsw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | { |
| 1152 | int status = 0; |
| 1153 | int i; |
| 1154 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1155 | switch (video_supported) { |
| 1156 | case TPACPI_VIDEO_570: |
| 1157 | if (!acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", |
| 1158 | TP_ACPI_VIDEO_570_PHSCMD)) |
| 1159 | return -EIO; |
| 1160 | status = i & TP_ACPI_VIDEO_570_PHSMASK; |
| 1161 | break; |
| 1162 | case TPACPI_VIDEO_770: |
| 1163 | if (!acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 1164 | return -EIO; |
| 1165 | if (i) |
| 1166 | status |= TP_ACPI_VIDEO_S_LCD; |
| 1167 | if (!acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 1168 | return -EIO; |
| 1169 | if (i) |
| 1170 | status |= TP_ACPI_VIDEO_S_CRT; |
| 1171 | break; |
| 1172 | case TPACPI_VIDEO_NEW: |
| 1173 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1) || |
| 1174 | !acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 1175 | return -EIO; |
| 1176 | if (i) |
| 1177 | status |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1179 | if (!acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0) || |
| 1180 | !acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 1181 | return -EIO; |
| 1182 | if (i) |
| 1183 | status |= TP_ACPI_VIDEO_S_LCD; |
| 1184 | if (!acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 1185 | return -EIO; |
| 1186 | if (i) |
| 1187 | status |= TP_ACPI_VIDEO_S_DVI; |
| 1188 | break; |
| 1189 | default: |
| 1190 | return -ENOSYS; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1191 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | |
| 1193 | return status; |
| 1194 | } |
| 1195 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1196 | static int video_outputsw_set(int status) |
| 1197 | { |
| 1198 | int autosw; |
| 1199 | int res = 0; |
| 1200 | |
| 1201 | switch (video_supported) { |
| 1202 | case TPACPI_VIDEO_570: |
| 1203 | res = acpi_evalf(NULL, NULL, |
| 1204 | "\\_SB.PHS2", "vdd", |
| 1205 | TP_ACPI_VIDEO_570_PHS2CMD, |
| 1206 | status | TP_ACPI_VIDEO_570_PHS2SET); |
| 1207 | break; |
| 1208 | case TPACPI_VIDEO_770: |
| 1209 | autosw = video_autosw_get(); |
| 1210 | if (autosw < 0) |
| 1211 | return autosw; |
| 1212 | |
| 1213 | res = video_autosw_set(1); |
| 1214 | if (res) |
| 1215 | return res; |
| 1216 | res = acpi_evalf(vid_handle, NULL, |
| 1217 | "ASWT", "vdd", status * 0x100, 0); |
| 1218 | if (!autosw && video_autosw_set(autosw)) { |
| 1219 | printk(IBM_ERR "video auto-switch left enabled due to error\n"); |
| 1220 | return -EIO; |
| 1221 | } |
| 1222 | break; |
| 1223 | case TPACPI_VIDEO_NEW: |
| 1224 | res = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
| 1225 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
| 1226 | break; |
| 1227 | default: |
| 1228 | return -ENOSYS; |
| 1229 | } |
| 1230 | |
| 1231 | return (res)? 0 : -EIO; |
| 1232 | } |
| 1233 | |
| 1234 | static int video_autosw_get(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1235 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1236 | int autosw = 0; |
| 1237 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1238 | switch (video_supported) { |
| 1239 | case TPACPI_VIDEO_570: |
| 1240 | if (!acpi_evalf(vid_handle, &autosw, "SWIT", "d")) |
| 1241 | return -EIO; |
| 1242 | break; |
| 1243 | case TPACPI_VIDEO_770: |
| 1244 | case TPACPI_VIDEO_NEW: |
| 1245 | if (!acpi_evalf(vid_handle, &autosw, "^VDEE", "d")) |
| 1246 | return -EIO; |
| 1247 | break; |
| 1248 | default: |
| 1249 | return -ENOSYS; |
| 1250 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1251 | |
| 1252 | return autosw & 1; |
| 1253 | } |
| 1254 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1255 | static int video_autosw_set(int enable) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1256 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1257 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", (enable)? 1 : 0)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1258 | return -EIO; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1259 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1260 | } |
| 1261 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1262 | static int video_outputsw_cycle(void) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1263 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1264 | int autosw = video_autosw_get(); |
| 1265 | int res; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1266 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1267 | if (autosw < 0) |
| 1268 | return autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1269 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1270 | switch (video_supported) { |
| 1271 | case TPACPI_VIDEO_570: |
| 1272 | res = video_autosw_set(1); |
| 1273 | if (res) |
| 1274 | return res; |
| 1275 | res = acpi_evalf(ec_handle, NULL, "_Q16", "v"); |
| 1276 | break; |
| 1277 | case TPACPI_VIDEO_770: |
| 1278 | case TPACPI_VIDEO_NEW: |
| 1279 | res = video_autosw_set(1); |
| 1280 | if (res) |
| 1281 | return res; |
| 1282 | res = acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 1283 | break; |
| 1284 | default: |
| 1285 | return -ENOSYS; |
| 1286 | } |
| 1287 | if (!autosw && video_autosw_set(autosw)) { |
| 1288 | printk(IBM_ERR "video auto-switch left enabled due to error\n"); |
| 1289 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1290 | } |
| 1291 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1292 | return (res)? 0 : -EIO; |
| 1293 | } |
| 1294 | |
| 1295 | static int video_expand_toggle(void) |
| 1296 | { |
| 1297 | switch (video_supported) { |
| 1298 | case TPACPI_VIDEO_570: |
| 1299 | return acpi_evalf(ec_handle, NULL, "_Q17", "v")? |
| 1300 | 0 : -EIO; |
| 1301 | case TPACPI_VIDEO_770: |
| 1302 | return acpi_evalf(vid_handle, NULL, "VEXP", "v")? |
| 1303 | 0 : -EIO; |
| 1304 | case TPACPI_VIDEO_NEW: |
| 1305 | return acpi_evalf(NULL, NULL, "\\VEXP", "v")? |
| 1306 | 0 : -EIO; |
| 1307 | default: |
| 1308 | return -ENOSYS; |
| 1309 | } |
| 1310 | /* not reached */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1311 | } |
| 1312 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1313 | static int video_read(char *p) |
| 1314 | { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1315 | int status, autosw; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1316 | int len = 0; |
| 1317 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1318 | if (video_supported == TPACPI_VIDEO_NONE) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1319 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1320 | return len; |
| 1321 | } |
| 1322 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1323 | status = video_outputsw_get(); |
| 1324 | if (status < 0) |
| 1325 | return status; |
| 1326 | |
| 1327 | autosw = video_autosw_get(); |
| 1328 | if (autosw < 0) |
| 1329 | return autosw; |
| 1330 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1331 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 1332 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 1333 | 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] | 1334 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1335 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 1336 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 1337 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 1338 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1339 | if (video_supported == TPACPI_VIDEO_NEW) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1340 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 1341 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
| 1342 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 1343 | |
| 1344 | return len; |
| 1345 | } |
| 1346 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1347 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | { |
| 1349 | char *cmd; |
| 1350 | int enable, disable, status; |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1351 | int res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1353 | if (video_supported == TPACPI_VIDEO_NONE) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1354 | return -ENODEV; |
| 1355 | |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1356 | enable = 0; |
| 1357 | disable = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | |
| 1359 | while ((cmd = next_cmd(&buf))) { |
| 1360 | if (strlencmp(cmd, "lcd_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1361 | enable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1363 | disable |= TP_ACPI_VIDEO_S_LCD; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1364 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1365 | enable |= TP_ACPI_VIDEO_S_CRT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1367 | disable |= TP_ACPI_VIDEO_S_CRT; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1368 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1369 | strlencmp(cmd, "dvi_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1370 | enable |= TP_ACPI_VIDEO_S_DVI; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1371 | } else if (video_supported == TPACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1372 | strlencmp(cmd, "dvi_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1373 | disable |= TP_ACPI_VIDEO_S_DVI; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1375 | res = video_autosw_set(1); |
| 1376 | if (res) |
| 1377 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1379 | res = video_autosw_set(0); |
| 1380 | if (res) |
| 1381 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1383 | res = video_outputsw_cycle(); |
| 1384 | if (res) |
| 1385 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1387 | res = video_expand_toggle(); |
| 1388 | if (res) |
| 1389 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | } else |
| 1391 | return -EINVAL; |
| 1392 | } |
| 1393 | |
| 1394 | if (enable || disable) { |
Henrique de Moraes Holschuh | 83f3472 | 2007-04-21 11:08:41 -0300 | [diff] [blame] | 1395 | status = video_outputsw_get(); |
| 1396 | if (status < 0) |
| 1397 | return status; |
| 1398 | res = video_outputsw_set((status & ~disable) | enable); |
| 1399 | if (res) |
| 1400 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1401 | } |
| 1402 | |
| 1403 | return 0; |
| 1404 | } |
| 1405 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1406 | static struct ibm_struct video_driver_data = { |
| 1407 | .name = "video", |
| 1408 | .read = video_read, |
| 1409 | .write = video_write, |
| 1410 | .exit = video_exit, |
| 1411 | }; |
| 1412 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1413 | /************************************************************************* |
| 1414 | * Light (thinklight) subdriver |
| 1415 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1417 | IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 1418 | IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
| 1419 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1420 | static int __init light_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1421 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1422 | vdbg_printk(TPACPI_DBG_INIT, "initializing light subdriver\n"); |
| 1423 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1424 | IBM_ACPIHANDLE_INIT(ledb); |
| 1425 | IBM_ACPIHANDLE_INIT(lght); |
| 1426 | IBM_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1427 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1428 | /* 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] | 1429 | tp_features.light = (cmos_handle || lght_handle) && !ledb_handle; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1430 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1431 | if (tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1432 | /* light status not supported on |
| 1433 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1434 | tp_features.light_status = |
| 1435 | acpi_evalf(ec_handle, NULL, "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1437 | vdbg_printk(TPACPI_DBG_INIT, "light is %s\n", |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1438 | str_supported(tp_features.light)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1439 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1440 | return (tp_features.light)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | } |
| 1442 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1443 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | { |
| 1445 | int len = 0; |
| 1446 | int status = 0; |
| 1447 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1448 | if (!tp_features.light) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1449 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1450 | } else if (!tp_features.light_status) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1451 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 1452 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 1453 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1454 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 1455 | return -EIO; |
| 1456 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1457 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 1458 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1459 | |
| 1460 | return len; |
| 1461 | } |
| 1462 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1463 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1464 | { |
| 1465 | int cmos_cmd, lght_cmd; |
| 1466 | char *cmd; |
| 1467 | int success; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1468 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1469 | if (!tp_features.light) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1470 | return -ENODEV; |
| 1471 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | while ((cmd = next_cmd(&buf))) { |
| 1473 | if (strlencmp(cmd, "on") == 0) { |
| 1474 | cmos_cmd = 0x0c; |
| 1475 | lght_cmd = 1; |
| 1476 | } else if (strlencmp(cmd, "off") == 0) { |
| 1477 | cmos_cmd = 0x0d; |
| 1478 | lght_cmd = 0; |
| 1479 | } else |
| 1480 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1481 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | success = cmos_handle ? |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1483 | acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) : |
| 1484 | acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | if (!success) |
| 1486 | return -EIO; |
| 1487 | } |
| 1488 | |
| 1489 | return 0; |
| 1490 | } |
| 1491 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1492 | static struct ibm_struct light_driver_data = { |
| 1493 | .name = "light", |
| 1494 | .read = light_read, |
| 1495 | .write = light_write, |
| 1496 | }; |
| 1497 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1498 | /************************************************************************* |
| 1499 | * Dock subdriver |
| 1500 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 1502 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1503 | |
| 1504 | IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ |
| 1505 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ |
| 1506 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ |
| 1507 | "\\_SB.PCI.ISA.SLCE", /* 570 */ |
| 1508 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ |
| 1509 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1510 | /* don't list other alternatives as we install a notify handler on the 570 */ |
| 1511 | IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ |
| 1512 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | #define dock_docked() (_sta(dock_handle) & 1) |
| 1514 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1515 | static int __init dock_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1516 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1517 | vdbg_printk(TPACPI_DBG_INIT, "initializing dock subdriver\n"); |
| 1518 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1519 | IBM_ACPIHANDLE_INIT(dock); |
| 1520 | IBM_ACPIHANDLE_INIT(pci); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1521 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1522 | vdbg_printk(TPACPI_DBG_INIT, "dock is %s\n", |
| 1523 | str_supported(dock_handle != NULL)); |
| 1524 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1525 | return (dock_handle)? 0 : 1; |
| 1526 | } |
| 1527 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1528 | static void dock_notify(struct ibm_struct *ibm, u32 event) |
| 1529 | { |
| 1530 | int docked = dock_docked(); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1531 | 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] | 1532 | |
| 1533 | if (event == 1 && !pci) /* 570 */ |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1534 | acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1535 | else if (event == 1 && pci) /* 570 */ |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1536 | acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1537 | else if (event == 3 && docked) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1538 | acpi_bus_generate_event(ibm->acpi->device, event, 1); /* button */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1539 | else if (event == 3 && !docked) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1540 | acpi_bus_generate_event(ibm->acpi->device, event, 2); /* undock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1541 | else if (event == 0 && docked) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1542 | acpi_bus_generate_event(ibm->acpi->device, event, 3); /* dock */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1543 | else { |
| 1544 | printk(IBM_ERR "unknown dock event %d, status %d\n", |
| 1545 | event, _sta(dock_handle)); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1546 | acpi_bus_generate_event(ibm->acpi->device, event, 0); /* unknown */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1547 | } |
| 1548 | } |
| 1549 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1550 | static int dock_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1551 | { |
| 1552 | int len = 0; |
| 1553 | int docked = dock_docked(); |
| 1554 | |
| 1555 | if (!dock_handle) |
| 1556 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1557 | else if (!docked) |
| 1558 | len += sprintf(p + len, "status:\t\tundocked\n"); |
| 1559 | else { |
| 1560 | len += sprintf(p + len, "status:\t\tdocked\n"); |
| 1561 | len += sprintf(p + len, "commands:\tdock, undock\n"); |
| 1562 | } |
| 1563 | |
| 1564 | return len; |
| 1565 | } |
| 1566 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1567 | static int dock_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1568 | { |
| 1569 | char *cmd; |
| 1570 | |
| 1571 | if (!dock_docked()) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1572 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | |
| 1574 | while ((cmd = next_cmd(&buf))) { |
| 1575 | if (strlencmp(cmd, "undock") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1576 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) || |
| 1577 | !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1578 | return -EIO; |
| 1579 | } else if (strlencmp(cmd, "dock") == 0) { |
| 1580 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1)) |
| 1581 | return -EIO; |
| 1582 | } else |
| 1583 | return -EINVAL; |
| 1584 | } |
| 1585 | |
| 1586 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1587 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1589 | static struct tp_acpi_drv_struct ibm_dock_acpidriver[2] = { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1590 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1591 | .notify = dock_notify, |
| 1592 | .handle = &dock_handle, |
| 1593 | .type = ACPI_SYSTEM_NOTIFY, |
| 1594 | }, |
| 1595 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1596 | .hid = IBM_PCI_HID, |
| 1597 | .notify = dock_notify, |
| 1598 | .handle = &pci_handle, |
| 1599 | .type = ACPI_SYSTEM_NOTIFY, |
| 1600 | }, |
| 1601 | }; |
| 1602 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1603 | static struct ibm_struct dock_driver_data[2] = { |
| 1604 | { |
| 1605 | .name = "dock", |
| 1606 | .read = dock_read, |
| 1607 | .write = dock_write, |
| 1608 | .acpi = &ibm_dock_acpidriver[0], |
| 1609 | }, |
| 1610 | { |
| 1611 | .name = "dock", |
| 1612 | .acpi = &ibm_dock_acpidriver[1], |
| 1613 | }, |
| 1614 | }; |
| 1615 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 1616 | #endif /* CONFIG_THINKPAD_ACPI_DOCK */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1617 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1618 | /************************************************************************* |
| 1619 | * Bay subdriver |
| 1620 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 1622 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1623 | IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ |
| 1624 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ |
| 1625 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ |
| 1626 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ |
| 1627 | ); /* A21e, R30, R31 */ |
| 1628 | IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */ |
| 1629 | "_EJ0", /* all others */ |
| 1630 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ |
| 1631 | IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */ |
| 1632 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ |
| 1633 | ); /* all others */ |
| 1634 | IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ |
| 1635 | "_EJ0", /* 770x */ |
| 1636 | ); /* all others */ |
| 1637 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1638 | static int __init bay_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1640 | vdbg_printk(TPACPI_DBG_INIT, "initializing bay subdriver\n"); |
| 1641 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1642 | IBM_ACPIHANDLE_INIT(bay); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1643 | if (bay_handle) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1644 | IBM_ACPIHANDLE_INIT(bay_ej); |
| 1645 | IBM_ACPIHANDLE_INIT(bay2); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1646 | if (bay2_handle) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1647 | IBM_ACPIHANDLE_INIT(bay2_ej); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1648 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1649 | tp_features.bay_status = bay_handle && |
| 1650 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); |
| 1651 | tp_features.bay_status2 = bay2_handle && |
| 1652 | acpi_evalf(bay2_handle, NULL, "_STA", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1653 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1654 | tp_features.bay_eject = bay_handle && bay_ej_handle && |
| 1655 | (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental); |
| 1656 | tp_features.bay_eject2 = bay2_handle && bay2_ej_handle && |
| 1657 | (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1659 | vdbg_printk(TPACPI_DBG_INIT, |
| 1660 | "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] | 1661 | str_supported(tp_features.bay_status), |
| 1662 | str_supported(tp_features.bay_eject), |
| 1663 | str_supported(tp_features.bay_status2), |
| 1664 | str_supported(tp_features.bay_eject2)); |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1665 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1666 | return (tp_features.bay_status || tp_features.bay_eject || |
| 1667 | tp_features.bay_status2 || tp_features.bay_eject2)? 0 : 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1670 | static void bay_notify(struct ibm_struct *ibm, u32 event) |
| 1671 | { |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1672 | acpi_bus_generate_event(ibm->acpi->device, event, 0); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1673 | } |
| 1674 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1675 | #define bay_occupied(b) (_sta(b##_handle) & 1) |
| 1676 | |
| 1677 | static int bay_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | { |
| 1679 | int len = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1680 | int occupied = bay_occupied(bay); |
| 1681 | int occupied2 = bay_occupied(bay2); |
| 1682 | int eject, eject2; |
| 1683 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1684 | len += sprintf(p + len, "status:\t\t%s\n", |
| 1685 | tp_features.bay_status ? |
| 1686 | (occupied ? "occupied" : "unoccupied") : |
| 1687 | "not supported"); |
| 1688 | if (tp_features.bay_status2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1689 | len += sprintf(p + len, "status2:\t%s\n", occupied2 ? |
| 1690 | "occupied" : "unoccupied"); |
| 1691 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1692 | eject = tp_features.bay_eject && occupied; |
| 1693 | eject2 = tp_features.bay_eject2 && occupied2; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1694 | |
| 1695 | if (eject && eject2) |
| 1696 | len += sprintf(p + len, "commands:\teject, eject2\n"); |
| 1697 | else if (eject) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1698 | len += sprintf(p + len, "commands:\teject\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1699 | else if (eject2) |
| 1700 | len += sprintf(p + len, "commands:\teject2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | |
| 1702 | return len; |
| 1703 | } |
| 1704 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1705 | static int bay_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1706 | { |
| 1707 | char *cmd; |
| 1708 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1709 | if (!tp_features.bay_eject && !tp_features.bay_eject2) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1710 | return -ENODEV; |
| 1711 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1712 | while ((cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1713 | if (tp_features.bay_eject && strlencmp(cmd, "eject") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1714 | if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1)) |
| 1715 | return -EIO; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 1716 | } else if (tp_features.bay_eject2 && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1717 | strlencmp(cmd, "eject2") == 0) { |
| 1718 | if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1719 | return -EIO; |
| 1720 | } else |
| 1721 | return -EINVAL; |
| 1722 | } |
| 1723 | |
| 1724 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1725 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1726 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1727 | static struct tp_acpi_drv_struct ibm_bay_acpidriver = { |
| 1728 | .notify = bay_notify, |
| 1729 | .handle = &bay_handle, |
| 1730 | .type = ACPI_SYSTEM_NOTIFY, |
| 1731 | }; |
| 1732 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1733 | static struct ibm_struct bay_driver_data = { |
| 1734 | .name = "bay", |
| 1735 | .read = bay_read, |
| 1736 | .write = bay_write, |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1737 | .acpi = &ibm_bay_acpidriver, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1738 | }; |
| 1739 | |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 1740 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1742 | /************************************************************************* |
| 1743 | * CMOS subdriver |
| 1744 | */ |
| 1745 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame^] | 1746 | /* sysfs cmos_command -------------------------------------------------- */ |
| 1747 | static ssize_t cmos_command_store(struct device *dev, |
| 1748 | struct device_attribute *attr, |
| 1749 | const char *buf, size_t count) |
| 1750 | { |
| 1751 | unsigned long cmos_cmd; |
| 1752 | int res; |
| 1753 | |
| 1754 | if (parse_strtoul(buf, 21, &cmos_cmd)) |
| 1755 | return -EINVAL; |
| 1756 | |
| 1757 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 1758 | return (res)? res : count; |
| 1759 | } |
| 1760 | |
| 1761 | static struct device_attribute dev_attr_cmos_command = |
| 1762 | __ATTR(cmos_command, S_IWUSR, NULL, cmos_command_store); |
| 1763 | |
| 1764 | /* --------------------------------------------------------------------- */ |
| 1765 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1766 | static int __init cmos_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1767 | { |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame^] | 1768 | int res; |
| 1769 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1770 | vdbg_printk(TPACPI_DBG_INIT, |
| 1771 | "initializing cmos commands subdriver\n"); |
| 1772 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1773 | IBM_ACPIHANDLE_INIT(cmos); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1774 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1775 | vdbg_printk(TPACPI_DBG_INIT, "cmos commands are %s\n", |
| 1776 | str_supported(cmos_handle != NULL)); |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame^] | 1777 | |
| 1778 | res = device_create_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 1779 | if (res) |
| 1780 | return res; |
| 1781 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1782 | return (cmos_handle)? 0 : 1; |
| 1783 | } |
| 1784 | |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame^] | 1785 | static void cmos_exit(void) |
| 1786 | { |
| 1787 | device_remove_file(&tpacpi_pdev->dev, &dev_attr_cmos_command); |
| 1788 | } |
| 1789 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1790 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1791 | { |
| 1792 | int len = 0; |
| 1793 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1794 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 1795 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1796 | if (!cmos_handle) |
| 1797 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1798 | else { |
| 1799 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1800 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1801 | } |
| 1802 | |
| 1803 | return len; |
| 1804 | } |
| 1805 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1806 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1807 | { |
| 1808 | char *cmd; |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 1809 | int cmos_cmd, res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
| 1811 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1812 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 1813 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | /* cmos_cmd set */ |
| 1815 | } else |
| 1816 | return -EINVAL; |
| 1817 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 1818 | res = issue_thinkpad_cmos_command(cmos_cmd); |
| 1819 | if (res) |
| 1820 | return res; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1824 | } |
| 1825 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1826 | static struct ibm_struct cmos_driver_data = { |
| 1827 | .name = "cmos", |
| 1828 | .read = cmos_read, |
| 1829 | .write = cmos_write, |
Henrique de Moraes Holschuh | b616004 | 2007-04-24 11:48:19 -0300 | [diff] [blame^] | 1830 | .exit = cmos_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1831 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1832 | |
| 1833 | /************************************************************************* |
| 1834 | * LED subdriver |
| 1835 | */ |
| 1836 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1837 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1838 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1839 | IBM_HANDLE(led, ec, "SLED", /* 570 */ |
| 1840 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 1841 | "LED", /* all others */ |
| 1842 | ); /* R30, R31 */ |
| 1843 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1844 | static int __init led_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1845 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1846 | vdbg_printk(TPACPI_DBG_INIT, "initializing LED subdriver\n"); |
| 1847 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1848 | IBM_ACPIHANDLE_INIT(led); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1849 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1850 | if (!led_handle) |
| 1851 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1852 | led_supported = TPACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1853 | else if (strlencmp(led_path, "SLED") == 0) |
| 1854 | /* 570 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1855 | led_supported = TPACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1856 | else if (strlencmp(led_path, "SYSL") == 0) |
| 1857 | /* 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] | 1858 | led_supported = TPACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1859 | else |
| 1860 | /* all others */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1861 | led_supported = TPACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1862 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1863 | vdbg_printk(TPACPI_DBG_INIT, "LED commands are %s, mode %d\n", |
| 1864 | str_supported(led_supported), led_supported); |
| 1865 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1866 | return (led_supported != TPACPI_LED_NONE)? 0 : 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1867 | } |
| 1868 | |
| 1869 | #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking")) |
| 1870 | |
| 1871 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | { |
| 1873 | int len = 0; |
| 1874 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1875 | if (!led_supported) { |
| 1876 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1877 | return len; |
| 1878 | } |
| 1879 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 1880 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1881 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1882 | /* 570 */ |
| 1883 | int i, status; |
| 1884 | for (i = 0; i < 8; i++) { |
| 1885 | if (!acpi_evalf(ec_handle, |
| 1886 | &status, "GLED", "dd", 1 << i)) |
| 1887 | return -EIO; |
| 1888 | len += sprintf(p + len, "%d:\t\t%s\n", |
| 1889 | i, led_status(status)); |
| 1890 | } |
| 1891 | } |
| 1892 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | len += sprintf(p + len, "commands:\t" |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1894 | "<led> on, <led> off, <led> blink (<led> is 0-7)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1895 | |
| 1896 | return len; |
| 1897 | } |
| 1898 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1899 | /* off, on, blink */ |
| 1900 | static const int led_sled_arg1[] = { 0, 1, 3 }; |
| 1901 | static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */ |
| 1902 | static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */ |
| 1903 | static const int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
| 1904 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1905 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1906 | { |
| 1907 | char *cmd; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1908 | int led, ind, ret; |
| 1909 | |
| 1910 | if (!led_supported) |
| 1911 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | |
| 1913 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1914 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1915 | return -EINVAL; |
| 1916 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1917 | if (strstr(cmd, "off")) { |
| 1918 | ind = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1919 | } else if (strstr(cmd, "on")) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1920 | ind = 1; |
| 1921 | } else if (strstr(cmd, "blink")) { |
| 1922 | ind = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1923 | } else |
| 1924 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1925 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1926 | if (led_supported == TPACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1927 | /* 570 */ |
| 1928 | led = 1 << led; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1930 | led, led_sled_arg1[ind])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | return -EIO; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1932 | } else if (led_supported == TPACPI_LED_OLD) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1933 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
| 1934 | led = 1 << led; |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1935 | ret = ec_write(TPACPI_LED_EC_HLMS, led); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1936 | if (ret >= 0) |
| 1937 | ret = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1938 | ec_write(TPACPI_LED_EC_HLBL, |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1939 | led * led_exp_hlbl[ind]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1940 | if (ret >= 0) |
| 1941 | ret = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 1942 | ec_write(TPACPI_LED_EC_HLCL, |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1943 | led * led_exp_hlcl[ind]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1944 | if (ret < 0) |
| 1945 | return ret; |
| 1946 | } else { |
| 1947 | /* all others */ |
| 1948 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 1949 | led, led_led_arg1[ind])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1951 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1952 | } |
| 1953 | |
| 1954 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1955 | } |
| 1956 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1957 | static struct ibm_struct led_driver_data = { |
| 1958 | .name = "led", |
| 1959 | .read = led_read, |
| 1960 | .write = led_write, |
| 1961 | }; |
| 1962 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 1963 | /************************************************************************* |
| 1964 | * Beep subdriver |
| 1965 | */ |
| 1966 | |
| 1967 | IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
| 1968 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 1969 | static int __init beep_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1970 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1971 | vdbg_printk(TPACPI_DBG_INIT, "initializing beep subdriver\n"); |
| 1972 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 1973 | IBM_ACPIHANDLE_INIT(beep); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1974 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 1975 | vdbg_printk(TPACPI_DBG_INIT, "beep is %s\n", |
| 1976 | str_supported(beep_handle != NULL)); |
| 1977 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 1978 | return (beep_handle)? 0 : 1; |
| 1979 | } |
| 1980 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1981 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1982 | { |
| 1983 | int len = 0; |
| 1984 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1985 | if (!beep_handle) |
| 1986 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1987 | else { |
| 1988 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 1989 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 1990 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | |
| 1992 | return len; |
| 1993 | } |
| 1994 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1995 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1996 | { |
| 1997 | char *cmd; |
| 1998 | int beep_cmd; |
| 1999 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2000 | if (!beep_handle) |
| 2001 | return -ENODEV; |
| 2002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2003 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2004 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 2005 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2006 | /* beep_cmd set */ |
| 2007 | } else |
| 2008 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2009 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2010 | return -EIO; |
| 2011 | } |
| 2012 | |
| 2013 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2014 | } |
| 2015 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2016 | static struct ibm_struct beep_driver_data = { |
| 2017 | .name = "beep", |
| 2018 | .read = beep_read, |
| 2019 | .write = beep_write, |
| 2020 | }; |
| 2021 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2022 | /************************************************************************* |
| 2023 | * Thermal subdriver |
| 2024 | */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2025 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2026 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2027 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 2028 | /* sysfs temp##_input -------------------------------------------------- */ |
| 2029 | |
| 2030 | static ssize_t thermal_temp_input_show(struct device *dev, |
| 2031 | struct device_attribute *attr, |
| 2032 | char *buf) |
| 2033 | { |
| 2034 | struct sensor_device_attribute *sensor_attr = |
| 2035 | to_sensor_dev_attr(attr); |
| 2036 | int idx = sensor_attr->index; |
| 2037 | s32 value; |
| 2038 | int res; |
| 2039 | |
| 2040 | res = thermal_get_sensor(idx, &value); |
| 2041 | if (res) |
| 2042 | return res; |
| 2043 | if (value == TP_EC_THERMAL_TMP_NA * 1000) |
| 2044 | return -ENXIO; |
| 2045 | |
| 2046 | return snprintf(buf, PAGE_SIZE, "%d\n", value); |
| 2047 | } |
| 2048 | |
| 2049 | #define THERMAL_SENSOR_ATTR_TEMP(_idxA, _idxB) \ |
| 2050 | SENSOR_ATTR(temp##_idxA##_input, S_IRUGO, thermal_temp_input_show, NULL, _idxB) |
| 2051 | |
| 2052 | static struct sensor_device_attribute sensor_dev_attr_thermal_temp_input[] = { |
| 2053 | THERMAL_SENSOR_ATTR_TEMP(1, 0), |
| 2054 | THERMAL_SENSOR_ATTR_TEMP(2, 1), |
| 2055 | THERMAL_SENSOR_ATTR_TEMP(3, 2), |
| 2056 | THERMAL_SENSOR_ATTR_TEMP(4, 3), |
| 2057 | THERMAL_SENSOR_ATTR_TEMP(5, 4), |
| 2058 | THERMAL_SENSOR_ATTR_TEMP(6, 5), |
| 2059 | THERMAL_SENSOR_ATTR_TEMP(7, 6), |
| 2060 | THERMAL_SENSOR_ATTR_TEMP(8, 7), |
| 2061 | THERMAL_SENSOR_ATTR_TEMP(9, 8), |
| 2062 | THERMAL_SENSOR_ATTR_TEMP(10, 9), |
| 2063 | THERMAL_SENSOR_ATTR_TEMP(11, 10), |
| 2064 | THERMAL_SENSOR_ATTR_TEMP(12, 11), |
| 2065 | THERMAL_SENSOR_ATTR_TEMP(13, 12), |
| 2066 | THERMAL_SENSOR_ATTR_TEMP(14, 13), |
| 2067 | THERMAL_SENSOR_ATTR_TEMP(15, 14), |
| 2068 | THERMAL_SENSOR_ATTR_TEMP(16, 15), |
| 2069 | }; |
| 2070 | |
| 2071 | #define THERMAL_ATTRS(X) \ |
| 2072 | &sensor_dev_attr_thermal_temp_input[X].dev_attr.attr |
| 2073 | |
| 2074 | static struct attribute *thermal_temp_input_attr[] = { |
| 2075 | THERMAL_ATTRS(8), |
| 2076 | THERMAL_ATTRS(9), |
| 2077 | THERMAL_ATTRS(10), |
| 2078 | THERMAL_ATTRS(11), |
| 2079 | THERMAL_ATTRS(12), |
| 2080 | THERMAL_ATTRS(13), |
| 2081 | THERMAL_ATTRS(14), |
| 2082 | THERMAL_ATTRS(15), |
| 2083 | THERMAL_ATTRS(0), |
| 2084 | THERMAL_ATTRS(1), |
| 2085 | THERMAL_ATTRS(2), |
| 2086 | THERMAL_ATTRS(3), |
| 2087 | THERMAL_ATTRS(4), |
| 2088 | THERMAL_ATTRS(5), |
| 2089 | THERMAL_ATTRS(6), |
| 2090 | THERMAL_ATTRS(7), |
| 2091 | NULL |
| 2092 | }; |
| 2093 | |
| 2094 | static const struct attribute_group thermal_temp_input16_group = { |
| 2095 | .attrs = thermal_temp_input_attr |
| 2096 | }; |
| 2097 | |
| 2098 | static const struct attribute_group thermal_temp_input8_group = { |
| 2099 | .attrs = &thermal_temp_input_attr[8] |
| 2100 | }; |
| 2101 | |
| 2102 | #undef THERMAL_SENSOR_ATTR_TEMP |
| 2103 | #undef THERMAL_ATTRS |
| 2104 | |
| 2105 | /* --------------------------------------------------------------------- */ |
| 2106 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2107 | static int __init thermal_init(struct ibm_init_struct *iibm) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2108 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2109 | u8 t, ta1, ta2; |
| 2110 | int i; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2111 | int acpi_tmp7; |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 2112 | int res; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2113 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2114 | vdbg_printk(TPACPI_DBG_INIT, "initializing thermal subdriver\n"); |
| 2115 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2116 | acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2117 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2118 | if (ibm_thinkpad_ec_found && experimental) { |
| 2119 | /* |
| 2120 | * Direct EC access mode: sensors at registers |
| 2121 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 2122 | * non-implemented, thermal sensors return 0x80 when |
| 2123 | * not available |
| 2124 | */ |
| 2125 | |
| 2126 | ta1 = ta2 = 0; |
| 2127 | for (i = 0; i < 8; i++) { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2128 | if (acpi_ec_read(TP_EC_THERMAL_TMP0 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2129 | ta1 |= t; |
| 2130 | } else { |
| 2131 | ta1 = 0; |
| 2132 | break; |
| 2133 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2134 | if (acpi_ec_read(TP_EC_THERMAL_TMP8 + i, &t)) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2135 | ta2 |= t; |
| 2136 | } else { |
| 2137 | ta1 = 0; |
| 2138 | break; |
| 2139 | } |
| 2140 | } |
| 2141 | if (ta1 == 0) { |
| 2142 | /* This is sheer paranoia, but we handle it anyway */ |
| 2143 | if (acpi_tmp7) { |
| 2144 | printk(IBM_ERR |
| 2145 | "ThinkPad ACPI EC access misbehaving, " |
| 2146 | "falling back to ACPI TMPx access mode\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2147 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2148 | } else { |
| 2149 | printk(IBM_ERR |
| 2150 | "ThinkPad ACPI EC access misbehaving, " |
| 2151 | "disabling thermal sensors access\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2152 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2153 | } |
| 2154 | } else { |
| 2155 | thermal_read_mode = |
| 2156 | (ta2 != 0) ? |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2157 | TPACPI_THERMAL_TPEC_16 : TPACPI_THERMAL_TPEC_8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2158 | } |
| 2159 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2160 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 2161 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2162 | thermal_read_mode = TPACPI_THERMAL_ACPI_UPDT; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2163 | } else { |
| 2164 | /* Standard ACPI TMPx access, max 8 sensors */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2165 | thermal_read_mode = TPACPI_THERMAL_ACPI_TMP07; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2166 | } |
| 2167 | } else { |
| 2168 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2169 | thermal_read_mode = TPACPI_THERMAL_NONE; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2170 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2171 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2172 | vdbg_printk(TPACPI_DBG_INIT, "thermal is %s, mode %d\n", |
| 2173 | str_supported(thermal_read_mode != TPACPI_THERMAL_NONE), |
| 2174 | thermal_read_mode); |
| 2175 | |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 2176 | switch(thermal_read_mode) { |
| 2177 | case TPACPI_THERMAL_TPEC_16: |
| 2178 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 2179 | &thermal_temp_input16_group); |
| 2180 | if (res) |
| 2181 | return res; |
| 2182 | break; |
| 2183 | case TPACPI_THERMAL_TPEC_8: |
| 2184 | case TPACPI_THERMAL_ACPI_TMP07: |
| 2185 | case TPACPI_THERMAL_ACPI_UPDT: |
| 2186 | res = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 2187 | &thermal_temp_input8_group); |
| 2188 | if (res) |
| 2189 | return res; |
| 2190 | break; |
| 2191 | case TPACPI_THERMAL_NONE: |
| 2192 | default: |
| 2193 | return 1; |
| 2194 | } |
| 2195 | |
| 2196 | return 0; |
| 2197 | } |
| 2198 | |
| 2199 | static void thermal_exit(void) |
| 2200 | { |
| 2201 | switch(thermal_read_mode) { |
| 2202 | case TPACPI_THERMAL_TPEC_16: |
| 2203 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 2204 | &thermal_temp_input16_group); |
| 2205 | break; |
| 2206 | case TPACPI_THERMAL_TPEC_8: |
| 2207 | case TPACPI_THERMAL_ACPI_TMP07: |
| 2208 | case TPACPI_THERMAL_ACPI_UPDT: |
| 2209 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, |
| 2210 | &thermal_temp_input16_group); |
| 2211 | break; |
| 2212 | case TPACPI_THERMAL_NONE: |
| 2213 | default: |
| 2214 | break; |
| 2215 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2216 | } |
| 2217 | |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2218 | /* idx is zero-based */ |
| 2219 | static int thermal_get_sensor(int idx, s32 *value) |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2220 | { |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2221 | int t; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2222 | s8 tmp; |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2223 | char tmpi[5]; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2224 | |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2225 | t = TP_EC_THERMAL_TMP0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2226 | |
| 2227 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2228 | #if TPACPI_MAX_THERMAL_SENSORS >= 16 |
| 2229 | case TPACPI_THERMAL_TPEC_16: |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2230 | if (idx >= 8 && idx <= 15) { |
| 2231 | t = TP_EC_THERMAL_TMP8; |
| 2232 | idx -= 8; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2233 | } |
| 2234 | /* fallthrough */ |
| 2235 | #endif |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2236 | case TPACPI_THERMAL_TPEC_8: |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2237 | if (idx <= 7) { |
| 2238 | if (!acpi_ec_read(t + idx, &tmp)) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2239 | return -EIO; |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2240 | *value = tmp * 1000; |
| 2241 | return 0; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2242 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2243 | break; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2244 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2245 | case TPACPI_THERMAL_ACPI_UPDT: |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2246 | if (idx <= 7) { |
| 2247 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
| 2248 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 2249 | return -EIO; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2250 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 2251 | return -EIO; |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2252 | *value = (t - 2732) * 100; |
| 2253 | return 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2254 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2255 | break; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2256 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2257 | case TPACPI_THERMAL_ACPI_TMP07: |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2258 | if (idx <= 7) { |
| 2259 | snprintf(tmpi, sizeof(tmpi), "TMP%c", '0' + idx); |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2260 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 2261 | return -EIO; |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2262 | *value = t * 1000; |
| 2263 | return 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2264 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2265 | break; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2266 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2267 | case TPACPI_THERMAL_NONE: |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2268 | default: |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2269 | return -ENOSYS; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2270 | } |
Henrique de Moraes Holschuh | 04cc862 | 2007-04-21 11:08:43 -0300 | [diff] [blame] | 2271 | |
| 2272 | return -EINVAL; |
| 2273 | } |
| 2274 | |
| 2275 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 2276 | { |
| 2277 | int res, i; |
| 2278 | int n; |
| 2279 | |
| 2280 | n = 8; |
| 2281 | i = 0; |
| 2282 | |
| 2283 | if (!s) |
| 2284 | return -EINVAL; |
| 2285 | |
| 2286 | if (thermal_read_mode == TPACPI_THERMAL_TPEC_16) |
| 2287 | n = 16; |
| 2288 | |
| 2289 | for(i = 0 ; i < n; i++) { |
| 2290 | res = thermal_get_sensor(i, &s->temp[i]); |
| 2291 | if (res) |
| 2292 | return res; |
| 2293 | } |
| 2294 | |
| 2295 | return n; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2296 | } |
| 2297 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2298 | static int thermal_read(char *p) |
| 2299 | { |
| 2300 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2301 | int n, i; |
| 2302 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2303 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2304 | n = thermal_get_sensors(&t); |
| 2305 | if (unlikely(n < 0)) |
| 2306 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2307 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2308 | len += sprintf(p + len, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2309 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2310 | if (n > 0) { |
| 2311 | for (i = 0; i < (n - 1); i++) |
| 2312 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 2313 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 2314 | } else |
| 2315 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2316 | |
| 2317 | return len; |
| 2318 | } |
| 2319 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2320 | static struct ibm_struct thermal_driver_data = { |
| 2321 | .name = "thermal", |
| 2322 | .read = thermal_read, |
Henrique de Moraes Holschuh | 2c37aa4 | 2007-04-24 11:48:16 -0300 | [diff] [blame] | 2323 | .exit = thermal_exit, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2324 | }; |
| 2325 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2326 | /************************************************************************* |
| 2327 | * EC Dump subdriver |
| 2328 | */ |
| 2329 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2330 | static u8 ecdump_regs[256]; |
| 2331 | |
| 2332 | static int ecdump_read(char *p) |
| 2333 | { |
| 2334 | int len = 0; |
| 2335 | int i, j; |
| 2336 | u8 v; |
| 2337 | |
| 2338 | len += sprintf(p + len, "EC " |
| 2339 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 2340 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 2341 | for (i = 0; i < 256; i += 16) { |
| 2342 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 2343 | for (j = 0; j < 16; j++) { |
| 2344 | if (!acpi_ec_read(i + j, &v)) |
| 2345 | break; |
| 2346 | if (v != ecdump_regs[i + j]) |
| 2347 | len += sprintf(p + len, " *%02x", v); |
| 2348 | else |
| 2349 | len += sprintf(p + len, " %02x", v); |
| 2350 | ecdump_regs[i + j] = v; |
| 2351 | } |
| 2352 | len += sprintf(p + len, "\n"); |
| 2353 | if (j != 16) |
| 2354 | break; |
| 2355 | } |
| 2356 | |
| 2357 | /* These are way too dangerous to advertise openly... */ |
| 2358 | #if 0 |
| 2359 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 2360 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 2361 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 2362 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 2363 | #endif |
| 2364 | return len; |
| 2365 | } |
| 2366 | |
| 2367 | static int ecdump_write(char *buf) |
| 2368 | { |
| 2369 | char *cmd; |
| 2370 | int i, v; |
| 2371 | |
| 2372 | while ((cmd = next_cmd(&buf))) { |
| 2373 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 2374 | /* i and v set */ |
| 2375 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 2376 | /* i and v set */ |
| 2377 | } else |
| 2378 | return -EINVAL; |
| 2379 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 2380 | if (!acpi_ec_write(i, v)) |
| 2381 | return -EIO; |
| 2382 | } else |
| 2383 | return -EINVAL; |
| 2384 | } |
| 2385 | |
| 2386 | return 0; |
| 2387 | } |
| 2388 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2389 | static struct ibm_struct ecdump_driver_data = { |
| 2390 | .name = "ecdump", |
| 2391 | .read = ecdump_read, |
| 2392 | .write = ecdump_write, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 2393 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2394 | }; |
| 2395 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2396 | /************************************************************************* |
| 2397 | * Backlight/brightness subdriver |
| 2398 | */ |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 2399 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2400 | static struct backlight_device *ibm_backlight_device = NULL; |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 2401 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 2402 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 2403 | .get_brightness = brightness_get, |
| 2404 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 2405 | }; |
| 2406 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2407 | static int __init brightness_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 2408 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 2409 | int b; |
| 2410 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2411 | vdbg_printk(TPACPI_DBG_INIT, "initializing brightness subdriver\n"); |
| 2412 | |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 2413 | b = brightness_get(NULL); |
| 2414 | if (b < 0) |
| 2415 | return b; |
| 2416 | |
Yu Luming | 519ab5f | 2006-12-19 12:56:15 -0800 | [diff] [blame] | 2417 | ibm_backlight_device = backlight_device_register("ibm", NULL, NULL, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 2418 | &ibm_backlight_data); |
| 2419 | if (IS_ERR(ibm_backlight_device)) { |
| 2420 | printk(IBM_ERR "Could not register backlight device\n"); |
| 2421 | return PTR_ERR(ibm_backlight_device); |
| 2422 | } |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2423 | vdbg_printk(TPACPI_DBG_INIT, "brightness is supported\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 2424 | |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 2425 | ibm_backlight_device->props.max_brightness = 7; |
| 2426 | ibm_backlight_device->props.brightness = b; |
| 2427 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 2428 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 2429 | return 0; |
| 2430 | } |
| 2431 | |
| 2432 | static void brightness_exit(void) |
| 2433 | { |
| 2434 | if (ibm_backlight_device) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2435 | vdbg_printk(TPACPI_DBG_EXIT, |
| 2436 | "calling backlight_device_unregister()\n"); |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 2437 | backlight_device_unregister(ibm_backlight_device); |
| 2438 | ibm_backlight_device = NULL; |
| 2439 | } |
| 2440 | } |
| 2441 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2442 | static int brightness_update_status(struct backlight_device *bd) |
| 2443 | { |
| 2444 | return brightness_set( |
| 2445 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 2446 | bd->props.power == FB_BLANK_UNBLANK) ? |
| 2447 | bd->props.brightness : 0); |
| 2448 | } |
| 2449 | |
| 2450 | static int brightness_get(struct backlight_device *bd) |
| 2451 | { |
| 2452 | u8 level; |
| 2453 | if (!acpi_ec_read(brightness_offset, &level)) |
| 2454 | return -EIO; |
| 2455 | |
| 2456 | level &= 0x7; |
| 2457 | |
| 2458 | return level; |
| 2459 | } |
| 2460 | |
| 2461 | static int brightness_set(int value) |
| 2462 | { |
| 2463 | int cmos_cmd, inc, i; |
| 2464 | int current_value = brightness_get(NULL); |
| 2465 | |
| 2466 | value &= 7; |
| 2467 | |
| 2468 | cmos_cmd = value > current_value ? TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN; |
| 2469 | inc = value > current_value ? 1 : -1; |
| 2470 | for (i = current_value; i != value; i += inc) { |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 2471 | if (issue_thinkpad_cmos_command(cmos_cmd)) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2472 | return -EIO; |
| 2473 | if (!acpi_ec_write(brightness_offset, i + inc)) |
| 2474 | return -EIO; |
| 2475 | } |
| 2476 | |
| 2477 | return 0; |
| 2478 | } |
| 2479 | |
| 2480 | static int brightness_read(char *p) |
| 2481 | { |
| 2482 | int len = 0; |
| 2483 | int level; |
| 2484 | |
| 2485 | if ((level = brightness_get(NULL)) < 0) { |
| 2486 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 2487 | } else { |
| 2488 | len += sprintf(p + len, "level:\t\t%d\n", level & 0x7); |
| 2489 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 2490 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 2491 | " (<level> is 0-7)\n"); |
| 2492 | } |
| 2493 | |
| 2494 | return len; |
| 2495 | } |
| 2496 | |
| 2497 | static int brightness_write(char *buf) |
| 2498 | { |
| 2499 | int level; |
| 2500 | int new_level; |
| 2501 | char *cmd; |
| 2502 | |
| 2503 | while ((cmd = next_cmd(&buf))) { |
| 2504 | if ((level = brightness_get(NULL)) < 0) |
| 2505 | return level; |
| 2506 | level &= 7; |
| 2507 | |
| 2508 | if (strlencmp(cmd, "up") == 0) { |
| 2509 | new_level = level == 7 ? 7 : level + 1; |
| 2510 | } else if (strlencmp(cmd, "down") == 0) { |
| 2511 | new_level = level == 0 ? 0 : level - 1; |
| 2512 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 2513 | new_level >= 0 && new_level <= 7) { |
| 2514 | /* new_level set */ |
| 2515 | } else |
| 2516 | return -EINVAL; |
| 2517 | |
| 2518 | brightness_set(new_level); |
| 2519 | } |
| 2520 | |
| 2521 | return 0; |
| 2522 | } |
| 2523 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2524 | static struct ibm_struct brightness_driver_data = { |
| 2525 | .name = "brightness", |
| 2526 | .read = brightness_read, |
| 2527 | .write = brightness_write, |
| 2528 | .exit = brightness_exit, |
| 2529 | }; |
| 2530 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2531 | /************************************************************************* |
| 2532 | * Volume subdriver |
| 2533 | */ |
| 2534 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2535 | static int volume_read(char *p) |
| 2536 | { |
| 2537 | int len = 0; |
| 2538 | u8 level; |
| 2539 | |
| 2540 | if (!acpi_ec_read(volume_offset, &level)) { |
| 2541 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 2542 | } else { |
| 2543 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); |
| 2544 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); |
| 2545 | len += sprintf(p + len, "commands:\tup, down, mute\n"); |
| 2546 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 2547 | " (<level> is 0-15)\n"); |
| 2548 | } |
| 2549 | |
| 2550 | return len; |
| 2551 | } |
| 2552 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2553 | static int volume_write(char *buf) |
| 2554 | { |
| 2555 | int cmos_cmd, inc, i; |
| 2556 | u8 level, mute; |
| 2557 | int new_level, new_mute; |
| 2558 | char *cmd; |
| 2559 | |
| 2560 | while ((cmd = next_cmd(&buf))) { |
| 2561 | if (!acpi_ec_read(volume_offset, &level)) |
| 2562 | return -EIO; |
| 2563 | new_mute = mute = level & 0x40; |
| 2564 | new_level = level = level & 0xf; |
| 2565 | |
| 2566 | if (strlencmp(cmd, "up") == 0) { |
| 2567 | if (mute) |
| 2568 | new_mute = 0; |
| 2569 | else |
| 2570 | new_level = level == 15 ? 15 : level + 1; |
| 2571 | } else if (strlencmp(cmd, "down") == 0) { |
| 2572 | if (mute) |
| 2573 | new_mute = 0; |
| 2574 | else |
| 2575 | new_level = level == 0 ? 0 : level - 1; |
| 2576 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 2577 | new_level >= 0 && new_level <= 15) { |
| 2578 | /* new_level set */ |
| 2579 | } else if (strlencmp(cmd, "mute") == 0) { |
| 2580 | new_mute = 0x40; |
| 2581 | } else |
| 2582 | return -EINVAL; |
| 2583 | |
| 2584 | if (new_level != level) { /* mute doesn't change */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2585 | 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] | 2586 | inc = new_level > level ? 1 : -1; |
| 2587 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 2588 | if (mute && (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2589 | !acpi_ec_write(volume_offset, level))) |
| 2590 | return -EIO; |
| 2591 | |
| 2592 | for (i = level; i != new_level; i += inc) |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 2593 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2594 | !acpi_ec_write(volume_offset, i + inc)) |
| 2595 | return -EIO; |
| 2596 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 2597 | if (mute && (issue_thinkpad_cmos_command(TP_CMOS_VOLUME_MUTE) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2598 | !acpi_ec_write(volume_offset, |
| 2599 | new_level + mute))) |
| 2600 | return -EIO; |
| 2601 | } |
| 2602 | |
| 2603 | if (new_mute != mute) { /* level doesn't change */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2604 | cmos_cmd = new_mute ? TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2605 | |
Henrique de Moraes Holschuh | c9bea99 | 2007-04-21 11:08:42 -0300 | [diff] [blame] | 2606 | if (issue_thinkpad_cmos_command(cmos_cmd) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2607 | !acpi_ec_write(volume_offset, level + new_mute)) |
| 2608 | return -EIO; |
| 2609 | } |
| 2610 | } |
| 2611 | |
| 2612 | return 0; |
| 2613 | } |
| 2614 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2615 | static struct ibm_struct volume_driver_data = { |
| 2616 | .name = "volume", |
| 2617 | .read = volume_read, |
| 2618 | .write = volume_write, |
| 2619 | }; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2620 | |
| 2621 | /************************************************************************* |
| 2622 | * Fan subdriver |
| 2623 | */ |
| 2624 | |
| 2625 | /* |
| 2626 | * FAN ACCESS MODES |
| 2627 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2628 | * TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2629 | * ACPI GFAN method: returns fan level |
| 2630 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2631 | * see TPACPI_FAN_WR_ACPI_SFAN |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 2632 | * EC 0x2f (HFSP) not available if GFAN exists |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2633 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2634 | * TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2635 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 2636 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 2637 | * EC 0x2f (HFSP) might be available *for reading*, but do not use |
| 2638 | * it for writing. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2639 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2640 | * TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 2641 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode |
| 2642 | * Supported on almost all ThinkPads |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2643 | * |
| 2644 | * Fan speed changes of any sort (including those caused by the |
| 2645 | * disengaged mode) are usually done slowly by the firmware as the |
| 2646 | * maximum ammount of fan duty cycle change per second seems to be |
| 2647 | * limited. |
| 2648 | * |
| 2649 | * Reading is not available if GFAN exists. |
| 2650 | * Writing is not available if SFAN exists. |
| 2651 | * |
| 2652 | * Bits |
| 2653 | * 7 automatic mode engaged; |
| 2654 | * (default operation mode of the ThinkPad) |
| 2655 | * fan level is ignored in this mode. |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 2656 | * 6 full speed mode (takes precedence over bit 7); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2657 | * not available on all thinkpads. May disable |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 2658 | * the tachometer while the fan controller ramps up |
| 2659 | * the speed (which can take up to a few *minutes*). |
| 2660 | * Speeds up fan to 100% duty-cycle, which is far above |
| 2661 | * the standard RPM levels. It is not impossible that |
| 2662 | * it could cause hardware damage. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2663 | * 5-3 unused in some models. Extra bits for fan level |
| 2664 | * in others, but still useless as all values above |
| 2665 | * 7 map to the same speed as level 7 in these models. |
| 2666 | * 2-0 fan level (0..7 usually) |
| 2667 | * 0x00 = stop |
| 2668 | * 0x07 = max (set when temperatures critical) |
| 2669 | * Some ThinkPads may have other levels, see |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2670 | * TPACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2671 | * |
| 2672 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 2673 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 2674 | * does so, its initial value is meaningless (0x07). |
| 2675 | * |
| 2676 | * For firmware bugs, refer to: |
| 2677 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 2678 | * |
| 2679 | * ---- |
| 2680 | * |
| 2681 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 2682 | * Main fan tachometer reading (in RPM) |
| 2683 | * |
| 2684 | * This register is present on all ThinkPads with a new-style EC, and |
| 2685 | * it is known not to be present on the A21m/e, and T22, as there is |
| 2686 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 2687 | * ThinkPads from this same time period (and earlier) probably lack the |
| 2688 | * tachometer as well. |
| 2689 | * |
| 2690 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare |
| 2691 | * was never fixed by IBM to report the EC firmware version string |
| 2692 | * probably support the tachometer (like the early X models), so |
| 2693 | * detecting it is quite hard. We need more data to know for sure. |
| 2694 | * |
| 2695 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 2696 | * might result. |
| 2697 | * |
Henrique de Moraes Holschuh | f51d1a3 | 2007-04-21 11:08:29 -0300 | [diff] [blame] | 2698 | * FIRMWARE BUG: may go stale while the EC is switching to full speed |
| 2699 | * mode. |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2700 | * |
| 2701 | * For firmware bugs, refer to: |
| 2702 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 2703 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2704 | * TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2705 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 2706 | * |
| 2707 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 2708 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 2709 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 2710 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 2711 | * |
| 2712 | * The speeds are stored on handles |
| 2713 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 2714 | * |
| 2715 | * There are three default speed sets, acessible as handles: |
| 2716 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 2717 | * |
| 2718 | * ACPI DSDT switches which set is in use depending on various |
| 2719 | * factors. |
| 2720 | * |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2721 | * 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] | 2722 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 2723 | * but the ACPI tables just mention level 7. |
| 2724 | */ |
| 2725 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2726 | static enum fan_status_access_mode fan_status_access_mode; |
| 2727 | static enum fan_control_access_mode fan_control_access_mode; |
| 2728 | static enum fan_control_commands fan_control_commands; |
| 2729 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2730 | static u8 fan_control_initial_status; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 2731 | static u8 fan_control_desired_level; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2732 | |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 2733 | static void fan_watchdog_fire(struct work_struct *ignored); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2734 | static int fan_watchdog_maxinterval; |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 2735 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2736 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 2737 | IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
| 2738 | IBM_HANDLE(gfan, ec, "GFAN", /* 570 */ |
| 2739 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 2740 | ); /* all others */ |
| 2741 | IBM_HANDLE(sfan, ec, "SFAN", /* 570 */ |
| 2742 | "JFNS", /* 770x-JL */ |
| 2743 | ); /* all others */ |
| 2744 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 2745 | /* |
| 2746 | * SYSFS fan layout: hwmon compatible (device) |
| 2747 | * |
| 2748 | * pwm*_enable: |
| 2749 | * 0: "disengaged" mode |
| 2750 | * 1: manual mode |
| 2751 | * 2: native EC "auto" mode (recommended, hardware default) |
| 2752 | * |
| 2753 | * pwm*: set speed in manual mode, ignored otherwise. |
| 2754 | * 0 is level 0; 255 is level 7. Intermediate points done with linear |
| 2755 | * interpolation. |
| 2756 | * |
| 2757 | * fan*_input: tachometer reading, RPM |
| 2758 | * |
| 2759 | * |
| 2760 | * SYSFS fan layout: extensions |
| 2761 | * |
| 2762 | * fan_watchdog (driver): |
| 2763 | * fan watchdog interval in seconds, 0 disables (default), max 120 |
| 2764 | */ |
| 2765 | |
| 2766 | /* sysfs fan pwm1_enable ----------------------------------------------- */ |
| 2767 | static ssize_t fan_pwm1_enable_show(struct device *dev, |
| 2768 | struct device_attribute *attr, |
| 2769 | char *buf) |
| 2770 | { |
| 2771 | int res, mode; |
| 2772 | u8 status; |
| 2773 | |
| 2774 | res = fan_get_status_safe(&status); |
| 2775 | if (res) |
| 2776 | return res; |
| 2777 | |
| 2778 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 2779 | if (status != fan_control_initial_status) { |
| 2780 | tp_features.fan_ctrl_status_undef = 0; |
| 2781 | } else { |
| 2782 | /* Return most likely status. In fact, it |
| 2783 | * might be the only possible status */ |
| 2784 | status = TP_EC_FAN_AUTO; |
| 2785 | } |
| 2786 | } |
| 2787 | |
| 2788 | if (status & TP_EC_FAN_FULLSPEED) { |
| 2789 | mode = 0; |
| 2790 | } else if (status & TP_EC_FAN_AUTO) { |
| 2791 | mode = 2; |
| 2792 | } else |
| 2793 | mode = 1; |
| 2794 | |
| 2795 | return snprintf(buf, PAGE_SIZE, "%d\n", mode); |
| 2796 | } |
| 2797 | |
| 2798 | static ssize_t fan_pwm1_enable_store(struct device *dev, |
| 2799 | struct device_attribute *attr, |
| 2800 | const char *buf, size_t count) |
| 2801 | { |
| 2802 | unsigned long t; |
| 2803 | int res, level; |
| 2804 | |
| 2805 | if (parse_strtoul(buf, 2, &t)) |
| 2806 | return -EINVAL; |
| 2807 | |
| 2808 | switch (t) { |
| 2809 | case 0: |
| 2810 | level = TP_EC_FAN_FULLSPEED; |
| 2811 | break; |
| 2812 | case 1: |
| 2813 | level = TPACPI_FAN_LAST_LEVEL; |
| 2814 | break; |
| 2815 | case 2: |
| 2816 | level = TP_EC_FAN_AUTO; |
| 2817 | break; |
| 2818 | case 3: |
| 2819 | /* reserved for software-controlled auto mode */ |
| 2820 | return -ENOSYS; |
| 2821 | default: |
| 2822 | return -EINVAL; |
| 2823 | } |
| 2824 | |
| 2825 | res = fan_set_level_safe(level); |
| 2826 | if (res < 0) |
| 2827 | return res; |
| 2828 | |
| 2829 | fan_watchdog_reset(); |
| 2830 | |
| 2831 | return count; |
| 2832 | } |
| 2833 | |
| 2834 | static struct device_attribute dev_attr_fan_pwm1_enable = |
| 2835 | __ATTR(pwm1_enable, S_IWUSR | S_IRUGO, |
| 2836 | fan_pwm1_enable_show, fan_pwm1_enable_store); |
| 2837 | |
| 2838 | /* sysfs fan pwm1 ------------------------------------------------------ */ |
| 2839 | static ssize_t fan_pwm1_show(struct device *dev, |
| 2840 | struct device_attribute *attr, |
| 2841 | char *buf) |
| 2842 | { |
| 2843 | int res; |
| 2844 | u8 status; |
| 2845 | |
| 2846 | res = fan_get_status_safe(&status); |
| 2847 | if (res) |
| 2848 | return res; |
| 2849 | |
| 2850 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
| 2851 | if (status != fan_control_initial_status) { |
| 2852 | tp_features.fan_ctrl_status_undef = 0; |
| 2853 | } else { |
| 2854 | status = TP_EC_FAN_AUTO; |
| 2855 | } |
| 2856 | } |
| 2857 | |
| 2858 | if ((status & |
| 2859 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) != 0) |
| 2860 | status = fan_control_desired_level; |
| 2861 | |
| 2862 | if (status > 7) |
| 2863 | status = 7; |
| 2864 | |
| 2865 | return snprintf(buf, PAGE_SIZE, "%u\n", (status * 255) / 7); |
| 2866 | } |
| 2867 | |
| 2868 | static ssize_t fan_pwm1_store(struct device *dev, |
| 2869 | struct device_attribute *attr, |
| 2870 | const char *buf, size_t count) |
| 2871 | { |
| 2872 | unsigned long s; |
| 2873 | int rc; |
| 2874 | u8 status, newlevel; |
| 2875 | |
| 2876 | if (parse_strtoul(buf, 255, &s)) |
| 2877 | return -EINVAL; |
| 2878 | |
| 2879 | /* scale down from 0-255 to 0-7 */ |
| 2880 | newlevel = (s >> 5) & 0x07; |
| 2881 | |
| 2882 | rc = mutex_lock_interruptible(&fan_mutex); |
| 2883 | if (rc < 0) |
| 2884 | return rc; |
| 2885 | |
| 2886 | rc = fan_get_status(&status); |
| 2887 | if (!rc && (status & |
| 2888 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 2889 | rc = fan_set_level(newlevel); |
| 2890 | if (!rc) |
| 2891 | fan_update_desired_level(newlevel); |
| 2892 | fan_watchdog_reset(); |
| 2893 | } |
| 2894 | |
| 2895 | mutex_unlock(&fan_mutex); |
| 2896 | return (rc)? rc : count; |
| 2897 | } |
| 2898 | |
| 2899 | static struct device_attribute dev_attr_fan_pwm1 = |
| 2900 | __ATTR(pwm1, S_IWUSR | S_IRUGO, |
| 2901 | fan_pwm1_show, fan_pwm1_store); |
| 2902 | |
| 2903 | /* sysfs fan fan1_input ------------------------------------------------ */ |
| 2904 | static ssize_t fan_fan1_input_show(struct device *dev, |
| 2905 | struct device_attribute *attr, |
| 2906 | char *buf) |
| 2907 | { |
| 2908 | int res; |
| 2909 | unsigned int speed; |
| 2910 | |
| 2911 | res = fan_get_speed(&speed); |
| 2912 | if (res < 0) |
| 2913 | return res; |
| 2914 | |
| 2915 | return snprintf(buf, PAGE_SIZE, "%u\n", speed); |
| 2916 | } |
| 2917 | |
| 2918 | static struct device_attribute dev_attr_fan_fan1_input = |
| 2919 | __ATTR(fan1_input, S_IRUGO, |
| 2920 | fan_fan1_input_show, NULL); |
| 2921 | |
| 2922 | /* sysfs fan fan_watchdog (driver) ------------------------------------- */ |
| 2923 | static ssize_t fan_fan_watchdog_show(struct device_driver *drv, |
| 2924 | char *buf) |
| 2925 | { |
| 2926 | return snprintf(buf, PAGE_SIZE, "%u\n", fan_watchdog_maxinterval); |
| 2927 | } |
| 2928 | |
| 2929 | static ssize_t fan_fan_watchdog_store(struct device_driver *drv, |
| 2930 | const char *buf, size_t count) |
| 2931 | { |
| 2932 | unsigned long t; |
| 2933 | |
| 2934 | if (parse_strtoul(buf, 120, &t)) |
| 2935 | return -EINVAL; |
| 2936 | |
| 2937 | fan_watchdog_maxinterval = t; |
| 2938 | fan_watchdog_reset(); |
| 2939 | |
| 2940 | return count; |
| 2941 | } |
| 2942 | |
| 2943 | static DRIVER_ATTR(fan_watchdog, S_IWUSR | S_IRUGO, |
| 2944 | fan_fan_watchdog_show, fan_fan_watchdog_store); |
| 2945 | |
| 2946 | /* --------------------------------------------------------------------- */ |
| 2947 | static struct attribute *fan_attributes[] = { |
| 2948 | &dev_attr_fan_pwm1_enable.attr, &dev_attr_fan_pwm1.attr, |
| 2949 | &dev_attr_fan_fan1_input.attr, |
| 2950 | NULL |
| 2951 | }; |
| 2952 | |
| 2953 | static const struct attribute_group fan_attr_group = { |
| 2954 | .attrs = fan_attributes, |
| 2955 | }; |
| 2956 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 2957 | static int __init fan_init(struct ibm_init_struct *iibm) |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2958 | { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 2959 | int rc; |
| 2960 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 2961 | vdbg_printk(TPACPI_DBG_INIT, "initializing fan subdriver\n"); |
| 2962 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 2963 | mutex_init(&fan_mutex); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2964 | fan_status_access_mode = TPACPI_FAN_NONE; |
| 2965 | fan_control_access_mode = TPACPI_FAN_WR_NONE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2966 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2967 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 2968 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 2969 | fan_control_desired_level = 7; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2970 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 2971 | IBM_ACPIHANDLE_INIT(fans); |
| 2972 | IBM_ACPIHANDLE_INIT(gfan); |
| 2973 | IBM_ACPIHANDLE_INIT(sfan); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 2974 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2975 | if (gfan_handle) { |
| 2976 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2977 | fan_status_access_mode = TPACPI_FAN_RD_ACPI_GFAN; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2978 | } else { |
| 2979 | /* all other ThinkPads: note that even old-style |
| 2980 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2981 | if (likely(acpi_ec_read(fan_status_offset, |
| 2982 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 2983 | fan_status_access_mode = TPACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2984 | |
| 2985 | /* In some ThinkPads, neither the EC nor the ACPI |
| 2986 | * DSDT initialize the fan status, and it ends up |
| 2987 | * being set to 0x07 when it *could* be either |
| 2988 | * 0x07 or 0x80. |
| 2989 | * |
| 2990 | * Enable for TP-1Y (T43), TP-78 (R51e), |
| 2991 | * TP-76 (R52), TP-70 (T43, R52), which are known |
| 2992 | * to be buggy. */ |
| 2993 | if (fan_control_initial_status == 0x07 && |
| 2994 | ibm_thinkpad_ec_found && |
| 2995 | ((ibm_thinkpad_ec_found[0] == '1' && |
| 2996 | ibm_thinkpad_ec_found[1] == 'Y') || |
| 2997 | (ibm_thinkpad_ec_found[0] == '7' && |
| 2998 | (ibm_thinkpad_ec_found[1] == '6' || |
| 2999 | ibm_thinkpad_ec_found[1] == '8' || |
| 3000 | ibm_thinkpad_ec_found[1] == '0')) |
| 3001 | )) { |
| 3002 | printk(IBM_NOTICE |
| 3003 | "fan_init: initial fan status is " |
| 3004 | "unknown, assuming it is in auto " |
| 3005 | "mode\n"); |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3006 | tp_features.fan_ctrl_status_undef = 1; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 3007 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 3008 | } else { |
| 3009 | printk(IBM_ERR |
| 3010 | "ThinkPad ACPI EC access misbehaving, " |
| 3011 | "fan status and control unavailable\n"); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3012 | return 1; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 3013 | } |
| 3014 | } |
| 3015 | |
| 3016 | if (sfan_handle) { |
| 3017 | /* 570, 770x-JL */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3018 | fan_control_access_mode = TPACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 3019 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3020 | TPACPI_FAN_CMD_LEVEL | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 3021 | } else { |
| 3022 | if (!gfan_handle) { |
| 3023 | /* gfan without sfan means no fan control */ |
| 3024 | /* all other models implement TP EC 0x2f control */ |
| 3025 | |
| 3026 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3027 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 3028 | fan_control_access_mode = |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3029 | TPACPI_FAN_WR_ACPI_FANS; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 3030 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3031 | TPACPI_FAN_CMD_SPEED | |
| 3032 | TPACPI_FAN_CMD_LEVEL | |
| 3033 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 3034 | } else { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3035 | fan_control_access_mode = TPACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 3036 | fan_control_commands |= |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3037 | TPACPI_FAN_CMD_LEVEL | |
| 3038 | TPACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 3039 | } |
| 3040 | } |
| 3041 | } |
| 3042 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3043 | vdbg_printk(TPACPI_DBG_INIT, "fan is %s, modes %d, %d\n", |
| 3044 | str_supported(fan_status_access_mode != TPACPI_FAN_NONE || |
| 3045 | fan_control_access_mode != TPACPI_FAN_WR_NONE), |
| 3046 | fan_status_access_mode, fan_control_access_mode); |
| 3047 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3048 | /* update fan_control_desired_level */ |
| 3049 | if (fan_status_access_mode != TPACPI_FAN_NONE) |
| 3050 | fan_get_status_safe(NULL); |
| 3051 | |
| 3052 | if (fan_status_access_mode != TPACPI_FAN_NONE || |
| 3053 | fan_control_access_mode != TPACPI_FAN_WR_NONE) { |
| 3054 | rc = sysfs_create_group(&tpacpi_pdev->dev.kobj, |
| 3055 | &fan_attr_group); |
| 3056 | if (!(rc < 0)) |
| 3057 | rc = driver_create_file(&tpacpi_pdriver.driver, |
| 3058 | &driver_attr_fan_watchdog); |
| 3059 | if (rc < 0) |
| 3060 | return rc; |
| 3061 | return 0; |
| 3062 | } else |
| 3063 | return 1; |
| 3064 | } |
| 3065 | |
| 3066 | /* |
| 3067 | * Call with fan_mutex held |
| 3068 | */ |
| 3069 | static void fan_update_desired_level(u8 status) |
| 3070 | { |
| 3071 | if ((status & |
| 3072 | (TP_EC_FAN_AUTO | TP_EC_FAN_FULLSPEED)) == 0) { |
| 3073 | if (status > 7) |
| 3074 | fan_control_desired_level = 7; |
| 3075 | else |
| 3076 | fan_control_desired_level = status; |
| 3077 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 3078 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3079 | |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 3080 | static int fan_get_status(u8 *status) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3081 | { |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 3082 | u8 s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3083 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3084 | /* TODO: |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3085 | * Add TPACPI_FAN_RD_ACPI_FANS ? */ |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3086 | |
Henrique de Moraes Holschuh | 3ef8a60 | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 3087 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3088 | case TPACPI_FAN_RD_ACPI_GFAN: |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3089 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 3090 | |
| 3091 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3092 | return -EIO; |
| 3093 | |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 3094 | if (likely(status)) |
| 3095 | *status = s & 0x07; |
| 3096 | |
| 3097 | break; |
| 3098 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3099 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 3100 | /* all except 570, 600e/x, 770e, 770x */ |
| 3101 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 3102 | return -EIO; |
| 3103 | |
| 3104 | if (likely(status)) |
| 3105 | *status = s; |
| 3106 | |
| 3107 | break; |
| 3108 | |
| 3109 | default: |
| 3110 | return -ENXIO; |
| 3111 | } |
| 3112 | |
| 3113 | return 0; |
| 3114 | } |
| 3115 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3116 | static int fan_get_status_safe(u8 *status) |
| 3117 | { |
| 3118 | int rc; |
| 3119 | u8 s; |
| 3120 | |
| 3121 | rc = mutex_lock_interruptible(&fan_mutex); |
| 3122 | if (rc < 0) |
| 3123 | return rc; |
| 3124 | rc = fan_get_status(&s); |
| 3125 | if (!rc) |
| 3126 | fan_update_desired_level(s); |
| 3127 | mutex_unlock(&fan_mutex); |
| 3128 | |
| 3129 | if (status) |
| 3130 | *status = s; |
| 3131 | |
| 3132 | return rc; |
| 3133 | } |
| 3134 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3135 | static void fan_exit(void) |
| 3136 | { |
Henrique de Moraes Holschuh | 99fba3f | 2007-04-21 11:08:44 -0300 | [diff] [blame] | 3137 | vdbg_printk(TPACPI_DBG_EXIT, "cancelling any pending fan watchdog tasks\n"); |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3138 | |
| 3139 | /* FIXME: can we really do this unconditionally? */ |
| 3140 | sysfs_remove_group(&tpacpi_pdev->dev.kobj, &fan_attr_group); |
| 3141 | driver_remove_file(&tpacpi_pdriver.driver, &driver_attr_fan_watchdog); |
| 3142 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3143 | cancel_delayed_work(&fan_watchdog_task); |
| 3144 | flush_scheduled_work(); |
| 3145 | } |
| 3146 | |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 3147 | static int fan_get_speed(unsigned int *speed) |
| 3148 | { |
| 3149 | u8 hi, lo; |
| 3150 | |
| 3151 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3152 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 3153 | /* all except 570, 600e/x, 770e, 770x */ |
| 3154 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 3155 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 3156 | return -EIO; |
| 3157 | |
| 3158 | if (likely(speed)) |
| 3159 | *speed = (hi << 8) | lo; |
| 3160 | |
| 3161 | break; |
| 3162 | |
| 3163 | default: |
| 3164 | return -ENXIO; |
| 3165 | } |
| 3166 | |
| 3167 | return 0; |
| 3168 | } |
| 3169 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3170 | static void fan_watchdog_fire(struct work_struct *ignored) |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 3171 | { |
Henrique de Moraes Holschuh | 99fba3f | 2007-04-21 11:08:44 -0300 | [diff] [blame] | 3172 | int rc; |
| 3173 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3174 | printk(IBM_NOTICE "fan watchdog: enabling fan\n"); |
Henrique de Moraes Holschuh | 99fba3f | 2007-04-21 11:08:44 -0300 | [diff] [blame] | 3175 | rc = fan_set_enable(); |
| 3176 | if (rc < 0) { |
| 3177 | printk(IBM_ERR "fan watchdog: error %d while enabling fan, " |
| 3178 | "will try again later...\n", -rc); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3179 | /* reschedule for later */ |
| 3180 | fan_watchdog_reset(); |
| 3181 | } |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 3182 | } |
| 3183 | |
| 3184 | static void fan_watchdog_reset(void) |
| 3185 | { |
| 3186 | static int fan_watchdog_active = 0; |
| 3187 | |
| 3188 | if (fan_watchdog_active) |
| 3189 | cancel_delayed_work(&fan_watchdog_task); |
| 3190 | |
| 3191 | if (fan_watchdog_maxinterval > 0) { |
| 3192 | fan_watchdog_active = 1; |
| 3193 | if (!schedule_delayed_work(&fan_watchdog_task, |
| 3194 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 3195 | * 1000))) { |
| 3196 | printk(IBM_ERR "failed to schedule the fan watchdog, " |
| 3197 | "watchdog will not trigger\n"); |
| 3198 | } |
| 3199 | } else |
| 3200 | fan_watchdog_active = 0; |
| 3201 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3202 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3203 | static int fan_set_level(int level) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3204 | { |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3205 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3206 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3207 | if (level >= 0 && level <= 7) { |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3208 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3209 | return -EIO; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3210 | } else |
| 3211 | return -EINVAL; |
| 3212 | break; |
| 3213 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3214 | case TPACPI_FAN_WR_ACPI_FANS: |
| 3215 | case TPACPI_FAN_WR_TPEC: |
| 3216 | if ((level != TP_EC_FAN_AUTO) && |
| 3217 | (level != TP_EC_FAN_FULLSPEED) && |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 3218 | ((level < 0) || (level > 7))) |
| 3219 | return -EINVAL; |
| 3220 | |
Henrique de Moraes Holschuh | eaa7571 | 2007-04-24 11:48:18 -0300 | [diff] [blame] | 3221 | /* safety net should the EC not support AUTO |
| 3222 | * or FULLSPEED mode bits and just ignore them */ |
| 3223 | if (level & TP_EC_FAN_FULLSPEED) |
| 3224 | level |= 7; /* safety min speed 7 */ |
| 3225 | else if (level & TP_EC_FAN_FULLSPEED) |
| 3226 | level |= 4; /* safety min speed 4 */ |
| 3227 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3228 | if (!acpi_ec_write(fan_status_offset, level)) |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 3229 | return -EIO; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 3230 | else |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3231 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 3232 | break; |
| 3233 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3234 | default: |
| 3235 | return -ENXIO; |
| 3236 | } |
| 3237 | return 0; |
| 3238 | } |
| 3239 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3240 | static int fan_set_level_safe(int level) |
| 3241 | { |
| 3242 | int rc; |
| 3243 | |
| 3244 | rc = mutex_lock_interruptible(&fan_mutex); |
| 3245 | if (rc < 0) |
| 3246 | return rc; |
| 3247 | |
| 3248 | if (level == TPACPI_FAN_LAST_LEVEL) |
| 3249 | level = fan_control_desired_level; |
| 3250 | |
| 3251 | rc = fan_set_level(level); |
| 3252 | if (!rc) |
| 3253 | fan_update_desired_level(level); |
| 3254 | |
| 3255 | mutex_unlock(&fan_mutex); |
| 3256 | return rc; |
| 3257 | } |
| 3258 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3259 | static int fan_set_enable(void) |
| 3260 | { |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 3261 | u8 s; |
| 3262 | int rc; |
| 3263 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3264 | rc = mutex_lock_interruptible(&fan_mutex); |
| 3265 | if (rc < 0) |
| 3266 | return rc; |
| 3267 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3268 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3269 | case TPACPI_FAN_WR_ACPI_FANS: |
| 3270 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3271 | rc = fan_get_status(&s); |
| 3272 | if (rc < 0) |
| 3273 | break; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 3274 | |
| 3275 | /* Don't go out of emergency fan mode */ |
Henrique de Moraes Holschuh | eaa7571 | 2007-04-24 11:48:18 -0300 | [diff] [blame] | 3276 | if (s != 7) { |
| 3277 | s &= 0x07; |
| 3278 | s |= TP_EC_FAN_AUTO | 4; /* min fan speed 4 */ |
| 3279 | } |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 3280 | |
| 3281 | if (!acpi_ec_write(fan_status_offset, s)) |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3282 | rc = -EIO; |
| 3283 | else { |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3284 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3285 | rc = 0; |
| 3286 | } |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 3287 | break; |
| 3288 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3289 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3290 | rc = fan_get_status(&s); |
| 3291 | if (rc < 0) |
| 3292 | break; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 3293 | |
| 3294 | s &= 0x07; |
| 3295 | |
| 3296 | /* Set fan to at least level 4 */ |
Henrique de Moraes Holschuh | eaa7571 | 2007-04-24 11:48:18 -0300 | [diff] [blame] | 3297 | s |= 4; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 3298 | |
| 3299 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3300 | rc= -EIO; |
| 3301 | else |
| 3302 | rc = 0; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3303 | break; |
| 3304 | |
| 3305 | default: |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3306 | rc = -ENXIO; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3307 | } |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3308 | |
| 3309 | mutex_unlock(&fan_mutex); |
| 3310 | return rc; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3311 | } |
| 3312 | |
| 3313 | static int fan_set_disable(void) |
| 3314 | { |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3315 | int rc; |
| 3316 | |
| 3317 | rc = mutex_lock_interruptible(&fan_mutex); |
| 3318 | if (rc < 0) |
| 3319 | return rc; |
| 3320 | |
| 3321 | rc = 0; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3322 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3323 | case TPACPI_FAN_WR_ACPI_FANS: |
| 3324 | case TPACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3325 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3326 | rc = -EIO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3327 | else { |
| 3328 | fan_control_desired_level = 0; |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3329 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3330 | } |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3331 | break; |
| 3332 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3333 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 3334 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3335 | rc = -EIO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3336 | else |
| 3337 | fan_control_desired_level = 0; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 3338 | break; |
| 3339 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3340 | default: |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3341 | rc = -ENXIO; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3342 | } |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3343 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3344 | |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3345 | mutex_unlock(&fan_mutex); |
| 3346 | return rc; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3347 | } |
| 3348 | |
| 3349 | static int fan_set_speed(int speed) |
| 3350 | { |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3351 | int rc; |
| 3352 | |
| 3353 | rc = mutex_lock_interruptible(&fan_mutex); |
| 3354 | if (rc < 0) |
| 3355 | return rc; |
| 3356 | |
| 3357 | rc = 0; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3358 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3359 | case TPACPI_FAN_WR_ACPI_FANS: |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3360 | if (speed >= 0 && speed <= 65535) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3361 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 3362 | speed, speed, speed)) |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3363 | rc = -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3364 | } else |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3365 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3366 | break; |
| 3367 | |
| 3368 | default: |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3369 | rc = -ENXIO; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3370 | } |
Henrique de Moraes Holschuh | 40ca9fd | 2007-04-24 11:48:15 -0300 | [diff] [blame] | 3371 | |
| 3372 | mutex_unlock(&fan_mutex); |
| 3373 | return rc; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3374 | } |
| 3375 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3376 | static int fan_read(char *p) |
| 3377 | { |
| 3378 | int len = 0; |
| 3379 | int rc; |
| 3380 | u8 status; |
| 3381 | unsigned int speed = 0; |
| 3382 | |
| 3383 | switch (fan_status_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3384 | case TPACPI_FAN_RD_ACPI_GFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3385 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3386 | if ((rc = fan_get_status_safe(&status)) < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3387 | return rc; |
| 3388 | |
| 3389 | len += sprintf(p + len, "status:\t\t%s\n" |
| 3390 | "level:\t\t%d\n", |
| 3391 | (status != 0) ? "enabled" : "disabled", status); |
| 3392 | break; |
| 3393 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3394 | case TPACPI_FAN_RD_TPEC: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3395 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3396 | if ((rc = fan_get_status_safe(&status)) < 0) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3397 | return rc; |
| 3398 | |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3399 | if (unlikely(tp_features.fan_ctrl_status_undef)) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3400 | if (status != fan_control_initial_status) |
Henrique de Moraes Holschuh | d8fd94d | 2007-04-21 11:08:36 -0300 | [diff] [blame] | 3401 | tp_features.fan_ctrl_status_undef = 0; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3402 | else |
| 3403 | /* Return most likely status. In fact, it |
| 3404 | * might be the only possible status */ |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3405 | status = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3406 | } |
| 3407 | |
| 3408 | len += sprintf(p + len, "status:\t\t%s\n", |
| 3409 | (status != 0) ? "enabled" : "disabled"); |
| 3410 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3411 | if ((rc = fan_get_speed(&speed)) < 0) |
| 3412 | return rc; |
| 3413 | |
| 3414 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
| 3415 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3416 | if (status & TP_EC_FAN_FULLSPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3417 | /* Disengaged mode takes precedence */ |
| 3418 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3419 | else if (status & TP_EC_FAN_AUTO) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3420 | len += sprintf(p + len, "level:\t\tauto\n"); |
| 3421 | else |
| 3422 | len += sprintf(p + len, "level:\t\t%d\n", status); |
| 3423 | break; |
| 3424 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3425 | case TPACPI_FAN_NONE: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3426 | default: |
| 3427 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 3428 | } |
| 3429 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3430 | if (fan_control_commands & TPACPI_FAN_CMD_LEVEL) { |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3431 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 3432 | |
| 3433 | switch (fan_control_access_mode) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3434 | case TPACPI_FAN_WR_ACPI_SFAN: |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3435 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 3436 | break; |
| 3437 | |
| 3438 | default: |
| 3439 | len += sprintf(p + len, " (<level> is 0-7, " |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3440 | "auto, disengaged, full-speed)\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3441 | break; |
| 3442 | } |
| 3443 | } |
| 3444 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3445 | if (fan_control_commands & TPACPI_FAN_CMD_ENABLE) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3446 | len += sprintf(p + len, "commands:\tenable, disable\n" |
| 3447 | "commands:\twatchdog <timeout> (<timeout> is 0 (off), " |
| 3448 | "1-120 (seconds))\n"); |
| 3449 | |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3450 | if (fan_control_commands & TPACPI_FAN_CMD_SPEED) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3451 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 3452 | " (<speed> is 0-65535)\n"); |
| 3453 | |
| 3454 | return len; |
| 3455 | } |
| 3456 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3457 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 3458 | { |
| 3459 | int level; |
| 3460 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 3461 | if (strlencmp(cmd, "level auto") == 0) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3462 | level = TP_EC_FAN_AUTO; |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3463 | else if ((strlencmp(cmd, "level disengaged") == 0) | |
| 3464 | (strlencmp(cmd, "level full-speed") == 0)) |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3465 | level = TP_EC_FAN_FULLSPEED; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 3466 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3467 | return 0; |
| 3468 | |
Henrique de Moraes Holschuh | fe98a52 | 2007-04-24 11:48:17 -0300 | [diff] [blame] | 3469 | if ((*rc = fan_set_level_safe(level)) == -ENXIO) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3470 | printk(IBM_ERR "level command accepted for unsupported " |
| 3471 | "access mode %d", fan_control_access_mode); |
| 3472 | |
| 3473 | return 1; |
| 3474 | } |
| 3475 | |
| 3476 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 3477 | { |
| 3478 | if (strlencmp(cmd, "enable") != 0) |
| 3479 | return 0; |
| 3480 | |
| 3481 | if ((*rc = fan_set_enable()) == -ENXIO) |
| 3482 | printk(IBM_ERR "enable command accepted for unsupported " |
| 3483 | "access mode %d", fan_control_access_mode); |
| 3484 | |
| 3485 | return 1; |
| 3486 | } |
| 3487 | |
| 3488 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 3489 | { |
| 3490 | if (strlencmp(cmd, "disable") != 0) |
| 3491 | return 0; |
| 3492 | |
| 3493 | if ((*rc = fan_set_disable()) == -ENXIO) |
| 3494 | printk(IBM_ERR "disable command accepted for unsupported " |
| 3495 | "access mode %d", fan_control_access_mode); |
| 3496 | |
| 3497 | return 1; |
| 3498 | } |
| 3499 | |
| 3500 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 3501 | { |
| 3502 | int speed; |
| 3503 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3504 | /* TODO: |
| 3505 | * Support speed <low> <medium> <high> ? */ |
| 3506 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3507 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 3508 | return 0; |
| 3509 | |
| 3510 | if ((*rc = fan_set_speed(speed)) == -ENXIO) |
| 3511 | printk(IBM_ERR "speed command accepted for unsupported " |
| 3512 | "access mode %d", fan_control_access_mode); |
| 3513 | |
| 3514 | return 1; |
| 3515 | } |
| 3516 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 3517 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 3518 | { |
| 3519 | int interval; |
| 3520 | |
| 3521 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 3522 | return 0; |
| 3523 | |
| 3524 | if (interval < 0 || interval > 120) |
| 3525 | *rc = -EINVAL; |
| 3526 | else |
| 3527 | fan_watchdog_maxinterval = interval; |
| 3528 | |
| 3529 | return 1; |
| 3530 | } |
| 3531 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3532 | static int fan_write(char *buf) |
| 3533 | { |
| 3534 | char *cmd; |
| 3535 | int rc = 0; |
| 3536 | |
| 3537 | while (!rc && (cmd = next_cmd(&buf))) { |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3538 | if (!((fan_control_commands & TPACPI_FAN_CMD_LEVEL) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3539 | fan_write_cmd_level(cmd, &rc)) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3540 | !((fan_control_commands & TPACPI_FAN_CMD_ENABLE) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3541 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 3542 | fan_write_cmd_disable(cmd, &rc) || |
| 3543 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | efa2714 | 2007-04-21 11:08:28 -0300 | [diff] [blame] | 3544 | !((fan_control_commands & TPACPI_FAN_CMD_SPEED) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3545 | fan_write_cmd_speed(cmd, &rc)) |
| 3546 | ) |
| 3547 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 3548 | else if (!rc) |
| 3549 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3550 | } |
| 3551 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 3552 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3553 | } |
| 3554 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3555 | static struct ibm_struct fan_driver_data = { |
| 3556 | .name = "fan", |
| 3557 | .read = fan_read, |
| 3558 | .write = fan_write, |
| 3559 | .exit = fan_exit, |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 3560 | .flags.experimental = 1, |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3561 | }; |
| 3562 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3563 | /**************************************************************************** |
| 3564 | **************************************************************************** |
| 3565 | * |
| 3566 | * Infrastructure |
| 3567 | * |
| 3568 | **************************************************************************** |
| 3569 | ****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3570 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3571 | /* /proc support */ |
| 3572 | static struct proc_dir_entry *proc_dir = NULL; |
| 3573 | |
| 3574 | /* Subdriver registry */ |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3575 | static LIST_HEAD(tpacpi_all_drivers); |
| 3576 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3578 | /* |
| 3579 | * Module and infrastructure proble, init and exit handling |
| 3580 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3581 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3582 | #ifdef CONFIG_THINKPAD_ACPI_DEBUG |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3583 | static const char * __init str_supported(int is_supported) |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3584 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3585 | static char text_unsupported[] __initdata = "not supported"; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3586 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3587 | return (is_supported)? &text_unsupported[4] : &text_unsupported[0]; |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3588 | } |
| 3589 | #endif /* CONFIG_THINKPAD_ACPI_DEBUG */ |
| 3590 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3591 | static int __init ibm_init(struct ibm_init_struct *iibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3592 | { |
| 3593 | int ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3594 | struct ibm_struct *ibm = iibm->data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | struct proc_dir_entry *entry; |
| 3596 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3597 | BUG_ON(ibm == NULL); |
| 3598 | |
| 3599 | INIT_LIST_HEAD(&ibm->all_drivers); |
| 3600 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 3601 | if (ibm->flags.experimental && !experimental) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 | return 0; |
| 3603 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3604 | dbg_printk(TPACPI_DBG_INIT, |
| 3605 | "probing for %s\n", ibm->name); |
| 3606 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3607 | if (iibm->init) { |
| 3608 | ret = iibm->init(iibm); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3609 | if (ret > 0) |
| 3610 | return 0; /* probe failed */ |
| 3611 | if (ret) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | return ret; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3613 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 3614 | ibm->flags.init_called = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3615 | } |
| 3616 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3617 | if (ibm->acpi) { |
| 3618 | if (ibm->acpi->hid) { |
| 3619 | ret = register_tpacpi_subdriver(ibm); |
| 3620 | if (ret) |
| 3621 | goto err_out; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3622 | } |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3623 | |
| 3624 | if (ibm->acpi->notify) { |
| 3625 | ret = setup_acpi_notify(ibm); |
| 3626 | if (ret == -ENODEV) { |
| 3627 | printk(IBM_NOTICE "disabling subdriver %s\n", |
| 3628 | ibm->name); |
| 3629 | ret = 0; |
| 3630 | goto err_out; |
| 3631 | } |
| 3632 | if (ret < 0) |
| 3633 | goto err_out; |
| 3634 | } |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3635 | } |
| 3636 | |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3637 | dbg_printk(TPACPI_DBG_INIT, |
| 3638 | "%s installed\n", ibm->name); |
| 3639 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3640 | if (ibm->read) { |
| 3641 | entry = create_proc_entry(ibm->name, |
| 3642 | S_IFREG | S_IRUGO | S_IWUSR, |
| 3643 | proc_dir); |
| 3644 | if (!entry) { |
| 3645 | printk(IBM_ERR "unable to create proc entry %s\n", |
| 3646 | ibm->name); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3647 | ret = -ENODEV; |
| 3648 | goto err_out; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3649 | } |
| 3650 | entry->owner = THIS_MODULE; |
| 3651 | entry->data = ibm; |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3652 | entry->read_proc = &dispatch_procfs_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3653 | if (ibm->write) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3654 | entry->write_proc = &dispatch_procfs_write; |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 3655 | ibm->flags.proc_created = 1; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3656 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3658 | list_add_tail(&ibm->all_drivers, &tpacpi_all_drivers); |
| 3659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3660 | return 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3661 | |
| 3662 | err_out: |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3663 | dbg_printk(TPACPI_DBG_INIT, |
| 3664 | "%s: at error exit path with result %d\n", |
| 3665 | ibm->name, ret); |
| 3666 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3667 | ibm_exit(ibm); |
| 3668 | return (ret < 0)? ret : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | } |
| 3670 | |
| 3671 | static void ibm_exit(struct ibm_struct *ibm) |
| 3672 | { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3673 | dbg_printk(TPACPI_DBG_EXIT, "removing %s\n", ibm->name); |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3674 | |
| 3675 | list_del_init(&ibm->all_drivers); |
| 3676 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3677 | if (ibm->flags.acpi_notify_installed) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3678 | dbg_printk(TPACPI_DBG_EXIT, |
| 3679 | "%s: acpi_remove_notify_handler\n", ibm->name); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3680 | BUG_ON(!ibm->acpi); |
| 3681 | acpi_remove_notify_handler(*ibm->acpi->handle, |
| 3682 | ibm->acpi->type, |
| 3683 | dispatch_acpi_notify); |
| 3684 | ibm->flags.acpi_notify_installed = 0; |
| 3685 | ibm->flags.acpi_notify_installed = 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3686 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3687 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 3688 | if (ibm->flags.proc_created) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3689 | dbg_printk(TPACPI_DBG_EXIT, |
| 3690 | "%s: remove_proc_entry\n", ibm->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3691 | remove_proc_entry(ibm->name, proc_dir); |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 3692 | ibm->flags.proc_created = 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3693 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3694 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3695 | if (ibm->flags.acpi_driver_registered) { |
Henrique de Moraes Holschuh | fe08bc4 | 2007-04-21 11:08:32 -0300 | [diff] [blame] | 3696 | dbg_printk(TPACPI_DBG_EXIT, |
| 3697 | "%s: acpi_bus_unregister_driver\n", ibm->name); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3698 | BUG_ON(!ibm->acpi); |
| 3699 | acpi_bus_unregister_driver(ibm->acpi->driver); |
| 3700 | kfree(ibm->acpi->driver); |
| 3701 | ibm->acpi->driver = NULL; |
| 3702 | ibm->flags.acpi_driver_registered = 0; |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3703 | } |
| 3704 | |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 3705 | if (ibm->flags.init_called && ibm->exit) { |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3706 | ibm->exit(); |
Henrique de Moraes Holschuh | 9264117 | 2007-04-21 11:08:35 -0300 | [diff] [blame] | 3707 | ibm->flags.init_called = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3708 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3709 | |
| 3710 | dbg_printk(TPACPI_DBG_INIT, "finished removing %s\n", ibm->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3711 | } |
| 3712 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3713 | /* Probing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3714 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3715 | static char *ibm_thinkpad_ec_found = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3716 | |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 3717 | static char* __init check_dmi_for_ec(void) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 3718 | { |
| 3719 | struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 3720 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 3721 | |
| 3722 | /* |
| 3723 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 3724 | * X32 or newer, all Z series; Some models must have an |
| 3725 | * up-to-date BIOS or they will not be detected. |
| 3726 | * |
| 3727 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 3728 | */ |
| 3729 | 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] | 3730 | if (sscanf(dev->name, |
| 3731 | "IBM ThinkPad Embedded Controller -[%17c", |
| 3732 | ec_fw_string) == 1) { |
| 3733 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 3734 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
| 3735 | return kstrdup(ec_fw_string, GFP_KERNEL); |
| 3736 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 3737 | } |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 3738 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | } |
| 3740 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3741 | static int __init probe_for_thinkpad(void) |
| 3742 | { |
| 3743 | int is_thinkpad; |
| 3744 | |
| 3745 | if (acpi_disabled) |
| 3746 | return -ENODEV; |
| 3747 | |
| 3748 | /* |
| 3749 | * Non-ancient models have better DMI tagging, but very old models |
| 3750 | * don't. |
| 3751 | */ |
| 3752 | is_thinkpad = dmi_name_in_vendors("ThinkPad"); |
| 3753 | |
| 3754 | /* 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] | 3755 | IBM_ACPIHANDLE_INIT(ec); |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3756 | if (!ec_handle) { |
| 3757 | if (is_thinkpad) |
| 3758 | printk(IBM_ERR |
| 3759 | "Not yet supported ThinkPad detected!\n"); |
| 3760 | return -ENODEV; |
| 3761 | } |
| 3762 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 3763 | /* |
| 3764 | * Risks a regression on very old machines, but reduces potential |
| 3765 | * false positives a damn great deal |
| 3766 | */ |
| 3767 | if (!is_thinkpad) |
| 3768 | is_thinkpad = dmi_name_in_vendors("IBM"); |
| 3769 | |
| 3770 | if (!is_thinkpad && !force_load) |
| 3771 | return -ENODEV; |
| 3772 | |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3773 | return 0; |
| 3774 | } |
| 3775 | |
| 3776 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3777 | /* Module init, exit, parameters */ |
| 3778 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3779 | static struct ibm_init_struct ibms_init[] __initdata = { |
| 3780 | { |
| 3781 | .init = thinkpad_acpi_driver_init, |
| 3782 | .data = &thinkpad_acpi_driver_data, |
| 3783 | }, |
| 3784 | { |
| 3785 | .init = hotkey_init, |
| 3786 | .data = &hotkey_driver_data, |
| 3787 | }, |
| 3788 | { |
| 3789 | .init = bluetooth_init, |
| 3790 | .data = &bluetooth_driver_data, |
| 3791 | }, |
| 3792 | { |
| 3793 | .init = wan_init, |
| 3794 | .data = &wan_driver_data, |
| 3795 | }, |
| 3796 | { |
| 3797 | .init = video_init, |
| 3798 | .data = &video_driver_data, |
| 3799 | }, |
| 3800 | { |
| 3801 | .init = light_init, |
| 3802 | .data = &light_driver_data, |
| 3803 | }, |
| 3804 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
| 3805 | { |
| 3806 | .init = dock_init, |
| 3807 | .data = &dock_driver_data[0], |
| 3808 | }, |
| 3809 | { |
| 3810 | .data = &dock_driver_data[1], |
| 3811 | }, |
| 3812 | #endif |
| 3813 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
| 3814 | { |
| 3815 | .init = bay_init, |
| 3816 | .data = &bay_driver_data, |
| 3817 | }, |
| 3818 | #endif |
| 3819 | { |
| 3820 | .init = cmos_init, |
| 3821 | .data = &cmos_driver_data, |
| 3822 | }, |
| 3823 | { |
| 3824 | .init = led_init, |
| 3825 | .data = &led_driver_data, |
| 3826 | }, |
| 3827 | { |
| 3828 | .init = beep_init, |
| 3829 | .data = &beep_driver_data, |
| 3830 | }, |
| 3831 | { |
| 3832 | .init = thermal_init, |
| 3833 | .data = &thermal_driver_data, |
| 3834 | }, |
| 3835 | { |
| 3836 | .data = &ecdump_driver_data, |
| 3837 | }, |
| 3838 | { |
| 3839 | .init = brightness_init, |
| 3840 | .data = &brightness_driver_data, |
| 3841 | }, |
| 3842 | { |
| 3843 | .data = &volume_driver_data, |
| 3844 | }, |
| 3845 | { |
| 3846 | .init = fan_init, |
| 3847 | .data = &fan_driver_data, |
| 3848 | }, |
| 3849 | }; |
| 3850 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3851 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
| 3852 | { |
| 3853 | unsigned int i; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3854 | struct ibm_struct *ibm; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3855 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3856 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 3857 | ibm = ibms_init[i].data; |
| 3858 | BUG_ON(ibm == NULL); |
| 3859 | |
| 3860 | if (strcmp(ibm->name, kp->name) == 0 && ibm->write) { |
| 3861 | if (strlen(val) > sizeof(ibms_init[i].param) - 2) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3862 | return -ENOSPC; |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3863 | strcpy(ibms_init[i].param, val); |
| 3864 | strcat(ibms_init[i].param, ","); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3865 | return 0; |
| 3866 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3867 | } |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3868 | |
| 3869 | return -EINVAL; |
| 3870 | } |
| 3871 | |
| 3872 | static int experimental; |
| 3873 | module_param(experimental, int, 0); |
| 3874 | |
Henrique de Moraes Holschuh | 132ce09 | 2007-04-21 11:08:30 -0300 | [diff] [blame] | 3875 | static u32 dbg_level; |
| 3876 | module_param_named(debug, dbg_level, uint, 0); |
| 3877 | |
Henrique de Moraes Holschuh | 0dcef77 | 2007-04-21 11:08:34 -0300 | [diff] [blame] | 3878 | static int force_load; |
| 3879 | module_param(force_load, int, 0); |
| 3880 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3881 | #define IBM_PARAM(feature) \ |
| 3882 | module_param_call(feature, set_ibm_param, NULL, NULL, 0) |
| 3883 | |
| 3884 | IBM_PARAM(hotkey); |
| 3885 | IBM_PARAM(bluetooth); |
| 3886 | IBM_PARAM(video); |
| 3887 | IBM_PARAM(light); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3888 | #ifdef CONFIG_THINKPAD_ACPI_DOCK |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3889 | IBM_PARAM(dock); |
| 3890 | #endif |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3891 | #ifdef CONFIG_THINKPAD_ACPI_BAY |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3892 | IBM_PARAM(bay); |
Henrique de Moraes Holschuh | 8599824 | 2007-03-29 01:58:41 -0300 | [diff] [blame] | 3893 | #endif /* CONFIG_THINKPAD_ACPI_BAY */ |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3894 | IBM_PARAM(cmos); |
| 3895 | IBM_PARAM(led); |
| 3896 | IBM_PARAM(beep); |
| 3897 | IBM_PARAM(ecdump); |
| 3898 | IBM_PARAM(brightness); |
| 3899 | IBM_PARAM(volume); |
| 3900 | IBM_PARAM(fan); |
| 3901 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 3902 | static int __init thinkpad_acpi_module_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3903 | { |
| 3904 | int ret, i; |
| 3905 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 3906 | /* Driver-level probe */ |
Henrique de Moraes Holschuh | 5fba344 | 2007-04-21 11:08:31 -0300 | [diff] [blame] | 3907 | ret = probe_for_thinkpad(); |
| 3908 | if (ret) |
| 3909 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3910 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 3911 | /* Driver initialization */ |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 3912 | ibm_thinkpad_ec_found = check_dmi_for_ec(); |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3913 | IBM_ACPIHANDLE_INIT(ecrd); |
| 3914 | IBM_ACPIHANDLE_INIT(ecwr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3915 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3916 | proc_dir = proc_mkdir(IBM_PROC_DIR, acpi_root_dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3917 | if (!proc_dir) { |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3918 | 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] | 3919 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3920 | return -ENODEV; |
| 3921 | } |
| 3922 | proc_dir->owner = THIS_MODULE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 3923 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 3924 | ret = platform_driver_register(&tpacpi_pdriver); |
| 3925 | if (ret) { |
| 3926 | printk(IBM_ERR "unable to register platform driver\n"); |
| 3927 | thinkpad_acpi_module_exit(); |
| 3928 | return ret; |
| 3929 | } |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 3930 | ret = tpacpi_create_driver_attributes(&tpacpi_pdriver.driver); |
| 3931 | if (ret) { |
| 3932 | printk(IBM_ERR "unable to create sysfs driver attributes\n"); |
| 3933 | thinkpad_acpi_module_exit(); |
| 3934 | return ret; |
| 3935 | } |
| 3936 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 3937 | |
| 3938 | /* Device initialization */ |
| 3939 | tpacpi_pdev = platform_device_register_simple(IBM_DRVR_NAME, -1, |
| 3940 | NULL, 0); |
| 3941 | if (IS_ERR(tpacpi_pdev)) { |
| 3942 | ret = PTR_ERR(tpacpi_pdev); |
| 3943 | tpacpi_pdev = NULL; |
| 3944 | printk(IBM_ERR "unable to register platform device\n"); |
| 3945 | thinkpad_acpi_module_exit(); |
| 3946 | return ret; |
| 3947 | } |
| 3948 | tpacpi_hwmon = hwmon_device_register(&tpacpi_pdev->dev); |
| 3949 | if (IS_ERR(tpacpi_hwmon)) { |
| 3950 | ret = PTR_ERR(tpacpi_hwmon); |
| 3951 | tpacpi_hwmon = NULL; |
| 3952 | printk(IBM_ERR "unable to register hwmon device\n"); |
| 3953 | thinkpad_acpi_module_exit(); |
| 3954 | return ret; |
| 3955 | } |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3956 | for (i = 0; i < ARRAY_SIZE(ibms_init); i++) { |
| 3957 | ret = ibm_init(&ibms_init[i]); |
| 3958 | if (ret >= 0 && *ibms_init[i].param) |
| 3959 | ret = ibms_init[i].data->write(ibms_init[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3960 | if (ret < 0) { |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 3961 | thinkpad_acpi_module_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3962 | return ret; |
| 3963 | } |
| 3964 | } |
| 3965 | |
| 3966 | return 0; |
| 3967 | } |
| 3968 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 3969 | static void thinkpad_acpi_module_exit(void) |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3970 | { |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3971 | struct ibm_struct *ibm, *itmp; |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3972 | |
Henrique de Moraes Holschuh | a5763f2 | 2007-04-21 11:08:33 -0300 | [diff] [blame] | 3973 | list_for_each_entry_safe_reverse(ibm, itmp, |
| 3974 | &tpacpi_all_drivers, |
| 3975 | all_drivers) { |
| 3976 | ibm_exit(ibm); |
| 3977 | } |
| 3978 | |
| 3979 | dbg_printk(TPACPI_DBG_INIT, "finished subdriver exit path...\n"); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3980 | |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 3981 | if (tpacpi_hwmon) |
| 3982 | hwmon_device_unregister(tpacpi_hwmon); |
| 3983 | |
| 3984 | if (tpacpi_pdev) |
| 3985 | platform_device_unregister(tpacpi_pdev); |
| 3986 | |
Henrique de Moraes Holschuh | 176750d | 2007-04-24 11:48:13 -0300 | [diff] [blame] | 3987 | tpacpi_remove_driver_attributes(&tpacpi_pdriver.driver); |
Henrique de Moraes Holschuh | 54ae150 | 2007-04-24 11:48:12 -0300 | [diff] [blame] | 3988 | platform_driver_unregister(&tpacpi_pdriver); |
| 3989 | |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3990 | if (proc_dir) |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3991 | remove_proc_entry(IBM_PROC_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3992 | |
Henrique de Moraes Holschuh | 8d376cd | 2007-04-21 11:08:37 -0300 | [diff] [blame] | 3993 | kfree(ibm_thinkpad_ec_found); |
Henrique de Moraes Holschuh | 56b6aeb | 2007-03-23 17:33:57 -0300 | [diff] [blame] | 3994 | } |
| 3995 | |
Henrique de Moraes Holschuh | 1def711 | 2007-04-21 11:08:27 -0300 | [diff] [blame] | 3996 | module_init(thinkpad_acpi_module_init); |
| 3997 | module_exit(thinkpad_acpi_module_exit); |