asus-wmi.c 46 KB

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