Commit 905dbf1d authored by Tony Lindgren's avatar Tony Lindgren Committed by Dmitry Torokhov

Input: omap4-keypad - scan keys in two phases and simplify with bitmask

Because of errata i689 the keyboard can idle with state where no key
up interrupts are seen until after the next key press.

This means we need to first check for any lost key up events before
scanning for new down events.

For example, rapidly pressing shift-shift-j can sometimes produce a J
instead of j. Let's fix the issue by scanning the keyboard in two
phases. First we scan for any key up events that we may have missed,
and then we scan for key down events.

Let's also simplify things with for_each_set_bit() as suggested by
Dmitry Torokhov <dmitry.torokhov@gmail.com>.
Signed-off-by: default avatarTony Lindgren <tony@atomide.com>
Link: https://lore.kernel.org/r/20210110190529.46135-3-tony@atomide.comSigned-off-by: default avatarDmitry Torokhov <dmitry.torokhov@gmail.com>
parent 7e0541b2
...@@ -78,7 +78,7 @@ struct omap4_keypad { ...@@ -78,7 +78,7 @@ struct omap4_keypad {
u32 irqreg_offset; u32 irqreg_offset;
unsigned int row_shift; unsigned int row_shift;
bool no_autorepeat; bool no_autorepeat;
unsigned char key_state[8]; u64 keys;
unsigned short *keymap; unsigned short *keymap;
}; };
...@@ -107,6 +107,33 @@ static void kbd_write_irqreg(struct omap4_keypad *keypad_data, ...@@ -107,6 +107,33 @@ static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
keypad_data->base + keypad_data->irqreg_offset + offset); keypad_data->base + keypad_data->irqreg_offset + offset);
} }
static int omap4_keypad_report_keys(struct omap4_keypad *keypad_data,
u64 keys, bool down)
{
struct input_dev *input_dev = keypad_data->input;
unsigned int col, row, code;
DECLARE_BITMAP(mask, 64);
unsigned long bit;
int events = 0;
bitmap_from_u64(mask, keys);
for_each_set_bit(bit, mask, keypad_data->rows * BITS_PER_BYTE) {
row = bit / BITS_PER_BYTE;
col = bit % BITS_PER_BYTE;
code = MATRIX_SCAN_CODE(row, col, keypad_data->row_shift);
input_event(input_dev, EV_MSC, MSC_SCAN, code);
input_report_key(input_dev, keypad_data->keymap[code], down);
events++;
}
if (events)
input_sync(input_dev);
return events;
}
/* Interrupt handlers */ /* Interrupt handlers */
static irqreturn_t omap4_keypad_irq_handler(int irq, void *dev_id) static irqreturn_t omap4_keypad_irq_handler(int irq, void *dev_id)
...@@ -122,35 +149,25 @@ static irqreturn_t omap4_keypad_irq_handler(int irq, void *dev_id) ...@@ -122,35 +149,25 @@ static irqreturn_t omap4_keypad_irq_handler(int irq, void *dev_id)
static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id) static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id)
{ {
struct omap4_keypad *keypad_data = dev_id; struct omap4_keypad *keypad_data = dev_id;
struct input_dev *input_dev = keypad_data->input; u32 low, high;
unsigned char key_state[ARRAY_SIZE(keypad_data->key_state)]; u64 keys, changed;
unsigned int col, row, code, changed;
u32 *new_state = (u32 *) key_state; low = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
high = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
*new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0); keys = low | (u64)high << 32;
*(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
changed = keys ^ keypad_data->keys;
for (row = 0; row < keypad_data->rows; row++) {
changed = key_state[row] ^ keypad_data->key_state[row]; /*
if (!changed) * Report key up events separately and first. This matters in case we
continue; * lost key-up interrupt and just now catching up.
*/
for (col = 0; col < keypad_data->cols; col++) { omap4_keypad_report_keys(keypad_data, changed & ~keys, false);
if (changed & (1 << col)) {
code = MATRIX_SCAN_CODE(row, col,
keypad_data->row_shift);
input_event(input_dev, EV_MSC, MSC_SCAN, code);
input_report_key(input_dev,
keypad_data->keymap[code],
key_state[row] & (1 << col));
}
}
}
input_sync(input_dev); /* Report key down events */
omap4_keypad_report_keys(keypad_data, changed & keys, true);
memcpy(keypad_data->key_state, key_state, keypad_data->keys = keys;
sizeof(keypad_data->key_state));
/* clear pending interrupts */ /* clear pending interrupts */
kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS, kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment