Skip to contentSkip to conversation

Implement sparse keymap library

PATCH Superseded Dmitry Torokhov 2 participants 11 messages Dec 2, 2009 – Dec 3, 2009

Subsystems (9)
Documentation ACPI HID Input drivers +5 more subsystems

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Dmitry Torokhov

author maintainer
#0 lore raw

cover Implement sparse keymap library

Hi,

It seems that almost everty platform driver out there copied the keymap implementation from wistron button driver... That's a lot of duplicated code and I think it is high time we split it into a library module that can be shared between all these drivers.

The code is only compile-tested since I don't have boxes that would run these drivers.

Thanks.

Signature · 1 line
Dmitry
author maintainer
#1 lore raw

PATCH 1/8 Input: add generic support for sparse keymaps

More and more devices choose to reimplement support for sparse keymaps first introduced by wistron driver. Move it into a library module so it can be easily used by interested parties.

---

 Documentation/DocBook/device-drivers.tmpl |    3 
 drivers/input/Kconfig                     |   28 +++-
 drivers/input/Makefile                    |    1 
 drivers/input/input-polldev.c             |   14 ++
 drivers/input/sparse-keymap.c             |  186 +++++++++++++++++++++++++++++
 include/linux/input/sparse-keymap.h       |   52 ++++++++
 6 files changed, 272 insertions(+), 12 deletions(-)
 create mode 100644 drivers/input/sparse-keymap.c
 create mode 100644 include/linux/input/sparse-keymap.h
Documentation/DocBook/device-drivers.tmpl +3 -0
index e994d1d..0d6c9ee 100644
@@ -306,6 +306,9 @@ X!Idrivers/video/console/fonts.c
      <sect1><title>Matrix keyboars/keypads</title>
 !Iinclude/linux/input/matrix_keypad.h
      </sect1>
+     <sect1><title>Sparse keymap support</title>
+!Iinclude/linux/input/sparse-keymap.h
+!Edrivers/input/sparse-keymap.c
   </chapter>
 
   <chapter id="spi">
drivers/input/Kconfig +20 -8
index cd50c00..50af91e 100644
@@ -8,7 +8,7 @@ menu "Input device support"
 config INPUT
 	tristate "Generic input layer (needed for keyboard, mouse, ...)" if EMBEDDED
 	default y
-	---help---
+	help
 	  Say Y here if you have any input device (mouse, keyboard, tablet,
 	  joystick, steering wheel ...) connected to your system and want
 	  it to be available to applications. This includes standard PS/2
@@ -27,8 +27,7 @@ if INPUT
 
 config INPUT_FF_MEMLESS
 	tristate "Support for memoryless force-feedback devices"
-	default n
-	---help---
+	help
 	  Say Y here if you have memoryless force-feedback input device
 	  such as Logitech WingMan Force 3D, ThrustMaster FireStorm Dual
 	  Power 2, or similar. You will also need to enable hardware-specific
@@ -52,12 +51,25 @@ config INPUT_POLLDEV
 	  To compile this driver as a module, choose M here: the
 	  module will be called input-polldev.
 
+config INPUT_SPARSEKMAP
+	tristate "Sparse keymap support library"
+	help
+	  Say Y here if you are using a driver for an input
+	  device that uses sparse keymap. This option is only
+	  useful for out-of-tree drivers since in-tree drivers
+	  select it automatically.
+
+	  If unsure, say N.
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called sparse-keymap.
+
 comment "Userland interfaces"
 
 config INPUT_MOUSEDEV
 	tristate "Mouse interface" if EMBEDDED
 	default y
-	---help---
+	help
 	  Say Y here if you want your mouse to be accessible as char devices
 	  13:32+ - /dev/input/mouseX and 13:63 - /dev/input/mice as an
 	  emulated IntelliMouse Explorer PS/2 mouse. That way, all user space
@@ -73,7 +85,7 @@ config INPUT_MOUSEDEV_PSAUX
 	bool "Provide legacy /dev/psaux device"
 	default y
 	depends on INPUT_MOUSEDEV
-	---help---
+	help
 	  Say Y here if you want your mouse also be accessible as char device
 	  10:1 - /dev/psaux. The data available through /dev/psaux is exactly
 	  the same as the data from /dev/input/mice.
@@ -103,7 +115,7 @@ config INPUT_MOUSEDEV_SCREEN_Y
 
 config INPUT_JOYDEV
 	tristate "Joystick interface"
-	---help---
+	help
 	  Say Y here if you want your joystick or gamepad to be
 	  accessible as char device 13:0+ - /dev/input/jsX device.
 
