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