From 03f1dd413df1d4b92880179e124a641c33ed766d Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Sat, 13 Jul 2024 17:32:58 +0100 Subject: [PATCH] input: paw32xx: only reschedule the handler if motion is asserted The motion event handler is currently setup to always retrigger until there's no more motion data from the sensor. Change that to only retrigger if the motion pin is asserted when the handler has finished running, this saves a bunch of unnecessary spi transactions. Ideally this driver would use a level interrupt, but I'd rather avoid that as that is unsupported by many gpio controllers. Signed-off-by: Fabio Baltieri --- drivers/input/input_paw32xx.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/input/input_paw32xx.c b/drivers/input/input_paw32xx.c index 277da93bd52..be9db7c3394 100644 --- a/drivers/input/input_paw32xx.c +++ b/drivers/input/input_paw32xx.c @@ -221,8 +221,10 @@ static void paw32xx_motion_work_handler(struct k_work *work) input_report_rel(data->dev, cfg->axis_x, x, false, K_FOREVER); input_report_rel(data->dev, cfg->axis_y, y, true, K_FOREVER); - /* Trigger one more scan in case more data is available. */ - k_work_submit(&data->motion_work); + /* Trigger one more scan if more data is available. */ + if (gpio_pin_get_dt(&cfg->motion_gpio)) { + k_work_submit(&data->motion_work); + } } static void paw32xx_motion_handler(const struct device *gpio_dev,