aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc/ibm_acpi.h
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/misc/ibm_acpi.h')
-rw-r--r--drivers/misc/ibm_acpi.h437
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 */
81static int acpi_evalf(acpi_handle handle,
82 void *res, char *method, char *fmt, ...);
83static int acpi_ec_read(int i, u8 * p);
84static int acpi_ec_write(int i, u8 v);
85static int _sta(acpi_handle handle);
86
87/* ACPI handles */
88static acpi_handle root_handle; /* root namespace */
89static acpi_handle ec_handle; /* EC */
90static acpi_handle ecrd_handle, ecwr_handle; /* 570 EC access */
91static acpi_handle cmos_handle, hkey_handle; /* basic thinkpad handles */
92
93static 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 */
101static struct proc_dir_entry *proc_dir;
102static int ibm_acpi_driver_init(void);
103static int ibm_acpi_driver_read(char *p);
104
105/* procfs helpers */
106static int dispatch_read(char *page, char **start, off_t off, int count,
107 int *eof, void *data);
108static int dispatch_write(struct file *file, const char __user * userbuf,
109 unsigned long count, void *data);
110static char *next_cmd(char **cmds);
111
112/* Module */
113static int experimental;
114static char *ibm_thinkpad_ec_found;
115
116static char* check_dmi_for_ec(void);
117static int acpi_ibm_init(void);
118static void acpi_ibm_exit(void);
119
120
121/****************************************************************************
122 * Subdrivers
123 */
124
125struct 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
150static struct ibm_struct ibms[];
151static int set_ibm_param(const char *val, struct kernel_param *kp);
152static int ibm_init(struct ibm_struct *ibm);
153static void ibm_exit(struct ibm_struct *ibm);
154
155/* ACPI devices */
156static void dispatch_notify(acpi_handle handle, u32 event, void *data);
157static int setup_notify(struct ibm_struct *ibm);
158static int ibm_device_add(struct acpi_device *device);
159static int register_ibmacpi_subdriver(struct ibm_struct *ibm);
160
161
162/*
163 * Bay subdriver
164 */
165
166#ifdef CONFIG_ACPI_IBM_BAY
167static int bay_status_supported, bay_eject_supported;
168static int bay_status2_supported, bay_eject2_supported;
169
170static acpi_handle bay_handle, bay_ej_handle;
171static acpi_handle bay2_handle, bay2_ej_handle;
172
173static int bay_init(void);
174static void bay_notify(struct ibm_struct *ibm, u32 event);
175static int bay_read(char *p);
176static int bay_write(char *buf);
177#endif /* CONFIG_ACPI_IBM_BAY */
178
179
180/*
181 * Beep subdriver
182 */
183
184static acpi_handle beep_handle;
185
186static int beep_read(char *p);
187static int beep_write(char *buf);
188
189
190/*
191 * Bluetooth subdriver
192 */
193
194static int bluetooth_supported;
195
196static int bluetooth_init(void);
197static int bluetooth_status(void);
198static int bluetooth_read(char *p);
199static int bluetooth_write(char *buf);
200
201
202/*
203 * Brightness (backlight) subdriver
204 */
205
206static struct backlight_device *ibm_backlight_device;
207static int brightness_offset = 0x31;
208
209static int brightness_init(void);
210static void brightness_exit(void);
211static int brightness_get(struct backlight_device *bd);
212static int brightness_set(int value);
213static int brightness_update_status(struct backlight_device *bd);
214static int brightness_read(char *p);
215static int brightness_write(char *buf);
216
217
218/*
219 * CMOS subdriver
220 */
221
222static int cmos_eval(int cmos_cmd);
223static int cmos_read(char *p);
224static int cmos_write(char *buf);
225
226
227/*
228 * Dock subdriver
229 */
230
231static acpi_handle pci_handle;
232#ifdef CONFIG_ACPI_IBM_DOCK
233static acpi_handle dock_handle;
234
235static void dock_notify(struct ibm_struct *ibm, u32 event);
236static int dock_read(char *p);
237static int dock_write(char *buf);
238#endif /* CONFIG_ACPI_IBM_DOCK */
239
240
241/*
242 * EC dump subdriver
243 */
244
245static int ecdump_read(char *p) ;
246static int ecdump_write(char *buf);
247
248
249/*
250 * Fan subdriver
251 */
252
253enum { /* 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
264enum 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
270enum 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
277enum 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
284static enum fan_status_access_mode fan_status_access_mode;
285static enum fan_control_access_mode fan_control_access_mode;
286static enum fan_control_commands fan_control_commands;
287static int fan_control_status_known;
288static u8 fan_control_initial_status;
289static int fan_watchdog_maxinterval;
290
291static acpi_handle fans_handle, gfan_handle, sfan_handle;
292
293static int fan_init(void);
294static void fan_exit(void);
295static int fan_get_status(u8 *status);
296static int fan_get_speed(unsigned int *speed);
297static void fan_watchdog_fire(struct work_struct *ignored);
298static void fan_watchdog_reset(void);
299static int fan_set_level(int level);
300static int fan_set_enable(void);
301static int fan_set_disable(void);
302static int fan_set_speed(int speed);
303static int fan_read(char *p);
304static int fan_write(char *buf);
305static int fan_write_cmd_level(const char *cmd, int *rc);
306static int fan_write_cmd_enable(const char *cmd, int *rc);
307static int fan_write_cmd_disable(const char *cmd, int *rc);
308static int fan_write_cmd_speed(const char *cmd, int *rc);
309static int fan_write_cmd_watchdog(const char *cmd, int *rc);
310
311
312/*
313 * Hotkey subdriver
314 */
315
316static int hotkey_supported;
317static int hotkey_mask_supported;
318static int hotkey_orig_status;
319static int hotkey_orig_mask;
320
321static int hotkey_init(void);
322static void hotkey_exit(void);
323static int hotkey_get(int *status, int *mask);
324static int hotkey_set(int status, int mask);
325static void hotkey_notify(struct ibm_struct *ibm, u32 event);
326static int hotkey_read(char *p);
327static int hotkey_write(char *buf);
328
329
330/*
331 * LED subdriver
332 */
333
334enum 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
341enum { /* 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
347static enum led_access_mode led_supported;
348static acpi_handle led_handle;
349
350static int led_init(void);
351static int led_read(char *p);
352static int led_write(char *buf);
353
354/*
355 * Light (thinklight) subdriver
356 */
357
358static int light_supported;
359static int light_status_supported;
360static acpi_handle lght_handle, ledb_handle;
361
362static int light_init(void);
363static int light_read(char *p);
364static int light_write(char *buf);
365
366
367/*
368 * Thermal subdriver
369 */
370
371enum 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 */
380struct ibm_thermal_sensors_struct {
381 s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
382};
383
384static int thermal_init(void);
385static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
386static int thermal_read(char *p);
387
388
389/*
390 * Video subdriver
391 */
392
393enum 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
400static enum video_access_mode video_supported;
401static int video_orig_autosw;
402static acpi_handle vid_handle, vid2_handle;
403
404static int video_init(void);
405static void video_exit(void);
406static int video_status(void);
407static int video_autosw(void);
408static int video_switch(void);
409static int video_switch2(int status);
410static int video_expand(void);
411static int video_read(char *p);
412static int video_write(char *buf);
413
414
415/*
416 * Volume subdriver
417 */
418
419static int volume_offset = 0x30;
420
421static int volume_read(char *p);
422static int volume_write(char *buf);
423
424
425/*
426 * Wan subdriver
427 */
428
429static int wan_supported;
430
431static int wan_init(void);
432static int wan_status(void);
433static int wan_read(char *p);
434static int wan_write(char *buf);
435
436
437#endif /* __IBM_ACPI_H */