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