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