From patchwork Thu Feb 27 02:04:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 11407615 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6F2BC14D5 for ; Thu, 27 Feb 2020 02:04:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5743224672 for ; Thu, 27 Feb 2020 02:04:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728244AbgB0CEM (ORCPT ); Wed, 26 Feb 2020 21:04:12 -0500 Received: from muru.com ([72.249.23.125]:57982 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728243AbgB0CEM (ORCPT ); Wed, 26 Feb 2020 21:04:12 -0500 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id E546A8022; Thu, 27 Feb 2020 02:04:56 +0000 (UTC) From: Tony Lindgren To: Dmitry Torokhov Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, Arthur Demchenkov , Merlijn Wajer , Pavel Machek , Sebastian Reichel Subject: [PATCH 1/2] Input: omap4-keypad - Configure interrupt as level Date: Wed, 26 Feb 2020 18:04:06 -0800 Message-Id: <20200227020407.17276-1-tony@atomide.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The interrupt should be level high for SoC internal devices. Otherwise interrupts may not be seen after a wake-up event. Cc: Arthur Demchenkov Cc: Merlijn Wajer Cc: Pavel Machek Cc: Sebastian Reichel Signed-off-by: Tony Lindgren --- 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"); From patchwork Thu Feb 27 02:04:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tony Lindgren X-Patchwork-Id: 11407621 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E6490159A for ; Thu, 27 Feb 2020 02:04:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id D069B24679 for ; Thu, 27 Feb 2020 02:04:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728315AbgB0CEO (ORCPT ); Wed, 26 Feb 2020 21:04:14 -0500 Received: from muru.com ([72.249.23.125]:57994 "EHLO muru.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728243AbgB0CEO (ORCPT ); Wed, 26 Feb 2020 21:04:14 -0500 Received: from hillo.muru.com (localhost [127.0.0.1]) by muru.com (Postfix) with ESMTP id 18AF7819C; Thu, 27 Feb 2020 02:04:58 +0000 (UTC) From: Tony Lindgren To: Dmitry Torokhov Cc: linux-input@vger.kernel.org, linux-kernel@vger.kernel.org, linux-omap@vger.kernel.org, Arthur Demchenkov , Merlijn Wajer , Pavel Machek , Sebastian Reichel Subject: [PATCH 2/2] Input: omap4-keypad - check state again for lost key-up interrupts Date: Wed, 26 Feb 2020 18:04:07 -0800 Message-Id: <20200227020407.17276-2-tony@atomide.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227020407.17276-1-tony@atomide.com> References: <20200227020407.17276-1-tony@atomide.com> MIME-Version: 1.0 Sender: linux-input-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org 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 Cc: Merlijn Wajer Cc: Pavel Machek Cc: Sebastian Reichel Signed-off-by: Tony Lindgren --- 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 #include #include +#include #include #include #include @@ -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));