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 15:20:52 +08:00
|
|
|
/*
|
|
|
|
* GPIO driven matrix keyboard driver
|
|
|
|
*
|
|
|
|
* Copyright (c) 2008 Marek Vasut <marek.vasut@gmail.com>
|
|
|
|
*
|
|
|
|
* Based on corgikbd.c
|
|
|
|
*
|
|
|
|
* 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/types.h>
|
|
|
|
#include <linux/delay.h>
|
|
|
|
#include <linux/platform_device.h>
|
|
|
|
#include <linux/input.h>
|
|
|
|
#include <linux/irq.h>
|
|
|
|
#include <linux/interrupt.h>
|
|
|
|
#include <linux/jiffies.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/gpio.h>
|
|
|
|
#include <linux/input/matrix_keypad.h>
|
include cleanup: Update gfp.h and slab.h includes to prepare for breaking implicit slab.h inclusion from percpu.h
percpu.h is included by sched.h and module.h and thus ends up being
included when building most .c files. percpu.h includes slab.h which
in turn includes gfp.h making everything defined by the two files
universally available and complicating inclusion dependencies.
percpu.h -> slab.h dependency is about to be removed. Prepare for
this change by updating users of gfp and slab facilities include those
headers directly instead of assuming availability. As this conversion
needs to touch large number of source files, the following script is
used as the basis of conversion.
http://userweb.kernel.org/~tj/misc/slabh-sweep.py
The script does the followings.
* Scan files for gfp and slab usages and update includes such that
only the necessary includes are there. ie. if only gfp is used,
gfp.h, if slab is used, slab.h.
* When the script inserts a new include, it looks at the include
blocks and try to put the new include such that its order conforms
to its surrounding. It's put in the include block which contains
core kernel includes, in the same order that the rest are ordered -
alphabetical, Christmas tree, rev-Xmas-tree or at the end if there
doesn't seem to be any matching order.
* If the script can't find a place to put a new include (mostly
because the file doesn't have fitting include block), it prints out
an error message indicating which .h file needs to be added to the
file.
The conversion was done in the following steps.
1. The initial automatic conversion of all .c files updated slightly
over 4000 files, deleting around 700 includes and adding ~480 gfp.h
and ~3000 slab.h inclusions. The script emitted errors for ~400
files.
2. Each error was manually checked. Some didn't need the inclusion,
some needed manual addition while adding it to implementation .h or
embedding .c file was more appropriate for others. This step added
inclusions to around 150 files.
3. The script was run again and the output was compared to the edits
from #2 to make sure no file was left behind.
4. Several build tests were done and a couple of problems were fixed.
e.g. lib/decompress_*.c used malloc/free() wrappers around slab
APIs requiring slab.h to be added manually.
5. The script was run on all .h files but without automatically
editing them as sprinkling gfp.h and slab.h inclusions around .h
files could easily lead to inclusion dependency hell. Most gfp.h
inclusion directives were ignored as stuff from gfp.h was usually
wildly available and often used in preprocessor macros. Each
slab.h inclusion directive was examined and added manually as
necessary.
6. percpu.h was updated not to include slab.h.
7. Build test were done on the following configurations and failures
were fixed. CONFIG_GCOV_KERNEL was turned off for all tests (as my
distributed build env didn't work with gcov compiles) and a few
more options had to be turned off depending on archs to make things
build (like ipr on powerpc/64 which failed due to missing writeq).
* x86 and x86_64 UP and SMP allmodconfig and a custom test config.
* powerpc and powerpc64 SMP allmodconfig
* sparc and sparc64 SMP allmodconfig
* ia64 SMP allmodconfig
* s390 SMP allmodconfig
* alpha SMP allmodconfig
* um on x86_64 SMP allmodconfig
8. percpu.h modifications were reverted so that it could be applied as
a separate patch and serve as bisection point.
Given the fact that I had only a couple of failures from tests on step
6, I'm fairly confident about the coverage of this conversion patch.
If there is a breakage, it's likely to be something in one of the arch
headers which should be easily discoverable easily on most builds of
the specific arch.
Signed-off-by: Tejun Heo <tj@kernel.org>
Guess-its-ok-by: Christoph Lameter <cl@linux-foundation.org>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Lee Schermerhorn <Lee.Schermerhorn@hp.com>
2010-03-24 16:04:11 +08:00
|
|
|
#include <linux/slab.h>
|
2012-11-21 14:49:31 +08:00
|
|
|
#include <linux/of.h>
|
|
|
|
#include <linux/of_gpio.h>
|
|
|
|
#include <linux/of_platform.h>
|
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 15:20:52 +08:00
|
|
|
|
|
|
|
struct matrix_keypad {
|
|
|
|
const struct matrix_keypad_platform_data *pdata;
|
|
|
|
struct input_dev *input_dev;
|
2009-08-05 16:24:41 +08:00
|
|
|
unsigned int row_shift;
|
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 15:20:52 +08:00
|
|
|
|
2009-12-25 14:50:23 +08:00
|
|
|
DECLARE_BITMAP(disabled_gpios, MATRIX_MAX_ROWS);
|
|
|
|
|
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 15:20:52 +08:00
|
|
|
uint32_t last_key_state[MATRIX_MAX_COLS];
|
|
|
|
struct delayed_work work;
|
2009-12-25 14:50:23 +08:00
|
|
|
spinlock_t lock;
|
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 15:20:52 +08:00
|
|
|
bool scan_pending;
|
|
|
|
bool stopped;
|
2010-06-11 03:05:23 +08:00
|
|
|
bool gpio_all_disabled;
|
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 15:20:52 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* NOTE: normally the GPIO has to be put into HiZ when de-activated to cause
|
|
|
|
* minmal side effect when scanning other columns, here it is configured to
|
|
|
|
* be input, and it should work on most platforms.
|
|
|
|
*/
|
|
|
|
static void __activate_col(const struct matrix_keypad_platform_data *pdata,
|
|
|
|
int col, bool on)
|
|
|
|
{
|
|
|
|
bool level_on = !pdata->active_low;
|
|
|
|
|
|
|
|
if (on) {
|
|
|
|
gpio_direction_output(pdata->col_gpios[col], level_on);
|
|
|
|
} else {
|
|
|
|
gpio_set_value_cansleep(pdata->col_gpios[col], !level_on);
|
|
|
|
gpio_direction_input(pdata->col_gpios[col]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void activate_col(const struct matrix_keypad_platform_data *pdata,
|
|
|
|
int col, bool on)
|
|
|
|
{
|
|
|
|
__activate_col(pdata, col, on);
|
|
|
|
|
|
|
|
if (on && pdata->col_scan_delay_us)
|
|
|
|
udelay(pdata->col_scan_delay_us);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void activate_all_cols(const struct matrix_keypad_platform_data *pdata,
|
|
|
|
bool on)
|
|
|
|
{
|
|
|
|
int col;
|
|
|
|
|
|
|
|
for (col = 0; col < pdata->num_col_gpios; col++)
|
|
|
|
__activate_col(pdata, col, on);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool row_asserted(const struct matrix_keypad_platform_data *pdata,
|
|
|
|
int row)
|
|
|
|
{
|
|
|
|
return gpio_get_value_cansleep(pdata->row_gpios[row]) ?
|
|
|
|
!pdata->active_low : pdata->active_low;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void enable_row_irqs(struct matrix_keypad *keypad)
|
|
|
|
{
|
|
|
|
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
|
|
|
|
int i;
|
|
|
|
|
2010-06-11 03:05:23 +08:00
|
|
|
if (pdata->clustered_irq > 0)
|
|
|
|
enable_irq(pdata->clustered_irq);
|
|
|
|
else {
|
|
|
|
for (i = 0; i < pdata->num_row_gpios; i++)
|
|
|
|
enable_irq(gpio_to_irq(pdata->row_gpios[i]));
|
|
|
|
}
|
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 15:20:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void disable_row_irqs(struct matrix_keypad *keypad)
|
|
|
|
{
|
|
|
|
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
|
|
|
|
int i;
|
|
|
|
|
2010-06-11 03:05:23 +08:00
|
|
|
if (pdata->clustered_irq > 0)
|
|
|
|
disable_irq_nosync(pdata->clustered_irq);
|
|
|
|
else {
|
|
|
|
for (i = 0; i < pdata->num_row_gpios; i++)
|
|
|
|
disable_irq_nosync(gpio_to_irq(pdata->row_gpios[i]));
|
|
|
|
}
|
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 15:20:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This gets the keys from keyboard and reports it to input subsystem
|
|
|
|
*/
|
|
|
|
static void matrix_keypad_scan(struct work_struct *work)
|
|
|
|
{
|
|
|
|
struct matrix_keypad *keypad =
|
|
|
|
container_of(work, struct matrix_keypad, work.work);
|
|
|
|
struct input_dev *input_dev = keypad->input_dev;
|
2012-11-21 14:49:31 +08:00
|
|
|
const unsigned short *keycodes = input_dev->keycode;
|
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 15:20:52 +08:00
|
|
|
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
|
|
|
|
uint32_t new_state[MATRIX_MAX_COLS];
|
|
|
|
int row, col, code;
|
|
|
|
|
|
|
|
/* de-activate all columns for scanning */
|
|
|
|
activate_all_cols(pdata, false);
|
|
|
|
|
|
|
|
memset(new_state, 0, sizeof(new_state));
|
|
|
|
|
|
|
|
/* assert each column and read the row status out */
|
|
|
|
for (col = 0; col < pdata->num_col_gpios; col++) {
|
|
|
|
|
|
|
|
activate_col(pdata, col, true);
|
|
|
|
|
|
|
|
for (row = 0; row < pdata->num_row_gpios; row++)
|
|
|
|
new_state[col] |=
|
|
|
|
row_asserted(pdata, row) ? (1 << row) : 0;
|
|
|
|
|
|
|
|
activate_col(pdata, col, false);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (col = 0; col < pdata->num_col_gpios; col++) {
|
|
|
|
uint32_t bits_changed;
|
|
|
|
|
|
|
|
bits_changed = keypad->last_key_state[col] ^ new_state[col];
|
|
|
|
if (bits_changed == 0)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
for (row = 0; row < pdata->num_row_gpios; row++) {
|
|
|
|
if ((bits_changed & (1 << row)) == 0)
|
|
|
|
continue;
|
|
|
|
|
2009-08-05 16:24:41 +08:00
|
|
|
code = MATRIX_SCAN_CODE(row, col, keypad->row_shift);
|
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 15:20:52 +08:00
|
|
|
input_event(input_dev, EV_MSC, MSC_SCAN, code);
|
|
|
|
input_report_key(input_dev,
|
2012-11-21 14:49:31 +08:00
|
|
|
keycodes[code],
|
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 15:20:52 +08:00
|
|
|
new_state[col] & (1 << row));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
input_sync(input_dev);
|
|
|
|
|
|
|
|
memcpy(keypad->last_key_state, new_state, sizeof(new_state));
|
|
|
|
|
|
|
|
activate_all_cols(pdata, true);
|
|
|
|
|
|
|
|
/* Enable IRQs again */
|
|
|
|
spin_lock_irq(&keypad->lock);
|
|
|
|
keypad->scan_pending = false;
|
|
|
|
enable_row_irqs(keypad);
|
|
|
|
spin_unlock_irq(&keypad->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
static irqreturn_t matrix_keypad_interrupt(int irq, void *id)
|
|
|
|
{
|
|
|
|
struct matrix_keypad *keypad = id;
|
|
|
|
unsigned long flags;
|
|
|
|
|
|
|
|
spin_lock_irqsave(&keypad->lock, flags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* See if another IRQ beaten us to it and scheduled the
|
|
|
|
* scan already. In that case we should not try to
|
|
|
|
* disable IRQs again.
|
|
|
|
*/
|
|
|
|
if (unlikely(keypad->scan_pending || keypad->stopped))
|
|
|
|
goto out;
|
|
|
|
|
|
|
|
disable_row_irqs(keypad);
|
|
|
|
keypad->scan_pending = true;
|
|
|
|
schedule_delayed_work(&keypad->work,
|
|
|
|
msecs_to_jiffies(keypad->pdata->debounce_ms));
|
|
|
|
|
|
|
|
out:
|
|
|
|
spin_unlock_irqrestore(&keypad->lock, flags);
|
|
|
|
return IRQ_HANDLED;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int matrix_keypad_start(struct input_dev *dev)
|
|
|
|
{
|
|
|
|
struct matrix_keypad *keypad = input_get_drvdata(dev);
|
|
|
|
|
|
|
|
keypad->stopped = false;
|
|
|
|
mb();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Schedule an immediate key scan to capture current key state;
|
|
|
|
* columns will be activated and IRQs be enabled after the scan.
|
|
|
|
*/
|
|
|
|
schedule_delayed_work(&keypad->work, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void matrix_keypad_stop(struct input_dev *dev)
|
|
|
|
{
|
|
|
|
struct matrix_keypad *keypad = input_get_drvdata(dev);
|
|
|
|
|
|
|
|
keypad->stopped = true;
|
|
|
|
mb();
|
|
|
|
flush_work(&keypad->work.work);
|
|
|
|
/*
|
|
|
|
* matrix_keypad_scan() will leave IRQs enabled;
|
|
|
|
* we should disable them now.
|
|
|
|
*/
|
|
|
|
disable_row_irqs(keypad);
|
|
|
|
}
|
|
|
|
|
2012-04-21 13:33:08 +08:00
|
|
|
#ifdef CONFIG_PM_SLEEP
|
2010-06-11 03:05:23 +08:00
|
|
|
static void matrix_keypad_enable_wakeup(struct matrix_keypad *keypad)
|
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 15:20:52 +08:00
|
|
|
{
|
|
|
|
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
|
2010-06-11 03:05:23 +08:00
|
|
|
unsigned int gpio;
|
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 15:20:52 +08:00
|
|
|
int i;
|
|
|
|
|
2010-06-11 03:05:23 +08:00
|
|
|
if (pdata->clustered_irq > 0) {
|
|
|
|
if (enable_irq_wake(pdata->clustered_irq) == 0)
|
|
|
|
keypad->gpio_all_disabled = true;
|
|
|
|
} else {
|
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 15:20:52 +08:00
|
|
|
|
2009-12-25 14:50:23 +08:00
|
|
|
for (i = 0; i < pdata->num_row_gpios; i++) {
|
|
|
|
if (!test_bit(i, keypad->disabled_gpios)) {
|
2010-06-11 03:05:23 +08:00
|
|
|
gpio = pdata->row_gpios[i];
|
2009-12-25 14:50:23 +08:00
|
|
|
|
|
|
|
if (enable_irq_wake(gpio_to_irq(gpio)) == 0)
|
|
|
|
__set_bit(i, keypad->disabled_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 15:20:52 +08:00
|
|
|
}
|
|
|
|
|
2010-06-11 03:05:23 +08:00
|
|
|
static void matrix_keypad_disable_wakeup(struct matrix_keypad *keypad)
|
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 15:20:52 +08:00
|
|
|
{
|
|
|
|
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
|
2010-06-11 03:05:23 +08:00
|
|
|
unsigned int gpio;
|
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 15:20:52 +08:00
|
|
|
int i;
|
|
|
|
|
2010-06-11 03:05:23 +08:00
|
|
|
if (pdata->clustered_irq > 0) {
|
|
|
|
if (keypad->gpio_all_disabled) {
|
|
|
|
disable_irq_wake(pdata->clustered_irq);
|
|
|
|
keypad->gpio_all_disabled = false;
|
|
|
|
}
|
|
|
|
} else {
|
2009-12-25 14:50:23 +08:00
|
|
|
for (i = 0; i < pdata->num_row_gpios; i++) {
|
|
|
|
if (test_and_clear_bit(i, keypad->disabled_gpios)) {
|
2010-06-11 03:05:23 +08:00
|
|
|
gpio = pdata->row_gpios[i];
|
2009-12-25 14:50:23 +08:00
|
|
|
disable_irq_wake(gpio_to_irq(gpio));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-06-11 03:05:23 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static int matrix_keypad_suspend(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct matrix_keypad *keypad = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
matrix_keypad_stop(keypad->input_dev);
|
|
|
|
|
|
|
|
if (device_may_wakeup(&pdev->dev))
|
|
|
|
matrix_keypad_enable_wakeup(keypad);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int matrix_keypad_resume(struct device *dev)
|
|
|
|
{
|
|
|
|
struct platform_device *pdev = to_platform_device(dev);
|
|
|
|
struct matrix_keypad *keypad = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
if (device_may_wakeup(&pdev->dev))
|
|
|
|
matrix_keypad_disable_wakeup(keypad);
|
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 15:20:52 +08:00
|
|
|
|
|
|
|
matrix_keypad_start(keypad->input_dev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-04-21 13:33:08 +08:00
|
|
|
static SIMPLE_DEV_PM_OPS(matrix_keypad_pm_ops,
|
|
|
|
matrix_keypad_suspend, matrix_keypad_resume);
|
|
|
|
|
2012-11-24 13:38:25 +08:00
|
|
|
static int matrix_keypad_init_gpio(struct platform_device *pdev,
|
|
|
|
struct matrix_keypad *keypad)
|
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 15:20:52 +08:00
|
|
|
{
|
|
|
|
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
|
2012-04-21 13:33:09 +08:00
|
|
|
int i, err;
|
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 15:20:52 +08:00
|
|
|
|
|
|
|
/* initialized strobe lines as outputs, activated */
|
|
|
|
for (i = 0; i < pdata->num_col_gpios; i++) {
|
|
|
|
err = gpio_request(pdata->col_gpios[i], "matrix_kbd_col");
|
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"failed to request GPIO%d for COL%d\n",
|
|
|
|
pdata->col_gpios[i], i);
|
|
|
|
goto err_free_cols;
|
|
|
|
}
|
|
|
|
|
|
|
|
gpio_direction_output(pdata->col_gpios[i], !pdata->active_low);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pdata->num_row_gpios; i++) {
|
|
|
|
err = gpio_request(pdata->row_gpios[i], "matrix_kbd_row");
|
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev,
|
|
|
|
"failed to request GPIO%d for ROW%d\n",
|
|
|
|
pdata->row_gpios[i], i);
|
|
|
|
goto err_free_rows;
|
|
|
|
}
|
|
|
|
|
|
|
|
gpio_direction_input(pdata->row_gpios[i]);
|
|
|
|
}
|
|
|
|
|
2010-06-11 03:05:23 +08:00
|
|
|
if (pdata->clustered_irq > 0) {
|
|
|
|
err = request_irq(pdata->clustered_irq,
|
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 15:20:52 +08:00
|
|
|
matrix_keypad_interrupt,
|
2010-06-11 03:05:23 +08:00
|
|
|
pdata->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 15:20:52 +08:00
|
|
|
"matrix-keypad", keypad);
|
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev,
|
2010-06-11 03:05:23 +08:00
|
|
|
"Unable to acquire clustered interrupt\n");
|
|
|
|
goto err_free_rows;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < pdata->num_row_gpios; i++) {
|
|
|
|
err = request_irq(gpio_to_irq(pdata->row_gpios[i]),
|
|
|
|
matrix_keypad_interrupt,
|
|
|
|
IRQF_TRIGGER_RISING |
|
|
|
|
IRQF_TRIGGER_FALLING,
|
|
|
|
"matrix-keypad", keypad);
|
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev,
|
2012-04-21 13:33:09 +08:00
|
|
|
"Unable to acquire interrupt for GPIO line %i\n",
|
2010-06-11 03:05:23 +08:00
|
|
|
pdata->row_gpios[i]);
|
|
|
|
goto err_free_irqs;
|
|
|
|
}
|
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 15:20:52 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* initialized as disabled - enabled by input->open */
|
|
|
|
disable_row_irqs(keypad);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err_free_irqs:
|
|
|
|
while (--i >= 0)
|
|
|
|
free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
|
|
|
|
i = pdata->num_row_gpios;
|
|
|
|
err_free_rows:
|
|
|
|
while (--i >= 0)
|
|
|
|
gpio_free(pdata->row_gpios[i]);
|
|
|
|
i = pdata->num_col_gpios;
|
|
|
|
err_free_cols:
|
|
|
|
while (--i >= 0)
|
|
|
|
gpio_free(pdata->col_gpios[i]);
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-04-21 13:33:09 +08:00
|
|
|
static void matrix_keypad_free_gpio(struct matrix_keypad *keypad)
|
|
|
|
{
|
|
|
|
const struct matrix_keypad_platform_data *pdata = keypad->pdata;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (pdata->clustered_irq > 0) {
|
|
|
|
free_irq(pdata->clustered_irq, keypad);
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < pdata->num_row_gpios; i++)
|
|
|
|
free_irq(gpio_to_irq(pdata->row_gpios[i]), keypad);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pdata->num_row_gpios; i++)
|
|
|
|
gpio_free(pdata->row_gpios[i]);
|
|
|
|
|
|
|
|
for (i = 0; i < pdata->num_col_gpios; i++)
|
|
|
|
gpio_free(pdata->col_gpios[i]);
|
|
|
|
}
|
|
|
|
|
2012-11-21 14:49:31 +08:00
|
|
|
#ifdef CONFIG_OF
|
2012-11-24 13:38:25 +08:00
|
|
|
static struct matrix_keypad_platform_data *
|
2012-11-21 14:49:31 +08:00
|
|
|
matrix_keypad_parse_dt(struct device *dev)
|
|
|
|
{
|
|
|
|
struct matrix_keypad_platform_data *pdata;
|
|
|
|
struct device_node *np = dev->of_node;
|
|
|
|
unsigned int *gpios;
|
2013-02-13 01:48:37 +08:00
|
|
|
int i, nrow, ncol;
|
2012-11-21 14:49:31 +08:00
|
|
|
|
|
|
|
if (!np) {
|
|
|
|
dev_err(dev, "device lacks DT data\n");
|
|
|
|
return ERR_PTR(-ENODEV);
|
|
|
|
}
|
|
|
|
|
|
|
|
pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
|
|
|
|
if (!pdata) {
|
|
|
|
dev_err(dev, "could not allocate memory for platform data\n");
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
}
|
|
|
|
|
2013-02-13 01:48:37 +08:00
|
|
|
pdata->num_row_gpios = nrow = of_gpio_named_count(np, "row-gpios");
|
|
|
|
pdata->num_col_gpios = ncol = of_gpio_named_count(np, "col-gpios");
|
|
|
|
if (nrow <= 0 || ncol <= 0) {
|
2012-11-21 14:49:31 +08:00
|
|
|
dev_err(dev, "number of keypad rows/columns not specified\n");
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (of_get_property(np, "linux,no-autorepeat", NULL))
|
|
|
|
pdata->no_autorepeat = true;
|
|
|
|
if (of_get_property(np, "linux,wakeup", NULL))
|
|
|
|
pdata->wakeup = true;
|
|
|
|
if (of_get_property(np, "gpio-activelow", NULL))
|
|
|
|
pdata->active_low = true;
|
|
|
|
|
|
|
|
of_property_read_u32(np, "debounce-delay-ms", &pdata->debounce_ms);
|
|
|
|
of_property_read_u32(np, "col-scan-delay-us",
|
|
|
|
&pdata->col_scan_delay_us);
|
|
|
|
|
|
|
|
gpios = devm_kzalloc(dev,
|
|
|
|
sizeof(unsigned int) *
|
|
|
|
(pdata->num_row_gpios + pdata->num_col_gpios),
|
|
|
|
GFP_KERNEL);
|
|
|
|
if (!gpios) {
|
|
|
|
dev_err(dev, "could not allocate memory for gpios\n");
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < pdata->num_row_gpios; i++)
|
|
|
|
gpios[i] = of_get_named_gpio(np, "row-gpios", i);
|
|
|
|
|
|
|
|
for (i = 0; i < pdata->num_col_gpios; i++)
|
|
|
|
gpios[pdata->num_row_gpios + i] =
|
|
|
|
of_get_named_gpio(np, "col-gpios", i);
|
|
|
|
|
|
|
|
pdata->row_gpios = gpios;
|
|
|
|
pdata->col_gpios = &gpios[pdata->num_row_gpios];
|
|
|
|
|
|
|
|
return pdata;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
static inline struct matrix_keypad_platform_data *
|
|
|
|
matrix_keypad_parse_dt(struct device *dev)
|
|
|
|
{
|
|
|
|
dev_err(dev, "no platform data defined\n");
|
|
|
|
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2012-11-24 13:38:25 +08:00
|
|
|
static int matrix_keypad_probe(struct platform_device *pdev)
|
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 15:20:52 +08:00
|
|
|
{
|
|
|
|
const struct matrix_keypad_platform_data *pdata;
|
|
|
|
struct matrix_keypad *keypad;
|
|
|
|
struct input_dev *input_dev;
|
|
|
|
int err;
|
|
|
|
|
2012-11-21 14:49:31 +08:00
|
|
|
pdata = dev_get_platdata(&pdev->dev);
|
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 15:20:52 +08:00
|
|
|
if (!pdata) {
|
2012-11-21 14:49:31 +08:00
|
|
|
pdata = matrix_keypad_parse_dt(&pdev->dev);
|
|
|
|
if (IS_ERR(pdata)) {
|
|
|
|
dev_err(&pdev->dev, "no platform data defined\n");
|
|
|
|
return PTR_ERR(pdata);
|
|
|
|
}
|
|
|
|
} else if (!pdata->keymap_data) {
|
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 15:20:52 +08:00
|
|
|
dev_err(&pdev->dev, "no keymap data defined\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2012-11-21 14:49:31 +08:00
|
|
|
keypad = kzalloc(sizeof(struct matrix_keypad), GFP_KERNEL);
|
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 15:20:52 +08:00
|
|
|
input_dev = input_allocate_device();
|
2012-04-21 13:33:08 +08:00
|
|
|
if (!keypad || !input_dev) {
|
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 15:20:52 +08:00
|
|
|
err = -ENOMEM;
|
|
|
|
goto err_free_mem;
|
|
|
|
}
|
|
|
|
|
|
|
|
keypad->input_dev = input_dev;
|
|
|
|
keypad->pdata = pdata;
|
2012-11-21 14:49:31 +08:00
|
|
|
keypad->row_shift = get_count_order(pdata->num_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 15:20:52 +08:00
|
|
|
keypad->stopped = true;
|
|
|
|
INIT_DELAYED_WORK(&keypad->work, matrix_keypad_scan);
|
|
|
|
spin_lock_init(&keypad->lock);
|
|
|
|
|
|
|
|
input_dev->name = pdev->name;
|
|
|
|
input_dev->id.bustype = BUS_HOST;
|
|
|
|
input_dev->dev.parent = &pdev->dev;
|
|
|
|
input_dev->open = matrix_keypad_start;
|
|
|
|
input_dev->close = matrix_keypad_stop;
|
|
|
|
|
2012-11-21 14:49:31 +08:00
|
|
|
err = matrix_keypad_build_keymap(pdata->keymap_data, NULL,
|
2012-05-11 13:37:08 +08:00
|
|
|
pdata->num_row_gpios,
|
|
|
|
pdata->num_col_gpios,
|
2012-11-21 14:49:31 +08:00
|
|
|
NULL, input_dev);
|
|
|
|
if (err) {
|
|
|
|
dev_err(&pdev->dev, "failed to build keymap\n");
|
2012-05-11 13:37:08 +08:00
|
|
|
goto err_free_mem;
|
2012-11-21 14:49:31 +08:00
|
|
|
}
|
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 15:20:52 +08:00
|
|
|
|
2012-05-11 13:37:08 +08:00
|
|
|
if (!pdata->no_autorepeat)
|
|
|
|
__set_bit(EV_REP, input_dev->evbit);
|
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 15:20:52 +08:00
|
|
|
input_set_capability(input_dev, EV_MSC, MSC_SCAN);
|
|
|
|
input_set_drvdata(input_dev, keypad);
|
|
|
|
|
2012-04-21 13:33:09 +08:00
|
|
|
err = matrix_keypad_init_gpio(pdev, keypad);
|
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 15:20:52 +08:00
|
|
|
if (err)
|
|
|
|
goto err_free_mem;
|
|
|
|
|
|
|
|
err = input_register_device(keypad->input_dev);
|
|
|
|
if (err)
|
2012-04-21 13:33:09 +08:00
|
|
|
goto err_free_gpio;
|
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 15:20:52 +08:00
|
|
|
|
|
|
|
device_init_wakeup(&pdev->dev, pdata->wakeup);
|
|
|
|
platform_set_drvdata(pdev, keypad);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2012-04-21 13:33:09 +08:00
|
|
|
err_free_gpio:
|
|
|
|
matrix_keypad_free_gpio(keypad);
|
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 15:20:52 +08:00
|
|
|
err_free_mem:
|
|
|
|
input_free_device(input_dev);
|
|
|
|
kfree(keypad);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2012-11-24 13:50:47 +08:00
|
|
|
static int matrix_keypad_remove(struct platform_device *pdev)
|
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 15:20:52 +08:00
|
|
|
{
|
|
|
|
struct matrix_keypad *keypad = platform_get_drvdata(pdev);
|
|
|
|
|
|
|
|
device_init_wakeup(&pdev->dev, 0);
|
|
|
|
|
2012-04-21 13:33:09 +08:00
|
|
|
matrix_keypad_free_gpio(keypad);
|
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 15:20:52 +08:00
|
|
|
input_unregister_device(keypad->input_dev);
|
|
|
|
kfree(keypad);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-11-21 14:49:31 +08:00
|
|
|
#ifdef CONFIG_OF
|
|
|
|
static const struct of_device_id matrix_keypad_dt_match[] = {
|
|
|
|
{ .compatible = "gpio-matrix-keypad" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
MODULE_DEVICE_TABLE(of, matrix_keypad_dt_match);
|
|
|
|
#endif
|
|
|
|
|
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 15:20:52 +08:00
|
|
|
static struct platform_driver matrix_keypad_driver = {
|
|
|
|
.probe = matrix_keypad_probe,
|
2012-11-24 13:27:39 +08:00
|
|
|
.remove = matrix_keypad_remove,
|
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 15:20:52 +08:00
|
|
|
.driver = {
|
|
|
|
.name = "matrix-keypad",
|
|
|
|
.owner = THIS_MODULE,
|
2009-12-04 14:24:15 +08:00
|
|
|
.pm = &matrix_keypad_pm_ops,
|
2012-11-21 14:49:31 +08:00
|
|
|
.of_match_table = of_match_ptr(matrix_keypad_dt_match),
|
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 15:20:52 +08:00
|
|
|
},
|
|
|
|
};
|
2011-11-30 03:08:39 +08:00
|
|
|
module_platform_driver(matrix_keypad_driver);
|
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 15:20:52 +08:00
|
|
|
|
|
|
|
MODULE_AUTHOR("Marek Vasut <marek.vasut@gmail.com>");
|
|
|
|
MODULE_DESCRIPTION("GPIO Driven Matrix Keypad Driver");
|
|
|
|
MODULE_LICENSE("GPL v2");
|
|
|
|
MODULE_ALIAS("platform:matrix-keypad");
|