From patchwork Mon Apr 25 14:19:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 12825827 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 B5534C433EF for ; Mon, 25 Apr 2022 14:19:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242428AbiDYOWn (ORCPT ); Mon, 25 Apr 2022 10:22:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60496 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242423AbiDYOW0 (ORCPT ); Mon, 25 Apr 2022 10:22:26 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 180AD1FA57 for ; Mon, 25 Apr 2022 07:19:20 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id 17-20020a05600c021100b00393a19f8f98so6665027wmi.4 for ; Mon, 25 Apr 2022 07:19:20 -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=ILXr0TJPBJo0r6+Bn2TlxMvdz9hhu2MSRkeWBLg3s/U=; b=a7zJOVdoFT/GJdg7tl5UUVlOAPsrIqhbrZwjAOwmQ4CUB3vTk6tzLUPDaiVYfgN/ZW qohGnepBzmVhEdNr448DkesYtQlznMwL36KNGAD/EQY30n9grXzN0t2iLQVJVVXUE5sp WSyC9oqtFSQ/7306YsSXPb5iJZg5HeuFtZQtUNSQV9N+vzf88FBtkiR+Y+nrbCgLJZFW aR7pQaK4H2Td6QTP++rtOW8CwXXVBU4cfQ3enBKgk8Cedh6VUBSzgsN+8tg0QXBkhjTX yhqsf1Q2RmG/LEl9lo8Q3uJM6Xy4s3YaYcBRk4qfzpqmnCk+lHlkqIaJktG+fc1EXs9G apSQ== 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=ILXr0TJPBJo0r6+Bn2TlxMvdz9hhu2MSRkeWBLg3s/U=; b=boB+FP3NGlYs95uAQI5DXzOKaPjw+s9B2jUl1nD1tWCQpV8lPEmPEBwSOF6GSQpWJP lc/lSYRIJUiHeoPtoabdVpbScUVOWV2fB5xU95zucXiR+G6JWM1KtZky+UoNOvTANDn0 vdOkEMrW0xKbgBgwvTvIoIO8tEMw4PsBqb2iTR2u89xYwWfiUThrQyoUTq9DLycsX+R4 1JwVIqw/jwqTtJuwsur6v4DpzzfEWCVFooXLiF1/ZpEUNMAsOCyBQkUwcCZoufO4ExCu jFt0aPEc19G5YpYo8Uzp7pmuHq5Kwfrp/Ostq8rIWQID+fhBuPLQuVzRZwKwBdO9dbTT MplQ== X-Gm-Message-State: AOAM531HycfIoLi56V5UP27hWjslZCdhPWqUhVMLL/r1DBMxlgEVGtqX r0g6anJkXkA/465Q3G9YsO1c/Q== X-Google-Smtp-Source: ABdhPJysAxok8ZUtzCpuS7vDpaS2DasQQibTMujnwrwmYIWm5LDaazhaCyHbAKTtyTITppXmXN7r9w== X-Received: by 2002:a05:600c:4ca2:b0:393:eb2e:faaa with SMTP id g34-20020a05600c4ca200b00393eb2efaaamr6016743wmp.206.1650896358597; Mon, 25 Apr 2022 07:19:18 -0700 (PDT) Received: from groot.home ([2a01:cb19:85e6:1900:ce86:3a65:67d7:726d]) by smtp.gmail.com with ESMTPSA id f10-20020a5d64ca000000b0020aa97b0383sm9144592wri.113.2022.04.25.07.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 07:19:18 -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 1/2] Input: mt6779-keypad - fix hardware code mapping Date: Mon, 25 Apr 2022 16:19:13 +0200 Message-Id: <20220425141914.158959-2-mkorpershoek@baylibre.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425141914.158959-1-mkorpershoek@baylibre.com> References: <20220425141914.158959-1-mkorpershoek@baylibre.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-input@vger.kernel.org In mt6779_keypad_irq_handler(), we 1. Read a hardware code from KPD_MEM1 -> KPD_MEM5 2. Use that hardware code to compute columns/rows for the standard keyboard matrix. According to the (non-public) datasheet, the map between the hardware code and the cols/rows is: |(0) |(1) |(2) ----*-----*-----*----- | | | |(9) |(10) |(11) ----*-----*-----*----- | | | |(18) |(19) |(20) ----*-----*-----*----- | | | This brings us to another formula: -> row = code / 9; -> col = code % 3; Implement this mapping in bitnr_to_col_row() to fetch the correct input event from keypad->input_dev->keycode and report that back to userspace. 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 | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/drivers/input/keyboard/mt6779-keypad.c b/drivers/input/keyboard/mt6779-keypad.c index 2e7c9187c10f..23360de20da5 100644 --- a/drivers/input/keyboard/mt6779-keypad.c +++ b/drivers/input/keyboard/mt6779-keypad.c @@ -36,6 +36,19 @@ static const struct regmap_config mt6779_keypad_regmap_cfg = { .max_register = 36, }; +/* + * | hardware key code | col0 | col1 | col2| + * | ----------------- | -----| ---- | --- | + * | row0 | 0 | 1 | 2 | + * | row1 | 9 | 10 | 11 | + * | row2 | 18 | 19 | 20 | + */ +static void bitnr_to_col_row(int bit_nr, int *col, int *row) +{ + *row = bit_nr / 9; + *col = bit_nr % 3; +} + static irqreturn_t mt6779_keypad_irq_handler(int irq, void *dev_id) { struct mt6779_keypad *keypad = dev_id; @@ -61,8 +74,7 @@ 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; + bitnr_to_col_row(bit_nr, &col, &row); scancode = MATRIX_SCAN_CODE(row, col, row_shift); /* 1: not pressed, 0: pressed */ pressed = !test_bit(bit_nr, new_state); From patchwork Mon Apr 25 14:19:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mattijs Korpershoek X-Patchwork-Id: 12825828 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 61D94C433FE for ; Mon, 25 Apr 2022 14:19:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242421AbiDYOWo (ORCPT ); Mon, 25 Apr 2022 10:22:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60516 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242424AbiDYOW1 (ORCPT ); Mon, 25 Apr 2022 10:22:27 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B548F1FA5C for ; Mon, 25 Apr 2022 07:19:20 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id d5so5880116wrb.6 for ; Mon, 25 Apr 2022 07:19:20 -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=f2ty6Kirg+4vRs3TX4nTiMefjQ+ct09dXtXeTw7jYik=; b=1sB7e3bdedA9AmRsfGnyCiarRfssvnjB14wg3RY5vuJjV8MlDlAG4m3750y3L4EI6B VCreeEhx06bcRLFb3DUHAYJvjqkhhjWZ5wEsdtvd0iyChuQyufYvQz/rFgbcBNXFkta5 oZ364bmnxUDmoMo5PKJYxul44ORkdDIAdkjhG7RD7z3xVe48qqIIxETG2j+dSi9L5Pxi 451O8ITGyPjGK/bRn2zi7whFR2olqTX68D+YTPvymtepHOVTUjCHRAG4eiBUy0hkofDD QV83KEgXbzukq11DA/dsG46j5gmqyPahC8HpJjhHATw13Xy4EH6GtVSWueTVkutXrcyB H+Lg== 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=f2ty6Kirg+4vRs3TX4nTiMefjQ+ct09dXtXeTw7jYik=; b=6luYxNb9pbwpVBJGuJOKcH2f7xwuawIWKBSl1/WAbIFVJrS4vONWwmu9+9bENJ2Oqw uq5KY/H1xx7IuS5Xr/SmsgtGsdfxiQrXjhHIy1EgWplkCdvc6TMr5z8Rt7QSiHBhHvE/ byn9PYcOyczBIWrB2Oa+uIIHC9TYJKVotzSELx92XTSxfo3MMLbRrJOJUAM1o4FWaA5J Cnp1XuICcnR4UlZ4nBa7RVNSocTdWKkwyQ9MM14Hl15dMgCtOCKlx2do4y0N7OFLHLsV 7YQLmmgVgvJUvFz3qo5MYzXP2vQpf+fyq2Nc4hbdYGrIqVQBvxnGhqtyNhJVgrtXhjVk I9tA== X-Gm-Message-State: AOAM531k+QS4fPh+hWIL0ChfDSv6mR4m7Sb1cR0UkfSA8IccmPgPQeI3 86QXWFIVGcJZU0XN59FdqBpRWg== X-Google-Smtp-Source: ABdhPJyz4lwM9SSlgEubsE2+9MARuzk/2+T+ZiKJb/BBzhW4+LWq+OpWxYNbBON2beZCu62KJb+UqQ== X-Received: by 2002:a05:6000:1a86:b0:20a:a933:ba16 with SMTP id f6-20020a0560001a8600b0020aa933ba16mr14279412wry.583.1650896359277; Mon, 25 Apr 2022 07:19:19 -0700 (PDT) Received: from groot.home ([2a01:cb19:85e6:1900:ce86:3a65:67d7:726d]) by smtp.gmail.com with ESMTPSA id f10-20020a5d64ca000000b0020aa97b0383sm9144592wri.113.2022.04.25.07.19.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Apr 2022 07:19:19 -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 2/2] Input: mt6779-keypad - implement row/column selection Date: Mon, 25 Apr 2022 16:19:14 +0200 Message-Id: <20220425141914.158959-3-mkorpershoek@baylibre.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20220425141914.158959-1-mkorpershoek@baylibre.com> References: <20220425141914.158959-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 23360de20da5..653dfc619696 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) (MTK_KPD_SEL_COL >> (6 - (c))) +#define MTK_KPD_SEL_ROWMASK(r) (MTK_KPD_SEL_ROW >> (6 - (r))) #define MTK_KPD_NUM_MEMS 5 #define MTK_KPD_NUM_BITS 136 /* 4*32+8 MEM5 only use 8 BITS */ @@ -171,6 +176,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);