eeepc-wmi.c 34 KB

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