thinkpad_acpi.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. /*
  2. * thinkpad_acpi.h - 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. #ifndef __THINKPAD_ACPI_H__
  24. #define __THINKPAD_ACPI_H__
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/types.h>
  29. #include <linux/string.h>
  30. #include <linux/list.h>
  31. #include <linux/proc_fs.h>
  32. #include <linux/backlight.h>
  33. #include <linux/fb.h>
  34. #include <asm/uaccess.h>
  35. #include <linux/dmi.h>
  36. #include <linux/jiffies.h>
  37. #include <linux/workqueue.h>
  38. #include <acpi/acpi_drivers.h>
  39. #include <acpi/acnamesp.h>
  40. /****************************************************************************
  41. * Main driver
  42. */
  43. #define IBM_NAME "thinkpad"
  44. #define IBM_DESC "ThinkPad ACPI Extras"
  45. #define IBM_FILE "thinkpad_acpi"
  46. #define IBM_URL "http://ibm-acpi.sf.net/"
  47. #define IBM_DIR "ibm"
  48. #define IBM_ACPI_EVENT_PREFIX "ibm"
  49. #define IBM_LOG IBM_FILE ": "
  50. #define IBM_ERR KERN_ERR IBM_LOG
  51. #define IBM_NOTICE KERN_NOTICE IBM_LOG
  52. #define IBM_INFO KERN_INFO IBM_LOG
  53. #define IBM_DEBUG KERN_DEBUG IBM_LOG
  54. #define IBM_MAX_ACPI_ARGS 3
  55. /* ThinkPad CMOS commands */
  56. #define TP_CMOS_VOLUME_DOWN 0
  57. #define TP_CMOS_VOLUME_UP 1
  58. #define TP_CMOS_VOLUME_MUTE 2
  59. #define TP_CMOS_BRIGHTNESS_UP 4
  60. #define TP_CMOS_BRIGHTNESS_DOWN 5
  61. #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
  62. #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
  63. #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
  64. /* Debugging */
  65. #define TPACPI_DBG_ALL 0xffff
  66. #define TPACPI_DBG_ALL 0xffff
  67. #define TPACPI_DBG_INIT 0x0001
  68. #define TPACPI_DBG_EXIT 0x0002
  69. #define dbg_printk(a_dbg_level, format, arg...) \
  70. do { if (dbg_level & a_dbg_level) \
  71. printk(IBM_DEBUG "%s: " format, __func__ , ## arg); } while (0)
  72. #ifdef CONFIG_THINKPAD_ACPI_DEBUG
  73. #define vdbg_printk(a_dbg_level, format, arg...) \
  74. dbg_printk(a_dbg_level, format, ## arg)
  75. static const char *str_supported(int is_supported);
  76. #else
  77. #define vdbg_printk(a_dbg_level, format, arg...)
  78. #endif
  79. /* ACPI HIDs */
  80. #define IBM_HKEY_HID "IBM0068"
  81. #define IBM_PCI_HID "PNP0A03"
  82. /* ACPI helpers */
  83. static int acpi_evalf(acpi_handle handle,
  84. void *res, char *method, char *fmt, ...);
  85. static int acpi_ec_read(int i, u8 * p);
  86. static int acpi_ec_write(int i, u8 v);
  87. static int _sta(acpi_handle handle);
  88. /* ACPI handles */
  89. static acpi_handle root_handle; /* root namespace */
  90. static acpi_handle ec_handle; /* EC */
  91. static acpi_handle ecrd_handle, ecwr_handle; /* 570 EC access */
  92. static acpi_handle cmos_handle, hkey_handle; /* basic thinkpad handles */
  93. static 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. /* procfs support */
  100. static struct proc_dir_entry *proc_dir;
  101. /* procfs helpers */
  102. static int dispatch_read(char *page, char **start, off_t off, int count,
  103. int *eof, void *data);
  104. static int dispatch_write(struct file *file, const char __user * userbuf,
  105. unsigned long count, void *data);
  106. static char *next_cmd(char **cmds);
  107. /* Module */
  108. static int experimental;
  109. static u32 dbg_level;
  110. static int force_load;
  111. static char *ibm_thinkpad_ec_found;
  112. static char* check_dmi_for_ec(void);
  113. static int thinkpad_acpi_module_init(void);
  114. static void thinkpad_acpi_module_exit(void);
  115. /****************************************************************************
  116. * Subdrivers
  117. */
  118. struct ibm_struct {
  119. char *name;
  120. char *hid;
  121. struct acpi_driver *driver;
  122. int (*read) (char *);
  123. int (*write) (char *);
  124. void (*exit) (void);
  125. void (*notify) (struct ibm_struct *, u32);
  126. acpi_handle *handle;
  127. int type;
  128. struct acpi_device *device;
  129. struct list_head all_drivers;
  130. struct {
  131. u8 driver_registered:1;
  132. u8 proc_created:1;
  133. u8 init_called:1;
  134. u8 notify_installed:1;
  135. u8 experimental:1;
  136. } flags;
  137. };
  138. struct ibm_init_struct {
  139. char param[32];
  140. int (*init) (struct ibm_init_struct *);
  141. struct ibm_struct *data;
  142. };
  143. static struct {
  144. #ifdef CONFIG_THINKPAD_ACPI_BAY
  145. u16 bay_status:1;
  146. u16 bay_eject:1;
  147. u16 bay_status2:1;
  148. u16 bay_eject2:1;
  149. #endif
  150. u16 bluetooth:1;
  151. u16 hotkey:1;
  152. u16 hotkey_mask:1;
  153. u16 light:1;
  154. u16 light_status:1;
  155. u16 wan:1;
  156. u16 fan_ctrl_status_undef:1;
  157. } tp_features;
  158. static struct list_head tpacpi_all_drivers;
  159. static struct ibm_init_struct ibms_init[];
  160. static int set_ibm_param(const char *val, struct kernel_param *kp);
  161. static int ibm_init(struct ibm_init_struct *iibm);
  162. static void ibm_exit(struct ibm_struct *ibm);
  163. /*
  164. * procfs master subdriver
  165. */
  166. static int thinkpad_acpi_driver_init(struct ibm_init_struct *iibm);
  167. static int thinkpad_acpi_driver_read(char *p);
  168. /*
  169. * Bay subdriver
  170. */
  171. #ifdef CONFIG_THINKPAD_ACPI_BAY
  172. static acpi_handle bay_handle, bay_ej_handle;
  173. static acpi_handle bay2_handle, bay2_ej_handle;
  174. static int bay_init(struct ibm_init_struct *iibm);
  175. static void bay_notify(struct ibm_struct *ibm, u32 event);
  176. static int bay_read(char *p);
  177. static int bay_write(char *buf);
  178. #endif /* CONFIG_THINKPAD_ACPI_BAY */
  179. /*
  180. * Beep subdriver
  181. */
  182. static acpi_handle beep_handle;
  183. static int beep_read(char *p);
  184. static int beep_write(char *buf);
  185. /*
  186. * Bluetooth subdriver
  187. */
  188. static int bluetooth_init(struct ibm_init_struct *iibm);
  189. static int bluetooth_status(void);
  190. static int bluetooth_read(char *p);
  191. static int bluetooth_write(char *buf);
  192. /*
  193. * Brightness (backlight) subdriver
  194. */
  195. static struct backlight_device *ibm_backlight_device;
  196. static int brightness_offset = 0x31;
  197. static int brightness_init(struct ibm_init_struct *iibm);
  198. static void brightness_exit(void);
  199. static int brightness_get(struct backlight_device *bd);
  200. static int brightness_set(int value);
  201. static int brightness_update_status(struct backlight_device *bd);
  202. static int brightness_read(char *p);
  203. static int brightness_write(char *buf);
  204. /*
  205. * CMOS subdriver
  206. */
  207. static int cmos_eval(int cmos_cmd);
  208. static int cmos_read(char *p);
  209. static int cmos_write(char *buf);
  210. /*
  211. * Dock subdriver
  212. */
  213. #ifdef CONFIG_THINKPAD_ACPI_DOCK
  214. static acpi_handle pci_handle;
  215. static acpi_handle dock_handle;
  216. static void dock_notify(struct ibm_struct *ibm, u32 event);
  217. static int dock_read(char *p);
  218. static int dock_write(char *buf);
  219. #endif /* CONFIG_THINKPAD_ACPI_DOCK */
  220. /*
  221. * EC dump subdriver
  222. */
  223. static int ecdump_read(char *p) ;
  224. static int ecdump_write(char *buf);
  225. /*
  226. * Fan subdriver
  227. */
  228. enum { /* Fan control constants */
  229. fan_status_offset = 0x2f, /* EC register 0x2f */
  230. fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
  231. * 0x84 must be read before 0x85 */
  232. TP_EC_FAN_FULLSPEED = 0x40, /* EC fan mode: full speed */
  233. TP_EC_FAN_AUTO = 0x80, /* EC fan mode: auto fan control */
  234. };
  235. enum fan_status_access_mode {
  236. TPACPI_FAN_NONE = 0, /* No fan status or control */
  237. TPACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
  238. TPACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
  239. };
  240. enum fan_control_access_mode {
  241. TPACPI_FAN_WR_NONE = 0, /* No fan control */
  242. TPACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
  243. TPACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
  244. TPACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
  245. };
  246. enum fan_control_commands {
  247. TPACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
  248. TPACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
  249. TPACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
  250. * and also watchdog cmd */
  251. };
  252. static enum fan_status_access_mode fan_status_access_mode;
  253. static enum fan_control_access_mode fan_control_access_mode;
  254. static enum fan_control_commands fan_control_commands;
  255. static u8 fan_control_initial_status;
  256. static int fan_watchdog_maxinterval;
  257. static acpi_handle fans_handle, gfan_handle, sfan_handle;
  258. static int fan_init(struct ibm_init_struct *iibm);
  259. static void fan_exit(void);
  260. static int fan_get_status(u8 *status);
  261. static int fan_get_speed(unsigned int *speed);
  262. static void fan_watchdog_fire(struct work_struct *ignored);
  263. static void fan_watchdog_reset(void);
  264. static int fan_set_level(int level);
  265. static int fan_set_enable(void);
  266. static int fan_set_disable(void);
  267. static int fan_set_speed(int speed);
  268. static int fan_read(char *p);
  269. static int fan_write(char *buf);
  270. static int fan_write_cmd_level(const char *cmd, int *rc);
  271. static int fan_write_cmd_enable(const char *cmd, int *rc);
  272. static int fan_write_cmd_disable(const char *cmd, int *rc);
  273. static int fan_write_cmd_speed(const char *cmd, int *rc);
  274. static int fan_write_cmd_watchdog(const char *cmd, int *rc);
  275. /*
  276. * Hotkey subdriver
  277. */
  278. static int hotkey_orig_status;
  279. static int hotkey_orig_mask;
  280. static int hotkey_init(struct ibm_init_struct *iibm);
  281. static void hotkey_exit(void);
  282. static int hotkey_get(int *status, int *mask);
  283. static int hotkey_set(int status, int mask);
  284. static void hotkey_notify(struct ibm_struct *ibm, u32 event);
  285. static int hotkey_read(char *p);
  286. static int hotkey_write(char *buf);
  287. /*
  288. * LED subdriver
  289. */
  290. enum led_access_mode {
  291. TPACPI_LED_NONE = 0,
  292. TPACPI_LED_570, /* 570 */
  293. TPACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
  294. TPACPI_LED_NEW, /* all others */
  295. };
  296. enum { /* For TPACPI_LED_OLD */
  297. TPACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */
  298. TPACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */
  299. TPACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */
  300. };
  301. static enum led_access_mode led_supported;
  302. static acpi_handle led_handle;
  303. static int led_init(struct ibm_init_struct *iibm);
  304. static int led_read(char *p);
  305. static int led_write(char *buf);
  306. /*
  307. * Light (thinklight) subdriver
  308. */
  309. static acpi_handle lght_handle, ledb_handle;
  310. static int light_init(struct ibm_init_struct *iibm);
  311. static int light_read(char *p);
  312. static int light_write(char *buf);
  313. /*
  314. * Thermal subdriver
  315. */
  316. enum thermal_access_mode {
  317. TPACPI_THERMAL_NONE = 0, /* No thermal support */
  318. TPACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
  319. TPACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
  320. TPACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
  321. TPACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
  322. };
  323. #define TPACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
  324. struct ibm_thermal_sensors_struct {
  325. s32 temp[TPACPI_MAX_THERMAL_SENSORS];
  326. };
  327. static int thermal_init(struct ibm_init_struct *iibm);
  328. static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
  329. static int thermal_read(char *p);
  330. /*
  331. * Video subdriver
  332. */
  333. enum video_access_mode {
  334. TPACPI_VIDEO_NONE = 0,
  335. TPACPI_VIDEO_570, /* 570 */
  336. TPACPI_VIDEO_770, /* 600e/x, 770e, 770x */
  337. TPACPI_VIDEO_NEW, /* all others */
  338. };
  339. static enum video_access_mode video_supported;
  340. static int video_orig_autosw;
  341. static acpi_handle vid_handle, vid2_handle;
  342. static int video_init(struct ibm_init_struct *iibm);
  343. static void video_exit(void);
  344. static int video_status(void);
  345. static int video_autosw(void);
  346. static int video_switch(void);
  347. static int video_switch2(int status);
  348. static int video_expand(void);
  349. static int video_read(char *p);
  350. static int video_write(char *buf);
  351. /*
  352. * Volume subdriver
  353. */
  354. static int volume_offset = 0x30;
  355. static int volume_read(char *p);
  356. static int volume_write(char *buf);
  357. /*
  358. * Wan subdriver
  359. */
  360. static int wan_init(struct ibm_init_struct *iibm);
  361. static int wan_status(void);
  362. static int wan_read(char *p);
  363. static int wan_write(char *buf);
  364. #endif /* __THINKPAD_ACPI_H */