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 #ifdef CONFIG_ACPI_IBM_BAY
176 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
177 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
178 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
179 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
180 ); /* A21e, R30, R31 */
182 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
183 "_EJ0", /* all others */
184 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
186 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
187 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
190 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
195 /* don't list other alternatives as we install a notify handler on the 570 */
196 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
198 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
199 "^HKEY", /* R30, R31 */
200 "HKEY", /* all others */
203 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
204 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
206 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
207 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
208 "LED", /* all others */
211 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
212 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
213 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
214 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
216 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
217 "\\FSPD", /* 600e/x, 770e, 770x */
220 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
221 "JFNS", /* 770x-JL */
224 #define IBM_HKEY_HID "IBM0068"
225 #define IBM_PCI_HID "PNP0A03"
227 enum thermal_access_mode
{
228 IBMACPI_THERMAL_NONE
= 0, /* No thermal support */
229 IBMACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
230 IBMACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
231 IBMACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
232 IBMACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
235 #define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
236 struct ibm_thermal_sensors_struct
{
237 s32 temp
[IBMACPI_MAX_THERMAL_SENSORS
];
243 * IBMACPI_FAN_RD_ACPI_GFAN:
244 * ACPI GFAN method: returns fan level
246 * see IBMACPI_FAN_WR_ACPI_SFAN
247 * EC 0x2f not available if GFAN exists
249 * IBMACPI_FAN_WR_ACPI_SFAN:
250 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
252 * EC 0x2f might be available *for reading*, but never for writing.
254 * IBMACPI_FAN_WR_TPEC:
255 * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported
256 * on almost all ThinkPads
258 * Fan speed changes of any sort (including those caused by the
259 * disengaged mode) are usually done slowly by the firmware as the
260 * maximum ammount of fan duty cycle change per second seems to be
263 * Reading is not available if GFAN exists.
264 * Writing is not available if SFAN exists.
267 * 7 automatic mode engaged;
268 * (default operation mode of the ThinkPad)
269 * fan level is ignored in this mode.
270 * 6 disengage mode (takes precedence over bit 7);
271 * not available on all thinkpads. May disable
272 * the tachometer, and speeds up fan to 100% duty-cycle,
273 * which speeds it up far above the standard RPM
274 * levels. It is not impossible that it could cause
276 * 5-3 unused in some models. Extra bits for fan level
277 * in others, but still useless as all values above
278 * 7 map to the same speed as level 7 in these models.
279 * 2-0 fan level (0..7 usually)
281 * 0x07 = max (set when temperatures critical)
282 * Some ThinkPads may have other levels, see
283 * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
285 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
286 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
287 * does so, its initial value is meaningless (0x07).
289 * For firmware bugs, refer to:
290 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
294 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
295 * Main fan tachometer reading (in RPM)
297 * This register is present on all ThinkPads with a new-style EC, and
298 * it is known not to be present on the A21m/e, and T22, as there is
299 * something else in offset 0x84 according to the ACPI DSDT. Other
300 * ThinkPads from this same time period (and earlier) probably lack the
301 * tachometer as well.
303 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
304 * was never fixed by IBM to report the EC firmware version string
305 * probably support the tachometer (like the early X models), so
306 * detecting it is quite hard. We need more data to know for sure.
308 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
311 * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this
312 * register is not invalidated in ThinkPads that disable tachometer
313 * readings. Thus, the tachometer readings go stale.
315 * For firmware bugs, refer to:
316 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
318 * IBMACPI_FAN_WR_ACPI_FANS:
319 * ThinkPad X31, X40, X41. Not available in the X60.
321 * FANS ACPI handle: takes three arguments: low speed, medium speed,
322 * high speed. ACPI DSDT seems to map these three speeds to levels
323 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
324 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
326 * The speeds are stored on handles
327 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
329 * There are three default speed sets, acessible as handles:
330 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
332 * ACPI DSDT switches which set is in use depending on various
335 * IBMACPI_FAN_WR_TPEC is also available and should be used to
336 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
337 * but the ACPI tables just mention level 7.
340 enum fan_status_access_mode
{
341 IBMACPI_FAN_NONE
= 0, /* No fan status or control */
342 IBMACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
343 IBMACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
346 enum fan_control_access_mode
{
347 IBMACPI_FAN_WR_NONE
= 0, /* No fan control */
348 IBMACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
349 IBMACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
350 IBMACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
353 enum fan_control_commands
{
354 IBMACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
355 IBMACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
356 IBMACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
357 * and also watchdog cmd */
360 enum { /* Fan control constants */
361 fan_status_offset
= 0x2f, /* EC register 0x2f */
362 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
363 * 0x84 must be read before 0x85 */
365 IBMACPI_FAN_EC_DISENGAGED
= 0x40, /* EC mode: tachometer
367 IBMACPI_FAN_EC_AUTO
= 0x80, /* EC mode: auto fan
371 static char *ibm_thinkpad_ec_found
= NULL
;
378 struct acpi_driver
*driver
;
381 int (*read
) (char *);
382 int (*write
) (char *);
385 void (*notify
) (struct ibm_struct
*, u32
);
388 struct acpi_device
*device
;
390 int driver_registered
;
393 int notify_installed
;
398 static struct proc_dir_entry
*proc_dir
= NULL
;
400 static struct backlight_device
*ibm_backlight_device
= NULL
;
402 #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
403 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
404 #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
406 static int acpi_evalf(acpi_handle handle
,
407 void *res
, char *method
, char *fmt
, ...)
410 struct acpi_object_list params
;
411 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
412 struct acpi_buffer result
, *resultp
;
413 union acpi_object out_obj
;
421 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
434 params
.pointer
= &in_objs
[0];
441 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
442 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
444 /* add more types as needed */
446 printk(IBM_ERR
"acpi_evalf() called "
447 "with invalid format character '%c'\n", c
);
453 if (res_type
!= 'v') {
454 result
.length
= sizeof(out_obj
);
455 result
.pointer
= &out_obj
;
460 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
465 *(int *)res
= out_obj
.integer
.value
;
466 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
469 success
= status
== AE_OK
;
471 /* add more types as needed */
473 printk(IBM_ERR
"acpi_evalf() called "
474 "with invalid format character '%c'\n", res_type
);
478 if (!success
&& !quiet
)
479 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
480 method
, fmt0
, status
);
485 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
489 if (acpi_evalf(handle
, &i
, method
, "d"))
490 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
492 printk(IBM_ERR
"error calling %s\n", method
);
495 static char *next_cmd(char **cmds
)
500 while ((end
= strchr(start
, ',')) && end
== start
)
511 static int driver_init(void)
513 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
514 printk(IBM_INFO
"%s\n", IBM_URL
);
519 static int driver_read(char *p
)
523 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
524 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
529 static int hotkey_supported
;
530 static int hotkey_mask_supported
;
531 static int hotkey_orig_status
;
532 static int hotkey_orig_mask
;
534 static int hotkey_get(int *status
, int *mask
)
536 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
539 if (hotkey_mask_supported
)
540 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
546 static int hotkey_set(int status
, int mask
)
550 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
553 if (hotkey_mask_supported
)
554 for (i
= 0; i
< 32; i
++) {
555 int bit
= ((1 << i
) & mask
) != 0;
556 if (!acpi_evalf(hkey_handle
,
557 NULL
, "MHKM", "vdd", i
+ 1, bit
))
564 static int hotkey_init(void)
566 /* hotkey not supported on 570 */
567 hotkey_supported
= hkey_handle
!= NULL
;
569 if (hotkey_supported
) {
570 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
571 A30, R30, R31, T20-22, X20-21, X22-24 */
572 hotkey_mask_supported
=
573 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
575 if (!hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
))
582 static int hotkey_read(char *p
)
587 if (!hotkey_supported
) {
588 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
592 if (!hotkey_get(&status
, &mask
))
595 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
596 if (hotkey_mask_supported
) {
597 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
598 len
+= sprintf(p
+ len
,
599 "commands:\tenable, disable, reset, <mask>\n");
601 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
602 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
608 static int hotkey_write(char *buf
)
614 if (!hotkey_supported
)
617 if (!hotkey_get(&status
, &mask
))
620 while ((cmd
= next_cmd(&buf
))) {
621 if (strlencmp(cmd
, "enable") == 0) {
623 } else if (strlencmp(cmd
, "disable") == 0) {
625 } else if (strlencmp(cmd
, "reset") == 0) {
626 status
= hotkey_orig_status
;
627 mask
= hotkey_orig_mask
;
628 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
630 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
637 if (do_cmd
&& !hotkey_set(status
, mask
))
643 static void hotkey_exit(void)
645 if (hotkey_supported
)
646 hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
649 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
653 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
654 acpi_bus_generate_event(ibm
->device
, event
, hkey
);
656 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
657 acpi_bus_generate_event(ibm
->device
, event
, 0);
661 static int bluetooth_supported
;
663 static int bluetooth_init(void)
665 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
666 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
667 bluetooth_supported
= hkey_handle
&&
668 acpi_evalf(hkey_handle
, NULL
, "GBDC", "qv");
673 static int bluetooth_status(void)
677 if (!bluetooth_supported
||
678 !acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
684 static int bluetooth_read(char *p
)
687 int status
= bluetooth_status();
689 if (!bluetooth_supported
)
690 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
691 else if (!(status
& 1))
692 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
694 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
695 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
701 static int bluetooth_write(char *buf
)
703 int status
= bluetooth_status();
707 if (!bluetooth_supported
)
710 while ((cmd
= next_cmd(&buf
))) {
711 if (strlencmp(cmd
, "enable") == 0) {
713 } else if (strlencmp(cmd
, "disable") == 0) {
720 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
726 static int wan_supported
;
728 static int wan_init(void)
730 wan_supported
= hkey_handle
&&
731 acpi_evalf(hkey_handle
, NULL
, "GWAN", "qv");
736 static int wan_status(void)
740 if (!wan_supported
|| !acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
746 static int wan_read(char *p
)
749 int status
= wan_status();
752 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
753 else if (!(status
& 1))
754 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
756 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
757 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
763 static int wan_write(char *buf
)
765 int status
= wan_status();
772 while ((cmd
= next_cmd(&buf
))) {
773 if (strlencmp(cmd
, "enable") == 0) {
775 } else if (strlencmp(cmd
, "disable") == 0) {
782 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
788 static int video_supported
;
789 static int video_orig_autosw
;
795 static int video_init(void)
799 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
800 /* G41, assume IVGA doesn't change */
801 vid_handle
= vid2_handle
;
804 /* video switching not supported on R30, R31 */
806 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
808 video_supported
= VIDEO_570
;
809 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
810 /* 600e/x, 770e, 770x */
811 video_supported
= VIDEO_770
;
814 video_supported
= VIDEO_NEW
;
819 static int video_status(void)
824 if (video_supported
== VIDEO_570
) {
825 if (acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd", 0x87))
827 } else if (video_supported
== VIDEO_770
) {
828 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
830 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
832 } else if (video_supported
== VIDEO_NEW
) {
833 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1);
834 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
837 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0);
838 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
840 if (acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
847 static int video_autosw(void)
851 if (video_supported
== VIDEO_570
)
852 acpi_evalf(vid_handle
, &autosw
, "SWIT", "d");
853 else if (video_supported
== VIDEO_770
|| video_supported
== VIDEO_NEW
)
854 acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d");
859 static int video_read(char *p
)
861 int status
= video_status();
862 int autosw
= video_autosw();
865 if (!video_supported
) {
866 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
870 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
871 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
872 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
873 if (video_supported
== VIDEO_NEW
)
874 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
875 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
876 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
877 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
878 if (video_supported
== VIDEO_NEW
)
879 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
880 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
881 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
886 static int video_switch(void)
888 int autosw
= video_autosw();
891 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
893 ret
= video_supported
== VIDEO_570
?
894 acpi_evalf(ec_handle
, NULL
, "_Q16", "v") :
895 acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
896 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
901 static int video_expand(void)
903 if (video_supported
== VIDEO_570
)
904 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v");
905 else if (video_supported
== VIDEO_770
)
906 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v");
908 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v");
911 static int video_switch2(int status
)
915 if (video_supported
== VIDEO_570
) {
916 ret
= acpi_evalf(NULL
, NULL
,
917 "\\_SB.PHS2", "vdd", 0x8b, status
| 0x80);
918 } else if (video_supported
== VIDEO_770
) {
919 int autosw
= video_autosw();
920 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
923 ret
= acpi_evalf(vid_handle
, NULL
,
924 "ASWT", "vdd", status
* 0x100, 0);
926 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
928 ret
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
929 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
935 static int video_write(char *buf
)
938 int enable
, disable
, status
;
940 if (!video_supported
)
943 enable
= disable
= 0;
945 while ((cmd
= next_cmd(&buf
))) {
946 if (strlencmp(cmd
, "lcd_enable") == 0) {
948 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
950 } else if (strlencmp(cmd
, "crt_enable") == 0) {
952 } else if (strlencmp(cmd
, "crt_disable") == 0) {
954 } else if (video_supported
== VIDEO_NEW
&&
955 strlencmp(cmd
, "dvi_enable") == 0) {
957 } else if (video_supported
== VIDEO_NEW
&&
958 strlencmp(cmd
, "dvi_disable") == 0) {
960 } else if (strlencmp(cmd
, "auto_enable") == 0) {
961 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
963 } else if (strlencmp(cmd
, "auto_disable") == 0) {
964 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 0))
966 } else if (strlencmp(cmd
, "video_switch") == 0) {
969 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
976 if (enable
|| disable
) {
977 status
= (video_status() & 0x0f & ~disable
) | enable
;
978 if (!video_switch2(status
))
985 static void video_exit(void)
987 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", video_orig_autosw
);
990 static int light_supported
;
991 static int light_status_supported
;
993 static int light_init(void)
995 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
996 light_supported
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
999 /* light status not supported on
1000 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
1001 light_status_supported
= acpi_evalf(ec_handle
, NULL
,
1007 static int light_read(char *p
)
1012 if (!light_supported
) {
1013 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1014 } else if (!light_status_supported
) {
1015 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1016 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1018 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1020 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1021 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1027 static int light_write(char *buf
)
1029 int cmos_cmd
, lght_cmd
;
1033 if (!light_supported
)
1036 while ((cmd
= next_cmd(&buf
))) {
1037 if (strlencmp(cmd
, "on") == 0) {
1040 } else if (strlencmp(cmd
, "off") == 0) {
1046 success
= cmos_handle
?
1047 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1048 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1056 #if defined(CONFIG_ACPI_IBM_DOCK) || defined(CONFIG_ACPI_IBM_BAY)
1057 static int _sta(acpi_handle handle
)
1061 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
1067 #ifdef CONFIG_ACPI_IBM_DOCK
1068 #define dock_docked() (_sta(dock_handle) & 1)
1070 static int dock_read(char *p
)
1073 int docked
= dock_docked();
1076 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1078 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1080 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1081 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1087 static int dock_write(char *buf
)
1094 while ((cmd
= next_cmd(&buf
))) {
1095 if (strlencmp(cmd
, "undock") == 0) {
1096 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1097 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1099 } else if (strlencmp(cmd
, "dock") == 0) {
1100 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1109 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1111 int docked
= dock_docked();
1112 int pci
= ibm
->hid
&& strstr(ibm
->hid
, IBM_PCI_HID
);
1114 if (event
== 1 && !pci
) /* 570 */
1115 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1116 else if (event
== 1 && pci
) /* 570 */
1117 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1118 else if (event
== 3 && docked
)
1119 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1120 else if (event
== 3 && !docked
)
1121 acpi_bus_generate_event(ibm
->device
, event
, 2); /* undock */
1122 else if (event
== 0 && docked
)
1123 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1125 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1126 event
, _sta(dock_handle
));
1127 acpi_bus_generate_event(ibm
->device
, event
, 0); /* unknown */
1132 #ifdef CONFIG_ACPI_IBM_BAY
1133 static int bay_status_supported
;
1134 static int bay_status2_supported
;
1135 static int bay_eject_supported
;
1136 static int bay_eject2_supported
;
1138 static int bay_init(void)
1140 bay_status_supported
= bay_handle
&&
1141 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1142 bay_status2_supported
= bay2_handle
&&
1143 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1145 bay_eject_supported
= bay_handle
&& bay_ej_handle
&&
1146 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1147 bay_eject2_supported
= bay2_handle
&& bay2_ej_handle
&&
1148 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1153 #define bay_occupied(b) (_sta(b##_handle) & 1)
1155 static int bay_read(char *p
)
1158 int occupied
= bay_occupied(bay
);
1159 int occupied2
= bay_occupied(bay2
);
1162 len
+= sprintf(p
+ len
, "status:\t\t%s\n", bay_status_supported
?
1163 (occupied
? "occupied" : "unoccupied") :
1165 if (bay_status2_supported
)
1166 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1167 "occupied" : "unoccupied");
1169 eject
= bay_eject_supported
&& occupied
;
1170 eject2
= bay_eject2_supported
&& occupied2
;
1172 if (eject
&& eject2
)
1173 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1175 len
+= sprintf(p
+ len
, "commands:\teject\n");
1177 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1182 static int bay_write(char *buf
)
1186 if (!bay_eject_supported
&& !bay_eject2_supported
)
1189 while ((cmd
= next_cmd(&buf
))) {
1190 if (bay_eject_supported
&& strlencmp(cmd
, "eject") == 0) {
1191 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1193 } else if (bay_eject2_supported
&&
1194 strlencmp(cmd
, "eject2") == 0) {
1195 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1204 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1206 acpi_bus_generate_event(ibm
->device
, event
, 0);
1210 static int cmos_read(char *p
)
1214 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1215 R30, R31, T20-22, X20-21 */
1217 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1219 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1220 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1226 static int cmos_eval(int cmos_cmd
)
1229 return acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
);
1234 static int cmos_write(char *buf
)
1242 while ((cmd
= next_cmd(&buf
))) {
1243 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1244 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1249 if (!cmos_eval(cmos_cmd
))
1256 static int led_supported
;
1262 static int led_init(void)
1265 /* led not supported on R30, R31 */
1267 else if (strlencmp(led_path
, "SLED") == 0)
1269 led_supported
= LED_570
;
1270 else if (strlencmp(led_path
, "SYSL") == 0)
1271 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1272 led_supported
= LED_OLD
;
1275 led_supported
= LED_NEW
;
1280 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1282 static int led_read(char *p
)
1286 if (!led_supported
) {
1287 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1290 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1292 if (led_supported
== LED_570
) {
1295 for (i
= 0; i
< 8; i
++) {
1296 if (!acpi_evalf(ec_handle
,
1297 &status
, "GLED", "dd", 1 << i
))
1299 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1300 i
, led_status(status
));
1304 len
+= sprintf(p
+ len
, "commands:\t"
1305 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1310 /* off, on, blink */
1311 static const int led_sled_arg1
[] = { 0, 1, 3 };
1312 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
1313 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
1314 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
1316 #define EC_HLCL 0x0c
1317 #define EC_HLBL 0x0d
1318 #define EC_HLMS 0x0e
1320 static int led_write(char *buf
)
1328 while ((cmd
= next_cmd(&buf
))) {
1329 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1332 if (strstr(cmd
, "off")) {
1334 } else if (strstr(cmd
, "on")) {
1336 } else if (strstr(cmd
, "blink")) {
1341 if (led_supported
== LED_570
) {
1344 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1345 led
, led_sled_arg1
[ind
]))
1347 } else if (led_supported
== LED_OLD
) {
1348 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1350 ret
= ec_write(EC_HLMS
, led
);
1353 ec_write(EC_HLBL
, led
* led_exp_hlbl
[ind
]);
1356 ec_write(EC_HLCL
, led
* led_exp_hlcl
[ind
]);
1361 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1362 led
, led_led_arg1
[ind
]))
1370 static int beep_read(char *p
)
1375 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1377 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1378 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1384 static int beep_write(char *buf
)
1392 while ((cmd
= next_cmd(&buf
))) {
1393 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1394 beep_cmd
>= 0 && beep_cmd
<= 17) {
1398 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1405 static int acpi_ec_read(int i
, u8
* p
)
1410 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
1414 if (ec_read(i
, p
) < 0)
1421 static int acpi_ec_write(int i
, u8 v
)
1424 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
1427 if (ec_write(i
, v
) < 0)
1434 static enum thermal_access_mode thermal_read_mode
;
1436 static int thermal_init(void)
1440 int acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
1442 if (ibm_thinkpad_ec_found
&& experimental
) {
1444 * Direct EC access mode: sensors at registers
1445 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1446 * non-implemented, thermal sensors return 0x80 when
1451 for (i
= 0; i
< 8; i
++) {
1452 if (likely(acpi_ec_read(0x78 + i
, &t
))) {
1458 if (likely(acpi_ec_read(0xC0 + i
, &t
))) {
1466 /* This is sheer paranoia, but we handle it anyway */
1469 "ThinkPad ACPI EC access misbehaving, "
1470 "falling back to ACPI TMPx access mode\n");
1471 thermal_read_mode
= IBMACPI_THERMAL_ACPI_TMP07
;
1474 "ThinkPad ACPI EC access misbehaving, "
1475 "disabling thermal sensors access\n");
1476 thermal_read_mode
= IBMACPI_THERMAL_NONE
;
1481 IBMACPI_THERMAL_TPEC_16
: IBMACPI_THERMAL_TPEC_8
;
1483 } else if (acpi_tmp7
) {
1484 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
1485 /* 600e/x, 770e, 770x */
1486 thermal_read_mode
= IBMACPI_THERMAL_ACPI_UPDT
;
1488 /* Standard ACPI TMPx access, max 8 sensors */
1489 thermal_read_mode
= IBMACPI_THERMAL_ACPI_TMP07
;
1492 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1493 thermal_read_mode
= IBMACPI_THERMAL_NONE
;
1499 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
1503 char tmpi
[] = "TMPi";
1508 switch (thermal_read_mode
) {
1509 #if IBMACPI_MAX_THERMAL_SENSORS >= 16
1510 case IBMACPI_THERMAL_TPEC_16
:
1511 for (i
= 0; i
< 8; i
++) {
1512 if (!acpi_ec_read(0xC0 + i
, &tmp
))
1514 s
->temp
[i
+ 8] = tmp
* 1000;
1518 case IBMACPI_THERMAL_TPEC_8
:
1519 for (i
= 0; i
< 8; i
++) {
1520 if (!acpi_ec_read(0x78 + i
, &tmp
))
1522 s
->temp
[i
] = tmp
* 1000;
1524 return (thermal_read_mode
== IBMACPI_THERMAL_TPEC_16
) ? 16 : 8;
1526 case IBMACPI_THERMAL_ACPI_UPDT
:
1527 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
1529 for (i
= 0; i
< 8; i
++) {
1531 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1533 s
->temp
[i
] = (t
- 2732) * 100;
1537 case IBMACPI_THERMAL_ACPI_TMP07
:
1538 for (i
= 0; i
< 8; i
++) {
1540 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1542 s
->temp
[i
] = t
* 1000;
1546 case IBMACPI_THERMAL_NONE
:
1552 static int thermal_read(char *p
)
1556 struct ibm_thermal_sensors_struct t
;
1558 n
= thermal_get_sensors(&t
);
1559 if (unlikely(n
< 0))
1562 len
+= sprintf(p
+ len
, "temperatures:\t");
1565 for (i
= 0; i
< (n
- 1); i
++)
1566 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
1567 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
1569 len
+= sprintf(p
+ len
, "not supported\n");
1574 static u8 ecdump_regs
[256];
1576 static int ecdump_read(char *p
)
1582 len
+= sprintf(p
+ len
, "EC "
1583 " +00 +01 +02 +03 +04 +05 +06 +07"
1584 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1585 for (i
= 0; i
< 256; i
+= 16) {
1586 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
1587 for (j
= 0; j
< 16; j
++) {
1588 if (!acpi_ec_read(i
+ j
, &v
))
1590 if (v
!= ecdump_regs
[i
+ j
])
1591 len
+= sprintf(p
+ len
, " *%02x", v
);
1593 len
+= sprintf(p
+ len
, " %02x", v
);
1594 ecdump_regs
[i
+ j
] = v
;
1596 len
+= sprintf(p
+ len
, "\n");
1601 /* These are way too dangerous to advertise openly... */
1603 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
1604 " (<offset> is 00-ff, <value> is 00-ff)\n");
1605 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
1606 " (<offset> is 00-ff, <value> is 0-255)\n");
1611 static int ecdump_write(char *buf
)
1616 while ((cmd
= next_cmd(&buf
))) {
1617 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
1619 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
1623 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
1624 if (!acpi_ec_write(i
, v
))
1633 static int brightness_offset
= 0x31;
1635 static int brightness_get(struct backlight_device
*bd
)
1638 if (!acpi_ec_read(brightness_offset
, &level
))
1646 static int brightness_read(char *p
)
1651 if ((level
= brightness_get(NULL
)) < 0) {
1652 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1654 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
1655 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
1656 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1657 " (<level> is 0-7)\n");
1663 #define BRIGHTNESS_UP 4
1664 #define BRIGHTNESS_DOWN 5
1666 static int brightness_set(int value
)
1668 int cmos_cmd
, inc
, i
;
1669 int current_value
= brightness_get(NULL
);
1673 cmos_cmd
= value
> current_value
? BRIGHTNESS_UP
: BRIGHTNESS_DOWN
;
1674 inc
= value
> current_value
? 1 : -1;
1675 for (i
= current_value
; i
!= value
; i
+= inc
) {
1676 if (!cmos_eval(cmos_cmd
))
1678 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
1685 static int brightness_write(char *buf
)
1691 while ((cmd
= next_cmd(&buf
))) {
1692 if ((level
= brightness_get(NULL
)) < 0)
1696 if (strlencmp(cmd
, "up") == 0) {
1697 new_level
= level
== 7 ? 7 : level
+ 1;
1698 } else if (strlencmp(cmd
, "down") == 0) {
1699 new_level
= level
== 0 ? 0 : level
- 1;
1700 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1701 new_level
>= 0 && new_level
<= 7) {
1706 brightness_set(new_level
);
1712 static int brightness_update_status(struct backlight_device
*bd
)
1714 return brightness_set(bd
->props
->brightness
);
1717 static struct backlight_properties ibm_backlight_data
= {
1718 .owner
= THIS_MODULE
,
1719 .get_brightness
= brightness_get
,
1720 .update_status
= brightness_update_status
,
1721 .max_brightness
= 7,
1724 static int brightness_init(void)
1726 ibm_backlight_device
= backlight_device_register("ibm", NULL
,
1727 &ibm_backlight_data
);
1728 if (IS_ERR(ibm_backlight_device
)) {
1729 printk(IBM_ERR
"Could not register backlight device\n");
1730 return PTR_ERR(ibm_backlight_device
);
1736 static void brightness_exit(void)
1738 if (ibm_backlight_device
) {
1739 backlight_device_unregister(ibm_backlight_device
);
1740 ibm_backlight_device
= NULL
;
1744 static int volume_offset
= 0x30;
1746 static int volume_read(char *p
)
1751 if (!acpi_ec_read(volume_offset
, &level
)) {
1752 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1754 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
1755 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
1756 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
1757 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1758 " (<level> is 0-15)\n");
1764 #define VOLUME_DOWN 0
1766 #define VOLUME_MUTE 2
1768 static int volume_write(char *buf
)
1770 int cmos_cmd
, inc
, i
;
1772 int new_level
, new_mute
;
1775 while ((cmd
= next_cmd(&buf
))) {
1776 if (!acpi_ec_read(volume_offset
, &level
))
1778 new_mute
= mute
= level
& 0x40;
1779 new_level
= level
= level
& 0xf;
1781 if (strlencmp(cmd
, "up") == 0) {
1785 new_level
= level
== 15 ? 15 : level
+ 1;
1786 } else if (strlencmp(cmd
, "down") == 0) {
1790 new_level
= level
== 0 ? 0 : level
- 1;
1791 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1792 new_level
>= 0 && new_level
<= 15) {
1794 } else if (strlencmp(cmd
, "mute") == 0) {
1799 if (new_level
!= level
) { /* mute doesn't change */
1800 cmos_cmd
= new_level
> level
? VOLUME_UP
: VOLUME_DOWN
;
1801 inc
= new_level
> level
? 1 : -1;
1803 if (mute
&& (!cmos_eval(cmos_cmd
) ||
1804 !acpi_ec_write(volume_offset
, level
)))
1807 for (i
= level
; i
!= new_level
; i
+= inc
)
1808 if (!cmos_eval(cmos_cmd
) ||
1809 !acpi_ec_write(volume_offset
, i
+ inc
))
1812 if (mute
&& (!cmos_eval(VOLUME_MUTE
) ||
1813 !acpi_ec_write(volume_offset
,
1818 if (new_mute
!= mute
) { /* level doesn't change */
1819 cmos_cmd
= new_mute
? VOLUME_MUTE
: VOLUME_UP
;
1821 if (!cmos_eval(cmos_cmd
) ||
1822 !acpi_ec_write(volume_offset
, level
+ new_mute
))
1830 static enum fan_status_access_mode fan_status_access_mode
;
1831 static enum fan_control_access_mode fan_control_access_mode
;
1832 static enum fan_control_commands fan_control_commands
;
1834 static int fan_control_status_known
;
1835 static u8 fan_control_initial_status
;
1837 static void fan_watchdog_fire(void *ignored
);
1838 static int fan_watchdog_maxinterval
;
1839 static DECLARE_WORK(fan_watchdog_task
, fan_watchdog_fire
, NULL
);
1841 static int fan_init(void)
1843 fan_status_access_mode
= IBMACPI_FAN_NONE
;
1844 fan_control_access_mode
= IBMACPI_FAN_WR_NONE
;
1845 fan_control_commands
= 0;
1846 fan_control_status_known
= 1;
1847 fan_watchdog_maxinterval
= 0;
1850 /* 570, 600e/x, 770e, 770x */
1851 fan_status_access_mode
= IBMACPI_FAN_RD_ACPI_GFAN
;
1853 /* all other ThinkPads: note that even old-style
1854 * ThinkPad ECs supports the fan control register */
1855 if (likely(acpi_ec_read(fan_status_offset
,
1856 &fan_control_initial_status
))) {
1857 fan_status_access_mode
= IBMACPI_FAN_RD_TPEC
;
1859 /* In some ThinkPads, neither the EC nor the ACPI
1860 * DSDT initialize the fan status, and it ends up
1861 * being set to 0x07 when it *could* be either
1864 * Enable for TP-1Y (T43), TP-78 (R51e),
1865 * TP-76 (R52), TP-70 (T43, R52), which are known
1867 if (fan_control_initial_status
== 0x07 &&
1868 ibm_thinkpad_ec_found
&&
1869 ((ibm_thinkpad_ec_found
[0] == '1' &&
1870 ibm_thinkpad_ec_found
[1] == 'Y') ||
1871 (ibm_thinkpad_ec_found
[0] == '7' &&
1872 (ibm_thinkpad_ec_found
[1] == '6' ||
1873 ibm_thinkpad_ec_found
[1] == '8' ||
1874 ibm_thinkpad_ec_found
[1] == '0'))
1877 "fan_init: initial fan status is "
1878 "unknown, assuming it is in auto "
1880 fan_control_status_known
= 0;
1884 "ThinkPad ACPI EC access misbehaving, "
1885 "fan status and control unavailable\n");
1892 fan_control_access_mode
= IBMACPI_FAN_WR_ACPI_SFAN
;
1893 fan_control_commands
|=
1894 IBMACPI_FAN_CMD_LEVEL
| IBMACPI_FAN_CMD_ENABLE
;
1897 /* gfan without sfan means no fan control */
1898 /* all other models implement TP EC 0x2f control */
1902 fan_control_access_mode
=
1903 IBMACPI_FAN_WR_ACPI_FANS
;
1904 fan_control_commands
|=
1905 IBMACPI_FAN_CMD_SPEED
|
1906 IBMACPI_FAN_CMD_LEVEL
|
1907 IBMACPI_FAN_CMD_ENABLE
;
1909 fan_control_access_mode
= IBMACPI_FAN_WR_TPEC
;
1910 fan_control_commands
|=
1911 IBMACPI_FAN_CMD_LEVEL
|
1912 IBMACPI_FAN_CMD_ENABLE
;
1920 static int fan_get_status(u8
*status
)
1925 * Add IBMACPI_FAN_RD_ACPI_FANS ? */
1927 switch (fan_status_access_mode
) {
1928 case IBMACPI_FAN_RD_ACPI_GFAN
:
1929 /* 570, 600e/x, 770e, 770x */
1931 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
1939 case IBMACPI_FAN_RD_TPEC
:
1940 /* all except 570, 600e/x, 770e, 770x */
1941 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
1956 static int fan_get_speed(unsigned int *speed
)
1960 switch (fan_status_access_mode
) {
1961 case IBMACPI_FAN_RD_TPEC
:
1962 /* all except 570, 600e/x, 770e, 770x */
1963 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
1964 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
1968 *speed
= (hi
<< 8) | lo
;
1979 static void fan_exit(void)
1981 cancel_delayed_work(&fan_watchdog_task
);
1982 flush_scheduled_work();
1985 static void fan_watchdog_reset(void)
1987 static int fan_watchdog_active
= 0;
1989 if (fan_watchdog_active
)
1990 cancel_delayed_work(&fan_watchdog_task
);
1992 if (fan_watchdog_maxinterval
> 0) {
1993 fan_watchdog_active
= 1;
1994 if (!schedule_delayed_work(&fan_watchdog_task
,
1995 msecs_to_jiffies(fan_watchdog_maxinterval
1997 printk(IBM_ERR
"failed to schedule the fan watchdog, "
1998 "watchdog will not trigger\n");
2001 fan_watchdog_active
= 0;
2004 static int fan_read(char *p
)
2009 unsigned int speed
= 0;
2011 switch (fan_status_access_mode
) {
2012 case IBMACPI_FAN_RD_ACPI_GFAN
:
2013 /* 570, 600e/x, 770e, 770x */
2014 if ((rc
= fan_get_status(&status
)) < 0)
2017 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
2019 (status
!= 0) ? "enabled" : "disabled", status
);
2022 case IBMACPI_FAN_RD_TPEC
:
2023 /* all except 570, 600e/x, 770e, 770x */
2024 if ((rc
= fan_get_status(&status
)) < 0)
2027 if (unlikely(!fan_control_status_known
)) {
2028 if (status
!= fan_control_initial_status
)
2029 fan_control_status_known
= 1;
2031 /* Return most likely status. In fact, it
2032 * might be the only possible status */
2033 status
= IBMACPI_FAN_EC_AUTO
;
2036 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2037 (status
!= 0) ? "enabled" : "disabled");
2039 /* No ThinkPad boots on disengaged mode, we can safely
2040 * assume the tachometer is online if fan control status
2042 if ((rc
= fan_get_speed(&speed
)) < 0)
2045 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
2047 if (status
& IBMACPI_FAN_EC_DISENGAGED
)
2048 /* Disengaged mode takes precedence */
2049 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
2050 else if (status
& IBMACPI_FAN_EC_AUTO
)
2051 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
2053 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
2056 case IBMACPI_FAN_NONE
:
2058 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2061 if (fan_control_commands
& IBMACPI_FAN_CMD_LEVEL
) {
2062 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
2064 switch (fan_control_access_mode
) {
2065 case IBMACPI_FAN_WR_ACPI_SFAN
:
2066 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
2070 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
2071 "auto, disengaged)\n");
2076 if (fan_control_commands
& IBMACPI_FAN_CMD_ENABLE
)
2077 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
2078 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2079 "1-120 (seconds))\n");
2081 if (fan_control_commands
& IBMACPI_FAN_CMD_SPEED
)
2082 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
2083 " (<speed> is 0-65535)\n");
2088 static int fan_set_level(int level
)
2090 switch (fan_control_access_mode
) {
2091 case IBMACPI_FAN_WR_ACPI_SFAN
:
2092 if (level
>= 0 && level
<= 7) {
2093 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
2099 case IBMACPI_FAN_WR_ACPI_FANS
:
2100 case IBMACPI_FAN_WR_TPEC
:
2101 if ((level
!= IBMACPI_FAN_EC_AUTO
) &&
2102 (level
!= IBMACPI_FAN_EC_DISENGAGED
) &&
2103 ((level
< 0) || (level
> 7)))
2106 if (!acpi_ec_write(fan_status_offset
, level
))
2109 fan_control_status_known
= 1;
2118 static int fan_set_enable(void)
2123 switch (fan_control_access_mode
) {
2124 case IBMACPI_FAN_WR_ACPI_FANS
:
2125 case IBMACPI_FAN_WR_TPEC
:
2126 if ((rc
= fan_get_status(&s
)) < 0)
2129 /* Don't go out of emergency fan mode */
2131 s
= IBMACPI_FAN_EC_AUTO
;
2133 if (!acpi_ec_write(fan_status_offset
, s
))
2136 fan_control_status_known
= 1;
2139 case IBMACPI_FAN_WR_ACPI_SFAN
:
2140 if ((rc
= fan_get_status(&s
)) < 0)
2145 /* Set fan to at least level 4 */
2149 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
2159 static int fan_set_disable(void)
2161 switch (fan_control_access_mode
) {
2162 case IBMACPI_FAN_WR_ACPI_FANS
:
2163 case IBMACPI_FAN_WR_TPEC
:
2164 if (!acpi_ec_write(fan_status_offset
, 0x00))
2167 fan_control_status_known
= 1;
2170 case IBMACPI_FAN_WR_ACPI_SFAN
:
2171 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
2181 static int fan_set_speed(int speed
)
2183 switch (fan_control_access_mode
) {
2184 case IBMACPI_FAN_WR_ACPI_FANS
:
2185 if (speed
>= 0 && speed
<= 65535) {
2186 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
2187 speed
, speed
, speed
))
2199 static int fan_write_cmd_level(const char *cmd
, int *rc
)
2203 if (strlencmp(cmd
, "level auto") == 0)
2204 level
= IBMACPI_FAN_EC_AUTO
;
2205 else if (strlencmp(cmd
, "level disengaged") == 0)
2206 level
= IBMACPI_FAN_EC_DISENGAGED
;
2207 else if (sscanf(cmd
, "level %d", &level
) != 1)
2210 if ((*rc
= fan_set_level(level
)) == -ENXIO
)
2211 printk(IBM_ERR
"level command accepted for unsupported "
2212 "access mode %d", fan_control_access_mode
);
2217 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
2219 if (strlencmp(cmd
, "enable") != 0)
2222 if ((*rc
= fan_set_enable()) == -ENXIO
)
2223 printk(IBM_ERR
"enable command accepted for unsupported "
2224 "access mode %d", fan_control_access_mode
);
2229 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
2231 if (strlencmp(cmd
, "disable") != 0)
2234 if ((*rc
= fan_set_disable()) == -ENXIO
)
2235 printk(IBM_ERR
"disable command accepted for unsupported "
2236 "access mode %d", fan_control_access_mode
);
2241 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
2246 * Support speed <low> <medium> <high> ? */
2248 if (sscanf(cmd
, "speed %d", &speed
) != 1)
2251 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
2252 printk(IBM_ERR
"speed command accepted for unsupported "
2253 "access mode %d", fan_control_access_mode
);
2258 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
2262 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
2265 if (interval
< 0 || interval
> 120)
2268 fan_watchdog_maxinterval
= interval
;
2273 static int fan_write(char *buf
)
2278 while (!rc
&& (cmd
= next_cmd(&buf
))) {
2279 if (!((fan_control_commands
& IBMACPI_FAN_CMD_LEVEL
) &&
2280 fan_write_cmd_level(cmd
, &rc
)) &&
2281 !((fan_control_commands
& IBMACPI_FAN_CMD_ENABLE
) &&
2282 (fan_write_cmd_enable(cmd
, &rc
) ||
2283 fan_write_cmd_disable(cmd
, &rc
) ||
2284 fan_write_cmd_watchdog(cmd
, &rc
))) &&
2285 !((fan_control_commands
& IBMACPI_FAN_CMD_SPEED
) &&
2286 fan_write_cmd_speed(cmd
, &rc
))
2290 fan_watchdog_reset();
2296 static void fan_watchdog_fire(void *ignored
)
2298 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
2299 if (fan_set_enable()) {
2300 printk(IBM_ERR
"fan watchdog: error while enabling fan\n");
2301 /* reschedule for later */
2302 fan_watchdog_reset();
2306 static struct ibm_struct ibms
[] = {
2309 .init
= driver_init
,
2310 .read
= driver_read
,
2314 .hid
= IBM_HKEY_HID
,
2315 .init
= hotkey_init
,
2316 .read
= hotkey_read
,
2317 .write
= hotkey_write
,
2318 .exit
= hotkey_exit
,
2319 .notify
= hotkey_notify
,
2320 .handle
= &hkey_handle
,
2321 .type
= ACPI_DEVICE_NOTIFY
,
2324 .name
= "bluetooth",
2325 .init
= bluetooth_init
,
2326 .read
= bluetooth_read
,
2327 .write
= bluetooth_write
,
2340 .write
= video_write
,
2347 .write
= light_write
,
2349 #ifdef CONFIG_ACPI_IBM_DOCK
2353 .write
= dock_write
,
2354 .notify
= dock_notify
,
2355 .handle
= &dock_handle
,
2356 .type
= ACPI_SYSTEM_NOTIFY
,
2361 .notify
= dock_notify
,
2362 .handle
= &pci_handle
,
2363 .type
= ACPI_SYSTEM_NOTIFY
,
2366 #ifdef CONFIG_ACPI_IBM_BAY
2372 .notify
= bay_notify
,
2373 .handle
= &bay_handle
,
2374 .type
= ACPI_SYSTEM_NOTIFY
,
2380 .write
= cmos_write
,
2391 .write
= beep_write
,
2395 .init
= thermal_init
,
2396 .read
= thermal_read
,
2400 .read
= ecdump_read
,
2401 .write
= ecdump_write
,
2405 .name
= "brightness",
2406 .read
= brightness_read
,
2407 .write
= brightness_write
,
2408 .init
= brightness_init
,
2409 .exit
= brightness_exit
,
2413 .read
= volume_read
,
2414 .write
= volume_write
,
2426 static int dispatch_read(char *page
, char **start
, off_t off
, int count
,
2427 int *eof
, void *data
)
2429 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
2432 if (!ibm
|| !ibm
->read
)
2435 len
= ibm
->read(page
);
2439 if (len
<= off
+ count
)
2441 *start
= page
+ off
;
2451 static int dispatch_write(struct file
*file
, const char __user
* userbuf
,
2452 unsigned long count
, void *data
)
2454 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
2458 if (!ibm
|| !ibm
->write
)
2461 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
2465 if (copy_from_user(kernbuf
, userbuf
, count
)) {
2471 strcat(kernbuf
, ",");
2472 ret
= ibm
->write(kernbuf
);
2481 static void dispatch_notify(acpi_handle handle
, u32 event
, void *data
)
2483 struct ibm_struct
*ibm
= (struct ibm_struct
*)data
;
2485 if (!ibm
|| !ibm
->notify
)
2488 ibm
->notify(ibm
, event
);
2491 static int __init
setup_notify(struct ibm_struct
*ibm
)
2499 ret
= acpi_bus_get_device(*ibm
->handle
, &ibm
->device
);
2501 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
2505 acpi_driver_data(ibm
->device
) = ibm
;
2506 sprintf(acpi_device_class(ibm
->device
), "%s/%s", IBM_NAME
, ibm
->name
);
2508 status
= acpi_install_notify_handler(*ibm
->handle
, ibm
->type
,
2509 dispatch_notify
, ibm
);
2510 if (ACPI_FAILURE(status
)) {
2511 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
2519 static int __init
ibm_device_add(struct acpi_device
*device
)
2524 static int __init
register_driver(struct ibm_struct
*ibm
)
2528 ibm
->driver
= kmalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
2530 printk(IBM_ERR
"kmalloc(ibm->driver) failed\n");
2534 memset(ibm
->driver
, 0, sizeof(struct acpi_driver
));
2535 sprintf(ibm
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
2536 ibm
->driver
->ids
= ibm
->hid
;
2537 ibm
->driver
->ops
.add
= &ibm_device_add
;
2539 ret
= acpi_bus_register_driver(ibm
->driver
);
2541 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
2549 static int __init
ibm_init(struct ibm_struct
*ibm
)
2552 struct proc_dir_entry
*entry
;
2554 if (ibm
->experimental
&& !experimental
)
2558 ret
= register_driver(ibm
);
2561 ibm
->driver_registered
= 1;
2568 ibm
->init_called
= 1;
2572 entry
= create_proc_entry(ibm
->name
,
2573 S_IFREG
| S_IRUGO
| S_IWUSR
,
2576 printk(IBM_ERR
"unable to create proc entry %s\n",
2580 entry
->owner
= THIS_MODULE
;
2582 entry
->read_proc
= &dispatch_read
;
2584 entry
->write_proc
= &dispatch_write
;
2585 ibm
->proc_created
= 1;
2589 ret
= setup_notify(ibm
);
2592 ibm
->notify_installed
= 1;
2598 static void ibm_exit(struct ibm_struct
*ibm
)
2600 if (ibm
->notify_installed
)
2601 acpi_remove_notify_handler(*ibm
->handle
, ibm
->type
,
2604 if (ibm
->proc_created
)
2605 remove_proc_entry(ibm
->name
, proc_dir
);
2607 if (ibm
->init_called
&& ibm
->exit
)
2610 if (ibm
->driver_registered
) {
2611 acpi_bus_unregister_driver(ibm
->driver
);
2616 static void __init
ibm_handle_init(char *name
,
2617 acpi_handle
* handle
, acpi_handle parent
,
2618 char **paths
, int num_paths
, char **path
)
2623 for (i
= 0; i
< num_paths
; i
++) {
2624 status
= acpi_get_handle(parent
, paths
[i
], handle
);
2625 if (ACPI_SUCCESS(status
)) {
2634 #define IBM_HANDLE_INIT(object) \
2635 ibm_handle_init(#object, &object##_handle, *object##_parent, \
2636 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
2638 static int set_ibm_param(const char *val
, struct kernel_param
*kp
)
2642 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++)
2643 if (strcmp(ibms
[i
].name
, kp
->name
) == 0 && ibms
[i
].write
) {
2644 if (strlen(val
) > sizeof(ibms
[i
].param
) - 2)
2646 strcpy(ibms
[i
].param
, val
);
2647 strcat(ibms
[i
].param
, ",");
2654 #define IBM_PARAM(feature) \
2655 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
2658 IBM_PARAM(bluetooth
);
2661 #ifdef CONFIG_ACPI_IBM_DOCK
2664 #ifdef CONFIG_ACPI_IBM_BAY
2671 IBM_PARAM(brightness
);
2675 static void acpi_ibm_exit(void)
2679 for (i
= ARRAY_SIZE(ibms
) - 1; i
>= 0; i
--)
2682 remove_proc_entry(IBM_DIR
, acpi_root_dir
);
2684 if (ibm_thinkpad_ec_found
)
2685 kfree(ibm_thinkpad_ec_found
);
2688 static char* __init
check_dmi_for_ec(void)
2690 struct dmi_device
*dev
= NULL
;
2691 char ec_fw_string
[18];
2694 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2695 * X32 or newer, all Z series; Some models must have an
2696 * up-to-date BIOS or they will not be detected.
2698 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2700 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
2701 if (sscanf(dev
->name
,
2702 "IBM ThinkPad Embedded Controller -[%17c",
2703 ec_fw_string
) == 1) {
2704 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
2705 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
2706 return kstrdup(ec_fw_string
, GFP_KERNEL
);
2712 static int __init
acpi_ibm_init(void)
2719 if (!acpi_specific_hotkey_enabled
) {
2720 printk(IBM_ERR
"using generic hotkey driver\n");
2724 /* ec is required because many other handles are relative to it */
2725 IBM_HANDLE_INIT(ec
);
2727 printk(IBM_ERR
"ec object not found\n");
2731 /* Models with newer firmware report the EC in DMI */
2732 ibm_thinkpad_ec_found
= check_dmi_for_ec();
2733 if (ibm_thinkpad_ec_found
)
2734 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
2735 ibm_thinkpad_ec_found
);
2737 /* these handles are not required */
2738 IBM_HANDLE_INIT(vid
);
2739 IBM_HANDLE_INIT(vid2
);
2740 IBM_HANDLE_INIT(ledb
);
2741 IBM_HANDLE_INIT(led
);
2742 IBM_HANDLE_INIT(hkey
);
2743 IBM_HANDLE_INIT(lght
);
2744 IBM_HANDLE_INIT(cmos
);
2745 #ifdef CONFIG_ACPI_IBM_DOCK
2746 IBM_HANDLE_INIT(dock
);
2748 IBM_HANDLE_INIT(pci
);
2749 #ifdef CONFIG_ACPI_IBM_BAY
2750 IBM_HANDLE_INIT(bay
);
2752 IBM_HANDLE_INIT(bay_ej
);
2753 IBM_HANDLE_INIT(bay2
);
2755 IBM_HANDLE_INIT(bay2_ej
);
2757 IBM_HANDLE_INIT(beep
);
2758 IBM_HANDLE_INIT(ecrd
);
2759 IBM_HANDLE_INIT(ecwr
);
2760 IBM_HANDLE_INIT(fans
);
2761 IBM_HANDLE_INIT(gfan
);
2762 IBM_HANDLE_INIT(sfan
);
2764 proc_dir
= proc_mkdir(IBM_DIR
, acpi_root_dir
);
2766 printk(IBM_ERR
"unable to create proc dir %s", IBM_DIR
);
2769 proc_dir
->owner
= THIS_MODULE
;
2771 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++) {
2772 ret
= ibm_init(&ibms
[i
]);
2773 if (ret
>= 0 && *ibms
[i
].param
)
2774 ret
= ibms
[i
].write(ibms
[i
].param
);
2784 module_init(acpi_ibm_init
);
2785 module_exit(acpi_ibm_exit
);