asus-wmi.c 47 KB

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