Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * ibm_acpi.c - IBM ThinkPad ACPI Extras |
| 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 | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 6 | * Copyright (C) 2006 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 |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 21 | */ |
| 22 | |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 23 | #define IBM_VERSION "0.13" |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 24 | |
| 25 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * Changelog: |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 27 | * |
| 28 | * 2006-11-22 0.13 new maintainer |
| 29 | * changelog now lives in git commit history, and will |
| 30 | * not be updated further in-file. |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 31 | * |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 32 | * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels |
| 33 | * 2005-03-17 0.11 support for 600e, 770x |
| 34 | * thanks to Jamie Lentin <lentinj@dial.pipex.com> |
| 35 | * support for 770e, G41 |
| 36 | * G40 and G41 don't have a thinklight |
| 37 | * temperatures no longer experimental |
| 38 | * experimental brightness control |
| 39 | * experimental volume control |
| 40 | * experimental fan enable/disable |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 41 | * 2005-01-16 0.10 fix module loading on R30, R31 |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 42 | * 2005-01-16 0.9 support for 570, R30, R31 |
| 43 | * ultrabay support on A22p, A3x |
| 44 | * limit arg for cmos, led, beep, drop experimental status |
| 45 | * more capable led control on A21e, A22p, T20-22, X20 |
| 46 | * experimental temperatures and fan speed |
| 47 | * experimental embedded controller register dump |
| 48 | * mark more functions as __init, drop incorrect __exit |
| 49 | * use MODULE_VERSION |
| 50 | * thanks to Henrik Brix Andersen <brix@gentoo.org> |
| 51 | * fix parameter passing on module loading |
| 52 | * thanks to Rusty Russell <rusty@rustcorp.com.au> |
| 53 | * thanks to Jim Radford <radford@blackbean.org> |
| 54 | * 2004-11-08 0.8 fix init error case, don't return from a macro |
| 55 | * thanks to Chris Wright <chrisw@osdl.org> |
| 56 | * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20 |
| 57 | * fix led control on A21e |
| 58 | * 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] | 59 | * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20 |
| 60 | * proc file format changed |
| 61 | * video_switch command |
| 62 | * experimental cmos control |
| 63 | * experimental led control |
| 64 | * experimental acpi sounds |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 65 | * 2004-09-16 0.4 support for module parameters |
| 66 | * hotkey mask can be prefixed by 0x |
| 67 | * video output switching |
| 68 | * video expansion control |
| 69 | * ultrabay eject support |
| 70 | * removed lcd brightness/on/off control, didn't work |
| 71 | * 2004-08-17 0.3 support for R40 |
| 72 | * lcd off, brightness control |
| 73 | * thinklight on/off |
| 74 | * 2004-08-14 0.2 support for T series, X20 |
| 75 | * bluetooth enable/disable |
| 76 | * hotkey events disabled by default |
| 77 | * removed fan control, currently useless |
| 78 | * 2004-08-09 0.1 initial release, support for X series |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | */ |
| 80 | |
Henrique de Moraes Holschuh | 1406cdd | 2007-03-23 17:33:56 -0300 | [diff] [blame^] | 81 | #include "ibm_acpi.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | |
Henrique de Moraes Holschuh | f9ff43a | 2006-11-25 16:37:38 -0200 | [diff] [blame] | 83 | MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 84 | MODULE_DESCRIPTION(IBM_DESC); |
| 85 | MODULE_VERSION(IBM_VERSION); |
| 86 | MODULE_LICENSE("GPL"); |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | #define __unused __attribute__ ((unused)) |
| 89 | |
| 90 | static int experimental; |
| 91 | module_param(experimental, int, 0); |
| 92 | |
| 93 | static acpi_handle root_handle = NULL; |
| 94 | |
| 95 | #define IBM_HANDLE(object, parent, paths...) \ |
| 96 | static acpi_handle object##_handle; \ |
| 97 | static acpi_handle *object##_parent = &parent##_handle; \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 98 | static char *object##_path; \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | static char *object##_paths[] = { paths } |
| 100 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 101 | IBM_HANDLE(ec, root, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */ |
| 102 | "\\_SB.PCI.ISA.EC", /* 570 */ |
| 103 | "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */ |
| 104 | "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ |
| 105 | "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ |
| 106 | "\\_SB.PCI0.ICH3.EC0", /* R31 */ |
| 107 | "\\_SB.PCI0.LPC.EC", /* all others */ |
| 108 | ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 110 | IBM_HANDLE(vid, root, "\\_SB.PCI.AGP.VGA", /* 570 */ |
| 111 | "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */ |
| 112 | "\\_SB.PCI0.VID0", /* 770e */ |
| 113 | "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */ |
| 114 | "\\_SB.PCI0.AGP.VID", /* all others */ |
| 115 | ); /* R30, R31 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 117 | IBM_HANDLE(vid2, root, "\\_SB.PCI0.AGPB.VID"); /* G41 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 119 | IBM_HANDLE(cmos, root, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */ |
| 120 | "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */ |
| 121 | "\\CMS", /* R40, R40e */ |
| 122 | ); /* all others */ |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 123 | #ifdef CONFIG_ACPI_IBM_DOCK |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 124 | IBM_HANDLE(dock, root, "\\_SB.GDCK", /* X30, X31, X40 */ |
| 125 | "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */ |
| 126 | "\\_SB.PCI0.PCI1.DOCK", /* all others */ |
| 127 | "\\_SB.PCI.ISA.SLCE", /* 570 */ |
| 128 | ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */ |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 129 | #endif |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 130 | #ifdef CONFIG_ACPI_IBM_BAY |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 131 | IBM_HANDLE(bay, root, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */ |
| 132 | "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 837ca6d | 2007-03-23 17:33:54 -0300 | [diff] [blame] | 133 | "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 134 | "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */ |
| 135 | ); /* A21e, R30, R31 */ |
| 136 | |
| 137 | IBM_HANDLE(bay_ej, bay, "_EJ3", /* 600e/x, A2xm/p, A3x */ |
| 138 | "_EJ0", /* all others */ |
| 139 | ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */ |
| 140 | |
| 141 | IBM_HANDLE(bay2, root, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */ |
| 142 | "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */ |
| 143 | ); /* all others */ |
| 144 | |
| 145 | IBM_HANDLE(bay2_ej, bay2, "_EJ3", /* 600e/x, 770e, A3x */ |
| 146 | "_EJ0", /* 770x */ |
| 147 | ); /* all others */ |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 148 | #endif /* CONFIG_ACPI_IBM_BAY */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 149 | |
| 150 | /* don't list other alternatives as we install a notify handler on the 570 */ |
| 151 | IBM_HANDLE(pci, root, "\\_SB.PCI"); /* 570 */ |
| 152 | |
| 153 | IBM_HANDLE(hkey, ec, "\\_SB.HKEY", /* 600e/x, 770e, 770x */ |
| 154 | "^HKEY", /* R30, R31 */ |
| 155 | "HKEY", /* all others */ |
| 156 | ); /* 570 */ |
| 157 | |
| 158 | IBM_HANDLE(lght, root, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */ |
| 159 | IBM_HANDLE(ledb, ec, "LEDB"); /* G4x */ |
| 160 | |
| 161 | IBM_HANDLE(led, ec, "SLED", /* 570 */ |
| 162 | "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
| 163 | "LED", /* all others */ |
| 164 | ); /* R30, R31 */ |
| 165 | |
| 166 | IBM_HANDLE(beep, ec, "BEEP"); /* all except R30, R31 */ |
| 167 | IBM_HANDLE(ecrd, ec, "ECRD"); /* 570 */ |
| 168 | IBM_HANDLE(ecwr, ec, "ECWR"); /* 570 */ |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 169 | IBM_HANDLE(fans, ec, "FANS"); /* X31, X40, X41 */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 170 | |
| 171 | IBM_HANDLE(gfan, ec, "GFAN", /* 570 */ |
| 172 | "\\FSPD", /* 600e/x, 770e, 770x */ |
| 173 | ); /* all others */ |
| 174 | |
| 175 | IBM_HANDLE(sfan, ec, "SFAN", /* 570 */ |
| 176 | "JFNS", /* 770x-JL */ |
| 177 | ); /* all others */ |
| 178 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 179 | /* |
| 180 | * FAN ACCESS MODES |
| 181 | * |
| 182 | * IBMACPI_FAN_RD_ACPI_GFAN: |
| 183 | * ACPI GFAN method: returns fan level |
| 184 | * |
| 185 | * see IBMACPI_FAN_WR_ACPI_SFAN |
| 186 | * EC 0x2f not available if GFAN exists |
| 187 | * |
| 188 | * IBMACPI_FAN_WR_ACPI_SFAN: |
| 189 | * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max) |
| 190 | * |
| 191 | * EC 0x2f might be available *for reading*, but never for writing. |
| 192 | * |
| 193 | * IBMACPI_FAN_WR_TPEC: |
| 194 | * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported |
| 195 | * on almost all ThinkPads |
| 196 | * |
| 197 | * Fan speed changes of any sort (including those caused by the |
| 198 | * disengaged mode) are usually done slowly by the firmware as the |
| 199 | * maximum ammount of fan duty cycle change per second seems to be |
| 200 | * limited. |
| 201 | * |
| 202 | * Reading is not available if GFAN exists. |
| 203 | * Writing is not available if SFAN exists. |
| 204 | * |
| 205 | * Bits |
| 206 | * 7 automatic mode engaged; |
| 207 | * (default operation mode of the ThinkPad) |
| 208 | * fan level is ignored in this mode. |
| 209 | * 6 disengage mode (takes precedence over bit 7); |
| 210 | * not available on all thinkpads. May disable |
| 211 | * the tachometer, and speeds up fan to 100% duty-cycle, |
| 212 | * which speeds it up far above the standard RPM |
| 213 | * levels. It is not impossible that it could cause |
| 214 | * hardware damage. |
| 215 | * 5-3 unused in some models. Extra bits for fan level |
| 216 | * in others, but still useless as all values above |
| 217 | * 7 map to the same speed as level 7 in these models. |
| 218 | * 2-0 fan level (0..7 usually) |
| 219 | * 0x00 = stop |
| 220 | * 0x07 = max (set when temperatures critical) |
| 221 | * Some ThinkPads may have other levels, see |
| 222 | * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41) |
| 223 | * |
| 224 | * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at |
| 225 | * boot. Apparently the EC does not intialize it, so unless ACPI DSDT |
| 226 | * does so, its initial value is meaningless (0x07). |
| 227 | * |
| 228 | * For firmware bugs, refer to: |
| 229 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 230 | * |
| 231 | * ---- |
| 232 | * |
| 233 | * ThinkPad EC register 0x84 (LSB), 0x85 (MSB): |
| 234 | * Main fan tachometer reading (in RPM) |
| 235 | * |
| 236 | * This register is present on all ThinkPads with a new-style EC, and |
| 237 | * it is known not to be present on the A21m/e, and T22, as there is |
| 238 | * something else in offset 0x84 according to the ACPI DSDT. Other |
| 239 | * ThinkPads from this same time period (and earlier) probably lack the |
| 240 | * tachometer as well. |
| 241 | * |
| 242 | * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare |
| 243 | * was never fixed by IBM to report the EC firmware version string |
| 244 | * probably support the tachometer (like the early X models), so |
| 245 | * detecting it is quite hard. We need more data to know for sure. |
| 246 | * |
| 247 | * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings |
| 248 | * might result. |
| 249 | * |
| 250 | * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this |
| 251 | * register is not invalidated in ThinkPads that disable tachometer |
| 252 | * readings. Thus, the tachometer readings go stale. |
| 253 | * |
| 254 | * For firmware bugs, refer to: |
| 255 | * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues |
| 256 | * |
| 257 | * IBMACPI_FAN_WR_ACPI_FANS: |
| 258 | * ThinkPad X31, X40, X41. Not available in the X60. |
| 259 | * |
| 260 | * FANS ACPI handle: takes three arguments: low speed, medium speed, |
| 261 | * high speed. ACPI DSDT seems to map these three speeds to levels |
| 262 | * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH |
| 263 | * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3") |
| 264 | * |
| 265 | * The speeds are stored on handles |
| 266 | * (FANA:FAN9), (FANC:FANB), (FANE:FAND). |
| 267 | * |
| 268 | * There are three default speed sets, acessible as handles: |
| 269 | * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H |
| 270 | * |
| 271 | * ACPI DSDT switches which set is in use depending on various |
| 272 | * factors. |
| 273 | * |
| 274 | * IBMACPI_FAN_WR_TPEC is also available and should be used to |
| 275 | * command the fan. The X31/X40/X41 seems to have 8 fan levels, |
| 276 | * but the ACPI tables just mention level 7. |
| 277 | */ |
| 278 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 279 | static char *ibm_thinkpad_ec_found = NULL; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 280 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | static struct proc_dir_entry *proc_dir = NULL; |
| 282 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 283 | static struct backlight_device *ibm_backlight_device = NULL; |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | static int acpi_evalf(acpi_handle handle, |
| 286 | void *res, char *method, char *fmt, ...) |
| 287 | { |
| 288 | char *fmt0 = fmt; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 289 | struct acpi_object_list params; |
| 290 | union acpi_object in_objs[IBM_MAX_ACPI_ARGS]; |
| 291 | struct acpi_buffer result, *resultp; |
| 292 | union acpi_object out_obj; |
| 293 | acpi_status status; |
| 294 | va_list ap; |
| 295 | char res_type; |
| 296 | int success; |
| 297 | int quiet; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | |
| 299 | if (!*fmt) { |
| 300 | printk(IBM_ERR "acpi_evalf() called with empty format\n"); |
| 301 | return 0; |
| 302 | } |
| 303 | |
| 304 | if (*fmt == 'q') { |
| 305 | quiet = 1; |
| 306 | fmt++; |
| 307 | } else |
| 308 | quiet = 0; |
| 309 | |
| 310 | res_type = *(fmt++); |
| 311 | |
| 312 | params.count = 0; |
| 313 | params.pointer = &in_objs[0]; |
| 314 | |
| 315 | va_start(ap, fmt); |
| 316 | while (*fmt) { |
| 317 | char c = *(fmt++); |
| 318 | switch (c) { |
| 319 | case 'd': /* int */ |
| 320 | in_objs[params.count].integer.value = va_arg(ap, int); |
| 321 | in_objs[params.count++].type = ACPI_TYPE_INTEGER; |
| 322 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 323 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | default: |
| 325 | printk(IBM_ERR "acpi_evalf() called " |
| 326 | "with invalid format character '%c'\n", c); |
| 327 | return 0; |
| 328 | } |
| 329 | } |
| 330 | va_end(ap); |
| 331 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 332 | if (res_type != 'v') { |
| 333 | result.length = sizeof(out_obj); |
| 334 | result.pointer = &out_obj; |
| 335 | resultp = &result; |
| 336 | } else |
| 337 | resultp = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 339 | status = acpi_evaluate_object(handle, method, ¶ms, resultp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
| 341 | switch (res_type) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 342 | case 'd': /* int */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | if (res) |
| 344 | *(int *)res = out_obj.integer.value; |
| 345 | success = status == AE_OK && out_obj.type == ACPI_TYPE_INTEGER; |
| 346 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 347 | case 'v': /* void */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | success = status == AE_OK; |
| 349 | break; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 350 | /* add more types as needed */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | default: |
| 352 | printk(IBM_ERR "acpi_evalf() called " |
| 353 | "with invalid format character '%c'\n", res_type); |
| 354 | return 0; |
| 355 | } |
| 356 | |
| 357 | if (!success && !quiet) |
| 358 | printk(IBM_ERR "acpi_evalf(%s, %s, ...) failed: %d\n", |
| 359 | method, fmt0, status); |
| 360 | |
| 361 | return success; |
| 362 | } |
| 363 | |
| 364 | static void __unused acpi_print_int(acpi_handle handle, char *method) |
| 365 | { |
| 366 | int i; |
| 367 | |
| 368 | if (acpi_evalf(handle, &i, method, "d")) |
| 369 | printk(IBM_INFO "%s = 0x%x\n", method, i); |
| 370 | else |
| 371 | printk(IBM_ERR "error calling %s\n", method); |
| 372 | } |
| 373 | |
| 374 | static char *next_cmd(char **cmds) |
| 375 | { |
| 376 | char *start = *cmds; |
| 377 | char *end; |
| 378 | |
| 379 | while ((end = strchr(start, ',')) && end == start) |
| 380 | start = end + 1; |
| 381 | |
| 382 | if (!end) |
| 383 | return NULL; |
| 384 | |
| 385 | *end = 0; |
| 386 | *cmds = end + 1; |
| 387 | return start; |
| 388 | } |
| 389 | |
Adrian Bunk | 1f21782 | 2006-12-19 13:01:28 -0800 | [diff] [blame] | 390 | static int ibm_acpi_driver_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { |
| 392 | printk(IBM_INFO "%s v%s\n", IBM_DESC, IBM_VERSION); |
| 393 | printk(IBM_INFO "%s\n", IBM_URL); |
| 394 | |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 395 | if (ibm_thinkpad_ec_found) |
| 396 | printk(IBM_INFO "ThinkPad EC firmware %s\n", |
| 397 | ibm_thinkpad_ec_found); |
| 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | return 0; |
| 400 | } |
| 401 | |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 402 | static int ibm_acpi_driver_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | { |
| 404 | int len = 0; |
| 405 | |
| 406 | len += sprintf(p + len, "driver:\t\t%s\n", IBM_DESC); |
| 407 | len += sprintf(p + len, "version:\t%s\n", IBM_VERSION); |
| 408 | |
| 409 | return len; |
| 410 | } |
| 411 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 412 | static int hotkey_supported; |
| 413 | static int hotkey_mask_supported; |
| 414 | static int hotkey_orig_status; |
| 415 | static int hotkey_orig_mask; |
| 416 | |
| 417 | static int hotkey_get(int *status, int *mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | { |
| 419 | if (!acpi_evalf(hkey_handle, status, "DHKC", "d")) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 420 | return 0; |
| 421 | |
| 422 | if (hotkey_mask_supported) |
| 423 | if (!acpi_evalf(hkey_handle, mask, "DHKN", "d")) |
| 424 | return 0; |
| 425 | |
| 426 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 429 | static int hotkey_set(int status, int mask) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | { |
| 431 | int i; |
| 432 | |
| 433 | if (!acpi_evalf(hkey_handle, NULL, "MHKC", "vd", status)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | return 0; |
| 435 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 436 | if (hotkey_mask_supported) |
| 437 | for (i = 0; i < 32; i++) { |
| 438 | int bit = ((1 << i) & mask) != 0; |
| 439 | if (!acpi_evalf(hkey_handle, |
| 440 | NULL, "MHKM", "vdd", i + 1, bit)) |
| 441 | return 0; |
| 442 | } |
| 443 | |
| 444 | return 1; |
| 445 | } |
| 446 | |
| 447 | static int hotkey_init(void) |
| 448 | { |
| 449 | /* hotkey not supported on 570 */ |
| 450 | hotkey_supported = hkey_handle != NULL; |
| 451 | |
| 452 | if (hotkey_supported) { |
| 453 | /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 454 | A30, R30, R31, T20-22, X20-21, X22-24 */ |
| 455 | hotkey_mask_supported = |
| 456 | acpi_evalf(hkey_handle, NULL, "DHKN", "qv"); |
| 457 | |
| 458 | if (!hotkey_get(&hotkey_orig_status, &hotkey_orig_mask)) |
| 459 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | } |
| 461 | |
| 462 | return 0; |
| 463 | } |
| 464 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 465 | static int hotkey_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | { |
| 467 | int status, mask; |
| 468 | int len = 0; |
| 469 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 470 | if (!hotkey_supported) { |
| 471 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 472 | return len; |
| 473 | } |
| 474 | |
| 475 | if (!hotkey_get(&status, &mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | return -EIO; |
| 477 | |
| 478 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 479 | if (hotkey_mask_supported) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | len += sprintf(p + len, "mask:\t\t0x%04x\n", mask); |
| 481 | len += sprintf(p + len, |
| 482 | "commands:\tenable, disable, reset, <mask>\n"); |
| 483 | } else { |
| 484 | len += sprintf(p + len, "mask:\t\tnot supported\n"); |
| 485 | len += sprintf(p + len, "commands:\tenable, disable, reset\n"); |
| 486 | } |
| 487 | |
| 488 | return len; |
| 489 | } |
| 490 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 491 | static int hotkey_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | { |
| 493 | int status, mask; |
| 494 | char *cmd; |
| 495 | int do_cmd = 0; |
| 496 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 497 | if (!hotkey_supported) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | return -ENODEV; |
| 499 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 500 | if (!hotkey_get(&status, &mask)) |
| 501 | return -EIO; |
| 502 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | while ((cmd = next_cmd(&buf))) { |
| 504 | if (strlencmp(cmd, "enable") == 0) { |
| 505 | status = 1; |
| 506 | } else if (strlencmp(cmd, "disable") == 0) { |
| 507 | status = 0; |
| 508 | } else if (strlencmp(cmd, "reset") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 509 | status = hotkey_orig_status; |
| 510 | mask = hotkey_orig_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } else if (sscanf(cmd, "0x%x", &mask) == 1) { |
| 512 | /* mask set */ |
| 513 | } else if (sscanf(cmd, "%x", &mask) == 1) { |
| 514 | /* mask set */ |
| 515 | } else |
| 516 | return -EINVAL; |
| 517 | do_cmd = 1; |
| 518 | } |
| 519 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 520 | if (do_cmd && !hotkey_set(status, mask)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | return -EIO; |
| 522 | |
| 523 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 524 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 526 | static void hotkey_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 528 | if (hotkey_supported) |
| 529 | hotkey_set(hotkey_orig_status, hotkey_orig_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | } |
| 531 | |
| 532 | static void hotkey_notify(struct ibm_struct *ibm, u32 event) |
| 533 | { |
| 534 | int hkey; |
| 535 | |
| 536 | if (acpi_evalf(hkey_handle, &hkey, "MHKP", "d")) |
| 537 | acpi_bus_generate_event(ibm->device, event, hkey); |
| 538 | else { |
| 539 | printk(IBM_ERR "unknown hotkey event %d\n", event); |
| 540 | acpi_bus_generate_event(ibm->device, event, 0); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 541 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | } |
| 543 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 544 | static int bluetooth_supported; |
| 545 | |
| 546 | static int bluetooth_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 548 | /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 549 | G4x, R30, R31, R40e, R50e, T20-22, X20-21 */ |
| 550 | bluetooth_supported = hkey_handle && |
| 551 | acpi_evalf(hkey_handle, NULL, "GBDC", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | |
| 553 | return 0; |
| 554 | } |
| 555 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 556 | static int bluetooth_status(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | { |
| 558 | int status; |
| 559 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 560 | if (!bluetooth_supported || |
| 561 | !acpi_evalf(hkey_handle, &status, "GBDC", "d")) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | status = 0; |
| 563 | |
| 564 | return status; |
| 565 | } |
| 566 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 567 | static int bluetooth_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | { |
| 569 | int len = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 570 | int status = bluetooth_status(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 571 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 572 | if (!bluetooth_supported) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 574 | else if (!(status & 1)) |
| 575 | len += sprintf(p + len, "status:\t\tnot installed\n"); |
| 576 | else { |
| 577 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1)); |
| 578 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 579 | } |
| 580 | |
| 581 | return len; |
| 582 | } |
| 583 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 584 | static int bluetooth_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 586 | int status = bluetooth_status(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | char *cmd; |
| 588 | int do_cmd = 0; |
| 589 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 590 | if (!bluetooth_supported) |
| 591 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
| 593 | while ((cmd = next_cmd(&buf))) { |
| 594 | if (strlencmp(cmd, "enable") == 0) { |
| 595 | status |= 2; |
| 596 | } else if (strlencmp(cmd, "disable") == 0) { |
| 597 | status &= ~2; |
| 598 | } else |
| 599 | return -EINVAL; |
| 600 | do_cmd = 1; |
| 601 | } |
| 602 | |
| 603 | if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SBDC", "vd", status)) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 604 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | |
| 606 | return 0; |
| 607 | } |
| 608 | |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 609 | static int wan_supported; |
| 610 | |
| 611 | static int wan_init(void) |
| 612 | { |
| 613 | wan_supported = hkey_handle && |
| 614 | acpi_evalf(hkey_handle, NULL, "GWAN", "qv"); |
| 615 | |
| 616 | return 0; |
| 617 | } |
| 618 | |
| 619 | static int wan_status(void) |
| 620 | { |
| 621 | int status; |
| 622 | |
Henrique de Moraes Holschuh | 8d29726 | 2006-11-24 11:47:07 -0200 | [diff] [blame] | 623 | if (!wan_supported || !acpi_evalf(hkey_handle, &status, "GWAN", "d")) |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 624 | status = 0; |
| 625 | |
| 626 | return status; |
| 627 | } |
| 628 | |
| 629 | static int wan_read(char *p) |
| 630 | { |
| 631 | int len = 0; |
| 632 | int status = wan_status(); |
| 633 | |
| 634 | if (!wan_supported) |
| 635 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 636 | else if (!(status & 1)) |
| 637 | len += sprintf(p + len, "status:\t\tnot installed\n"); |
| 638 | else { |
| 639 | len += sprintf(p + len, "status:\t\t%s\n", enabled(status, 1)); |
| 640 | len += sprintf(p + len, "commands:\tenable, disable\n"); |
| 641 | } |
| 642 | |
| 643 | return len; |
| 644 | } |
| 645 | |
| 646 | static int wan_write(char *buf) |
| 647 | { |
| 648 | int status = wan_status(); |
| 649 | char *cmd; |
| 650 | int do_cmd = 0; |
| 651 | |
| 652 | if (!wan_supported) |
| 653 | return -ENODEV; |
| 654 | |
| 655 | while ((cmd = next_cmd(&buf))) { |
| 656 | if (strlencmp(cmd, "enable") == 0) { |
| 657 | status |= 2; |
| 658 | } else if (strlencmp(cmd, "disable") == 0) { |
| 659 | status &= ~2; |
| 660 | } else |
| 661 | return -EINVAL; |
| 662 | do_cmd = 1; |
| 663 | } |
| 664 | |
| 665 | if (do_cmd && !acpi_evalf(hkey_handle, NULL, "SWAN", "vd", status)) |
| 666 | return -EIO; |
| 667 | |
| 668 | return 0; |
| 669 | } |
| 670 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 671 | static enum video_access_mode video_supported; |
| 672 | static int video_orig_autosw; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 673 | |
| 674 | static int video_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 676 | int ivga; |
| 677 | |
| 678 | if (vid2_handle && acpi_evalf(NULL, &ivga, "\\IVGA", "d") && ivga) |
| 679 | /* G41, assume IVGA doesn't change */ |
| 680 | vid_handle = vid2_handle; |
| 681 | |
| 682 | if (!vid_handle) |
| 683 | /* video switching not supported on R30, R31 */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 684 | video_supported = IBMACPI_VIDEO_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 685 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "SWIT", "qd")) |
| 686 | /* 570 */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 687 | video_supported = IBMACPI_VIDEO_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 688 | else if (acpi_evalf(vid_handle, &video_orig_autosw, "^VADL", "qd")) |
| 689 | /* 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 690 | video_supported = IBMACPI_VIDEO_770; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 691 | else |
| 692 | /* all others */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 693 | video_supported = IBMACPI_VIDEO_NEW; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | |
| 695 | return 0; |
| 696 | } |
| 697 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 698 | static int video_status(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 699 | { |
| 700 | int status = 0; |
| 701 | int i; |
| 702 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 703 | if (video_supported == IBMACPI_VIDEO_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 704 | if (acpi_evalf(NULL, &i, "\\_SB.PHS", "dd", 0x87)) |
| 705 | status = i & 3; |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 706 | } else if (video_supported == IBMACPI_VIDEO_770) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 707 | if (acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 708 | status |= 0x01 * i; |
| 709 | if (acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 710 | status |= 0x02 * i; |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 711 | } else if (video_supported == IBMACPI_VIDEO_NEW) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 712 | acpi_evalf(NULL, NULL, "\\VUPS", "vd", 1); |
| 713 | if (acpi_evalf(NULL, &i, "\\VCDC", "d")) |
| 714 | status |= 0x02 * i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 716 | acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0); |
| 717 | if (acpi_evalf(NULL, &i, "\\VCDL", "d")) |
| 718 | status |= 0x01 * i; |
| 719 | if (acpi_evalf(NULL, &i, "\\VCDD", "d")) |
| 720 | status |= 0x08 * i; |
| 721 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | |
| 723 | return status; |
| 724 | } |
| 725 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 726 | static int video_autosw(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 728 | int autosw = 0; |
| 729 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 730 | if (video_supported == IBMACPI_VIDEO_570) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 731 | acpi_evalf(vid_handle, &autosw, "SWIT", "d"); |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 732 | else if (video_supported == IBMACPI_VIDEO_770 || |
| 733 | video_supported == IBMACPI_VIDEO_NEW) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 734 | acpi_evalf(vid_handle, &autosw, "^VDEE", "d"); |
| 735 | |
| 736 | return autosw & 1; |
| 737 | } |
| 738 | |
| 739 | static int video_read(char *p) |
| 740 | { |
| 741 | int status = video_status(); |
| 742 | int autosw = video_autosw(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 743 | int len = 0; |
| 744 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 745 | if (!video_supported) { |
| 746 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 747 | return len; |
| 748 | } |
| 749 | |
| 750 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | len += sprintf(p + len, "lcd:\t\t%s\n", enabled(status, 0)); |
| 752 | len += sprintf(p + len, "crt:\t\t%s\n", enabled(status, 1)); |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 753 | if (video_supported == IBMACPI_VIDEO_NEW) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 754 | len += sprintf(p + len, "dvi:\t\t%s\n", enabled(status, 3)); |
| 755 | len += sprintf(p + len, "auto:\t\t%s\n", enabled(autosw, 0)); |
| 756 | len += sprintf(p + len, "commands:\tlcd_enable, lcd_disable\n"); |
| 757 | len += sprintf(p + len, "commands:\tcrt_enable, crt_disable\n"); |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 758 | if (video_supported == IBMACPI_VIDEO_NEW) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 759 | len += sprintf(p + len, "commands:\tdvi_enable, dvi_disable\n"); |
| 760 | len += sprintf(p + len, "commands:\tauto_enable, auto_disable\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | len += sprintf(p + len, "commands:\tvideo_switch, expand_toggle\n"); |
| 762 | |
| 763 | return len; |
| 764 | } |
| 765 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 766 | static int video_switch(void) |
| 767 | { |
| 768 | int autosw = video_autosw(); |
| 769 | int ret; |
| 770 | |
| 771 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) |
| 772 | return -EIO; |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 773 | ret = video_supported == IBMACPI_VIDEO_570 ? |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 774 | acpi_evalf(ec_handle, NULL, "_Q16", "v") : |
| 775 | acpi_evalf(vid_handle, NULL, "VSWT", "v"); |
| 776 | acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw); |
| 777 | |
| 778 | return ret; |
| 779 | } |
| 780 | |
| 781 | static int video_expand(void) |
| 782 | { |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 783 | if (video_supported == IBMACPI_VIDEO_570) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 784 | return acpi_evalf(ec_handle, NULL, "_Q17", "v"); |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 785 | else if (video_supported == IBMACPI_VIDEO_770) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 786 | return acpi_evalf(vid_handle, NULL, "VEXP", "v"); |
| 787 | else |
| 788 | return acpi_evalf(NULL, NULL, "\\VEXP", "v"); |
| 789 | } |
| 790 | |
| 791 | static int video_switch2(int status) |
| 792 | { |
| 793 | int ret; |
| 794 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 795 | if (video_supported == IBMACPI_VIDEO_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 796 | ret = acpi_evalf(NULL, NULL, |
| 797 | "\\_SB.PHS2", "vdd", 0x8b, status | 0x80); |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 798 | } else if (video_supported == IBMACPI_VIDEO_770) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 799 | int autosw = video_autosw(); |
| 800 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) |
| 801 | return -EIO; |
| 802 | |
| 803 | ret = acpi_evalf(vid_handle, NULL, |
| 804 | "ASWT", "vdd", status * 0x100, 0); |
| 805 | |
| 806 | acpi_evalf(vid_handle, NULL, "_DOS", "vd", autosw); |
| 807 | } else { |
| 808 | ret = acpi_evalf(NULL, NULL, "\\VUPS", "vd", 0x80) && |
| 809 | acpi_evalf(NULL, NULL, "\\VSDS", "vdd", status, 1); |
| 810 | } |
| 811 | |
| 812 | return ret; |
| 813 | } |
| 814 | |
| 815 | static int video_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 816 | { |
| 817 | char *cmd; |
| 818 | int enable, disable, status; |
| 819 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 820 | if (!video_supported) |
| 821 | return -ENODEV; |
| 822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | enable = disable = 0; |
| 824 | |
| 825 | while ((cmd = next_cmd(&buf))) { |
| 826 | if (strlencmp(cmd, "lcd_enable") == 0) { |
| 827 | enable |= 0x01; |
| 828 | } else if (strlencmp(cmd, "lcd_disable") == 0) { |
| 829 | disable |= 0x01; |
| 830 | } else if (strlencmp(cmd, "crt_enable") == 0) { |
| 831 | enable |= 0x02; |
| 832 | } else if (strlencmp(cmd, "crt_disable") == 0) { |
| 833 | disable |= 0x02; |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 834 | } else if (video_supported == IBMACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 835 | strlencmp(cmd, "dvi_enable") == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | enable |= 0x08; |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 837 | } else if (video_supported == IBMACPI_VIDEO_NEW && |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 838 | strlencmp(cmd, "dvi_disable") == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 839 | disable |= 0x08; |
| 840 | } else if (strlencmp(cmd, "auto_enable") == 0) { |
| 841 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 1)) |
| 842 | return -EIO; |
| 843 | } else if (strlencmp(cmd, "auto_disable") == 0) { |
| 844 | if (!acpi_evalf(vid_handle, NULL, "_DOS", "vd", 0)) |
| 845 | return -EIO; |
| 846 | } else if (strlencmp(cmd, "video_switch") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 847 | if (!video_switch()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | return -EIO; |
| 849 | } else if (strlencmp(cmd, "expand_toggle") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 850 | if (!video_expand()) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | return -EIO; |
| 852 | } else |
| 853 | return -EINVAL; |
| 854 | } |
| 855 | |
| 856 | if (enable || disable) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 857 | status = (video_status() & 0x0f & ~disable) | enable; |
| 858 | if (!video_switch2(status)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 859 | return -EIO; |
| 860 | } |
| 861 | |
| 862 | return 0; |
| 863 | } |
| 864 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 865 | static void video_exit(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 867 | acpi_evalf(vid_handle, NULL, "_DOS", "vd", video_orig_autosw); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | } |
| 869 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 870 | static int light_supported; |
| 871 | static int light_status_supported; |
| 872 | |
| 873 | static int light_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 874 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 875 | /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */ |
| 876 | light_supported = (cmos_handle || lght_handle) && !ledb_handle; |
| 877 | |
| 878 | if (light_supported) |
| 879 | /* light status not supported on |
| 880 | 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */ |
| 881 | light_status_supported = acpi_evalf(ec_handle, NULL, |
| 882 | "KBLT", "qv"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | |
| 884 | return 0; |
| 885 | } |
| 886 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 887 | static int light_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 888 | { |
| 889 | int len = 0; |
| 890 | int status = 0; |
| 891 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 892 | if (!light_supported) { |
| 893 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 894 | } else if (!light_status_supported) { |
| 895 | len += sprintf(p + len, "status:\t\tunknown\n"); |
| 896 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 897 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | if (!acpi_evalf(ec_handle, &status, "KBLT", "d")) |
| 899 | return -EIO; |
| 900 | len += sprintf(p + len, "status:\t\t%s\n", onoff(status, 0)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 901 | len += sprintf(p + len, "commands:\ton, off\n"); |
| 902 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | |
| 904 | return len; |
| 905 | } |
| 906 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 907 | static int light_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | { |
| 909 | int cmos_cmd, lght_cmd; |
| 910 | char *cmd; |
| 911 | int success; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 912 | |
| 913 | if (!light_supported) |
| 914 | return -ENODEV; |
| 915 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | while ((cmd = next_cmd(&buf))) { |
| 917 | if (strlencmp(cmd, "on") == 0) { |
| 918 | cmos_cmd = 0x0c; |
| 919 | lght_cmd = 1; |
| 920 | } else if (strlencmp(cmd, "off") == 0) { |
| 921 | cmos_cmd = 0x0d; |
| 922 | lght_cmd = 0; |
| 923 | } else |
| 924 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 926 | success = cmos_handle ? |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 927 | acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd) : |
| 928 | acpi_evalf(lght_handle, NULL, NULL, "vd", lght_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 929 | if (!success) |
| 930 | return -EIO; |
| 931 | } |
| 932 | |
| 933 | return 0; |
| 934 | } |
| 935 | |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 936 | #if defined(CONFIG_ACPI_IBM_DOCK) || defined(CONFIG_ACPI_IBM_BAY) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 937 | static int _sta(acpi_handle handle) |
| 938 | { |
| 939 | int status; |
| 940 | |
| 941 | if (!handle || !acpi_evalf(handle, &status, "_STA", "d")) |
| 942 | status = 0; |
| 943 | |
| 944 | return status; |
| 945 | } |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 946 | #endif |
Henrique de Moraes Holschuh | d2fadbb | 2007-01-11 02:58:15 -0500 | [diff] [blame] | 947 | |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 948 | #ifdef CONFIG_ACPI_IBM_DOCK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 949 | #define dock_docked() (_sta(dock_handle) & 1) |
| 950 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 951 | static int dock_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 952 | { |
| 953 | int len = 0; |
| 954 | int docked = dock_docked(); |
| 955 | |
| 956 | if (!dock_handle) |
| 957 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 958 | else if (!docked) |
| 959 | len += sprintf(p + len, "status:\t\tundocked\n"); |
| 960 | else { |
| 961 | len += sprintf(p + len, "status:\t\tdocked\n"); |
| 962 | len += sprintf(p + len, "commands:\tdock, undock\n"); |
| 963 | } |
| 964 | |
| 965 | return len; |
| 966 | } |
| 967 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 968 | static int dock_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | { |
| 970 | char *cmd; |
| 971 | |
| 972 | if (!dock_docked()) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 973 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | |
| 975 | while ((cmd = next_cmd(&buf))) { |
| 976 | if (strlencmp(cmd, "undock") == 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 977 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 0) || |
| 978 | !acpi_evalf(dock_handle, NULL, "_EJ0", "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 979 | return -EIO; |
| 980 | } else if (strlencmp(cmd, "dock") == 0) { |
| 981 | if (!acpi_evalf(dock_handle, NULL, "_DCK", "vd", 1)) |
| 982 | return -EIO; |
| 983 | } else |
| 984 | return -EINVAL; |
| 985 | } |
| 986 | |
| 987 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 988 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 989 | |
| 990 | static void dock_notify(struct ibm_struct *ibm, u32 event) |
| 991 | { |
| 992 | int docked = dock_docked(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 993 | int pci = ibm->hid && strstr(ibm->hid, IBM_PCI_HID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 994 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 995 | if (event == 1 && !pci) /* 570 */ |
| 996 | acpi_bus_generate_event(ibm->device, event, 1); /* button */ |
| 997 | else if (event == 1 && pci) /* 570 */ |
| 998 | acpi_bus_generate_event(ibm->device, event, 3); /* dock */ |
| 999 | else if (event == 3 && docked) |
| 1000 | acpi_bus_generate_event(ibm->device, event, 1); /* button */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1001 | else if (event == 3 && !docked) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1002 | acpi_bus_generate_event(ibm->device, event, 2); /* undock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | else if (event == 0 && docked) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1004 | acpi_bus_generate_event(ibm->device, event, 3); /* dock */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1005 | else { |
| 1006 | printk(IBM_ERR "unknown dock event %d, status %d\n", |
| 1007 | event, _sta(dock_handle)); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1008 | acpi_bus_generate_event(ibm->device, event, 0); /* unknown */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | } |
| 1010 | } |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 1011 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1012 | |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 1013 | #ifdef CONFIG_ACPI_IBM_BAY |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1014 | static int bay_status_supported; |
| 1015 | static int bay_status2_supported; |
| 1016 | static int bay_eject_supported; |
| 1017 | static int bay_eject2_supported; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1018 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1019 | static int bay_init(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1020 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1021 | bay_status_supported = bay_handle && |
| 1022 | acpi_evalf(bay_handle, NULL, "_STA", "qv"); |
| 1023 | bay_status2_supported = bay2_handle && |
| 1024 | acpi_evalf(bay2_handle, NULL, "_STA", "qv"); |
| 1025 | |
| 1026 | bay_eject_supported = bay_handle && bay_ej_handle && |
| 1027 | (strlencmp(bay_ej_path, "_EJ0") == 0 || experimental); |
| 1028 | bay_eject2_supported = bay2_handle && bay2_ej_handle && |
| 1029 | (strlencmp(bay2_ej_path, "_EJ0") == 0 || experimental); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
| 1031 | return 0; |
| 1032 | } |
| 1033 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1034 | #define bay_occupied(b) (_sta(b##_handle) & 1) |
| 1035 | |
| 1036 | static int bay_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | { |
| 1038 | int len = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1039 | int occupied = bay_occupied(bay); |
| 1040 | int occupied2 = bay_occupied(bay2); |
| 1041 | int eject, eject2; |
| 1042 | |
| 1043 | len += sprintf(p + len, "status:\t\t%s\n", bay_status_supported ? |
| 1044 | (occupied ? "occupied" : "unoccupied") : |
| 1045 | "not supported"); |
| 1046 | if (bay_status2_supported) |
| 1047 | len += sprintf(p + len, "status2:\t%s\n", occupied2 ? |
| 1048 | "occupied" : "unoccupied"); |
| 1049 | |
| 1050 | eject = bay_eject_supported && occupied; |
| 1051 | eject2 = bay_eject2_supported && occupied2; |
| 1052 | |
| 1053 | if (eject && eject2) |
| 1054 | len += sprintf(p + len, "commands:\teject, eject2\n"); |
| 1055 | else if (eject) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | len += sprintf(p + len, "commands:\teject\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1057 | else if (eject2) |
| 1058 | len += sprintf(p + len, "commands:\teject2\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | |
| 1060 | return len; |
| 1061 | } |
| 1062 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1063 | static int bay_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1064 | { |
| 1065 | char *cmd; |
| 1066 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1067 | if (!bay_eject_supported && !bay_eject2_supported) |
| 1068 | return -ENODEV; |
| 1069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1070 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1071 | if (bay_eject_supported && strlencmp(cmd, "eject") == 0) { |
| 1072 | if (!acpi_evalf(bay_ej_handle, NULL, NULL, "vd", 1)) |
| 1073 | return -EIO; |
| 1074 | } else if (bay_eject2_supported && |
| 1075 | strlencmp(cmd, "eject2") == 0) { |
| 1076 | if (!acpi_evalf(bay2_ej_handle, NULL, NULL, "vd", 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | return -EIO; |
| 1078 | } else |
| 1079 | return -EINVAL; |
| 1080 | } |
| 1081 | |
| 1082 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1083 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | |
| 1085 | static void bay_notify(struct ibm_struct *ibm, u32 event) |
| 1086 | { |
| 1087 | acpi_bus_generate_event(ibm->device, event, 0); |
| 1088 | } |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 1089 | #endif /* CONFIG_ACPI_IBM_BAY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1090 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1091 | static int cmos_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | { |
| 1093 | int len = 0; |
| 1094 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1095 | /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p, |
| 1096 | R30, R31, T20-22, X20-21 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1097 | if (!cmos_handle) |
| 1098 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1099 | else { |
| 1100 | len += sprintf(p + len, "status:\t\tsupported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1101 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-21)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | return len; |
| 1105 | } |
| 1106 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1107 | static int cmos_eval(int cmos_cmd) |
| 1108 | { |
| 1109 | if (cmos_handle) |
| 1110 | return acpi_evalf(cmos_handle, NULL, NULL, "vd", cmos_cmd); |
| 1111 | else |
| 1112 | return 1; |
| 1113 | } |
| 1114 | |
| 1115 | static int cmos_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | { |
| 1117 | char *cmd; |
| 1118 | int cmos_cmd; |
| 1119 | |
| 1120 | if (!cmos_handle) |
| 1121 | return -EINVAL; |
| 1122 | |
| 1123 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1124 | if (sscanf(cmd, "%u", &cmos_cmd) == 1 && |
| 1125 | cmos_cmd >= 0 && cmos_cmd <= 21) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1126 | /* cmos_cmd set */ |
| 1127 | } else |
| 1128 | return -EINVAL; |
| 1129 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1130 | if (!cmos_eval(cmos_cmd)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | return -EIO; |
| 1132 | } |
| 1133 | |
| 1134 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1135 | } |
| 1136 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1137 | static enum led_access_mode led_supported; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1138 | |
| 1139 | static int led_init(void) |
| 1140 | { |
| 1141 | if (!led_handle) |
| 1142 | /* led not supported on R30, R31 */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1143 | led_supported = IBMACPI_LED_NONE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1144 | else if (strlencmp(led_path, "SLED") == 0) |
| 1145 | /* 570 */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1146 | led_supported = IBMACPI_LED_570; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1147 | else if (strlencmp(led_path, "SYSL") == 0) |
| 1148 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1149 | led_supported = IBMACPI_LED_OLD; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1150 | else |
| 1151 | /* all others */ |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1152 | led_supported = IBMACPI_LED_NEW; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1153 | |
| 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking")) |
| 1158 | |
| 1159 | static int led_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | { |
| 1161 | int len = 0; |
| 1162 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1163 | if (!led_supported) { |
| 1164 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1165 | return len; |
| 1166 | } |
| 1167 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 1168 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1169 | if (led_supported == IBMACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1170 | /* 570 */ |
| 1171 | int i, status; |
| 1172 | for (i = 0; i < 8; i++) { |
| 1173 | if (!acpi_evalf(ec_handle, |
| 1174 | &status, "GLED", "dd", 1 << i)) |
| 1175 | return -EIO; |
| 1176 | len += sprintf(p + len, "%d:\t\t%s\n", |
| 1177 | i, led_status(status)); |
| 1178 | } |
| 1179 | } |
| 1180 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | len += sprintf(p + len, "commands:\t" |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1182 | "<led> on, <led> off, <led> blink (<led> is 0-7)\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | |
| 1184 | return len; |
| 1185 | } |
| 1186 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1187 | /* off, on, blink */ |
| 1188 | static const int led_sled_arg1[] = { 0, 1, 3 }; |
| 1189 | static const int led_exp_hlbl[] = { 0, 0, 1 }; /* led# * */ |
| 1190 | static const int led_exp_hlcl[] = { 0, 1, 1 }; /* led# * */ |
| 1191 | static const int led_led_arg1[] = { 0, 0x80, 0xc0 }; |
| 1192 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1193 | static int led_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1194 | { |
| 1195 | char *cmd; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1196 | int led, ind, ret; |
| 1197 | |
| 1198 | if (!led_supported) |
| 1199 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1200 | |
| 1201 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1202 | if (sscanf(cmd, "%d", &led) != 1 || led < 0 || led > 7) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1203 | return -EINVAL; |
| 1204 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1205 | if (strstr(cmd, "off")) { |
| 1206 | ind = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1207 | } else if (strstr(cmd, "on")) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1208 | ind = 1; |
| 1209 | } else if (strstr(cmd, "blink")) { |
| 1210 | ind = 2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | } else |
| 1212 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1213 | |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1214 | if (led_supported == IBMACPI_LED_570) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1215 | /* 570 */ |
| 1216 | led = 1 << led; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1218 | led, led_sled_arg1[ind])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1219 | return -EIO; |
Henrique de Moraes Holschuh | 9a8e173 | 2006-11-25 16:36:00 -0200 | [diff] [blame] | 1220 | } else if (led_supported == IBMACPI_LED_OLD) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1221 | /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */ |
| 1222 | led = 1 << led; |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1223 | ret = ec_write(IBMACPI_LED_EC_HLMS, led); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1224 | if (ret >= 0) |
| 1225 | ret = |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1226 | ec_write(IBMACPI_LED_EC_HLBL, |
| 1227 | led * led_exp_hlbl[ind]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1228 | if (ret >= 0) |
| 1229 | ret = |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1230 | ec_write(IBMACPI_LED_EC_HLCL, |
| 1231 | led * led_exp_hlcl[ind]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1232 | if (ret < 0) |
| 1233 | return ret; |
| 1234 | } else { |
| 1235 | /* all others */ |
| 1236 | if (!acpi_evalf(led_handle, NULL, NULL, "vdd", |
| 1237 | led, led_led_arg1[ind])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | return -EIO; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1239 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1240 | } |
| 1241 | |
| 1242 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1243 | } |
| 1244 | |
| 1245 | static int beep_read(char *p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1246 | { |
| 1247 | int len = 0; |
| 1248 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1249 | if (!beep_handle) |
| 1250 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
| 1251 | else { |
| 1252 | len += sprintf(p + len, "status:\t\tsupported\n"); |
| 1253 | len += sprintf(p + len, "commands:\t<cmd> (<cmd> is 0-17)\n"); |
| 1254 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | |
| 1256 | return len; |
| 1257 | } |
| 1258 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1259 | static int beep_write(char *buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1260 | { |
| 1261 | char *cmd; |
| 1262 | int beep_cmd; |
| 1263 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1264 | if (!beep_handle) |
| 1265 | return -ENODEV; |
| 1266 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1267 | while ((cmd = next_cmd(&buf))) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1268 | if (sscanf(cmd, "%u", &beep_cmd) == 1 && |
| 1269 | beep_cmd >= 0 && beep_cmd <= 17) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1270 | /* beep_cmd set */ |
| 1271 | } else |
| 1272 | return -EINVAL; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1273 | if (!acpi_evalf(beep_handle, NULL, NULL, "vdd", beep_cmd, 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | return -EIO; |
| 1275 | } |
| 1276 | |
| 1277 | return 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1278 | } |
| 1279 | |
| 1280 | static int acpi_ec_read(int i, u8 * p) |
| 1281 | { |
| 1282 | int v; |
| 1283 | |
| 1284 | if (ecrd_handle) { |
| 1285 | if (!acpi_evalf(ecrd_handle, &v, NULL, "dd", i)) |
| 1286 | return 0; |
| 1287 | *p = v; |
| 1288 | } else { |
| 1289 | if (ec_read(i, p) < 0) |
| 1290 | return 0; |
| 1291 | } |
| 1292 | |
| 1293 | return 1; |
| 1294 | } |
| 1295 | |
| 1296 | static int acpi_ec_write(int i, u8 v) |
| 1297 | { |
| 1298 | if (ecwr_handle) { |
| 1299 | if (!acpi_evalf(ecwr_handle, NULL, NULL, "vdd", i, v)) |
| 1300 | return 0; |
| 1301 | } else { |
| 1302 | if (ec_write(i, v) < 0) |
| 1303 | return 0; |
| 1304 | } |
| 1305 | |
| 1306 | return 1; |
| 1307 | } |
| 1308 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1309 | static enum thermal_access_mode thermal_read_mode; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1310 | |
| 1311 | static int thermal_init(void) |
| 1312 | { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1313 | u8 t, ta1, ta2; |
| 1314 | int i; |
| 1315 | int acpi_tmp7 = acpi_evalf(ec_handle, NULL, "TMP7", "qv"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1316 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1317 | if (ibm_thinkpad_ec_found && experimental) { |
| 1318 | /* |
| 1319 | * Direct EC access mode: sensors at registers |
| 1320 | * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for |
| 1321 | * non-implemented, thermal sensors return 0x80 when |
| 1322 | * not available |
| 1323 | */ |
| 1324 | |
| 1325 | ta1 = ta2 = 0; |
| 1326 | for (i = 0; i < 8; i++) { |
| 1327 | if (likely(acpi_ec_read(0x78 + i, &t))) { |
| 1328 | ta1 |= t; |
| 1329 | } else { |
| 1330 | ta1 = 0; |
| 1331 | break; |
| 1332 | } |
| 1333 | if (likely(acpi_ec_read(0xC0 + i, &t))) { |
| 1334 | ta2 |= t; |
| 1335 | } else { |
| 1336 | ta1 = 0; |
| 1337 | break; |
| 1338 | } |
| 1339 | } |
| 1340 | if (ta1 == 0) { |
| 1341 | /* This is sheer paranoia, but we handle it anyway */ |
| 1342 | if (acpi_tmp7) { |
| 1343 | printk(IBM_ERR |
| 1344 | "ThinkPad ACPI EC access misbehaving, " |
| 1345 | "falling back to ACPI TMPx access mode\n"); |
| 1346 | thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07; |
| 1347 | } else { |
| 1348 | printk(IBM_ERR |
| 1349 | "ThinkPad ACPI EC access misbehaving, " |
| 1350 | "disabling thermal sensors access\n"); |
| 1351 | thermal_read_mode = IBMACPI_THERMAL_NONE; |
| 1352 | } |
| 1353 | } else { |
| 1354 | thermal_read_mode = |
| 1355 | (ta2 != 0) ? |
| 1356 | IBMACPI_THERMAL_TPEC_16 : IBMACPI_THERMAL_TPEC_8; |
| 1357 | } |
| 1358 | } else if (acpi_tmp7) { |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1359 | if (acpi_evalf(ec_handle, NULL, "UPDT", "qv")) { |
| 1360 | /* 600e/x, 770e, 770x */ |
| 1361 | thermal_read_mode = IBMACPI_THERMAL_ACPI_UPDT; |
| 1362 | } else { |
| 1363 | /* Standard ACPI TMPx access, max 8 sensors */ |
| 1364 | thermal_read_mode = IBMACPI_THERMAL_ACPI_TMP07; |
| 1365 | } |
| 1366 | } else { |
| 1367 | /* temperatures not supported on 570, G4x, R30, R31, R32 */ |
| 1368 | thermal_read_mode = IBMACPI_THERMAL_NONE; |
| 1369 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1370 | |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1374 | static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s) |
| 1375 | { |
| 1376 | int i, t; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1377 | s8 tmp; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1378 | char tmpi[] = "TMPi"; |
| 1379 | |
| 1380 | if (!s) |
| 1381 | return -EINVAL; |
| 1382 | |
| 1383 | switch (thermal_read_mode) { |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1384 | #if IBMACPI_MAX_THERMAL_SENSORS >= 16 |
| 1385 | case IBMACPI_THERMAL_TPEC_16: |
| 1386 | for (i = 0; i < 8; i++) { |
| 1387 | if (!acpi_ec_read(0xC0 + i, &tmp)) |
| 1388 | return -EIO; |
| 1389 | s->temp[i + 8] = tmp * 1000; |
| 1390 | } |
| 1391 | /* fallthrough */ |
| 1392 | #endif |
| 1393 | case IBMACPI_THERMAL_TPEC_8: |
| 1394 | for (i = 0; i < 8; i++) { |
| 1395 | if (!acpi_ec_read(0x78 + i, &tmp)) |
| 1396 | return -EIO; |
| 1397 | s->temp[i] = tmp * 1000; |
| 1398 | } |
| 1399 | return (thermal_read_mode == IBMACPI_THERMAL_TPEC_16) ? 16 : 8; |
| 1400 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1401 | case IBMACPI_THERMAL_ACPI_UPDT: |
| 1402 | if (!acpi_evalf(ec_handle, NULL, "UPDT", "v")) |
| 1403 | return -EIO; |
| 1404 | for (i = 0; i < 8; i++) { |
| 1405 | tmpi[3] = '0' + i; |
| 1406 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 1407 | return -EIO; |
| 1408 | s->temp[i] = (t - 2732) * 100; |
| 1409 | } |
| 1410 | return 8; |
| 1411 | |
| 1412 | case IBMACPI_THERMAL_ACPI_TMP07: |
| 1413 | for (i = 0; i < 8; i++) { |
| 1414 | tmpi[3] = '0' + i; |
| 1415 | if (!acpi_evalf(ec_handle, &t, tmpi, "d")) |
| 1416 | return -EIO; |
| 1417 | s->temp[i] = t * 1000; |
| 1418 | } |
| 1419 | return 8; |
| 1420 | |
| 1421 | case IBMACPI_THERMAL_NONE: |
| 1422 | default: |
| 1423 | return 0; |
| 1424 | } |
| 1425 | } |
| 1426 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1427 | static int thermal_read(char *p) |
| 1428 | { |
| 1429 | int len = 0; |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1430 | int n, i; |
| 1431 | struct ibm_thermal_sensors_struct t; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1432 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1433 | n = thermal_get_sensors(&t); |
| 1434 | if (unlikely(n < 0)) |
| 1435 | return n; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1436 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1437 | len += sprintf(p + len, "temperatures:\t"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1438 | |
Henrique de Moraes Holschuh | a26f878 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 1439 | if (n > 0) { |
| 1440 | for (i = 0; i < (n - 1); i++) |
| 1441 | len += sprintf(p + len, "%d ", t.temp[i] / 1000); |
| 1442 | len += sprintf(p + len, "%d\n", t.temp[i] / 1000); |
| 1443 | } else |
| 1444 | len += sprintf(p + len, "not supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1445 | |
| 1446 | return len; |
| 1447 | } |
| 1448 | |
| 1449 | static u8 ecdump_regs[256]; |
| 1450 | |
| 1451 | static int ecdump_read(char *p) |
| 1452 | { |
| 1453 | int len = 0; |
| 1454 | int i, j; |
| 1455 | u8 v; |
| 1456 | |
| 1457 | len += sprintf(p + len, "EC " |
| 1458 | " +00 +01 +02 +03 +04 +05 +06 +07" |
| 1459 | " +08 +09 +0a +0b +0c +0d +0e +0f\n"); |
| 1460 | for (i = 0; i < 256; i += 16) { |
| 1461 | len += sprintf(p + len, "EC 0x%02x:", i); |
| 1462 | for (j = 0; j < 16; j++) { |
| 1463 | if (!acpi_ec_read(i + j, &v)) |
| 1464 | break; |
| 1465 | if (v != ecdump_regs[i + j]) |
| 1466 | len += sprintf(p + len, " *%02x", v); |
| 1467 | else |
| 1468 | len += sprintf(p + len, " %02x", v); |
| 1469 | ecdump_regs[i + j] = v; |
| 1470 | } |
| 1471 | len += sprintf(p + len, "\n"); |
| 1472 | if (j != 16) |
| 1473 | break; |
| 1474 | } |
| 1475 | |
| 1476 | /* These are way too dangerous to advertise openly... */ |
| 1477 | #if 0 |
| 1478 | len += sprintf(p + len, "commands:\t0x<offset> 0x<value>" |
| 1479 | " (<offset> is 00-ff, <value> is 00-ff)\n"); |
| 1480 | len += sprintf(p + len, "commands:\t0x<offset> <value> " |
| 1481 | " (<offset> is 00-ff, <value> is 0-255)\n"); |
| 1482 | #endif |
| 1483 | return len; |
| 1484 | } |
| 1485 | |
| 1486 | static int ecdump_write(char *buf) |
| 1487 | { |
| 1488 | char *cmd; |
| 1489 | int i, v; |
| 1490 | |
| 1491 | while ((cmd = next_cmd(&buf))) { |
| 1492 | if (sscanf(cmd, "0x%x 0x%x", &i, &v) == 2) { |
| 1493 | /* i and v set */ |
| 1494 | } else if (sscanf(cmd, "0x%x %u", &i, &v) == 2) { |
| 1495 | /* i and v set */ |
| 1496 | } else |
| 1497 | return -EINVAL; |
| 1498 | if (i >= 0 && i < 256 && v >= 0 && v < 256) { |
| 1499 | if (!acpi_ec_write(i, v)) |
| 1500 | return -EIO; |
| 1501 | } else |
| 1502 | return -EINVAL; |
| 1503 | } |
| 1504 | |
| 1505 | return 0; |
| 1506 | } |
| 1507 | |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1508 | static int brightness_get(struct backlight_device *bd) |
| 1509 | { |
Henrique de Moraes Holschuh | 8d29726 | 2006-11-24 11:47:07 -0200 | [diff] [blame] | 1510 | u8 level; |
| 1511 | if (!acpi_ec_read(brightness_offset, &level)) |
| 1512 | return -EIO; |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1513 | |
Henrique de Moraes Holschuh | 8d29726 | 2006-11-24 11:47:07 -0200 | [diff] [blame] | 1514 | level &= 0x7; |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 1515 | |
Henrique de Moraes Holschuh | 8d29726 | 2006-11-24 11:47:07 -0200 | [diff] [blame] | 1516 | return level; |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1517 | } |
| 1518 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1519 | static int brightness_read(char *p) |
| 1520 | { |
| 1521 | int len = 0; |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1522 | int level; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1523 | |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1524 | if ((level = brightness_get(NULL)) < 0) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1525 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 1526 | } else { |
| 1527 | len += sprintf(p + len, "level:\t\t%d\n", level & 0x7); |
| 1528 | len += sprintf(p + len, "commands:\tup, down\n"); |
| 1529 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 1530 | " (<level> is 0-7)\n"); |
| 1531 | } |
| 1532 | |
| 1533 | return len; |
| 1534 | } |
| 1535 | |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1536 | static int brightness_set(int value) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1537 | { |
| 1538 | int cmos_cmd, inc, i; |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1539 | int current_value = brightness_get(NULL); |
| 1540 | |
| 1541 | value &= 7; |
| 1542 | |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1543 | cmos_cmd = value > current_value ? |
| 1544 | TP_CMOS_BRIGHTNESS_UP : TP_CMOS_BRIGHTNESS_DOWN; |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1545 | inc = value > current_value ? 1 : -1; |
| 1546 | for (i = current_value; i != value; i += inc) { |
| 1547 | if (!cmos_eval(cmos_cmd)) |
| 1548 | return -EIO; |
| 1549 | if (!acpi_ec_write(brightness_offset, i + inc)) |
| 1550 | return -EIO; |
| 1551 | } |
| 1552 | |
| 1553 | return 0; |
| 1554 | } |
| 1555 | |
| 1556 | static int brightness_write(char *buf) |
| 1557 | { |
| 1558 | int level; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1559 | int new_level; |
| 1560 | char *cmd; |
| 1561 | |
| 1562 | while ((cmd = next_cmd(&buf))) { |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1563 | if ((level = brightness_get(NULL)) < 0) |
| 1564 | return level; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1565 | level &= 7; |
| 1566 | |
| 1567 | if (strlencmp(cmd, "up") == 0) { |
| 1568 | new_level = level == 7 ? 7 : level + 1; |
| 1569 | } else if (strlencmp(cmd, "down") == 0) { |
| 1570 | new_level = level == 0 ? 0 : level - 1; |
| 1571 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 1572 | new_level >= 0 && new_level <= 7) { |
| 1573 | /* new_level set */ |
| 1574 | } else |
| 1575 | return -EINVAL; |
| 1576 | |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1577 | brightness_set(new_level); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1578 | } |
| 1579 | |
| 1580 | return 0; |
| 1581 | } |
| 1582 | |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1583 | static int brightness_update_status(struct backlight_device *bd) |
| 1584 | { |
Henrique de Moraes Holschuh | c9bf296 | 2007-03-08 05:28:15 -0300 | [diff] [blame] | 1585 | return brightness_set( |
| 1586 | (bd->props.fb_blank == FB_BLANK_UNBLANK && |
| 1587 | bd->props.power == FB_BLANK_UNBLANK) ? |
| 1588 | bd->props.brightness : 0); |
Holger Macht | 8acb025 | 2006-10-20 14:30:28 -0700 | [diff] [blame] | 1589 | } |
| 1590 | |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 1591 | static struct backlight_ops ibm_backlight_data = { |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 1592 | .get_brightness = brightness_get, |
| 1593 | .update_status = brightness_update_status, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 1594 | }; |
| 1595 | |
| 1596 | static int brightness_init(void) |
| 1597 | { |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 1598 | int b; |
| 1599 | |
| 1600 | b = brightness_get(NULL); |
| 1601 | if (b < 0) |
| 1602 | return b; |
| 1603 | |
Yu Luming | 519ab5f | 2006-12-19 12:56:15 -0800 | [diff] [blame] | 1604 | ibm_backlight_device = backlight_device_register("ibm", NULL, NULL, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 1605 | &ibm_backlight_data); |
| 1606 | if (IS_ERR(ibm_backlight_device)) { |
| 1607 | printk(IBM_ERR "Could not register backlight device\n"); |
| 1608 | return PTR_ERR(ibm_backlight_device); |
| 1609 | } |
| 1610 | |
Henrique de Moraes Holschuh | adb0058 | 2007-02-22 16:04:55 -0200 | [diff] [blame] | 1611 | ibm_backlight_device->props.max_brightness = 7; |
| 1612 | ibm_backlight_device->props.brightness = b; |
| 1613 | backlight_update_status(ibm_backlight_device); |
Richard Purdie | 599a52d | 2007-02-10 23:07:48 +0000 | [diff] [blame] | 1614 | |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 1615 | return 0; |
| 1616 | } |
| 1617 | |
| 1618 | static void brightness_exit(void) |
| 1619 | { |
| 1620 | if (ibm_backlight_device) { |
| 1621 | backlight_device_unregister(ibm_backlight_device); |
| 1622 | ibm_backlight_device = NULL; |
| 1623 | } |
| 1624 | } |
| 1625 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1626 | static int volume_read(char *p) |
| 1627 | { |
| 1628 | int len = 0; |
| 1629 | u8 level; |
| 1630 | |
| 1631 | if (!acpi_ec_read(volume_offset, &level)) { |
| 1632 | len += sprintf(p + len, "level:\t\tunreadable\n"); |
| 1633 | } else { |
| 1634 | len += sprintf(p + len, "level:\t\t%d\n", level & 0xf); |
| 1635 | len += sprintf(p + len, "mute:\t\t%s\n", onoff(level, 6)); |
| 1636 | len += sprintf(p + len, "commands:\tup, down, mute\n"); |
| 1637 | len += sprintf(p + len, "commands:\tlevel <level>" |
| 1638 | " (<level> is 0-15)\n"); |
| 1639 | } |
| 1640 | |
| 1641 | return len; |
| 1642 | } |
| 1643 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1644 | static int volume_write(char *buf) |
| 1645 | { |
| 1646 | int cmos_cmd, inc, i; |
| 1647 | u8 level, mute; |
| 1648 | int new_level, new_mute; |
| 1649 | char *cmd; |
| 1650 | |
| 1651 | while ((cmd = next_cmd(&buf))) { |
| 1652 | if (!acpi_ec_read(volume_offset, &level)) |
| 1653 | return -EIO; |
| 1654 | new_mute = mute = level & 0x40; |
| 1655 | new_level = level = level & 0xf; |
| 1656 | |
| 1657 | if (strlencmp(cmd, "up") == 0) { |
| 1658 | if (mute) |
| 1659 | new_mute = 0; |
| 1660 | else |
| 1661 | new_level = level == 15 ? 15 : level + 1; |
| 1662 | } else if (strlencmp(cmd, "down") == 0) { |
| 1663 | if (mute) |
| 1664 | new_mute = 0; |
| 1665 | else |
| 1666 | new_level = level == 0 ? 0 : level - 1; |
| 1667 | } else if (sscanf(cmd, "level %d", &new_level) == 1 && |
| 1668 | new_level >= 0 && new_level <= 15) { |
| 1669 | /* new_level set */ |
| 1670 | } else if (strlencmp(cmd, "mute") == 0) { |
| 1671 | new_mute = 0x40; |
| 1672 | } else |
| 1673 | return -EINVAL; |
| 1674 | |
| 1675 | if (new_level != level) { /* mute doesn't change */ |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1676 | cmos_cmd = new_level > level ? |
| 1677 | TP_CMOS_VOLUME_UP : TP_CMOS_VOLUME_DOWN; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1678 | inc = new_level > level ? 1 : -1; |
| 1679 | |
| 1680 | if (mute && (!cmos_eval(cmos_cmd) || |
| 1681 | !acpi_ec_write(volume_offset, level))) |
| 1682 | return -EIO; |
| 1683 | |
| 1684 | for (i = level; i != new_level; i += inc) |
| 1685 | if (!cmos_eval(cmos_cmd) || |
| 1686 | !acpi_ec_write(volume_offset, i + inc)) |
| 1687 | return -EIO; |
| 1688 | |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1689 | if (mute && (!cmos_eval(TP_CMOS_VOLUME_MUTE) || |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1690 | !acpi_ec_write(volume_offset, |
| 1691 | new_level + mute))) |
| 1692 | return -EIO; |
| 1693 | } |
| 1694 | |
| 1695 | if (new_mute != mute) { /* level doesn't change */ |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 1696 | cmos_cmd = new_mute ? |
| 1697 | TP_CMOS_VOLUME_MUTE : TP_CMOS_VOLUME_UP; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1698 | |
| 1699 | if (!cmos_eval(cmos_cmd) || |
| 1700 | !acpi_ec_write(volume_offset, level + new_mute)) |
| 1701 | return -EIO; |
| 1702 | } |
| 1703 | } |
| 1704 | |
| 1705 | return 0; |
| 1706 | } |
| 1707 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1708 | static enum fan_status_access_mode fan_status_access_mode; |
| 1709 | static enum fan_control_access_mode fan_control_access_mode; |
| 1710 | static enum fan_control_commands fan_control_commands; |
| 1711 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1712 | static int fan_control_status_known; |
| 1713 | static u8 fan_control_initial_status; |
| 1714 | |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 1715 | static void fan_watchdog_fire(struct work_struct *ignored); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1716 | static int fan_watchdog_maxinterval; |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 1717 | static DECLARE_DELAYED_WORK(fan_watchdog_task, fan_watchdog_fire); |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1718 | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1719 | static int fan_init(void) |
| 1720 | { |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1721 | fan_status_access_mode = IBMACPI_FAN_NONE; |
| 1722 | fan_control_access_mode = IBMACPI_FAN_WR_NONE; |
| 1723 | fan_control_commands = 0; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1724 | fan_control_status_known = 1; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1725 | fan_watchdog_maxinterval = 0; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1726 | |
| 1727 | if (gfan_handle) { |
| 1728 | /* 570, 600e/x, 770e, 770x */ |
| 1729 | fan_status_access_mode = IBMACPI_FAN_RD_ACPI_GFAN; |
| 1730 | } else { |
| 1731 | /* all other ThinkPads: note that even old-style |
| 1732 | * ThinkPad ECs supports the fan control register */ |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1733 | if (likely(acpi_ec_read(fan_status_offset, |
| 1734 | &fan_control_initial_status))) { |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1735 | fan_status_access_mode = IBMACPI_FAN_RD_TPEC; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1736 | |
| 1737 | /* In some ThinkPads, neither the EC nor the ACPI |
| 1738 | * DSDT initialize the fan status, and it ends up |
| 1739 | * being set to 0x07 when it *could* be either |
| 1740 | * 0x07 or 0x80. |
| 1741 | * |
| 1742 | * Enable for TP-1Y (T43), TP-78 (R51e), |
| 1743 | * TP-76 (R52), TP-70 (T43, R52), which are known |
| 1744 | * to be buggy. */ |
| 1745 | if (fan_control_initial_status == 0x07 && |
| 1746 | ibm_thinkpad_ec_found && |
| 1747 | ((ibm_thinkpad_ec_found[0] == '1' && |
| 1748 | ibm_thinkpad_ec_found[1] == 'Y') || |
| 1749 | (ibm_thinkpad_ec_found[0] == '7' && |
| 1750 | (ibm_thinkpad_ec_found[1] == '6' || |
| 1751 | ibm_thinkpad_ec_found[1] == '8' || |
| 1752 | ibm_thinkpad_ec_found[1] == '0')) |
| 1753 | )) { |
| 1754 | printk(IBM_NOTICE |
| 1755 | "fan_init: initial fan status is " |
| 1756 | "unknown, assuming it is in auto " |
| 1757 | "mode\n"); |
| 1758 | fan_control_status_known = 0; |
| 1759 | } |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1760 | } else { |
| 1761 | printk(IBM_ERR |
| 1762 | "ThinkPad ACPI EC access misbehaving, " |
| 1763 | "fan status and control unavailable\n"); |
| 1764 | return 0; |
| 1765 | } |
| 1766 | } |
| 1767 | |
| 1768 | if (sfan_handle) { |
| 1769 | /* 570, 770x-JL */ |
| 1770 | fan_control_access_mode = IBMACPI_FAN_WR_ACPI_SFAN; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 1771 | fan_control_commands |= |
| 1772 | IBMACPI_FAN_CMD_LEVEL | IBMACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1773 | } else { |
| 1774 | if (!gfan_handle) { |
| 1775 | /* gfan without sfan means no fan control */ |
| 1776 | /* all other models implement TP EC 0x2f control */ |
| 1777 | |
| 1778 | if (fans_handle) { |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 1779 | /* X31, X40, X41 */ |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1780 | fan_control_access_mode = |
| 1781 | IBMACPI_FAN_WR_ACPI_FANS; |
| 1782 | fan_control_commands |= |
| 1783 | IBMACPI_FAN_CMD_SPEED | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 1784 | IBMACPI_FAN_CMD_LEVEL | |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1785 | IBMACPI_FAN_CMD_ENABLE; |
| 1786 | } else { |
| 1787 | fan_control_access_mode = IBMACPI_FAN_WR_TPEC; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 1788 | fan_control_commands |= |
| 1789 | IBMACPI_FAN_CMD_LEVEL | |
| 1790 | IBMACPI_FAN_CMD_ENABLE; |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 1791 | } |
| 1792 | } |
| 1793 | } |
| 1794 | |
| 1795 | return 0; |
| 1796 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1797 | |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1798 | static int fan_get_status(u8 *status) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1799 | { |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1800 | u8 s; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1801 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 1802 | /* TODO: |
| 1803 | * Add IBMACPI_FAN_RD_ACPI_FANS ? */ |
| 1804 | |
Henrique de Moraes Holschuh | 3ef8a60 | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1805 | switch (fan_status_access_mode) { |
| 1806 | case IBMACPI_FAN_RD_ACPI_GFAN: |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1807 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1808 | |
| 1809 | if (unlikely(!acpi_evalf(gfan_handle, &s, NULL, "d"))) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1810 | return -EIO; |
| 1811 | |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1812 | if (likely(status)) |
| 1813 | *status = s & 0x07; |
| 1814 | |
| 1815 | break; |
| 1816 | |
| 1817 | case IBMACPI_FAN_RD_TPEC: |
| 1818 | /* all except 570, 600e/x, 770e, 770x */ |
| 1819 | if (unlikely(!acpi_ec_read(fan_status_offset, &s))) |
| 1820 | return -EIO; |
| 1821 | |
| 1822 | if (likely(status)) |
| 1823 | *status = s; |
| 1824 | |
| 1825 | break; |
| 1826 | |
| 1827 | default: |
| 1828 | return -ENXIO; |
| 1829 | } |
| 1830 | |
| 1831 | return 0; |
| 1832 | } |
| 1833 | |
| 1834 | static int fan_get_speed(unsigned int *speed) |
| 1835 | { |
| 1836 | u8 hi, lo; |
| 1837 | |
| 1838 | switch (fan_status_access_mode) { |
| 1839 | case IBMACPI_FAN_RD_TPEC: |
| 1840 | /* all except 570, 600e/x, 770e, 770x */ |
| 1841 | if (unlikely(!acpi_ec_read(fan_rpm_offset, &lo) || |
| 1842 | !acpi_ec_read(fan_rpm_offset + 1, &hi))) |
| 1843 | return -EIO; |
| 1844 | |
| 1845 | if (likely(speed)) |
| 1846 | *speed = (hi << 8) | lo; |
| 1847 | |
| 1848 | break; |
| 1849 | |
| 1850 | default: |
| 1851 | return -ENXIO; |
| 1852 | } |
| 1853 | |
| 1854 | return 0; |
| 1855 | } |
| 1856 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1857 | static void fan_exit(void) |
| 1858 | { |
| 1859 | cancel_delayed_work(&fan_watchdog_task); |
| 1860 | flush_scheduled_work(); |
| 1861 | } |
| 1862 | |
| 1863 | static void fan_watchdog_reset(void) |
| 1864 | { |
| 1865 | static int fan_watchdog_active = 0; |
| 1866 | |
| 1867 | if (fan_watchdog_active) |
| 1868 | cancel_delayed_work(&fan_watchdog_task); |
| 1869 | |
| 1870 | if (fan_watchdog_maxinterval > 0) { |
| 1871 | fan_watchdog_active = 1; |
| 1872 | if (!schedule_delayed_work(&fan_watchdog_task, |
| 1873 | msecs_to_jiffies(fan_watchdog_maxinterval |
| 1874 | * 1000))) { |
| 1875 | printk(IBM_ERR "failed to schedule the fan watchdog, " |
| 1876 | "watchdog will not trigger\n"); |
| 1877 | } |
| 1878 | } else |
| 1879 | fan_watchdog_active = 0; |
| 1880 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1881 | |
| 1882 | static int fan_read(char *p) |
| 1883 | { |
| 1884 | int len = 0; |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1885 | int rc; |
| 1886 | u8 status; |
| 1887 | unsigned int speed = 0; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1888 | |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1889 | switch (fan_status_access_mode) { |
| 1890 | case IBMACPI_FAN_RD_ACPI_GFAN: |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1891 | /* 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1892 | if ((rc = fan_get_status(&status)) < 0) |
| 1893 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1894 | |
Henrique de Moraes Holschuh | bab812a | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 1895 | len += sprintf(p + len, "status:\t\t%s\n" |
| 1896 | "level:\t\t%d\n", |
| 1897 | (status != 0) ? "enabled" : "disabled", status); |
Henrique de Moraes Holschuh | 3ef8a60 | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1898 | break; |
| 1899 | |
| 1900 | case IBMACPI_FAN_RD_TPEC: |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1901 | /* all except 570, 600e/x, 770e, 770x */ |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1902 | if ((rc = fan_get_status(&status)) < 0) |
| 1903 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1904 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1905 | if (unlikely(!fan_control_status_known)) { |
| 1906 | if (status != fan_control_initial_status) |
| 1907 | fan_control_status_known = 1; |
| 1908 | else |
| 1909 | /* Return most likely status. In fact, it |
| 1910 | * might be the only possible status */ |
| 1911 | status = IBMACPI_FAN_EC_AUTO; |
| 1912 | } |
| 1913 | |
Henrique de Moraes Holschuh | bab812a | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 1914 | len += sprintf(p + len, "status:\t\t%s\n", |
| 1915 | (status != 0) ? "enabled" : "disabled"); |
Henrique de Moraes Holschuh | 3ef8a60 | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1916 | |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1917 | /* No ThinkPad boots on disengaged mode, we can safely |
| 1918 | * assume the tachometer is online if fan control status |
| 1919 | * was unknown */ |
Henrique de Moraes Holschuh | c52f0aa | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1920 | if ((rc = fan_get_speed(&speed)) < 0) |
| 1921 | return rc; |
| 1922 | |
| 1923 | len += sprintf(p + len, "speed:\t\t%d\n", speed); |
Henrique de Moraes Holschuh | bab812a | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 1924 | |
| 1925 | if (status & IBMACPI_FAN_EC_DISENGAGED) |
| 1926 | /* Disengaged mode takes precedence */ |
| 1927 | len += sprintf(p + len, "level:\t\tdisengaged\n"); |
| 1928 | else if (status & IBMACPI_FAN_EC_AUTO) |
| 1929 | len += sprintf(p + len, "level:\t\tauto\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1930 | else |
Henrique de Moraes Holschuh | bab812a | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 1931 | len += sprintf(p + len, "level:\t\t%d\n", status); |
Henrique de Moraes Holschuh | 3ef8a60 | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1932 | break; |
| 1933 | |
| 1934 | case IBMACPI_FAN_NONE: |
| 1935 | default: |
| 1936 | len += sprintf(p + len, "status:\t\tnot supported\n"); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1937 | } |
| 1938 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 1939 | if (fan_control_commands & IBMACPI_FAN_CMD_LEVEL) { |
| 1940 | len += sprintf(p + len, "commands:\tlevel <level>"); |
| 1941 | |
| 1942 | switch (fan_control_access_mode) { |
| 1943 | case IBMACPI_FAN_WR_ACPI_SFAN: |
| 1944 | len += sprintf(p + len, " (<level> is 0-7)\n"); |
| 1945 | break; |
| 1946 | |
| 1947 | default: |
| 1948 | len += sprintf(p + len, " (<level> is 0-7, " |
| 1949 | "auto, disengaged)\n"); |
| 1950 | break; |
| 1951 | } |
| 1952 | } |
Henrique de Moraes Holschuh | 3ef8a60 | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1953 | |
| 1954 | if (fan_control_commands & IBMACPI_FAN_CMD_ENABLE) |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1955 | len += sprintf(p + len, "commands:\tenable, disable\n" |
| 1956 | "commands:\twatchdog <timeout> (<timeout> is 0 (off), " |
| 1957 | "1-120 (seconds))\n"); |
Henrique de Moraes Holschuh | 3ef8a60 | 2006-11-24 11:47:10 -0200 | [diff] [blame] | 1958 | |
| 1959 | if (fan_control_commands & IBMACPI_FAN_CMD_SPEED) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1960 | len += sprintf(p + len, "commands:\tspeed <speed>" |
| 1961 | " (<speed> is 0-65535)\n"); |
| 1962 | |
| 1963 | return len; |
| 1964 | } |
| 1965 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 1966 | static int fan_set_level(int level) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1967 | { |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 1968 | switch (fan_control_access_mode) { |
| 1969 | case IBMACPI_FAN_WR_ACPI_SFAN: |
| 1970 | if (level >= 0 && level <= 7) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 1971 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", level)) |
| 1972 | return -EIO; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 1973 | } else |
| 1974 | return -EINVAL; |
| 1975 | break; |
| 1976 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 1977 | case IBMACPI_FAN_WR_ACPI_FANS: |
| 1978 | case IBMACPI_FAN_WR_TPEC: |
| 1979 | if ((level != IBMACPI_FAN_EC_AUTO) && |
| 1980 | (level != IBMACPI_FAN_EC_DISENGAGED) && |
| 1981 | ((level < 0) || (level > 7))) |
| 1982 | return -EINVAL; |
| 1983 | |
| 1984 | if (!acpi_ec_write(fan_status_offset, level)) |
| 1985 | return -EIO; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 1986 | else |
| 1987 | fan_control_status_known = 1; |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 1988 | break; |
| 1989 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 1990 | default: |
| 1991 | return -ENXIO; |
| 1992 | } |
| 1993 | return 0; |
| 1994 | } |
| 1995 | |
| 1996 | static int fan_set_enable(void) |
| 1997 | { |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 1998 | u8 s; |
| 1999 | int rc; |
| 2000 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2001 | switch (fan_control_access_mode) { |
| 2002 | case IBMACPI_FAN_WR_ACPI_FANS: |
| 2003 | case IBMACPI_FAN_WR_TPEC: |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 2004 | if ((rc = fan_get_status(&s)) < 0) |
| 2005 | return rc; |
| 2006 | |
| 2007 | /* Don't go out of emergency fan mode */ |
| 2008 | if (s != 7) |
| 2009 | s = IBMACPI_FAN_EC_AUTO; |
| 2010 | |
| 2011 | if (!acpi_ec_write(fan_status_offset, s)) |
| 2012 | return -EIO; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2013 | else |
| 2014 | fan_control_status_known = 1; |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 2015 | break; |
| 2016 | |
| 2017 | case IBMACPI_FAN_WR_ACPI_SFAN: |
| 2018 | if ((rc = fan_get_status(&s)) < 0) |
| 2019 | return rc; |
| 2020 | |
| 2021 | s &= 0x07; |
| 2022 | |
| 2023 | /* Set fan to at least level 4 */ |
| 2024 | if (s < 4) |
| 2025 | s = 4; |
| 2026 | |
| 2027 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", s)) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2028 | return -EIO; |
| 2029 | break; |
| 2030 | |
| 2031 | default: |
| 2032 | return -ENXIO; |
| 2033 | } |
| 2034 | return 0; |
| 2035 | } |
| 2036 | |
| 2037 | static int fan_set_disable(void) |
| 2038 | { |
| 2039 | switch (fan_control_access_mode) { |
| 2040 | case IBMACPI_FAN_WR_ACPI_FANS: |
| 2041 | case IBMACPI_FAN_WR_TPEC: |
| 2042 | if (!acpi_ec_write(fan_status_offset, 0x00)) |
| 2043 | return -EIO; |
Henrique de Moraes Holschuh | 778b4d7 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2044 | else |
| 2045 | fan_control_status_known = 1; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2046 | break; |
| 2047 | |
Henrique de Moraes Holschuh | 1c6a334 | 2006-11-24 11:47:12 -0200 | [diff] [blame] | 2048 | case IBMACPI_FAN_WR_ACPI_SFAN: |
| 2049 | if (!acpi_evalf(sfan_handle, NULL, NULL, "vd", 0x00)) |
| 2050 | return -EIO; |
| 2051 | break; |
| 2052 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2053 | default: |
| 2054 | return -ENXIO; |
| 2055 | } |
| 2056 | return 0; |
| 2057 | } |
| 2058 | |
| 2059 | static int fan_set_speed(int speed) |
| 2060 | { |
| 2061 | switch (fan_control_access_mode) { |
| 2062 | case IBMACPI_FAN_WR_ACPI_FANS: |
| 2063 | if (speed >= 0 && speed <= 65535) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2064 | if (!acpi_evalf(fans_handle, NULL, NULL, "vddd", |
| 2065 | speed, speed, speed)) |
| 2066 | return -EIO; |
| 2067 | } else |
| 2068 | return -EINVAL; |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2069 | break; |
| 2070 | |
| 2071 | default: |
| 2072 | return -ENXIO; |
| 2073 | } |
| 2074 | return 0; |
| 2075 | } |
| 2076 | |
| 2077 | static int fan_write_cmd_level(const char *cmd, int *rc) |
| 2078 | { |
| 2079 | int level; |
| 2080 | |
Henrique de Moraes Holschuh | a12095c | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2081 | if (strlencmp(cmd, "level auto") == 0) |
| 2082 | level = IBMACPI_FAN_EC_AUTO; |
| 2083 | else if (strlencmp(cmd, "level disengaged") == 0) |
| 2084 | level = IBMACPI_FAN_EC_DISENGAGED; |
| 2085 | else if (sscanf(cmd, "level %d", &level) != 1) |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2086 | return 0; |
| 2087 | |
| 2088 | if ((*rc = fan_set_level(level)) == -ENXIO) |
| 2089 | printk(IBM_ERR "level command accepted for unsupported " |
| 2090 | "access mode %d", fan_control_access_mode); |
| 2091 | |
| 2092 | return 1; |
| 2093 | } |
| 2094 | |
| 2095 | static int fan_write_cmd_enable(const char *cmd, int *rc) |
| 2096 | { |
| 2097 | if (strlencmp(cmd, "enable") != 0) |
| 2098 | return 0; |
| 2099 | |
| 2100 | if ((*rc = fan_set_enable()) == -ENXIO) |
| 2101 | printk(IBM_ERR "enable command accepted for unsupported " |
| 2102 | "access mode %d", fan_control_access_mode); |
| 2103 | |
| 2104 | return 1; |
| 2105 | } |
| 2106 | |
| 2107 | static int fan_write_cmd_disable(const char *cmd, int *rc) |
| 2108 | { |
| 2109 | if (strlencmp(cmd, "disable") != 0) |
| 2110 | return 0; |
| 2111 | |
| 2112 | if ((*rc = fan_set_disable()) == -ENXIO) |
| 2113 | printk(IBM_ERR "disable command accepted for unsupported " |
| 2114 | "access mode %d", fan_control_access_mode); |
| 2115 | |
| 2116 | return 1; |
| 2117 | } |
| 2118 | |
| 2119 | static int fan_write_cmd_speed(const char *cmd, int *rc) |
| 2120 | { |
| 2121 | int speed; |
| 2122 | |
Henrique de Moraes Holschuh | a8b7a66 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2123 | /* TODO: |
| 2124 | * Support speed <low> <medium> <high> ? */ |
| 2125 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2126 | if (sscanf(cmd, "speed %d", &speed) != 1) |
| 2127 | return 0; |
| 2128 | |
| 2129 | if ((*rc = fan_set_speed(speed)) == -ENXIO) |
| 2130 | printk(IBM_ERR "speed command accepted for unsupported " |
| 2131 | "access mode %d", fan_control_access_mode); |
| 2132 | |
| 2133 | return 1; |
| 2134 | } |
| 2135 | |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2136 | static int fan_write_cmd_watchdog(const char *cmd, int *rc) |
| 2137 | { |
| 2138 | int interval; |
| 2139 | |
| 2140 | if (sscanf(cmd, "watchdog %d", &interval) != 1) |
| 2141 | return 0; |
| 2142 | |
| 2143 | if (interval < 0 || interval > 120) |
| 2144 | *rc = -EINVAL; |
| 2145 | else |
| 2146 | fan_watchdog_maxinterval = interval; |
| 2147 | |
| 2148 | return 1; |
| 2149 | } |
| 2150 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2151 | static int fan_write(char *buf) |
| 2152 | { |
| 2153 | char *cmd; |
| 2154 | int rc = 0; |
| 2155 | |
| 2156 | while (!rc && (cmd = next_cmd(&buf))) { |
| 2157 | if (!((fan_control_commands & IBMACPI_FAN_CMD_LEVEL) && |
| 2158 | fan_write_cmd_level(cmd, &rc)) && |
| 2159 | !((fan_control_commands & IBMACPI_FAN_CMD_ENABLE) && |
| 2160 | (fan_write_cmd_enable(cmd, &rc) || |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2161 | fan_write_cmd_disable(cmd, &rc) || |
| 2162 | fan_write_cmd_watchdog(cmd, &rc))) && |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2163 | !((fan_control_commands & IBMACPI_FAN_CMD_SPEED) && |
| 2164 | fan_write_cmd_speed(cmd, &rc)) |
| 2165 | ) |
| 2166 | rc = -EINVAL; |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2167 | else if (!rc) |
| 2168 | fan_watchdog_reset(); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2169 | } |
| 2170 | |
Henrique de Moraes Holschuh | 18ad799 | 2006-11-24 11:47:11 -0200 | [diff] [blame] | 2171 | return rc; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2172 | } |
| 2173 | |
Len Brown | 25c68a3 | 2006-12-08 04:43:41 -0500 | [diff] [blame] | 2174 | static void fan_watchdog_fire(struct work_struct *ignored) |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2175 | { |
| 2176 | printk(IBM_NOTICE "fan watchdog: enabling fan\n"); |
| 2177 | if (fan_set_enable()) { |
| 2178 | printk(IBM_ERR "fan watchdog: error while enabling fan\n"); |
| 2179 | /* reschedule for later */ |
| 2180 | fan_watchdog_reset(); |
| 2181 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | } |
| 2183 | |
| 2184 | static struct ibm_struct ibms[] = { |
| 2185 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2186 | .name = "driver", |
Adrian Bunk | 1f21782 | 2006-12-19 13:01:28 -0800 | [diff] [blame] | 2187 | .init = ibm_acpi_driver_init, |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 2188 | .read = ibm_acpi_driver_read, |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2189 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2190 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2191 | .name = "hotkey", |
| 2192 | .hid = IBM_HKEY_HID, |
| 2193 | .init = hotkey_init, |
| 2194 | .read = hotkey_read, |
| 2195 | .write = hotkey_write, |
| 2196 | .exit = hotkey_exit, |
| 2197 | .notify = hotkey_notify, |
| 2198 | .handle = &hkey_handle, |
| 2199 | .type = ACPI_DEVICE_NOTIFY, |
| 2200 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2201 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2202 | .name = "bluetooth", |
| 2203 | .init = bluetooth_init, |
| 2204 | .read = bluetooth_read, |
| 2205 | .write = bluetooth_write, |
| 2206 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2207 | { |
Jeremy Fitzhardinge | 42adb53 | 2006-06-01 17:41:00 -0400 | [diff] [blame] | 2208 | .name = "wan", |
| 2209 | .init = wan_init, |
| 2210 | .read = wan_read, |
| 2211 | .write = wan_write, |
| 2212 | .experimental = 1, |
| 2213 | }, |
| 2214 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2215 | .name = "video", |
| 2216 | .init = video_init, |
| 2217 | .read = video_read, |
| 2218 | .write = video_write, |
| 2219 | .exit = video_exit, |
| 2220 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2221 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2222 | .name = "light", |
| 2223 | .init = light_init, |
| 2224 | .read = light_read, |
| 2225 | .write = light_write, |
| 2226 | }, |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 2227 | #ifdef CONFIG_ACPI_IBM_DOCK |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2228 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2229 | .name = "dock", |
| 2230 | .read = dock_read, |
| 2231 | .write = dock_write, |
| 2232 | .notify = dock_notify, |
| 2233 | .handle = &dock_handle, |
| 2234 | .type = ACPI_SYSTEM_NOTIFY, |
| 2235 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2237 | .name = "dock", |
| 2238 | .hid = IBM_PCI_HID, |
| 2239 | .notify = dock_notify, |
| 2240 | .handle = &pci_handle, |
| 2241 | .type = ACPI_SYSTEM_NOTIFY, |
| 2242 | }, |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 2243 | #endif |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 2244 | #ifdef CONFIG_ACPI_IBM_BAY |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2245 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2246 | .name = "bay", |
| 2247 | .init = bay_init, |
| 2248 | .read = bay_read, |
| 2249 | .write = bay_write, |
| 2250 | .notify = bay_notify, |
| 2251 | .handle = &bay_handle, |
| 2252 | .type = ACPI_SYSTEM_NOTIFY, |
| 2253 | }, |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 2254 | #endif /* CONFIG_ACPI_IBM_BAY */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2255 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2256 | .name = "cmos", |
| 2257 | .read = cmos_read, |
| 2258 | .write = cmos_write, |
| 2259 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2260 | { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2261 | .name = "led", |
| 2262 | .init = led_init, |
| 2263 | .read = led_read, |
| 2264 | .write = led_write, |
| 2265 | }, |
| 2266 | { |
| 2267 | .name = "beep", |
| 2268 | .read = beep_read, |
| 2269 | .write = beep_write, |
| 2270 | }, |
| 2271 | { |
| 2272 | .name = "thermal", |
| 2273 | .init = thermal_init, |
| 2274 | .read = thermal_read, |
| 2275 | }, |
| 2276 | { |
| 2277 | .name = "ecdump", |
| 2278 | .read = ecdump_read, |
| 2279 | .write = ecdump_write, |
| 2280 | .experimental = 1, |
| 2281 | }, |
| 2282 | { |
| 2283 | .name = "brightness", |
| 2284 | .read = brightness_read, |
| 2285 | .write = brightness_write, |
Henrique de Moraes Holschuh | fb87a81 | 2006-11-25 16:35:09 -0200 | [diff] [blame] | 2286 | .init = brightness_init, |
| 2287 | .exit = brightness_exit, |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2288 | }, |
| 2289 | { |
| 2290 | .name = "volume", |
| 2291 | .read = volume_read, |
| 2292 | .write = volume_write, |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2293 | }, |
| 2294 | { |
| 2295 | .name = "fan", |
| 2296 | .read = fan_read, |
| 2297 | .write = fan_write, |
Henrique de Moraes Holschuh | 69ba91c | 2006-11-24 11:47:09 -0200 | [diff] [blame] | 2298 | .init = fan_init, |
Henrique de Moraes Holschuh | 16663a8 | 2006-11-24 11:47:14 -0200 | [diff] [blame] | 2299 | .exit = fan_exit, |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2300 | .experimental = 1, |
| 2301 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2302 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2303 | |
| 2304 | static int dispatch_read(char *page, char **start, off_t off, int count, |
| 2305 | int *eof, void *data) |
| 2306 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 2307 | struct ibm_struct *ibm = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2308 | int len; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2309 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2310 | if (!ibm || !ibm->read) |
| 2311 | return -EINVAL; |
| 2312 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2313 | len = ibm->read(page); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2314 | if (len < 0) |
| 2315 | return len; |
| 2316 | |
| 2317 | if (len <= off + count) |
| 2318 | *eof = 1; |
| 2319 | *start = page + off; |
| 2320 | len -= off; |
| 2321 | if (len > count) |
| 2322 | len = count; |
| 2323 | if (len < 0) |
| 2324 | len = 0; |
| 2325 | |
| 2326 | return len; |
| 2327 | } |
| 2328 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2329 | static int dispatch_write(struct file *file, const char __user * userbuf, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | unsigned long count, void *data) |
| 2331 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 2332 | struct ibm_struct *ibm = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2333 | char *kernbuf; |
| 2334 | int ret; |
| 2335 | |
| 2336 | if (!ibm || !ibm->write) |
| 2337 | return -EINVAL; |
| 2338 | |
| 2339 | kernbuf = kmalloc(count + 2, GFP_KERNEL); |
| 2340 | if (!kernbuf) |
| 2341 | return -ENOMEM; |
| 2342 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2343 | if (copy_from_user(kernbuf, userbuf, count)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2344 | kfree(kernbuf); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2345 | return -EFAULT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2346 | } |
| 2347 | |
| 2348 | kernbuf[count] = 0; |
| 2349 | strcat(kernbuf, ","); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2350 | ret = ibm->write(kernbuf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | if (ret == 0) |
| 2352 | ret = count; |
| 2353 | |
| 2354 | kfree(kernbuf); |
| 2355 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2356 | return ret; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2357 | } |
| 2358 | |
| 2359 | static void dispatch_notify(acpi_handle handle, u32 event, void *data) |
| 2360 | { |
Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 2361 | struct ibm_struct *ibm = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2362 | |
| 2363 | if (!ibm || !ibm->notify) |
| 2364 | return; |
| 2365 | |
| 2366 | ibm->notify(ibm, event); |
| 2367 | } |
| 2368 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2369 | static int __init setup_notify(struct ibm_struct *ibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2370 | { |
| 2371 | acpi_status status; |
| 2372 | int ret; |
| 2373 | |
| 2374 | if (!*ibm->handle) |
| 2375 | return 0; |
| 2376 | |
| 2377 | ret = acpi_bus_get_device(*ibm->handle, &ibm->device); |
| 2378 | if (ret < 0) { |
| 2379 | printk(IBM_ERR "%s device not present\n", ibm->name); |
Henrique de Moraes Holschuh | 96e89af | 2007-03-15 16:15:06 -0300 | [diff] [blame] | 2380 | return -ENODEV; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2381 | } |
| 2382 | |
| 2383 | acpi_driver_data(ibm->device) = ibm; |
| 2384 | sprintf(acpi_device_class(ibm->device), "%s/%s", IBM_NAME, ibm->name); |
| 2385 | |
| 2386 | status = acpi_install_notify_handler(*ibm->handle, ibm->type, |
| 2387 | dispatch_notify, ibm); |
| 2388 | if (ACPI_FAILURE(status)) { |
Henrique de Moraes Holschuh | 96e89af | 2007-03-15 16:15:06 -0300 | [diff] [blame] | 2389 | if (status == AE_ALREADY_EXISTS) { |
| 2390 | printk(IBM_NOTICE "another device driver is already handling %s events\n", |
| 2391 | ibm->name); |
| 2392 | } else { |
| 2393 | printk(IBM_ERR "acpi_install_notify_handler(%s) failed: %d\n", |
| 2394 | ibm->name, status); |
| 2395 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2396 | return -ENODEV; |
| 2397 | } |
Alexey Starikovskiy | 4afaf54 | 2006-12-18 14:53:33 -0300 | [diff] [blame] | 2398 | ibm->notify_installed = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2399 | return 0; |
| 2400 | } |
| 2401 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2402 | static int __init ibm_device_add(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2403 | { |
| 2404 | return 0; |
| 2405 | } |
| 2406 | |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 2407 | static int __init register_ibmacpi_subdriver(struct ibm_struct *ibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2408 | { |
| 2409 | int ret; |
| 2410 | |
Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 2411 | ibm->driver = kzalloc(sizeof(struct acpi_driver), GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2412 | if (!ibm->driver) { |
| 2413 | printk(IBM_ERR "kmalloc(ibm->driver) failed\n"); |
| 2414 | return -1; |
| 2415 | } |
| 2416 | |
Henrique de Moraes Holschuh | 3dfd35c | 2006-11-24 10:32:32 -0200 | [diff] [blame] | 2417 | sprintf(ibm->driver->name, "%s_%s", IBM_NAME, ibm->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2418 | ibm->driver->ids = ibm->hid; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2419 | ibm->driver->ops.add = &ibm_device_add; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2420 | |
| 2421 | ret = acpi_bus_register_driver(ibm->driver); |
| 2422 | if (ret < 0) { |
| 2423 | printk(IBM_ERR "acpi_bus_register_driver(%s) failed: %d\n", |
| 2424 | ibm->hid, ret); |
| 2425 | kfree(ibm->driver); |
| 2426 | } |
| 2427 | |
| 2428 | return ret; |
| 2429 | } |
| 2430 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2431 | static int __init ibm_init(struct ibm_struct *ibm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | { |
| 2433 | int ret; |
| 2434 | struct proc_dir_entry *entry; |
| 2435 | |
| 2436 | if (ibm->experimental && !experimental) |
| 2437 | return 0; |
| 2438 | |
| 2439 | if (ibm->hid) { |
Henrique de Moraes Holschuh | e062e03 | 2007-03-23 17:33:55 -0300 | [diff] [blame] | 2440 | ret = register_ibmacpi_subdriver(ibm); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2441 | if (ret < 0) |
| 2442 | return ret; |
| 2443 | ibm->driver_registered = 1; |
| 2444 | } |
| 2445 | |
| 2446 | if (ibm->init) { |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2447 | ret = ibm->init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2448 | if (ret != 0) |
| 2449 | return ret; |
| 2450 | ibm->init_called = 1; |
| 2451 | } |
| 2452 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2453 | if (ibm->read) { |
| 2454 | entry = create_proc_entry(ibm->name, |
| 2455 | S_IFREG | S_IRUGO | S_IWUSR, |
| 2456 | proc_dir); |
| 2457 | if (!entry) { |
| 2458 | printk(IBM_ERR "unable to create proc entry %s\n", |
| 2459 | ibm->name); |
| 2460 | return -ENODEV; |
| 2461 | } |
| 2462 | entry->owner = THIS_MODULE; |
| 2463 | entry->data = ibm; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | entry->read_proc = &dispatch_read; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2465 | if (ibm->write) |
| 2466 | entry->write_proc = &dispatch_write; |
| 2467 | ibm->proc_created = 1; |
| 2468 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2469 | |
| 2470 | if (ibm->notify) { |
| 2471 | ret = setup_notify(ibm); |
Henrique de Moraes Holschuh | 96e89af | 2007-03-15 16:15:06 -0300 | [diff] [blame] | 2472 | if (ret == -ENODEV) { |
| 2473 | printk(IBM_NOTICE "disabling subdriver %s\n", |
| 2474 | ibm->name); |
| 2475 | ibm_exit(ibm); |
| 2476 | return 0; |
| 2477 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2478 | if (ret < 0) |
| 2479 | return ret; |
| 2480 | } |
| 2481 | |
| 2482 | return 0; |
| 2483 | } |
| 2484 | |
| 2485 | static void ibm_exit(struct ibm_struct *ibm) |
| 2486 | { |
| 2487 | if (ibm->notify_installed) |
| 2488 | acpi_remove_notify_handler(*ibm->handle, ibm->type, |
| 2489 | dispatch_notify); |
| 2490 | |
| 2491 | if (ibm->proc_created) |
| 2492 | remove_proc_entry(ibm->name, proc_dir); |
| 2493 | |
| 2494 | if (ibm->init_called && ibm->exit) |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2495 | ibm->exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2496 | |
| 2497 | if (ibm->driver_registered) { |
| 2498 | acpi_bus_unregister_driver(ibm->driver); |
| 2499 | kfree(ibm->driver); |
| 2500 | } |
| 2501 | } |
| 2502 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2503 | static void __init ibm_handle_init(char *name, |
| 2504 | acpi_handle * handle, acpi_handle parent, |
| 2505 | char **paths, int num_paths, char **path) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2506 | { |
| 2507 | int i; |
| 2508 | acpi_status status; |
| 2509 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2510 | for (i = 0; i < num_paths; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2511 | status = acpi_get_handle(parent, paths[i], handle); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2512 | if (ACPI_SUCCESS(status)) { |
| 2513 | *path = paths[i]; |
| 2514 | return; |
| 2515 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2516 | } |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2517 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2518 | *handle = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2519 | } |
| 2520 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2521 | #define IBM_HANDLE_INIT(object) \ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2522 | ibm_handle_init(#object, &object##_handle, *object##_parent, \ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2523 | object##_paths, ARRAY_SIZE(object##_paths), &object##_path) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2524 | |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 2525 | static int __init set_ibm_param(const char *val, struct kernel_param *kp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2526 | { |
| 2527 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2529 | for (i = 0; i < ARRAY_SIZE(ibms); i++) |
| 2530 | if (strcmp(ibms[i].name, kp->name) == 0 && ibms[i].write) { |
| 2531 | if (strlen(val) > sizeof(ibms[i].param) - 2) |
| 2532 | return -ENOSPC; |
| 2533 | strcpy(ibms[i].param, val); |
| 2534 | strcat(ibms[i].param, ","); |
| 2535 | return 0; |
| 2536 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2538 | return -EINVAL; |
| 2539 | } |
| 2540 | |
| 2541 | #define IBM_PARAM(feature) \ |
| 2542 | module_param_call(feature, set_ibm_param, NULL, NULL, 0) |
| 2543 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2544 | IBM_PARAM(hotkey); |
| 2545 | IBM_PARAM(bluetooth); |
| 2546 | IBM_PARAM(video); |
| 2547 | IBM_PARAM(light); |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 2548 | #ifdef CONFIG_ACPI_IBM_DOCK |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2549 | IBM_PARAM(dock); |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 2550 | #endif |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 2551 | #ifdef CONFIG_ACPI_IBM_BAY |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2552 | IBM_PARAM(bay); |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 2553 | #endif /* CONFIG_ACPI_IBM_BAY */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2554 | IBM_PARAM(cmos); |
| 2555 | IBM_PARAM(led); |
| 2556 | IBM_PARAM(beep); |
| 2557 | IBM_PARAM(ecdump); |
| 2558 | IBM_PARAM(brightness); |
| 2559 | IBM_PARAM(volume); |
| 2560 | IBM_PARAM(fan); |
| 2561 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | static void acpi_ibm_exit(void) |
| 2563 | { |
| 2564 | int i; |
| 2565 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2566 | for (i = ARRAY_SIZE(ibms) - 1; i >= 0; i--) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | ibm_exit(&ibms[i]); |
| 2568 | |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 2569 | if (proc_dir) |
| 2570 | remove_proc_entry(IBM_DIR, acpi_root_dir); |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2571 | |
| 2572 | if (ibm_thinkpad_ec_found) |
| 2573 | kfree(ibm_thinkpad_ec_found); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | } |
| 2575 | |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2576 | static char* __init check_dmi_for_ec(void) |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2577 | { |
| 2578 | struct dmi_device *dev = NULL; |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2579 | char ec_fw_string[18]; |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2580 | |
| 2581 | /* |
| 2582 | * ThinkPad T23 or newer, A31 or newer, R50e or newer, |
| 2583 | * X32 or newer, all Z series; Some models must have an |
| 2584 | * up-to-date BIOS or they will not be detected. |
| 2585 | * |
| 2586 | * See http://thinkwiki.org/wiki/List_of_DMI_IDs |
| 2587 | */ |
| 2588 | 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] | 2589 | if (sscanf(dev->name, |
| 2590 | "IBM ThinkPad Embedded Controller -[%17c", |
| 2591 | ec_fw_string) == 1) { |
| 2592 | ec_fw_string[sizeof(ec_fw_string) - 1] = 0; |
| 2593 | ec_fw_string[strcspn(ec_fw_string, " ]")] = 0; |
| 2594 | return kstrdup(ec_fw_string, GFP_KERNEL); |
| 2595 | } |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2596 | } |
Henrique de Moraes Holschuh | 49a13cd | 2006-11-24 11:47:13 -0200 | [diff] [blame] | 2597 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2598 | } |
| 2599 | |
| 2600 | static int __init acpi_ibm_init(void) |
| 2601 | { |
| 2602 | int ret, i; |
| 2603 | |
| 2604 | if (acpi_disabled) |
| 2605 | return -ENODEV; |
| 2606 | |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2607 | /* ec is required because many other handles are relative to it */ |
| 2608 | IBM_HANDLE_INIT(ec); |
| 2609 | if (!ec_handle) { |
| 2610 | printk(IBM_ERR "ec object not found\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | return -ENODEV; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2612 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | |
Henrique de Moraes Holschuh | 60eb0b3 | 2006-11-24 11:47:08 -0200 | [diff] [blame] | 2614 | /* Models with newer firmware report the EC in DMI */ |
| 2615 | ibm_thinkpad_ec_found = check_dmi_for_ec(); |
| 2616 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | /* these handles are not required */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2618 | IBM_HANDLE_INIT(vid); |
| 2619 | IBM_HANDLE_INIT(vid2); |
| 2620 | IBM_HANDLE_INIT(ledb); |
| 2621 | IBM_HANDLE_INIT(led); |
| 2622 | IBM_HANDLE_INIT(hkey); |
| 2623 | IBM_HANDLE_INIT(lght); |
| 2624 | IBM_HANDLE_INIT(cmos); |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 2625 | #ifdef CONFIG_ACPI_IBM_DOCK |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2626 | IBM_HANDLE_INIT(dock); |
Kristen Accardi | 63e5f24 | 2006-02-23 17:56:06 -0800 | [diff] [blame] | 2627 | #endif |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2628 | IBM_HANDLE_INIT(pci); |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 2629 | #ifdef CONFIG_ACPI_IBM_BAY |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2630 | IBM_HANDLE_INIT(bay); |
| 2631 | if (bay_handle) |
| 2632 | IBM_HANDLE_INIT(bay_ej); |
| 2633 | IBM_HANDLE_INIT(bay2); |
| 2634 | if (bay2_handle) |
| 2635 | IBM_HANDLE_INIT(bay2_ej); |
Henrique de Moraes Holschuh | 2bc808a | 2007-02-21 13:05:38 -0200 | [diff] [blame] | 2636 | #endif /* CONFIG_ACPI_IBM_BAY */ |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2637 | IBM_HANDLE_INIT(beep); |
| 2638 | IBM_HANDLE_INIT(ecrd); |
| 2639 | IBM_HANDLE_INIT(ecwr); |
| 2640 | IBM_HANDLE_INIT(fans); |
| 2641 | IBM_HANDLE_INIT(gfan); |
| 2642 | IBM_HANDLE_INIT(sfan); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2643 | |
| 2644 | proc_dir = proc_mkdir(IBM_DIR, acpi_root_dir); |
| 2645 | if (!proc_dir) { |
| 2646 | printk(IBM_ERR "unable to create proc dir %s", IBM_DIR); |
Henrique de Moraes Holschuh | 3945ac3 | 2007-02-06 19:13:44 -0200 | [diff] [blame] | 2647 | acpi_ibm_exit(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | return -ENODEV; |
| 2649 | } |
| 2650 | proc_dir->owner = THIS_MODULE; |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2651 | |
| 2652 | for (i = 0; i < ARRAY_SIZE(ibms); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | ret = ibm_init(&ibms[i]); |
Borislav Deianov | 78f81cc | 2005-08-17 00:00:00 -0400 | [diff] [blame] | 2654 | if (ret >= 0 && *ibms[i].param) |
| 2655 | ret = ibms[i].write(ibms[i].param); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | if (ret < 0) { |
| 2657 | acpi_ibm_exit(); |
| 2658 | return ret; |
| 2659 | } |
| 2660 | } |
| 2661 | |
| 2662 | return 0; |
| 2663 | } |
| 2664 | |
| 2665 | module_init(acpi_ibm_init); |
| 2666 | module_exit(acpi_ibm_exit); |