All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: linux-input@vger.kernel.org, Len Brown <lenb@kernel.org>
Cc: linux-acpi@vger.kernel.org,
	Herton Ronaldo Krzesinski <herton@mandriva.com.br>,
	Harald Welte <laforge@gnumonks.org>,
	Corentin Chary <corentincj@iksaif.net>,
	Carlos Corbacho <carlos@strangeworlds.co.uk>,
	Wu Zhangjin <wuzhangjin@gmail.com>,
	Anisse Astier <anisse@astier.eu>
Subject: [PATCH 6/9] Input: eeepc-laptop - switch to using sparse keymap library
Date: Thu, 03 Dec 2009 22:12:25 -0800	[thread overview]
Message-ID: <20091204061225.28288.88508.stgit@localhost.localdomain> (raw)
In-Reply-To: <20091204060701.28288.91430.stgit@localhost.localdomain>

Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
---

 drivers/platform/x86/Kconfig        |    1 
 drivers/platform/x86/eeepc-laptop.c |  170 +++++++++++------------------------
 2 files changed, 52 insertions(+), 119 deletions(-)

diff --git a/drivers/platform/x86/Kconfig b/drivers/platform/x86/Kconfig
index 18b66fd..ae9c976 100644
--- a/drivers/platform/x86/Kconfig
+++ b/drivers/platform/x86/Kconfig
@@ -336,6 +336,7 @@ config EEEPC_LAPTOP
 	depends on HOTPLUG_PCI
 	select BACKLIGHT_CLASS_DEVICE
 	select HWMON
+	select INPUT_SPARSEKMAP
 	---help---
 	  This driver supports the Fn-Fx keys on Eee PC laptops.
 
diff --git a/drivers/platform/x86/eeepc-laptop.c b/drivers/platform/x86/eeepc-laptop.c
index 4226e53..c97305e 100644
--- a/drivers/platform/x86/eeepc-laptop.c
+++ b/drivers/platform/x86/eeepc-laptop.c
@@ -31,6 +31,7 @@
 #include <acpi/acpi_bus.h>
 #include <linux/uaccess.h>
 #include <linux/input.h>
+#include <linux/input/sparse-keymap.h>
 #include <linux/rfkill.h>
 #include <linux/pci.h>
 #include <linux/pci_hotplug.h>
