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>
85 #include <linux/jiffies.h>
86 #include <linux/workqueue.h>
88 #include <acpi/acpi_drivers.h>
89 #include <acpi/acnamesp.h>
91 #define IBM_NAME "ibm"
92 #define IBM_DESC "IBM ThinkPad ACPI Extras"
93 #define IBM_FILE "ibm_acpi"
94 #define IBM_URL "http://ibm-acpi.sf.net/"
96 MODULE_AUTHOR("Borislav Deianov");
97 MODULE_DESCRIPTION(IBM_DESC
);
98 MODULE_VERSION(IBM_VERSION
);
99 MODULE_LICENSE("GPL");
101 #define IBM_DIR IBM_NAME
103 #define IBM_LOG IBM_FILE ": "
104 #define IBM_ERR KERN_ERR IBM_LOG
105 #define IBM_NOTICE KERN_NOTICE IBM_LOG
106 #define IBM_INFO KERN_INFO IBM_LOG
107 #define IBM_DEBUG KERN_DEBUG IBM_LOG
109 #define IBM_MAX_ACPI_ARGS 3
111 #define __unused __attribute__ ((unused))
113 static int experimental
;
114 module_param(experimental
, int, 0);
116 static acpi_handle root_handle
= NULL
;
118 #define IBM_HANDLE(object, parent, paths...) \
119 static acpi_handle object##_handle; \
120 static acpi_handle *object##_parent = &parent##_handle; \
121 static char *object##_path; \
122 static char *object##_paths[] = { paths }
125 * The following models are supported to various degrees:
127 * 570, 600e, 600x, 770e, 770x
128 * A20m, A21e, A21m, A21p, A22p, A30, A30p, A31, A31p
130 * R30, R31, R32, R40, R40e, R50, R50e, R50p, R51
131 * T20, T21, T22, T23, T30, T40, T40p, T41, T41p, T42, T42p, T43
132 * X20, X21, X22, X23, X24, X30, X31, X40
134 * The following models have no supported features:
138 * Still missing DSDTs for the following models:
146 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
147 "\\_SB.PCI.ISA.EC", /* 570 */
148 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
149 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
150 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
151 "\\_SB.PCI0.ICH3.EC0", /* R31 */
152 "\\_SB.PCI0.LPC.EC", /* all others */
155 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
156 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
157 "\\_SB.PCI0.VID0", /* 770e */
158 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
159 "\\_SB.PCI0.AGP.VID", /* all others */
162 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
164 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
165 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
166 "\\CMS", /* R40, R40e */
168 #ifdef CONFIG_ACPI_IBM_DOCK
169 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
170 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
171 "\\_SB.PCI0.PCI1.DOCK", /* all others */
172 "\\_SB.PCI.ISA.SLCE", /* 570 */
173 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
175 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
176 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
177 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
178 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
179 ); /* A21e, R30, R31 */
181 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
182 "_EJ0", /* all others */
183 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
185 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
186 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
189 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
193 /* don't list other alternatives as we install a notify handler on the 570 */
194 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
196 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
197 "^HKEY", /* R30, R31 */
198 "HKEY", /* all others */
201 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
202 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
204 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
205 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
206 "LED", /* all others */
209 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
210 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
211 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
212 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
214 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
215 "\\FSPD", /* 600e/x, 770e, 770x */
218 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
219 "JFNS", /* 770x-JL */
222 #define IBM_HKEY_HID "IBM0068"
223 #define IBM_PCI_HID "PNP0A03"
225 enum thermal_access_mode
{
226 IBMACPI_THERMAL_NONE
= 0, /* No thermal support */
227 IBMACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
228 IBMACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
229 IBMACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
230 IBMACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
233 #define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
234 struct ibm_thermal_sensors_struct
{
235 s32 temp
[IBMACPI_MAX_THERMAL_SENSORS
];
241 * IBMACPI_FAN_RD_ACPI_GFAN:
242 * ACPI GFAN method: returns fan level
244 * see IBMACPI_FAN_WR_ACPI_SFAN
245 * EC 0x2f not available if GFAN exists
247 * IBMACPI_FAN_WR_ACPI_SFAN:
248 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
250 * EC 0x2f might be available *for reading*, but never for writing.
252 * IBMACPI_FAN_WR_TPEC:
253 * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported
254 * on almost all ThinkPads
256 * Fan speed changes of any sort (including those caused by the
257 * disengaged mode) are usually done slowly by the firmware as the
258 * maximum ammount of fan duty cycle change per second seems to be
261 * Reading is not available if GFAN exists.
262 * Writing is not available if SFAN exists.
265 * 7 automatic mode engaged;
266 * (default operation mode of the ThinkPad)
267 * fan level is ignored in this mode.
268 * 6 disengage mode (takes precedence over bit 7);
269 * not available on all thinkpads. May disable
270 * the tachometer, and speeds up fan to 100% duty-cycle,
271 * which speeds it up far above the standard RPM
272 * levels. It is not impossible that it could cause
274 * 5-3 unused in some models. Extra bits for fan level
275 * in others, but still useless as all values above
276 * 7 map to the same speed as level 7 in these models.
277 * 2-0 fan level (0..7 usually)
279 * 0x07 = max (set when temperatures critical)
280 * Some ThinkPads may have other levels, see
281 * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
283 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
284 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
285 * does so, its initial value is meaningless (0x07).
287 * For firmware bugs, refer to:
288 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
292 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
293 * Main fan tachometer reading (in RPM)
295 * This register is present on all ThinkPads with a new-style EC, and
296 * it is known not to be present on the A21m/e, and T22, as there is
297 * something else in offset 0x84 according to the ACPI DSDT. Other
298 * ThinkPads from this same time period (and earlier) probably lack the
299 * tachometer as well.
301 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
302 * was never fixed by IBM to report the EC firmware version string
303 * probably support the tachometer (like the early X models), so
304 * detecting it is quite hard. We need more data to know for sure.
306 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
309 * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this
310 * register is not invalidated in ThinkPads that disable tachometer
311 * readings. Thus, the tachometer readings go stale.
313 * For firmware bugs, refer to:
314 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
316 * IBMACPI_FAN_WR_ACPI_FANS:
317 * ThinkPad X31, X40, X41. Not available in the X60.
319 * FANS ACPI handle: takes three arguments: low speed, medium speed,
320 * high speed. ACPI DSDT seems to map these three speeds to levels
321 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
322 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
324 * The speeds are stored on handles
325 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
327 * There are three default speed sets, acessible as handles:
328 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
330 * ACPI DSDT switches which set is in use depending on various
333 * IBMACPI_FAN_WR_TPEC is also available and should be used to
334 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
335 * but the ACPI tables just mention level 7.
338 enum fan_status_access_mode
{
339 IBMACPI_FAN_NONE
= 0, /* No fan status or control */
340 IBMACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
341 IBMACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
344 enum fan_control_access_mode
{
345 IBMACPI_FAN_WR_NONE
= 0, /* No fan control */
346 IBMACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
347 IBMACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
348 IBMACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
351 enum fan_control_commands
{
352 IBMACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
353 IBMACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
354 IBMACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
355 * and also watchdog cmd */
358 enum { /* Fan control constants */
359 fan_status_offset
= 0x2f, /* EC register 0x2f */
360 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
361 * 0x84 must be read before 0x85 */
363 IBMACPI_FAN_EC_DISENGAGED
= 0x40, /* EC mode: tachometer
365 IBMACPI_FAN_EC_AUTO
= 0x80, /* EC mode: auto fan
369 static char *ibm_thinkpad_ec_found
= NULL
;
376 struct acpi_driver
*driver
;
379 int (*read
) (char *);
380 int (*write
) (char *);
383 void (*notify
) (struct ibm_struct
*, u32
);
386 struct acpi_device
*device
;
388 int driver_registered
;
391 int notify_installed
;
396 static struct proc_dir_entry
*proc_dir
= NULL
;
398 static struct backlight_device
*ibm_backlight_device
;
400 #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
401 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
402 #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
404 static int acpi_evalf(acpi_handle handle
,
405 void *res
, char *method
, char *fmt
, ...)
408 struct acpi_object_list params
;
409 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
410 struct acpi_buffer result
, *resultp
;
411 union acpi_object out_obj
;
419 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
432 params
.pointer
= &in_objs
[0];
439 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
440 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
442 /* add more types as needed */
444 printk(IBM_ERR
"acpi_evalf() called "
445 "with invalid format character '%c'\n", c
);
451 if (res_type
!= 'v') {
452 result
.length
= sizeof(out_obj
);
453 result
.pointer
= &out_obj
;
458 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
463 *(int *)res
= out_obj
.integer
.value
;
464 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
467 success
= status
== AE_OK
;
469 /* add more types as needed */
471 printk(IBM_ERR
"acpi_evalf() called "
472 "with invalid format character '%c'\n", res_type
);
476 if (!success
&& !quiet
)
477 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
478 method
, fmt0
, status
);
483 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
487 if (acpi_evalf(handle
, &i
, method
, "d"))
488 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
490 printk(IBM_ERR
"error calling %s\n", method
);
493 static char *next_cmd(char **cmds
)
498 while ((end
= strchr(start
, ',')) && end
== start
)
509 static int driver_init(void)
511 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
512 printk(IBM_INFO
"%s\n", IBM_URL
);
517 static int driver_read(char *p
)
521 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
522 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
527 static int hotkey_supported
;
528 static int hotkey_mask_supported
;
529 static int hotkey_orig_status
;
530 static int hotkey_orig_mask
;
532 static int hotkey_get(int *status
, int *mask
)
534 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
537 if (hotkey_mask_supported
)
538 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
544 static int hotkey_set(int status
, int mask
)
548 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
551 if (hotkey_mask_supported
)
552 for (i
= 0; i
< 32; i
++) {
553 int bit
= ((1 << i
) & mask
) != 0;
554 if (!acpi_evalf(hkey_handle
,
555 NULL
, "MHKM", "vdd", i
+ 1, bit
))
562 static int hotkey_init(void)
564 /* hotkey not supported on 570 */
565 hotkey_supported
= hkey_handle
!= NULL
;
567 if (hotkey_supported
) {
568 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
569 A30, R30, R31, T20-22, X20-21, X22-24 */
570 hotkey_mask_supported
=
571 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
573 if (!hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
))
580 static int hotkey_read(char *p
)
585 if (!hotkey_supported
) {
586 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
590 if (!hotkey_get(&status
, &mask
))
593 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
594 if (hotkey_mask_supported
) {
595 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
596 len
+= sprintf(p
+ len
,
597 "commands:\tenable, disable, reset, <mask>\n");
599 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
600 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
606 static int hotkey_write(char *buf
)
612 if (!hotkey_supported
)
615 if (!hotkey_get(&status
, &mask
))
618 while ((cmd
= next_cmd(&buf
))) {
619 if (strlencmp(cmd
, "enable") == 0) {
621 } else if (strlencmp(cmd
, "disable") == 0) {
623 } else if (strlencmp(cmd
, "reset") == 0) {
624 status
= hotkey_orig_status
;
625 mask
= hotkey_orig_mask
;
626 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
628 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
635 if (do_cmd
&& !hotkey_set(status
, mask
))
641 static void hotkey_exit(void)
643 if (hotkey_supported
)
644 hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
647 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
651 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
652 acpi_bus_generate_event(ibm
->device
, event
, hkey
);
654 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
655 acpi_bus_generate_event(ibm
->device
, event
, 0);
659 static int bluetooth_supported
;
661 static int bluetooth_init(void)
663 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
664 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
665 bluetooth_supported
= hkey_handle
&&
666 acpi_evalf(hkey_handle
, NULL
, "GBDC", "qv");
671 static int bluetooth_status(void)
675 if (!bluetooth_supported
||
676 !acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
682 static int bluetooth_read(char *p
)
685 int status
= bluetooth_status();
687 if (!bluetooth_supported
)
688 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
689 else if (!(status
& 1))
690 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
692 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
693 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
699 static int bluetooth_write(char *buf
)
701 int status
= bluetooth_status();
705 if (!bluetooth_supported
)
708 while ((cmd
= next_cmd(&buf
))) {
709 if (strlencmp(cmd
, "enable") == 0) {
711 } else if (strlencmp(cmd
, "disable") == 0) {
718 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
724 static int wan_supported
;
726 static int wan_init(void)
728 wan_supported
= hkey_handle
&&
729 acpi_evalf(hkey_handle
, NULL
, "GWAN", "qv");
734 static int wan_status(void)
738 if (!wan_supported
|| !acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
744 static int wan_read(char *p
)
747 int status
= wan_status();
750 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
751 else if (!(status
& 1))
752 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
754 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
755 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
761 static int wan_write(char *buf
)
763 int status
= wan_status();
770 while ((cmd
= next_cmd(&buf
))) {
771 if (strlencmp(cmd
, "enable") == 0) {
773 } else if (strlencmp(cmd
, "disable") == 0) {
780 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
786 static int video_supported
;
787 static int video_orig_autosw
;
793 static int video_init(void)
797 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
798 /* G41, assume IVGA doesn't change */
799 vid_handle
= vid2_handle
;
802 /* video switching not supported on R30, R31 */
804 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
806 video_supported
= VIDEO_570
;
807 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
808 /* 600e/x, 770e, 770x */
809 video_supported
= VIDEO_770
;
812 video_supported
= VIDEO_NEW
;
817 static int video_status(void)
822 if (video_supported
== VIDEO_570
) {
823 if (acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd", 0x87))
825 } else if (video_supported
== VIDEO_770
) {
826 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
828 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
830 } else if (video_supported
== VIDEO_NEW
) {
831 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1);
832 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
835 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0);
836 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
838 if (acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
845 static int video_autosw(void)
849 if (video_supported
== VIDEO_570
)
850 acpi_evalf(vid_handle
, &autosw
, "SWIT", "d");
851 else if (video_supported
== VIDEO_770
|| video_supported
== VIDEO_NEW
)
852 acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d");
857 static int video_read(char *p
)
859 int status
= video_status();
860 int autosw
= video_autosw();
863 if (!video_supported
) {
864 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
868 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
869 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
870 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
871 if (video_supported
== VIDEO_NEW
)
872 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
873 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
874 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
875 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
876 if (video_supported
== VIDEO_NEW
)
877 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
878 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
879 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
884 static int video_switch(void)
886 int autosw
= video_autosw();
889 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
891 ret
= video_supported
== VIDEO_570
?
892 acpi_evalf(ec_handle
, NULL
, "_Q16", "v") :
893 acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
894 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
899 static int video_expand(void)
901 if (video_supported
== VIDEO_570
)
902 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v");
903 else if (video_supported
== VIDEO_770
)
904 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v");
906 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v");
909 static int video_switch2(int status
)
913 if (video_supported
== VIDEO_570
) {
914 ret
= acpi_evalf(NULL
, NULL
,
915 "\\_SB.PHS2", "vdd", 0x8b, status
| 0x80);
916 } else if (video_supported
== VIDEO_770
) {
917 int autosw
= video_autosw();
918 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
921 ret
= acpi_evalf(vid_handle
, NULL
,
922 "ASWT", "vdd", status
* 0x100, 0);
924 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
926 ret
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
927 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
933 static int video_write(char *buf
)
936 int enable
, disable
, status
;
938 if (!video_supported
)
941 enable
= disable
= 0;
943 while ((cmd
= next_cmd(&buf
))) {
944 if (strlencmp(cmd
, "lcd_enable") == 0) {
946 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
948 } else if (strlencmp(cmd
, "crt_enable") == 0) {
950 } else if (strlencmp(cmd
, "crt_disable") == 0) {
952 } else if (video_supported
== VIDEO_NEW
&&
953 strlencmp(cmd
, "dvi_enable") == 0) {
955 } else if (video_supported
== VIDEO_NEW
&&
956 strlencmp(cmd
, "dvi_disable") == 0) {
958 } else if (strlencmp(cmd
, "auto_enable") == 0) {
959 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
961 } else if (strlencmp(cmd
, "auto_disable") == 0) {
962 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 0))
964 } else if (strlencmp(cmd
, "video_switch") == 0) {
967 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
974 if (enable
|| disable
) {
975 status
= (video_status() & 0x0f & ~disable
) | enable
;
976 if (!video_switch2(status
))
983 static void video_exit(void)
985 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", video_orig_autosw
);
988 static int light_supported
;
989 static int light_status_supported
;
991 static int light_init(void)
993 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
994 light_supported
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
997 /* light status not supported on
998 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
999 light_status_supported
= acpi_evalf(ec_handle
, NULL
,
1005 static int light_read(char *p
)
1010 if (!light_supported
) {
1011 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1012 } else if (!light_status_supported
) {
1013 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1014 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1016 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1018 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1019 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1025 static int light_write(char *buf
)
1027 int cmos_cmd
, lght_cmd
;
1031 if (!light_supported
)
1034 while ((cmd
= next_cmd(&buf
))) {
1035 if (strlencmp(cmd
, "on") == 0) {
1038 } else if (strlencmp(cmd
, "off") == 0) {
1044 success
= cmos_handle
?
1045 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1046 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1054 static int _sta(acpi_handle handle
)
1058 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
1064 #ifdef CONFIG_ACPI_IBM_DOCK
1065 #define dock_docked() (_sta(dock_handle) & 1)
1067 static int dock_read(char *p
)
1070 int docked
= dock_docked();
1073 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1075 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1077 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1078 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1084 static int dock_write(char *buf
)
1091 while ((cmd
= next_cmd(&buf
))) {
1092 if (strlencmp(cmd
, "undock") == 0) {
1093 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1094 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1096 } else if (strlencmp(cmd
, "dock") == 0) {
1097 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1106 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1108 int docked
= dock_docked();
1109 int pci
= ibm
->hid
&& strstr(ibm
->hid
, IBM_PCI_HID
);
1111 if (event
== 1 && !pci
) /* 570 */
1112 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1113 else if (event
== 1 && pci
) /* 570 */
1114 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1115 else if (event
== 3 && docked
)
1116 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1117 else if (event
== 3 && !docked
)
1118 acpi_bus_generate_event(ibm
->device
, event
, 2); /* undock */
1119 else if (event
== 0 && docked
)
1120 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1122 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1123 event
, _sta(dock_handle
));
1124 acpi_bus_generate_event(ibm
->device
, event
, 0); /* unknown */
1129 static int bay_status_supported
;
1130 static int bay_status2_supported
;
1131 static int bay_eject_supported
;
1132 static int bay_eject2_supported
;
1134 static int bay_init(void)
1136 bay_status_supported
= bay_handle
&&
1137 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1138 bay_status2_supported
= bay2_handle
&&
1139 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1141 bay_eject_supported
= bay_handle
&& bay_ej_handle
&&
1142 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1143 bay_eject2_supported
= bay2_handle
&& bay2_ej_handle
&&
1144 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1149 #define bay_occupied(b) (_sta(b##_handle) & 1)
1151 static int bay_read(char *p
)
1154 int occupied
= bay_occupied(bay
);
1155 int occupied2
= bay_occupied(bay2
);
1158 len
+= sprintf(p
+ len
, "status:\t\t%s\n", bay_status_supported
?
1159 (occupied
? "occupied" : "unoccupied") :
1161 if (bay_status2_supported
)
1162 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1163 "occupied" : "unoccupied");
1165 eject
= bay_eject_supported
&& occupied
;
1166 eject2
= bay_eject2_supported
&& occupied2
;
1168 if (eject
&& eject2
)
1169 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1171 len
+= sprintf(p
+ len
, "commands:\teject\n");
1173 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1178 static int bay_write(char *buf
)
1182 if (!bay_eject_supported
&& !bay_eject2_supported
)
1185 while ((cmd
= next_cmd(&buf
))) {
1186 if (bay_eject_supported
&& strlencmp(cmd
, "eject") == 0) {
1187 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1189 } else if (bay_eject2_supported
&&
1190 strlencmp(cmd
, "eject2") == 0) {
1191 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1200 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1202 acpi_bus_generate_event(ibm
->device
, event
, 0);
1205 static int cmos_read(char *p
)
1209 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1210 R30, R31, T20-22, X20-21 */
1212 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1214 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1215 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1221 static int cmos_eval(int cmos_cmd
)
1224 return acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
);
1229 static int cmos_write(char *buf
)
1237 while ((cmd
= next_cmd(&buf
))) {
1238 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1239 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1244 if (!cmos_eval(cmos_cmd
))
1251 static int led_supported
;
1257 static int led_init(void)
1260 /* led not supported on R30, R31 */
1262 else if (strlencmp(led_path
, "SLED") == 0)
1264 led_supported
= LED_570
;
1265 else if (strlencmp(led_path
, "SYSL") == 0)
1266 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1267 led_supported
= LED_OLD
;
1270 led_supported
= LED_NEW
;
1275 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1277 static int led_read(char *p
)
1281 if (!led_supported
) {
1282 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1285 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1287 if (led_supported
== LED_570
) {
1290 for (i
= 0; i
< 8; i
++) {
1291 if (!acpi_evalf(ec_handle
,
1292 &status
, "GLED", "dd", 1 << i
))
1294 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1295 i
, led_status(status
));
1299 len
+= sprintf(p
+ len
, "commands:\t"
1300 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1305 /* off, on, blink */
1306 static const int led_sled_arg1
[] = { 0, 1, 3 };
1307 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
1308 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
1309 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
1311 #define EC_HLCL 0x0c
1312 #define EC_HLBL 0x0d
1313 #define EC_HLMS 0x0e
1315 static int led_write(char *buf
)
1323 while ((cmd
= next_cmd(&buf
))) {
1324 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1327 if (strstr(cmd
, "off")) {
1329 } else if (strstr(cmd
, "on")) {
1331 } else if (strstr(cmd
, "blink")) {
1336 if (led_supported
== LED_570
) {
1339 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1340 led
, led_sled_arg1
[ind
]))
1342 } else if (led_supported
== LED_OLD
) {
1343 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1345 ret
= ec_write(EC_HLMS
, led
);
1348 ec_write(EC_HLBL
, led
* led_exp_hlbl
[ind
]);
1351 ec_write(EC_HLCL
, led
* led_exp_hlcl
[ind
]);
1356 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1357 led
, led_led_arg1
[ind
]))
1365 static int beep_read(char *p
)
1370 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1372 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1373 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1379 static int beep_write(char *buf
)
1387 while ((cmd
= next_cmd(&buf
))) {
1388 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1389 beep_cmd
>= 0 && beep_cmd
<= 17) {
1393 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1400 static int acpi_ec_read(int i
, u8
* p
)
1405 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
1409 if (ec_read(i
, p
) < 0)
1416 static int acpi_ec_write(int i
, u8 v
)
1419 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
1422 if (ec_write(i
, v
) < 0)
1429 static enum thermal_access_mode thermal_read_mode
;
1431 static int thermal_init(void)
1435 int acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
1437 if (ibm_thinkpad_ec_found
&& experimental
) {
1439 * Direct EC access mode: sensors at registers
1440 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1441 * non-implemented, thermal sensors return 0x80 when
1446 for (i
= 0; i
< 8; i
++) {
1447 if (likely(acpi_ec_read(0x78 + i
, &t
))) {
1453 if (likely(acpi_ec_read(0xC0 + i
, &t
))) {
1461 /* This is sheer paranoia, but we handle it anyway */
1464 "ThinkPad ACPI EC access misbehaving, "
1465 "falling back to ACPI TMPx access mode\n");
1466 thermal_read_mode
= IBMACPI_THERMAL_ACPI_TMP07
;
1469 "ThinkPad ACPI EC access misbehaving, "
1470 "disabling thermal sensors access\n");
1471 thermal_read_mode
= IBMACPI_THERMAL_NONE
;
1476 IBMACPI_THERMAL_TPEC_16
: IBMACPI_THERMAL_TPEC_8
;
1478 } else if (acpi_tmp7
) {
1479 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
1480 /* 600e/x, 770e, 770x */
1481 thermal_read_mode
= IBMACPI_THERMAL_ACPI_UPDT
;
1483 /* Standard ACPI TMPx access, max 8 sensors */
1484 thermal_read_mode
= IBMACPI_THERMAL_ACPI_TMP07
;
1487 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1488 thermal_read_mode
= IBMACPI_THERMAL_NONE
;
1494 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
1498 char tmpi
[] = "TMPi";
1503 switch (thermal_read_mode
) {
1504 #if IBMACPI_MAX_THERMAL_SENSORS >= 16
1505 case IBMACPI_THERMAL_TPEC_16
:
1506 for (i
= 0; i
< 8; i
++) {
1507 if (!acpi_ec_read(0xC0 + i
, &tmp
))
1509 s
->temp
[i
+ 8] = tmp
* 1000;
1513 case IBMACPI_THERMAL_TPEC_8
:
1514 for (i
= 0; i
< 8; i
++) {
1515 if (!acpi_ec_read(0x78 + i
, &tmp
))
1517 s
->temp
[i
] = tmp
* 1000;
1519 return (thermal_read_mode
== IBMACPI_THERMAL_TPEC_16
) ? 16 : 8;
1521 case IBMACPI_THERMAL_ACPI_UPDT
:
1522 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
1524 for (i
= 0; i
< 8; i
++) {
1526 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1528 s
->temp
[i
] = (t
- 2732) * 100;
1532 case IBMACPI_THERMAL_ACPI_TMP07
:
1533 for (i
= 0; i
< 8; i
++) {
1535 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1537 s
->temp
[i
] = t
* 1000;
1541 case IBMACPI_THERMAL_NONE
:
1547 static int thermal_read(char *p
)
1551 struct ibm_thermal_sensors_struct t
;
1553 n
= thermal_get_sensors(&t
);
1554 if (unlikely(n
< 0))
1557 len
+= sprintf(p
+ len
, "temperatures:\t");
1560 for (i
= 0; i
< (n
- 1); i
++)
1561 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
1562 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
1564 len
+= sprintf(p
+ len
, "not supported\n");
1569 static u8 ecdump_regs
[256];
1571 static int ecdump_read(char *p
)
1577 len
+= sprintf(p
+ len
, "EC "
1578 " +00 +01 +02 +03 +04 +05 +06 +07"
1579 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1580 for (i
= 0; i
< 256; i
+= 16) {
1581 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
1582 for (j
= 0; j
< 16; j
++) {
1583 if (!acpi_ec_read(i
+ j
, &v
))
1585 if (v
!= ecdump_regs
[i
+ j
])
1586 len
+= sprintf(p
+ len
, " *%02x", v
);
1588 len
+= sprintf(p
+ len
, " %02x", v
);
1589 ecdump_regs
[i
+ j
] = v
;
1591 len
+= sprintf(p
+ len
, "\n");
1596 /* These are way too dangerous to advertise openly... */
1598 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
1599 " (<offset> is 00-ff, <value> is 00-ff)\n");
1600 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
1601 " (<offset> is 00-ff, <value> is 0-255)\n");
1606 static int ecdump_write(char *buf
)
1611 while ((cmd
= next_cmd(&buf
))) {
1612 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
1614 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
1618 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
1619 if (!acpi_ec_write(i
, v
))
1628 static int brightness_offset
= 0x31;
1630 static int brightness_get(struct backlight_device
*bd
)
1633 if (!acpi_ec_read(brightness_offset
, &level
))
1640 static int brightness_read(char *p
)
1645 if ((level
= brightness_get(NULL
)) < 0) {
1646 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1648 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
1649 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
1650 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1651 " (<level> is 0-7)\n");
1657 #define BRIGHTNESS_UP 4
1658 #define BRIGHTNESS_DOWN 5
1660 static int brightness_set(int value
)
1662 int cmos_cmd
, inc
, i
;
1663 int current_value
= brightness_get(NULL
);
1667 cmos_cmd
= value
> current_value
? BRIGHTNESS_UP
: BRIGHTNESS_DOWN
;
1668 inc
= value
> current_value
? 1 : -1;
1669 for (i
= current_value
; i
!= value
; i
+= inc
) {
1670 if (!cmos_eval(cmos_cmd
))
1672 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
1679 static int brightness_write(char *buf
)
1685 while ((cmd
= next_cmd(&buf
))) {
1686 if ((level
= brightness_get(NULL
)) < 0)
1690 if (strlencmp(cmd
, "up") == 0) {
1691 new_level
= level
== 7 ? 7 : level
+ 1;
1692 } else if (strlencmp(cmd
, "down") == 0) {
1693 new_level
= level
== 0 ? 0 : level
- 1;
1694 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1695 new_level
>= 0 && new_level
<= 7) {
1700 brightness_set(new_level
);
1706 static int brightness_update_status(struct backlight_device
*bd
)
1708 return brightness_set(bd
->props
->brightness
);
1711 static int volume_offset
= 0x30;
1713 static int volume_read(char *p
)
1718 if (!acpi_ec_read(volume_offset
, &level
)) {
1719 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1721 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
1722 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
1723 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
1724 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1725 " (<level> is 0-15)\n");
1731 #define VOLUME_DOWN 0
1733 #define VOLUME_MUTE 2
1735 static int volume_write(char *buf
)
1737 int cmos_cmd
, inc
, i
;
1739 int new_level
, new_mute
;
1742 while ((cmd
= next_cmd(&buf
))) {
1743 if (!acpi_ec_read(volume_offset
, &level
))
1745 new_mute
= mute
= level
& 0x40;
1746 new_level
= level
= level
& 0xf;
1748 if (strlencmp(cmd
, "up") == 0) {
1752 new_level
= level
== 15 ? 15 : level
+ 1;
1753 } else if (strlencmp(cmd
, "down") == 0) {
1757 new_level
= level
== 0 ? 0 : level
- 1;
1758 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1759 new_level
>= 0 && new_level
<= 15) {
1761 } else if (strlencmp(cmd
, "mute") == 0) {
1766 if (new_level
!= level
) { /* mute doesn't change */
1767 cmos_cmd
= new_level
> level
? VOLUME_UP
: VOLUME_DOWN
;
1768 inc
= new_level
> level
? 1 : -1;
1770 if (mute
&& (!cmos_eval(cmos_cmd
) ||
1771 !acpi_ec_write(volume_offset
, level
)))
1774 for (i
= level
; i
!= new_level
; i
+= inc
)
1775 if (!cmos_eval(cmos_cmd
) ||
1776 !acpi_ec_write(volume_offset
, i
+ inc
))
1779 if (mute
&& (!cmos_eval(VOLUME_MUTE
) ||
1780 !acpi_ec_write(volume_offset
,
1785 if (new_mute
!= mute
) { /* level doesn't change */
1786 cmos_cmd
= new_mute
? VOLUME_MUTE
: VOLUME_UP
;
1788 if (!cmos_eval(cmos_cmd
) ||
1789 !acpi_ec_write(volume_offset
, level
+ new_mute
))
1797 static enum fan_status_access_mode fan_status_access_mode
;
1798 static enum fan_control_access_mode fan_control_access_mode
;
1799 static enum fan_control_commands fan_control_commands
;
1801 static int fan_control_status_known
;
1802 static u8 fan_control_initial_status
;
1804 static void fan_watchdog_fire(void *ignored
);
1805 static int fan_watchdog_maxinterval
;
1806 static DECLARE_WORK(fan_watchdog_task
, fan_watchdog_fire
, NULL
);
1808 static int fan_init(void)
1810 fan_status_access_mode
= IBMACPI_FAN_NONE
;
1811 fan_control_access_mode
= IBMACPI_FAN_WR_NONE
;
1812 fan_control_commands
= 0;
1813 fan_control_status_known
= 1;
1814 fan_watchdog_maxinterval
= 0;
1817 /* 570, 600e/x, 770e, 770x */
1818 fan_status_access_mode
= IBMACPI_FAN_RD_ACPI_GFAN
;
1820 /* all other ThinkPads: note that even old-style
1821 * ThinkPad ECs supports the fan control register */
1822 if (likely(acpi_ec_read(fan_status_offset
,
1823 &fan_control_initial_status
))) {
1824 fan_status_access_mode
= IBMACPI_FAN_RD_TPEC
;
1826 /* In some ThinkPads, neither the EC nor the ACPI
1827 * DSDT initialize the fan status, and it ends up
1828 * being set to 0x07 when it *could* be either
1831 * Enable for TP-1Y (T43), TP-78 (R51e),
1832 * TP-76 (R52), TP-70 (T43, R52), which are known
1834 if (fan_control_initial_status
== 0x07 &&
1835 ibm_thinkpad_ec_found
&&
1836 ((ibm_thinkpad_ec_found
[0] == '1' &&
1837 ibm_thinkpad_ec_found
[1] == 'Y') ||
1838 (ibm_thinkpad_ec_found
[0] == '7' &&
1839 (ibm_thinkpad_ec_found
[1] == '6' ||
1840 ibm_thinkpad_ec_found
[1] == '8' ||
1841 ibm_thinkpad_ec_found
[1] == '0'))
1844 "fan_init: initial fan status is "
1845 "unknown, assuming it is in auto "
1847 fan_control_status_known
= 0;
1851 "ThinkPad ACPI EC access misbehaving, "
1852 "fan status and control unavailable\n");
1859 fan_control_access_mode
= IBMACPI_FAN_WR_ACPI_SFAN
;
1860 fan_control_commands
|=
1861 IBMACPI_FAN_CMD_LEVEL
| IBMACPI_FAN_CMD_ENABLE
;
1864 /* gfan without sfan means no fan control */
1865 /* all other models implement TP EC 0x2f control */
1869 fan_control_access_mode
=
1870 IBMACPI_FAN_WR_ACPI_FANS
;
1871 fan_control_commands
|=
1872 IBMACPI_FAN_CMD_SPEED
|
1873 IBMACPI_FAN_CMD_LEVEL
|
1874 IBMACPI_FAN_CMD_ENABLE
;
1876 fan_control_access_mode
= IBMACPI_FAN_WR_TPEC
;
1877 fan_control_commands
|=
1878 IBMACPI_FAN_CMD_LEVEL
|
1879 IBMACPI_FAN_CMD_ENABLE
;
1887 static int fan_get_status(u8
*status
)
1892 * Add IBMACPI_FAN_RD_ACPI_FANS ? */
1894 switch (fan_status_access_mode
) {
1895 case IBMACPI_FAN_RD_ACPI_GFAN
:
1896 /* 570, 600e/x, 770e, 770x */
1898 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
1906 case IBMACPI_FAN_RD_TPEC
:
1907 /* all except 570, 600e/x, 770e, 770x */
1908 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
1923 static int fan_get_speed(unsigned int *speed
)
1927 switch (fan_status_access_mode
) {
1928 case IBMACPI_FAN_RD_TPEC
:
1929 /* all except 570, 600e/x, 770e, 770x */
1930 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
1931 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
1935 *speed
= (hi
<< 8) | lo
;
1946 static void fan_exit(void)
1948 cancel_delayed_work(&fan_watchdog_task
);
1949 flush_scheduled_work();
1952 static void fan_watchdog_reset(void)
1954 static int fan_watchdog_active
= 0;
1956 if (fan_watchdog_active
)
1957 cancel_delayed_work(&fan_watchdog_task
);
1959 if (fan_watchdog_maxinterval
> 0) {
1960 fan_watchdog_active
= 1;
1961 if (!schedule_delayed_work(&fan_watchdog_task
,
1962 msecs_to_jiffies(fan_watchdog_maxinterval
1964 printk(IBM_ERR
"failed to schedule the fan watchdog, "
1965 "watchdog will not trigger\n");
1968 fan_watchdog_active
= 0;
1971 static int fan_read(char *p
)
1976 unsigned int speed
= 0;
1978 switch (fan_status_access_mode
) {
1979 case IBMACPI_FAN_RD_ACPI_GFAN
:
1980 /* 570, 600e/x, 770e, 770x */
1981 if ((rc
= fan_get_status(&status
)) < 0)
1984 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
1986 (status
!= 0) ? "enabled" : "disabled", status
);
1989 case IBMACPI_FAN_RD_TPEC
:
1990 /* all except 570, 600e/x, 770e, 770x */
1991 if ((rc
= fan_get_status(&status
)) < 0)
1994 if (unlikely(!fan_control_status_known
)) {
1995 if (status
!= fan_control_initial_status
)
1996 fan_control_status_known
= 1;
1998 /* Return most likely status. In fact, it
1999 * might be the only possible status */
2000 status
= IBMACPI_FAN_EC_AUTO
;
2003 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2004 (status
!= 0) ? "enabled" : "disabled");
2006 /* No ThinkPad boots on disengaged mode, we can safely
2007 * assume the tachometer is online if fan control status
2009 if ((rc
= fan_get_speed(&speed
)) < 0)
2012 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
2014 if (status
& IBMACPI_FAN_EC_DISENGAGED
)
2015 /* Disengaged mode takes precedence */
2016 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
2017 else if (status
& IBMACPI_FAN_EC_AUTO
)
2018 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
2020 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
2023 case IBMACPI_FAN_NONE
:
2025 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2028 if (fan_control_commands
& IBMACPI_FAN_CMD_LEVEL
) {
2029 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
2031 switch (fan_control_access_mode
) {
2032 case IBMACPI_FAN_WR_ACPI_SFAN
:
2033 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
2037 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
2038 "auto, disengaged)\n");
2043 if (fan_control_commands
& IBMACPI_FAN_CMD_ENABLE
)
2044 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
2045 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2046 "1-120 (seconds))\n");
2048 if (fan_control_commands
& IBMACPI_FAN_CMD_SPEED
)
2049 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
2050 " (<speed> is 0-65535)\n");
2055 static int fan_set_level(int level
)
2057 switch (fan_control_access_mode
) {
2058 case IBMACPI_FAN_WR_ACPI_SFAN
:
2059 if (level
>= 0 && level
<= 7) {
2060 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
2066 case IBMACPI_FAN_WR_ACPI_FANS
:
2067 case IBMACPI_FAN_WR_TPEC
:
2068 if ((level
!= IBMACPI_FAN_EC_AUTO
) &&
2069 (level
!= IBMACPI_FAN_EC_DISENGAGED
) &&
2070 ((level
< 0) || (level
> 7)))
2073 if (!acpi_ec_write(fan_status_offset
, level
))
2076 fan_control_status_known
= 1;
2085 static int fan_set_enable(void)
2090 switch (fan_control_access_mode
) {
2091 case IBMACPI_FAN_WR_ACPI_FANS
:
2092 case IBMACPI_FAN_WR_TPEC
:
2093 if ((rc
= fan_get_status(&s
)) < 0)
2096 /* Don't go out of emergency fan mode */
2098 s
= IBMACPI_FAN_EC_AUTO
;
2100 if (!acpi_ec_write(fan_status_offset
, s
))
2103 fan_control_status_known
= 1;
2106 case IBMACPI_FAN_WR_ACPI_SFAN
:
2107 if ((rc
= fan_get_status(&s
)) < 0)
2112 /* Set fan to at least level 4 */
2116 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
2126 static int fan_set_disable(void)
2128 switch (fan_control_access_mode
) {
2129 case IBMACPI_FAN_WR_ACPI_FANS
:
2130 case IBMACPI_FAN_WR_TPEC
:
2131 if (!acpi_ec_write(fan_status_offset
, 0x00))
2134 fan_control_status_known
= 1;
2137 case IBMACPI_FAN_WR_ACPI_SFAN
:
2138 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
2148 static int fan_set_speed(int speed
)
2150 switch (fan_control_access_mode
) {
2151 case IBMACPI_FAN_WR_ACPI_FANS
:
2152 if (speed
>= 0 && speed
<= 65535) {
2153 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
2154 speed
, speed
, speed
))
2166 static int fan_write_cmd_level(const char *cmd
, int *rc
)
2170 if (strlencmp(cmd
, "level auto") == 0)
2171 level
= IBMACPI_FAN_EC_AUTO
;
2172 else if (strlencmp(cmd
, "level disengaged") == 0)
2173 level
= IBMACPI_FAN_EC_DISENGAGED
;
2174 else if (sscanf(cmd
, "level %d", &level
) != 1)
2177 if ((*rc
= fan_set_level(level
)) == -ENXIO
)
2178 printk(IBM_ERR
"level command accepted for unsupported "
2179 "access mode %d", fan_control_access_mode
);
2184 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
2186 if (strlencmp(cmd
, "enable") != 0)
2189 if ((*rc
= fan_set_enable()) == -ENXIO
)
2190 printk(IBM_ERR
"enable command accepted for unsupported "
2191 "access mode %d", fan_control_access_mode
);
2196 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
2198 if (strlencmp(cmd
, "disable") != 0)
2201 if ((*rc
= fan_set_disable()) == -ENXIO
)
2202 printk(IBM_ERR
"disable command accepted for unsupported "
2203 "access mode %d", fan_control_access_mode
);
2208 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
2213 * Support speed <low> <medium> <high> ? */
2215 if (sscanf(cmd
, "speed %d", &speed
) != 1)
2218 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
2219 printk(IBM_ERR
"speed command accepted for unsupported "
2220 "access mode %d", fan_control_access_mode
);
2225 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
2229 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
2232 if (interval
< 0 || interval
> 120)
2235 fan_watchdog_maxinterval
= interval
;
2240 static int fan_write(char *buf
)
2245 while (!rc
&& (cmd
= next_cmd(&buf
))) {
2246 if (!((fan_control_commands
& IBMACPI_FAN_CMD_LEVEL
) &&
2247 fan_write_cmd_level(cmd
, &rc
)) &&
2248 !((fan_control_commands
& IBMACPI_FAN_CMD_ENABLE
) &&
2249 (fan_write_cmd_enable(cmd
, &rc
) ||
2250 fan_write_cmd_disable(cmd
, &rc
) ||
2251 fan_write_cmd_watchdog(cmd
, &rc
))) &&
2252 !((fan_control_commands
& IBMACPI_FAN_CMD_SPEED
) &&
2253 fan_write_cmd_speed(cmd
, &rc
))
2257 fan_watchdog_reset();
2263 static void fan_watchdog_fire(void *ignored
)
2265 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
2266 if (fan_set_enable()) {
2267 printk(IBM_ERR
"fan watchdog: error while enabling fan\n");
2268 /* reschedule for later */
2269 fan_watchdog_reset();
2273 static struct ibm_struct ibms
[] = {
2276 .init
= driver_init
,
2277 .read
= driver_read
,
2281 .hid
= IBM_HKEY_HID
,
2282 .init
= hotkey_init
,
2283 .read
= hotkey_read
,
2284 .write
= hotkey_write
,
2285 .exit
= hotkey_exit
,
2286 .notify
= hotkey_notify
,
2287 .handle
= &hkey_handle
,
2288 .type
= ACPI_DEVICE_NOTIFY
,
2291 .name
= "bluetooth",
2292 .init
= bluetooth_init
,
2293 .read
= bluetooth_read
,
2294 .write
= bluetooth_write
,
2307 .write
= video_write
,
2314 .write
= light_write
,
2316 #ifdef CONFIG_ACPI_IBM_DOCK
2320 .write
= dock_write
,
2321 .notify
= dock_notify
,
2322 .handle
= &dock_handle
,
2323 .type
= ACPI_SYSTEM_NOTIFY
,
2328 .notify
= dock_notify
,
2329 .handle
= &pci_handle
,
2330 .type
= ACPI_SYSTEM_NOTIFY
,
2338 .notify
= bay_notify
,
2339 .handle
= &bay_handle
,
2340 .type
= ACPI_SYSTEM_NOTIFY
,
2345 .write
= cmos_write
,
2356 .write
= beep_write
,
2360 .init
= thermal_init
,
2361 .read
= thermal_read
,
2365 .read
= ecdump_read
,
2366 .write
= ecdump_write
,
2370 .name
= "brightness",
2371 .read
= brightness_read
,
2372 .write
= brightness_write
,
2376 .read
= volume_read
,
2377 .write
= volume_write
,
2389 static int dispatch_read(char *page
, char **start
, off_t off
, int count
,
2390 int *eof
, void *data
)
2392 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
2395 if (!ibm
|| !ibm
->read
)
2398 len
= ibm
->read(page
);
2402 if (len
<= off
+ count
)
2404 *start
= page
+ off
;
2414 static int dispatch_write(struct file
*file
, const char __user
* userbuf
,
2415 unsigned long count
, void *data
)
2417 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
2421 if (!ibm
|| !ibm
->write
)
2424 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
2428 if (copy_from_user(kernbuf
, userbuf
, count
)) {
2434 strcat(kernbuf
, ",");
2435 ret
= ibm
->write(kernbuf
);
2444 static void dispatch_notify(acpi_handle handle
, u32 event
, void *data
)
2446 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
2448 if (!ibm
|| !ibm
->notify
)
2451 ibm
->notify(ibm
, event
);
2454 static int __init
setup_notify(struct ibm_struct
*ibm
)
2462 ret
= acpi_bus_get_device(*ibm
->handle
, &ibm
->device
);
2464 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
2468 acpi_driver_data(ibm
->device
) = ibm
;
2469 sprintf(acpi_device_class(ibm
->device
), "%s/%s", IBM_NAME
, ibm
->name
);
2471 status
= acpi_install_notify_handler(*ibm
->handle
, ibm
->type
,
2472 dispatch_notify
, ibm
);
2473 if (ACPI_FAILURE(status
)) {
2474 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
2482 static int __init
ibm_device_add(struct acpi_device
*device
)
2487 static int __init
register_driver(struct ibm_struct
*ibm
)
2491 ibm
->driver
= kmalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
2493 printk(IBM_ERR
"kmalloc(ibm->driver) failed\n");
2497 memset(ibm
->driver
, 0, sizeof(struct acpi_driver
));
2498 sprintf(ibm
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
2499 ibm
->driver
->ids
= ibm
->hid
;
2500 ibm
->driver
->ops
.add
= &ibm_device_add
;
2502 ret
= acpi_bus_register_driver(ibm
->driver
);
2504 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
2512 static int __init
ibm_init(struct ibm_struct
*ibm
)
2515 struct proc_dir_entry
*entry
;
2517 if (ibm
->experimental
&& !experimental
)
2521 ret
= register_driver(ibm
);
2524 ibm
->driver_registered
= 1;
2531 ibm
->init_called
= 1;
2535 entry
= create_proc_entry(ibm
->name
,
2536 S_IFREG
| S_IRUGO
| S_IWUSR
,
2539 printk(IBM_ERR
"unable to create proc entry %s\n",
2543 entry
->owner
= THIS_MODULE
;
2545 entry
->read_proc
= &dispatch_read
;
2547 entry
->write_proc
= &dispatch_write
;
2548 ibm
->proc_created
= 1;
2552 ret
= setup_notify(ibm
);
2555 ibm
->notify_installed
= 1;
2561 static void ibm_exit(struct ibm_struct
*ibm
)
2563 if (ibm
->notify_installed
)
2564 acpi_remove_notify_handler(*ibm
->handle
, ibm
->type
,
2567 if (ibm
->proc_created
)
2568 remove_proc_entry(ibm
->name
, proc_dir
);
2570 if (ibm
->init_called
&& ibm
->exit
)
2573 if (ibm
->driver_registered
) {
2574 acpi_bus_unregister_driver(ibm
->driver
);
2579 static void __init
ibm_handle_init(char *name
,
2580 acpi_handle
* handle
, acpi_handle parent
,
2581 char **paths
, int num_paths
, char **path
)
2586 for (i
= 0; i
< num_paths
; i
++) {
2587 status
= acpi_get_handle(parent
, paths
[i
], handle
);
2588 if (ACPI_SUCCESS(status
)) {
2597 #define IBM_HANDLE_INIT(object) \
2598 ibm_handle_init(#object, &object##_handle, *object##_parent, \
2599 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
2601 static int set_ibm_param(const char *val
, struct kernel_param
*kp
)
2605 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++)
2606 if (strcmp(ibms
[i
].name
, kp
->name
) == 0 && ibms
[i
].write
) {
2607 if (strlen(val
) > sizeof(ibms
[i
].param
) - 2)
2609 strcpy(ibms
[i
].param
, val
);
2610 strcat(ibms
[i
].param
, ",");
2617 #define IBM_PARAM(feature) \
2618 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
2621 IBM_PARAM(bluetooth
);
2624 #ifdef CONFIG_ACPI_IBM_DOCK
2632 IBM_PARAM(brightness
);
2636 static struct backlight_properties ibm_backlight_data
= {
2637 .owner
= THIS_MODULE
,
2638 .get_brightness
= brightness_get
,
2639 .update_status
= brightness_update_status
,
2640 .max_brightness
= 7,
2643 static void acpi_ibm_exit(void)
2647 if (ibm_backlight_device
)
2648 backlight_device_unregister(ibm_backlight_device
);
2650 for (i
= ARRAY_SIZE(ibms
) - 1; i
>= 0; i
--)
2653 remove_proc_entry(IBM_DIR
, acpi_root_dir
);
2655 if (ibm_thinkpad_ec_found
)
2656 kfree(ibm_thinkpad_ec_found
);
2659 static char* __init
check_dmi_for_ec(void)
2661 struct dmi_device
*dev
= NULL
;
2662 char ec_fw_string
[18];
2665 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2666 * X32 or newer, all Z series; Some models must have an
2667 * up-to-date BIOS or they will not be detected.
2669 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2671 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
2672 if (sscanf(dev
->name
,
2673 "IBM ThinkPad Embedded Controller -[%17c",
2674 ec_fw_string
) == 1) {
2675 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
2676 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
2677 return kstrdup(ec_fw_string
, GFP_KERNEL
);
2683 static int __init
acpi_ibm_init(void)
2690 if (!acpi_specific_hotkey_enabled
) {
2691 printk(IBM_ERR
"using generic hotkey driver\n");
2695 /* ec is required because many other handles are relative to it */
2696 IBM_HANDLE_INIT(ec
);
2698 printk(IBM_ERR
"ec object not found\n");
2702 /* Models with newer firmware report the EC in DMI */
2703 ibm_thinkpad_ec_found
= check_dmi_for_ec();
2704 if (ibm_thinkpad_ec_found
)
2705 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
2706 ibm_thinkpad_ec_found
);
2708 /* these handles are not required */
2709 IBM_HANDLE_INIT(vid
);
2710 IBM_HANDLE_INIT(vid2
);
2711 IBM_HANDLE_INIT(ledb
);
2712 IBM_HANDLE_INIT(led
);
2713 IBM_HANDLE_INIT(hkey
);
2714 IBM_HANDLE_INIT(lght
);
2715 IBM_HANDLE_INIT(cmos
);
2716 #ifdef CONFIG_ACPI_IBM_DOCK
2717 IBM_HANDLE_INIT(dock
);
2719 IBM_HANDLE_INIT(pci
);
2720 IBM_HANDLE_INIT(bay
);
2722 IBM_HANDLE_INIT(bay_ej
);
2723 IBM_HANDLE_INIT(bay2
);
2725 IBM_HANDLE_INIT(bay2_ej
);
2726 IBM_HANDLE_INIT(beep
);
2727 IBM_HANDLE_INIT(ecrd
);
2728 IBM_HANDLE_INIT(ecwr
);
2729 IBM_HANDLE_INIT(fans
);
2730 IBM_HANDLE_INIT(gfan
);
2731 IBM_HANDLE_INIT(sfan
);
2733 proc_dir
= proc_mkdir(IBM_DIR
, acpi_root_dir
);
2735 printk(IBM_ERR
"unable to create proc dir %s", IBM_DIR
);
2738 proc_dir
->owner
= THIS_MODULE
;
2740 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++) {
2741 ret
= ibm_init(&ibms
[i
]);
2742 if (ret
>= 0 && *ibms
[i
].param
)
2743 ret
= ibms
[i
].write(ibms
[i
].param
);
2750 ibm_backlight_device
= backlight_device_register("ibm", NULL
,
2751 &ibm_backlight_data
);
2752 if (IS_ERR(ibm_backlight_device
)) {
2753 printk(IBM_ERR
"Could not register ibm backlight device\n");
2754 ibm_backlight_device
= NULL
;
2761 module_init(acpi_ibm_init
);
2762 module_exit(acpi_ibm_exit
);