eeepc-wmi.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. /*
  2. * Eee PC WMI hotkey driver
  3. *
  4. * Copyright(C) 2010 Intel Corporation.
  5. * Copyright(C) 2010-2011 Corentin Chary <corentin.chary@gmail.com>
  6. *
  7. * Portions based on wistron_btns.c:
  8. * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
  9. * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
  10. * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <linux/init.h>
  30. #include <linux/input.h>
  31. #include <linux/input/sparse-keymap.h>
  32. #include <linux/dmi.h>
  33. #include <linux/fb.h>
  34. #include <linux/acpi.h>
  35. #include "asus-wmi.h"
  36. #define EEEPC_WMI_FILE "eeepc-wmi"
  37. MODULE_AUTHOR("Corentin Chary <corentin.chary@gmail.com>");
  38. MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver");
  39. MODULE_LICENSE("GPL");
  40. #define EEEPC_ACPI_HID "ASUS010" /* old _HID used in eeepc-laptop */
  41. #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000"
  42. MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID);
  43. static bool hotplug_wireless;
  44. module_param(hotplug_wireless, bool, 0444);
  45. MODULE_PARM_DESC(hotplug_wireless,
  46. "Enable hotplug for wireless device. "
  47. "If your laptop needs that, please report to "
  48. "acpi4asus-user@lists.sourceforge.net.");
  49. /* Values for T101MT "Home" key */
  50. #define HOME_PRESS 0xe4
  51. #define HOME_HOLD 0xea
  52. #define HOME_RELEASE 0xe5
  53. static const struct key_entry eeepc_wmi_keymap[] = {
  54. { KE_KEY, ASUS_WMI_BRN_DOWN, { KEY_BRIGHTNESSDOWN } },
  55. { KE_KEY, ASUS_WMI_BRN_UP, { KEY_BRIGHTNESSUP } },
  56. /* Sleep already handled via generic ACPI code */
  57. { KE_KEY, 0x30, { KEY_VOLUMEUP } },
  58. { KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
  59. { KE_KEY, 0x32, { KEY_MUTE } },
  60. { KE_KEY, 0x5c, { KEY_F15 } }, /* Power Gear key */
  61. { KE_KEY, 0x5d, { KEY_WLAN } },
  62. { KE_KEY, 0x6b, { KEY_TOUCHPAD_TOGGLE } }, /* Toggle Touchpad */
  63. { KE_KEY, 0x82, { KEY_CAMERA } },
  64. { KE_KEY, 0x83, { KEY_CAMERA_ZOOMIN } },
  65. { KE_KEY, 0x88, { KEY_WLAN } },
  66. { KE_KEY, 0xbd, { KEY_CAMERA } },
  67. { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
  68. { KE_KEY, 0xe0, { KEY_PROG1 } }, /* Task Manager */
  69. { KE_KEY, 0xe1, { KEY_F14 } }, /* Change Resolution */
  70. { KE_KEY, HOME_PRESS, { KEY_CONFIG } }, /* Home/Express gate key */
  71. { KE_KEY, 0xe8, { KEY_SCREENLOCK } },
  72. { KE_KEY, 0xe9, { KEY_DISPLAYTOGGLE } },
  73. { KE_KEY, 0xeb, { KEY_CAMERA_ZOOMOUT } },
  74. { KE_KEY, 0xec, { KEY_CAMERA_UP } },
  75. { KE_KEY, 0xed, { KEY_CAMERA_DOWN } },
  76. { KE_KEY, 0xee, { KEY_CAMERA_LEFT } },
  77. { KE_KEY, 0xef, { KEY_CAMERA_RIGHT } },
  78. { KE_KEY, 0xf3, { KEY_MENU } },
  79. { KE_KEY, 0xf5, { KEY_HOMEPAGE } },
  80. { KE_KEY, 0xf6, { KEY_ESC } },
  81. { KE_END, 0},
  82. };
  83. static struct quirk_entry quirk_asus_unknown = {
  84. };
  85. static struct quirk_entry quirk_asus_1000h = {
  86. .hotplug_wireless = true,
  87. };
  88. static struct quirk_entry quirk_asus_et2012_type1 = {
  89. .store_backlight_power = true,
  90. };
  91. static struct quirk_entry quirk_asus_et2012_type3 = {
  92. .scalar_panel_brightness = true,
  93. .store_backlight_power = true,
  94. };
  95. static struct quirk_entry quirk_asus_x101ch = {
  96. /* We need this when ACPI function doesn't do this well */
  97. .wmi_backlight_power = true,
  98. };
  99. static struct quirk_entry *quirks;
  100. static void et2012_quirks(void)
  101. {
  102. const struct dmi_device *dev = NULL;
  103. char oemstring[30];
  104. while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING, NULL, dev))) {
  105. if (sscanf(dev->name, "AEMS%24c", oemstring) == 1) {
  106. if (oemstring[18] == '1')
  107. quirks = &quirk_asus_et2012_type1;
  108. else if (oemstring[18] == '3')
  109. quirks = &quirk_asus_et2012_type3;
  110. break;
  111. }
  112. }
  113. }
  114. static int dmi_matched(const struct dmi_system_id *dmi)
  115. {
  116. char *model;
  117. quirks = dmi->driver_data;
  118. model = (char *)dmi->matches[1].substr;
  119. if (unlikely(strncmp(model, "ET2012", 6) == 0))
  120. et2012_quirks();
  121. return 1;
  122. }
  123. static const struct dmi_system_id asus_quirks[] = {
  124. {
  125. .callback = dmi_matched,
  126. .ident = "ASUSTeK Computer INC. 1000H",
  127. .matches = {
  128. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
  129. DMI_MATCH(DMI_PRODUCT_NAME, "1000H"),
  130. },
  131. .driver_data = &quirk_asus_1000h,
  132. },
  133. {
  134. .callback = dmi_matched,
  135. .ident = "ASUSTeK Computer INC. ET2012E/I",
  136. .matches = {
  137. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer INC."),
  138. DMI_MATCH(DMI_PRODUCT_NAME, "ET2012"),
  139. },
  140. .driver_data = &quirk_asus_unknown,
  141. },
  142. {
  143. .callback = dmi_matched,
  144. .ident = "ASUSTeK Computer INC. X101CH",
  145. .matches = {
  146. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  147. DMI_MATCH(DMI_PRODUCT_NAME, "X101CH"),
  148. },
  149. .driver_data = &quirk_asus_x101ch,
  150. },
  151. {
  152. .callback = dmi_matched,
  153. .ident = "ASUSTeK Computer INC. 1015CX",
  154. .matches = {
  155. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK COMPUTER INC."),
  156. DMI_MATCH(DMI_PRODUCT_NAME, "1015CX"),
  157. },
  158. .driver_data = &quirk_asus_x101ch,
  159. },
  160. {},
  161. };
  162. static void eeepc_wmi_key_filter(struct asus_wmi_driver *asus_wmi, int *code,
  163. unsigned int *value, bool *autorelease)
  164. {
  165. switch (*code) {
  166. case HOME_PRESS:
  167. *value = 1;
  168. *autorelease = 0;
  169. break;
  170. case HOME_HOLD:
  171. *code = ASUS_WMI_KEY_IGNORE;
  172. break;
  173. case HOME_RELEASE:
  174. *code = HOME_PRESS;
  175. *value = 0;
  176. *autorelease = 0;
  177. break;
  178. }
  179. }
  180. static int eeepc_wmi_probe(struct platform_device *pdev)
  181. {
  182. if (acpi_dev_found(EEEPC_ACPI_HID)) {
  183. pr_warn("Found legacy ATKD device (%s)\n", EEEPC_ACPI_HID);
  184. pr_warn("WMI device present, but legacy ATKD device is also "
  185. "present and enabled\n");
  186. pr_warn("You probably booted with acpi_osi=\"Linux\" or "
  187. "acpi_osi=\"!Windows 2009\"\n");
  188. pr_warn("Can't load eeepc-wmi, use default acpi_osi "
  189. "(preferred) or eeepc-laptop\n");
  190. return -EBUSY;
  191. }
  192. return 0;
  193. }
  194. static void eeepc_wmi_quirks(struct asus_wmi_driver *driver)
  195. {
  196. quirks = &quirk_asus_unknown;
  197. quirks->hotplug_wireless = hotplug_wireless;
  198. dmi_check_system(asus_quirks);
  199. driver->quirks = quirks;
  200. driver->quirks->wapf = -1;
  201. driver->panel_power = FB_BLANK_UNBLANK;
  202. }
  203. static struct asus_wmi_driver asus_wmi_driver = {
  204. .name = EEEPC_WMI_FILE,
  205. .owner = THIS_MODULE,
  206. .event_guid = EEEPC_WMI_EVENT_GUID,
  207. .keymap = eeepc_wmi_keymap,
  208. .input_name = "Eee PC WMI hotkeys",
  209. .input_phys = EEEPC_WMI_FILE "/input0",
  210. .key_filter = eeepc_wmi_key_filter,
  211. .probe = eeepc_wmi_probe,
  212. .detect_quirks = eeepc_wmi_quirks,
  213. };
  214. static int __init eeepc_wmi_init(void)
  215. {
  216. return asus_wmi_register_driver(&asus_wmi_driver);
  217. }
  218. static void __exit eeepc_wmi_exit(void)
  219. {
  220. asus_wmi_unregister_driver(&asus_wmi_driver);
  221. }
  222. module_init(eeepc_wmi_init);
  223. module_exit(eeepc_wmi_exit);