@@ -169,32 +170,25 @@ static struct platform_driver platform_driver = {
 
 static struct platform_device *platform_device;
 
-struct key_entry {
-	char type;
-	u8 code;
-	u16 keycode;
-};
-
-enum { KE_KEY, KE_END };
-
-static struct key_entry eeepc_keymap[] = {
+static const struct key_entry eeepc_keymap[] = {
 	/* Sleep already handled via generic ACPI code */
-	{KE_KEY, 0x10, KEY_WLAN },
-	{KE_KEY, 0x11, KEY_WLAN },
-	{KE_KEY, 0x12, KEY_PROG1 },
-	{KE_KEY, 0x13, KEY_MUTE },
-	{KE_KEY, 0x14, KEY_VOLUMEDOWN },
-	{KE_KEY, 0x15, KEY_VOLUMEUP },
-	{KE_KEY, 0x1a, KEY_COFFEE },
-	{KE_KEY, 0x1b, KEY_ZOOM },
-	{KE_KEY, 0x1c, KEY_PROG2 },
-	{KE_KEY, 0x1d, KEY_PROG3 },
-	{KE_KEY, NOTIFY_BRN_MIN,     KEY_BRIGHTNESSDOWN },
-	{KE_KEY, NOTIFY_BRN_MIN + 2, KEY_BRIGHTNESSUP },
-	{KE_KEY, 0x30, KEY_SWITCHVIDEOMODE },
-	{KE_KEY, 0x31, KEY_SWITCHVIDEOMODE },
-	{KE_KEY, 0x32, KEY_SWITCHVIDEOMODE },
-	{KE_END, 0},
+	{ KE_KEY, 0x10, { KEY_WLAN } },
+	{ KE_KEY, 0x11, { KEY_WLAN } },
+	{ KE_KEY, 0x12, { KEY_PROG1 } },
+	{ KE_KEY, 0x13, { KEY_MUTE } },
+	{ KE_KEY, 0x14, { KEY_VOLUMEDOWN } },
+	{ KE_KEY, 0x15, { KEY_VOLUMEUP } },
+	{ KE_KEY, 0x1a, { KEY_COFFEE } },
+	{ KE_KEY, 0x1b, { KEY_ZOOM } },
+	{ KE_KEY, 0x1c, { KEY_PROG2 } },
+	{ KE_KEY, 0x1d, { KEY_PROG3 } },
+	{ KE_KEY, NOTIFY_BRN_MIN,     { KEY_BRIGHTNESSDOWN } },
+	{ KE_IGNORE, NOTIFY_BRN_MIN + 1, },
+	{ KE_KEY, NOTIFY_BRN_MIN + 2, { KEY_BRIGHTNESSUP } },
+	{ KE_KEY, 0x30, { KEY_SWITCHVIDEOMODE } },
+	{ KE_KEY, 0x31, { KEY_SWITCHVIDEOMODE } },
+	{ KE_KEY, 0x32, { KEY_SWITCHVIDEOMODE } },
+	{ KE_END, 0},
 };
 
 /*
@@ -509,61 +503,6 @@ static struct attribute_group platform_attribute_group = {
 /*
  * Hotkey functions
  */
-static struct key_entry *eepc_get_entry_by_scancode(int code)
-{
-	struct key_entry *key;
-
-	for (key = eeepc_keymap; key->type != KE_END; key++)
-		if (code == key->code)
-			return key;
-
-	return NULL;
-}
-
-static struct key_entry *eepc_get_entry_by_keycode(int code)
-{
-	struct key_entry *key;
-
-	for (key = eeepc_keymap; key->type != KE_END; key++)
-		if (code == key->keycode && key->type == KE_KEY)
-			return key;
-
-	return NULL;
-}
-
-static int eeepc_getkeycode(struct input_dev *dev, int scancode, int *keycode)
-{
-	struct key_entry *key = eepc_get_entry_by_scancode(scancode);
-
-	if (key && key->type == KE_KEY) {
-		*keycode = key->keycode;
-		return 0;
-	}
-
-	return -EINVAL;
-}
-
-static int eeepc_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 = eepc_get_entry_by_scancode(scancode);
-	if (key && key->type == KE_KEY) {
-		old_keycode = key->keycode;
-		key->keycode = keycode;
-		set_bit(keycode, dev->keybit);
-		if (!eepc_get_entry_by_keycode(old_keycode))
-			clear_bit(old_keycode, dev->keybit);
-		return 0;
-	}
-
-	return -EINVAL;
-}
-
 static void cmsg_quirk(int cm, const char *name)
 {
 	int dummy;
@@ -698,9 +637,8 @@ static void eeepc_rfkill_notify(acpi_handle handle, u32 event, void *data)
 
 static void eeepc_hotk_notify(struct acpi_device *device, u32 event)
 {
-	static struct key_entry *key;
-	u16 count;
 	int brn = -ENODEV;
+	u16 count;
 
 	if (!ehotk)
 		return;
@@ -729,19 +667,8 @@ static void eeepc_hotk_notify(struct acpi_device *device, u32 event)
 			else
 				event = NOTIFY_BRN_MIN + 1; /* ... unchanged */
 		}
-		key = eepc_get_entry_by_scancode(event);
-		if (key) {
-			switch (key->type) {
-			case KE_KEY:
-				input_report_key(ehotk->inputdev, key->keycode,
-						 1);
-				input_sync(ehotk->inputdev);
-				input_report_key(ehotk->inputdev, key->keycode,
-						 0);
-				input_sync(ehotk->inputdev);
-				break;
-			}
-		}
+
+		sparse_keymap_report_event(ehotk->inputdev, event, 1, true);
 	}
 }
 
@@ -1017,8 +944,10 @@ static void eeepc_rfkill_exit(void)
 
 static void eeepc_input_exit(void)
 {
-	if (ehotk->inputdev)
+	if (ehotk->inputdev) {
+		sparse_keymap_free(ehotk->inputdev);
 		input_unregister_device(ehotk->inputdev);
+	}
 }
 
 static void eeepc_hwmon_exit(void)
