hp-wmi.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695
  1. /*
  2. * HP WMI hotkeys
  3. *
  4. * Copyright (C) 2008 Red Hat <mjg@redhat.com>
  5. *
  6. * Portions based on wistron_btns.c:
  7. * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz>
  8. * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org>
  9. * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru>
  10. *
  11. * This program is free software; you can redistribute it and/or modify
  12. * it under the terms of the GNU General Public License as published by
  13. * the Free Software Foundation; either version 2 of the License, or
  14. * (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  24. */
  25. #include <linux/kernel.h>
  26. #include <linux/module.h>
  27. #include <linux/init.h>
  28. #include <linux/slab.h>
  29. #include <linux/types.h>
  30. #include <linux/input.h>
  31. #include <linux/input/sparse-keymap.h>
  32. #include <linux/platform_device.h>
  33. #include <linux/acpi.h>
  34. #include <linux/rfkill.h>
  35. #include <linux/string.h>
  36. MODULE_AUTHOR("Matthew Garrett <mjg59@srcf.ucam.org>");
  37. MODULE_DESCRIPTION("HP laptop WMI hotkeys driver");
  38. MODULE_LICENSE("GPL");
  39. MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C");
  40. MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4");
  41. #define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C"
  42. #define HPWMI_BIOS_GUID "5FB7F034-2C63-45e9-BE91-3D44E2C707E4"
  43. #define HPWMI_DISPLAY_QUERY 0x1
  44. #define HPWMI_HDDTEMP_QUERY 0x2
  45. #define HPWMI_ALS_QUERY 0x3
  46. #define HPWMI_HARDWARE_QUERY 0x4
  47. #define HPWMI_WIRELESS_QUERY 0x5
  48. #define HPWMI_HOTKEY_QUERY 0xc
  49. #define PREFIX "HP WMI: "
  50. #define UNIMP "Unimplemented "
  51. enum hp_wmi_radio {
  52. HPWMI_WIFI = 0,
  53. HPWMI_BLUETOOTH = 1,
  54. HPWMI_WWAN = 2,
  55. };
  56. enum hp_wmi_event_ids {
  57. HPWMI_DOCK_EVENT = 1,
  58. HPWMI_PARK_HDD = 2,
  59. HPWMI_SMART_ADAPTER = 3,
  60. HPWMI_BEZEL_BUTTON = 4,
  61. HPWMI_WIRELESS = 5,
  62. HPWMI_CPU_BATTERY_THROTTLE = 6,
  63. HPWMI_LOCK_SWITCH = 7,
  64. };
  65. static int __devinit hp_wmi_bios_setup(struct platform_device *device);
  66. static int __exit hp_wmi_bios_remove(struct platform_device *device);
  67. static int hp_wmi_resume_handler(struct device *device);
  68. struct bios_args {
  69. u32 signature;
  70. u32 command;
  71. u32 commandtype;
  72. u32 datasize;
  73. u32 data;
  74. };
  75. struct bios_return {
  76. u32 sigpass;
  77. u32 return_code;
  78. u32 value;
  79. };
  80. static const struct key_entry hp_wmi_keymap[] = {
  81. { KE_KEY, 0x02, { KEY_BRIGHTNESSUP } },
  82. { KE_KEY, 0x03, { KEY_BRIGHTNESSDOWN } },
  83. { KE_KEY, 0x20e6, { KEY_PROG1 } },
  84. { KE_KEY, 0x20e8, { KEY_MEDIA } },
  85. { KE_KEY, 0x2142, { KEY_MEDIA } },
  86. { KE_KEY, 0x213b, { KEY_INFO } },
  87. { KE_KEY, 0x2169, { KEY_DIRECTION } },
  88. { KE_KEY, 0x231b, { KEY_HELP } },
  89. { KE_END, 0 }
  90. };
  91. static struct input_dev *hp_wmi_input_dev;
  92. static struct platform_device *hp_wmi_platform_dev;
  93. static struct rfkill *wifi_rfkill;
  94. static struct rfkill *bluetooth_rfkill;
  95. static struct rfkill *wwan_rfkill;
  96. static const struct dev_pm_ops hp_wmi_pm_ops = {
  97. .resume = hp_wmi_resume_handler,
  98. .restore = hp_wmi_resume_handler,
  99. };
  100. static struct platform_driver hp_wmi_driver = {
  101. .driver = {
  102. .name = "hp-wmi",
  103. .owner = THIS_MODULE,
  104. .pm = &hp_wmi_pm_ops,
  105. },
  106. .probe = hp_wmi_bios_setup,
  107. .remove = hp_wmi_bios_remove,
  108. };
  109. /*
  110. * hp_wmi_perform_query
  111. *
  112. * query: The commandtype -> What should be queried
  113. * write: The command -> 0 read, 1 write, 3 ODM specific
  114. * buffer: Buffer used as input and/or output
  115. * buffersize: Size of buffer
  116. *
  117. * returns zero on success
  118. * an HP WMI query specific error code (which is positive)
  119. * -EINVAL if the query was not successful at all
  120. * -EINVAL if the output buffer size exceeds buffersize
  121. *
  122. * Note: The buffersize must at least be the maximum of the input and output
  123. * size. E.g. Battery info query (0x7) is defined to have 1 byte input
  124. * and 128 byte output. The caller would do:
  125. * buffer = kzalloc(128, GFP_KERNEL);
  126. * ret = hp_wmi_perform_query(0x7, 0, buffer, 128)
  127. */
  128. static int hp_wmi_perform_query(int query, int write, u32 *buffer,
  129. int buffersize)
  130. {
  131. struct bios_return bios_return;
  132. acpi_status status;
  133. union acpi_object *obj;
  134. struct bios_args args = {
  135. .signature = 0x55434553,
  136. .command = write ? 0x2 : 0x1,
  137. .commandtype = query,
  138. .datasize = buffersize,
  139. .data = *buffer,
  140. };
  141. struct acpi_buffer input = { sizeof(struct bios_args), &args };
  142. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  143. status = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output);
  144. obj = output.pointer;
  145. if (!obj)
  146. return -EINVAL;
  147. else if (obj->type != ACPI_TYPE_BUFFER) {
  148. kfree(obj);
  149. return -EINVAL;
  150. }
  151. bios_return = *((struct bios_return *)obj->buffer.pointer);
  152. memcpy(buffer, &bios_return.value, sizeof(bios_return.value));
  153. kfree(obj);
  154. return 0;
  155. }
  156. static int hp_wmi_display_state(void)
  157. {
  158. int state = 0;
  159. int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, &state,
  160. sizeof(state));
  161. if (ret)
  162. return -EINVAL;
  163. return state;
  164. }
  165. static int hp_wmi_hddtemp_state(void)
  166. {
  167. int state = 0;
  168. int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, &state,
  169. sizeof(state));
  170. if (ret)
  171. return -EINVAL;
  172. return state;
  173. }
  174. static int hp_wmi_als_state(void)
  175. {
  176. int state = 0;
  177. int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, &state,
  178. sizeof(state));
  179. if (ret)
  180. return -EINVAL;
  181. return state;
  182. }
  183. static int hp_wmi_dock_state(void)
  184. {
  185. int state = 0;
  186. int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state,
  187. sizeof(state));
  188. if (ret)
  189. return -EINVAL;
  190. return state & 0x1;
  191. }
  192. static int hp_wmi_tablet_state(void)
  193. {
  194. int state = 0;
  195. int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state,
  196. sizeof(state));
  197. if (ret)
  198. return ret;
  199. return (state & 0x4) ? 1 : 0;
  200. }
  201. static int hp_wmi_set_block(void *data, bool blocked)
  202. {
  203. enum hp_wmi_radio r = (enum hp_wmi_radio) data;
  204. int query = BIT(r + 8) | ((!blocked) << r);
  205. int ret;
  206. ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1,
  207. &query, sizeof(query));
  208. if (ret)
  209. return -EINVAL;
  210. return 0;
  211. }
  212. static const struct rfkill_ops hp_wmi_rfkill_ops = {
  213. .set_block = hp_wmi_set_block,
  214. };
  215. static bool hp_wmi_get_sw_state(enum hp_wmi_radio r)
  216. {
  217. int wireless = 0;
  218. int mask;
  219. hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0,
  220. &wireless, sizeof(wireless));
  221. /* TBD: Pass error */
  222. mask = 0x200 << (r * 8);
  223. if (wireless & mask)
  224. return false;
  225. else
  226. return true;
  227. }
  228. static bool hp_wmi_get_hw_state(enum hp_wmi_radio r)
  229. {
  230. int wireless = 0;
  231. int mask;
  232. hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0,
  233. &wireless, sizeof(wireless));
  234. /* TBD: Pass error */
  235. mask = 0x800 << (r * 8);
  236. if (wireless & mask)
  237. return false;
  238. else
  239. return true;
  240. }
  241. static ssize_t show_display(struct device *dev, struct device_attribute *attr,
  242. char *buf)
  243. {
  244. int value = hp_wmi_display_state();
  245. if (value < 0)
  246. return -EINVAL;
  247. return sprintf(buf, "%d\n", value);
  248. }
  249. static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr,
  250. char *buf)
  251. {
  252. int value = hp_wmi_hddtemp_state();
  253. if (value < 0)
  254. return -EINVAL;
  255. return sprintf(buf, "%d\n", value);
  256. }
  257. static ssize_t show_als(struct device *dev, struct device_attribute *attr,
  258. char *buf)
  259. {
  260. int value = hp_wmi_als_state();
  261. if (value < 0)
  262. return -EINVAL;
  263. return sprintf(buf, "%d\n", value);
  264. }
  265. static ssize_t show_dock(struct device *dev, struct device_attribute *attr,
  266. char *buf)
  267. {
  268. int value = hp_wmi_dock_state();
  269. if (value < 0)
  270. return -EINVAL;
  271. return sprintf(buf, "%d\n", value);
  272. }
  273. static ssize_t show_tablet(struct device *dev, struct device_attribute *attr,
  274. char *buf)
  275. {
  276. int value = hp_wmi_tablet_state();
  277. if (value < 0)
  278. return -EINVAL;
  279. return sprintf(buf, "%d\n", value);
  280. }
  281. static ssize_t set_als(struct device *dev, struct device_attribute *attr,
  282. const char *buf, size_t count)
  283. {
  284. u32 tmp = simple_strtoul(buf, NULL, 10);
  285. int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, &tmp,
  286. sizeof(tmp));
  287. if (ret)
  288. return -EINVAL;
  289. return count;
  290. }
  291. static DEVICE_ATTR(display, S_IRUGO, show_display, NULL);
  292. static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL);
  293. static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als);
  294. static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL);
  295. static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL);
  296. static void hp_wmi_notify(u32 value, void *context)
  297. {
  298. struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
  299. union acpi_object *obj;
  300. u32 event_id, event_data;
  301. int key_code = 0, ret;
  302. u32 *location;
  303. acpi_status status;
  304. status = wmi_get_event_data(value, &response);
  305. if (status != AE_OK) {
  306. printk(KERN_INFO PREFIX "bad event status 0x%x\n", status);
  307. return;
  308. }
  309. obj = (union acpi_object *)response.pointer;
  310. if (!obj)
  311. return;
  312. if (obj->type != ACPI_TYPE_BUFFER) {
  313. printk(KERN_INFO "hp-wmi: Unknown response received %d\n",
  314. obj->type);
  315. kfree(obj);
  316. return;
  317. }
  318. /*
  319. * Depending on ACPI version the concatenation of id and event data
  320. * inside _WED function will result in a 8 or 16 byte buffer.
  321. */
  322. location = (u32 *)obj->buffer.pointer;
  323. if (obj->buffer.length == 8) {
  324. event_id = *location;
  325. event_data = *(location + 1);
  326. } else if (obj->buffer.length == 16) {
  327. event_id = *location;
  328. event_data = *(location + 2);
  329. } else {
  330. printk(KERN_INFO "hp-wmi: Unknown buffer length %d\n",
  331. obj->buffer.length);
  332. kfree(obj);
  333. return;
  334. }
  335. kfree(obj);
  336. switch (event_id) {
  337. case HPWMI_DOCK_EVENT:
  338. input_report_switch(hp_wmi_input_dev, SW_DOCK,
  339. hp_wmi_dock_state());
  340. input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
  341. hp_wmi_tablet_state());
  342. input_sync(hp_wmi_input_dev);
  343. break;
  344. case HPWMI_PARK_HDD:
  345. break;
  346. case HPWMI_SMART_ADAPTER:
  347. break;
  348. case HPWMI_BEZEL_BUTTON:
  349. ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0,
  350. &key_code,
  351. sizeof(key_code));
  352. if (ret)
  353. break;
  354. if (!sparse_keymap_report_event(hp_wmi_input_dev,
  355. key_code, 1, true))
  356. printk(KERN_INFO PREFIX "Unknown key code - 0x%x\n",
  357. key_code);
  358. break;
  359. case HPWMI_WIRELESS:
  360. if (wifi_rfkill)
  361. rfkill_set_states(wifi_rfkill,
  362. hp_wmi_get_sw_state(HPWMI_WIFI),
  363. hp_wmi_get_hw_state(HPWMI_WIFI));
  364. if (bluetooth_rfkill)
  365. rfkill_set_states(bluetooth_rfkill,
  366. hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
  367. hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
  368. if (wwan_rfkill)
  369. rfkill_set_states(wwan_rfkill,
  370. hp_wmi_get_sw_state(HPWMI_WWAN),
  371. hp_wmi_get_hw_state(HPWMI_WWAN));
  372. break;
  373. case HPWMI_CPU_BATTERY_THROTTLE:
  374. printk(KERN_INFO PREFIX UNIMP "CPU throttle because of 3 Cell"
  375. " battery event detected\n");
  376. break;
  377. case HPWMI_LOCK_SWITCH:
  378. break;
  379. default:
  380. printk(KERN_INFO PREFIX "Unknown event_id - %d - 0x%x\n",
  381. event_id, event_data);
  382. break;
  383. }
  384. }
  385. static int __init hp_wmi_input_setup(void)
  386. {
  387. acpi_status status;
  388. int err;
  389. hp_wmi_input_dev = input_allocate_device();
  390. if (!hp_wmi_input_dev)
  391. return -ENOMEM;
  392. hp_wmi_input_dev->name = "HP WMI hotkeys";
  393. hp_wmi_input_dev->phys = "wmi/input0";
  394. hp_wmi_input_dev->id.bustype = BUS_HOST;
  395. __set_bit(EV_SW, hp_wmi_input_dev->evbit);
  396. __set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
  397. __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
  398. err = sparse_keymap_setup(hp_wmi_input_dev, hp_wmi_keymap, NULL);
  399. if (err)
  400. goto err_free_dev;
  401. /* Set initial hardware state */
  402. input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state());
  403. input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
  404. hp_wmi_tablet_state());
  405. input_sync(hp_wmi_input_dev);
  406. status = wmi_install_notify_handler(HPWMI_EVENT_GUID, hp_wmi_notify, NULL);
  407. if (ACPI_FAILURE(status)) {
  408. err = -EIO;
  409. goto err_free_keymap;
  410. }
  411. err = input_register_device(hp_wmi_input_dev);
  412. if (err)
  413. goto err_uninstall_notifier;
  414. return 0;
  415. err_uninstall_notifier:
  416. wmi_remove_notify_handler(HPWMI_EVENT_GUID);
  417. err_free_keymap:
  418. sparse_keymap_free(hp_wmi_input_dev);
  419. err_free_dev:
  420. input_free_device(hp_wmi_input_dev);
  421. return err;
  422. }
  423. static void hp_wmi_input_destroy(void)
  424. {
  425. wmi_remove_notify_handler(HPWMI_EVENT_GUID);
  426. sparse_keymap_free(hp_wmi_input_dev);
  427. input_unregister_device(hp_wmi_input_dev);
  428. }
  429. static void cleanup_sysfs(struct platform_device *device)
  430. {
  431. device_remove_file(&device->dev, &dev_attr_display);
  432. device_remove_file(&device->dev, &dev_attr_hddtemp);
  433. device_remove_file(&device->dev, &dev_attr_als);
  434. device_remove_file(&device->dev, &dev_attr_dock);
  435. device_remove_file(&device->dev, &dev_attr_tablet);
  436. }
  437. static int __devinit hp_wmi_bios_setup(struct platform_device *device)
  438. {
  439. int err;
  440. int wireless = 0;
  441. err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, &wireless,
  442. sizeof(wireless));
  443. if (err)
  444. return err;
  445. err = device_create_file(&device->dev, &dev_attr_display);
  446. if (err)
  447. goto add_sysfs_error;
  448. err = device_create_file(&device->dev, &dev_attr_hddtemp);
  449. if (err)
  450. goto add_sysfs_error;
  451. err = device_create_file(&device->dev, &dev_attr_als);
  452. if (err)
  453. goto add_sysfs_error;
  454. err = device_create_file(&device->dev, &dev_attr_dock);
  455. if (err)
  456. goto add_sysfs_error;
  457. err = device_create_file(&device->dev, &dev_attr_tablet);
  458. if (err)
  459. goto add_sysfs_error;
  460. if (wireless & 0x1) {
  461. wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
  462. RFKILL_TYPE_WLAN,
  463. &hp_wmi_rfkill_ops,
  464. (void *) HPWMI_WIFI);
  465. rfkill_init_sw_state(wifi_rfkill,
  466. hp_wmi_get_sw_state(HPWMI_WIFI));
  467. rfkill_set_hw_state(wifi_rfkill,
  468. hp_wmi_get_hw_state(HPWMI_WIFI));
  469. err = rfkill_register(wifi_rfkill);
  470. if (err)
  471. goto register_wifi_error;
  472. }
  473. if (wireless & 0x2) {
  474. bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
  475. RFKILL_TYPE_BLUETOOTH,
  476. &hp_wmi_rfkill_ops,
  477. (void *) HPWMI_BLUETOOTH);
  478. rfkill_init_sw_state(bluetooth_rfkill,
  479. hp_wmi_get_sw_state(HPWMI_BLUETOOTH));
  480. rfkill_set_hw_state(bluetooth_rfkill,
  481. hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
  482. err = rfkill_register(bluetooth_rfkill);
  483. if (err)
  484. goto register_bluetooth_error;
  485. }
  486. if (wireless & 0x4) {
  487. wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
  488. RFKILL_TYPE_WWAN,
  489. &hp_wmi_rfkill_ops,
  490. (void *) HPWMI_WWAN);
  491. rfkill_init_sw_state(wwan_rfkill,
  492. hp_wmi_get_sw_state(HPWMI_WWAN));
  493. rfkill_set_hw_state(wwan_rfkill,
  494. hp_wmi_get_hw_state(HPWMI_WWAN));
  495. err = rfkill_register(wwan_rfkill);
  496. if (err)
  497. goto register_wwan_err;
  498. }
  499. return 0;
  500. register_wwan_err:
  501. rfkill_destroy(wwan_rfkill);
  502. if (bluetooth_rfkill)
  503. rfkill_unregister(bluetooth_rfkill);
  504. register_bluetooth_error:
  505. rfkill_destroy(bluetooth_rfkill);
  506. if (wifi_rfkill)
  507. rfkill_unregister(wifi_rfkill);
  508. register_wifi_error:
  509. rfkill_destroy(wifi_rfkill);
  510. add_sysfs_error:
  511. cleanup_sysfs(device);
  512. return err;
  513. }
  514. static int __exit hp_wmi_bios_remove(struct platform_device *device)
  515. {
  516. cleanup_sysfs(device);
  517. if (wifi_rfkill) {
  518. rfkill_unregister(wifi_rfkill);
  519. rfkill_destroy(wifi_rfkill);
  520. }
  521. if (bluetooth_rfkill) {
  522. rfkill_unregister(bluetooth_rfkill);
  523. rfkill_destroy(bluetooth_rfkill);
  524. }
  525. if (wwan_rfkill) {
  526. rfkill_unregister(wwan_rfkill);
  527. rfkill_destroy(wwan_rfkill);
  528. }
  529. return 0;
  530. }
  531. static int hp_wmi_resume_handler(struct device *device)
  532. {
  533. /*
  534. * Hardware state may have changed while suspended, so trigger
  535. * input events for the current state. As this is a switch,
  536. * the input layer will only actually pass it on if the state
  537. * changed.
  538. */
  539. if (hp_wmi_input_dev) {
  540. input_report_switch(hp_wmi_input_dev, SW_DOCK,
  541. hp_wmi_dock_state());
  542. input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
  543. hp_wmi_tablet_state());
  544. input_sync(hp_wmi_input_dev);
  545. }
  546. if (wifi_rfkill)
  547. rfkill_set_states(wifi_rfkill,
  548. hp_wmi_get_sw_state(HPWMI_WIFI),
  549. hp_wmi_get_hw_state(HPWMI_WIFI));
  550. if (bluetooth_rfkill)
  551. rfkill_set_states(bluetooth_rfkill,
  552. hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
  553. hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
  554. if (wwan_rfkill)
  555. rfkill_set_states(wwan_rfkill,
  556. hp_wmi_get_sw_state(HPWMI_WWAN),
  557. hp_wmi_get_hw_state(HPWMI_WWAN));
  558. return 0;
  559. }
  560. static int __init hp_wmi_init(void)
  561. {
  562. int err;
  563. int event_capable = wmi_has_guid(HPWMI_EVENT_GUID);
  564. int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID);
  565. if (event_capable) {
  566. err = hp_wmi_input_setup();
  567. if (err)
  568. return err;
  569. }
  570. if (bios_capable) {
  571. err = platform_driver_register(&hp_wmi_driver);
  572. if (err)
  573. goto err_driver_reg;
  574. hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1);
  575. if (!hp_wmi_platform_dev) {
  576. err = -ENOMEM;
  577. goto err_device_alloc;
  578. }
  579. err = platform_device_add(hp_wmi_platform_dev);
  580. if (err)
  581. goto err_device_add;
  582. }
  583. if (!bios_capable && !event_capable)
  584. return -ENODEV;
  585. return 0;
  586. err_device_add:
  587. platform_device_put(hp_wmi_platform_dev);
  588. err_device_alloc:
  589. platform_driver_unregister(&hp_wmi_driver);
  590. err_driver_reg:
  591. if (event_capable)
  592. hp_wmi_input_destroy();
  593. return err;
  594. }
  595. static void __exit hp_wmi_exit(void)
  596. {
  597. if (wmi_has_guid(HPWMI_EVENT_GUID))
  598. hp_wmi_input_destroy();
  599. if (hp_wmi_platform_dev) {
  600. platform_device_unregister(hp_wmi_platform_dev);
  601. platform_driver_unregister(&hp_wmi_driver);
  602. }
  603. }
  604. module_init(hp_wmi_init);
  605. module_exit(hp_wmi_exit);