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: Marek Vasut <marek.vasut@gmail.com>
Reviewed-by: Trilok Soni <soni.trilok@gmail.com>
Reviewed-by: Uli Luckas <u.luckas@road.de>
Reviewed-by: Russell King <linux@arm.linux.org.uk>
Reviewed-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2009-06-29 14:20:52 +07:00
|
|
|
#ifndef _MATRIX_KEYPAD_H
|
|
|
|
#define _MATRIX_KEYPAD_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
|
2011-02-11 15:44:41 +07:00
|
|
|
#define MATRIX_MAX_ROWS 32
|
|
|
|
#define MATRIX_MAX_COLS 32
|
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: Marek Vasut <marek.vasut@gmail.com>
Reviewed-by: Trilok Soni <soni.trilok@gmail.com>
Reviewed-by: Uli Luckas <u.luckas@road.de>
Reviewed-by: Russell King <linux@arm.linux.org.uk>
Reviewed-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2009-06-29 14:20:52 +07:00
|
|
|
|
|
|
|
#define KEY(row, col, val) ((((row) & (MATRIX_MAX_ROWS - 1)) << 24) |\
|
|
|
|
(((col) & (MATRIX_MAX_COLS - 1)) << 16) |\
|
2010-12-21 04:09:22 +07:00
|
|
|
((val) & 0xffff))
|
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: Marek Vasut <marek.vasut@gmail.com>
Reviewed-by: Trilok Soni <soni.trilok@gmail.com>
Reviewed-by: Uli Luckas <u.luckas@road.de>
Reviewed-by: Russell King <linux@arm.linux.org.uk>
Reviewed-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2009-06-29 14:20:52 +07:00
|
|
|
|
|
|
|
#define KEY_ROW(k) (((k) >> 24) & 0xff)
|
|
|
|
#define KEY_COL(k) (((k) >> 16) & 0xff)
|
|
|
|
#define KEY_VAL(k) ((k) & 0xffff)
|
|
|
|
|
2009-08-05 15:24:41 +07:00
|
|
|
#define MATRIX_SCAN_CODE(row, col, row_shift) (((row) << (row_shift)) + (col))
|
|
|
|
|
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: Marek Vasut <marek.vasut@gmail.com>
Reviewed-by: Trilok Soni <soni.trilok@gmail.com>
Reviewed-by: Uli Luckas <u.luckas@road.de>
Reviewed-by: Russell King <linux@arm.linux.org.uk>
Reviewed-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2009-06-29 14:20:52 +07:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* struct matrix_keypad_platform_data - platform-dependent keypad data
|
|
|
|
* @keymap_data: pointer to &matrix_keymap_data
|
2009-08-05 15:24:41 +07:00
|
|
|
* @row_gpios: pointer to array of gpio numbers representing rows
|
|
|
|
* @col_gpios: pointer to array of gpio numbers reporesenting colums
|
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: Marek Vasut <marek.vasut@gmail.com>
Reviewed-by: Trilok Soni <soni.trilok@gmail.com>
Reviewed-by: Uli Luckas <u.luckas@road.de>
Reviewed-by: Russell King <linux@arm.linux.org.uk>
Reviewed-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2009-06-29 14:20:52 +07:00
|
|
|
* @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
|
2010-06-11 02:05:23 +07:00
|
|
|
* @clustered_irq: may be specified if interrupts of all row/column GPIOs
|
|
|
|
* are bundled to one single irq
|
|
|
|
* @clustered_irq_flags: flags that are needed for the clustered irq
|
2009-11-17 13:12:20 +07:00
|
|
|
* @active_low: gpio polarity
|
|
|
|
* @wakeup: controls whether the device should be set up as wakeup
|
|
|
|
* source
|
2010-04-06 12:29:09 +07:00
|
|
|
* @no_autorepeat: disable key autorepeat
|
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: Marek Vasut <marek.vasut@gmail.com>
Reviewed-by: Trilok Soni <soni.trilok@gmail.com>
Reviewed-by: Uli Luckas <u.luckas@road.de>
Reviewed-by: Russell King <linux@arm.linux.org.uk>
Reviewed-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2009-06-29 14:20:52 +07:00
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2009-08-05 15:24:41 +07:00
|
|
|
const unsigned int *row_gpios;
|
|
|
|
const unsigned int *col_gpios;
|
|
|
|
|
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: Marek Vasut <marek.vasut@gmail.com>
Reviewed-by: Trilok Soni <soni.trilok@gmail.com>
Reviewed-by: Uli Luckas <u.luckas@road.de>
Reviewed-by: Russell King <linux@arm.linux.org.uk>
Reviewed-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2009-06-29 14:20:52 +07:00
|
|
|
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;
|
|
|
|
|
2010-06-11 02:05:23 +07:00
|
|
|
unsigned int clustered_irq;
|
|
|
|
unsigned int clustered_irq_flags;
|
|
|
|
|
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: Marek Vasut <marek.vasut@gmail.com>
Reviewed-by: Trilok Soni <soni.trilok@gmail.com>
Reviewed-by: Uli Luckas <u.luckas@road.de>
Reviewed-by: Russell King <linux@arm.linux.org.uk>
Reviewed-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2009-06-29 14:20:52 +07:00
|
|
|
bool active_low;
|
|
|
|
bool wakeup;
|
2010-04-06 12:29:09 +07:00
|
|
|
bool no_autorepeat;
|
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: Marek Vasut <marek.vasut@gmail.com>
Reviewed-by: Trilok Soni <soni.trilok@gmail.com>
Reviewed-by: Uli Luckas <u.luckas@road.de>
Reviewed-by: Russell King <linux@arm.linux.org.uk>
Reviewed-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2009-06-29 14:20:52 +07:00
|
|
|
};
|
|
|
|
|
2009-08-26 09:24:13 +07:00
|
|
|
/**
|
|
|
|
* matrix_keypad_build_keymap - convert platform keymap into matrix keymap
|
|
|
|
* @keymap_data: keymap supplied by the platform code
|
|
|
|
* @row_shift: number of bits to shift row value by to advance to the next
|
|
|
|
* line in the keymap
|
|
|
|
* @keymap: expanded version of keymap that is suitable for use by
|
|
|
|
* matrix keyboad driver
|
|
|
|
* @keybit: pointer to bitmap of keys supported by input device
|
|
|
|
*
|
|
|
|
* This function converts platform keymap (encoded with KEY() macro) into
|
|
|
|
* an array of keycodes that is suitable for using in a standard matrix
|
|
|
|
* keyboard driver that uses row and col as indices.
|
|
|
|
*/
|
|
|
|
static inline void
|
|
|
|
matrix_keypad_build_keymap(const struct matrix_keymap_data *keymap_data,
|
|
|
|
unsigned int row_shift,
|
|
|
|
unsigned short *keymap, unsigned long *keybit)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < keymap_data->keymap_size; i++) {
|
|
|
|
unsigned int key = keymap_data->keymap[i];
|
|
|
|
unsigned int row = KEY_ROW(key);
|
|
|
|
unsigned int col = KEY_COL(key);
|
|
|
|
unsigned short code = KEY_VAL(key);
|
|
|
|
|
|
|
|
keymap[MATRIX_SCAN_CODE(row, col, row_shift)] = code;
|
|
|
|
__set_bit(code, keybit);
|
|
|
|
}
|
|
|
|
__clear_bit(KEY_RESERVED, keybit);
|
|
|
|
}
|
|
|
|
|
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: Marek Vasut <marek.vasut@gmail.com>
Reviewed-by: Trilok Soni <soni.trilok@gmail.com>
Reviewed-by: Uli Luckas <u.luckas@road.de>
Reviewed-by: Russell King <linux@arm.linux.org.uk>
Reviewed-by: Robert Jarzmik <robert.jarzmik@free.fr>
Signed-off-by: Eric Miao <eric.miao@marvell.com>
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
2009-06-29 14:20:52 +07:00
|
|
|
#endif /* _MATRIX_KEYPAD_H */
|