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: 12825824 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 9D58EC433F5 for ; Mon, 25 Apr 2022 14:21:28 +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=irGzth41L9pWDDsSjqRNfHXA/90L2rEAT5A0tJ8HOnE=; b=p6Sv/4LqiXzvnS 7ZhmnICM9mFODupeWfuquZuJhvvr1S7JbkmGyY+mbLXVb1b80uzNHw2xmnYhnlhbfB7d5XdiEaZL4 pvxmbBQMVRoe+R1UgtystGz6zXoWMq16mLZLpeLIHUbYXewRRtmAFM697N3IiWdVKMvufDn/Z/lUm 8O4t8v77dw6NmQMdp38Eod3R+1+PYHTc96PlrhHY40vE3cMXdPgt4rk7l7C+MSprsHEi0DELPJv6G Q5Dag3w0aKuzPPeTK2JcQRkI6hAGlRO4gjdIB1YQCSUkBvLUhvyvqblupc9GdcMlAQs85SkFcOFHo DpRxfXDJ5AWKNsVVHOSA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nizZa-009tV3-H1; Mon, 25 Apr 2022 14:20:18 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nizYg-009t4y-4C for linux-arm-kernel@lists.infradead.org; Mon, 25 Apr 2022 14:19:26 +0000 Received: by mail-wm1-x329.google.com with SMTP id n126-20020a1c2784000000b0038e8af3e788so9680235wmn.1 for ; Mon, 25 Apr 2022 07:19:19 -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=J503dowwPp14eF0oaS7tBwfqH89mRTcwV3fh508DjRmh1KmxYrFPkp4VgBMhPCR96j 1EoCVlU0NT3KLk6s6xHSpc98BGOMuw5A0h4UZWcSTdBBbD+GavTIRfHUaxwucelrHGp5 x3QR8e0ImMpbze1Gt9Bs4XzjjhrS/NmpoiidPaYrDNdQdWwUWKfFcEVP0GhcwX9g2aq8 GQMtgqtL7XsPsbpgniP6CZ64uL+V6Tbp56fV+u2VwsKBsKDjyTtraDGfuTAAOHr7DE0/ jX9HxsN4eQwdBxRHyDJj6rQ8CFXS2R0hyxgDisGXpFiPPASSiWUDJGK81bHxXEjcNX6E 1n4g== X-Gm-Message-State: AOAM533aeqVJVP0fsGxfPmb41kP/XcL1wcq+ArUv5BygVPAPI7Rw3VvQ oh6hIyeluUAxKdI1NWAqzW10Nw== 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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220425_071922_241225_D3DCB6AB X-CRM114-Status: GOOD ( 16.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 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);