blob: 02a297e0525f28dbc61cfbb6083085f6808c6e54 [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
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300259 TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */
260 TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300261};
262
263enum fan_status_access_mode {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300264 TPACPI_FAN_NONE = 0, /* No fan status or control */
265 TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
266 TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300267};
268
269enum fan_control_access_mode {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300270 TPACPI_FAN_WR_NONE = 0, /* No fan control */
271 TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
272 TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
273 TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300274};
275
276enum fan_control_commands {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300277 TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
278 TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
279 TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300280 * and also watchdog cmd */
281};
282
283static enum fan_status_access_mode fan_status_access_mode;
284static enum fan_control_access_mode fan_control_access_mode;
285static enum fan_control_commands fan_control_commands;
286static int fan_control_status_known;
287static u8 fan_control_initial_status;
288static int fan_watchdog_maxinterval;
289
290static acpi_handle fans_handle, gfan_handle, sfan_handle;
291
292static int fan_init(void);
293static void fan_exit(void);
294static int fan_get_status(u8 *status);
295static int fan_get_speed(unsigned int *speed);
296static void fan_watchdog_fire(struct work_struct *ignored);
297static void fan_watchdog_reset(void);
298static int fan_set_level(int level);
299static int fan_set_enable(void);
300static int fan_set_disable(void);
301static int fan_set_speed(int speed);
302static int fan_read(char *p);
303static int fan_write(char *buf);
304static int fan_write_cmd_level(const char *cmd, int *rc);
305static int fan_write_cmd_enable(const char *cmd, int *rc);
306static int fan_write_cmd_disable(const char *cmd, int *rc);
307static int fan_write_cmd_speed(const char *cmd, int *rc);
308static int fan_write_cmd_watchdog(const char *cmd, int *rc);
309
310
311/*
312 * Hotkey subdriver
313 */
314
315static int hotkey_supported;
316static int hotkey_mask_supported;
317static int hotkey_orig_status;
318static int hotkey_orig_mask;
319
320static int hotkey_init(void);
321static void hotkey_exit(void);
322static int hotkey_get(int *status, int *mask);
323static int hotkey_set(int status, int mask);
324static void hotkey_notify(struct ibm_struct *ibm, u32 event);
325static int hotkey_read(char *p);
326static int hotkey_write(char *buf);
327
328
329/*
330 * LED subdriver
331 */
332
333enum led_access_mode {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300334 TPACPI_LED_NONE = 0,
335 TPACPI_LED_570, /* 570 */
336 TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
337 TPACPI_LED_NEW, /* all others */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300338};
339
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300340enum { /* For TPACPI_LED_OLD */
341 TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */
342 TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */
343 TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300344};
345
346static enum led_access_mode led_supported;
347static acpi_handle led_handle;
348
349static int led_init(void);
350static int led_read(char *p);
351static int led_write(char *buf);
352
353/*
354 * Light (thinklight) subdriver
355 */
356
357static int light_supported;
358static int light_status_supported;
359static acpi_handle lght_handle, ledb_handle;
360
361static int light_init(void);
362static int light_read(char *p);
363static int light_write(char *buf);
364
365
366/*
367 * Thermal subdriver
368 */
369
370enum thermal_access_mode {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300371 TPACPI_THERMAL_NONE = 0, /* No thermal support */
372 TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
373 TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
374 TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
375 TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300376};
377
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300378#define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300379struct ibm_thermal_sensors_struct {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300380 s32 temp[TPACPI_MAX_THERMAL_SENSORS];
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300381};
382
383static int thermal_init(void);
384static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
385static int thermal_read(char *p);
386
387
388/*
389 * Video subdriver
390 */
391
392enum video_access_mode {
Henrique de Moraes Holschuhefa27142007-04-21 11:08:28 -0300393 TPACPI_VIDEO_NONE = 0,
394 TPACPI_VIDEO_570, /* 570 */
395 TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */
396 TPACPI_VIDEO_NEW, /* all others */
Henrique de Moraes Holschuh1406cdd2007-03-23 17:33:56 -0300397};
398
399static enum video_access_mode video_supported;
400static int video_orig_autosw;
401static acpi_handle vid_handle, vid2_handle;
402
403static int video_init(void);
404static void video_exit(void);
405static int video_status(void);
406static int video_autosw(void);
407static int video_switch(void);
408static int video_switch2(int status);
409static int video_expand(void);
410static int video_read(char *p);
411static int video_write(char *buf);
412
413
414/*
415 * Volume subdriver
416 */
417
418static int volume_offset = 0x30;
419
420static int volume_read(char *p);
421static int volume_write(char *buf);
422
423
424/*
425 * Wan subdriver
426 */
427
428static int wan_supported;
429
430static int wan_init(void);
431static int wan_status(void);
432static int wan_read(char *p);
433static int wan_write(char *buf);
434
435
Henrique de Moraes Holschuh643f12d2007-03-29 01:58:43 -0300436#endif /* __THINKPAD_ACPI_H */