From patchwork Fri Dec 4 06:12:30 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Torokhov X-Patchwork-Id: 64787 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id nB46CUYK003882 for ; Fri, 4 Dec 2009 06:12:35 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751962AbZLDGM1 (ORCPT ); Fri, 4 Dec 2009 01:12:27 -0500 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1751975AbZLDGM1 (ORCPT ); Fri, 4 Dec 2009 01:12:27 -0500 Received: from mail-yx0-f187.google.com ([209.85.210.187]:55857 "EHLO mail-yx0-f187.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751962AbZLDGM0 (ORCPT ); Fri, 4 Dec 2009 01:12:26 -0500 Received: by mail-yx0-f187.google.com with SMTP id 17so1850312yxe.33 for ; Thu, 03 Dec 2009 22:12:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:from:subject:to:cc:date :message-id:in-reply-to:references:user-agent:mime-version :content-type:content-transfer-encoding; bh=c4/k/2hOCHoACQEYI663/5cjBG5OhE/uwtNJmNc0YjY=; b=DSoJvTlnwur3eXLPhUUpyWTB+N7we0ccvN2jVgbXzVRIk/7tUksb8eBNuJDpy0ptMO kncgrATOu6D470eVa+/YMjaABS2AvlVj/hY4aOpRwCP7U18mdKh050O3W7C1usMzg1Vl DQNopPVfIGOadNU+kGTHX0XGyjOS+RvV5EVDI= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=from:subject:to:cc:date:message-id:in-reply-to:references :user-agent:mime-version:content-type:content-transfer-encoding; b=i0AW7HI1egekYYLE8y9Wn5nZDYWcw3q5dJuVOwH+wfjv6X7OJFDEc4V5roSlfyiatf PZDFHyhL3EZMqTuMCD+PzBUkb3zUkmaxujfIJ8G5/YW6WreNruuIU1TuI+iZiDjVWKMS p/3vCMDQ8oSX9ERskfX+uGduhFkW+/ARXD6HM= Received: by 10.150.25.19 with SMTP id 19mr4647555yby.165.1259907153396; Thu, 03 Dec 2009 22:12:33 -0800 (PST) Received: from mailhub.coreip.homeip.net (c-24-6-153-137.hsd1.ca.comcast.net [24.6.153.137]) by mx.google.com with ESMTPS id 6sm1102402ywc.39.2009.12.03.22.12.32 (version=TLSv1/SSLv3 cipher=RC4-MD5); Thu, 03 Dec 2009 22:12:32 -0800 (PST) From: Dmitry Torokhov Subject: [PATCH 7/9] Input: asus-laptop - switch to using sparse keymap library To: linux-input@vger.kernel.org, Len Brown Cc: linux-acpi@vger.kernel.org, Herton Ronaldo Krzesinski , Harald Welte , Corentin Chary , Carlos Corbacho , Wu Zhangjin , Anisse Astier Date: Thu, 03 Dec 2009 22:12:30 -0800 Message-ID: <20091204061230.28288.26159.stgit@localhost.localdomain> In-Reply-To: <20091204060701.28288.91430.stgit@localhost.localdomain> References: <20091204060701.28288.91430.stgit@localhost.localdomain> User-Agent: StGIT/0.14.3 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig index ae9c976..e555d39 100644 --- a/drivers/platform/x86/Kconfig +++ b/drivers/platform/x86/Kconfig @@ -59,6 +59,7 @@ config ASUS_LAPTOP select NEW_LEDS select BACKLIGHT_CLASS_DEVICE depends on INPUT + select INPUT_SPARSEKMAP ---help--- This is the new Linux driver for Asus laptops. It may also support some MEDION, JVC or VICTOR laptops. It makes all the extra buttons generate diff --git a/drivers/platform/x86/asus-laptop.c b/drivers/platform/x86/asus-laptop.c index b39d2bb..7da59d8 100644 --- a/drivers/platform/x86/asus-laptop.c +++ b/drivers/platform/x86/asus-laptop.c @@ -49,6 +49,7 @@ #include #include #include +#include #define ASUS_LAPTOP_VERSION "0.42" @@ -284,42 +285,34 @@ ASUS_LED(pled, "phone", 1); ASUS_LED(gled, "gaming", 1); ASUS_LED(kled, "kbd_backlight", 3); -struct key_entry { - char type; - u8 code; - u16 keycode; -}; - -enum { KE_KEY, KE_END }; - -static struct key_entry asus_keymap[] = { - {KE_KEY, 0x30, KEY_VOLUMEUP}, - {KE_KEY, 0x31, KEY_VOLUMEDOWN}, - {KE_KEY, 0x32, KEY_MUTE}, - {KE_KEY, 0x33, KEY_SWITCHVIDEOMODE}, - {KE_KEY, 0x34, KEY_SWITCHVIDEOMODE}, - {KE_KEY, 0x40, KEY_PREVIOUSSONG}, - {KE_KEY, 0x41, KEY_NEXTSONG}, - {KE_KEY, 0x43, KEY_STOPCD}, - {KE_KEY, 0x45, KEY_PLAYPAUSE}, - {KE_KEY, 0x4c, KEY_MEDIA}, - {KE_KEY, 0x50, KEY_EMAIL}, - {KE_KEY, 0x51, KEY_WWW}, - {KE_KEY, 0x55, KEY_CALC}, - {KE_KEY, 0x5C, KEY_SCREENLOCK}, /* Screenlock */ - {KE_KEY, 0x5D, KEY_WLAN}, - {KE_KEY, 0x5E, KEY_WLAN}, - {KE_KEY, 0x5F, KEY_WLAN}, - {KE_KEY, 0x60, KEY_SWITCHVIDEOMODE}, - {KE_KEY, 0x61, KEY_SWITCHVIDEOMODE}, - {KE_KEY, 0x6B, BTN_TOUCH}, /* Lock Mouse */ - {KE_KEY, 0x82, KEY_CAMERA}, - {KE_KEY, 0x8A, KEY_PROG1}, - {KE_KEY, 0x95, KEY_MEDIA}, - {KE_KEY, 0x99, KEY_PHONE}, - {KE_KEY, 0xc4, KEY_KBDILLUMUP}, - {KE_KEY, 0xc5, KEY_KBDILLUMDOWN}, - {KE_END, 0}, +static const struct key_entry asus_keymap[] = { + { KE_KEY, 0x30, { KEY_VOLUMEUP } }, + { KE_KEY, 0x31, { KEY_VOLUMEDOWN } }, + { KE_KEY, 0x32, { KEY_MUTE } }, + { KE_KEY, 0x33, { KEY_SWITCHVIDEOMODE } }, + { KE_KEY, 0x34, { KEY_SWITCHVIDEOMODE } }, + { KE_KEY, 0x40, { KEY_PREVIOUSSONG } }, + { KE_KEY, 0x41, { KEY_NEXTSONG } }, + { KE_KEY, 0x43, { KEY_STOPCD } }, + { KE_KEY, 0x45, { KEY_PLAYPAUSE } }, + { KE_KEY, 0x4c, { KEY_MEDIA } }, + { KE_KEY, 0x50, { KEY_EMAIL } }, + { KE_KEY, 0x51, { KEY_WWW } }, + { KE_KEY, 0x55, { KEY_CALC } }, + { KE_KEY, 0x5C, { KEY_SCREENLOCK } }, /* Screenlock */ + { KE_KEY, 0x5D, { KEY_WLAN } }, + { KE_KEY, 0x5E, { KEY_WLAN } }, + { KE_KEY, 0x5F, { KEY_WLAN } }, + { KE_KEY, 0x60, { KEY_SWITCHVIDEOMODE } }, + { KE_KEY, 0x61, { KEY_SWITCHVIDEOMODE } }, + { KE_KEY, 0x6B, { BTN_TOUCH } }, /* Lock Mouse */ + { KE_KEY, 0x82, { KEY_CAMERA } }, + { KE_KEY, 0x8A, { KEY_PROG1 } }, + { KE_KEY, 0x95, { KEY_MEDIA } }, + { KE_KEY, 0x99, { KEY_PHONE } }, + { KE_KEY, 0xc4, { KEY_KBDILLUMUP } }, + { KE_KEY, 0xc5, { KEY_KBDILLUMDOWN } }, + { KE_END, 0}, }; /* @@ -866,64 +859,8 @@ static ssize_t store_gps(struct device *dev, struct device_attribute *attr, /* * Hotkey functions */ -static struct key_entry *asus_get_entry_by_scancode(int code) -{ - struct key_entry *key; - - for (key = asus_keymap; key->type != KE_END; key++) - if (code == key->code) - return key; - - return NULL; -} - -static struct key_entry *asus_get_entry_by_keycode(int code) -{ - struct key_entry *key; - - for (key = asus_keymap; key->type != KE_END; key++) - if (code == key->keycode && key->type == KE_KEY) - return key; - - return NULL; -} - -static int asus_getkeycode(struct input_dev *dev, int scancode, int *keycode) -{ - struct key_entry *key = asus_get_entry_by_scancode(scancode); - - if (key && key->type == KE_KEY) { - *keycode = key->keycode; - return 0; - } - - return -EINVAL; -} - -static int asus_setkeycode(struct input_dev *dev, int scancode, int keycode) -{ - struct key_entry *key; - int old_keycode; - - if (keycode < 0 || keycode > KEY_MAX) - return -EINVAL; - - key = asus_get_entry_by_scancode(scancode); - if (key && key->type == KE_KEY) { - old_keycode = key->keycode; - key->keycode = keycode; - set_bit(keycode, dev->keybit); - if (!asus_get_entry_by_keycode(old_keycode)) - clear_bit(old_keycode, dev->keybit); - return 0; - } - - return -EINVAL; -} - static void asus_hotk_notify(struct acpi_device *device, u32 event) { - static struct key_entry *key; u16 count; /* TODO Find a better way to handle events count. */ @@ -948,20 +885,8 @@ static void asus_hotk_notify(struct acpi_device *device, u32 event) dev_name(&hotk->device->dev), event, count); - if (hotk->inputdev) { - key = asus_get_entry_by_scancode(event); - if (!key) - return ; - - switch (key->type) { - case KE_KEY: - input_report_key(hotk->inputdev, key->keycode, 1); - input_sync(hotk->inputdev); - input_report_key(hotk->inputdev, key->keycode, 0); - input_sync(hotk->inputdev); - break; - } - } + if (hotk->inputdev) + sparse_keymap_report_event(hotk->inputdev, event, 1, true); } #define ASUS_CREATE_DEVICE_ATTR(_name) \ @@ -1009,7 +934,7 @@ static struct platform_driver asuspf_driver = { .driver = { .name = ASUS_HOTK_FILE, .owner = THIS_MODULE, - } + }, }; static struct platform_device *asuspf_device; @@ -1184,36 +1109,41 @@ static int asus_hotk_get_info(void) return AE_OK; } -static int asus_input_init(void) +static int __init asus_input_init(void) { - const struct key_entry *key; - int result; + struct input_dev *inputdev; + int error; - hotk->inputdev = input_allocate_device(); - if (!hotk->inputdev) { - pr_info("Unable to allocate input device\n"); - return 0; + inputdev = input_allocate_device(); + if (!inputdev) { + pr_err("Unable to allocate input device\n"); + return -ENOMEM; } - hotk->inputdev->name = "Asus Laptop extra buttons"; - hotk->inputdev->phys = ASUS_HOTK_FILE "/input0"; - hotk->inputdev->id.bustype = BUS_HOST; - hotk->inputdev->getkeycode = asus_getkeycode; - hotk->inputdev->setkeycode = asus_setkeycode; - - for (key = asus_keymap; key->type != KE_END; key++) { - switch (key->type) { - case KE_KEY: - set_bit(EV_KEY, hotk->inputdev->evbit); - set_bit(key->keycode, hotk->inputdev->keybit); - break; - } + + inputdev->name = "Asus Laptop extra buttons"; + inputdev->phys = ASUS_HOTK_FILE "/input0"; + inputdev->id.bustype = BUS_HOST; + + error = sparse_keymap_setup(inputdev, asus_keymap, NULL); + if (error) { + pr_err("Unable to setup input device keymap\n"); + goto err_free_dev; } - result = input_register_device(hotk->inputdev); - if (result) { - pr_info("Unable to register input device\n"); - input_free_device(hotk->inputdev); + + error = input_register_device(inputdev); + if (error) { + pr_err("Unable to register input device\n"); + goto err_free_keymap; } - return result; + + hotk->inputdev = inputdev; + return 0; + + err_free_keymap: + sparse_keymap_free(inputdev); + err_free_dev: + input_free_device(inputdev); + return error; } static int asus_hotk_check(void) @@ -1338,8 +1268,10 @@ static void asus_led_exit(void) static void asus_input_exit(void) { - if (hotk->inputdev) + if (hotk->inputdev) { + sparse_keymap_free(hotk->inputdev); input_unregister_device(hotk->inputdev); + } } static void __exit asus_laptop_exit(void)