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