Add an eeepc_wmi context structure to manage all the sub-devices that will be implemented later on. Put input device into it first. Signed-off-by: Yong Wang <yong.y.wang@xxxxxxxxx> --- drivers/platform/x86/eeepc-wmi.c | 65 +++++++++++++++++++++++++++----------- 1 files changed, 46 insertions(+), 19 deletions(-) diff --git a/drivers/platform/x86/eeepc-wmi.c b/drivers/platform/x86/eeepc-wmi.c index 9f88226..f030410 100644 --- a/drivers/platform/x86/eeepc-wmi.c +++ b/drivers/platform/x86/eeepc-wmi.c @@ -58,10 +58,13 @@ static const struct key_entry eeepc_wmi_keymap[] = { { KE_END, 0}, }; -static struct input_dev *eeepc_wmi_input_dev; +struct eeepc_wmi { + struct input_dev *input_dev; +}; static void eeepc_wmi_notify(u32 value, void *context) { + struct eeepc_wmi *eeepc_wmi = (struct eeepc_wmi *)context; struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL }; union acpi_object *obj; acpi_status status; @@ -83,7 +86,7 @@ static void eeepc_wmi_notify(u32 value, void *context) else if (code >= NOTIFY_BRNDOWN_MIN && code <= NOTIFY_BRNDOWN_MAX) code = NOTIFY_BRNDOWN_MIN; - if (!sparse_keymap_report_event(eeepc_wmi_input_dev, + if (!sparse_keymap_report_event(eeepc_wmi->input_dev, code, 1, true)) pr_info("EEEPC WMI: Unknown key %x pressed\n", code); } @@ -91,37 +94,48 @@ static void eeepc_wmi_notify(u32 value, void *context) kfree(obj); } -static int eeepc_wmi_input_setup(void) +static int eeepc_wmi_input_init(struct eeepc_wmi *eeepc_wmi) { int err; - eeepc_wmi_input_dev = input_allocate_device(); - if (!eeepc_wmi_input_dev) + eeepc_wmi->input_dev = input_allocate_device(); + if (!eeepc_wmi->input_dev) return -ENOMEM; - eeepc_wmi_input_dev->name = "Eee PC WMI hotkeys"; - eeepc_wmi_input_dev->phys = "wmi/input0"; - eeepc_wmi_input_dev->id.bustype = BUS_HOST; + eeepc_wmi->input_dev->name = "Eee PC WMI hotkeys"; + eeepc_wmi->input_dev->phys = "wmi/input0"; + eeepc_wmi->input_dev->id.bustype = BUS_HOST; - err = sparse_keymap_setup(eeepc_wmi_input_dev, eeepc_wmi_keymap, NULL); + err = sparse_keymap_setup(eeepc_wmi->input_dev, eeepc_wmi_keymap, NULL); if (err) goto err_free_dev; - err = input_register_device(eeepc_wmi_input_dev); + err = input_register_device(eeepc_wmi->input_dev); if (err) goto err_free_keymap; return 0; err_free_keymap: - sparse_keymap_free(eeepc_wmi_input_dev); + sparse_keymap_free(eeepc_wmi->input_dev); err_free_dev: - input_free_device(eeepc_wmi_input_dev); + input_free_device(eeepc_wmi->input_dev); return err; } +static void eeepc_wmi_input_exit(struct eeepc_wmi *eeepc_wmi) +{ + if (eeepc_wmi->input_dev) { + sparse_keymap_free(eeepc_wmi->input_dev); + input_unregister_device(eeepc_wmi->input_dev); + } + + eeepc_wmi->input_dev = NULL; +} + static int __init eeepc_wmi_init(void) { + static struct eeepc_wmi *eeepc_wmi; int err; acpi_status status; @@ -130,17 +144,27 @@ static int __init eeepc_wmi_init(void) return -ENODEV; } - err = eeepc_wmi_input_setup(); - if (err) + eeepc_wmi = kzalloc(sizeof(struct eeepc_wmi), GFP_KERNEL); + if (!eeepc_wmi) { + pr_warning("EEEPC WMI: Unable to allocate eeepc_wmi device\n"); + return -ENOMEM; + } + + wmi_set_driver_data(EEEPC_WMI_EVENT_GUID, eeepc_wmi); + + err = eeepc_wmi_input_init(eeepc_wmi); + if (err) { + kfree(eeepc_wmi); return err; + } status = wmi_install_notify_handler(EEEPC_WMI_EVENT_GUID, - eeepc_wmi_notify, NULL); + eeepc_wmi_notify, eeepc_wmi); if (ACPI_FAILURE(status)) { - sparse_keymap_free(eeepc_wmi_input_dev); - input_unregister_device(eeepc_wmi_input_dev); pr_err("EEEPC WMI: Unable to register notify handler - %d\n", status); + eeepc_wmi_input_exit(eeepc_wmi); + kfree(eeepc_wmi); return -ENODEV; } @@ -149,9 +173,12 @@ static int __init eeepc_wmi_init(void) static void __exit eeepc_wmi_exit(void) { + static struct eeepc_wmi *eeepc_wmi; + + eeepc_wmi = wmi_get_driver_data(EEEPC_WMI_EVENT_GUID); wmi_remove_notify_handler(EEEPC_WMI_EVENT_GUID); - sparse_keymap_free(eeepc_wmi_input_dev); - input_unregister_device(eeepc_wmi_input_dev); + eeepc_wmi_input_exit(eeepc_wmi); + kfree(eeepc_wmi); } module_init(eeepc_wmi_init); -- 1.5.5.1 -- To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html