From c82b38c7be850a6451ef3f897b81241305d302dd Mon Sep 17 00:00:00 2001 From: Fabio Baltieri Date: Thu, 14 Mar 2024 19:50:43 +0000 Subject: [PATCH] input: pmw3610: run the whole init with spi clock on Move the pmw3610_spi_clk_on and pmw3610_spi_clk_off calls so that the "on" call is before the first write. The datasheet calls for doing this before any write operations, though some writes seems to work without this in place, other seems to behave erroneously. The non static functions do it on their own as they can be called separately. Signed-off-by: Fabio Baltieri --- drivers/input/input_pmw3610.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/drivers/input/input_pmw3610.c b/drivers/input/input_pmw3610.c index 5458910be9..bcf55496b2 100644 --- a/drivers/input/input_pmw3610.c +++ b/drivers/input/input_pmw3610.c @@ -376,6 +376,10 @@ static int pmw3610_configure(const struct device *dev) } /* Power-up init sequence */ + ret = pmw3610_spi_clk_on(dev); + if (ret < 0) { + return ret; + } ret = pmw3610_write_reg(dev, PMW3610_OBSERVATION1, 0); if (ret < 0) { @@ -424,11 +428,6 @@ static int pmw3610_configure(const struct device *dev) /* Configuration */ if (cfg->invert_x || cfg->invert_y) { - ret = pmw3610_spi_clk_on(dev); - if (ret < 0) { - return ret; - } - ret = pmw3610_write_reg(dev, PWM3610_SPI_PAGE0, SPI_PAGE0_1); if (ret < 0) { return ret; @@ -452,12 +451,15 @@ static int pmw3610_configure(const struct device *dev) return ret; } - ret = pmw3610_spi_clk_off(dev); - if (ret < 0) { - return ret; - } } + ret = pmw3610_spi_clk_off(dev); + if (ret < 0) { + return ret; + } + + /* The remaining functions call spi_clk_on/off independently. */ + if (cfg->res_cpi > 0) { pmw3610_set_resolution(dev, cfg->res_cpi); }