linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCHv3 0/3] Lost key-up interrupt handling for omap4-keypad
@ 2020-03-18 22:57 Tony Lindgren
  2020-03-18 22:57 ` [PATCH 1/3] Input: omap4-keypad - disable unused long interrupts Tony Lindgren
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Tony Lindgren @ 2020-03-18 22:57 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, linux-kernel, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek, Sebastian Reichel, ruleh

Hi all,

This series updates omap4-keypad to disable unused long interrupts, and
implements the missing parts for the lost key-up interrupt quirk as
described in the silicon errata pdf.

Regards,

Tony


Changes since v2:

- Drop bogus level change, that already comes from device tree

- Scan keyboard in two phases and simplify using a bitmask

- Use mod_delayed_work and cancel_delayed_work_sync for the quirk


Tony Lindgren (3):
  Input: omap4-keypad - disable unused long interrupts
  Input: omap4-keypad - Scan keys in two phases and simplify with
    bitmask
  Input: omap4-keypad - check state again for lost key-up interrupts

 drivers/input/keyboard/omap4-keypad.c | 124 ++++++++++++++++++++------
 1 file changed, 95 insertions(+), 29 deletions(-)

-- 
2.25.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] Input: omap4-keypad - disable unused long interrupts
  2020-03-18 22:57 [PATCHv3 0/3] Lost key-up interrupt handling for omap4-keypad Tony Lindgren
@ 2020-03-18 22:57 ` Tony Lindgren
  2020-03-18 22:57 ` [PATCH 2/3] Input: omap4-keypad - Scan keys in two phases and simplify with bitmask Tony Lindgren
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Tony Lindgren @ 2020-03-18 22:57 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, linux-kernel, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek, ruleh, Sebastian Reichel

We are not using the long interrupts and they produce extra interrupts.
Let's not enable them at all.

Note that also the v3.0.8 Linux Android kernel has long interrupts
disabled.

Cc: Arthur Demchenkov <spinal.by@gmail.com>
Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: ruleh <ruleh@gmx.de>
Cc: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/input/keyboard/omap4-keypad.c | 5 ++---
 1 file changed, 2 insertions(+), 3 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
@@ -176,10 +176,9 @@ static int omap4_keypad_open(struct input_dev *input)
 	kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
 			 kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
 	kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQENABLE,
-			OMAP4_DEF_IRQENABLE_EVENTEN |
-				OMAP4_DEF_IRQENABLE_LONGKEY);
+			OMAP4_DEF_IRQENABLE_EVENTEN);
 	kbd_writel(keypad_data, OMAP4_KBD_WAKEUPENABLE,
-			OMAP4_DEF_WUP_EVENT_ENA | OMAP4_DEF_WUP_LONG_KEY_ENA);
+			OMAP4_DEF_WUP_EVENT_ENA);
 
 	enable_irq(keypad_data->irq);
 
-- 
2.25.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/3] Input: omap4-keypad - Scan keys in two phases and simplify with bitmask
  2020-03-18 22:57 [PATCHv3 0/3] Lost key-up interrupt handling for omap4-keypad Tony Lindgren
  2020-03-18 22:57 ` [PATCH 1/3] Input: omap4-keypad - disable unused long interrupts Tony Lindgren
