hp-wmi.c 17 KB

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