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