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> |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 5 | * Copyright (C) 2010, 2011 Anssi Hannula <anssi.hannula@iki.fi> |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 6 | * |
| 7 | * Portions based on wistron_btns.c: |
| 8 | * Copyright (C) 2005 Miloslav Trmac <mitr@volny.cz> |
| 9 | * Copyright (C) 2005 Bernhard Rosenkraenzer <bero@arklinux.org> |
| 10 | * Copyright (C) 2005 Dmitry Torokhov <dtor@mail.ru> |
| 11 | * |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; either version 2 of the License, or |
| 15 | * (at your option) any later version. |
| 16 | * |
| 17 | * This program is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 20 | * GNU General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU General Public License |
| 23 | * along with this program; if not, write to the Free Software |
| 24 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 25 | */ |
| 26 | |
Joe Perches | b5a4223 | 2011-03-29 15:21:41 -0700 | [diff] [blame] | 27 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 28 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 29 | #include <linux/kernel.h> |
| 30 | #include <linux/module.h> |
| 31 | #include <linux/init.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 33 | #include <linux/types.h> |
| 34 | #include <linux/input.h> |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 35 | #include <linux/input/sparse-keymap.h> |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 36 | #include <linux/platform_device.h> |
| 37 | #include <linux/acpi.h> |
| 38 | #include <linux/rfkill.h> |
| 39 | #include <linux/string.h> |
| 40 | |
| 41 | MODULE_AUTHOR("Matthew Garrett <mjg59@srcf.ucam.org>"); |
| 42 | MODULE_DESCRIPTION("HP laptop WMI hotkeys driver"); |
| 43 | MODULE_LICENSE("GPL"); |
| 44 | |
| 45 | MODULE_ALIAS("wmi:95F24279-4D7B-4334-9387-ACCDC67EF61C"); |
| 46 | MODULE_ALIAS("wmi:5FB7F034-2C63-45e9-BE91-3D44E2C707E4"); |
| 47 | |
| 48 | #define HPWMI_EVENT_GUID "95F24279-4D7B-4334-9387-ACCDC67EF61C" |
| 49 | #define HPWMI_BIOS_GUID "5FB7F034-2C63-45e9-BE91-3D44E2C707E4" |
| 50 | |
| 51 | #define HPWMI_DISPLAY_QUERY 0x1 |
| 52 | #define HPWMI_HDDTEMP_QUERY 0x2 |
| 53 | #define HPWMI_ALS_QUERY 0x3 |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 54 | #define HPWMI_HARDWARE_QUERY 0x4 |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 55 | #define HPWMI_WIRELESS_QUERY 0x5 |
Matthew Garrett | b253c9d | 2013-07-08 11:44:40 -0400 | [diff] [blame^] | 56 | #define HPWMI_BIOS_QUERY 0x9 |
Matthew Garrett | a8823ae | 2008-09-02 14:36:03 -0700 | [diff] [blame] | 57 | #define HPWMI_HOTKEY_QUERY 0xc |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 58 | #define HPWMI_WIRELESS2_QUERY 0x1b |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 59 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 60 | enum hp_wmi_radio { |
| 61 | HPWMI_WIFI = 0, |
| 62 | HPWMI_BLUETOOTH = 1, |
| 63 | HPWMI_WWAN = 2, |
Trepák Vilmos | 4fca7ce | 2012-10-11 12:51:00 +0200 | [diff] [blame] | 64 | HPWMI_GPS = 3, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 65 | }; |
| 66 | |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 67 | enum hp_wmi_event_ids { |
| 68 | HPWMI_DOCK_EVENT = 1, |
Thomas Renninger | 1bbdfd5 | 2010-05-21 16:18:13 +0200 | [diff] [blame] | 69 | HPWMI_PARK_HDD = 2, |
| 70 | HPWMI_SMART_ADAPTER = 3, |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 71 | HPWMI_BEZEL_BUTTON = 4, |
| 72 | HPWMI_WIRELESS = 5, |
Thomas Renninger | 1bbdfd5 | 2010-05-21 16:18:13 +0200 | [diff] [blame] | 73 | HPWMI_CPU_BATTERY_THROTTLE = 6, |
| 74 | HPWMI_LOCK_SWITCH = 7, |
Alex Hung | d9e290a | 2013-03-15 17:18:22 +0800 | [diff] [blame] | 75 | HPWMI_LID_SWITCH = 8, |
| 76 | HPWMI_SCREEN_ROTATION = 9, |
| 77 | HPWMI_COOLSENSE_SYSTEM_MOBILE = 0x0A, |
| 78 | HPWMI_COOLSENSE_SYSTEM_HOT = 0x0B, |
| 79 | HPWMI_PROXIMITY_SENSOR = 0x0C, |
| 80 | HPWMI_BACKLIT_KB_BRIGHTNESS = 0x0D, |
| 81 | HPWMI_PEAKSHIFT_PERIOD = 0x0F, |
| 82 | HPWMI_BATTERY_CHARGE_PERIOD = 0x10, |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 83 | }; |
| 84 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 85 | struct bios_args { |
| 86 | u32 signature; |
| 87 | u32 command; |
| 88 | u32 commandtype; |
| 89 | u32 datasize; |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 90 | u32 data; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 91 | }; |
| 92 | |
| 93 | struct bios_return { |
| 94 | u32 sigpass; |
| 95 | u32 return_code; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 96 | }; |
| 97 | |
Anssi Hannula | 9af0e0f | 2011-02-20 20:07:20 +0200 | [diff] [blame] | 98 | enum hp_return_value { |
| 99 | HPWMI_RET_WRONG_SIGNATURE = 0x02, |
| 100 | HPWMI_RET_UNKNOWN_COMMAND = 0x03, |
| 101 | HPWMI_RET_UNKNOWN_CMDTYPE = 0x04, |
| 102 | HPWMI_RET_INVALID_PARAMETERS = 0x05, |
| 103 | }; |
| 104 | |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 105 | enum hp_wireless2_bits { |
| 106 | HPWMI_POWER_STATE = 0x01, |
| 107 | HPWMI_POWER_SOFT = 0x02, |
| 108 | HPWMI_POWER_BIOS = 0x04, |
| 109 | HPWMI_POWER_HARD = 0x08, |
| 110 | }; |
| 111 | |
| 112 | #define IS_HWBLOCKED(x) ((x & (HPWMI_POWER_BIOS | HPWMI_POWER_HARD)) \ |
| 113 | != (HPWMI_POWER_BIOS | HPWMI_POWER_HARD)) |
| 114 | #define IS_SWBLOCKED(x) !(x & HPWMI_POWER_SOFT) |
| 115 | |
| 116 | struct bios_rfkill2_device_state { |
| 117 | u8 radio_type; |
| 118 | u8 bus_type; |
| 119 | u16 vendor_id; |
| 120 | u16 product_id; |
| 121 | u16 subsys_vendor_id; |
| 122 | u16 subsys_product_id; |
| 123 | u8 rfkill_id; |
| 124 | u8 power; |
| 125 | u8 unknown[4]; |
| 126 | }; |
| 127 | |
| 128 | /* 7 devices fit into the 128 byte buffer */ |
| 129 | #define HPWMI_MAX_RFKILL2_DEVICES 7 |
| 130 | |
| 131 | struct bios_rfkill2_state { |
| 132 | u8 unknown[7]; |
| 133 | u8 count; |
| 134 | u8 pad[8]; |
| 135 | struct bios_rfkill2_device_state device[HPWMI_MAX_RFKILL2_DEVICES]; |
| 136 | }; |
| 137 | |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 138 | static const struct key_entry hp_wmi_keymap[] = { |
| 139 | { KE_KEY, 0x02, { KEY_BRIGHTNESSUP } }, |
| 140 | { KE_KEY, 0x03, { KEY_BRIGHTNESSDOWN } }, |
| 141 | { KE_KEY, 0x20e6, { KEY_PROG1 } }, |
| 142 | { KE_KEY, 0x20e8, { KEY_MEDIA } }, |
| 143 | { KE_KEY, 0x2142, { KEY_MEDIA } }, |
| 144 | { KE_KEY, 0x213b, { KEY_INFO } }, |
| 145 | { KE_KEY, 0x2169, { KEY_DIRECTION } }, |
| 146 | { KE_KEY, 0x231b, { KEY_HELP } }, |
| 147 | { KE_END, 0 } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 148 | }; |
| 149 | |
| 150 | static struct input_dev *hp_wmi_input_dev; |
| 151 | static struct platform_device *hp_wmi_platform_dev; |
| 152 | |
| 153 | static struct rfkill *wifi_rfkill; |
| 154 | static struct rfkill *bluetooth_rfkill; |
| 155 | static struct rfkill *wwan_rfkill; |
Trepák Vilmos | 4fca7ce | 2012-10-11 12:51:00 +0200 | [diff] [blame] | 156 | static struct rfkill *gps_rfkill; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 157 | |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 158 | struct rfkill2_device { |
| 159 | u8 id; |
| 160 | int num; |
| 161 | struct rfkill *rfkill; |
| 162 | }; |
| 163 | |
| 164 | static int rfkill2_count; |
| 165 | static struct rfkill2_device rfkill2[HPWMI_MAX_RFKILL2_DEVICES]; |
| 166 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 167 | /* |
| 168 | * hp_wmi_perform_query |
| 169 | * |
| 170 | * query: The commandtype -> What should be queried |
| 171 | * write: The command -> 0 read, 1 write, 3 ODM specific |
| 172 | * buffer: Buffer used as input and/or output |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 173 | * insize: Size of input buffer |
| 174 | * outsize: Size of output buffer |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 175 | * |
| 176 | * returns zero on success |
| 177 | * an HP WMI query specific error code (which is positive) |
| 178 | * -EINVAL if the query was not successful at all |
| 179 | * -EINVAL if the output buffer size exceeds buffersize |
| 180 | * |
| 181 | * Note: The buffersize must at least be the maximum of the input and output |
| 182 | * size. E.g. Battery info query (0x7) is defined to have 1 byte input |
| 183 | * and 128 byte output. The caller would do: |
| 184 | * buffer = kzalloc(128, GFP_KERNEL); |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 185 | * ret = hp_wmi_perform_query(0x7, 0, buffer, 1, 128) |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 186 | */ |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 187 | static int hp_wmi_perform_query(int query, int write, void *buffer, |
| 188 | int insize, int outsize) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 189 | { |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 190 | struct bios_return *bios_return; |
| 191 | int actual_outsize; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 192 | union acpi_object *obj; |
| 193 | struct bios_args args = { |
| 194 | .signature = 0x55434553, |
| 195 | .command = write ? 0x2 : 0x1, |
| 196 | .commandtype = query, |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 197 | .datasize = insize, |
| 198 | .data = 0, |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 199 | }; |
| 200 | struct acpi_buffer input = { sizeof(struct bios_args), &args }; |
| 201 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
Eric Dumazet | 0401846 | 2011-07-11 12:22:21 +0200 | [diff] [blame] | 202 | u32 rc; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 203 | |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 204 | if (WARN_ON(insize > sizeof(args.data))) |
| 205 | return -EINVAL; |
| 206 | memcpy(&args.data, buffer, insize); |
| 207 | |
Anssi Hannula | 25bb067 | 2011-02-20 20:07:21 +0200 | [diff] [blame] | 208 | wmi_evaluate_method(HPWMI_BIOS_GUID, 0, 0x3, &input, &output); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 209 | |
| 210 | obj = output.pointer; |
| 211 | |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 212 | if (!obj) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 213 | return -EINVAL; |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 214 | else if (obj->type != ACPI_TYPE_BUFFER) { |
| 215 | kfree(obj); |
| 216 | return -EINVAL; |
| 217 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 218 | |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 219 | bios_return = (struct bios_return *)obj->buffer.pointer; |
Eric Dumazet | 0401846 | 2011-07-11 12:22:21 +0200 | [diff] [blame] | 220 | rc = bios_return->return_code; |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 221 | |
Eric Dumazet | 0401846 | 2011-07-11 12:22:21 +0200 | [diff] [blame] | 222 | if (rc) { |
| 223 | if (rc != HPWMI_RET_UNKNOWN_CMDTYPE) |
| 224 | pr_warn("query 0x%x returned error 0x%x\n", query, rc); |
Anssi Hannula | 9af0e0f | 2011-02-20 20:07:20 +0200 | [diff] [blame] | 225 | kfree(obj); |
Eric Dumazet | 0401846 | 2011-07-11 12:22:21 +0200 | [diff] [blame] | 226 | return rc; |
Anssi Hannula | 9af0e0f | 2011-02-20 20:07:20 +0200 | [diff] [blame] | 227 | } |
| 228 | |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 229 | if (!outsize) { |
| 230 | /* ignore output data */ |
| 231 | kfree(obj); |
| 232 | return 0; |
| 233 | } |
Zeng Zhaoming | 53c96df | 2010-11-19 00:46:19 +0800 | [diff] [blame] | 234 | |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 235 | actual_outsize = min(outsize, (int)(obj->buffer.length - sizeof(*bios_return))); |
| 236 | memcpy(buffer, obj->buffer.pointer + sizeof(*bios_return), actual_outsize); |
| 237 | memset(buffer + actual_outsize, 0, outsize - actual_outsize); |
Zeng Zhaoming | 53c96df | 2010-11-19 00:46:19 +0800 | [diff] [blame] | 238 | kfree(obj); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 239 | return 0; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 240 | } |
| 241 | |
| 242 | static int hp_wmi_display_state(void) |
| 243 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 244 | int state = 0; |
| 245 | int ret = hp_wmi_perform_query(HPWMI_DISPLAY_QUERY, 0, &state, |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 246 | sizeof(state), sizeof(state)); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 247 | if (ret) |
| 248 | return -EINVAL; |
| 249 | return state; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | static int hp_wmi_hddtemp_state(void) |
| 253 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 254 | int state = 0; |
| 255 | int ret = hp_wmi_perform_query(HPWMI_HDDTEMP_QUERY, 0, &state, |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 256 | sizeof(state), sizeof(state)); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 257 | if (ret) |
| 258 | return -EINVAL; |
| 259 | return state; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 260 | } |
| 261 | |
| 262 | static int hp_wmi_als_state(void) |
| 263 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 264 | int state = 0; |
| 265 | int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 0, &state, |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 266 | sizeof(state), sizeof(state)); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 267 | if (ret) |
| 268 | return -EINVAL; |
| 269 | return state; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | static int hp_wmi_dock_state(void) |
| 273 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 274 | int state = 0; |
| 275 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state, |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 276 | sizeof(state), sizeof(state)); |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 277 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 278 | if (ret) |
| 279 | return -EINVAL; |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 280 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 281 | return state & 0x1; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 282 | } |
| 283 | |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 284 | static int hp_wmi_tablet_state(void) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 285 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 286 | int state = 0; |
| 287 | int ret = hp_wmi_perform_query(HPWMI_HARDWARE_QUERY, 0, &state, |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 288 | sizeof(state), sizeof(state)); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 289 | if (ret) |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 290 | return ret; |
| 291 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 292 | return (state & 0x4) ? 1 : 0; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 293 | } |
| 294 | |
Matthew Garrett | b253c9d | 2013-07-08 11:44:40 -0400 | [diff] [blame^] | 295 | static int hp_wmi_enable_hotkeys(void) |
| 296 | { |
| 297 | int ret; |
| 298 | int query = 0x6e; |
| 299 | |
| 300 | ret = hp_wmi_perform_query(HPWMI_BIOS_QUERY, 1, &query, sizeof(query), |
| 301 | 0); |
| 302 | |
| 303 | if (ret) |
| 304 | return -EINVAL; |
| 305 | return 0; |
| 306 | } |
| 307 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 308 | static int hp_wmi_set_block(void *data, bool blocked) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 309 | { |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 310 | enum hp_wmi_radio r = (enum hp_wmi_radio) data; |
| 311 | int query = BIT(r + 8) | ((!blocked) << r); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 312 | int ret; |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 313 | |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 314 | ret = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 1, |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 315 | &query, sizeof(query), 0); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 316 | if (ret) |
| 317 | return -EINVAL; |
| 318 | return 0; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 319 | } |
| 320 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 321 | static const struct rfkill_ops hp_wmi_rfkill_ops = { |
| 322 | .set_block = hp_wmi_set_block, |
| 323 | }; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 324 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 325 | static bool hp_wmi_get_sw_state(enum hp_wmi_radio r) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 326 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 327 | int wireless = 0; |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 328 | int mask; |
| 329 | hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 330 | &wireless, sizeof(wireless), |
| 331 | sizeof(wireless)); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 332 | /* TBD: Pass error */ |
| 333 | |
| 334 | mask = 0x200 << (r * 8); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 335 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 336 | if (wireless & mask) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 337 | return false; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 338 | else |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 339 | return true; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 342 | static bool hp_wmi_get_hw_state(enum hp_wmi_radio r) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 343 | { |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 344 | int wireless = 0; |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 345 | int mask; |
| 346 | hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 347 | &wireless, sizeof(wireless), |
| 348 | sizeof(wireless)); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 349 | /* TBD: Pass error */ |
| 350 | |
| 351 | mask = 0x800 << (r * 8); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 352 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 353 | if (wireless & mask) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 354 | return false; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 355 | else |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 356 | return true; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 357 | } |
| 358 | |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 359 | static int hp_wmi_rfkill2_set_block(void *data, bool blocked) |
| 360 | { |
| 361 | int rfkill_id = (int)(long)data; |
| 362 | char buffer[4] = { 0x01, 0x00, rfkill_id, !blocked }; |
| 363 | |
| 364 | if (hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, 1, |
| 365 | buffer, sizeof(buffer), 0)) |
| 366 | return -EINVAL; |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | static const struct rfkill_ops hp_wmi_rfkill2_ops = { |
| 371 | .set_block = hp_wmi_rfkill2_set_block, |
| 372 | }; |
| 373 | |
| 374 | static int hp_wmi_rfkill2_refresh(void) |
| 375 | { |
| 376 | int err, i; |
| 377 | struct bios_rfkill2_state state; |
| 378 | |
| 379 | err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, 0, &state, |
| 380 | 0, sizeof(state)); |
| 381 | if (err) |
| 382 | return err; |
| 383 | |
| 384 | for (i = 0; i < rfkill2_count; i++) { |
| 385 | int num = rfkill2[i].num; |
| 386 | struct bios_rfkill2_device_state *devstate; |
| 387 | devstate = &state.device[num]; |
| 388 | |
| 389 | if (num >= state.count || |
| 390 | devstate->rfkill_id != rfkill2[i].id) { |
Joe Perches | b5a4223 | 2011-03-29 15:21:41 -0700 | [diff] [blame] | 391 | pr_warn("power configuration of the wireless devices unexpectedly changed\n"); |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 392 | continue; |
| 393 | } |
| 394 | |
| 395 | rfkill_set_states(rfkill2[i].rfkill, |
| 396 | IS_SWBLOCKED(devstate->power), |
| 397 | IS_HWBLOCKED(devstate->power)); |
| 398 | } |
| 399 | |
| 400 | return 0; |
| 401 | } |
| 402 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 403 | static ssize_t show_display(struct device *dev, struct device_attribute *attr, |
| 404 | char *buf) |
| 405 | { |
| 406 | int value = hp_wmi_display_state(); |
| 407 | if (value < 0) |
| 408 | return -EINVAL; |
| 409 | return sprintf(buf, "%d\n", value); |
| 410 | } |
| 411 | |
| 412 | static ssize_t show_hddtemp(struct device *dev, struct device_attribute *attr, |
| 413 | char *buf) |
| 414 | { |
| 415 | int value = hp_wmi_hddtemp_state(); |
| 416 | if (value < 0) |
| 417 | return -EINVAL; |
| 418 | return sprintf(buf, "%d\n", value); |
| 419 | } |
| 420 | |
| 421 | static ssize_t show_als(struct device *dev, struct device_attribute *attr, |
| 422 | char *buf) |
| 423 | { |
| 424 | int value = hp_wmi_als_state(); |
| 425 | if (value < 0) |
| 426 | return -EINVAL; |
| 427 | return sprintf(buf, "%d\n", value); |
| 428 | } |
| 429 | |
| 430 | static ssize_t show_dock(struct device *dev, struct device_attribute *attr, |
| 431 | char *buf) |
| 432 | { |
| 433 | int value = hp_wmi_dock_state(); |
| 434 | if (value < 0) |
| 435 | return -EINVAL; |
| 436 | return sprintf(buf, "%d\n", value); |
| 437 | } |
| 438 | |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 439 | static ssize_t show_tablet(struct device *dev, struct device_attribute *attr, |
| 440 | char *buf) |
| 441 | { |
| 442 | int value = hp_wmi_tablet_state(); |
| 443 | if (value < 0) |
| 444 | return -EINVAL; |
| 445 | return sprintf(buf, "%d\n", value); |
| 446 | } |
| 447 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 448 | static ssize_t set_als(struct device *dev, struct device_attribute *attr, |
| 449 | const char *buf, size_t count) |
| 450 | { |
| 451 | u32 tmp = simple_strtoul(buf, NULL, 10); |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 452 | int ret = hp_wmi_perform_query(HPWMI_ALS_QUERY, 1, &tmp, |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 453 | sizeof(tmp), sizeof(tmp)); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 454 | if (ret) |
| 455 | return -EINVAL; |
| 456 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 457 | return count; |
| 458 | } |
| 459 | |
| 460 | static DEVICE_ATTR(display, S_IRUGO, show_display, NULL); |
| 461 | static DEVICE_ATTR(hddtemp, S_IRUGO, show_hddtemp, NULL); |
| 462 | static DEVICE_ATTR(als, S_IRUGO | S_IWUSR, show_als, set_als); |
| 463 | static DEVICE_ATTR(dock, S_IRUGO, show_dock, NULL); |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 464 | static DEVICE_ATTR(tablet, S_IRUGO, show_tablet, NULL); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 465 | |
Adrian Bunk | 88429a1 | 2008-10-15 22:05:17 -0700 | [diff] [blame] | 466 | static void hp_wmi_notify(u32 value, void *context) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 467 | { |
| 468 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 469 | union acpi_object *obj; |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 470 | u32 event_id, event_data; |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 471 | int key_code = 0, ret; |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 472 | u32 *location; |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 473 | acpi_status status; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 474 | |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 475 | status = wmi_get_event_data(value, &response); |
| 476 | if (status != AE_OK) { |
Joe Perches | b5a4223 | 2011-03-29 15:21:41 -0700 | [diff] [blame] | 477 | pr_info("bad event status 0x%x\n", status); |
Len Brown | fda11e6 | 2009-12-26 23:02:24 -0500 | [diff] [blame] | 478 | return; |
| 479 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 480 | |
| 481 | obj = (union acpi_object *)response.pointer; |
| 482 | |
Thomas Renninger | c477506 | 2010-07-29 12:27:59 +0200 | [diff] [blame] | 483 | if (!obj) |
| 484 | return; |
| 485 | if (obj->type != ACPI_TYPE_BUFFER) { |
Joe Perches | b5a4223 | 2011-03-29 15:21:41 -0700 | [diff] [blame] | 486 | pr_info("Unknown response received %d\n", obj->type); |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 487 | kfree(obj); |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 488 | return; |
| 489 | } |
| 490 | |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 491 | /* |
| 492 | * Depending on ACPI version the concatenation of id and event data |
| 493 | * inside _WED function will result in a 8 or 16 byte buffer. |
| 494 | */ |
| 495 | location = (u32 *)obj->buffer.pointer; |
| 496 | if (obj->buffer.length == 8) { |
| 497 | event_id = *location; |
| 498 | event_data = *(location + 1); |
| 499 | } else if (obj->buffer.length == 16) { |
| 500 | event_id = *location; |
| 501 | event_data = *(location + 2); |
| 502 | } else { |
Joe Perches | b5a4223 | 2011-03-29 15:21:41 -0700 | [diff] [blame] | 503 | pr_info("Unknown buffer length %d\n", obj->buffer.length); |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 504 | kfree(obj); |
| 505 | return; |
| 506 | } |
Thomas Renninger | 44ef00e | 2009-12-18 15:29:23 +0100 | [diff] [blame] | 507 | kfree(obj); |
Thomas Renninger | 8dda6b0 | 2010-05-21 16:41:43 +0200 | [diff] [blame] | 508 | |
| 509 | switch (event_id) { |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 510 | case HPWMI_DOCK_EVENT: |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 511 | input_report_switch(hp_wmi_input_dev, SW_DOCK, |
| 512 | hp_wmi_dock_state()); |
| 513 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
| 514 | hp_wmi_tablet_state()); |
| 515 | input_sync(hp_wmi_input_dev); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 516 | break; |
Thomas Renninger | 1bbdfd5 | 2010-05-21 16:18:13 +0200 | [diff] [blame] | 517 | case HPWMI_PARK_HDD: |
| 518 | break; |
| 519 | case HPWMI_SMART_ADAPTER: |
| 520 | break; |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 521 | case HPWMI_BEZEL_BUTTON: |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 522 | ret = hp_wmi_perform_query(HPWMI_HOTKEY_QUERY, 0, |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 523 | &key_code, |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 524 | sizeof(key_code), |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 525 | sizeof(key_code)); |
| 526 | if (ret) |
| 527 | break; |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 528 | |
| 529 | if (!sparse_keymap_report_event(hp_wmi_input_dev, |
| 530 | key_code, 1, true)) |
Joe Perches | b5a4223 | 2011-03-29 15:21:41 -0700 | [diff] [blame] | 531 | pr_info("Unknown key code - 0x%x\n", key_code); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 532 | break; |
| 533 | case HPWMI_WIRELESS: |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 534 | if (rfkill2_count) { |
| 535 | hp_wmi_rfkill2_refresh(); |
| 536 | break; |
| 537 | } |
| 538 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 539 | if (wifi_rfkill) |
| 540 | rfkill_set_states(wifi_rfkill, |
| 541 | hp_wmi_get_sw_state(HPWMI_WIFI), |
| 542 | hp_wmi_get_hw_state(HPWMI_WIFI)); |
| 543 | if (bluetooth_rfkill) |
| 544 | rfkill_set_states(bluetooth_rfkill, |
| 545 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH), |
| 546 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); |
| 547 | if (wwan_rfkill) |
| 548 | rfkill_set_states(wwan_rfkill, |
| 549 | hp_wmi_get_sw_state(HPWMI_WWAN), |
| 550 | hp_wmi_get_hw_state(HPWMI_WWAN)); |
Trepák Vilmos | 4fca7ce | 2012-10-11 12:51:00 +0200 | [diff] [blame] | 551 | if (gps_rfkill) |
| 552 | rfkill_set_states(gps_rfkill, |
| 553 | hp_wmi_get_sw_state(HPWMI_GPS), |
| 554 | hp_wmi_get_hw_state(HPWMI_GPS)); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 555 | break; |
Thomas Renninger | 1bbdfd5 | 2010-05-21 16:18:13 +0200 | [diff] [blame] | 556 | case HPWMI_CPU_BATTERY_THROTTLE: |
Joe Perches | b5a4223 | 2011-03-29 15:21:41 -0700 | [diff] [blame] | 557 | pr_info("Unimplemented CPU throttle because of 3 Cell battery event detected\n"); |
Thomas Renninger | 1bbdfd5 | 2010-05-21 16:18:13 +0200 | [diff] [blame] | 558 | break; |
| 559 | case HPWMI_LOCK_SWITCH: |
| 560 | break; |
Alex Hung | d9e290a | 2013-03-15 17:18:22 +0800 | [diff] [blame] | 561 | case HPWMI_LID_SWITCH: |
| 562 | break; |
| 563 | case HPWMI_SCREEN_ROTATION: |
| 564 | break; |
| 565 | case HPWMI_COOLSENSE_SYSTEM_MOBILE: |
| 566 | break; |
| 567 | case HPWMI_COOLSENSE_SYSTEM_HOT: |
| 568 | break; |
| 569 | case HPWMI_PROXIMITY_SENSOR: |
| 570 | break; |
| 571 | case HPWMI_BACKLIT_KB_BRIGHTNESS: |
| 572 | break; |
| 573 | case HPWMI_PEAKSHIFT_PERIOD: |
| 574 | break; |
| 575 | case HPWMI_BATTERY_CHARGE_PERIOD: |
| 576 | break; |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 577 | default: |
Joe Perches | b5a4223 | 2011-03-29 15:21:41 -0700 | [diff] [blame] | 578 | pr_info("Unknown event_id - %d - 0x%x\n", event_id, event_data); |
Thomas Renninger | 751ae80 | 2010-05-21 16:18:09 +0200 | [diff] [blame] | 579 | break; |
| 580 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | static int __init hp_wmi_input_setup(void) |
| 584 | { |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 585 | acpi_status status; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 586 | int err; |
| 587 | |
| 588 | hp_wmi_input_dev = input_allocate_device(); |
Axel Lin | bc28596 | 2010-07-20 15:19:51 -0700 | [diff] [blame] | 589 | if (!hp_wmi_input_dev) |
| 590 | return -ENOMEM; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 591 | |
| 592 | hp_wmi_input_dev->name = "HP WMI hotkeys"; |
| 593 | hp_wmi_input_dev->phys = "wmi/input0"; |
| 594 | hp_wmi_input_dev->id.bustype = BUS_HOST; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 595 | |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 596 | __set_bit(EV_SW, hp_wmi_input_dev->evbit); |
| 597 | __set_bit(SW_DOCK, hp_wmi_input_dev->swbit); |
| 598 | __set_bit(SW_TABLET_MODE, hp_wmi_input_dev->swbit); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 599 | |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 600 | err = sparse_keymap_setup(hp_wmi_input_dev, hp_wmi_keymap, NULL); |
| 601 | if (err) |
| 602 | goto err_free_dev; |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 603 | |
| 604 | /* Set initial hardware state */ |
| 605 | input_report_switch(hp_wmi_input_dev, SW_DOCK, hp_wmi_dock_state()); |
| 606 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
| 607 | hp_wmi_tablet_state()); |
| 608 | input_sync(hp_wmi_input_dev); |
| 609 | |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 610 | status = wmi_install_notify_handler(HPWMI_EVENT_GUID, hp_wmi_notify, NULL); |
| 611 | if (ACPI_FAILURE(status)) { |
| 612 | err = -EIO; |
| 613 | goto err_free_keymap; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 616 | err = input_register_device(hp_wmi_input_dev); |
| 617 | if (err) |
| 618 | goto err_uninstall_notifier; |
| 619 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 620 | return 0; |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 621 | |
| 622 | err_uninstall_notifier: |
| 623 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); |
| 624 | err_free_keymap: |
| 625 | sparse_keymap_free(hp_wmi_input_dev); |
| 626 | err_free_dev: |
| 627 | input_free_device(hp_wmi_input_dev); |
| 628 | return err; |
| 629 | } |
| 630 | |
| 631 | static void hp_wmi_input_destroy(void) |
| 632 | { |
| 633 | wmi_remove_notify_handler(HPWMI_EVENT_GUID); |
| 634 | sparse_keymap_free(hp_wmi_input_dev); |
| 635 | input_unregister_device(hp_wmi_input_dev); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 636 | } |
| 637 | |
| 638 | static void cleanup_sysfs(struct platform_device *device) |
| 639 | { |
| 640 | device_remove_file(&device->dev, &dev_attr_display); |
| 641 | device_remove_file(&device->dev, &dev_attr_hddtemp); |
| 642 | device_remove_file(&device->dev, &dev_attr_als); |
| 643 | device_remove_file(&device->dev, &dev_attr_dock); |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 644 | device_remove_file(&device->dev, &dev_attr_tablet); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 645 | } |
| 646 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 647 | static int hp_wmi_rfkill_setup(struct platform_device *device) |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 648 | { |
| 649 | int err; |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 650 | int wireless = 0; |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 651 | |
Matthew Garrett | a8ec105 | 2010-08-23 15:52:34 -0400 | [diff] [blame] | 652 | err = hp_wmi_perform_query(HPWMI_WIRELESS_QUERY, 0, &wireless, |
Anssi Hannula | c3021ea | 2011-02-20 20:07:22 +0200 | [diff] [blame] | 653 | sizeof(wireless), sizeof(wireless)); |
Thomas Renninger | 6d96e00 | 2010-05-21 16:42:40 +0200 | [diff] [blame] | 654 | if (err) |
| 655 | return err; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 656 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 657 | if (wireless & 0x1) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 658 | wifi_rfkill = rfkill_alloc("hp-wifi", &device->dev, |
| 659 | RFKILL_TYPE_WLAN, |
| 660 | &hp_wmi_rfkill_ops, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 661 | (void *) HPWMI_WIFI); |
Dan Carpenter | dd258c0 | 2012-05-17 09:48:12 +0300 | [diff] [blame] | 662 | if (!wifi_rfkill) |
| 663 | return -ENOMEM; |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 664 | rfkill_init_sw_state(wifi_rfkill, |
| 665 | hp_wmi_get_sw_state(HPWMI_WIFI)); |
| 666 | rfkill_set_hw_state(wifi_rfkill, |
| 667 | hp_wmi_get_hw_state(HPWMI_WIFI)); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 668 | err = rfkill_register(wifi_rfkill); |
| 669 | if (err) |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 670 | goto register_wifi_error; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 671 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 672 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 673 | if (wireless & 0x2) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 674 | bluetooth_rfkill = rfkill_alloc("hp-bluetooth", &device->dev, |
| 675 | RFKILL_TYPE_BLUETOOTH, |
| 676 | &hp_wmi_rfkill_ops, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 677 | (void *) HPWMI_BLUETOOTH); |
Dan Carpenter | dd258c0 | 2012-05-17 09:48:12 +0300 | [diff] [blame] | 678 | if (!bluetooth_rfkill) { |
| 679 | err = -ENOMEM; |
| 680 | goto register_wifi_error; |
| 681 | } |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 682 | rfkill_init_sw_state(bluetooth_rfkill, |
| 683 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH)); |
| 684 | rfkill_set_hw_state(bluetooth_rfkill, |
| 685 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 686 | err = rfkill_register(bluetooth_rfkill); |
Frans Pop | 6989d56 | 2009-01-29 14:25:14 -0800 | [diff] [blame] | 687 | if (err) |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 688 | goto register_bluetooth_error; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 689 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 690 | |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 691 | if (wireless & 0x4) { |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 692 | wwan_rfkill = rfkill_alloc("hp-wwan", &device->dev, |
| 693 | RFKILL_TYPE_WWAN, |
| 694 | &hp_wmi_rfkill_ops, |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 695 | (void *) HPWMI_WWAN); |
Dan Carpenter | dd258c0 | 2012-05-17 09:48:12 +0300 | [diff] [blame] | 696 | if (!wwan_rfkill) { |
| 697 | err = -ENOMEM; |
Trepák Vilmos | 4fca7ce | 2012-10-11 12:51:00 +0200 | [diff] [blame] | 698 | goto register_gps_error; |
Dan Carpenter | dd258c0 | 2012-05-17 09:48:12 +0300 | [diff] [blame] | 699 | } |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 700 | rfkill_init_sw_state(wwan_rfkill, |
| 701 | hp_wmi_get_sw_state(HPWMI_WWAN)); |
| 702 | rfkill_set_hw_state(wwan_rfkill, |
| 703 | hp_wmi_get_hw_state(HPWMI_WWAN)); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 704 | err = rfkill_register(wwan_rfkill); |
| 705 | if (err) |
| 706 | goto register_wwan_err; |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 707 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 708 | |
Trepák Vilmos | 4fca7ce | 2012-10-11 12:51:00 +0200 | [diff] [blame] | 709 | if (wireless & 0x8) { |
| 710 | gps_rfkill = rfkill_alloc("hp-gps", &device->dev, |
| 711 | RFKILL_TYPE_GPS, |
| 712 | &hp_wmi_rfkill_ops, |
| 713 | (void *) HPWMI_GPS); |
| 714 | if (!gps_rfkill) { |
| 715 | err = -ENOMEM; |
| 716 | goto register_bluetooth_error; |
| 717 | } |
| 718 | rfkill_init_sw_state(gps_rfkill, |
| 719 | hp_wmi_get_sw_state(HPWMI_GPS)); |
lan,Tianyu | af1d486 | 2013-05-28 02:25:33 +0000 | [diff] [blame] | 720 | rfkill_set_hw_state(gps_rfkill, |
Trepák Vilmos | 4fca7ce | 2012-10-11 12:51:00 +0200 | [diff] [blame] | 721 | hp_wmi_get_hw_state(HPWMI_GPS)); |
| 722 | err = rfkill_register(gps_rfkill); |
| 723 | if (err) |
| 724 | goto register_gps_error; |
| 725 | } |
| 726 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 727 | return 0; |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 728 | register_wwan_err: |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 729 | rfkill_destroy(wwan_rfkill); |
Anssi Hannula | 6d97db5 | 2011-02-20 20:07:24 +0200 | [diff] [blame] | 730 | wwan_rfkill = NULL; |
Trepák Vilmos | 4fca7ce | 2012-10-11 12:51:00 +0200 | [diff] [blame] | 731 | if (gps_rfkill) |
| 732 | rfkill_unregister(gps_rfkill); |
| 733 | register_gps_error: |
| 734 | rfkill_destroy(gps_rfkill); |
| 735 | gps_rfkill = NULL; |
Andrew Morton | 44f0606 | 2009-02-04 15:12:07 -0800 | [diff] [blame] | 736 | if (bluetooth_rfkill) |
| 737 | rfkill_unregister(bluetooth_rfkill); |
Larry Finger | fe8e4e0 | 2009-01-09 16:40:54 -0800 | [diff] [blame] | 738 | register_bluetooth_error: |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 739 | rfkill_destroy(bluetooth_rfkill); |
Anssi Hannula | 6d97db5 | 2011-02-20 20:07:24 +0200 | [diff] [blame] | 740 | bluetooth_rfkill = NULL; |
Andrew Morton | 44f0606 | 2009-02-04 15:12:07 -0800 | [diff] [blame] | 741 | if (wifi_rfkill) |
| 742 | rfkill_unregister(wifi_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 743 | register_wifi_error: |
| 744 | rfkill_destroy(wifi_rfkill); |
Anssi Hannula | 6d97db5 | 2011-02-20 20:07:24 +0200 | [diff] [blame] | 745 | wifi_rfkill = NULL; |
Anssi Hannula | eceb7bd | 2011-02-20 20:07:23 +0200 | [diff] [blame] | 746 | return err; |
| 747 | } |
| 748 | |
Greg Kroah-Hartman | b859f15 | 2012-12-21 13:18:33 -0800 | [diff] [blame] | 749 | static int hp_wmi_rfkill2_setup(struct platform_device *device) |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 750 | { |
| 751 | int err, i; |
| 752 | struct bios_rfkill2_state state; |
| 753 | err = hp_wmi_perform_query(HPWMI_WIRELESS2_QUERY, 0, &state, |
| 754 | 0, sizeof(state)); |
| 755 | if (err) |
| 756 | return err; |
| 757 | |
| 758 | if (state.count > HPWMI_MAX_RFKILL2_DEVICES) { |
Joe Perches | b5a4223 | 2011-03-29 15:21:41 -0700 | [diff] [blame] | 759 | pr_warn("unable to parse 0x1b query output\n"); |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 760 | return -EINVAL; |
| 761 | } |
| 762 | |
| 763 | for (i = 0; i < state.count; i++) { |
| 764 | struct rfkill *rfkill; |
| 765 | enum rfkill_type type; |
| 766 | char *name; |
| 767 | switch (state.device[i].radio_type) { |
| 768 | case HPWMI_WIFI: |
| 769 | type = RFKILL_TYPE_WLAN; |
| 770 | name = "hp-wifi"; |
| 771 | break; |
| 772 | case HPWMI_BLUETOOTH: |
| 773 | type = RFKILL_TYPE_BLUETOOTH; |
| 774 | name = "hp-bluetooth"; |
| 775 | break; |
| 776 | case HPWMI_WWAN: |
| 777 | type = RFKILL_TYPE_WWAN; |
| 778 | name = "hp-wwan"; |
| 779 | break; |
Trepák Vilmos | 4fca7ce | 2012-10-11 12:51:00 +0200 | [diff] [blame] | 780 | case HPWMI_GPS: |
| 781 | type = RFKILL_TYPE_GPS; |
| 782 | name = "hp-gps"; |
| 783 | break; |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 784 | default: |
Joe Perches | b5a4223 | 2011-03-29 15:21:41 -0700 | [diff] [blame] | 785 | pr_warn("unknown device type 0x%x\n", |
| 786 | state.device[i].radio_type); |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 787 | continue; |
| 788 | } |
| 789 | |
| 790 | if (!state.device[i].vendor_id) { |
Joe Perches | b5a4223 | 2011-03-29 15:21:41 -0700 | [diff] [blame] | 791 | pr_warn("zero device %d while %d reported\n", |
| 792 | i, state.count); |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 793 | continue; |
| 794 | } |
| 795 | |
| 796 | rfkill = rfkill_alloc(name, &device->dev, type, |
| 797 | &hp_wmi_rfkill2_ops, (void *)(long)i); |
| 798 | if (!rfkill) { |
| 799 | err = -ENOMEM; |
| 800 | goto fail; |
| 801 | } |
| 802 | |
| 803 | rfkill2[rfkill2_count].id = state.device[i].rfkill_id; |
| 804 | rfkill2[rfkill2_count].num = i; |
| 805 | rfkill2[rfkill2_count].rfkill = rfkill; |
| 806 | |
| 807 | rfkill_init_sw_state(rfkill, |
| 808 | IS_SWBLOCKED(state.device[i].power)); |
| 809 | rfkill_set_hw_state(rfkill, |
| 810 | IS_HWBLOCKED(state.device[i].power)); |
| 811 | |
| 812 | if (!(state.device[i].power & HPWMI_POWER_BIOS)) |
Joe Perches | b5a4223 | 2011-03-29 15:21:41 -0700 | [diff] [blame] | 813 | pr_info("device %s blocked by BIOS\n", name); |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 814 | |
| 815 | err = rfkill_register(rfkill); |
| 816 | if (err) { |
| 817 | rfkill_destroy(rfkill); |
| 818 | goto fail; |
| 819 | } |
| 820 | |
| 821 | rfkill2_count++; |
| 822 | } |
| 823 | |
| 824 | return 0; |
| 825 | fail: |
| 826 | for (; rfkill2_count > 0; rfkill2_count--) { |
| 827 | rfkill_unregister(rfkill2[rfkill2_count - 1].rfkill); |
| 828 | rfkill_destroy(rfkill2[rfkill2_count - 1].rfkill); |
| 829 | } |
| 830 | return err; |
| 831 | } |
| 832 | |
Dmitry Torokhov | c165b80 | 2013-02-20 00:44:34 -0800 | [diff] [blame] | 833 | static int __init hp_wmi_bios_setup(struct platform_device *device) |
Anssi Hannula | eceb7bd | 2011-02-20 20:07:23 +0200 | [diff] [blame] | 834 | { |
| 835 | int err; |
| 836 | |
Anssi Hannula | 6d97db5 | 2011-02-20 20:07:24 +0200 | [diff] [blame] | 837 | /* clear detected rfkill devices */ |
| 838 | wifi_rfkill = NULL; |
| 839 | bluetooth_rfkill = NULL; |
| 840 | wwan_rfkill = NULL; |
Trepák Vilmos | 4fca7ce | 2012-10-11 12:51:00 +0200 | [diff] [blame] | 841 | gps_rfkill = NULL; |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 842 | rfkill2_count = 0; |
Anssi Hannula | 6d97db5 | 2011-02-20 20:07:24 +0200 | [diff] [blame] | 843 | |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 844 | if (hp_wmi_rfkill_setup(device)) |
| 845 | hp_wmi_rfkill2_setup(device); |
Anssi Hannula | eceb7bd | 2011-02-20 20:07:23 +0200 | [diff] [blame] | 846 | |
| 847 | err = device_create_file(&device->dev, &dev_attr_display); |
| 848 | if (err) |
| 849 | goto add_sysfs_error; |
| 850 | err = device_create_file(&device->dev, &dev_attr_hddtemp); |
| 851 | if (err) |
| 852 | goto add_sysfs_error; |
| 853 | err = device_create_file(&device->dev, &dev_attr_als); |
| 854 | if (err) |
| 855 | goto add_sysfs_error; |
| 856 | err = device_create_file(&device->dev, &dev_attr_dock); |
| 857 | if (err) |
| 858 | goto add_sysfs_error; |
| 859 | err = device_create_file(&device->dev, &dev_attr_tablet); |
| 860 | if (err) |
| 861 | goto add_sysfs_error; |
| 862 | return 0; |
| 863 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 864 | add_sysfs_error: |
| 865 | cleanup_sysfs(device); |
| 866 | return err; |
| 867 | } |
| 868 | |
| 869 | static int __exit hp_wmi_bios_remove(struct platform_device *device) |
| 870 | { |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 871 | int i; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 872 | cleanup_sysfs(device); |
| 873 | |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 874 | for (i = 0; i < rfkill2_count; i++) { |
| 875 | rfkill_unregister(rfkill2[i].rfkill); |
| 876 | rfkill_destroy(rfkill2[i].rfkill); |
| 877 | } |
| 878 | |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 879 | if (wifi_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 880 | rfkill_unregister(wifi_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 881 | rfkill_destroy(wifi_rfkill); |
| 882 | } |
| 883 | if (bluetooth_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 884 | rfkill_unregister(bluetooth_rfkill); |
Corentin Chary | 09729f0 | 2009-09-14 12:43:51 +0200 | [diff] [blame] | 885 | rfkill_destroy(bluetooth_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 886 | } |
| 887 | if (wwan_rfkill) { |
Matthew Garrett | 3f6e2f1 | 2008-09-02 14:36:00 -0700 | [diff] [blame] | 888 | rfkill_unregister(wwan_rfkill); |
Johannes Berg | 19d337d | 2009-06-02 13:01:37 +0200 | [diff] [blame] | 889 | rfkill_destroy(wwan_rfkill); |
| 890 | } |
Trepák Vilmos | 4fca7ce | 2012-10-11 12:51:00 +0200 | [diff] [blame] | 891 | if (gps_rfkill) { |
| 892 | rfkill_unregister(gps_rfkill); |
| 893 | rfkill_destroy(gps_rfkill); |
| 894 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 895 | |
| 896 | return 0; |
| 897 | } |
| 898 | |
Frans Pop | 8dd2b42 | 2009-08-20 20:38:13 +0200 | [diff] [blame] | 899 | static int hp_wmi_resume_handler(struct device *device) |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 900 | { |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 901 | /* |
Matthew Garrett | 871043b | 2009-06-01 15:25:45 +0100 | [diff] [blame] | 902 | * Hardware state may have changed while suspended, so trigger |
| 903 | * input events for the current state. As this is a switch, |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 904 | * the input layer will only actually pass it on if the state |
| 905 | * changed. |
| 906 | */ |
Frans Pop | daed953 | 2009-07-30 17:16:05 -0400 | [diff] [blame] | 907 | if (hp_wmi_input_dev) { |
| 908 | input_report_switch(hp_wmi_input_dev, SW_DOCK, |
| 909 | hp_wmi_dock_state()); |
| 910 | input_report_switch(hp_wmi_input_dev, SW_TABLET_MODE, |
| 911 | hp_wmi_tablet_state()); |
| 912 | input_sync(hp_wmi_input_dev); |
| 913 | } |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 914 | |
Anssi Hannula | c0b9c64 | 2011-02-20 20:07:26 +0200 | [diff] [blame] | 915 | if (rfkill2_count) |
| 916 | hp_wmi_rfkill2_refresh(); |
| 917 | |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 918 | if (wifi_rfkill) |
| 919 | rfkill_set_states(wifi_rfkill, |
| 920 | hp_wmi_get_sw_state(HPWMI_WIFI), |
| 921 | hp_wmi_get_hw_state(HPWMI_WIFI)); |
| 922 | if (bluetooth_rfkill) |
| 923 | rfkill_set_states(bluetooth_rfkill, |
| 924 | hp_wmi_get_sw_state(HPWMI_BLUETOOTH), |
| 925 | hp_wmi_get_hw_state(HPWMI_BLUETOOTH)); |
| 926 | if (wwan_rfkill) |
| 927 | rfkill_set_states(wwan_rfkill, |
| 928 | hp_wmi_get_sw_state(HPWMI_WWAN), |
| 929 | hp_wmi_get_hw_state(HPWMI_WWAN)); |
Trepák Vilmos | 4fca7ce | 2012-10-11 12:51:00 +0200 | [diff] [blame] | 930 | if (gps_rfkill) |
| 931 | rfkill_set_states(gps_rfkill, |
| 932 | hp_wmi_get_sw_state(HPWMI_GPS), |
| 933 | hp_wmi_get_hw_state(HPWMI_GPS)); |
Alan Jenkins | e5fbba8 | 2009-07-21 12:14:01 +0100 | [diff] [blame] | 934 | |
Frans Pop | 4c395bd | 2009-03-04 11:55:28 -0800 | [diff] [blame] | 935 | return 0; |
| 936 | } |
| 937 | |
Dmitry Torokhov | c165b80 | 2013-02-20 00:44:34 -0800 | [diff] [blame] | 938 | static const struct dev_pm_ops hp_wmi_pm_ops = { |
| 939 | .resume = hp_wmi_resume_handler, |
| 940 | .restore = hp_wmi_resume_handler, |
| 941 | }; |
| 942 | |
| 943 | static struct platform_driver hp_wmi_driver = { |
| 944 | .driver = { |
| 945 | .name = "hp-wmi", |
| 946 | .owner = THIS_MODULE, |
| 947 | .pm = &hp_wmi_pm_ops, |
| 948 | }, |
| 949 | .remove = __exit_p(hp_wmi_bios_remove), |
| 950 | }; |
| 951 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 952 | static int __init hp_wmi_init(void) |
| 953 | { |
| 954 | int err; |
Thomas Renninger | b096667 | 2010-07-20 15:19:29 -0700 | [diff] [blame] | 955 | int event_capable = wmi_has_guid(HPWMI_EVENT_GUID); |
| 956 | int bios_capable = wmi_has_guid(HPWMI_BIOS_GUID); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 957 | |
Dmitry Torokhov | c165b80 | 2013-02-20 00:44:34 -0800 | [diff] [blame] | 958 | if (!bios_capable && !event_capable) |
| 959 | return -ENODEV; |
| 960 | |
Thomas Renninger | b096667 | 2010-07-20 15:19:29 -0700 | [diff] [blame] | 961 | if (event_capable) { |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 962 | err = hp_wmi_input_setup(); |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 963 | if (err) |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 964 | return err; |
Matthew Garrett | b253c9d | 2013-07-08 11:44:40 -0400 | [diff] [blame^] | 965 | |
| 966 | hp_wmi_enable_hotkeys(); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 967 | } |
| 968 | |
Thomas Renninger | b096667 | 2010-07-20 15:19:29 -0700 | [diff] [blame] | 969 | if (bios_capable) { |
Dmitry Torokhov | c165b80 | 2013-02-20 00:44:34 -0800 | [diff] [blame] | 970 | hp_wmi_platform_dev = |
| 971 | platform_device_register_simple("hp-wmi", -1, NULL, 0); |
| 972 | if (IS_ERR(hp_wmi_platform_dev)) { |
| 973 | err = PTR_ERR(hp_wmi_platform_dev); |
| 974 | goto err_destroy_input; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 975 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 976 | |
Dmitry Torokhov | c165b80 | 2013-02-20 00:44:34 -0800 | [diff] [blame] | 977 | err = platform_driver_probe(&hp_wmi_driver, hp_wmi_bios_setup); |
| 978 | if (err) |
| 979 | goto err_unregister_device; |
| 980 | } |
Thomas Renninger | b096667 | 2010-07-20 15:19:29 -0700 | [diff] [blame] | 981 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 982 | return 0; |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 983 | |
Dmitry Torokhov | c165b80 | 2013-02-20 00:44:34 -0800 | [diff] [blame] | 984 | err_unregister_device: |
| 985 | platform_device_unregister(hp_wmi_platform_dev); |
| 986 | err_destroy_input: |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 987 | if (event_capable) |
| 988 | hp_wmi_input_destroy(); |
Axel Lin | dfec5c4 | 2010-06-10 16:06:40 +0800 | [diff] [blame] | 989 | |
| 990 | return err; |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 991 | } |
Dmitry Torokhov | c165b80 | 2013-02-20 00:44:34 -0800 | [diff] [blame] | 992 | module_init(hp_wmi_init); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 993 | |
| 994 | static void __exit hp_wmi_exit(void) |
| 995 | { |
Dmitry Torokhov | 4d291ed | 2010-08-04 22:30:13 -0700 | [diff] [blame] | 996 | if (wmi_has_guid(HPWMI_EVENT_GUID)) |
| 997 | hp_wmi_input_destroy(); |
| 998 | |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 999 | if (hp_wmi_platform_dev) { |
Axel Lin | 97ba0af | 2010-06-03 15:18:03 +0800 | [diff] [blame] | 1000 | platform_device_unregister(hp_wmi_platform_dev); |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 1001 | platform_driver_unregister(&hp_wmi_driver); |
| 1002 | } |
| 1003 | } |
Matthew Garrett | 62ec30d | 2008-07-25 01:45:39 -0700 | [diff] [blame] | 1004 | module_exit(hp_wmi_exit); |