2022-07-26 12:58:16

by Mattijs Korpershoek

[permalink] [raw]
Subject: [PATCH v2 0/7] Input: mt6779-keypad - double keys support

The MediaTek keypad controller has multiple operating modes:
* single key detection (currently implemented)
* double key detection

With double key detection, each (row,column) is a group that can detect
two keys in the key matrix.
This minimizes the overall pin counts for cost reduction.
However, pressing multiple keys in the same group will not be
detected properly.

On some boards, like mt8183-pumpkin, double key detection is used.

Signed-off-by: Mattijs Korpershoek <[email protected]>

---
Changes in v2:
- bindings: add matrix-keymap justification in commit message (Krzysztof)
- bindings: switch from double-keys(boolean) to keys-per-group(uint32) (Krzysztof)
- driver: add a function pointer for row/column calculation (Angelo)
- Link to v1: https://lore.kernel.org/r/[email protected]

---
Fabien Parent (2):
arm64: dts: mediatek: mt8183: add keyboard node
arm64: dts: mediatek: mt8183-pumpkin: add keypad support

Mattijs Korpershoek (5):
MAINTAINERS: input: add mattijs for mt6779-keypad
dt-bindings: mediatek,mt6779-keypad: use unevaluatedProperties
dt-bindings: mediatek,mt6779-keypad: add mediatek,keys-per-group
Input: mt6779-keypad - prepare double keys support with calc_row_col
Input: mt6779-keypad - support double keys matrix

.../bindings/input/mediatek,mt6779-keypad.yaml | 8 ++++-
MAINTAINERS | 6 ++++
arch/arm64/boot/dts/mediatek/mt8183-pumpkin.dts | 21 +++++++++++
arch/arm64/boot/dts/mediatek/mt8183.dtsi | 9 +++++
drivers/input/keyboard/mt6779-keypad.c | 41 ++++++++++++++++++++--
5 files changed, 82 insertions(+), 3 deletions(-)
---
base-commit: 668af1b6548837b44a2bfe65dcbae6b250adbf63
change-id: 20220720-mt8183-keypad-20aa77106ff0

Best regards,
--
Mattijs Korpershoek <[email protected]>


2022-07-26 12:58:46

by Mattijs Korpershoek

[permalink] [raw]
Subject: [PATCH v2 7/7] arm64: dts: mediatek: mt8183-pumpkin: add keypad support

From: Fabien Parent <[email protected]>

Add device-tree bindings for the keypad driver on the MT8183 Pumpkin
board.

The MT8183 Pumpkin board has 2 buttons connected using: KPROW0,
KPROW1 and KPCOL0.

Signed-off-by: Fabien Parent <[email protected]>
Signed-off-by: Mattijs Korpershoek <[email protected]>

diff --git a/arch/arm64/boot/dts/mediatek/mt8183-pumpkin.dts b/arch/arm64/boot/dts/mediatek/mt8183-pumpkin.dts
index 530e0c9ce0c9..a1d01639df30 100644
--- a/arch/arm64/boot/dts/mediatek/mt8183-pumpkin.dts
+++ b/arch/arm64/boot/dts/mediatek/mt8183-pumpkin.dts
@@ -7,6 +7,7 @@
/dts-v1/;

#include <dt-bindings/gpio/gpio.h>
+#include <dt-bindings/input/input.h>
#include "mt8183.dtsi"
#include "mt6358.dtsi"

@@ -122,6 +123,18 @@ &i2c6 {
clock-frequency = <100000>;
};

+&keyboard {
+ pinctrl-names = "default";
+ pinctrl-0 = <&keyboard_pins>;
+ status = "okay";
+ linux,keymap = <MATRIX_KEY(0x00, 0x00, KEY_VOLUMEDOWN)
+ MATRIX_KEY(0x01, 0x00, KEY_VOLUMEUP)>;
+ keypad,num-rows = <2>;
+ keypad,num-columns = <1>;
+ debounce-delay-ms = <32>;
+ mediatek,keys-per-group = <2>;
+};
+
&mmc0 {
status = "okay";
pinctrl-names = "default", "state_uhs";
@@ -226,6 +239,14 @@ pins_cmd_dat {
};
};

