linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mattijs Korpershoek <mkorpershoek@baylibre.com>
To: unlisted-recipients:; (no To-header on input)
Cc: linux-arm-kernel@lists.infradead.org,
	AngeloGioacchino Del Regno 
	<angelogioacchino.delregno@collabora.com>,
	Fabien Parent <fparent@baylibre.com>,
	linux-mediatek@lists.infradead.org, devicetree@vger.kernel.org,
	linux-kernel@vger.kernel.org, linux-input@vger.kernel.org,
	Fabien Parent <parent.f@gmail.com>
Subject: [PATCH v2 5/7] Input: mt6779-keypad - support double keys matrix
Date: Tue, 26 Jul 2022 14:56:10 +0200	[thread overview]
Message-ID: <20220720-mt8183-keypad-v2-5-6d42c357cb76@baylibre.com> (raw)
In-Reply-To: <20220720-mt8183-keypad-v2-0-6d42c357cb76@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,keys-per-group
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 39c931974bde..f70b02396de4 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)
@@ -102,12 +103,21 @@ static void mt6779_keypad_calc_row_col_single(unsigned int key,
 	*col = key % 9;
 }
 
+static void mt6779_keypad_calc_row_col_double(unsigned int key,
+					      unsigned int *row,
+					      unsigned int *col)
+{
+	*row = key / 13;
+	*col = (key % 13) / 2;
+}
+
 static int mt6779_keypad_pdrv_probe(struct platform_device *pdev)
 {
 	struct mt6779_keypad *keypad;
 	void __iomem *base;
 	int irq;
 	u32 debounce;
+	u32 keys_per_group;
 	bool wakeup;
 	int error;
 
@@ -156,7 +166,20 @@ static int mt6779_keypad_pdrv_probe(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	keypad->calc_row_col = mt6779_keypad_calc_row_col_single;
+	if (device_property_read_u32(&pdev->dev, "mediatek,keys-per-group", &keys_per_group))
+		keys_per_group = 1;
+
+	switch (keys_per_group) {
+	case 1:
+		keypad->calc_row_col = mt6779_keypad_calc_row_col_single;
+		break;
+	case 2:
+		keypad->calc_row_col = mt6779_keypad_calc_row_col_double;
+		break;
+	default:
+		dev_err(&pdev->dev, "Invalid keys-per-group: %d\n", keys_per_group);
+		return -EINVAL;
+	}
 
 	wakeup = device_property_read_bool(&pdev->dev, "wakeup-source");
 
@@ -176,6 +199,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 (keys_per_group == 2)
+		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-78725

  parent reply	other threads:[~2022-07-26 12:56 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-26 12:56 [PATCH v2 0/7] Input: mt6779-keypad - double keys support Mattijs Korpershoek
2022-07-26 12:56 ` [PATCH v2 1/7] MAINTAINERS: input: add mattijs for mt6779-keypad Mattijs Korpershoek
2022-07-26 12:56 ` [PATCH v2 2/7] dt-bindings: mediatek,mt6779-keypad: use unevaluatedProperties Mattijs Korpershoek
2022-07-27 10:27   ` Krzysztof Kozlowski
2022-07-26 12:56 ` [PATCH v2 3/7] dt-bindings: mediatek,mt6779-keypad: add mediatek,keys-per-group Mattijs Korpershoek
2022-07-27 10:27   ` Krzysztof Kozlowski
2022-07-26 12:56 ` [PATCH v2 4/7] Input: mt6779-keypad - prepare double keys support with calc_row_col Mattijs Korpershoek
2022-07-27  7:34   ` AngeloGioacchino Del Regno
2022-07-26 12:56 ` Mattijs Korpershoek [this message]
2022-07-27  7:34   ` [PATCH v2 5/7] Input: mt6779-keypad - support double keys matrix AngeloGioacchino Del Regno
2022-07-26 12:56 ` [PATCH v2 6/7] arm64: dts: mediatek: mt8183: add keyboard node Mattijs Korpershoek
2022-07-26 12:56 ` [PATCH v2 7/7] arm64: dts: mediatek: mt8183-pumpkin: add keypad support Mattijs Korpershoek
2022-08-10 22:53 ` [PATCH v2 0/7] Input: mt6779-keypad - double keys support Dmitry Torokhov
2022-08-24 13:55   ` Matthias Brugger

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-v2-5-6d42c357cb76@baylibre.com \
    --to=mkorpershoek@baylibre.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=devicetree@vger.kernel.org \
    --cc=fparent@baylibre.com \
    --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=parent.f@gmail.com \
    /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).