hp-wmi.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635
  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 <acpi/acpi_drivers.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. enum hp_wmi_radio {
  50. HPWMI_WIFI = 0,
  51. HPWMI_BLUETOOTH = 1,
  52. HPWMI_WWAN = 2,
  53. };
  54. enum hp_wmi_event_ids {
  55. HPWMI_DOCK_EVENT = 1,
  56. HPWMI_BEZEL_BUTTON = 4,
  57. HPWMI_WIRELESS = 5,
  58. };
  59. static int __devinit hp_wmi_bios_setup(struct platform_device *device);
  60. static int __exit hp_wmi_bios_remove(struct platform_device *device);
  61. static int hp_wmi_resume_handler(struct device *device);
  62. struct bios_args {
  63. u32 signature;
  64. u32 command;
  65. u32 commandtype;
  66. u32 datasize;
  67. u32 data;
  68. };
  69. struct bios_return {
  70. u32 sigpass;
  71. u32 return_code;
  72. u32 value;
  73. };
  74. struct key_entry {
  75. char type; /* See KE_* below */
  76. u16 code;
  77. u16 keycode;
  78. };
  79. enum { KE_KEY, KE_END };
  80. static 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, 0x2142, KEY_MEDIA},
  85. {KE_KEY, 0x213b, KEY_INFO},
  86. {KE_KEY, 0x2169, KEY_DIRECTION},
  87. {KE_KEY, 0x231b, KEY_HELP},
  88. {KE_END, 0}
  89. };
  90. static struct input_dev *hp_wmi_input_dev;
  91. static struct platform_device *hp_wmi_platform_dev;
  92. static struct rfkill *wifi_rfkill;
  93. static struct rfkill *bluetooth_rfkill;
  94. static struct rfkill *wwan_rfkill;
  95. static const struct dev_pm_ops hp_wmi_pm_ops = {
  96. .resume = hp_wmi_resume_handler,
  97. .restore = hp_wmi_resume_handler,
  98. };
  99. static struct platform_driver hp_wmi_driver = {
  100. .driver = {
  101. .name = "hp-wmi",
  102. .owner = THIS_MODULE,
  103. .pm = &hp_wmi_pm_ops,
  104. },
  105. .probe = hp_wmi_bios_setup,
  106. .remove = hp_wmi_bios_remove,
  107. };
  108. static int hp_wmi_perform_query(int query, int write, int value)
  109. {
  110. struct bios_return bios_return;
  111. acpi_status status;
  112. union acpi_object *obj;
  113. struct bios_args args = {
  114. .signature = 0x55434553,
  115. .command = write ? 0x2 : 0x1,
  116. .commandtype = query,
  117. .datasize = write ? 0x4 : 0,
  118. .data = value,
  119. };
  120. struct acpi_buffer input = { sizeof(struct bios_args), &args };
  121. struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
  122. status = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output);
  123. obj = output.pointer;
  124. if (!obj)
  125. return -EINVAL;
  126. else if (obj->type != ACPI_TYPE_BUFFER) {
  127. kfree(obj);
  128. return -EINVAL;
  129. }
  130. bios_return = *((struct bios_return *)obj->buffer.pointer);
  131. kfree(obj);
  132. if (bios_return.return_code > 0)
  133. return bios_return.return_code * -1;
  134. else
  135. return bios_return.value;
  136. }
  137. static int hp_wmi_display_state(void)
  138. {
  139. return hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, 0);
  140. }
  141. static int hp_wmi_hddtemp_state(void)
  142. {
  143. return hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, 0);
  144. }
  145. static int hp_wmi_als_state(void)
  146. {
  147. return hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, 0);
  148. }
  149. static int hp_wmi_dock_state(void)
  150. {
  151. int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0);
  152. if (ret < 0)
  153. return ret;
  154. return ret & 0x1;
  155. }
  156. static int hp_wmi_tablet_state(void)
  157. {
  158. int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, 0);
  159. if (ret < 0)
  160. return ret;
  161. return (ret & 0x4) ? 1 : 0;
  162. }
  163. static int hp_wmi_set_block(void *data, bool blocked)
  164. {
  165. enum hp_wmi_radio r = (enum hp_wmi_radio) data;
  166. int query = BIT(r + 8) | ((!blocked) << r);
  167. return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query);
  168. }
  169. static const struct rfkill_ops hp_wmi_rfkill_ops = {
  170. .set_block = hp_wmi_set_block,
  171. };
  172. static bool hp_wmi_get_sw_state(enum hp_wmi_radio r)
  173. {
  174. int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
  175. int mask = 0x200 << (r * 8);
  176. if (wireless & mask)
  177. return false;
  178. else
  179. return true;
  180. }
  181. static bool hp_wmi_get_hw_state(enum hp_wmi_radio r)
  182. {
  183. int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
  184. int mask = 0x800 << (r * 8);
  185. if (wireless & mask)
  186. return false;
  187. else
  188. return true;
  189. }
  190. static ssize_t show_display(struct device *dev, struct device_attribute *attr,
  191. char *buf)
  192. {
  193. int value = hp_wmi_display_state();
  194. if (value < 0)
  195. return -EINVAL;
  196. return sprintf(buf, "%d\n", value);
  197. }
  198. static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr,
  199. char *buf)
  200. {
  201. int value = hp_wmi_hddtemp_state();
  202. if (value < 0)
  203. return -EINVAL;
  204. return sprintf(buf, "%d\n", value);
  205. }
  206. static ssize_t show_als(struct device *dev, struct device_attribute *attr,
  207. char *buf)
  208. {
  209. int value = hp_wmi_als_state();
  210. if (value < 0)
  211. return -EINVAL;
  212. return sprintf(buf, "%d\n", value);
  213. }
  214. static ssize_t show_dock(struct device *dev, struct device_attribute *attr,
  215. char *buf)
  216. {
  217. int value = hp_wmi_dock_state();
  218. if (value < 0)
  219. return -EINVAL;
  220. return sprintf(buf, "%d\n", value);
  221. }
  222. static ssize_t show_tablet(struct device *dev, struct device_attribute *attr,
  223. char *buf)
  224. {
  225. int value = hp_wmi_tablet_state();
  226. if (value < 0)
  227. return -EINVAL;
  228. return sprintf(buf, "%d\n", value);
  229. }
  230. static ssize_t set_als(struct device *dev, struct device_attribute *attr,
  231. const char *buf, size_t count)
  232. {
  233. u32 tmp = simple_strtoul(buf, NULL, 10);
  234. hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, tmp);
  235. return count;
  236. }
  237. static DEVICE_ATTR(display, S_IRUGO, show_display, NULL);
  238. static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL);
  239. static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als);
  240. static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL);
  241. static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL);
  242. static struct key_entry *hp_wmi_get_entry_by_scancode(unsigned int code)
  243. {
  244. struct key_entry *key;
  245. for (key = hp_wmi_keymap; key->type != KE_END; key++)
  246. if (code == key->code)
  247. return key;
  248. return NULL;
  249. }
  250. static struct key_entry *hp_wmi_get_entry_by_keycode(unsigned int keycode)
  251. {
  252. struct key_entry *key;
  253. for (key = hp_wmi_keymap; key->type != KE_END; key++)
  254. if (key->type == KE_KEY && keycode == key->keycode)
  255. return key;
  256. return NULL;
  257. }
  258. static int hp_wmi_getkeycode(struct input_dev *dev,
  259. unsigned int scancode, unsigned int *keycode)
  260. {
  261. struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode);
  262. if (key && key->type == KE_KEY) {
  263. *keycode = key->keycode;
  264. return 0;
  265. }
  266. return -EINVAL;
  267. }
  268. static int hp_wmi_setkeycode(struct input_dev *dev,
  269. unsigned int scancode, unsigned int keycode)
  270. {
  271. struct key_entry *key;
  272. unsigned int old_keycode;
  273. key = hp_wmi_get_entry_by_scancode(scancode);
  274. if (key && key->type == KE_KEY) {
  275. old_keycode = key->keycode;
  276. key->keycode = keycode;
  277. set_bit(keycode, dev->keybit);
  278. if (!hp_wmi_get_entry_by_keycode(old_keycode))
  279. clear_bit(old_keycode, dev->keybit);
  280. return 0;
  281. }
  282. return -EINVAL;
  283. }
  284. static void hp_wmi_notify(u32 value, void *context)
  285. {
  286. struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
  287. static struct key_entry *key;
  288. union acpi_object *obj;
  289. int eventcode, key_code;
  290. acpi_status status;
  291. status = wmi_get_event_data(value, &response);
  292. if (status != AE_OK) {
  293. printk(KERN_INFO "hp-wmi: bad event status 0x%x\n", status);
  294. return;
  295. }
  296. obj = (union acpi_object *)response.pointer;
  297. if (!obj || obj->type != ACPI_TYPE_BUFFER || obj->buffer.length != 8) {
  298. printk(KERN_INFO "HP WMI: Unknown response received\n");
  299. kfree(obj);
  300. return;
  301. }
  302. eventcode = *((u8 *) obj->buffer.pointer);
  303. kfree(obj);
  304. switch (eventcode) {
  305. case HPWMI_DOCK_EVENT:
  306. input_report_switch(hp_wmi_input_dev, SW_DOCK,
  307. hp_wmi_dock_state());
  308. input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
  309. hp_wmi_tablet_state());
  310. input_sync(hp_wmi_input_dev);
  311. break;
  312. case HPWMI_BEZEL_BUTTON:
  313. key_code = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0,
  314. 0);
  315. key = hp_wmi_get_entry_by_scancode(key_code);
  316. if (key) {
  317. switch (key->type) {
  318. case KE_KEY:
  319. input_report_key(hp_wmi_input_dev,
  320. key->keycode, 1);
  321. input_sync(hp_wmi_input_dev);
  322. input_report_key(hp_wmi_input_dev,
  323. key->keycode, 0);
  324. input_sync(hp_wmi_input_dev);
  325. break;
  326. }
  327. } else
  328. printk(KERN_INFO "HP WMI: Unknown key code - 0x%x\n",
  329. key_code);
  330. break;
  331. case HPWMI_WIRELESS:
  332. if (wifi_rfkill)
  333. rfkill_set_states(wifi_rfkill,
  334. hp_wmi_get_sw_state(HPWMI_WIFI),
  335. hp_wmi_get_hw_state(HPWMI_WIFI));
  336. if (bluetooth_rfkill)
  337. rfkill_set_states(bluetooth_rfkill,
  338. hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
  339. hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
  340. if (wwan_rfkill)
  341. rfkill_set_states(wwan_rfkill,
  342. hp_wmi_get_sw_state(HPWMI_WWAN),
  343. hp_wmi_get_hw_state(HPWMI_WWAN));
  344. break;
  345. default:
  346. printk(KERN_INFO "HP WMI: Unknown eventcode - %d\n",
  347. eventcode);
  348. break;
  349. }
  350. }
  351. static int __init hp_wmi_input_setup(void)
  352. {
  353. struct key_entry *key;
  354. int err;
  355. hp_wmi_input_dev = input_allocate_device();
  356. hp_wmi_input_dev->name = "HP WMI hotkeys";
  357. hp_wmi_input_dev->phys = "wmi/input0";
  358. hp_wmi_input_dev->id.bustype = BUS_HOST;
  359. hp_wmi_input_dev->getkeycode = hp_wmi_getkeycode;
  360. hp_wmi_input_dev->setkeycode = hp_wmi_setkeycode;
  361. for (key = hp_wmi_keymap; key->type != KE_END; key++) {
  362. switch (key->type) {
  363. case KE_KEY:
  364. set_bit(EV_KEY, hp_wmi_input_dev->evbit);
  365. set_bit(key->keycode, hp_wmi_input_dev->keybit);
  366. break;
  367. }
  368. }
  369. set_bit(EV_SW, hp_wmi_input_dev->evbit);
  370. set_bit(SW_DOCK, hp_wmi_input_dev->swbit);
  371. set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit);
  372. /* Set initial hardware state */
  373. input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state());
  374. input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
  375. hp_wmi_tablet_state());
  376. input_sync(hp_wmi_input_dev);
  377. err = input_register_device(hp_wmi_input_dev);
  378. if (err) {
  379. input_free_device(hp_wmi_input_dev);
  380. return err;
  381. }
  382. return 0;
  383. }
  384. static void cleanup_sysfs(struct platform_device *device)
  385. {
  386. device_remove_file(&device->dev, &dev_attr_display);
  387. device_remove_file(&device->dev, &dev_attr_hddtemp);
  388. device_remove_file(&device->dev, &dev_attr_als);
  389. device_remove_file(&device->dev, &dev_attr_dock);
  390. device_remove_file(&device->dev, &dev_attr_tablet);
  391. }
  392. static int __devinit hp_wmi_bios_setup(struct platform_device *device)
  393. {
  394. int err;
  395. int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0);
  396. err = device_create_file(&device->dev, &dev_attr_display);
  397. if (err)
  398. goto add_sysfs_error;
  399. err = device_create_file(&device->dev, &dev_attr_hddtemp);
  400. if (err)
  401. goto add_sysfs_error;
  402. err = device_create_file(&device->dev, &dev_attr_als);
  403. if (err)
  404. goto add_sysfs_error;
  405. err = device_create_file(&device->dev, &dev_attr_dock);
  406. if (err)
  407. goto add_sysfs_error;
  408. err = device_create_file(&device->dev, &dev_attr_tablet);
  409. if (err)
  410. goto add_sysfs_error;
  411. if (wireless & 0x1) {
  412. wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev,
  413. RFKILL_TYPE_WLAN,
  414. &hp_wmi_rfkill_ops,
  415. (void *) HPWMI_WIFI);
  416. rfkill_init_sw_state(wifi_rfkill,
  417. hp_wmi_get_sw_state(HPWMI_WIFI));
  418. rfkill_set_hw_state(wifi_rfkill,
  419. hp_wmi_get_hw_state(HPWMI_WIFI));
  420. err = rfkill_register(wifi_rfkill);
  421. if (err)
  422. goto register_wifi_error;
  423. }
  424. if (wireless & 0x2) {
  425. bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev,
  426. RFKILL_TYPE_BLUETOOTH,
  427. &hp_wmi_rfkill_ops,
  428. (void *) HPWMI_BLUETOOTH);
  429. rfkill_init_sw_state(bluetooth_rfkill,
  430. hp_wmi_get_sw_state(HPWMI_BLUETOOTH));
  431. rfkill_set_hw_state(bluetooth_rfkill,
  432. hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
  433. err = rfkill_register(bluetooth_rfkill);
  434. if (err)
  435. goto register_bluetooth_error;
  436. }
  437. if (wireless & 0x4) {
  438. wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev,
  439. RFKILL_TYPE_WWAN,
  440. &hp_wmi_rfkill_ops,
  441. (void *) HPWMI_WWAN);
  442. rfkill_init_sw_state(wwan_rfkill,
  443. hp_wmi_get_sw_state(HPWMI_WWAN));
  444. rfkill_set_hw_state(wwan_rfkill,
  445. hp_wmi_get_hw_state(HPWMI_WWAN));
  446. err = rfkill_register(wwan_rfkill);
  447. if (err)
  448. goto register_wwan_err;
  449. }
  450. return 0;
  451. register_wwan_err:
  452. rfkill_destroy(wwan_rfkill);
  453. if (bluetooth_rfkill)
  454. rfkill_unregister(bluetooth_rfkill);
  455. register_bluetooth_error:
  456. rfkill_destroy(bluetooth_rfkill);
  457. if (wifi_rfkill)
  458. rfkill_unregister(wifi_rfkill);
  459. register_wifi_error:
  460. rfkill_destroy(wifi_rfkill);
  461. add_sysfs_error:
  462. cleanup_sysfs(device);
  463. return err;
  464. }
  465. static int __exit hp_wmi_bios_remove(struct platform_device *device)
  466. {
  467. cleanup_sysfs(device);
  468. if (wifi_rfkill) {
  469. rfkill_unregister(wifi_rfkill);
  470. rfkill_destroy(wifi_rfkill);
  471. }
  472. if (bluetooth_rfkill) {
  473. rfkill_unregister(bluetooth_rfkill);
  474. rfkill_destroy(bluetooth_rfkill);
  475. }
  476. if (wwan_rfkill) {
  477. rfkill_unregister(wwan_rfkill);
  478. rfkill_destroy(wwan_rfkill);
  479. }
  480. return 0;
  481. }
  482. static int hp_wmi_resume_handler(struct device *device)
  483. {
  484. /*
  485. * Hardware state may have changed while suspended, so trigger
  486. * input events for the current state. As this is a switch,
  487. * the input layer will only actually pass it on if the state
  488. * changed.
  489. */
  490. if (hp_wmi_input_dev) {
  491. input_report_switch(hp_wmi_input_dev, SW_DOCK,
  492. hp_wmi_dock_state());
  493. input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE,
  494. hp_wmi_tablet_state());
  495. input_sync(hp_wmi_input_dev);
  496. }
  497. if (wifi_rfkill)
  498. rfkill_set_states(wifi_rfkill,
  499. hp_wmi_get_sw_state(HPWMI_WIFI),
  500. hp_wmi_get_hw_state(HPWMI_WIFI));
  501. if (bluetooth_rfkill)
  502. rfkill_set_states(bluetooth_rfkill,
  503. hp_wmi_get_sw_state(HPWMI_BLUETOOTH),
  504. hp_wmi_get_hw_state(HPWMI_BLUETOOTH));
  505. if (wwan_rfkill)
  506. rfkill_set_states(wwan_rfkill,
  507. hp_wmi_get_sw_state(HPWMI_WWAN),
  508. hp_wmi_get_hw_state(HPWMI_WWAN));
  509. return 0;
  510. }
  511. static int __init hp_wmi_init(void)
  512. {
  513. int err;
  514. if (wmi_has_guid(HPWMI_EVENT_GUID)) {
  515. err = wmi_install_notify_handler(HPWMI_EVENT_GUID,
  516. hp_wmi_notify, NULL);
  517. if (ACPI_SUCCESS(err))
  518. hp_wmi_input_setup();
  519. }
  520. if (wmi_has_guid(HPWMI_BIOS_GUID)) {
  521. err = platform_driver_register(&hp_wmi_driver);
  522. if (err)
  523. return 0;
  524. hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1);
  525. if (!hp_wmi_platform_dev) {
  526. platform_driver_unregister(&hp_wmi_driver);
  527. return 0;
  528. }
  529. platform_device_add(hp_wmi_platform_dev);
  530. }
  531. return 0;
  532. }
  533. static void __exit hp_wmi_exit(void)
  534. {
  535. if (wmi_has_guid(HPWMI_EVENT_GUID)) {
  536. wmi_remove_notify_handler(HPWMI_EVENT_GUID);
  537. input_unregister_device(hp_wmi_input_dev);
  538. }
  539. if (hp_wmi_platform_dev) {
  540. platform_device_del(hp_wmi_platform_dev);
  541. platform_driver_unregister(&hp_wmi_driver);
  542. }
  543. }
  544. module_init(hp_wmi_init);
  545. module_exit(hp_wmi_exit);