ACPI: thinkpad-acpi: add subdriver debug statements
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / misc / thinkpad_acpi.h
blobbeb1447a7f3fc38b74033bfb1767527cb07ff77d
1 /*
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
21 * 02110-1301, USA.
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>
35 #include <linux/fb.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 /****************************************************************************
47 * Main driver
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/"
55 #define IBM_DIR "ibm"
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)))
77 /* Debugging */
78 #define TPACPI_DBG_ALL 0xffff
79 #define TPACPI_DBG_ALL 0xffff
80 #define TPACPI_DBG_INIT 0x0001
81 #define TPACPI_DBG_EXIT 0x0002
82 #define dbg_printk(a_dbg_level, format, arg...) \
83 do { if (dbg_level & a_dbg_level) \
84 printk(IBM_DEBUG "%s: " format, __func__ , ## arg); } while (0)
85 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
86 #define vdbg_printk(a_dbg_level, format, arg...) \
87 dbg_printk(a_dbg_level, format, ## arg)
88 static const char *str_supported(int is_supported);
89 #else
90 #define vdbg_printk(a_dbg_level, format, arg...)
91 #endif
93 /* ACPI HIDs */
94 #define IBM_HKEY_HID "IBM0068"
95 #define IBM_PCI_HID "PNP0A03"
97 /* ACPI helpers */
98 static int acpi_evalf(acpi_handle handle,
99 void *res, char *method, char *fmt, ...);
100 static int acpi_ec_read(int i, u8 * p);
101 static int acpi_ec_write(int i, u8 v);
102 static int _sta(acpi_handle handle);
104 /* ACPI handles */
105 static acpi_handle root_handle; /* root namespace */
106 static acpi_handle ec_handle; /* EC */
107 static acpi_handle ecrd_handle, ecwr_handle; /* 570 EC access */
108 static acpi_handle cmos_handle, hkey_handle; /* basic thinkpad handles */
110 static void ibm_handle_init(char *name,
111 acpi_handle *handle, acpi_handle parent,
112 char **paths, int num_paths, char **path);
113 #define IBM_HANDLE_INIT(object) \
114 ibm_handle_init(#object, &object##_handle, *object##_parent, \
115 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
117 /* procfs support */
118 static struct proc_dir_entry *proc_dir;
119 static int thinkpad_acpi_driver_init(void);
120 static int thinkpad_acpi_driver_read(char *p);
122 /* procfs helpers */
123 static int dispatch_read(char *page, char **start, off_t off, int count,
124 int *eof, void *data);
125 static int dispatch_write(struct file *file, const char __user * userbuf,
126 unsigned long count, void *data);
127 static char *next_cmd(char **cmds);
129 /* Module */
130 static int experimental;
131 static u32 dbg_level;
132 static char *ibm_thinkpad_ec_found;
134 static char* check_dmi_for_ec(void);
135 static int thinkpad_acpi_module_init(void);
136 static void thinkpad_acpi_module_exit(void);
139 /****************************************************************************
140 * Subdrivers
143 struct ibm_struct {
144 char *name;
145 char param[32];
147 char *hid;
148 struct acpi_driver *driver;
150 int (*init) (void);
151 int (*read) (char *);
152 int (*write) (char *);
153 void (*exit) (void);
155 void (*notify) (struct ibm_struct *, u32);
156 acpi_handle *handle;
157 int type;
158 struct acpi_device *device;
160 int driver_registered;
161 int proc_created;
162 int init_called;
163 int notify_installed;
165 int experimental;
168 static struct ibm_struct ibms[];
169 static int set_ibm_param(const char *val, struct kernel_param *kp);
170 static int ibm_init(struct ibm_struct *ibm);
171 static void ibm_exit(struct ibm_struct *ibm);
173 /* ACPI devices */
174 static void dispatch_notify(acpi_handle handle, u32 event, void *data);
175 static int setup_notify(struct ibm_struct *ibm);
176 static int ibm_device_add(struct acpi_device *device);
177 static int register_tpacpi_subdriver(struct ibm_struct *ibm);
181 * Bay subdriver
184 #ifdef CONFIG_THINKPAD_ACPI_BAY
185 static int bay_status_supported, bay_eject_supported;
186 static int bay_status2_supported, bay_eject2_supported;
188 static acpi_handle bay_handle, bay_ej_handle;
189 static acpi_handle bay2_handle, bay2_ej_handle;
191 static int bay_init(void);
192 static void bay_notify(struct ibm_struct *ibm, u32 event);
193 static int bay_read(char *p);
194 static int bay_write(char *buf);
195 #endif /* CONFIG_THINKPAD_ACPI_BAY */
199 * Beep subdriver
202 static acpi_handle beep_handle;
204 static int beep_read(char *p);
205 static int beep_write(char *buf);
209 * Bluetooth subdriver
212 static int bluetooth_supported;
214 static int bluetooth_init(void);
215 static int bluetooth_status(void);
216 static int bluetooth_read(char *p);
217 static int bluetooth_write(char *buf);
221 * Brightness (backlight) subdriver
224 static struct backlight_device *ibm_backlight_device;
225 static int brightness_offset = 0x31;
227 static int brightness_init(void);
228 static void brightness_exit(void);
229 static int brightness_get(struct backlight_device *bd);
230 static int brightness_set(int value);
231 static int brightness_update_status(struct backlight_device *bd);
232 static int brightness_read(char *p);
233 static int brightness_write(char *buf);
237 * CMOS subdriver
240 static int cmos_eval(int cmos_cmd);
241 static int cmos_read(char *p);
242 static int cmos_write(char *buf);
246 * Dock subdriver
249 #ifdef CONFIG_THINKPAD_ACPI_DOCK
250 static acpi_handle pci_handle;
251 static acpi_handle dock_handle;
253 static void dock_notify(struct ibm_struct *ibm, u32 event);
254 static int dock_read(char *p);
255 static int dock_write(char *buf);
256 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
260 * EC dump subdriver
263 static int ecdump_read(char *p) ;
264 static int ecdump_write(char *buf);
268 * Fan subdriver
271 enum { /* Fan control constants */
272 fan_status_offset = 0x2f, /* EC register 0x2f */
273 fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
274 * 0x84 must be read before 0x85 */
276 TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */
277 TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */
280 enum fan_status_access_mode {
281 TPACPI_FAN_NONE = 0, /* No fan status or control */
282 TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
283 TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
286 enum fan_control_access_mode {
287 TPACPI_FAN_WR_NONE = 0, /* No fan control */
288 TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
289 TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
290 TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
293 enum fan_control_commands {
294 TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
295 TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
296 TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
297 * and also watchdog cmd */
300 static enum fan_status_access_mode fan_status_access_mode;
301 static enum fan_control_access_mode fan_control_access_mode;
302 static enum fan_control_commands fan_control_commands;
303 static int fan_control_status_known;
304 static u8 fan_control_initial_status;
305 static int fan_watchdog_maxinterval;
307 static acpi_handle fans_handle, gfan_handle, sfan_handle;
309 static int fan_init(void);
310 static void fan_exit(void);
311 static int fan_get_status(u8 *status);
312 static int fan_get_speed(unsigned int *speed);
313 static void fan_watchdog_fire(struct work_struct *ignored);
314 static void fan_watchdog_reset(void);
315 static int fan_set_level(int level);
316 static int fan_set_enable(void);
317 static int fan_set_disable(void);
318 static int fan_set_speed(int speed);
319 static int fan_read(char *p);
320 static int fan_write(char *buf);
321 static int fan_write_cmd_level(const char *cmd, int *rc);
322 static int fan_write_cmd_enable(const char *cmd, int *rc);
323 static int fan_write_cmd_disable(const char *cmd, int *rc);
324 static int fan_write_cmd_speed(const char *cmd, int *rc);
325 static int fan_write_cmd_watchdog(const char *cmd, int *rc);
329 * Hotkey subdriver
332 static int hotkey_supported;
333 static int hotkey_mask_supported;
334 static int hotkey_orig_status;
335 static int hotkey_orig_mask;
337 static int hotkey_init(void);
338 static void hotkey_exit(void);
339 static int hotkey_get(int *status, int *mask);
340 static int hotkey_set(int status, int mask);
341 static void hotkey_notify(struct ibm_struct *ibm, u32 event);
342 static int hotkey_read(char *p);
343 static int hotkey_write(char *buf);
347 * LED subdriver
350 enum led_access_mode {
351 TPACPI_LED_NONE = 0,
352 TPACPI_LED_570, /* 570 */
353 TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
354 TPACPI_LED_NEW, /* all others */
357 enum { /* For TPACPI_LED_OLD */
358 TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */
359 TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */
360 TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */
363 static enum led_access_mode led_supported;
364 static acpi_handle led_handle;
366 static int led_init(void);
367 static int led_read(char *p);
368 static int led_write(char *buf);
371 * Light (thinklight) subdriver
374 static int light_supported;
375 static int light_status_supported;
376 static acpi_handle lght_handle, ledb_handle;
378 static int light_init(void);
379 static int light_read(char *p);
380 static int light_write(char *buf);
384 * Thermal subdriver
387 enum thermal_access_mode {
388 TPACPI_THERMAL_NONE = 0, /* No thermal support */
389 TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
390 TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
391 TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
392 TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
395 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
396 struct ibm_thermal_sensors_struct {
397 s32 temp[TPACPI_MAX_THERMAL_SENSORS];
400 static int thermal_init(void);
401 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
402 static int thermal_read(char *p);
406 * Video subdriver
409 enum video_access_mode {
410 TPACPI_VIDEO_NONE = 0,
411 TPACPI_VIDEO_570, /* 570 */
412 TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */
413 TPACPI_VIDEO_NEW, /* all others */
416 static enum video_access_mode video_supported;
417 static int video_orig_autosw;
418 static acpi_handle vid_handle, vid2_handle;
420 static int video_init(void);
421 static void video_exit(void);
422 static int video_status(void);
423 static int video_autosw(void);
424 static int video_switch(void);
425 static int video_switch2(int status);
426 static int video_expand(void);
427 static int video_read(char *p);
428 static int video_write(char *buf);
432 * Volume subdriver
435 static int volume_offset = 0x30;
437 static int volume_read(char *p);
438 static int volume_write(char *buf);
442 * Wan subdriver
445 static int wan_supported;
447 static int wan_init(void);
448 static int wan_status(void);
449 static int wan_read(char *p);
450 static int wan_write(char *buf);
453 #endif /* __THINKPAD_ACPI_H */