eeepc-wmi.c 32 KB

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