From 70b22e19b0010161132c94feebf72163c0a434c5 Mon Sep 17 00:00:00 2001 From: Yong Wang Date: Sun, 11 Apr 2010 09:27:19 +0800 Subject: [PATCH] --- yaml --- r: 190207 b: refs/heads/master c: 45f2c6937ed6066c9a177c4d37f6bd76daa607c0 h: refs/heads/master i: 190205: 2ff8be41dd727f91be5915285c215cddd0c1132a 190203: 1d929dbdaa163b873500709541a798fbf08f22df 190199: 0b26d09319b3cccb41dfb3102dd4e72fd8f4b919 190191: a18ae87e48c36cf21abb282542b67496b3d9c1be 190175: 646b84bad5727ad855d36bf2e037fbc701d1e2c6 190143: e655522d12102002b3eb277c6e7f0455febbd636 190079: 4414ed33445be7a501d2308950f32f796a755792 189951: 771820fe15355080f29cbb2c53b62d0cf85b0c09 v: v3 --- [refs] | 2 +- trunk/drivers/platform/x86/eeepc-wmi.c | 102 +++++++++++++++++++++---- 2 files changed, 87 insertions(+), 17 deletions(-) diff --git a/[refs] b/[refs] index 0a51d70b5936..6b353c01e11e 100644 --- a/[refs] +++ b/[refs] @@ -1,2 +1,2 @@ --- -refs/heads/master: 8124888940be5d9d73a6e04970d73eaec7c582b7 +refs/heads/master: 45f2c6937ed6066c9a177c4d37f6bd76daa607c0 diff --git a/trunk/drivers/platform/x86/eeepc-wmi.c b/trunk/drivers/platform/x86/eeepc-wmi.c index daed4a476b39..0c9596c97a0f 100644 --- a/trunk/drivers/platform/x86/eeepc-wmi.c +++ b/trunk/drivers/platform/x86/eeepc-wmi.c @@ -32,9 +32,12 @@ #include #include #include +#include #include #include +#define EEEPC_WMI_FILE "eeepc-wmi" + MODULE_AUTHOR("Yong Wang "); MODULE_DESCRIPTION("Eee PC WMI Hotkey Driver"); MODULE_LICENSE("GPL"); @@ -64,7 +67,7 @@ struct eeepc_wmi { struct input_dev *inputdev; }; -static struct eeepc_wmi *eeepc; +static struct platform_device *platform_device; static void eeepc_wmi_notify(u32 value, void *context) { @@ -107,8 +110,9 @@ static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc) return -ENOMEM; eeepc->inputdev->name = "Eee PC WMI hotkeys"; - eeepc->inputdev->phys = "wmi/input0"; + eeepc->inputdev->phys = EEEPC_WMI_FILE "/input0"; eeepc->inputdev->id.bustype = BUS_HOST; + eeepc->inputdev->dev.parent = &platform_device->dev; err = sparse_keymap_setup(eeepc->inputdev, eeepc_wmi_keymap, NULL); if (err) @@ -137,11 +141,60 @@ static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc) eeepc->inputdev = NULL; } -static int __init eeepc_wmi_init(void) +static int __devinit eeepc_wmi_platform_probe(struct platform_device *device) { + struct eeepc_wmi *eeepc; int err; acpi_status status; + eeepc = platform_get_drvdata(device); + + err = eeepc_wmi_input_init(eeepc); + if (err) + return err; + + status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID, + eeepc_wmi_notify, eeepc); + if (ACPI_FAILURE(status)) { + pr_err("Unable to register notify handler - %d\n", + status); + err = -ENODEV; + goto error_wmi; + } + + return 0; + +error_wmi: + eeepc_wmi_input_exit(eeepc); + + return err; +} + +static int __devexit eeepc_wmi_platform_remove(struct platform_device *device) +{ + struct eeepc_wmi *eeepc; + + eeepc = platform_get_drvdata(device); + wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); + eeepc_wmi_input_exit(eeepc); + + return 0; +} + +static struct platform_driver platform_driver = { + .driver = { + .name = EEEPC_WMI_FILE, + .owner = THIS_MODULE, + }, + .probe = eeepc_wmi_platform_probe, + .remove = __devexit_p(eeepc_wmi_platform_remove), +}; + +static int __init eeepc_wmi_init(void) +{ + struct eeepc_wmi *eeepc; + int err; + if (!wmi_has_guid(EEEPC_WMI_EVENT_GUID)) { pr_warning("No known WMI GUID found\n"); return -ENODEV; @@ -151,29 +204,46 @@ static int __init eeepc_wmi_init(void) if (!eeepc) return -ENOMEM; - err = eeepc_wmi_input_init(eeepc); + platform_device = platform_device_alloc(EEEPC_WMI_FILE, -1); + if (!platform_device) { + pr_warning("Unable to allocate platform device\n"); + err = -ENOMEM; + goto fail_platform; + } + + err = platform_device_add(platform_device); if (err) { - kfree(eeepc); - return err; + pr_warning("Unable to add platform device\n"); + goto put_dev; } - status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID, - eeepc_wmi_notify, eeepc); - if (ACPI_FAILURE(status)) { - pr_err("Unable to register notify handler - %d\n", - status); - eeepc_wmi_input_exit(eeepc); - kfree(eeepc); - return -ENODEV; + platform_set_drvdata(platform_device, eeepc); + + err = platform_driver_register(&platform_driver); + if (err) { + pr_warning("Unable to register platform driver\n"); + goto del_dev; } return 0; + +del_dev: + platform_device_del(platform_device); +put_dev: + platform_device_put(platform_device); +fail_platform: + kfree(eeepc); + + return err; } static void __exit eeepc_wmi_exit(void) { - wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); - eeepc_wmi_input_exit(eeepc); + struct eeepc_wmi *eeepc; + + eeepc = platform_get_drvdata(platform_device); + platform_driver_unregister(&platform_driver); + platform_device_unregister(platform_device); kfree(eeepc); }