From patchwork Fri Jun 17 08:19:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 12885254 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C9BF0C43334 for ; Fri, 17 Jun 2022 08:20:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=olbEUQu/XQF7XAQceR3nDnBpajS+0vkfYH+zXdQ29jw=; b=WGB6UrQkoGYz45 oaf9drIEwqTcijpU4GkiuylyclZmNkWPKjdM/pI8PqLKAUSMtiXMutmkV4lBeGRlrBd8oPhvfMOL7 xRHmsaBmpdeZhtdw2NQB1IXGFiK5Cqzw7VXKlzM+OIjypy6L9zeA9tAQ0RqmlR2Gmrwec+imPkiiK c0fnYt0UzSo+uWxg6p1n234j5Jz7QrptoZIBHuqqgviMwMGxaH3lGBIhX9TEOWjsFMU53sWl8hp3I a7f/b5QD1E42bDUiYaMhSjWe/eg/kaneOqjXMYhFvU4yeTe/YqXVwq0jcqA0ga2MkAPwnp2Ae5Xsl i5s40YbB1pgF/Se+iraw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o27CP-006Ftb-E1; Fri, 17 Jun 2022 08:19:25 +0000 Received: from mail-wr1-x42a.google.com ([2a00:1450:4864:20::42a]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o27CB-006Foa-GA for linux-arm-kernel@lists.infradead.org; Fri, 17 Jun 2022 08:19:14 +0000 Received: by mail-wr1-x42a.google.com with SMTP id c21so4785145wrb.1 for ; Fri, 17 Jun 2022 01:19:09 -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=CWIw+SKozEYKSjXKiyhkbgZmMOtdHn0KwhrfNy6oyETgyT90moWsaDQWt1xbeWfagr GO8BJm/gbXxQnzzNT52jBfNTohTqjzZaJCVaTWUQlOiUX84/vkOFMTMrIuWaau2efh4x lTszgI8YDW50cv6K8Yhb9KSr3CnpmQp7uhrCSY/Zwsp7ehnxStnqE1mQD1gw0OvzszGB oopBaloytTGS1PaHtnIIaGf/xEmsq9ulEgL2qc5yxcfq0iDVGFFxli9x7TgzN4trFtQK AW9haYEXPQTPnBt1PHpi53rud0Tz5cgiROx3gOQqc1G+7FEoGNxis6gOwDN/3uYVSE8e 8efQ== 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=T2QGeJt6B7Aj3pKvzR1gLmDONBMAZ6ftg10GGjwOmvuTXdtoOaAFJL4Jcn9t2O96D1 ooxRbVWsMx/c3cSP4S6ZpJr3S/NSd8E0Gqb26KhLRatV/xoeGSGIpXuUwGJ+9M58ovG+ NSUANIgUB0ipRmIcSkeaeU+3pBR+rCzIvaKdeicboqDaZgj4S8QFNY374akeAwFtfNRs +RWmhSxcObjc8BDW7XY7zWpGn1FujYLrEBNydmioWq8WfSiHfjtTH2Wzezkl/ZeqwypS nPIe3M4+xrkeoO/WnibkNYXdSomTQ4UoL6TK5jA2WmwaSG2V+08xeF5HnxhBXgkCfj/l Fqew== X-Gm-Message-State: AJIora+17rOCtM+dRjR3bEV37kU9n+6HKMxeVivXYUA1ogaRG4PjHHtw ysQG354fct7jUbSJLHXKn7TjKw== X-Google-Smtp-Source: AGRyM1ta2q9ocH3+ZlEIO4Zm/dANjzoJkhcNDdzPCDqronR3KId0B5dJhF5i4ZTu2Sx/xXjavxJDVA== X-Received: by 2002:a5d:570c:0:b0:210:32e1:7250 with SMTP id a12-20020a5d570c000000b0021032e17250mr8269541wrv.368.1655453948779; Fri, 17 Jun 2022 01:19:08 -0700 (PDT) Received: from groot.. ([2a01:cb19:85e6:1900:b8a0:45dd:a367:2e65]) by smtp.gmail.com with ESMTPSA id l9-20020a05600c4f0900b0039db500714fsm4970245wmq.6.2022.06.17.01.19.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 01:19:07 -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: [PATCH v3 1/2] Input: mt6779-keypad - match hardware matrix organization Date: Fri, 17 Jun 2022 10:19:01 +0200 Message-Id: <20220617081902.2931099-2-mkorpershoek@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220617081902.2931099-1-mkorpershoek@baylibre.com> References: <20220617081902.2931099-1-mkorpershoek@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220617_011911_561900_435F0930 X-CRM114-Status: GOOD ( 13.62 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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 Fri Jun 17 08:19:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 12885255 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 18284C43334 for ; Fri, 17 Jun 2022 08:20:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=kvoTrkUk7Z5z0x/QxXnu2l40QY4uzGa8/2gLmEpomV0=; b=Oq9O0opYOf7ZtM ikYUN5NuzLa3JjT6jt1me9bGcW5lDUVu5AEZC4nTr7CRdxFLs4mixirEaQ0jZdZPfhFyImihoG8cY yDq1E16B5duTR5QkcxyYzQpqYGKY/lW602h2E3iTofa0lp4UFwDCxY83PtQAHY1u08UGA2f5o68vZ lXSEibFg8RTOrAPmUSjKtaWcdk3e9ddDfIDpE+dEJU2VfKKGITcdanZ3Onxp/rEMMMbFIJqfhTmqa 947FGLyOcv+W46wOkoPd+WIqU4eqfQRUGEeU5vxIDeYydOjNFbJZAJOA5j0SVt69gjI5CrJwff7vt PnM3TG+A6w02GZbUerXg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1o27CZ-006FwG-W0; Fri, 17 Jun 2022 08:19:36 +0000 Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1o27CC-006Fod-Gp for linux-arm-kernel@lists.infradead.org; Fri, 17 Jun 2022 08:19:14 +0000 Received: by mail-wm1-x32e.google.com with SMTP id n185so1916060wmn.4 for ; Fri, 17 Jun 2022 01:19:11 -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=mtQXnNncLkH5+APNy+qa+gXYlCjcWp0W7PGKAfj+IFRVykr8G5oPo2oW38RIlhfBIU oHB2kCRIZLFlAiyyfIO7CcTf6m9MP6snoDpTRdcgCiv3tt2YmCcZBI2LYbw7xDmuXHgv Xzqez09XcW9J3W5ttBTNwR498IHRR0N1umoe0EGDdtFJr4ZlYS69p9OsslUiAP5Lpol2 ver6MQNRB2CHNr5Hi4xAXUv1Rtm5mG973JnVAcSh12HRLgsQBj4HC/Up35ID4CuwmMga B7A+t9iG/jUgKD+7gIm1fbV7/Oy33nNsJF7mPodlfOmQHpvYxf7Bn4i1VBxdesgUKVhC bxBw== 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=nB6nUQV95a1WBF7zjLvyCizCJjj54Ch3sNzX/JbBbL7gDdqDstHoylXJ+x45QNiWY7 5q9kbuwrjw8ICwoeLB/q4J4Oj61gj17DXAU2k+DRzlffruSFjuxO6QquPgvCsudB1YAk 5N65DI8qIRa7FZsG/IsVQ4yFXdiXE960OGoi529amt3IGGz0aOnS/JOjCe1bTA1nxT3q 8B6OcEbzVotbeD5VCz/nEFuKtxiUSABwCVKsO/emswE/LjgpwrHXUSSWBHdJ7Z7KzUvC /6HwtLEOXk2IBbHzfGs2s3g0rmYeaA8DkXh4DKd81Ci31efZdBGQEDF9wWjxmGb92UCk a2sw== X-Gm-Message-State: AJIora/R+bbm6MbZ2tGknzbILFTS2wRVbx4RWkVBfkJ0S1V1a+OGe0nu FmQe3bRU6wZDcNJwlvEVkwamag== X-Google-Smtp-Source: AGRyM1tIXg2YoKkkCqDilEVxCCUSgr+DQnIy9x2PWUwFyjbZee7lkDg9EWeYCjC81sWbPrxlGE3Bvg== X-Received: by 2002:a05:600c:4f4e:b0:39c:1bbb:734f with SMTP id m14-20020a05600c4f4e00b0039c1bbb734fmr8830394wmq.116.1655453950431; Fri, 17 Jun 2022 01:19:10 -0700 (PDT) Received: from groot.. ([2a01:cb19:85e6:1900:b8a0:45dd:a367:2e65]) by smtp.gmail.com with ESMTPSA id l9-20020a05600c4f0900b0039db500714fsm4970245wmq.6.2022.06.17.01.19.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Jun 2022 01:19:09 -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: [PATCH v3 2/2] Input: mt6779-keypad - implement row/column selection Date: Fri, 17 Jun 2022 10:19:02 +0200 Message-Id: <20220617081902.2931099-3-mkorpershoek@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220617081902.2931099-1-mkorpershoek@baylibre.com> References: <20220617081902.2931099-1-mkorpershoek@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220617_011912_614844_A92FBD2D X-CRM114-Status: GOOD ( 12.59 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.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);