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