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