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> |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 32 | #include <linux/input/sparse-keymap.h> |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 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; |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 83 | u32 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 | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 89 | u32 value; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 90 | }; |
| 91 | |
Anssi Hannula | 9af0e0f | 2011-02-20 20:07:20 +0200 | [diff] [blame^] | 92 | enum hp_return_value { |
| 93 | HPWMI_RET_WRONG_SIGNATURE = 0x02, |
| 94 | HPWMI_RET_UNKNOWN_COMMAND = 0x03, |
| 95 | HPWMI_RET_UNKNOWN_CMDTYPE = 0x04, |
| 96 | HPWMI_RET_INVALID_PARAMETERS = 0x05, |
| 97 | }; |
| 98 | |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 99 | static const struct key_entry hp_wmi_keymap[] = { |
| 100 | { KE_KEY, 0x02, { KEY_BRIGHTNESSUP } }, |
| 101 | { KE_KEY, 0x03, { KEY_BRIGHTNESSDOWN } }, |
| 102 | { KE_KEY, 0x20e6, { KEY_PROG1 } }, |
| 103 | { KE_KEY, 0x20e8, { KEY_MEDIA } }, |
| 104 | { KE_KEY, 0x2142, { KEY_MEDIA } }, |
| 105 | { KE_KEY, 0x213b, { KEY_INFO } }, |
| 106 | { KE_KEY, 0x2169, { KEY_DIRECTION } }, |
| 107 | { KE_KEY, 0x231b, { KEY_HELP } }, |
| 108 | { KE_END, 0 } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 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 | */ |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 152 | static int hp_wmi_perform_query(int query, int write, u32 *buffer, |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 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, |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 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 | |
Anssi Hannula | 9af0e0f | 2011-02-20 20:07:20 +0200 | [diff] [blame^] | 181 | if (bios_return.return_code) { |
| 182 | if (bios_return.return_code != HPWMI_RET_UNKNOWN_CMDTYPE) |
| 183 | printk(KERN_WARNING PREFIX "query 0x%x returned " |
| 184 | "error 0x%x\n", |
| 185 | query, bios_return.return_code); |
| 186 | kfree(obj); |
| 187 | return bios_return.return_code; |
| 188 | } |
| 189 | |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 190 | memcpy(buffer, &bios_return.value, sizeof(bios_return.value)); |
Zeng Zhaoming | 53c96df | 2010-11-19 00:46:19 +0800 | [diff] [blame] | 191 | |
| 192 | kfree(obj); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 193 | return 0; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static int hp_wmi_display_state(void) |
| 197 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 198 | int state = 0; |
| 199 | int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, &state, |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 200 | sizeof(state)); |
| 201 | if (ret) |
| 202 | return -EINVAL; |
| 203 | return state; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | static int hp_wmi_hddtemp_state(void) |
| 207 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 208 | int state = 0; |
| 209 | int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, &state, |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 210 | sizeof(state)); |
| 211 | if (ret) |
| 212 | return -EINVAL; |
| 213 | return state; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | static int hp_wmi_als_state(void) |
| 217 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 218 | int state = 0; |
| 219 | int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, &state, |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 220 | sizeof(state)); |
| 221 | if (ret) |
| 222 | return -EINVAL; |
| 223 | return state; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | static int hp_wmi_dock_state(void) |
| 227 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 228 | int state = 0; |
| 229 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state, |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 230 | sizeof(state)); |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 231 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 232 | if (ret) |
| 233 | return -EINVAL; |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 234 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 235 | return state & 0x1; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 238 | static int hp_wmi_tablet_state(void) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 239 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 240 | int state = 0; |
| 241 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state, |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 242 | sizeof(state)); |
| 243 | if (ret) |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 244 | return ret; |
| 245 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 246 | return (state & 0x4) ? 1 : 0; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 247 | } |
| 248 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 249 | static int hp_wmi_set_block(void *data, bool blocked) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 250 | { |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 251 | enum hp_wmi_radio r = (enum hp_wmi_radio) data; |
| 252 | int query = BIT(r + 8) | ((!blocked) << r); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 253 | int ret; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 254 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 255 | ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 256 | &query, sizeof(query)); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 257 | if (ret) |
| 258 | return -EINVAL; |
| 259 | return 0; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 260 | } |
| 261 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 262 | static const struct rfkill_ops hp_wmi_rfkill_ops = { |
| 263 | .set_block = hp_wmi_set_block, |
| 264 | }; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 265 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 266 | static bool hp_wmi_get_sw_state(enum hp_wmi_radio r) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 267 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 268 | int wireless = 0; |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 269 | int mask; |
| 270 | hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 271 | &wireless, sizeof(wireless)); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 272 | /* TBD: Pass error */ |
| 273 | |
| 274 | mask = 0x200 << (r * 8); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 275 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 276 | if (wireless & mask) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 277 | return false; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 278 | else |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 279 | return true; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 282 | static bool hp_wmi_get_hw_state(enum hp_wmi_radio r) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 283 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 284 | int wireless = 0; |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 285 | int mask; |
| 286 | hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 287 | &wireless, sizeof(wireless)); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 288 | /* TBD: Pass error */ |
| 289 | |
| 290 | mask = 0x800 << (r * 8); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 291 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 292 | if (wireless & mask) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 293 | return false; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 294 | else |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 295 | return true; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, |
| 299 | char *buf) |
| 300 | { |
| 301 | int value = hp_wmi_display_state(); |
| 302 | if (value < 0) |
| 303 | return -EINVAL; |
| 304 | return sprintf(buf, "%d\n", value); |
| 305 | } |
| 306 | |
| 307 | static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr, |
| 308 | char *buf) |
| 309 | { |
| 310 | int value = hp_wmi_hddtemp_state(); |
| 311 | if (value < 0) |
| 312 | return -EINVAL; |
| 313 | return sprintf(buf, "%d\n", value); |
| 314 | } |
| 315 | |
| 316 | static ssize_t show_als(struct device *dev, struct device_attribute *attr, |
| 317 | char *buf) |
| 318 | { |
| 319 | int value = hp_wmi_als_state(); |
| 320 | if (value < 0) |
| 321 | return -EINVAL; |
| 322 | return sprintf(buf, "%d\n", value); |
| 323 | } |
| 324 | |
| 325 | static ssize_t show_dock(struct device *dev, struct device_attribute *attr, |
| 326 | char *buf) |
| 327 | { |
| 328 | int value = hp_wmi_dock_state(); |
| 329 | if (value < 0) |
| 330 | return -EINVAL; |
| 331 | return sprintf(buf, "%d\n", value); |
| 332 | } |
| 333 | |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 334 | static ssize_t show_tablet(struct device *dev, struct device_attribute *attr, |
| 335 | char *buf) |
| 336 | { |
| 337 | int value = hp_wmi_tablet_state(); |
| 338 | if (value < 0) |
| 339 | return -EINVAL; |
| 340 | return sprintf(buf, "%d\n", value); |
| 341 | } |
| 342 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 343 | static ssize_t set_als(struct device *dev, struct device_attribute *attr, |
| 344 | const char *buf, size_t count) |
| 345 | { |
| 346 | u32 tmp = simple_strtoul(buf, NULL, 10); |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 347 | int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, &tmp, |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 348 | sizeof(tmp)); |
| 349 | if (ret) |
| 350 | return -EINVAL; |
| 351 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 352 | return count; |
| 353 | } |
| 354 | |
| 355 | static DEVICE_ATTR(display, S_IRUGO, show_display, NULL); |
| 356 | static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL); |
| 357 | static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als); |
| 358 | static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL); |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 359 | static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 360 | |
Adrian Bunk | 88429a1 | 2008-10-15 22:05:17 -0700 | [diff] [blame] | 361 | static void hp_wmi_notify(u32 value, void *context) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 362 | { |
| 363 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 364 | union acpi_object *obj; |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 365 | u32 event_id, event_data; |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 366 | int key_code = 0, ret; |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 367 | u32 *location; |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 368 | acpi_status status; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 369 | |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 370 | status = wmi_get_event_data(value, &response); |
| 371 | if (status != AE_OK) { |
Thomas Renninger | a2806c6 | 2010-05-21 16:18:11 +0200 | [diff] [blame] | 372 | printk(KERN_INFO PREFIX "bad event status 0x%x\n", status); |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 373 | return; |
| 374 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 375 | |
| 376 | obj = (union acpi_object *)response.pointer; |
| 377 | |
Thomas Renninger | c477506 | 2010-07-29 12:27:59 +0200 | [diff] [blame] | 378 | if (!obj) |
| 379 | return; |
| 380 | if (obj->type != ACPI_TYPE_BUFFER) { |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 381 | printk(KERN_INFO "hp-wmi: Unknown response received %d\n", |
| 382 | obj->type); |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 383 | kfree(obj); |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 384 | return; |
| 385 | } |
| 386 | |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 387 | /* |
| 388 | * Depending on ACPI version the concatenation of id and event data |
| 389 | * inside _WED function will result in a 8 or 16 byte buffer. |
| 390 | */ |
| 391 | location = (u32 *)obj->buffer.pointer; |
| 392 | if (obj->buffer.length == 8) { |
| 393 | event_id = *location; |
| 394 | event_data = *(location + 1); |
| 395 | } else if (obj->buffer.length == 16) { |
| 396 | event_id = *location; |
| 397 | event_data = *(location + 2); |
| 398 | } else { |
| 399 | printk(KERN_INFO "hp-wmi: Unknown buffer length %d\n", |
| 400 | obj->buffer.length); |
| 401 | kfree(obj); |
| 402 | return; |
| 403 | } |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 404 | kfree(obj); |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 405 | |
| 406 | switch (event_id) { |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 407 | case HPWMI_DOCK_EVENT: |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 408 | input_report_switch(hp_wmi_input_dev, SW_DOCK, |
| 409 | hp_wmi_dock_state()); |
| 410 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
| 411 | hp_wmi_tablet_state()); |
| 412 | input_sync(hp_wmi_input_dev); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 413 | break; |
Thomas Renninger | 1bbdfd5 | 2010-05-21 16:18:13 +0200 | [diff] [blame] | 414 | case HPWMI_PARK_HDD: |
| 415 | break; |
| 416 | case HPWMI_SMART_ADAPTER: |
| 417 | break; |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 418 | case HPWMI_BEZEL_BUTTON: |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 419 | ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 420 | &key_code, |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 421 | sizeof(key_code)); |
| 422 | if (ret) |
| 423 | break; |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 424 | |
| 425 | if (!sparse_keymap_report_event(hp_wmi_input_dev, |
| 426 | key_code, 1, true)) |
Thomas Renninger | a2806c6 | 2010-05-21 16:18:11 +0200 | [diff] [blame] | 427 | printk(KERN_INFO PREFIX "Unknown key code - 0x%x\n", |
Thomas Renninger | da9a79b | 2010-05-21 16:18:10 +0200 | [diff] [blame] | 428 | key_code); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 429 | break; |
| 430 | case HPWMI_WIRELESS: |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 431 | if (wifi_rfkill) |
| 432 | rfkill_set_states(wifi_rfkill, |
| 433 | hp_wmi_get_sw_state(HPWMI_WIFI), |
| 434 | hp_wmi_get_hw_state(HPWMI_WIFI)); |
| 435 | if (bluetooth_rfkill) |
| 436 | rfkill_set_states(bluetooth_rfkill, |
| 437 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH), |
| 438 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); |
| 439 | if (wwan_rfkill) |
| 440 | rfkill_set_states(wwan_rfkill, |
| 441 | hp_wmi_get_sw_state(HPWMI_WWAN), |
| 442 | hp_wmi_get_hw_state(HPWMI_WWAN)); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 443 | break; |
Thomas Renninger | 1bbdfd5 | 2010-05-21 16:18:13 +0200 | [diff] [blame] | 444 | case HPWMI_CPU_BATTERY_THROTTLE: |
| 445 | printk(KERN_INFO PREFIX UNIMP "CPU throttle because of 3 Cell" |
| 446 | " battery event detected\n"); |
| 447 | break; |
| 448 | case HPWMI_LOCK_SWITCH: |
| 449 | break; |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 450 | default: |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 451 | printk(KERN_INFO PREFIX "Unknown event_id - %d - 0x%x\n", |
| 452 | event_id, event_data); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 453 | break; |
| 454 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 455 | } |
| 456 | |
| 457 | static int __init hp_wmi_input_setup(void) |
| 458 | { |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 459 | acpi_status status; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 460 | int err; |
| 461 | |
| 462 | hp_wmi_input_dev = input_allocate_device(); |
Axel Lin | bc28596 | 2010-07-20 15:19:51 -0700 | [diff] [blame] | 463 | if (!hp_wmi_input_dev) |
| 464 | return -ENOMEM; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 465 | |
| 466 | hp_wmi_input_dev->name = "HP WMI hotkeys"; |
| 467 | hp_wmi_input_dev->phys = "wmi/input0"; |
| 468 | hp_wmi_input_dev->id.bustype = BUS_HOST; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 469 | |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 470 | __set_bit(EV_SW, hp_wmi_input_dev->evbit); |
| 471 | __set_bit(SW_DOCK, hp_wmi_input_dev->swbit); |
| 472 | __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 473 | |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 474 | err = sparse_keymap_setup(hp_wmi_input_dev, hp_wmi_keymap, NULL); |
| 475 | if (err) |
| 476 | goto err_free_dev; |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 477 | |
| 478 | /* Set initial hardware state */ |
| 479 | input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state()); |
| 480 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
| 481 | hp_wmi_tablet_state()); |
| 482 | input_sync(hp_wmi_input_dev); |
| 483 | |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 484 | status = wmi_install_notify_handler(HPWMI_EVENT_GUID, hp_wmi_notify, NULL); |
| 485 | if (ACPI_FAILURE(status)) { |
| 486 | err = -EIO; |
| 487 | goto err_free_keymap; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 488 | } |
| 489 | |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 490 | err = input_register_device(hp_wmi_input_dev); |
| 491 | if (err) |
| 492 | goto err_uninstall_notifier; |
| 493 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 494 | return 0; |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 495 | |
| 496 | err_uninstall_notifier: |
| 497 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); |
| 498 | err_free_keymap: |
| 499 | sparse_keymap_free(hp_wmi_input_dev); |
| 500 | err_free_dev: |
| 501 | input_free_device(hp_wmi_input_dev); |
| 502 | return err; |
| 503 | } |
| 504 | |
| 505 | static void hp_wmi_input_destroy(void) |
| 506 | { |
| 507 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); |
| 508 | sparse_keymap_free(hp_wmi_input_dev); |
| 509 | input_unregister_device(hp_wmi_input_dev); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 510 | } |
| 511 | |
| 512 | static void cleanup_sysfs(struct platform_device *device) |
| 513 | { |
| 514 | device_remove_file(&device->dev, &dev_attr_display); |
| 515 | device_remove_file(&device->dev, &dev_attr_hddtemp); |
| 516 | device_remove_file(&device->dev, &dev_attr_als); |
| 517 | device_remove_file(&device->dev, &dev_attr_dock); |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 518 | device_remove_file(&device->dev, &dev_attr_tablet); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 519 | } |
| 520 | |
Uwe Kleine-König | ea79632 | 2010-02-04 20:56:52 +0100 | [diff] [blame] | 521 | static int __devinit hp_wmi_bios_setup(struct platform_device *device) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 522 | { |
| 523 | int err; |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 524 | int wireless = 0; |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 525 | |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 526 | err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, &wireless, |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 527 | sizeof(wireless)); |
| 528 | if (err) |
| 529 | return err; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 530 | |
| 531 | err = device_create_file(&device->dev, &dev_attr_display); |
| 532 | if (err) |
| 533 | goto add_sysfs_error; |
| 534 | err = device_create_file(&device->dev, &dev_attr_hddtemp); |
| 535 | if (err) |
| 536 | goto add_sysfs_error; |
| 537 | err = device_create_file(&device->dev, &dev_attr_als); |
| 538 | if (err) |
| 539 | goto add_sysfs_error; |
| 540 | err = device_create_file(&device->dev, &dev_attr_dock); |
| 541 | if (err) |
| 542 | goto add_sysfs_error; |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 543 | err = device_create_file(&device->dev, &dev_attr_tablet); |
| 544 | if (err) |
| 545 | goto add_sysfs_error; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 546 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 547 | if (wireless & 0x1) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 548 | wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev, |
| 549 | RFKILL_TYPE_WLAN, |
| 550 | &hp_wmi_rfkill_ops, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 551 | (void *) HPWMI_WIFI); |
| 552 | rfkill_init_sw_state(wifi_rfkill, |
| 553 | hp_wmi_get_sw_state(HPWMI_WIFI)); |
| 554 | rfkill_set_hw_state(wifi_rfkill, |
| 555 | hp_wmi_get_hw_state(HPWMI_WIFI)); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 556 | err = rfkill_register(wifi_rfkill); |
| 557 | if (err) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 558 | goto register_wifi_error; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 559 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 560 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 561 | if (wireless & 0x2) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 562 | bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev, |
| 563 | RFKILL_TYPE_BLUETOOTH, |
| 564 | &hp_wmi_rfkill_ops, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 565 | (void *) HPWMI_BLUETOOTH); |
| 566 | rfkill_init_sw_state(bluetooth_rfkill, |
| 567 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH)); |
| 568 | rfkill_set_hw_state(bluetooth_rfkill, |
| 569 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 570 | err = rfkill_register(bluetooth_rfkill); |
Frans Pop | 6989d56 | 2009-01-29 14:25:14 -0800 | [diff] [blame] | 571 | if (err) |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 572 | goto register_bluetooth_error; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 573 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 574 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 575 | if (wireless & 0x4) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 576 | wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev, |
| 577 | RFKILL_TYPE_WWAN, |
| 578 | &hp_wmi_rfkill_ops, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 579 | (void *) HPWMI_WWAN); |
| 580 | rfkill_init_sw_state(wwan_rfkill, |
| 581 | hp_wmi_get_sw_state(HPWMI_WWAN)); |
| 582 | rfkill_set_hw_state(wwan_rfkill, |
| 583 | hp_wmi_get_hw_state(HPWMI_WWAN)); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 584 | err = rfkill_register(wwan_rfkill); |
| 585 | if (err) |
| 586 | goto register_wwan_err; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 587 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 588 | |
| 589 | return 0; |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 590 | register_wwan_err: |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 591 | rfkill_destroy(wwan_rfkill); |
Andrew Morton | 44f0606 | 2009-02-04 15:12:07 -0800 | [diff] [blame] | 592 | if (bluetooth_rfkill) |
| 593 | rfkill_unregister(bluetooth_rfkill); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 594 | register_bluetooth_error: |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 595 | rfkill_destroy(bluetooth_rfkill); |
Andrew Morton | 44f0606 | 2009-02-04 15:12:07 -0800 | [diff] [blame] | 596 | if (wifi_rfkill) |
| 597 | rfkill_unregister(wifi_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 598 | register_wifi_error: |
| 599 | rfkill_destroy(wifi_rfkill); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 600 | add_sysfs_error: |
| 601 | cleanup_sysfs(device); |
| 602 | return err; |
| 603 | } |
| 604 | |
| 605 | static int __exit hp_wmi_bios_remove(struct platform_device *device) |
| 606 | { |
| 607 | cleanup_sysfs(device); |
| 608 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 609 | if (wifi_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 610 | rfkill_unregister(wifi_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 611 | rfkill_destroy(wifi_rfkill); |
| 612 | } |
| 613 | if (bluetooth_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 614 | rfkill_unregister(bluetooth_rfkill); |
Corentin Chary | 09729f0 | 2009-09-14 12:43:51 +0200 | [diff] [blame] | 615 | rfkill_destroy(bluetooth_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 616 | } |
| 617 | if (wwan_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 618 | rfkill_unregister(wwan_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 619 | rfkill_destroy(wwan_rfkill); |
| 620 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 621 | |
| 622 | return 0; |
| 623 | } |
| 624 | |
Frans Pop | 8dd2b42 | 2009-08-20 20:38:13 +0200 | [diff] [blame] | 625 | static int hp_wmi_resume_handler(struct device *device) |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 626 | { |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 627 | /* |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 628 | * Hardware state may have changed while suspended, so trigger |
| 629 | * input events for the current state. As this is a switch, |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 630 | * the input layer will only actually pass it on if the state |
| 631 | * changed. |
| 632 | */ |
Frans Pop | daed953 | 2009-07-30 17:16:05 -0400 | [diff] [blame] | 633 | if (hp_wmi_input_dev) { |
| 634 | input_report_switch(hp_wmi_input_dev, SW_DOCK, |
| 635 | hp_wmi_dock_state()); |
| 636 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
| 637 | hp_wmi_tablet_state()); |
| 638 | input_sync(hp_wmi_input_dev); |
| 639 | } |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 640 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 641 | if (wifi_rfkill) |
| 642 | rfkill_set_states(wifi_rfkill, |
| 643 | hp_wmi_get_sw_state(HPWMI_WIFI), |
| 644 | hp_wmi_get_hw_state(HPWMI_WIFI)); |
| 645 | if (bluetooth_rfkill) |
| 646 | rfkill_set_states(bluetooth_rfkill, |
| 647 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH), |
| 648 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); |
| 649 | if (wwan_rfkill) |
| 650 | rfkill_set_states(wwan_rfkill, |
| 651 | hp_wmi_get_sw_state(HPWMI_WWAN), |
| 652 | hp_wmi_get_hw_state(HPWMI_WWAN)); |
| 653 | |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 654 | return 0; |
| 655 | } |
| 656 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 657 | static int __init hp_wmi_init(void) |
| 658 | { |
| 659 | int err; |
Thomas Renninger | b096667 | 2010-07-20 15:19:29 -0700 | [diff] [blame] | 660 | int event_capable = wmi_has_guid(HPWMI_EVENT_GUID); |
| 661 | int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 662 | |
Thomas Renninger | b096667 | 2010-07-20 15:19:29 -0700 | [diff] [blame] | 663 | if (event_capable) { |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 664 | err = hp_wmi_input_setup(); |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 665 | if (err) |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 666 | return err; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 667 | } |
| 668 | |
Thomas Renninger | b096667 | 2010-07-20 15:19:29 -0700 | [diff] [blame] | 669 | if (bios_capable) { |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 670 | err = platform_driver_register(&hp_wmi_driver); |
| 671 | if (err) |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 672 | goto err_driver_reg; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 673 | hp_wmi_platform_dev = platform_device_alloc("hp-wmi", -1); |
| 674 | if (!hp_wmi_platform_dev) { |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 675 | err = -ENOMEM; |
| 676 | goto err_device_alloc; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 677 | } |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 678 | err = platform_device_add(hp_wmi_platform_dev); |
| 679 | if (err) |
| 680 | goto err_device_add; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Thomas Renninger | b096667 | 2010-07-20 15:19:29 -0700 | [diff] [blame] | 683 | if (!bios_capable && !event_capable) |
| 684 | return -ENODEV; |
| 685 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 686 | return 0; |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 687 | |
| 688 | err_device_add: |
| 689 | platform_device_put(hp_wmi_platform_dev); |
| 690 | err_device_alloc: |
| 691 | platform_driver_unregister(&hp_wmi_driver); |
| 692 | err_driver_reg: |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 693 | if (event_capable) |
| 694 | hp_wmi_input_destroy(); |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 695 | |
| 696 | return err; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 697 | } |
| 698 | |
| 699 | static void __exit hp_wmi_exit(void) |
| 700 | { |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 701 | if (wmi_has_guid(HPWMI_EVENT_GUID)) |
| 702 | hp_wmi_input_destroy(); |
| 703 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 704 | if (hp_wmi_platform_dev) { |
Axel Lin | 97ba0af | 2010-06-03 15:18:03 +0800 | [diff] [blame] | 705 | platform_device_unregister(hp_wmi_platform_dev); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 706 | platform_driver_unregister(&hp_wmi_driver); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | module_init(hp_wmi_init); |
| 711 | module_exit(hp_wmi_exit); |