diff options
Diffstat (limited to 'drivers/misc/ibm_acpi.h')
-rw-r--r-- | drivers/misc/ibm_acpi.h | 437 |
1 files changed, 437 insertions, 0 deletions
diff --git a/drivers/misc/ibm_acpi.h b/drivers/misc/ibm_acpi.h new file mode 100644 index 000000000000..7ebaaa40e183 --- /dev/null +++ b/drivers/misc/ibm_acpi.h | |||
@@ -0,0 +1,437 @@ | |||
1 | /* | ||
2 | * ibm_acpi.h - IBM 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 __IBM_ACPI_H__ | ||
25 | #define __IBM_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 "ibm" | ||
51 | #define IBM_DESC "IBM ThinkPad ACPI Extras" | ||
52 | #define IBM_FILE "ibm_acpi" | ||
53 | #define IBM_URL "http://ibm-acpi.sf.net/" | ||
54 | |||
55 | #define IBM_DIR IBM_NAME | ||
56 | |||
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 | ||
62 | |||
63 | #define IBM_MAX_ACPI_ARGS 3 | ||
64 | |||
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 | ||
71 | |||
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))) | ||
75 | |||
76 | /* ACPI HIDs */ | ||
77 | #define IBM_HKEY_HID "IBM0068" | ||
78 | #define IBM_PCI_HID "PNP0A03" | ||
79 | |||
80 | /* ACPI helpers */ | ||
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); | ||
86 | |||
87 | /* ACPI handles */ | ||
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 */ | ||
92 | |||
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) | ||
99 | |||
100 | /* procfs support */ | ||
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); | ||
104 | |||
105 | /* procfs helpers */ | ||
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); | ||
111 | |||
112 | /* Module */ | ||
113 | static int experimental; | ||
114 | static char *ibm_thinkpad_ec_found; | ||
115 | |||
116 | static char* check_dmi_for_ec(void); | ||
117 | static int acpi_ibm_init(void); | ||
118 | static void acpi_ibm_exit(void); | ||
119 | |||
120 | |||
121 | /**************************************************************************** | ||
122 | * Subdrivers | ||
123 | */ | ||
124 | |||
125 | struct ibm_struct { | ||
126 | char *name; | ||
127 | char param[32]; | ||
128 | |||
129 | char *hid; | ||
130 | struct acpi_driver *driver; | ||
131 | |||
132 | int (*init) (void); | ||
133 | int (*read) (char *); | ||
134 | int (*write) (char *); | ||
135 | void (*exit) (void); | ||
136 | |||
137 | void (*notify) (struct ibm_struct *, u32); | ||
138 | acpi_handle *handle; | ||
139 | int type; | ||
140 | struct acpi_device *device; | ||
141 | |||
142 | int driver_registered; | ||
143 | int proc_created; | ||
144 | int init_called; | ||
145 | int notify_installed; | ||
146 | |||
147 | int experimental; | ||
148 | }; | ||
149 | |||
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); | ||
154 | |||
155 | /* ACPI devices */ | ||
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); | ||
160 | |||
161 | |||
162 | /* | ||
163 | * Bay subdriver | ||
164 | */ | ||
165 | |||
166 | #ifdef CONFIG_ACPI_IBM_BAY | ||
167 | static int bay_status_supported, bay_eject_supported; | ||
168 | static int bay_status2_supported, bay_eject2_supported; | ||
169 | |||
170 | static acpi_handle bay_handle, bay_ej_handle; | ||
171 | static acpi_handle bay2_handle, bay2_ej_handle; | ||
172 | |||
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_ACPI_IBM_BAY */ | ||
178 | |||
179 | |||
180 | /* | ||
181 | * Beep subdriver | ||
182 | */ | ||
183 | |||
184 | static acpi_handle beep_handle; | ||
185 | |||
186 | static int beep_read(char *p); | ||
187 | static int beep_write(char *buf); | ||
188 | |||
189 | |||
190 | /* | ||
191 | * Bluetooth subdriver | ||
192 | */ | ||
193 | |||
194 | static int bluetooth_supported; | ||
195 | |||
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); | ||
200 | |||
201 | |||
202 | /* | ||
203 | * Brightness (backlight) subdriver | ||
204 | */ | ||
205 | |||
206 | static struct backlight_device *ibm_backlight_device; | ||
207 | static int brightness_offset = 0x31; | ||
208 | |||
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); | ||
216 | |||
217 | |||
218 | /* | ||
219 | * CMOS subdriver | ||
220 | */ | ||
221 | |||
222 | static int cmos_eval(int cmos_cmd); | ||
223 | static int cmos_read(char *p); | ||
224 | static int cmos_write(char *buf); | ||
225 | |||
226 | |||
227 | /* | ||
228 | * Dock subdriver | ||
229 | */ | ||
230 | |||
231 | static acpi_handle pci_handle; | ||
232 | #ifdef CONFIG_ACPI_IBM_DOCK | ||
233 | static acpi_handle dock_handle; | ||
234 | |||
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_ACPI_IBM_DOCK */ | ||
239 | |||
240 | |||
241 | /* | ||
242 | * EC dump subdriver | ||
243 | */ | ||
244 | |||
245 | static int ecdump_read(char *p) ; | ||
246 | static int ecdump_write(char *buf); | ||
247 | |||
248 | |||
249 | /* | ||
250 | * Fan subdriver | ||
251 | */ | ||
252 | |||
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 */ | ||
257 | |||
258 | IBMACPI_FAN_EC_DISENGAGED = 0x40, /* EC mode: tachometer | ||
259 | * disengaged */ | ||
260 | IBMACPI_FAN_EC_AUTO = 0x80, /* EC mode: auto fan | ||
261 | * control */ | ||
262 | }; | ||
263 | |||
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 */ | ||
268 | }; | ||
269 | |||
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 */ | ||
275 | }; | ||
276 | |||
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 */ | ||
282 | }; | ||
283 | |||
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; | ||
290 | |||
291 | static acpi_handle fans_handle, gfan_handle, sfan_handle; | ||
292 | |||
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); | ||
310 | |||
311 | |||
312 | /* | ||
313 | * Hotkey subdriver | ||
314 | */ | ||
315 | |||
316 | static int hotkey_supported; | ||
317 | static int hotkey_mask_supported; | ||
318 | static int hotkey_orig_status; | ||
319 | static int hotkey_orig_mask; | ||
320 | |||
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); | ||
328 | |||
329 | |||
330 | /* | ||
331 | * LED subdriver | ||
332 | */ | ||
333 | |||
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 */ | ||
339 | }; | ||
340 | |||
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 */ | ||
345 | }; | ||
346 | |||
347 | static enum led_access_mode led_supported; | ||
348 | static acpi_handle led_handle; | ||
349 | |||
350 | static int led_init(void); | ||
351 | static int led_read(char *p); | ||
352 | static int led_write(char *buf); | ||
353 | |||
354 | /* | ||
355 | * Light (thinklight) subdriver | ||
356 | */ | ||
357 | |||
358 | static int light_supported; | ||
359 | static int light_status_supported; | ||
360 | static acpi_handle lght_handle, ledb_handle; | ||
361 | |||
362 | static int light_init(void); | ||
363 | static int light_read(char *p); | ||
364 | static int light_write(char *buf); | ||
365 | |||
366 | |||
367 | /* | ||
368 | * Thermal subdriver | ||
369 | */ | ||
370 | |||
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 */ | ||
377 | }; | ||
378 | |||
379 | #define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */ | ||
380 | struct ibm_thermal_sensors_struct { | ||
381 | s32 temp[IBMACPI_MAX_THERMAL_SENSORS]; | ||
382 | }; | ||
383 | |||
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); | ||
387 | |||
388 | |||
389 | /* | ||
390 | * Video subdriver | ||
391 | */ | ||
392 | |||
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 */ | ||
398 | }; | ||
399 | |||
400 | static enum video_access_mode video_supported; | ||
401 | static int video_orig_autosw; | ||
402 | static acpi_handle vid_handle, vid2_handle; | ||
403 | |||
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); | ||
413 | |||
414 | |||
415 | /* | ||
416 | * Volume subdriver | ||
417 | */ | ||
418 | |||
419 | static int volume_offset = 0x30; | ||
420 | |||
421 | static int volume_read(char *p); | ||
422 | static int volume_write(char *buf); | ||
423 | |||
424 | |||
425 | /* | ||
426 | * Wan subdriver | ||
427 | */ | ||
428 | |||
429 | static int wan_supported; | ||
430 | |||
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); | ||
435 | |||
436 | |||
437 | #endif /* __IBM_ACPI_H */ | ||