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