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; |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 83 | char *data; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 84 | }; |
| 85 | |
| 86 | struct bios_return { |
| 87 | u32 sigpass; |
| 88 | u32 return_code; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | struct key_entry { |
| 92 | char type; /* See KE_* below */ |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 93 | u16 code; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 94 | u16 keycode; |
| 95 | }; |
| 96 | |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 97 | enum { KE_KEY, KE_END }; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 98 | |
| 99 | static struct key_entry hp_wmi_keymap[] = { |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 100 | {KE_KEY, 0x02, KEY_BRIGHTNESSUP}, |
| 101 | {KE_KEY, 0x03, KEY_BRIGHTNESSDOWN}, |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 102 | {KE_KEY, 0x20e6, KEY_PROG1}, |
Thomas Renninger | f6b2ff0 | 2010-05-21 16:18:12 +0200 | [diff] [blame] | 103 | {KE_KEY, 0x20e8, KEY_MEDIA}, |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 104 | {KE_KEY, 0x2142, KEY_MEDIA}, |
Eric Piel | 5c62484 | 2008-10-18 20:27:28 -0700 | [diff] [blame] | 105 | {KE_KEY, 0x213b, KEY_INFO}, |
Matthew Garrett | caeacf5 | 2010-02-17 10:29:39 -0500 | [diff] [blame] | 106 | {KE_KEY, 0x2169, KEY_DIRECTION}, |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 107 | {KE_KEY, 0x231b, KEY_HELP}, |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 108 | {KE_END, 0} |
| 109 | }; |
| 110 | |
| 111 | static struct input_dev *hp_wmi_input_dev; |
| 112 | static struct platform_device *hp_wmi_platform_dev; |
| 113 | |
| 114 | static struct rfkill *wifi_rfkill; |
| 115 | static struct rfkill *bluetooth_rfkill; |
| 116 | static struct rfkill *wwan_rfkill; |
| 117 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 118 | static const struct dev_pm_ops hp_wmi_pm_ops = { |
Frans Pop | 8dd2b42 | 2009-08-20 20:38:13 +0200 | [diff] [blame] | 119 | .resume = hp_wmi_resume_handler, |
| 120 | .restore = hp_wmi_resume_handler, |
| 121 | }; |
| 122 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 123 | static struct platform_driver hp_wmi_driver = { |
| 124 | .driver = { |
Frans Pop | 8dd2b42 | 2009-08-20 20:38:13 +0200 | [diff] [blame] | 125 | .name = "hp-wmi", |
| 126 | .owner = THIS_MODULE, |
| 127 | .pm = &hp_wmi_pm_ops, |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 128 | }, |
| 129 | .probe = hp_wmi_bios_setup, |
| 130 | .remove = hp_wmi_bios_remove, |
| 131 | }; |
| 132 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 133 | /* |
| 134 | * hp_wmi_perform_query |
| 135 | * |
| 136 | * query: The commandtype -> What should be queried |
| 137 | * write: The command -> 0 read, 1 write, 3 ODM specific |
| 138 | * buffer: Buffer used as input and/or output |
| 139 | * buffersize: Size of buffer |
| 140 | * |
| 141 | * returns zero on success |
| 142 | * an HP WMI query specific error code (which is positive) |
| 143 | * -EINVAL if the query was not successful at all |
| 144 | * -EINVAL if the output buffer size exceeds buffersize |
| 145 | * |
| 146 | * Note: The buffersize must at least be the maximum of the input and output |
| 147 | * size. E.g. Battery info query (0x7) is defined to have 1 byte input |
| 148 | * and 128 byte output. The caller would do: |
| 149 | * buffer = kzalloc(128, GFP_KERNEL); |
| 150 | * ret = hp_wmi_perform_query(0x7, 0, buffer, 128) |
| 151 | */ |
| 152 | static int hp_wmi_perform_query(int query, int write, char *buffer, |
| 153 | int buffersize) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 154 | { |
| 155 | struct bios_return bios_return; |
| 156 | acpi_status status; |
| 157 | union acpi_object *obj; |
| 158 | struct bios_args args = { |
| 159 | .signature = 0x55434553, |
| 160 | .command = write ? 0x2 : 0x1, |
| 161 | .commandtype = query, |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 162 | .datasize = buffersize, |
| 163 | .data = buffer, |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 164 | }; |
| 165 | struct acpi_buffer input = { sizeof(struct bios_args), &args }; |
| 166 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 167 | |
| 168 | status = wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output); |
| 169 | |
| 170 | obj = output.pointer; |
| 171 | |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 172 | if (!obj) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 173 | return -EINVAL; |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 174 | else if (obj->type != ACPI_TYPE_BUFFER) { |
| 175 | kfree(obj); |
| 176 | return -EINVAL; |
| 177 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 178 | |
| 179 | bios_return = *((struct bios_return *)obj->buffer.pointer); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 180 | |
| 181 | if (bios_return.return_code) { |
| 182 | printk(KERN_WARNING PREFIX "Query %d returned %d\n", query, |
| 183 | bios_return.return_code); |
| 184 | kfree(obj); |
| 185 | return bios_return.return_code; |
| 186 | } |
| 187 | if (obj->buffer.length - sizeof(bios_return) > buffersize) { |
| 188 | kfree(obj); |
| 189 | return -EINVAL; |
| 190 | } |
| 191 | |
| 192 | memset(buffer, 0, buffersize); |
| 193 | memcpy(buffer, |
| 194 | ((char *)obj->buffer.pointer) + sizeof(struct bios_return), |
| 195 | obj->buffer.length - sizeof(bios_return)); |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 196 | kfree(obj); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 197 | return 0; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | static int hp_wmi_display_state(void) |
| 201 | { |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 202 | int state; |
| 203 | int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, (char *)&state, |
| 204 | sizeof(state)); |
| 205 | if (ret) |
| 206 | return -EINVAL; |
| 207 | return state; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static int hp_wmi_hddtemp_state(void) |
| 211 | { |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 212 | int state; |
| 213 | int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, (char *)&state, |
| 214 | sizeof(state)); |
| 215 | if (ret) |
| 216 | return -EINVAL; |
| 217 | return state; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static int hp_wmi_als_state(void) |
| 221 | { |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 222 | int state; |
| 223 | int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, (char *)&state, |
| 224 | sizeof(state)); |
| 225 | if (ret) |
| 226 | return -EINVAL; |
| 227 | return state; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | static int hp_wmi_dock_state(void) |
| 231 | { |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 232 | int state; |
| 233 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, (char *)&state, |
| 234 | sizeof(state)); |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 235 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 236 | if (ret) |
| 237 | return -EINVAL; |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 238 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 239 | return state & 0x1; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 240 | } |
| 241 | |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 242 | static int hp_wmi_tablet_state(void) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 243 | { |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 244 | int state; |
| 245 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, (char *)&state, |
| 246 | sizeof(state)); |
| 247 | if (ret) |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 248 | return ret; |
| 249 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 250 | return (state & 0x4) ? 1 : 0; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 251 | } |
| 252 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 253 | static int hp_wmi_set_block(void *data, bool blocked) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 254 | { |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 255 | enum hp_wmi_radio r = (enum hp_wmi_radio) data; |
| 256 | int query = BIT(r + 8) | ((!blocked) << r); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 257 | int ret; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 258 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 259 | ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, |
| 260 | (char *)&query, sizeof(query)); |
| 261 | if (ret) |
| 262 | return -EINVAL; |
| 263 | return 0; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 264 | } |
| 265 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 266 | static const struct rfkill_ops hp_wmi_rfkill_ops = { |
| 267 | .set_block = hp_wmi_set_block, |
| 268 | }; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 269 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 270 | static bool hp_wmi_get_sw_state(enum hp_wmi_radio r) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 271 | { |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 272 | int wireless; |
| 273 | int mask; |
| 274 | hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, |
| 275 | (char *)&wireless, sizeof(wireless)); |
| 276 | /* TBD: Pass error */ |
| 277 | |
| 278 | mask = 0x200 << (r * 8); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 279 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 280 | if (wireless & mask) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 281 | return false; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 282 | else |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 283 | return true; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 284 | } |
| 285 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 286 | static bool hp_wmi_get_hw_state(enum hp_wmi_radio r) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 287 | { |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 288 | int wireless; |
| 289 | int mask; |
| 290 | hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, |
| 291 | (char *)&wireless, sizeof(wireless)); |
| 292 | /* TBD: Pass error */ |
| 293 | |
| 294 | mask = 0x800 << (r * 8); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 295 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 296 | if (wireless & mask) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 297 | return false; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 298 | else |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 299 | return true; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, |
| 303 | char *buf) |
| 304 | { |
| 305 | int value = hp_wmi_display_state(); |
| 306 | if (value < 0) |
| 307 | return -EINVAL; |
| 308 | return sprintf(buf, "%d\n", value); |
| 309 | } |
| 310 | |
| 311 | static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr, |
| 312 | char *buf) |
| 313 | { |
| 314 | int value = hp_wmi_hddtemp_state(); |
| 315 | if (value < 0) |
| 316 | return -EINVAL; |
| 317 | return sprintf(buf, "%d\n", value); |
| 318 | } |
| 319 | |
| 320 | static ssize_t show_als(struct device *dev, struct device_attribute *attr, |
| 321 | char *buf) |
| 322 | { |
| 323 | int value = hp_wmi_als_state(); |
| 324 | if (value < 0) |
| 325 | return -EINVAL; |
| 326 | return sprintf(buf, "%d\n", value); |
| 327 | } |
| 328 | |
| 329 | static ssize_t show_dock(struct device *dev, struct device_attribute *attr, |
| 330 | char *buf) |
| 331 | { |
| 332 | int value = hp_wmi_dock_state(); |
| 333 | if (value < 0) |
| 334 | return -EINVAL; |
| 335 | return sprintf(buf, "%d\n", value); |
| 336 | } |
| 337 | |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 338 | static ssize_t show_tablet(struct device *dev, struct device_attribute *attr, |
| 339 | char *buf) |
| 340 | { |
| 341 | int value = hp_wmi_tablet_state(); |
| 342 | if (value < 0) |
| 343 | return -EINVAL; |
| 344 | return sprintf(buf, "%d\n", value); |
| 345 | } |
| 346 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 347 | static ssize_t set_als(struct device *dev, struct device_attribute *attr, |
| 348 | const char *buf, size_t count) |
| 349 | { |
| 350 | u32 tmp = simple_strtoul(buf, NULL, 10); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 351 | int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, (char *)&tmp, |
| 352 | sizeof(tmp)); |
| 353 | if (ret) |
| 354 | return -EINVAL; |
| 355 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 356 | return count; |
| 357 | } |
| 358 | |
| 359 | static DEVICE_ATTR(display, S_IRUGO, show_display, NULL); |
| 360 | static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL); |
| 361 | static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als); |
| 362 | static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL); |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 363 | static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 364 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 365 | 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] | 366 | { |
| 367 | struct key_entry *key; |
| 368 | |
| 369 | for (key = hp_wmi_keymap; key->type != KE_END; key++) |
| 370 | if (code == key->code) |
| 371 | return key; |
| 372 | |
| 373 | return NULL; |
| 374 | } |
| 375 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 376 | 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] | 377 | { |
| 378 | struct key_entry *key; |
| 379 | |
| 380 | for (key = hp_wmi_keymap; key->type != KE_END; key++) |
| 381 | if (key->type == KE_KEY && keycode == key->keycode) |
| 382 | return key; |
| 383 | |
| 384 | return NULL; |
| 385 | } |
| 386 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 387 | static int hp_wmi_getkeycode(struct input_dev *dev, |
| 388 | unsigned int scancode, unsigned int *keycode) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 389 | { |
| 390 | struct key_entry *key = hp_wmi_get_entry_by_scancode(scancode); |
| 391 | |
| 392 | if (key && key->type == KE_KEY) { |
| 393 | *keycode = key->keycode; |
| 394 | return 0; |
| 395 | } |
| 396 | |
| 397 | return -EINVAL; |
| 398 | } |
| 399 | |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 400 | static int hp_wmi_setkeycode(struct input_dev *dev, |
| 401 | unsigned int scancode, unsigned int keycode) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 402 | { |
| 403 | struct key_entry *key; |
Dmitry Torokhov | 58b9399 | 2010-03-08 22:37:10 -0800 | [diff] [blame] | 404 | unsigned int old_keycode; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 405 | |
| 406 | key = hp_wmi_get_entry_by_scancode(scancode); |
| 407 | if (key && key->type == KE_KEY) { |
| 408 | old_keycode = key->keycode; |
| 409 | key->keycode = keycode; |
| 410 | set_bit(keycode, dev->keybit); |
| 411 | if (!hp_wmi_get_entry_by_keycode(old_keycode)) |
| 412 | clear_bit(old_keycode, dev->keybit); |
| 413 | return 0; |
| 414 | } |
| 415 | |
| 416 | return -EINVAL; |
| 417 | } |
| 418 | |
Adrian Bunk | 88429a1 | 2008-10-15 22:05:17 -0700 | [diff] [blame] | 419 | static void hp_wmi_notify(u32 value, void *context) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 420 | { |
| 421 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 422 | static struct key_entry *key; |
| 423 | union acpi_object *obj; |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 424 | u32 event_id, event_data; |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 425 | int key_code, ret; |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 426 | u32 *location; |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 427 | acpi_status status; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 428 | |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 429 | status = wmi_get_event_data(value, &response); |
| 430 | if (status != AE_OK) { |
Thomas Renninger | a2806c6 | 2010-05-21 16:18:11 +0200 | [diff] [blame] | 431 | printk(KERN_INFO PREFIX "bad event status 0x%x\n", status); |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 432 | return; |
| 433 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 434 | |
| 435 | obj = (union acpi_object *)response.pointer; |
| 436 | |
Thomas Renninger | c477506 | 2010-07-29 12:27:59 +0200 | [diff] [blame^] | 437 | if (!obj) |
| 438 | return; |
| 439 | if (obj->type != ACPI_TYPE_BUFFER) { |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 440 | printk(KERN_INFO "hp-wmi: Unknown response received %d\n", |
| 441 | obj->type); |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 442 | kfree(obj); |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 443 | return; |
| 444 | } |
| 445 | |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 446 | /* |
| 447 | * Depending on ACPI version the concatenation of id and event data |
| 448 | * inside _WED function will result in a 8 or 16 byte buffer. |
| 449 | */ |
| 450 | location = (u32 *)obj->buffer.pointer; |
| 451 | if (obj->buffer.length == 8) { |
| 452 | event_id = *location; |
| 453 | event_data = *(location + 1); |
| 454 | } else if (obj->buffer.length == 16) { |
| 455 | event_id = *location; |
| 456 | event_data = *(location + 2); |
| 457 | } else { |
| 458 | printk(KERN_INFO "hp-wmi: Unknown buffer length %d\n", |
| 459 | obj->buffer.length); |
| 460 | kfree(obj); |
| 461 | return; |
| 462 | } |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 463 | kfree(obj); |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 464 | |
| 465 | switch (event_id) { |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 466 | case HPWMI_DOCK_EVENT: |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 467 | input_report_switch(hp_wmi_input_dev, SW_DOCK, |
| 468 | hp_wmi_dock_state()); |
| 469 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
| 470 | hp_wmi_tablet_state()); |
| 471 | input_sync(hp_wmi_input_dev); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 472 | break; |
Thomas Renninger | 1bbdfd5 | 2010-05-21 16:18:13 +0200 | [diff] [blame] | 473 | case HPWMI_PARK_HDD: |
| 474 | break; |
| 475 | case HPWMI_SMART_ADAPTER: |
| 476 | break; |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 477 | case HPWMI_BEZEL_BUTTON: |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 478 | ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, |
| 479 | (char *)&key_code, |
| 480 | sizeof(key_code)); |
| 481 | if (ret) |
| 482 | break; |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 483 | key = hp_wmi_get_entry_by_scancode(key_code); |
| 484 | if (key) { |
| 485 | switch (key->type) { |
| 486 | case KE_KEY: |
| 487 | input_report_key(hp_wmi_input_dev, |
| 488 | key->keycode, 1); |
| 489 | input_sync(hp_wmi_input_dev); |
| 490 | input_report_key(hp_wmi_input_dev, |
| 491 | key->keycode, 0); |
| 492 | input_sync(hp_wmi_input_dev); |
| 493 | break; |
| 494 | } |
Thomas Renninger | da9a79b | 2010-05-21 16:18:10 +0200 | [diff] [blame] | 495 | } else |
Thomas Renninger | a2806c6 | 2010-05-21 16:18:11 +0200 | [diff] [blame] | 496 | printk(KERN_INFO PREFIX "Unknown key code - 0x%x\n", |
Thomas Renninger | da9a79b | 2010-05-21 16:18:10 +0200 | [diff] [blame] | 497 | key_code); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 498 | break; |
| 499 | case HPWMI_WIRELESS: |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 500 | if (wifi_rfkill) |
| 501 | rfkill_set_states(wifi_rfkill, |
| 502 | hp_wmi_get_sw_state(HPWMI_WIFI), |
| 503 | hp_wmi_get_hw_state(HPWMI_WIFI)); |
| 504 | if (bluetooth_rfkill) |
| 505 | rfkill_set_states(bluetooth_rfkill, |
| 506 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH), |
| 507 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); |
| 508 | if (wwan_rfkill) |
| 509 | rfkill_set_states(wwan_rfkill, |
| 510 | hp_wmi_get_sw_state(HPWMI_WWAN), |
| 511 | hp_wmi_get_hw_state(HPWMI_WWAN)); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 512 | break; |
Thomas Renninger | 1bbdfd5 | 2010-05-21 16:18:13 +0200 | [diff] [blame] | 513 | case HPWMI_CPU_BATTERY_THROTTLE: |
| 514 | printk(KERN_INFO PREFIX UNIMP "CPU throttle because of 3 Cell" |
| 515 | " battery event detected\n"); |
| 516 | break; |
| 517 | case HPWMI_LOCK_SWITCH: |
| 518 | break; |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 519 | default: |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 520 | printk(KERN_INFO PREFIX "Unknown event_id - %d - 0x%x\n", |
| 521 | event_id, event_data); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 522 | break; |
| 523 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | static int __init hp_wmi_input_setup(void) |
| 527 | { |
| 528 | struct key_entry *key; |
| 529 | int err; |
| 530 | |
| 531 | hp_wmi_input_dev = input_allocate_device(); |
Axel Lin | bc28596 | 2010-07-20 15:19:51 -0700 | [diff] [blame] | 532 | if (!hp_wmi_input_dev) |
| 533 | return -ENOMEM; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 534 | |
| 535 | hp_wmi_input_dev->name = "HP WMI hotkeys"; |
| 536 | hp_wmi_input_dev->phys = "wmi/input0"; |
| 537 | hp_wmi_input_dev->id.bustype = BUS_HOST; |
| 538 | hp_wmi_input_dev->getkeycode = hp_wmi_getkeycode; |
| 539 | hp_wmi_input_dev->setkeycode = hp_wmi_setkeycode; |
| 540 | |
| 541 | for (key = hp_wmi_keymap; key->type != KE_END; key++) { |
| 542 | switch (key->type) { |
| 543 | case KE_KEY: |
| 544 | set_bit(EV_KEY, hp_wmi_input_dev->evbit); |
| 545 | set_bit(key->keycode, hp_wmi_input_dev->keybit); |
| 546 | break; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 547 | } |
| 548 | } |
| 549 | |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 550 | set_bit(EV_SW, hp_wmi_input_dev->evbit); |
| 551 | set_bit(SW_DOCK, hp_wmi_input_dev->swbit); |
| 552 | set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit); |
| 553 | |
| 554 | /* Set initial hardware state */ |
| 555 | input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state()); |
| 556 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
| 557 | hp_wmi_tablet_state()); |
| 558 | input_sync(hp_wmi_input_dev); |
| 559 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 560 | err = input_register_device(hp_wmi_input_dev); |
| 561 | |
| 562 | if (err) { |
| 563 | input_free_device(hp_wmi_input_dev); |
| 564 | return err; |
| 565 | } |
| 566 | |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | static void cleanup_sysfs(struct platform_device *device) |
| 571 | { |
| 572 | device_remove_file(&device->dev, &dev_attr_display); |
| 573 | device_remove_file(&device->dev, &dev_attr_hddtemp); |
| 574 | device_remove_file(&device->dev, &dev_attr_als); |
| 575 | device_remove_file(&device->dev, &dev_attr_dock); |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 576 | device_remove_file(&device->dev, &dev_attr_tablet); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Uwe Kleine-König | ea79632 | 2010-02-04 20:56:52 +0100 | [diff] [blame] | 579 | static int __devinit hp_wmi_bios_setup(struct platform_device *device) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 580 | { |
| 581 | int err; |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 582 | int wireless; |
| 583 | |
| 584 | err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, (char *)&wireless, |
| 585 | sizeof(wireless)); |
| 586 | if (err) |
| 587 | return err; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 588 | |
| 589 | err = device_create_file(&device->dev, &dev_attr_display); |
| 590 | if (err) |
| 591 | goto add_sysfs_error; |
| 592 | err = device_create_file(&device->dev, &dev_attr_hddtemp); |
| 593 | if (err) |
| 594 | goto add_sysfs_error; |
| 595 | err = device_create_file(&device->dev, &dev_attr_als); |
| 596 | if (err) |
| 597 | goto add_sysfs_error; |
| 598 | err = device_create_file(&device->dev, &dev_attr_dock); |
| 599 | if (err) |
| 600 | goto add_sysfs_error; |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 601 | err = device_create_file(&device->dev, &dev_attr_tablet); |
| 602 | if (err) |
| 603 | goto add_sysfs_error; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 604 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 605 | if (wireless & 0x1) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 606 | wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev, |
| 607 | RFKILL_TYPE_WLAN, |
| 608 | &hp_wmi_rfkill_ops, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 609 | (void *) HPWMI_WIFI); |
| 610 | rfkill_init_sw_state(wifi_rfkill, |
| 611 | hp_wmi_get_sw_state(HPWMI_WIFI)); |
| 612 | rfkill_set_hw_state(wifi_rfkill, |
| 613 | hp_wmi_get_hw_state(HPWMI_WIFI)); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 614 | err = rfkill_register(wifi_rfkill); |
| 615 | if (err) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 616 | goto register_wifi_error; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 617 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 618 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 619 | if (wireless & 0x2) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 620 | bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev, |
| 621 | RFKILL_TYPE_BLUETOOTH, |
| 622 | &hp_wmi_rfkill_ops, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 623 | (void *) HPWMI_BLUETOOTH); |
| 624 | rfkill_init_sw_state(bluetooth_rfkill, |
| 625 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH)); |
| 626 | rfkill_set_hw_state(bluetooth_rfkill, |
| 627 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 628 | err = rfkill_register(bluetooth_rfkill); |
Frans Pop | 6989d56 | 2009-01-29 14:25:14 -0800 | [diff] [blame] | 629 | if (err) |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 630 | goto register_bluetooth_error; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 631 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 632 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 633 | if (wireless & 0x4) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 634 | wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev, |
| 635 | RFKILL_TYPE_WWAN, |
| 636 | &hp_wmi_rfkill_ops, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 637 | (void *) HPWMI_WWAN); |
| 638 | rfkill_init_sw_state(wwan_rfkill, |
| 639 | hp_wmi_get_sw_state(HPWMI_WWAN)); |
| 640 | rfkill_set_hw_state(wwan_rfkill, |
| 641 | hp_wmi_get_hw_state(HPWMI_WWAN)); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 642 | err = rfkill_register(wwan_rfkill); |
| 643 | if (err) |
| 644 | goto register_wwan_err; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 645 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 646 | |
| 647 | return 0; |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 648 | register_wwan_err: |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 649 | rfkill_destroy(wwan_rfkill); |
Andrew Morton | 44f0606 | 2009-02-04 15:12:07 -0800 | [diff] [blame] | 650 | if (bluetooth_rfkill) |
| 651 | rfkill_unregister(bluetooth_rfkill); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 652 | register_bluetooth_error: |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 653 | rfkill_destroy(bluetooth_rfkill); |
Andrew Morton | 44f0606 | 2009-02-04 15:12:07 -0800 | [diff] [blame] | 654 | if (wifi_rfkill) |
| 655 | rfkill_unregister(wifi_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 656 | register_wifi_error: |
| 657 | rfkill_destroy(wifi_rfkill); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 658 | add_sysfs_error: |
| 659 | cleanup_sysfs(device); |
| 660 | return err; |
| 661 | } |
| 662 | |
| 663 | static int __exit hp_wmi_bios_remove(struct platform_device *device) |
| 664 | { |
| 665 | cleanup_sysfs(device); |
| 666 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 667 | if (wifi_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 668 | rfkill_unregister(wifi_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 669 | rfkill_destroy(wifi_rfkill); |
| 670 | } |
| 671 | if (bluetooth_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 672 | rfkill_unregister(bluetooth_rfkill); |
Corentin Chary | 09729f0 | 2009-09-14 12:43:51 +0200 | [diff] [blame] | 673 | rfkill_destroy(bluetooth_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 674 | } |
| 675 | if (wwan_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 676 | rfkill_unregister(wwan_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 677 | rfkill_destroy(wwan_rfkill); |
| 678 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 679 | |
| 680 | return 0; |
| 681 | } |
| 682 | |
Frans Pop | 8dd2b42 | 2009-08-20 20:38:13 +0200 | [diff] [blame] | 683 | static int hp_wmi_resume_handler(struct device *device) |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 684 | { |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 685 | /* |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 686 | * Hardware state may have changed while suspended, so trigger |
| 687 | * input events for the current state. As this is a switch, |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 688 | * the input layer will only actually pass it on if the state |
| 689 | * changed. |
| 690 | */ |
Frans Pop | daed953 | 2009-07-30 17:16:05 -0400 | [diff] [blame] | 691 | if (hp_wmi_input_dev) { |
| 692 | input_report_switch(hp_wmi_input_dev, SW_DOCK, |
| 693 | hp_wmi_dock_state()); |
| 694 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
| 695 | hp_wmi_tablet_state()); |
| 696 | input_sync(hp_wmi_input_dev); |
| 697 | } |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 698 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 699 | if (wifi_rfkill) |
| 700 | rfkill_set_states(wifi_rfkill, |
| 701 | hp_wmi_get_sw_state(HPWMI_WIFI), |
| 702 | hp_wmi_get_hw_state(HPWMI_WIFI)); |
| 703 | if (bluetooth_rfkill) |
| 704 | rfkill_set_states(bluetooth_rfkill, |
| 705 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH), |
| 706 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); |
| 707 | if (wwan_rfkill) |
| 708 | rfkill_set_states(wwan_rfkill, |
| 709 | hp_wmi_get_sw_state(HPWMI_WWAN), |
| 710 | hp_wmi_get_hw_state(HPWMI_WWAN)); |
| 711 | |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 712 | return 0; |
| 713 | } |
| 714 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 715 | static int __init hp_wmi_init(void) |
| 716 | { |
| 717 | int err; |
Thomas Renninger | b096667 | 2010-07-20 15:19:29 -0700 | [diff] [blame] | 718 | int event_capable = wmi_has_guid(HPWMI_EVENT_GUID); |
| 719 | int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 720 | |
Thomas Renninger | b096667 | 2010-07-20 15:19:29 -0700 | [diff] [blame] | 721 | if (event_capable) { |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 722 | err = wmi_install_notify_handler(HPWMI_EVENT_GUID, |
| 723 | hp_wmi_notify, NULL); |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 724 | if (ACPI_FAILURE(err)) |
| 725 | return -EINVAL; |
| 726 | err = hp_wmi_input_setup(); |
| 727 | if (err) { |
| 728 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); |
| 729 | return err; |
| 730 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 731 | } |
| 732 | |
Thomas Renninger | b096667 | 2010-07-20 15:19:29 -0700 | [diff] [blame] | 733 | if (bios_capable) { |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 734 | err = platform_driver_register(&hp_wmi_driver); |
| 735 | if (err) |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 736 | goto err_driver_reg; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 737 | hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1); |
| 738 | if (!hp_wmi_platform_dev) { |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 739 | err = -ENOMEM; |
| 740 | goto err_device_alloc; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 741 | } |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 742 | err = platform_device_add(hp_wmi_platform_dev); |
| 743 | if (err) |
| 744 | goto err_device_add; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 745 | } |
| 746 | |
Thomas Renninger | b096667 | 2010-07-20 15:19:29 -0700 | [diff] [blame] | 747 | if (!bios_capable && !event_capable) |
| 748 | return -ENODEV; |
| 749 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 750 | return 0; |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 751 | |
| 752 | err_device_add: |
| 753 | platform_device_put(hp_wmi_platform_dev); |
| 754 | err_device_alloc: |
| 755 | platform_driver_unregister(&hp_wmi_driver); |
| 756 | err_driver_reg: |
| 757 | if (wmi_has_guid(HPWMI_EVENT_GUID)) { |
| 758 | input_unregister_device(hp_wmi_input_dev); |
| 759 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); |
| 760 | } |
| 761 | |
| 762 | return err; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | static void __exit hp_wmi_exit(void) |
| 766 | { |
| 767 | if (wmi_has_guid(HPWMI_EVENT_GUID)) { |
| 768 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); |
| 769 | input_unregister_device(hp_wmi_input_dev); |
| 770 | } |
| 771 | if (hp_wmi_platform_dev) { |
Axel Lin | 97ba0af | 2010-06-03 15:18:03 +0800 | [diff] [blame] | 772 | platform_device_unregister(hp_wmi_platform_dev); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 773 | platform_driver_unregister(&hp_wmi_driver); |
| 774 | } |
| 775 | } |
| 776 | |
| 777 | module_init(hp_wmi_init); |
| 778 | module_exit(hp_wmi_exit); |