@@ -125,7 +137,7 @@ config INPUT_EVDEV
 
 config INPUT_EVBUG
 	tristate "Event debugging"
-	---help---
+	help
 	  Say Y here if you have a problem with the input subsystem and
 	  want all events (keypresses, mouse movements), to be output to
 	  the system log. While this is useful for debugging, it's also
@@ -140,7 +152,7 @@ config INPUT_EVBUG
 config INPUT_APMPOWER
 	tristate "Input Power Event -> APM Bridge" if EMBEDDED
 	depends on INPUT && APM_EMULATION
-	---help---
+	help
 	  Say Y here if you want suspend key events to trigger a user
 	  requested suspend through APM. This is useful on embedded
 	  systems where such behaviour is desired without userspace
drivers/input/Makefile +1 -0
index 4c9c745..7ad212d 100644
@@ -9,6 +9,7 @@ input-core-objs := input.o input-compat.o ff-core.o
 
 obj-$(CONFIG_INPUT_FF_MEMLESS)	+= ff-memless.o
 obj-$(CONFIG_INPUT_POLLDEV)	+= input-polldev.o
+obj-$(CONFIG_INPUT_SPARSEKMAP)	+= sparse-keymap.o
 
 obj-$(CONFIG_INPUT_MOUSEDEV)	+= mousedev.o
 obj-$(CONFIG_INPUT_JOYDEV)	+= joydev.o
drivers/input/input-polldev.c +10 -4
index 6a2eb39..aa6713b 100644
@@ -212,7 +212,7 @@ EXPORT_SYMBOL(input_allocate_polled_device);
  * @dev: device to free
  *
  * The function frees memory allocated for polling device and drops
- * reference to the associated input device (if present).
+ * reference to the associated input device.
  */
 void input_free_polled_device(struct input_polled_dev *dev)
 {
@@ -258,6 +258,15 @@ int input_register_polled_device(struct input_polled_dev *dev)
 		return error;
 	}
 
+	/*
+	 * Take extra reference to the underlying input device so
+	 * that it survives call to input_unregister_polled_device()
+	 * and is deleted only after input_free_polled_device()
+	 * has been invoked. This is needed to ease task of freeing
+	 * sparse keymaps.
+	 */
+	input_get_device(input);
+
 	return 0;
 }
 EXPORT_SYMBOL(input_register_polled_device);
@@ -269,8 +278,6 @@ EXPORT_SYMBOL(input_register_polled_device);
  * The function unregisters previously registered polled input
  * device from input layer. Polling is stopped and device is
  * ready to be freed with call to input_free_polled_device().
- * Callers should not attempt to access dev->input pointer
- * after calling this function.
  */
 void input_unregister_polled_device(struct input_polled_dev *dev)
 {
@@ -278,7 +285,6 @@ void input_unregister_polled_device(struct input_polled_dev *dev)
 			   &input_polldev_attribute_group);
 
 	input_unregister_device(dev->input);
-	dev->input = NULL;
 }
 EXPORT_SYMBOL(input_unregister_polled_device);
 
drivers/input/sparse-keymap.c new file +186 -0

186 lines not on this page · raw message

include/linux/input/sparse-keymap.h new file +52 -0

52 lines not on this page · raw message

author maintainer
#2 lore raw

PATCH 2/8 Input: wistron_btns - switch to using sparse keymap library

In reply to Dmitry Torokhov

The keymap manipulation code was split into a library module, so let's make us of it.

---

 drivers/input/misc/Kconfig        |    1 
 drivers/input/misc/wistron_btns.c |  150 ++++++++++---------------------------
 2 files changed, 42 insertions(+), 109 deletions(-)
drivers/input/misc/Kconfig +1 -0
index a9bb254..d25ecbb 100644
@@ -80,6 +80,7 @@ config INPUT_WISTRON_BTNS
 	tristate "x86 Wistron laptop button interface"
 	depends on X86 && !X86_64
 	select INPUT_POLLDEV
+	select INPUT_SPARSEKMAP
 	select NEW_LEDS
 	select LEDS_CLASS
 	select CHECK_SIGNATURE
drivers/input/misc/wistron_btns.c +41 -109

201 lines not on this page · raw message

author maintainer
#3 lore raw

PATCH 3/8 Input: dell-wmi - switch to using sparse keymap library

In reply to Dmitry Torokhov

---

 drivers/platform/x86/Kconfig    |    1 
 drivers/platform/x86/dell-wmi.c |  186 +++++++++++++--------------------------
 2 files changed, 61 insertions(+), 126 deletions(-)
