thinkpad_acpi.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437
  1. /*
  2. * ibm_acpi.h - IBM 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 __IBM_ACPI_H__
  24. #define __IBM_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/proc_fs.h>
  31. #include <linux/backlight.h>
  32. #include <linux/fb.h>
  33. #include <asm/uaccess.h>
  34. #include <linux/dmi.h>
  35. #include <linux/jiffies.h>
  36. #include <linux/workqueue.h>
  37. #include <acpi/acpi_drivers.h>
  38. #include <acpi/acnamesp.h>
  39. /****************************************************************************
  40. * Main driver
  41. */
  42. #define IBM_NAME "ibm"
  43. #define IBM_DESC "IBM ThinkPad ACPI Extras"
  44. #define IBM_FILE "ibm_acpi"
  45. #define IBM_URL "http://ibm-acpi.sf.net/"
  46. #define IBM_DIR IBM_NAME
  47. #define IBM_LOG IBM_FILE ": "
  48. #define IBM_ERR KERN_ERR IBM_LOG
  49. #define IBM_NOTICE KERN_NOTICE IBM_LOG
  50. #define IBM_INFO KERN_INFO IBM_LOG
  51. #define IBM_DEBUG KERN_DEBUG IBM_LOG
  52. #define IBM_MAX_ACPI_ARGS 3
  53. /* ThinkPad CMOS commands */
  54. #define TP_CMOS_VOLUME_DOWN 0
  55. #define TP_CMOS_VOLUME_UP 1
  56. #define TP_CMOS_VOLUME_MUTE 2
  57. #define TP_CMOS_BRIGHTNESS_UP 4
  58. #define TP_CMOS_BRIGHTNESS_DOWN 5
  59. #define onoff(status,bit) ((status) & (1 << (bit)) ? "on" : "off")
  60. #define enabled(status,bit) ((status) & (1 << (bit)) ? "enabled" : "disabled")
  61. #define strlencmp(a,b) (strncmp((a), (b), strlen(b)))
  62. /* ACPI HIDs */
  63. #define IBM_HKEY_HID "IBM0068"
  64. #define IBM_PCI_HID "PNP0A03"
  65. /* ACPI helpers */
  66. static int acpi_evalf(acpi_handle handle,
  67. void *res, char *method, char *fmt, ...);
  68. static int acpi_ec_read(int i, u8 * p);
  69. static int acpi_ec_write(int i, u8 v);
  70. static int _sta(acpi_handle handle);
  71. /* ACPI handles */
  72. static acpi_handle root_handle; /* root namespace */
  73. static acpi_handle ec_handle; /* EC */
  74. static acpi_handle ecrd_handle, ecwr_handle; /* 570 EC access */
  75. static acpi_handle cmos_handle, hkey_handle; /* basic thinkpad handles */
  76. static void ibm_handle_init(char *name,
  77. acpi_handle * handle, acpi_handle parent,
  78. char **paths, int num_paths, char **path);
  79. #define IBM_HANDLE_INIT(object) \
  80. ibm_handle_init(#object, &object##_handle, *object##_parent, \
  81. object##_paths, ARRAY_SIZE(object##_paths), &object##_path)
  82. /* procfs support */
  83. static struct proc_dir_entry *proc_dir;
  84. static int ibm_acpi_driver_init(void);
  85. static int ibm_acpi_driver_read(char *p);
  86. /* procfs helpers */
  87. static int dispatch_read(char *page, char **start, off_t off, int count,
  88. int *eof, void *data);
  89. static int dispatch_write(struct file *file, const char __user * userbuf,
  90. unsigned long count, void *data);
  91. static char *next_cmd(char **cmds);
  92. /* Module */
  93. static int experimental;
  94. static char *ibm_thinkpad_ec_found;
  95. static char* check_dmi_for_ec(void);
  96. static int acpi_ibm_init(void);
  97. static void acpi_ibm_exit(void);
  98. /****************************************************************************
  99. * Subdrivers
  100. */
  101. struct ibm_struct {
  102. char *name;
  103. char param[32];
  104. char *hid;
  105. struct acpi_driver *driver;
  106. int (*init) (void);
  107. int (*read) (char *);
  108. int (*write) (char *);
  109. void (*exit) (void);
  110. void (*notify) (struct ibm_struct *, u32);
  111. acpi_handle *handle;
  112. int type;
  113. struct acpi_device *device;
  114. int driver_registered;
  115. int proc_created;
  116. int init_called;
  117. int notify_installed;
  118. int experimental;
  119. };
  120. static struct ibm_struct ibms[];
  121. static int set_ibm_param(const char *val, struct kernel_param *kp);
  122. static int ibm_init(struct ibm_struct *ibm);
  123. static void ibm_exit(struct ibm_struct *ibm);
  124. /* ACPI devices */
  125. static void dispatch_notify(acpi_handle handle, u32 event, void *data);
  126. static int setup_notify(struct ibm_struct *ibm);
  127. static int ibm_device_add(struct acpi_device *device);
  128. static int register_ibmacpi_subdriver(struct ibm_struct *ibm);
  129. /*
  130. * Bay subdriver
  131. */
  132. #ifdef CONFIG_ACPI_IBM_BAY
  133. static int bay_status_supported, bay_eject_supported;
  134. static int bay_status2_supported, bay_eject2_supported;
  135. static acpi_handle bay_handle, bay_ej_handle;
  136. static acpi_handle bay2_handle, bay2_ej_handle;
  137. static int bay_init(void);
  138. static void bay_notify(struct ibm_struct *ibm, u32 event);
  139. static int bay_read(char *p);
  140. static int bay_write(char *buf);
  141. #endif /* CONFIG_ACPI_IBM_BAY */
  142. /*
  143. * Beep subdriver
  144. */
  145. static acpi_handle beep_handle;
  146. static int beep_read(char *p);
  147. static int beep_write(char *buf);
  148. /*
  149. * Bluetooth subdriver
  150. */
  151. static int bluetooth_supported;
  152. static int bluetooth_init(void);
  153. static int bluetooth_status(void);
  154. static int bluetooth_read(char *p);
  155. static int bluetooth_write(char *buf);
  156. /*
  157. * Brightness (backlight) subdriver
  158. */
  159. static struct backlight_device *ibm_backlight_device;
  160. static int brightness_offset = 0x31;
  161. static int brightness_init(void);
  162. static void brightness_exit(void);
  163. static int brightness_get(struct backlight_device *bd);
  164. static int brightness_set(int value);
  165. static int brightness_update_status(struct backlight_device *bd);
  166. static int brightness_read(char *p);
  167. static int brightness_write(char *buf);
  168. /*
  169. * CMOS subdriver
  170. */
  171. static int cmos_eval(int cmos_cmd);
  172. static int cmos_read(char *p);
  173. static int cmos_write(char *buf);
  174. /*
  175. * Dock subdriver
  176. */
  177. static acpi_handle pci_handle;
  178. #ifdef CONFIG_ACPI_IBM_DOCK
  179. static acpi_handle dock_handle;
  180. static void dock_notify(struct ibm_struct *ibm, u32 event);
  181. static int dock_read(char *p);
  182. static int dock_write(char *buf);
  183. #endif /* CONFIG_ACPI_IBM_DOCK */
  184. /*
  185. * EC dump subdriver
  186. */
  187. static int ecdump_read(char *p) ;
  188. static int ecdump_write(char *buf);
  189. /*
  190. * Fan subdriver
  191. */
  192. enum { /* Fan control constants */
  193. fan_status_offset = 0x2f, /* EC register 0x2f */
  194. fan_rpm_offset = 0x84, /* EC register 0x84: LSB, 0x85 MSB (RPM)
  195. * 0x84 must be read before 0x85 */
  196. IBMACPI_FAN_EC_DISENGAGED = 0x40, /* EC mode: tachometer
  197. * disengaged */
  198. IBMACPI_FAN_EC_AUTO = 0x80, /* EC mode: auto fan
  199. * control */
  200. };
  201. enum fan_status_access_mode {
  202. IBMACPI_FAN_NONE = 0, /* No fan status or control */
  203. IBMACPI_FAN_RD_ACPI_GFAN, /* Use ACPI GFAN */
  204. IBMACPI_FAN_RD_TPEC, /* Use ACPI EC regs 0x2f, 0x84-0x85 */
  205. };
  206. enum fan_control_access_mode {
  207. IBMACPI_FAN_WR_NONE = 0, /* No fan control */
  208. IBMACPI_FAN_WR_ACPI_SFAN, /* Use ACPI SFAN */
  209. IBMACPI_FAN_WR_TPEC, /* Use ACPI EC reg 0x2f */
  210. IBMACPI_FAN_WR_ACPI_FANS, /* Use ACPI FANS and EC reg 0x2f */
  211. };
  212. enum fan_control_commands {
  213. IBMACPI_FAN_CMD_SPEED = 0x0001, /* speed command */
  214. IBMACPI_FAN_CMD_LEVEL = 0x0002, /* level command */
  215. IBMACPI_FAN_CMD_ENABLE = 0x0004, /* enable/disable cmd,
  216. * and also watchdog cmd */
  217. };
  218. static enum fan_status_access_mode fan_status_access_mode;
  219. static enum fan_control_access_mode fan_control_access_mode;
  220. static enum fan_control_commands fan_control_commands;
  221. static int fan_control_status_known;
  222. static u8 fan_control_initial_status;
  223. static int fan_watchdog_maxinterval;
  224. static acpi_handle fans_handle, gfan_handle, sfan_handle;
  225. static int fan_init(void);
  226. static void fan_exit(void);
  227. static int fan_get_status(u8 *status);
  228. static int fan_get_speed(unsigned int *speed);
  229. static void fan_watchdog_fire(struct work_struct *ignored);
  230. static void fan_watchdog_reset(void);
  231. static int fan_set_level(int level);
  232. static int fan_set_enable(void);
  233. static int fan_set_disable(void);
  234. static int fan_set_speed(int speed);
  235. static int fan_read(char *p);
  236. static int fan_write(char *buf);
  237. static int fan_write_cmd_level(const char *cmd, int *rc);
  238. static int fan_write_cmd_enable(const char *cmd, int *rc);
  239. static int fan_write_cmd_disable(const char *cmd, int *rc);
  240. static int fan_write_cmd_speed(const char *cmd, int *rc);
  241. static int fan_write_cmd_watchdog(const char *cmd, int *rc);
  242. /*
  243. * Hotkey subdriver
  244. */
  245. static int hotkey_supported;
  246. static int hotkey_mask_supported;
  247. static int hotkey_orig_status;
  248. static int hotkey_orig_mask;
  249. static int hotkey_init(void);
  250. static void hotkey_exit(void);
  251. static int hotkey_get(int *status, int *mask);
  252. static int hotkey_set(int status, int mask);
  253. static void hotkey_notify(struct ibm_struct *ibm, u32 event);
  254. static int hotkey_read(char *p);
  255. static int hotkey_write(char *buf);
  256. /*
  257. * LED subdriver
  258. */
  259. enum led_access_mode {
  260. IBMACPI_LED_NONE = 0,
  261. IBMACPI_LED_570, /* 570 */
  262. IBMACPI_LED_OLD, /* 600e/x, 770e, 770x, A21e, A2xm/p, T20-22, X20-21 */
  263. IBMACPI_LED_NEW, /* all others */
  264. };
  265. enum { /* For IBMACPI_LED_OLD */
  266. IBMACPI_LED_EC_HLCL = 0x0c, /* EC reg to get led to power on */
  267. IBMACPI_LED_EC_HLBL = 0x0d, /* EC reg to blink a lit led */
  268. IBMACPI_LED_EC_HLMS = 0x0e, /* EC reg to select led to command */
  269. };
  270. static enum led_access_mode led_supported;
  271. static acpi_handle led_handle;
  272. static int led_init(void);
  273. static int led_read(char *p);
  274. static int led_write(char *buf);
  275. /*
  276. * Light (thinklight) subdriver
  277. */
  278. static int light_supported;
  279. static int light_status_supported;
  280. static acpi_handle lght_handle, ledb_handle;
  281. static int light_init(void);
  282. static int light_read(char *p);
  283. static int light_write(char *buf);
  284. /*
  285. * Thermal subdriver
  286. */
  287. enum thermal_access_mode {
  288. IBMACPI_THERMAL_NONE = 0, /* No thermal support */
  289. IBMACPI_THERMAL_ACPI_TMP07, /* Use ACPI TMP0-7 */
  290. IBMACPI_THERMAL_ACPI_UPDT, /* Use ACPI TMP0-7 with UPDT */
  291. IBMACPI_THERMAL_TPEC_8, /* Use ACPI EC regs, 8 sensors */
  292. IBMACPI_THERMAL_TPEC_16, /* Use ACPI EC regs, 16 sensors */
  293. };
  294. #define IBMACPI_MAX_THERMAL_SENSORS 16 /* Max thermal sensors supported */
  295. struct ibm_thermal_sensors_struct {
  296. s32 temp[IBMACPI_MAX_THERMAL_SENSORS];
  297. };
  298. static int thermal_init(void);
  299. static int thermal_get_sensors(struct ibm_thermal_sensors_struct *s);
  300. static int thermal_read(char *p);
  301. /*
  302. * Video subdriver
  303. */
  304. enum video_access_mode {
  305. IBMACPI_VIDEO_NONE = 0,
  306. IBMACPI_VIDEO_570, /* 570 */
  307. IBMACPI_VIDEO_770, /* 600e/x, 770e, 770x */
  308. IBMACPI_VIDEO_NEW, /* all others */
  309. };
  310. static enum video_access_mode video_supported;
  311. static int video_orig_autosw;
  312. static acpi_handle vid_handle, vid2_handle;
  313. static int video_init(void);
  314. static void video_exit(void);
  315. static int video_status(void);
  316. static int video_autosw(void);
  317. static int video_switch(void);
  318. static int video_switch2(int status);
  319. static int video_expand(void);
  320. static int video_read(char *p);
  321. static int video_write(char *buf);
  322. /*
  323. * Volume subdriver
  324. */
  325. static int volume_offset = 0x30;
  326. static int volume_read(char *p);
  327. static int volume_write(char *buf);
  328. /*
  329. * Wan subdriver
  330. */
  331. static int wan_supported;
  332. static int wan_init(void);
  333. static int wan_status(void);
  334. static int wan_read(char *p);
  335. static int wan_write(char *buf);
  336. #endif /* __IBM_ACPI_H */