hp-wmi.c 16 KB

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