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