diff options
Diffstat (limited to 'drivers/platform/x86/eeepc-wmi.c')
| -rw-r--r-- | drivers/platform/x86/eeepc-wmi.c | 333 |
1 files changed, 294 insertions, 39 deletions
diff --git a/drivers/platform/x86/eeepc-wmi.c b/drivers/platform/x86/eeepc-wmi.c index 9f8822658fd7..b227eb469f49 100644 --- a/drivers/platform/x86/eeepc-wmi.c +++ b/drivers/platform/x86/eeepc-wmi.c | |||
| @@ -23,6 +23,8 @@ | |||
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 24 | */ | 24 | */ |
| 25 | 25 | ||
| 26 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt | ||
| 27 | |||
| 26 | #include <linux/kernel.h> | 28 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> | 29 | #include <linux/module.h> |
| 28 | #include <linux/init.h> | 30 | #include <linux/init.h> |
| @@ -30,22 +32,34 @@ | |||
| 30 | #include <linux/slab.h> | 32 | #include <linux/slab.h> |
| 31 | #include <linux/input.h> | 33 | #include <linux/input.h> |
| 32 | #include <linux/input/sparse-keymap.h> | 34 | #include <linux/input/sparse-keymap.h> |
| 35 | #include <linux/fb.h> | ||
| 36 | #include <linux/backlight.h> | ||
| 37 | #include <linux/platform_device.h> | ||
| 33 | #include <acpi/acpi_bus.h> | 38 | #include <acpi/acpi_bus.h> |
| 34 | #include <acpi/acpi_drivers.h> | 39 | #include <acpi/acpi_drivers.h> |
| 35 | 40 | ||
| 41 | #define EEEPC_WMI_FILE "eeepc-wmi" | ||
| 42 | |||
| 36 | MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>"); | 43 | MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>"); |
| 37 | MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver"); | 44 | MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver"); |
| 38 | MODULE_LICENSE("GPL"); | 45 | MODULE_LICENSE("GPL"); |
| 39 | 46 | ||
| 40 | #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000" | 47 | #define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000" |
| 48 | #define EEEPC_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66" | ||
| 41 | 49 | ||
| 42 | MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID); | 50 | MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID); |
| 51 | MODULE_ALIAS("wmi:"EEEPC_WMI_MGMT_GUID); | ||
| 43 | 52 | ||
| 44 | #define NOTIFY_BRNUP_MIN 0x11 | 53 | #define NOTIFY_BRNUP_MIN 0x11 |
| 45 | #define NOTIFY_BRNUP_MAX 0x1f | 54 | #define NOTIFY_BRNUP_MAX 0x1f |
| 46 | #define NOTIFY_BRNDOWN_MIN 0x20 | 55 | #define NOTIFY_BRNDOWN_MIN 0x20 |
| 47 | #define NOTIFY_BRNDOWN_MAX 0x2e | 56 | #define NOTIFY_BRNDOWN_MAX 0x2e |
| 48 | 57 | ||
| 58 | #define EEEPC_WMI_METHODID_DEVS 0x53564544 | ||
| 59 | #define EEEPC_WMI_METHODID_DSTS 0x53544344 | ||
| 60 | |||
| 61 | #define EEEPC_WMI_DEVID_BACKLIGHT 0x00050012 | ||
| 62 | |||
| 49 | static const struct key_entry eeepc_wmi_keymap[] = { | 63 | static const struct key_entry eeepc_wmi_keymap[] = { |
| 50 | /* Sleep already handled via generic ACPI code */ | 64 | /* Sleep already handled via generic ACPI code */ |
| 51 | { KE_KEY, 0x5d, { KEY_WLAN } }, | 65 | { KE_KEY, 0x5d, { KEY_WLAN } }, |
| @@ -58,18 +72,198 @@ static const struct key_entry eeepc_wmi_keymap[] = { | |||
| 58 | { KE_END, 0}, | 72 | { KE_END, 0}, |
| 59 | }; | 73 | }; |
| 60 | 74 | ||
| 61 | static struct input_dev *eeepc_wmi_input_dev; | 75 | struct bios_args { |
| 76 | u32 dev_id; | ||
| 77 | u32 ctrl_param; | ||
| 78 | }; | ||
| 79 | |||
| 80 | struct eeepc_wmi { | ||
| 81 | struct input_dev *inputdev; | ||
| 82 | struct backlight_device *backlight_device; | ||
| 83 | }; | ||
| 84 | |||
| 85 | static struct platform_device *platform_device; | ||
| 86 | |||
| 87 | static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc) | ||
| 88 | { | ||
| 89 | int err; | ||
| 90 | |||
| 91 | eeepc->inputdev = input_allocate_device(); | ||
| 92 | if (!eeepc->inputdev) | ||
| 93 | return -ENOMEM; | ||
| 94 | |||
| 95 | eeepc->inputdev->name = "Eee PC WMI hotkeys"; | ||
| 96 | eeepc->inputdev->phys = EEEPC_WMI_FILE "/input0"; | ||
| 97 | eeepc->inputdev->id.bustype = BUS_HOST; | ||
| 98 | eeepc->inputdev->dev.parent = &platform_device->dev; | ||
| 99 | |||
| 100 | err = sparse_keymap_setup(eeepc->inputdev, eeepc_wmi_keymap, NULL); | ||
| 101 | if (err) | ||
| 102 | goto err_free_dev; | ||
| 103 | |||
| 104 | err = input_register_device(eeepc->inputdev); | ||
| 105 | if (err) | ||
| 106 | goto err_free_keymap; | ||
| 107 | |||
| 108 | return 0; | ||
| 109 | |||
| 110 | err_free_keymap: | ||
| 111 | sparse_keymap_free(eeepc->inputdev); | ||
| 112 | err_free_dev: | ||
| 113 | input_free_device(eeepc->inputdev); | ||
| 114 | return err; | ||
| 115 | } | ||
| 116 | |||
| 117 | static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc) | ||
| 118 | { | ||
| 119 | if (eeepc->inputdev) { | ||
| 120 | sparse_keymap_free(eeepc->inputdev); | ||
| 121 | input_unregister_device(eeepc->inputdev); | ||
| 122 | } | ||
| 123 | |||
| 124 | eeepc->inputdev = NULL; | ||
| 125 | } | ||
| 126 | |||
| 127 | static acpi_status eeepc_wmi_get_devstate(u32 dev_id, u32 *ctrl_param) | ||
| 128 | { | ||
| 129 | struct acpi_buffer input = { (acpi_size)sizeof(u32), &dev_id }; | ||
| 130 | struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; | ||
| 131 | union acpi_object *obj; | ||
| 132 | acpi_status status; | ||
| 133 | u32 tmp; | ||
| 134 | |||
| 135 | status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, | ||
| 136 | 1, EEEPC_WMI_METHODID_DSTS, &input, &output); | ||
| 137 | |||
| 138 | if (ACPI_FAILURE(status)) | ||
| 139 | return status; | ||
| 140 | |||
| 141 | obj = (union acpi_object *)output.pointer; | ||
| 142 | if (obj && obj->type == ACPI_TYPE_INTEGER) | ||
| 143 | tmp = (u32)obj->integer.value; | ||
| 144 | else | ||
| 145 | tmp = 0; | ||
| 146 | |||
| 147 | if (ctrl_param) | ||
| 148 | *ctrl_param = tmp; | ||
| 149 | |||
| 150 | kfree(obj); | ||
| 151 | |||
| 152 | return status; | ||
| 153 | |||
| 154 | } | ||
| 155 | |||
| 156 | static acpi_status eeepc_wmi_set_devstate(u32 dev_id, u32 ctrl_param) | ||
| 157 | { | ||
| 158 | struct bios_args args = { | ||
| 159 | .dev_id = dev_id, | ||
| 160 | .ctrl_param = ctrl_param, | ||
| 161 | }; | ||
| 162 | struct acpi_buffer input = { (acpi_size)sizeof(args), &args }; | ||
| 163 | acpi_status status; | ||
| 164 | |||
| 165 | status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID, | ||
| 166 | 1, EEEPC_WMI_METHODID_DEVS, &input, NULL); | ||
| 167 | |||
| 168 | return status; | ||
| 169 | } | ||
| 170 | |||
| 171 | static int read_brightness(struct backlight_device *bd) | ||
| 172 | { | ||
| 173 | static u32 ctrl_param; | ||
| 174 | acpi_status status; | ||
| 175 | |||
| 176 | status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_BACKLIGHT, &ctrl_param); | ||
| 177 | |||
| 178 | if (ACPI_FAILURE(status)) | ||
| 179 | return -1; | ||
| 180 | else | ||
| 181 | return ctrl_param & 0xFF; | ||
| 182 | } | ||
| 183 | |||
| 184 | static int update_bl_status(struct backlight_device *bd) | ||
| 185 | { | ||
| 186 | |||
| 187 | static u32 ctrl_param; | ||
| 188 | acpi_status status; | ||
| 189 | |||
| 190 | ctrl_param = bd->props.brightness; | ||
| 191 | |||
| 192 | status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BACKLIGHT, ctrl_param); | ||
| 193 | |||
| 194 | if (ACPI_FAILURE(status)) | ||
| 195 | return -1; | ||
| 196 | else | ||
| 197 | return 0; | ||
| 198 | } | ||
| 199 | |||
| 200 | static const struct backlight_ops eeepc_wmi_bl_ops = { | ||
| 201 | .get_brightness = read_brightness, | ||
| 202 | .update_status = update_bl_status, | ||
| 203 | }; | ||
| 204 | |||
| 205 | static int eeepc_wmi_backlight_notify(struct eeepc_wmi *eeepc, int code) | ||
| 206 | { | ||
| 207 | struct backlight_device *bd = eeepc->backlight_device; | ||
| 208 | int old = bd->props.brightness; | ||
| 209 | int new; | ||
| 210 | |||
| 211 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) | ||
| 212 | new = code - NOTIFY_BRNUP_MIN + 1; | ||
| 213 | else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) | ||
| 214 | new = code - NOTIFY_BRNDOWN_MIN; | ||
| 215 | |||
| 216 | bd->props.brightness = new; | ||
| 217 | backlight_update_status(bd); | ||
| 218 | backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY); | ||
| 219 | |||
| 220 | return old; | ||
| 221 | } | ||
| 222 | |||
| 223 | static int eeepc_wmi_backlight_init(struct eeepc_wmi *eeepc) | ||
| 224 | { | ||
| 225 | struct backlight_device *bd; | ||
| 226 | struct backlight_properties props; | ||
| 227 | |||
| 228 | memset(&props, 0, sizeof(struct backlight_properties)); | ||
| 229 | props.max_brightness = 15; | ||
| 230 | bd = backlight_device_register(EEEPC_WMI_FILE, | ||
| 231 | &platform_device->dev, eeepc, | ||
| 232 | &eeepc_wmi_bl_ops, &props); | ||
| 233 | if (IS_ERR(bd)) { | ||
| 234 | pr_err("Could not register backlight device\n"); | ||
| 235 | return PTR_ERR(bd); | ||
| 236 | } | ||
| 237 | |||
| 238 | eeepc->backlight_device = bd; | ||
| 239 | |||
| 240 | bd->props.brightness = read_brightness(bd); | ||
| 241 | bd->props.power = FB_BLANK_UNBLANK; | ||
| 242 | backlight_update_status(bd); | ||
| 243 | |||
| 244 | return 0; | ||
| 245 | } | ||
| 246 | |||
| 247 | static void eeepc_wmi_backlight_exit(struct eeepc_wmi *eeepc) | ||
| 248 | { | ||
| 249 | if (eeepc->backlight_device) | ||
| 250 | backlight_device_unregister(eeepc->backlight_device); | ||
| 251 | |||
| 252 | eeepc->backlight_device = NULL; | ||
| 253 | } | ||
| 62 | 254 | ||
| 63 | static void eeepc_wmi_notify(u32 value, void *context) | 255 | static void eeepc_wmi_notify(u32 value, void *context) |
| 64 | { | 256 | { |
| 257 | struct eeepc_wmi *eeepc = context; | ||
| 65 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; | 258 | struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; |
| 66 | union acpi_object *obj; | 259 | union acpi_object *obj; |
| 67 | acpi_status status; | 260 | acpi_status status; |
| 68 | int code; | 261 | int code; |
| 262 | int orig_code; | ||
| 69 | 263 | ||
| 70 | status = wmi_get_event_data(value, &response); | 264 | status = wmi_get_event_data(value, &response); |
| 71 | if (status != AE_OK) { | 265 | if (status != AE_OK) { |
| 72 | pr_err("EEEPC WMI: bad event status 0x%x\n", status); | 266 | pr_err("bad event status 0x%x\n", status); |
| 73 | return; | 267 | return; |
| 74 | } | 268 | } |
| 75 | 269 | ||
| @@ -77,81 +271,142 @@ static void eeepc_wmi_notify(u32 value, void *context) | |||
| 77 | 271 | ||
| 78 | if (obj && obj->type == ACPI_TYPE_INTEGER) { | 272 | if (obj && obj->type == ACPI_TYPE_INTEGER) { |
| 79 | code = obj->integer.value; | 273 | code = obj->integer.value; |
| 274 | orig_code = code; | ||
| 80 | 275 | ||
| 81 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) | 276 | if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX) |
| 82 | code = NOTIFY_BRNUP_MIN; | 277 | code = NOTIFY_BRNUP_MIN; |
| 83 | else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) | 278 | else if (code >= NOTIFY_BRNDOWN_MIN && |
| 279 | code <= NOTIFY_BRNDOWN_MAX) | ||
| 84 | code = NOTIFY_BRNDOWN_MIN; | 280 | code = NOTIFY_BRNDOWN_MIN; |
| 85 | 281 | ||
| 86 | if (!sparse_keymap_report_event(eeepc_wmi_input_dev, | 282 | if (code == NOTIFY_BRNUP_MIN || code == NOTIFY_BRNDOWN_MIN) { |
| 283 | if (!acpi_video_backlight_support()) | ||
| 284 | eeepc_wmi_backlight_notify(eeepc, orig_code); | ||
| 285 | } | ||
| 286 | |||
| 287 | if (!sparse_keymap_report_event(eeepc->inputdev, | ||
| 87 | code, 1, true)) | 288 | code, 1, true)) |
| 88 | pr_info("EEEPC WMI: Unknown key %x pressed\n", code); | 289 | pr_info("Unknown key %x pressed\n", code); |
| 89 | } | 290 | } |
| 90 | 291 | ||
| 91 | kfree(obj); | 292 | kfree(obj); |
| 92 | } | 293 | } |
| 93 | 294 | ||
| 94 | static int eeepc_wmi_input_setup(void) | 295 | static int __devinit eeepc_wmi_platform_probe(struct platform_device *device) |
| 95 | { | 296 | { |
| 297 | struct eeepc_wmi *eeepc; | ||
| 96 | int err; | 298 | int err; |
| 299 | acpi_status status; | ||
| 97 | 300 | ||
| 98 | eeepc_wmi_input_dev = input_allocate_device(); | 301 | eeepc = platform_get_drvdata(device); |
| 99 | if (!eeepc_wmi_input_dev) | ||
| 100 | return -ENOMEM; | ||
| 101 | |||
| 102 | eeepc_wmi_input_dev->name = "Eee PC WMI hotkeys"; | ||
| 103 | eeepc_wmi_input_dev->phys = "wmi/input0"; | ||
| 104 | eeepc_wmi_input_dev->id.bustype = BUS_HOST; | ||
| 105 | 302 | ||
| 106 | err = sparse_keymap_setup(eeepc_wmi_input_dev, eeepc_wmi_keymap, NULL); | 303 | err = eeepc_wmi_input_init(eeepc); |
| 107 | if (err) | 304 | if (err) |
| 108 | goto err_free_dev; | 305 | goto error_input; |
| 109 | 306 | ||
| 110 | err = input_register_device(eeepc_wmi_input_dev); | 307 | if (!acpi_video_backlight_support()) { |
| 111 | if (err) | 308 | err = eeepc_wmi_backlight_init(eeepc); |
| 112 | goto err_free_keymap; | 309 | if (err) |
| 310 | goto error_backlight; | ||
| 311 | } else | ||
| 312 | pr_info("Backlight controlled by ACPI video driver\n"); | ||
| 313 | |||
| 314 | status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID, | ||
| 315 | eeepc_wmi_notify, eeepc); | ||
| 316 | if (ACPI_FAILURE(status)) { | ||
| 317 | pr_err("Unable to register notify handler - %d\n", | ||
| 318 | status); | ||
| 319 | err = -ENODEV; | ||
| 320 | goto error_wmi; | ||
| 321 | } | ||
| 113 | 322 | ||
| 114 | return 0; | 323 | return 0; |
| 115 | 324 | ||
| 116 | err_free_keymap: | 325 | error_wmi: |
| 117 | sparse_keymap_free(eeepc_wmi_input_dev); | 326 | eeepc_wmi_backlight_exit(eeepc); |
| 118 | err_free_dev: | 327 | error_backlight: |
| 119 | input_free_device(eeepc_wmi_input_dev); | 328 | eeepc_wmi_input_exit(eeepc); |
| 329 | error_input: | ||
| 120 | return err; | 330 | return err; |
| 121 | } | 331 | } |
| 122 | 332 | ||
| 333 | static int __devexit eeepc_wmi_platform_remove(struct platform_device *device) | ||
| 334 | { | ||
| 335 | struct eeepc_wmi *eeepc; | ||
| 336 | |||
| 337 | eeepc = platform_get_drvdata(device); | ||
| 338 | wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); | ||
| 339 | eeepc_wmi_backlight_exit(eeepc); | ||
| 340 | eeepc_wmi_input_exit(eeepc); | ||
| 341 | |||
| 342 | return 0; | ||
| 343 | } | ||
| 344 | |||
| 345 | static struct platform_driver platform_driver = { | ||
| 346 | .driver = { | ||
| 347 | .name = EEEPC_WMI_FILE, | ||
| 348 | .owner = THIS_MODULE, | ||
| 349 | }, | ||
| 350 | .probe = eeepc_wmi_platform_probe, | ||
| 351 | .remove = __devexit_p(eeepc_wmi_platform_remove), | ||
| 352 | }; | ||
| 353 | |||
| 123 | static int __init eeepc_wmi_init(void) | 354 | static int __init eeepc_wmi_init(void) |
| 124 | { | 355 | { |
| 356 | struct eeepc_wmi *eeepc; | ||
| 125 | int err; | 357 | int err; |
| 126 | acpi_status status; | ||
| 127 | 358 | ||
| 128 | if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID)) { | 359 | if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID) || |
| 129 | pr_warning("EEEPC WMI: No known WMI GUID found\n"); | 360 | !wmi_has_guid(EEEPC_WMI_MGMT_GUID)) { |
| 361 | pr_warning("No known WMI GUID found\n"); | ||
| 130 | return -ENODEV; | 362 | return -ENODEV; |
| 131 | } | 363 | } |
| 132 | 364 | ||
| 133 | err = eeepc_wmi_input_setup(); | 365 | eeepc = kzalloc(sizeof(struct eeepc_wmi), GFP_KERNEL); |
| 134 | if (err) | 366 | if (!eeepc) |
| 135 | return err; | 367 | return -ENOMEM; |
| 136 | 368 | ||
| 137 | status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID, | 369 | platform_device = platform_device_alloc(EEEPC_WMI_FILE, -1); |
| 138 | eeepc_wmi_notify, NULL); | 370 | if (!platform_device) { |
| 139 | if (ACPI_FAILURE(status)) { | 371 | pr_warning("Unable to allocate platform device\n"); |
| 140 | sparse_keymap_free(eeepc_wmi_input_dev); | 372 | err = -ENOMEM; |
| 141 | input_unregister_device(eeepc_wmi_input_dev); | 373 | goto fail_platform; |
| 142 | pr_err("EEEPC WMI: Unable to register notify handler - %d\n", | 374 | } |
| 143 | status); | 375 | |
| 144 | return -ENODEV; | 376 | err = platform_device_add(platform_device); |
| 377 | if (err) { | ||
| 378 | pr_warning("Unable to add platform device\n"); | ||
| 379 | goto put_dev; | ||
| 380 | } | ||
| 381 | |||
| 382 | platform_set_drvdata(platform_device, eeepc); | ||
| 383 | |||
| 384 | err = platform_driver_register(&platform_driver); | ||
| 385 | if (err) { | ||
| 386 | pr_warning("Unable to register platform driver\n"); | ||
| 387 | goto del_dev; | ||
| 145 | } | 388 | } |
| 146 | 389 | ||
| 147 | return 0; | 390 | return 0; |
| 391 | |||
| 392 | del_dev: | ||
| 393 | platform_device_del(platform_device); | ||
| 394 | put_dev: | ||
| 395 | platform_device_put(platform_device); | ||
| 396 | fail_platform: | ||
| 397 | kfree(eeepc); | ||
| 398 | |||
| 399 | return err; | ||
| 148 | } | 400 | } |
| 149 | 401 | ||
| 150 | static void __exit eeepc_wmi_exit(void) | 402 | static void __exit eeepc_wmi_exit(void) |
| 151 | { | 403 | { |
| 152 | wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); | 404 | struct eeepc_wmi *eeepc; |
| 153 | sparse_keymap_free(eeepc_wmi_input_dev); | 405 | |
| 154 | input_unregister_device(eeepc_wmi_input_dev); | 406 | eeepc = platform_get_drvdata(platform_device); |
| 407 | platform_driver_unregister(&platform_driver); | ||
| 408 | platform_device_unregister(platform_device); | ||
| 409 | kfree(eeepc); | ||
| 155 | } | 410 | } |
| 156 | 411 | ||
| 157 | module_init(eeepc_wmi_init); | 412 | module_init(eeepc_wmi_init); |
