[PATCH 3/4] iio: proximity: vl53l0x-i2c: Fix reset sequence

Petr Hodina via B4 Relay posted 4 patches 3 weeks ago
[PATCH 3/4] iio: proximity: vl53l0x-i2c: Fix reset sequence
Posted by Petr Hodina via B4 Relay 3 weeks ago
From: Petr Hodina <petr.hodina@protonmail.com>

Fix the reset GPIO handling and power-up timing to better match the
VL53L0X reset requirements.

Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
---
 drivers/iio/proximity/vl53l0x-i2c.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/proximity/vl53l0x-i2c.c b/drivers/iio/proximity/vl53l0x-i2c.c
index 7bfab396377a..6901ce7dd835 100644
--- a/drivers/iio/proximity/vl53l0x-i2c.c
+++ b/drivers/iio/proximity/vl53l0x-i2c.c
@@ -275,9 +275,13 @@ static int vl53l0x_power_on(struct vl53l0x_data *data)
 			return ret;
 	}
 
-	gpiod_set_value_cansleep(data->reset_gpio, 0);
-
-	usleep_range(3200, 5000);
+	usleep_range(5000, 6000);
+	if (data->reset_gpio) {
+		gpiod_set_value_cansleep(data->reset_gpio, 1);
+		usleep_range(5000, 6000);
+		gpiod_set_value_cansleep(data->reset_gpio, 0);
+		usleep_range(5000, 6000);
+	}
 
 	return 0;
 }
@@ -354,7 +358,7 @@ static int vl53l0x_probe(struct i2c_client *client)
 		return dev_err_probe(&client->dev, PTR_ERR(data->vio_supply),
 				     "Unable to get VDDIO regulator\n");
 
-	data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);
+	data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW);
 	if (IS_ERR(data->reset_gpio))
 		return dev_err_probe(&client->dev, PTR_ERR(data->reset_gpio),
 				     "Cannot get reset GPIO\n");

-- 
2.52.0
Re: [PATCH 3/4] iio: proximity: vl53l0x-i2c: Fix reset sequence
Posted by Krzysztof Kozlowski 2 weeks, 6 days ago
On Mon, Jan 19, 2026 at 06:19:57PM +0100, Petr Hodina wrote:
> Fix the reset GPIO handling and power-up timing to better match the
> VL53L0X reset requirements.
> 
> Signed-off-by: Petr Hodina <petr.hodina@protonmail.com>
> ---
>  drivers/iio/proximity/vl53l0x-i2c.c | 12 ++++++++----
>  1 file changed, 8 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/iio/proximity/vl53l0x-i2c.c b/drivers/iio/proximity/vl53l0x-i2c.c
> index 7bfab396377a..6901ce7dd835 100644
> --- a/drivers/iio/proximity/vl53l0x-i2c.c
> +++ b/drivers/iio/proximity/vl53l0x-i2c.c
> @@ -275,9 +275,13 @@ static int vl53l0x_power_on(struct vl53l0x_data *data)
>  			return ret;
>  	}
>  
> -	gpiod_set_value_cansleep(data->reset_gpio, 0);
> -
> -	usleep_range(3200, 5000);
> +	usleep_range(5000, 6000);
> +	if (data->reset_gpio) {
> +		gpiod_set_value_cansleep(data->reset_gpio, 1);
> +		usleep_range(5000, 6000);
> +		gpiod_set_value_cansleep(data->reset_gpio, 0);
> +		usleep_range(5000, 6000);
> +	}
>  
>  	return 0;
>  }
> @@ -354,7 +358,7 @@ static int vl53l0x_probe(struct i2c_client *client)
>  		return dev_err_probe(&client->dev, PTR_ERR(data->vio_supply),
>  				     "Unable to get VDDIO regulator\n");
>  
> -	data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);
> +	data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW);

This feels wrong - you are now bringing the device out of reset without
observing any of the reset sequence constraints.

Best regards,
Krzysztof
Re: [PATCH 3/4] iio: proximity: vl53l0x-i2c: Fix reset sequence
Posted by Andy Shevchenko 3 weeks ago
On Mon, Jan 19, 2026 at 06:19:57PM +0100, Petr Hodina via B4 Relay wrote:

> Fix the reset GPIO handling and power-up timing to better match the
> VL53L0X reset requirements.

...

> -	usleep_range(3200, 5000);
> +	usleep_range(5000, 6000);

> +		usleep_range(5000, 6000);

> +		usleep_range(5000, 6000);

Can you switch to fsleep() while at it?

...

> -	data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);
> +	data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_LOW);
>  	if (IS_ERR(data->reset_gpio))
>  		return dev_err_probe(&client->dev, PTR_ERR(data->reset_gpio),
>  				     "Cannot get reset GPIO\n");

Wondering if in a future change this can be converted to use reset-gpio driver
instead of poking GPIOs directly.

-- 
With Best Regards,
Andy Shevchenko