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