ACPI: thinkpad-acpi: rename module glue
[safe/jmp/linux-2.6] / drivers / misc / thinkpad_acpi.h
1 /*
2  *  thinkpad_acpi.h - ThinkPad ACPI Extras
3  *
4  *
5  *  Copyright (C) 2004-2005 Borislav Deianov <borislav@users.sf.net>
6  *  Copyright (C) 2006-2007 Henrique de Moraes Holschuh <hmh@hmh.eng.br>
7  *
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.
12  *
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.
17  *
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.
22  */
23
24 #ifndef __THINKPAD_ACPI_H__
25 #define __THINKPAD_ACPI_H__
26
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>
32
33 #include <linux/proc_fs.h>
34 #include <linux/backlight.h>
35 #include <linux/fb.h>
36 #include <asm/uaccess.h>
37
38 #include <linux/dmi.h>
39 #include <linux/jiffies.h>
40 #include <linux/workqueue.h>
41
42 #include <acpi/acpi_drivers.h>
43 #include <acpi/acnamesp.h>
44
45
46 /****************************************************************************
47  * Main driver
48  */
49
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/"
54
55 #define IBM_DIR "ibm"
56 #define IBM_ACPI_EVENT_PREFIX "ibm"
57
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
63
64 #define IBM_MAX_ACPI_ARGS 3
65
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
72
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)))
76
77 /* ACPI HIDs */
78 #define IBM_HKEY_HID    "IBM0068"
79 #define IBM_PCI_HID     "PNP0A03"
80
81 /* ACPI helpers */
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);
87
88 /* ACPI handles */
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 */
93
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)
100
101 /* procfs support */
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);
105
106 /* procfs helpers */
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);
112
113 /* Module */
114 static int experimental;
115 static char *ibm_thinkpad_ec_found;
116
117 static char* check_dmi_for_ec(void);
118 static int thinkpad_acpi_module_init(void);
119 static void thinkpad_acpi_module_exit(void);
120
121
122 /****************************************************************************
123  * Subdrivers
124  */
125
126 struct ibm_struct {
127         char *name;
128         char param[32];
129
130         char *hid;
131         struct acpi_driver *driver;
132
133         int (*init) (void);
134         int (*read) (char *);
135         int (*write) (char *);
136         void (*exit) (void);
137
138         void (*notify) (struct ibm_struct *, u32);
139         acpi_handle *handle;
140         int type;
141         struct acpi_device *device;
142
143         int driver_registered;
144         int proc_created;
145         int init_called;
146         int notify_installed;
147
148         int experimental;
149 };
150
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);
155
156 /* ACPI devices */
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);
161
162
163 /*
164  * Bay subdriver
165  */
166
167 #ifdef CONFIG_THINKPAD_ACPI_BAY
168 static int bay_status_supported, bay_eject_supported;
169 static int bay_status2_supported, bay_eject2_supported;
170
171 static acpi_handle bay_handle, bay_ej_handle;
172 static acpi_handle bay2_handle, bay2_ej_handle;
173
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 */
179
180
181 /*
182  * Beep subdriver
183  */
184
185 static acpi_handle beep_handle;
186
187 static int beep_read(char *p);
188 static int beep_write(char *buf);
189
190
191 /*
192  * Bluetooth subdriver
193  */
194
195 static int bluetooth_supported;
196
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);
201
202
203 /*
204  * Brightness (backlight) subdriver
205  */
206
207 static struct backlight_device *ibm_backlight_device;
208 static int brightness_offset = 0x31;
209
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);
217
218
219 /*
220  * CMOS subdriver
221  */
222
223 static int cmos_eval(int cmos_cmd);
224 static int cmos_read(char *p);
225 static int cmos_write(char *buf);
226
227
228 /*
229  * Dock subdriver
230  */
231
232 static acpi_handle pci_handle;
233 #ifdef CONFIG_THINKPAD_ACPI_DOCK
234 static acpi_handle dock_handle;
235
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 */
240
241
242 /*
243  * EC dump subdriver
244  */
245
246 static int ecdump_read(char *p) ;
247 static int ecdump_write(char *buf);
248
249
250 /*
251  * Fan subdriver
252  */
253
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 */
258
259         IBMACPI_FAN_EC_DISENGAGED       = 0x40, /* EC mode: tachometer
260                                                  * disengaged */
261         IBMACPI_FAN_EC_AUTO             = 0x80, /* EC mode: auto fan
262                                                  * control */
263 };
264
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 */
269 };
270
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 */
276 };
277
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 */
283 };
284
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;
291
292 static acpi_handle fans_handle, gfan_handle, sfan_handle;
293
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);
311
312
313 /*
314  * Hotkey subdriver
315  */
316
317 static int hotkey_supported;
318 static int hotkey_mask_supported;
319 static int hotkey_orig_status;
320 static int hotkey_orig_mask;
321
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);
329
330
331 /*
332  * LED subdriver
333  */
334
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 */
340 };
341
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 */
346 };
347
348 static enum led_access_mode led_supported;
349 static acpi_handle led_handle;
350
351 static int led_init(void);
352 static int led_read(char *p);
353 static int led_write(char *buf);
354
355 /*
356  * Light (thinklight) subdriver
357  */
358
359 static int light_supported;
360 static int light_status_supported;
361 static acpi_handle lght_handle, ledb_handle;
362
363 static int light_init(void);
364 static int light_read(char *p);
365 static int light_write(char *buf);
366
367
368 /*
369  * Thermal subdriver
370  */
371
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 */
378 };
379
380 #define IBMACPI_MAX_THERMAL_SENSORS 16  /* Max thermal sensors supported */
381 struct ibm_thermal_sensors_struct {
382         s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
383 };
384
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);
388
389
390 /*
391  * Video subdriver
392  */
393
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 */
399 };
400
401 static enum video_access_mode video_supported;
402 static int video_orig_autosw;
403 static acpi_handle vid_handle, vid2_handle;
404
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);
414
415
416 /*
417  * Volume subdriver
418  */
419
420 static int volume_offset = 0x30;
421
422 static int volume_read(char *p);
423 static int volume_write(char *buf);
424
425
426 /*
427  * Wan subdriver
428  */
429
430 static int wan_supported;
431
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);
436
437
438 #endif /* __THINKPAD_ACPI_H */