+ keyboard_pins: keyboard {
+ pins_keyboard {
+ pinmux = <PINMUX_GPIO91__FUNC_KPROW1>,
+ <PINMUX_GPIO92__FUNC_KPROW0>,
+ <PINMUX_GPIO93__FUNC_KPCOL0>;
+ };
+ };
+
mmc0_pins_default: mmc0-pins-default {
pins_cmd_dat {
pinmux = <PINMUX_GPIO123__FUNC_MSDC0_DAT0>,

--
b4 0.10.0-dev-78725

2022-07-26 12:58:55

by Mattijs Korpershoek

[permalink] [raw]
Subject: [PATCH v2 6/7] arm64: dts: mediatek: mt8183: add keyboard node

From: Fabien Parent <[email protected]>

MT8183 has an on-SoC keyboard controller commonly used for volume
up/down buttons.

List it in the SoC dts so that boards can enable/use it.

Signed-off-by: Fabien Parent <[email protected]>
Signed-off-by: Mattijs Korpershoek <[email protected]>
Reviewed-by: AngeloGioacchino Del Regno <[email protected]>

diff --git a/arch/arm64/boot/dts/mediatek/mt8183.dtsi b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
index 9d32871973a2..9d8fdebaabe3 100644
--- a/arch/arm64/boot/dts/mediatek/mt8183.dtsi
+++ b/arch/arm64/boot/dts/mediatek/mt8183.dtsi
@@ -943,6 +943,15 @@ pwrap: pwrap@1000d000 {
clock-names = "spi", "wrap";
};

+ keyboard: keyboard@10010000 {
+ compatible = "mediatek,mt6779-keypad";
+ reg = <0 0x10010000 0 0x1000>;
+ interrupts = <GIC_SPI 186 IRQ_TYPE_EDGE_FALLING>;
+ clocks = <&clk26m>;
+ clock-names = "kpd";
+ status = "disabled";
+ };
+
scp: scp@10500000 {
compatible = "mediatek,mt8183-scp";
reg = <0 0x10500000 0 0x80000>,

--
b4 0.10.0-dev-78725

2022-07-26 13:04:29

by Mattijs Korpershoek

[permalink] [raw]
Subject: [PATCH v2 2/7] dt-bindings: mediatek,mt6779-keypad: use unevaluatedProperties

writing-bindings.rst states:
> - If schema includes other schema (e.g. /schemas/i2c/i2c-controller.yaml) use
> "unevaluatedProperties:false". In other cases, usually use
> "additionalProperties:false".

All 3 properties from matrix-keymap.yaml are valid for the MediaTek keypad:
* keypad,num-rows and keypad,num-cols configure the KP_SEL register
* linux,keymap represents the (at most) 8x8 hardware matrix

Signed-off-by: Mattijs Korpershoek <[email protected]>

diff --git a/Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml b/Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml
index 03ebd2665d07..ca8ae40a73f7 100644
--- a/Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml
+++ b/Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml
@@ -56,7 +56,7 @@ required:
- clocks
- clock-names

-additionalProperties: false
+unevaluatedProperties: false

examples:
- |

--
b4 0.10.0-dev-78725

2022-07-26 13:05:14

by Mattijs Korpershoek

[permalink] [raw]
Subject: [PATCH v2 4/7] Input: mt6779-keypad - prepare double keys support with calc_row_col

The MediaTek keypad can operate in two modes: single key or double key.
The driver only supports single key mode. In double key mode, the
row/column calculation based on the key is different.

Add a calc_row_col function pointer which will be different based on
single/double key mode.

No functional change.

Suggested-by: AngeloGioacchino Del Regno <[email protected]>
Signed-off-by: Mattijs Korpershoek <[email protected]>

diff --git a/drivers/input/keyboard/mt6779-keypad.c b/drivers/input/keyboard/mt6779-keypad.c
index bf447bf598fb..39c931974bde 100644
--- a/drivers/input/keyboard/mt6779-keypad.c
+++ b/drivers/input/keyboard/mt6779-keypad.c
@@ -31,6 +31,7 @@ struct mt6779_keypad {
struct clk *clk;
u32 n_rows;
u32 n_cols;
+ void (*calc_row_col)(unsigned int key, unsigned int *row, unsigned int *col);
DECLARE_BITMAP(keymap_state, MTK_KPD_NUM_BITS);
};

@@ -67,8 +68,7 @@ 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;
+ keypad->calc_row_col(key, &row, &col);

scancode = MATRIX_SCAN_CODE(row, col, row_shift);
/* 1: not pressed, 0: pressed */
@@ -94,6 +94,14 @@ static void mt6779_keypad_clk_disable(void *data)
clk_disable_unprepare(data);
}

+static void mt6779_keypad_calc_row_col_single(unsigned int key,
+ unsigned int *row,
+ unsigned int *col)
+{
+ *row = key / 9;
+ *col = key % 9;
+}
+
static int mt6779_keypad_pdrv_probe(struct platform_device *pdev)
{
struct mt6779_keypad *keypad;
@@ -148,6 +156,8 @@ static int mt6779_keypad_pdrv_probe(struct platform_device *pdev)
return -EINVAL;
}

+ keypad->calc_row_col = mt6779_keypad_calc_row_col_single;
+
wakeup = device_property_read_bool(&pdev->dev, "wakeup-source");

dev_dbg(&pdev->dev, "n_row=%d n_col=%d debounce=%d\n",

--
b4 0.10.0-dev-78725

2022-07-26 13:08:53

by Mattijs Korpershoek

[permalink] [raw]
Subject: [PATCH v2 5/7] Input: mt6779-keypad - support double keys matrix

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 <[email protected]>

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

2022-07-26 13:17:42

by Mattijs Korpershoek

[permalink] [raw]
Subject: [PATCH v2 3/7] dt-bindings: mediatek,mt6779-keypad: add mediatek,keys-per-group

The 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

With double key, two keys are physically wired to one (row, column) pin.
These keys are in the same "group".

Multiple keys in the same group reduces the number of pins which
minimizes cost.

Add a keys-per-group property to describe this.

Signed-off-by: Mattijs Korpershoek <[email protected]>

diff --git a/Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml b/Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml
index ca8ae40a73f7..387d0448ff77 100644
--- a/Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml
+++ b/Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml
@@ -49,6 +49,12 @@ properties:
maximum: 256
default: 16

+ mediatek,keys-per-group:
+ description: each (row, column) group has multiple keys
+ $ref: /schemas/types.yaml#/definitions/uint32
+ default: 1
+ maximum: 2
+
required:
- compatible
- reg

--
b4 0.10.0-dev-78725

Subject: Re: [PATCH v2 5/7] Input: mt6779-keypad - support double keys matrix

Il 26/07/22 14:56, Mattijs Korpershoek ha scritto:
> 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 <[email protected]>

Reviewed-by: AngeloGioacchino Del Regno <[email protected]>

Subject: Re: [PATCH v2 4/7] Input: mt6779-keypad - prepare double keys support with calc_row_col

Il 26/07/22 14:56, Mattijs Korpershoek ha scritto:
> The MediaTek keypad can operate in two modes: single key or double key.
> The driver only supports single key mode. In double key mode, the
> row/column calculation based on the key is different.
>
> Add a calc_row_col function pointer which will be different based on
> single/double key mode.
>
> No functional change.
>
> Suggested-by: AngeloGioacchino Del Regno <[email protected]>
> Signed-off-by: Mattijs Korpershoek <[email protected]>

Reviewed-by: AngeloGioacchino Del Regno <[email protected]>

2022-07-27 10:41:17

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH v2 2/7] dt-bindings: mediatek,mt6779-keypad: use unevaluatedProperties

On 26/07/2022 14:56, Mattijs Korpershoek wrote:
> writing-bindings.rst states:
>> - If schema includes other schema (e.g. /schemas/i2c/i2c-controller.yaml) use
>> "unevaluatedProperties:false". In other cases, usually use
>> "additionalProperties:false".
>
> All 3 properties from matrix-keymap.yaml are valid for the MediaTek keypad:
> * keypad,num-rows and keypad,num-cols configure the KP_SEL register
> * linux,keymap represents the (at most) 8x8 hardware matrix
>
> Signed-off-by: Mattijs Korpershoek <[email protected]>


Reviewed-by: Krzysztof Kozlowski <[email protected]>


Best regards,
Krzysztof

2022-07-27 10:56:29

by Krzysztof Kozlowski

[permalink] [raw]
Subject: Re: [PATCH v2 3/7] dt-bindings: mediatek,mt6779-keypad: add mediatek,keys-per-group

On 26/07/2022 14:56, Mattijs Korpershoek wrote:
> The 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
>
> With double key, two keys are physically wired to one (row, column) pin.
> These keys are in the same "group".
>
> Multiple keys in the same group reduces the number of pins which
> minimizes cost.
>
> Add a keys-per-group property to describe this.
>
> Signed-off-by: Mattijs Korpershoek <[email protected]>


Reviewed-by: Krzysztof Kozlowski <[email protected]>


Best regards,
Krzysztof

2022-08-10 23:34:43

by Dmitry Torokhov

[permalink] [raw]
Subject: Re: [PATCH v2 0/7] Input: mt6779-keypad - double keys support

On Tue, Jul 26, 2022 at 02:56:05PM +0200, Mattijs Korpershoek wrote:
> The MediaTek keypad controller has multiple operating modes:
> * single key detection (currently implemented)
> * double key detection
>
> With double key detection, each (row,column) is a group that can detect
> two keys in the key matrix.
> This minimizes the overall pin counts for cost reduction.
> However, pressing multiple keys in the same group will not be
> detected properly.
>
> On some boards, like mt8183-pumpkin, double key detection is used.
>
> Signed-off-by: Mattijs Korpershoek <[email protected]>

Applied patches 1 through 5 (leaving dts patches out), thank you.

>
> ---
> Changes in v2:
> - bindings: add matrix-keymap justification in commit message (Krzysztof)
> - bindings: switch from double-keys(boolean) to keys-per-group(uint32) (Krzysztof)
> - driver: add a function pointer for row/column calculation (Angelo)
> - Link to v1: https://lore.kernel.org/r/[email protected]
>
> ---
> Fabien Parent (2):
> arm64: dts: mediatek: mt8183: add keyboard node
> arm64: dts: mediatek: mt8183-pumpkin: add keypad support
>
> Mattijs Korpershoek (5):
> MAINTAINERS: input: add mattijs for mt6779-keypad
> dt-bindings: mediatek,mt6779-keypad: use unevaluatedProperties
> dt-bindings: mediatek,mt6779-keypad: add mediatek,keys-per-group
> Input: mt6779-keypad - prepare double keys support with calc_row_col
> Input: mt6779-keypad - support double keys matrix
>
> .../bindings/input/mediatek,mt6779-keypad.yaml | 8 ++++-
> MAINTAINERS | 6 ++++
> arch/arm64/boot/dts/mediatek/mt8183-pumpkin.dts | 21 +++++++++++
> arch/arm64/boot/dts/mediatek/mt8183.dtsi | 9 +++++
> drivers/input/keyboard/mt6779-keypad.c | 41 ++++++++++++++++++++--
> 5 files changed, 82 insertions(+), 3 deletions(-)
> ---
> base-commit: 668af1b6548837b44a2bfe65dcbae6b250adbf63
> change-id: 20220720-mt8183-keypad-20aa77106ff0
>
> Best regards,
> --
> Mattijs Korpershoek <[email protected]>

--
Dmitry

2022-08-24 14:12:09

by Matthias Brugger

[permalink] [raw]
Subject: Re: [PATCH v2 0/7] Input: mt6779-keypad - double keys support



On 11/08/2022 00:53, Dmitry Torokhov wrote:
> On Tue, Jul 26, 2022 at 02:56:05PM +0200, Mattijs Korpershoek wrote:
>> The MediaTek keypad controller has multiple operating modes:
>> * single key detection (currently implemented)
>> * double key detection
>>
>> With double key detection, each (row,column) is a group that can detect
>> two keys in the key matrix.
>> This minimizes the overall pin counts for cost reduction.
>> However, pressing multiple keys in the same group will not be
>> detected properly.
>>
>> On some boards, like mt8183-pumpkin, double key detection is used.
>>
>> Signed-off-by: Mattijs Korpershoek <[email protected]>
>
> Applied patches 1 through 5 (leaving dts patches out), thank you.
>

Applied 6 and 7 now. Thanks!

>>
>> ---
>> Changes in v2:
>> - bindings: add matrix-keymap justification in commit message (Krzysztof)
>> - bindings: switch from double-keys(boolean) to keys-per-group(uint32) (Krzysztof)
>> - driver: add a function pointer for row/column calculation (Angelo)
>> - Link to v1: https://lore.kernel.org/r/[email protected]
>>
>> ---
>> Fabien Parent (2):
>> arm64: dts: mediatek: mt8183: add keyboard node
>> arm64: dts: mediatek: mt8183-pumpkin: add keypad support
>>
>> Mattijs Korpershoek (5):
>> MAINTAINERS: input: add mattijs for mt6779-keypad
>> dt-bindings: mediatek,mt6779-keypad: use unevaluatedProperties
>> dt-bindings: mediatek,mt6779-keypad: add mediatek,keys-per-group
>> Input: mt6779-keypad - prepare double keys support with calc_row_col
>> Input: mt6779-keypad - support double keys matrix
>>
>> .../bindings/input/mediatek,mt6779-keypad.yaml | 8 ++++-
>> MAINTAINERS | 6 ++++
>> arch/arm64/boot/dts/mediatek/mt8183-pumpkin.dts | 21 +++++++++++
>> arch/arm64/boot/dts/mediatek/mt8183.dtsi | 9 +++++
>> drivers/input/keyboard/mt6779-keypad.c | 41 ++++++++++++++++++++--
>> 5 files changed, 82 insertions(+), 3 deletions(-)
>> ---
>> base-commit: 668af1b6548837b44a2bfe65dcbae6b250adbf63
>> change-id: 20220720-mt8183-keypad-20aa77106ff0
>>
>> Best regards,
>> --
>> Mattijs Korpershoek <[email protected]>
>