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