eeepc-wmi.c 30 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276
  1. /*
  2. * Eee PC WMI hotkey driver
  3. *
  4. * Copyright(C) 2010 Intel Corporation.
  5. * Copyright(C) 2010 Corentin Chary <corentin.chary@gmail.com>
  6. *
  7. * Portions based on wistron_btns.c:
  8. * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
  9. * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
  10. * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 2 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  25. */
  26. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  27. #include <linux/kernel.h>
  28. #include <linux/module.h>
  29. #include <linux/init.h>
  30. #include <linux/types.h>
  31. #include <linux/slab.h>
  32. #include <linux/input.h>
  33. #include <linux/input/sparse-keymap.h>
  34. #include <linux/fb.h>
  35. #include <linux/backlight.h>
  36. #include <linux/leds.h>
  37. #include <linux/rfkill.h>
  38. #include <linux/pci.h>
  39. #include <linux/pci_hotplug.h>
  40. #include <linux/debugfs.h>
  41. #include <linux/seq_file.h>
  42. #include <linux/platform_device.h>
  43. #include <linux/dmi.h>
  44. #include <acpi/acpi_bus.h>
  45. #include <acpi/acpi_drivers.h>
  46. #define EEEPC_WMI_FILE "eeepc-wmi"
  47. MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>");
  48. MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver");
  49. MODULE_LICENSE("GPL");
  50. #define EEEPC_ACPI_HID "ASUS010" /* old _HID used in eeepc-laptop */
  51. #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000"
  52. #define EEEPC_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66"
  53. MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID);
  54. MODULE_ALIAS("wmi:"EEEPC_WMI_MGMT_GUID);
  55. #define NOTIFY_BRNUP_MIN 0x11
  56. #define NOTIFY_BRNUP_MAX 0x1f
  57. #define NOTIFY_BRNDOWN_MIN 0x20
  58. #define NOTIFY_BRNDOWN_MAX 0x2e
  59. #define EEEPC_WMI_METHODID_DSTS 0x53544344
  60. #define EEEPC_WMI_METHODID_DEVS 0x53564544
  61. #define EEEPC_WMI_METHODID_CFVS 0x53564643
  62. #define EEEPC_WMI_DEVID_WLAN 0x00010011
  63. #define EEEPC_WMI_DEVID_BLUETOOTH 0x00010013
  64. #define EEEPC_WMI_DEVID_WWAN3G 0x00010019
  65. #define EEEPC_WMI_DEVID_BACKLIGHT 0x00050012
  66. #define EEEPC_WMI_DEVID_TPDLED 0x00100011
  67. #define EEEPC_WMI_DSTS_STATUS_BIT 0x00000001
  68. #define EEEPC_WMI_DSTS_PRESENCE_BIT 0x00010000
  69. static bool hotplug_wireless;
  70. module_param(hotplug_wireless, bool, 0444);
  71. MODULE_PARM_DESC(hotplug_wireless,
  72. "Enable hotplug for wireless device. "
  73. "If your laptop needs that, please report to "
  74. "acpi4asus-user@lists.sourceforge.net.");
  75. static const struct key_entry eeepc_wmi_keymap[] = {
  76. /* Sleep already handled via generic ACPI code */
  77. { KE_IGNORE, NOTIFY_BRNDOWN_MIN, { KEY_BRIGHTNESSDOWN } },
  78. { KE_IGNORE, NOTIFY_BRNUP_MIN, { KEY_BRIGHTNESSUP } },
  79. { KE_KEY, 0x30, { KEY_VOLUMEUP } },
  80. { KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
  81. { KE_KEY, 0x32, { KEY_MUTE } },
  82. { KE_KEY, 0x5c, { KEY_F15 } },
  83. { KE_KEY, 0x5d, { KEY_WLAN } },
  84. { KE_KEY, 0x6b, { KEY_F13 } }, /* Disable Touchpad */
  85. { KE_KEY, 0x88, { KEY_WLAN } },
  86. { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
  87. { KE_KEY, 0xe0, { KEY_PROG1 } },
  88. { KE_KEY, 0xe1, { KEY_F14 } },
  89. { KE_KEY, 0xe9, { KEY_DISPLAY_OFF } },
  90. { KE_END, 0},
  91. };
  92. struct bios_args {
  93. u32 dev_id;
  94. u32 ctrl_param;
  95. };
  96. /*
  97. * eeepc-wmi/ - debugfs root directory
  98. * dev_id - current dev_id
  99. * ctrl_param - current ctrl_param
  100. * devs - call DEVS(dev_id, ctrl_param) and print result
  101. * dsts - call DSTS(dev_id) and print result
  102. */
  103. struct eeepc_wmi_debug {
  104. struct dentry *root;
  105. u32 dev_id;
  106. u32 ctrl_param;
  107. };
  108. struct eeepc_wmi {
  109. bool hotplug_wireless;
  110. struct input_dev *inputdev;
  111. struct backlight_device *backlight_device;
  112. struct platform_device *platform_device;
  113. struct led_classdev tpd_led;
  114. int tpd_led_wk;
  115. struct workqueue_struct *led_workqueue;
  116. struct work_struct tpd_led_work;
  117. struct rfkill *wlan_rfkill;
  118. struct rfkill *bluetooth_rfkill;
  119. struct rfkill *wwan3g_rfkill;
  120. struct hotplug_slot *hotplug_slot;
  121. struct mutex hotplug_lock;
  122. struct mutex wmi_lock;
  123. struct workqueue_struct *hotplug_workqueue;
  124. struct work_struct hotplug_work;
  125. struct eeepc_wmi_debug debug;
  126. };
  127. static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc)
  128. {
  129. int err;
  130. eeepc->inputdev = input_allocate_device();
  131. if (!eeepc->inputdev)
  132. return -ENOMEM;
  133. eeepc->inputdev->name = "Eee PC WMI hotkeys";
  134. eeepc->inputdev->phys = EEEPC_WMI_FILE "/input0";
  135. eeepc->inputdev->id.bustype = BUS_HOST;
  136. eeepc->inputdev->dev.parent = &eeepc->platform_device->dev;
  137. err = sparse_keymap_setup(eeepc->inputdev, eeepc_wmi_keymap, NULL);
  138. if (err)
  139. goto err_free_dev;
  140. err = input_register_device(eeepc->inputdev);
  141. if (err)
  142. goto err_free_keymap;
  143. return 0;
  144. err_free_keymap:
  145. sparse_keymap_free(eeepc->inputdev);
  146. err_free_dev:
  147. input_free_device(eeepc->inputdev);
  148. return err;
  149. }
  150. static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc)
  151. {
  152. if (eeepc->inputdev) {
  153. sparse_keymap_free(eeepc->inputdev);
  154. input_unregister_device(eeepc->inputdev);
  155. }
  156. eeepc->inputdev = NULL;
  157. }
  158. static acpi_status eeepc_wmi_get_devstate(u32 dev_id, u32 *retval)
  159. {
  160. struct acpi_buffer input = { (acpi_size)sizeof(u32), &dev_id };
  161. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  162. union acpi_object *obj;
  163. acpi_status status;
  164. u32 tmp;
  165. status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID,
  166. 1, EEEPC_WMI_METHODID_DSTS,
  167. &input, &output);
  168. if (ACPI_FAILURE(status))
  169. return status;
  170. obj = (union acpi_object *)output.pointer;
  171. if (obj && obj->type == ACPI_TYPE_INTEGER)
  172. tmp = (u32)obj->integer.value;
  173. else
  174. tmp = 0;
  175. if (retval)
  176. *retval = tmp;
  177. kfree(obj);
  178. return status;
  179. }
  180. static acpi_status eeepc_wmi_set_devstate(u32 dev_id, u32 ctrl_param,
  181. u32 *retval)
  182. {
  183. struct bios_args args = {
  184. .dev_id = dev_id,
  185. .ctrl_param = ctrl_param,
  186. };
  187. struct acpi_buffer input = { (acpi_size)sizeof(args), &args };
  188. acpi_status status;
  189. if (!retval) {
  190. status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1,
  191. EEEPC_WMI_METHODID_DEVS,
  192. &input, NULL);
  193. } else {
  194. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  195. union acpi_object *obj;
  196. u32 tmp;
  197. status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, 1,
  198. EEEPC_WMI_METHODID_DEVS,
  199. &input, &output);
  200. if (ACPI_FAILURE(status))
  201. return status;
  202. obj = (union acpi_object *)output.pointer;
  203. if (obj && obj->type == ACPI_TYPE_INTEGER)
  204. tmp = (u32)obj->integer.value;
  205. else
  206. tmp = 0;
  207. *retval = tmp;
  208. kfree(obj);
  209. }
  210. return status;
  211. }
  212. /* Helper for special devices with magic return codes */
  213. static int eeepc_wmi_get_devstate_simple(u32 dev_id)
  214. {
  215. u32 retval = 0;
  216. acpi_status status;
  217. status = eeepc_wmi_get_devstate(dev_id, &retval);
  218. if (ACPI_FAILURE(status))
  219. return -EINVAL;
  220. if (!(retval & EEEPC_WMI_DSTS_PRESENCE_BIT))
  221. return -ENODEV;
  222. return retval & EEEPC_WMI_DSTS_STATUS_BIT;
  223. }
  224. /*
  225. * LEDs
  226. */
  227. /*
  228. * These functions actually update the LED's, and are called from a
  229. * workqueue. By doing this as separate work rather than when the LED
  230. * subsystem asks, we avoid messing with the Eeepc ACPI stuff during a
  231. * potentially bad time, such as a timer interrupt.
  232. */
  233. static void tpd_led_update(struct work_struct *work)
  234. {
  235. int ctrl_param;
  236. struct eeepc_wmi *eeepc;
  237. eeepc = container_of(work, struct eeepc_wmi, tpd_led_work);
  238. ctrl_param = eeepc->tpd_led_wk;
  239. eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_TPDLED, ctrl_param, NULL);
  240. }
  241. static void tpd_led_set(struct led_classdev *led_cdev,
  242. enum led_brightness value)
  243. {
  244. struct eeepc_wmi *eeepc;
  245. eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led);
  246. eeepc->tpd_led_wk = !!value;
  247. queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work);
  248. }
  249. static int read_tpd_state(struct eeepc_wmi *eeepc)
  250. {
  251. return eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_TPDLED);
  252. }
  253. static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
  254. {
  255. struct eeepc_wmi *eeepc;
  256. eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led);
  257. return read_tpd_state(eeepc);
  258. }
  259. static int eeepc_wmi_led_init(struct eeepc_wmi *eeepc)
  260. {
  261. int rv;
  262. if (read_tpd_state(eeepc) < 0)
  263. return 0;
  264. eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue");
  265. if (!eeepc->led_workqueue)
  266. return -ENOMEM;
  267. INIT_WORK(&eeepc->tpd_led_work, tpd_led_update);
  268. eeepc->tpd_led.name = "eeepc::touchpad";
  269. eeepc->tpd_led.brightness_set = tpd_led_set;
  270. eeepc->tpd_led.brightness_get = tpd_led_get;
  271. eeepc->tpd_led.max_brightness = 1;
  272. rv = led_classdev_register(&eeepc->platform_device->dev,
  273. &eeepc->tpd_led);
  274. if (rv) {
  275. destroy_workqueue(eeepc->led_workqueue);
  276. return rv;
  277. }
  278. return 0;
  279. }
  280. static void eeepc_wmi_led_exit(struct eeepc_wmi *eeepc)
  281. {
  282. if (eeepc->tpd_led.dev)
  283. led_classdev_unregister(&eeepc->tpd_led);
  284. if (eeepc->led_workqueue)
  285. destroy_workqueue(eeepc->led_workqueue);
  286. }
  287. /*
  288. * PCI hotplug (for wlan rfkill)
  289. */
  290. static bool eeepc_wlan_rfkill_blocked(struct eeepc_wmi *eeepc)
  291. {
  292. int result = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
  293. if (result < 0)
  294. return false;
  295. return !result;
  296. }
  297. static void eeepc_rfkill_hotplug(struct eeepc_wmi *eeepc)
  298. {
  299. struct pci_dev *dev;
  300. struct pci_bus *bus;
  301. bool blocked;
  302. bool absent;
  303. u32 l;
  304. mutex_lock(&eeepc->wmi_lock);
  305. blocked = eeepc_wlan_rfkill_blocked(eeepc);
  306. mutex_unlock(&eeepc->wmi_lock);
  307. mutex_lock(&eeepc->hotplug_lock);
  308. if (eeepc->wlan_rfkill)
  309. rfkill_set_sw_state(eeepc->wlan_rfkill, blocked);
  310. if (eeepc->hotplug_slot) {
  311. bus = pci_find_bus(0, 1);
  312. if (!bus) {
  313. pr_warning("Unable to find PCI bus 1?\n");
  314. goto out_unlock;
  315. }
  316. if (pci_bus_read_config_dword(bus, 0, PCI_VENDOR_ID, &l)) {
  317. pr_err("Unable to read PCI config space?\n");
  318. goto out_unlock;
  319. }
  320. absent = (l == 0xffffffff);
  321. if (blocked != absent) {
  322. pr_warning("BIOS says wireless lan is %s, "
  323. "but the pci device is %s\n",
  324. blocked ? "blocked" : "unblocked",
  325. absent ? "absent" : "present");
  326. pr_warning("skipped wireless hotplug as probably "
  327. "inappropriate for this model\n");
  328. goto out_unlock;
  329. }
  330. if (!blocked) {
  331. dev = pci_get_slot(bus, 0);
  332. if (dev) {
  333. /* Device already present */
  334. pci_dev_put(dev);
  335. goto out_unlock;
  336. }
  337. dev = pci_scan_single_device(bus, 0);
  338. if (dev) {
  339. pci_bus_assign_resources(bus);
  340. if (pci_bus_add_device(dev))
  341. pr_err("Unable to hotplug wifi\n");
  342. }
  343. } else {
  344. dev = pci_get_slot(bus, 0);
  345. if (dev) {
  346. pci_remove_bus_device(dev);
  347. pci_dev_put(dev);
  348. }
  349. }
  350. }
  351. out_unlock:
  352. mutex_unlock(&eeepc->hotplug_lock);
  353. }
  354. static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
  355. {
  356. struct eeepc_wmi *eeepc = data;
  357. if (event != ACPI_NOTIFY_BUS_CHECK)
  358. return;
  359. /*
  360. * We can't call directly eeepc_rfkill_hotplug because most
  361. * of the time WMBC is still being executed and not reetrant.
  362. * There is currently no way to tell ACPICA that we want this
  363. * method to be serialized, we schedule a eeepc_rfkill_hotplug
  364. * call later, in a safer context.
  365. */
  366. queue_work(eeepc->hotplug_workqueue, &eeepc->hotplug_work);
  367. }
  368. static int eeepc_register_rfkill_notifier(struct eeepc_wmi *eeepc,
  369. char *node)
  370. {
  371. acpi_status status;
  372. acpi_handle handle;
  373. status = acpi_get_handle(NULL, node, &handle);
  374. if (ACPI_SUCCESS(status)) {
  375. status = acpi_install_notify_handler(handle,
  376. ACPI_SYSTEM_NOTIFY,
  377. eeepc_rfkill_notify,
  378. eeepc);
  379. if (ACPI_FAILURE(status))
  380. pr_warning("Failed to register notify on %s\n", node);
  381. } else
  382. return -ENODEV;
  383. return 0;
  384. }
  385. static void eeepc_unregister_rfkill_notifier(struct eeepc_wmi *eeepc,
  386. char *node)
  387. {
  388. acpi_status status = AE_OK;
  389. acpi_handle handle;
  390. status = acpi_get_handle(NULL, node, &handle);
  391. if (ACPI_SUCCESS(status)) {
  392. status = acpi_remove_notify_handler(handle,
  393. ACPI_SYSTEM_NOTIFY,
  394. eeepc_rfkill_notify);
  395. if (ACPI_FAILURE(status))
  396. pr_err("Error removing rfkill notify handler %s\n",
  397. node);
  398. }
  399. }
  400. static int eeepc_get_adapter_status(struct hotplug_slot *hotplug_slot,
  401. u8 *value)
  402. {
  403. int result = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
  404. if (result < 0)
  405. return result;
  406. *value = !!result;
  407. return 0;
  408. }
  409. static void eeepc_cleanup_pci_hotplug(struct hotplug_slot *hotplug_slot)
  410. {
  411. kfree(hotplug_slot->info);
  412. kfree(hotplug_slot);
  413. }
  414. static struct hotplug_slot_ops eeepc_hotplug_slot_ops = {
  415. .owner = THIS_MODULE,
  416. .get_adapter_status = eeepc_get_adapter_status,
  417. .get_power_status = eeepc_get_adapter_status,
  418. };
  419. static void eeepc_hotplug_work(struct work_struct *work)
  420. {
  421. struct eeepc_wmi *eeepc;
  422. eeepc = container_of(work, struct eeepc_wmi, hotplug_work);
  423. eeepc_rfkill_hotplug(eeepc);
  424. }
  425. static int eeepc_setup_pci_hotplug(struct eeepc_wmi *eeepc)
  426. {
  427. int ret = -ENOMEM;
  428. struct pci_bus *bus = pci_find_bus(0, 1);
  429. if (!bus) {
  430. pr_err("Unable to find wifi PCI bus\n");
  431. return -ENODEV;
  432. }
  433. eeepc->hotplug_workqueue =
  434. create_singlethread_workqueue("hotplug_workqueue");
  435. if (!eeepc->hotplug_workqueue)
  436. goto error_workqueue;
  437. INIT_WORK(&eeepc->hotplug_work, eeepc_hotplug_work);
  438. eeepc->hotplug_slot = kzalloc(sizeof(struct hotplug_slot), GFP_KERNEL);
  439. if (!eeepc->hotplug_slot)
  440. goto error_slot;
  441. eeepc->hotplug_slot->info = kzalloc(sizeof(struct hotplug_slot_info),
  442. GFP_KERNEL);
  443. if (!eeepc->hotplug_slot->info)
  444. goto error_info;
  445. eeepc->hotplug_slot->private = eeepc;
  446. eeepc->hotplug_slot->release = &eeepc_cleanup_pci_hotplug;
  447. eeepc->hotplug_slot->ops = &eeepc_hotplug_slot_ops;
  448. eeepc_get_adapter_status(eeepc->hotplug_slot,
  449. &eeepc->hotplug_slot->info->adapter_status);
  450. ret = pci_hp_register(eeepc->hotplug_slot, bus, 0, "eeepc-wifi");
  451. if (ret) {
  452. pr_err("Unable to register hotplug slot - %d\n", ret);
  453. goto error_register;
  454. }
  455. return 0;
  456. error_register:
  457. kfree(eeepc->hotplug_slot->info);
  458. error_info:
  459. kfree(eeepc->hotplug_slot);
  460. eeepc->hotplug_slot = NULL;
  461. error_slot:
  462. destroy_workqueue(eeepc->hotplug_workqueue);
  463. error_workqueue:
  464. return ret;
  465. }
  466. /*
  467. * Rfkill devices
  468. */
  469. static int eeepc_rfkill_set(void *data, bool blocked)
  470. {
  471. int dev_id = (unsigned long)data;
  472. u32 ctrl_param = !blocked;
  473. acpi_status status;
  474. status = eeepc_wmi_set_devstate(dev_id, ctrl_param, NULL);
  475. if (ACPI_FAILURE(status))
  476. return -EIO;
  477. return 0;
  478. }
  479. static void eeepc_rfkill_query(struct rfkill *rfkill, void *data)
  480. {
  481. int dev_id = (unsigned long)data;
  482. int result;
  483. result = eeepc_wmi_get_devstate_simple(dev_id);
  484. if (result < 0)
  485. return ;
  486. rfkill_set_sw_state(rfkill, !result);
  487. }
  488. static int eeepc_rfkill_wlan_set(void *data, bool blocked)
  489. {
  490. struct eeepc_wmi *eeepc = data;
  491. int ret;
  492. /*
  493. * This handler is enabled only if hotplug is enabled.
  494. * In this case, the eeepc_wmi_set_devstate() will
  495. * trigger a wmi notification and we need to wait
  496. * this call to finish before being able to call
  497. * any wmi method
  498. */
  499. mutex_lock(&eeepc->wmi_lock);
  500. ret = eeepc_rfkill_set((void *)(long)EEEPC_WMI_DEVID_WLAN, blocked);
  501. mutex_unlock(&eeepc->wmi_lock);
  502. return ret;
  503. }
  504. static void eeepc_rfkill_wlan_query(struct rfkill *rfkill, void *data)
  505. {
  506. eeepc_rfkill_query(rfkill, (void *)(long)EEEPC_WMI_DEVID_WLAN);
  507. }
  508. static const struct rfkill_ops eeepc_rfkill_wlan_ops = {
  509. .set_block = eeepc_rfkill_wlan_set,
  510. .query = eeepc_rfkill_wlan_query,
  511. };
  512. static const struct rfkill_ops eeepc_rfkill_ops = {
  513. .set_block = eeepc_rfkill_set,
  514. .query = eeepc_rfkill_query,
  515. };
  516. static int eeepc_new_rfkill(struct eeepc_wmi *eeepc,
  517. struct rfkill **rfkill,
  518. const char *name,
  519. enum rfkill_type type, int dev_id)
  520. {
  521. int result = eeepc_wmi_get_devstate_simple(dev_id);
  522. if (result < 0)
  523. return result;
  524. if (dev_id == EEEPC_WMI_DEVID_WLAN && eeepc->hotplug_wireless)
  525. *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
  526. &eeepc_rfkill_wlan_ops, eeepc);
  527. else
  528. *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type,
  529. &eeepc_rfkill_ops, (void *)(long)dev_id);
  530. if (!*rfkill)
  531. return -EINVAL;
  532. rfkill_init_sw_state(*rfkill, !result);
  533. result = rfkill_register(*rfkill);
  534. if (result) {
  535. rfkill_destroy(*rfkill);
  536. *rfkill = NULL;
  537. return result;
  538. }
  539. return 0;
  540. }
  541. static void eeepc_wmi_rfkill_exit(struct eeepc_wmi *eeepc)
  542. {
  543. eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
  544. eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
  545. eeepc_unregister_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
  546. if (eeepc->wlan_rfkill) {
  547. rfkill_unregister(eeepc->wlan_rfkill);
  548. rfkill_destroy(eeepc->wlan_rfkill);
  549. eeepc->wlan_rfkill = NULL;
  550. }
  551. /*
  552. * Refresh pci hotplug in case the rfkill state was changed after
  553. * eeepc_unregister_rfkill_notifier()
  554. */
  555. eeepc_rfkill_hotplug(eeepc);
  556. if (eeepc->hotplug_slot)
  557. pci_hp_deregister(eeepc->hotplug_slot);
  558. if (eeepc->hotplug_workqueue)
  559. destroy_workqueue(eeepc->hotplug_workqueue);
  560. if (eeepc->bluetooth_rfkill) {
  561. rfkill_unregister(eeepc->bluetooth_rfkill);
  562. rfkill_destroy(eeepc->bluetooth_rfkill);
  563. eeepc->bluetooth_rfkill = NULL;
  564. }
  565. if (eeepc->wwan3g_rfkill) {
  566. rfkill_unregister(eeepc->wwan3g_rfkill);
  567. rfkill_destroy(eeepc->wwan3g_rfkill);
  568. eeepc->wwan3g_rfkill = NULL;
  569. }
  570. }
  571. static int eeepc_wmi_rfkill_init(struct eeepc_wmi *eeepc)
  572. {
  573. int result = 0;
  574. mutex_init(&eeepc->hotplug_lock);
  575. mutex_init(&eeepc->wmi_lock);
  576. result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill,
  577. "eeepc-wlan", RFKILL_TYPE_WLAN,
  578. EEEPC_WMI_DEVID_WLAN);
  579. if (result && result != -ENODEV)
  580. goto exit;
  581. result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill,
  582. "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH,
  583. EEEPC_WMI_DEVID_BLUETOOTH);
  584. if (result && result != -ENODEV)
  585. goto exit;
  586. result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill,
  587. "eeepc-wwan3g", RFKILL_TYPE_WWAN,
  588. EEEPC_WMI_DEVID_WWAN3G);
  589. if (result && result != -ENODEV)
  590. goto exit;
  591. result = eeepc_setup_pci_hotplug(eeepc);
  592. /*
  593. * If we get -EBUSY then something else is handling the PCI hotplug -
  594. * don't fail in this case
  595. */
  596. if (result == -EBUSY)
  597. result = 0;
  598. eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P5");
  599. eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P6");
  600. eeepc_register_rfkill_notifier(eeepc, "\\_SB.PCI0.P0P7");
  601. /*
  602. * Refresh pci hotplug in case the rfkill state was changed during
  603. * setup.
  604. */
  605. eeepc_rfkill_hotplug(eeepc);
  606. exit:
  607. if (result && result != -ENODEV)
  608. eeepc_wmi_rfkill_exit(eeepc);
  609. if (result == -ENODEV)
  610. result = 0;
  611. return result;
  612. }
  613. /*
  614. * Backlight
  615. */
  616. static int read_brightness(struct backlight_device *bd)
  617. {
  618. u32 retval;
  619. acpi_status status;
  620. status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_BACKLIGHT, &retval);
  621. if (ACPI_FAILURE(status))
  622. return -1;
  623. else
  624. return retval & 0xFF;
  625. }
  626. static int update_bl_status(struct backlight_device *bd)
  627. {
  628. u32 ctrl_param;
  629. acpi_status status;
  630. ctrl_param = bd->props.brightness;
  631. status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BACKLIGHT,
  632. ctrl_param, NULL);
  633. if (ACPI_FAILURE(status))
  634. return -1;
  635. else
  636. return 0;
  637. }
  638. static const struct backlight_ops eeepc_wmi_bl_ops = {
  639. .get_brightness = read_brightness,
  640. .update_status = update_bl_status,
  641. };
  642. static int eeepc_wmi_backlight_notify(struct eeepc_wmi *eeepc, int code)
  643. {
  644. struct backlight_device *bd = eeepc->backlight_device;
  645. int old = bd->props.brightness;
  646. int new = old;
  647. if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
  648. new = code - NOTIFY_BRNUP_MIN + 1;
  649. else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
  650. new = code - NOTIFY_BRNDOWN_MIN;
  651. bd->props.brightness = new;
  652. backlight_update_status(bd);
  653. backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
  654. return old;
  655. }
  656. static int eeepc_wmi_backlight_init(struct eeepc_wmi *eeepc)
  657. {
  658. struct backlight_device *bd;
  659. struct backlight_properties props;
  660. memset(&props, 0, sizeof(struct backlight_properties));
  661. props.max_brightness = 15;
  662. bd = backlight_device_register(EEEPC_WMI_FILE,
  663. &eeepc->platform_device->dev, eeepc,
  664. &eeepc_wmi_bl_ops, &props);
  665. if (IS_ERR(bd)) {
  666. pr_err("Could not register backlight device\n");
  667. return PTR_ERR(bd);
  668. }
  669. eeepc->backlight_device = bd;
  670. bd->props.brightness = read_brightness(bd);
  671. bd->props.power = FB_BLANK_UNBLANK;
  672. backlight_update_status(bd);
  673. return 0;
  674. }
  675. static void eeepc_wmi_backlight_exit(struct eeepc_wmi *eeepc)
  676. {
  677. if (eeepc->backlight_device)
  678. backlight_device_unregister(eeepc->backlight_device);
  679. eeepc->backlight_device = NULL;
  680. }
  681. static void eeepc_wmi_notify(u32 value, void *context)
  682. {
  683. struct eeepc_wmi *eeepc = context;
  684. struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
  685. union acpi_object *obj;
  686. acpi_status status;
  687. int code;
  688. int orig_code;
  689. status = wmi_get_event_data(value, &response);
  690. if (status != AE_OK) {
  691. pr_err("bad event status 0x%x\n", status);
  692. return;
  693. }
  694. obj = (union acpi_object *)response.pointer;
  695. if (obj && obj->type == ACPI_TYPE_INTEGER) {
  696. code = obj->integer.value;
  697. orig_code = code;
  698. if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
  699. code = NOTIFY_BRNUP_MIN;
  700. else if (code >= NOTIFY_BRNDOWN_MIN &&
  701. code <= NOTIFY_BRNDOWN_MAX)
  702. code = NOTIFY_BRNDOWN_MIN;
  703. if (code == NOTIFY_BRNUP_MIN || code == NOTIFY_BRNDOWN_MIN) {
  704. if (!acpi_video_backlight_support())
  705. eeepc_wmi_backlight_notify(eeepc, orig_code);
  706. }
  707. if (!sparse_keymap_report_event(eeepc->inputdev,
  708. code, 1, true))
  709. pr_info("Unknown key %x pressed\n", code);
  710. }
  711. kfree(obj);
  712. }
  713. static ssize_t store_cpufv(struct device *dev, struct device_attribute *attr,
  714. const char *buf, size_t count)
  715. {
  716. int value;
  717. struct acpi_buffer input = { (acpi_size)sizeof(value), &value };
  718. acpi_status status;
  719. if (!count || sscanf(buf, "%i", &value) != 1)
  720. return -EINVAL;
  721. if (value < 0 || value > 2)
  722. return -EINVAL;
  723. status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID,
  724. 1, EEEPC_WMI_METHODID_CFVS, &input, NULL);
  725. if (ACPI_FAILURE(status))
  726. return -EIO;
  727. else
  728. return count;
  729. }
  730. static DEVICE_ATTR(cpufv, S_IRUGO | S_IWUSR, NULL, store_cpufv);
  731. static struct attribute *platform_attributes[] = {
  732. &dev_attr_cpufv.attr,
  733. NULL
  734. };
  735. static struct attribute_group platform_attribute_group = {
  736. .attrs = platform_attributes
  737. };
  738. static void eeepc_wmi_sysfs_exit(struct platform_device *device)
  739. {
  740. sysfs_remove_group(&device->dev.kobj, &platform_attribute_group);
  741. }
  742. static int eeepc_wmi_sysfs_init(struct platform_device *device)
  743. {
  744. return sysfs_create_group(&device->dev.kobj, &platform_attribute_group);
  745. }
  746. /*
  747. * Platform device
  748. */
  749. static int __init eeepc_wmi_platform_init(struct eeepc_wmi *eeepc)
  750. {
  751. return eeepc_wmi_sysfs_init(eeepc->platform_device);
  752. }
  753. static void eeepc_wmi_platform_exit(struct eeepc_wmi *eeepc)
  754. {
  755. eeepc_wmi_sysfs_exit(eeepc->platform_device);
  756. }
  757. /*
  758. * debugfs
  759. */
  760. struct eeepc_wmi_debugfs_node {
  761. struct eeepc_wmi *eeepc;
  762. char *name;
  763. int (*show)(struct seq_file *m, void *data);
  764. };
  765. static int show_dsts(struct seq_file *m, void *data)
  766. {
  767. struct eeepc_wmi *eeepc = m->private;
  768. acpi_status status;
  769. u32 retval = -1;
  770. status = eeepc_wmi_get_devstate(eeepc->debug.dev_id, &retval);
  771. if (ACPI_FAILURE(status))
  772. return -EIO;
  773. seq_printf(m, "DSTS(%x) = %x\n", eeepc->debug.dev_id, retval);
  774. return 0;
  775. }
  776. static int show_devs(struct seq_file *m, void *data)
  777. {
  778. struct eeepc_wmi *eeepc = m->private;
  779. acpi_status status;
  780. u32 retval = -1;
  781. status = eeepc_wmi_set_devstate(eeepc->debug.dev_id,
  782. eeepc->debug.ctrl_param, &retval);
  783. if (ACPI_FAILURE(status))
  784. return -EIO;
  785. seq_printf(m, "DEVS(%x, %x) = %x\n", eeepc->debug.dev_id,
  786. eeepc->debug.ctrl_param, retval);
  787. return 0;
  788. }
  789. static struct eeepc_wmi_debugfs_node eeepc_wmi_debug_files[] = {
  790. { NULL, "devs", show_devs },
  791. { NULL, "dsts", show_dsts },
  792. };
  793. static int eeepc_wmi_debugfs_open(struct inode *inode, struct file *file)
  794. {
  795. struct eeepc_wmi_debugfs_node *node = inode->i_private;
  796. return single_open(file, node->show, node->eeepc);
  797. }
  798. static const struct file_operations eeepc_wmi_debugfs_io_ops = {
  799. .owner = THIS_MODULE,
  800. .open = eeepc_wmi_debugfs_open,
  801. .read = seq_read,
  802. .llseek = seq_lseek,
  803. .release = single_release,
  804. };
  805. static void eeepc_wmi_debugfs_exit(struct eeepc_wmi *eeepc)
  806. {
  807. debugfs_remove_recursive(eeepc->debug.root);
  808. }
  809. static int eeepc_wmi_debugfs_init(struct eeepc_wmi *eeepc)
  810. {
  811. struct dentry *dent;
  812. int i;
  813. eeepc->debug.root = debugfs_create_dir(EEEPC_WMI_FILE, NULL);
  814. if (!eeepc->debug.root) {
  815. pr_err("failed to create debugfs directory");
  816. goto error_debugfs;
  817. }
  818. dent = debugfs_create_x32("dev_id", S_IRUGO|S_IWUSR,
  819. eeepc->debug.root, &eeepc->debug.dev_id);
  820. if (!dent)
  821. goto error_debugfs;
  822. dent = debugfs_create_x32("ctrl_param", S_IRUGO|S_IWUSR,
  823. eeepc->debug.root, &eeepc->debug.ctrl_param);
  824. if (!dent)
  825. goto error_debugfs;
  826. for (i = 0; i < ARRAY_SIZE(eeepc_wmi_debug_files); i++) {
  827. struct eeepc_wmi_debugfs_node *node = &eeepc_wmi_debug_files[i];
  828. node->eeepc = eeepc;
  829. dent = debugfs_create_file(node->name, S_IFREG | S_IRUGO,
  830. eeepc->debug.root, node,
  831. &eeepc_wmi_debugfs_io_ops);
  832. if (!dent) {
  833. pr_err("failed to create debug file: %s\n", node->name);
  834. goto error_debugfs;
  835. }
  836. }
  837. return 0;
  838. error_debugfs:
  839. eeepc_wmi_debugfs_exit(eeepc);
  840. return -ENOMEM;
  841. }
  842. /*
  843. * WMI Driver
  844. */
  845. static void eeepc_dmi_check(struct eeepc_wmi *eeepc)
  846. {
  847. const char *model;
  848. model = dmi_get_system_info(DMI_PRODUCT_NAME);
  849. if (!model)
  850. return;
  851. /*
  852. * Whitelist for wlan hotplug
  853. *
  854. * Eeepc 1000H needs the current hotplug code to handle
  855. * Fn+F2 correctly. We may add other Eeepc here later, but
  856. * it seems that most of the laptops supported by eeepc-wmi
  857. * don't need to be on this list
  858. */
  859. if (strcmp(model, "1000H") == 0) {
  860. eeepc->hotplug_wireless = true;
  861. pr_info("wlan hotplug enabled\n");
  862. }
  863. }
  864. static int __init eeepc_wmi_add(struct platform_device *pdev)
  865. {
  866. struct eeepc_wmi *eeepc;
  867. acpi_status status;
  868. int err;
  869. eeepc = kzalloc(sizeof(struct eeepc_wmi), GFP_KERNEL);
  870. if (!eeepc)
  871. return -ENOMEM;
  872. eeepc->platform_device = pdev;
  873. platform_set_drvdata(eeepc->platform_device, eeepc);
  874. eeepc->hotplug_wireless = hotplug_wireless;
  875. eeepc_dmi_check(eeepc);
  876. err = eeepc_wmi_platform_init(eeepc);
  877. if (err)
  878. goto fail_platform;
  879. err = eeepc_wmi_input_init(eeepc);
  880. if (err)
  881. goto fail_input;
  882. err = eeepc_wmi_led_init(eeepc);
  883. if (err)
  884. goto fail_leds;
  885. err = eeepc_wmi_rfkill_init(eeepc);
  886. if (err)
  887. goto fail_rfkill;
  888. if (!acpi_video_backlight_support()) {
  889. err = eeepc_wmi_backlight_init(eeepc);
  890. if (err)
  891. goto fail_backlight;
  892. } else
  893. pr_info("Backlight controlled by ACPI video driver\n");
  894. status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID,
  895. eeepc_wmi_notify, eeepc);
  896. if (ACPI_FAILURE(status)) {
  897. pr_err("Unable to register notify handler - %d\n",
  898. status);
  899. err = -ENODEV;
  900. goto fail_wmi_handler;
  901. }
  902. err = eeepc_wmi_debugfs_init(eeepc);
  903. if (err)
  904. goto fail_debugfs;
  905. return 0;
  906. fail_debugfs:
  907. wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID);
  908. fail_wmi_handler:
  909. eeepc_wmi_backlight_exit(eeepc);
  910. fail_backlight:
  911. eeepc_wmi_rfkill_exit(eeepc);
  912. fail_rfkill:
  913. eeepc_wmi_led_exit(eeepc);
  914. fail_leds:
  915. eeepc_wmi_input_exit(eeepc);
  916. fail_input:
  917. eeepc_wmi_platform_exit(eeepc);
  918. fail_platform:
  919. kfree(eeepc);
  920. return err;
  921. }
  922. static int __exit eeepc_wmi_remove(struct platform_device *device)
  923. {
  924. struct eeepc_wmi *eeepc;
  925. eeepc = platform_get_drvdata(device);
  926. wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID);
  927. eeepc_wmi_backlight_exit(eeepc);
  928. eeepc_wmi_input_exit(eeepc);
  929. eeepc_wmi_led_exit(eeepc);
  930. eeepc_wmi_rfkill_exit(eeepc);
  931. eeepc_wmi_debugfs_exit(eeepc);
  932. eeepc_wmi_platform_exit(eeepc);
  933. kfree(eeepc);
  934. return 0;
  935. }
  936. /*
  937. * Platform driver - hibernate/resume callbacks
  938. */
  939. static int eeepc_hotk_thaw(struct device *device)
  940. {
  941. struct eeepc_wmi *eeepc = dev_get_drvdata(device);
  942. if (eeepc->wlan_rfkill) {
  943. bool wlan;
  944. /*
  945. * Work around bios bug - acpi _PTS turns off the wireless led
  946. * during suspend. Normally it restores it on resume, but
  947. * we should kick it ourselves in case hibernation is aborted.
  948. */
  949. wlan = eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WLAN);
  950. eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_WLAN, wlan, NULL);
  951. }
  952. return 0;
  953. }
  954. static int eeepc_hotk_restore(struct device *device)
  955. {
  956. struct eeepc_wmi *eeepc = dev_get_drvdata(device);
  957. int bl;
  958. /* Refresh both wlan rfkill state and pci hotplug */
  959. if (eeepc->wlan_rfkill)
  960. eeepc_rfkill_hotplug(eeepc);
  961. if (eeepc->bluetooth_rfkill) {
  962. bl = !eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_BLUETOOTH);
  963. rfkill_set_sw_state(eeepc->bluetooth_rfkill, bl);
  964. }
  965. if (eeepc->wwan3g_rfkill) {
  966. bl = !eeepc_wmi_get_devstate_simple(EEEPC_WMI_DEVID_WWAN3G);
  967. rfkill_set_sw_state(eeepc->wwan3g_rfkill, bl);
  968. }
  969. return 0;
  970. }
  971. static const struct dev_pm_ops eeepc_pm_ops = {
  972. .thaw = eeepc_hotk_thaw,
  973. .restore = eeepc_hotk_restore,
  974. };
  975. static struct platform_driver platform_driver = {
  976. .remove = __exit_p(eeepc_wmi_remove),
  977. .driver = {
  978. .name = EEEPC_WMI_FILE,
  979. .owner = THIS_MODULE,
  980. .pm = &eeepc_pm_ops,
  981. },
  982. };
  983. static acpi_status __init eeepc_wmi_parse_device(acpi_handle handle, u32 level,
  984. void *context, void **retval)
  985. {
  986. pr_warning("Found legacy ATKD device (%s)", EEEPC_ACPI_HID);
  987. *(bool *)context = true;
  988. return AE_CTRL_TERMINATE;
  989. }
  990. static int __init eeepc_wmi_check_atkd(void)
  991. {
  992. acpi_status status;
  993. bool found = false;
  994. status = acpi_get_devices(EEEPC_ACPI_HID, eeepc_wmi_parse_device,
  995. &found, NULL);
  996. if (ACPI_FAILURE(status) || !found)
  997. return 0;
  998. return -1;
  999. }
  1000. static int __init eeepc_wmi_probe(struct platform_device *pdev)
  1001. {
  1002. if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID) ||
  1003. !wmi_has_guid(EEEPC_WMI_MGMT_GUID)) {
  1004. pr_warning("No known WMI GUID found\n");
  1005. return -ENODEV;
  1006. }
  1007. if (eeepc_wmi_check_atkd()) {
  1008. pr_warning("WMI device present, but legacy ATKD device is also "
  1009. "present and enabled.");
  1010. pr_warning("You probably booted with acpi_osi=\"Linux\" or "
  1011. "acpi_osi=\"!Windows 2009\"");
  1012. pr_warning("Can't load eeepc-wmi, use default acpi_osi "
  1013. "(preferred) or eeepc-laptop");
  1014. return -ENODEV;
  1015. }
  1016. return eeepc_wmi_add(pdev);
  1017. }
  1018. static struct platform_device *platform_device;
  1019. static int __init eeepc_wmi_init(void)
  1020. {
  1021. platform_device = platform_create_bundle(&platform_driver,
  1022. eeepc_wmi_probe,
  1023. NULL, 0, NULL, 0);
  1024. if (IS_ERR(platform_device))
  1025. return PTR_ERR(platform_device);
  1026. return 0;
  1027. }
  1028. static void __exit eeepc_wmi_exit(void)
  1029. {
  1030. platform_device_unregister(platform_device);
  1031. platform_driver_unregister(&platform_driver);
  1032. }
  1033. module_init(eeepc_wmi_init);
  1034. module_exit(eeepc_wmi_exit);