asus-wmi.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876
  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/hwmon.h>
  41. #include <linux/hwmon-sysfs.h>
  42. #include <linux/debugfs.h>
  43. #include <linux/seq_file.h>
  44. #include <linux/platform_device.h>
  45. #include <linux/thermal.h>
  46. #include <acpi/acpi_bus.h>
  47. #include <acpi/acpi_drivers.h>
  48. #include "asus-wmi.h"
  49. MODULE_AUTHOR("Corentin Chary <corentincj@iksaif.net>, "
  50. "Yong Wang <yong.y.wang@intel.com>");
  51. MODULE_DESCRIPTION("Asus Generic WMI Driver");
  52. MODULE_LICENSE("GPL");
  53. #define to_platform_driver(drv) \
  54. (container_of((drv), struct platform_driver, driver))
  55. #define to_asus_wmi_driver(pdrv) \
  56. (container_of((pdrv), struct asus_wmi_driver, platform_driver))
  57. #define ASUS_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66"
  58. #define NOTIFY_BRNUP_MIN 0x11
  59. #define NOTIFY_BRNUP_MAX 0x1f
  60. #define NOTIFY_BRNDOWN_MIN 0x20
  61. #define NOTIFY_BRNDOWN_MAX 0x2e
  62. #define NOTIFY_KBD_BRTUP 0xc4
  63. #define NOTIFY_KBD_BRTDWN 0xc5
  64. /* WMI Methods */
  65. #define ASUS_WMI_METHODID_SPEC 0x43455053 /* BIOS SPECification */
  66. #define ASUS_WMI_METHODID_SFBD 0x44424653 /* Set First Boot Device */
  67. #define ASUS_WMI_METHODID_GLCD 0x44434C47 /* Get LCD status */
  68. #define ASUS_WMI_METHODID_GPID 0x44495047 /* Get Panel ID?? (Resol) */
  69. #define ASUS_WMI_METHODID_QMOD 0x444F4D51 /* Quiet MODe */
  70. #define ASUS_WMI_METHODID_SPLV 0x4C425053 /* Set Panel Light Value */
  71. #define ASUS_WMI_METHODID_SFUN 0x4E554653 /* FUNCtionalities */
  72. #define ASUS_WMI_METHODID_SDSP 0x50534453 /* Set DiSPlay output */
  73. #define ASUS_WMI_METHODID_GDSP 0x50534447 /* Get DiSPlay output */
  74. #define ASUS_WMI_METHODID_DEVP 0x50564544 /* DEVice Policy */
  75. #define ASUS_WMI_METHODID_OSVR 0x5256534F /* OS VeRsion */
  76. #define ASUS_WMI_METHODID_DSTS 0x53544344 /* Device STatuS */
  77. #define ASUS_WMI_METHODID_DSTS2 0x53545344 /* Device STatuS #2*/
  78. #define ASUS_WMI_METHODID_BSTS 0x53545342 /* Bios STatuS ? */
  79. #define ASUS_WMI_METHODID_DEVS 0x53564544 /* DEVice Set */
  80. #define ASUS_WMI_METHODID_CFVS 0x53564643 /* CPU Frequency Volt Set */
  81. #define ASUS_WMI_METHODID_KBFT 0x5446424B /* KeyBoard FilTer */
  82. #define ASUS_WMI_METHODID_INIT 0x54494E49 /* INITialize */
  83. #define ASUS_WMI_METHODID_HKEY 0x59454B48 /* Hot KEY ?? */
  84. #define ASUS_WMI_UNSUPPORTED_METHOD 0xFFFFFFFE
  85. /* Wireless */
  86. #define ASUS_WMI_DEVID_HW_SWITCH 0x00010001
  87. #define ASUS_WMI_DEVID_WIRELESS_LED 0x00010002
  88. #define ASUS_WMI_DEVID_CWAP 0x00010003
  89. #define ASUS_WMI_DEVID_WLAN 0x00010011
  90. #define ASUS_WMI_DEVID_BLUETOOTH 0x00010013
  91. #define ASUS_WMI_DEVID_GPS 0x00010015
  92. #define ASUS_WMI_DEVID_WIMAX 0x00010017
  93. #define ASUS_WMI_DEVID_WWAN3G 0x00010019
  94. #define ASUS_WMI_DEVID_UWB 0x00010021
  95. /* Leds */
  96. /* 0x000200XX and 0x000400XX */
  97. #define ASUS_WMI_DEVID_LED1 0x00020011
  98. #define ASUS_WMI_DEVID_LED2 0x00020012
  99. #define ASUS_WMI_DEVID_LED3 0x00020013
  100. #define ASUS_WMI_DEVID_LED4 0x00020014
  101. #define ASUS_WMI_DEVID_LED5 0x00020015
  102. #define ASUS_WMI_DEVID_LED6 0x00020016
  103. /* Backlight and Brightness */
  104. #define ASUS_WMI_DEVID_BACKLIGHT 0x00050011
  105. #define ASUS_WMI_DEVID_BRIGHTNESS 0x00050012
  106. #define ASUS_WMI_DEVID_KBD_BACKLIGHT 0x00050021
  107. #define ASUS_WMI_DEVID_LIGHT_SENSOR 0x00050022 /* ?? */
  108. /* Misc */
  109. #define ASUS_WMI_DEVID_CAMERA 0x00060013
  110. /* Storage */
  111. #define ASUS_WMI_DEVID_CARDREADER 0x00080013
  112. /* Input */
  113. #define ASUS_WMI_DEVID_TOUCHPAD 0x00100011
  114. #define ASUS_WMI_DEVID_TOUCHPAD_LED 0x00100012
  115. /* Fan, Thermal */
  116. #define ASUS_WMI_DEVID_THERMAL_CTRL 0x00110011
  117. #define ASUS_WMI_DEVID_FAN_CTRL 0x00110012
  118. /* Power */
  119. #define ASUS_WMI_DEVID_PROCESSOR_STATE 0x00120012
  120. /* DSTS masks */
  121. #define ASUS_WMI_DSTS_STATUS_BIT 0x00000001
  122. #define ASUS_WMI_DSTS_UNKNOWN_BIT 0x00000002
  123. #define ASUS_WMI_DSTS_PRESENCE_BIT 0x00010000
  124. #define ASUS_WMI_DSTS_USER_BIT 0x00020000
  125. #define ASUS_WMI_DSTS_BIOS_BIT 0x00040000
  126. #define ASUS_WMI_DSTS_BRIGHTNESS_MASK 0x000000FF
  127. #define ASUS_WMI_DSTS_MAX_BRIGTH_MASK 0x0000FF00
  128. struct bios_args {
  129. u32 arg0;
  130. u32 arg1;
  131. } __packed;
  132. /*
  133. * <platform>/ - debugfs root directory
  134. * dev_id - current dev_id
  135. * ctrl_param - current ctrl_param
  136. * method_id - current method_id
  137. * devs - call DEVS(dev_id, ctrl_param) and print result
  138. * dsts - call DSTS(dev_id) and print result
  139. * call - call method_id(dev_id, ctrl_param) and print result
  140. */
  141. struct asus_wmi_debug {
  142. struct dentry *root;
  143. u32 method_id;
  144. u32 dev_id;
  145. u32 ctrl_param;
  146. };
  147. struct asus_rfkill {
  148. struct asus_wmi *asus;
  149. struct rfkill *rfkill;
  150. u32 dev_id;
  151. };
  152. struct asus_wmi {
  153. int dsts_id;
  154. int spec;
  155. int sfun;
  156. struct input_dev *inputdev;
  157. struct backlight_device *backlight_device;
  158. struct device *hwmon_device;
  159. struct platform_device *platform_device;
  160. struct led_classdev tpd_led;
  161. int tpd_led_wk;
  162. struct led_classdev kbd_led;
  163. int kbd_led_wk;
  164. struct workqueue_struct *led_workqueue;
  165. struct work_struct tpd_led_work;
  166. struct work_struct kbd_led_work;
  167. struct asus_rfkill wlan;
  168. struct asus_rfkill bluetooth;
  169. struct asus_rfkill wimax;
  170. struct asus_rfkill wwan3g;
  171. struct asus_rfkill gps;
  172. struct asus_rfkill uwb;
  173. struct hotplug_slot *hotplug_slot;
  174. struct mutex hotplug_lock;
  175. struct mutex wmi_lock;
  176. struct workqueue_struct *hotplug_workqueue;
  177. struct work_struct hotplug_work;
  178. struct asus_wmi_debug debug;
  179. struct asus_wmi_driver *driver;
  180. };
  181. static int asus_wmi_input_init(struct asus_wmi *asus)
  182. {
  183. int err;
  184. asus->inputdev = input_allocate_device();
  185. if (!asus->inputdev)
  186. return -ENOMEM;
  187. asus->inputdev->name = asus->driver->input_name;
  188. asus->inputdev->phys = asus->driver->input_phys;
  189. asus->inputdev->id.bustype = BUS_HOST;
  190. asus->inputdev->dev.parent = &asus->platform_device->dev;
  191. set_bit(EV_REP, asus->inputdev->evbit);
  192. err = sparse_keymap_setup(asus->inputdev, asus->driver->keymap, NULL);
  193. if (err)
  194. goto err_free_dev;
  195. err = input_register_device(asus->inputdev);
  196. if (err)
  197. goto err_free_keymap;
  198. return 0;
  199. err_free_keymap:
  200. sparse_keymap_free(asus->inputdev);
  201. err_free_dev:
  202. input_free_device(asus->inputdev);
  203. return err;
  204. }
  205. static void asus_wmi_input_exit(struct asus_wmi *asus)
  206. {
  207. if (asus->inputdev) {
  208. sparse_keymap_free(asus->inputdev);
  209. input_unregister_device(asus->inputdev);
  210. }
  211. asus->inputdev = NULL;
  212. }
  213. static int asus_wmi_evaluate_method(u32 method_id, u32 arg0, u32 arg1,
  214. u32 *retval)
  215. {
  216. struct bios_args args = {
  217. .arg0 = arg0,
  218. .arg1 = arg1,
  219. };
  220. struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
  221. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  222. acpi_status status;
  223. union acpi_object *obj;
  224. u32 tmp;
  225. status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID, 1, method_id,
  226. &input, &output);
  227. if (ACPI_FAILURE(status))
  228. goto exit;
  229. obj = (union acpi_object *)output.pointer;
  230. if (obj && obj->type == ACPI_TYPE_INTEGER)
  231. tmp = (u32) obj->integer.value;
  232. else
  233. tmp = 0;
  234. if (retval)
  235. *retval = tmp;
  236. kfree(obj);
  237. exit:
  238. if (ACPI_FAILURE(status))
  239. return -EIO;
  240. if (tmp == ASUS_WMI_UNSUPPORTED_METHOD)
  241. return -ENODEV;
  242. return 0;
  243. }
  244. static int asus_wmi_get_devstate(struct asus_wmi *asus, u32 dev_id, u32 *retval)
  245. {
  246. return asus_wmi_evaluate_method(asus->dsts_id, dev_id, 0, retval);
  247. }
  248. static int asus_wmi_set_devstate(u32 dev_id, u32 ctrl_param,
  249. u32 *retval)
  250. {
  251. return asus_wmi_evaluate_method(ASUS_WMI_METHODID_DEVS, dev_id,
  252. ctrl_param, retval);
  253. }
  254. /* Helper for special devices with magic return codes */
  255. static int asus_wmi_get_devstate_bits(struct asus_wmi *asus,
  256. u32 dev_id, u32 mask)
  257. {
  258. u32 retval = 0;
  259. int err;
  260. err = asus_wmi_get_devstate(asus, dev_id, &retval);
  261. if (err < 0)
  262. return err;
  263. if (!(retval & ASUS_WMI_DSTS_PRESENCE_BIT))
  264. return -ENODEV;
  265. if (mask == ASUS_WMI_DSTS_STATUS_BIT) {
  266. if (retval & ASUS_WMI_DSTS_UNKNOWN_BIT)
  267. return -ENODEV;
  268. }
  269. return retval & mask;
  270. }
  271. static int asus_wmi_get_devstate_simple(struct asus_wmi *asus, u32 dev_id)
  272. {
  273. return asus_wmi_get_devstate_bits(asus, dev_id,
  274. ASUS_WMI_DSTS_STATUS_BIT);
  275. }
  276. /*
  277. * LEDs
  278. */
  279. /*
  280. * These functions actually update the LED's, and are called from a
  281. * workqueue. By doing this as separate work rather than when the LED
  282. * subsystem asks, we avoid messing with the Asus ACPI stuff during a
  283. * potentially bad time, such as a timer interrupt.
  284. */
  285. static void tpd_led_update(struct work_struct *work)
  286. {
  287. int ctrl_param;
  288. struct asus_wmi *asus;
  289. asus = container_of(work, struct asus_wmi, tpd_led_work);
  290. ctrl_param = asus->tpd_led_wk;
  291. asus_wmi_set_devstate(ASUS_WMI_DEVID_TOUCHPAD_LED, ctrl_param, NULL);
  292. }
  293. static void tpd_led_set(struct led_classdev *led_cdev,
  294. enum led_brightness value)
  295. {
  296. struct asus_wmi *asus;
  297. asus = container_of(led_cdev, struct asus_wmi, tpd_led);
  298. asus->tpd_led_wk = !!value;
  299. queue_work(asus->led_workqueue, &asus->tpd_led_work);
  300. }
  301. static int read_tpd_led_state(struct asus_wmi *asus)
  302. {
  303. return asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_TOUCHPAD_LED);
  304. }
  305. static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
  306. {
  307. struct asus_wmi *asus;
  308. asus = container_of(led_cdev, struct asus_wmi, tpd_led);
  309. return read_tpd_led_state(asus);
  310. }
  311. static void kbd_led_update(struct work_struct *work)
  312. {
  313. int ctrl_param = 0;
  314. struct asus_wmi *asus;
  315. asus = container_of(work, struct asus_wmi, kbd_led_work);
  316. /*
  317. * bits 0-2: level
  318. * bit 7: light on/off
  319. */
  320. if (asus->kbd_led_wk > 0)
  321. ctrl_param = 0x80 | (asus->kbd_led_wk & 0x7F);
  322. asus_wmi_set_devstate(ASUS_WMI_DEVID_KBD_BACKLIGHT, ctrl_param, NULL);
  323. }
  324. static int kbd_led_read(struct asus_wmi *asus, int *level, int *env)
  325. {
  326. int retval;
  327. /*
  328. * bits 0-2: level
  329. * bit 7: light on/off
  330. * bit 8-10: environment (0: dark, 1: normal, 2: light)
  331. * bit 17: status unknown
  332. */
  333. retval = asus_wmi_get_devstate_bits(asus, ASUS_WMI_DEVID_KBD_BACKLIGHT,
  334. 0xFFFF);
  335. /* Unknown status is considered as off */
  336. if (retval == 0x8000)
  337. retval = 0;
  338. if (retval >= 0) {
  339. if (level)
  340. *level = retval & 0x7F;
  341. if (env)
  342. *env = (retval >> 8) & 0x7F;
  343. retval = 0;
  344. }
  345. return retval;
  346. }
  347. static void kbd_led_set(struct led_classdev *led_cdev,
  348. enum led_brightness value)
  349. {
  350. struct asus_wmi *asus;
  351. asus = container_of(led_cdev, struct asus_wmi, kbd_led);
  352. if (value > asus->kbd_led.max_brightness)
  353. value = asus->kbd_led.max_brightness;
  354. else if (value < 0)
  355. value = 0;
  356. asus->kbd_led_wk = value;
  357. queue_work(asus->led_workqueue, &asus->kbd_led_work);
  358. }
  359. static enum led_brightness kbd_led_get(struct led_classdev *led_cdev)
  360. {
  361. struct asus_wmi *asus;
  362. int retval, value;
  363. asus = container_of(led_cdev, struct asus_wmi, kbd_led);
  364. retval = kbd_led_read(asus, &value, NULL);
  365. if (retval < 0)
  366. return retval;
  367. return value;
  368. }
  369. static void asus_wmi_led_exit(struct asus_wmi *asus)
  370. {
  371. if (!IS_ERR_OR_NULL(asus->kbd_led.dev))
  372. led_classdev_unregister(&asus->kbd_led);
  373. if (!IS_ERR_OR_NULL(asus->tpd_led.dev))
  374. led_classdev_unregister(&asus->tpd_led);
  375. if (asus->led_workqueue)
  376. destroy_workqueue(asus->led_workqueue);
  377. }
  378. static int asus_wmi_led_init(struct asus_wmi *asus)
  379. {
  380. int rv = 0;
  381. asus->led_workqueue = create_singlethread_workqueue("led_workqueue");
  382. if (!asus->led_workqueue)
  383. return -ENOMEM;
  384. if (read_tpd_led_state(asus) >= 0) {
  385. INIT_WORK(&asus->tpd_led_work, tpd_led_update);
  386. asus->tpd_led.name = "asus::touchpad";
  387. asus->tpd_led.brightness_set = tpd_led_set;
  388. asus->tpd_led.brightness_get = tpd_led_get;
  389. asus->tpd_led.max_brightness = 1;
  390. rv = led_classdev_register(&asus->platform_device->dev,
  391. &asus->tpd_led);
  392. if (rv)
  393. goto error;
  394. }
  395. if (kbd_led_read(asus, NULL, NULL) >= 0) {
  396. INIT_WORK(&asus->kbd_led_work, kbd_led_update);
  397. asus->kbd_led.name = "asus::kbd_backlight";
  398. asus->kbd_led.brightness_set = kbd_led_set;
  399. asus->kbd_led.brightness_get = kbd_led_get;
  400. asus->kbd_led.max_brightness = 3;
  401. rv = led_classdev_register(&asus->platform_device->dev,
  402. &asus->kbd_led);
  403. }
  404. error:
  405. if (rv)
  406. asus_wmi_led_exit(asus);
  407. return rv;
  408. }
  409. /*
  410. * PCI hotplug (for wlan rfkill)
  411. */
  412. static bool asus_wlan_rfkill_blocked(struct asus_wmi *asus)
  413. {
  414. int result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN);
  415. if (result < 0)
  416. return false;
  417. return !result;
  418. }
  419. static void asus_rfkill_hotplug(struct asus_wmi *asus)
  420. {
  421. struct pci_dev *dev;
  422. struct pci_bus *bus;
  423. bool blocked;
  424. bool absent;
  425. u32 l;
  426. mutex_lock(&asus->wmi_lock);
  427. blocked = asus_wlan_rfkill_blocked(asus);
  428. mutex_unlock(&asus->wmi_lock);
  429. mutex_lock(&asus->hotplug_lock);
  430. if (asus->wlan.rfkill)
  431. rfkill_set_sw_state(asus->wlan.rfkill, blocked);
  432. if (asus->hotplug_slot) {
  433. bus = pci_find_bus(0, 1);
  434. if (!bus) {
  435. pr_warn("Unable to find PCI bus 1?\n");
  436. goto out_unlock;
  437. }
  438. if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
  439. pr_err("Unable to read PCI config space?\n");
  440. goto out_unlock;
  441. }
  442. absent = (l == 0xffffffff);
  443. if (blocked != absent) {
  444. pr_warn("BIOS says wireless lan is %s, "
  445. "but the pci device is %s\n",
  446. blocked ? "blocked" : "unblocked",
  447. absent ? "absent" : "present");
  448. pr_warn("skipped wireless hotplug as probably "
  449. "inappropriate for this model\n");
  450. goto out_unlock;
  451. }
  452. if (!blocked) {
  453. dev = pci_get_slot(bus, 0);
  454. if (dev) {
  455. /* Device already present */
  456. pci_dev_put(dev);
  457. goto out_unlock;
  458. }
  459. dev = pci_scan_single_device(bus, 0);
  460. if (dev) {
  461. pci_bus_assign_resources(bus);
  462. if (pci_bus_add_device(dev))
  463. pr_err("Unable to hotplug wifi\n");
  464. }
  465. } else {
  466. dev = pci_get_slot(bus, 0);
  467. if (dev) {
  468. pci_stop_and_remove_bus_device(dev);
  469. pci_dev_put(dev);
  470. }
  471. }
  472. }
  473. out_unlock:
  474. mutex_unlock(&asus->hotplug_lock);
  475. }
  476. static void asus_rfkill_notify(acpi_handle handle, u32 event, void *data)
  477. {
  478. struct asus_wmi *asus = data;
  479. if (event != ACPI_NOTIFY_BUS_CHECK)
  480. return;
  481. /*
  482. * We can't call directly asus_rfkill_hotplug because most
  483. * of the time WMBC is still being executed and not reetrant.
  484. * There is currently no way to tell ACPICA that we want this
  485. * method to be serialized, we schedule a asus_rfkill_hotplug
  486. * call later, in a safer context.
  487. */
  488. queue_work(asus->hotplug_workqueue, &asus->hotplug_work);
  489. }
  490. static int asus_register_rfkill_notifier(struct asus_wmi *asus, char *node)
  491. {
  492. acpi_status status;
  493. acpi_handle handle;
  494. status = acpi_get_handle(NULL, node, &handle);
  495. if (ACPI_SUCCESS(status)) {
  496. status = acpi_install_notify_handler(handle,
  497. ACPI_SYSTEM_NOTIFY,
  498. asus_rfkill_notify, asus);
  499. if (ACPI_FAILURE(status))
  500. pr_warn("Failed to register notify on %s\n", node);
  501. } else
  502. return -ENODEV;
  503. return 0;
  504. }
  505. static void asus_unregister_rfkill_notifier(struct asus_wmi *asus, char *node)
  506. {
  507. acpi_status status = AE_OK;
  508. acpi_handle handle;
  509. status = acpi_get_handle(NULL, node, &handle);
  510. if (ACPI_SUCCESS(status)) {
  511. status = acpi_remove_notify_handler(handle,
  512. ACPI_SYSTEM_NOTIFY,
  513. asus_rfkill_notify);
  514. if (ACPI_FAILURE(status))
  515. pr_err("Error removing rfkill notify handler %s\n",
  516. node);
  517. }
  518. }
  519. static int asus_get_adapter_status(struct hotplug_slot *hotplug_slot,
  520. u8 *value)
  521. {
  522. struct asus_wmi *asus = hotplug_slot->private;
  523. int result = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN);
  524. if (result < 0)
  525. return result;
  526. *value = !!result;
  527. return 0;
  528. }
  529. static void asus_cleanup_pci_hotplug(struct hotplug_slot *hotplug_slot)
  530. {
  531. kfree(hotplug_slot->info);
  532. kfree(hotplug_slot);
  533. }
  534. static struct hotplug_slot_ops asus_hotplug_slot_ops = {
  535. .owner = THIS_MODULE,
  536. .get_adapter_status = asus_get_adapter_status,
  537. .get_power_status = asus_get_adapter_status,
  538. };
  539. static void asus_hotplug_work(struct work_struct *work)
  540. {
  541. struct asus_wmi *asus;
  542. asus = container_of(work, struct asus_wmi, hotplug_work);
  543. asus_rfkill_hotplug(asus);
  544. }
  545. static int asus_setup_pci_hotplug(struct asus_wmi *asus)
  546. {
  547. int ret = -ENOMEM;
  548. struct pci_bus *bus = pci_find_bus(0, 1);
  549. if (!bus) {
  550. pr_err("Unable to find wifi PCI bus\n");
  551. return -ENODEV;
  552. }
  553. asus->hotplug_workqueue =
  554. create_singlethread_workqueue("hotplug_workqueue");
  555. if (!asus->hotplug_workqueue)
  556. goto error_workqueue;
  557. INIT_WORK(&asus->hotplug_work, asus_hotplug_work);
  558. asus->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
  559. if (!asus->hotplug_slot)
  560. goto error_slot;
  561. asus->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
  562. GFP_KERNEL);
  563. if (!asus->hotplug_slot->info)
  564. goto error_info;
  565. asus->hotplug_slot->private = asus;
  566. asus->hotplug_slot->release = &asus_cleanup_pci_hotplug;
  567. asus->hotplug_slot->ops = &asus_hotplug_slot_ops;
  568. asus_get_adapter_status(asus->hotplug_slot,
  569. &asus->hotplug_slot->info->adapter_status);
  570. ret = pci_hp_register(asus->hotplug_slot, bus, 0, "asus-wifi");
  571. if (ret) {
  572. pr_err("Unable to register hotplug slot - %d\n", ret);
  573. goto error_register;
  574. }
  575. return 0;
  576. error_register:
  577. kfree(asus->hotplug_slot->info);
  578. error_info:
  579. kfree(asus->hotplug_slot);
  580. asus->hotplug_slot = NULL;
  581. error_slot:
  582. destroy_workqueue(asus->hotplug_workqueue);
  583. error_workqueue:
  584. return ret;
  585. }
  586. /*
  587. * Rfkill devices
  588. */
  589. static int asus_rfkill_set(void *data, bool blocked)
  590. {
  591. struct asus_rfkill *priv = data;
  592. u32 ctrl_param = !blocked;
  593. return asus_wmi_set_devstate(priv->dev_id, ctrl_param, NULL);
  594. }
  595. static void asus_rfkill_query(struct rfkill *rfkill, void *data)
  596. {
  597. struct asus_rfkill *priv = data;
  598. int result;
  599. result = asus_wmi_get_devstate_simple(priv->asus, priv->dev_id);
  600. if (result < 0)
  601. return;
  602. rfkill_set_sw_state(priv->rfkill, !result);
  603. }
  604. static int asus_rfkill_wlan_set(void *data, bool blocked)
  605. {
  606. struct asus_rfkill *priv = data;
  607. struct asus_wmi *asus = priv->asus;
  608. int ret;
  609. /*
  610. * This handler is enabled only if hotplug is enabled.
  611. * In this case, the asus_wmi_set_devstate() will
  612. * trigger a wmi notification and we need to wait
  613. * this call to finish before being able to call
  614. * any wmi method
  615. */
  616. mutex_lock(&asus->wmi_lock);
  617. ret = asus_rfkill_set(data, blocked);
  618. mutex_unlock(&asus->wmi_lock);
  619. return ret;
  620. }
  621. static const struct rfkill_ops asus_rfkill_wlan_ops = {
  622. .set_block = asus_rfkill_wlan_set,
  623. .query = asus_rfkill_query,
  624. };
  625. static const struct rfkill_ops asus_rfkill_ops = {
  626. .set_block = asus_rfkill_set,
  627. .query = asus_rfkill_query,
  628. };
  629. static int asus_new_rfkill(struct asus_wmi *asus,
  630. struct asus_rfkill *arfkill,
  631. const char *name, enum rfkill_type type, int dev_id)
  632. {
  633. int result = asus_wmi_get_devstate_simple(asus, dev_id);
  634. struct rfkill **rfkill = &arfkill->rfkill;
  635. if (result < 0)
  636. return result;
  637. arfkill->dev_id = dev_id;
  638. arfkill->asus = asus;
  639. if (dev_id == ASUS_WMI_DEVID_WLAN &&
  640. asus->driver->quirks->hotplug_wireless)
  641. *rfkill = rfkill_alloc(name, &asus->platform_device->dev, type,
  642. &asus_rfkill_wlan_ops, arfkill);
  643. else
  644. *rfkill = rfkill_alloc(name, &asus->platform_device->dev, type,
  645. &asus_rfkill_ops, arfkill);
  646. if (!*rfkill)
  647. return -EINVAL;
  648. rfkill_init_sw_state(*rfkill, !result);
  649. result = rfkill_register(*rfkill);
  650. if (result) {
  651. rfkill_destroy(*rfkill);
  652. *rfkill = NULL;
  653. return result;
  654. }
  655. return 0;
  656. }
  657. static void asus_wmi_rfkill_exit(struct asus_wmi *asus)
  658. {
  659. asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P5");
  660. asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P6");
  661. asus_unregister_rfkill_notifier(asus, "\\_SB.PCI0.P0P7");
  662. if (asus->wlan.rfkill) {
  663. rfkill_unregister(asus->wlan.rfkill);
  664. rfkill_destroy(asus->wlan.rfkill);
  665. asus->wlan.rfkill = NULL;
  666. }
  667. /*
  668. * Refresh pci hotplug in case the rfkill state was changed after
  669. * asus_unregister_rfkill_notifier()
  670. */
  671. asus_rfkill_hotplug(asus);
  672. if (asus->hotplug_slot)
  673. pci_hp_deregister(asus->hotplug_slot);
  674. if (asus->hotplug_workqueue)
  675. destroy_workqueue(asus->hotplug_workqueue);
  676. if (asus->bluetooth.rfkill) {
  677. rfkill_unregister(asus->bluetooth.rfkill);
  678. rfkill_destroy(asus->bluetooth.rfkill);
  679. asus->bluetooth.rfkill = NULL;
  680. }
  681. if (asus->wimax.rfkill) {
  682. rfkill_unregister(asus->wimax.rfkill);
  683. rfkill_destroy(asus->wimax.rfkill);
  684. asus->wimax.rfkill = NULL;
  685. }
  686. if (asus->wwan3g.rfkill) {
  687. rfkill_unregister(asus->wwan3g.rfkill);
  688. rfkill_destroy(asus->wwan3g.rfkill);
  689. asus->wwan3g.rfkill = NULL;
  690. }
  691. if (asus->gps.rfkill) {
  692. rfkill_unregister(asus->gps.rfkill);
  693. rfkill_destroy(asus->gps.rfkill);
  694. asus->gps.rfkill = NULL;
  695. }
  696. if (asus->uwb.rfkill) {
  697. rfkill_unregister(asus->uwb.rfkill);
  698. rfkill_destroy(asus->uwb.rfkill);
  699. asus->uwb.rfkill = NULL;
  700. }
  701. }
  702. static int asus_wmi_rfkill_init(struct asus_wmi *asus)
  703. {
  704. int result = 0;
  705. mutex_init(&asus->hotplug_lock);
  706. mutex_init(&asus->wmi_lock);
  707. result = asus_new_rfkill(asus, &asus->wlan, "asus-wlan",
  708. RFKILL_TYPE_WLAN, ASUS_WMI_DEVID_WLAN);
  709. if (result && result != -ENODEV)
  710. goto exit;
  711. result = asus_new_rfkill(asus, &asus->bluetooth,
  712. "asus-bluetooth", RFKILL_TYPE_BLUETOOTH,
  713. ASUS_WMI_DEVID_BLUETOOTH);
  714. if (result && result != -ENODEV)
  715. goto exit;
  716. result = asus_new_rfkill(asus, &asus->wimax, "asus-wimax",
  717. RFKILL_TYPE_WIMAX, ASUS_WMI_DEVID_WIMAX);
  718. if (result && result != -ENODEV)
  719. goto exit;
  720. result = asus_new_rfkill(asus, &asus->wwan3g, "asus-wwan3g",
  721. RFKILL_TYPE_WWAN, ASUS_WMI_DEVID_WWAN3G);
  722. if (result && result != -ENODEV)
  723. goto exit;
  724. result = asus_new_rfkill(asus, &asus->gps, "asus-gps",
  725. RFKILL_TYPE_GPS, ASUS_WMI_DEVID_GPS);
  726. if (result && result != -ENODEV)
  727. goto exit;
  728. result = asus_new_rfkill(asus, &asus->uwb, "asus-uwb",
  729. RFKILL_TYPE_UWB, ASUS_WMI_DEVID_UWB);
  730. if (result && result != -ENODEV)
  731. goto exit;
  732. if (!asus->driver->quirks->hotplug_wireless)
  733. goto exit;
  734. result = asus_setup_pci_hotplug(asus);
  735. /*
  736. * If we get -EBUSY then something else is handling the PCI hotplug -
  737. * don't fail in this case
  738. */
  739. if (result == -EBUSY)
  740. result = 0;
  741. asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P5");
  742. asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P6");
  743. asus_register_rfkill_notifier(asus, "\\_SB.PCI0.P0P7");
  744. /*
  745. * Refresh pci hotplug in case the rfkill state was changed during
  746. * setup.
  747. */
  748. asus_rfkill_hotplug(asus);
  749. exit:
  750. if (result && result != -ENODEV)
  751. asus_wmi_rfkill_exit(asus);
  752. if (result == -ENODEV)
  753. result = 0;
  754. return result;
  755. }
  756. /*
  757. * Hwmon device
  758. */
  759. static ssize_t asus_hwmon_pwm1(struct device *dev,
  760. struct device_attribute *attr,
  761. char *buf)
  762. {
  763. struct asus_wmi *asus = dev_get_drvdata(dev);
  764. u32 value;
  765. int err;
  766. err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_FAN_CTRL, &value);
  767. if (err < 0)
  768. return err;
  769. value &= 0xFF;
  770. if (value == 1) /* Low Speed */
  771. value = 85;
  772. else if (value == 2)
  773. value = 170;
  774. else if (value == 3)
  775. value = 255;
  776. else if (value != 0) {
  777. pr_err("Unknown fan speed %#x", value);
  778. value = -1;
  779. }
  780. return sprintf(buf, "%d\n", value);
  781. }
  782. static ssize_t asus_hwmon_temp1(struct device *dev,
  783. struct device_attribute *attr,
  784. char *buf)
  785. {
  786. struct asus_wmi *asus = dev_get_drvdata(dev);
  787. u32 value;
  788. int err;
  789. err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_THERMAL_CTRL, &value);
  790. if (err < 0)
  791. return err;
  792. value = KELVIN_TO_CELSIUS((value & 0xFFFF)) * 1000;
  793. return sprintf(buf, "%d\n", value);
  794. }
  795. static SENSOR_DEVICE_ATTR(pwm1, S_IRUGO, asus_hwmon_pwm1, NULL, 0);
  796. static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, asus_hwmon_temp1, NULL, 0);
  797. static ssize_t
  798. show_name(struct device *dev, struct device_attribute *attr, char *buf)
  799. {
  800. return sprintf(buf, "asus\n");
  801. }
  802. static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, 0);
  803. static struct attribute *hwmon_attributes[] = {
  804. &sensor_dev_attr_pwm1.dev_attr.attr,
  805. &sensor_dev_attr_temp1_input.dev_attr.attr,
  806. &sensor_dev_attr_name.dev_attr.attr,
  807. NULL
  808. };
  809. static umode_t asus_hwmon_sysfs_is_visible(struct kobject *kobj,
  810. struct attribute *attr, int idx)
  811. {
  812. struct device *dev = container_of(kobj, struct device, kobj);
  813. struct platform_device *pdev = to_platform_device(dev->parent);
  814. struct asus_wmi *asus = platform_get_drvdata(pdev);
  815. bool ok = true;
  816. int dev_id = -1;
  817. u32 value = ASUS_WMI_UNSUPPORTED_METHOD;
  818. if (attr == &sensor_dev_attr_pwm1.dev_attr.attr)
  819. dev_id = ASUS_WMI_DEVID_FAN_CTRL;
  820. else if (attr == &sensor_dev_attr_temp1_input.dev_attr.attr)
  821. dev_id = ASUS_WMI_DEVID_THERMAL_CTRL;
  822. if (dev_id != -1) {
  823. int err = asus_wmi_get_devstate(asus, dev_id, &value);
  824. if (err < 0)
  825. return 0; /* can't return negative here */
  826. }
  827. if (dev_id == ASUS_WMI_DEVID_FAN_CTRL) {
  828. /*
  829. * We need to find a better way, probably using sfun,
  830. * bits or spec ...
  831. * Currently we disable it if:
  832. * - ASUS_WMI_UNSUPPORTED_METHOD is returned
  833. * - reverved bits are non-zero
  834. * - sfun and presence bit are not set
  835. */
  836. if (value == ASUS_WMI_UNSUPPORTED_METHOD || value & 0xFFF80000
  837. || (!asus->sfun && !(value & ASUS_WMI_DSTS_PRESENCE_BIT)))
  838. ok = false;
  839. } else if (dev_id == ASUS_WMI_DEVID_THERMAL_CTRL) {
  840. /* If value is zero, something is clearly wrong */
  841. if (value == 0)
  842. ok = false;
  843. }
  844. return ok ? attr->mode : 0;
  845. }
  846. static struct attribute_group hwmon_attribute_group = {
  847. .is_visible = asus_hwmon_sysfs_is_visible,
  848. .attrs = hwmon_attributes
  849. };
  850. static void asus_wmi_hwmon_exit(struct asus_wmi *asus)
  851. {
  852. struct device *hwmon;
  853. hwmon = asus->hwmon_device;
  854. if (!hwmon)
  855. return;
  856. sysfs_remove_group(&hwmon->kobj, &hwmon_attribute_group);
  857. hwmon_device_unregister(hwmon);
  858. asus->hwmon_device = NULL;
  859. }
  860. static int asus_wmi_hwmon_init(struct asus_wmi *asus)
  861. {
  862. struct device *hwmon;
  863. int result;
  864. hwmon = hwmon_device_register(&asus->platform_device->dev);
  865. if (IS_ERR(hwmon)) {
  866. pr_err("Could not register asus hwmon device\n");
  867. return PTR_ERR(hwmon);
  868. }
  869. dev_set_drvdata(hwmon, asus);
  870. asus->hwmon_device = hwmon;
  871. result = sysfs_create_group(&hwmon->kobj, &hwmon_attribute_group);
  872. if (result)
  873. asus_wmi_hwmon_exit(asus);
  874. return result;
  875. }
  876. /*
  877. * Backlight
  878. */
  879. static int read_backlight_power(struct asus_wmi *asus)
  880. {
  881. int ret;
  882. if (asus->driver->quirks->store_backlight_power)
  883. ret = !asus->driver->panel_power;
  884. else
  885. ret = asus_wmi_get_devstate_simple(asus,
  886. ASUS_WMI_DEVID_BACKLIGHT);
  887. if (ret < 0)
  888. return ret;
  889. return ret ? FB_BLANK_UNBLANK : FB_BLANK_POWERDOWN;
  890. }
  891. static int read_brightness_max(struct asus_wmi *asus)
  892. {
  893. u32 retval;
  894. int err;
  895. err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval);
  896. if (err < 0)
  897. return err;
  898. retval = retval & ASUS_WMI_DSTS_MAX_BRIGTH_MASK;
  899. retval >>= 8;
  900. if (!retval)
  901. return -ENODEV;
  902. return retval;
  903. }
  904. static int read_brightness(struct backlight_device *bd)
  905. {
  906. struct asus_wmi *asus = bl_get_data(bd);
  907. u32 retval;
  908. int err;
  909. err = asus_wmi_get_devstate(asus, ASUS_WMI_DEVID_BRIGHTNESS, &retval);
  910. if (err < 0)
  911. return err;
  912. return retval & ASUS_WMI_DSTS_BRIGHTNESS_MASK;
  913. }
  914. static u32 get_scalar_command(struct backlight_device *bd)
  915. {
  916. struct asus_wmi *asus = bl_get_data(bd);
  917. u32 ctrl_param = 0;
  918. if ((asus->driver->brightness < bd->props.brightness) ||
  919. bd->props.brightness == bd->props.max_brightness)
  920. ctrl_param = 0x00008001;
  921. else if ((asus->driver->brightness > bd->props.brightness) ||
  922. bd->props.brightness == 0)
  923. ctrl_param = 0x00008000;
  924. asus->driver->brightness = bd->props.brightness;
  925. return ctrl_param;
  926. }
  927. static int update_bl_status(struct backlight_device *bd)
  928. {
  929. struct asus_wmi *asus = bl_get_data(bd);
  930. u32 ctrl_param;
  931. int power, err = 0;
  932. power = read_backlight_power(asus);
  933. if (power != -ENODEV && bd->props.power != power) {
  934. ctrl_param = !!(bd->props.power == FB_BLANK_UNBLANK);
  935. err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BACKLIGHT,
  936. ctrl_param, NULL);
  937. if (asus->driver->quirks->store_backlight_power)
  938. asus->driver->panel_power = bd->props.power;
  939. /* When using scalar brightness, updating the brightness
  940. * will mess with the backlight power */
  941. if (asus->driver->quirks->scalar_panel_brightness)
  942. return err;
  943. }
  944. if (asus->driver->quirks->scalar_panel_brightness)
  945. ctrl_param = get_scalar_command(bd);
  946. else
  947. ctrl_param = bd->props.brightness;
  948. err = asus_wmi_set_devstate(ASUS_WMI_DEVID_BRIGHTNESS,
  949. ctrl_param, NULL);
  950. return err;
  951. }
  952. static const struct backlight_ops asus_wmi_bl_ops = {
  953. .get_brightness = read_brightness,
  954. .update_status = update_bl_status,
  955. };
  956. static int asus_wmi_backlight_notify(struct asus_wmi *asus, int code)
  957. {
  958. struct backlight_device *bd = asus->backlight_device;
  959. int old = bd->props.brightness;
  960. int new = old;
  961. if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
  962. new = code - NOTIFY_BRNUP_MIN + 1;
  963. else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
  964. new = code - NOTIFY_BRNDOWN_MIN;
  965. bd->props.brightness = new;
  966. backlight_update_status(bd);
  967. backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
  968. return old;
  969. }
  970. static int asus_wmi_backlight_init(struct asus_wmi *asus)
  971. {
  972. struct backlight_device *bd;
  973. struct backlight_properties props;
  974. int max;
  975. int power;
  976. max = read_brightness_max(asus);
  977. if (max == -ENODEV)
  978. max = 0;
  979. else if (max < 0)
  980. return max;
  981. power = read_backlight_power(asus);
  982. if (power == -ENODEV)
  983. power = FB_BLANK_UNBLANK;
  984. else if (power < 0)
  985. return power;
  986. memset(&props, 0, sizeof(struct backlight_properties));
  987. props.type = BACKLIGHT_PLATFORM;
  988. props.max_brightness = max;
  989. bd = backlight_device_register(asus->driver->name,
  990. &asus->platform_device->dev, asus,
  991. &asus_wmi_bl_ops, &props);
  992. if (IS_ERR(bd)) {
  993. pr_err("Could not register backlight device\n");
  994. return PTR_ERR(bd);
  995. }
  996. asus->backlight_device = bd;
  997. if (asus->driver->quirks->store_backlight_power)
  998. asus->driver->panel_power = power;
  999. bd->props.brightness = read_brightness(bd);
  1000. bd->props.power = power;
  1001. backlight_update_status(bd);
  1002. asus->driver->brightness = bd->props.brightness;
  1003. return 0;
  1004. }
  1005. static void asus_wmi_backlight_exit(struct asus_wmi *asus)
  1006. {
  1007. if (asus->backlight_device)
  1008. backlight_device_unregister(asus->backlight_device);
  1009. asus->backlight_device = NULL;
  1010. }
  1011. static void asus_wmi_notify(u32 value, void *context)
  1012. {
  1013. struct asus_wmi *asus = context;
  1014. struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
  1015. union acpi_object *obj;
  1016. acpi_status status;
  1017. int code;
  1018. int orig_code;
  1019. unsigned int key_value = 1;
  1020. bool autorelease = 1;
  1021. status = wmi_get_event_data(value, &response);
  1022. if (status != AE_OK) {
  1023. pr_err("bad event status 0x%x\n", status);
  1024. return;
  1025. }
  1026. obj = (union acpi_object *)response.pointer;
  1027. if (!obj || obj->type != ACPI_TYPE_INTEGER)
  1028. goto exit;
  1029. code = obj->integer.value;
  1030. orig_code = code;
  1031. if (asus->driver->key_filter) {
  1032. asus->driver->key_filter(asus->driver, &code, &key_value,
  1033. &autorelease);
  1034. if (code == ASUS_WMI_KEY_IGNORE)
  1035. goto exit;
  1036. }
  1037. if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
  1038. code = NOTIFY_BRNUP_MIN;
  1039. else if (code >= NOTIFY_BRNDOWN_MIN &&
  1040. code <= NOTIFY_BRNDOWN_MAX)
  1041. code = NOTIFY_BRNDOWN_MIN;
  1042. if (code == NOTIFY_BRNUP_MIN || code == NOTIFY_BRNDOWN_MIN) {
  1043. if (!acpi_video_backlight_support())
  1044. asus_wmi_backlight_notify(asus, orig_code);
  1045. } else if (!sparse_keymap_report_event(asus->inputdev, code,
  1046. key_value, autorelease))
  1047. pr_info("Unknown key %x pressed\n", code);
  1048. exit:
  1049. kfree(obj);
  1050. }
  1051. /*
  1052. * Sys helpers
  1053. */
  1054. static int parse_arg(const char *buf, unsigned long count, int *val)
  1055. {
  1056. if (!count)
  1057. return 0;
  1058. if (sscanf(buf, "%i", val) != 1)
  1059. return -EINVAL;
  1060. return count;
  1061. }
  1062. static ssize_t store_sys_wmi(struct asus_wmi *asus, int devid,
  1063. const char *buf, size_t count)
  1064. {
  1065. u32 retval;
  1066. int rv, err, value;
  1067. value = asus_wmi_get_devstate_simple(asus, devid);
  1068. if (value == -ENODEV) /* Check device presence */
  1069. return value;
  1070. rv = parse_arg(buf, count, &value);
  1071. err = asus_wmi_set_devstate(devid, value, &retval);
  1072. if (err < 0)
  1073. return err;
  1074. return rv;
  1075. }
  1076. static ssize_t show_sys_wmi(struct asus_wmi *asus, int devid, char *buf)
  1077. {
  1078. int value = asus_wmi_get_devstate_simple(asus, devid);
  1079. if (value < 0)
  1080. return value;
  1081. return sprintf(buf, "%d\n", value);
  1082. }
  1083. #define ASUS_WMI_CREATE_DEVICE_ATTR(_name, _mode, _cm) \
  1084. static ssize_t show_##_name(struct device *dev, \
  1085. struct device_attribute *attr, \
  1086. char *buf) \
  1087. { \
  1088. struct asus_wmi *asus = dev_get_drvdata(dev); \
  1089. \
  1090. return show_sys_wmi(asus, _cm, buf); \
  1091. } \
  1092. static ssize_t store_##_name(struct device *dev, \
  1093. struct device_attribute *attr, \
  1094. const char *buf, size_t count) \
  1095. { \
  1096. struct asus_wmi *asus = dev_get_drvdata(dev); \
  1097. \
  1098. return store_sys_wmi(asus, _cm, buf, count); \
  1099. } \
  1100. static struct device_attribute dev_attr_##_name = { \
  1101. .attr = { \
  1102. .name = __stringify(_name), \
  1103. .mode = _mode }, \
  1104. .show = show_##_name, \
  1105. .store = store_##_name, \
  1106. }
  1107. ASUS_WMI_CREATE_DEVICE_ATTR(touchpad, 0644, ASUS_WMI_DEVID_TOUCHPAD);
  1108. ASUS_WMI_CREATE_DEVICE_ATTR(camera, 0644, ASUS_WMI_DEVID_CAMERA);
  1109. ASUS_WMI_CREATE_DEVICE_ATTR(cardr, 0644, ASUS_WMI_DEVID_CARDREADER);
  1110. static ssize_t store_cpufv(struct device *dev, struct device_attribute *attr,
  1111. const char *buf, size_t count)
  1112. {
  1113. int value, rv;
  1114. if (!count || sscanf(buf, "%i", &value) != 1)
  1115. return -EINVAL;
  1116. if (value < 0 || value > 2)
  1117. return -EINVAL;
  1118. rv = asus_wmi_evaluate_method(ASUS_WMI_METHODID_CFVS, value, 0, NULL);
  1119. if (rv < 0)
  1120. return rv;
  1121. return count;
  1122. }
  1123. static DEVICE_ATTR(cpufv, S_IRUGO | S_IWUSR, NULL, store_cpufv);
  1124. static struct attribute *platform_attributes[] = {
  1125. &dev_attr_cpufv.attr,
  1126. &dev_attr_camera.attr,
  1127. &dev_attr_cardr.attr,
  1128. &dev_attr_touchpad.attr,
  1129. NULL
  1130. };
  1131. static umode_t asus_sysfs_is_visible(struct kobject *kobj,
  1132. struct attribute *attr, int idx)
  1133. {
  1134. struct device *dev = container_of(kobj, struct device, kobj);
  1135. struct platform_device *pdev = to_platform_device(dev);
  1136. struct asus_wmi *asus = platform_get_drvdata(pdev);
  1137. bool ok = true;
  1138. int devid = -1;
  1139. if (attr == &dev_attr_camera.attr)
  1140. devid = ASUS_WMI_DEVID_CAMERA;
  1141. else if (attr == &dev_attr_cardr.attr)
  1142. devid = ASUS_WMI_DEVID_CARDREADER;
  1143. else if (attr == &dev_attr_touchpad.attr)
  1144. devid = ASUS_WMI_DEVID_TOUCHPAD;
  1145. if (devid != -1)
  1146. ok = !(asus_wmi_get_devstate_simple(asus, devid) < 0);
  1147. return ok ? attr->mode : 0;
  1148. }
  1149. static struct attribute_group platform_attribute_group = {
  1150. .is_visible = asus_sysfs_is_visible,
  1151. .attrs = platform_attributes
  1152. };
  1153. static void asus_wmi_sysfs_exit(struct platform_device *device)
  1154. {
  1155. sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
  1156. }
  1157. static int asus_wmi_sysfs_init(struct platform_device *device)
  1158. {
  1159. return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
  1160. }
  1161. /*
  1162. * Platform device
  1163. */
  1164. static int asus_wmi_platform_init(struct asus_wmi *asus)
  1165. {
  1166. int rv;
  1167. /* INIT enable hotkeys on some models */
  1168. if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_INIT, 0, 0, &rv))
  1169. pr_info("Initialization: %#x", rv);
  1170. /* We don't know yet what to do with this version... */
  1171. if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_SPEC, 0, 0x9, &rv)) {
  1172. pr_info("BIOS WMI version: %d.%d", rv >> 16, rv & 0xFF);
  1173. asus->spec = rv;
  1174. }
  1175. /*
  1176. * The SFUN method probably allows the original driver to get the list
  1177. * of features supported by a given model. For now, 0x0100 or 0x0800
  1178. * bit signifies that the laptop is equipped with a Wi-Fi MiniPCI card.
  1179. * The significance of others is yet to be found.
  1180. */
  1181. if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_SFUN, 0, 0, &rv)) {
  1182. pr_info("SFUN value: %#x", rv);
  1183. asus->sfun = rv;
  1184. }
  1185. /*
  1186. * Eee PC and Notebooks seems to have different method_id for DSTS,
  1187. * but it may also be related to the BIOS's SPEC.
  1188. * Note, on most Eeepc, there is no way to check if a method exist
  1189. * or note, while on notebooks, they returns 0xFFFFFFFE on failure,
  1190. * but once again, SPEC may probably be used for that kind of things.
  1191. */
  1192. if (!asus_wmi_evaluate_method(ASUS_WMI_METHODID_DSTS, 0, 0, NULL))
  1193. asus->dsts_id = ASUS_WMI_METHODID_DSTS;
  1194. else
  1195. asus->dsts_id = ASUS_WMI_METHODID_DSTS2;
  1196. /* CWAP allow to define the behavior of the Fn+F2 key,
  1197. * this method doesn't seems to be present on Eee PCs */
  1198. if (asus->driver->quirks->wapf >= 0)
  1199. asus_wmi_set_devstate(ASUS_WMI_DEVID_CWAP,
  1200. asus->driver->quirks->wapf, NULL);
  1201. return asus_wmi_sysfs_init(asus->platform_device);
  1202. }
  1203. static void asus_wmi_platform_exit(struct asus_wmi *asus)
  1204. {
  1205. asus_wmi_sysfs_exit(asus->platform_device);
  1206. }
  1207. /*
  1208. * debugfs
  1209. */
  1210. struct asus_wmi_debugfs_node {
  1211. struct asus_wmi *asus;
  1212. char *name;
  1213. int (*show) (struct seq_file *m, void *data);
  1214. };
  1215. static int show_dsts(struct seq_file *m, void *data)
  1216. {
  1217. struct asus_wmi *asus = m->private;
  1218. int err;
  1219. u32 retval = -1;
  1220. err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
  1221. if (err < 0)
  1222. return err;
  1223. seq_printf(m, "DSTS(%#x) = %#x\n", asus->debug.dev_id, retval);
  1224. return 0;
  1225. }
  1226. static int show_devs(struct seq_file *m, void *data)
  1227. {
  1228. struct asus_wmi *asus = m->private;
  1229. int err;
  1230. u32 retval = -1;
  1231. err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
  1232. &retval);
  1233. if (err < 0)
  1234. return err;
  1235. seq_printf(m, "DEVS(%#x, %#x) = %#x\n", asus->debug.dev_id,
  1236. asus->debug.ctrl_param, retval);
  1237. return 0;
  1238. }
  1239. static int show_call(struct seq_file *m, void *data)
  1240. {
  1241. struct asus_wmi *asus = m->private;
  1242. struct bios_args args = {
  1243. .arg0 = asus->debug.dev_id,
  1244. .arg1 = asus->debug.ctrl_param,
  1245. };
  1246. struct acpi_buffer input = { (acpi_size) sizeof(args), &args };
  1247. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  1248. union acpi_object *obj;
  1249. acpi_status status;
  1250. status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
  1251. 1, asus->debug.method_id,
  1252. &input, &output);
  1253. if (ACPI_FAILURE(status))
  1254. return -EIO;
  1255. obj = (union acpi_object *)output.pointer;
  1256. if (obj && obj->type == ACPI_TYPE_INTEGER)
  1257. seq_printf(m, "%#x(%#x, %#x) = %#x\n", asus->debug.method_id,
  1258. asus->debug.dev_id, asus->debug.ctrl_param,
  1259. (u32) obj->integer.value);
  1260. else
  1261. seq_printf(m, "%#x(%#x, %#x) = t:%d\n", asus->debug.method_id,
  1262. asus->debug.dev_id, asus->debug.ctrl_param,
  1263. obj ? obj->type : -1);
  1264. kfree(obj);
  1265. return 0;
  1266. }
  1267. static struct asus_wmi_debugfs_node asus_wmi_debug_files[] = {
  1268. {NULL, "devs", show_devs},
  1269. {NULL, "dsts", show_dsts},
  1270. {NULL, "call", show_call},
  1271. };
  1272. static int asus_wmi_debugfs_open(struct inode *inode, struct file *file)
  1273. {
  1274. struct asus_wmi_debugfs_node *node = inode->i_private;
  1275. return single_open(file, node->show, node->asus);
  1276. }
  1277. static const struct file_operations asus_wmi_debugfs_io_ops = {
  1278. .owner = THIS_MODULE,
  1279. .open = asus_wmi_debugfs_open,
  1280. .read = seq_read,
  1281. .llseek = seq_lseek,
  1282. .release = single_release,
  1283. };
  1284. static void asus_wmi_debugfs_exit(struct asus_wmi *asus)
  1285. {
  1286. debugfs_remove_recursive(asus->debug.root);
  1287. }
  1288. static int asus_wmi_debugfs_init(struct asus_wmi *asus)
  1289. {
  1290. struct dentry *dent;
  1291. int i;
  1292. asus->debug.root = debugfs_create_dir(asus->driver->name, NULL);
  1293. if (!asus->debug.root) {
  1294. pr_err("failed to create debugfs directory");
  1295. goto error_debugfs;
  1296. }
  1297. dent = debugfs_create_x32("method_id", S_IRUGO | S_IWUSR,
  1298. asus->debug.root, &asus->debug.method_id);
  1299. if (!dent)
  1300. goto error_debugfs;
  1301. dent = debugfs_create_x32("dev_id", S_IRUGO | S_IWUSR,
  1302. asus->debug.root, &asus->debug.dev_id);
  1303. if (!dent)
  1304. goto error_debugfs;
  1305. dent = debugfs_create_x32("ctrl_param", S_IRUGO | S_IWUSR,
  1306. asus->debug.root, &asus->debug.ctrl_param);
  1307. if (!dent)
  1308. goto error_debugfs;
  1309. for (i = 0; i < ARRAY_SIZE(asus_wmi_debug_files); i++) {
  1310. struct asus_wmi_debugfs_node *node = &asus_wmi_debug_files[i];
  1311. node->asus = asus;
  1312. dent = debugfs_create_file(node->name, S_IFREG | S_IRUGO,
  1313. asus->debug.root, node,
  1314. &asus_wmi_debugfs_io_ops);
  1315. if (!dent) {
  1316. pr_err("failed to create debug file: %s\n", node->name);
  1317. goto error_debugfs;
  1318. }
  1319. }
  1320. return 0;
  1321. error_debugfs:
  1322. asus_wmi_debugfs_exit(asus);
  1323. return -ENOMEM;
  1324. }
  1325. /*
  1326. * WMI Driver
  1327. */
  1328. static int asus_wmi_add(struct platform_device *pdev)
  1329. {
  1330. struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver);
  1331. struct asus_wmi_driver *wdrv = to_asus_wmi_driver(pdrv);
  1332. struct asus_wmi *asus;
  1333. acpi_status status;
  1334. int err;
  1335. asus = kzalloc(sizeof(struct asus_wmi), GFP_KERNEL);
  1336. if (!asus)
  1337. return -ENOMEM;
  1338. asus->driver = wdrv;
  1339. asus->platform_device = pdev;
  1340. wdrv->platform_device = pdev;
  1341. platform_set_drvdata(asus->platform_device, asus);
  1342. if (wdrv->detect_quirks)
  1343. wdrv->detect_quirks(asus->driver);
  1344. err = asus_wmi_platform_init(asus);
  1345. if (err)
  1346. goto fail_platform;
  1347. err = asus_wmi_input_init(asus);
  1348. if (err)
  1349. goto fail_input;
  1350. err = asus_wmi_hwmon_init(asus);
  1351. if (err)
  1352. goto fail_hwmon;
  1353. err = asus_wmi_led_init(asus);
  1354. if (err)
  1355. goto fail_leds;
  1356. err = asus_wmi_rfkill_init(asus);
  1357. if (err)
  1358. goto fail_rfkill;
  1359. if (!acpi_video_backlight_support()) {
  1360. err = asus_wmi_backlight_init(asus);
  1361. if (err && err != -ENODEV)
  1362. goto fail_backlight;
  1363. } else
  1364. pr_info("Backlight controlled by ACPI video driver\n");
  1365. status = wmi_install_notify_handler(asus->driver->event_guid,
  1366. asus_wmi_notify, asus);
  1367. if (ACPI_FAILURE(status)) {
  1368. pr_err("Unable to register notify handler - %d\n", status);
  1369. err = -ENODEV;
  1370. goto fail_wmi_handler;
  1371. }
  1372. err = asus_wmi_debugfs_init(asus);
  1373. if (err)
  1374. goto fail_debugfs;
  1375. return 0;
  1376. fail_debugfs:
  1377. wmi_remove_notify_handler(asus->driver->event_guid);
  1378. fail_wmi_handler:
  1379. asus_wmi_backlight_exit(asus);
  1380. fail_backlight:
  1381. asus_wmi_rfkill_exit(asus);
  1382. fail_rfkill:
  1383. asus_wmi_led_exit(asus);
  1384. fail_leds:
  1385. asus_wmi_hwmon_exit(asus);
  1386. fail_hwmon:
  1387. asus_wmi_input_exit(asus);
  1388. fail_input:
  1389. asus_wmi_platform_exit(asus);
  1390. fail_platform:
  1391. kfree(asus);
  1392. return err;
  1393. }
  1394. static int asus_wmi_remove(struct platform_device *device)
  1395. {
  1396. struct asus_wmi *asus;
  1397. asus = platform_get_drvdata(device);
  1398. wmi_remove_notify_handler(asus->driver->event_guid);
  1399. asus_wmi_backlight_exit(asus);
  1400. asus_wmi_input_exit(asus);
  1401. asus_wmi_hwmon_exit(asus);
  1402. asus_wmi_led_exit(asus);
  1403. asus_wmi_rfkill_exit(asus);
  1404. asus_wmi_debugfs_exit(asus);
  1405. asus_wmi_platform_exit(asus);
  1406. kfree(asus);
  1407. return 0;
  1408. }
  1409. /*
  1410. * Platform driver - hibernate/resume callbacks
  1411. */
  1412. static int asus_hotk_thaw(struct device *device)
  1413. {
  1414. struct asus_wmi *asus = dev_get_drvdata(device);
  1415. if (asus->wlan.rfkill) {
  1416. bool wlan;
  1417. /*
  1418. * Work around bios bug - acpi _PTS turns off the wireless led
  1419. * during suspend. Normally it restores it on resume, but
  1420. * we should kick it ourselves in case hibernation is aborted.
  1421. */
  1422. wlan = asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WLAN);
  1423. asus_wmi_set_devstate(ASUS_WMI_DEVID_WLAN, wlan, NULL);
  1424. }
  1425. return 0;
  1426. }
  1427. static int asus_hotk_restore(struct device *device)
  1428. {
  1429. struct asus_wmi *asus = dev_get_drvdata(device);
  1430. int bl;
  1431. /* Refresh both wlan rfkill state and pci hotplug */
  1432. if (asus->wlan.rfkill)
  1433. asus_rfkill_hotplug(asus);
  1434. if (asus->bluetooth.rfkill) {
  1435. bl = !asus_wmi_get_devstate_simple(asus,
  1436. ASUS_WMI_DEVID_BLUETOOTH);
  1437. rfkill_set_sw_state(asus->bluetooth.rfkill, bl);
  1438. }
  1439. if (asus->wimax.rfkill) {
  1440. bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WIMAX);
  1441. rfkill_set_sw_state(asus->wimax.rfkill, bl);
  1442. }
  1443. if (asus->wwan3g.rfkill) {
  1444. bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_WWAN3G);
  1445. rfkill_set_sw_state(asus->wwan3g.rfkill, bl);
  1446. }
  1447. if (asus->gps.rfkill) {
  1448. bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_GPS);
  1449. rfkill_set_sw_state(asus->gps.rfkill, bl);
  1450. }
  1451. if (asus->uwb.rfkill) {
  1452. bl = !asus_wmi_get_devstate_simple(asus, ASUS_WMI_DEVID_UWB);
  1453. rfkill_set_sw_state(asus->uwb.rfkill, bl);
  1454. }
  1455. return 0;
  1456. }
  1457. static const struct dev_pm_ops asus_pm_ops = {
  1458. .thaw = asus_hotk_thaw,
  1459. .restore = asus_hotk_restore,
  1460. };
  1461. static int asus_wmi_probe(struct platform_device *pdev)
  1462. {
  1463. struct platform_driver *pdrv = to_platform_driver(pdev->dev.driver);
  1464. struct asus_wmi_driver *wdrv = to_asus_wmi_driver(pdrv);
  1465. int ret;
  1466. if (!wmi_has_guid(ASUS_WMI_MGMT_GUID)) {
  1467. pr_warn("Management GUID not found\n");
  1468. return -ENODEV;
  1469. }
  1470. if (wdrv->event_guid && !wmi_has_guid(wdrv->event_guid)) {
  1471. pr_warn("Event GUID not found\n");
  1472. return -ENODEV;
  1473. }
  1474. if (wdrv->probe) {
  1475. ret = wdrv->probe(pdev);
  1476. if (ret)
  1477. return ret;
  1478. }
  1479. return asus_wmi_add(pdev);
  1480. }
  1481. static bool used;
  1482. int __init_or_module asus_wmi_register_driver(struct asus_wmi_driver *driver)
  1483. {
  1484. struct platform_driver *platform_driver;
  1485. struct platform_device *platform_device;
  1486. if (used)
  1487. return -EBUSY;
  1488. platform_driver = &driver->platform_driver;
  1489. platform_driver->remove = asus_wmi_remove;
  1490. platform_driver->driver.owner = driver->owner;
  1491. platform_driver->driver.name = driver->name;
  1492. platform_driver->driver.pm = &asus_pm_ops;
  1493. platform_device = platform_create_bundle(platform_driver,
  1494. asus_wmi_probe,
  1495. NULL, 0, NULL, 0);
  1496. if (IS_ERR(platform_device))
  1497. return PTR_ERR(platform_device);
  1498. used = true;
  1499. return 0;
  1500. }
  1501. EXPORT_SYMBOL_GPL(asus_wmi_register_driver);
  1502. void asus_wmi_unregister_driver(struct asus_wmi_driver *driver)
  1503. {
  1504. platform_device_unregister(driver->platform_device);
  1505. platform_driver_unregister(&driver->platform_driver);
  1506. used = false;
  1507. }
  1508. EXPORT_SYMBOL_GPL(asus_wmi_unregister_driver);
  1509. static int __init asus_wmi_init(void)
  1510. {
  1511. if (!wmi_has_guid(ASUS_WMI_MGMT_GUID)) {
  1512. pr_info("Asus Management GUID not found");
  1513. return -ENODEV;
  1514. }
  1515. pr_info("ASUS WMI generic driver loaded");
  1516. return 0;
  1517. }
  1518. static void __exit asus_wmi_exit(void)
  1519. {
  1520. pr_info("ASUS WMI generic driver unloaded");
  1521. }
  1522. module_init(asus_wmi_init);
  1523. module_exit(asus_wmi_exit);