* [PATCH 0/2] Input: mt6779-keypad - fix hw code logic and row/col selection
@ 2022-04-25 14:19 Mattijs Korpershoek
2022-04-25 14:19 ` [PATCH 1/2] Input: mt6779-keypad - fix hardware code mapping Mattijs Korpershoek
2022-04-25 14:19 ` [PATCH 2/2] Input: mt6779-keypad - implement row/column selection Mattijs Korpershoek
0 siblings, 2 replies; 3+ messages in thread
From: Mattijs Korpershoek @ 2022-04-25 14:19 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Matthias Brugger, AngeloGioacchino Del Regno, Kevin Hilman,
Fabien Parent, linux-input, linux-mediatek, linux-arm-kernel,
linux-kernel, Mattijs Korpershoek
This serie is the first follow-up on the mt6779-keypad in
order to enable it on the MediaTek mt8183-pumpkin board.
To fully enable it on mt8183-pumpkin, we still need:
* double key support
* dts changes
To ease up reviewing, I preferred sending this first.
The first patch fixes a logic bug based on the (non-public) datasheet
I have.
The second patch configures the keypad correctly in order to not
report bogus values.
Thank you,
Mattijs
Mattijs Korpershoek (2):
Input: mt6779-keypad - fix hardware code mapping
Input: mt6779-keypad - implement row/column selection
drivers/input/keyboard/mt6779-keypad.c | 26 ++++++++++++++++++++++++--
1 file changed, 24 insertions(+), 2 deletions(-)
base-commit: b243018eafeb69bf074ef013c54504632fd161ec
--
2.32.0
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH 1/2] Input: mt6779-keypad - fix hardware code mapping
2022-04-25 14:19 [PATCH 0/2] Input: mt6779-keypad - fix hw code logic and row/col selection Mattijs Korpershoek
@ 2022-04-25 14:19 ` Mattijs Korpershoek
2022-04-25 14:19 ` [PATCH 2/2] Input: mt6779-keypad - implement row/column selection Mattijs Korpershoek
1 sibling, 0 replies; 3+ messages in thread
From: Mattijs Korpershoek @ 2022-04-25 14:19 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Matthias Brugger, AngeloGioacchino Del Regno, Kevin Hilman,
Fabien Parent, linux-input, linux-mediatek, linux-arm-kernel,
linux-kernel, Mattijs Korpershoek
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 <fparent@baylibre.com>
Signed-off-by: Fabien Parent <fparent@baylibre.com>
Signed-off-by: Mattijs Korpershoek <mkorpershoek@baylibre.com>
---
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);
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] Input: mt6779-keypad - implement row/column selection
2022-04-25 14:19 [PATCH 0/2] Input: mt6779-keypad - fix hw code logic and row/col selection Mattijs Korpershoek
2022-04-25 14:19 ` [PATCH 1/2] Input: mt6779-keypad - fix hardware code mapping Mattijs Korpershoek
@ 2022-04-25 14:19 ` Mattijs Korpershoek
1 sibling, 0 replies; 3+ messages in thread
From: Mattijs Korpershoek @ 2022-04-25 14:19 UTC (permalink / raw)
To: Dmitry Torokhov
Cc: Matthias Brugger, AngeloGioacchino Del Regno, Kevin Hilman,
Fabien Parent, linux-input, linux-mediatek, linux-arm-kernel,
linux-kernel, Mattijs Korpershoek
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 <mkorpershoek@baylibre.com>
---
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);
--
2.32.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2022-04-25 14:19 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-25 14:19 [PATCH 0/2] Input: mt6779-keypad - fix hw code logic and row/col selection Mattijs Korpershoek
2022-04-25 14:19 ` [PATCH 1/2] Input: mt6779-keypad - fix hardware code mapping Mattijs Korpershoek
2022-04-25 14:19 ` [PATCH 2/2] Input: mt6779-keypad - implement row/column selection Mattijs Korpershoek
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).