From patchwork Fri Jun 21 18:09:52 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gerhard Sittig X-Patchwork-Id: 2763791 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 320EEC0AB1 for ; Fri, 21 Jun 2013 18:11:59 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 46F3C20140 for ; Fri, 21 Jun 2013 18:11:58 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4C8242012C for ; Fri, 21 Jun 2013 18:11:57 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uq5ni-0006jD-9h; Fri, 21 Jun 2013 18:11:10 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uq5nY-00025a-9L; Fri, 21 Jun 2013 18:11:00 +0000 Received: from mail-out.m-online.net ([2001:a60:0:28:0:1:25:1]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1Uq5nM-00022H-3t for linux-arm-kernel@lists.infradead.org; Fri, 21 Jun 2013 18:10:50 +0000 Received: from frontend1.mail.m-online.net (frontend1.mail.intern.m-online.net [192.168.8.180]) by mail-out.m-online.net (Postfix) with ESMTP id 3bcScH5Gjdz3hj8l; Fri, 21 Jun 2013 20:10:23 +0200 (CEST) Received: from localhost (dynscan1.mnet-online.de [192.168.6.68]) by mail.m-online.net (Postfix) with ESMTP id 3bcScH4vXLzbbkg; Fri, 21 Jun 2013 20:10:23 +0200 (CEST) X-Virus-Scanned: amavisd-new at mnet-online.de Received: from mail.mnet-online.de ([192.168.8.180]) by localhost (dynscan1.mail.m-online.net [192.168.6.68]) (amavisd-new, port 10024) with ESMTP id BOfYTLEd-hds; Fri, 21 Jun 2013 20:10:22 +0200 (CEST) X-Auth-Info: eTWBdEC0ogh8o7IVuK73Iz/tFrN433TFgxB19HYSifc= Received: from localhost (kons-4d027c0a.pool.mediaWays.net [77.2.124.10]) by mail.mnet-online.de (Postfix) with ESMTPA; Fri, 21 Jun 2013 20:10:21 +0200 (CEST) From: Gerhard Sittig To: Dmitry Torokhov , linux-input@vger.kernel.org, devicetree-discuss@lists.ozlabs.org, linux-arm-kernel@lists.infradead.org, Chao Xie Subject: [PATCH v1 06/12] input: keypad-matrix: refactor matrix scan logic Date: Fri, 21 Jun 2013 20:09:52 +0200 Message-Id: <1371838198-7327-7-git-send-email-gsi@denx.de> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1371838198-7327-1-git-send-email-gsi@denx.de> References: <1371838198-7327-1-git-send-email-gsi@denx.de> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20130621_141048_749650_153731C6 X-CRM114-Status: GOOD ( 12.98 ) X-Spam-Score: -1.9 (-) Cc: Eric Miao , Detlev Zundel , Arnd Bergmann , Tony Lindgren , Gerhard Sittig , Sekhar Nori , Haojian Zhuang , Marek Vasut , Ralf Baechle , Anatolij Gustschin X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-5.7 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP - factor out determination of all rows for a column into a separate routine - only call input_sync() when input events were generated (in the future empty key code positions may get skipped, in the current implementation short bounces may trigger matrix scans while no change is seen) Signed-off-by: Gerhard Sittig --- drivers/input/keyboard/matrix_keypad.c | 43 ++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 13 deletions(-) diff --git a/drivers/input/keyboard/matrix_keypad.c b/drivers/input/keyboard/matrix_keypad.c index 85e16a2..0b2599d 100644 --- a/drivers/input/keyboard/matrix_keypad.c +++ b/drivers/input/keyboard/matrix_keypad.c @@ -126,6 +126,28 @@ static bool row_asserted(const struct matrix_keypad_platform_data *pdata, } /* + * this routine fetches the status of all rows within the specified + * column, the column will get selected and deselected before and after + * sampling the row status + */ +static uint32_t sample_rows_for_col(struct matrix_keypad *keypad, int col) +{ + const struct matrix_keypad_platform_data *pdata; + uint32_t row_state; + int row; + + pdata = keypad->pdata; + + activate_col(pdata, col, true); + row_state = 0; + for (row = 0; row < pdata->num_row_gpios; row++) + row_state |= row_asserted(pdata, row) ? (1 << row) : 0; + activate_col(pdata, col, false); + + return row_state; +} + +/* * this routine enables IRQs after a keypad matrix scan has completed, * to have any subsequent change in the key press status trigger the ISR * @@ -178,25 +200,18 @@ static void matrix_keypad_scan(struct work_struct *work) const struct matrix_keypad_platform_data *pdata = keypad->pdata; uint32_t new_state[MATRIX_MAX_COLS]; int row, col, code; + int has_events; /* de-activate all columns before scanning the matrix */ activate_all_cols(pdata, false); - memset(new_state, 0, sizeof(new_state)); - /* assert each column in turn and read back the row status */ - for (col = 0; col < pdata->num_col_gpios; col++) { - - activate_col(pdata, col, true); - - for (row = 0; row < pdata->num_row_gpios; row++) - new_state[col] |= - row_asserted(pdata, row) ? (1 << row) : 0; - - activate_col(pdata, col, false); - } + memset(new_state, 0, sizeof(new_state)); + for (col = 0; col < pdata->num_col_gpios; col++) + new_state[col] = sample_rows_for_col(keypad, col); /* detect changes and derive input events, update the snapshot */ + has_events = 0; for (col = 0; col < pdata->num_col_gpios; col++) { uint32_t bits_changed; @@ -222,9 +237,11 @@ static void matrix_keypad_scan(struct work_struct *work) input_report_key(input_dev, keycodes[code], new_state[col] & (1 << row)); + has_events++; } } - input_sync(input_dev); + if (has_events) + input_sync(input_dev); memcpy(keypad->last_key_state, new_state, sizeof(new_state)); /*