iio: light: cm3232: Reset before reading HW ID
authorCibil Pankiras <cibil.pankiras@aerq.com>
Thu, 14 Nov 2024 09:13:23 +0000 (10:13 +0100)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Sat, 7 Dec 2024 17:47:58 +0000 (17:47 +0000)
According to the datasheet, the chip requires a reset before any data
can be read. This commit moves the device identification logic to
occur after the reset to ensure proper initialization.

Cc: Kevin Tsai <ktsai@capellamicro.com>
Signed-off-by: Cibil Pankiras <cibil.pankiras@aerq.com>
Link: https://patch.msgid.link/20241114091323.7415-1-cibil.pankiras@aerq.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/light/cm3232.c

index b6288dd25bbff35a7efeef9f682587bc4b5e8976..5b00ad2a014e9945d92b14ce5ea141ba6ac4e743 100644 (file)
@@ -89,6 +89,15 @@ static int cm3232_reg_init(struct cm3232_chip *chip)
 
        chip->als_info = &cm3232_als_info_default;
 
+       /* Disable and reset device */
+       chip->regs_cmd = CM3232_CMD_ALS_DISABLE | CM3232_CMD_ALS_RESET;
+       ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD,
+                                       chip->regs_cmd);
+       if (ret < 0) {
+               dev_err(&chip->client->dev, "Error writing reg_cmd\n");
+               return ret;
+       }
+
        /* Identify device */
        ret = i2c_smbus_read_word_data(client, CM3232_REG_ADDR_ID);
        if (ret < 0) {
@@ -99,15 +108,6 @@ static int cm3232_reg_init(struct cm3232_chip *chip)
        if ((ret & 0xFF) != chip->als_info->hw_id)
                return -ENODEV;
 
-       /* Disable and reset device */
-       chip->regs_cmd = CM3232_CMD_ALS_DISABLE | CM3232_CMD_ALS_RESET;
-       ret = i2c_smbus_write_byte_data(client, CM3232_REG_ADDR_CMD,
-                                       chip->regs_cmd);
-       if (ret < 0) {
-               dev_err(&chip->client->dev, "Error writing reg_cmd\n");
-               return ret;
-       }
-
        /* Register default value */
        chip->regs_cmd = chip->als_info->regs_cmd_default;