Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 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 | |
| 26 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/init.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 | |
| 37 | MODULE_AUTHOR("Matthew Garrett <mjg59@srcf.ucam.org>"); |
| 38 | MODULE_DESCRIPTION("HP laptop WMI hotkeys driver"); |
| 39 | MODULE_LICENSE("GPL"); |
| 40 | |
| 41 | MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C"); |
| 42 | MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4"); |
| 43 | |
| 44 | #define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C" |
| 45 | #define HPWMI_BIOS_GUID "5FB7F034-2C63-45e9-BE91-3D44E2C707E4" |
| 46 | |
| 47 | #define HPWMI_DISPLAY_QUERY 0x1 |
| 48 | #define HPWMI_HDDTEMP_QUERY 0x2 |
| 49 | #define HPWMI_ALS_QUERY 0x3 |
| 50 | #define HPWMI_DOCK_QUERY 0x4 |
| 51 | #define HPWMI_WIRELESS_QUERY 0x5 |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 52 | #define HPWMI_HOTKEY_QUERY 0xc |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 53 | |
| 54 | static int __init hp_wmi_bios_setup(struct platform_device *device); |
| 55 | static int __exit hp_wmi_bios_remove(struct platform_device *device); |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 56 | static int hp_wmi_resume_handler(struct platform_device *device); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 57 | |
| 58 | struct bios_args { |
| 59 | u32 signature; |
| 60 | u32 command; |
| 61 | u32 commandtype; |
| 62 | u32 datasize; |
| 63 | u32 data; |
| 64 | }; |
| 65 | |
| 66 | struct bios_return { |
| 67 | u32 sigpass; |
| 68 | u32 return_code; |
| 69 | u32 value; |
| 70 | }; |
| 71 | |
| 72 | struct key_entry { |
| 73 | char type; /* See KE_* below */ |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 74 | u16 code; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 75 | u16 keycode; |
| 76 | }; |
| 77 | |
| 78 | enum { KE_KEY, KE_SW, KE_END }; |
| 79 | |
| 80 | static struct key_entry hp_wmi_keymap[] = { |
| 81 | {KE_SW, 0x01, SW_DOCK}, |
| 82 | {KE_KEY, 0x02, KEY_BRIGHTNESSUP}, |
| 83 | {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN}, |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 84 | {KE_KEY, 0x20e6, KEY_PROG1}, |
| 85 | {KE_KEY, 0x2142, KEY_MEDIA}, |
Eric Piel | 5c62484 | 2008-10-18 20:27:28 -0700 | [diff] [blame] | 86 | {KE_KEY, 0x213b, KEY_INFO}, |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 87 | {KE_KEY, 0x231b, KEY_HELP}, |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 88 | {KE_END, 0} |
| 89 | }; |
| 90 | |
| 91 | static struct input_dev *hp_wmi_input_dev; |
| 92 | static struct platform_device *hp_wmi_platform_dev; |
| 93 | |
| 94 | static struct rfkill *wifi_rfkill; |
| 95 | static struct rfkill *bluetooth_rfkill; |
| 96 | static struct rfkill *wwan_rfkill; |
| 97 | |
| 98 | static struct platform_driver hp_wmi_driver = { |
| 99 | .driver = { |
| 100 | .name = "hp-wmi", |
| 101 | .owner = THIS_MODULE, |
| 102 | }, |
| 103 | .probe = hp_wmi_bios_setup, |
| 104 | .remove = hp_wmi_bios_remove, |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 105 | .resume = hp_wmi_resume_handler, |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 106 | }; |
| 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 | |
| 123 | status = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output); |
| 124 | |
| 125 | obj = output.pointer; |
| 126 | |
| 127 | if (!obj || obj->type != ACPI_TYPE_BUFFER) |
| 128 | return -EINVAL; |
| 129 | |
| 130 | bios_return = *((struct bios_return *)obj->buffer.pointer); |
| 131 | if (bios_return.return_code > 0) |
| 132 | return bios_return.return_code * -1; |
| 133 | else |
| 134 | return bios_return.value; |
| 135 | } |
| 136 | |
| 137 | static int hp_wmi_display_state(void) |
| 138 | { |
| 139 | return hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, 0); |
| 140 | } |
| 141 | |
| 142 | static int hp_wmi_hddtemp_state(void) |
| 143 | { |
| 144 | return hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, 0); |
| 145 | } |
| 146 | |
| 147 | static int hp_wmi_als_state(void) |
| 148 | { |
| 149 | return hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, 0); |
| 150 | } |
| 151 | |
| 152 | static int hp_wmi_dock_state(void) |
| 153 | { |
| 154 | return hp_wmi_perform_query(HPWMI_DOCK_QUERY, 0, 0); |
| 155 | } |
| 156 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 157 | static int hp_wmi_set_block(void *data, bool blocked) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 158 | { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 159 | unsigned long b = (unsigned long) data; |
| 160 | int query = BIT(b + 8) | ((!!blocked) << b); |
| 161 | |
| 162 | return hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, query); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 163 | } |
| 164 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 165 | static const struct rfkill_ops hp_wmi_rfkill_ops = { |
| 166 | .set_block = hp_wmi_set_block, |
| 167 | }; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 168 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 169 | static bool hp_wmi_wifi_state(void) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 170 | { |
| 171 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
| 172 | |
| 173 | if (wireless & 0x100) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 174 | return false; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 175 | else |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 176 | return true; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 177 | } |
| 178 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 179 | static bool hp_wmi_bluetooth_state(void) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 180 | { |
| 181 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
| 182 | |
| 183 | if (wireless & 0x10000) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 184 | return false; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 185 | else |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 186 | return true; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 187 | } |
| 188 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 189 | static bool hp_wmi_wwan_state(void) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 190 | { |
| 191 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
| 192 | |
| 193 | if (wireless & 0x1000000) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 194 | return false; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 195 | else |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 196 | return true; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, |
| 200 | char *buf) |
| 201 | { |
| 202 | int value = hp_wmi_display_state(); |
| 203 | if (value < 0) |
| 204 | return -EINVAL; |
| 205 | return sprintf(buf, "%d\n", value); |
| 206 | } |
| 207 | |
| 208 | static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr, |
| 209 | char *buf) |
| 210 | { |
| 211 | int value = hp_wmi_hddtemp_state(); |
| 212 | if (value < 0) |
| 213 | return -EINVAL; |
| 214 | return sprintf(buf, "%d\n", value); |
| 215 | } |
| 216 | |
| 217 | static ssize_t show_als(struct device *dev, struct device_attribute *attr, |
| 218 | char *buf) |
| 219 | { |
| 220 | int value = hp_wmi_als_state(); |
| 221 | if (value < 0) |
| 222 | return -EINVAL; |
| 223 | return sprintf(buf, "%d\n", value); |
| 224 | } |
| 225 | |
| 226 | static ssize_t show_dock(struct device *dev, struct device_attribute *attr, |
| 227 | char *buf) |
| 228 | { |
| 229 | int value = hp_wmi_dock_state(); |
| 230 | if (value < 0) |
| 231 | return -EINVAL; |
| 232 | return sprintf(buf, "%d\n", value); |
| 233 | } |
| 234 | |
| 235 | static ssize_t set_als(struct device *dev, struct device_attribute *attr, |
| 236 | const char *buf, size_t count) |
| 237 | { |
| 238 | u32 tmp = simple_strtoul(buf, NULL, 10); |
| 239 | hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, tmp); |
| 240 | return count; |
| 241 | } |
| 242 | |
| 243 | static DEVICE_ATTR(display, S_IRUGO, show_display, NULL); |
| 244 | static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL); |
| 245 | static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als); |
| 246 | static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL); |
| 247 | |
| 248 | static struct key_entry *hp_wmi_get_entry_by_scancode(int code) |
| 249 | { |
| 250 | struct key_entry *key; |
| 251 | |
| 252 | for (key = hp_wmi_keymap; key->type != KE_END; key++) |
| 253 | if (code == key->code) |
| 254 | return key; |
| 255 | |
| 256 | return NULL; |
| 257 | } |
| 258 | |
| 259 | static struct key_entry *hp_wmi_get_entry_by_keycode(int keycode) |
| 260 | { |
| 261 | struct key_entry *key; |
| 262 | |
| 263 | for (key = hp_wmi_keymap; key->type != KE_END; key++) |
| 264 | if (key->type == KE_KEY && keycode == key->keycode) |
| 265 | return key; |
| 266 | |
| 267 | return NULL; |
| 268 | } |
| 269 | |
| 270 | static int hp_wmi_getkeycode(struct input_dev *dev, int scancode, int *keycode) |
| 271 | { |
| 272 | struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode); |
| 273 | |
| 274 | if (key && key->type == KE_KEY) { |
| 275 | *keycode = key->keycode; |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | return -EINVAL; |
| 280 | } |
| 281 | |
| 282 | static int hp_wmi_setkeycode(struct input_dev *dev, int scancode, int keycode) |
| 283 | { |
| 284 | struct key_entry *key; |
| 285 | int old_keycode; |
| 286 | |
| 287 | if (keycode < 0 || keycode > KEY_MAX) |
| 288 | return -EINVAL; |
| 289 | |
| 290 | key = hp_wmi_get_entry_by_scancode(scancode); |
| 291 | if (key && key->type == KE_KEY) { |
| 292 | old_keycode = key->keycode; |
| 293 | key->keycode = keycode; |
| 294 | set_bit(keycode, dev->keybit); |
| 295 | if (!hp_wmi_get_entry_by_keycode(old_keycode)) |
| 296 | clear_bit(old_keycode, dev->keybit); |
| 297 | return 0; |
| 298 | } |
| 299 | |
| 300 | return -EINVAL; |
| 301 | } |
| 302 | |
Adrian Bunk | 88429a1 | 2008-10-15 22:05:17 -0700 | [diff] [blame] | 303 | static void hp_wmi_notify(u32 value, void *context) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 304 | { |
| 305 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 306 | static struct key_entry *key; |
| 307 | union acpi_object *obj; |
| 308 | |
| 309 | wmi_get_event_data(value, &response); |
| 310 | |
| 311 | obj = (union acpi_object *)response.pointer; |
| 312 | |
| 313 | if (obj && obj->type == ACPI_TYPE_BUFFER && obj->buffer.length == 8) { |
| 314 | int eventcode = *((u8 *) obj->buffer.pointer); |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 315 | if (eventcode == 0x4) |
| 316 | eventcode = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, |
| 317 | 0); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 318 | key = hp_wmi_get_entry_by_scancode(eventcode); |
| 319 | if (key) { |
| 320 | switch (key->type) { |
| 321 | case KE_KEY: |
| 322 | input_report_key(hp_wmi_input_dev, |
| 323 | key->keycode, 1); |
| 324 | input_sync(hp_wmi_input_dev); |
| 325 | input_report_key(hp_wmi_input_dev, |
| 326 | key->keycode, 0); |
| 327 | input_sync(hp_wmi_input_dev); |
| 328 | break; |
| 329 | case KE_SW: |
| 330 | input_report_switch(hp_wmi_input_dev, |
| 331 | key->keycode, |
| 332 | hp_wmi_dock_state()); |
| 333 | input_sync(hp_wmi_input_dev); |
| 334 | break; |
| 335 | } |
| 336 | } else if (eventcode == 0x5) { |
| 337 | if (wifi_rfkill) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 338 | rfkill_set_sw_state(wifi_rfkill, |
| 339 | hp_wmi_wifi_state()); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 340 | if (bluetooth_rfkill) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 341 | rfkill_set_sw_state(bluetooth_rfkill, |
| 342 | hp_wmi_bluetooth_state()); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 343 | if (wwan_rfkill) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 344 | rfkill_set_sw_state(wwan_rfkill, |
| 345 | hp_wmi_wwan_state()); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 346 | } else |
| 347 | printk(KERN_INFO "HP WMI: Unknown key pressed - %x\n", |
| 348 | eventcode); |
| 349 | } else |
| 350 | printk(KERN_INFO "HP WMI: Unknown response received\n"); |
| 351 | } |
| 352 | |
| 353 | static int __init hp_wmi_input_setup(void) |
| 354 | { |
| 355 | struct key_entry *key; |
| 356 | int err; |
| 357 | |
| 358 | hp_wmi_input_dev = input_allocate_device(); |
| 359 | |
| 360 | hp_wmi_input_dev->name = "HP WMI hotkeys"; |
| 361 | hp_wmi_input_dev->phys = "wmi/input0"; |
| 362 | hp_wmi_input_dev->id.bustype = BUS_HOST; |
| 363 | hp_wmi_input_dev->getkeycode = hp_wmi_getkeycode; |
| 364 | hp_wmi_input_dev->setkeycode = hp_wmi_setkeycode; |
| 365 | |
| 366 | for (key = hp_wmi_keymap; key->type != KE_END; key++) { |
| 367 | switch (key->type) { |
| 368 | case KE_KEY: |
| 369 | set_bit(EV_KEY, hp_wmi_input_dev->evbit); |
| 370 | set_bit(key->keycode, hp_wmi_input_dev->keybit); |
| 371 | break; |
| 372 | case KE_SW: |
| 373 | set_bit(EV_SW, hp_wmi_input_dev->evbit); |
| 374 | set_bit(key->keycode, hp_wmi_input_dev->swbit); |
Frans Pop | 3095eb8 | 2009-01-29 14:25:25 -0800 | [diff] [blame] | 375 | |
| 376 | /* Set initial dock state */ |
| 377 | input_report_switch(hp_wmi_input_dev, key->keycode, |
| 378 | hp_wmi_dock_state()); |
| 379 | input_sync(hp_wmi_input_dev); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 380 | break; |
| 381 | } |
| 382 | } |
| 383 | |
| 384 | err = input_register_device(hp_wmi_input_dev); |
| 385 | |
| 386 | if (err) { |
| 387 | input_free_device(hp_wmi_input_dev); |
| 388 | return err; |
| 389 | } |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | static void cleanup_sysfs(struct platform_device *device) |
| 395 | { |
| 396 | device_remove_file(&device->dev, &dev_attr_display); |
| 397 | device_remove_file(&device->dev, &dev_attr_hddtemp); |
| 398 | device_remove_file(&device->dev, &dev_attr_als); |
| 399 | device_remove_file(&device->dev, &dev_attr_dock); |
| 400 | } |
| 401 | |
| 402 | static int __init hp_wmi_bios_setup(struct platform_device *device) |
| 403 | { |
| 404 | int err; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 405 | int wireless = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, 0); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 406 | |
| 407 | err = device_create_file(&device->dev, &dev_attr_display); |
| 408 | if (err) |
| 409 | goto add_sysfs_error; |
| 410 | err = device_create_file(&device->dev, &dev_attr_hddtemp); |
| 411 | if (err) |
| 412 | goto add_sysfs_error; |
| 413 | err = device_create_file(&device->dev, &dev_attr_als); |
| 414 | if (err) |
| 415 | goto add_sysfs_error; |
| 416 | err = device_create_file(&device->dev, &dev_attr_dock); |
| 417 | if (err) |
| 418 | goto add_sysfs_error; |
| 419 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 420 | if (wireless & 0x1) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 421 | wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev, |
| 422 | RFKILL_TYPE_WLAN, |
| 423 | &hp_wmi_rfkill_ops, |
| 424 | (void *) 0); |
| 425 | rfkill_set_sw_state(wifi_rfkill, hp_wmi_wifi_state()); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 426 | err = rfkill_register(wifi_rfkill); |
| 427 | if (err) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 428 | goto register_wifi_error; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 429 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 430 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 431 | if (wireless & 0x2) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 432 | bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev, |
| 433 | RFKILL_TYPE_BLUETOOTH, |
| 434 | &hp_wmi_rfkill_ops, |
| 435 | (void *) 1); |
| 436 | rfkill_set_sw_state(bluetooth_rfkill, |
| 437 | hp_wmi_bluetooth_state()); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 438 | err = rfkill_register(bluetooth_rfkill); |
Frans Pop | 6989d56 | 2009-01-29 14:25:14 -0800 | [diff] [blame] | 439 | if (err) |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 440 | goto register_bluetooth_error; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 441 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 442 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 443 | if (wireless & 0x4) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 444 | wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev, |
| 445 | RFKILL_TYPE_WWAN, |
| 446 | &hp_wmi_rfkill_ops, |
| 447 | (void *) 2); |
| 448 | rfkill_set_sw_state(wwan_rfkill, hp_wmi_wwan_state()); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 449 | err = rfkill_register(wwan_rfkill); |
| 450 | if (err) |
| 451 | goto register_wwan_err; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 452 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 453 | |
| 454 | return 0; |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 455 | register_wwan_err: |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 456 | rfkill_destroy(wwan_rfkill); |
Andrew Morton | 44f0606 | 2009-02-04 15:12:07 -0800 | [diff] [blame] | 457 | if (bluetooth_rfkill) |
| 458 | rfkill_unregister(bluetooth_rfkill); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 459 | register_bluetooth_error: |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 460 | rfkill_destroy(bluetooth_rfkill); |
Andrew Morton | 44f0606 | 2009-02-04 15:12:07 -0800 | [diff] [blame] | 461 | if (wifi_rfkill) |
| 462 | rfkill_unregister(wifi_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 463 | register_wifi_error: |
| 464 | rfkill_destroy(wifi_rfkill); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 465 | add_sysfs_error: |
| 466 | cleanup_sysfs(device); |
| 467 | return err; |
| 468 | } |
| 469 | |
| 470 | static int __exit hp_wmi_bios_remove(struct platform_device *device) |
| 471 | { |
| 472 | cleanup_sysfs(device); |
| 473 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 474 | if (wifi_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 475 | rfkill_unregister(wifi_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 476 | rfkill_destroy(wifi_rfkill); |
| 477 | } |
| 478 | if (bluetooth_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 479 | rfkill_unregister(bluetooth_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 480 | rfkill_destroy(wifi_rfkill); |
| 481 | } |
| 482 | if (wwan_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 483 | rfkill_unregister(wwan_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame^] | 484 | rfkill_destroy(wwan_rfkill); |
| 485 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 486 | |
| 487 | return 0; |
| 488 | } |
| 489 | |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 490 | static int hp_wmi_resume_handler(struct platform_device *device) |
| 491 | { |
| 492 | struct key_entry *key; |
| 493 | |
| 494 | /* |
| 495 | * Docking state may have changed while suspended, so trigger |
| 496 | * an input event for the current state. As this is a switch, |
| 497 | * the input layer will only actually pass it on if the state |
| 498 | * changed. |
| 499 | */ |
| 500 | for (key = hp_wmi_keymap; key->type != KE_END; key++) { |
| 501 | switch (key->type) { |
| 502 | case KE_SW: |
| 503 | input_report_switch(hp_wmi_input_dev, key->keycode, |
| 504 | hp_wmi_dock_state()); |
| 505 | input_sync(hp_wmi_input_dev); |
| 506 | break; |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | return 0; |
| 511 | } |
| 512 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 513 | static int __init hp_wmi_init(void) |
| 514 | { |
| 515 | int err; |
| 516 | |
| 517 | if (wmi_has_guid(HPWMI_EVENT_GUID)) { |
| 518 | err = wmi_install_notify_handler(HPWMI_EVENT_GUID, |
| 519 | hp_wmi_notify, NULL); |
| 520 | if (!err) |
| 521 | hp_wmi_input_setup(); |
| 522 | } |
| 523 | |
| 524 | if (wmi_has_guid(HPWMI_BIOS_GUID)) { |
| 525 | err = platform_driver_register(&hp_wmi_driver); |
| 526 | if (err) |
| 527 | return 0; |
| 528 | hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1); |
| 529 | if (!hp_wmi_platform_dev) { |
| 530 | platform_driver_unregister(&hp_wmi_driver); |
| 531 | return 0; |
| 532 | } |
| 533 | platform_device_add(hp_wmi_platform_dev); |
| 534 | } |
| 535 | |
| 536 | return 0; |
| 537 | } |
| 538 | |
| 539 | static void __exit hp_wmi_exit(void) |
| 540 | { |
| 541 | if (wmi_has_guid(HPWMI_EVENT_GUID)) { |
| 542 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); |
| 543 | input_unregister_device(hp_wmi_input_dev); |
| 544 | } |
| 545 | if (hp_wmi_platform_dev) { |
| 546 | platform_device_del(hp_wmi_platform_dev); |
| 547 | platform_driver_unregister(&hp_wmi_driver); |
| 548 | } |
| 549 | } |
| 550 | |
| 551 | module_init(hp_wmi_init); |
| 552 | module_exit(hp_wmi_exit); |