eeepc-wmi.c 33 KB

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