linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tony Lindgren <tony@atomide.com>
To: Dmitry Torokhov <dmitry.torokhov@gmail.com>
Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-omap@vger.kernel.org,
	Arthur Demchenkov <spinal.by@gmail.com>,
	Merlijn Wajer <merlijn@wizzup.org>, Pavel Machek <pavel@ucw.cz>,
	Sebastian Reichel <sre@kernel.org>
Subject: [PATCH 2/2] Input: omap4-keypad - check state again for lost key-up interrupts
Date: Wed, 26 Feb 2020 18:04:07 -0800	[thread overview]
Message-ID: <20200227020407.17276-2-tony@atomide.com> (raw)
In-Reply-To: <20200227020407.17276-1-tony@atomide.com>

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(-)

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));
-- 
2.25.1

  reply	other threads:[~2020-02-27  2:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-27  2:04 [PATCH 1/2] Input: omap4-keypad - Configure interrupt as level Tony Lindgren
2020-02-27  2:04 ` Tony Lindgren [this message]
2020-02-27 16:08   ` [PATCH 2/2] Input: omap4-keypad - check state again for lost key-up interrupts Tony Lindgren
2020-03-06 18:58 ` [PATCH 1/2] Input: omap4-keypad - Configure interrupt as level Dmitry Torokhov
2020-03-06 19:04   ` Tony Lindgren

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200227020407.17276-2-tony@atomide.com \
    --to=tony@atomide.com \
    --cc=dmitry.torokhov@gmail.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-omap@vger.kernel.org \
    --cc=merlijn@wizzup.org \
    --cc=pavel@ucw.cz \
    --cc=spinal.by@gmail.com \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).