Commit bab7614d authored by Eric Miao's avatar Eric Miao Committed by Dmitry Torokhov

Input: add support for generic GPIO-based matrix keypad

Original patch by Marek Vasut, modified by Eric in:

1. use delayed work to simplify the debouncing
2. combine col_polarity/row_polarity into a single active_low field
3. use a generic bit array based XOR algorithm to detect key
   press/release, which should make the column assertion time
   shorter and code a bit cleaner
4. remove the ALT_FN handling, which is no way generic, the ALT_FN
   key should be treated as no different from other keys, and
   translation will be done by user space by commands like 'loadkeys'.
5. explicitly disable row IRQs and flush potential pending work,
   and schedule an immediate scan after resuming as suggested
   by Uli Luckas
6. incorporate review comments from many others

Patch tested on Littleton/PXA310 (though PXA310 has a dedicate keypad
controller, I have to configure those pins as generic GPIO to use this
driver, works quite well, though), and Sharp Zaurus model SL-C7x0
and SL-C1000.

[dtor@mail.ru: fix error unwinding path, support changing keymap
 from userspace]
Signed-off-by: default avatarMarek Vasut <marek.vasut@gmail.com>
Reviewed-by: default avatarTrilok Soni <soni.trilok@gmail.com>
Reviewed-by: default avatarUli Luckas <u.luckas@road.de>
Reviewed-by: default avatarRussell King <linux@arm.linux.org.uk>
Reviewed-by: default avatarRobert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: default avatarEric Miao <eric.miao@marvell.com>
Signed-off-by: default avatarDmitry Torokhov <dtor@mail.ru>
parent cb589529
...@@ -158,7 +158,16 @@ config KEYBOARD_GPIO ...@@ -158,7 +158,16 @@ config KEYBOARD_GPIO
with configuration data saying which GPIOs are used. with configuration data saying which GPIOs are used.
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called gpio-keys. module will be called gpio_keys.
config KEYBOARD_MATRIX
tristate "GPIO driven matrix keypad support"
depends on GENERIC_GPIO
help
Enable support for GPIO driven matrix keypad.
To compile this driver as a module, choose M here: the
module will be called matrix_keypad.
config KEYBOARD_HIL_OLD config KEYBOARD_HIL_OLD
tristate "HP HIL keyboard support (simple driver)" tristate "HP HIL keyboard support (simple driver)"
...@@ -254,7 +263,7 @@ config KEYBOARD_PXA27x ...@@ -254,7 +263,7 @@ config KEYBOARD_PXA27x
tristate "PXA27x/PXA3xx keypad support" tristate "PXA27x/PXA3xx keypad support"
depends on PXA27x || PXA3xx depends on PXA27x || PXA3xx
help help
Enable support for PXA27x/PXA3xx keypad controller Enable support for PXA27x/PXA3xx keypad controller.
To compile this driver as a module, choose M here: the To compile this driver as a module, choose M here: the
module will be called pxa27x_keypad. module will be called pxa27x_keypad.
......
...@@ -20,6 +20,7 @@ obj-$(CONFIG_KEYBOARD_LKKBD) += lkkbd.o ...@@ -20,6 +20,7 @@ obj-$(CONFIG_KEYBOARD_LKKBD) += lkkbd.o
obj-$(CONFIG_KEYBOARD_LM8323) += lm8323.o obj-$(CONFIG_KEYBOARD_LM8323) += lm8323.o
obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o
obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o
obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o
obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o obj-$(CONFIG_KEYBOARD_NEWTON) += newtonkbd.o
obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o obj-$(CONFIG_KEYBOARD_OMAP) += omap-keypad.o
obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o obj-$(CONFIG_KEYBOARD_PXA27x) += pxa27x_keypad.o
......
This diff is collapsed.
#ifndef _MATRIX_KEYPAD_H
#define _MATRIX_KEYPAD_H
#include <linux/types.h>
#include <linux/input.h>
#define MATRIX_MAX_ROWS 16
#define MATRIX_MAX_COLS 16
#define KEY(row, col, val) ((((row) & (MATRIX_MAX_ROWS - 1)) << 24) |\
(((col) & (MATRIX_MAX_COLS - 1)) << 16) |\
(val & 0xffff))
#define KEY_ROW(k) (((k) >> 24) & 0xff)
#define KEY_COL(k) (((k) >> 16) & 0xff)
#define KEY_VAL(k) ((k) & 0xffff)
/**
* struct matrix_keymap_data - keymap for matrix keyboards
* @keymap: pointer to array of uint32 values encoded with KEY() macro
* representing keymap
* @keymap_size: number of entries (initialized) in this keymap
* @max_keymap_size: maximum size of keymap supported by the device
*
* This structure is supposed to be used by platform code to supply
* keymaps to drivers that implement matrix-like keypads/keyboards.
*/
struct matrix_keymap_data {
const uint32_t *keymap;
unsigned int keymap_size;
unsigned int max_keymap_size;
};
/**
* struct matrix_keypad_platform_data - platform-dependent keypad data
* @keymap_data: pointer to &matrix_keymap_data
* @row_gpios: array of gpio numbers reporesenting rows
* @col_gpios: array of gpio numbers reporesenting colums
* @num_row_gpios: actual number of row gpios used by device
* @num_col_gpios: actual number of col gpios used by device
* @col_scan_delay_us: delay, measured in microseconds, that is
* needed before we can keypad after activating column gpio
* @debounce_ms: debounce interval in milliseconds
*
* This structure represents platform-specific data that use used by
* matrix_keypad driver to perform proper initialization.
*/
struct matrix_keypad_platform_data {
const struct matrix_keymap_data *keymap_data;
unsigned int row_gpios[MATRIX_MAX_ROWS];
unsigned int col_gpios[MATRIX_MAX_COLS];
unsigned int num_row_gpios;
unsigned int num_col_gpios;
unsigned int col_scan_delay_us;
/* key debounce interval in milli-second */
unsigned int debounce_ms;
bool active_low;
bool wakeup;
};
#endif /* _MATRIX_KEYPAD_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment