]> www.infradead.org Git - users/jedix/linux-maple.git/commitdiff
iio: proximity: vl53l0x-i2c: Added sensor ID check
authorAbhash Jha <abhashkumarjha123@gmail.com>
Mon, 9 Sep 2024 10:15:06 +0000 (15:45 +0530)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 30 Sep 2024 08:21:03 +0000 (09:21 +0100)
The commit adds a check for the sensor's model ID. We read the model
identification register (0xC0) and expect a value of 0xEE.

Signed-off-by: Abhash Jha <abhashkumarjha123@gmail.com>
Link: https://patch.msgid.link/20240909101508.263085-2-abhashkumarjha123@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/proximity/vl53l0x-i2c.c

index 8d4f3f849fe246370f34d6c4b0a4dbaf90204d6a..3f416d3db058af7d59c7d734b130c32cba2dc1cf 100644 (file)
 
 #define VL_REG_RESULT_INT_STATUS                       0x13
 #define VL_REG_RESULT_RANGE_STATUS                     0x14
+#define VL_REG_IDENTIFICATION_MODEL_ID                 0xC0
 #define VL_REG_RESULT_RANGE_STATUS_COMPLETE            BIT(0)
 
+#define VL53L0X_MODEL_ID_VAL                           0xEE
+
 struct vl53l0x_data {
        struct i2c_client *client;
        struct completion completion;
@@ -223,6 +226,7 @@ static int vl53l0x_probe(struct i2c_client *client)
        struct vl53l0x_data *data;
        struct iio_dev *indio_dev;
        int error;
+       int ret;
 
        indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
        if (!indio_dev)
@@ -237,6 +241,13 @@ static int vl53l0x_probe(struct i2c_client *client)
                                     I2C_FUNC_SMBUS_BYTE_DATA))
                return -EOPNOTSUPP;
 
+       ret = i2c_smbus_read_byte_data(data->client, VL_REG_IDENTIFICATION_MODEL_ID);
+       if (ret < 0)
+               return -EINVAL;
+
+       if (ret != VL53L0X_MODEL_ID_VAL)
+               dev_info(&client->dev, "Unknown model id: 0x%x", ret);
+
        data->vdd_supply = devm_regulator_get(&client->dev, "vdd");
        if (IS_ERR(data->vdd_supply))
                return dev_err_probe(&client->dev, PTR_ERR(data->vdd_supply),
@@ -265,8 +276,6 @@ static int vl53l0x_probe(struct i2c_client *client)
 
        /* usage of interrupt is optional */
        if (client->irq) {
-               int ret;
-
                init_completion(&data->completion);
 
                ret = vl53l0x_configure_irq(client, indio_dev);