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