Input: omap4-keypad - Configure interrupt as level
Subsystems (2)
PATCH 1/2 Input: omap4-keypad - Configure interrupt as level
The interrupt should be level high for SoC internal devices. Otherwise interrupts may not be seen after a wake-up event.
--- drivers/input/keyboard/omap4-keypad.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/input/keyboard/omap4-keypad.c +2 -1
@@ -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" );
Signature · 1 line
2.25.1
PATCH 2/2 Input: omap4-keypad - check state again for lost key-up interrupts
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.
---
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(-)
drivers/input/keyboard/omap4-keypad.c +33 -4
@@ -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 ));
Signature · 1 line
2.25.1
Re: [PATCH 2/2] Input: omap4-keypad - check state again for lost key-up interrupts
drivers/input/keyboard/omap4-keypad.c static irqreturn_t omap4_keypad_irq_thread_fn(int irq, void *dev_id) · line 181
Quoted 6 lines · Tony Lindgren
drivers/input/keyboard/omap4-keypad.c +6
-0+/* 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
Dmitry Torokhov
maintainerHi Tony,
Quoted 16 lines · Tony Lindgren
The interrupt should be level high for SoC internal devices. Otherwise interrupts may not be seen after a wake-up event.
Cc Arthur Demchenkov <[email protected]>Cc Merlijn Wajer <[email protected]>Cc Pavel Machek <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/input/keyboard/omap4-keypad.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/input/keyboard/omap4-keypad.c static int omap4_keypad_probe(struct platform_device *pdev) · line 348
Quoted 6 lines
drivers/input/keyboard/omap4-keypad.c +2
-1@@ -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.
Signature · 1 line
Dmitry
Quoted 21 lines · Dmitry Torokhov
Hi Tony,
Quoted 18 lines · Tony Lindgren
The interrupt should be level high for SoC internal devices. Otherwise interrupts may not be seen after a wake-up event.
Cc Arthur Demchenkov <[email protected]>Cc Merlijn Wajer <[email protected]>Cc Pavel Machek <[email protected]>Cc Sebastian Reichel <[email protected]>Signed-off-by Tony Lindgren <[email protected]>--- drivers/input/keyboard/omap4-keypad.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/input/keyboard/omap4-keypad.c +0
-0@@ -344,7 +344,8 @@ static int omap4_keypad_probe(struct platform_device *pdev) }
Quoted 6 lines
drivers/input/keyboard/omap4-keypad.c static int omap4_keypad_probe(struct platform_device *pdev) · line 348
Quoted 4 lines
drivers/input/keyboard/omap4-keypad.c +2
-1error = 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