diff mbox series

[2/2] Input: omap4-keypad - check state again for lost key-up interrupts

Message ID 20200227020407.17276-2-tony@atomide.com (mailing list archive)
State New, archived
Headers show
Series [1/2] Input: omap4-keypad - Configure interrupt as level | expand

Commit Message

Tony Lindgren Feb. 27, 2020, 2:04 a.m. UTC
We only have partial errata i689 implemented with Commit 6c3516fed7b6
("Input: omap-keypad - fix keyboard debounce configuration"). We are
still missing the check for lost key-up interrupts as described in the
omap4 silicon errata documentation as Errata ID i689 "1.32 Keyboard Key
Up Event Can Be Missed":

"When a key is released for a time shorter than the debounce time,
 in-between 2 key press (KP1 and KP2), the keyboard state machine will go
 to idle mode and will never detect the key release (after KP1, and also
 after KP2), and thus will never generate a new IRQ indicating the key
 release."

Let's just check the keyboard state one more time after no more key
press events.

Cc: Arthur Demchenkov <spinal.by@gmail.com>
Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---

Can you guys test if you're still seeing stuck keys here and there
with this patch applied? Seems to behave for me based on very brief
testing so not sure if I got it right..

---
 drivers/input/keyboard/omap4-keypad.c | 37 ++++++++++++++++++++++++---
 1 file changed, 33 insertions(+), 4 deletions(-)

Comments

Tony Lindgren Feb. 27, 2020, 4:08 p.m. UTC | #1
* Tony Lindgren <tony@atomide.com> [200227 02:05]:
> +		/* Check once after debounce time when no more keys down */
> +		if (!new_keys_pressed) {
> +			usleep_range(OMAP4_DEBOUNCE_MS * 1000 * 2,
> +				     OMAP4_DEBOUNCE_MS * 1000 * 3);
> +			new_keys_pressed = omap4_keypad_scan_keys(keypad_data);
> +		}

So this can be outside the loop. And we actually need to clear
the state looks like.

I'll send out v2 series of these after some more debugging.

Regards,

Tony
diff mbox series

Patch

diff --git a/drivers/input/keyboard/omap4-keypad.c b/drivers/input/keyboard/omap4-keypad.c
--- a/drivers/input/keyboard/omap4-keypad.c
+++ b/drivers/input/keyboard/omap4-keypad.c
@@ -11,6 +11,7 @@ 
 #include <linux/module.h>
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
+#include <linux/delay.h>
 #include <linux/errno.h>
 #include <linux/io.h>
 #include <linux/of.h>
@@ -57,8 +58,10 @@ 
 #define OMAP4_KEYPAD_PTV_DIV_128        0x6
 #define OMAP4_KEYPAD_DEBOUNCINGTIME_MS(dbms, ptv)     \
 	((((dbms) * 1000) / ((1 << ((ptv) + 1)) * (1000000 / 32768))) - 1)
+#define OMAP4_DEBOUNCE_MS		16	/* In milliseconds */
 #define OMAP4_VAL_DEBOUNCINGTIME_16MS					\
-	OMAP4_KEYPAD_DEBOUNCINGTIME_MS(16, OMAP4_KEYPAD_PTV_DIV_128)
+	OMAP4_KEYPAD_DEBOUNCINGTIME_MS(OMAP4_DEBOUNCE_MS, \
+				       OMAP4_KEYPAD_PTV_DIV_128)
 
 enum {
 	KBD_REVISION_OMAP4 = 0,
@@ -119,13 +122,13 @@  static irqreturn_t omap4_keypad_irq_handler(int irq, void *dev_id)
 	return IRQ_NONE;
 }
 
-static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id)
+static int omap4_keypad_scan_keys(struct omap4_keypad *keypad_data)
 {
-	struct omap4_keypad *keypad_data = dev_id;
 	struct input_dev *input_dev = keypad_data->input;
 	unsigned char key_state[ARRAY_SIZE(keypad_data->key_state)];
 	unsigned int col, row, code, changed;
 	u32 *new_state = (u32 *) key_state;
+	int key_down, keys_pressed = 0;
 
 	*new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
 	*(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
@@ -140,9 +143,12 @@  static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id)
 				code = MATRIX_SCAN_CODE(row, col,
 						keypad_data->row_shift);
 				input_event(input_dev, EV_MSC, MSC_SCAN, code);
+				key_down = key_state[row] & (1 << col);
 				input_report_key(input_dev,
 						 keypad_data->keymap[code],
-						 key_state[row] & (1 << col));
+						 key_down);
+				if (key_down)
+					keys_pressed++;
 			}
 		}
 	}
@@ -152,6 +158,29 @@  static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id)
 	memcpy(keypad_data->key_state, key_state,
 		sizeof(keypad_data->key_state));
 
+	return keys_pressed;
+}
+
+static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id)
+{
+	struct omap4_keypad *keypad_data = dev_id;
+	int new_keys_pressed;
+
+	/*
+	 * Errata ID i689 "1.32 Keyboard Key Up Event Can Be Missed"
+	 * check keyboard state again for lost key-up interrupts.
+	 */
+	do {
+		new_keys_pressed = omap4_keypad_scan_keys(keypad_data);
+
+		/* Check once after debounce time when no more keys down */
+		if (!new_keys_pressed) {
+			usleep_range(OMAP4_DEBOUNCE_MS * 1000 * 2,
+				     OMAP4_DEBOUNCE_MS * 1000 * 3);
+			new_keys_pressed = omap4_keypad_scan_keys(keypad_data);
+		}
+	} while (new_keys_pressed);
+
 	/* clear pending interrupts */
 	kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
 			 kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));