drivers/platform/x86/Kconfig +1 -0
index 55ca39d..1f10bf4 100644
@@ -88,6 +88,7 @@ config DELL_WMI
 	tristate "Dell WMI extras"
 	depends on ACPI_WMI
 	depends on INPUT
+	select INPUT_SPARSEKMAP
 	---help---
 	  Say Y here if you want to support WMI-based hotkeys on Dell laptops.
 
drivers/platform/x86/dell-wmi.c +60 -126

265 lines not on this page · raw message

author maintainer
#4 lore raw

PATCH 4/8 Input: hp-wmi - switch to using sparse keymap library

In reply to Dmitry Torokhov

---

 drivers/platform/x86/Kconfig  |    1 
 drivers/platform/x86/hp-wmi.c |  142 ++++++++++++-----------------------------
 2 files changed, 44 insertions(+), 99 deletions(-)
drivers/platform/x86/Kconfig +1 -0
index 1f10bf4..18b66fd 100644
@@ -137,6 +137,7 @@ config HP_WMI
 	depends on ACPI_WMI
 	depends on INPUT
 	depends on RFKILL || RFKILL = n
+	select INPUT_SPARSEKMAP
 	help
 	 Say Y here if you want to support WMI-based hotkeys on HP laptops and
 	 to read data from WMI such as docking or ambient light sensor state.
drivers/platform/x86/hp-wmi.c +43 -99

200 lines not on this page · raw message

author maintainer
#7 lore raw

PATCH 5/8 Input: eeepc-laptop - switch to using sparse keymap library

In reply to Dmitry Torokhov

---

 drivers/platform/x86/Kconfig        |    1 
 drivers/platform/x86/eeepc-laptop.c |  153 +++++++++++------------------------
 2 files changed, 49 insertions(+), 105 deletions(-)
drivers/platform/x86/Kconfig +1 -0
index 18b66fd..ae9c976 100644
@@ -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.
 
drivers/platform/x86/eeepc-laptop.c +48 -105

204 lines not on this page · raw message

author maintainer
#8 lore raw

PATCH 6/8 Input: asus-laptop - switch to using sparse keymap library

In reply to Dmitry Torokhov

---

 drivers/platform/x86/Kconfig       |    1 
 drivers/platform/x86/asus-laptop.c |  181 +++++++++++++-----------------------
 2 files changed, 64 insertions(+), 118 deletions(-)
drivers/platform/x86/Kconfig +1 -0
index ae9c976..e555d39 100644
@@ -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
drivers/platform/x86/asus-laptop.c +63 -118

231 lines not on this page · raw message

author maintainer
#9 lore raw

PATCH 7/8 Input: topstar-laptop - switch to using sparse keymap library

In reply to Dmitry Torokhov

---

 drivers/platform/x86/Kconfig          |    1 
 drivers/platform/x86/topstar-laptop.c |  146 ++++++++++++---------------------
 2 files changed, 52 insertions(+), 95 deletions(-)
drivers/platform/x86/Kconfig +1 -0
index e555d39..00e94b0 100644
@@ -405,6 +405,7 @@ config TOPSTAR_LAPTOP
 	tristate "Topstar Laptop Extras"
 	depends on ACPI
 	depends on INPUT
+	select INPUT_SPARSEKMAP
 	---help---
 	  This driver adds support for hotkeys found on Topstar laptops.
 
drivers/platform/x86/topstar-laptop.c +51 -95

191 lines not on this page · raw message

author maintainer
#10 lore raw

PATCH 8/8 Input: panasonic-laptop - switch to using sparse keymap library

In reply to Dmitry Torokhov

---

 drivers/platform/x86/Kconfig            |    1 
 drivers/platform/x86/panasonic-laptop.c |  172 ++++++++++++-------------------
 2 files changed, 66 insertions(+), 107 deletions(-)
drivers/platform/x86/Kconfig +1 -0
index 00e94b0..1b27e4d 100644
@@ -168,6 +168,7 @@ config PANASONIC_LAPTOP
 	tristate "Panasonic Laptop Extras"
 	depends on INPUT && ACPI
 	depends on BACKLIGHT_CLASS_DEVICE
+	select INPUT_SPARSEKMAP
 	---help---
 	  This driver adds support for access to backlight control and hotkeys
 	  on Panasonic Let's Note laptops.
drivers/platform/x86/panasonic-laptop.c +65 -107

241 lines not on this page · raw message

#5 lore raw

Re: [PATCH 4/8] Input: hp-wmi - switch to using sparse keymap library

