thinkpad_acpi.h 12 KB

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