Add WMI driver for some Megaware notebook models.
PATCH 1/1 Add WMI driver for some Megaware notebook models.
This driver supports some keys for Megaware notebook models. This particular driver was sponsored by Ulevel <http://ulevel.com>.
---
Perhaps, some function names are a little odd or some of the functions should be open-coded instead. Comments, please?
Note that it depends on both the last fix for WMI and the recent touchpad keys in input.h.
Thanks,
Cascardo.
--- drivers/platform/x86/Kconfig | 8 ++ drivers/platform/x86/Makefile | 1 + drivers/platform/x86/megaware-wmi.c | 226 +++++++++++++++++++++++++++++++++++ 3 files changed, 235 insertions(+), 0 deletions(-) create mode 100644 drivers/platform/x86/megaware-wmi.c
drivers/platform/x86/Kconfig +8 -0
@@ -651,4 +651,12 @@ config XO1_RFKILL Support for enabling/disabling the WLAN interface on the OLPC XO-1 laptop. +config MEGAWARE_WMI + tristate "Megaware WMI input keys" + depends on ACPI_WMI + select INPUT + select INPUT_SPARSEKMAP + ---help--- + This adds support for the keys in some Megaware notebook models. + endif # X86_PLATFORM_DEVICES
drivers/platform/x86/Makefile +1 -0
@@ -34,3 +34,4 @@ obj-$(CONFIG_INTEL_IPS) += intel_ips.o obj-$(CONFIG_GPIO_INTEL_PMIC) += intel_pmic_gpio.o obj-$(CONFIG_XO1_RFKILL) += xo1-rfkill.o obj-$(CONFIG_IBM_RTL) += ibm_rtl.o +obj-$(CONFIG_MEGAWARE_WMI) += megaware-wmi.o
drivers/platform/x86/megaware-wmi.c new file +226 -0
226 lines not on this page · raw message
Signature · 1 line
1.7.2.3
Hi,
Quoted 30 lines · Thadeu Lima de Souza Cascardo
This driver supports some keys for Megaware notebook models. This particular driver was sponsored by Ulevel <http://ulevel.com>.
Signed-off-by Thadeu Lima de Souza Cascardo <[email protected]>---
Perhaps, some function names are a little odd or some of the functions should be open-coded instead. Comments, please?
Note that it depends on both the last fix for WMI and the recent touchpad keys in
input.h.Thanks,
Cascardo.---
drivers/platform/x86/Kconfig | 8 ++drivers/platform/x86/Makefile| 1 +drivers/platform/x86/megaware-wmi.c| 226 +++++++++++++++++++++++++++++++++++3 files changed, 235 insertions(+), 0 deletions(-)create mode 100644
drivers/platform/x86/megaware-wmi.cdrivers/platform/x86/Kconfig +0
-0@@ -651,4 +651,12 @@ config XO1_RFKILLSupport for enabling/disabling the WLAN interface on the OLPC XO-1 laptop.
Quoted 4 lines
+config
MEGAWARE_WMI
+ tristate "Megaware WMI input keys"
+ depends onACPI_WMI
+ select INPUT
depends on INPUT, only use select for small stuff.
Quoted 57 lines
+ select
INPUT_SPARSEKMAP
+ ---help---
+ This adds support for the keys in some Megaware notebook models. +
endif #X86_PLATFORM_DEVICESdrivers/platform/x86/Makefile +0
-0@@ -34,3 +34,4 @@ obj-$(CONFIG_INTEL_IPS) += intel_ips.oobj-$(CONFIG_GPIO_INTEL_PMIC) += intel_pmic_gpio.o obj-$(CONFIG_XO1_RFKILL) += xo1-rfkill.o obj-$(CONFIG_IBM_RTL) += ibm_rtl.o
drivers/platform/x86/Makefile +1
-0+obj-$(CONFIG_MEGAWARE_WMI) += megaware-wmi.odrivers/platform/x86/megaware-wmi.c new file +37
-0@@ -0,0 +1,226 @@ +/* +* Copyright (C) 2010 Thadeu Lima de Souza Cascardo <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/input.h> +#include <linux/input/sparse-keymap.h> +#include <linux/platform_device.h> +#include <linux/acpi.h> + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Thadeu Lima de Souza Cascardo <[email protected]>" ); + +#define MEGAWARE_DRIVER_NAME "megaware" + +#define MEGAWARE_GUID_CODE "39142400-C6A3-40FA-BADB-8A2652834100" +#define MEGAWARE_GUID_EVENT "59142400-C6A3-40FA-BADB-8A2652834100" +#define MEGAWARE_GUID_INIT "79142400-C6A3-40FA-BADB-8A2652834100" + +MODULE_ALIAS ("wmi:" MEGAWARE_GUID_INIT ); +
drivers/platform/x86/megaware-wmi.c line 47
Quoted 10 lines
drivers/platform/x86/megaware-wmi.c new file +10
-0+struct megaware_device { + struct input_dev *idev; +}; + +static acpi_status megaware_call_wq00 (acpi_handle handle, + unsigned long long *ret) +{ + struct acpi_buffer output; + union acpi_object *obj; + acpi_status status;
add an empty line between variable declaration and code ?
I don't know if it's in the coding style, but I find it more readable. Apply this comment to all functions.
Quoted 19 lines
drivers/platform/x86/megaware-wmi.c new file +19
-0+ output.length = ACPI_ALLOCATE_BUFFER; + output.pointer = NULL; + status = wmi_query_block(MEGAWARE_GUID_CODE, 1, &output); + if (status) + return status; + obj = output.pointer; + if (obj && obj->type == ACPI_TYPE_INTEGER) + *ret = obj->integer.value; + else + status = AE_TYPE; + kfree(obj); + return status; +} + +static acpi_status megaware_call_init (struct megaware_device *megaware) +{ + struct acpi_buffer input; + unsigned long long value = 0; + acpi_status status;
drivers/platform/x86/megaware-wmi.c line 76
Quoted 10 lines
drivers/platform/x86/megaware-wmi.c new file +10
-0+ input.length = sizeof(value); + input.pointer = &value; + status = wmi_evaluate_method(MEGAWARE_GUID_INIT, 1, 0, &input, NULL); + return status; +} + +static const struct key_entry megaware_keys[] = { + { KE_KEY, 0x100, { KEY_WLAN } }, + { KE_KEY, 0x101, { KEY_BLUETOOTH } }, + { KE_KEY, 0x102, { KEY_PROG1 } },
Maybe you could add a comment to describe the PROG1 key ?
Quoted 53 lines
drivers/platform/x86/megaware-wmi.c new file +53
-0+ { KE_KEY, 0x107, { KEY_SWITCHVIDEOMODE } }, + { KE_KEY, 0x108, { KEY_TOUCHPAD_TOGGLE } }, + { KE_KEY, 0x109, { KEY_MUTE } }, + { KE_KEY, 0x10A, { KEY_VOLUMEUP } }, + { KE_KEY, 0x10B, { KEY_VOLUMEDOWN } }, + { KE_END, } +}; + +static int megaware_add (struct platform_device *dev) +{ + struct megaware_device *megaware = dev_get_drvdata(&dev->dev); + struct input_dev *inputdev; + int error; + acpi_status status; + + status = megaware_call_init(megaware); + if (!ACPI_SUCCESS(status)) + return -EIO; + + inputdev = input_allocate_device(); + if (!inputdev) + return -ENOMEM; + inputdev->name = MEGAWARE_DRIVER_NAME "_keys"; + inputdev->dev.parent = &dev->dev; + + error = sparse_keymap_setup(inputdev, megaware_keys, NULL); + if (error) + goto err_alloc; + + error = input_register_device(inputdev); + if (error) + goto err_keymap; + megaware->idev = inputdev; + return 0; + +err_keymap: + sparse_keymap_free(inputdev); +err_alloc: + input_free_device(inputdev); + return error; +} + +static int megaware_del (struct platform_device *dev) +{ + struct megaware_device *megaware = dev_get_drvdata(&dev->dev); + struct input_dev *inputdev = megaware->idev; + sparse_keymap_free(inputdev); + input_unregister_device(inputdev); + return 0; +} + +static void megaware_notify (u32 event,void *data) +{
drivers/platform/x86/megaware-wmi.c line 139
Quoted 10 lines
drivers/platform/x86/megaware-wmi.c new file +10
-0+ struct megaware_device *megaware = data; + struct input_dev *inputdev = megaware->idev; + acpi_status status; + unsigned long long value = 0; + if (event != 0x80) + return; + status = megaware_call_wq00(megaware, &value); + if (!ACPI_SUCCESS(status)) + return; + sparse_keymap_report_event(inputdev, value, 1, true);
Add a trace for non-mapped keys ? Will help to support new models.
Quoted 22 lines
drivers/platform/x86/megaware-wmi.c new file +22
-0+} + +static __devinit int megaware_probe (struct platform_device *dev) +{ + struct megaware_device *megaware = dev_get_drvdata(&dev->dev); + int ret; + acpi_status status; + ret = megaware_add(dev); + if (ret) + return ret; + status = wmi_install_notify_handler(MEGAWARE_GUID_EVENT, + megaware_notify, megaware); + if (ACPI_FAILURE(status)) { + megaware_del(dev); + ret = -EIO; + } + return ret; +} + +static __devexit int megaware_remove(struct platform_device *dev) +{ + int ret;
drivers/platform/x86/megaware-wmi.c line 171
Quoted 10 lines
drivers/platform/x86/megaware-wmi.c new file +10
-0+ wmi_remove_notify_handler(MEGAWARE_GUID_EVENT); + ret = megaware_del(dev); + return ret; +} + +static struct platform_driver megaware_driver = { + .driver = { + .owner = THIS_MODULE, + .name = MEGAWARE_DRIVER_NAME, + },
I'd suggest that you don't use .probe / .remove, because if probe fail you won't know about it and the module will still be loaded.
I recently sent a patch for eeepc-wmi (it's in linux-next) to fix the same issue, calling
the megaware_add like function directly in the module init function.
Another way to go is to use platform_driver_probe/platform_create_bundle.
drivers/platform/x86/megaware-wmi.c line 182
Quoted 11 lines
drivers/platform/x86/megaware-wmi.c new file +11
-0+ .probe = megaware_probe, + .remove = __devexit_p(megaware_remove), +}; + +static struct platform_device *megaware_device; + +static __init int megaware_init (void ) +{ + struct megaware_device *megaware; + int ret; + if (!wmi_has_guid(MEGAWARE_GUID_INIT)) {
Maybe you could also check MEGAWARE_GUID_CODE here ?
Or even the three GUID ? (but the event guid should already be checked when installing the notify handler).
drivers/platform/x86/megaware-wmi.c line 183
Quoted 1 line
drivers/platform/x86/megaware-wmi.c new file +1
-0+ printk(KERN_WARNING "Could not find megaware WMI device.\n");
Use pr_* functions instead of printk ? This way it will add a prefix automatically.
Quoted 44 lines
drivers/platform/x86/megaware-wmi.c new file +43
-1+ ret = -ENODEV; + goto out_guid; + } + megaware = kzalloc(sizeof(*megaware), GFP_KERNEL); + if (!megaware) { + ret = -ENOMEM; + goto out_alloc; + } + megaware_device = platform_device_alloc(MEGAWARE_DRIVER_NAME, 0); + if (!megaware_device) { + ret = -ENOMEM; + goto out_devalloc; + } + ret = platform_device_add(megaware_device); + if (ret) + goto out_devadd; + dev_set_drvdata(&megaware_device->dev, megaware); + ret = platform_driver_register(&megaware_driver); + if (ret) + goto out_driver; + return 0; +out_driver: + platform_device_del(megaware_device); +out_devadd: + platform_device_put(megaware_device); +out_devalloc: + kfree(megaware); +out_alloc: +out_guid: + return ret; +} + +static __exit void megaware_exit(void) +{ + struct megaware_device *megaware; + platform_driver_unregister(&megaware_driver); + megaware = dev_get_drvdata(&megaware_device->dev); + platform_device_unregister(megaware_device); + kfree(megaware); +} + +module_init (megaware_init); +module_exit (megaware_exit); --
Quoted 1 line
1.7.2.3
Otherwise, this looks like a clean wmi driver :)
Thanks.
Signature · 2 lines
Corentin Chary http://xf.iksaif.net
Quoted 104 lines · Corentin Chary
Hi,
Quoted 30 lines · Thadeu Lima de Souza Cascardo
This driver supports some keys for Megaware notebook models. This particular driver was sponsored by Ulevel <http://ulevel.com>.
Signed-off-by Thadeu Lima de Souza Cascardo <[email protected]>---
Perhaps, some function names are a little odd or some of the functions should be open-coded instead. Comments, please?
Note that it depends on both the last fix for WMI and the recent touchpad keys in
input.h.Thanks,
Cascardo.---
drivers/platform/x86/Kconfig | 8 ++drivers/platform/x86/Makefile| 1 +drivers/platform/x86/megaware-wmi.c| 226 +++++++++++++++++++++++++++++++++++3 files changed, 235 insertions(+), 0 deletions(-)create mode 100644
drivers/platform/x86/megaware-wmi.cdrivers/platform/x86/Kconfig +0
-0@@ -651,4 +651,12 @@ config XO1_RFKILLSupport for enabling/disabling the WLAN interface on the OLPC XO-1 laptop.
Quoted 4 lines
+config
MEGAWARE_WMI
+ tristate "Megaware WMI input keys"
+ depends onACPI_WMI
+ select INPUTdepends on INPUT, only use select for small stuff.
Quoted 63 lines
+ select
INPUT_SPARSEKMAP
+ ---help---
+ This adds support for the keys in some Megaware notebook models. +
endif #X86_PLATFORM_DEVICESdrivers/platform/x86/Makefile +0
-0@@ -34,3 +34,4 @@ obj-$(CONFIG_INTEL_IPS) += intel_ips.oobj-$(CONFIG_GPIO_INTEL_PMIC) += intel_pmic_gpio.o obj-$(CONFIG_XO1_RFKILL) += xo1-rfkill.o obj-$(CONFIG_IBM_RTL) += ibm_rtl.o
drivers/platform/x86/Makefile +1
-0+obj-$(CONFIG_MEGAWARE_WMI) += megaware-wmi.odrivers/platform/x86/megaware-wmi.c new file +43
-0@@ -0,0 +1,226 @@ +/* +* Copyright (C) 2010 Thadeu Lima de Souza Cascardo <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/input.h> +#include <linux/input/sparse-keymap.h> +#include <linux/platform_device.h> +#include <linux/acpi.h> + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Thadeu Lima de Souza Cascardo <[email protected]>" ); + +#define MEGAWARE_DRIVER_NAME "megaware" + +#define MEGAWARE_GUID_CODE "39142400-C6A3-40FA-BADB-8A2652834100" +#define MEGAWARE_GUID_EVENT "59142400-C6A3-40FA-BADB-8A2652834100" +#define MEGAWARE_GUID_INIT "79142400-C6A3-40FA-BADB-8A2652834100" + +MODULE_ALIAS ("wmi:" MEGAWARE_GUID_INIT ); + +struct megaware_device { + struct input_dev *idev; +}; + +static acpi_status megaware_call_wq00 (acpi_handle handle, + unsigned long long *ret)
Quoted 8 lines
drivers/platform/x86/megaware-wmi.c line 47
Quoted 4 lines
drivers/platform/x86/megaware-wmi.c new file +4
-0+{ + struct acpi_buffer output; + union acpi_object *obj; + acpi_status status;add an empty line between variable declaration and code ?
I don't know if it's in the coding style, but I find it more readable. Apply this comment to all functions.
Yes, separating declarations and code is preferred style. In general, judicious use of empty lines to group related statements is very welcome.
Quoted 16 lines
Quoted 16 lines
drivers/platform/x86/megaware-wmi.c new file +15
-0+ output.length = ACPI_ALLOCATE_BUFFER; + output.pointer = NULL; + status = wmi_query_block(MEGAWARE_GUID_CODE, 1, &output); + if (status) + return status; + obj = output.pointer; + if (obj && obj->type == ACPI_TYPE_INTEGER) + *ret = obj->integer.value; + else + status = AE_TYPE; + kfree(obj); + return status; +} + +static acpi_status megaware_call_init (struct megaware_device *megaware)
Quoted 8 lines
drivers/platform/x86/megaware-wmi.c line 70
Quoted 8 lines
drivers/platform/x86/megaware-wmi.c new file +8
-0+{ + struct acpi_buffer input; + unsigned long long value = 0; + acpi_status status; + input.length = sizeof(value); + input.pointer = &value; + status = wmi_evaluate_method(MEGAWARE_GUID_INIT, 1, 0, &input, NULL); + return status;
Could probably be written as:
unsigned long long value = 0;
struct acpi_buffer input = {
.length = sizeof(value),
.pointer = &value,
};
return wmi_evaluate_method(MEGAWARE_GUID_INIT, 1, 0, &input, NULL);Quoted 9 lines
drivers/platform/x86/megaware-wmi.c line 76
Quoted 6 lines
drivers/platform/x86/megaware-wmi.c new file +6
-0+} + +static const struct key_entry megaware_keys[] = { + { KE_KEY, 0x100, { KEY_WLAN } }, + { KE_KEY, 0x101, { KEY_BLUETOOTH } }, + { KE_KEY, 0x102, { KEY_PROG1 } },Maybe you could add a comment to describe the PROG1 key ?
Quoted 9 lines
drivers/platform/x86/megaware-wmi.c line 85
Quoted 9 lines
drivers/platform/x86/megaware-wmi.c new file +9
-0+ { KE_KEY, 0x107, { KEY_SWITCHVIDEOMODE } }, + { KE_KEY, 0x108, { KEY_TOUCHPAD_TOGGLE } }, + { KE_KEY, 0x109, { KEY_MUTE } }, + { KE_KEY, 0x10A, { KEY_VOLUMEUP } }, + { KE_KEY, 0x10B, { KEY_VOLUMEDOWN } }, + { KE_END, } +}; + +static int megaware_add (struct platform_device *dev)
Can also be __devinit. And why don't you use struct megaware_device * as the argument instead of platform device? And call it megaware_input_init()?
Quoted 27 lines
Quoted 27 lines
drivers/platform/x86/megaware-wmi.c new file +27
-0+{ + struct megaware_device *megaware = dev_get_drvdata(&dev->dev); + struct input_dev *inputdev; + int error; + acpi_status status; + + status = megaware_call_init(megaware); + if (!ACPI_SUCCESS(status)) + return -EIO; + + inputdev = input_allocate_device(); + if (!inputdev) + return -ENOMEM; + inputdev->name = MEGAWARE_DRIVER_NAME "_keys"; + inputdev->dev.parent = &dev->dev; + + error = sparse_keymap_setup(inputdev, megaware_keys, NULL); + if (error) + goto err_alloc; + + error = input_register_device(inputdev); + if (error) + goto err_keymap; + megaware->idev = inputdev; + return 0; + +err_keymap:
Quoted 8 lines
drivers/platform/x86/megaware-wmi.c line 120
Quoted 8 lines
drivers/platform/x86/megaware-wmi.c new file +8
-0+ sparse_keymap_free(inputdev); +err_alloc: + input_free_device(inputdev); + return error; +} + +static int megaware_del (struct platform_device *dev) +{
Same here, struct megaware_device * as an argument would make more sense.
Quoted 49 lines
Quoted 9 lines
drivers/platform/x86/megaware-wmi.c new file +9
-0+ struct megaware_device *megaware = dev_get_drvdata(&dev->dev); + struct input_dev *inputdev = megaware->idev; + sparse_keymap_free(inputdev); + input_unregister_device(inputdev); + return 0; +} + +static void megaware_notify (u32 event,void *data) +{drivers/platform/x86/megaware-wmi.c line 139
Quoted 10 lines
drivers/platform/x86/megaware-wmi.c new file +10
-0+ struct megaware_device *megaware = data; + struct input_dev *inputdev = megaware->idev; + acpi_status status; + unsigned long long value = 0; + if (event != 0x80) + return; + status = megaware_call_wq00(megaware, &value); + if (!ACPI_SUCCESS(status)) + return; + sparse_keymap_report_event(inputdev, value, 1, true);Add a trace for non-mapped keys ? Will help to support new models.
Quoted 27 lines
drivers/platform/x86/megaware-wmi.c new file +27
-0+} + +static __devinit int megaware_probe (struct platform_device *dev) +{ + struct megaware_device *megaware = dev_get_drvdata(&dev->dev); + int ret; + acpi_status status; + ret = megaware_add(dev); + if (ret) + return ret; + status = wmi_install_notify_handler(MEGAWARE_GUID_EVENT, + megaware_notify, megaware); + if (ACPI_FAILURE(status)) { + megaware_del(dev); + ret = -EIO; + } + return ret; +} + +static __devexit int megaware_remove(struct platform_device *dev) +{ + int ret; + wmi_remove_notify_handler(MEGAWARE_GUID_EVENT); + ret = megaware_del(dev); + return ret; +} +
Quoted 8 lines
drivers/platform/x86/megaware-wmi.c line 171
Quoted 5 lines
drivers/platform/x86/megaware-wmi.c new file +5
-0+static struct platform_driver megaware_driver = { + .driver = { + .owner = THIS_MODULE, + .name = MEGAWARE_DRIVER_NAME, + },I'd suggest that you don't use .probe / .remove, because if probe fail you won't know about it and the module will still be loaded.
.remove is still needed but I guess Corentin refers to using platform_driver_probe() instead of platform_driver_register() so the megaware_probe can be marked __init and discarded after driver initialization has been completed.
Quoted 23 lines
I recently sent a patch for eeepc-wmi (it's in linux-next) to fix the same issue, calling
themegaware_addlike function directly in the module init function.Another way to go is to use platform_driver_probe/platform_create_bundle.
drivers/platform/x86/megaware-wmi.c line 182
Quoted 11 lines
drivers/platform/x86/megaware-wmi.c new file +11
-0+ .probe = megaware_probe, + .remove = __devexit_p(megaware_remove), +}; + +static struct platform_device *megaware_device; + +static __init int megaware_init (void ) +{ + struct megaware_device *megaware; + int ret; + if (!wmi_has_guid(MEGAWARE_GUID_INIT)) {Maybe you could also check
MEGAWARE_GUID_CODEhere ?
Or even the three GUID ? (but the event guid should already be checked when installing the notify handler).
Quoted 13 lines
drivers/platform/x86/megaware-wmi.c line 183
Quoted 1 line
drivers/platform/x86/megaware-wmi.c new file +1
-0+ printk(KERN_WARNING "Could not find megaware WMI device.\n");Use pr_* functions instead of printk ? This way it will add a prefix automatically.
Quoted 8 lines
drivers/platform/x86/megaware-wmi.c new file +8
-0+ ret = -ENODEV; + goto out_guid; + } + megaware = kzalloc(sizeof(*megaware), GFP_KERNEL); + if (!megaware) { + ret = -ENOMEM; + goto out_alloc; + }
I do not really see the point in dynamically allocating megaware structure since there can only be one instance of it.
Quoted 50 lines
Quoted 36 lines
drivers/platform/x86/megaware-wmi.c new file +35
-1+ megaware_device = platform_device_alloc(MEGAWARE_DRIVER_NAME, 0); + if (!megaware_device) { + ret = -ENOMEM; + goto out_devalloc; + } + ret = platform_device_add(megaware_device); + if (ret) + goto out_devadd; + dev_set_drvdata(&megaware_device->dev, megaware); + ret = platform_driver_register(&megaware_driver); + if (ret) + goto out_driver; + return 0; +out_driver: + platform_device_del(megaware_device); +out_devadd: + platform_device_put(megaware_device); +out_devalloc: + kfree(megaware); +out_alloc: +out_guid: + return ret; +} + +static __exit void megaware_exit(void) +{ + struct megaware_device *megaware; + platform_driver_unregister(&megaware_driver); + megaware = dev_get_drvdata(&megaware_device->dev); + platform_device_unregister(megaware_device); + kfree(megaware); +} + +module_init (megaware_init); +module_exit (megaware_exit); --Quoted 1 line
1.7.2.3
Otherwise, this looks like a clean wmi driver :)
Thanks.
Signature · 6 lines
Corentin Chary http://xf.iksaif.net -- To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 1 line
Dmitry
Quoted 274 lines · Dmitry Torokhov
Quoted 104 lines · Corentin Chary
Hi,
Quoted 30 lines · Thadeu Lima de Souza Cascardo
This driver supports some keys for Megaware notebook models. This particular driver was sponsored by Ulevel <http://ulevel.com>.
Signed-off-by Thadeu Lima de Souza Cascardo <[email protected]>---
Perhaps, some function names are a little odd or some of the functions should be open-coded instead. Comments, please?
Note that it depends on both the last fix for WMI and the recent touchpad keys in
input.h.Thanks,
Cascardo.---
drivers/platform/x86/Kconfig | 8 ++drivers/platform/x86/Makefile| 1 +drivers/platform/x86/megaware-wmi.c| 226 +++++++++++++++++++++++++++++++++++3 files changed, 235 insertions(+), 0 deletions(-)create mode 100644
drivers/platform/x86/megaware-wmi.cdrivers/platform/x86/Kconfig +0
-0@@ -651,4 +651,12 @@ config XO1_RFKILLSupport for enabling/disabling the WLAN interface on the OLPC XO-1 laptop.
Quoted 4 lines
+config
MEGAWARE_WMI
+ tristate "Megaware WMI input keys"
+ depends onACPI_WMI
+ select INPUTdepends on INPUT, only use select for small stuff.
Quoted 63 lines
+ select
INPUT_SPARSEKMAP
+ ---help---
+ This adds support for the keys in some Megaware notebook models. +
endif #X86_PLATFORM_DEVICESdrivers/platform/x86/Makefile +0
-0@@ -34,3 +34,4 @@ obj-$(CONFIG_INTEL_IPS) += intel_ips.oobj-$(CONFIG_GPIO_INTEL_PMIC) += intel_pmic_gpio.o obj-$(CONFIG_XO1_RFKILL) += xo1-rfkill.o obj-$(CONFIG_IBM_RTL) += ibm_rtl.o
drivers/platform/x86/Makefile +1
-0+obj-$(CONFIG_MEGAWARE_WMI) += megaware-wmi.odrivers/platform/x86/megaware-wmi.c new file +43
-0@@ -0,0 +1,226 @@ +/* +* Copyright (C) 2010 Thadeu Lima de Souza Cascardo <[email protected]> +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License as published by +* the Free Software Foundation; either version 2 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/slab.h> +#include <linux/input.h> +#include <linux/input/sparse-keymap.h> +#include <linux/platform_device.h> +#include <linux/acpi.h> + +MODULE_LICENSE ("GPL" ); +MODULE_AUTHOR ("Thadeu Lima de Souza Cascardo <[email protected]>" ); + +#define MEGAWARE_DRIVER_NAME "megaware" + +#define MEGAWARE_GUID_CODE "39142400-C6A3-40FA-BADB-8A2652834100" +#define MEGAWARE_GUID_EVENT "59142400-C6A3-40FA-BADB-8A2652834100" +#define MEGAWARE_GUID_INIT "79142400-C6A3-40FA-BADB-8A2652834100" + +MODULE_ALIAS ("wmi:" MEGAWARE_GUID_INIT ); + +struct megaware_device { + struct input_dev *idev; +}; + +static acpi_status megaware_call_wq00 (acpi_handle handle, + unsigned long long *ret)Quoted 8 lines
drivers/platform/x86/megaware-wmi.c line 47
Quoted 4 lines
drivers/platform/x86/megaware-wmi.c new file +4
-0+{ + struct acpi_buffer output; + union acpi_object *obj; + acpi_status status;add an empty line between variable declaration and code ?
I don't know if it's in the coding style, but I find it more readable. Apply this comment to all functions.Yes, separating declarations and code is preferred style. In general, judicious use of empty lines to group related statements is very welcome.
Quoted 16 lines
Quoted 16 lines
drivers/platform/x86/megaware-wmi.c new file +15
-0+ output.length = ACPI_ALLOCATE_BUFFER; + output.pointer = NULL; + status = wmi_query_block(MEGAWARE_GUID_CODE, 1, &output); + if (status) + return status; + obj = output.pointer; + if (obj && obj->type == ACPI_TYPE_INTEGER) + *ret = obj->integer.value; + else + status = AE_TYPE; + kfree(obj); + return status; +} + +static acpi_status megaware_call_init (struct megaware_device *megaware)Quoted 8 lines
drivers/platform/x86/megaware-wmi.c line 70
Quoted 8 lines
drivers/platform/x86/megaware-wmi.c new file +8
-0+{ + struct acpi_buffer input; + unsigned long long value = 0; + acpi_status status; + input.length = sizeof(value); + input.pointer = &value; + status = wmi_evaluate_method(MEGAWARE_GUID_INIT, 1, 0, &input, NULL); + return status;Could probably be written as:
unsigned long long value = 0;
structacpi_bufferinput = {
.length = sizeof(value),
.pointer = &value,
};return
wmi_evaluate_method(MEGAWARE_GUID_INIT, 1, 0, &input, NULL);Quoted 9 lines
drivers/platform/x86/megaware-wmi.c line 76
Quoted 6 lines
drivers/platform/x86/megaware-wmi.c new file +6
-0+} + +static const struct key_entry megaware_keys[] = { + { KE_KEY, 0x100, { KEY_WLAN } }, + { KE_KEY, 0x101, { KEY_BLUETOOTH } }, + { KE_KEY, 0x102, { KEY_PROG1 } },Maybe you could add a comment to describe the PROG1 key ?
Quoted 9 lines
drivers/platform/x86/megaware-wmi.c line 85
Quoted 9 lines
drivers/platform/x86/megaware-wmi.c new file +9
-0+ { KE_KEY, 0x107, { KEY_SWITCHVIDEOMODE } }, + { KE_KEY, 0x108, { KEY_TOUCHPAD_TOGGLE } }, + { KE_KEY, 0x109, { KEY_MUTE } }, + { KE_KEY, 0x10A, { KEY_VOLUMEUP } }, + { KE_KEY, 0x10B, { KEY_VOLUMEDOWN } }, + { KE_END, } +}; + +static int megaware_add (struct platform_device *dev)Can also be
__devinit. And why don't you use structmegaware_device* as the argument instead of platform device? And call itmegaware_input_init()?Quoted 27 lines
Quoted 27 lines
drivers/platform/x86/megaware-wmi.c new file +27
-0+{ + struct megaware_device *megaware = dev_get_drvdata(&dev->dev); + struct input_dev *inputdev; + int error; + acpi_status status; + + status = megaware_call_init(megaware); + if (!ACPI_SUCCESS(status)) + return -EIO; + + inputdev = input_allocate_device(); + if (!inputdev) + return -ENOMEM; + inputdev->name = MEGAWARE_DRIVER_NAME "_keys"; + inputdev->dev.parent = &dev->dev; + + error = sparse_keymap_setup(inputdev, megaware_keys, NULL); + if (error) + goto err_alloc; + + error = input_register_device(inputdev); + if (error) + goto err_keymap; + megaware->idev = inputdev; + return 0; + +err_keymap:Quoted 8 lines
drivers/platform/x86/megaware-wmi.c line 120
Quoted 8 lines
drivers/platform/x86/megaware-wmi.c new file +8
-0+ sparse_keymap_free(inputdev); +err_alloc: + input_free_device(inputdev); + return error; +} + +static int megaware_del (struct platform_device *dev) +{Same here, struct
megaware_device* as an argument would make more sense.Quoted 49 lines
Quoted 9 lines
drivers/platform/x86/megaware-wmi.c new file +9
-0+ struct megaware_device *megaware = dev_get_drvdata(&dev->dev); + struct input_dev *inputdev = megaware->idev; + sparse_keymap_free(inputdev); + input_unregister_device(inputdev); + return 0; +} + +static void megaware_notify (u32 event,void *data) +{drivers/platform/x86/megaware-wmi.c line 139
Quoted 10 lines
drivers/platform/x86/megaware-wmi.c new file +10
-0+ struct megaware_device *megaware = data; + struct input_dev *inputdev = megaware->idev; + acpi_status status; + unsigned long long value = 0; + if (event != 0x80) + return; + status = megaware_call_wq00(megaware, &value); + if (!ACPI_SUCCESS(status)) + return; + sparse_keymap_report_event(inputdev, value, 1, true);Add a trace for non-mapped keys ? Will help to support new models.
Quoted 27 lines
drivers/platform/x86/megaware-wmi.c new file +27
-0+} + +static __devinit int megaware_probe (struct platform_device *dev) +{ + struct megaware_device *megaware = dev_get_drvdata(&dev->dev); + int ret; + acpi_status status; + ret = megaware_add(dev); + if (ret) + return ret; + status = wmi_install_notify_handler(MEGAWARE_GUID_EVENT, + megaware_notify, megaware); + if (ACPI_FAILURE(status)) { + megaware_del(dev); + ret = -EIO; + } + return ret; +} + +static __devexit int megaware_remove(struct platform_device *dev) +{ + int ret; + wmi_remove_notify_handler(MEGAWARE_GUID_EVENT); + ret = megaware_del(dev); + return ret; +} +Quoted 8 lines
drivers/platform/x86/megaware-wmi.c line 171
Quoted 5 lines
drivers/platform/x86/megaware-wmi.c new file +5
-0+static struct platform_driver megaware_driver = { + .driver = { + .owner = THIS_MODULE, + .name = MEGAWARE_DRIVER_NAME, + },I'd suggest that you don't use .probe / .remove, because if probe fail you won't know about it and the module will still be loaded.
Quoted 4 lines
.remove is still needed but I guess Corentin refers to using
platform_driver_probe()instead ofplatform_driver_register()so themegaware_probecan be marked__initand discarded after driver initialization has been completed.
Also, register won't return any error code if the probe function failed, and the driver will be left in a strange state.
Calling directly platform_driver_probe() will return an error code.
But since it's a singleton device, and since the real "probe" code is already in the module_init function (wmi_has_guid()) call, using the probe callback to initialize data structures doesn't seems to make sense.
Quoted 94 lines
Quoted 23 lines
I recently sent a patch for eeepc-wmi (it's in linux-next) to fix the same issue, calling
themegaware_addlike function directly in the module init function.Another way to go is to use platform_driver_probe/platform_create_bundle.
drivers/platform/x86/megaware-wmi.c line 182
Quoted 11 lines
drivers/platform/x86/megaware-wmi.c new file +11
-0+ .probe = megaware_probe, + .remove = __devexit_p(megaware_remove), +}; + +static struct platform_device *megaware_device; + +static __init int megaware_init (void ) +{ + struct megaware_device *megaware; + int ret; + if (!wmi_has_guid(MEGAWARE_GUID_INIT)) {Maybe you could also check
MEGAWARE_GUID_CODEhere ?
Or even the three GUID ? (but the event guid should already be checked when installing the notify handler).Quoted 13 lines
drivers/platform/x86/megaware-wmi.c line 183
Quoted 1 line
drivers/platform/x86/megaware-wmi.c new file +1
-0+ printk(KERN_WARNING "Could not find megaware WMI device.\n");Use pr_* functions instead of printk ? This way it will add a prefix automatically.
Quoted 8 lines
drivers/platform/x86/megaware-wmi.c new file +8
-0+ ret = -ENODEV; + goto out_guid; + } + megaware = kzalloc(sizeof(*megaware), GFP_KERNEL); + if (!megaware) { + ret = -ENOMEM; + goto out_alloc; + }I do not really see the point in dynamically allocating megaware structure since there can only be one instance of it.
Quoted 43 lines
Quoted 36 lines
drivers/platform/x86/megaware-wmi.c new file +35
-1+ megaware_device = platform_device_alloc(MEGAWARE_DRIVER_NAME, 0); + if (!megaware_device) { + ret = -ENOMEM; + goto out_devalloc; + } + ret = platform_device_add(megaware_device); + if (ret) + goto out_devadd; + dev_set_drvdata(&megaware_device->dev, megaware); + ret = platform_driver_register(&megaware_driver); + if (ret) + goto out_driver; + return 0; +out_driver: + platform_device_del(megaware_device); +out_devadd: + platform_device_put(megaware_device); +out_devalloc: + kfree(megaware); +out_alloc: +out_guid: + return ret; +} + +static __exit void megaware_exit(void) +{ + struct megaware_device *megaware; + platform_driver_unregister(&megaware_driver); + megaware = dev_get_drvdata(&megaware_device->dev); + platform_device_unregister(megaware_device); + kfree(megaware); +} + +module_init (megaware_init); +module_exit (megaware_exit); --Quoted 1 line
1.7.2.3
Otherwise, this looks like a clean wmi driver :)
Thanks.
Quoted 7 lines
--
Corentin Chary
http://xf.iksaif.net
--
To unsubscribe from this list: send the line "unsubscribe platform-driver-x86" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html--
Dmitry
Signature · 2 lines
Corentin Chary http://xf.iksaif.net
Quoted 11 lines · Corentin Chary
Quoted 5 lines · Dmitry Torokhov
.remove is still needed but I guess Corentin refers to using
platform_driver_probe()instead ofplatform_driver_register()so themegaware_probecan be marked__initand discarded after driver initialization has been completed.Also, register won't return any error code if the probe function failed, and the driver will be left in a strange state.
Quoted 7 lines
Calling directly
platform_driver_probe()will return an error code.But since it's a singleton device, and since the real "probe" code is already in the
module_initfunction (wmi_has_guid()) call, using the probe callback to initialize data structures doesn't seems to make sense.
What's the other option (provided that we want to keep platform device)? Manual binding device and driver? I think platform_driver_probe() is better tested and is safer, emits all necessary uevents. etc, etc.
I'd suggest platform_create_bundle() except I am not quite happy with the API at the moment (needs to also accept drvdata I think).
Signature · 1 line
Dmitry
Quoted 20 lines · Dmitry Torokhov
Quoted 11 lines · Corentin Chary
Quoted 5 lines · Dmitry Torokhov
.remove is still needed but I guess Corentin refers to using
platform_driver_probe()instead ofplatform_driver_register()so themegaware_probecan be marked__initand discarded after driver initialization has been completed.Also, register won't return any error code if the probe function failed, and the driver will be left in a strange state.
Quoted 7 lines
Calling directly
platform_driver_probe()will return an error code.But since it's a singleton device, and since the real "probe" code is already in the
module_initfunction (wmi_has_guid()) call, using the probe callback to initialize data structures doesn't seems to make sense.
Quoted 7 lines
What's the other option (provided that we want to keep platform device)? Manual binding device and driver? I think
platform_driver_probe()is better tested and is safer, emits all necessary uevents. etc, etc.I'd suggest
platform_create_bundle()except I am not quite happy with the API at the moment (needs to also accept drvdata I think).
Well, I'd suggest something like
http://git.kernel.org/?p=linux/kernel/git/mjg59/platform-drivers-x86.git;a=blob;f=drivers/platform/x86/eeepc-wmi.c;hb=linux-next#l887
It's like platform_create_bundle, but by hand, because I didn't like the API too.
Please note that I'd gladly accept any comment/patch on eeepc-wmi if you think it's not ok :).
Maybe the wmi_has_guid() calls should be in the probe callback, and we should all call platform_driver_probe() ?
Signature · 2 lines
Corentin Chary http://xf.iksaif.net
Quoted 30 lines · Corentin Chary
Quoted 20 lines · Dmitry Torokhov
Quoted 11 lines · Corentin Chary
Quoted 5 lines · Dmitry Torokhov
.remove is still needed but I guess Corentin refers to using
platform_driver_probe()instead ofplatform_driver_register()so themegaware_probecan be marked__initand discarded after driver initialization has been completed.Also, register won't return any error code if the probe function failed, and the driver will be left in a strange state.
Quoted 7 lines
Calling directly
platform_driver_probe()will return an error code.But since it's a singleton device, and since the real "probe" code is already in the
module_initfunction (wmi_has_guid()) call, using the probe callback to initialize data structures doesn't seems to make sense.Quoted 7 lines
What's the other option (provided that we want to keep platform device)? Manual binding device and driver? I think
platform_driver_probe()is better tested and is safer, emits all necessary uevents. etc, etc.I'd suggest
platform_create_bundle()except I am not quite happy with the API at the moment (needs to also accept drvdata I think).
Quoted 8 lines
Well, I'd suggest something like
http://git.kernel.org/?p=linux/kernel/git/mjg59/platform-drivers-x86.git;a=blob;f=drivers/platform/x86/eeepc-wmi.c;hb=linux-next#l887It's like
platform_create_bundle, but by hand, because I didn't like the API too.Please note that I'd gladly accept any comment/patch on eeepc-wmi if you think it's not ok :).
Well, I see one, more theoretical than practical issue here. Your platform driver does not suppress bind/unbind via sysfs and when I unbind a driver from a device I'd really expect children disappear. But your implementation of eeepc-wmi it does not work this way.
Quoted 4 lines
Maybe the
wmi_has_guid()calls should be in the probe callback, and we should all callplatform_driver_probe()?
Yes, I think this would work.
Signature · 1 line
Dmitry