asus-wmi.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411
  1. /*
  2. * Asus PC WMI hotkey driver
  3. *
  4. * Copyright(C) 2010 Intel Corporation.
  5. * Copyright(C) 2010-2011 Corentin Chary <corentin.chary@gmail.com>
  6. *
  7. * Portions based on wistron_btns.c:
  8. * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
  9. * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
  10. * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <linux/init.h>
  30. #include <linux/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 <acpi/acpi_bus.h>
  44. #include <acpi/acpi_drivers.h>
  45. #include "asus-wmi.h"
  46. MODULE_AUTHOR("Corentin Chary <corentincj@iksaif.net>, "
  47. "Yong Wang <yong.y.wang@intel.com>");
  48. MODULE_DESCRIPTION("Asus Generic WMI Driver");
  49. MODULE_LICENSE("GPL");
  50. #define to_platform_driver(drv) \
  51. (container_of((drv), struct platform_driver, driver))
  52. #define to_asus_wmi_driver(pdrv) \
  53. (container_of((pdrv), struct asus_wmi_driver, platform_driver))
  54. #define ASUS_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66"
  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. /* WMI Methods */
  60. #define ASUS_WMI_METHODID_DSTS 0x53544344
  61. #define ASUS_WMI_METHODID_DEVS 0x53564544
  62. #define ASUS_WMI_METHODID_CFVS 0x53564643
  63. /* Wireless */
  64. #define ASUS_WMI_DEVID_WLAN 0x00010011
  65. #define ASUS_WMI_DEVID_BLUETOOTH 0x00010013
  66. #define ASUS_WMI_DEVID_WIMAX 0x00010017
  67. #define ASUS_WMI_DEVID_WWAN3G 0x00010019
  68. /* Backlight and Brightness */
  69. #define ASUS_WMI_DEVID_BACKLIGHT 0x00050011
  70. #define ASUS_WMI_DEVID_BRIGHTNESS 0x00050012
  71. /* Misc */
  72. #define ASUS_WMI_DEVID_CAMERA 0x00060013
  73. /* Storage */
  74. #define ASUS_WMI_DEVID_CARDREADER 0x00080013
  75. /* Input */
  76. #define ASUS_WMI_DEVID_TOUCHPAD 0x00100011
  77. #define ASUS_WMI_DEVID_TOUCHPAD_LED 0x00100012
  78. /* DSTS masks */
  79. #define ASUS_WMI_DSTS_STATUS_BIT 0x00000001
  80. #define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002
  81. #define ASUS_WMI_DSTS_PRESENCE_BIT 0x00010000
  82. #define ASUS_WMI_DSTS_BRIGHTNESS_MASK 0x000000FF
  83. #define ASUS_WMI_DSTS_MAX_BRIGTH_MASK 0x0000FF00
  84. struct bios_args {
  85. u32 dev_id;
  86. u32 ctrl_param;
  87. };
  88. /*
  89. * <platform>/ - debugfs root directory
  90. * dev_id - current dev_id
  91. * ctrl_param - current ctrl_param
  92. * devs - call DEVS(dev_id, ctrl_param) and print result
  93. * dsts - call DSTS(dev_id) and print result
  94. */
  95. struct asus_wmi_debug {
  96. struct dentry *root;
  97. u32 dev_id;
  98. u32 ctrl_param;
  99. };
  100. struct asus_rfkill {
  101. struct asus_wmi *asus;
  102. struct rfkill *rfkill;
  103. u32 dev_id;
  104. };
  105. struct asus_wmi {
  106. struct input_dev *inputdev;
  107. struct backlight_device *backlight_device;
  108. struct platform_device *platform_device;
  109. struct led_classdev tpd_led;
  110. int tpd_led_wk;
  111. struct workqueue_struct *led_workqueue;
  112. struct work_struct tpd_led_work;
  113. struct asus_rfkill wlan;
  114. struct asus_rfkill bluetooth;
  115. struct asus_rfkill wimax;
  116. struct asus_rfkill wwan3g;
  117. struct hotplug_slot *hotplug_slot;
  118. struct mutex hotplug_lock;
  119. struct mutex wmi_lock;
  120. struct workqueue_struct *hotplug_workqueue;
  121. struct work_struct hotplug_work;
  122. struct asus_wmi_debug debug;
  123. struct asus_wmi_driver *driver;
  124. };
  125. static int asus_wmi_input_init(struct asus_wmi *asus)
  126. {
  127. int err;
  128. asus->inputdev = input_allocate_device();
  129. if (!asus->inputdev)
  130. return -ENOMEM;
  131. asus->inputdev->name = asus->driver->input_phys;
  132. asus->inputdev->phys = asus->driver->input_name;
  133. asus->inputdev->id.bustype = BUS_HOST;
  134. asus->inputdev->dev.parent = &asus->platform_device->dev;
  135. err = sparse_keymap_setup(asus->inputdev, asus->driver->keymap, NULL);
  136. if (err)
  137. goto err_free_dev;
  138. err = input_register_device(asus->inputdev);
  139. if (err)
  140. goto err_free_keymap;
  141. return 0;
  142. err_free_keymap:
  143. sparse_keymap_free(asus->inputdev);
  144. err_free_dev:
  145. input_free_device(asus->inputdev);
  146. return err;
  147. }
  148. static void asus_wmi_input_exit(struct asus_wmi *asus)
  149. {
  150. if (asus->inputdev) {
  151. sparse_keymap_free(asus->inputdev);
  152. input_unregister_device(asus->inputdev);
  153. }
  154. asus->inputdev = NULL;
  155. }
  156. static acpi_status asus_wmi_get_devstate(u32 dev_id, u32 *retval)
  157. {
  158. struct acpi_buffer input = { (acpi_size) sizeof(u32), &dev_id };
  159. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  160. union acpi_object *obj;
  161. acpi_status status;
  162. u32 tmp;
  163. status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
  164. 1, ASUS_WMI_METHODID_DSTS,
  165. &input, &output);
  166. if (ACPI_FAILURE(status))
  167. return status;
  168. obj = (union acpi_object *)output.pointer;
  169. if (obj && obj->type == ACPI_TYPE_INTEGER)
  170. tmp = (u32) obj->integer.value;
  171. else
  172. tmp = 0;
  173. if (retval)
  174. *retval = tmp;
  175. kfree(obj);
  176. return status;
  177. }
  178. static acpi_status asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param,
  179. u32 *retval)
  180. {
  181. struct bios_args args = {
  182. .dev_id = dev_id,
  183. .ctrl_param = ctrl_param,
  184. };
  185. struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
  186. acpi_status status;
  187. if (!retval) {
  188. status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, 1,
  189. ASUS_WMI_METHODID_DEVS,
  190. &input, NULL);
  191. } else {
  192. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  193. union acpi_object *obj;
  194. u32 tmp;
  195. status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, 1,
  196. ASUS_WMI_METHODID_DEVS,
  197. &input, &output);
  198. if (ACPI_FAILURE(status))
  199. return status;
  200. obj = (union acpi_object *)output.pointer;
  201. if (obj && obj->type == ACPI_TYPE_INTEGER)
  202. tmp = (u32) obj->integer.value;
  203. else
  204. tmp = 0;
  205. *retval = tmp;
  206. kfree(obj);
  207. }
  208. return status;
  209. }
  210. /* Helper for special devices with magic return codes */
  211. static int asus_wmi_get_devstate_bits(u32 dev_id, u32 mask)
  212. {
  213. u32 retval = 0;
  214. acpi_status status;
  215. status = asus_wmi_get_devstate(dev_id, &retval);
  216. if (ACPI_FAILURE(status))
  217. return -EINVAL;
  218. if (!(retval & ASUS_WMI_DSTS_PRESENCE_BIT))
  219. return -ENODEV;
  220. if (mask == ASUS_WMI_DSTS_STATUS_BIT) {
  221. if (retval & ASUS_WMI_DSTS_UNKNOWN_BIT)
  222. return -ENODEV;
  223. }
  224. return retval & mask;
  225. }
  226. static int asus_wmi_get_devstate_simple(u32 dev_id)
  227. {
  228. return asus_wmi_get_devstate_bits(dev_id, ASUS_WMI_DSTS_STATUS_BIT);
  229. }
  230. /*
  231. * LEDs
  232. */
  233. /*
  234. * These functions actually update the LED's, and are called from a
  235. * workqueue. By doing this as separate work rather than when the LED
  236. * subsystem asks, we avoid messing with the Asus ACPI stuff during a
  237. * potentially bad time, such as a timer interrupt.
  238. */
  239. static void tpd_led_update(struct work_struct *work)
  240. {
  241. int ctrl_param;
  242. struct asus_wmi *asus;
  243. asus = container_of(work, struct asus_wmi, tpd_led_work);
  244. ctrl_param = asus->tpd_led_wk;
  245. asus_wmi_set_devstate(ASUS_WMI_DEVID_TOUCHPAD_LED, ctrl_param, NULL);
  246. }
  247. static void tpd_led_set(struct led_classdev *led_cdev,
  248. enum led_brightness value)
  249. {
  250. struct asus_wmi *asus;
  251. asus = container_of(led_cdev, struct asus_wmi, tpd_led);
  252. asus->tpd_led_wk = !!value;
  253. queue_work(asus->led_workqueue, &asus->tpd_led_work);
  254. }
  255. static int read_tpd_led_state(struct asus_wmi *asus)
  256. {
  257. return asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_TOUCHPAD_LED);
  258. }
  259. static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
  260. {
  261. struct asus_wmi *asus;
  262. asus = container_of(led_cdev, struct asus_wmi, tpd_led);
  263. return read_tpd_led_state(asus);
  264. }
  265. static int asus_wmi_led_init(struct asus_wmi *asus)
  266. {
  267. int rv;
  268. if (read_tpd_led_state(asus) < 0)
  269. return 0;
  270. asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
  271. if (!asus->led_workqueue)
  272. return -ENOMEM;
  273. INIT_WORK(&asus->tpd_led_work, tpd_led_update);
  274. asus->tpd_led.name = "asus::touchpad";
  275. asus->tpd_led.brightness_set = tpd_led_set;
  276. asus->tpd_led.brightness_get = tpd_led_get;
  277. asus->tpd_led.max_brightness = 1;
  278. rv = led_classdev_register(&asus->platform_device->dev, &asus->tpd_led);
  279. if (rv) {
  280. destroy_workqueue(asus->led_workqueue);
  281. return rv;
  282. }
  283. return 0;
  284. }
  285. static void asus_wmi_led_exit(struct asus_wmi *asus)
  286. {
  287. if (asus->tpd_led.dev)
  288. led_classdev_unregister(&asus->tpd_led);
  289. if (asus->led_workqueue)
  290. destroy_workqueue(asus->led_workqueue);
  291. }
  292. /*
  293. * PCI hotplug (for wlan rfkill)
  294. */
  295. static bool asus_wlan_rfkill_blocked(struct asus_wmi *asus)
  296. {
  297. int result = asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_WLAN);
  298. if (result < 0)
  299. return false;
  300. return !result;
  301. }
  302. static void asus_rfkill_hotplug(struct asus_wmi *asus)
  303. {
  304. struct pci_dev *dev;
  305. struct pci_bus *bus;
  306. bool blocked;
  307. bool absent;
  308. u32 l;
  309. mutex_lock(&asus->wmi_lock);
  310. blocked = asus_wlan_rfkill_blocked(asus);
  311. mutex_unlock(&asus->wmi_lock);
  312. mutex_lock(&asus->hotplug_lock);
  313. if (asus->wlan.rfkill)
  314. rfkill_set_sw_state(asus->wlan.rfkill, blocked);
  315. if (asus->hotplug_slot) {
  316. bus = pci_find_bus(0, 1);
  317. if (!bus) {
  318. pr_warning("Unable to find PCI bus 1?\n");
  319. goto out_unlock;
  320. }
  321. if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
  322. pr_err("Unable to read PCI config space?\n");
  323. goto out_unlock;
  324. }
  325. absent = (l == 0xffffffff);
  326. if (blocked != absent) {
  327. pr_warning("BIOS says wireless lan is %s, "
  328. "but the pci device is %s\n",
  329. blocked ? "blocked" : "unblocked",
  330. absent ? "absent" : "present");
  331. pr_warning("skipped wireless hotplug as probably "
  332. "inappropriate for this model\n");
  333. goto out_unlock;
  334. }
  335. if (!blocked) {
  336. dev = pci_get_slot(bus, 0);
  337. if (dev) {
  338. /* Device already present */
  339. pci_dev_put(dev);
  340. goto out_unlock;
  341. }
  342. dev = pci_scan_single_device(bus, 0);
  343. if (dev) {
  344. pci_bus_assign_resources(bus);
  345. if (pci_bus_add_device(dev))
  346. pr_err("Unable to hotplug wifi\n");
  347. }
  348. } else {
  349. dev = pci_get_slot(bus, 0);
  350. if (dev) {
  351. pci_remove_bus_device(dev);
  352. pci_dev_put(dev);
  353. }
  354. }
  355. }
  356. out_unlock:
  357. mutex_unlock(&asus->hotplug_lock);
  358. }
  359. static void asus_rfkill_notify(acpi_handle handle, u32 event, void *data)
  360. {
  361. struct asus_wmi *asus = data;
  362. if (event != ACPI_NOTIFY_BUS_CHECK)
  363. return;
  364. /*
  365. * We can't call directly asus_rfkill_hotplug because most
  366. * of the time WMBC is still being executed and not reetrant.
  367. * There is currently no way to tell ACPICA that we want this
  368. * method to be serialized, we schedule a asus_rfkill_hotplug
  369. * call later, in a safer context.
  370. */
  371. queue_work(asus->hotplug_workqueue, &asus->hotplug_work);
  372. }
  373. static int asus_register_rfkill_notifier(struct asus_wmi *asus, 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. asus_rfkill_notify, asus);
  382. if (ACPI_FAILURE(status))
  383. pr_warning("Failed to register notify on %s\n", node);
  384. } else
  385. return -ENODEV;
  386. return 0;
  387. }
  388. static void asus_unregister_rfkill_notifier(struct asus_wmi *asus, 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. asus_rfkill_notify);
  397. if (ACPI_FAILURE(status))
  398. pr_err("Error removing rfkill notify handler %s\n",
  399. node);
  400. }
  401. }
  402. static int asus_get_adapter_status(struct hotplug_slot *hotplug_slot,
  403. u8 *value)
  404. {
  405. int result = asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_WLAN);
  406. if (result < 0)
  407. return result;
  408. *value = !!result;
  409. return 0;
  410. }
  411. static void asus_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 asus_hotplug_slot_ops = {
  417. .owner = THIS_MODULE,
  418. .get_adapter_status = asus_get_adapter_status,
  419. .get_power_status = asus_get_adapter_status,
  420. };
  421. static void asus_hotplug_work(struct work_struct *work)
  422. {
  423. struct asus_wmi *asus;
  424. asus = container_of(work, struct asus_wmi, hotplug_work);
  425. asus_rfkill_hotplug(asus);
  426. }
  427. static int asus_setup_pci_hotplug(struct asus_wmi *asus)
  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. asus->hotplug_workqueue =
  436. create_singlethread_workqueue("hotplug_workqueue");
  437. if (!asus->hotplug_workqueue)
  438. goto error_workqueue;
  439. INIT_WORK(&asus->hotplug_work, asus_hotplug_work);
  440. asus->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
  441. if (!asus->hotplug_slot)
  442. goto error_slot;
  443. asus->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
  444. GFP_KERNEL);
  445. if (!asus->hotplug_slot->info)
  446. goto error_info;
  447. asus->hotplug_slot->private = asus;
  448. asus->hotplug_slot->release = &asus_cleanup_pci_hotplug;
  449. asus->hotplug_slot->ops = &asus_hotplug_slot_ops;
  450. asus_get_adapter_status(asus->hotplug_slot,
  451. &asus->hotplug_slot->info->adapter_status);
  452. ret = pci_hp_register(asus->hotplug_slot, bus, 0, "asus-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(asus->hotplug_slot->info);
  460. error_info:
  461. kfree(asus->hotplug_slot);
  462. asus->hotplug_slot = NULL;
  463. error_slot:
  464. destroy_workqueue(asus->hotplug_workqueue);
  465. error_workqueue:
  466. return ret;
  467. }
  468. /*
  469. * Rfkill devices
  470. */
  471. static int asus_rfkill_set(void *data, bool blocked)
  472. {
  473. struct asus_rfkill *priv = data;
  474. u32 ctrl_param = !blocked;
  475. acpi_status status;
  476. status = asus_wmi_set_devstate(priv->dev_id, ctrl_param, NULL);
  477. if (ACPI_FAILURE(status))
  478. return -EIO;
  479. return 0;
  480. }
  481. static void asus_rfkill_query(struct rfkill *rfkill, void *data)
  482. {
  483. struct asus_rfkill *priv = data;
  484. int result;
  485. result = asus_wmi_get_devstate_simple(priv->dev_id);
  486. if (result < 0)
  487. return;
  488. rfkill_set_sw_state(priv->rfkill, !result);
  489. }
  490. static int asus_rfkill_wlan_set(void *data, bool blocked)
  491. {
  492. struct asus_rfkill *priv = data;
  493. struct asus_wmi *asus = priv->asus;
  494. int ret;
  495. /*
  496. * This handler is enabled only if hotplug is enabled.
  497. * In this case, the asus_wmi_set_devstate() will
  498. * trigger a wmi notification and we need to wait
  499. * this call to finish before being able to call
  500. * any wmi method
  501. */
  502. mutex_lock(&asus->wmi_lock);
  503. ret = asus_rfkill_set(data, blocked);
  504. mutex_unlock(&asus->wmi_lock);
  505. return ret;
  506. }
  507. static const struct rfkill_ops asus_rfkill_wlan_ops = {
  508. .set_block = asus_rfkill_wlan_set,
  509. .query = asus_rfkill_query,
  510. };
  511. static const struct rfkill_ops asus_rfkill_ops = {
  512. .set_block = asus_rfkill_set,
  513. .query = asus_rfkill_query,
  514. };
  515. static int asus_new_rfkill(struct asus_wmi *asus,
  516. struct asus_rfkill *arfkill,
  517. const char *name, enum rfkill_type type, int dev_id)
  518. {
  519. int result = asus_wmi_get_devstate_simple(dev_id);
  520. struct rfkill **rfkill = &arfkill->rfkill;
  521. if (result < 0)
  522. return result;
  523. arfkill->dev_id = dev_id;
  524. arfkill->asus = asus;
  525. if (dev_id == ASUS_WMI_DEVID_WLAN && asus->driver->hotplug_wireless)
  526. *rfkill = rfkill_alloc(name, &asus->platform_device->dev, type,
  527. &asus_rfkill_wlan_ops, arfkill);
  528. else
  529. *rfkill = rfkill_alloc(name, &asus->platform_device->dev, type,
  530. &asus_rfkill_ops, arfkill);
  531. if (!*rfkill)
  532. return -EINVAL;
  533. rfkill_init_sw_state(*rfkill, !result);
  534. result = rfkill_register(*rfkill);
  535. if (result) {
  536. rfkill_destroy(*rfkill);
  537. *rfkill = NULL;
  538. return result;
  539. }
  540. return 0;
  541. }
  542. static void asus_wmi_rfkill_exit(struct asus_wmi *asus)
  543. {
  544. asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P5");
  545. asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P6");
  546. asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P7");
  547. if (asus->wlan.rfkill) {
  548. rfkill_unregister(asus->wlan.rfkill);
  549. rfkill_destroy(asus->wlan.rfkill);
  550. asus->wlan.rfkill = NULL;
  551. }
  552. /*
  553. * Refresh pci hotplug in case the rfkill state was changed after
  554. * asus_unregister_rfkill_notifier()
  555. */
  556. asus_rfkill_hotplug(asus);
  557. if (asus->hotplug_slot)
  558. pci_hp_deregister(asus->hotplug_slot);
  559. if (asus->hotplug_workqueue)
  560. destroy_workqueue(asus->hotplug_workqueue);
  561. if (asus->bluetooth.rfkill) {
  562. rfkill_unregister(asus->bluetooth.rfkill);
  563. rfkill_destroy(asus->bluetooth.rfkill);
  564. asus->bluetooth.rfkill = NULL;
  565. }
  566. if (asus->wimax.rfkill) {
  567. rfkill_unregister(asus->wimax.rfkill);
  568. rfkill_destroy(asus->wimax.rfkill);
  569. asus->wimax.rfkill = NULL;
  570. }
  571. if (asus->wwan3g.rfkill) {
  572. rfkill_unregister(asus->wwan3g.rfkill);
  573. rfkill_destroy(asus->wwan3g.rfkill);
  574. asus->wwan3g.rfkill = NULL;
  575. }
  576. }
  577. static int asus_wmi_rfkill_init(struct asus_wmi *asus)
  578. {
  579. int result = 0;
  580. mutex_init(&asus->hotplug_lock);
  581. mutex_init(&asus->wmi_lock);
  582. result = asus_new_rfkill(asus, &asus->wlan, "asus-wlan",
  583. RFKILL_TYPE_WLAN, ASUS_WMI_DEVID_WLAN);
  584. if (result && result != -ENODEV)
  585. goto exit;
  586. result = asus_new_rfkill(asus, &asus->bluetooth,
  587. "asus-bluetooth", RFKILL_TYPE_BLUETOOTH,
  588. ASUS_WMI_DEVID_BLUETOOTH);
  589. if (result && result != -ENODEV)
  590. goto exit;
  591. result = asus_new_rfkill(asus, &asus->wimax, "asus-wimax",
  592. RFKILL_TYPE_WIMAX, ASUS_WMI_DEVID_WIMAX);
  593. if (result && result != -ENODEV)
  594. goto exit;
  595. result = asus_new_rfkill(asus, &asus->wwan3g, "asus-wwan3g",
  596. RFKILL_TYPE_WWAN, ASUS_WMI_DEVID_WWAN3G);
  597. if (result && result != -ENODEV)
  598. goto exit;
  599. if (!asus->driver->hotplug_wireless)
  600. goto exit;
  601. result = asus_setup_pci_hotplug(asus);
  602. /*
  603. * If we get -EBUSY then something else is handling the PCI hotplug -
  604. * don't fail in this case
  605. */
  606. if (result == -EBUSY)
  607. result = 0;
  608. asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P5");
  609. asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P6");
  610. asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P7");
  611. /*
  612. * Refresh pci hotplug in case the rfkill state was changed during
  613. * setup.
  614. */
  615. asus_rfkill_hotplug(asus);
  616. exit:
  617. if (result && result != -ENODEV)
  618. asus_wmi_rfkill_exit(asus);
  619. if (result == -ENODEV)
  620. result = 0;
  621. return result;
  622. }
  623. /*
  624. * Backlight
  625. */
  626. static int read_backlight_power(void)
  627. {
  628. int ret = asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_BACKLIGHT);
  629. if (ret < 0)
  630. return ret;
  631. return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
  632. }
  633. static int read_brightness(struct backlight_device *bd)
  634. {
  635. u32 retval;
  636. acpi_status status;
  637. status = asus_wmi_get_devstate(ASUS_WMI_DEVID_BRIGHTNESS, &retval);
  638. if (ACPI_FAILURE(status))
  639. return -EIO;
  640. else
  641. return retval & ASUS_WMI_DSTS_BRIGHTNESS_MASK;
  642. }
  643. static int update_bl_status(struct backlight_device *bd)
  644. {
  645. u32 ctrl_param;
  646. acpi_status status;
  647. int power;
  648. ctrl_param = bd->props.brightness;
  649. status = asus_wmi_set_devstate(ASUS_WMI_DEVID_BRIGHTNESS,
  650. ctrl_param, NULL);
  651. if (ACPI_FAILURE(status))
  652. return -EIO;
  653. power = read_backlight_power();
  654. if (power != -ENODEV && bd->props.power != power) {
  655. ctrl_param = !!(bd->props.power == FB_BLANK_UNBLANK);
  656. status = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT,
  657. ctrl_param, NULL);
  658. if (ACPI_FAILURE(status))
  659. return -EIO;
  660. }
  661. return 0;
  662. }
  663. static const struct backlight_ops asus_wmi_bl_ops = {
  664. .get_brightness = read_brightness,
  665. .update_status = update_bl_status,
  666. };
  667. static int asus_wmi_backlight_notify(struct asus_wmi *asus, int code)
  668. {
  669. struct backlight_device *bd = asus->backlight_device;
  670. int old = bd->props.brightness;
  671. int new = old;
  672. if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
  673. new = code - NOTIFY_BRNUP_MIN + 1;
  674. else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
  675. new = code - NOTIFY_BRNDOWN_MIN;
  676. bd->props.brightness = new;
  677. backlight_update_status(bd);
  678. backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
  679. return old;
  680. }
  681. static int asus_wmi_backlight_init(struct asus_wmi *asus)
  682. {
  683. struct backlight_device *bd;
  684. struct backlight_properties props;
  685. int max;
  686. int power;
  687. max = asus_wmi_get_devstate_bits(ASUS_WMI_DEVID_BRIGHTNESS,
  688. ASUS_WMI_DSTS_MAX_BRIGTH_MASK);
  689. power = read_backlight_power();
  690. if (max < 0 && power < 0) {
  691. /* Try to keep the original error */
  692. if (max == -ENODEV && power == -ENODEV)
  693. return -ENODEV;
  694. if (max != -ENODEV)
  695. return max;
  696. else
  697. return power;
  698. }
  699. if (max == -ENODEV)
  700. max = 0;
  701. if (power == -ENODEV)
  702. power = FB_BLANK_UNBLANK;
  703. memset(&props, 0, sizeof(struct backlight_properties));
  704. props.max_brightness = max;
  705. bd = backlight_device_register(asus->driver->name,
  706. &asus->platform_device->dev, asus,
  707. &asus_wmi_bl_ops, &props);
  708. if (IS_ERR(bd)) {
  709. pr_err("Could not register backlight device\n");
  710. return PTR_ERR(bd);
  711. }
  712. asus->backlight_device = bd;
  713. bd->props.brightness = read_brightness(bd);
  714. bd->props.power = power;
  715. backlight_update_status(bd);
  716. return 0;
  717. }
  718. static void asus_wmi_backlight_exit(struct asus_wmi *asus)
  719. {
  720. if (asus->backlight_device)
  721. backlight_device_unregister(asus->backlight_device);
  722. asus->backlight_device = NULL;
  723. }
  724. static void asus_wmi_notify(u32 value, void *context)
  725. {
  726. struct asus_wmi *asus = context;
  727. struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
  728. union acpi_object *obj;
  729. acpi_status status;
  730. int code;
  731. int orig_code;
  732. status = wmi_get_event_data(value, &response);
  733. if (status != AE_OK) {
  734. pr_err("bad event status 0x%x\n", status);
  735. return;
  736. }
  737. obj = (union acpi_object *)response.pointer;
  738. if (!obj || obj->type != ACPI_TYPE_INTEGER)
  739. goto exit;
  740. code = obj->integer.value;
  741. orig_code = code;
  742. if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
  743. code = NOTIFY_BRNUP_MIN;
  744. else if (code >= NOTIFY_BRNDOWN_MIN &&
  745. code <= NOTIFY_BRNDOWN_MAX)
  746. code = NOTIFY_BRNDOWN_MIN;
  747. if (code == NOTIFY_BRNUP_MIN || code == NOTIFY_BRNDOWN_MIN) {
  748. if (!acpi_video_backlight_support())
  749. asus_wmi_backlight_notify(asus, orig_code);
  750. } else if (!sparse_keymap_report_event(asus->inputdev, code, 1, true))
  751. pr_info("Unknown key %x pressed\n", code);
  752. exit:
  753. kfree(obj);
  754. }
  755. /*
  756. * Sys helpers
  757. */
  758. static int parse_arg(const char *buf, unsigned long count, int *val)
  759. {
  760. if (!count)
  761. return 0;
  762. if (sscanf(buf, "%i", val) != 1)
  763. return -EINVAL;
  764. return count;
  765. }
  766. static ssize_t store_sys_wmi(int devid, const char *buf, size_t count)
  767. {
  768. acpi_status status;
  769. u32 retval;
  770. int rv, value;
  771. value = asus_wmi_get_devstate_simple(devid);
  772. if (value == -ENODEV) /* Check device presence */
  773. return value;
  774. rv = parse_arg(buf, count, &value);
  775. status = asus_wmi_set_devstate(devid, value, &retval);
  776. if (ACPI_FAILURE(status))
  777. return -EIO;
  778. return rv;
  779. }
  780. static ssize_t show_sys_wmi(int devid, char *buf)
  781. {
  782. int value = asus_wmi_get_devstate_simple(devid);
  783. if (value < 0)
  784. return value;
  785. return sprintf(buf, "%d\n", value);
  786. }
  787. #define ASUS_WMI_CREATE_DEVICE_ATTR(_name, _mode, _cm) \
  788. static ssize_t show_##_name(struct device *dev, \
  789. struct device_attribute *attr, \
  790. char *buf) \
  791. { \
  792. return show_sys_wmi(_cm, buf); \
  793. } \
  794. static ssize_t store_##_name(struct device *dev, \
  795. struct device_attribute *attr, \
  796. const char *buf, size_t count) \
  797. { \
  798. return store_sys_wmi(_cm, buf, count); \
  799. } \
  800. static struct device_attribute dev_attr_##_name = { \
  801. .attr = { \
  802. .name = __stringify(_name), \
  803. .mode = _mode }, \
  804. .show = show_##_name, \
  805. .store = store_##_name, \
  806. }
  807. ASUS_WMI_CREATE_DEVICE_ATTR(touchpad, 0644, ASUS_WMI_DEVID_TOUCHPAD);
  808. ASUS_WMI_CREATE_DEVICE_ATTR(camera, 0644, ASUS_WMI_DEVID_CAMERA);
  809. ASUS_WMI_CREATE_DEVICE_ATTR(cardr, 0644, ASUS_WMI_DEVID_CARDREADER);
  810. static ssize_t store_cpufv(struct device *dev, struct device_attribute *attr,
  811. const char *buf, size_t count)
  812. {
  813. int value;
  814. struct acpi_buffer input = { (acpi_size) sizeof(value), &value };
  815. acpi_status status;
  816. if (!count || sscanf(buf, "%i", &value) != 1)
  817. return -EINVAL;
  818. if (value < 0 || value > 2)
  819. return -EINVAL;
  820. status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
  821. 1, ASUS_WMI_METHODID_CFVS, &input, NULL);
  822. if (ACPI_FAILURE(status))
  823. return -EIO;
  824. else
  825. return count;
  826. }
  827. static DEVICE_ATTR(cpufv, S_IRUGO | S_IWUSR, NULL, store_cpufv);
  828. static struct attribute *platform_attributes[] = {
  829. &dev_attr_cpufv.attr,
  830. &dev_attr_camera.attr,
  831. &dev_attr_cardr.attr,
  832. &dev_attr_touchpad.attr,
  833. NULL
  834. };
  835. static mode_t asus_sysfs_is_visible(struct kobject *kobj,
  836. struct attribute *attr, int idx)
  837. {
  838. bool supported = true;
  839. int devid = -1;
  840. if (attr == &dev_attr_camera.attr)
  841. devid = ASUS_WMI_DEVID_CAMERA;
  842. else if (attr == &dev_attr_cardr.attr)
  843. devid = ASUS_WMI_DEVID_CARDREADER;
  844. else if (attr == &dev_attr_touchpad.attr)
  845. devid = ASUS_WMI_DEVID_TOUCHPAD;
  846. if (devid != -1)
  847. supported = asus_wmi_get_devstate_simple(devid) != -ENODEV;
  848. return supported ? attr->mode : 0;
  849. }
  850. static struct attribute_group platform_attribute_group = {
  851. .is_visible = asus_sysfs_is_visible,
  852. .attrs = platform_attributes
  853. };
  854. static void asus_wmi_sysfs_exit(struct platform_device *device)
  855. {
  856. sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
  857. }
  858. static int asus_wmi_sysfs_init(struct platform_device *device)
  859. {
  860. return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
  861. }
  862. /*
  863. * Platform device
  864. */
  865. static int __init asus_wmi_platform_init(struct asus_wmi *asus)
  866. {
  867. return asus_wmi_sysfs_init(asus->platform_device);
  868. }
  869. static void asus_wmi_platform_exit(struct asus_wmi *asus)
  870. {
  871. asus_wmi_sysfs_exit(asus->platform_device);
  872. }
  873. /*
  874. * debugfs
  875. */
  876. struct asus_wmi_debugfs_node {
  877. struct asus_wmi *asus;
  878. char *name;
  879. int (*show) (struct seq_file *m, void *data);
  880. };
  881. static int show_dsts(struct seq_file *m, void *data)
  882. {
  883. struct asus_wmi *asus = m->private;
  884. acpi_status status;
  885. u32 retval = -1;
  886. status = asus_wmi_get_devstate(asus->debug.dev_id, &retval);
  887. if (ACPI_FAILURE(status))
  888. return -EIO;
  889. seq_printf(m, "DSTS(%x) = %x\n", asus->debug.dev_id, retval);
  890. return 0;
  891. }
  892. static int show_devs(struct seq_file *m, void *data)
  893. {
  894. struct asus_wmi *asus = m->private;
  895. acpi_status status;
  896. u32 retval = -1;
  897. status = asus_wmi_set_devstate(asus->debug.dev_id,
  898. asus->debug.ctrl_param, &retval);
  899. if (ACPI_FAILURE(status))
  900. return -EIO;
  901. seq_printf(m, "DEVS(%x, %x) = %x\n", asus->debug.dev_id,
  902. asus->debug.ctrl_param, retval);
  903. return 0;
  904. }
  905. static struct asus_wmi_debugfs_node asus_wmi_debug_files[] = {
  906. {NULL, "devs", show_devs},
  907. {NULL, "dsts", show_dsts},
  908. };
  909. static int asus_wmi_debugfs_open(struct inode *inode, struct file *file)
  910. {
  911. struct asus_wmi_debugfs_node *node = inode->i_private;
  912. return single_open(file, node->show, node->asus);
  913. }
  914. static const struct file_operations asus_wmi_debugfs_io_ops = {
  915. .owner = THIS_MODULE,
  916. .open = asus_wmi_debugfs_open,
  917. .read = seq_read,
  918. .llseek = seq_lseek,
  919. .release = single_release,
  920. };
  921. static void asus_wmi_debugfs_exit(struct asus_wmi *asus)
  922. {
  923. debugfs_remove_recursive(asus->debug.root);
  924. }
  925. static int asus_wmi_debugfs_init(struct asus_wmi *asus)
  926. {
  927. struct dentry *dent;
  928. int i;
  929. asus->debug.root = debugfs_create_dir(asus->driver->name, NULL);
  930. if (!asus->debug.root) {
  931. pr_err("failed to create debugfs directory");
  932. goto error_debugfs;
  933. }
  934. dent = debugfs_create_x32("dev_id", S_IRUGO | S_IWUSR,
  935. asus->debug.root, &asus->debug.dev_id);
  936. if (!dent)
  937. goto error_debugfs;
  938. dent = debugfs_create_x32("ctrl_param", S_IRUGO | S_IWUSR,
  939. asus->debug.root, &asus->debug.ctrl_param);
  940. if (!dent)
  941. goto error_debugfs;
  942. for (i = 0; i < ARRAY_SIZE(asus_wmi_debug_files); i++) {
  943. struct asus_wmi_debugfs_node *node = &asus_wmi_debug_files[i];
  944. node->asus = asus;
  945. dent = debugfs_create_file(node->name, S_IFREG | S_IRUGO,
  946. asus->debug.root, node,
  947. &asus_wmi_debugfs_io_ops);
  948. if (!dent) {
  949. pr_err("failed to create debug file: %s\n", node->name);
  950. goto error_debugfs;
  951. }
  952. }
  953. return 0;
  954. error_debugfs:
  955. asus_wmi_debugfs_exit(asus);
  956. return -ENOMEM;
  957. }
  958. /*
  959. * WMI Driver
  960. */
  961. static int asus_wmi_add(struct platform_device *pdev)
  962. {
  963. struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver);
  964. struct asus_wmi_driver *wdrv = to_asus_wmi_driver(pdrv);
  965. struct asus_wmi *asus;
  966. acpi_status status;
  967. int err;
  968. asus = kzalloc(sizeof(struct asus_wmi), GFP_KERNEL);
  969. if (!asus)
  970. return -ENOMEM;
  971. asus->driver = wdrv;
  972. asus->platform_device = pdev;
  973. wdrv->platform_device = pdev;
  974. platform_set_drvdata(asus->platform_device, asus);
  975. if (wdrv->quirks)
  976. wdrv->quirks(asus->driver);
  977. err = asus_wmi_platform_init(asus);
  978. if (err)
  979. goto fail_platform;
  980. err = asus_wmi_input_init(asus);
  981. if (err)
  982. goto fail_input;
  983. err = asus_wmi_led_init(asus);
  984. if (err)
  985. goto fail_leds;
  986. err = asus_wmi_rfkill_init(asus);
  987. if (err)
  988. goto fail_rfkill;
  989. if (!acpi_video_backlight_support()) {
  990. err = asus_wmi_backlight_init(asus);
  991. if (err && err != -ENODEV)
  992. goto fail_backlight;
  993. } else
  994. pr_info("Backlight controlled by ACPI video driver\n");
  995. status = wmi_install_notify_handler(asus->driver->event_guid,
  996. asus_wmi_notify, asus);
  997. if (ACPI_FAILURE(status)) {
  998. pr_err("Unable to register notify handler - %d\n", status);
  999. err = -ENODEV;
  1000. goto fail_wmi_handler;
  1001. }
  1002. err = asus_wmi_debugfs_init(asus);
  1003. if (err)
  1004. goto fail_debugfs;
  1005. return 0;
  1006. fail_debugfs:
  1007. wmi_remove_notify_handler(asus->driver->event_guid);
  1008. fail_wmi_handler:
  1009. asus_wmi_backlight_exit(asus);
  1010. fail_backlight:
  1011. asus_wmi_rfkill_exit(asus);
  1012. fail_rfkill:
  1013. asus_wmi_led_exit(asus);
  1014. fail_leds:
  1015. asus_wmi_input_exit(asus);
  1016. fail_input:
  1017. asus_wmi_platform_exit(asus);
  1018. fail_platform:
  1019. kfree(asus);
  1020. return err;
  1021. }
  1022. static int asus_wmi_remove(struct platform_device *device)
  1023. {
  1024. struct asus_wmi *asus;
  1025. asus = platform_get_drvdata(device);
  1026. wmi_remove_notify_handler(asus->driver->event_guid);
  1027. asus_wmi_backlight_exit(asus);
  1028. asus_wmi_input_exit(asus);
  1029. asus_wmi_led_exit(asus);
  1030. asus_wmi_rfkill_exit(asus);
  1031. asus_wmi_debugfs_exit(asus);
  1032. asus_wmi_platform_exit(asus);
  1033. kfree(asus);
  1034. return 0;
  1035. }
  1036. /*
  1037. * Platform driver - hibernate/resume callbacks
  1038. */
  1039. static int asus_hotk_thaw(struct device *device)
  1040. {
  1041. struct asus_wmi *asus = dev_get_drvdata(device);
  1042. if (asus->wlan.rfkill) {
  1043. bool wlan;
  1044. /*
  1045. * Work around bios bug - acpi _PTS turns off the wireless led
  1046. * during suspend. Normally it restores it on resume, but
  1047. * we should kick it ourselves in case hibernation is aborted.
  1048. */
  1049. wlan = asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_WLAN);
  1050. asus_wmi_set_devstate(ASUS_WMI_DEVID_WLAN, wlan, NULL);
  1051. }
  1052. return 0;
  1053. }
  1054. static int asus_hotk_restore(struct device *device)
  1055. {
  1056. struct asus_wmi *asus = dev_get_drvdata(device);
  1057. int bl;
  1058. /* Refresh both wlan rfkill state and pci hotplug */
  1059. if (asus->wlan.rfkill)
  1060. asus_rfkill_hotplug(asus);
  1061. if (asus->bluetooth.rfkill) {
  1062. bl = !asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_BLUETOOTH);
  1063. rfkill_set_sw_state(asus->bluetooth.rfkill, bl);
  1064. }
  1065. if (asus->wimax.rfkill) {
  1066. bl = !asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_WIMAX);
  1067. rfkill_set_sw_state(asus->wimax.rfkill, bl);
  1068. }
  1069. if (asus->wwan3g.rfkill) {
  1070. bl = !asus_wmi_get_devstate_simple(ASUS_WMI_DEVID_WWAN3G);
  1071. rfkill_set_sw_state(asus->wwan3g.rfkill, bl);
  1072. }
  1073. return 0;
  1074. }
  1075. static const struct dev_pm_ops asus_pm_ops = {
  1076. .thaw = asus_hotk_thaw,
  1077. .restore = asus_hotk_restore,
  1078. };
  1079. static int asus_wmi_probe(struct platform_device *pdev)
  1080. {
  1081. struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver);
  1082. struct asus_wmi_driver *wdrv = to_asus_wmi_driver(pdrv);
  1083. int ret;
  1084. if (!wmi_has_guid(ASUS_WMI_MGMT_GUID)) {
  1085. pr_warning("Management GUID not found\n");
  1086. return -ENODEV;
  1087. }
  1088. if (wdrv->event_guid && !wmi_has_guid(wdrv->event_guid)) {
  1089. pr_warning("Event GUID not found\n");
  1090. return -ENODEV;
  1091. }
  1092. if (wdrv->probe) {
  1093. ret = wdrv->probe(pdev);
  1094. if (ret)
  1095. return ret;
  1096. }
  1097. return asus_wmi_add(pdev);
  1098. }
  1099. static bool used;
  1100. int asus_wmi_register_driver(struct asus_wmi_driver *driver)
  1101. {
  1102. struct platform_driver *platform_driver;
  1103. struct platform_device *platform_device;
  1104. if (used)
  1105. return -EBUSY;
  1106. platform_driver = &driver->platform_driver;
  1107. platform_driver->remove = asus_wmi_remove;
  1108. platform_driver->driver.owner = driver->owner;
  1109. platform_driver->driver.name = driver->name;
  1110. platform_driver->driver.pm = &asus_pm_ops;
  1111. platform_device = platform_create_bundle(platform_driver,
  1112. asus_wmi_probe,
  1113. NULL, 0, NULL, 0);
  1114. if (IS_ERR(platform_device))
  1115. return PTR_ERR(platform_device);
  1116. used = true;
  1117. return 0;
  1118. }
  1119. EXPORT_SYMBOL_GPL(asus_wmi_register_driver);
  1120. void asus_wmi_unregister_driver(struct asus_wmi_driver *driver)
  1121. {
  1122. platform_device_unregister(driver->platform_device);
  1123. platform_driver_unregister(&driver->platform_driver);
  1124. used = false;
  1125. }
  1126. EXPORT_SYMBOL_GPL(asus_wmi_unregister_driver);
  1127. static int __init asus_wmi_init(void)
  1128. {
  1129. if (!wmi_has_guid(ASUS_WMI_MGMT_GUID)) {
  1130. pr_info("Asus Management GUID not found");
  1131. return -ENODEV;
  1132. }
  1133. pr_info("ASUS WMI generic driver loaded");
  1134. return 0;
  1135. }
  1136. static void __exit asus_wmi_exit(void)
  1137. {
  1138. pr_info("ASUS WMI generic driver unloaded");
  1139. }
  1140. module_init(asus_wmi_init);
  1141. module_exit(asus_wmi_exit);