linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mattijs Korpershoek <mkorpershoek@baylibre.com>
To: Rob Herring <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Mattijs Korpershoek <mkorpershoek@baylibre.com>,
	Dmitry Torokhov <dmitry.torokhov@gmail.com>,
	Matthias Brugger <matthias.bgg@gmail.com>
Cc: linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
	Fabien Parent <parent.f@gmail.com>,
	devicetree@vger.kernel.org, linux-mediatek@lists.infradead.org,
	Fabien Parent <fparent@baylibre.com>,
	linux-arm-kernel@lists.infradead.org
Subject: [PATCH v1 4/6] Input: mt6779-keypad - support double keys matrix
Date: Wed, 20 Jul 2022 16:48:40 +0200	[thread overview]
Message-ID: <20220720-mt8183-keypad-v1-4-ef9fc29dbff4@baylibre.com> (raw)
In-Reply-To: <20220720-mt8183-keypad-v1-0-ef9fc29dbff4@baylibre.com>

MediaTek keypad has 2 modes of detecting key events:
- single key: each (row, column) can detect one key
- double key: each (row, column) is a group of 2 keys

Double key support exists to minimize cost, since it reduces the number
of pins required for physical keys.

Double key is configured by setting BIT(0) of the KP_SEL register.

Enable double key matrix support based on the mediatek,double-keys
device tree property.

Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>

diff --git a/drivers/input/keyboard/mt6779-keypad.c b/drivers/input/keyboard/mt6779-keypad.c
index bf447bf598fb..9a5dbd415dac 100644
--- a/drivers/input/keyboard/mt6779-keypad.c
+++ b/drivers/input/keyboard/mt6779-keypad.c
@@ -18,6 +18,7 @@
 #define MTK_KPD_DEBOUNCE_MASK	GENMASK(13, 0)
 #define MTK_KPD_DEBOUNCE_MAX_MS	256
 #define MTK_KPD_SEL		0x0020
+#define MTK_KPD_SEL_DOUBLE_KP_MODE	BIT(0)
 #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)
@@ -31,6 +32,7 @@ struct mt6779_keypad {
 	struct clk *clk;
 	u32 n_rows;
 	u32 n_cols;
+	bool double_keys;
 	DECLARE_BITMAP(keymap_state, MTK_KPD_NUM_BITS);
 };
 
@@ -67,8 +69,13 @@ static irqreturn_t mt6779_keypad_irq_handler(int irq, void *dev_id)
 			continue;
 
 		key = bit_nr / 32 * 16 + bit_nr % 32;
-		row = key / 9;
-		col = key % 9;
+		if (keypad->double_keys) {
+			row = key / 13;
+			col = (key % 13) / 2;
+		} else {
+			row = key / 9;
+			col = key % 9;
+		}
 
 		scancode = MATRIX_SCAN_CODE(row, col, row_shift);
 		/* 1: not pressed, 0: pressed */
@@ -150,6 +157,8 @@ static int mt6779_keypad_pdrv_probe(struct platform_device *pdev)
 
 	wakeup = device_property_read_bool(&pdev->dev, "wakeup-source");
 
+	keypad->double_keys = device_property_read_bool(&pdev->dev, "mediatek,double-keys");
+
 	dev_dbg(&pdev->dev, "n_row=%d n_col=%d debounce=%d\n",
 		keypad->n_rows, keypad->n_cols, debounce);
 
@@ -166,6 +175,10 @@ static int mt6779_keypad_pdrv_probe(struct platform_device *pdev)
 	regmap_write(keypad->regmap, MTK_KPD_DEBOUNCE,
 		     (debounce * (1 << 5)) & MTK_KPD_DEBOUNCE_MASK);
 
+	if (keypad->double_keys)
+		regmap_update_bits(keypad->regmap, MTK_KPD_SEL,
+				   MTK_KPD_SEL_DOUBLE_KP_MODE, MTK_KPD_SEL_DOUBLE_KP_MODE);
+
 	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,

-- 
b4 0.10.0-dev-54fef

  parent reply	other threads:[~2022-07-20 14:49 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-20 14:48 [PATCH v1 0/6] Input: mt6779-keypad - double keys support Mattijs Korpershoek
2022-07-20 14:48 ` [PATCH v1 1/6] MAINTAINERS: input: add mattijs for mt6779-keypad Mattijs Korpershoek
2022-07-20 14:48 ` [PATCH v1 2/6] dt-bindings: mediatek,mt6779-keypad: use unevaluatedProperties Mattijs Korpershoek
2022-07-20 17:14   ` Krzysztof Kozlowski
2022-07-21  9:06     ` Mattijs Korpershoek
2022-07-21  9:16       ` Krzysztof Kozlowski
2022-07-21 13:11         ` Mattijs Korpershoek
2022-07-20 14:48 ` [PATCH v1 3/6] dt-bindings: mediatek,mt6779-keypad: add mediatek,double-keys Mattijs Korpershoek
2022-07-20 17:26   ` Krzysztof Kozlowski
2022-07-21 13:32     ` Mattijs Korpershoek
2022-07-21 13:51       ` Krzysztof Kozlowski
2022-07-21 14:44         ` Mattijs Korpershoek
2022-07-21  8:40   ` AngeloGioacchino Del Regno
2022-07-21 13:34     ` Mattijs Korpershoek
2022-07-20 14:48 ` Mattijs Korpershoek [this message]
2022-07-20 14:53   ` [PATCH v1 4/6] Input: mt6779-keypad - support double keys matrix Matthias Brugger
2022-07-21  8:34   ` AngeloGioacchino Del Regno
2022-07-21 14:51     ` Mattijs Korpershoek
2022-07-21 14:55       ` AngeloGioacchino Del Regno
2022-07-26  9:52         ` Mattijs Korpershoek
2022-07-20 14:48 ` [PATCH v1 5/6] arm64: dts: mediatek: mt8183: add keyboard node Mattijs Korpershoek
2022-07-21  8:41   ` AngeloGioacchino Del Regno
2022-07-20 14:48 ` [PATCH v1 6/6] arm64: dts: mediatek: mt8183-pumpkin: add keypad support Mattijs Korpershoek

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220720-mt8183-keypad-v1-4-ef9fc29dbff4@baylibre.com \
    --to=mkorpershoek@baylibre.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dmitry.torokhov@gmail.com \
    --cc=fparent@baylibre.com \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=matthias.bgg@gmail.com \
    --cc=parent.f@gmail.com \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).