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