From patchwork Thu Jul 7 07:52:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 12909184 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CE6ECCA481 for ; Thu, 7 Jul 2022 07:52:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234626AbiGGHwo (ORCPT ); Thu, 7 Jul 2022 03:52:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235191AbiGGHwn (ORCPT ); Thu, 7 Jul 2022 03:52:43 -0400 Received: from mail-wr1-x431.google.com (mail-wr1-x431.google.com [IPv6:2a00:1450:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B6AB63336B for ; Thu, 7 Jul 2022 00:52:41 -0700 (PDT) Received: by mail-wr1-x431.google.com with SMTP id q9so25092995wrd.8 for ; Thu, 07 Jul 2022 00:52:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=B+0V1FswFhS8JDSDQi560ezRR3egayVm0kqkR8HX1a0=; b=s7qniQ82clkr0qiDz/59anL2Yhq0MJPmg5Uo+vvMjhFZ2nNzPjMoByBSrPJZvNcNyJ ijbTMdy1h4wdCvGOOU18QWioh7teFl4wVHMQ+O47et+Aca3Gyi2aNjbtYa6j+PGDAbem We2Y6w8oMpa44OGB09r5nzcNCuMgj3poFhkqfMb8iDPwPu/s5VufDiGu3yqMgzvte3Nl DwxzWvI0fHEcUTDyZwfcdmZVyzjkjU0xNv1JOPsnfU6TABEotuD1zrg7jdXu0tNnz93v hG/hTE8orD4FTYfMjh6pA5aR1murMAGzonAcIFaoRU+l3wmjCAgOOMnNCL2xfuW5iLq2 7x1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=B+0V1FswFhS8JDSDQi560ezRR3egayVm0kqkR8HX1a0=; b=h4XKycPtYR9r3MDosZiFno86vWS01poGHbqQn53Zp/Fgv8Gcjkq6VXemnMKFECB1s6 UwmMHhsvBvfNYgNQa0SEZRCX+0pnwORDiYg8JmZUp5swQgcZP6KfKYN3/8F1GXYBc4AK pnuxdkcl28ziONonpflH+FHgoIYhRLQUWx4touRmHZ81habAPspEENNR9U4OTG9jhnXQ wCry7HkNdhK7CRU5oah8tGWzepkrYxVHRglU+bqTIDH4lV9KB3uNorgdlrsUWiZXAcXf c4PTQ01eiYFh5xZczu+LeNti/e+YzWoQCK2ucL/GtI1G79HHNvmZa1vl+kAaN1OuR12g aY8A== X-Gm-Message-State: AJIora/dv9if7M+5io/0TwkQqvlRAV/QtT/1GBmnJ747TJ14HKf10VlF tlZ/lgDR0atwrlEoVX1XQ0DV+cb8viqdtA== X-Google-Smtp-Source: AGRyM1vpNxZN7VNyJdlVhEnP2s+sR0sREI2vQy0cjQ06bLJ4egqraKcgsxkQF5alFIsdPU+dYGR5nA== X-Received: by 2002:a05:6000:1ac7:b0:21d:134e:5d74 with SMTP id i7-20020a0560001ac700b0021d134e5d74mr42907947wry.78.1657180360266; Thu, 07 Jul 2022 00:52:40 -0700 (PDT) Received: from groot.home ([2a01:cb19:85e6:1900:334b:5931:88c6:bbd2]) by smtp.gmail.com with ESMTPSA id m16-20020adfe950000000b0021d70a871cbsm6972089wrn.32.2022.07.07.00.52.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 00:52:39 -0700 (PDT) From: Mattijs Korpershoek To: Dmitry Torokhov Cc: Matthias Brugger , AngeloGioacchino Del Regno , Kevin Hilman , Fabien Parent , linux-input@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mattijs Korpershoek , Fabien Parent Subject: [RESEND PATCH v3 1/2] Input: mt6779-keypad - match hardware matrix organization Date: Thu, 7 Jul 2022 09:52:35 +0200 Message-Id: <20220707075236.126631-2-mkorpershoek@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707075236.126631-1-mkorpershoek@baylibre.com> References: <20220707075236.126631-1-mkorpershoek@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The MediaTek keypad has a set of bits representing keys, from KEY0 to KEY77, arranged in 5 chunks of 15 bits split into 5 32-bit registers. In our implementation, we simply decided to use register number as row and offset in the register as column when encoding our "matrix". Because of this, we can have a 5x32 matrix which does not match the hardware at all, which is confusing. Change the row/column calculation to match the hardware. Fixes: f28af984e771 ("Input: mt6779-keypad - add MediaTek keypad driver") Co-developed-by: Fabien Parent Signed-off-by: Fabien Parent Signed-off-by: Mattijs Korpershoek --- drivers/input/keyboard/mt6779-keypad.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/input/keyboard/mt6779-keypad.c b/drivers/input/keyboard/mt6779-keypad.c index 2e7c9187c10f..bd86cb95bde3 100644 --- a/drivers/input/keyboard/mt6779-keypad.c +++ b/drivers/input/keyboard/mt6779-keypad.c @@ -42,7 +42,7 @@ static irqreturn_t mt6779_keypad_irq_handler(int irq, void *dev_id) const unsigned short *keycode = keypad->input_dev->keycode; DECLARE_BITMAP(new_state, MTK_KPD_NUM_BITS); DECLARE_BITMAP(change, MTK_KPD_NUM_BITS); - unsigned int bit_nr; + unsigned int bit_nr, key; unsigned int row, col; unsigned int scancode; unsigned int row_shift = get_count_order(keypad->n_cols); @@ -61,8 +61,10 @@ static irqreturn_t mt6779_keypad_irq_handler(int irq, void *dev_id) if (bit_nr % 32 >= 16) continue; - row = bit_nr / 32; - col = bit_nr % 32; + key = bit_nr / 32 * 16 + bit_nr % 32; + row = key / 9; + col = key % 9; + scancode = MATRIX_SCAN_CODE(row, col, row_shift); /* 1: not pressed, 0: pressed */ pressed = !test_bit(bit_nr, new_state); From patchwork Thu Jul 7 07:52:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 12909186 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 61289CCA479 for ; Thu, 7 Jul 2022 07:52:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235201AbiGGHwp (ORCPT ); Thu, 7 Jul 2022 03:52:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40322 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235194AbiGGHwn (ORCPT ); Thu, 7 Jul 2022 03:52:43 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7871232EE6 for ; Thu, 7 Jul 2022 00:52:42 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id v16so13656111wrd.13 for ; Thu, 07 Jul 2022 00:52:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=i6KN7qFz99qq/ALEKkoJkPgYJrjmF3EU2O4lIDewe7o=; b=2xWwxlQmOxFF7hkSwLKpunHGvB5x/X0vkrg/yhdWYf37lt4PSFeBuS/zCnxcpFzwrh HKDRN0N2yCvbPkyA3QiH99SXtyd4xFJu8OslBkqSP58kp4twJwZRnVn6uM9hDdYs/NmE scAllfzUBCgC3DvTT/3kcl/uX2f/j9EXSuZgOgCIc1yl3CwUa8/P9KLyx5ljtKMqLz8S Onmv+/j7i2UPWUJn52OVvG2ThAzfPtMgEhc+ZfPdB5UK55cK34jWeW2D2hH+6pCBAJjD d1ZJD+cj2n/Iox9G/muCTOiD3DOlT9eh6Xl21FCLrbFrXl/nPMqvWX5v+rtpxmk50oaV 8Kqg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=i6KN7qFz99qq/ALEKkoJkPgYJrjmF3EU2O4lIDewe7o=; b=m05WDfWAh+n84EpnsKwpfGOBkRoM6yFkm8AEV5aUNrv0fvmvEoTfEkqcn0sePM++AA U7FzLRGfM2mxVwWzFOZh2Huv+t1dX8UOXIGIk6porpdeHBfvEbyJ+GBcwN+svyufomUn gvwUidsdFUxb9H6Y76//shHeFWRDkGrE4a4YpAE/80R0lla3Q78YonoX4eANyCyq6wqP /rGWyqqvzcpxqmsIEho2LttzHE4dFcaLdcPk7SLmaF964TPzf95KQp3p7f/gVLNODjeq W2Yr9LYWSRuKNqLCGyjbZQLHNiExfkJqjGZxFoURit4prQFEBuwQanc0ZPtB8pBrIFZe XsGA== X-Gm-Message-State: AJIora8Q01WH+aqhmotci+8A7Ie1TUtp+OUWn5lmPuegue7MTCzHyANf 1eHxNRw99RLpd3fztN8iwBIyig== X-Google-Smtp-Source: AGRyM1soDhGfdev4LQ0mIklVU0dko84uYu7TIAzqbK7fMuXRnesTOeRRyxcpUQ5KiguXVGPAm3TRKA== X-Received: by 2002:adf:f9ce:0:b0:21d:68b7:e7af with SMTP id w14-20020adff9ce000000b0021d68b7e7afmr20416179wrr.236.1657180361035; Thu, 07 Jul 2022 00:52:41 -0700 (PDT) Received: from groot.home ([2a01:cb19:85e6:1900:334b:5931:88c6:bbd2]) by smtp.gmail.com with ESMTPSA id m16-20020adfe950000000b0021d70a871cbsm6972089wrn.32.2022.07.07.00.52.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jul 2022 00:52:40 -0700 (PDT) From: Mattijs Korpershoek To: Dmitry Torokhov Cc: Matthias Brugger , AngeloGioacchino Del Regno , Kevin Hilman , Fabien Parent , linux-input@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Mattijs Korpershoek Subject: [RESEND PATCH v3 2/2] Input: mt6779-keypad - implement row/column selection Date: Thu, 7 Jul 2022 09:52:36 +0200 Message-Id: <20220707075236.126631-3-mkorpershoek@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220707075236.126631-1-mkorpershoek@baylibre.com> References: <20220707075236.126631-1-mkorpershoek@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org The MediaTek keypad has a total of 6 input rows and 6 input columns. By default, rows/columns 0-2 are enabled. This is controlled by the KP_SEL register: - bits[9:4] control row selection - bits[15:10] control column selection Each bit enables the corresponding row/column number (e.g KP_SEL[4] enables ROW0) Depending on how the keypad is wired, this may result in wrong readings of the keypad state. Program the KP_SEL register to limit the key detection to n_rows, n_cols we retrieve from the device tree. Signed-off-by: Mattijs Korpershoek --- drivers/input/keyboard/mt6779-keypad.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/input/keyboard/mt6779-keypad.c b/drivers/input/keyboard/mt6779-keypad.c index bd86cb95bde3..bf447bf598fb 100644 --- a/drivers/input/keyboard/mt6779-keypad.c +++ b/drivers/input/keyboard/mt6779-keypad.c @@ -17,6 +17,11 @@ #define MTK_KPD_DEBOUNCE 0x0018 #define MTK_KPD_DEBOUNCE_MASK GENMASK(13, 0) #define MTK_KPD_DEBOUNCE_MAX_MS 256 +#define MTK_KPD_SEL 0x0020 +#define MTK_KPD_SEL_COL GENMASK(15, 10) +#define MTK_KPD_SEL_ROW GENMASK(9, 4) +#define MTK_KPD_SEL_COLMASK(c) GENMASK((c) + 9, 10) +#define MTK_KPD_SEL_ROWMASK(r) GENMASK((r) + 3, 4) #define MTK_KPD_NUM_MEMS 5 #define MTK_KPD_NUM_BITS 136 /* 4*32+8 MEM5 only use 8 BITS */ @@ -161,6 +166,11 @@ static int mt6779_keypad_pdrv_probe(struct platform_device *pdev) regmap_write(keypad->regmap, MTK_KPD_DEBOUNCE, (debounce * (1 << 5)) & MTK_KPD_DEBOUNCE_MASK); + regmap_update_bits(keypad->regmap, MTK_KPD_SEL, MTK_KPD_SEL_ROW, + MTK_KPD_SEL_ROWMASK(keypad->n_rows)); + regmap_update_bits(keypad->regmap, MTK_KPD_SEL, MTK_KPD_SEL_COL, + MTK_KPD_SEL_COLMASK(keypad->n_cols)); + keypad->clk = devm_clk_get(&pdev->dev, "kpd"); if (IS_ERR(keypad->clk)) return PTR_ERR(keypad->clk);