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