blob: 8b2fd1a1a8a15b325ccbd39f3f9a1350f1df53f2 [file] [log] [blame]
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -03001/*
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -03002 * thinkpad_acpi.h - ThinkPad ACPI Extras
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -03003 *
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
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -030024#ifndef __THINKPAD_ACPI_H__
25#define __THINKPAD_ACPI_H__
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -030026
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
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -030050#define IBM_NAME "thinkpad"
51#define IBM_DESC "ThinkPad ACPI Extras"
52#define IBM_FILE "thinkpad_acpi"
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -030053#define IBM_URL "http://ibm-acpi.sf.net/"
54
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -030055#define IBM_DIR "ibm"
56#define IBM_ACPI_EVENT_PREFIX "ibm"
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -030057
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 */
82static int acpi_evalf(acpi_handle handle,
83 void *res, char *method, char *fmt, ...);
84static int acpi_ec_read(int i, u8 * p);
85static int acpi_ec_write(int i, u8 v);
86static int _sta(acpi_handle handle);
87
88/* ACPI handles */
89static acpi_handle root_handle; /* root namespace */
90static acpi_handle ec_handle; /* EC */
91static acpi_handle ecrd_handle, ecwr_handle; /* 570 EC access */
92static acpi_handle cmos_handle, hkey_handle; /* basic thinkpad handles */
93
94static 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 */
102static struct proc_dir_entry *proc_dir;
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -0300103static int thinkpad_acpi_driver_init(void);
104static int thinkpad_acpi_driver_read(char *p);
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300105
106/* procfs helpers */
107static int dispatch_read(char *page, char **start, off_t off, int count,
108 int *eof, void *data);
109static int dispatch_write(struct file *file, const char __user * userbuf,
110 unsigned long count, void *data);
111static char *next_cmd(char **cmds);
112
113/* Module */
114static int experimental;
115static char *ibm_thinkpad_ec_found;
116
117static char* check_dmi_for_ec(void);
Henrique de Moraes Holschuh1def7112007-04-21 11:08:27 -0300118static int thinkpad_acpi_module_init(void);
119static void thinkpad_acpi_module_exit(void);
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300120
121
122/****************************************************************************
123 * Subdrivers
124 */
125
126struct 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
151static struct ibm_struct ibms[];
152static int set_ibm_param(const char *val, struct kernel_param *kp);
153static int ibm_init(struct ibm_struct *ibm);
154static void ibm_exit(struct ibm_struct *ibm);
155
156/* ACPI devices */
157static void dispatch_notify(acpi_handle handle, u32 event, void *data);
158static int setup_notify(struct ibm_struct *ibm);
159static int ibm_device_add(struct acpi_device *device);
Henrique de Moraes Holschuh67001212007-04-21 11:08:25 -0300160static int register_tpacpi_subdriver(struct ibm_struct *ibm);
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300161
162
163/*
164 * Bay subdriver
165 */
166
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -0300167#ifdef CONFIG_THINKPAD_ACPI_BAY
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300168static int bay_status_supported, bay_eject_supported;
169static int bay_status2_supported, bay_eject2_supported;
170
171static acpi_handle bay_handle, bay_ej_handle;
172static acpi_handle bay2_handle, bay2_ej_handle;
173
174static int bay_init(void);
175static void bay_notify(struct ibm_struct *ibm, u32 event);
176static int bay_read(char *p);
177static int bay_write(char *buf);
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -0300178#endif /* CONFIG_THINKPAD_ACPI_BAY */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300179
180
181/*
182 * Beep subdriver
183 */
184
185static acpi_handle beep_handle;
186
187static int beep_read(char *p);
188static int beep_write(char *buf);
189
190
191/*
192 * Bluetooth subdriver
193 */
194
195static int bluetooth_supported;
196
197static int bluetooth_init(void);
198static int bluetooth_status(void);
199static int bluetooth_read(char *p);
200static int bluetooth_write(char *buf);
201
202
203/*
204 * Brightness (backlight) subdriver
205 */
206
207static struct backlight_device *ibm_backlight_device;
208static int brightness_offset = 0x31;
209
210static int brightness_init(void);
211static void brightness_exit(void);
212static int brightness_get(struct backlight_device *bd);
213static int brightness_set(int value);
214static int brightness_update_status(struct backlight_device *bd);
215static int brightness_read(char *p);
216static int brightness_write(char *buf);
217
218
219/*
220 * CMOS subdriver
221 */
222
223static int cmos_eval(int cmos_cmd);
224static int cmos_read(char *p);
225static int cmos_write(char *buf);
226
227
228/*
229 * Dock subdriver
230 */
231
232static acpi_handle pci_handle;
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -0300233#ifdef CONFIG_THINKPAD_ACPI_DOCK
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300234static acpi_handle dock_handle;
235
236static void dock_notify(struct ibm_struct *ibm, u32 event);
237static int dock_read(char *p);
238static int dock_write(char *buf);
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -0300239#endif /* CONFIG_THINKPAD_ACPI_DOCK */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300240
241
242/*
243 * EC dump subdriver
244 */
245
246static int ecdump_read(char *p) ;
247static int ecdump_write(char *buf);
248
249
250/*
251 * Fan subdriver
252 */
253
254enum { /* 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
265enum 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
271enum 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
278enum 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
285static enum fan_status_access_mode fan_status_access_mode;
286static enum fan_control_access_mode fan_control_access_mode;
287static enum fan_control_commands fan_control_commands;
288static int fan_control_status_known;
289static u8 fan_control_initial_status;
290static int fan_watchdog_maxinterval;
291
292static acpi_handle fans_handle, gfan_handle, sfan_handle;
293
294static int fan_init(void);
295static void fan_exit(void);
296static int fan_get_status(u8 *status);
297static int fan_get_speed(unsigned int *speed);
298static void fan_watchdog_fire(struct work_struct *ignored);
299static void fan_watchdog_reset(void);
300static int fan_set_level(int level);
301static int fan_set_enable(void);
302static int fan_set_disable(void);
303static int fan_set_speed(int speed);
304static int fan_read(char *p);
305static int fan_write(char *buf);
306static int fan_write_cmd_level(const char *cmd, int *rc);
307static int fan_write_cmd_enable(const char *cmd, int *rc);
308static int fan_write_cmd_disable(const char *cmd, int *rc);
309static int fan_write_cmd_speed(const char *cmd, int *rc);
310static int fan_write_cmd_watchdog(const char *cmd, int *rc);
311
312
313/*
314 * Hotkey subdriver
315 */
316
317static int hotkey_supported;
318static int hotkey_mask_supported;
319static int hotkey_orig_status;
320static int hotkey_orig_mask;
321
322static int hotkey_init(void);
323static void hotkey_exit(void);
324static int hotkey_get(int *status, int *mask);
325static int hotkey_set(int status, int mask);
326static void hotkey_notify(struct ibm_struct *ibm, u32 event);
327static int hotkey_read(char *p);
328static int hotkey_write(char *buf);
329
330
331/*
332 * LED subdriver
333 */
334
335enum 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
342enum { /* 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
348static enum led_access_mode led_supported;
349static acpi_handle led_handle;
350
351static int led_init(void);
352static int led_read(char *p);
353static int led_write(char *buf);
354
355/*
356 * Light (thinklight) subdriver
357 */
358
359static int light_supported;
360static int light_status_supported;
361static acpi_handle lght_handle, ledb_handle;
362
363static int light_init(void);
364static int light_read(char *p);
365static int light_write(char *buf);
366
367
368/*
369 * Thermal subdriver
370 */
371
372enum 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 */
381struct ibm_thermal_sensors_struct {
382 s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
383};
384
385static int thermal_init(void);
386static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
387static int thermal_read(char *p);
388
389
390/*
391 * Video subdriver
392 */
393
394enum 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
401static enum video_access_mode video_supported;
402static int video_orig_autosw;
403static acpi_handle vid_handle, vid2_handle;
404
405static int video_init(void);
406static void video_exit(void);
407static int video_status(void);
408static int video_autosw(void);
409static int video_switch(void);
410static int video_switch2(int status);
411static int video_expand(void);
412static int video_read(char *p);
413static int video_write(char *buf);
414
415
416/*
417 * Volume subdriver
418 */
419
420static int volume_offset = 0x30;
421
422static int volume_read(char *p);
423static int volume_write(char *buf);
424
425
426/*
427 * Wan subdriver
428 */
429
430static int wan_supported;
431
432static int wan_init(void);
433static int wan_status(void);
434static int wan_read(char *p);
435static int wan_write(char *buf);
436
437
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -0300438#endif /* __THINKPAD_ACPI_H */