2 * thinkpad_acpi.h - 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 __THINKPAD_ACPI_H__
25 #define __THINKPAD_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 "thinkpad"
51 #define IBM_DESC "ThinkPad ACPI Extras"
52 #define IBM_FILE "thinkpad_acpi"
53 #define IBM_URL "http://ibm-acpi.sf.net/"
56 #define IBM_ACPI_EVENT_PREFIX "ibm"
58 #define IBM_LOG IBM_FILE ": "
59 #define IBM_ERR KERN_ERR IBM_LOG
60 #define IBM_NOTICE KERN_NOTICE IBM_LOG
61 #define IBM_INFO KERN_INFO IBM_LOG
62 #define IBM_DEBUG KERN_DEBUG IBM_LOG
64 #define IBM_MAX_ACPI_ARGS 3
66 /* ThinkPad CMOS commands */
67 #define TP_CMOS_VOLUME_DOWN 0
68 #define TP_CMOS_VOLUME_UP 1
69 #define TP_CMOS_VOLUME_MUTE 2
70 #define TP_CMOS_BRIGHTNESS_UP 4
71 #define TP_CMOS_BRIGHTNESS_DOWN 5
73 #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
74 #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
75 #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
78 #define IBM_HKEY_HID "IBM0068"
79 #define IBM_PCI_HID "PNP0A03"
82 static int acpi_evalf(acpi_handle handle
,
83 void *res
, char *method
, char *fmt
, ...);
84 static int acpi_ec_read(int i
, u8
* p
);
85 static int acpi_ec_write(int i
, u8 v
);
86 static int _sta(acpi_handle handle
);
89 static acpi_handle root_handle
; /* root namespace */
90 static acpi_handle ec_handle
; /* EC */
91 static acpi_handle ecrd_handle
, ecwr_handle
; /* 570 EC access */
92 static acpi_handle cmos_handle
, hkey_handle
; /* basic thinkpad handles */
94 static void ibm_handle_init(char *name
,
95 acpi_handle
* handle
, acpi_handle parent
,
96 char **paths
, int num_paths
, char **path
);
97 #define IBM_HANDLE_INIT(object) \
98 ibm_handle_init(#object, &object##_handle, *object##_parent, \
99 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
102 static struct proc_dir_entry
*proc_dir
;
103 static int thinkpad_acpi_driver_init(void);
104 static int thinkpad_acpi_driver_read(char *p
);
107 static int dispatch_read(char *page
, char **start
, off_t off
, int count
,
108 int *eof
, void *data
);
109 static int dispatch_write(struct file
*file
, const char __user
* userbuf
,
110 unsigned long count
, void *data
);
111 static char *next_cmd(char **cmds
);
114 static int experimental
;
115 static char *ibm_thinkpad_ec_found
;
117 static char* check_dmi_for_ec(void);
118 static int acpi_ibm_init(void);
119 static void acpi_ibm_exit(void);
122 /****************************************************************************
131 struct acpi_driver
*driver
;
134 int (*read
) (char *);
135 int (*write
) (char *);
138 void (*notify
) (struct ibm_struct
*, u32
);
141 struct acpi_device
*device
;
143 int driver_registered
;
146 int notify_installed
;
151 static struct ibm_struct ibms
[];
152 static int set_ibm_param(const char *val
, struct kernel_param
*kp
);
153 static int ibm_init(struct ibm_struct
*ibm
);
154 static void ibm_exit(struct ibm_struct
*ibm
);
157 static void dispatch_notify(acpi_handle handle
, u32 event
, void *data
);
158 static int setup_notify(struct ibm_struct
*ibm
);
159 static int ibm_device_add(struct acpi_device
*device
);
160 static int register_tpacpi_subdriver(struct ibm_struct
*ibm
);
167 #ifdef CONFIG_THINKPAD_ACPI_BAY
168 static int bay_status_supported
, bay_eject_supported
;
169 static int bay_status2_supported
, bay_eject2_supported
;
171 static acpi_handle bay_handle
, bay_ej_handle
;
172 static acpi_handle bay2_handle
, bay2_ej_handle
;
174 static int bay_init(void);
175 static void bay_notify(struct ibm_struct
*ibm
, u32 event
);
176 static int bay_read(char *p
);
177 static int bay_write(char *buf
);
178 #endif /* CONFIG_THINKPAD_ACPI_BAY */
185 static acpi_handle beep_handle
;
187 static int beep_read(char *p
);
188 static int beep_write(char *buf
);
192 * Bluetooth subdriver
195 static int bluetooth_supported
;
197 static int bluetooth_init(void);
198 static int bluetooth_status(void);
199 static int bluetooth_read(char *p
);
200 static int bluetooth_write(char *buf
);
204 * Brightness (backlight) subdriver
207 static struct backlight_device
*ibm_backlight_device
;
208 static int brightness_offset
= 0x31;
210 static int brightness_init(void);
211 static void brightness_exit(void);
212 static int brightness_get(struct backlight_device
*bd
);
213 static int brightness_set(int value
);
214 static int brightness_update_status(struct backlight_device
*bd
);
215 static int brightness_read(char *p
);
216 static int brightness_write(char *buf
);
223 static int cmos_eval(int cmos_cmd
);
224 static int cmos_read(char *p
);
225 static int cmos_write(char *buf
);
232 static acpi_handle pci_handle
;
233 #ifdef CONFIG_THINKPAD_ACPI_DOCK
234 static acpi_handle dock_handle
;
236 static void dock_notify(struct ibm_struct
*ibm
, u32 event
);
237 static int dock_read(char *p
);
238 static int dock_write(char *buf
);
239 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
246 static int ecdump_read(char *p
) ;
247 static int ecdump_write(char *buf
);
254 enum { /* Fan control constants */
255 fan_status_offset
= 0x2f, /* EC register 0x2f */
256 fan_rpm_offset
= 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
257 * 0x84 must be read before 0x85 */
259 IBMACPI_FAN_EC_DISENGAGED
= 0x40, /* EC mode: tachometer
261 IBMACPI_FAN_EC_AUTO
= 0x80, /* EC mode: auto fan
265 enum fan_status_access_mode
{
266 IBMACPI_FAN_NONE
= 0, /* No fan status or control */
267 IBMACPI_FAN_RD_ACPI_GFAN
, /* Use ACPI GFAN */
268 IBMACPI_FAN_RD_TPEC
, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
271 enum fan_control_access_mode
{
272 IBMACPI_FAN_WR_NONE
= 0, /* No fan control */
273 IBMACPI_FAN_WR_ACPI_SFAN
, /* Use ACPI SFAN */
274 IBMACPI_FAN_WR_TPEC
, /* Use ACPI EC reg 0x2f */
275 IBMACPI_FAN_WR_ACPI_FANS
, /* Use ACPI FANS and EC reg 0x2f */
278 enum fan_control_commands
{
279 IBMACPI_FAN_CMD_SPEED
= 0x0001, /* speed command */
280 IBMACPI_FAN_CMD_LEVEL
= 0x0002, /* level command */
281 IBMACPI_FAN_CMD_ENABLE
= 0x0004, /* enable/disable cmd,
282 * and also watchdog cmd */
285 static enum fan_status_access_mode fan_status_access_mode
;
286 static enum fan_control_access_mode fan_control_access_mode
;
287 static enum fan_control_commands fan_control_commands
;
288 static int fan_control_status_known
;
289 static u8 fan_control_initial_status
;
290 static int fan_watchdog_maxinterval
;
292 static acpi_handle fans_handle
, gfan_handle
, sfan_handle
;
294 static int fan_init(void);
295 static void fan_exit(void);
296 static int fan_get_status(u8
*status
);
297 static int fan_get_speed(unsigned int *speed
);
298 static void fan_watchdog_fire(struct work_struct
*ignored
);
299 static void fan_watchdog_reset(void);
300 static int fan_set_level(int level
);
301 static int fan_set_enable(void);
302 static int fan_set_disable(void);
303 static int fan_set_speed(int speed
);
304 static int fan_read(char *p
);
305 static int fan_write(char *buf
);
306 static int fan_write_cmd_level(const char *cmd
, int *rc
);
307 static int fan_write_cmd_enable(const char *cmd
, int *rc
);
308 static int fan_write_cmd_disable(const char *cmd
, int *rc
);
309 static int fan_write_cmd_speed(const char *cmd
, int *rc
);
310 static int fan_write_cmd_watchdog(const char *cmd
, int *rc
);
317 static int hotkey_supported
;
318 static int hotkey_mask_supported
;
319 static int hotkey_orig_status
;
320 static int hotkey_orig_mask
;
322 static int hotkey_init(void);
323 static void hotkey_exit(void);
324 static int hotkey_get(int *status
, int *mask
);
325 static int hotkey_set(int status
, int mask
);
326 static void hotkey_notify(struct ibm_struct
*ibm
, u32 event
);
327 static int hotkey_read(char *p
);
328 static int hotkey_write(char *buf
);
335 enum led_access_mode
{
336 IBMACPI_LED_NONE
= 0,
337 IBMACPI_LED_570
, /* 570 */
338 IBMACPI_LED_OLD
, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
339 IBMACPI_LED_NEW
, /* all others */
342 enum { /* For IBMACPI_LED_OLD */
343 IBMACPI_LED_EC_HLCL
= 0x0c, /* EC reg to get led to power on */
344 IBMACPI_LED_EC_HLBL
= 0x0d, /* EC reg to blink a lit led */
345 IBMACPI_LED_EC_HLMS
= 0x0e, /* EC reg to select led to command */
348 static enum led_access_mode led_supported
;
349 static acpi_handle led_handle
;
351 static int led_init(void);
352 static int led_read(char *p
);
353 static int led_write(char *buf
);
356 * Light (thinklight) subdriver
359 static int light_supported
;
360 static int light_status_supported
;
361 static acpi_handle lght_handle
, ledb_handle
;
363 static int light_init(void);
364 static int light_read(char *p
);
365 static int light_write(char *buf
);
372 enum thermal_access_mode
{
373 IBMACPI_THERMAL_NONE
= 0, /* No thermal support */
374 IBMACPI_THERMAL_ACPI_TMP07
, /* Use ACPI TMP0-7 */
375 IBMACPI_THERMAL_ACPI_UPDT
, /* Use ACPI TMP0-7 with UPDT */
376 IBMACPI_THERMAL_TPEC_8
, /* Use ACPI EC regs, 8 sensors */
377 IBMACPI_THERMAL_TPEC_16
, /* Use ACPI EC regs, 16 sensors */
380 #define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
381 struct ibm_thermal_sensors_struct
{
382 s32 temp
[IBMACPI_MAX_THERMAL_SENSORS
];
385 static int thermal_init(void);
386 static int thermal_get_sensors(struct ibm_thermal_sensors_struct
*s
);
387 static int thermal_read(char *p
);
394 enum video_access_mode
{
395 IBMACPI_VIDEO_NONE
= 0,
396 IBMACPI_VIDEO_570
, /* 570 */
397 IBMACPI_VIDEO_770
, /* 600e/x, 770e, 770x */
398 IBMACPI_VIDEO_NEW
, /* all others */
401 static enum video_access_mode video_supported
;
402 static int video_orig_autosw
;
403 static acpi_handle vid_handle
, vid2_handle
;
405 static int video_init(void);
406 static void video_exit(void);
407 static int video_status(void);
408 static int video_autosw(void);
409 static int video_switch(void);
410 static int video_switch2(int status
);
411 static int video_expand(void);
412 static int video_read(char *p
);
413 static int video_write(char *buf
);
420 static int volume_offset
= 0x30;
422 static int volume_read(char *p
);
423 static int volume_write(char *buf
);
430 static int wan_supported
;
432 static int wan_init(void);
433 static int wan_status(void);
434 static int wan_read(char *p
);
435 static int wan_write(char *buf
);
438 #endif /* __THINKPAD_ACPI_H */