Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Eee PC WMI hotkey driver |
| 3 | * |
| 4 | * Copyright(C) 2010 Intel Corporation. |
| 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 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 26 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 27 | |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 28 | #include <linux/kernel.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/init.h> |
| 31 | #include <linux/types.h> |
Tejun Heo | a32f392 | 2010-04-05 11:37:59 +0900 | [diff] [blame] | 32 | #include <linux/slab.h> |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 33 | #include <linux/input.h> |
| 34 | #include <linux/input/sparse-keymap.h> |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 35 | #include <linux/fb.h> |
| 36 | #include <linux/backlight.h> |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 37 | #include <linux/leds.h> |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame^] | 38 | #include <linux/rfkill.h> |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 39 | #include <linux/platform_device.h> |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 40 | #include <acpi/acpi_bus.h> |
| 41 | #include <acpi/acpi_drivers.h> |
| 42 | |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 43 | #define EEEPC_WMI_FILE "eeepc-wmi" |
| 44 | |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 45 | MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>"); |
| 46 | MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver"); |
| 47 | MODULE_LICENSE("GPL"); |
| 48 | |
| 49 | #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000" |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 50 | #define EEEPC_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66" |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 51 | |
| 52 | MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 53 | MODULE_ALIAS("wmi:"EEEPC_WMI_MGMT_GUID); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 54 | |
| 55 | #define NOTIFY_BRNUP_MIN 0x11 |
| 56 | #define NOTIFY_BRNUP_MAX 0x1f |
| 57 | #define NOTIFY_BRNDOWN_MIN 0x20 |
| 58 | #define NOTIFY_BRNDOWN_MAX 0x2e |
| 59 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 60 | #define EEEPC_WMI_METHODID_DEVS 0x53564544 |
| 61 | #define EEEPC_WMI_METHODID_DSTS 0x53544344 |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 62 | #define EEEPC_WMI_METHODID_CFVS 0x53564643 |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 63 | |
| 64 | #define EEEPC_WMI_DEVID_BACKLIGHT 0x00050012 |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 65 | #define EEEPC_WMI_DEVID_TPDLED 0x00100011 |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame^] | 66 | #define EEEPC_WMI_DEVID_WLAN 0x00010011 |
| 67 | #define EEEPC_WMI_DEVID_BLUETOOTH 0x00010013 |
| 68 | #define EEEPC_WMI_DEVID_WWAN3G 0x00010019 |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 69 | |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 70 | static const struct key_entry eeepc_wmi_keymap[] = { |
| 71 | /* Sleep already handled via generic ACPI code */ |
| 72 | { KE_KEY, 0x5d, { KEY_WLAN } }, |
| 73 | { KE_KEY, 0x32, { KEY_MUTE } }, |
| 74 | { KE_KEY, 0x31, { KEY_VOLUMEDOWN } }, |
| 75 | { KE_KEY, 0x30, { KEY_VOLUMEUP } }, |
| 76 | { KE_IGNORE, NOTIFY_BRNDOWN_MIN, { KEY_BRIGHTNESSDOWN } }, |
| 77 | { KE_IGNORE, NOTIFY_BRNUP_MIN, { KEY_BRIGHTNESSUP } }, |
| 78 | { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } }, |
Chris Bagwell | eda1748 | 2010-10-11 18:47:17 -0500 | [diff] [blame] | 79 | { KE_KEY, 0x6b, { KEY_F13 } }, /* Disable Touchpad */ |
| 80 | { KE_KEY, 0xe1, { KEY_F14 } }, |
| 81 | { KE_KEY, 0xe9, { KEY_DISPLAY_OFF } }, |
| 82 | { KE_KEY, 0xe0, { KEY_PROG1 } }, |
| 83 | { KE_KEY, 0x5c, { KEY_F15 } }, |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 84 | { KE_END, 0}, |
| 85 | }; |
| 86 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 87 | struct bios_args { |
| 88 | u32 dev_id; |
| 89 | u32 ctrl_param; |
| 90 | }; |
| 91 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 92 | struct eeepc_wmi { |
| 93 | struct input_dev *inputdev; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 94 | struct backlight_device *backlight_device; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 95 | struct platform_device *platform_device; |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 96 | |
| 97 | struct led_classdev tpd_led; |
| 98 | int tpd_led_wk; |
| 99 | struct workqueue_struct *led_workqueue; |
| 100 | struct work_struct tpd_led_work; |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame^] | 101 | |
| 102 | struct rfkill *wlan_rfkill; |
| 103 | struct rfkill *bluetooth_rfkill; |
| 104 | struct rfkill *wwan3g_rfkill; |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 105 | }; |
| 106 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 107 | /* Only used in eeepc_wmi_init() and eeepc_wmi_exit() */ |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 108 | static struct platform_device *platform_device; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 109 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 110 | static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 111 | { |
| 112 | int err; |
| 113 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 114 | eeepc->inputdev = input_allocate_device(); |
| 115 | if (!eeepc->inputdev) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 116 | return -ENOMEM; |
| 117 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 118 | eeepc->inputdev->name = "Eee PC WMI hotkeys"; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 119 | eeepc->inputdev->phys = EEEPC_WMI_FILE "/input0"; |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 120 | eeepc->inputdev->id.bustype = BUS_HOST; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 121 | eeepc->inputdev->dev.parent = &eeepc->platform_device->dev; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 122 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 123 | err = sparse_keymap_setup(eeepc->inputdev, eeepc_wmi_keymap, NULL); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 124 | if (err) |
| 125 | goto err_free_dev; |
| 126 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 127 | err = input_register_device(eeepc->inputdev); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 128 | if (err) |
| 129 | goto err_free_keymap; |
| 130 | |
| 131 | return 0; |
| 132 | |
| 133 | err_free_keymap: |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 134 | sparse_keymap_free(eeepc->inputdev); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 135 | err_free_dev: |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 136 | input_free_device(eeepc->inputdev); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 137 | return err; |
| 138 | } |
| 139 | |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 140 | static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc) |
| 141 | { |
| 142 | if (eeepc->inputdev) { |
| 143 | sparse_keymap_free(eeepc->inputdev); |
| 144 | input_unregister_device(eeepc->inputdev); |
| 145 | } |
| 146 | |
| 147 | eeepc->inputdev = NULL; |
| 148 | } |
| 149 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 150 | static acpi_status eeepc_wmi_get_devstate(u32 dev_id, u32 *ctrl_param) |
| 151 | { |
| 152 | struct acpi_buffer input = { (acpi_size)sizeof(u32), &dev_id }; |
| 153 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 154 | union acpi_object *obj; |
| 155 | acpi_status status; |
| 156 | u32 tmp; |
| 157 | |
| 158 | status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, |
| 159 | 1, EEEPC_WMI_METHODID_DSTS, &input, &output); |
| 160 | |
| 161 | if (ACPI_FAILURE(status)) |
| 162 | return status; |
| 163 | |
| 164 | obj = (union acpi_object *)output.pointer; |
| 165 | if (obj && obj->type == ACPI_TYPE_INTEGER) |
| 166 | tmp = (u32)obj->integer.value; |
| 167 | else |
| 168 | tmp = 0; |
| 169 | |
| 170 | if (ctrl_param) |
| 171 | *ctrl_param = tmp; |
| 172 | |
| 173 | kfree(obj); |
| 174 | |
| 175 | return status; |
| 176 | |
| 177 | } |
| 178 | |
| 179 | static acpi_status eeepc_wmi_set_devstate(u32 dev_id, u32 ctrl_param) |
| 180 | { |
| 181 | struct bios_args args = { |
| 182 | .dev_id = dev_id, |
| 183 | .ctrl_param = ctrl_param, |
| 184 | }; |
| 185 | struct acpi_buffer input = { (acpi_size)sizeof(args), &args }; |
| 186 | acpi_status status; |
| 187 | |
| 188 | status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, |
| 189 | 1, EEEPC_WMI_METHODID_DEVS, &input, NULL); |
| 190 | |
| 191 | return status; |
| 192 | } |
| 193 | |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 194 | /* |
| 195 | * LEDs |
| 196 | */ |
| 197 | /* |
| 198 | * These functions actually update the LED's, and are called from a |
| 199 | * workqueue. By doing this as separate work rather than when the LED |
| 200 | * subsystem asks, we avoid messing with the Eeepc ACPI stuff during a |
| 201 | * potentially bad time, such as a timer interrupt. |
| 202 | */ |
| 203 | static void tpd_led_update(struct work_struct *work) |
| 204 | { |
| 205 | int ctrl_param; |
| 206 | struct eeepc_wmi *eeepc; |
| 207 | |
| 208 | eeepc = container_of(work, struct eeepc_wmi, tpd_led_work); |
| 209 | |
| 210 | ctrl_param = eeepc->tpd_led_wk; |
| 211 | eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_TPDLED, ctrl_param); |
| 212 | } |
| 213 | |
| 214 | static void tpd_led_set(struct led_classdev *led_cdev, |
| 215 | enum led_brightness value) |
| 216 | { |
| 217 | struct eeepc_wmi *eeepc; |
| 218 | |
| 219 | eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led); |
| 220 | |
| 221 | eeepc->tpd_led_wk = !!value; |
| 222 | queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work); |
| 223 | } |
| 224 | |
| 225 | static int read_tpd_state(struct eeepc_wmi *eeepc) |
| 226 | { |
| 227 | static u32 ctrl_param; |
| 228 | acpi_status status; |
| 229 | |
| 230 | status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_TPDLED, &ctrl_param); |
| 231 | |
| 232 | if (ACPI_FAILURE(status)) |
| 233 | return -1; |
| 234 | else if (!ctrl_param || ctrl_param == 0x00060000) |
| 235 | /* |
| 236 | * if touchpad led is present, DSTS will set some bits, |
| 237 | * usually 0x00020000. |
| 238 | * 0x00060000 means that the device is not supported |
| 239 | */ |
| 240 | return -ENODEV; |
| 241 | else |
| 242 | /* Status is stored in the first bit */ |
| 243 | return ctrl_param & 0x1; |
| 244 | } |
| 245 | |
| 246 | static enum led_brightness tpd_led_get(struct led_classdev *led_cdev) |
| 247 | { |
| 248 | struct eeepc_wmi *eeepc; |
| 249 | |
| 250 | eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led); |
| 251 | |
| 252 | return read_tpd_state(eeepc); |
| 253 | } |
| 254 | |
| 255 | static int eeepc_wmi_led_init(struct eeepc_wmi *eeepc) |
| 256 | { |
| 257 | int rv; |
| 258 | |
| 259 | if (read_tpd_state(eeepc) < 0) |
| 260 | return 0; |
| 261 | |
| 262 | eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue"); |
| 263 | if (!eeepc->led_workqueue) |
| 264 | return -ENOMEM; |
| 265 | INIT_WORK(&eeepc->tpd_led_work, tpd_led_update); |
| 266 | |
| 267 | eeepc->tpd_led.name = "eeepc::touchpad"; |
| 268 | eeepc->tpd_led.brightness_set = tpd_led_set; |
| 269 | eeepc->tpd_led.brightness_get = tpd_led_get; |
| 270 | eeepc->tpd_led.max_brightness = 1; |
| 271 | |
| 272 | rv = led_classdev_register(&eeepc->platform_device->dev, |
| 273 | &eeepc->tpd_led); |
| 274 | if (rv) { |
| 275 | destroy_workqueue(eeepc->led_workqueue); |
| 276 | return rv; |
| 277 | } |
| 278 | |
| 279 | return 0; |
| 280 | } |
| 281 | |
| 282 | static void eeepc_wmi_led_exit(struct eeepc_wmi *eeepc) |
| 283 | { |
| 284 | if (eeepc->tpd_led.dev) |
| 285 | led_classdev_unregister(&eeepc->tpd_led); |
| 286 | if (eeepc->led_workqueue) |
| 287 | destroy_workqueue(eeepc->led_workqueue); |
| 288 | } |
| 289 | |
| 290 | /* |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame^] | 291 | * Rfkill devices |
| 292 | */ |
| 293 | static int eeepc_rfkill_set(void *data, bool blocked) |
| 294 | { |
| 295 | int dev_id = (unsigned long)data; |
| 296 | u32 ctrl_param = !blocked; |
| 297 | |
| 298 | return eeepc_wmi_set_devstate(dev_id, ctrl_param); |
| 299 | } |
| 300 | |
| 301 | static void eeepc_rfkill_query(struct rfkill *rfkill, void *data) |
| 302 | { |
| 303 | int dev_id = (unsigned long)data; |
| 304 | u32 ctrl_param; |
| 305 | acpi_status status; |
| 306 | |
| 307 | status = eeepc_wmi_get_devstate(dev_id, &ctrl_param); |
| 308 | |
| 309 | if (ACPI_FAILURE(status)) |
| 310 | return ; |
| 311 | |
| 312 | rfkill_set_sw_state(rfkill, !(ctrl_param & 0x1)); |
| 313 | } |
| 314 | |
| 315 | static const struct rfkill_ops eeepc_rfkill_ops = { |
| 316 | .set_block = eeepc_rfkill_set, |
| 317 | .query = eeepc_rfkill_query, |
| 318 | }; |
| 319 | |
| 320 | static int eeepc_new_rfkill(struct eeepc_wmi *eeepc, |
| 321 | struct rfkill **rfkill, |
| 322 | const char *name, |
| 323 | enum rfkill_type type, int dev_id) |
| 324 | { |
| 325 | int result; |
| 326 | u32 ctrl_param; |
| 327 | acpi_status status; |
| 328 | |
| 329 | status = eeepc_wmi_get_devstate(dev_id, &ctrl_param); |
| 330 | |
| 331 | if (ACPI_FAILURE(status)) |
| 332 | return -1; |
| 333 | |
| 334 | /* If the device is present, DSTS will always set some bits |
| 335 | * 0x00070000 - 1110000000000000000 - device supported |
| 336 | * 0x00060000 - 1100000000000000000 - not supported |
| 337 | * 0x00020000 - 0100000000000000000 - device supported |
| 338 | * 0x00010000 - 0010000000000000000 - not supported / special mode ? |
| 339 | */ |
| 340 | if (!ctrl_param || ctrl_param == 0x00060000) |
| 341 | return -ENODEV; |
| 342 | |
| 343 | *rfkill = rfkill_alloc(name, &eeepc->platform_device->dev, type, |
| 344 | &eeepc_rfkill_ops, (void *)(long)dev_id); |
| 345 | |
| 346 | if (!*rfkill) |
| 347 | return -EINVAL; |
| 348 | |
| 349 | rfkill_init_sw_state(*rfkill, !(ctrl_param & 0x1)); |
| 350 | result = rfkill_register(*rfkill); |
| 351 | if (result) { |
| 352 | rfkill_destroy(*rfkill); |
| 353 | *rfkill = NULL; |
| 354 | return result; |
| 355 | } |
| 356 | return 0; |
| 357 | } |
| 358 | |
| 359 | static void eeepc_wmi_rfkill_exit(struct eeepc_wmi *eeepc) |
| 360 | { |
| 361 | if (eeepc->wlan_rfkill) { |
| 362 | rfkill_unregister(eeepc->wlan_rfkill); |
| 363 | rfkill_destroy(eeepc->wlan_rfkill); |
| 364 | eeepc->wlan_rfkill = NULL; |
| 365 | } |
| 366 | if (eeepc->bluetooth_rfkill) { |
| 367 | rfkill_unregister(eeepc->bluetooth_rfkill); |
| 368 | rfkill_destroy(eeepc->bluetooth_rfkill); |
| 369 | eeepc->bluetooth_rfkill = NULL; |
| 370 | } |
| 371 | if (eeepc->wwan3g_rfkill) { |
| 372 | rfkill_unregister(eeepc->wwan3g_rfkill); |
| 373 | rfkill_destroy(eeepc->wwan3g_rfkill); |
| 374 | eeepc->wwan3g_rfkill = NULL; |
| 375 | } |
| 376 | } |
| 377 | |
| 378 | static int eeepc_wmi_rfkill_init(struct eeepc_wmi *eeepc) |
| 379 | { |
| 380 | int result = 0; |
| 381 | |
| 382 | result = eeepc_new_rfkill(eeepc, &eeepc->wlan_rfkill, |
| 383 | "eeepc-wlan", RFKILL_TYPE_WLAN, |
| 384 | EEEPC_WMI_DEVID_WLAN); |
| 385 | |
| 386 | if (result && result != -ENODEV) |
| 387 | goto exit; |
| 388 | |
| 389 | result = eeepc_new_rfkill(eeepc, &eeepc->bluetooth_rfkill, |
| 390 | "eeepc-bluetooth", RFKILL_TYPE_BLUETOOTH, |
| 391 | EEEPC_WMI_DEVID_BLUETOOTH); |
| 392 | |
| 393 | if (result && result != -ENODEV) |
| 394 | goto exit; |
| 395 | |
| 396 | result = eeepc_new_rfkill(eeepc, &eeepc->wwan3g_rfkill, |
| 397 | "eeepc-wwan3g", RFKILL_TYPE_WWAN, |
| 398 | EEEPC_WMI_DEVID_WWAN3G); |
| 399 | |
| 400 | if (result && result != -ENODEV) |
| 401 | goto exit; |
| 402 | |
| 403 | exit: |
| 404 | if (result && result != -ENODEV) |
| 405 | eeepc_wmi_rfkill_exit(eeepc); |
| 406 | |
| 407 | if (result == -ENODEV) |
| 408 | result = 0; |
| 409 | |
| 410 | return result; |
| 411 | } |
| 412 | |
| 413 | /* |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 414 | * Backlight |
| 415 | */ |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 416 | static int read_brightness(struct backlight_device *bd) |
| 417 | { |
| 418 | static u32 ctrl_param; |
| 419 | acpi_status status; |
| 420 | |
| 421 | status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_BACKLIGHT, &ctrl_param); |
| 422 | |
| 423 | if (ACPI_FAILURE(status)) |
| 424 | return -1; |
| 425 | else |
| 426 | return ctrl_param & 0xFF; |
| 427 | } |
| 428 | |
| 429 | static int update_bl_status(struct backlight_device *bd) |
| 430 | { |
| 431 | |
| 432 | static u32 ctrl_param; |
| 433 | acpi_status status; |
| 434 | |
| 435 | ctrl_param = bd->props.brightness; |
| 436 | |
| 437 | status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BACKLIGHT, ctrl_param); |
| 438 | |
| 439 | if (ACPI_FAILURE(status)) |
| 440 | return -1; |
| 441 | else |
| 442 | return 0; |
| 443 | } |
| 444 | |
| 445 | static const struct backlight_ops eeepc_wmi_bl_ops = { |
| 446 | .get_brightness = read_brightness, |
| 447 | .update_status = update_bl_status, |
| 448 | }; |
| 449 | |
| 450 | static int eeepc_wmi_backlight_notify(struct eeepc_wmi *eeepc, int code) |
| 451 | { |
| 452 | struct backlight_device *bd = eeepc->backlight_device; |
| 453 | int old = bd->props.brightness; |
Daniel Mack | b7670ed | 2010-05-19 12:37:01 +0200 | [diff] [blame] | 454 | int new = old; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 455 | |
| 456 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) |
| 457 | new = code - NOTIFY_BRNUP_MIN + 1; |
| 458 | else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) |
| 459 | new = code - NOTIFY_BRNDOWN_MIN; |
| 460 | |
| 461 | bd->props.brightness = new; |
| 462 | backlight_update_status(bd); |
| 463 | backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY); |
| 464 | |
| 465 | return old; |
| 466 | } |
| 467 | |
| 468 | static int eeepc_wmi_backlight_init(struct eeepc_wmi *eeepc) |
| 469 | { |
| 470 | struct backlight_device *bd; |
| 471 | struct backlight_properties props; |
| 472 | |
| 473 | memset(&props, 0, sizeof(struct backlight_properties)); |
| 474 | props.max_brightness = 15; |
| 475 | bd = backlight_device_register(EEEPC_WMI_FILE, |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 476 | &eeepc->platform_device->dev, eeepc, |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 477 | &eeepc_wmi_bl_ops, &props); |
| 478 | if (IS_ERR(bd)) { |
| 479 | pr_err("Could not register backlight device\n"); |
| 480 | return PTR_ERR(bd); |
| 481 | } |
| 482 | |
| 483 | eeepc->backlight_device = bd; |
| 484 | |
| 485 | bd->props.brightness = read_brightness(bd); |
| 486 | bd->props.power = FB_BLANK_UNBLANK; |
| 487 | backlight_update_status(bd); |
| 488 | |
| 489 | return 0; |
| 490 | } |
| 491 | |
| 492 | static void eeepc_wmi_backlight_exit(struct eeepc_wmi *eeepc) |
| 493 | { |
| 494 | if (eeepc->backlight_device) |
| 495 | backlight_device_unregister(eeepc->backlight_device); |
| 496 | |
| 497 | eeepc->backlight_device = NULL; |
| 498 | } |
| 499 | |
| 500 | static void eeepc_wmi_notify(u32 value, void *context) |
| 501 | { |
| 502 | struct eeepc_wmi *eeepc = context; |
| 503 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 504 | union acpi_object *obj; |
| 505 | acpi_status status; |
| 506 | int code; |
| 507 | int orig_code; |
| 508 | |
| 509 | status = wmi_get_event_data(value, &response); |
| 510 | if (status != AE_OK) { |
| 511 | pr_err("bad event status 0x%x\n", status); |
| 512 | return; |
| 513 | } |
| 514 | |
| 515 | obj = (union acpi_object *)response.pointer; |
| 516 | |
| 517 | if (obj && obj->type == ACPI_TYPE_INTEGER) { |
| 518 | code = obj->integer.value; |
| 519 | orig_code = code; |
| 520 | |
| 521 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) |
| 522 | code = NOTIFY_BRNUP_MIN; |
| 523 | else if (code >= NOTIFY_BRNDOWN_MIN && |
| 524 | code <= NOTIFY_BRNDOWN_MAX) |
| 525 | code = NOTIFY_BRNDOWN_MIN; |
| 526 | |
| 527 | if (code == NOTIFY_BRNUP_MIN || code == NOTIFY_BRNDOWN_MIN) { |
| 528 | if (!acpi_video_backlight_support()) |
| 529 | eeepc_wmi_backlight_notify(eeepc, orig_code); |
| 530 | } |
| 531 | |
| 532 | if (!sparse_keymap_report_event(eeepc->inputdev, |
| 533 | code, 1, true)) |
| 534 | pr_info("Unknown key %x pressed\n", code); |
| 535 | } |
| 536 | |
| 537 | kfree(obj); |
| 538 | } |
| 539 | |
Dmitry Torokhov | 67fa38e | 2010-11-03 11:14:01 -0700 | [diff] [blame] | 540 | static ssize_t store_cpufv(struct device *dev, struct device_attribute *attr, |
| 541 | const char *buf, size_t count) |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 542 | { |
| 543 | int value; |
| 544 | struct acpi_buffer input = { (acpi_size)sizeof(value), &value }; |
| 545 | acpi_status status; |
| 546 | |
| 547 | if (!count || sscanf(buf, "%i", &value) != 1) |
| 548 | return -EINVAL; |
| 549 | if (value < 0 || value > 2) |
| 550 | return -EINVAL; |
| 551 | |
| 552 | status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, |
| 553 | 1, EEEPC_WMI_METHODID_CFVS, &input, NULL); |
| 554 | |
| 555 | if (ACPI_FAILURE(status)) |
| 556 | return -EIO; |
| 557 | else |
| 558 | return count; |
| 559 | } |
| 560 | |
| 561 | static DEVICE_ATTR(cpufv, S_IRUGO | S_IWUSR, NULL, store_cpufv); |
| 562 | |
| 563 | static void eeepc_wmi_sysfs_exit(struct platform_device *device) |
| 564 | { |
| 565 | device_remove_file(&device->dev, &dev_attr_cpufv); |
| 566 | } |
| 567 | |
| 568 | static int eeepc_wmi_sysfs_init(struct platform_device *device) |
| 569 | { |
| 570 | int retval = -ENOMEM; |
| 571 | |
| 572 | retval = device_create_file(&device->dev, &dev_attr_cpufv); |
| 573 | if (retval) |
| 574 | goto error_sysfs; |
| 575 | |
| 576 | return 0; |
| 577 | |
| 578 | error_sysfs: |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 579 | eeepc_wmi_sysfs_exit(device); |
Chris Bagwell | 7f80d73 | 2010-10-11 18:47:18 -0500 | [diff] [blame] | 580 | return retval; |
| 581 | } |
| 582 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 583 | /* |
| 584 | * Platform device |
| 585 | */ |
| 586 | static int __init eeepc_wmi_platform_init(struct eeepc_wmi *eeepc) |
| 587 | { |
| 588 | int err; |
| 589 | |
| 590 | eeepc->platform_device = platform_device_alloc(EEEPC_WMI_FILE, -1); |
| 591 | if (!eeepc->platform_device) |
| 592 | return -ENOMEM; |
| 593 | platform_set_drvdata(eeepc->platform_device, eeepc); |
| 594 | |
| 595 | err = platform_device_add(eeepc->platform_device); |
| 596 | if (err) |
| 597 | goto fail_platform_device; |
| 598 | |
| 599 | err = eeepc_wmi_sysfs_init(eeepc->platform_device); |
| 600 | if (err) |
| 601 | goto fail_sysfs; |
| 602 | return 0; |
| 603 | |
| 604 | fail_sysfs: |
| 605 | platform_device_del(eeepc->platform_device); |
| 606 | fail_platform_device: |
| 607 | platform_device_put(eeepc->platform_device); |
| 608 | return err; |
| 609 | } |
| 610 | |
| 611 | static void eeepc_wmi_platform_exit(struct eeepc_wmi *eeepc) |
| 612 | { |
| 613 | eeepc_wmi_sysfs_exit(eeepc->platform_device); |
| 614 | platform_device_unregister(eeepc->platform_device); |
| 615 | } |
| 616 | |
| 617 | /* |
| 618 | * WMI Driver |
| 619 | */ |
| 620 | static struct platform_device * __init eeepc_wmi_add(void) |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 621 | { |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 622 | struct eeepc_wmi *eeepc; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 623 | acpi_status status; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 624 | int err; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 625 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 626 | eeepc = kzalloc(sizeof(struct eeepc_wmi), GFP_KERNEL); |
| 627 | if (!eeepc) |
| 628 | return ERR_PTR(-ENOMEM); |
| 629 | |
| 630 | /* |
| 631 | * Register the platform device first. It is used as a parent for the |
| 632 | * sub-devices below. |
| 633 | */ |
| 634 | err = eeepc_wmi_platform_init(eeepc); |
| 635 | if (err) |
| 636 | goto fail_platform; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 637 | |
| 638 | err = eeepc_wmi_input_init(eeepc); |
| 639 | if (err) |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 640 | goto fail_input; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 641 | |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 642 | err = eeepc_wmi_led_init(eeepc); |
| 643 | if (err) |
| 644 | goto fail_leds; |
| 645 | |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame^] | 646 | err = eeepc_wmi_rfkill_init(eeepc); |
| 647 | if (err) |
| 648 | goto fail_rfkill; |
| 649 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 650 | if (!acpi_video_backlight_support()) { |
| 651 | err = eeepc_wmi_backlight_init(eeepc); |
| 652 | if (err) |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 653 | goto fail_backlight; |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 654 | } else |
| 655 | pr_info("Backlight controlled by ACPI video driver\n"); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 656 | |
| 657 | status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID, |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 658 | eeepc_wmi_notify, eeepc); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 659 | if (ACPI_FAILURE(status)) { |
| 660 | pr_err("Unable to register notify handler - %d\n", |
| 661 | status); |
| 662 | err = -ENODEV; |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 663 | goto fail_wmi_handler; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 664 | } |
| 665 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 666 | return eeepc->platform_device; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 667 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 668 | fail_wmi_handler: |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 669 | eeepc_wmi_backlight_exit(eeepc); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 670 | fail_backlight: |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame^] | 671 | eeepc_wmi_rfkill_exit(eeepc); |
| 672 | fail_rfkill: |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 673 | eeepc_wmi_led_exit(eeepc); |
| 674 | fail_leds: |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 675 | eeepc_wmi_input_exit(eeepc); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 676 | fail_input: |
| 677 | eeepc_wmi_platform_exit(eeepc); |
| 678 | fail_platform: |
| 679 | kfree(eeepc); |
| 680 | return ERR_PTR(err); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 681 | } |
| 682 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 683 | static int eeepc_wmi_remove(struct platform_device *device) |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 684 | { |
| 685 | struct eeepc_wmi *eeepc; |
| 686 | |
| 687 | eeepc = platform_get_drvdata(device); |
| 688 | wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 689 | eeepc_wmi_backlight_exit(eeepc); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 690 | eeepc_wmi_input_exit(eeepc); |
Corentin Chary | 084fca6 | 2010-11-29 08:14:06 +0100 | [diff] [blame] | 691 | eeepc_wmi_led_exit(eeepc); |
Corentin Chary | ba48fdb | 2010-11-29 08:14:07 +0100 | [diff] [blame^] | 692 | eeepc_wmi_rfkill_exit(eeepc); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 693 | eeepc_wmi_platform_exit(eeepc); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 694 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 695 | kfree(eeepc); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 696 | return 0; |
| 697 | } |
| 698 | |
| 699 | static struct platform_driver platform_driver = { |
| 700 | .driver = { |
| 701 | .name = EEEPC_WMI_FILE, |
| 702 | .owner = THIS_MODULE, |
| 703 | }, |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 704 | }; |
| 705 | |
| 706 | static int __init eeepc_wmi_init(void) |
| 707 | { |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 708 | int err; |
| 709 | |
Yong Wang | 3d7b165 | 2010-04-11 09:27:54 +0800 | [diff] [blame] | 710 | if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID) || |
| 711 | !wmi_has_guid(EEEPC_WMI_MGMT_GUID)) { |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 712 | pr_warning("No known WMI GUID found\n"); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 713 | return -ENODEV; |
| 714 | } |
| 715 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 716 | platform_device = eeepc_wmi_add(); |
| 717 | if (IS_ERR(platform_device)) { |
| 718 | err = PTR_ERR(platform_device); |
| 719 | goto fail_eeepc_wmi; |
Yong Wang | 8124888 | 2010-04-11 09:26:33 +0800 | [diff] [blame] | 720 | } |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 721 | |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 722 | err = platform_driver_register(&platform_driver); |
| 723 | if (err) { |
| 724 | pr_warning("Unable to register platform driver\n"); |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 725 | goto fail_platform_driver; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | return 0; |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 729 | |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 730 | fail_platform_driver: |
| 731 | eeepc_wmi_remove(platform_device); |
| 732 | fail_eeepc_wmi: |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 733 | return err; |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 734 | } |
| 735 | |
| 736 | static void __exit eeepc_wmi_exit(void) |
| 737 | { |
Corentin Chary | 27c136c | 2010-11-29 08:14:05 +0100 | [diff] [blame] | 738 | eeepc_wmi_remove(platform_device); |
Yong Wang | 45f2c69 | 2010-04-11 09:27:19 +0800 | [diff] [blame] | 739 | platform_driver_unregister(&platform_driver); |
Yong Wang | ee027e4 | 2010-03-21 10:26:34 +0800 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | module_init(eeepc_wmi_init); |
| 743 | module_exit(eeepc_wmi_exit); |