Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: proximity: vl53l0x-i2c: Added sensor ID check

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>

authored by

Abhash Jha and committed by
Jonathan Cameron
962b48d4 3ea51548

+11 -2
+11 -2
drivers/iio/proximity/vl53l0x-i2c.c
··· 39 39 40 40 #define VL_REG_RESULT_INT_STATUS 0x13 41 41 #define VL_REG_RESULT_RANGE_STATUS 0x14 42 + #define VL_REG_IDENTIFICATION_MODEL_ID 0xC0 42 43 #define VL_REG_RESULT_RANGE_STATUS_COMPLETE BIT(0) 44 + 45 + #define VL53L0X_MODEL_ID_VAL 0xEE 43 46 44 47 struct vl53l0x_data { 45 48 struct i2c_client *client; ··· 226 223 struct vl53l0x_data *data; 227 224 struct iio_dev *indio_dev; 228 225 int error; 226 + int ret; 229 227 230 228 indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data)); 231 229 if (!indio_dev) ··· 240 236 I2C_FUNC_SMBUS_READ_I2C_BLOCK | 241 237 I2C_FUNC_SMBUS_BYTE_DATA)) 242 238 return -EOPNOTSUPP; 239 + 240 + ret = i2c_smbus_read_byte_data(data->client, VL_REG_IDENTIFICATION_MODEL_ID); 241 + if (ret < 0) 242 + return -EINVAL; 243 + 244 + if (ret != VL53L0X_MODEL_ID_VAL) 245 + dev_info(&client->dev, "Unknown model id: 0x%x", ret); 243 246 244 247 data->vdd_supply = devm_regulator_get(&client->dev, "vdd"); 245 248 if (IS_ERR(data->vdd_supply)) ··· 276 265 277 266 /* usage of interrupt is optional */ 278 267 if (client->irq) { 279 - int ret; 280 - 281 268 init_completion(&data->completion); 282 269 283 270 ret = vl53l0x_configure_irq(client, indio_dev);