Re: [PATCH 3/3] ideapad: add hotkey support

From: Corentin Chary
Date: Thu Nov 18 2010 - 02:36:05 EST


On Wed, Nov 17, 2010 at 10:29 PM, Dmitry Torokhov
<dmitry.torokhov@xxxxxxxxx> wrote:
> On Wed, Nov 17, 2010 at 03:00:38PM +0800, Ike Panhc wrote:
>> Hotkey enabled by this patch:
>> Â Fn+F3: Video mode switch
>> Â Fn+F5: software rfkill for wifi
>>
>> For some ideapad when push Fn+F3, hardware generates Super-P keys, those key
>> will not be enabled by this patch.
>>
>> Signed-off-by: Ike Panhc <ike.pan@xxxxxxxxxxxxx>
>> ---
>> Âdrivers/platform/x86/ideapad-laptop.c | Â 74 +++++++++++++++++++++++++++++++++
>> Â1 files changed, 74 insertions(+), 0 deletions(-)
>>
>> diff --git a/drivers/platform/x86/ideapad-laptop.c b/drivers/platform/x86/ideapad-laptop.c
>> index d75c21f..d397034 100644
>> --- a/drivers/platform/x86/ideapad-laptop.c
>> +++ b/drivers/platform/x86/ideapad-laptop.c
>> @@ -28,6 +28,8 @@
>> Â#include <acpi/acpi_drivers.h>
>> Â#include <linux/rfkill.h>
>> Â#include <linux/platform_device.h>
>> +#include <linux/input.h>
>> +#include <linux/input/sparse-keymap.h>
>>
>> Â#define IDEAPAD_DEV_CAMERA Â 0
>> Â#define IDEAPAD_DEV_WLAN Â Â 1
>> @@ -39,6 +41,7 @@ struct ideapad_private {
>> Â Â Â acpi_handle handle;
>> Â Â Â struct rfkill *rfk[5];
>> Â Â Â struct platform_device *platform_device;
>> + Â Â struct input_dev *inputdev;
>> Â} *ideapad_priv;
>>
>> Âstatic struct {
>> @@ -325,6 +328,68 @@ static void ideapad_platform_exit(void)
>> Â}
>> Â/* the above is platform device */
>>
>> +/*
>> + * input device
>> + */
>> +static const struct key_entry ideapad_keymap[] = {
>> + Â Â { KE_KEY, 0x06, { KEY_SWITCHVIDEOMODE } },
>> + Â Â { KE_KEY, 0x0D, { KEY_WLAN } },
>> + Â Â { KE_END, 0 },
>> +};
>> +
>> +static int ideapad_input_init(void)
>
> __devinit?
>
>> +{
>> + Â Â struct input_dev *inputdev;
>> + Â Â int error;
>> +
>> + Â Â inputdev = input_allocate_device();
>> + Â Â if (!inputdev) {
>> + Â Â Â Â Â Â pr_info("Unable to allocate input device\n");
>> + Â Â Â Â Â Â return -ENOMEM;
>> + Â Â }
>> +
>> + Â Â inputdev->name = "Ideapad extra buttons";
>> + Â Â inputdev->phys = "ideapad/input0";
>> + Â Â inputdev->id.bustype = BUS_HOST;
>> + Â Â inputdev->dev.parent = &ideapad_priv->platform_device->dev;
>> +
>> + Â Â error = sparse_keymap_setup(inputdev, ideapad_keymap, NULL);
>> + Â Â if (error) {
>> + Â Â Â Â Â Â pr_err("Unable to setup input device keymap\n");
>> + Â Â Â Â Â Â goto err_free_dev;
>> + Â Â }
>> +
>> + Â Â error = input_register_device(inputdev);
>> + Â Â if (error) {
>> + Â Â Â Â Â Â pr_err("Unable to register input device\n");
>> + Â Â Â Â Â Â goto err_free_keymap;
>> + Â Â }
>> +
>> + Â Â ideapad_priv->inputdev = inputdev;
>
> Why don't you pass ideapad_priv in as an argument instead of relying on
> global. I know that there can only be one, but then why do you have a
> structure?

That may allow to remove the global later, like we did on
eeepc-laptop/asus-laptop.

>> + Â Â return 0;
>> +
>> +err_free_keymap:
>> + Â Â sparse_keymap_free(inputdev);
>> +err_free_dev:
>> + Â Â input_free_device(inputdev);
>> + Â Â return error;
>> +}
>> +
>> +static void ideapad_input_exit(void)
>
> __devexit? The rest of the driver might user these markups as well.
>
>> +{
>> + Â Â if (ideapad_priv->inputdev) {
>> + Â Â Â Â Â Â sparse_keymap_free(ideapad_priv->inputdev);
>> + Â Â Â Â Â Â input_unregister_device(ideapad_priv->inputdev);
>> + Â Â }
>> + Â Â ideapad_priv->inputdev = NULL;
>
> You fail driver initialization when ideapad_input_init() fails so there
> is no point in checking whether ideapad_priv->inputdev is null or not.
>
> Otherwise looks good from input POV.
>
> Thanks.



--
Corentin Chary
http://xf.iksaif.net
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/