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