eeepc-wmi.c 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  1. /*
  2. * Eee PC WMI hotkey driver
  3. *
  4. * Copyright(C) 2010 Intel Corporation.
  5. * Copyright(C) 2010 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/types.h>
  31. #include <linux/slab.h>
  32. #include <linux/input.h>
  33. #include <linux/input/sparse-keymap.h>
  34. #include <linux/fb.h>
  35. #include <linux/backlight.h>
  36. #include <linux/leds.h>
  37. #include <linux/rfkill.h>
  38. #include <linux/pci.h>
  39. #include <linux/pci_hotplug.h>
  40. #include <linux/debugfs.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/platform_device.h>
  43. #include <linux/dmi.h>
  44. #include <acpi/acpi_bus.h>
  45. #include <acpi/acpi_drivers.h>
  46. #define EEEPC_WMI_FILE "eeepc-wmi"
  47. MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>");
  48. MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver");
  49. MODULE_LICENSE("GPL");
  50. #define EEEPC_ACPI_HID "ASUS010" /* old _HID used in eeepc-laptop */
  51. #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000"
  52. #define EEEPC_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66"
  53. MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID);
  54. MODULE_ALIAS("wmi:"EEEPC_WMI_MGMT_GUID);
  55. #define NOTIFY_BRNUP_MIN 0x11
  56. #define NOTIFY_BRNUP_MAX 0x1f
  57. #define NOTIFY_BRNDOWN_MIN 0x20
  58. #define NOTIFY_BRNDOWN_MAX 0x2e
  59. #define EEEPC_WMI_METHODID_DSTS 0x53544344
  60. #define EEEPC_WMI_METHODID_DEVS 0x53564544
  61. #define EEEPC_WMI_METHODID_CFVS 0x53564643
  62. #define EEEPC_WMI_DEVID_WLAN 0x00010011
  63. #define EEEPC_WMI_DEVID_BLUETOOTH 0x00010013
  64. #define EEEPC_WMI_DEVID_WIMAX 0x00010017
  65. #define EEEPC_WMI_DEVID_WWAN3G 0x00010019
  66. #define EEEPC_WMI_DEVID_BACKLIGHT 0x00050011
  67. #define EEEPC_WMI_DEVID_BRIGHTNESS 0x00050012
  68. #define EEEPC_WMI_DEVID_CAMERA 0x00060013
  69. #define EEEPC_WMI_DEVID_CARDREADER 0x00080013
  70. #define EEEPC_WMI_DEVID_TOUCHPAD_LED 0x00100012
  71. #define EEEPC_WMI_DSTS_STATUS_BIT 0x00000001
  72. #define EEEPC_WMI_DSTS_PRESENCE_BIT 0x00010000
  73. #define EEEPC_WMI_DSTS_BRIGHTNESS_MASK 0x000000FF
  74. #define EEEPC_WMI_DSTS_MAX_BRIGTH_MASK 0x0000FF00
  75. static bool hotplug_wireless;
  76. module_param(hotplug_wireless, bool, 0444);
  77. MODULE_PARM_DESC(hotplug_wireless,
  78. "Enable hotplug for wireless device. "
  79. "If your laptop needs that, please report to "
  80. "acpi4asus-user@lists.sourceforge.net.");
  81. static const struct key_entry eeepc_wmi_keymap[] = {
  82. /* Sleep already handled via generic ACPI code */
  83. { KE_IGNORE, NOTIFY_BRNDOWN_MIN, { KEY_BRIGHTNESSDOWN } },
  84. { KE_IGNORE, NOTIFY_BRNUP_MIN, { KEY_BRIGHTNESSUP } },
  85. { KE_KEY, 0x30, { KEY_VOLUMEUP } },
  86. { KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
  87. { KE_KEY, 0x32, { KEY_MUTE } },
  88. { KE_KEY, 0x5c, { KEY_F15 } }, /* Power Gear key */
  89. { KE_KEY, 0x5d, { KEY_WLAN } },
  90. { KE_KEY, 0x6b, { KEY_F13 } }, /* Disable Touchpad */
  91. { KE_KEY, 0x88, { KEY_WLAN } },
  92. { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
  93. { KE_KEY, 0xe0, { KEY_PROG1 } }, /* Task Manager */
  94. { KE_KEY, 0xe1, { KEY_F14 } }, /* Change Resolution */
  95. { KE_KEY, 0xe9, { KEY_BRIGHTNESS_ZERO } },
  96. { KE_END, 0},
  97. };
  98. struct bios_args {
  99. u32 dev_id;
  100. u32 ctrl_param;
  101. };
  102. /*
  103. * eeepc-wmi/ - debugfs root directory
  104. * dev_id - current dev_id
  105. * ctrl_param - current ctrl_param
  106. * devs - call DEVS(dev_id, ctrl_param) and print result
  107. * dsts - call DSTS(dev_id) and print result
  108. */
  109. struct eeepc_wmi_debug {
  110. struct dentry *root;
  111. u32 dev_id;
  112. u32 ctrl_param;
  113. };
  114. struct eeepc_wmi {
  115. bool hotplug_wireless;
  116. struct input_dev *inputdev;
  117. struct backlight_device *backlight_device;
  118. struct platform_device *platform_device;
  119. struct led_classdev tpd_led;
  120. int tpd_led_wk;
  121. struct workqueue_struct *led_workqueue;
  122. struct work_struct tpd_led_work;
  123. struct rfkill *wlan_rfkill;
  124. struct rfkill *bluetooth_rfkill;
  125. struct rfkill *wimax_rfkill;
  126. struct rfkill *wwan3g_rfkill;
  127. struct hotplug_slot *hotplug_slot;
  128. struct mutex hotplug_lock;
  129. struct mutex wmi_lock;
  130. struct workqueue_struct *hotplug_workqueue;
  131. struct work_struct hotplug_work;
  132. struct eeepc_wmi_debug debug;
  133. };
  134. static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc)
  135. {
  136. int err;
  137. eeepc->inputdev = input_allocate_device();
  138. if (!eeepc->inputdev)
  139. return -ENOMEM;
  140. eeepc->inputdev->name = "Eee PC WMI hotkeys";
  141. eeepc->inputdev->phys = EEEPC_WMI_FILE "/input0";
  142. eeepc->inputdev->id.bustype = BUS_HOST;
  143. eeepc->inputdev->dev.parent = &eeepc->platform_device->dev;
  144. err = sparse_keymap_setup(eeepc->inputdev, eeepc_wmi_keymap, NULL);
  145. if (err)
  146. goto err_free_dev;
  147. err = input_register_device(eeepc->inputdev);
  148. if (err)
  149. goto err_free_keymap;
  150. return 0;
  151. err_free_keymap:
  152. sparse_keymap_free(eeepc->inputdev);
  153. err_free_dev:
  154. input_free_device(eeepc->inputdev);
  155. return err;
  156. }
  157. static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc)
  158. {
  159. if (eeepc->inputdev) {
  160. sparse_keymap_free(eeepc->inputdev);
  161. input_unregister_device(eeepc->inputdev);
  162. }
  163. eeepc->inputdev = NULL;
  164. }
  165. static acpi_status eeepc_wmi_get_devstate(u32 dev_id, u32 *retval)
  166. {
  167. struct acpi_buffer input = { (acpi_size)sizeof(u32), &dev_id };
  168. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  169. union acpi_object *obj;
  170. acpi_status status;
  171. u32 tmp;
  172. status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID,
  173. 1, EEEPC_WMI_METHODID_DSTS,
  174. &input, &output);
  175. if (ACPI_FAILURE(status))
  176. return status;
  177. obj = (union acpi_object *)output.pointer;
  178. if (obj && obj->type == ACPI_TYPE_INTEGER)
  179. tmp = (u32)obj->integer.value;
  180. else
  181. tmp = 0;
  182. if (retval)
  183. *retval = tmp;
  184. kfree(obj);
  185. return status;
  186. }
  187. static acpi_status eeepc_wmi_set_devstate(u32 dev_id, u32 ctrl_param,
  188. u32 *retval)
  189. {
  190. struct bios_args args = {
  191. .dev_id = dev_id,
  192. .ctrl_param = ctrl_param,
  193. };
  194. struct acpi_buffer input = { (acpi_size)sizeof(args), &args };
  195. acpi_status status;
  196. if (!retval) {
  197. status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1,
  198. EEEPC_WMI_METHODID_DEVS,
  199. &input, NULL);
  200. } else {
  201. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  202. union acpi_object *obj;
  203. u32 tmp;
  204. status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1,
  205. EEEPC_WMI_METHODID_DEVS,
  206. &input, &output);
  207. if (ACPI_FAILURE(status))
  208. return status;
  209. obj = (union acpi_object *)output.pointer;
  210. if (obj && obj->type == ACPI_TYPE_INTEGER)
  211. tmp = (u32)obj->integer.value;
  212. else
  213. tmp = 0;
  214. *retval = tmp;
  215. kfree(obj);
  216. }
  217. return status;
  218. }
  219. /* Helper for special devices with magic return codes */
  220. static int eeepc_wmi_get_devstate_bits(u32 dev_id, u32 mask)
  221. {
  222. u32 retval = 0;
  223. acpi_status status;
  224. status = eeepc_wmi_get_devstate(dev_id, &retval);
  225. if (ACPI_FAILURE(status))
  226. return -EINVAL;
  227. if (!(retval & EEEPC_WMI_DSTS_PRESENCE_BIT))
  228. return -ENODEV;
  229. return retval & mask;
  230. }
  231. static int eeepc_wmi_get_devstate_simple(u32 dev_id)
  232. {
  233. return eeepc_wmi_get_devstate_bits(dev_id, EEEPC_WMI_DSTS_STATUS_BIT);
  234. }
  235. /*
  236. * LEDs
  237. */
  238. /*
  239. * These functions actually update the LED's, and are called from a
  240. * workqueue. By doing this as separate work rather than when the LED
  241. * subsystem asks, we avoid messing with the Eeepc ACPI stuff during a
  242. * potentially bad time, such as a timer interrupt.
  243. */
  244. static void tpd_led_update(struct work_struct *work)
  245. {
  246. int ctrl_param;
  247. struct eeepc_wmi *eeepc;
  248. eeepc = container_of(work, struct eeepc_wmi, tpd_led_work);
  249. ctrl_param = eeepc->tpd_led_wk;
  250. eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_TOUCHPAD_LED, ctrl_param, NULL);
  251. }
  252. static void tpd_led_set(struct led_classdev *led_cdev,
  253. enum led_brightness value)
  254. {
  255. struct eeepc_wmi *eeepc;
  256. eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led);
  257. eeepc->tpd_led_wk = !!value;
  258. queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work);
  259. }
  260. static int read_tpd_led_state(struct eeepc_wmi *eeepc)
  261. {
  262. return eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_TOUCHPAD_LED);
  263. }
  264. static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
  265. {
  266. struct eeepc_wmi *eeepc;
  267. eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led);
  268. return read_tpd_led_state(eeepc);
  269. }
  270. static int eeepc_wmi_led_init(struct eeepc_wmi *eeepc)
  271. {
  272. int rv;
  273. if (read_tpd_led_state(eeepc) < 0)
  274. return 0;
  275. eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue");
  276. if (!eeepc->led_workqueue)
  277. return -ENOMEM;
  278. INIT_WORK(&eeepc->tpd_led_work, tpd_led_update);
  279. eeepc->tpd_led.name = "eeepc::touchpad";
  280. eeepc->tpd_led.brightness_set = tpd_led_set;
  281. eeepc->tpd_led.brightness_get = tpd_led_get;
  282. eeepc->tpd_led.max_brightness = 1;
  283. rv = led_classdev_register(&eeepc->platform_device->dev,
  284. &eeepc->tpd_led);
  285. if (rv) {
  286. destroy_workqueue(eeepc->led_workqueue);
  287. return rv;
  288. }
  289. return 0;
  290. }
  291. static void eeepc_wmi_led_exit(struct eeepc_wmi *eeepc)
  292. {
  293. if (eeepc->tpd_led.dev)
  294. led_classdev_unregister(&eeepc->tpd_led);
  295. if (eeepc->led_workqueue)
  296. destroy_workqueue(eeepc->led_workqueue);
  297. }
  298. /*
  299. * PCI hotplug (for wlan rfkill)
  300. */
  301. static bool eeepc_wlan_rfkill_blocked(struct eeepc_wmi *eeepc)
  302. {
  303. int result = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
  304. if (result < 0)
  305. return false;
  306. return !result;
  307. }
  308. static void eeepc_rfkill_hotplug(struct eeepc_wmi *eeepc)
  309. {
  310. struct pci_dev *dev;
  311. struct pci_bus *bus;
  312. bool blocked;
  313. bool absent;
  314. u32 l;
  315. mutex_lock(&eeepc->wmi_lock);
  316. blocked = eeepc_wlan_rfkill_blocked(eeepc);
  317. mutex_unlock(&eeepc->wmi_lock);
  318. mutex_lock(&eeepc->hotplug_lock);
  319. if (eeepc->wlan_rfkill)
  320. rfkill_set_sw_state(eeepc->wlan_rfkill, blocked);
  321. if (eeepc->hotplug_slot) {
  322. bus = pci_find_bus(0, 1);
  323. if (!bus) {
  324. pr_warning("Unable to find PCI bus 1?\n");
  325. goto out_unlock;
  326. }
  327. if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
  328. pr_err("Unable to read PCI config space?\n");
  329. goto out_unlock;
  330. }
  331. absent = (l == 0xffffffff);
  332. if (blocked != absent) {
  333. pr_warning("BIOS says wireless lan is %s, "
  334. "but the pci device is %s\n",
  335. blocked ? "blocked" : "unblocked",
  336. absent ? "absent" : "present");
  337. pr_warning("skipped wireless hotplug as probably "
  338. "inappropriate for this model\n");
  339. goto out_unlock;
  340. }
  341. if (!blocked) {
  342. dev = pci_get_slot(bus, 0);
  343. if (dev) {
  344. /* Device already present */
  345. pci_dev_put(dev);
  346. goto out_unlock;
  347. }
  348. dev = pci_scan_single_device(bus, 0);
  349. if (dev) {
  350. pci_bus_assign_resources(bus);
  351. if (pci_bus_add_device(dev))
  352. pr_err("Unable to hotplug wifi\n");
  353. }
  354. } else {
  355. dev = pci_get_slot(bus, 0);
  356. if (dev) {
  357. pci_remove_bus_device(dev);
  358. pci_dev_put(dev);
  359. }
  360. }
  361. }
  362. out_unlock:
  363. mutex_unlock(&eeepc->hotplug_lock);
  364. }
  365. static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
  366. {
  367. struct eeepc_wmi *eeepc = data;
  368. if (event != ACPI_NOTIFY_BUS_CHECK)
  369. return;
  370. /*
  371. * We can't call directly eeepc_rfkill_hotplug because most
  372. * of the time WMBC is still being executed and not reetrant.
  373. * There is currently no way to tell ACPICA that we want this
  374. * method to be serialized, we schedule a eeepc_rfkill_hotplug
  375. * call later, in a safer context.
  376. */
  377. queue_work(eeepc->hotplug_workqueue, &eeepc->hotplug_work);
  378. }
  379. static int eeepc_register_rfkill_notifier(struct eeepc_wmi *eeepc,
  380. char *node)
  381. {
  382. acpi_status status;
  383. acpi_handle handle;
  384. status = acpi_get_handle(NULL, node, &handle);
  385. if (ACPI_SUCCESS(status)) {
  386. status = acpi_install_notify_handler(handle,
  387. ACPI_SYSTEM_NOTIFY,
  388. eeepc_rfkill_notify,
  389. eeepc);
  390. if (ACPI_FAILURE(status))
  391. pr_warning("Failed to register notify on %s\n", node);
  392. } else
  393. return -ENODEV;
  394. return 0;
  395. }
  396. static void eeepc_unregister_rfkill_notifier(struct eeepc_wmi *eeepc,
  397. char *node)
  398. {
  399. acpi_status status = AE_OK;
  400. acpi_handle handle;
  401. status = acpi_get_handle(NULL, node, &handle);
  402. if (ACPI_SUCCESS(status)) {
  403. status = acpi_remove_notify_handler(handle,
  404. ACPI_SYSTEM_NOTIFY,
  405. eeepc_rfkill_notify);
  406. if (ACPI_FAILURE(status))
  407. pr_err("Error removing rfkill notify handler %s\n",
  408. node);
  409. }
  410. }
  411. static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
  412. u8 *value)
  413. {
  414. int result = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
  415. if (result < 0)
  416. return result;
  417. *value = !!result;
  418. return 0;
  419. }
  420. static void eeepc_cleanup_pci_hotplug(struct hotplug_slot *hotplug_slot)
  421. {
  422. kfree(hotplug_slot->info);
  423. kfree(hotplug_slot);
  424. }
  425. static struct hotplug_slot_ops eeepc_hotplug_slot_ops = {
  426. .owner = THIS_MODULE,
  427. .get_adapter_status = eeepc_get_adapter_status,
  428. .get_power_status = eeepc_get_adapter_status,
  429. };
  430. static void eeepc_hotplug_work(struct work_struct *work)
  431. {
  432. struct eeepc_wmi *eeepc;
  433. eeepc = container_of(work, struct eeepc_wmi, hotplug_work);
  434. eeepc_rfkill_hotplug(eeepc);
  435. }
  436. static int eeepc_setup_pci_hotplug(struct eeepc_wmi *eeepc)
  437. {
  438. int ret = -ENOMEM;
  439. struct pci_bus *bus = pci_find_bus(0, 1);
  440. if (!bus) {
  441. pr_err("Unable to find wifi PCI bus\n");
  442. return -ENODEV;
  443. }
  444. eeepc->hotplug_workqueue =
  445. create_singlethread_workqueue("hotplug_workqueue");
  446. if (!eeepc->hotplug_workqueue)
  447. goto error_workqueue;
  448. INIT_WORK(&eeepc->hotplug_work, eeepc_hotplug_work);
  449. eeepc->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
  450. if (!eeepc->hotplug_slot)
  451. goto error_slot;
  452. eeepc->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
  453. GFP_KERNEL);
  454. if (!eeepc->hotplug_slot->info)
  455. goto error_info;
  456. eeepc->hotplug_slot->private = eeepc;
  457. eeepc->hotplug_slot->release = &eeepc_cleanup_pci_hotplug;
  458. eeepc->hotplug_slot->ops = &eeepc_hotplug_slot_ops;
  459. eeepc_get_adapter_status(eeepc->hotplug_slot,
  460. &eeepc->hotplug_slot->info->adapter_status);
  461. ret = pci_hp_register(eeepc->hotplug_slot, bus, 0, "eeepc-wifi");
  462. if (ret) {
  463. pr_err("Unable to register hotplug slot - %d\n", ret);
  464. goto error_register;
  465. }
  466. return 0;
  467. error_register:
  468. kfree(eeepc->hotplug_slot->info);
  469. error_info:
  470. kfree(eeepc->hotplug_slot);
  471. eeepc->hotplug_slot = NULL;
  472. error_slot:
  473. destroy_workqueue(eeepc->hotplug_workqueue);
  474. error_workqueue:
  475. return ret;
  476. }
  477. /*
  478. * Rfkill devices
  479. */
  480. static int eeepc_rfkill_set(void *data, bool blocked)
  481. {
  482. int dev_id = (unsigned long)data;
  483. u32 ctrl_param = !blocked;
  484. acpi_status status;
  485. status = eeepc_wmi_set_devstate(dev_id, ctrl_param, NULL);
  486. if (ACPI_FAILURE(status))
  487. return -EIO;
  488. return 0;
  489. }
  490. static void eeepc_rfkill_query(struct rfkill *rfkill, void *data)
  491. {
  492. int dev_id = (unsigned long)data;
  493. int result;
  494. result = eeepc_wmi_get_devstate_simple(dev_id);
  495. if (result < 0)
  496. return ;
  497. rfkill_set_sw_state(rfkill, !result);
  498. }
  499. static int eeepc_rfkill_wlan_set(void *data, bool blocked)
  500. {
  501. struct eeepc_wmi *eeepc = data;
  502. int ret;
  503. /*
  504. * This handler is enabled only if hotplug is enabled.
  505. * In this case, the eeepc_wmi_set_devstate() will
  506. * trigger a wmi notification and we need to wait
  507. * this call to finish before being able to call
  508. * any wmi method
  509. */
  510. mutex_lock(&eeepc->wmi_lock);
  511. ret = eeepc_rfkill_set((void *)(long)EEEPC_WMI_DEVID_WLAN, blocked);
  512. mutex_unlock(&eeepc->wmi_lock);
  513. return ret;
  514. }
  515. static void eeepc_rfkill_wlan_query(struct rfkill *rfkill, void *data)
  516. {
  517. eeepc_rfkill_query(rfkill, (void *)(long)EEEPC_WMI_DEVID_WLAN);
  518. }
  519. static const struct rfkill_ops eeepc_rfkill_wlan_ops = {
  520. .set_block = eeepc_rfkill_wlan_set,
  521. .query = eeepc_rfkill_wlan_query,
  522. };
  523. static const struct rfkill_ops eeepc_rfkill_ops = {
  524. .set_block = eeepc_rfkill_set,
  525. .query = eeepc_rfkill_query,
  526. };
  527. static int eeepc_new_rfkill(struct eeepc_wmi *eeepc,
  528. struct rfkill **rfkill,
  529. const char *name,
  530. enum rfkill_type type, int dev_id)
  531. {
  532. int result = eeepc_wmi_get_devstate_simple(dev_id);
  533. if (result < 0)
  534. return result;
  535. if (dev_id == EEEPC_WMI_DEVID_WLAN && eeepc->hotplug_wireless)
  536. *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
  537. &eeepc_rfkill_wlan_ops, eeepc);
  538. else
  539. *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
  540. &eeepc_rfkill_ops, (void *)(long)dev_id);
  541. if (!*rfkill)
  542. return -EINVAL;
  543. rfkill_init_sw_state(*rfkill, !result);
  544. result = rfkill_register(*rfkill);
  545. if (result) {
  546. rfkill_destroy(*rfkill);
  547. *rfkill = NULL;
  548. return result;
  549. }
  550. return 0;
  551. }
  552. static void eeepc_wmi_rfkill_exit(struct eeepc_wmi *eeepc)
  553. {
  554. eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
  555. eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
  556. eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
  557. if (eeepc->wlan_rfkill) {
  558. rfkill_unregister(eeepc->wlan_rfkill);
  559. rfkill_destroy(eeepc->wlan_rfkill);
  560. eeepc->wlan_rfkill = NULL;
  561. }
  562. /*
  563. * Refresh pci hotplug in case the rfkill state was changed after
  564. * eeepc_unregister_rfkill_notifier()
  565. */
  566. eeepc_rfkill_hotplug(eeepc);
  567. if (eeepc->hotplug_slot)
  568. pci_hp_deregister(eeepc->hotplug_slot);
  569. if (eeepc->hotplug_workqueue)
  570. destroy_workqueue(eeepc->hotplug_workqueue);
  571. if (eeepc->bluetooth_rfkill) {
  572. rfkill_unregister(eeepc->bluetooth_rfkill);
  573. rfkill_destroy(eeepc->bluetooth_rfkill);
  574. eeepc->bluetooth_rfkill = NULL;
  575. }
  576. if (eeepc->wimax_rfkill) {
  577. rfkill_unregister(eeepc->wimax_rfkill);
  578. rfkill_destroy(eeepc->wimax_rfkill);
  579. eeepc->wimax_rfkill = NULL;
  580. }
  581. if (eeepc->wwan3g_rfkill) {
  582. rfkill_unregister(eeepc->wwan3g_rfkill);
  583. rfkill_destroy(eeepc->wwan3g_rfkill);
  584. eeepc->wwan3g_rfkill = NULL;
  585. }
  586. }
  587. static int eeepc_wmi_rfkill_init(struct eeepc_wmi *eeepc)
  588. {
  589. int result = 0;
  590. mutex_init(&eeepc->hotplug_lock);
  591. mutex_init(&eeepc->wmi_lock);
  592. result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill,
  593. "eeepc-wlan", RFKILL_TYPE_WLAN,
  594. EEEPC_WMI_DEVID_WLAN);
  595. if (result && result != -ENODEV)
  596. goto exit;
  597. result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill,
  598. "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH,
  599. EEEPC_WMI_DEVID_BLUETOOTH);
  600. if (result && result != -ENODEV)
  601. goto exit;
  602. result = eeepc_new_rfkill(eeepc, &eeepc->wimax_rfkill,
  603. "eeepc-wimax", RFKILL_TYPE_WIMAX,
  604. EEEPC_WMI_DEVID_WIMAX);
  605. if (result && result != -ENODEV)
  606. goto exit;
  607. result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill,
  608. "eeepc-wwan3g", RFKILL_TYPE_WWAN,
  609. EEEPC_WMI_DEVID_WWAN3G);
  610. if (result && result != -ENODEV)
  611. goto exit;
  612. if (!eeepc->hotplug_wireless)
  613. goto exit;
  614. result = eeepc_setup_pci_hotplug(eeepc);
  615. /*
  616. * If we get -EBUSY then something else is handling the PCI hotplug -
  617. * don't fail in this case
  618. */
  619. if (result == -EBUSY)
  620. result = 0;
  621. eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
  622. eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
  623. eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
  624. /*
  625. * Refresh pci hotplug in case the rfkill state was changed during
  626. * setup.
  627. */
  628. eeepc_rfkill_hotplug(eeepc);
  629. exit:
  630. if (result && result != -ENODEV)
  631. eeepc_wmi_rfkill_exit(eeepc);
  632. if (result == -ENODEV)
  633. result = 0;
  634. return result;
  635. }
  636. /*
  637. * Backlight
  638. */
  639. static int read_backlight_power(void)
  640. {
  641. int ret = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_BACKLIGHT);
  642. if (ret < 0)
  643. return ret;
  644. return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
  645. }
  646. static int read_brightness(struct backlight_device *bd)
  647. {
  648. u32 retval;
  649. acpi_status status;
  650. status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_BRIGHTNESS, &retval);
  651. if (ACPI_FAILURE(status))
  652. return -EIO;
  653. else
  654. return retval & EEEPC_WMI_DSTS_BRIGHTNESS_MASK;
  655. }
  656. static int update_bl_status(struct backlight_device *bd)
  657. {
  658. u32 ctrl_param;
  659. acpi_status status;
  660. int power;
  661. ctrl_param = bd->props.brightness;
  662. status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BRIGHTNESS,
  663. ctrl_param, NULL);
  664. if (ACPI_FAILURE(status))
  665. return -EIO;
  666. power = read_backlight_power();
  667. if (power != -ENODEV && bd->props.power != power) {
  668. ctrl_param = !!(bd->props.power == FB_BLANK_UNBLANK);
  669. status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BACKLIGHT,
  670. ctrl_param, NULL);
  671. if (ACPI_FAILURE(status))
  672. return -EIO;
  673. }
  674. return 0;
  675. }
  676. static const struct backlight_ops eeepc_wmi_bl_ops = {
  677. .get_brightness = read_brightness,
  678. .update_status = update_bl_status,
  679. };
  680. static int eeepc_wmi_backlight_notify(struct eeepc_wmi *eeepc, int code)
  681. {
  682. struct backlight_device *bd = eeepc->backlight_device;
  683. int old = bd->props.brightness;
  684. int new = old;
  685. if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
  686. new = code - NOTIFY_BRNUP_MIN + 1;
  687. else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
  688. new = code - NOTIFY_BRNDOWN_MIN;
  689. bd->props.brightness = new;
  690. backlight_update_status(bd);
  691. backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
  692. return old;
  693. }
  694. static int eeepc_wmi_backlight_init(struct eeepc_wmi *eeepc)
  695. {
  696. struct backlight_device *bd;
  697. struct backlight_properties props;
  698. int max;
  699. int power;
  700. max = eeepc_wmi_get_devstate_bits(EEEPC_WMI_DEVID_BRIGHTNESS,
  701. EEEPC_WMI_DSTS_MAX_BRIGTH_MASK);
  702. power = read_backlight_power();
  703. if (max < 0 && power < 0) {
  704. /* Try to keep the original error */
  705. if (max == -ENODEV && power == -ENODEV)
  706. return -ENODEV;
  707. if (max != -ENODEV)
  708. return max;
  709. else
  710. return power;
  711. }
  712. if (max == -ENODEV)
  713. max = 0;
  714. if (power == -ENODEV)
  715. power = FB_BLANK_UNBLANK;
  716. memset(&props, 0, sizeof(struct backlight_properties));
  717. props.max_brightness = max;
  718. bd = backlight_device_register(EEEPC_WMI_FILE,
  719. &eeepc->platform_device->dev, eeepc,
  720. &eeepc_wmi_bl_ops, &props);
  721. if (IS_ERR(bd)) {
  722. pr_err("Could not register backlight device\n");
  723. return PTR_ERR(bd);
  724. }
  725. eeepc->backlight_device = bd;
  726. bd->props.brightness = read_brightness(bd);
  727. bd->props.power = power;
  728. backlight_update_status(bd);
  729. return 0;
  730. }
  731. static void eeepc_wmi_backlight_exit(struct eeepc_wmi *eeepc)
  732. {
  733. if (eeepc->backlight_device)
  734. backlight_device_unregister(eeepc->backlight_device);
  735. eeepc->backlight_device = NULL;
  736. }
  737. static void eeepc_wmi_notify(u32 value, void *context)
  738. {
  739. struct eeepc_wmi *eeepc = context;
  740. struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
  741. union acpi_object *obj;
  742. acpi_status status;
  743. int code;
  744. int orig_code;
  745. status = wmi_get_event_data(value, &response);
  746. if (status != AE_OK) {
  747. pr_err("bad event status 0x%x\n", status);
  748. return;
  749. }
  750. obj = (union acpi_object *)response.pointer;
  751. if (obj && obj->type == ACPI_TYPE_INTEGER) {
  752. code = obj->integer.value;
  753. orig_code = code;
  754. if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
  755. code = NOTIFY_BRNUP_MIN;
  756. else if (code >= NOTIFY_BRNDOWN_MIN &&
  757. code <= NOTIFY_BRNDOWN_MAX)
  758. code = NOTIFY_BRNDOWN_MIN;
  759. if (code == NOTIFY_BRNUP_MIN || code == NOTIFY_BRNDOWN_MIN) {
  760. if (!acpi_video_backlight_support())
  761. eeepc_wmi_backlight_notify(eeepc, orig_code);
  762. }
  763. if (!sparse_keymap_report_event(eeepc->inputdev,
  764. code, 1, true))
  765. pr_info("Unknown key %x pressed\n", code);
  766. }
  767. kfree(obj);
  768. }
  769. /*
  770. * Sys helpers
  771. */
  772. static int parse_arg(const char *buf, unsigned long count, int *val)
  773. {
  774. if (!count)
  775. return 0;
  776. if (sscanf(buf, "%i", val) != 1)
  777. return -EINVAL;
  778. return count;
  779. }
  780. static ssize_t store_sys_wmi(int devid, const char *buf, size_t count)
  781. {
  782. acpi_status status;
  783. u32 retval;
  784. int rv, value;
  785. value = eeepc_wmi_get_devstate_simple(devid);
  786. if (value == -ENODEV) /* Check device presence */
  787. return value;
  788. rv = parse_arg(buf, count, &value);
  789. status = eeepc_wmi_set_devstate(devid, value, &retval);
  790. if (ACPI_FAILURE(status))
  791. return -EIO;
  792. return rv;
  793. }
  794. static ssize_t show_sys_wmi(int devid, char *buf)
  795. {
  796. int value = eeepc_wmi_get_devstate_simple(devid);
  797. if (value < 0)
  798. return value;
  799. return sprintf(buf, "%d\n", value);
  800. }
  801. #define EEEPC_WMI_CREATE_DEVICE_ATTR(_name, _mode, _cm) \
  802. static ssize_t show_##_name(struct device *dev, \
  803. struct device_attribute *attr, \
  804. char *buf) \
  805. { \
  806. return show_sys_wmi(_cm, buf); \
  807. } \
  808. static ssize_t store_##_name(struct device *dev, \
  809. struct device_attribute *attr, \
  810. const char *buf, size_t count) \
  811. { \
  812. return store_sys_wmi(_cm, buf, count); \
  813. } \
  814. static struct device_attribute dev_attr_##_name = { \
  815. .attr = { \
  816. .name = __stringify(_name), \
  817. .mode = _mode }, \
  818. .show = show_##_name, \
  819. .store = store_##_name, \
  820. }
  821. EEEPC_WMI_CREATE_DEVICE_ATTR(camera, 0644, EEEPC_WMI_DEVID_CAMERA);
  822. EEEPC_WMI_CREATE_DEVICE_ATTR(cardr, 0644, EEEPC_WMI_DEVID_CARDREADER);
  823. static ssize_t store_cpufv(struct device *dev, struct device_attribute *attr,
  824. const char *buf, size_t count)
  825. {
  826. int value;
  827. struct acpi_buffer input = { (acpi_size)sizeof(value), &value };
  828. acpi_status status;
  829. if (!count || sscanf(buf, "%i", &value) != 1)
  830. return -EINVAL;
  831. if (value < 0 || value > 2)
  832. return -EINVAL;
  833. status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID,
  834. 1, EEEPC_WMI_METHODID_CFVS, &input, NULL);
  835. if (ACPI_FAILURE(status))
  836. return -EIO;
  837. else
  838. return count;
  839. }
  840. static DEVICE_ATTR(cpufv, S_IRUGO | S_IWUSR, NULL, store_cpufv);
  841. static struct attribute *platform_attributes[] = {
  842. &dev_attr_cpufv.attr,
  843. &dev_attr_camera.attr,
  844. &dev_attr_cardr.attr,
  845. NULL
  846. };
  847. static mode_t eeepc_sysfs_is_visible(struct kobject *kobj,
  848. struct attribute *attr,
  849. int idx)
  850. {
  851. bool supported = true;
  852. int devid = -1;
  853. if (attr == &dev_attr_camera.attr)
  854. devid = EEEPC_WMI_DEVID_CAMERA;
  855. else if (attr == &dev_attr_cardr.attr)
  856. devid = EEEPC_WMI_DEVID_CARDREADER;
  857. if (devid != -1)
  858. supported = eeepc_wmi_get_devstate_simple(devid) != -ENODEV;
  859. return supported ? attr->mode : 0;
  860. }
  861. static struct attribute_group platform_attribute_group = {
  862. .is_visible = eeepc_sysfs_is_visible,
  863. .attrs = platform_attributes
  864. };
  865. static void eeepc_wmi_sysfs_exit(struct platform_device *device)
  866. {
  867. sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
  868. }
  869. static int eeepc_wmi_sysfs_init(struct platform_device *device)
  870. {
  871. return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
  872. }
  873. /*
  874. * Platform device
  875. */
  876. static int __init eeepc_wmi_platform_init(struct eeepc_wmi *eeepc)
  877. {
  878. return eeepc_wmi_sysfs_init(eeepc->platform_device);
  879. }
  880. static void eeepc_wmi_platform_exit(struct eeepc_wmi *eeepc)
  881. {
  882. eeepc_wmi_sysfs_exit(eeepc->platform_device);
  883. }
  884. /*
  885. * debugfs
  886. */
  887. struct eeepc_wmi_debugfs_node {
  888. struct eeepc_wmi *eeepc;
  889. char *name;
  890. int (*show)(struct seq_file *m, void *data);
  891. };
  892. static int show_dsts(struct seq_file *m, void *data)
  893. {
  894. struct eeepc_wmi *eeepc = m->private;
  895. acpi_status status;
  896. u32 retval = -1;
  897. status = eeepc_wmi_get_devstate(eeepc->debug.dev_id, &retval);
  898. if (ACPI_FAILURE(status))
  899. return -EIO;
  900. seq_printf(m, "DSTS(%x) = %x\n", eeepc->debug.dev_id, retval);
  901. return 0;
  902. }
  903. static int show_devs(struct seq_file *m, void *data)
  904. {
  905. struct eeepc_wmi *eeepc = m->private;
  906. acpi_status status;
  907. u32 retval = -1;
  908. status = eeepc_wmi_set_devstate(eeepc->debug.dev_id,
  909. eeepc->debug.ctrl_param, &retval);
  910. if (ACPI_FAILURE(status))
  911. return -EIO;
  912. seq_printf(m, "DEVS(%x, %x) = %x\n", eeepc->debug.dev_id,
  913. eeepc->debug.ctrl_param, retval);
  914. return 0;
  915. }
  916. static struct eeepc_wmi_debugfs_node eeepc_wmi_debug_files[] = {
  917. { NULL, "devs", show_devs },
  918. { NULL, "dsts", show_dsts },
  919. };
  920. static int eeepc_wmi_debugfs_open(struct inode *inode, struct file *file)
  921. {
  922. struct eeepc_wmi_debugfs_node *node = inode->i_private;
  923. return single_open(file, node->show, node->eeepc);
  924. }
  925. static const struct file_operations eeepc_wmi_debugfs_io_ops = {
  926. .owner = THIS_MODULE,
  927. .open = eeepc_wmi_debugfs_open,
  928. .read = seq_read,
  929. .llseek = seq_lseek,
  930. .release = single_release,
  931. };
  932. static void eeepc_wmi_debugfs_exit(struct eeepc_wmi *eeepc)
  933. {
  934. debugfs_remove_recursive(eeepc->debug.root);
  935. }
  936. static int eeepc_wmi_debugfs_init(struct eeepc_wmi *eeepc)
  937. {
  938. struct dentry *dent;
  939. int i;
  940. eeepc->debug.root = debugfs_create_dir(EEEPC_WMI_FILE, NULL);
  941. if (!eeepc->debug.root) {
  942. pr_err("failed to create debugfs directory");
  943. goto error_debugfs;
  944. }
  945. dent = debugfs_create_x32("dev_id", S_IRUGO|S_IWUSR,
  946. eeepc->debug.root, &eeepc->debug.dev_id);
  947. if (!dent)
  948. goto error_debugfs;
  949. dent = debugfs_create_x32("ctrl_param", S_IRUGO|S_IWUSR,
  950. eeepc->debug.root, &eeepc->debug.ctrl_param);
  951. if (!dent)
  952. goto error_debugfs;
  953. for (i = 0; i < ARRAY_SIZE(eeepc_wmi_debug_files); i++) {
  954. struct eeepc_wmi_debugfs_node *node = &eeepc_wmi_debug_files[i];
  955. node->eeepc = eeepc;
  956. dent = debugfs_create_file(node->name, S_IFREG | S_IRUGO,
  957. eeepc->debug.root, node,
  958. &eeepc_wmi_debugfs_io_ops);
  959. if (!dent) {
  960. pr_err("failed to create debug file: %s\n", node->name);
  961. goto error_debugfs;
  962. }
  963. }
  964. return 0;
  965. error_debugfs:
  966. eeepc_wmi_debugfs_exit(eeepc);
  967. return -ENOMEM;
  968. }
  969. /*
  970. * WMI Driver
  971. */
  972. static void eeepc_dmi_check(struct eeepc_wmi *eeepc)
  973. {
  974. const char *model;
  975. model = dmi_get_system_info(DMI_PRODUCT_NAME);
  976. if (!model)
  977. return;
  978. /*
  979. * Whitelist for wlan hotplug
  980. *
  981. * Eeepc 1000H needs the current hotplug code to handle
  982. * Fn+F2 correctly. We may add other Eeepc here later, but
  983. * it seems that most of the laptops supported by eeepc-wmi
  984. * don't need to be on this list
  985. */
  986. if (strcmp(model, "1000H") == 0) {
  987. eeepc->hotplug_wireless = true;
  988. pr_info("wlan hotplug enabled\n");
  989. }
  990. }
  991. static int __init eeepc_wmi_add(struct platform_device *pdev)
  992. {
  993. struct eeepc_wmi *eeepc;
  994. acpi_status status;
  995. int err;
  996. eeepc = kzalloc(sizeof(struct eeepc_wmi), GFP_KERNEL);
  997. if (!eeepc)
  998. return -ENOMEM;
  999. eeepc->platform_device = pdev;
  1000. platform_set_drvdata(eeepc->platform_device, eeepc);
  1001. eeepc->hotplug_wireless = hotplug_wireless;
  1002. eeepc_dmi_check(eeepc);
  1003. err = eeepc_wmi_platform_init(eeepc);
  1004. if (err)
  1005. goto fail_platform;
  1006. err = eeepc_wmi_input_init(eeepc);
  1007. if (err)
  1008. goto fail_input;
  1009. err = eeepc_wmi_led_init(eeepc);
  1010. if (err)
  1011. goto fail_leds;
  1012. err = eeepc_wmi_rfkill_init(eeepc);
  1013. if (err)
  1014. goto fail_rfkill;
  1015. if (!acpi_video_backlight_support()) {
  1016. err = eeepc_wmi_backlight_init(eeepc);
  1017. if (err && err != -ENODEV)
  1018. goto fail_backlight;
  1019. } else
  1020. pr_info("Backlight controlled by ACPI video driver\n");
  1021. status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID,
  1022. eeepc_wmi_notify, eeepc);
  1023. if (ACPI_FAILURE(status)) {
  1024. pr_err("Unable to register notify handler - %d\n",
  1025. status);
  1026. err = -ENODEV;
  1027. goto fail_wmi_handler;
  1028. }
  1029. err = eeepc_wmi_debugfs_init(eeepc);
  1030. if (err)
  1031. goto fail_debugfs;
  1032. return 0;
  1033. fail_debugfs:
  1034. wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID);
  1035. fail_wmi_handler:
  1036. eeepc_wmi_backlight_exit(eeepc);
  1037. fail_backlight:
  1038. eeepc_wmi_rfkill_exit(eeepc);
  1039. fail_rfkill:
  1040. eeepc_wmi_led_exit(eeepc);
  1041. fail_leds:
  1042. eeepc_wmi_input_exit(eeepc);
  1043. fail_input:
  1044. eeepc_wmi_platform_exit(eeepc);
  1045. fail_platform:
  1046. kfree(eeepc);
  1047. return err;
  1048. }
  1049. static int __exit eeepc_wmi_remove(struct platform_device *device)
  1050. {
  1051. struct eeepc_wmi *eeepc;
  1052. eeepc = platform_get_drvdata(device);
  1053. wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID);
  1054. eeepc_wmi_backlight_exit(eeepc);
  1055. eeepc_wmi_input_exit(eeepc);
  1056. eeepc_wmi_led_exit(eeepc);
  1057. eeepc_wmi_rfkill_exit(eeepc);
  1058. eeepc_wmi_debugfs_exit(eeepc);
  1059. eeepc_wmi_platform_exit(eeepc);
  1060. kfree(eeepc);
  1061. return 0;
  1062. }
  1063. /*
  1064. * Platform driver - hibernate/resume callbacks
  1065. */
  1066. static int eeepc_hotk_thaw(struct device *device)
  1067. {
  1068. struct eeepc_wmi *eeepc = dev_get_drvdata(device);
  1069. if (eeepc->wlan_rfkill) {
  1070. bool wlan;
  1071. /*
  1072. * Work around bios bug - acpi _PTS turns off the wireless led
  1073. * during suspend. Normally it restores it on resume, but
  1074. * we should kick it ourselves in case hibernation is aborted.
  1075. */
  1076. wlan = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
  1077. eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_WLAN, wlan, NULL);
  1078. }
  1079. return 0;
  1080. }
  1081. static int eeepc_hotk_restore(struct device *device)
  1082. {
  1083. struct eeepc_wmi *eeepc = dev_get_drvdata(device);
  1084. int bl;
  1085. /* Refresh both wlan rfkill state and pci hotplug */
  1086. if (eeepc->wlan_rfkill)
  1087. eeepc_rfkill_hotplug(eeepc);
  1088. if (eeepc->bluetooth_rfkill) {
  1089. bl = !eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_BLUETOOTH);
  1090. rfkill_set_sw_state(eeepc->bluetooth_rfkill, bl);
  1091. }
  1092. if (eeepc->wimax_rfkill) {
  1093. bl = !eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WIMAX);
  1094. rfkill_set_sw_state(eeepc->wimax_rfkill, bl);
  1095. }
  1096. if (eeepc->wwan3g_rfkill) {
  1097. bl = !eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WWAN3G);
  1098. rfkill_set_sw_state(eeepc->wwan3g_rfkill, bl);
  1099. }
  1100. return 0;
  1101. }
  1102. static const struct dev_pm_ops eeepc_pm_ops = {
  1103. .thaw = eeepc_hotk_thaw,
  1104. .restore = eeepc_hotk_restore,
  1105. };
  1106. static struct platform_driver platform_driver = {
  1107. .remove = __exit_p(eeepc_wmi_remove),
  1108. .driver = {
  1109. .name = EEEPC_WMI_FILE,
  1110. .owner = THIS_MODULE,
  1111. .pm = &eeepc_pm_ops,
  1112. },
  1113. };
  1114. static acpi_status __init eeepc_wmi_parse_device(acpi_handle handle, u32 level,
  1115. void *context, void **retval)
  1116. {
  1117. pr_warning("Found legacy ATKD device (%s)", EEEPC_ACPI_HID);
  1118. *(bool *)context = true;
  1119. return AE_CTRL_TERMINATE;
  1120. }
  1121. static int __init eeepc_wmi_check_atkd(void)
  1122. {
  1123. acpi_status status;
  1124. bool found = false;
  1125. status = acpi_get_devices(EEEPC_ACPI_HID, eeepc_wmi_parse_device,
  1126. &found, NULL);
  1127. if (ACPI_FAILURE(status) || !found)
  1128. return 0;
  1129. return -1;
  1130. }
  1131. static int __init eeepc_wmi_probe(struct platform_device *pdev)
  1132. {
  1133. if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID) ||
  1134. !wmi_has_guid(EEEPC_WMI_MGMT_GUID)) {
  1135. pr_warning("No known WMI GUID found\n");
  1136. return -ENODEV;
  1137. }
  1138. if (eeepc_wmi_check_atkd()) {
  1139. pr_warning("WMI device present, but legacy ATKD device is also "
  1140. "present and enabled.");
  1141. pr_warning("You probably booted with acpi_osi=\"Linux\" or "
  1142. "acpi_osi=\"!Windows 2009\"");
  1143. pr_warning("Can't load eeepc-wmi, use default acpi_osi "
  1144. "(preferred) or eeepc-laptop");
  1145. return -ENODEV;
  1146. }
  1147. return eeepc_wmi_add(pdev);
  1148. }
  1149. static struct platform_device *platform_device;
  1150. static int __init eeepc_wmi_init(void)
  1151. {
  1152. platform_device = platform_create_bundle(&platform_driver,
  1153. eeepc_wmi_probe,
  1154. NULL, 0, NULL, 0);
  1155. if (IS_ERR(platform_device))
  1156. return PTR_ERR(platform_device);
  1157. return 0;
  1158. }
  1159. static void __exit eeepc_wmi_exit(void)
  1160. {
  1161. platform_device_unregister(platform_device);
  1162. platform_driver_unregister(&platform_driver);
  1163. }
  1164. module_init(eeepc_wmi_init);
  1165. module_exit(eeepc_wmi_exit);