ACPI: thinkpad-acpi: clean up probing and move init to subdrivers
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / drivers / misc / thinkpad_acpi.h
blob06d4c3839afdeaca1600bb340b0fe626eb2b82a1
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 dbg_printk(a_dbg_level, format, arg...) \
80 do { if (dbg_level & a_dbg_level) \
81 printk(IBM_DEBUG "%s: " format, __func__ , ## arg); } while (0)
82 #ifdef CONFIG_THINKPAD_ACPI_DEBUG
83 #define vdbg_printk(a_dbg_level, format, arg...) \
84 dbg_printk(a_dbg_level, format, ## arg)
85 #else
86 #define vdbg_printk(a_dbg_level, format, arg...)
87 #endif
89 /* ACPI HIDs */
90 #define IBM_HKEY_HID "IBM0068"
91 #define IBM_PCI_HID "PNP0A03"
93 /* ACPI helpers */
94 static int acpi_evalf(acpi_handle handle,
95 void *res, char *method, char *fmt, ...);
96 static int acpi_ec_read(int i, u8 * p);
97 static int acpi_ec_write(int i, u8 v);
98 static int _sta(acpi_handle handle);
100 /* ACPI handles */
101 static acpi_handle root_handle; /* root namespace */
102 static acpi_handle ec_handle; /* EC */
103 static acpi_handle ecrd_handle, ecwr_handle; /* 570 EC access */
104 static acpi_handle cmos_handle, hkey_handle; /* basic thinkpad handles */
106 static void ibm_handle_init(char *name,
107 acpi_handle *handle, acpi_handle parent,
108 char **paths, int num_paths, char **path);
109 #define IBM_HANDLE_INIT(object) \
110 ibm_handle_init(#object, &object##_handle, *object##_parent, \
111 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
113 /* procfs support */
114 static struct proc_dir_entry *proc_dir;
115 static int thinkpad_acpi_driver_init(void);
116 static int thinkpad_acpi_driver_read(char *p);
118 /* procfs helpers */
119 static int dispatch_read(char *page, char **start, off_t off, int count,
120 int *eof, void *data);
121 static int dispatch_write(struct file *file, const char __user * userbuf,
122 unsigned long count, void *data);
123 static char *next_cmd(char **cmds);
125 /* Module */
126 static int experimental;
127 static u32 dbg_level;
128 static char *ibm_thinkpad_ec_found;
130 static char* check_dmi_for_ec(void);
131 static int thinkpad_acpi_module_init(void);
132 static void thinkpad_acpi_module_exit(void);
135 /****************************************************************************
136 * Subdrivers
139 struct ibm_struct {
140 char *name;
141 char param[32];
143 char *hid;
144 struct acpi_driver *driver;
146 int (*init) (void);
147 int (*read) (char *);
148 int (*write) (char *);
149 void (*exit) (void);
151 void (*notify) (struct ibm_struct *, u32);
152 acpi_handle *handle;
153 int type;
154 struct acpi_device *device;
156 int driver_registered;
157 int proc_created;
158 int init_called;
159 int notify_installed;
161 int experimental;
164 static struct ibm_struct ibms[];
165 static int set_ibm_param(const char *val, struct kernel_param *kp);
166 static int ibm_init(struct ibm_struct *ibm);
167 static void ibm_exit(struct ibm_struct *ibm);
169 /* ACPI devices */
170 static void dispatch_notify(acpi_handle handle, u32 event, void *data);
171 static int setup_notify(struct ibm_struct *ibm);
172 static int ibm_device_add(struct acpi_device *device);
173 static int register_tpacpi_subdriver(struct ibm_struct *ibm);
177 * Bay subdriver
180 #ifdef CONFIG_THINKPAD_ACPI_BAY
181 static int bay_status_supported, bay_eject_supported;
182 static int bay_status2_supported, bay_eject2_supported;
184 static acpi_handle bay_handle, bay_ej_handle;
185 static acpi_handle bay2_handle, bay2_ej_handle;
187 static int bay_init(void);
188 static void bay_notify(struct ibm_struct *ibm, u32 event);
189 static int bay_read(char *p);
190 static int bay_write(char *buf);
191 #endif /* CONFIG_THINKPAD_ACPI_BAY */
195 * Beep subdriver
198 static acpi_handle beep_handle;
200 static int beep_read(char *p);
201 static int beep_write(char *buf);
205 * Bluetooth subdriver
208 static int bluetooth_supported;
210 static int bluetooth_init(void);
211 static int bluetooth_status(void);
212 static int bluetooth_read(char *p);
213 static int bluetooth_write(char *buf);
217 * Brightness (backlight) subdriver
220 static struct backlight_device *ibm_backlight_device;
221 static int brightness_offset = 0x31;
223 static int brightness_init(void);
224 static void brightness_exit(void);
225 static int brightness_get(struct backlight_device *bd);
226 static int brightness_set(int value);
227 static int brightness_update_status(struct backlight_device *bd);
228 static int brightness_read(char *p);
229 static int brightness_write(char *buf);
233 * CMOS subdriver
236 static int cmos_eval(int cmos_cmd);
237 static int cmos_read(char *p);
238 static int cmos_write(char *buf);
242 * Dock subdriver
245 #ifdef CONFIG_THINKPAD_ACPI_DOCK
246 static acpi_handle pci_handle;
247 static acpi_handle dock_handle;
249 static void dock_notify(struct ibm_struct *ibm, u32 event);
250 static int dock_read(char *p);
251 static int dock_write(char *buf);
252 #endif /* CONFIG_THINKPAD_ACPI_DOCK */
256 * EC dump subdriver
259 static int ecdump_read(char *p) ;
260 static int ecdump_write(char *buf);
264 * Fan subdriver
267 enum { /* Fan control constants */
268 fan_status_offset = 0x2f, /* EC register 0x2f */
269 fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
270 * 0x84 must be read before 0x85 */
272 TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */
273 TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */
276 enum fan_status_access_mode {
277 TPACPI_FAN_NONE = 0, /* No fan status or control */
278 TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
279 TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
282 enum fan_control_access_mode {
283 TPACPI_FAN_WR_NONE = 0, /* No fan control */
284 TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
285 TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
286 TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
289 enum fan_control_commands {
290 TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
291 TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
292 TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
293 * and also watchdog cmd */
296 static enum fan_status_access_mode fan_status_access_mode;
297 static enum fan_control_access_mode fan_control_access_mode;
298 static enum fan_control_commands fan_control_commands;
299 static int fan_control_status_known;
300 static u8 fan_control_initial_status;
301 static int fan_watchdog_maxinterval;
303 static acpi_handle fans_handle, gfan_handle, sfan_handle;
305 static int fan_init(void);
306 static void fan_exit(void);
307 static int fan_get_status(u8 *status);
308 static int fan_get_speed(unsigned int *speed);
309 static void fan_watchdog_fire(struct work_struct *ignored);
310 static void fan_watchdog_reset(void);
311 static int fan_set_level(int level);
312 static int fan_set_enable(void);
313 static int fan_set_disable(void);
314 static int fan_set_speed(int speed);
315 static int fan_read(char *p);
316 static int fan_write(char *buf);
317 static int fan_write_cmd_level(const char *cmd, int *rc);
318 static int fan_write_cmd_enable(const char *cmd, int *rc);
319 static int fan_write_cmd_disable(const char *cmd, int *rc);
320 static int fan_write_cmd_speed(const char *cmd, int *rc);
321 static int fan_write_cmd_watchdog(const char *cmd, int *rc);
325 * Hotkey subdriver
328 static int hotkey_supported;
329 static int hotkey_mask_supported;
330 static int hotkey_orig_status;
331 static int hotkey_orig_mask;
333 static int hotkey_init(void);
334 static void hotkey_exit(void);
335 static int hotkey_get(int *status, int *mask);
336 static int hotkey_set(int status, int mask);
337 static void hotkey_notify(struct ibm_struct *ibm, u32 event);
338 static int hotkey_read(char *p);
339 static int hotkey_write(char *buf);
343 * LED subdriver
346 enum led_access_mode {
347 TPACPI_LED_NONE = 0,
348 TPACPI_LED_570, /* 570 */
349 TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
350 TPACPI_LED_NEW, /* all others */
353 enum { /* For TPACPI_LED_OLD */
354 TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */
355 TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */
356 TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */
359 static enum led_access_mode led_supported;
360 static acpi_handle led_handle;
362 static int led_init(void);
363 static int led_read(char *p);
364 static int led_write(char *buf);
367 * Light (thinklight) subdriver
370 static int light_supported;
371 static int light_status_supported;
372 static acpi_handle lght_handle, ledb_handle;
374 static int light_init(void);
375 static int light_read(char *p);
376 static int light_write(char *buf);
380 * Thermal subdriver
383 enum thermal_access_mode {
384 TPACPI_THERMAL_NONE = 0, /* No thermal support */
385 TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
386 TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
387 TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
388 TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
391 #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
392 struct ibm_thermal_sensors_struct {
393 s32 temp[TPACPI_MAX_THERMAL_SENSORS];
396 static int thermal_init(void);
397 static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
398 static int thermal_read(char *p);
402 * Video subdriver
405 enum video_access_mode {
406 TPACPI_VIDEO_NONE = 0,
407 TPACPI_VIDEO_570, /* 570 */
408 TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */
409 TPACPI_VIDEO_NEW, /* all others */
412 static enum video_access_mode video_supported;
413 static int video_orig_autosw;
414 static acpi_handle vid_handle, vid2_handle;
416 static int video_init(void);
417 static void video_exit(void);
418 static int video_status(void);
419 static int video_autosw(void);
420 static int video_switch(void);
421 static int video_switch2(int status);
422 static int video_expand(void);
423 static int video_read(char *p);
424 static int video_write(char *buf);
428 * Volume subdriver
431 static int volume_offset = 0x30;
433 static int volume_read(char *p);
434 static int volume_write(char *buf);
438 * Wan subdriver
441 static int wan_supported;
443 static int wan_init(void);
444 static int wan_status(void);
445 static int wan_read(char *p);
446 static int wan_write(char *buf);
449 #endif /* __THINKPAD_ACPI_H */