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