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>, ruleh <ruleh@gmx.de>
Subject: [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts
Date: Fri, 28 Feb 2020 09:12:23 -0800	[thread overview]
Message-ID: <20200228171223.11444-4-tony@atomide.com> (raw)
In-Reply-To: <20200228171223.11444-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 check the keyboard state with delayed_work after each event. And
if the problem state is detect, let's clear all 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>
---
 drivers/input/keyboard/omap4-keypad.c | 56 ++++++++++++++++++++++++---
 1 file changed, 50 insertions(+), 6 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
@@ -71,6 +71,8 @@ struct omap4_keypad {
 	void __iomem *base;
 	bool irq_wake_enabled;
 	unsigned int irq;
+	struct delayed_work key_work;
+	struct mutex lock;		/* for key scan */
 
 	unsigned int rows;
 	unsigned int cols;
@@ -119,16 +121,22 @@ 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 bool omap4_keypad_scan_keys(struct omap4_keypad *keypad_data, bool clear)
 {
-	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;
-
-	*new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
-	*(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
+	u32 *rows_lo = (u32 *)key_state;
+	u32 *rows_hi = rows_lo + 1;
+
+	mutex_lock(&keypad_data->lock);
+	if (clear) {
+		*rows_lo = 0;
+		*rows_hi = 0;
+	} else {
+		*rows_lo = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
+		*rows_hi = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
+	}
 
 	for (row = 0; row < keypad_data->rows; row++) {
 		changed = key_state[row] ^ keypad_data->key_state[row];
@@ -151,6 +159,20 @@ 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));
+	mutex_unlock(&keypad_data->lock);
+
+	return *rows_lo || *rows_hi;
+}
+
+static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id)
+{
+	struct omap4_keypad *keypad_data = dev_id;
+	bool events;
+
+	events = omap4_keypad_scan_keys(keypad_data, false);
+	if (events)
+		schedule_delayed_work(&keypad_data->key_work,
+				      msecs_to_jiffies(50));
 
 	/* clear pending interrupts */
 	kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
@@ -159,6 +181,25 @@ static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id)
 	return IRQ_HANDLED;
 }
 
+/*
+ * Errata ID i689 "1.32 Keyboard Key Up Event Can Be Missed".
+ * Interrupt may not happen for key-up events.
+ */
+static void omap4_keypad_work(struct work_struct *work)
+{
+	struct omap4_keypad *keypad_data =
+		container_of(work, struct omap4_keypad, key_work.work);
+	bool events;
+	u32 active;
+
+	active = kbd_readl(keypad_data, OMAP4_KBD_STATEMACHINE);
+	if (active)
+		return;
+
+	dev_dbg(keypad_data->input->dev.parent, "idle with events\n");
+	events = omap4_keypad_scan_keys(keypad_data, true);
+}
+
 static int omap4_keypad_open(struct input_dev *input)
 {
 	struct omap4_keypad *keypad_data = input_get_drvdata(input);
@@ -251,6 +292,8 @@ static int omap4_keypad_probe(struct platform_device *pdev)
 	}
 
 	keypad_data->irq = irq;
+	mutex_init(&keypad_data->lock);
+	INIT_DELAYED_WORK(&keypad_data->key_work, omap4_keypad_work);
 
 	error = omap4_keypad_parse_dt(&pdev->dev, keypad_data);
 	if (error)
@@ -387,6 +430,7 @@ static int omap4_keypad_remove(struct platform_device *pdev)
 	struct resource *res;
 
 	free_irq(keypad_data->irq, keypad_data);
+	cancel_delayed_work_sync(&keypad_data->key_work);
 
 	pm_runtime_disable(&pdev->dev);
 
-- 
2.25.1

  parent reply	other threads:[~2020-02-28 17:12 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-02-28 17:12 [PATCHv2 0/3] Lost key-up interrupt handling for omap4-keypad Tony Lindgren
2020-02-28 17:12 ` [PATCH 1/3] Input: omap4-keypad - configure interrupt as level Tony Lindgren
2020-02-28 17:12 ` [PATCH 2/3] Input: omap4-keypad - disable unused long interrupts Tony Lindgren
2020-02-28 17:12 ` Tony Lindgren [this message]
2020-03-06 19:10   ` [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts Dmitry Torokhov
2020-03-06 19:23     ` Tony Lindgren
2020-02-28 18:02 ` [PATCHv2 4/3] Input: omap4-keypad - scan the keys in two phases to detect lost key-up Tony Lindgren
2020-03-06 19:04   ` Dmitry Torokhov
2020-03-06 19:09     ` Tony Lindgren
2020-02-28 18:04 ` [PATCHv2 0/3] Lost key-up interrupt handling for omap4-keypad Tony Lindgren
2020-03-18 22:57 [PATCHv3 " Tony Lindgren
2020-03-18 22:57 ` [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts 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=20200228171223.11444-4-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=ruleh@gmx.de \
    --cc=spinal.by@gmail.com \
    --cc=sre@kernel.org \
    --subject='Re: [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts' \
    /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

This is a public inbox, see mirroring instructions
on how to clone and mirror all data and code used for this inbox