In reply to Dmitry Torokhov

Hi Dmitry,

Quoted 27 lines · Dmitry Torokhov
drivers/platform/x86/hp-wmi.c +11 -5
index c284217..8868610 100644
@@ -411,14 +342,29 @@ static int __init hp_wmi_input_setup(void)
 			    hp_wmi_tablet_state());
 	input_sync(hp_wmi_input_dev);
 
-	err = input_register_device(hp_wmi_input_dev);
+	err = wmi_install_notify_handler(HPWMI_EVENT_GUID, hp_wmi_notify, NULL);
+	if (err)
+		goto err_free_keymap;
 
-	if (err) {
-		input_free_device(hp_wmi_input_dev);
-		return err;
-	}
+	err = input_register_device(hp_wmi_input_dev);
+	if (err)
+		goto err_uninstall_notifier;
 
 	return 0;
+
+ err_uninstall_notifier:
+	wmi_remove_notify_handler(HPWMI_EVENT_GUID);
+ err_free_keymap:
+	(hp_wmi_input_dev);

drivers/platform/x86/hp-wmi.c static int __init hp_wmi_input_setup(void) · line 368

Quoted 10 lines
drivers/platform/x86/hp-wmi.c +9 -0
+ err_free_dev:
+	input_free_device(hp_wmi_input_dev);
+	return err;
+}
+
+static void __exit hp_wmi_input_destroy(void)
+{
+	wmi_remove_notify_handler(HPWMI_EVENT_GUID);
+	input_unregister_device(hp_wmi_input_dev);
 }

I'm not sure if you're calling sparse_keymap_free on the exit path.

Quoted 7 lines
drivers/platform/x86/hp-wmi.c +0 -0
 static void cleanup_sysfs(struct platform_device *device)
@@ -564,10 +509,9 @@ static int __init hp_wmi_init(void)
 
 static void __exit hp_wmi_exit(void)
 {

drivers/platform/x86/hp-wmi.c static int __init hp_wmi_init(void) · line 517

Quoted 10 lines
drivers/platform/x86/hp-wmi.c +3 -4
-	if (wmi_has_guid(HPWMI_EVENT_GUID)) {
-		wmi_remove_notify_handler(HPWMI_EVENT_GUID);
-		input_unregister_device(hp_wmi_input_dev);
-	}
+	if (wmi_has_guid(HPWMI_EVENT_GUID))
+		hp_wmi_input_destroy();
+
 	if (hp_wmi_platform_dev) {
 		platform_device_del(hp_wmi_platform_dev);
 		platform_driver_unregister(&hp_wmi_driver);

OK, I'm guilty, I copied my sparse keymap adaptation for msi-wmi from this patch :-)

--
Anisse

author maintainer
#6 lore raw

Re: [PATCH 4/8] Input: hp-wmi - switch to using sparse keymap library

Quoted 35 lines · Anisse Astier

Hi Dmitry,

Quoted 30 lines · Dmitry Torokhov
drivers/platform/x86/hp-wmi.c +14 -5
index c284217..8868610 100644
@@ -411,14 +342,29 @@ static int __init hp_wmi_input_setup(void)
 			    hp_wmi_tablet_state());
 	input_sync(hp_wmi_input_dev);
 
-	err = input_register_device(hp_wmi_input_dev);
+	err = wmi_install_notify_handler(HPWMI_EVENT_GUID, hp_wmi_notify, NULL);
+	if (err)
+		goto err_free_keymap;
 
-	if (err) {
-		input_free_device(hp_wmi_input_dev);
-		return err;
-	}
+	err = input_register_device(hp_wmi_input_dev);
+	if (err)
+		goto err_uninstall_notifier;
 
 	return 0;
+
+ err_uninstall_notifier:
+	wmi_remove_notify_handler(HPWMI_EVENT_GUID);
+ err_free_keymap:
+	(hp_wmi_input_dev);
+ err_free_dev:
+	input_free_device(hp_wmi_input_dev);
+	return err;
Quoted 9 lines

drivers/platform/x86/hp-wmi.c static int __init hp_wmi_input_setup(void) · line 368

Quoted 7 lines
drivers/platform/x86/hp-wmi.c +6 -0
+}
+
+static void __exit hp_wmi_input_destroy(void)
+{
+	wmi_remove_notify_handler(HPWMI_EVENT_GUID);
+	input_unregister_device(hp_wmi_input_dev);
 }

I'm not sure if you're calling sparse_keymap_free on the exit path.

Guilty as charged ;)

Signature · 1 line
Dmitry