blob: f12a25da40551a510217f81f8592abbcf22070ef [file] [log] [blame]
Yong Wangee027e42010-03-21 10:26:34 +08001/*
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 Wang81248882010-04-11 09:26:33 +080026#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
27
Yong Wangee027e42010-03-21 10:26:34 +080028#include <linux/kernel.h>
29#include <linux/module.h>
30#include <linux/init.h>
31#include <linux/types.h>
Tejun Heoa32f3922010-04-05 11:37:59 +090032#include <linux/slab.h>
Yong Wangee027e42010-03-21 10:26:34 +080033#include <linux/input.h>
34#include <linux/input/sparse-keymap.h>
Yong Wang3d7b1652010-04-11 09:27:54 +080035#include <linux/fb.h>
36#include <linux/backlight.h>
Corentin Chary084fca62010-11-29 08:14:06 +010037#include <linux/leds.h>
Yong Wang45f2c692010-04-11 09:27:19 +080038#include <linux/platform_device.h>
Yong Wangee027e42010-03-21 10:26:34 +080039#include <acpi/acpi_bus.h>
40#include <acpi/acpi_drivers.h>
41
Yong Wang45f2c692010-04-11 09:27:19 +080042#define EEEPC_WMI_FILE "eeepc-wmi"
43
Yong Wangee027e42010-03-21 10:26:34 +080044MODULE_AUTHOR("Yong Wang <yong.y.wang@intel.com>");
45MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver");
46MODULE_LICENSE("GPL");
47
48#define EEEPC_WMI_EVENT_GUID "ABBC0F72-8EA1-11D1-00A0-C90629100000"
Yong Wang3d7b1652010-04-11 09:27:54 +080049#define EEEPC_WMI_MGMT_GUID "97845ED0-4E6D-11DE-8A39-0800200C9A66"
Yong Wangee027e42010-03-21 10:26:34 +080050
51MODULE_ALIAS("wmi:"EEEPC_WMI_EVENT_GUID);
Yong Wang3d7b1652010-04-11 09:27:54 +080052MODULE_ALIAS("wmi:"EEEPC_WMI_MGMT_GUID);
Yong Wangee027e42010-03-21 10:26:34 +080053
54#define NOTIFY_BRNUP_MIN 0x11
55#define NOTIFY_BRNUP_MAX 0x1f
56#define NOTIFY_BRNDOWN_MIN 0x20
57#define NOTIFY_BRNDOWN_MAX 0x2e
58
Yong Wang3d7b1652010-04-11 09:27:54 +080059#define EEEPC_WMI_METHODID_DEVS 0x53564544
60#define EEEPC_WMI_METHODID_DSTS 0x53544344
Chris Bagwell7f80d732010-10-11 18:47:18 -050061#define EEEPC_WMI_METHODID_CFVS 0x53564643
Yong Wang3d7b1652010-04-11 09:27:54 +080062
63#define EEEPC_WMI_DEVID_BACKLIGHT 0x00050012
Corentin Chary084fca62010-11-29 08:14:06 +010064#define EEEPC_WMI_DEVID_TPDLED 0x00100011
Yong Wang3d7b1652010-04-11 09:27:54 +080065
Yong Wangee027e42010-03-21 10:26:34 +080066static const struct key_entry eeepc_wmi_keymap[] = {
67 /* Sleep already handled via generic ACPI code */
68 { KE_KEY, 0x5d, { KEY_WLAN } },
69 { KE_KEY, 0x32, { KEY_MUTE } },
70 { KE_KEY, 0x31, { KEY_VOLUMEDOWN } },
71 { KE_KEY, 0x30, { KEY_VOLUMEUP } },
72 { KE_IGNORE, NOTIFY_BRNDOWN_MIN, { KEY_BRIGHTNESSDOWN } },
73 { KE_IGNORE, NOTIFY_BRNUP_MIN, { KEY_BRIGHTNESSUP } },
74 { KE_KEY, 0xcc, { KEY_SWITCHVIDEOMODE } },
Chris Bagwelleda17482010-10-11 18:47:17 -050075 { KE_KEY, 0x6b, { KEY_F13 } }, /* Disable Touchpad */
76 { KE_KEY, 0xe1, { KEY_F14 } },
77 { KE_KEY, 0xe9, { KEY_DISPLAY_OFF } },
78 { KE_KEY, 0xe0, { KEY_PROG1 } },
79 { KE_KEY, 0x5c, { KEY_F15 } },
Yong Wangee027e42010-03-21 10:26:34 +080080 { KE_END, 0},
81};
82
Yong Wang3d7b1652010-04-11 09:27:54 +080083struct bios_args {
84 u32 dev_id;
85 u32 ctrl_param;
86};
87
Yong Wang81248882010-04-11 09:26:33 +080088struct eeepc_wmi {
89 struct input_dev *inputdev;
Yong Wang3d7b1652010-04-11 09:27:54 +080090 struct backlight_device *backlight_device;
Corentin Chary27c136c2010-11-29 08:14:05 +010091 struct platform_device *platform_device;
Corentin Chary084fca62010-11-29 08:14:06 +010092
93 struct led_classdev tpd_led;
94 int tpd_led_wk;
95 struct workqueue_struct *led_workqueue;
96 struct work_struct tpd_led_work;
Yong Wang81248882010-04-11 09:26:33 +080097};
98
Corentin Chary27c136c2010-11-29 08:14:05 +010099/* Only used in eeepc_wmi_init() and eeepc_wmi_exit() */
Yong Wang45f2c692010-04-11 09:27:19 +0800100static struct platform_device *platform_device;
Yong Wangee027e42010-03-21 10:26:34 +0800101
Yong Wang81248882010-04-11 09:26:33 +0800102static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc)
Yong Wangee027e42010-03-21 10:26:34 +0800103{
104 int err;
105
Yong Wang81248882010-04-11 09:26:33 +0800106 eeepc->inputdev = input_allocate_device();
107 if (!eeepc->inputdev)
Yong Wangee027e42010-03-21 10:26:34 +0800108 return -ENOMEM;
109
Yong Wang81248882010-04-11 09:26:33 +0800110 eeepc->inputdev->name = "Eee PC WMI hotkeys";
Yong Wang45f2c692010-04-11 09:27:19 +0800111 eeepc->inputdev->phys = EEEPC_WMI_FILE "/input0";
Yong Wang81248882010-04-11 09:26:33 +0800112 eeepc->inputdev->id.bustype = BUS_HOST;
Corentin Chary27c136c2010-11-29 08:14:05 +0100113 eeepc->inputdev->dev.parent = &eeepc->platform_device->dev;
Yong Wangee027e42010-03-21 10:26:34 +0800114
Yong Wang81248882010-04-11 09:26:33 +0800115 err = sparse_keymap_setup(eeepc->inputdev, eeepc_wmi_keymap, NULL);
Yong Wangee027e42010-03-21 10:26:34 +0800116 if (err)
117 goto err_free_dev;
118
Yong Wang81248882010-04-11 09:26:33 +0800119 err = input_register_device(eeepc->inputdev);
Yong Wangee027e42010-03-21 10:26:34 +0800120 if (err)
121 goto err_free_keymap;
122
123 return 0;
124
125err_free_keymap:
Yong Wang81248882010-04-11 09:26:33 +0800126 sparse_keymap_free(eeepc->inputdev);
Yong Wangee027e42010-03-21 10:26:34 +0800127err_free_dev:
Yong Wang81248882010-04-11 09:26:33 +0800128 input_free_device(eeepc->inputdev);
Yong Wangee027e42010-03-21 10:26:34 +0800129 return err;
130}
131
Yong Wang81248882010-04-11 09:26:33 +0800132static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc)
133{
134 if (eeepc->inputdev) {
135 sparse_keymap_free(eeepc->inputdev);
136 input_unregister_device(eeepc->inputdev);
137 }
138
139 eeepc->inputdev = NULL;
140}
141
Yong Wang3d7b1652010-04-11 09:27:54 +0800142static acpi_status eeepc_wmi_get_devstate(u32 dev_id, u32 *ctrl_param)
143{
144 struct acpi_buffer input = { (acpi_size)sizeof(u32), &dev_id };
145 struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL };
146 union acpi_object *obj;
147 acpi_status status;
148 u32 tmp;
149
150 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID,
151 1, EEEPC_WMI_METHODID_DSTS, &input, &output);
152
153 if (ACPI_FAILURE(status))
154 return status;
155
156 obj = (union acpi_object *)output.pointer;
157 if (obj && obj->type == ACPI_TYPE_INTEGER)
158 tmp = (u32)obj->integer.value;
159 else
160 tmp = 0;
161
162 if (ctrl_param)
163 *ctrl_param = tmp;
164
165 kfree(obj);
166
167 return status;
168
169}
170
171static acpi_status eeepc_wmi_set_devstate(u32 dev_id, u32 ctrl_param)
172{
173 struct bios_args args = {
174 .dev_id = dev_id,
175 .ctrl_param = ctrl_param,
176 };
177 struct acpi_buffer input = { (acpi_size)sizeof(args), &args };
178 acpi_status status;
179
180 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID,
181 1, EEEPC_WMI_METHODID_DEVS, &input, NULL);
182
183 return status;
184}
185
Corentin Chary084fca62010-11-29 08:14:06 +0100186/*
187 * LEDs
188 */
189/*
190 * These functions actually update the LED's, and are called from a
191 * workqueue. By doing this as separate work rather than when the LED
192 * subsystem asks, we avoid messing with the Eeepc ACPI stuff during a
193 * potentially bad time, such as a timer interrupt.
194 */
195static void tpd_led_update(struct work_struct *work)
196{
197 int ctrl_param;
198 struct eeepc_wmi *eeepc;
199
200 eeepc = container_of(work, struct eeepc_wmi, tpd_led_work);
201
202 ctrl_param = eeepc->tpd_led_wk;
203 eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_TPDLED, ctrl_param);
204}
205
206static void tpd_led_set(struct led_classdev *led_cdev,
207 enum led_brightness value)
208{
209 struct eeepc_wmi *eeepc;
210
211 eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led);
212
213 eeepc->tpd_led_wk = !!value;
214 queue_work(eeepc->led_workqueue, &eeepc->tpd_led_work);
215}
216
217static int read_tpd_state(struct eeepc_wmi *eeepc)
218{
219 static u32 ctrl_param;
220 acpi_status status;
221
222 status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_TPDLED, &ctrl_param);
223
224 if (ACPI_FAILURE(status))
225 return -1;
226 else if (!ctrl_param || ctrl_param == 0x00060000)
227 /*
228 * if touchpad led is present, DSTS will set some bits,
229 * usually 0x00020000.
230 * 0x00060000 means that the device is not supported
231 */
232 return -ENODEV;
233 else
234 /* Status is stored in the first bit */
235 return ctrl_param & 0x1;
236}
237
238static enum led_brightness tpd_led_get(struct led_classdev *led_cdev)
239{
240 struct eeepc_wmi *eeepc;
241
242 eeepc = container_of(led_cdev, struct eeepc_wmi, tpd_led);
243
244 return read_tpd_state(eeepc);
245}
246
247static int eeepc_wmi_led_init(struct eeepc_wmi *eeepc)
248{
249 int rv;
250
251 if (read_tpd_state(eeepc) < 0)
252 return 0;
253
254 eeepc->led_workqueue = create_singlethread_workqueue("led_workqueue");
255 if (!eeepc->led_workqueue)
256 return -ENOMEM;
257 INIT_WORK(&eeepc->tpd_led_work, tpd_led_update);
258
259 eeepc->tpd_led.name = "eeepc::touchpad";
260 eeepc->tpd_led.brightness_set = tpd_led_set;
261 eeepc->tpd_led.brightness_get = tpd_led_get;
262 eeepc->tpd_led.max_brightness = 1;
263
264 rv = led_classdev_register(&eeepc->platform_device->dev,
265 &eeepc->tpd_led);
266 if (rv) {
267 destroy_workqueue(eeepc->led_workqueue);
268 return rv;
269 }
270
271 return 0;
272}
273
274static void eeepc_wmi_led_exit(struct eeepc_wmi *eeepc)
275{
276 if (eeepc->tpd_led.dev)
277 led_classdev_unregister(&eeepc->tpd_led);
278 if (eeepc->led_workqueue)
279 destroy_workqueue(eeepc->led_workqueue);
280}
281
282/*
283 * Backlight
284 */
Yong Wang3d7b1652010-04-11 09:27:54 +0800285static int read_brightness(struct backlight_device *bd)
286{
287 static u32 ctrl_param;
288 acpi_status status;
289
290 status = eeepc_wmi_get_devstate(EEEPC_WMI_DEVID_BACKLIGHT, &ctrl_param);
291
292 if (ACPI_FAILURE(status))
293 return -1;
294 else
295 return ctrl_param & 0xFF;
296}
297
298static int update_bl_status(struct backlight_device *bd)
299{
300
301 static u32 ctrl_param;
302 acpi_status status;
303
304 ctrl_param = bd->props.brightness;
305
306 status = eeepc_wmi_set_devstate(EEEPC_WMI_DEVID_BACKLIGHT, ctrl_param);
307
308 if (ACPI_FAILURE(status))
309 return -1;
310 else
311 return 0;
312}
313
314static const struct backlight_ops eeepc_wmi_bl_ops = {
315 .get_brightness = read_brightness,
316 .update_status = update_bl_status,
317};
318
319static int eeepc_wmi_backlight_notify(struct eeepc_wmi *eeepc, int code)
320{
321 struct backlight_device *bd = eeepc->backlight_device;
322 int old = bd->props.brightness;
Daniel Mackb7670ed2010-05-19 12:37:01 +0200323 int new = old;
Yong Wang3d7b1652010-04-11 09:27:54 +0800324
325 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
326 new = code - NOTIFY_BRNUP_MIN + 1;
327 else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX)
328 new = code - NOTIFY_BRNDOWN_MIN;
329
330 bd->props.brightness = new;
331 backlight_update_status(bd);
332 backlight_force_update(bd, BACKLIGHT_UPDATE_HOTKEY);
333
334 return old;
335}
336
337static int eeepc_wmi_backlight_init(struct eeepc_wmi *eeepc)
338{
339 struct backlight_device *bd;
340 struct backlight_properties props;
341
342 memset(&props, 0, sizeof(struct backlight_properties));
343 props.max_brightness = 15;
344 bd = backlight_device_register(EEEPC_WMI_FILE,
Corentin Chary27c136c2010-11-29 08:14:05 +0100345 &eeepc->platform_device->dev, eeepc,
Yong Wang3d7b1652010-04-11 09:27:54 +0800346 &eeepc_wmi_bl_ops, &props);
347 if (IS_ERR(bd)) {
348 pr_err("Could not register backlight device\n");
349 return PTR_ERR(bd);
350 }
351
352 eeepc->backlight_device = bd;
353
354 bd->props.brightness = read_brightness(bd);
355 bd->props.power = FB_BLANK_UNBLANK;
356 backlight_update_status(bd);
357
358 return 0;
359}
360
361static void eeepc_wmi_backlight_exit(struct eeepc_wmi *eeepc)
362{
363 if (eeepc->backlight_device)
364 backlight_device_unregister(eeepc->backlight_device);
365
366 eeepc->backlight_device = NULL;
367}
368
369static void eeepc_wmi_notify(u32 value, void *context)
370{
371 struct eeepc_wmi *eeepc = context;
372 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
373 union acpi_object *obj;
374 acpi_status status;
375 int code;
376 int orig_code;
377
378 status = wmi_get_event_data(value, &response);
379 if (status != AE_OK) {
380 pr_err("bad event status 0x%x\n", status);
381 return;
382 }
383
384 obj = (union acpi_object *)response.pointer;
385
386 if (obj && obj->type == ACPI_TYPE_INTEGER) {
387 code = obj->integer.value;
388 orig_code = code;
389
390 if (code >= NOTIFY_BRNUP_MIN && code <= NOTIFY_BRNUP_MAX)
391 code = NOTIFY_BRNUP_MIN;
392 else if (code >= NOTIFY_BRNDOWN_MIN &&
393 code <= NOTIFY_BRNDOWN_MAX)
394 code = NOTIFY_BRNDOWN_MIN;
395
396 if (code == NOTIFY_BRNUP_MIN || code == NOTIFY_BRNDOWN_MIN) {
397 if (!acpi_video_backlight_support())
398 eeepc_wmi_backlight_notify(eeepc, orig_code);
399 }
400
401 if (!sparse_keymap_report_event(eeepc->inputdev,
402 code, 1, true))
403 pr_info("Unknown key %x pressed\n", code);
404 }
405
406 kfree(obj);
407}
408
Dmitry Torokhov67fa38e2010-11-03 11:14:01 -0700409static ssize_t store_cpufv(struct device *dev, struct device_attribute *attr,
410 const char *buf, size_t count)
Chris Bagwell7f80d732010-10-11 18:47:18 -0500411{
412 int value;
413 struct acpi_buffer input = { (acpi_size)sizeof(value), &value };
414 acpi_status status;
415
416 if (!count || sscanf(buf, "%i", &value) != 1)
417 return -EINVAL;
418 if (value < 0 || value > 2)
419 return -EINVAL;
420
421 status = wmi_evaluate_method(EEEPC_WMI_MGMT_GUID,
422 1, EEEPC_WMI_METHODID_CFVS, &input, NULL);
423
424 if (ACPI_FAILURE(status))
425 return -EIO;
426 else
427 return count;
428}
429
430static DEVICE_ATTR(cpufv, S_IRUGO | S_IWUSR, NULL, store_cpufv);
431
432static void eeepc_wmi_sysfs_exit(struct platform_device *device)
433{
434 device_remove_file(&device->dev, &dev_attr_cpufv);
435}
436
437static int eeepc_wmi_sysfs_init(struct platform_device *device)
438{
439 int retval = -ENOMEM;
440
441 retval = device_create_file(&device->dev, &dev_attr_cpufv);
442 if (retval)
443 goto error_sysfs;
444
445 return 0;
446
447error_sysfs:
Corentin Chary27c136c2010-11-29 08:14:05 +0100448 eeepc_wmi_sysfs_exit(device);
Chris Bagwell7f80d732010-10-11 18:47:18 -0500449 return retval;
450}
451
Corentin Chary27c136c2010-11-29 08:14:05 +0100452/*
453 * Platform device
454 */
455static int __init eeepc_wmi_platform_init(struct eeepc_wmi *eeepc)
456{
457 int err;
458
459 eeepc->platform_device = platform_device_alloc(EEEPC_WMI_FILE, -1);
460 if (!eeepc->platform_device)
461 return -ENOMEM;
462 platform_set_drvdata(eeepc->platform_device, eeepc);
463
464 err = platform_device_add(eeepc->platform_device);
465 if (err)
466 goto fail_platform_device;
467
468 err = eeepc_wmi_sysfs_init(eeepc->platform_device);
469 if (err)
470 goto fail_sysfs;
471 return 0;
472
473fail_sysfs:
474 platform_device_del(eeepc->platform_device);
475fail_platform_device:
476 platform_device_put(eeepc->platform_device);
477 return err;
478}
479
480static void eeepc_wmi_platform_exit(struct eeepc_wmi *eeepc)
481{
482 eeepc_wmi_sysfs_exit(eeepc->platform_device);
483 platform_device_unregister(eeepc->platform_device);
484}
485
486/*
487 * WMI Driver
488 */
489static struct platform_device * __init eeepc_wmi_add(void)
Yong Wangee027e42010-03-21 10:26:34 +0800490{
Yong Wang45f2c692010-04-11 09:27:19 +0800491 struct eeepc_wmi *eeepc;
Yong Wangee027e42010-03-21 10:26:34 +0800492 acpi_status status;
Corentin Chary27c136c2010-11-29 08:14:05 +0100493 int err;
Yong Wangee027e42010-03-21 10:26:34 +0800494
Corentin Chary27c136c2010-11-29 08:14:05 +0100495 eeepc = kzalloc(sizeof(struct eeepc_wmi), GFP_KERNEL);
496 if (!eeepc)
497 return ERR_PTR(-ENOMEM);
498
499 /*
500 * Register the platform device first. It is used as a parent for the
501 * sub-devices below.
502 */
503 err = eeepc_wmi_platform_init(eeepc);
504 if (err)
505 goto fail_platform;
Yong Wang45f2c692010-04-11 09:27:19 +0800506
507 err = eeepc_wmi_input_init(eeepc);
508 if (err)
Corentin Chary27c136c2010-11-29 08:14:05 +0100509 goto fail_input;
Yong Wang3d7b1652010-04-11 09:27:54 +0800510
Corentin Chary084fca62010-11-29 08:14:06 +0100511 err = eeepc_wmi_led_init(eeepc);
512 if (err)
513 goto fail_leds;
514
Yong Wang3d7b1652010-04-11 09:27:54 +0800515 if (!acpi_video_backlight_support()) {
516 err = eeepc_wmi_backlight_init(eeepc);
517 if (err)
Corentin Chary27c136c2010-11-29 08:14:05 +0100518 goto fail_backlight;
Yong Wang3d7b1652010-04-11 09:27:54 +0800519 } else
520 pr_info("Backlight controlled by ACPI video driver\n");
Yong Wang45f2c692010-04-11 09:27:19 +0800521
522 status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID,
Corentin Chary27c136c2010-11-29 08:14:05 +0100523 eeepc_wmi_notify, eeepc);
Yong Wang45f2c692010-04-11 09:27:19 +0800524 if (ACPI_FAILURE(status)) {
525 pr_err("Unable to register notify handler - %d\n",
526 status);
527 err = -ENODEV;
Corentin Chary27c136c2010-11-29 08:14:05 +0100528 goto fail_wmi_handler;
Yong Wang45f2c692010-04-11 09:27:19 +0800529 }
530
Corentin Chary27c136c2010-11-29 08:14:05 +0100531 return eeepc->platform_device;
Yong Wang45f2c692010-04-11 09:27:19 +0800532
Corentin Chary27c136c2010-11-29 08:14:05 +0100533fail_wmi_handler:
Yong Wang3d7b1652010-04-11 09:27:54 +0800534 eeepc_wmi_backlight_exit(eeepc);
Corentin Chary27c136c2010-11-29 08:14:05 +0100535fail_backlight:
Corentin Chary084fca62010-11-29 08:14:06 +0100536 eeepc_wmi_led_exit(eeepc);
537fail_leds:
Yong Wang45f2c692010-04-11 09:27:19 +0800538 eeepc_wmi_input_exit(eeepc);
Corentin Chary27c136c2010-11-29 08:14:05 +0100539fail_input:
540 eeepc_wmi_platform_exit(eeepc);
541fail_platform:
542 kfree(eeepc);
543 return ERR_PTR(err);
Yong Wang45f2c692010-04-11 09:27:19 +0800544}
545
Corentin Chary27c136c2010-11-29 08:14:05 +0100546static int eeepc_wmi_remove(struct platform_device *device)
Yong Wang45f2c692010-04-11 09:27:19 +0800547{
548 struct eeepc_wmi *eeepc;
549
550 eeepc = platform_get_drvdata(device);
551 wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID);
Yong Wang3d7b1652010-04-11 09:27:54 +0800552 eeepc_wmi_backlight_exit(eeepc);
Yong Wang45f2c692010-04-11 09:27:19 +0800553 eeepc_wmi_input_exit(eeepc);
Corentin Chary084fca62010-11-29 08:14:06 +0100554 eeepc_wmi_led_exit(eeepc);
Corentin Chary27c136c2010-11-29 08:14:05 +0100555 eeepc_wmi_platform_exit(eeepc);
Yong Wang45f2c692010-04-11 09:27:19 +0800556
Corentin Chary27c136c2010-11-29 08:14:05 +0100557 kfree(eeepc);
Yong Wang45f2c692010-04-11 09:27:19 +0800558 return 0;
559}
560
561static struct platform_driver platform_driver = {
562 .driver = {
563 .name = EEEPC_WMI_FILE,
564 .owner = THIS_MODULE,
565 },
Yong Wang45f2c692010-04-11 09:27:19 +0800566};
567
568static int __init eeepc_wmi_init(void)
569{
Yong Wang45f2c692010-04-11 09:27:19 +0800570 int err;
571
Yong Wang3d7b1652010-04-11 09:27:54 +0800572 if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID) ||
573 !wmi_has_guid(EEEPC_WMI_MGMT_GUID)) {
Yong Wang81248882010-04-11 09:26:33 +0800574 pr_warning("No known WMI GUID found\n");
Yong Wangee027e42010-03-21 10:26:34 +0800575 return -ENODEV;
576 }
577
Corentin Chary27c136c2010-11-29 08:14:05 +0100578 platform_device = eeepc_wmi_add();
579 if (IS_ERR(platform_device)) {
580 err = PTR_ERR(platform_device);
581 goto fail_eeepc_wmi;
Yong Wang81248882010-04-11 09:26:33 +0800582 }
Yong Wangee027e42010-03-21 10:26:34 +0800583
Yong Wang45f2c692010-04-11 09:27:19 +0800584 err = platform_driver_register(&platform_driver);
585 if (err) {
586 pr_warning("Unable to register platform driver\n");
Corentin Chary27c136c2010-11-29 08:14:05 +0100587 goto fail_platform_driver;
Yong Wangee027e42010-03-21 10:26:34 +0800588 }
589
590 return 0;
Yong Wang45f2c692010-04-11 09:27:19 +0800591
Corentin Chary27c136c2010-11-29 08:14:05 +0100592fail_platform_driver:
593 eeepc_wmi_remove(platform_device);
594fail_eeepc_wmi:
Yong Wang45f2c692010-04-11 09:27:19 +0800595 return err;
Yong Wangee027e42010-03-21 10:26:34 +0800596}
597
598static void __exit eeepc_wmi_exit(void)
599{
Corentin Chary27c136c2010-11-29 08:14:05 +0100600 eeepc_wmi_remove(platform_device);
Yong Wang45f2c692010-04-11 09:27:19 +0800601 platform_driver_unregister(&platform_driver);
Yong Wangee027e42010-03-21 10:26:34 +0800602}
603
604module_init(eeepc_wmi_init);
605module_exit(eeepc_wmi_exit);