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