Re: [PATCH v2 2/2] Input: keyboard: Add Nuvoton MA35D1 keypad driver
From: Dmitry Torokhov
Date: Mon Nov 30 2026 - 15:40:00 EST
Hi Feng-Yi,
On Fri, Nov 13, 2026 at 05:02:29PM +0800, Feng-Yi Hsueh wrote:
> Add 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.
>
> Signed-off-by: Feng-Yi Hsueh <fyhsueh4linux@xxxxxxxxx>
Thank you for the driver, a few comments below.
...
> obj-$(CONFIG_KEYBOARD_LPC32XX) += lpc32xx-keys.o
> +obj-$(CONFIG_KEYBOARD_MA35D1) += ma35d1_keypad.o
Stray space before the tabs.
...
> + int irq;
> + bool running; /* protected by input->mutex */
> +};
Why do we need "running"? Input core pairs open() and close() under
input->mutex on input_device_enabled() transitions, and suspend() and
resume() both check input_device_enabled() while userspace is frozen.
The only case where it makes a difference is if clk_prepare_enable()
fails on resume and a later close() or suspend() calls
ma35d1_keypad_disable() again. If that is what you are guarding against,
please add a brief comment; otherwise please drop it.
...
> +/* Release software key states when hardware scanning is stopped. */
> +static void ma35d1_keypad_release_keys(struct ma35d1_keypad *keypad)
> +{
> + struct input_dev *input = keypad->input;
> + unsigned int row, col, scan, code;
> + bool reported = false;
> +
> + for (row = 0; row < keypad->rows; row++) {
> + for (col = 0; col < keypad->cols; col++) {
> + scan = MATRIX_SCAN_CODE(row, col, keypad->row_shift);
> + code = keypad->keycodes[scan];
> + if (code == KEY_RESERVED || !test_bit(code, input->key))
> + continue;
> +
> + input_event(input, EV_MSC, MSC_SCAN, scan);
> + input_report_key(input, code, 0);
> + reported = true;
> + }
> + }
> +
> + if (reported)
> + input_sync(input);
> +}
Input core already releases pressed keys on suspend, freeze, inhibit,
and disconnect. Only plain close() does not, and scanning keycodes[]
against input->key here will emit a bogus MSC_SCAN if two matrix
positions map to the same keycode (it also checks input->key and
keycodes[] outside input->event_lock). If you want to release keys on
close, dropping the synthetic MSC_SCAN would be cleaner, or you can
just drop this helper and let input core handle it.
...
> + while (events) {
> + bit = __ffs(events);
> + events &= ~BIT(bit);
Making "events" an unsigned long and using
for_each_set_bit(bit, &events, 32) would be cleaner than iterating with
__ffs() manually.
...
> + keypad = devm_kzalloc(dev, sizeof(*keypad), GFP_KERNEL);
Please use devm_kzalloc_obj(dev, *keypad).
...
> + keypad->clk = devm_clk_get(dev, NULL);
> + if (IS_ERR(keypad->clk))
> + return dev_err_probe(dev, PTR_ERR(keypad->clk),
> + "failed to get KPI clock\n");
Patch 1/2 adds an optional "resets" property to the binding, but the
driver does not handle it at all. Should probe acquire and deassert it
with devm_reset_control_get_optional_exclusive_deasserted(), or is there
a reason to leave reset handling out?
Thanks.
--
Dmitry