@ 2020-03-18 22:57 ` Tony Lindgren
  2020-03-18 22:57 ` [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts Tony Lindgren
  2020-09-08  8:52 ` [PATCHv3 0/3] Lost key-up interrupt handling for omap4-keypad Pavel Machek
  3 siblings, 0 replies; 9+ messages in thread
From: Tony Lindgren @ 2020-03-18 22:57 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, linux-kernel, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek, ruleh, Sebastian Reichel

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>.

Cc: Arthur Demchenkov <spinal.by@gmail.com>
Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: ruleh <ruleh@gmx.de>
Cc: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/input/keyboard/omap4-keypad.c | 70 ++++++++++++++++++---------
 1 file changed, 47 insertions(+), 23 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
@@ -78,7 +78,7 @@ struct omap4_keypad {
 	u32 irqreg_offset;
 	unsigned int row_shift;
 	bool no_autorepeat;
-	unsigned char key_state[8];
+	u64 keys;
 	unsigned short *keymap;
 };
 
@@ -107,6 +107,41 @@ static void kbd_write_irqreg(struct omap4_keypad *keypad_data,
 		     keypad_data->base + keypad_data->irqreg_offset + offset);
 }
 
+static int omap4_keypad_scan_state(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;
+	bool key_down;
+	u64 changed;
+
+	changed = keys ^ keypad_data->keys;
+	bitmap_from_u64(mask, changed);
+
+	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);
+
+		if (BIT_ULL(bit) & keys)
+			key_down = true;
+		else
+			key_down = false;
+
+		if (key_down != down)
+			continue;
+
+		input_event(input_dev, EV_MSC, MSC_SCAN, code);
+		input_report_key(input_dev, keypad_data->keymap[code],
+				 key_down);
+		events++;
+	}
+
+	return events;
+}
 
 /* Interrupt handlers */
 static irqreturn_t omap4_keypad_irq_handler(int irq, void *dev_id)
@@ -123,34 +158,23 @@ static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id)
 {
 	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 keys_up, keys_down;
+	u32 low, high;
+	u64 keys;
 
-	*new_state = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
-	*(new_state + 1) = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
+	low = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
+	high = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
+	keys = low | (u64)high << 32;
 
-	for (row = 0; row < keypad_data->rows; row++) {
-		changed = key_state[row] ^ keypad_data->key_state[row];
-		if (!changed)
-			continue;
+	/* Scan for key up events for lost key-up interrupts */
+	keys_up = omap4_keypad_scan_state(keypad_data, keys, false);
 
-		for (col = 0; col < keypad_data->cols; col++) {
-			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));
-			}
-		}
-	}
+	/* Scan for key down events */
+	keys_down = omap4_keypad_scan_state(keypad_data, keys, true);
 
 	input_sync(input_dev);
 
-	memcpy(keypad_data->key_state, key_state,
-		sizeof(keypad_data->key_state));
+	keypad_data->keys = keys;
 
 	/* clear pending interrupts */
 	kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
-- 
2.25.1

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts
  2020-03-18 22:57 [PATCHv3 0/3] Lost key-up interrupt handling for omap4-keypad Tony Lindgren
  2020-03-18 22:57 ` [PATCH 1/3] Input: omap4-keypad - disable unused long interrupts Tony Lindgren
  2020-03-18 22:57 ` [PATCH 2/3] Input: omap4-keypad - Scan keys in two phases and simplify with bitmask Tony Lindgren
@ 2020-03-18 22:57 ` Tony Lindgren
  2020-09-08  8:52 ` [PATCHv3 0/3] Lost key-up interrupt handling for omap4-keypad Pavel Machek
  3 siblings, 0 replies; 9+ messages in thread
From: Tony Lindgren @ 2020-03-18 22:57 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, linux-kernel, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek, ruleh, Sebastian Reichel

We are still missing handling for errata i689 related issues for the
case where we never see a key up interrupt for the last pressed key.

To fix the issue, we must scan the key state again after the keyboard
controller has idled to check if a key up event was missed. This is
described in the omap4 silicon errata documentation for 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 use delayed_work after each key down event to catch stuck keys if
no more interrupts are seen. We use mod_delayed_work() as we already
scan for lost key up events in case of new interrupts, so only the
last key down interrupt needs the delayed_work handling.

Cc: Arthur Demchenkov <spinal.by@gmail.com>
Cc: Merlijn Wajer <merlijn@wizzup.org>
Cc: Pavel Machek <pavel@ucw.cz>
Cc: ruleh <ruleh@gmx.de>
Cc: Sebastian Reichel <sre@kernel.org>
Signed-off-by: Tony Lindgren <tony@atomide.com>
---
 drivers/input/keyboard/omap4-keypad.c | 55 ++++++++++++++++++++++++---
 1 file changed, 49 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;
@@ -154,17 +156,19 @@ 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;
 	int keys_up, keys_down;
 	u32 low, high;
-	u64 keys;
+	u64 keys = 0;
 
-	low = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
-	high = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
-	keys = low | (u64)high << 32;
+	mutex_lock(&keypad_data->lock);
+	if (!clear) {
+		low = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE31_0);
+		high = kbd_readl(keypad_data, OMAP4_KBD_FULLCODE63_32);
+		keys = low | (u64)high << 32;
+	}
 
 	/* Scan for key up events for lost key-up interrupts */
 	keys_up = omap4_keypad_scan_state(keypad_data, keys, false);
@@ -176,6 +180,23 @@ static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id)
 
 	keypad_data->keys = keys;
 
+	mutex_unlock(&keypad_data->lock);
+
+	return keys_down;
+}
+
+static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id)
+{
+	struct omap4_keypad *keypad_data = dev_id;
+	bool down_events;
+
+	down_events = omap4_keypad_scan_keys(keypad_data, false);
+	if (down_events)
+		mod_delayed_work(system_wq, &keypad_data->key_work,
+				 msecs_to_jiffies(50));
+	else
+		cancel_delayed_work_sync(&keypad_data->key_work);
+
 	/* clear pending interrupts */
 	kbd_write_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS,
 			 kbd_read_irqreg(keypad_data, OMAP4_KBD_IRQSTATUS));
@@ -183,6 +204,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);
@@ -275,6 +315,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)
@@ -410,6 +452,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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCHv3 0/3] Lost key-up interrupt handling for omap4-keypad
  2020-03-18 22:57 [PATCHv3 0/3] Lost key-up interrupt handling for omap4-keypad Tony Lindgren
                   ` (2 preceding siblings ...)
  2020-03-18 22:57 ` [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts Tony Lindgren
@ 2020-09-08  8:52 ` Pavel Machek
  2020-09-09  6:00   ` Tony Lindgren
  3 siblings, 1 reply; 9+ messages in thread
From: Pavel Machek @ 2020-09-08  8:52 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: Dmitry Torokhov, linux-input, linux-kernel, linux-omap,
	Arthur Demchenkov, Merlijn Wajer, Sebastian Reichel, ruleh

[-- Attachment #1: Type: text/plain, Size: 441 bytes --]

Hi!

> This series updates omap4-keypad to disable unused long interrupts, and
> implements the missing parts for the lost key-up interrupt quirk as
> described in the silicon errata pdf.

I do not see this in 5.9-rc4; problem is real, could we get this
merged?

Best regards,
								Pavel
-- 
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCHv3 0/3] Lost key-up interrupt handling for omap4-keypad
  2020-09-08  8:52 ` [PATCHv3 0/3] Lost key-up interrupt handling for omap4-keypad Pavel Machek
@ 2020-09-09  6:00   ` Tony Lindgren
  0 siblings, 0 replies; 9+ messages in thread
From: Tony Lindgren @ 2020-09-09  6:00 UTC (permalink / raw)
  To: Pavel Machek
  Cc: Dmitry Torokhov, linux-input, linux-kernel, linux-omap,
	Arthur Demchenkov, Merlijn Wajer, Sebastian Reichel, ruleh

* Pavel Machek <pavel@ucw.cz> [200908 08:52]:
> Hi!
> 
> > This series updates omap4-keypad to disable unused long interrupts, and
> > implements the missing parts for the lost key-up interrupt quirk as
> > described in the silicon errata pdf.
> 
> I do not see this in 5.9-rc4; problem is real, could we get this
> merged?

Sorry for the slow going here. FYI, I'm still seeing stuck keys few times
a day though. It seems to be with the last entered key now though.

Regards,

Tony

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts
  2020-03-06 19:10   ` Dmitry Torokhov
@ 2020-03-06 19:23     ` Tony Lindgren
  0 siblings, 0 replies; 9+ messages in thread
From: Tony Lindgren @ 2020-03-06 19:23 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, linux-kernel, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek, Sebastian Reichel, ruleh

* Dmitry Torokhov <dmitry.torokhov@gmail.com> [200306 19:11]:
> On Fri, Feb 28, 2020 at 09:12:23AM -0800, Tony Lindgren wrote:
> > 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 */
> 
> I think having threaded interrupt and delayed work together defeats the
> purpose of having threaded interrupt. If you want to add a delay before
> repeating scan I think you can add it directly in
> omap4_keypad_irq_thread_fn(). Or is there a concern that we will not
> rely quickly enough on additional key presses? It is unclear to me if
> additional key press within the debounce time will result in additional
> interrupt.

Well if we wait in threaded interrupt, we won't see a new interrupt.
So yes, an additional key press will still produce an interrupt.

After a key press has been detected, we need to set a timer that checks
the keyboard controller state after it has idled. Then check for a
potentially stuck state, and clear all down events if the state is
idle with keys down.

I don't think we can really use runtime PM autosuspend delay here as we
already keep the device enabled with clock autogated so there's nothing
to do. If we now added runtime PM calls, we'd end up in mode with
clocks completely disabled. Maybe some tinkering of usage counts in
the interrupt handler would allow using PM runtime though :)

Regards,

Tony


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts
  2020-02-28 17:12 ` [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts Tony Lindgren
@ 2020-03-06 19:10   ` Dmitry Torokhov
  2020-03-06 19:23     ` Tony Lindgren
  0 siblings, 1 reply; 9+ messages in thread
From: Dmitry Torokhov @ 2020-03-06 19:10 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: linux-input, linux-kernel, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek, Sebastian Reichel, ruleh

On Fri, Feb 28, 2020 at 09:12:23AM -0800, Tony Lindgren wrote:
> 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 */

I think having threaded interrupt and delayed work together defeats the
purpose of having threaded interrupt. If you want to add a delay before
repeating scan I think you can add it directly in
omap4_keypad_irq_thread_fn(). Or is there a concern that we will not
rely quickly enough on additional key presses? It is unclear to me if
additional key press within the debounce time will result in additional
interrupt.

Thanks.

-- 
Dmitry

^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts
  2020-02-28 17:12 [PATCHv2 " Tony Lindgren
@ 2020-02-28 17:12 ` Tony Lindgren
  2020-03-06 19:10   ` Dmitry Torokhov
  0 siblings, 1 reply; 9+ messages in thread
From: Tony Lindgren @ 2020-02-28 17:12 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, linux-kernel, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek, Sebastian Reichel, ruleh

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-09-09  6:00 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-18 22:57 [PATCHv3 0/3] Lost key-up interrupt handling for omap4-keypad Tony Lindgren
2020-03-18 22:57 ` [PATCH 1/3] Input: omap4-keypad - disable unused long interrupts Tony Lindgren
2020-03-18 22:57 ` [PATCH 2/3] Input: omap4-keypad - Scan keys in two phases and simplify with bitmask Tony Lindgren
2020-03-18 22:57 ` [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts Tony Lindgren
2020-09-08  8:52 ` [PATCHv3 0/3] Lost key-up interrupt handling for omap4-keypad Pavel Machek
2020-09-09  6:00   ` Tony Lindgren
  -- strict thread matches above, loose matches on Subject: below --
2020-02-28 17:12 [PATCHv2 " Tony Lindgren
2020-02-28 17:12 ` [PATCH 3/3] Input: omap4-keypad - check state again for lost key-up interrupts Tony Lindgren
2020-03-06 19:10   ` Dmitry Torokhov
2020-03-06 19:23     ` Tony Lindgren

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