[PATCH v3 2/2] iio: proximity: cleanup fixes for vl53l1x-i2c

From: Siratul Islam

Date: Thu Jun 11 2026 - 09:43:43 EST


Extract data-ready polling into a helper, fix regmap_read_poll_timeout()
argument alignment, and add field definitions for BIT(0).
No functional changes.

Suggested-by: Andy Shevchenko <andriy.shevchenko@xxxxxxxxx>
Reviewed-by: Nuno Sá <nuno.sa@xxxxxxxxxx>

Signed-off-by: Siratul Islam <email@xxxxxxxx>
---
drivers/iio/proximity/vl53l1x-i2c.c | 38 +++++++++++++++--------------
1 file changed, 20 insertions(+), 18 deletions(-)

diff --git a/drivers/iio/proximity/vl53l1x-i2c.c b/drivers/iio/proximity/vl53l1x-i2c.c
index 8302e0049e7c..1782c89d5277 100644
--- a/drivers/iio/proximity/vl53l1x-i2c.c
+++ b/drivers/iio/proximity/vl53l1x-i2c.c
@@ -82,6 +82,9 @@

#define VL53L1X_OSC_CALIBRATE_MASK GENMASK(9, 0)

+#define VL53L1X_FIRMWARE__SYSTEM_STATUS_BOOTED BIT(0)
+#define VL53L1X_GPIO__TIO_HV_STATUS_DATA_READY BIT(0)
+
/* Inter-measurement period uses PLL divider with 1.075 oscillator correction */
static const struct u32_fract vl53l1x_osc_correction = {
.numerator = 1075,
@@ -191,6 +194,18 @@ static int vl53l1x_stop_ranging(struct vl53l1x_data *data)
VL53L1X_MODE_START_STOP);
}

+static int vl53l1x_wait_data_ready(struct vl53l1x_data *data)
+{
+ unsigned int val;
+
+ /* 1ms poll, 1s timeout covers max timing budgets (per ST Ultra Lite Driver) */
+ return regmap_read_poll_timeout(data->regmap,
+ VL53L1X_REG_GPIO__TIO_HV_STATUS,
+ val, (val & VL53L1X_GPIO__TIO_HV_STATUS_DATA_READY) !=
+ data->gpio_polarity,
+ 1 * USEC_PER_MSEC, 1 * USEC_PER_SEC);
+}
+
/*
* Default configuration blob from ST's VL53L1X Ultra Lite Driver
* (STSW-IMG009).
@@ -230,10 +245,9 @@ static int vl53l1x_chip_init(struct vl53l1x_data *data)
}

ret = regmap_read_poll_timeout(data->regmap,
- VL53L1X_REG_FIRMWARE__SYSTEM_STATUS, val,
- val & BIT(0),
- 1 * USEC_PER_MSEC,
- 100 * USEC_PER_MSEC);
+ VL53L1X_REG_FIRMWARE__SYSTEM_STATUS,
+ val, val & VL53L1X_FIRMWARE__SYSTEM_STATUS_BOOTED,
+ 1 * USEC_PER_MSEC, 100 * USEC_PER_MSEC);
if (ret)
return dev_err_probe(dev, ret, "firmware boot timeout\n");

@@ -261,12 +275,7 @@ static int vl53l1x_chip_init(struct vl53l1x_data *data)
if (ret)
return ret;

- /* 1ms poll, 1s timeout covers max timing budgets (per ST Ultra Lite Driver) */
- ret = regmap_read_poll_timeout(data->regmap,
- VL53L1X_REG_GPIO__TIO_HV_STATUS, val,
- (val & 1) != data->gpio_polarity,
- 1 * USEC_PER_MSEC,
- 1000 * USEC_PER_MSEC);
+ ret = vl53l1x_wait_data_ready(data);
if (ret)
return ret;

@@ -461,14 +470,7 @@ static int vl53l1x_read_proximity(struct vl53l1x_data *data, int *val)
if (!wait_for_completion_timeout(&data->completion, HZ))
return -ETIMEDOUT;
} else {
- unsigned int rdy;
-
- /* 1ms poll, 1s timeout covers max timing budgets (per ST Ultra Lite Driver) */
- ret = regmap_read_poll_timeout(data->regmap,
- VL53L1X_REG_GPIO__TIO_HV_STATUS, rdy,
- (rdy & 1) != data->gpio_polarity,
- 1 * USEC_PER_MSEC,
- 1000 * USEC_PER_MSEC);
+ ret = vl53l1x_wait_data_ready(data);
if (ret)
return ret;
}
--
2.54.0