Input: mt6779-keypad - double keys support
Subsystems (5)
v2 cover 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.
---
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,
Signature · 1 line
Mattijs Korpershoek <[email protected]>
PATCH v2 1/7 MAINTAINERS: input: add mattijs for mt6779-keypad
As stated in [1]:
Fengping has no longer interest and time to maintain this driver so he agreed to transfer maintainership over to me.
Add a dedicated maintainer entry as well for the driver to make sure that I can help with patch reviews.
[1] https://lore.kernel.org/r/[email protected]
MAINTAINERS +6 -0
@@ -12805,6 +12805,12 @@ S: Supported F: Documentation/devicetree/bindings/media/mediatek-jpeg-*.yaml F: drivers/media/platform/mediatek/jpeg/ +MEDIATEK KEYPAD DRIVER +M: Mattijs Korpershoek <[email protected]> +S: Supported +F: Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml +F: drivers/input/keyboard/mt6779-keypad.c + MEDIATEK MDP DRIVER M: Minghsiu Tsai <[email protected]> M: Houlong Wei <[email protected]>
Signature · 1 line
b4 0.10.0-dev-78725
PATCH v2 2/7 dt-bindings: mediatek,mt6779-keypad: use unevaluatedProperties
In reply to Mattijs Korpershoekwriting-bindings.rst states:
Quoted 3 lines
- 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
Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml +1 -1
@@ -56,7 +56,7 @@ required: - clocks - clock-names -additionalProperties: false +unevaluatedProperties: false examples: - |
Signature · 1 line
b4 0.10.0-dev-78725
Re: [PATCH v2 2/7] dt-bindings: mediatek,mt6779-keypad: use unevaluatedProperties
Quoted 10 lines · Mattijs Korpershoek
writing-bindings.rststates:Quoted 3 lines
- 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.yamlare valid for the MediaTek keypad:
* keypad,num-rows and keypad,num-cols configure theKP_SELregister
* linux,keymap represents the (at most) 8x8 hardware matrixSigned-off-by Mattijs Korpershoek <[email protected]>
Best regards,
Krzysztof
PATCH v2 3/7 dt-bindings: mediatek,mt6779-keypad: add mediatek,keys-per-group
In reply to Mattijs KorpershoekThe 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.
Documentation/devicetree/bindings/input/mediatek,mt6779-keypad.yaml +6 -0
@@ -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
Signature · 1 line
b4 0.10.0-dev-78725
Re: [PATCH v2 3/7] dt-bindings: mediatek,mt6779-keypad: add mediatek,keys-per-group
Quoted 7 lines · Mattijs Korpershoek
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 keysWith double key, two keys are physically wired to one (row, column) pin. These keys are in the same "group".
Quoted 6 lines
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]>
Best regards,
Krzysztof
PATCH v2 4/7 Input: mt6779-keypad - prepare double keys support with calc_row_col
In reply to Mattijs KorpershoekThe 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.
drivers/input/keyboard/mt6779-keypad.c +12 -2
@@ -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",
Signature · 1 line
b4 0.10.0-dev-78725
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:
Quoted 11 lines
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_colfunction 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]>
PATCH v2 5/7 Input: mt6779-keypad - support double keys matrix
In reply to Mattijs KorpershoekMediaTek 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.
drivers/input/keyboard/mt6779-keypad.c +28 -1
@@ -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,
Signature · 1 line
b4 0.10.0-dev-78725
Re: [PATCH v2 5/7] Input: mt6779-keypad - support double keys matrix
Il 26/07/22 14:56, Mattijs Korpershoek ha scritto:
Quoted 7 lines
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 keysDouble key support exists to minimize cost, since it reduces the number of pins required for physical keys.
Quoted 6 lines
Double key is configured by setting BIT(0) of the
KP_SELregister.Enable double key matrix support based on the mediatek,keys-per-group device tree property.
Signed-off-by Mattijs Korpershoek <[email protected]>
PATCH v2 6/7 arm64: dts: mediatek: mt8183: add keyboard node
In reply to Mattijs KorpershoekFrom: 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.
arch/arm64/boot/dts/mediatek/mt8183.dtsi +9 -0
@@ -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>,
Signature · 1 line
b4 0.10.0-dev-78725
PATCH v2 7/7 arm64: dts: mediatek: mt8183-pumpkin: add keypad support
In reply to Mattijs KorpershoekFrom: 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.
arch/arm64/boot/dts/mediatek/mt8183-pumpkin.dts +21 -0
@@ -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>,
Signature · 1 line
b4 0.10.0-dev-78725
Quoted 10 lines · Mattijs Korpershoek
The MediaTek keypad controller has multiple operating modes:
* single key detection (currently implemented)
* double key detectionWith 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.
Quoted 3 lines
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.
Quoted 33 lines
---
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 supportMattijs 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 withcalc_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-20aa77106ff0Best regards,
Signature · 1 line
Mattijs Korpershoek <[email protected]>
Signature · 1 line
Dmitry
Matthias Brugger
maintainerQuoted 11 lines · Dmitry Torokhov
Quoted 10 lines · Mattijs Korpershoek
The MediaTek keypad controller has multiple operating modes:
* single key detection (currently implemented)
* double key detectionWith 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.
Quoted 6 lines
Quoted 3 lines
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!
Quoted 34 lines
Quoted 33 lines
---
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 supportMattijs 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 withcalc_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-20aa77106ff0Best regards,
Signature · 1 line
Mattijs Korpershoek <[email protected]>