2 * ibm_acpi.h - IBM ThinkPad ACPI Extras
5 * Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6 * Copyright (C) 2006-2007 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., 51 Franklin Street, Fifth Floor, Boston, MA
24 #ifndef __IBM_ACPI_H__
25 #define __IBM_ACPI_H__
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/init.h>
30 #include <linux/types.h>
31 #include <linux/string.h>
33 #include <linux/proc_fs.h>
34 #include <linux/backlight.h>
36 #include <asm/uaccess.h>
38 #include <linux/dmi.h>
39 #include <linux/jiffies.h>
40 #include <linux/workqueue.h>
42 #include <acpi/acpi_drivers.h>
43 #include <acpi/acnamesp.h>
46 /****************************************************************************
50 #define IBM_NAME "ibm"
51 #define IBM_DESC "IBM ThinkPad ACPI Extras"
52 #define IBM_FILE "ibm_acpi"
53 #define IBM_URL "http://ibm-acpi.sf.net/"
55 #define IBM_DIR IBM_NAME
57 #define IBM_LOG IBM_FILE ": "
58 #define IBM_ERR KERN_ERR IBM_LOG
59 #define IBM_NOTICE KERN_NOTICE IBM_LOG
60 #define IBM_INFO KERN_INFO IBM_LOG
61 #define IBM_DEBUG KERN_DEBUG IBM_LOG
63 #define IBM_MAX_ACPI_ARGS 3
65 /* ThinkPad CMOS commands */
66 #define TP_CMOS_VOLUME_DOWN 0
67 #define TP_CMOS_VOLUME_UP 1
68 #define TP_CMOS_VOLUME_MUTE 2
69 #define TP_CMOS_BRIGHTNESS_UP 4
70 #define TP_CMOS_BRIGHTNESS_DOWN 5
72 #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
73 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
74 #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
77 #define IBM_HKEY_HID "IBM0068"
78 #define IBM_PCI_HID "PNP0A03"
81 static int acpi_evalf(acpi_handle handle
,
82 void *res
, char *method
, char *fmt
, ...);
83 static int acpi_ec_read(int i
, u8
* p
);
84 static int acpi_ec_write(int i
, u8 v
);
85 static int _sta(acpi_handle handle
);
88 static acpi_handle root_handle
; /* root namespace */
89 static acpi_handle ec_handle
; /* EC */
90 static acpi_handle ecrd_handle
, ecwr_handle
; /* 570 EC access */
91 static acpi_handle cmos_handle
, hkey_handle
; /* basic thinkpad handles */
93 static void ibm_handle_init(char *name
,
94 acpi_handle
* handle
, acpi_handle parent
,
95 char **paths
, int num_paths
, char **path
);
96 #define IBM_HANDLE_INIT(object) \
97 ibm_handle_init(#object, &object##_handle, *object##_parent, \
98 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
101 static struct proc_dir_entry
*proc_dir
;
102 static int ibm_acpi_driver_init(void);
103 static int ibm_acpi_driver_read(char *p
);
106 static int dispatch_read(char *page
, char **start
, off_t off
, int count
,
107 int *eof
, void *data
);
108 static int dispatch_write(struct file
*file
, const char __user
* userbuf
,
109 unsigned long count
, void *data
);
110 static char *next_cmd(char **cmds
);
113 static int experimental
;
114 static char *ibm_thinkpad_ec_found
;
116 static char* check_dmi_for_ec(void);
117 static int acpi_ibm_init(void);
118 static void acpi_ibm_exit(void);
121 /****************************************************************************
130 struct acpi_driver
*driver
;
133 int (*read
) (char *);
134 int (*write
) (char *);
137 void (*notify
) (struct ibm_struct
*, u32
);
140 struct acpi_device
*device
;
142 int driver_registered
;
145 int notify_installed
;
150 static struct ibm_struct ibms
[];
151 static int set_ibm_param(const char *val
, struct kernel_param
*kp
);
152 static int ibm_init(struct ibm_struct
*ibm
);
153 static void ibm_exit(struct ibm_struct
*ibm
);
156 static void dispatch_notify(acpi_handle handle
, u32 event
, void *data
);
157 static int setup_notify(struct ibm_struct
*ibm
);
158 static int ibm_device_add(struct acpi_device
*device
);
159 static int register_ibmacpi_subdriver(struct ibm_struct
*ibm
);
166 #ifdef CONFIG_THINKPAD_ACPI_BAY
167 static int bay_status_supported
, bay_eject_supported
;
168 static int bay_status2_supported
, bay_eject2_supported
;
170 static acpi_handle bay_handle
, bay_ej_handle
;
171 static acpi_handle bay2_handle
, bay2_ej_handle
;
173 static int bay_init(void);
174 static void bay_notify(struct ibm_struct
*ibm
, u32 event
);
175 static int bay_read(char *p
);
176 static int bay_write(char *buf
);
177 #endif /* CONFIG_THINKPAD_ACPI_BAY */
184 static acpi_handle beep_handle
;
186 static int beep_read(char *p
);
187 static int beep_write(char *buf
);
191 * Bluetooth subdriver
194 static int bluetooth_supported
;
196 static int bluetooth_init(void);
197 static int bluetooth_status(void);
198 static int bluetooth_read(char *p
);
199 static int bluetooth_write(char *buf
);
203 * Brightness (backlight) subdriver
206 static struct backlight_device
*ibm_backlight_device
;
207 static int brightness_offset
= 0x31;
209 static int brightness_init(void);
210 static void brightness_exit(void);
211 static int brightness_get(struct backlight_device
*bd
);
212 static int brightness_set(int value
);
213 static int brightness_update_status(struct backlight_device
*bd
);
214 static int brightness_read(char *p
);
215 static int brightness_write(char *buf
);
222 static int cmos_eval(int cmos_cmd
);
223 static int cmos_read(char *p
);
224 static int cmos_write(char *buf
);
231 static acpi_handle pci_handle
;
232 #ifdef CONFIG_THINKPAD_ACPI_DOCK
233 static acpi_handle dock_handle
;
235 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
236 static int dock_read(char *p
);
237 static int dock_write(char *buf
);
238 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
245 static int ecdump_read(char *p
) ;
246 static int ecdump_write(char *buf
);
253 enum { /* Fan control constants */
254 fan_status_offset
= 0x2f, /* EC register 0x2f */
255 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
256 * 0x84 must be read before 0x85 */
258 IBMACPI_FAN_EC_DISENGAGED
= 0x40, /* EC mode: tachometer
260 IBMACPI_FAN_EC_AUTO
= 0x80, /* EC mode: auto fan
264 enum fan_status_access_mode
{
265 IBMACPI_FAN_NONE
= 0, /* No fan status or control */
266 IBMACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
267 IBMACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
270 enum fan_control_access_mode
{
271 IBMACPI_FAN_WR_NONE
= 0, /* No fan control */
272 IBMACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
273 IBMACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
274 IBMACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
277 enum fan_control_commands
{
278 IBMACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
279 IBMACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
280 IBMACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
281 * and also watchdog cmd */
284 static enum fan_status_access_mode fan_status_access_mode
;
285 static enum fan_control_access_mode fan_control_access_mode
;
286 static enum fan_control_commands fan_control_commands
;
287 static int fan_control_status_known
;
288 static u8 fan_control_initial_status
;
289 static int fan_watchdog_maxinterval
;
291 static acpi_handle fans_handle
, gfan_handle
, sfan_handle
;
293 static int fan_init(void);
294 static void fan_exit(void);
295 static int fan_get_status(u8
*status
);
296 static int fan_get_speed(unsigned int *speed
);
297 static void fan_watchdog_fire(struct work_struct
*ignored
);
298 static void fan_watchdog_reset(void);
299 static int fan_set_level(int level
);
300 static int fan_set_enable(void);
301 static int fan_set_disable(void);
302 static int fan_set_speed(int speed
);
303 static int fan_read(char *p
);
304 static int fan_write(char *buf
);
305 static int fan_write_cmd_level(const char *cmd
, int *rc
);
306 static int fan_write_cmd_enable(const char *cmd
, int *rc
);
307 static int fan_write_cmd_disable(const char *cmd
, int *rc
);
308 static int fan_write_cmd_speed(const char *cmd
, int *rc
);
309 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
);
316 static int hotkey_supported
;
317 static int hotkey_mask_supported
;
318 static int hotkey_orig_status
;
319 static int hotkey_orig_mask
;
321 static int hotkey_init(void);
322 static void hotkey_exit(void);
323 static int hotkey_get(int *status
, int *mask
);
324 static int hotkey_set(int status
, int mask
);
325 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
);
326 static int hotkey_read(char *p
);
327 static int hotkey_write(char *buf
);
334 enum led_access_mode
{
335 IBMACPI_LED_NONE
= 0,
336 IBMACPI_LED_570
, /* 570 */
337 IBMACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
338 IBMACPI_LED_NEW
, /* all others */
341 enum { /* For IBMACPI_LED_OLD */
342 IBMACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
343 IBMACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
344 IBMACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
347 static enum led_access_mode led_supported
;
348 static acpi_handle led_handle
;
350 static int led_init(void);
351 static int led_read(char *p
);
352 static int led_write(char *buf
);
355 * Light (thinklight) subdriver
358 static int light_supported
;
359 static int light_status_supported
;
360 static acpi_handle lght_handle
, ledb_handle
;
362 static int light_init(void);
363 static int light_read(char *p
);
364 static int light_write(char *buf
);
371 enum thermal_access_mode
{
372 IBMACPI_THERMAL_NONE
= 0, /* No thermal support */
373 IBMACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
374 IBMACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
375 IBMACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
376 IBMACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
379 #define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
380 struct ibm_thermal_sensors_struct
{
381 s32 temp
[IBMACPI_MAX_THERMAL_SENSORS
];
384 static int thermal_init(void);
385 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
);
386 static int thermal_read(char *p
);
393 enum video_access_mode
{
394 IBMACPI_VIDEO_NONE
= 0,
395 IBMACPI_VIDEO_570
, /* 570 */
396 IBMACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
397 IBMACPI_VIDEO_NEW
, /* all others */
400 static enum video_access_mode video_supported
;
401 static int video_orig_autosw
;
402 static acpi_handle vid_handle
, vid2_handle
;
404 static int video_init(void);
405 static void video_exit(void);
406 static int video_status(void);
407 static int video_autosw(void);
408 static int video_switch(void);
409 static int video_switch2(int status
);
410 static int video_expand(void);
411 static int video_read(char *p
);
412 static int video_write(char *buf
);
419 static int volume_offset
= 0x30;
421 static int volume_read(char *p
);
422 static int volume_write(char *buf
);
429 static int wan_supported
;
431 static int wan_init(void);
432 static int wan_status(void);
433 static int wan_read(char *p
);
434 static int wan_write(char *buf
);
437 #endif /* __IBM_ACPI_H */