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