2 * ibm_acpi.c - IBM ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #define IBM_VERSION "0.12a"
27 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
28 * 2005-03-17 0.11 support for 600e, 770x
29 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
30 * support for 770e, G41
31 * G40 and G41 don't have a thinklight
32 * temperatures no longer experimental
33 * experimental brightness control
34 * experimental volume control
35 * experimental fan enable/disable
36 * 2005-01-16 0.10 fix module loading on R30, R31
37 * 2005-01-16 0.9 support for 570, R30, R31
38 * ultrabay support on A22p, A3x
39 * limit arg for cmos, led, beep, drop experimental status
40 * more capable led control on A21e, A22p, T20-22, X20
41 * experimental temperatures and fan speed
42 * experimental embedded controller register dump
43 * mark more functions as __init, drop incorrect __exit
45 * thanks to Henrik Brix Andersen <brix@gentoo.org>
46 * fix parameter passing on module loading
47 * thanks to Rusty Russell <rusty@rustcorp.com.au>
48 * thanks to Jim Radford <radford@blackbean.org>
49 * 2004-11-08 0.8 fix init error case, don't return from a macro
50 * thanks to Chris Wright <chrisw@osdl.org>
51 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
52 * fix led control on A21e
53 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
54 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
55 * proc file format changed
56 * video_switch command
57 * experimental cmos control
58 * experimental led control
59 * experimental acpi sounds
60 * 2004-09-16 0.4 support for module parameters
61 * hotkey mask can be prefixed by 0x
62 * video output switching
63 * video expansion control
64 * ultrabay eject support
65 * removed lcd brightness/on/off control, didn't work
66 * 2004-08-17 0.3 support for R40
67 * lcd off, brightness control
69 * 2004-08-14 0.2 support for T series, X20
70 * bluetooth enable/disable
71 * hotkey events disabled by default
72 * removed fan control, currently useless
73 * 2004-08-09 0.1 initial release, support for X series
76 #include <linux/kernel.h>
77 #include <linux/module.h>
78 #include <linux/init.h>
79 #include <linux/types.h>
80 #include <linux/string.h>
81 #include <linux/proc_fs.h>
82 #include <linux/backlight.h>
83 #include <asm/uaccess.h>
84 #include <linux/dmi.h>
86 #include <acpi/acpi_drivers.h>
87 #include <acpi/acnamesp.h>
89 #define IBM_NAME "ibm"
90 #define IBM_DESC "IBM ThinkPad ACPI Extras"
91 #define IBM_FILE "ibm_acpi"
92 #define IBM_URL "http://ibm-acpi.sf.net/"
94 MODULE_AUTHOR("Borislav Deianov");
95 MODULE_DESCRIPTION(IBM_DESC
);
96 MODULE_VERSION(IBM_VERSION
);
97 MODULE_LICENSE("GPL");
99 #define IBM_DIR IBM_NAME
101 #define IBM_LOG IBM_FILE ": "
102 #define IBM_ERR KERN_ERR IBM_LOG
103 #define IBM_NOTICE KERN_NOTICE IBM_LOG
104 #define IBM_INFO KERN_INFO IBM_LOG
105 #define IBM_DEBUG KERN_DEBUG IBM_LOG
107 #define IBM_MAX_ACPI_ARGS 3
109 #define __unused __attribute__ ((unused))
111 static int experimental
;
112 module_param(experimental
, int, 0);
114 static acpi_handle root_handle
= NULL
;
116 #define IBM_HANDLE(object, parent, paths...) \
117 static acpi_handle object##_handle; \
118 static acpi_handle *object##_parent = &parent##_handle; \
119 static char *object##_path; \
120 static char *object##_paths[] = { paths }
123 * The following models are supported to various degrees:
125 * 570, 600e, 600x, 770e, 770x
126 * A20m, A21e, A21m, A21p, A22p, A30, A30p, A31, A31p
128 * R30, R31, R32, R40, R40e, R50, R50e, R50p, R51
129 * T20, T21, T22, T23, T30, T40, T40p, T41, T41p, T42, T42p, T43
130 * X20, X21, X22, X23, X24, X30, X31, X40
132 * The following models have no supported features:
136 * Still missing DSDTs for the following models:
144 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
145 "\\_SB.PCI.ISA.EC", /* 570 */
146 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
147 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
148 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
149 "\\_SB.PCI0.ICH3.EC0", /* R31 */
150 "\\_SB.PCI0.LPC.EC", /* all others */
153 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
154 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
155 "\\_SB.PCI0.VID0", /* 770e */
156 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
157 "\\_SB.PCI0.AGP.VID", /* all others */
160 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
162 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
163 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
164 "\\CMS", /* R40, R40e */
166 #ifdef CONFIG_ACPI_IBM_DOCK
167 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
168 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
169 "\\_SB.PCI0.PCI1.DOCK", /* all others */
170 "\\_SB.PCI.ISA.SLCE", /* 570 */
171 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
173 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
174 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
175 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
176 ); /* A21e, R30, R31 */
178 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
179 "_EJ0", /* all others */
180 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
182 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
183 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
186 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
190 /* don't list other alternatives as we install a notify handler on the 570 */
191 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
193 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
194 "^HKEY", /* R30, R31 */
195 "HKEY", /* all others */
198 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
199 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
201 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
202 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
203 "LED", /* all others */
206 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
207 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
208 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
209 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
211 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
212 "\\FSPD", /* 600e/x, 770e, 770x */
215 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
216 "JFNS", /* 770x-JL */
219 #define IBM_HKEY_HID "IBM0068"
220 #define IBM_PCI_HID "PNP0A03"
222 enum thermal_access_mode
{
223 IBMACPI_THERMAL_NONE
= 0, /* No thermal support */
224 IBMACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
225 IBMACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
226 IBMACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
227 IBMACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
230 #define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
231 struct ibm_thermal_sensors_struct
{
232 s32 temp
[IBMACPI_MAX_THERMAL_SENSORS
];
238 * IBMACPI_FAN_RD_ACPI_GFAN:
239 * ACPI GFAN method: returns fan level
241 * see IBMACPI_FAN_WR_ACPI_SFAN
242 * EC 0x2f not available if GFAN exists
244 * IBMACPI_FAN_WR_ACPI_SFAN:
245 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
247 * EC 0x2f might be available *for reading*, but never for writing.
249 * IBMACPI_FAN_WR_TPEC:
250 * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported
251 * on almost all ThinkPads
253 * Fan speed changes of any sort (including those caused by the
254 * disengaged mode) are usually done slowly by the firmware as the
255 * maximum ammount of fan duty cycle change per second seems to be
258 * Reading is not available if GFAN exists.
259 * Writing is not available if SFAN exists.
262 * 7 automatic mode engaged;
263 * (default operation mode of the ThinkPad)
264 * fan level is ignored in this mode.
265 * 6 disengage mode (takes precedence over bit 7);
266 * not available on all thinkpads. May disable
267 * the tachometer, and speeds up fan to 100% duty-cycle,
268 * which speeds it up far above the standard RPM
269 * levels. It is not impossible that it could cause
271 * 5-3 unused in some models. Extra bits for fan level
272 * in others, but still useless as all values above
273 * 7 map to the same speed as level 7 in these models.
274 * 2-0 fan level (0..7 usually)
276 * 0x07 = max (set when temperatures critical)
277 * Some ThinkPads may have other levels, see
278 * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
280 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
281 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
282 * does so, its initial value is meaningless (0x07).
284 * For firmware bugs, refer to:
285 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
289 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
290 * Main fan tachometer reading (in RPM)
292 * This register is present on all ThinkPads with a new-style EC, and
293 * it is known not to be present on the A21m/e, and T22, as there is
294 * something else in offset 0x84 according to the ACPI DSDT. Other
295 * ThinkPads from this same time period (and earlier) probably lack the
296 * tachometer as well.
298 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
299 * was never fixed by IBM to report the EC firmware version string
300 * probably support the tachometer (like the early X models), so
301 * detecting it is quite hard. We need more data to know for sure.
303 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
306 * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this
307 * register is not invalidated in ThinkPads that disable tachometer
308 * readings. Thus, the tachometer readings go stale.
310 * For firmware bugs, refer to:
311 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
313 * IBMACPI_FAN_WR_ACPI_FANS:
314 * ThinkPad X31, X40, X41. Not available in the X60.
316 * FANS ACPI handle: takes three arguments: low speed, medium speed,
317 * high speed. ACPI DSDT seems to map these three speeds to levels
318 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
319 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
321 * The speeds are stored on handles
322 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
324 * There are three default speed sets, acessible as handles:
325 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
327 * ACPI DSDT switches which set is in use depending on various
330 * IBMACPI_FAN_WR_TPEC is also available and should be used to
331 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
332 * but the ACPI tables just mention level 7.
335 enum fan_status_access_mode
{
336 IBMACPI_FAN_NONE
= 0, /* No fan status or control */
337 IBMACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
338 IBMACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
341 enum fan_control_access_mode
{
342 IBMACPI_FAN_WR_NONE
= 0, /* No fan control */
343 IBMACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
344 IBMACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
345 IBMACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
348 enum fan_control_commands
{
349 IBMACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
350 IBMACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
351 IBMACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd */
354 enum { /* Fan control constants */
355 fan_status_offset
= 0x2f, /* EC register 0x2f */
356 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
357 * 0x84 must be read before 0x85 */
359 IBMACPI_FAN_EC_DISENGAGED
= 0x40, /* EC mode: tachometer
361 IBMACPI_FAN_EC_AUTO
= 0x80, /* EC mode: auto fan
365 static char* ibm_thinkpad_ec_found
= NULL
;
372 struct acpi_driver
*driver
;
375 int (*read
) (char *);
376 int (*write
) (char *);
379 void (*notify
) (struct ibm_struct
*, u32
);
382 struct acpi_device
*device
;
384 int driver_registered
;
387 int notify_installed
;
392 static struct proc_dir_entry
*proc_dir
= NULL
;
394 static struct backlight_device
*ibm_backlight_device
;
396 #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
397 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
398 #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
400 static int acpi_evalf(acpi_handle handle
,
401 void *res
, char *method
, char *fmt
, ...)
404 struct acpi_object_list params
;
405 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
406 struct acpi_buffer result
, *resultp
;
407 union acpi_object out_obj
;
415 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
428 params
.pointer
= &in_objs
[0];
435 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
436 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
438 /* add more types as needed */
440 printk(IBM_ERR
"acpi_evalf() called "
441 "with invalid format character '%c'\n", c
);
447 if (res_type
!= 'v') {
448 result
.length
= sizeof(out_obj
);
449 result
.pointer
= &out_obj
;
454 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
459 *(int *)res
= out_obj
.integer
.value
;
460 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
463 success
= status
== AE_OK
;
465 /* add more types as needed */
467 printk(IBM_ERR
"acpi_evalf() called "
468 "with invalid format character '%c'\n", res_type
);
472 if (!success
&& !quiet
)
473 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
474 method
, fmt0
, status
);
479 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
483 if (acpi_evalf(handle
, &i
, method
, "d"))
484 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
486 printk(IBM_ERR
"error calling %s\n", method
);
489 static char *next_cmd(char **cmds
)
494 while ((end
= strchr(start
, ',')) && end
== start
)
505 static int driver_init(void)
507 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
508 printk(IBM_INFO
"%s\n", IBM_URL
);
513 static int driver_read(char *p
)
517 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
518 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
523 static int hotkey_supported
;
524 static int hotkey_mask_supported
;
525 static int hotkey_orig_status
;
526 static int hotkey_orig_mask
;
528 static int hotkey_get(int *status
, int *mask
)
530 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
533 if (hotkey_mask_supported
)
534 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
540 static int hotkey_set(int status
, int mask
)
544 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
547 if (hotkey_mask_supported
)
548 for (i
= 0; i
< 32; i
++) {
549 int bit
= ((1 << i
) & mask
) != 0;
550 if (!acpi_evalf(hkey_handle
,
551 NULL
, "MHKM", "vdd", i
+ 1, bit
))
558 static int hotkey_init(void)
560 /* hotkey not supported on 570 */
561 hotkey_supported
= hkey_handle
!= NULL
;
563 if (hotkey_supported
) {
564 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
565 A30, R30, R31, T20-22, X20-21, X22-24 */
566 hotkey_mask_supported
=
567 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
569 if (!hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
))
576 static int hotkey_read(char *p
)
581 if (!hotkey_supported
) {
582 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
586 if (!hotkey_get(&status
, &mask
))
589 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
590 if (hotkey_mask_supported
) {
591 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
592 len
+= sprintf(p
+ len
,
593 "commands:\tenable, disable, reset, <mask>\n");
595 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
596 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
602 static int hotkey_write(char *buf
)
608 if (!hotkey_supported
)
611 if (!hotkey_get(&status
, &mask
))
614 while ((cmd
= next_cmd(&buf
))) {
615 if (strlencmp(cmd
, "enable") == 0) {
617 } else if (strlencmp(cmd
, "disable") == 0) {
619 } else if (strlencmp(cmd
, "reset") == 0) {
620 status
= hotkey_orig_status
;
621 mask
= hotkey_orig_mask
;
622 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
624 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
631 if (do_cmd
&& !hotkey_set(status
, mask
))
637 static void hotkey_exit(void)
639 if (hotkey_supported
)
640 hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
643 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
647 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
648 acpi_bus_generate_event(ibm
->device
, event
, hkey
);
650 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
651 acpi_bus_generate_event(ibm
->device
, event
, 0);
655 static int bluetooth_supported
;
657 static int bluetooth_init(void)
659 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
660 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
661 bluetooth_supported
= hkey_handle
&&
662 acpi_evalf(hkey_handle
, NULL
, "GBDC", "qv");
667 static int bluetooth_status(void)
671 if (!bluetooth_supported
||
672 !acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
678 static int bluetooth_read(char *p
)
681 int status
= bluetooth_status();
683 if (!bluetooth_supported
)
684 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
685 else if (!(status
& 1))
686 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
688 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
689 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
695 static int bluetooth_write(char *buf
)
697 int status
= bluetooth_status();
701 if (!bluetooth_supported
)
704 while ((cmd
= next_cmd(&buf
))) {
705 if (strlencmp(cmd
, "enable") == 0) {
707 } else if (strlencmp(cmd
, "disable") == 0) {
714 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
720 static int wan_supported
;
722 static int wan_init(void)
724 wan_supported
= hkey_handle
&&
725 acpi_evalf(hkey_handle
, NULL
, "GWAN", "qv");
730 static int wan_status(void)
734 if (!wan_supported
|| !acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
740 static int wan_read(char *p
)
743 int status
= wan_status();
746 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
747 else if (!(status
& 1))
748 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
750 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
751 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
757 static int wan_write(char *buf
)
759 int status
= wan_status();
766 while ((cmd
= next_cmd(&buf
))) {
767 if (strlencmp(cmd
, "enable") == 0) {
769 } else if (strlencmp(cmd
, "disable") == 0) {
776 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
782 static int video_supported
;
783 static int video_orig_autosw
;
789 static int video_init(void)
793 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
794 /* G41, assume IVGA doesn't change */
795 vid_handle
= vid2_handle
;
798 /* video switching not supported on R30, R31 */
800 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
802 video_supported
= VIDEO_570
;
803 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
804 /* 600e/x, 770e, 770x */
805 video_supported
= VIDEO_770
;
808 video_supported
= VIDEO_NEW
;
813 static int video_status(void)
818 if (video_supported
== VIDEO_570
) {
819 if (acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd", 0x87))
821 } else if (video_supported
== VIDEO_770
) {
822 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
824 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
826 } else if (video_supported
== VIDEO_NEW
) {
827 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1);
828 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
831 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0);
832 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
834 if (acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
841 static int video_autosw(void)
845 if (video_supported
== VIDEO_570
)
846 acpi_evalf(vid_handle
, &autosw
, "SWIT", "d");
847 else if (video_supported
== VIDEO_770
|| video_supported
== VIDEO_NEW
)
848 acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d");
853 static int video_read(char *p
)
855 int status
= video_status();
856 int autosw
= video_autosw();
859 if (!video_supported
) {
860 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
864 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
865 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
866 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
867 if (video_supported
== VIDEO_NEW
)
868 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
869 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
870 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
871 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
872 if (video_supported
== VIDEO_NEW
)
873 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
874 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
875 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
880 static int video_switch(void)
882 int autosw
= video_autosw();
885 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
887 ret
= video_supported
== VIDEO_570
?
888 acpi_evalf(ec_handle
, NULL
, "_Q16", "v") :
889 acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
890 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
895 static int video_expand(void)
897 if (video_supported
== VIDEO_570
)
898 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v");
899 else if (video_supported
== VIDEO_770
)
900 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v");
902 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v");
905 static int video_switch2(int status
)
909 if (video_supported
== VIDEO_570
) {
910 ret
= acpi_evalf(NULL
, NULL
,
911 "\\_SB.PHS2", "vdd", 0x8b, status
| 0x80);
912 } else if (video_supported
== VIDEO_770
) {
913 int autosw
= video_autosw();
914 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
917 ret
= acpi_evalf(vid_handle
, NULL
,
918 "ASWT", "vdd", status
* 0x100, 0);
920 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
922 ret
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
923 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
929 static int video_write(char *buf
)
932 int enable
, disable
, status
;
934 if (!video_supported
)
937 enable
= disable
= 0;
939 while ((cmd
= next_cmd(&buf
))) {
940 if (strlencmp(cmd
, "lcd_enable") == 0) {
942 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
944 } else if (strlencmp(cmd
, "crt_enable") == 0) {
946 } else if (strlencmp(cmd
, "crt_disable") == 0) {
948 } else if (video_supported
== VIDEO_NEW
&&
949 strlencmp(cmd
, "dvi_enable") == 0) {
951 } else if (video_supported
== VIDEO_NEW
&&
952 strlencmp(cmd
, "dvi_disable") == 0) {
954 } else if (strlencmp(cmd
, "auto_enable") == 0) {
955 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
957 } else if (strlencmp(cmd
, "auto_disable") == 0) {
958 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 0))
960 } else if (strlencmp(cmd
, "video_switch") == 0) {
963 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
970 if (enable
|| disable
) {
971 status
= (video_status() & 0x0f & ~disable
) | enable
;
972 if (!video_switch2(status
))
979 static void video_exit(void)
981 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", video_orig_autosw
);
984 static int light_supported
;
985 static int light_status_supported
;
987 static int light_init(void)
989 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
990 light_supported
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
993 /* light status not supported on
994 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
995 light_status_supported
= acpi_evalf(ec_handle
, NULL
,
1001 static int light_read(char *p
)
1006 if (!light_supported
) {
1007 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1008 } else if (!light_status_supported
) {
1009 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1010 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1012 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1014 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1015 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1021 static int light_write(char *buf
)
1023 int cmos_cmd
, lght_cmd
;
1027 if (!light_supported
)
1030 while ((cmd
= next_cmd(&buf
))) {
1031 if (strlencmp(cmd
, "on") == 0) {
1034 } else if (strlencmp(cmd
, "off") == 0) {
1040 success
= cmos_handle
?
1041 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1042 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1050 static int _sta(acpi_handle handle
)
1054 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
1060 #ifdef CONFIG_ACPI_IBM_DOCK
1061 #define dock_docked() (_sta(dock_handle) & 1)
1063 static int dock_read(char *p
)
1066 int docked
= dock_docked();
1069 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1071 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1073 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1074 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1080 static int dock_write(char *buf
)
1087 while ((cmd
= next_cmd(&buf
))) {
1088 if (strlencmp(cmd
, "undock") == 0) {
1089 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1090 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1092 } else if (strlencmp(cmd
, "dock") == 0) {
1093 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1102 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1104 int docked
= dock_docked();
1105 int pci
= ibm
->hid
&& strstr(ibm
->hid
, IBM_PCI_HID
);
1107 if (event
== 1 && !pci
) /* 570 */
1108 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1109 else if (event
== 1 && pci
) /* 570 */
1110 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1111 else if (event
== 3 && docked
)
1112 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1113 else if (event
== 3 && !docked
)
1114 acpi_bus_generate_event(ibm
->device
, event
, 2); /* undock */
1115 else if (event
== 0 && docked
)
1116 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1118 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1119 event
, _sta(dock_handle
));
1120 acpi_bus_generate_event(ibm
->device
, event
, 0); /* unknown */
1125 static int bay_status_supported
;
1126 static int bay_status2_supported
;
1127 static int bay_eject_supported
;
1128 static int bay_eject2_supported
;
1130 static int bay_init(void)
1132 bay_status_supported
= bay_handle
&&
1133 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1134 bay_status2_supported
= bay2_handle
&&
1135 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1137 bay_eject_supported
= bay_handle
&& bay_ej_handle
&&
1138 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1139 bay_eject2_supported
= bay2_handle
&& bay2_ej_handle
&&
1140 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1145 #define bay_occupied(b) (_sta(b##_handle) & 1)
1147 static int bay_read(char *p
)
1150 int occupied
= bay_occupied(bay
);
1151 int occupied2
= bay_occupied(bay2
);
1154 len
+= sprintf(p
+ len
, "status:\t\t%s\n", bay_status_supported
?
1155 (occupied
? "occupied" : "unoccupied") :
1157 if (bay_status2_supported
)
1158 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1159 "occupied" : "unoccupied");
1161 eject
= bay_eject_supported
&& occupied
;
1162 eject2
= bay_eject2_supported
&& occupied2
;
1164 if (eject
&& eject2
)
1165 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1167 len
+= sprintf(p
+ len
, "commands:\teject\n");
1169 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1174 static int bay_write(char *buf
)
1178 if (!bay_eject_supported
&& !bay_eject2_supported
)
1181 while ((cmd
= next_cmd(&buf
))) {
1182 if (bay_eject_supported
&& strlencmp(cmd
, "eject") == 0) {
1183 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1185 } else if (bay_eject2_supported
&&
1186 strlencmp(cmd
, "eject2") == 0) {
1187 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1196 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1198 acpi_bus_generate_event(ibm
->device
, event
, 0);
1201 static int cmos_read(char *p
)
1205 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1206 R30, R31, T20-22, X20-21 */
1208 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1210 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1211 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1217 static int cmos_eval(int cmos_cmd
)
1220 return acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
);
1225 static int cmos_write(char *buf
)
1233 while ((cmd
= next_cmd(&buf
))) {
1234 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1235 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1240 if (!cmos_eval(cmos_cmd
))
1247 static int led_supported
;
1253 static int led_init(void)
1256 /* led not supported on R30, R31 */
1258 else if (strlencmp(led_path
, "SLED") == 0)
1260 led_supported
= LED_570
;
1261 else if (strlencmp(led_path
, "SYSL") == 0)
1262 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1263 led_supported
= LED_OLD
;
1266 led_supported
= LED_NEW
;
1271 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1273 static int led_read(char *p
)
1277 if (!led_supported
) {
1278 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1281 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1283 if (led_supported
== LED_570
) {
1286 for (i
= 0; i
< 8; i
++) {
1287 if (!acpi_evalf(ec_handle
,
1288 &status
, "GLED", "dd", 1 << i
))
1290 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1291 i
, led_status(status
));
1295 len
+= sprintf(p
+ len
, "commands:\t"
1296 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
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 };
1307 #define EC_HLCL 0x0c
1308 #define EC_HLBL 0x0d
1309 #define EC_HLMS 0x0e
1311 static int led_write(char *buf
)
1319 while ((cmd
= next_cmd(&buf
))) {
1320 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1323 if (strstr(cmd
, "off")) {
1325 } else if (strstr(cmd
, "on")) {
1327 } else if (strstr(cmd
, "blink")) {
1332 if (led_supported
== LED_570
) {
1335 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1336 led
, led_sled_arg1
[ind
]))
1338 } else if (led_supported
== LED_OLD
) {
1339 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1341 ret
= ec_write(EC_HLMS
, led
);
1344 ec_write(EC_HLBL
, led
* led_exp_hlbl
[ind
]);
1347 ec_write(EC_HLCL
, led
* led_exp_hlcl
[ind
]);
1352 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1353 led
, led_led_arg1
[ind
]))
1361 static int beep_read(char *p
)
1366 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1368 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1369 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1375 static int beep_write(char *buf
)
1383 while ((cmd
= next_cmd(&buf
))) {
1384 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1385 beep_cmd
>= 0 && beep_cmd
<= 17) {
1389 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1396 static int acpi_ec_read(int i
, u8
* p
)
1401 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
1405 if (ec_read(i
, p
) < 0)
1412 static int acpi_ec_write(int i
, u8 v
)
1415 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
1418 if (ec_write(i
, v
) < 0)
1425 static enum thermal_access_mode thermal_read_mode
;
1427 static int thermal_init(void)
1431 int acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
1433 if (ibm_thinkpad_ec_found
&& experimental
) {
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
1442 for (i
= 0; i
< 8; i
++) {
1443 if (likely(acpi_ec_read(0x78 + i
, &t
))) {
1449 if (likely(acpi_ec_read(0xC0 + i
, &t
))) {
1457 /* This is sheer paranoia, but we handle it anyway */
1460 "ThinkPad ACPI EC access misbehaving, "
1461 "falling back to ACPI TMPx access mode\n");
1462 thermal_read_mode
= IBMACPI_THERMAL_ACPI_TMP07
;
1465 "ThinkPad ACPI EC access misbehaving, "
1466 "disabling thermal sensors access\n");
1467 thermal_read_mode
= IBMACPI_THERMAL_NONE
;
1472 IBMACPI_THERMAL_TPEC_16
: IBMACPI_THERMAL_TPEC_8
;
1474 } else if (acpi_tmp7
) {
1475 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
1476 /* 600e/x, 770e, 770x */
1477 thermal_read_mode
= IBMACPI_THERMAL_ACPI_UPDT
;
1479 /* Standard ACPI TMPx access, max 8 sensors */
1480 thermal_read_mode
= IBMACPI_THERMAL_ACPI_TMP07
;
1483 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1484 thermal_read_mode
= IBMACPI_THERMAL_NONE
;
1490 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
1494 char tmpi
[] = "TMPi";
1499 switch (thermal_read_mode
) {
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
))
1505 s
->temp
[i
+ 8] = tmp
* 1000;
1509 case IBMACPI_THERMAL_TPEC_8
:
1510 for (i
= 0; i
< 8; i
++) {
1511 if (!acpi_ec_read(0x78 + i
, &tmp
))
1513 s
->temp
[i
] = tmp
* 1000;
1515 return (thermal_read_mode
== IBMACPI_THERMAL_TPEC_16
) ? 16 : 8;
1517 case IBMACPI_THERMAL_ACPI_UPDT
:
1518 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
1520 for (i
= 0; i
< 8; i
++) {
1522 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1524 s
->temp
[i
] = (t
- 2732) * 100;
1528 case IBMACPI_THERMAL_ACPI_TMP07
:
1529 for (i
= 0; i
< 8; i
++) {
1531 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1533 s
->temp
[i
] = t
* 1000;
1537 case IBMACPI_THERMAL_NONE
:
1543 static int thermal_read(char *p
)
1547 struct ibm_thermal_sensors_struct t
;
1549 n
= thermal_get_sensors(&t
);
1550 if (unlikely(n
< 0))
1553 len
+= sprintf(p
+ len
, "temperatures:\t");
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);
1560 len
+= sprintf(p
+ len
, "not supported\n");
1565 static u8 ecdump_regs
[256];
1567 static int ecdump_read(char *p
)
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
))
1581 if (v
!= ecdump_regs
[i
+ j
])
1582 len
+= sprintf(p
+ len
, " *%02x", v
);
1584 len
+= sprintf(p
+ len
, " %02x", v
);
1585 ecdump_regs
[i
+ j
] = v
;
1587 len
+= sprintf(p
+ len
, "\n");
1592 /* These are way too dangerous to advertise openly... */
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");
1602 static int ecdump_write(char *buf
)
1607 while ((cmd
= next_cmd(&buf
))) {
1608 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
1610 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
1614 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
1615 if (!acpi_ec_write(i
, v
))
1624 static int brightness_offset
= 0x31;
1626 static int brightness_get(struct backlight_device
*bd
)
1629 if (!acpi_ec_read(brightness_offset
, &level
))
1636 static int brightness_read(char *p
)
1641 if ((level
= brightness_get(NULL
)) < 0) {
1642 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1644 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
1645 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
1646 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1647 " (<level> is 0-7)\n");
1653 #define BRIGHTNESS_UP 4
1654 #define BRIGHTNESS_DOWN 5
1656 static int brightness_set(int value
)
1658 int cmos_cmd
, inc
, i
;
1659 int current_value
= brightness_get(NULL
);
1663 cmos_cmd
= value
> current_value
? BRIGHTNESS_UP
: BRIGHTNESS_DOWN
;
1664 inc
= value
> current_value
? 1 : -1;
1665 for (i
= current_value
; i
!= value
; i
+= inc
) {
1666 if (!cmos_eval(cmos_cmd
))
1668 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
1675 static int brightness_write(char *buf
)
1681 while ((cmd
= next_cmd(&buf
))) {
1682 if ((level
= brightness_get(NULL
)) < 0)
1686 if (strlencmp(cmd
, "up") == 0) {
1687 new_level
= level
== 7 ? 7 : level
+ 1;
1688 } else if (strlencmp(cmd
, "down") == 0) {
1689 new_level
= level
== 0 ? 0 : level
- 1;
1690 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1691 new_level
>= 0 && new_level
<= 7) {
1696 brightness_set(new_level
);
1702 static int brightness_update_status(struct backlight_device
*bd
)
1704 return brightness_set(bd
->props
->brightness
);
1707 static int volume_offset
= 0x30;
1709 static int volume_read(char *p
)
1714 if (!acpi_ec_read(volume_offset
, &level
)) {
1715 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1717 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
1718 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
1719 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
1720 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1721 " (<level> is 0-15)\n");
1727 #define VOLUME_DOWN 0
1729 #define VOLUME_MUTE 2
1731 static int volume_write(char *buf
)
1733 int cmos_cmd
, inc
, i
;
1735 int new_level
, new_mute
;
1738 while ((cmd
= next_cmd(&buf
))) {
1739 if (!acpi_ec_read(volume_offset
, &level
))
1741 new_mute
= mute
= level
& 0x40;
1742 new_level
= level
= level
& 0xf;
1744 if (strlencmp(cmd
, "up") == 0) {
1748 new_level
= level
== 15 ? 15 : level
+ 1;
1749 } else if (strlencmp(cmd
, "down") == 0) {
1753 new_level
= level
== 0 ? 0 : level
- 1;
1754 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1755 new_level
>= 0 && new_level
<= 15) {
1757 } else if (strlencmp(cmd
, "mute") == 0) {
1762 if (new_level
!= level
) { /* mute doesn't change */
1763 cmos_cmd
= new_level
> level
? VOLUME_UP
: VOLUME_DOWN
;
1764 inc
= new_level
> level
? 1 : -1;
1766 if (mute
&& (!cmos_eval(cmos_cmd
) ||
1767 !acpi_ec_write(volume_offset
, level
)))
1770 for (i
= level
; i
!= new_level
; i
+= inc
)
1771 if (!cmos_eval(cmos_cmd
) ||
1772 !acpi_ec_write(volume_offset
, i
+ inc
))
1775 if (mute
&& (!cmos_eval(VOLUME_MUTE
) ||
1776 !acpi_ec_write(volume_offset
,
1781 if (new_mute
!= mute
) { /* level doesn't change */
1782 cmos_cmd
= new_mute
? VOLUME_MUTE
: VOLUME_UP
;
1784 if (!cmos_eval(cmos_cmd
) ||
1785 !acpi_ec_write(volume_offset
, level
+ new_mute
))
1793 static enum fan_status_access_mode fan_status_access_mode
;
1794 static enum fan_control_access_mode fan_control_access_mode
;
1795 static enum fan_control_commands fan_control_commands
;
1797 static int fan_init(void)
1801 fan_status_access_mode
= IBMACPI_FAN_NONE
;
1802 fan_control_access_mode
= IBMACPI_FAN_WR_NONE
;
1803 fan_control_commands
= 0;
1806 /* 570, 600e/x, 770e, 770x */
1807 fan_status_access_mode
= IBMACPI_FAN_RD_ACPI_GFAN
;
1809 /* all other ThinkPads: note that even old-style
1810 * ThinkPad ECs supports the fan control register */
1811 if (likely(acpi_ec_read(fan_status_offset
, &status
))) {
1812 fan_status_access_mode
= IBMACPI_FAN_RD_TPEC
;
1815 "ThinkPad ACPI EC access misbehaving, "
1816 "fan status and control unavailable\n");
1823 fan_control_access_mode
= IBMACPI_FAN_WR_ACPI_SFAN
;
1824 fan_control_commands
|=
1825 IBMACPI_FAN_CMD_LEVEL
| IBMACPI_FAN_CMD_ENABLE
;
1828 /* gfan without sfan means no fan control */
1829 /* all other models implement TP EC 0x2f control */
1833 fan_control_access_mode
=
1834 IBMACPI_FAN_WR_ACPI_FANS
;
1835 fan_control_commands
|=
1836 IBMACPI_FAN_CMD_SPEED
|
1837 IBMACPI_FAN_CMD_LEVEL
|
1838 IBMACPI_FAN_CMD_ENABLE
;
1840 fan_control_access_mode
= IBMACPI_FAN_WR_TPEC
;
1841 fan_control_commands
|=
1842 IBMACPI_FAN_CMD_LEVEL
|
1843 IBMACPI_FAN_CMD_ENABLE
;
1851 static int fan_get_status(u8
*status
)
1856 * Add IBMACPI_FAN_RD_ACPI_FANS ? */
1858 switch (fan_status_access_mode
) {
1859 case IBMACPI_FAN_RD_ACPI_GFAN
:
1860 /* 570, 600e/x, 770e, 770x */
1862 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
1870 case IBMACPI_FAN_RD_TPEC
:
1871 /* all except 570, 600e/x, 770e, 770x */
1872 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
1887 static int fan_get_speed(unsigned int *speed
)
1891 switch (fan_status_access_mode
) {
1892 case IBMACPI_FAN_RD_TPEC
:
1893 /* all except 570, 600e/x, 770e, 770x */
1894 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
1895 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
1899 *speed
= (hi
<< 8) | lo
;
1910 static int fan_read(char *p
)
1915 unsigned int speed
= 0;
1917 switch (fan_status_access_mode
) {
1918 case IBMACPI_FAN_RD_ACPI_GFAN
:
1919 /* 570, 600e/x, 770e, 770x */
1920 if ((rc
= fan_get_status(&status
)) < 0)
1923 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
1925 (status
!= 0) ? "enabled" : "disabled", status
);
1928 case IBMACPI_FAN_RD_TPEC
:
1929 /* all except 570, 600e/x, 770e, 770x */
1930 if ((rc
= fan_get_status(&status
)) < 0)
1933 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1934 (status
!= 0) ? "enabled" : "disabled");
1936 if ((rc
= fan_get_speed(&speed
)) < 0)
1939 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
1941 if (status
& IBMACPI_FAN_EC_DISENGAGED
)
1942 /* Disengaged mode takes precedence */
1943 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
1944 else if (status
& IBMACPI_FAN_EC_AUTO
)
1945 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
1947 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
1950 case IBMACPI_FAN_NONE
:
1952 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1955 if (fan_control_commands
& IBMACPI_FAN_CMD_LEVEL
) {
1956 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
1958 switch (fan_control_access_mode
) {
1959 case IBMACPI_FAN_WR_ACPI_SFAN
:
1960 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
1964 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
1965 "auto, disengaged)\n");
1970 if (fan_control_commands
& IBMACPI_FAN_CMD_ENABLE
)
1971 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1973 if (fan_control_commands
& IBMACPI_FAN_CMD_SPEED
)
1974 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
1975 " (<speed> is 0-65535)\n");
1980 static int fan_set_level(int level
)
1982 switch (fan_control_access_mode
) {
1983 case IBMACPI_FAN_WR_ACPI_SFAN
:
1984 if (level
>= 0 && level
<= 7) {
1985 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
1991 case IBMACPI_FAN_WR_ACPI_FANS
:
1992 case IBMACPI_FAN_WR_TPEC
:
1993 if ((level
!= IBMACPI_FAN_EC_AUTO
) &&
1994 (level
!= IBMACPI_FAN_EC_DISENGAGED
) &&
1995 ((level
< 0) || (level
> 7)))
1998 if (!acpi_ec_write(fan_status_offset
, level
))
2008 static int fan_set_enable(void)
2013 switch (fan_control_access_mode
) {
2014 case IBMACPI_FAN_WR_ACPI_FANS
:
2015 case IBMACPI_FAN_WR_TPEC
:
2016 if ((rc
= fan_get_status(&s
)) < 0)
2019 /* Don't go out of emergency fan mode */
2021 s
= IBMACPI_FAN_EC_AUTO
;
2023 if (!acpi_ec_write(fan_status_offset
, s
))
2027 case IBMACPI_FAN_WR_ACPI_SFAN
:
2028 if ((rc
= fan_get_status(&s
)) < 0)
2033 /* Set fan to at least level 4 */
2037 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
2047 static int fan_set_disable(void)
2049 switch (fan_control_access_mode
) {
2050 case IBMACPI_FAN_WR_ACPI_FANS
:
2051 case IBMACPI_FAN_WR_TPEC
:
2052 if (!acpi_ec_write(fan_status_offset
, 0x00))
2056 case IBMACPI_FAN_WR_ACPI_SFAN
:
2057 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
2067 static int fan_set_speed(int speed
)
2069 switch (fan_control_access_mode
) {
2070 case IBMACPI_FAN_WR_ACPI_FANS
:
2071 if (speed
>= 0 && speed
<= 65535) {
2072 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
2073 speed
, speed
, speed
))
2085 static int fan_write_cmd_level(const char *cmd
, int *rc
)
2089 if (strlencmp(cmd
, "level auto") == 0)
2090 level
= IBMACPI_FAN_EC_AUTO
;
2091 else if (strlencmp(cmd
, "level disengaged") == 0)
2092 level
= IBMACPI_FAN_EC_DISENGAGED
;
2093 else if (sscanf(cmd
, "level %d", &level
) != 1)
2096 if ((*rc
= fan_set_level(level
)) == -ENXIO
)
2097 printk(IBM_ERR
"level command accepted for unsupported "
2098 "access mode %d", fan_control_access_mode
);
2103 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
2105 if (strlencmp(cmd
, "enable") != 0)
2108 if ((*rc
= fan_set_enable()) == -ENXIO
)
2109 printk(IBM_ERR
"enable command accepted for unsupported "
2110 "access mode %d", fan_control_access_mode
);
2115 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
2117 if (strlencmp(cmd
, "disable") != 0)
2120 if ((*rc
= fan_set_disable()) == -ENXIO
)
2121 printk(IBM_ERR
"disable command accepted for unsupported "
2122 "access mode %d", fan_control_access_mode
);
2127 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
2132 * Support speed <low> <medium> <high> ? */
2134 if (sscanf(cmd
, "speed %d", &speed
) != 1)
2137 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
2138 printk(IBM_ERR
"speed command accepted for unsupported "
2139 "access mode %d", fan_control_access_mode
);
2144 static int fan_write(char *buf
)
2149 while (!rc
&& (cmd
= next_cmd(&buf
))) {
2150 if (!((fan_control_commands
& IBMACPI_FAN_CMD_LEVEL
) &&
2151 fan_write_cmd_level(cmd
, &rc
)) &&
2152 !((fan_control_commands
& IBMACPI_FAN_CMD_ENABLE
) &&
2153 (fan_write_cmd_enable(cmd
, &rc
) ||
2154 fan_write_cmd_disable(cmd
, &rc
))) &&
2155 !((fan_control_commands
& IBMACPI_FAN_CMD_SPEED
) &&
2156 fan_write_cmd_speed(cmd
, &rc
))
2164 static struct ibm_struct ibms
[] = {
2167 .init
= driver_init
,
2168 .read
= driver_read
,
2172 .hid
= IBM_HKEY_HID
,
2173 .init
= hotkey_init
,
2174 .read
= hotkey_read
,
2175 .write
= hotkey_write
,
2176 .exit
= hotkey_exit
,
2177 .notify
= hotkey_notify
,
2178 .handle
= &hkey_handle
,
2179 .type
= ACPI_DEVICE_NOTIFY
,
2182 .name
= "bluetooth",
2183 .init
= bluetooth_init
,
2184 .read
= bluetooth_read
,
2185 .write
= bluetooth_write
,
2198 .write
= video_write
,
2205 .write
= light_write
,
2207 #ifdef CONFIG_ACPI_IBM_DOCK
2211 .write
= dock_write
,
2212 .notify
= dock_notify
,
2213 .handle
= &dock_handle
,
2214 .type
= ACPI_SYSTEM_NOTIFY
,
2219 .notify
= dock_notify
,
2220 .handle
= &pci_handle
,
2221 .type
= ACPI_SYSTEM_NOTIFY
,
2229 .notify
= bay_notify
,
2230 .handle
= &bay_handle
,
2231 .type
= ACPI_SYSTEM_NOTIFY
,
2236 .write
= cmos_write
,
2247 .write
= beep_write
,
2251 .init
= thermal_init
,
2252 .read
= thermal_read
,
2256 .read
= ecdump_read
,
2257 .write
= ecdump_write
,
2261 .name
= "brightness",
2262 .read
= brightness_read
,
2263 .write
= brightness_write
,
2267 .read
= volume_read
,
2268 .write
= volume_write
,
2279 static int dispatch_read(char *page
, char **start
, off_t off
, int count
,
2280 int *eof
, void *data
)
2282 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
2285 if (!ibm
|| !ibm
->read
)
2288 len
= ibm
->read(page
);
2292 if (len
<= off
+ count
)
2294 *start
= page
+ off
;
2304 static int dispatch_write(struct file
*file
, const char __user
* userbuf
,
2305 unsigned long count
, void *data
)
2307 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
2311 if (!ibm
|| !ibm
->write
)
2314 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
2318 if (copy_from_user(kernbuf
, userbuf
, count
)) {
2324 strcat(kernbuf
, ",");
2325 ret
= ibm
->write(kernbuf
);
2334 static void dispatch_notify(acpi_handle handle
, u32 event
, void *data
)
2336 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
2338 if (!ibm
|| !ibm
->notify
)
2341 ibm
->notify(ibm
, event
);
2344 static int __init
setup_notify(struct ibm_struct
*ibm
)
2352 ret
= acpi_bus_get_device(*ibm
->handle
, &ibm
->device
);
2354 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
2358 acpi_driver_data(ibm
->device
) = ibm
;
2359 sprintf(acpi_device_class(ibm
->device
), "%s/%s", IBM_NAME
, ibm
->name
);
2361 status
= acpi_install_notify_handler(*ibm
->handle
, ibm
->type
,
2362 dispatch_notify
, ibm
);
2363 if (ACPI_FAILURE(status
)) {
2364 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
2372 static int __init
ibm_device_add(struct acpi_device
*device
)
2377 static int __init
register_driver(struct ibm_struct
*ibm
)
2381 ibm
->driver
= kmalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
2383 printk(IBM_ERR
"kmalloc(ibm->driver) failed\n");
2387 memset(ibm
->driver
, 0, sizeof(struct acpi_driver
));
2388 sprintf(ibm
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
2389 ibm
->driver
->ids
= ibm
->hid
;
2390 ibm
->driver
->ops
.add
= &ibm_device_add
;
2392 ret
= acpi_bus_register_driver(ibm
->driver
);
2394 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
2402 static int __init
ibm_init(struct ibm_struct
*ibm
)
2405 struct proc_dir_entry
*entry
;
2407 if (ibm
->experimental
&& !experimental
)
2411 ret
= register_driver(ibm
);
2414 ibm
->driver_registered
= 1;
2421 ibm
->init_called
= 1;
2425 entry
= create_proc_entry(ibm
->name
,
2426 S_IFREG
| S_IRUGO
| S_IWUSR
,
2429 printk(IBM_ERR
"unable to create proc entry %s\n",
2433 entry
->owner
= THIS_MODULE
;
2435 entry
->read_proc
= &dispatch_read
;
2437 entry
->write_proc
= &dispatch_write
;
2438 ibm
->proc_created
= 1;
2442 ret
= setup_notify(ibm
);
2445 ibm
->notify_installed
= 1;
2451 static void ibm_exit(struct ibm_struct
*ibm
)
2453 if (ibm
->notify_installed
)
2454 acpi_remove_notify_handler(*ibm
->handle
, ibm
->type
,
2457 if (ibm
->proc_created
)
2458 remove_proc_entry(ibm
->name
, proc_dir
);
2460 if (ibm
->init_called
&& ibm
->exit
)
2463 if (ibm
->driver_registered
) {
2464 acpi_bus_unregister_driver(ibm
->driver
);
2469 static void __init
ibm_handle_init(char *name
,
2470 acpi_handle
* handle
, acpi_handle parent
,
2471 char **paths
, int num_paths
, char **path
)
2476 for (i
= 0; i
< num_paths
; i
++) {
2477 status
= acpi_get_handle(parent
, paths
[i
], handle
);
2478 if (ACPI_SUCCESS(status
)) {
2487 #define IBM_HANDLE_INIT(object) \
2488 ibm_handle_init(#object, &object##_handle, *object##_parent, \
2489 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
2491 static int set_ibm_param(const char *val
, struct kernel_param
*kp
)
2495 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++)
2496 if (strcmp(ibms
[i
].name
, kp
->name
) == 0 && ibms
[i
].write
) {
2497 if (strlen(val
) > sizeof(ibms
[i
].param
) - 2)
2499 strcpy(ibms
[i
].param
, val
);
2500 strcat(ibms
[i
].param
, ",");
2507 #define IBM_PARAM(feature) \
2508 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
2511 IBM_PARAM(bluetooth
);
2514 #ifdef CONFIG_ACPI_IBM_DOCK
2522 IBM_PARAM(brightness
);
2526 static struct backlight_properties ibm_backlight_data
= {
2527 .owner
= THIS_MODULE
,
2528 .get_brightness
= brightness_get
,
2529 .update_status
= brightness_update_status
,
2530 .max_brightness
= 7,
2533 static void acpi_ibm_exit(void)
2537 if (ibm_backlight_device
)
2538 backlight_device_unregister(ibm_backlight_device
);
2540 for (i
= ARRAY_SIZE(ibms
) - 1; i
>= 0; i
--)
2543 remove_proc_entry(IBM_DIR
, acpi_root_dir
);
2545 if (ibm_thinkpad_ec_found
)
2546 kfree(ibm_thinkpad_ec_found
);
2549 static char* __init
check_dmi_for_ec(void)
2551 struct dmi_device
*dev
= NULL
;
2552 char ec_fw_string
[18];
2555 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2556 * X32 or newer, all Z series; Some models must have an
2557 * up-to-date BIOS or they will not be detected.
2559 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2561 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
2562 if (sscanf(dev
->name
,
2563 "IBM ThinkPad Embedded Controller -[%17c",
2564 ec_fw_string
) == 1) {
2565 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
2566 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
2567 return kstrdup(ec_fw_string
, GFP_KERNEL
);
2573 static int __init
acpi_ibm_init(void)
2580 if (!acpi_specific_hotkey_enabled
) {
2581 printk(IBM_ERR
"using generic hotkey driver\n");
2585 /* ec is required because many other handles are relative to it */
2586 IBM_HANDLE_INIT(ec
);
2588 printk(IBM_ERR
"ec object not found\n");
2592 /* Models with newer firmware report the EC in DMI */
2593 ibm_thinkpad_ec_found
= check_dmi_for_ec();
2594 if (ibm_thinkpad_ec_found
)
2595 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
2596 ibm_thinkpad_ec_found
);
2598 /* these handles are not required */
2599 IBM_HANDLE_INIT(vid
);
2600 IBM_HANDLE_INIT(vid2
);
2601 IBM_HANDLE_INIT(ledb
);
2602 IBM_HANDLE_INIT(led
);
2603 IBM_HANDLE_INIT(hkey
);
2604 IBM_HANDLE_INIT(lght
);
2605 IBM_HANDLE_INIT(cmos
);
2606 #ifdef CONFIG_ACPI_IBM_DOCK
2607 IBM_HANDLE_INIT(dock
);
2609 IBM_HANDLE_INIT(pci
);
2610 IBM_HANDLE_INIT(bay
);
2612 IBM_HANDLE_INIT(bay_ej
);
2613 IBM_HANDLE_INIT(bay2
);
2615 IBM_HANDLE_INIT(bay2_ej
);
2616 IBM_HANDLE_INIT(beep
);
2617 IBM_HANDLE_INIT(ecrd
);
2618 IBM_HANDLE_INIT(ecwr
);
2619 IBM_HANDLE_INIT(fans
);
2620 IBM_HANDLE_INIT(gfan
);
2621 IBM_HANDLE_INIT(sfan
);
2623 proc_dir
= proc_mkdir(IBM_DIR
, acpi_root_dir
);
2625 printk(IBM_ERR
"unable to create proc dir %s", IBM_DIR
);
2628 proc_dir
->owner
= THIS_MODULE
;
2630 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++) {
2631 ret
= ibm_init(&ibms
[i
]);
2632 if (ret
>= 0 && *ibms
[i
].param
)
2633 ret
= ibms
[i
].write(ibms
[i
].param
);
2640 ibm_backlight_device
= backlight_device_register("ibm", NULL
,
2641 &ibm_backlight_data
);
2642 if (IS_ERR(ibm_backlight_device
)) {
2643 printk(IBM_ERR
"Could not register ibm backlight device\n");
2644 ibm_backlight_device
= NULL
;
2651 module_init(acpi_ibm_init
);
2652 module_exit(acpi_ibm_exit
);