asus-wmi.c 33 KB

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