@@ -1158,36 +1087,39 @@ static int eeepc_hwmon_init(struct device *dev)
 
 static int eeepc_input_init(struct device *dev)
 {
-	const struct key_entry *key;
-	int result;
+	struct input_dev *input;
+	int error;
 
-	ehotk->inputdev = input_allocate_device();
-	if (!ehotk->inputdev) {
+	input = input_allocate_device();
+	if (!input) {
 		pr_info("Unable to allocate input device\n");
 		return -ENOMEM;
 	}
-	ehotk->inputdev->name = "Asus EeePC extra buttons";
-	ehotk->inputdev->dev.parent = dev;
-	ehotk->inputdev->phys = EEEPC_HOTK_FILE "/input0";
-	ehotk->inputdev->id.bustype = BUS_HOST;
-	ehotk->inputdev->getkeycode = eeepc_getkeycode;
-	ehotk->inputdev->setkeycode = eeepc_setkeycode;
-
-	for (key = eeepc_keymap; key->type != KE_END; key++) {
-		switch (key->type) {
-		case KE_KEY:
-			set_bit(EV_KEY, ehotk->inputdev->evbit);
-			set_bit(key->keycode, ehotk->inputdev->keybit);
-			break;
-		}
+	input->name = "Asus EeePC extra buttons";
+	input->dev.parent = dev;
+	input->phys = EEEPC_HOTK_FILE "/input0";
+	input->id.bustype = BUS_HOST;
+
+	error = sparse_keymap_setup(input, eeepc_keymap, NULL);
+	if (error) {
+		pr_err("Unable to setup input device keymap\n");
+		goto err_free_dev;
 	}
-	result = input_register_device(ehotk->inputdev);
-	if (result) {
-		pr_info("Unable to register input device\n");
-		input_free_device(ehotk->inputdev);
-		return result;
+
+	error = input_register_device(input);
+	if (error) {
+		pr_err("Unable to register input device\n");
+		goto err_free_keymap;
 	}
+
+	ehotk->inputdev = input;
 	return 0;
+
+ err_free_keymap:
+	sparse_keymap_free(input);
+ err_free_dev:
+	input_free_device(input);
+	return error;
 }
 
 static int __devinit eeepc_hotk_add(struct acpi_device *device)


  parent reply	other threads:[~2009-12-04  6:12 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-12-04  6:11 [PATCH v2 0/9] Implement sparse keymap library Dmitry Torokhov
2009-12-04  6:11 ` [PATCH 1/9] Input: add generic support for sparse keymaps Dmitry Torokhov
2009-12-04  8:02   ` Wu Zhangjin
2009-12-04  8:34     ` Anisse Astier
2009-12-04  9:17       ` Wu Zhangjin
2009-12-04  8:37     ` Dmitry Torokhov
2009-12-04  9:18       ` Wu Zhangjin
2009-12-04 14:06   ` Anisse Astier
2009-12-04 18:19     ` Dmitry Torokhov
2009-12-04 21:15       ` Anisse Astier
2009-12-06 22:57   ` Anisse Astier
2009-12-04  6:12 ` [PATCH 2/9] Input: wistron_btns - switch to using sparse keymap library Dmitry Torokhov
2009-12-04  6:12 ` [PATCH 3/9] Input: dm355evm_kbd " Dmitry Torokhov
2009-12-04  6:12 ` [PATCH 4/9] Input: dell-wmi " Dmitry Torokhov
2009-12-04  6:12 ` [PATCH 5/9] Input: hp-wmi " Dmitry Torokhov
2009-12-04  6:12 ` Dmitry Torokhov [this message]
2009-12-04  6:12 ` [PATCH 7/9] Input: asus-laptop " Dmitry Torokhov
2009-12-04  6:12 ` [PATCH 8/9] Input: topstar-laptop " Dmitry Torokhov
2010-03-29 22:19   ` Herton Ronaldo Krzesinski
2009-12-04  6:12 ` [PATCH 9/9] Input: panasonic-laptop " Dmitry Torokhov
2009-12-04 19:14   ` Harald Welte
2009-12-04 20:27     ` Dmitry Torokhov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20091204061225.28288.88508.stgit@localhost.localdomain \
    --to=dmitry.torokhov@gmail.com \
    --cc=anisse@astier.eu \
    --cc=carlos@strangeworlds.co.uk \
    --cc=corentincj@iksaif.net \
    --cc=herton@mandriva.com.br \
    --cc=laforge@gnumonks.org \
    --cc=lenb@kernel.org \
    --cc=linux-acpi@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=wuzhangjin@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.