linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] Input: omap4-keypad - Configure interrupt as level
@ 2020-02-27  2:04 Tony Lindgren
  2020-02-27  2:04 ` [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
  0 siblings, 2 replies; 5+ messages in thread
From: Tony Lindgren @ 2020-02-27  2:04 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, linux-kernel, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek, Sebastian Reichel

The interrupt should be level high for SoC internal devices.
Otherwise interrupts may not be seen after a wake-up event.

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 | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

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
@@ -344,7 +344,8 @@ static int omap4_keypad_probe(struct platform_device *pdev)
 	}
 
 	error = request_threaded_irq(keypad_data->irq, omap4_keypad_irq_handler,
-				     omap4_keypad_irq_thread_fn, IRQF_ONESHOT,
+				     omap4_keypad_irq_thread_fn,
+				     IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
 				     "omap4-keypad", keypad_data);
 	if (error) {
 		dev_err(&pdev->dev, "failed to register interrupt\n");
-- 
2.25.1

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

* [PATCH 2/2] Input: omap4-keypad - check state again for lost key-up interrupts
  2020-02-27  2:04 [PATCH 1/2] Input: omap4-keypad - Configure interrupt as level Tony Lindgren
@ 2020-02-27  2:04 ` Tony Lindgren
  2020-02-27 16:08   ` Tony Lindgren
  2020-03-06 18:58 ` [PATCH 1/2] Input: omap4-keypad - Configure interrupt as level Dmitry Torokhov
  1 sibling, 1 reply; 5+ messages in thread
From: Tony Lindgren @ 2020-02-27  2:04 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, linux-kernel, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek, Sebastian Reichel

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

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

* Re: [PATCH 2/2] Input: omap4-keypad - check state again for lost key-up interrupts
  2020-02-27  2:04 ` [PATCH 2/2] Input: omap4-keypad - check state again for lost key-up interrupts Tony Lindgren
@ 2020-02-27 16:08   ` Tony Lindgren
  0 siblings, 0 replies; 5+ messages in thread
From: Tony Lindgren @ 2020-02-27 16:08 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, linux-kernel, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek, Sebastian Reichel

* 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

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

* Re: [PATCH 1/2] Input: omap4-keypad - Configure interrupt as level
  2020-02-27  2:04 [PATCH 1/2] Input: omap4-keypad - Configure interrupt as level Tony Lindgren
  2020-02-27  2:04 ` [PATCH 2/2] Input: omap4-keypad - check state again for lost key-up interrupts Tony Lindgren
@ 2020-03-06 18:58 ` Dmitry Torokhov
  2020-03-06 19:04   ` Tony Lindgren
  1 sibling, 1 reply; 5+ messages in thread
From: Dmitry Torokhov @ 2020-03-06 18:58 UTC (permalink / raw)
  To: Tony Lindgren
  Cc: linux-input, linux-kernel, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek, Sebastian Reichel

Hi Tony,

On Wed, Feb 26, 2020 at 06:04:06PM -0800, Tony Lindgren wrote:
> The interrupt should be level high for SoC internal devices.
> Otherwise interrupts may not be seen after a wake-up event.
> 
> 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 | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> 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
> @@ -344,7 +344,8 @@ static int omap4_keypad_probe(struct platform_device *pdev)
>  	}
>  
>  	error = request_threaded_irq(keypad_data->irq, omap4_keypad_irq_handler,
> -				     omap4_keypad_irq_thread_fn, IRQF_ONESHOT,
> +				     omap4_keypad_irq_thread_fn,
> +				     IRQF_TRIGGER_HIGH | IRQF_ONESHOT,

Can't we rely on DT/platform to configure this properly?

Thanks.

-- 
Dmitry

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

* Re: [PATCH 1/2] Input: omap4-keypad - Configure interrupt as level
  2020-03-06 18:58 ` [PATCH 1/2] Input: omap4-keypad - Configure interrupt as level Dmitry Torokhov
@ 2020-03-06 19:04   ` Tony Lindgren
  0 siblings, 0 replies; 5+ messages in thread
From: Tony Lindgren @ 2020-03-06 19:04 UTC (permalink / raw)
  To: Dmitry Torokhov
  Cc: linux-input, linux-kernel, linux-omap, Arthur Demchenkov,
	Merlijn Wajer, Pavel Machek, Sebastian Reichel

* Dmitry Torokhov <dmitry.torokhov@gmail.com> [200306 18:58]:
> Hi Tony,
> 
> On Wed, Feb 26, 2020 at 06:04:06PM -0800, Tony Lindgren wrote:
> > The interrupt should be level high for SoC internal devices.
> > Otherwise interrupts may not be seen after a wake-up event.
> > 
> > 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 | 3 ++-
> >  1 file changed, 2 insertions(+), 1 deletion(-)
> > 
> > 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
> > @@ -344,7 +344,8 @@ static int omap4_keypad_probe(struct platform_device *pdev)
> >  	}
> >  
> >  	error = request_threaded_irq(keypad_data->irq, omap4_keypad_irq_handler,
> > -				     omap4_keypad_irq_thread_fn, IRQF_ONESHOT,
> > +				     omap4_keypad_irq_thread_fn,
> > +				     IRQF_TRIGGER_HIGH | IRQF_ONESHOT,
> 
> Can't we rely on DT/platform to configure this properly?

Oops yeah you're right, and we already have that set with
IRQ_TYPE_LEVEL_HIGH in dts.

Sorry I was again diffing against the old v3.0.8 vendor kernel
trying to figure out what they were doing for the lost keys
and spotted this change :)

So this patch can be just ignored.

Regards,

Tony

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

end of thread, other threads:[~2020-03-06 19:04 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-27  2:04 [PATCH 1/2] Input: omap4-keypad - Configure interrupt as level Tony Lindgren
2020-02-27  2:04 ` [PATCH 2/2] Input: omap4-keypad - check state again for lost key-up interrupts Tony Lindgren
2020-02-27 16:08   ` 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

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