Implement sparse keymap library
Subsystems (9)
Dmitry Torokhov
maintainerv2 cover Implement sparse keymap library
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.
Changes since v1: added sparse_keymap_report_event() and sparse_keymap_report_entry() to furger reduce code in the drivers.
Len, what would be the best way to merge this? The patches touch a few of the platform drivers and I would like to get it done sooner than later because teh patch converting EVIOCGKEYCODE and EVIOCSKEYCODE to use unisgned int instead of signed int scancodes depends on it.
Thanks.
Signature · 1 line
Dmitry
Dmitry Torokhov
maintainerPATCH v2 1/9 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 | 4 drivers/input/Kconfig | 28 ++- drivers/input/Makefile | 1 drivers/input/input-polldev.c | 14 +- drivers/input/sparse-keymap.c | 251 +++++++++++++++++++++++++++++ include/linux/input/sparse-keymap.h | 62 +++++++ 6 files changed, 348 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 +4 -0
@@ -306,6 +306,10 @@ 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 + </sect1> </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 +251 -0
251 lines not on this page · raw message
include/linux/input/sparse-keymap.h new file +62 -0
62 lines not on this page · raw message
Re: [PATCH 1/9] Input: add generic support for sparse keymaps
Quoted 3 lines · Dmitry Torokhov
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.
Hi, Dmitry
I have tried to apply this patch to the latest 2.6.32 and the linux-mips tree, both rejected.
So, which git tree should I use?
Thanks!
Wu Zhangjin
Quoted 499 lines
Signed-off-by Dmitry Torokhov <[email protected]>---
Documentation/DocBook/device-drivers.tmpl | 4 drivers/input/Kconfig | 28 ++- drivers/input/Makefile | 1 drivers/input/input-polldev.c | 14 +- drivers/input/sparse-keymap.c | 251 +++++++++++++++++++++++++++++ include/linux/input/sparse-keymap.h | 62 +++++++ 6 files changed, 348 insertions(+), 12 deletions(-) create mode 100644 drivers/input/sparse-keymap.c create mode 100644 include/linux/input/sparse-keymap.hDocumentation/DocBook/device-drivers.tmpl +4
-0@@ -306,6 +306,10 @@ 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 + </sect1> </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 userspacedrivers/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.odrivers/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 +251
-0@@ -0,0 +1,251 @@ +/* +* Generic support for sparse keymaps +* +* Copyright (c) 2009 Dmitry Torokhov +* +* Derived from wistron button driver: +* Copyright (C) 2005 Miloslav Trmac <[email protected]> +* Copyright (C) 2005 Bernhard Rosenkraenzer <[email protected]> +* Copyright (C) 2005 Dmitry Torokhov <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published by +* the Free Software Foundation. +*/ + +#include <linux/input.h> +#include <linux/input/sparse-keymap.h> + +MODULE_AUTHOR ("Dmitry Torokhov <[email protected]>" ); +MODULE_DESCRIPTION ("Generic support for sparse keymaps" ); +MODULE_LICENSE ("GPL v2" ); +MODULE_VERSION ("0.1" ); + +/** +* sparse_keymap_entry_from_scancode - perform sparse keymap lookup +* @dev: Input device using sparse keymap +* @code: Scan code +* +* This function is used to perform &struct key_entry lookup in an +* input device using sparse keymap. +*/ +struct key_entry *sparse_keymap_entry_from_scancode (struct input_dev *dev, +unsigned int code) +{ +struct key_entry *key; + +for (key = dev->keycode; key->type !=KE_END ; key++) +if (code == key->code) +return key; + +return NULL ; +} +EXPORT_SYMBOL (sparse_keymap_entry_from_scancode); + +/** +* sparse_keymap_entry_from_keycode - perform sparse keymap lookup +* @dev: Input device using sparse keymap +* @keycode: Key code +* +* This function is used to perform &struct key_entry lookup in an +* input device using sparse keymap. +*/ +struct key_entry *sparse_keymap_entry_from_keycode (struct input_dev *dev, +unsigned int keycode) +{ +struct key_entry *key; + +for (key = dev->keycode; key->type !=KE_END ; key++) +if (key->type ==KE_KEY && keycode == key->keycode) +return key; + +return NULL ; +} +EXPORT_SYMBOL (sparse_keymap_entry_from_keycode); + +static int sparse_keymap_getkeycode (struct input_dev *dev, +int scancode,int *keycode) +{ +const struct key_entry *key = +sparse_keymap_entry_from_scancode (dev, scancode); + +if (key && key->type ==KE_KEY ) { + *keycode = key->keycode; +return 0 ; + } + +return -EINVAL ; +} + +static int sparse_keymap_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 =sparse_keymap_entry_from_scancode (dev, scancode); +if (key && key->type ==KE_KEY ) { + old_keycode = key->keycode; + key->keycode = keycode; +set_bit (keycode, dev->keybit); +if (!sparse_keymap_entry_from_keycode (dev, old_keycode)) +clear_bit (old_keycode, dev->keybit); +return 0 ; + } + +return -EINVAL ; +} +EXPORT_SYMBOL (sparse_keymap_setkeycode); + +/** +* sparse_keymap_setup - set up sparse keymap for an input device +* @dev: Input device +* @keymap: Keymap in form of array of &key_entry structures ending +* with %KE_END type entry +* @setup: Function that can be used to adjust keymap entries +* depending on device's deeds, may be %NULL +* +* The function calculates size and allocates copy of the original +* keymap after which sets up input device event bits appropriately. +* Before detsroying input device allocated keymap should be freed +* with a call to sparse_keymap_free(). +*/ +int sparse_keymap_setup (struct input_dev *dev, +const struct key_entry *keymap, +int (*setup)(struct input_dev *,struct key_entry *)) +{ +size_t map_size =1 ;/* to account for the last KE_END entry */ +const struct key_entry *e; +struct key_entry *map, *entry; +int i; +int error; + +for (e = keymap; e->type !=KE_END ; e++) + map_size++; + + map =kcalloc (map_size,sizeof (struct key_entry ),GFP_KERNEL ); +if (!map) +return -ENOMEM ; + +memcpy (map, keymap, map_size *sizeof (struct key_entry )); + +for (i =0 ; i < map_size; i++) { + entry = &map[i]; + +if (setup) { + error =setup (dev, entry); +if (error) + goto err_out; + } + +switch (entry->type) { +case KE_KEY : +__set_bit (EV_KEY , dev->evbit); +__set_bit (entry->keycode, dev->keybit); +break ; + +case KE_SW : +__set_bit (EV_SW , dev->evbit); +__set_bit (entry->sw.code, dev->swbit); +break ; + } + } + + dev->keycode = map; + dev->keycodemax = map_size; + dev->getkeycode = sparse_keymap_getkeycode; + dev->setkeycode = sparse_keymap_setkeycode; + +return 0 ; + + err_out: +kfree (keymap); +return error; + +} +EXPORT_SYMBOL (sparse_keymap_setup); + +/** +* sparse_keymap_free - free memory allocated for sparse keymap +* @dev: Input device using sparse keymap +* +* This function is used to free memory allocated by sparse keymap +* in an input device that was set up by sparse_keymap_setup(). +*/ +void sparse_keymap_free (struct input_dev *dev) +{ +kfree (dev->keycode); + dev->keycode =NULL ; + dev->keycodemax =0 ; + dev->getkeycode =NULL ; + dev->setkeycode =NULL ; +} +EXPORT_SYMBOL (sparse_keymap_free); + +/** +* sparse_keymap_report_event - report event corresponding to given key entry +* @dev: Input device for which event should be reported +* @ke: key entry describing event +* @value: Value that should be reported (ignored by %KE_SW entries) +* @autorelease: Signals whether release event should be emitted for %KE_KEY +* entries right after reporting press event, ignored by all other +* entries +* +* This function is used to report input event described by given +* &struct key_entry. +*/ +void sparse_keymap_report_entry (struct input_dev *dev,const struct key_entry *ke, +unsigned int value,bool autorelease) +{ +switch (ke->type) { +case KE_KEY : +input_report_key (dev, ke->keycode, value); +input_sync (dev); +if (value && autorelease) { +input_report_key (dev, ke->keycode,0 ); +input_sync (dev); + } +break ; + +case KE_SW : + value = ke->sw.value; +/* fall through */ + +case KE_VSW : +input_report_switch (dev, ke->sw.code, value); +break ; + } +} +EXPORT_SYMBOL (sparse_keymap_report_entry); + +/** +* sparse_keymap_report_event - report event corresponding to given scancode +* @dev: Input device using sparse keymap +* @code: Scan code +* @value: Value that should be reported (ignored by %KE_SW entries) +* @autorelease: Signals whether release event should be emitted for %KE_KEY +* entries right after reporting press event, ignored by all other +* entries +* +* This function is used to perform lookup in an input device using sparse +* keymap and report corresponding event. Returns %true if lookup was +* successful and %false otherwise. +*/ +bool sparse_keymap_report_event (struct input_dev *dev,unsigned int code, +unsigned int value,bool autorelease) +{ +const struct key_entry *ke = +sparse_keymap_entry_from_scancode (dev, code); + +if (ke) { +sparse_keymap_report_entry (dev, ke, value, autorelease); +return true; + } + +return false; +} +EXPORT_SYMBOL (sparse_keymap_report_event); +include/linux/input/sparse-keymap.h new file +62
-0@@ -0,0 +1,62 @@ +#ifndef _SPARSE_KEYMAP_H +#define _SPARSE_KEYMAP_H + +/* +* Copyright (c) 2009 Dmitry Torokhov +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License version 2 as published by +* the Free Software Foundation. +*/ + +#define KE_END 0/* Indicates end of keymap */ +#define KE_KEY 1/* Ordinary key/button */ +#define KE_SW 2/* Switch (predetermined value) */ +#define KE_VSW 3/* Switch (value supplied at runtime) */ +#define KE_IGNORE 4/* Known entry that should be ignored */ +#define KE_LAST KE_IGNORE + +/** +* struct key_entry - keymap entry for use in sparse keymap +* @type: Type of the key entry (KE_KEY, KE_SW, KE_VSW, KE_END); +* drivers are allowed to extend the list with their own +* private definitions. +* @code: Device-specific data identifying the button/switch +* @keycode: KEY_* code assigned to a key/button +* @sw.code: SW_* code assigned to a switch +* @sw.value: Value that should be sent in an input even when KE_SW +* switch is toggled. KE_VSW switches ignore this field and +* expect driver to supply value for the event. +* +* This structure defines an entry in a sparse keymap used by some +* input devices for which traditional table-based approach is not +* suitable. +*/ +struct key_entry { +int type;/* See KE_* above */ +u32 code; +union { +u16 keycode;/* For KE_KEY */ +struct {/* For KE_SW, KE_VSW */ +u8 code; +u8 value;/* For KE_SW, ignored by KE_VSW */ + } sw; + }; +}; + +struct key_entry *sparse_keymap_entry_from_scancode (struct input_dev *dev, +unsigned int code); +struct key_entry *sparse_keymap_entry_from_keycode (struct input_dev *dev, +unsigned int code); +int sparse_keymap_setup (struct input_dev *dev, +const struct key_entry *keymap, +int (*setup)(struct input_dev *,struct key_entry *)); +void sparse_keymap_free (struct input_dev *dev); + +void sparse_keymap_report_entry (struct input_dev *dev,const struct key_entry *ke, +unsigned int value,bool autorelease); + +bool sparse_keymap_report_event (struct input_dev *dev,unsigned int code, +unsigned int value,bool autorelease); + +#endif /* _SPARSE_KEYMAP_H */
Re: [PATCH 1/9] Input: add generic support for sparse keymaps
Hi Wu,
Quoted 5 lines · Wu Zhangjin
I have tried to apply this patch to the latest 2.6.32 and the linux-mips tree, both rejected.
So, which git tree should I use?
Last time I had to use Dmitry's input tree:git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git
Just checked it, this one applies.
Regards,
Anisse
Re: [PATCH 1/9] Input: add generic support for sparse keymaps
Quoted 6 lines · Anisse Astier
Hi Wu,
Quoted 1 line · Wu Zhangjin
Quoted 9 lines
Quoted 4 lines
I have tried to apply this patch to the latest 2.6.32 and the linux-mips tree, both rejected.
So, which git tree should I use?
Last time I had to use Dmitry's input tree:
git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git
Just checked it, this one applies.
Thanks! Just fetched it ;)
Quoted 3 lines
Regards,
Anisse
Dmitry Torokhov
maintainerRe: [PATCH 1/9] Input: add generic support for sparse keymaps
In reply to Wu ZhangjinQuoted 5 lines · Wu Zhangjin
Quoted 3 lines · Dmitry Torokhov
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.
Quoted 7 lines
Hi, Dmitry
I have tried to apply this patch to the latest 2.6.32 and the linux-mips tree, both rejected.
So, which git tree should I use?
Mine ;)
git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
Signature · 1 line
Dmitry
Re: [PATCH 1/9] Input: add generic support for sparse keymaps
Quoted 11 lines · Dmitry Torokhov
Quoted 10 lines · Wu Zhangjin
Quoted 3 lines · Dmitry Torokhov
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.
Hi, Dmitry
I have tried to apply this patch to the latest 2.6.32 and the linux-mips tree, both rejected.
Quoted 7 lines
Quoted 2 lines
So, which git tree should I use?
Mine ;)
git.kernel.org/pub/scm/linux/kernel/git/dtor/input.git next
Thanks, I am rebasing the input driver for YeeLoong on your git tree ;)
Regards,
Wu Zhangjin
Re: [PATCH 1/9] Input: add generic support for sparse keymaps
In reply to Dmitry Torokhovdrivers/input/sparse-keymap.c line 189
Quoted 3 lines · Dmitry Torokhov
drivers/input/sparse-keymap.c new file +3
-0+ +/** +* sparse_keymap_report_event - report event corresponding to given key entry
You meant _report_entry ?
Quoted 62 lines
+ * @dev: Input device for which event should be reported
+ * @ke: key entry describing event
+ * @value: Value that should be reported (ignored by %KE_SW entries)
+ * @autorelease: Signals whether release event should be emitted for %KE_KEY
+ * entries right after reporting press event, ignored by all other
+ * entries
+ *
+ * This function is used to report input event described by given
+ * &structkey_entry.
+ */drivers/input/sparse-keymap.c new file +52
-0+void sparse_keymap_report_entry (struct input_dev *dev,const struct key_entry *ke, +unsigned int value,bool autorelease) +{ +switch (ke->type) { +case KE_KEY : +input_report_key (dev, ke->keycode, value); +input_sync (dev); +if (value && autorelease) { +input_report_key (dev, ke->keycode,0 ); +input_sync (dev); + } +break ; + +case KE_SW : + value = ke->sw.value; +/* fall through */ + +case KE_VSW : +input_report_switch (dev, ke->sw.code, value); +break ; + } +} +EXPORT_SYMBOL (sparse_keymap_report_entry); + +/** +* sparse_keymap_report_event - report event corresponding to given scancode +* @dev: Input device using sparse keymap +* @code: Scan code +* @value: Value that should be reported (ignored by %KE_SW entries) +* @autorelease: Signals whether release event should be emitted for %KE_KEY +* entries right after reporting press event, ignored by all other +* entries +* +* This function is used to perform lookup in an input device using sparse +* keymap and report corresponding event. Returns %true if lookup was +* successful and %false otherwise. +*/ +bool sparse_keymap_report_event (struct input_dev *dev,unsigned int code, +unsigned int value,bool autorelease) +{ +const struct key_entry *ke = +sparse_keymap_entry_from_scancode (dev, code); + +if (ke) { +sparse_keymap_report_entry (dev, ke, value, autorelease); +return true; + } + +return false; +} +EXPORT_SYMBOL (sparse_keymap_report_event); +
Dmitry Torokhov
maintainerRe: [PATCH 1/9] Input: add generic support for sparse keymaps
Quoted 7 lines · Anisse Astier
drivers/input/sparse-keymap.c line 189
Quoted 3 lines · Dmitry Torokhov
drivers/input/sparse-keymap.c new file +3
-0+ +/** +* sparse_keymap_report_event - report event corresponding to given key entry You meant
_report_entry?
Indeed. Can I add your "Reviewed-by:" please?
Signature · 1 line
Dmitry
Re: [PATCH 1/9] Input: add generic support for sparse keymaps
Quoted 11 lines · Dmitry Torokhov
Quoted 7 lines · Anisse Astier
drivers/input/sparse-keymap.c line 189
Quoted 3 lines · Dmitry Torokhov
drivers/input/sparse-keymap.c new file +3
-0+ +/** +* sparse_keymap_report_event - report event corresponding to given key entry You meant
_report_entry?Indeed. Can I add your "Reviewed-by:" please?
You can, but I didn't review the whole thing, just read the patch quickly and checked if it applied.
--
Anisse
Re: [PATCH 1/9] Input: add generic support for sparse keymaps
In reply to Dmitry TorokhovHi Dmitry,
Quoted 5 lines · Dmitry Torokhov
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.
Signed-off-by Dmitry Torokhov <[email protected]>
Regards,
Signature · 1 line
Anisse
Dmitry Torokhov
maintainerPATCH v2 2/9 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 | 178 +++++++++---------------------------- 2 files changed, 45 insertions(+), 134 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 +44 -134
244 lines not on this page · raw message
Dmitry Torokhov
maintainerPATCH v2 3/9 Input: dm355evm_kbd - switch to using sparse keymap library
In reply to Dmitry Torokhov---
drivers/input/misc/Kconfig | 1 drivers/input/misc/dm355evm_keys.c | 150 +++++++++++++----------------------- 2 files changed, 57 insertions(+), 94 deletions(-)
drivers/input/misc/Kconfig +1 -0
@@ -282,6 +282,7 @@ config INPUT_RB532_BUTTON config INPUT_DM355EVM tristate "TI DaVinci DM355 EVM Keypad and IR Remote" depends on MFD_DM355EVM_MSP + select INPUT_SPARSEKMAP help Supports the pushbuttons and IR remote used with the DM355 EVM board.
drivers/input/misc/dm355evm_keys.c +56 -94
233 lines not on this page · raw message
Dmitry Torokhov
maintainerPATCH v2 4/9 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 | 199 ++++++++++++--------------------------- 2 files changed, 64 insertions(+), 136 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 +63 -136
280 lines not on this page · raw message
Dmitry Torokhov
maintainerPATCH v2 5/9 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 | 159 ++++++++++++----------------------------- 2 files changed, 49 insertions(+), 111 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 +48 -111
221 lines not on this page · raw message
Dmitry Torokhov
maintainerPATCH v2 6/9 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 | 170 +++++++++++------------------------ 2 files changed, 52 insertions(+), 119 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 +51 -119
222 lines not on this page · raw message
Dmitry Torokhov
maintainerPATCH v2 7/9 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 | 198 ++++++++++++------------------------ 2 files changed, 66 insertions(+), 133 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 +65 -133
248 lines not on this page · raw message
Dmitry Torokhov
maintainerPATCH v2 8/9 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 | 162 +++++++++++---------------------- 2 files changed, 55 insertions(+), 108 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 +54 -108
208 lines not on this page · raw message
Re: [PATCH 8/9] Input: topstar-laptop - switch to using sparse keymap library
Em Sex 04 Dez 2009, às 04:12:36, Dmitry Torokhov escreveu:
Quoted 6 lines
Signed-off-by Dmitry Torokhov <[email protected]>---
drivers/platform/x86/Kconfig | 1 drivers/platform/x86/topstar-laptop.c | 162 +++++++++++---------------------- 2 files changed, 55 insertions(+), 108 deletions(-)
Hi, I saw this wasn't included in 2.6.34. From my side is ok, I was without any topstar notebook for some time, now I got a sample and tested it too, the patch is ok, It only needs a rediff now with latest 2.6.34-rc2-gitX
I thought it was going to be included without any ack etc., if needed you can add:
and tested-by or signed-off if desired.
The rediffed patch for latest 2.6.34 is below:
drivers/platform/x86/Kconfig +1 -0
@@ -455,6 +455,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 +54 -107
207 lines not on this page · raw message
Quoted 236 lines
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 +54
-109@@ -18,6 +18,7 @@#include <linux/init.h> #include <linux/acpi.h> #include <linux/input.h> +#include <linux/input/sparse-keymap.h> #define ACPI_TOPSTAR_CLASS "topstar"@@ -25,52 +26,37 @@ struct topstar_hkey {struct input_dev *inputdev; }; -struct tps_key_entry { -u8 code; -u16 keycode; -}; - -static struct tps_key_entry topstar_keymap[] = { - {0x80 ,KEY_BRIGHTNESSUP }, - {0x81 ,KEY_BRIGHTNESSDOWN }, - {0x83 ,KEY_VOLUMEUP }, - {0x84 ,KEY_VOLUMEDOWN }, - {0x85 ,KEY_MUTE }, - {0x86 ,KEY_SWITCHVIDEOMODE }, - {0x87 ,KEY_F13 },/* touchpad enable/disable key */ - {0x88 ,KEY_WLAN }, - {0x8a ,KEY_WWW }, - {0x8b ,KEY_MAIL }, - {0x8c ,KEY_MEDIA }, - {0x96 ,KEY_F14 },/* G key? */ - { } -}; - -static struct tps_key_entry *tps_get_key_by_scancode (int code) -{ -struct tps_key_entry *key; - -for (key = topstar_keymap; key->code; key++) -if (code == key->code) -return key; +static const struct key_entry topstar_keymap[] = { + {KE_KEY ,0x80 , {KEY_BRIGHTNESSUP } }, + {KE_KEY ,0x81 , {KEY_BRIGHTNESSDOWN } }, + {KE_KEY ,0x83 , {KEY_VOLUMEUP } }, + {KE_KEY ,0x84 , {KEY_VOLUMEDOWN } }, + {KE_KEY ,0x85 , {KEY_MUTE } }, + {KE_KEY ,0x86 , {KEY_SWITCHVIDEOMODE } }, + {KE_KEY ,0x87 , {KEY_F13 } },/* touchpad enable/disable key */ + {KE_KEY ,0x88 , {KEY_WLAN } }, + {KE_KEY ,0x8a , {KEY_WWW } }, + {KE_KEY ,0x8b , {KEY_MAIL } }, + {KE_KEY ,0x8c , {KEY_MEDIA } }, -return NULL ; -} - -static struct tps_key_entry *tps_get_key_by_keycode (int code) -{ -struct tps_key_entry *key; +/* Known non hotkey events don't handled or that we don't care yet */ + {KE_IGNORE ,0x8e , }, + {KE_IGNORE ,0x8f , }, + {KE_IGNORE ,0x90 , }, -for (key = topstar_keymap; key->code; key++) -if (code == key->keycode) -return key; +/* +* 'G key' generate two event codes, convert to only +* one event/key code for now, consider replacing by +* a switch (3G switch - SW_3G?) +*/ + {KE_KEY ,0x96 , {KEY_F14 } }, + {KE_KEY ,0x97 , {KEY_F14 } }, -return NULL ; -} + {KE_END ,0 } +};static void acpi_topstar_notify (struct acpi_device *device,u32 event) { -struct tps_key_entry *key;static bool dup_evnt[2 ];bool *dup;struct topstar_hkey *hkey =acpi_driver_data (device);@@ -85,27 +71,8 @@ static void acpi_topstar_notify(struct acpi_device *device, u32 event) *dup = true; } -/* -* 'G key' generate two event codes, convert to only -* one event/key code for now (3G switch?) -*/ -if (event ==0x97 ) - event =0x96 ; - - key =tps_get_key_by_scancode (event); -if (key) { -input_report_key (hkey->inputdev, key->keycode,1 ); -input_sync (hkey->inputdev); -input_report_key (hkey->inputdev, key->keycode,0 ); -input_sync (hkey->inputdev); -return ; - } - -/* Known non hotkey events don't handled or that we don't care yet */ -if (event ==0x8e || event ==0x8f || event ==0x90 ) -return ; - -pr_info ("unknown event = 0x%02x\n" , event); +if (!sparse_keymap_report_event (hkey->inputdev, event,1 , true)) +pr_info ("unknown event = 0x%02x\n" , event); }static int acpi_topstar_fncx_switch (struct acpi_device *device,bool state)@@ -126,63 +93,41 @@ static int acpi_topstar_fncx_switch(struct acpi_device *device, bool state)return 0 ; } -static int topstar_getkeycode (struct input_dev *dev,int scancode,int *keycode) -{ -struct tps_key_entry *key =tps_get_key_by_scancode (scancode); - -if (!key) -return -EINVAL ; - - *keycode = key->keycode; -return 0 ; -} - -static int topstar_setkeycode (struct input_dev *dev,int scancode,int keycode) -{ -struct tps_key_entry *key; -int old_keycode; - -if (keycode <0 || keycode >KEY_MAX ) -return -EINVAL ; - - key =tps_get_key_by_scancode (scancode); - -if (!key) -return -EINVAL ; - - old_keycode = key->keycode; - key->keycode = keycode; -set_bit (keycode, dev->keybit); -if (!tps_get_key_by_keycode (old_keycode)) -clear_bit (old_keycode, dev->keybit); -return 0 ; -} -static int acpi_topstar_init_hkey (struct topstar_hkey *hkey) { -struct tps_key_entry *key; +struct input_dev *input; +int error; - hkey->inputdev =input_allocate_device (); -if (!hkey->inputdev) { + input =input_allocate_device (); +if (!input) {pr_err ("Unable to allocate input device\n" ); -return -ENODEV ; +return -ENOMEM ; } - hkey->inputdev->name ="Topstar Laptop extra buttons" ; - hkey->inputdev->phys ="topstar/input0" ; - hkey->inputdev->id.bustype =BUS_HOST ; - hkey->inputdev->getkeycode = topstar_getkeycode; - hkey->inputdev->setkeycode = topstar_setkeycode; -for (key = topstar_keymap; key->code; key++) { -set_bit (EV_KEY , hkey->inputdev->evbit); -set_bit (key->keycode, hkey->inputdev->keybit); + + input->name ="Topstar Laptop extra buttons" ; + input->phys ="topstar/input0" ; + input->id.bustype =BUS_HOST ; + + error =sparse_keymap_setup (input, topstar_keymap,NULL ); +if (error) { +pr_err ("Unable to setup input device keymap\n" ); + goto err_free_dev; } -if (input_register_device (hkey->inputdev)) { + + error =input_register_device (input); +if (error) {pr_err ("Unable to register input device\n" ); -input_free_device (hkey->inputdev); -return -ENODEV ; + goto err_free_keymap; } + hkey->inputdev = input;return 0 ; + + err_free_keymap: +sparse_keymap_free (input); + err_free_dev: +input_free_device (input); +return error; }static int acpi_topstar_add (struct acpi_device *device)@@ -216,6 +161,7 @@ static int acpi_topstar_remove(struct acpi_device *device, int type)acpi_topstar_fncx_switch (device, false); +sparse_keymap_free (tps_hkey->inputdev);input_unregister_device (tps_hkey->inputdev);kfree (tps_hkey); --To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 6 lines
[]'s Herton -- To unsubscribe from this list: send the line "unsubscribe linux-acpi" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
Dmitry Torokhov
maintainerPATCH v2 9/9 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 | 165 +++++++++++-------------------- 2 files changed, 58 insertions(+), 108 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 +57 -108
233 lines not on this page · raw message
Re: [PATCH 9/9] Input: panasonic-laptop - switch to using sparse keymap library
Dear Dmitry.
Looks fine to me, but I'm currently travelling and don't have any hardware where I can test it on. I will put it on my todo list, but that will likely take one week.
How shall we proceed?
Signature · 4 lines
- Harald Welte <[email protected]> http://laforge.gnumonks.org/ ============================================================================ "Privacy in residential applications is a desirable marketing option." (ETSI EN 300 175-7 Ch. A6)
Dmitry Torokhov
maintainerRe: [PATCH 9/9] Input: panasonic-laptop - switch to using sparse keymap library
Hi Harald,
Quoted 6 lines · Harald Welte
Dear Dmitry.
Looks fine to me, but I'm currently travelling and don't have any hardware where I can test it on. I will put it on my todo list, but that will likely take one week.
That should be fine.
I will be merging the input parts (the library module) in the merge window but drivers can folow later (in fact, since drivers/platform is Len's domain he will decide when to push them out once the changes been reviewed and tested). Ultimately I'd prefer to have these changes appear in .33 release.
Thanks.
Signature · 1 line
Dmitry