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/proc_fs.h>
81 #include <linux/backlight.h>
82 #include <asm/uaccess.h>
83 #include <linux/dmi.h>
85 #include <acpi/acpi_drivers.h>
86 #include <acpi/acnamesp.h>
88 #define IBM_NAME "ibm"
89 #define IBM_DESC "IBM ThinkPad ACPI Extras"
90 #define IBM_FILE "ibm_acpi"
91 #define IBM_URL "http://ibm-acpi.sf.net/"
93 MODULE_AUTHOR("Borislav Deianov");
94 MODULE_DESCRIPTION(IBM_DESC
);
95 MODULE_VERSION(IBM_VERSION
);
96 MODULE_LICENSE("GPL");
98 #define IBM_DIR IBM_NAME
100 #define IBM_LOG IBM_FILE ": "
101 #define IBM_ERR KERN_ERR IBM_LOG
102 #define IBM_NOTICE KERN_NOTICE IBM_LOG
103 #define IBM_INFO KERN_INFO IBM_LOG
104 #define IBM_DEBUG KERN_DEBUG IBM_LOG
106 #define IBM_MAX_ACPI_ARGS 3
108 #define __unused __attribute__ ((unused))
110 static int experimental
;
111 module_param(experimental
, int, 0);
113 static acpi_handle root_handle
= NULL
;
115 #define IBM_HANDLE(object, parent, paths...) \
116 static acpi_handle object##_handle; \
117 static acpi_handle *object##_parent = &parent##_handle; \
118 static char *object##_path; \
119 static char *object##_paths[] = { paths }
122 * The following models are supported to various degrees:
124 * 570, 600e, 600x, 770e, 770x
125 * A20m, A21e, A21m, A21p, A22p, A30, A30p, A31, A31p
127 * R30, R31, R32, R40, R40e, R50, R50e, R50p, R51
128 * T20, T21, T22, T23, T30, T40, T40p, T41, T41p, T42, T42p, T43
129 * X20, X21, X22, X23, X24, X30, X31, X40
131 * The following models have no supported features:
135 * Still missing DSDTs for the following models:
143 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
144 "\\_SB.PCI.ISA.EC", /* 570 */
145 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
146 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
147 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
148 "\\_SB.PCI0.ICH3.EC0", /* R31 */
149 "\\_SB.PCI0.LPC.EC", /* all others */
152 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
153 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
154 "\\_SB.PCI0.VID0", /* 770e */
155 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
156 "\\_SB.PCI0.AGP.VID", /* all others */
159 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
161 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
162 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
163 "\\CMS", /* R40, R40e */
165 #ifdef CONFIG_ACPI_IBM_DOCK
166 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
167 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
168 "\\_SB.PCI0.PCI1.DOCK", /* all others */
169 "\\_SB.PCI.ISA.SLCE", /* 570 */
170 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
172 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
173 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
174 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
175 ); /* A21e, R30, R31 */
177 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
178 "_EJ0", /* all others */
179 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
181 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
182 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
185 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
189 /* don't list other alternatives as we install a notify handler on the 570 */
190 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
192 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
193 "^HKEY", /* R30, R31 */
194 "HKEY", /* all others */
197 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
198 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
200 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
201 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
202 "LED", /* all others */
205 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
206 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
207 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
208 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
210 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
211 "\\FSPD", /* 600e/x, 770e, 770x */
214 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
215 "JFNS", /* 770x-JL */
218 #define IBM_HKEY_HID "IBM0068"
219 #define IBM_PCI_HID "PNP0A03"
221 enum thermal_access_mode
{
222 IBMACPI_THERMAL_NONE
= 0, /* No thermal support */
223 IBMACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
224 IBMACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
225 IBMACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
226 IBMACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
229 #define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
230 struct ibm_thermal_sensors_struct
{
231 s32 temp
[IBMACPI_MAX_THERMAL_SENSORS
];
237 * IBMACPI_FAN_RD_ACPI_GFAN:
238 * ACPI GFAN method: returns fan level
240 * see IBMACPI_FAN_WR_ACPI_SFAN
241 * EC 0x2f not available if GFAN exists
243 * IBMACPI_FAN_WR_ACPI_SFAN:
244 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
246 * EC 0x2f might be available *for reading*, but never for writing.
248 * IBMACPI_FAN_WR_TPEC:
249 * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported
250 * on almost all ThinkPads
252 * Fan speed changes of any sort (including those caused by the
253 * disengaged mode) are usually done slowly by the firmware as the
254 * maximum ammount of fan duty cycle change per second seems to be
257 * Reading is not available if GFAN exists.
258 * Writing is not available if SFAN exists.
261 * 7 automatic mode engaged;
262 * (default operation mode of the ThinkPad)
263 * fan level is ignored in this mode.
264 * 6 disengage mode (takes precedence over bit 7);
265 * not available on all thinkpads. May disable
266 * the tachometer, and speeds up fan to 100% duty-cycle,
267 * which speeds it up far above the standard RPM
268 * levels. It is not impossible that it could cause
270 * 5-3 unused in some models. Extra bits for fan level
271 * in others, but still useless as all values above
272 * 7 map to the same speed as level 7 in these models.
273 * 2-0 fan level (0..7 usually)
275 * 0x07 = max (set when temperatures critical)
276 * Some ThinkPads may have other levels, see
277 * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
279 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
280 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
281 * does so, its initial value is meaningless (0x07).
283 * For firmware bugs, refer to:
284 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
288 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
289 * Main fan tachometer reading (in RPM)
291 * This register is present on all ThinkPads with a new-style EC, and
292 * it is known not to be present on the A21m/e, and T22, as there is
293 * something else in offset 0x84 according to the ACPI DSDT. Other
294 * ThinkPads from this same time period (and earlier) probably lack the
295 * tachometer as well.
297 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
298 * was never fixed by IBM to report the EC firmware version string
299 * probably support the tachometer (like the early X models), so
300 * detecting it is quite hard. We need more data to know for sure.
302 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
305 * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this
306 * register is not invalidated in ThinkPads that disable tachometer
307 * readings. Thus, the tachometer readings go stale.
309 * For firmware bugs, refer to:
310 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
312 * IBMACPI_FAN_WR_ACPI_FANS:
313 * ThinkPad X31, X40, X41. Not available in the X60.
315 * FANS ACPI handle: takes three arguments: low speed, medium speed,
316 * high speed. ACPI DSDT seems to map these three speeds to levels
317 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
318 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
320 * The speeds are stored on handles
321 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
323 * There are three default speed sets, acessible as handles:
324 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
326 * ACPI DSDT switches which set is in use depending on various
329 * IBMACPI_FAN_WR_TPEC is also available and should be used to
330 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
331 * but the ACPI tables just mention level 7.
334 enum fan_status_access_mode
{
335 IBMACPI_FAN_NONE
= 0, /* No fan status or control */
336 IBMACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
337 IBMACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
340 enum fan_control_access_mode
{
341 IBMACPI_FAN_WR_NONE
= 0, /* No fan control */
342 IBMACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
343 IBMACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
344 IBMACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
347 enum fan_control_commands
{
348 IBMACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
349 IBMACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
350 IBMACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd */
353 enum { /* Fan control constants */
354 fan_status_offset
= 0x2f, /* EC register 0x2f */
355 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
356 * 0x84 must be read before 0x85 */
358 IBMACPI_FAN_EC_DISENGAGED
= 0x40, /* EC mode: tachometer
360 IBMACPI_FAN_EC_AUTO
= 0x80, /* EC mode: auto fan
364 static int ibm_thinkpad_ec_found
;
371 struct acpi_driver
*driver
;
374 int (*read
) (char *);
375 int (*write
) (char *);
378 void (*notify
) (struct ibm_struct
*, u32
);
381 struct acpi_device
*device
;
383 int driver_registered
;
386 int notify_installed
;
391 static struct proc_dir_entry
*proc_dir
= NULL
;
393 static struct backlight_device
*ibm_backlight_device
;
395 #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
396 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
397 #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
399 static int acpi_evalf(acpi_handle handle
,
400 void *res
, char *method
, char *fmt
, ...)
403 struct acpi_object_list params
;
404 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
405 struct acpi_buffer result
, *resultp
;
406 union acpi_object out_obj
;
414 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
427 params
.pointer
= &in_objs
[0];
434 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
435 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
437 /* add more types as needed */
439 printk(IBM_ERR
"acpi_evalf() called "
440 "with invalid format character '%c'\n", c
);
446 if (res_type
!= 'v') {
447 result
.length
= sizeof(out_obj
);
448 result
.pointer
= &out_obj
;
453 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
458 *(int *)res
= out_obj
.integer
.value
;
459 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
462 success
= status
== AE_OK
;
464 /* add more types as needed */
466 printk(IBM_ERR
"acpi_evalf() called "
467 "with invalid format character '%c'\n", res_type
);
471 if (!success
&& !quiet
)
472 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
473 method
, fmt0
, status
);
478 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
482 if (acpi_evalf(handle
, &i
, method
, "d"))
483 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
485 printk(IBM_ERR
"error calling %s\n", method
);
488 static char *next_cmd(char **cmds
)
493 while ((end
= strchr(start
, ',')) && end
== start
)
504 static int driver_init(void)
506 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
507 printk(IBM_INFO
"%s\n", IBM_URL
);
512 static int driver_read(char *p
)
516 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
517 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
522 static int hotkey_supported
;
523 static int hotkey_mask_supported
;
524 static int hotkey_orig_status
;
525 static int hotkey_orig_mask
;
527 static int hotkey_get(int *status
, int *mask
)
529 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
532 if (hotkey_mask_supported
)
533 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
539 static int hotkey_set(int status
, int mask
)
543 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
546 if (hotkey_mask_supported
)
547 for (i
= 0; i
< 32; i
++) {
548 int bit
= ((1 << i
) & mask
) != 0;
549 if (!acpi_evalf(hkey_handle
,
550 NULL
, "MHKM", "vdd", i
+ 1, bit
))
557 static int hotkey_init(void)
559 /* hotkey not supported on 570 */
560 hotkey_supported
= hkey_handle
!= NULL
;
562 if (hotkey_supported
) {
563 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
564 A30, R30, R31, T20-22, X20-21, X22-24 */
565 hotkey_mask_supported
=
566 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
568 if (!hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
))
575 static int hotkey_read(char *p
)
580 if (!hotkey_supported
) {
581 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
585 if (!hotkey_get(&status
, &mask
))
588 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
589 if (hotkey_mask_supported
) {
590 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
591 len
+= sprintf(p
+ len
,
592 "commands:\tenable, disable, reset, <mask>\n");
594 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
595 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
601 static int hotkey_write(char *buf
)
607 if (!hotkey_supported
)
610 if (!hotkey_get(&status
, &mask
))
613 while ((cmd
= next_cmd(&buf
))) {
614 if (strlencmp(cmd
, "enable") == 0) {
616 } else if (strlencmp(cmd
, "disable") == 0) {
618 } else if (strlencmp(cmd
, "reset") == 0) {
619 status
= hotkey_orig_status
;
620 mask
= hotkey_orig_mask
;
621 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
623 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
630 if (do_cmd
&& !hotkey_set(status
, mask
))
636 static void hotkey_exit(void)
638 if (hotkey_supported
)
639 hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
642 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
646 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
647 acpi_bus_generate_event(ibm
->device
, event
, hkey
);
649 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
650 acpi_bus_generate_event(ibm
->device
, event
, 0);
654 static int bluetooth_supported
;
656 static int bluetooth_init(void)
658 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
659 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
660 bluetooth_supported
= hkey_handle
&&
661 acpi_evalf(hkey_handle
, NULL
, "GBDC", "qv");
666 static int bluetooth_status(void)
670 if (!bluetooth_supported
||
671 !acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
677 static int bluetooth_read(char *p
)
680 int status
= bluetooth_status();
682 if (!bluetooth_supported
)
683 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
684 else if (!(status
& 1))
685 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
687 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
688 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
694 static int bluetooth_write(char *buf
)
696 int status
= bluetooth_status();
700 if (!bluetooth_supported
)
703 while ((cmd
= next_cmd(&buf
))) {
704 if (strlencmp(cmd
, "enable") == 0) {
706 } else if (strlencmp(cmd
, "disable") == 0) {
713 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
719 static int wan_supported
;
721 static int wan_init(void)
723 wan_supported
= hkey_handle
&&
724 acpi_evalf(hkey_handle
, NULL
, "GWAN", "qv");
729 static int wan_status(void)
733 if (!wan_supported
|| !acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
739 static int wan_read(char *p
)
742 int status
= wan_status();
745 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
746 else if (!(status
& 1))
747 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
749 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
750 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
756 static int wan_write(char *buf
)
758 int status
= wan_status();
765 while ((cmd
= next_cmd(&buf
))) {
766 if (strlencmp(cmd
, "enable") == 0) {
768 } else if (strlencmp(cmd
, "disable") == 0) {
775 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
781 static int video_supported
;
782 static int video_orig_autosw
;
788 static int video_init(void)
792 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
793 /* G41, assume IVGA doesn't change */
794 vid_handle
= vid2_handle
;
797 /* video switching not supported on R30, R31 */
799 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
801 video_supported
= VIDEO_570
;
802 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
803 /* 600e/x, 770e, 770x */
804 video_supported
= VIDEO_770
;
807 video_supported
= VIDEO_NEW
;
812 static int video_status(void)
817 if (video_supported
== VIDEO_570
) {
818 if (acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd", 0x87))
820 } else if (video_supported
== VIDEO_770
) {
821 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
823 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
825 } else if (video_supported
== VIDEO_NEW
) {
826 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1);
827 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
830 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0);
831 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
833 if (acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
840 static int video_autosw(void)
844 if (video_supported
== VIDEO_570
)
845 acpi_evalf(vid_handle
, &autosw
, "SWIT", "d");
846 else if (video_supported
== VIDEO_770
|| video_supported
== VIDEO_NEW
)
847 acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d");
852 static int video_read(char *p
)
854 int status
= video_status();
855 int autosw
= video_autosw();
858 if (!video_supported
) {
859 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
863 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
864 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
865 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
866 if (video_supported
== VIDEO_NEW
)
867 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
868 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
869 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
870 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
871 if (video_supported
== VIDEO_NEW
)
872 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
873 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
874 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
879 static int video_switch(void)
881 int autosw
= video_autosw();
884 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
886 ret
= video_supported
== VIDEO_570
?
887 acpi_evalf(ec_handle
, NULL
, "_Q16", "v") :
888 acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
889 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
894 static int video_expand(void)
896 if (video_supported
== VIDEO_570
)
897 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v");
898 else if (video_supported
== VIDEO_770
)
899 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v");
901 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v");
904 static int video_switch2(int status
)
908 if (video_supported
== VIDEO_570
) {
909 ret
= acpi_evalf(NULL
, NULL
,
910 "\\_SB.PHS2", "vdd", 0x8b, status
| 0x80);
911 } else if (video_supported
== VIDEO_770
) {
912 int autosw
= video_autosw();
913 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
916 ret
= acpi_evalf(vid_handle
, NULL
,
917 "ASWT", "vdd", status
* 0x100, 0);
919 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
921 ret
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
922 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
928 static int video_write(char *buf
)
931 int enable
, disable
, status
;
933 if (!video_supported
)
936 enable
= disable
= 0;
938 while ((cmd
= next_cmd(&buf
))) {
939 if (strlencmp(cmd
, "lcd_enable") == 0) {
941 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
943 } else if (strlencmp(cmd
, "crt_enable") == 0) {
945 } else if (strlencmp(cmd
, "crt_disable") == 0) {
947 } else if (video_supported
== VIDEO_NEW
&&
948 strlencmp(cmd
, "dvi_enable") == 0) {
950 } else if (video_supported
== VIDEO_NEW
&&
951 strlencmp(cmd
, "dvi_disable") == 0) {
953 } else if (strlencmp(cmd
, "auto_enable") == 0) {
954 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
956 } else if (strlencmp(cmd
, "auto_disable") == 0) {
957 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 0))
959 } else if (strlencmp(cmd
, "video_switch") == 0) {
962 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
969 if (enable
|| disable
) {
970 status
= (video_status() & 0x0f & ~disable
) | enable
;
971 if (!video_switch2(status
))
978 static void video_exit(void)
980 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", video_orig_autosw
);
983 static int light_supported
;
984 static int light_status_supported
;
986 static int light_init(void)
988 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
989 light_supported
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
992 /* light status not supported on
993 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
994 light_status_supported
= acpi_evalf(ec_handle
, NULL
,
1000 static int light_read(char *p
)
1005 if (!light_supported
) {
1006 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1007 } else if (!light_status_supported
) {
1008 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1009 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1011 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1013 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1014 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1020 static int light_write(char *buf
)
1022 int cmos_cmd
, lght_cmd
;
1026 if (!light_supported
)
1029 while ((cmd
= next_cmd(&buf
))) {
1030 if (strlencmp(cmd
, "on") == 0) {
1033 } else if (strlencmp(cmd
, "off") == 0) {
1039 success
= cmos_handle
?
1040 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1041 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1049 static int _sta(acpi_handle handle
)
1053 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
1059 #ifdef CONFIG_ACPI_IBM_DOCK
1060 #define dock_docked() (_sta(dock_handle) & 1)
1062 static int dock_read(char *p
)
1065 int docked
= dock_docked();
1068 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1070 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1072 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1073 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1079 static int dock_write(char *buf
)
1086 while ((cmd
= next_cmd(&buf
))) {
1087 if (strlencmp(cmd
, "undock") == 0) {
1088 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1089 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1091 } else if (strlencmp(cmd
, "dock") == 0) {
1092 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1101 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1103 int docked
= dock_docked();
1104 int pci
= ibm
->hid
&& strstr(ibm
->hid
, IBM_PCI_HID
);
1106 if (event
== 1 && !pci
) /* 570 */
1107 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1108 else if (event
== 1 && pci
) /* 570 */
1109 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1110 else if (event
== 3 && docked
)
1111 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1112 else if (event
== 3 && !docked
)
1113 acpi_bus_generate_event(ibm
->device
, event
, 2); /* undock */
1114 else if (event
== 0 && docked
)
1115 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1117 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1118 event
, _sta(dock_handle
));
1119 acpi_bus_generate_event(ibm
->device
, event
, 0); /* unknown */
1124 static int bay_status_supported
;
1125 static int bay_status2_supported
;
1126 static int bay_eject_supported
;
1127 static int bay_eject2_supported
;
1129 static int bay_init(void)
1131 bay_status_supported
= bay_handle
&&
1132 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1133 bay_status2_supported
= bay2_handle
&&
1134 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1136 bay_eject_supported
= bay_handle
&& bay_ej_handle
&&
1137 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1138 bay_eject2_supported
= bay2_handle
&& bay2_ej_handle
&&
1139 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1144 #define bay_occupied(b) (_sta(b##_handle) & 1)
1146 static int bay_read(char *p
)
1149 int occupied
= bay_occupied(bay
);
1150 int occupied2
= bay_occupied(bay2
);
1153 len
+= sprintf(p
+ len
, "status:\t\t%s\n", bay_status_supported
?
1154 (occupied
? "occupied" : "unoccupied") :
1156 if (bay_status2_supported
)
1157 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1158 "occupied" : "unoccupied");
1160 eject
= bay_eject_supported
&& occupied
;
1161 eject2
= bay_eject2_supported
&& occupied2
;
1163 if (eject
&& eject2
)
1164 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1166 len
+= sprintf(p
+ len
, "commands:\teject\n");
1168 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1173 static int bay_write(char *buf
)
1177 if (!bay_eject_supported
&& !bay_eject2_supported
)
1180 while ((cmd
= next_cmd(&buf
))) {
1181 if (bay_eject_supported
&& strlencmp(cmd
, "eject") == 0) {
1182 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1184 } else if (bay_eject2_supported
&&
1185 strlencmp(cmd
, "eject2") == 0) {
1186 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1195 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1197 acpi_bus_generate_event(ibm
->device
, event
, 0);
1200 static int cmos_read(char *p
)
1204 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1205 R30, R31, T20-22, X20-21 */
1207 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1209 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1210 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1216 static int cmos_eval(int cmos_cmd
)
1219 return acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
);
1224 static int cmos_write(char *buf
)
1232 while ((cmd
= next_cmd(&buf
))) {
1233 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1234 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1239 if (!cmos_eval(cmos_cmd
))
1246 static int led_supported
;
1252 static int led_init(void)
1255 /* led not supported on R30, R31 */
1257 else if (strlencmp(led_path
, "SLED") == 0)
1259 led_supported
= LED_570
;
1260 else if (strlencmp(led_path
, "SYSL") == 0)
1261 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1262 led_supported
= LED_OLD
;
1265 led_supported
= LED_NEW
;
1270 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1272 static int led_read(char *p
)
1276 if (!led_supported
) {
1277 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1280 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1282 if (led_supported
== LED_570
) {
1285 for (i
= 0; i
< 8; i
++) {
1286 if (!acpi_evalf(ec_handle
,
1287 &status
, "GLED", "dd", 1 << i
))
1289 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1290 i
, led_status(status
));
1294 len
+= sprintf(p
+ len
, "commands:\t"
1295 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1300 /* off, on, blink */
1301 static const int led_sled_arg1
[] = { 0, 1, 3 };
1302 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
1303 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
1304 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
1306 #define EC_HLCL 0x0c
1307 #define EC_HLBL 0x0d
1308 #define EC_HLMS 0x0e
1310 static int led_write(char *buf
)
1318 while ((cmd
= next_cmd(&buf
))) {
1319 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1322 if (strstr(cmd
, "off")) {
1324 } else if (strstr(cmd
, "on")) {
1326 } else if (strstr(cmd
, "blink")) {
1331 if (led_supported
== LED_570
) {
1334 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1335 led
, led_sled_arg1
[ind
]))
1337 } else if (led_supported
== LED_OLD
) {
1338 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1340 ret
= ec_write(EC_HLMS
, led
);
1343 ec_write(EC_HLBL
, led
* led_exp_hlbl
[ind
]);
1346 ec_write(EC_HLCL
, led
* led_exp_hlcl
[ind
]);
1351 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1352 led
, led_led_arg1
[ind
]))
1360 static int beep_read(char *p
)
1365 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1367 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1368 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1374 static int beep_write(char *buf
)
1382 while ((cmd
= next_cmd(&buf
))) {
1383 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1384 beep_cmd
>= 0 && beep_cmd
<= 17) {
1388 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1395 static int acpi_ec_read(int i
, u8
* p
)
1400 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
1404 if (ec_read(i
, p
) < 0)
1411 static int acpi_ec_write(int i
, u8 v
)
1414 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
1417 if (ec_write(i
, v
) < 0)
1424 static enum thermal_access_mode thermal_read_mode
;
1426 static int thermal_init(void)
1430 int acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
1432 if (ibm_thinkpad_ec_found
&& experimental
) {
1434 * Direct EC access mode: sensors at registers
1435 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1436 * non-implemented, thermal sensors return 0x80 when
1441 for (i
= 0; i
< 8; i
++) {
1442 if (likely(acpi_ec_read(0x78 + i
, &t
))) {
1448 if (likely(acpi_ec_read(0xC0 + i
, &t
))) {
1456 /* This is sheer paranoia, but we handle it anyway */
1459 "ThinkPad ACPI EC access misbehaving, "
1460 "falling back to ACPI TMPx access mode\n");
1461 thermal_read_mode
= IBMACPI_THERMAL_ACPI_TMP07
;
1464 "ThinkPad ACPI EC access misbehaving, "
1465 "disabling thermal sensors access\n");
1466 thermal_read_mode
= IBMACPI_THERMAL_NONE
;
1471 IBMACPI_THERMAL_TPEC_16
: IBMACPI_THERMAL_TPEC_8
;
1473 } else if (acpi_tmp7
) {
1474 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
1475 /* 600e/x, 770e, 770x */
1476 thermal_read_mode
= IBMACPI_THERMAL_ACPI_UPDT
;
1478 /* Standard ACPI TMPx access, max 8 sensors */
1479 thermal_read_mode
= IBMACPI_THERMAL_ACPI_TMP07
;
1482 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1483 thermal_read_mode
= IBMACPI_THERMAL_NONE
;
1489 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
1493 char tmpi
[] = "TMPi";
1498 switch (thermal_read_mode
) {
1499 #if IBMACPI_MAX_THERMAL_SENSORS >= 16
1500 case IBMACPI_THERMAL_TPEC_16
:
1501 for (i
= 0; i
< 8; i
++) {
1502 if (!acpi_ec_read(0xC0 + i
, &tmp
))
1504 s
->temp
[i
+ 8] = tmp
* 1000;
1508 case IBMACPI_THERMAL_TPEC_8
:
1509 for (i
= 0; i
< 8; i
++) {
1510 if (!acpi_ec_read(0x78 + i
, &tmp
))
1512 s
->temp
[i
] = tmp
* 1000;
1514 return (thermal_read_mode
== IBMACPI_THERMAL_TPEC_16
) ? 16 : 8;
1516 case IBMACPI_THERMAL_ACPI_UPDT
:
1517 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
1519 for (i
= 0; i
< 8; i
++) {
1521 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1523 s
->temp
[i
] = (t
- 2732) * 100;
1527 case IBMACPI_THERMAL_ACPI_TMP07
:
1528 for (i
= 0; i
< 8; i
++) {
1530 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1532 s
->temp
[i
] = t
* 1000;
1536 case IBMACPI_THERMAL_NONE
:
1542 static int thermal_read(char *p
)
1546 struct ibm_thermal_sensors_struct t
;
1548 n
= thermal_get_sensors(&t
);
1549 if (unlikely(n
< 0))
1552 len
+= sprintf(p
+ len
, "temperatures:\t");
1555 for (i
= 0; i
< (n
- 1); i
++)
1556 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
1557 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
1559 len
+= sprintf(p
+ len
, "not supported\n");
1564 static u8 ecdump_regs
[256];
1566 static int ecdump_read(char *p
)
1572 len
+= sprintf(p
+ len
, "EC "
1573 " +00 +01 +02 +03 +04 +05 +06 +07"
1574 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1575 for (i
= 0; i
< 256; i
+= 16) {
1576 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
1577 for (j
= 0; j
< 16; j
++) {
1578 if (!acpi_ec_read(i
+ j
, &v
))
1580 if (v
!= ecdump_regs
[i
+ j
])
1581 len
+= sprintf(p
+ len
, " *%02x", v
);
1583 len
+= sprintf(p
+ len
, " %02x", v
);
1584 ecdump_regs
[i
+ j
] = v
;
1586 len
+= sprintf(p
+ len
, "\n");
1591 /* These are way too dangerous to advertise openly... */
1593 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
1594 " (<offset> is 00-ff, <value> is 00-ff)\n");
1595 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
1596 " (<offset> is 00-ff, <value> is 0-255)\n");
1601 static int ecdump_write(char *buf
)
1606 while ((cmd
= next_cmd(&buf
))) {
1607 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
1609 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
1613 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
1614 if (!acpi_ec_write(i
, v
))
1623 static int brightness_offset
= 0x31;
1625 static int brightness_get(struct backlight_device
*bd
)
1628 if (!acpi_ec_read(brightness_offset
, &level
))
1635 static int brightness_read(char *p
)
1640 if ((level
= brightness_get(NULL
)) < 0) {
1641 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1643 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
1644 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
1645 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1646 " (<level> is 0-7)\n");
1652 #define BRIGHTNESS_UP 4
1653 #define BRIGHTNESS_DOWN 5
1655 static int brightness_set(int value
)
1657 int cmos_cmd
, inc
, i
;
1658 int current_value
= brightness_get(NULL
);
1662 cmos_cmd
= value
> current_value
? BRIGHTNESS_UP
: BRIGHTNESS_DOWN
;
1663 inc
= value
> current_value
? 1 : -1;
1664 for (i
= current_value
; i
!= value
; i
+= inc
) {
1665 if (!cmos_eval(cmos_cmd
))
1667 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
1674 static int brightness_write(char *buf
)
1680 while ((cmd
= next_cmd(&buf
))) {
1681 if ((level
= brightness_get(NULL
)) < 0)
1685 if (strlencmp(cmd
, "up") == 0) {
1686 new_level
= level
== 7 ? 7 : level
+ 1;
1687 } else if (strlencmp(cmd
, "down") == 0) {
1688 new_level
= level
== 0 ? 0 : level
- 1;
1689 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1690 new_level
>= 0 && new_level
<= 7) {
1695 brightness_set(new_level
);
1701 static int brightness_update_status(struct backlight_device
*bd
)
1703 return brightness_set(bd
->props
->brightness
);
1706 static int volume_offset
= 0x30;
1708 static int volume_read(char *p
)
1713 if (!acpi_ec_read(volume_offset
, &level
)) {
1714 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1716 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
1717 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
1718 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
1719 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1720 " (<level> is 0-15)\n");
1726 #define VOLUME_DOWN 0
1728 #define VOLUME_MUTE 2
1730 static int volume_write(char *buf
)
1732 int cmos_cmd
, inc
, i
;
1734 int new_level
, new_mute
;
1737 while ((cmd
= next_cmd(&buf
))) {
1738 if (!acpi_ec_read(volume_offset
, &level
))
1740 new_mute
= mute
= level
& 0x40;
1741 new_level
= level
= level
& 0xf;
1743 if (strlencmp(cmd
, "up") == 0) {
1747 new_level
= level
== 15 ? 15 : level
+ 1;
1748 } else if (strlencmp(cmd
, "down") == 0) {
1752 new_level
= level
== 0 ? 0 : level
- 1;
1753 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1754 new_level
>= 0 && new_level
<= 15) {
1756 } else if (strlencmp(cmd
, "mute") == 0) {
1761 if (new_level
!= level
) { /* mute doesn't change */
1762 cmos_cmd
= new_level
> level
? VOLUME_UP
: VOLUME_DOWN
;
1763 inc
= new_level
> level
? 1 : -1;
1765 if (mute
&& (!cmos_eval(cmos_cmd
) ||
1766 !acpi_ec_write(volume_offset
, level
)))
1769 for (i
= level
; i
!= new_level
; i
+= inc
)
1770 if (!cmos_eval(cmos_cmd
) ||
1771 !acpi_ec_write(volume_offset
, i
+ inc
))
1774 if (mute
&& (!cmos_eval(VOLUME_MUTE
) ||
1775 !acpi_ec_write(volume_offset
,
1780 if (new_mute
!= mute
) { /* level doesn't change */
1781 cmos_cmd
= new_mute
? VOLUME_MUTE
: VOLUME_UP
;
1783 if (!cmos_eval(cmos_cmd
) ||
1784 !acpi_ec_write(volume_offset
, level
+ new_mute
))
1792 static enum fan_status_access_mode fan_status_access_mode
;
1793 static enum fan_control_access_mode fan_control_access_mode
;
1794 static enum fan_control_commands fan_control_commands
;
1796 static int fan_init(void)
1800 fan_status_access_mode
= IBMACPI_FAN_NONE
;
1801 fan_control_access_mode
= IBMACPI_FAN_WR_NONE
;
1802 fan_control_commands
= 0;
1805 /* 570, 600e/x, 770e, 770x */
1806 fan_status_access_mode
= IBMACPI_FAN_RD_ACPI_GFAN
;
1808 /* all other ThinkPads: note that even old-style
1809 * ThinkPad ECs supports the fan control register */
1810 if (likely(acpi_ec_read(fan_status_offset
, &status
))) {
1811 fan_status_access_mode
= IBMACPI_FAN_RD_TPEC
;
1814 "ThinkPad ACPI EC access misbehaving, "
1815 "fan status and control unavailable\n");
1822 fan_control_access_mode
= IBMACPI_FAN_WR_ACPI_SFAN
;
1823 fan_control_commands
|=
1824 IBMACPI_FAN_CMD_LEVEL
| IBMACPI_FAN_CMD_ENABLE
;
1827 /* gfan without sfan means no fan control */
1828 /* all other models implement TP EC 0x2f control */
1832 fan_control_access_mode
=
1833 IBMACPI_FAN_WR_ACPI_FANS
;
1834 fan_control_commands
|=
1835 IBMACPI_FAN_CMD_SPEED
|
1836 IBMACPI_FAN_CMD_LEVEL
|
1837 IBMACPI_FAN_CMD_ENABLE
;
1839 fan_control_access_mode
= IBMACPI_FAN_WR_TPEC
;
1840 fan_control_commands
|=
1841 IBMACPI_FAN_CMD_LEVEL
|
1842 IBMACPI_FAN_CMD_ENABLE
;
1850 static int fan_get_status(u8
*status
)
1855 * Add IBMACPI_FAN_RD_ACPI_FANS ? */
1857 switch (fan_status_access_mode
) {
1858 case IBMACPI_FAN_RD_ACPI_GFAN
:
1859 /* 570, 600e/x, 770e, 770x */
1861 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
1869 case IBMACPI_FAN_RD_TPEC
:
1870 /* all except 570, 600e/x, 770e, 770x */
1871 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
1886 static int fan_get_speed(unsigned int *speed
)
1890 switch (fan_status_access_mode
) {
1891 case IBMACPI_FAN_RD_TPEC
:
1892 /* all except 570, 600e/x, 770e, 770x */
1893 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
1894 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
1898 *speed
= (hi
<< 8) | lo
;
1909 static int fan_read(char *p
)
1914 unsigned int speed
= 0;
1916 switch (fan_status_access_mode
) {
1917 case IBMACPI_FAN_RD_ACPI_GFAN
:
1918 /* 570, 600e/x, 770e, 770x */
1919 if ((rc
= fan_get_status(&status
)) < 0)
1922 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
1924 (status
!= 0) ? "enabled" : "disabled", status
);
1927 case IBMACPI_FAN_RD_TPEC
:
1928 /* all except 570, 600e/x, 770e, 770x */
1929 if ((rc
= fan_get_status(&status
)) < 0)
1932 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
1933 (status
!= 0) ? "enabled" : "disabled");
1935 if ((rc
= fan_get_speed(&speed
)) < 0)
1938 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
1940 if (status
& IBMACPI_FAN_EC_DISENGAGED
)
1941 /* Disengaged mode takes precedence */
1942 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
1943 else if (status
& IBMACPI_FAN_EC_AUTO
)
1944 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
1946 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
1949 case IBMACPI_FAN_NONE
:
1951 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1954 if (fan_control_commands
& IBMACPI_FAN_CMD_LEVEL
) {
1955 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
1957 switch (fan_control_access_mode
) {
1958 case IBMACPI_FAN_WR_ACPI_SFAN
:
1959 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
1963 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
1964 "auto, disengaged)\n");
1969 if (fan_control_commands
& IBMACPI_FAN_CMD_ENABLE
)
1970 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
1972 if (fan_control_commands
& IBMACPI_FAN_CMD_SPEED
)
1973 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
1974 " (<speed> is 0-65535)\n");
1979 static int fan_set_level(int level
)
1981 switch (fan_control_access_mode
) {
1982 case IBMACPI_FAN_WR_ACPI_SFAN
:
1983 if (level
>= 0 && level
<= 7) {
1984 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
1990 case IBMACPI_FAN_WR_ACPI_FANS
:
1991 case IBMACPI_FAN_WR_TPEC
:
1992 if ((level
!= IBMACPI_FAN_EC_AUTO
) &&
1993 (level
!= IBMACPI_FAN_EC_DISENGAGED
) &&
1994 ((level
< 0) || (level
> 7)))
1997 if (!acpi_ec_write(fan_status_offset
, level
))
2007 static int fan_set_enable(void)
2012 switch (fan_control_access_mode
) {
2013 case IBMACPI_FAN_WR_ACPI_FANS
:
2014 case IBMACPI_FAN_WR_TPEC
:
2015 if ((rc
= fan_get_status(&s
)) < 0)
2018 /* Don't go out of emergency fan mode */
2020 s
= IBMACPI_FAN_EC_AUTO
;
2022 if (!acpi_ec_write(fan_status_offset
, s
))
2026 case IBMACPI_FAN_WR_ACPI_SFAN
:
2027 if ((rc
= fan_get_status(&s
)) < 0)
2032 /* Set fan to at least level 4 */
2036 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
2046 static int fan_set_disable(void)
2048 switch (fan_control_access_mode
) {
2049 case IBMACPI_FAN_WR_ACPI_FANS
:
2050 case IBMACPI_FAN_WR_TPEC
:
2051 if (!acpi_ec_write(fan_status_offset
, 0x00))
2055 case IBMACPI_FAN_WR_ACPI_SFAN
:
2056 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
2066 static int fan_set_speed(int speed
)
2068 switch (fan_control_access_mode
) {
2069 case IBMACPI_FAN_WR_ACPI_FANS
:
2070 if (speed
>= 0 && speed
<= 65535) {
2071 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
2072 speed
, speed
, speed
))
2084 static int fan_write_cmd_level(const char *cmd
, int *rc
)
2088 if (strlencmp(cmd
, "level auto") == 0)
2089 level
= IBMACPI_FAN_EC_AUTO
;
2090 else if (strlencmp(cmd
, "level disengaged") == 0)
2091 level
= IBMACPI_FAN_EC_DISENGAGED
;
2092 else if (sscanf(cmd
, "level %d", &level
) != 1)
2095 if ((*rc
= fan_set_level(level
)) == -ENXIO
)
2096 printk(IBM_ERR
"level command accepted for unsupported "
2097 "access mode %d", fan_control_access_mode
);
2102 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
2104 if (strlencmp(cmd
, "enable") != 0)
2107 if ((*rc
= fan_set_enable()) == -ENXIO
)
2108 printk(IBM_ERR
"enable command accepted for unsupported "
2109 "access mode %d", fan_control_access_mode
);
2114 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
2116 if (strlencmp(cmd
, "disable") != 0)
2119 if ((*rc
= fan_set_disable()) == -ENXIO
)
2120 printk(IBM_ERR
"disable command accepted for unsupported "
2121 "access mode %d", fan_control_access_mode
);
2126 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
2131 * Support speed <low> <medium> <high> ? */
2133 if (sscanf(cmd
, "speed %d", &speed
) != 1)
2136 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
2137 printk(IBM_ERR
"speed command accepted for unsupported "
2138 "access mode %d", fan_control_access_mode
);
2143 static int fan_write(char *buf
)
2148 while (!rc
&& (cmd
= next_cmd(&buf
))) {
2149 if (!((fan_control_commands
& IBMACPI_FAN_CMD_LEVEL
) &&
2150 fan_write_cmd_level(cmd
, &rc
)) &&
2151 !((fan_control_commands
& IBMACPI_FAN_CMD_ENABLE
) &&
2152 (fan_write_cmd_enable(cmd
, &rc
) ||
2153 fan_write_cmd_disable(cmd
, &rc
))) &&
2154 !((fan_control_commands
& IBMACPI_FAN_CMD_SPEED
) &&
2155 fan_write_cmd_speed(cmd
, &rc
))
2163 static struct ibm_struct ibms
[] = {
2166 .init
= driver_init
,
2167 .read
= driver_read
,
2171 .hid
= IBM_HKEY_HID
,
2172 .init
= hotkey_init
,
2173 .read
= hotkey_read
,
2174 .write
= hotkey_write
,
2175 .exit
= hotkey_exit
,
2176 .notify
= hotkey_notify
,
2177 .handle
= &hkey_handle
,
2178 .type
= ACPI_DEVICE_NOTIFY
,
2181 .name
= "bluetooth",
2182 .init
= bluetooth_init
,
2183 .read
= bluetooth_read
,
2184 .write
= bluetooth_write
,
2197 .write
= video_write
,
2204 .write
= light_write
,
2206 #ifdef CONFIG_ACPI_IBM_DOCK
2210 .write
= dock_write
,
2211 .notify
= dock_notify
,
2212 .handle
= &dock_handle
,
2213 .type
= ACPI_SYSTEM_NOTIFY
,
2218 .notify
= dock_notify
,
2219 .handle
= &pci_handle
,
2220 .type
= ACPI_SYSTEM_NOTIFY
,
2228 .notify
= bay_notify
,
2229 .handle
= &bay_handle
,
2230 .type
= ACPI_SYSTEM_NOTIFY
,
2235 .write
= cmos_write
,
2246 .write
= beep_write
,
2250 .init
= thermal_init
,
2251 .read
= thermal_read
,
2255 .read
= ecdump_read
,
2256 .write
= ecdump_write
,
2260 .name
= "brightness",
2261 .read
= brightness_read
,
2262 .write
= brightness_write
,
2266 .read
= volume_read
,
2267 .write
= volume_write
,
2278 static int dispatch_read(char *page
, char **start
, off_t off
, int count
,
2279 int *eof
, void *data
)
2281 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
2284 if (!ibm
|| !ibm
->read
)
2287 len
= ibm
->read(page
);
2291 if (len
<= off
+ count
)
2293 *start
= page
+ off
;
2303 static int dispatch_write(struct file
*file
, const char __user
* userbuf
,
2304 unsigned long count
, void *data
)
2306 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
2310 if (!ibm
|| !ibm
->write
)
2313 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
2317 if (copy_from_user(kernbuf
, userbuf
, count
)) {
2323 strcat(kernbuf
, ",");
2324 ret
= ibm
->write(kernbuf
);
2333 static void dispatch_notify(acpi_handle handle
, u32 event
, void *data
)
2335 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
2337 if (!ibm
|| !ibm
->notify
)
2340 ibm
->notify(ibm
, event
);
2343 static int __init
setup_notify(struct ibm_struct
*ibm
)
2351 ret
= acpi_bus_get_device(*ibm
->handle
, &ibm
->device
);
2353 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
2357 acpi_driver_data(ibm
->device
) = ibm
;
2358 sprintf(acpi_device_class(ibm
->device
), "%s/%s", IBM_NAME
, ibm
->name
);
2360 status
= acpi_install_notify_handler(*ibm
->handle
, ibm
->type
,
2361 dispatch_notify
, ibm
);
2362 if (ACPI_FAILURE(status
)) {
2363 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
2371 static int __init
ibm_device_add(struct acpi_device
*device
)
2376 static int __init
register_driver(struct ibm_struct
*ibm
)
2380 ibm
->driver
= kmalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
2382 printk(IBM_ERR
"kmalloc(ibm->driver) failed\n");
2386 memset(ibm
->driver
, 0, sizeof(struct acpi_driver
));
2387 sprintf(ibm
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
2388 ibm
->driver
->ids
= ibm
->hid
;
2389 ibm
->driver
->ops
.add
= &ibm_device_add
;
2391 ret
= acpi_bus_register_driver(ibm
->driver
);
2393 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
2401 static int __init
ibm_init(struct ibm_struct
*ibm
)
2404 struct proc_dir_entry
*entry
;
2406 if (ibm
->experimental
&& !experimental
)
2410 ret
= register_driver(ibm
);
2413 ibm
->driver_registered
= 1;
2420 ibm
->init_called
= 1;
2424 entry
= create_proc_entry(ibm
->name
,
2425 S_IFREG
| S_IRUGO
| S_IWUSR
,
2428 printk(IBM_ERR
"unable to create proc entry %s\n",
2432 entry
->owner
= THIS_MODULE
;
2434 entry
->read_proc
= &dispatch_read
;
2436 entry
->write_proc
= &dispatch_write
;
2437 ibm
->proc_created
= 1;
2441 ret
= setup_notify(ibm
);
2444 ibm
->notify_installed
= 1;
2450 static void ibm_exit(struct ibm_struct
*ibm
)
2452 if (ibm
->notify_installed
)
2453 acpi_remove_notify_handler(*ibm
->handle
, ibm
->type
,
2456 if (ibm
->proc_created
)
2457 remove_proc_entry(ibm
->name
, proc_dir
);
2459 if (ibm
->init_called
&& ibm
->exit
)
2462 if (ibm
->driver_registered
) {
2463 acpi_bus_unregister_driver(ibm
->driver
);
2468 static void __init
ibm_handle_init(char *name
,
2469 acpi_handle
* handle
, acpi_handle parent
,
2470 char **paths
, int num_paths
, char **path
)
2475 for (i
= 0; i
< num_paths
; i
++) {
2476 status
= acpi_get_handle(parent
, paths
[i
], handle
);
2477 if (ACPI_SUCCESS(status
)) {
2486 #define IBM_HANDLE_INIT(object) \
2487 ibm_handle_init(#object, &object##_handle, *object##_parent, \
2488 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
2490 static int set_ibm_param(const char *val
, struct kernel_param
*kp
)
2494 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++)
2495 if (strcmp(ibms
[i
].name
, kp
->name
) == 0 && ibms
[i
].write
) {
2496 if (strlen(val
) > sizeof(ibms
[i
].param
) - 2)
2498 strcpy(ibms
[i
].param
, val
);
2499 strcat(ibms
[i
].param
, ",");
2506 #define IBM_PARAM(feature) \
2507 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
2510 IBM_PARAM(bluetooth
);
2513 #ifdef CONFIG_ACPI_IBM_DOCK
2521 IBM_PARAM(brightness
);
2525 static struct backlight_properties ibm_backlight_data
= {
2526 .owner
= THIS_MODULE
,
2527 .get_brightness
= brightness_get
,
2528 .update_status
= brightness_update_status
,
2529 .max_brightness
= 7,
2532 static void acpi_ibm_exit(void)
2536 if (ibm_backlight_device
)
2537 backlight_device_unregister(ibm_backlight_device
);
2539 for (i
= ARRAY_SIZE(ibms
) - 1; i
>= 0; i
--)
2542 remove_proc_entry(IBM_DIR
, acpi_root_dir
);
2545 static int __init
check_dmi_for_ec(void)
2547 struct dmi_device
*dev
= NULL
;
2550 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2551 * X32 or newer, all Z series; Some models must have an
2552 * up-to-date BIOS or they will not be detected.
2554 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2556 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
2557 if (strstr(dev
->name
, "IBM ThinkPad Embedded Controller"))
2563 static int __init
acpi_ibm_init(void)
2570 if (!acpi_specific_hotkey_enabled
) {
2571 printk(IBM_ERR
"using generic hotkey driver\n");
2575 /* ec is required because many other handles are relative to it */
2576 IBM_HANDLE_INIT(ec
);
2578 printk(IBM_ERR
"ec object not found\n");
2582 /* Models with newer firmware report the EC in DMI */
2583 ibm_thinkpad_ec_found
= check_dmi_for_ec();
2585 /* these handles are not required */
2586 IBM_HANDLE_INIT(vid
);
2587 IBM_HANDLE_INIT(vid2
);
2588 IBM_HANDLE_INIT(ledb
);
2589 IBM_HANDLE_INIT(led
);
2590 IBM_HANDLE_INIT(hkey
);
2591 IBM_HANDLE_INIT(lght
);
2592 IBM_HANDLE_INIT(cmos
);
2593 #ifdef CONFIG_ACPI_IBM_DOCK
2594 IBM_HANDLE_INIT(dock
);
2596 IBM_HANDLE_INIT(pci
);
2597 IBM_HANDLE_INIT(bay
);
2599 IBM_HANDLE_INIT(bay_ej
);
2600 IBM_HANDLE_INIT(bay2
);
2602 IBM_HANDLE_INIT(bay2_ej
);
2603 IBM_HANDLE_INIT(beep
);
2604 IBM_HANDLE_INIT(ecrd
);
2605 IBM_HANDLE_INIT(ecwr
);
2606 IBM_HANDLE_INIT(fans
);
2607 IBM_HANDLE_INIT(gfan
);
2608 IBM_HANDLE_INIT(sfan
);
2610 proc_dir
= proc_mkdir(IBM_DIR
, acpi_root_dir
);
2612 printk(IBM_ERR
"unable to create proc dir %s", IBM_DIR
);
2615 proc_dir
->owner
= THIS_MODULE
;
2617 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++) {
2618 ret
= ibm_init(&ibms
[i
]);
2619 if (ret
>= 0 && *ibms
[i
].param
)
2620 ret
= ibms
[i
].write(ibms
[i
].param
);
2627 ibm_backlight_device
= backlight_device_register("ibm", NULL
,
2628 &ibm_backlight_data
);
2629 if (IS_ERR(ibm_backlight_device
)) {
2630 printk(IBM_ERR
"Could not register ibm backlight device\n");
2631 ibm_backlight_device
= NULL
;
2638 module_init(acpi_ibm_init
);
2639 module_exit(acpi_ibm_exit
);