From 988e3ddd595644a2ee0953d64d9a8c6d65f54b00 Mon Sep 17 00:00:00 2001 From: Dmitry Torokhov Date: Fri, 3 Jul 2026 22:57:30 -0700 Subject: [PATCH] Input: maple_keyb - implement open and close methods Instead of polling the keyboard constantly from probe, implement open and close methods for the input device to only start polling when the device is actually opened by userspace, and stop polling when it is closed. This matches the behavior of maplemouse and maplecontrol drivers. Assisted-by: Antigravity:gemini-3.5-flash Link: https://patch.msgid.link/20260703-b4-maple-cleanup-v1-7-41e424964da5@gmail.com Signed-off-by: Dmitry Torokhov --- drivers/input/keyboard/maple_keyb.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/input/keyboard/maple_keyb.c b/drivers/input/keyboard/maple_keyb.c index 3d5538dd4f23..7039fdf42915 100644 --- a/drivers/input/keyboard/maple_keyb.c +++ b/drivers/input/keyboard/maple_keyb.c @@ -140,6 +140,24 @@ static void dc_kbd_callback(struct mapleq *mq) } } +static int dc_kbd_open(struct input_dev *dev) +{ + struct maple_device *mdev = input_get_drvdata(dev); + + /* Maple polling is locked to VBLANK - which may be just 50/s */ + maple_getcond_callback(mdev, dc_kbd_callback, HZ / 50, + MAPLE_FUNC_KEYBOARD); + + return 0; +} + +static void dc_kbd_close(struct input_dev *dev) +{ + struct maple_device *mdev = input_get_drvdata(dev); + + maple_getcond_callback(mdev, NULL, 0, MAPLE_FUNC_KEYBOARD); +} + static int probe_maple_kbd(struct device *dev) { struct maple_device *mdev; @@ -167,6 +185,7 @@ static int probe_maple_kbd(struct device *dev) memcpy(kbd->keycode, dc_kbd_keycode, sizeof(kbd->keycode)); maple_set_drvdata(mdev, kbd); + input_set_drvdata(idev, mdev); idev->name = mdev->product_name; idev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP); @@ -175,6 +194,8 @@ static int probe_maple_kbd(struct device *dev) idev->keycodemax = ARRAY_SIZE(kbd->keycode); idev->id.bustype = BUS_HOST; idev->dev.parent = &mdev->dev; + idev->open = dc_kbd_open; + idev->close = dc_kbd_close; for (i = 0; i < NR_SCANCODES; i++) __set_bit(dc_kbd_keycode[i], idev->keybit); @@ -186,10 +207,6 @@ static int probe_maple_kbd(struct device *dev) if (error) goto fail_register; - /* Maple polling is locked to VBLANK - which may be just 50/s */ - maple_getcond_callback(mdev, dc_kbd_callback, HZ/50, - MAPLE_FUNC_KEYBOARD); - mdev->driver = mdrv; return error;