Input: Add Nuvoton MA35D1 keypad support
Subsystems (4)
cover Input: Add Nuvoton MA35D1 keypad support
This series adds support for the Nuvoton MA35D1 hardware matrix keypad controller.
The controller supports up to eight rows and eight columns. It provides key press and release event registers, which the driver handles through the Linux input subsystem.
The driver uses the common clock framework and configures the controller's scanning and debounce parameters using fixed register settings.
The series consists of:
- A device tree binding for the MA35D1 keypad controller.
- An input driver with Kconfig and Makefile integration.
Tested on a Nuvoton MA35D1 board with a 4x1 keypad configuration and a 1 MHz KPI clock.
Tests performed:
- Key press and release events verified using evtest.
- Input device open and close verified using evtest.
An earlier MA35D1 keypad driver was submitted by Ming-jen Chen. This series is a separate v1 submission with a revised implementation, focusing on simpler clock management and hardware event handling
Feng-Yi Hsueh (2):
dt-bindings: input: Add Nuvoton MA35D1 keypad controller
Input: keyboard: Add Nuvoton MA35D1 keypad driver
.../bindings/input/nuvoton,ma35d1-keypad.yaml | 73 ++++ drivers/input/keyboard/Kconfig | 11 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/ma35d1_keypad.c | 405 ++++++++++++++++++ 4 files changed, 490 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml create mode 100644 drivers/input/keyboard/ma35d1_keypad.c
Signature · 1 line
2.43.0
PATCH 1/2 dt-bindings: input: Add Nuvoton MA35D1 keypad controller
Document the Nuvoton MA35D1 hardware matrix keypad controller.
The controller supports up to eight rows and eight columns and generates interrupts for key press and release events.
--- .../bindings/input/nuvoton,ma35d1-keypad.yaml | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml
Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml new file +73 -0
@@ -0,0 +1,73 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/nuvoton,ma35d1-keypad.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton MA35D1 Matrix Keypad Controller + +maintainers: + - Feng-Yi Hsueh <[email protected]> + +description: | + The Nuvoton MA35D1 keypad controller scans a matrix of up to eight rows + and eight columns and reports key press and release interrupts. + +allOf: + - $ref: /schemas/input/matrix-keymap.yaml# + +properties: + compatible: + const: nuvoton,ma35d1-keypad + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + keypad,num-rows: + minimum: 2 + maximum: 8 + + keypad,num-columns: + minimum: 1 + maximum: 8 + + autorepeat: + type: boolean + description: Enable key autorepeat events. + +required: + - compatible + - reg + - interrupts + - clocks + - keypad,num-rows + - keypad,num-columns + - linux,keymap + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/input/input.h> + + keypad@404a0000 { + compatible = "nuvoton,ma35d1-keypad"; + reg = <0x404a0000 0x10000>; + interrupts = <79>; + clocks = <&clk>; + + keypad,num-rows = <4>; + keypad,num-columns = <1>; + linux,keymap = < + MATRIX_KEY(0, 0, KEY_1) + MATRIX_KEY(1, 0, KEY_2) + MATRIX_KEY(2, 0, KEY_3) + MATRIX_KEY(3, 0, KEY_4) + >; + };
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v1 1/2] dt-bindings: input: Add Nuvoton MA35D1 keypad controller
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [Low] dt-bindings: input: ma35d1-keypad: redefine autorepeat instead of input.yaml# - [Low] dt-bindings…
Thank you for your contribution! Sashiko AI review found 3 potential issues to consider:
- [Low] dt-bindings: input: ma35d1-keypad: redefine autorepeat instead of input.yaml#
- [Low] dt-bindings: input: ma35d1-keypad: omit resets property for MA35D1_RESET_KPI
- [Low] dt-bindings: input: ma35d1-keypad: bad clock/IRQ cells and align in example
--
commit 6eade3d3eb06d707c8d9f0ddfa65827ec7270074
Author: Feng-Yi Hsueh <[email protected]>
dt-bindings: input: Add Nuvoton MA35D1 keypad controller
This commit adds the Device Tree binding schema for the Nuvoton MA35D1 matrix keypad controller.
Quoted 6 lines
Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml new file +0
-0@@ -0,0 +1,73 @@
[ ... ]
Quoted 5 lines
Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml new file +5
-0+allOf: + - $ref: /schemas/input/matrix-keymap.yaml# + +properties: + compatible:
Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml line 30
Quoted 10 lines
Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml new file +10
-0+ const: nuvoton,ma35d1-keypad + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1
[Severity: Low]
Should properties also document resets (with maxItems: 1)?
include/dt-bindings/reset/nuvoton,ma35d1-reset.h defines MA35D1_RESET_KPI for this controller, and drivers/reset/reset-ma35d1.c implements it in ma35d1_reset_map. Because this schema sets unevaluatedProperties: false, any board or SoC devicetree node specifying resets = <&sys MA35D1_RESET_KPI> will fail dtbs_check validation.
Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml line 42
Quoted 12 lines
Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml new file +12
-0+ + keypad,num-rows: + minimum: 2 + maximum: 8 + + keypad,num-columns: + minimum: 1 + maximum: 8 + + autorepeat: + type: boolean + description: Enable key autorepeat events.
[Severity: Low]
Should this schema reference input.yaml# in allOf instead of redefining autorepeat locally?
Documentation/devicetree/bindings/input/input.yaml already defines autorepeat with its type and description, so referencing input.yaml# in allOf (and at most listing autorepeat: true here) avoids duplicating the common property definition.
Quoted 21 lines
Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml new file +21
-0+ +required: + - compatible + - reg + - interrupts + - clocks + - keypad,num-rows + - keypad,num-columns + - linux,keymap + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/input/input.h> + + keypad@404a0000 { + compatible = "nuvoton,ma35d1-keypad"; + reg = <0x404a0000 0x10000>; + interrupts = <79>; + clocks = <&clk>;
Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml line 73
Quoted 10 lines
Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml new file +10
-0+ + keypad,num-rows = <4>; + keypad,num-columns = <1>; + linux,keymap = < + MATRIX_KEY(0, 0, KEY_1) + MATRIX_KEY(1, 0, KEY_2) + MATRIX_KEY(2, 0, KEY_3) + MATRIX_KEY(3, 0, KEY_4) + >; + };
[Severity: Low]
Should the example include the GIC interrupt specifier and the KPI_GATE clock cell, and align the linux,keymap entries?
On MA35D1, the interrupt controller uses three GIC cells (such as <GIC_SPI 79 IRQ_TYPE_LEVEL_HIGH>) and &clk takes a clock specifier cell (<&clk KPI_GATE> from dt-bindings/clock/nuvoton,ma35d1-clk.h). Also, the multi-line linux,keymap entries are indented by four extra spaces rather than aligned with the opening bracket, which triggers continuation-alignment warnings from scripts/dtc/dt-check-style --mode=strict.
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH v1 1/2] dt-bindings: input: Add Nuvoton MA35D1 keypad controller
In reply to Feng-Yi HsuehQuoted 6 lines · Feng-Yi Hsueh
Document the Nuvoton MA35D1 hardware matrix keypad controller.
The controller supports up to eight rows and eight columns and generates interrupts for key press and release events.
Signed-off-by Feng-Yi Hsueh <[email protected]>
Most of what the bot says seems valid to implement,
pw-bot: changes-requested
Thanks,
Conor.
Quoted 87 lines
--- .../bindings/input/nuvoton,ma35d1-keypad.yaml | 73 +++++++++++++++++++ 1 file changed, 73 insertions(+) create mode 100644 Documentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yamlDocumentation/devicetree/bindings/input/nuvoton,ma35d1-keypad.yaml new file +73
-0@@ -0,0 +1,73 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/input/nuvoton,ma35d1-keypad.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Nuvoton MA35D1 Matrix Keypad Controller + +maintainers: + - Feng-Yi Hsueh <[email protected]> + +description: | + The Nuvoton MA35D1 keypad controller scans a matrix of up to eight rows + and eight columns and reports key press and release interrupts. + +allOf: + - $ref: /schemas/input/matrix-keymap.yaml# + +properties: + compatible: + const: nuvoton,ma35d1-keypad + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + keypad,num-rows: + minimum: 2 + maximum: 8 + + keypad,num-columns: + minimum: 1 + maximum: 8 + + autorepeat: + type: boolean + description: Enable key autorepeat events. + +required: + - compatible + - reg + - interrupts + - clocks + - keypad,num-rows + - keypad,num-columns + - linux,keymap + +unevaluatedProperties: false + +examples: + - | + #include <dt-bindings/input/input.h> + + keypad@404a0000 { + compatible = "nuvoton,ma35d1-keypad"; + reg = <0x404a0000 0x10000>; + interrupts = <79>; + clocks = <&clk>; + + keypad,num-rows = <4>; + keypad,num-columns = <1>; + linux,keymap = < + MATRIX_KEY(0, 0, KEY_1) + MATRIX_KEY(1, 0, KEY_2) + MATRIX_KEY(2, 0, KEY_3) + MATRIX_KEY(3, 0, KEY_4) + >; + };Signature · 1 line
2.43.0
PATCH 2/2 Input: keyboard: Add Nuvoton MA35D1 keypad driver
In reply to Feng-Yi HsuehAdd support for the Nuvoton MA35D1 hardware matrix keypad controller.
The driver handles key press and release interrupts, reports key events through the Linux input subsystem, and manages the peripheral clock during device open, close, and system suspend and resume.
--- drivers/input/keyboard/Kconfig | 11 + drivers/input/keyboard/Makefile | 1 + drivers/input/keyboard/ma35d1_keypad.c | 405 +++++++++++++++++++++++++ 3 files changed, 417 insertions(+) create mode 100644 drivers/input/keyboard/ma35d1_keypad.c
drivers/input/keyboard/Kconfig +11 -0
@@ -358,6 +358,17 @@ config KEYBOARD_LPC32XX To compile this driver as a module, choose M here: the module will be called lpc32xx-keys. +config KEYBOARD_MA35D1 + tristate "Nuvoton MA35D1 keypad controller" + depends on ARCH_MA35 || COMPILE_TEST + select INPUT_MATRIXKMAP + help + Say Y here to enable support for the Nuvoton MA35D1 + hardware matrix keypad controller. + + To compile this driver as a module, choose M here. + The module will be called ma35d1_keypad. + config KEYBOARD_MAPLE tristate "Maple bus keyboard" depends on SH_DREAMCAST && MAPLE
drivers/input/keyboard/Makefile +1 -0
@@ -39,6 +39,7 @@ obj-$(CONFIG_KEYBOARD_LM8323) += lm8323.o obj-$(CONFIG_KEYBOARD_LM8333) += lm8333.o obj-$(CONFIG_KEYBOARD_LOCOMO) += locomokbd.o obj-$(CONFIG_KEYBOARD_LPC32XX) += lpc32xx-keys.o +obj-$(CONFIG_KEYBOARD_MA35D1) += ma35d1_keypad.o obj-$(CONFIG_KEYBOARD_MAPLE) += maple_keyb.o obj-$(CONFIG_KEYBOARD_MATRIX) += matrix_keypad.o obj-$(CONFIG_KEYBOARD_MAX7359) += max7359_keypad.o
drivers/input/keyboard/ma35d1_keypad.c new file +405 -0
405 lines not on this page · raw message
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH v1 2/2] Input: keyboard: Add Nuvoton MA35D1 keypad driver
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider: - [Low] Input: ma35d1_keypad - use guard(mutex) in suspend and resume callbacks - [Low] Input: ma35d1_keypad…
Thank you for your contribution! Sashiko AI review found 2 potential issues to consider:
- [Low] Input: ma35d1_keypad - use guard(mutex) in suspend and resume callbacks
- [Low] Input: ma35d1_keypad - name errno variables error and return 0 explicitly
--
commit ca9c8a019e4d03872087b6ba2c747cf4ce6faf45
Author: Feng-Yi Hsueh <[email protected]>
Input: keyboard: Add Nuvoton MA35D1 keypad driver
This commit adds an input driver for the Nuvoton MA35D1 hardware matrix keypad controller, handling key press/release interrupts, input event reporting, and clock management across open, close, suspend, and resume.
Quoted 5 lines
drivers/input/keyboard/ma35d1_keypad.c new file +0
-0
[ ... ]
drivers/input/keyboard/ma35d1_keypad.c line 133
Quoted 11 lines
drivers/input/keyboard/ma35d1_keypad.c new file +11
-0+/* Called with input->mutex held (open, PM resume). */ +static int ma35d1_keypad_enable (struct ma35d1_keypad *keypad) +{ +int ret; + +if (keypad->running) +return 0 ; + + ret =clk_prepare_enable (keypad->clk); +if (ret) +return ret;
[Severity: Low]
This isn't a bug, but in the input subsystem, variables that only hold 0 or a negative error code are conventionally named error or err rather than ret. The same applies to ma35d1_keypad_resume() and ma35d1_keypad_probe(), and ma35d1_keypad_resume() should also explicitly return 0 on the success path rather than returning the error variable directly.
[ ... ]
Quoted 16 lines
drivers/input/keyboard/ma35d1_keypad.c new file +16
-0+static int ma35d1_keypad_suspend (struct device *dev) +{ +struct ma35d1_keypad *keypad =dev_get_drvdata (dev); +struct input_dev *input = keypad->input; + +mutex_lock (&input->mutex); +if (input_device_enabled (input)) +ma35d1_keypad_disable (keypad); +mutex_unlock (&input->mutex); + +return 0 ; +} + +static int ma35d1_keypad_resume (struct device *dev) +{ +struct ma35d1_keypad *keypad =dev_get_drvdata (dev);
drivers/input/keyboard/ma35d1_keypad.c line 293
Quoted 10 lines
drivers/input/keyboard/ma35d1_keypad.c new file +10
-0+struct input_dev *input = keypad->input; +int ret =0 ; + +mutex_lock (&input->mutex); +if (input_device_enabled (input)) + ret =ma35d1_keypad_enable (keypad); +mutex_unlock (&input->mutex); + +return ret; +}
[Severity: Low]
This isn't a bug, but new input drivers prefer guard(mutex)(&input->mutex) over manual mutex_lock() and mutex_unlock() calls in ma35d1_keypad_suspend() and ma35d1_keypad_resume().
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=2
Re: [PATCH v1 2/2] Input: keyboard: Add Nuvoton MA35D1 keypad driver
In reply to Feng-Yi Hsuehdrivers/input/keyboard/ma35d1_keypad.c line 18
Quoted 3 lines · Feng-Yi Hsueh
drivers/input/keyboard/ma35d1_keypad.c new file +2
-0+#include <linux/mod_devicetable.h> +#include <linux/platform_device.h>
Please don't include <linux/mod_devicetable.h> as it introduces a bunch of unneeded build dependencies. <linux/platform_device.h> is sufficient to get of_device_id.
Best regards
Uwe