Implement sparse keymap library
Subsystems (9)
Dmitry Torokhov
maintainercover 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
Dmitry Torokhov
maintainerPATCH 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
@@ -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
@@ -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
@@ -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
@@ -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
Dmitry Torokhov
maintainerPATCH 2/8 Input: wistron_btns - switch to using sparse keymap library
In reply to Dmitry TorokhovThe 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
@@ -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
Dmitry Torokhov
maintainerPATCH 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
@@ -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
Dmitry Torokhov
maintainerPATCH 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
@@ -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
Re: [PATCH 4/8] Input: hp-wmi - switch to using sparse keymap library
Hi Dmitry,
Quoted 27 lines · Dmitry Torokhov
drivers/platform/x86/hp-wmi.c +11
-5@@ -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
-0static 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
Dmitry Torokhov
maintainerRe: [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@@ -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_freeon the exit path.
Guilty as charged ;)
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerPATCH 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
@@ -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
Dmitry Torokhov
maintainerPATCH 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
@@ -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
Dmitry Torokhov
maintainerPATCH 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
@@ -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
Dmitry Torokhov
maintainerPATCH 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
@@ -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