hp-wmi.c 19 KB

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