blob: beb1447a7f3fc38b74033bfb1767527cb07ff77d [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
Henrique de Moraes Holschuh132ce092007-04-21 11:08:30 -030077/* Debugging */
78#define TPACPI_DBG_ALL 0xffff
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -030079#define TPACPI_DBG_ALL 0xffff
80#define TPACPI_DBG_INIT 0x0001
81#define TPACPI_DBG_EXIT 0x0002
Henrique de Moraes Holschuh132ce092007-04-21 11:08:30 -030082#define dbg_printk(a_dbg_level, format, arg...) \
83 do { if (dbg_level & a_dbg_level) \
84 printk(IBM_DEBUG "%s: " format, __func__ , ## arg); } while (0)
85#ifdef CONFIG_THINKPAD_ACPI_DEBUG
86#define vdbg_printk(a_dbg_level, format, arg...) \
87 dbg_printk(a_dbg_level, format, ## arg)
Henrique de Moraes Holschuhfe08bc42007-04-21 11:08:32 -030088static const char *str_supported(int is_supported);
Henrique de Moraes Holschuh132ce092007-04-21 11:08:30 -030089#else
90#define vdbg_printk(a_dbg_level, format, arg...)
91#endif
92
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -030093/* ACPI HIDs */
94#define IBM_HKEY_HID "IBM0068"
95#define IBM_PCI_HID "PNP0A03"
96
97/* ACPI helpers */
98static int acpi_evalf(acpi_handle handle,
99 void *res, char *method, char *fmt, ...);
100static int acpi_ec_read(int i, u8 * p);
101static int acpi_ec_write(int i, u8 v);
102static int _sta(acpi_handle handle);
103
104/* ACPI handles */
105static acpi_handle root_handle; /* root namespace */
106static acpi_handle ec_handle; /* EC */
107static acpi_handle ecrd_handle, ecwr_handle; /* 570 EC access */
108static acpi_handle cmos_handle, hkey_handle; /* basic thinkpad handles */
109
110static void ibm_handle_init(char *name,
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -0300111 acpi_handle *handle, acpi_handle parent,
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300112 char **paths, int num_paths, char **path);
113#define IBM_HANDLE_INIT(object) \
114 ibm_handle_init(#object, &object##_handle, *object##_parent, \
115 object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
116
117/* procfs support */
118static struct proc_dir_entry *proc_dir;
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -0300119static int thinkpad_acpi_driver_init(void);
120static int thinkpad_acpi_driver_read(char *p);
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300121
122/* procfs helpers */
123static int dispatch_read(char *page, char **start, off_t off, int count,
124 int *eof, void *data);
125static int dispatch_write(struct file *file, const char __user * userbuf,
126 unsigned long count, void *data);
127static char *next_cmd(char **cmds);
128
129/* Module */
130static int experimental;
Henrique de Moraes Holschuh132ce092007-04-21 11:08:30 -0300131static u32 dbg_level;
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300132static char *ibm_thinkpad_ec_found;
133
134static char* check_dmi_for_ec(void);
Henrique de Moraes Holschuh1def7112007-04-21 11:08:27 -0300135static int thinkpad_acpi_module_init(void);
136static void thinkpad_acpi_module_exit(void);
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300137
138
139/****************************************************************************
140 * Subdrivers
141 */
142
143struct ibm_struct {
144 char *name;
145 char param[32];
146
147 char *hid;
148 struct acpi_driver *driver;
149
150 int (*init) (void);
151 int (*read) (char *);
152 int (*write) (char *);
153 void (*exit) (void);
154
155 void (*notify) (struct ibm_struct *, u32);
156 acpi_handle *handle;
157 int type;
158 struct acpi_device *device;
159
160 int driver_registered;
161 int proc_created;
162 int init_called;
163 int notify_installed;
164
165 int experimental;
166};
167
168static struct ibm_struct ibms[];
169static int set_ibm_param(const char *val, struct kernel_param *kp);
170static int ibm_init(struct ibm_struct *ibm);
171static void ibm_exit(struct ibm_struct *ibm);
172
173/* ACPI devices */
174static void dispatch_notify(acpi_handle handle, u32 event, void *data);
175static int setup_notify(struct ibm_struct *ibm);
176static int ibm_device_add(struct acpi_device *device);
Henrique de Moraes Holschuh67001212007-04-21 11:08:25 -0300177static int register_tpacpi_subdriver(struct ibm_struct *ibm);
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300178
179
180/*
181 * Bay subdriver
182 */
183
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -0300184#ifdef CONFIG_THINKPAD_ACPI_BAY
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300185static int bay_status_supported, bay_eject_supported;
186static int bay_status2_supported, bay_eject2_supported;
187
188static acpi_handle bay_handle, bay_ej_handle;
189static acpi_handle bay2_handle, bay2_ej_handle;
190
191static int bay_init(void);
192static void bay_notify(struct ibm_struct *ibm, u32 event);
193static int bay_read(char *p);
194static int bay_write(char *buf);
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -0300195#endif /* CONFIG_THINKPAD_ACPI_BAY */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300196
197
198/*
199 * Beep subdriver
200 */
201
202static acpi_handle beep_handle;
203
204static int beep_read(char *p);
205static int beep_write(char *buf);
206
207
208/*
209 * Bluetooth subdriver
210 */
211
212static int bluetooth_supported;
213
214static int bluetooth_init(void);
215static int bluetooth_status(void);
216static int bluetooth_read(char *p);
217static int bluetooth_write(char *buf);
218
219
220/*
221 * Brightness (backlight) subdriver
222 */
223
224static struct backlight_device *ibm_backlight_device;
225static int brightness_offset = 0x31;
226
227static int brightness_init(void);
228static void brightness_exit(void);
229static int brightness_get(struct backlight_device *bd);
230static int brightness_set(int value);
231static int brightness_update_status(struct backlight_device *bd);
232static int brightness_read(char *p);
233static int brightness_write(char *buf);
234
235
236/*
237 * CMOS subdriver
238 */
239
240static int cmos_eval(int cmos_cmd);
241static int cmos_read(char *p);
242static int cmos_write(char *buf);
243
244
245/*
246 * Dock subdriver
247 */
248
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -0300249#ifdef CONFIG_THINKPAD_ACPI_DOCK
Henrique de Moraes Holschuh5fba3442007-04-21 11:08:31 -0300250static acpi_handle pci_handle;
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300251static acpi_handle dock_handle;
252
253static void dock_notify(struct ibm_struct *ibm, u32 event);
254static int dock_read(char *p);
255static int dock_write(char *buf);
Henrique de Moraes Holschuh85998242007-03-29 01:58:41 -0300256#endif /* CONFIG_THINKPAD_ACPI_DOCK */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300257
258
259/*
260 * EC dump subdriver
261 */
262
263static int ecdump_read(char *p) ;
264static int ecdump_write(char *buf);
265
266
267/*
268 * Fan subdriver
269 */
270
271enum { /* Fan control constants */
272 fan_status_offset = 0x2f, /* EC register 0x2f */
273 fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
274 * 0x84 must be read before 0x85 */
275
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300276 TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */
277 TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300278};
279
280enum fan_status_access_mode {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300281 TPACPI_FAN_NONE = 0, /* No fan status or control */
282 TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
283 TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300284};
285
286enum fan_control_access_mode {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300287 TPACPI_FAN_WR_NONE = 0, /* No fan control */
288 TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
289 TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
290 TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300291};
292
293enum fan_control_commands {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300294 TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
295 TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
296 TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300297 * and also watchdog cmd */
298};
299
300static enum fan_status_access_mode fan_status_access_mode;
301static enum fan_control_access_mode fan_control_access_mode;
302static enum fan_control_commands fan_control_commands;
303static int fan_control_status_known;
304static u8 fan_control_initial_status;
305static int fan_watchdog_maxinterval;
306
307static acpi_handle fans_handle, gfan_handle, sfan_handle;
308
309static int fan_init(void);
310static void fan_exit(void);
311static int fan_get_status(u8 *status);
312static int fan_get_speed(unsigned int *speed);
313static void fan_watchdog_fire(struct work_struct *ignored);
314static void fan_watchdog_reset(void);
315static int fan_set_level(int level);
316static int fan_set_enable(void);
317static int fan_set_disable(void);
318static int fan_set_speed(int speed);
319static int fan_read(char *p);
320static int fan_write(char *buf);
321static int fan_write_cmd_level(const char *cmd, int *rc);
322static int fan_write_cmd_enable(const char *cmd, int *rc);
323static int fan_write_cmd_disable(const char *cmd, int *rc);
324static int fan_write_cmd_speed(const char *cmd, int *rc);
325static int fan_write_cmd_watchdog(const char *cmd, int *rc);
326
327
328/*
329 * Hotkey subdriver
330 */
331
332static int hotkey_supported;
333static int hotkey_mask_supported;
334static int hotkey_orig_status;
335static int hotkey_orig_mask;
336
337static int hotkey_init(void);
338static void hotkey_exit(void);
339static int hotkey_get(int *status, int *mask);
340static int hotkey_set(int status, int mask);
341static void hotkey_notify(struct ibm_struct *ibm, u32 event);
342static int hotkey_read(char *p);
343static int hotkey_write(char *buf);
344
345
346/*
347 * LED subdriver
348 */
349
350enum led_access_mode {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300351 TPACPI_LED_NONE = 0,
352 TPACPI_LED_570, /* 570 */
353 TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
354 TPACPI_LED_NEW, /* all others */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300355};
356
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300357enum { /* For TPACPI_LED_OLD */
358 TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */
359 TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */
360 TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300361};
362
363static enum led_access_mode led_supported;
364static acpi_handle led_handle;
365
366static int led_init(void);
367static int led_read(char *p);
368static int led_write(char *buf);
369
370/*
371 * Light (thinklight) subdriver
372 */
373
374static int light_supported;
375static int light_status_supported;
376static acpi_handle lght_handle, ledb_handle;
377
378static int light_init(void);
379static int light_read(char *p);
380static int light_write(char *buf);
381
382
383/*
384 * Thermal subdriver
385 */
386
387enum thermal_access_mode {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300388 TPACPI_THERMAL_NONE = 0, /* No thermal support */
389 TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
390 TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
391 TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
392 TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300393};
394
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300395#define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300396struct ibm_thermal_sensors_struct {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300397 s32 temp[TPACPI_MAX_THERMAL_SENSORS];
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300398};
399
400static int thermal_init(void);
401static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
402static int thermal_read(char *p);
403
404
405/*
406 * Video subdriver
407 */
408
409enum video_access_mode {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300410 TPACPI_VIDEO_NONE = 0,
411 TPACPI_VIDEO_570, /* 570 */
412 TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */
413 TPACPI_VIDEO_NEW, /* all others */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300414};
415
416static enum video_access_mode video_supported;
417static int video_orig_autosw;
418static acpi_handle vid_handle, vid2_handle;
419
420static int video_init(void);
421static void video_exit(void);
422static int video_status(void);
423static int video_autosw(void);
424static int video_switch(void);
425static int video_switch2(int status);
426static int video_expand(void);
427static int video_read(char *p);
428static int video_write(char *buf);
429
430
431/*
432 * Volume subdriver
433 */
434
435static int volume_offset = 0x30;
436
437static int volume_read(char *p);
438static int volume_write(char *buf);
439
440
441/*
442 * Wan subdriver
443 */
444
445static int wan_supported;
446
447static int wan_init(void);
448static int wan_status(void);
449static int wan_read(char *p);
450static int wan_write(char *buf);
451
452
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -0300453#endif /* __THINKPAD_ACPI_H */