2 * ibm_acpi.c - IBM ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #define IBM_VERSION "0.13"
28 * 2006-11-22 0.13 new maintainer
29 * changelog now lives in git commit history, and will
30 * not be updated further in-file.
32 * 2005-08-17 0.12 fix compilation on 2.6.13-rc kernels
33 * 2005-03-17 0.11 support for 600e, 770x
34 * thanks to Jamie Lentin <lentinj@dial.pipex.com>
35 * support for 770e, G41
36 * G40 and G41 don't have a thinklight
37 * temperatures no longer experimental
38 * experimental brightness control
39 * experimental volume control
40 * experimental fan enable/disable
41 * 2005-01-16 0.10 fix module loading on R30, R31
42 * 2005-01-16 0.9 support for 570, R30, R31
43 * ultrabay support on A22p, A3x
44 * limit arg for cmos, led, beep, drop experimental status
45 * more capable led control on A21e, A22p, T20-22, X20
46 * experimental temperatures and fan speed
47 * experimental embedded controller register dump
48 * mark more functions as __init, drop incorrect __exit
50 * thanks to Henrik Brix Andersen <brix@gentoo.org>
51 * fix parameter passing on module loading
52 * thanks to Rusty Russell <rusty@rustcorp.com.au>
53 * thanks to Jim Radford <radford@blackbean.org>
54 * 2004-11-08 0.8 fix init error case, don't return from a macro
55 * thanks to Chris Wright <chrisw@osdl.org>
56 * 2004-10-23 0.7 fix module loading on A21e, A22p, T20, T21, X20
57 * fix led control on A21e
58 * 2004-10-19 0.6 use acpi_bus_register_driver() to claim HKEY device
59 * 2004-10-18 0.5 thinklight support on A21e, G40, R32, T20, T21, X20
60 * proc file format changed
61 * video_switch command
62 * experimental cmos control
63 * experimental led control
64 * experimental acpi sounds
65 * 2004-09-16 0.4 support for module parameters
66 * hotkey mask can be prefixed by 0x
67 * video output switching
68 * video expansion control
69 * ultrabay eject support
70 * removed lcd brightness/on/off control, didn't work
71 * 2004-08-17 0.3 support for R40
72 * lcd off, brightness control
74 * 2004-08-14 0.2 support for T series, X20
75 * bluetooth enable/disable
76 * hotkey events disabled by default
77 * removed fan control, currently useless
78 * 2004-08-09 0.1 initial release, support for X series
81 #include <linux/kernel.h>
82 #include <linux/module.h>
83 #include <linux/init.h>
84 #include <linux/types.h>
85 #include <linux/string.h>
87 #include <linux/proc_fs.h>
88 #include <linux/backlight.h>
89 #include <asm/uaccess.h>
91 #include <linux/dmi.h>
92 #include <linux/jiffies.h>
93 #include <linux/workqueue.h>
95 #include <acpi/acpi_drivers.h>
96 #include <acpi/acnamesp.h>
98 #define IBM_NAME "ibm"
99 #define IBM_DESC "IBM ThinkPad ACPI Extras"
100 #define IBM_FILE "ibm_acpi"
101 #define IBM_URL "http://ibm-acpi.sf.net/"
103 MODULE_AUTHOR("Borislav Deianov, Henrique de Moraes Holschuh");
104 MODULE_DESCRIPTION(IBM_DESC
);
105 MODULE_VERSION(IBM_VERSION
);
106 MODULE_LICENSE("GPL");
108 #define IBM_DIR IBM_NAME
110 #define IBM_LOG IBM_FILE ": "
111 #define IBM_ERR KERN_ERR IBM_LOG
112 #define IBM_NOTICE KERN_NOTICE IBM_LOG
113 #define IBM_INFO KERN_INFO IBM_LOG
114 #define IBM_DEBUG KERN_DEBUG IBM_LOG
116 #define IBM_MAX_ACPI_ARGS 3
118 #define __unused __attribute__ ((unused))
120 static int experimental
;
121 module_param(experimental
, int, 0);
123 static acpi_handle root_handle
= NULL
;
125 #define IBM_HANDLE(object, parent, paths...) \
126 static acpi_handle object##_handle; \
127 static acpi_handle *object##_parent = &parent##_handle; \
128 static char *object##_path; \
129 static char *object##_paths[] = { paths }
131 IBM_HANDLE(ec
, root
, "\\_SB.PCI0.ISA.EC0", /* 240, 240x */
132 "\\_SB.PCI.ISA.EC", /* 570 */
133 "\\_SB.PCI0.ISA0.EC0", /* 600e/x, 770e, 770x */
134 "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */
135 "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */
136 "\\_SB.PCI0.ICH3.EC0", /* R31 */
137 "\\_SB.PCI0.LPC.EC", /* all others */
140 IBM_HANDLE(vid
, root
, "\\_SB.PCI.AGP.VGA", /* 570 */
141 "\\_SB.PCI0.AGP0.VID0", /* 600e/x, 770x */
142 "\\_SB.PCI0.VID0", /* 770e */
143 "\\_SB.PCI0.VID", /* A21e, G4x, R50e, X30, X40 */
144 "\\_SB.PCI0.AGP.VID", /* all others */
147 IBM_HANDLE(vid2
, root
, "\\_SB.PCI0.AGPB.VID"); /* G41 */
149 IBM_HANDLE(cmos
, root
, "\\UCMS", /* R50, R50e, R50p, R51, T4x, X31, X40 */
150 "\\CMOS", /* A3x, G4x, R32, T23, T30, X22-24, X30 */
151 "\\CMS", /* R40, R40e */
153 #ifdef CONFIG_ACPI_IBM_DOCK
154 IBM_HANDLE(dock
, root
, "\\_SB.GDCK", /* X30, X31, X40 */
155 "\\_SB.PCI0.DOCK", /* 600e/x,770e,770x,A2xm/p,T20-22,X20-21 */
156 "\\_SB.PCI0.PCI1.DOCK", /* all others */
157 "\\_SB.PCI.ISA.SLCE", /* 570 */
158 ); /* A21e,G4x,R30,R31,R32,R40,R40e,R50e */
160 #ifdef CONFIG_ACPI_IBM_BAY
161 IBM_HANDLE(bay
, root
, "\\_SB.PCI.IDE.SECN.MAST", /* 570 */
162 "\\_SB.PCI0.IDE0.IDES.IDSM", /* 600e/x, 770e, 770x */
163 "\\_SB.PCI0.SATA.SCND.MSTR", /* T60, X60, Z60 */
164 "\\_SB.PCI0.IDE0.SCND.MSTR", /* all others */
165 ); /* A21e, R30, R31 */
167 IBM_HANDLE(bay_ej
, bay
, "_EJ3", /* 600e/x, A2xm/p, A3x */
168 "_EJ0", /* all others */
169 ); /* 570,A21e,G4x,R30,R31,R32,R40e,R50e */
171 IBM_HANDLE(bay2
, root
, "\\_SB.PCI0.IDE0.PRIM.SLAV", /* A3x, R32 */
172 "\\_SB.PCI0.IDE0.IDEP.IDPS", /* 600e/x, 770e, 770x */
175 IBM_HANDLE(bay2_ej
, bay2
, "_EJ3", /* 600e/x, 770e, A3x */
178 #endif /* CONFIG_ACPI_IBM_BAY */
180 /* don't list other alternatives as we install a notify handler on the 570 */
181 IBM_HANDLE(pci
, root
, "\\_SB.PCI"); /* 570 */
183 IBM_HANDLE(hkey
, ec
, "\\_SB.HKEY", /* 600e/x, 770e, 770x */
184 "^HKEY", /* R30, R31 */
185 "HKEY", /* all others */
188 IBM_HANDLE(lght
, root
, "\\LGHT"); /* A21e, A2xm/p, T20-22, X20-21 */
189 IBM_HANDLE(ledb
, ec
, "LEDB"); /* G4x */
191 IBM_HANDLE(led
, ec
, "SLED", /* 570 */
192 "SYSL", /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
193 "LED", /* all others */
196 IBM_HANDLE(beep
, ec
, "BEEP"); /* all except R30, R31 */
197 IBM_HANDLE(ecrd
, ec
, "ECRD"); /* 570 */
198 IBM_HANDLE(ecwr
, ec
, "ECWR"); /* 570 */
199 IBM_HANDLE(fans
, ec
, "FANS"); /* X31, X40, X41 */
201 IBM_HANDLE(gfan
, ec
, "GFAN", /* 570 */
202 "\\FSPD", /* 600e/x, 770e, 770x */
205 IBM_HANDLE(sfan
, ec
, "SFAN", /* 570 */
206 "JFNS", /* 770x-JL */
209 #define IBM_HKEY_HID "IBM0068"
210 #define IBM_PCI_HID "PNP0A03"
212 enum thermal_access_mode
{
213 IBMACPI_THERMAL_NONE
= 0, /* No thermal support */
214 IBMACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
215 IBMACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
216 IBMACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
217 IBMACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
220 #define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
221 struct ibm_thermal_sensors_struct
{
222 s32 temp
[IBMACPI_MAX_THERMAL_SENSORS
];
228 * IBMACPI_FAN_RD_ACPI_GFAN:
229 * ACPI GFAN method: returns fan level
231 * see IBMACPI_FAN_WR_ACPI_SFAN
232 * EC 0x2f not available if GFAN exists
234 * IBMACPI_FAN_WR_ACPI_SFAN:
235 * ACPI SFAN method: sets fan level, 0 (stop) to 7 (max)
237 * EC 0x2f might be available *for reading*, but never for writing.
239 * IBMACPI_FAN_WR_TPEC:
240 * ThinkPad EC register 0x2f (HFSP): fan control loop mode Supported
241 * on almost all ThinkPads
243 * Fan speed changes of any sort (including those caused by the
244 * disengaged mode) are usually done slowly by the firmware as the
245 * maximum ammount of fan duty cycle change per second seems to be
248 * Reading is not available if GFAN exists.
249 * Writing is not available if SFAN exists.
252 * 7 automatic mode engaged;
253 * (default operation mode of the ThinkPad)
254 * fan level is ignored in this mode.
255 * 6 disengage mode (takes precedence over bit 7);
256 * not available on all thinkpads. May disable
257 * the tachometer, and speeds up fan to 100% duty-cycle,
258 * which speeds it up far above the standard RPM
259 * levels. It is not impossible that it could cause
261 * 5-3 unused in some models. Extra bits for fan level
262 * in others, but still useless as all values above
263 * 7 map to the same speed as level 7 in these models.
264 * 2-0 fan level (0..7 usually)
266 * 0x07 = max (set when temperatures critical)
267 * Some ThinkPads may have other levels, see
268 * IBMACPI_FAN_WR_ACPI_FANS (X31/X40/X41)
270 * FIRMWARE BUG: on some models, EC 0x2f might not be initialized at
271 * boot. Apparently the EC does not intialize it, so unless ACPI DSDT
272 * does so, its initial value is meaningless (0x07).
274 * For firmware bugs, refer to:
275 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
279 * ThinkPad EC register 0x84 (LSB), 0x85 (MSB):
280 * Main fan tachometer reading (in RPM)
282 * This register is present on all ThinkPads with a new-style EC, and
283 * it is known not to be present on the A21m/e, and T22, as there is
284 * something else in offset 0x84 according to the ACPI DSDT. Other
285 * ThinkPads from this same time period (and earlier) probably lack the
286 * tachometer as well.
288 * Unfortunately a lot of ThinkPads with new-style ECs but whose firwmare
289 * was never fixed by IBM to report the EC firmware version string
290 * probably support the tachometer (like the early X models), so
291 * detecting it is quite hard. We need more data to know for sure.
293 * FIRMWARE BUG: always read 0x84 first, otherwise incorrect readings
296 * FIRMWARE BUG: when EC 0x2f bit 6 is set (disengaged mode), this
297 * register is not invalidated in ThinkPads that disable tachometer
298 * readings. Thus, the tachometer readings go stale.
300 * For firmware bugs, refer to:
301 * http://thinkwiki.org/wiki/Embedded_Controller_Firmware#Firmware_Issues
303 * IBMACPI_FAN_WR_ACPI_FANS:
304 * ThinkPad X31, X40, X41. Not available in the X60.
306 * FANS ACPI handle: takes three arguments: low speed, medium speed,
307 * high speed. ACPI DSDT seems to map these three speeds to levels
308 * as follows: STOP LOW LOW MED MED HIGH HIGH HIGH HIGH
309 * (this map is stored on FAN0..FAN8 as "0,1,1,2,2,3,3,3,3")
311 * The speeds are stored on handles
312 * (FANA:FAN9), (FANC:FANB), (FANE:FAND).
314 * There are three default speed sets, acessible as handles:
315 * FS1L,FS1M,FS1H; FS2L,FS2M,FS2H; FS3L,FS3M,FS3H
317 * ACPI DSDT switches which set is in use depending on various
320 * IBMACPI_FAN_WR_TPEC is also available and should be used to
321 * command the fan. The X31/X40/X41 seems to have 8 fan levels,
322 * but the ACPI tables just mention level 7.
325 enum fan_status_access_mode
{
326 IBMACPI_FAN_NONE
= 0, /* No fan status or control */
327 IBMACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
328 IBMACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
331 enum fan_control_access_mode
{
332 IBMACPI_FAN_WR_NONE
= 0, /* No fan control */
333 IBMACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
334 IBMACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
335 IBMACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
338 enum fan_control_commands
{
339 IBMACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
340 IBMACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
341 IBMACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
342 * and also watchdog cmd */
345 enum { /* Fan control constants */
346 fan_status_offset
= 0x2f, /* EC register 0x2f */
347 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
348 * 0x84 must be read before 0x85 */
350 IBMACPI_FAN_EC_DISENGAGED
= 0x40, /* EC mode: tachometer
352 IBMACPI_FAN_EC_AUTO
= 0x80, /* EC mode: auto fan
356 static char *ibm_thinkpad_ec_found
= NULL
;
363 struct acpi_driver
*driver
;
366 int (*read
) (char *);
367 int (*write
) (char *);
370 void (*notify
) (struct ibm_struct
*, u32
);
373 struct acpi_device
*device
;
375 int driver_registered
;
378 int notify_installed
;
383 static struct proc_dir_entry
*proc_dir
= NULL
;
385 static struct backlight_device
*ibm_backlight_device
= NULL
;
387 #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
388 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
389 #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
391 static int acpi_evalf(acpi_handle handle
,
392 void *res
, char *method
, char *fmt
, ...)
395 struct acpi_object_list params
;
396 union acpi_object in_objs
[IBM_MAX_ACPI_ARGS
];
397 struct acpi_buffer result
, *resultp
;
398 union acpi_object out_obj
;
406 printk(IBM_ERR
"acpi_evalf() called with empty format\n");
419 params
.pointer
= &in_objs
[0];
426 in_objs
[params
.count
].integer
.value
= va_arg(ap
, int);
427 in_objs
[params
.count
++].type
= ACPI_TYPE_INTEGER
;
429 /* add more types as needed */
431 printk(IBM_ERR
"acpi_evalf() called "
432 "with invalid format character '%c'\n", c
);
438 if (res_type
!= 'v') {
439 result
.length
= sizeof(out_obj
);
440 result
.pointer
= &out_obj
;
445 status
= acpi_evaluate_object(handle
, method
, ¶ms
, resultp
);
450 *(int *)res
= out_obj
.integer
.value
;
451 success
= status
== AE_OK
&& out_obj
.type
== ACPI_TYPE_INTEGER
;
454 success
= status
== AE_OK
;
456 /* add more types as needed */
458 printk(IBM_ERR
"acpi_evalf() called "
459 "with invalid format character '%c'\n", res_type
);
463 if (!success
&& !quiet
)
464 printk(IBM_ERR
"acpi_evalf(%s, %s, ...) failed: %d\n",
465 method
, fmt0
, status
);
470 static void __unused
acpi_print_int(acpi_handle handle
, char *method
)
474 if (acpi_evalf(handle
, &i
, method
, "d"))
475 printk(IBM_INFO
"%s = 0x%x\n", method
, i
);
477 printk(IBM_ERR
"error calling %s\n", method
);
480 static char *next_cmd(char **cmds
)
485 while ((end
= strchr(start
, ',')) && end
== start
)
496 static int ibm_acpi_driver_init(void)
498 printk(IBM_INFO
"%s v%s\n", IBM_DESC
, IBM_VERSION
);
499 printk(IBM_INFO
"%s\n", IBM_URL
);
501 if (ibm_thinkpad_ec_found
)
502 printk(IBM_INFO
"ThinkPad EC firmware %s\n",
503 ibm_thinkpad_ec_found
);
508 static int driver_read(char *p
)
512 len
+= sprintf(p
+ len
, "driver:\t\t%s\n", IBM_DESC
);
513 len
+= sprintf(p
+ len
, "version:\t%s\n", IBM_VERSION
);
518 static int hotkey_supported
;
519 static int hotkey_mask_supported
;
520 static int hotkey_orig_status
;
521 static int hotkey_orig_mask
;
523 static int hotkey_get(int *status
, int *mask
)
525 if (!acpi_evalf(hkey_handle
, status
, "DHKC", "d"))
528 if (hotkey_mask_supported
)
529 if (!acpi_evalf(hkey_handle
, mask
, "DHKN", "d"))
535 static int hotkey_set(int status
, int mask
)
539 if (!acpi_evalf(hkey_handle
, NULL
, "MHKC", "vd", status
))
542 if (hotkey_mask_supported
)
543 for (i
= 0; i
< 32; i
++) {
544 int bit
= ((1 << i
) & mask
) != 0;
545 if (!acpi_evalf(hkey_handle
,
546 NULL
, "MHKM", "vdd", i
+ 1, bit
))
553 static int hotkey_init(void)
555 /* hotkey not supported on 570 */
556 hotkey_supported
= hkey_handle
!= NULL
;
558 if (hotkey_supported
) {
559 /* mask not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
560 A30, R30, R31, T20-22, X20-21, X22-24 */
561 hotkey_mask_supported
=
562 acpi_evalf(hkey_handle
, NULL
, "DHKN", "qv");
564 if (!hotkey_get(&hotkey_orig_status
, &hotkey_orig_mask
))
571 static int hotkey_read(char *p
)
576 if (!hotkey_supported
) {
577 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
581 if (!hotkey_get(&status
, &mask
))
584 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 0));
585 if (hotkey_mask_supported
) {
586 len
+= sprintf(p
+ len
, "mask:\t\t0x%04x\n", mask
);
587 len
+= sprintf(p
+ len
,
588 "commands:\tenable, disable, reset, <mask>\n");
590 len
+= sprintf(p
+ len
, "mask:\t\tnot supported\n");
591 len
+= sprintf(p
+ len
, "commands:\tenable, disable, reset\n");
597 static int hotkey_write(char *buf
)
603 if (!hotkey_supported
)
606 if (!hotkey_get(&status
, &mask
))
609 while ((cmd
= next_cmd(&buf
))) {
610 if (strlencmp(cmd
, "enable") == 0) {
612 } else if (strlencmp(cmd
, "disable") == 0) {
614 } else if (strlencmp(cmd
, "reset") == 0) {
615 status
= hotkey_orig_status
;
616 mask
= hotkey_orig_mask
;
617 } else if (sscanf(cmd
, "0x%x", &mask
) == 1) {
619 } else if (sscanf(cmd
, "%x", &mask
) == 1) {
626 if (do_cmd
&& !hotkey_set(status
, mask
))
632 static void hotkey_exit(void)
634 if (hotkey_supported
)
635 hotkey_set(hotkey_orig_status
, hotkey_orig_mask
);
638 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
)
642 if (acpi_evalf(hkey_handle
, &hkey
, "MHKP", "d"))
643 acpi_bus_generate_event(ibm
->device
, event
, hkey
);
645 printk(IBM_ERR
"unknown hotkey event %d\n", event
);
646 acpi_bus_generate_event(ibm
->device
, event
, 0);
650 static int bluetooth_supported
;
652 static int bluetooth_init(void)
654 /* bluetooth not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
655 G4x, R30, R31, R40e, R50e, T20-22, X20-21 */
656 bluetooth_supported
= hkey_handle
&&
657 acpi_evalf(hkey_handle
, NULL
, "GBDC", "qv");
662 static int bluetooth_status(void)
666 if (!bluetooth_supported
||
667 !acpi_evalf(hkey_handle
, &status
, "GBDC", "d"))
673 static int bluetooth_read(char *p
)
676 int status
= bluetooth_status();
678 if (!bluetooth_supported
)
679 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
680 else if (!(status
& 1))
681 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
683 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
684 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
690 static int bluetooth_write(char *buf
)
692 int status
= bluetooth_status();
696 if (!bluetooth_supported
)
699 while ((cmd
= next_cmd(&buf
))) {
700 if (strlencmp(cmd
, "enable") == 0) {
702 } else if (strlencmp(cmd
, "disable") == 0) {
709 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SBDC", "vd", status
))
715 static int wan_supported
;
717 static int wan_init(void)
719 wan_supported
= hkey_handle
&&
720 acpi_evalf(hkey_handle
, NULL
, "GWAN", "qv");
725 static int wan_status(void)
729 if (!wan_supported
|| !acpi_evalf(hkey_handle
, &status
, "GWAN", "d"))
735 static int wan_read(char *p
)
738 int status
= wan_status();
741 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
742 else if (!(status
& 1))
743 len
+= sprintf(p
+ len
, "status:\t\tnot installed\n");
745 len
+= sprintf(p
+ len
, "status:\t\t%s\n", enabled(status
, 1));
746 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n");
752 static int wan_write(char *buf
)
754 int status
= wan_status();
761 while ((cmd
= next_cmd(&buf
))) {
762 if (strlencmp(cmd
, "enable") == 0) {
764 } else if (strlencmp(cmd
, "disable") == 0) {
771 if (do_cmd
&& !acpi_evalf(hkey_handle
, NULL
, "SWAN", "vd", status
))
777 enum video_access_mode
{
778 IBMACPI_VIDEO_NONE
= 0,
779 IBMACPI_VIDEO_570
, /* 570 */
780 IBMACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
781 IBMACPI_VIDEO_NEW
, /* all others */
784 static enum video_access_mode video_supported
;
785 static int video_orig_autosw
;
787 static int video_init(void)
791 if (vid2_handle
&& acpi_evalf(NULL
, &ivga
, "\\IVGA", "d") && ivga
)
792 /* G41, assume IVGA doesn't change */
793 vid_handle
= vid2_handle
;
796 /* video switching not supported on R30, R31 */
797 video_supported
= IBMACPI_VIDEO_NONE
;
798 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "SWIT", "qd"))
800 video_supported
= IBMACPI_VIDEO_570
;
801 else if (acpi_evalf(vid_handle
, &video_orig_autosw
, "^VADL", "qd"))
802 /* 600e/x, 770e, 770x */
803 video_supported
= IBMACPI_VIDEO_770
;
806 video_supported
= IBMACPI_VIDEO_NEW
;
811 static int video_status(void)
816 if (video_supported
== IBMACPI_VIDEO_570
) {
817 if (acpi_evalf(NULL
, &i
, "\\_SB.PHS", "dd", 0x87))
819 } else if (video_supported
== IBMACPI_VIDEO_770
) {
820 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
822 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
824 } else if (video_supported
== IBMACPI_VIDEO_NEW
) {
825 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 1);
826 if (acpi_evalf(NULL
, &i
, "\\VCDC", "d"))
829 acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0);
830 if (acpi_evalf(NULL
, &i
, "\\VCDL", "d"))
832 if (acpi_evalf(NULL
, &i
, "\\VCDD", "d"))
839 static int video_autosw(void)
843 if (video_supported
== IBMACPI_VIDEO_570
)
844 acpi_evalf(vid_handle
, &autosw
, "SWIT", "d");
845 else if (video_supported
== IBMACPI_VIDEO_770
||
846 video_supported
== IBMACPI_VIDEO_NEW
)
847 acpi_evalf(vid_handle
, &autosw
, "^VDEE", "d");
852 static int video_read(char *p
)
854 int status
= video_status();
855 int autosw
= video_autosw();
858 if (!video_supported
) {
859 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
863 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
864 len
+= sprintf(p
+ len
, "lcd:\t\t%s\n", enabled(status
, 0));
865 len
+= sprintf(p
+ len
, "crt:\t\t%s\n", enabled(status
, 1));
866 if (video_supported
== IBMACPI_VIDEO_NEW
)
867 len
+= sprintf(p
+ len
, "dvi:\t\t%s\n", enabled(status
, 3));
868 len
+= sprintf(p
+ len
, "auto:\t\t%s\n", enabled(autosw
, 0));
869 len
+= sprintf(p
+ len
, "commands:\tlcd_enable, lcd_disable\n");
870 len
+= sprintf(p
+ len
, "commands:\tcrt_enable, crt_disable\n");
871 if (video_supported
== IBMACPI_VIDEO_NEW
)
872 len
+= sprintf(p
+ len
, "commands:\tdvi_enable, dvi_disable\n");
873 len
+= sprintf(p
+ len
, "commands:\tauto_enable, auto_disable\n");
874 len
+= sprintf(p
+ len
, "commands:\tvideo_switch, expand_toggle\n");
879 static int video_switch(void)
881 int autosw
= video_autosw();
884 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
886 ret
= video_supported
== IBMACPI_VIDEO_570
?
887 acpi_evalf(ec_handle
, NULL
, "_Q16", "v") :
888 acpi_evalf(vid_handle
, NULL
, "VSWT", "v");
889 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
894 static int video_expand(void)
896 if (video_supported
== IBMACPI_VIDEO_570
)
897 return acpi_evalf(ec_handle
, NULL
, "_Q17", "v");
898 else if (video_supported
== IBMACPI_VIDEO_770
)
899 return acpi_evalf(vid_handle
, NULL
, "VEXP", "v");
901 return acpi_evalf(NULL
, NULL
, "\\VEXP", "v");
904 static int video_switch2(int status
)
908 if (video_supported
== IBMACPI_VIDEO_570
) {
909 ret
= acpi_evalf(NULL
, NULL
,
910 "\\_SB.PHS2", "vdd", 0x8b, status
| 0x80);
911 } else if (video_supported
== IBMACPI_VIDEO_770
) {
912 int autosw
= video_autosw();
913 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
916 ret
= acpi_evalf(vid_handle
, NULL
,
917 "ASWT", "vdd", status
* 0x100, 0);
919 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", autosw
);
921 ret
= acpi_evalf(NULL
, NULL
, "\\VUPS", "vd", 0x80) &&
922 acpi_evalf(NULL
, NULL
, "\\VSDS", "vdd", status
, 1);
928 static int video_write(char *buf
)
931 int enable
, disable
, status
;
933 if (!video_supported
)
936 enable
= disable
= 0;
938 while ((cmd
= next_cmd(&buf
))) {
939 if (strlencmp(cmd
, "lcd_enable") == 0) {
941 } else if (strlencmp(cmd
, "lcd_disable") == 0) {
943 } else if (strlencmp(cmd
, "crt_enable") == 0) {
945 } else if (strlencmp(cmd
, "crt_disable") == 0) {
947 } else if (video_supported
== IBMACPI_VIDEO_NEW
&&
948 strlencmp(cmd
, "dvi_enable") == 0) {
950 } else if (video_supported
== IBMACPI_VIDEO_NEW
&&
951 strlencmp(cmd
, "dvi_disable") == 0) {
953 } else if (strlencmp(cmd
, "auto_enable") == 0) {
954 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 1))
956 } else if (strlencmp(cmd
, "auto_disable") == 0) {
957 if (!acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", 0))
959 } else if (strlencmp(cmd
, "video_switch") == 0) {
962 } else if (strlencmp(cmd
, "expand_toggle") == 0) {
969 if (enable
|| disable
) {
970 status
= (video_status() & 0x0f & ~disable
) | enable
;
971 if (!video_switch2(status
))
978 static void video_exit(void)
980 acpi_evalf(vid_handle
, NULL
, "_DOS", "vd", video_orig_autosw
);
983 static int light_supported
;
984 static int light_status_supported
;
986 static int light_init(void)
988 /* light not supported on 570, 600e/x, 770e, 770x, G4x, R30, R31 */
989 light_supported
= (cmos_handle
|| lght_handle
) && !ledb_handle
;
992 /* light status not supported on
993 570, 600e/x, 770e, 770x, G4x, R30, R31, R32, X20 */
994 light_status_supported
= acpi_evalf(ec_handle
, NULL
,
1000 static int light_read(char *p
)
1005 if (!light_supported
) {
1006 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1007 } else if (!light_status_supported
) {
1008 len
+= sprintf(p
+ len
, "status:\t\tunknown\n");
1009 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1011 if (!acpi_evalf(ec_handle
, &status
, "KBLT", "d"))
1013 len
+= sprintf(p
+ len
, "status:\t\t%s\n", onoff(status
, 0));
1014 len
+= sprintf(p
+ len
, "commands:\ton, off\n");
1020 static int light_write(char *buf
)
1022 int cmos_cmd
, lght_cmd
;
1026 if (!light_supported
)
1029 while ((cmd
= next_cmd(&buf
))) {
1030 if (strlencmp(cmd
, "on") == 0) {
1033 } else if (strlencmp(cmd
, "off") == 0) {
1039 success
= cmos_handle
?
1040 acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
) :
1041 acpi_evalf(lght_handle
, NULL
, NULL
, "vd", lght_cmd
);
1049 #if defined(CONFIG_ACPI_IBM_DOCK) || defined(CONFIG_ACPI_IBM_BAY)
1050 static int _sta(acpi_handle handle
)
1054 if (!handle
|| !acpi_evalf(handle
, &status
, "_STA", "d"))
1061 #ifdef CONFIG_ACPI_IBM_DOCK
1062 #define dock_docked() (_sta(dock_handle) & 1)
1064 static int dock_read(char *p
)
1067 int docked
= dock_docked();
1070 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1072 len
+= sprintf(p
+ len
, "status:\t\tundocked\n");
1074 len
+= sprintf(p
+ len
, "status:\t\tdocked\n");
1075 len
+= sprintf(p
+ len
, "commands:\tdock, undock\n");
1081 static int dock_write(char *buf
)
1088 while ((cmd
= next_cmd(&buf
))) {
1089 if (strlencmp(cmd
, "undock") == 0) {
1090 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 0) ||
1091 !acpi_evalf(dock_handle
, NULL
, "_EJ0", "vd", 1))
1093 } else if (strlencmp(cmd
, "dock") == 0) {
1094 if (!acpi_evalf(dock_handle
, NULL
, "_DCK", "vd", 1))
1103 static void dock_notify(struct ibm_struct
*ibm
, u32 event
)
1105 int docked
= dock_docked();
1106 int pci
= ibm
->hid
&& strstr(ibm
->hid
, IBM_PCI_HID
);
1108 if (event
== 1 && !pci
) /* 570 */
1109 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1110 else if (event
== 1 && pci
) /* 570 */
1111 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1112 else if (event
== 3 && docked
)
1113 acpi_bus_generate_event(ibm
->device
, event
, 1); /* button */
1114 else if (event
== 3 && !docked
)
1115 acpi_bus_generate_event(ibm
->device
, event
, 2); /* undock */
1116 else if (event
== 0 && docked
)
1117 acpi_bus_generate_event(ibm
->device
, event
, 3); /* dock */
1119 printk(IBM_ERR
"unknown dock event %d, status %d\n",
1120 event
, _sta(dock_handle
));
1121 acpi_bus_generate_event(ibm
->device
, event
, 0); /* unknown */
1126 #ifdef CONFIG_ACPI_IBM_BAY
1127 static int bay_status_supported
;
1128 static int bay_status2_supported
;
1129 static int bay_eject_supported
;
1130 static int bay_eject2_supported
;
1132 static int bay_init(void)
1134 bay_status_supported
= bay_handle
&&
1135 acpi_evalf(bay_handle
, NULL
, "_STA", "qv");
1136 bay_status2_supported
= bay2_handle
&&
1137 acpi_evalf(bay2_handle
, NULL
, "_STA", "qv");
1139 bay_eject_supported
= bay_handle
&& bay_ej_handle
&&
1140 (strlencmp(bay_ej_path
, "_EJ0") == 0 || experimental
);
1141 bay_eject2_supported
= bay2_handle
&& bay2_ej_handle
&&
1142 (strlencmp(bay2_ej_path
, "_EJ0") == 0 || experimental
);
1147 #define bay_occupied(b) (_sta(b##_handle) & 1)
1149 static int bay_read(char *p
)
1152 int occupied
= bay_occupied(bay
);
1153 int occupied2
= bay_occupied(bay2
);
1156 len
+= sprintf(p
+ len
, "status:\t\t%s\n", bay_status_supported
?
1157 (occupied
? "occupied" : "unoccupied") :
1159 if (bay_status2_supported
)
1160 len
+= sprintf(p
+ len
, "status2:\t%s\n", occupied2
?
1161 "occupied" : "unoccupied");
1163 eject
= bay_eject_supported
&& occupied
;
1164 eject2
= bay_eject2_supported
&& occupied2
;
1166 if (eject
&& eject2
)
1167 len
+= sprintf(p
+ len
, "commands:\teject, eject2\n");
1169 len
+= sprintf(p
+ len
, "commands:\teject\n");
1171 len
+= sprintf(p
+ len
, "commands:\teject2\n");
1176 static int bay_write(char *buf
)
1180 if (!bay_eject_supported
&& !bay_eject2_supported
)
1183 while ((cmd
= next_cmd(&buf
))) {
1184 if (bay_eject_supported
&& strlencmp(cmd
, "eject") == 0) {
1185 if (!acpi_evalf(bay_ej_handle
, NULL
, NULL
, "vd", 1))
1187 } else if (bay_eject2_supported
&&
1188 strlencmp(cmd
, "eject2") == 0) {
1189 if (!acpi_evalf(bay2_ej_handle
, NULL
, NULL
, "vd", 1))
1198 static void bay_notify(struct ibm_struct
*ibm
, u32 event
)
1200 acpi_bus_generate_event(ibm
->device
, event
, 0);
1202 #endif /* CONFIG_ACPI_IBM_BAY */
1204 static int cmos_read(char *p
)
1208 /* cmos not supported on 570, 600e/x, 770e, 770x, A21e, A2xm/p,
1209 R30, R31, T20-22, X20-21 */
1211 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1213 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1214 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-21)\n");
1220 static int cmos_eval(int cmos_cmd
)
1223 return acpi_evalf(cmos_handle
, NULL
, NULL
, "vd", cmos_cmd
);
1228 static int cmos_write(char *buf
)
1236 while ((cmd
= next_cmd(&buf
))) {
1237 if (sscanf(cmd
, "%u", &cmos_cmd
) == 1 &&
1238 cmos_cmd
>= 0 && cmos_cmd
<= 21) {
1243 if (!cmos_eval(cmos_cmd
))
1250 enum led_access_mode
{
1251 IBMACPI_LED_NONE
= 0,
1252 IBMACPI_LED_570
, /* 570 */
1253 IBMACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1254 IBMACPI_LED_NEW
, /* all others */
1256 static enum led_access_mode led_supported
;
1258 static int led_init(void)
1261 /* led not supported on R30, R31 */
1262 led_supported
= IBMACPI_LED_NONE
;
1263 else if (strlencmp(led_path
, "SLED") == 0)
1265 led_supported
= IBMACPI_LED_570
;
1266 else if (strlencmp(led_path
, "SYSL") == 0)
1267 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
1268 led_supported
= IBMACPI_LED_OLD
;
1271 led_supported
= IBMACPI_LED_NEW
;
1276 #define led_status(s) ((s) == 0 ? "off" : ((s) == 1 ? "on" : "blinking"))
1278 static int led_read(char *p
)
1282 if (!led_supported
) {
1283 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1286 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1288 if (led_supported
== IBMACPI_LED_570
) {
1291 for (i
= 0; i
< 8; i
++) {
1292 if (!acpi_evalf(ec_handle
,
1293 &status
, "GLED", "dd", 1 << i
))
1295 len
+= sprintf(p
+ len
, "%d:\t\t%s\n",
1296 i
, led_status(status
));
1300 len
+= sprintf(p
+ len
, "commands:\t"
1301 "<led> on, <led> off, <led> blink (<led> is 0-7)\n");
1306 /* off, on, blink */
1307 static const int led_sled_arg1
[] = { 0, 1, 3 };
1308 static const int led_exp_hlbl
[] = { 0, 0, 1 }; /* led# * */
1309 static const int led_exp_hlcl
[] = { 0, 1, 1 }; /* led# * */
1310 static const int led_led_arg1
[] = { 0, 0x80, 0xc0 };
1312 #define EC_HLCL 0x0c
1313 #define EC_HLBL 0x0d
1314 #define EC_HLMS 0x0e
1316 static int led_write(char *buf
)
1324 while ((cmd
= next_cmd(&buf
))) {
1325 if (sscanf(cmd
, "%d", &led
) != 1 || led
< 0 || led
> 7)
1328 if (strstr(cmd
, "off")) {
1330 } else if (strstr(cmd
, "on")) {
1332 } else if (strstr(cmd
, "blink")) {
1337 if (led_supported
== IBMACPI_LED_570
) {
1340 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1341 led
, led_sled_arg1
[ind
]))
1343 } else if (led_supported
== IBMACPI_LED_OLD
) {
1344 /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20 */
1346 ret
= ec_write(EC_HLMS
, led
);
1349 ec_write(EC_HLBL
, led
* led_exp_hlbl
[ind
]);
1352 ec_write(EC_HLCL
, led
* led_exp_hlcl
[ind
]);
1357 if (!acpi_evalf(led_handle
, NULL
, NULL
, "vdd",
1358 led
, led_led_arg1
[ind
]))
1366 static int beep_read(char *p
)
1371 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
1373 len
+= sprintf(p
+ len
, "status:\t\tsupported\n");
1374 len
+= sprintf(p
+ len
, "commands:\t<cmd> (<cmd> is 0-17)\n");
1380 static int beep_write(char *buf
)
1388 while ((cmd
= next_cmd(&buf
))) {
1389 if (sscanf(cmd
, "%u", &beep_cmd
) == 1 &&
1390 beep_cmd
>= 0 && beep_cmd
<= 17) {
1394 if (!acpi_evalf(beep_handle
, NULL
, NULL
, "vdd", beep_cmd
, 0))
1401 static int acpi_ec_read(int i
, u8
* p
)
1406 if (!acpi_evalf(ecrd_handle
, &v
, NULL
, "dd", i
))
1410 if (ec_read(i
, p
) < 0)
1417 static int acpi_ec_write(int i
, u8 v
)
1420 if (!acpi_evalf(ecwr_handle
, NULL
, NULL
, "vdd", i
, v
))
1423 if (ec_write(i
, v
) < 0)
1430 static enum thermal_access_mode thermal_read_mode
;
1432 static int thermal_init(void)
1436 int acpi_tmp7
= acpi_evalf(ec_handle
, NULL
, "TMP7", "qv");
1438 if (ibm_thinkpad_ec_found
&& experimental
) {
1440 * Direct EC access mode: sensors at registers
1441 * 0x78-0x7F, 0xC0-0xC7. Registers return 0x00 for
1442 * non-implemented, thermal sensors return 0x80 when
1447 for (i
= 0; i
< 8; i
++) {
1448 if (likely(acpi_ec_read(0x78 + i
, &t
))) {
1454 if (likely(acpi_ec_read(0xC0 + i
, &t
))) {
1462 /* This is sheer paranoia, but we handle it anyway */
1465 "ThinkPad ACPI EC access misbehaving, "
1466 "falling back to ACPI TMPx access mode\n");
1467 thermal_read_mode
= IBMACPI_THERMAL_ACPI_TMP07
;
1470 "ThinkPad ACPI EC access misbehaving, "
1471 "disabling thermal sensors access\n");
1472 thermal_read_mode
= IBMACPI_THERMAL_NONE
;
1477 IBMACPI_THERMAL_TPEC_16
: IBMACPI_THERMAL_TPEC_8
;
1479 } else if (acpi_tmp7
) {
1480 if (acpi_evalf(ec_handle
, NULL
, "UPDT", "qv")) {
1481 /* 600e/x, 770e, 770x */
1482 thermal_read_mode
= IBMACPI_THERMAL_ACPI_UPDT
;
1484 /* Standard ACPI TMPx access, max 8 sensors */
1485 thermal_read_mode
= IBMACPI_THERMAL_ACPI_TMP07
;
1488 /* temperatures not supported on 570, G4x, R30, R31, R32 */
1489 thermal_read_mode
= IBMACPI_THERMAL_NONE
;
1495 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
)
1499 char tmpi
[] = "TMPi";
1504 switch (thermal_read_mode
) {
1505 #if IBMACPI_MAX_THERMAL_SENSORS >= 16
1506 case IBMACPI_THERMAL_TPEC_16
:
1507 for (i
= 0; i
< 8; i
++) {
1508 if (!acpi_ec_read(0xC0 + i
, &tmp
))
1510 s
->temp
[i
+ 8] = tmp
* 1000;
1514 case IBMACPI_THERMAL_TPEC_8
:
1515 for (i
= 0; i
< 8; i
++) {
1516 if (!acpi_ec_read(0x78 + i
, &tmp
))
1518 s
->temp
[i
] = tmp
* 1000;
1520 return (thermal_read_mode
== IBMACPI_THERMAL_TPEC_16
) ? 16 : 8;
1522 case IBMACPI_THERMAL_ACPI_UPDT
:
1523 if (!acpi_evalf(ec_handle
, NULL
, "UPDT", "v"))
1525 for (i
= 0; i
< 8; i
++) {
1527 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1529 s
->temp
[i
] = (t
- 2732) * 100;
1533 case IBMACPI_THERMAL_ACPI_TMP07
:
1534 for (i
= 0; i
< 8; i
++) {
1536 if (!acpi_evalf(ec_handle
, &t
, tmpi
, "d"))
1538 s
->temp
[i
] = t
* 1000;
1542 case IBMACPI_THERMAL_NONE
:
1548 static int thermal_read(char *p
)
1552 struct ibm_thermal_sensors_struct t
;
1554 n
= thermal_get_sensors(&t
);
1555 if (unlikely(n
< 0))
1558 len
+= sprintf(p
+ len
, "temperatures:\t");
1561 for (i
= 0; i
< (n
- 1); i
++)
1562 len
+= sprintf(p
+ len
, "%d ", t
.temp
[i
] / 1000);
1563 len
+= sprintf(p
+ len
, "%d\n", t
.temp
[i
] / 1000);
1565 len
+= sprintf(p
+ len
, "not supported\n");
1570 static u8 ecdump_regs
[256];
1572 static int ecdump_read(char *p
)
1578 len
+= sprintf(p
+ len
, "EC "
1579 " +00 +01 +02 +03 +04 +05 +06 +07"
1580 " +08 +09 +0a +0b +0c +0d +0e +0f\n");
1581 for (i
= 0; i
< 256; i
+= 16) {
1582 len
+= sprintf(p
+ len
, "EC 0x%02x:", i
);
1583 for (j
= 0; j
< 16; j
++) {
1584 if (!acpi_ec_read(i
+ j
, &v
))
1586 if (v
!= ecdump_regs
[i
+ j
])
1587 len
+= sprintf(p
+ len
, " *%02x", v
);
1589 len
+= sprintf(p
+ len
, " %02x", v
);
1590 ecdump_regs
[i
+ j
] = v
;
1592 len
+= sprintf(p
+ len
, "\n");
1597 /* These are way too dangerous to advertise openly... */
1599 len
+= sprintf(p
+ len
, "commands:\t0x<offset> 0x<value>"
1600 " (<offset> is 00-ff, <value> is 00-ff)\n");
1601 len
+= sprintf(p
+ len
, "commands:\t0x<offset> <value> "
1602 " (<offset> is 00-ff, <value> is 0-255)\n");
1607 static int ecdump_write(char *buf
)
1612 while ((cmd
= next_cmd(&buf
))) {
1613 if (sscanf(cmd
, "0x%x 0x%x", &i
, &v
) == 2) {
1615 } else if (sscanf(cmd
, "0x%x %u", &i
, &v
) == 2) {
1619 if (i
>= 0 && i
< 256 && v
>= 0 && v
< 256) {
1620 if (!acpi_ec_write(i
, v
))
1629 static int brightness_offset
= 0x31;
1631 static int brightness_get(struct backlight_device
*bd
)
1634 if (!acpi_ec_read(brightness_offset
, &level
))
1642 static int brightness_read(char *p
)
1647 if ((level
= brightness_get(NULL
)) < 0) {
1648 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1650 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0x7);
1651 len
+= sprintf(p
+ len
, "commands:\tup, down\n");
1652 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1653 " (<level> is 0-7)\n");
1659 #define BRIGHTNESS_UP 4
1660 #define BRIGHTNESS_DOWN 5
1662 static int brightness_set(int value
)
1664 int cmos_cmd
, inc
, i
;
1665 int current_value
= brightness_get(NULL
);
1669 cmos_cmd
= value
> current_value
? BRIGHTNESS_UP
: BRIGHTNESS_DOWN
;
1670 inc
= value
> current_value
? 1 : -1;
1671 for (i
= current_value
; i
!= value
; i
+= inc
) {
1672 if (!cmos_eval(cmos_cmd
))
1674 if (!acpi_ec_write(brightness_offset
, i
+ inc
))
1681 static int brightness_write(char *buf
)
1687 while ((cmd
= next_cmd(&buf
))) {
1688 if ((level
= brightness_get(NULL
)) < 0)
1692 if (strlencmp(cmd
, "up") == 0) {
1693 new_level
= level
== 7 ? 7 : level
+ 1;
1694 } else if (strlencmp(cmd
, "down") == 0) {
1695 new_level
= level
== 0 ? 0 : level
- 1;
1696 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1697 new_level
>= 0 && new_level
<= 7) {
1702 brightness_set(new_level
);
1708 static int brightness_update_status(struct backlight_device
*bd
)
1710 return brightness_set(bd
->props
->brightness
);
1713 static struct backlight_properties ibm_backlight_data
= {
1714 .owner
= THIS_MODULE
,
1715 .get_brightness
= brightness_get
,
1716 .update_status
= brightness_update_status
,
1717 .max_brightness
= 7,
1720 static int brightness_init(void)
1722 ibm_backlight_device
= backlight_device_register("ibm", NULL
, NULL
,
1723 &ibm_backlight_data
);
1724 if (IS_ERR(ibm_backlight_device
)) {
1725 printk(IBM_ERR
"Could not register backlight device\n");
1726 return PTR_ERR(ibm_backlight_device
);
1732 static void brightness_exit(void)
1734 if (ibm_backlight_device
) {
1735 backlight_device_unregister(ibm_backlight_device
);
1736 ibm_backlight_device
= NULL
;
1740 static int volume_offset
= 0x30;
1742 static int volume_read(char *p
)
1747 if (!acpi_ec_read(volume_offset
, &level
)) {
1748 len
+= sprintf(p
+ len
, "level:\t\tunreadable\n");
1750 len
+= sprintf(p
+ len
, "level:\t\t%d\n", level
& 0xf);
1751 len
+= sprintf(p
+ len
, "mute:\t\t%s\n", onoff(level
, 6));
1752 len
+= sprintf(p
+ len
, "commands:\tup, down, mute\n");
1753 len
+= sprintf(p
+ len
, "commands:\tlevel <level>"
1754 " (<level> is 0-15)\n");
1760 #define VOLUME_DOWN 0
1762 #define VOLUME_MUTE 2
1764 static int volume_write(char *buf
)
1766 int cmos_cmd
, inc
, i
;
1768 int new_level
, new_mute
;
1771 while ((cmd
= next_cmd(&buf
))) {
1772 if (!acpi_ec_read(volume_offset
, &level
))
1774 new_mute
= mute
= level
& 0x40;
1775 new_level
= level
= level
& 0xf;
1777 if (strlencmp(cmd
, "up") == 0) {
1781 new_level
= level
== 15 ? 15 : level
+ 1;
1782 } else if (strlencmp(cmd
, "down") == 0) {
1786 new_level
= level
== 0 ? 0 : level
- 1;
1787 } else if (sscanf(cmd
, "level %d", &new_level
) == 1 &&
1788 new_level
>= 0 && new_level
<= 15) {
1790 } else if (strlencmp(cmd
, "mute") == 0) {
1795 if (new_level
!= level
) { /* mute doesn't change */
1796 cmos_cmd
= new_level
> level
? VOLUME_UP
: VOLUME_DOWN
;
1797 inc
= new_level
> level
? 1 : -1;
1799 if (mute
&& (!cmos_eval(cmos_cmd
) ||
1800 !acpi_ec_write(volume_offset
, level
)))
1803 for (i
= level
; i
!= new_level
; i
+= inc
)
1804 if (!cmos_eval(cmos_cmd
) ||
1805 !acpi_ec_write(volume_offset
, i
+ inc
))
1808 if (mute
&& (!cmos_eval(VOLUME_MUTE
) ||
1809 !acpi_ec_write(volume_offset
,
1814 if (new_mute
!= mute
) { /* level doesn't change */
1815 cmos_cmd
= new_mute
? VOLUME_MUTE
: VOLUME_UP
;
1817 if (!cmos_eval(cmos_cmd
) ||
1818 !acpi_ec_write(volume_offset
, level
+ new_mute
))
1826 static enum fan_status_access_mode fan_status_access_mode
;
1827 static enum fan_control_access_mode fan_control_access_mode
;
1828 static enum fan_control_commands fan_control_commands
;
1830 static int fan_control_status_known
;
1831 static u8 fan_control_initial_status
;
1833 static void fan_watchdog_fire(struct work_struct
*ignored
);
1834 static int fan_watchdog_maxinterval
;
1835 static DECLARE_DELAYED_WORK(fan_watchdog_task
, fan_watchdog_fire
);
1837 static int fan_init(void)
1839 fan_status_access_mode
= IBMACPI_FAN_NONE
;
1840 fan_control_access_mode
= IBMACPI_FAN_WR_NONE
;
1841 fan_control_commands
= 0;
1842 fan_control_status_known
= 1;
1843 fan_watchdog_maxinterval
= 0;
1846 /* 570, 600e/x, 770e, 770x */
1847 fan_status_access_mode
= IBMACPI_FAN_RD_ACPI_GFAN
;
1849 /* all other ThinkPads: note that even old-style
1850 * ThinkPad ECs supports the fan control register */
1851 if (likely(acpi_ec_read(fan_status_offset
,
1852 &fan_control_initial_status
))) {
1853 fan_status_access_mode
= IBMACPI_FAN_RD_TPEC
;
1855 /* In some ThinkPads, neither the EC nor the ACPI
1856 * DSDT initialize the fan status, and it ends up
1857 * being set to 0x07 when it *could* be either
1860 * Enable for TP-1Y (T43), TP-78 (R51e),
1861 * TP-76 (R52), TP-70 (T43, R52), which are known
1863 if (fan_control_initial_status
== 0x07 &&
1864 ibm_thinkpad_ec_found
&&
1865 ((ibm_thinkpad_ec_found
[0] == '1' &&
1866 ibm_thinkpad_ec_found
[1] == 'Y') ||
1867 (ibm_thinkpad_ec_found
[0] == '7' &&
1868 (ibm_thinkpad_ec_found
[1] == '6' ||
1869 ibm_thinkpad_ec_found
[1] == '8' ||
1870 ibm_thinkpad_ec_found
[1] == '0'))
1873 "fan_init: initial fan status is "
1874 "unknown, assuming it is in auto "
1876 fan_control_status_known
= 0;
1880 "ThinkPad ACPI EC access misbehaving, "
1881 "fan status and control unavailable\n");
1888 fan_control_access_mode
= IBMACPI_FAN_WR_ACPI_SFAN
;
1889 fan_control_commands
|=
1890 IBMACPI_FAN_CMD_LEVEL
| IBMACPI_FAN_CMD_ENABLE
;
1893 /* gfan without sfan means no fan control */
1894 /* all other models implement TP EC 0x2f control */
1898 fan_control_access_mode
=
1899 IBMACPI_FAN_WR_ACPI_FANS
;
1900 fan_control_commands
|=
1901 IBMACPI_FAN_CMD_SPEED
|
1902 IBMACPI_FAN_CMD_LEVEL
|
1903 IBMACPI_FAN_CMD_ENABLE
;
1905 fan_control_access_mode
= IBMACPI_FAN_WR_TPEC
;
1906 fan_control_commands
|=
1907 IBMACPI_FAN_CMD_LEVEL
|
1908 IBMACPI_FAN_CMD_ENABLE
;
1916 static int fan_get_status(u8
*status
)
1921 * Add IBMACPI_FAN_RD_ACPI_FANS ? */
1923 switch (fan_status_access_mode
) {
1924 case IBMACPI_FAN_RD_ACPI_GFAN
:
1925 /* 570, 600e/x, 770e, 770x */
1927 if (unlikely(!acpi_evalf(gfan_handle
, &s
, NULL
, "d")))
1935 case IBMACPI_FAN_RD_TPEC
:
1936 /* all except 570, 600e/x, 770e, 770x */
1937 if (unlikely(!acpi_ec_read(fan_status_offset
, &s
)))
1952 static int fan_get_speed(unsigned int *speed
)
1956 switch (fan_status_access_mode
) {
1957 case IBMACPI_FAN_RD_TPEC
:
1958 /* all except 570, 600e/x, 770e, 770x */
1959 if (unlikely(!acpi_ec_read(fan_rpm_offset
, &lo
) ||
1960 !acpi_ec_read(fan_rpm_offset
+ 1, &hi
)))
1964 *speed
= (hi
<< 8) | lo
;
1975 static void fan_exit(void)
1977 cancel_delayed_work(&fan_watchdog_task
);
1978 flush_scheduled_work();
1981 static void fan_watchdog_reset(void)
1983 static int fan_watchdog_active
= 0;
1985 if (fan_watchdog_active
)
1986 cancel_delayed_work(&fan_watchdog_task
);
1988 if (fan_watchdog_maxinterval
> 0) {
1989 fan_watchdog_active
= 1;
1990 if (!schedule_delayed_work(&fan_watchdog_task
,
1991 msecs_to_jiffies(fan_watchdog_maxinterval
1993 printk(IBM_ERR
"failed to schedule the fan watchdog, "
1994 "watchdog will not trigger\n");
1997 fan_watchdog_active
= 0;
2000 static int fan_read(char *p
)
2005 unsigned int speed
= 0;
2007 switch (fan_status_access_mode
) {
2008 case IBMACPI_FAN_RD_ACPI_GFAN
:
2009 /* 570, 600e/x, 770e, 770x */
2010 if ((rc
= fan_get_status(&status
)) < 0)
2013 len
+= sprintf(p
+ len
, "status:\t\t%s\n"
2015 (status
!= 0) ? "enabled" : "disabled", status
);
2018 case IBMACPI_FAN_RD_TPEC
:
2019 /* all except 570, 600e/x, 770e, 770x */
2020 if ((rc
= fan_get_status(&status
)) < 0)
2023 if (unlikely(!fan_control_status_known
)) {
2024 if (status
!= fan_control_initial_status
)
2025 fan_control_status_known
= 1;
2027 /* Return most likely status. In fact, it
2028 * might be the only possible status */
2029 status
= IBMACPI_FAN_EC_AUTO
;
2032 len
+= sprintf(p
+ len
, "status:\t\t%s\n",
2033 (status
!= 0) ? "enabled" : "disabled");
2035 /* No ThinkPad boots on disengaged mode, we can safely
2036 * assume the tachometer is online if fan control status
2038 if ((rc
= fan_get_speed(&speed
)) < 0)
2041 len
+= sprintf(p
+ len
, "speed:\t\t%d\n", speed
);
2043 if (status
& IBMACPI_FAN_EC_DISENGAGED
)
2044 /* Disengaged mode takes precedence */
2045 len
+= sprintf(p
+ len
, "level:\t\tdisengaged\n");
2046 else if (status
& IBMACPI_FAN_EC_AUTO
)
2047 len
+= sprintf(p
+ len
, "level:\t\tauto\n");
2049 len
+= sprintf(p
+ len
, "level:\t\t%d\n", status
);
2052 case IBMACPI_FAN_NONE
:
2054 len
+= sprintf(p
+ len
, "status:\t\tnot supported\n");
2057 if (fan_control_commands
& IBMACPI_FAN_CMD_LEVEL
) {
2058 len
+= sprintf(p
+ len
, "commands:\tlevel <level>");
2060 switch (fan_control_access_mode
) {
2061 case IBMACPI_FAN_WR_ACPI_SFAN
:
2062 len
+= sprintf(p
+ len
, " (<level> is 0-7)\n");
2066 len
+= sprintf(p
+ len
, " (<level> is 0-7, "
2067 "auto, disengaged)\n");
2072 if (fan_control_commands
& IBMACPI_FAN_CMD_ENABLE
)
2073 len
+= sprintf(p
+ len
, "commands:\tenable, disable\n"
2074 "commands:\twatchdog <timeout> (<timeout> is 0 (off), "
2075 "1-120 (seconds))\n");
2077 if (fan_control_commands
& IBMACPI_FAN_CMD_SPEED
)
2078 len
+= sprintf(p
+ len
, "commands:\tspeed <speed>"
2079 " (<speed> is 0-65535)\n");
2084 static int fan_set_level(int level
)
2086 switch (fan_control_access_mode
) {
2087 case IBMACPI_FAN_WR_ACPI_SFAN
:
2088 if (level
>= 0 && level
<= 7) {
2089 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", level
))
2095 case IBMACPI_FAN_WR_ACPI_FANS
:
2096 case IBMACPI_FAN_WR_TPEC
:
2097 if ((level
!= IBMACPI_FAN_EC_AUTO
) &&
2098 (level
!= IBMACPI_FAN_EC_DISENGAGED
) &&
2099 ((level
< 0) || (level
> 7)))
2102 if (!acpi_ec_write(fan_status_offset
, level
))
2105 fan_control_status_known
= 1;
2114 static int fan_set_enable(void)
2119 switch (fan_control_access_mode
) {
2120 case IBMACPI_FAN_WR_ACPI_FANS
:
2121 case IBMACPI_FAN_WR_TPEC
:
2122 if ((rc
= fan_get_status(&s
)) < 0)
2125 /* Don't go out of emergency fan mode */
2127 s
= IBMACPI_FAN_EC_AUTO
;
2129 if (!acpi_ec_write(fan_status_offset
, s
))
2132 fan_control_status_known
= 1;
2135 case IBMACPI_FAN_WR_ACPI_SFAN
:
2136 if ((rc
= fan_get_status(&s
)) < 0)
2141 /* Set fan to at least level 4 */
2145 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", s
))
2155 static int fan_set_disable(void)
2157 switch (fan_control_access_mode
) {
2158 case IBMACPI_FAN_WR_ACPI_FANS
:
2159 case IBMACPI_FAN_WR_TPEC
:
2160 if (!acpi_ec_write(fan_status_offset
, 0x00))
2163 fan_control_status_known
= 1;
2166 case IBMACPI_FAN_WR_ACPI_SFAN
:
2167 if (!acpi_evalf(sfan_handle
, NULL
, NULL
, "vd", 0x00))
2177 static int fan_set_speed(int speed
)
2179 switch (fan_control_access_mode
) {
2180 case IBMACPI_FAN_WR_ACPI_FANS
:
2181 if (speed
>= 0 && speed
<= 65535) {
2182 if (!acpi_evalf(fans_handle
, NULL
, NULL
, "vddd",
2183 speed
, speed
, speed
))
2195 static int fan_write_cmd_level(const char *cmd
, int *rc
)
2199 if (strlencmp(cmd
, "level auto") == 0)
2200 level
= IBMACPI_FAN_EC_AUTO
;
2201 else if (strlencmp(cmd
, "level disengaged") == 0)
2202 level
= IBMACPI_FAN_EC_DISENGAGED
;
2203 else if (sscanf(cmd
, "level %d", &level
) != 1)
2206 if ((*rc
= fan_set_level(level
)) == -ENXIO
)
2207 printk(IBM_ERR
"level command accepted for unsupported "
2208 "access mode %d", fan_control_access_mode
);
2213 static int fan_write_cmd_enable(const char *cmd
, int *rc
)
2215 if (strlencmp(cmd
, "enable") != 0)
2218 if ((*rc
= fan_set_enable()) == -ENXIO
)
2219 printk(IBM_ERR
"enable command accepted for unsupported "
2220 "access mode %d", fan_control_access_mode
);
2225 static int fan_write_cmd_disable(const char *cmd
, int *rc
)
2227 if (strlencmp(cmd
, "disable") != 0)
2230 if ((*rc
= fan_set_disable()) == -ENXIO
)
2231 printk(IBM_ERR
"disable command accepted for unsupported "
2232 "access mode %d", fan_control_access_mode
);
2237 static int fan_write_cmd_speed(const char *cmd
, int *rc
)
2242 * Support speed <low> <medium> <high> ? */
2244 if (sscanf(cmd
, "speed %d", &speed
) != 1)
2247 if ((*rc
= fan_set_speed(speed
)) == -ENXIO
)
2248 printk(IBM_ERR
"speed command accepted for unsupported "
2249 "access mode %d", fan_control_access_mode
);
2254 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
)
2258 if (sscanf(cmd
, "watchdog %d", &interval
) != 1)
2261 if (interval
< 0 || interval
> 120)
2264 fan_watchdog_maxinterval
= interval
;
2269 static int fan_write(char *buf
)
2274 while (!rc
&& (cmd
= next_cmd(&buf
))) {
2275 if (!((fan_control_commands
& IBMACPI_FAN_CMD_LEVEL
) &&
2276 fan_write_cmd_level(cmd
, &rc
)) &&
2277 !((fan_control_commands
& IBMACPI_FAN_CMD_ENABLE
) &&
2278 (fan_write_cmd_enable(cmd
, &rc
) ||
2279 fan_write_cmd_disable(cmd
, &rc
) ||
2280 fan_write_cmd_watchdog(cmd
, &rc
))) &&
2281 !((fan_control_commands
& IBMACPI_FAN_CMD_SPEED
) &&
2282 fan_write_cmd_speed(cmd
, &rc
))
2286 fan_watchdog_reset();
2292 static void fan_watchdog_fire(struct work_struct
*ignored
)
2294 printk(IBM_NOTICE
"fan watchdog: enabling fan\n");
2295 if (fan_set_enable()) {
2296 printk(IBM_ERR
"fan watchdog: error while enabling fan\n");
2297 /* reschedule for later */
2298 fan_watchdog_reset();
2302 static struct ibm_struct ibms
[] = {
2305 .init
= ibm_acpi_driver_init
,
2306 .read
= driver_read
,
2310 .hid
= IBM_HKEY_HID
,
2311 .init
= hotkey_init
,
2312 .read
= hotkey_read
,
2313 .write
= hotkey_write
,
2314 .exit
= hotkey_exit
,
2315 .notify
= hotkey_notify
,
2316 .handle
= &hkey_handle
,
2317 .type
= ACPI_DEVICE_NOTIFY
,
2320 .name
= "bluetooth",
2321 .init
= bluetooth_init
,
2322 .read
= bluetooth_read
,
2323 .write
= bluetooth_write
,
2336 .write
= video_write
,
2343 .write
= light_write
,
2345 #ifdef CONFIG_ACPI_IBM_DOCK
2349 .write
= dock_write
,
2350 .notify
= dock_notify
,
2351 .handle
= &dock_handle
,
2352 .type
= ACPI_SYSTEM_NOTIFY
,
2357 .notify
= dock_notify
,
2358 .handle
= &pci_handle
,
2359 .type
= ACPI_SYSTEM_NOTIFY
,
2362 #ifdef CONFIG_ACPI_IBM_BAY
2368 .notify
= bay_notify
,
2369 .handle
= &bay_handle
,
2370 .type
= ACPI_SYSTEM_NOTIFY
,
2372 #endif /* CONFIG_ACPI_IBM_BAY */
2376 .write
= cmos_write
,
2387 .write
= beep_write
,
2391 .init
= thermal_init
,
2392 .read
= thermal_read
,
2396 .read
= ecdump_read
,
2397 .write
= ecdump_write
,
2401 .name
= "brightness",
2402 .read
= brightness_read
,
2403 .write
= brightness_write
,
2404 .init
= brightness_init
,
2405 .exit
= brightness_exit
,
2409 .read
= volume_read
,
2410 .write
= volume_write
,
2422 static int dispatch_read(char *page
, char **start
, off_t off
, int count
,
2423 int *eof
, void *data
)
2425 struct ibm_struct
*ibm
= data
;
2428 if (!ibm
|| !ibm
->read
)
2431 len
= ibm
->read(page
);
2435 if (len
<= off
+ count
)
2437 *start
= page
+ off
;
2447 static int dispatch_write(struct file
*file
, const char __user
* userbuf
,
2448 unsigned long count
, void *data
)
2450 struct ibm_struct
*ibm
= data
;
2454 if (!ibm
|| !ibm
->write
)
2457 kernbuf
= kmalloc(count
+ 2, GFP_KERNEL
);
2461 if (copy_from_user(kernbuf
, userbuf
, count
)) {
2467 strcat(kernbuf
, ",");
2468 ret
= ibm
->write(kernbuf
);
2477 static void dispatch_notify(acpi_handle handle
, u32 event
, void *data
)
2479 struct ibm_struct
*ibm
= data
;
2481 if (!ibm
|| !ibm
->notify
)
2484 ibm
->notify(ibm
, event
);
2487 static int __init
setup_notify(struct ibm_struct
*ibm
)
2495 ret
= acpi_bus_get_device(*ibm
->handle
, &ibm
->device
);
2497 printk(IBM_ERR
"%s device not present\n", ibm
->name
);
2501 acpi_driver_data(ibm
->device
) = ibm
;
2502 sprintf(acpi_device_class(ibm
->device
), "%s/%s", IBM_NAME
, ibm
->name
);
2504 status
= acpi_install_notify_handler(*ibm
->handle
, ibm
->type
,
2505 dispatch_notify
, ibm
);
2506 if (ACPI_FAILURE(status
)) {
2507 printk(IBM_ERR
"acpi_install_notify_handler(%s) failed: %d\n",
2511 ibm
->notify_installed
= 1;
2515 static int __init
ibm_device_add(struct acpi_device
*device
)
2520 static int __init
register_driver(struct ibm_struct
*ibm
)
2524 ibm
->driver
= kzalloc(sizeof(struct acpi_driver
), GFP_KERNEL
);
2526 printk(IBM_ERR
"kmalloc(ibm->driver) failed\n");
2530 sprintf(ibm
->driver
->name
, "%s_%s", IBM_NAME
, ibm
->name
);
2531 ibm
->driver
->ids
= ibm
->hid
;
2532 ibm
->driver
->ops
.add
= &ibm_device_add
;
2534 ret
= acpi_bus_register_driver(ibm
->driver
);
2536 printk(IBM_ERR
"acpi_bus_register_driver(%s) failed: %d\n",
2544 static int __init
ibm_init(struct ibm_struct
*ibm
)
2547 struct proc_dir_entry
*entry
;
2549 if (ibm
->experimental
&& !experimental
)
2553 ret
= register_driver(ibm
);
2556 ibm
->driver_registered
= 1;
2563 ibm
->init_called
= 1;
2567 entry
= create_proc_entry(ibm
->name
,
2568 S_IFREG
| S_IRUGO
| S_IWUSR
,
2571 printk(IBM_ERR
"unable to create proc entry %s\n",
2575 entry
->owner
= THIS_MODULE
;
2577 entry
->read_proc
= &dispatch_read
;
2579 entry
->write_proc
= &dispatch_write
;
2580 ibm
->proc_created
= 1;
2584 ret
= setup_notify(ibm
);
2592 static void ibm_exit(struct ibm_struct
*ibm
)
2594 if (ibm
->notify_installed
)
2595 acpi_remove_notify_handler(*ibm
->handle
, ibm
->type
,
2598 if (ibm
->proc_created
)
2599 remove_proc_entry(ibm
->name
, proc_dir
);
2601 if (ibm
->init_called
&& ibm
->exit
)
2604 if (ibm
->driver_registered
) {
2605 acpi_bus_unregister_driver(ibm
->driver
);
2610 static void __init
ibm_handle_init(char *name
,
2611 acpi_handle
* handle
, acpi_handle parent
,
2612 char **paths
, int num_paths
, char **path
)
2617 for (i
= 0; i
< num_paths
; i
++) {
2618 status
= acpi_get_handle(parent
, paths
[i
], handle
);
2619 if (ACPI_SUCCESS(status
)) {
2628 #define IBM_HANDLE_INIT(object) \
2629 ibm_handle_init(#object, &object##_handle, *object##_parent, \
2630 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
2632 static int __init
set_ibm_param(const char *val
, struct kernel_param
*kp
)
2636 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++)
2637 if (strcmp(ibms
[i
].name
, kp
->name
) == 0 && ibms
[i
].write
) {
2638 if (strlen(val
) > sizeof(ibms
[i
].param
) - 2)
2640 strcpy(ibms
[i
].param
, val
);
2641 strcat(ibms
[i
].param
, ",");
2648 #define IBM_PARAM(feature) \
2649 module_param_call(feature, set_ibm_param, NULL, NULL, 0)
2652 IBM_PARAM(bluetooth
);
2655 #ifdef CONFIG_ACPI_IBM_DOCK
2658 #ifdef CONFIG_ACPI_IBM_BAY
2660 #endif /* CONFIG_ACPI_IBM_BAY */
2665 IBM_PARAM(brightness
);
2669 static void acpi_ibm_exit(void)
2673 for (i
= ARRAY_SIZE(ibms
) - 1; i
>= 0; i
--)
2677 remove_proc_entry(IBM_DIR
, acpi_root_dir
);
2679 if (ibm_thinkpad_ec_found
)
2680 kfree(ibm_thinkpad_ec_found
);
2683 static char* __init
check_dmi_for_ec(void)
2685 struct dmi_device
*dev
= NULL
;
2686 char ec_fw_string
[18];
2689 * ThinkPad T23 or newer, A31 or newer, R50e or newer,
2690 * X32 or newer, all Z series; Some models must have an
2691 * up-to-date BIOS or they will not be detected.
2693 * See http://thinkwiki.org/wiki/List_of_DMI_IDs
2695 while ((dev
= dmi_find_device(DMI_DEV_TYPE_OEM_STRING
, NULL
, dev
))) {
2696 if (sscanf(dev
->name
,
2697 "IBM ThinkPad Embedded Controller -[%17c",
2698 ec_fw_string
) == 1) {
2699 ec_fw_string
[sizeof(ec_fw_string
) - 1] = 0;
2700 ec_fw_string
[strcspn(ec_fw_string
, " ]")] = 0;
2701 return kstrdup(ec_fw_string
, GFP_KERNEL
);
2707 static int __init
acpi_ibm_init(void)
2714 if (!acpi_specific_hotkey_enabled
) {
2715 printk(IBM_ERR
"using generic hotkey driver\n");
2719 /* ec is required because many other handles are relative to it */
2720 IBM_HANDLE_INIT(ec
);
2722 printk(IBM_ERR
"ec object not found\n");
2726 /* Models with newer firmware report the EC in DMI */
2727 ibm_thinkpad_ec_found
= check_dmi_for_ec();
2729 /* these handles are not required */
2730 IBM_HANDLE_INIT(vid
);
2731 IBM_HANDLE_INIT(vid2
);
2732 IBM_HANDLE_INIT(ledb
);
2733 IBM_HANDLE_INIT(led
);
2734 IBM_HANDLE_INIT(hkey
);
2735 IBM_HANDLE_INIT(lght
);
2736 IBM_HANDLE_INIT(cmos
);
2737 #ifdef CONFIG_ACPI_IBM_DOCK
2738 IBM_HANDLE_INIT(dock
);
2740 IBM_HANDLE_INIT(pci
);
2741 #ifdef CONFIG_ACPI_IBM_BAY
2742 IBM_HANDLE_INIT(bay
);
2744 IBM_HANDLE_INIT(bay_ej
);
2745 IBM_HANDLE_INIT(bay2
);
2747 IBM_HANDLE_INIT(bay2_ej
);
2748 #endif /* CONFIG_ACPI_IBM_BAY */
2749 IBM_HANDLE_INIT(beep
);
2750 IBM_HANDLE_INIT(ecrd
);
2751 IBM_HANDLE_INIT(ecwr
);
2752 IBM_HANDLE_INIT(fans
);
2753 IBM_HANDLE_INIT(gfan
);
2754 IBM_HANDLE_INIT(sfan
);
2756 proc_dir
= proc_mkdir(IBM_DIR
, acpi_root_dir
);
2758 printk(IBM_ERR
"unable to create proc dir %s", IBM_DIR
);
2762 proc_dir
->owner
= THIS_MODULE
;
2764 for (i
= 0; i
< ARRAY_SIZE(ibms
); i
++) {
2765 ret
= ibm_init(&ibms
[i
]);
2766 if (ret
>= 0 && *ibms
[i
].param
)
2767 ret
= ibms
[i
].write(ibms
[i
].param
);
2777 module_init(acpi_ibm_init
);
2778 module_exit(acpi_ibm_exit
);