proximity: vl53l0x: Handle the reset GPIO
Handle the GPIO connected to the XSHUT/RST_N pin of VL53L0X.
Signed-off-by: Markuss Broks <markuss.broks@gmail.com>
Link: https://lore.kernel.org/r/20220523175344.5845-5-markuss.broks@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
diff --git a/drivers/iio/proximity/vl53l0x-i2c.c b/drivers/iio/proximity/vl53l0x-i2c.c
index db2bdba..3b7a33ff 100644
--- a/drivers/iio/proximity/vl53l0x-i2c.c
+++ b/drivers/iio/proximity/vl53l0x-i2c.c
@@ -15,6 +15,7 @@
*/
#include <linux/delay.h>
+#include <linux/gpio/consumer.h>
#include <linux/i2c.h>
#include <linux/irq.h>
#include <linux/interrupt.h>
@@ -44,6 +45,7 @@ struct vl53l0x_data {
struct i2c_client *client;
struct completion completion;
struct regulator *vdd_supply;
+ struct gpio_desc *reset_gpio;
};
static irqreturn_t vl53l0x_handle_irq(int irq, void *priv)
@@ -196,6 +198,8 @@ static void vl53l0x_power_off(void *_data)
{
struct vl53l0x_data *data = _data;
+ gpiod_set_value_cansleep(data->reset_gpio, 1);
+
regulator_disable(data->vdd_supply);
}
@@ -207,6 +211,8 @@ static int vl53l0x_power_on(struct vl53l0x_data *data)
if (ret)
return ret;
+ gpiod_set_value_cansleep(data->reset_gpio, 0);
+
usleep_range(3200, 5000);
return 0;
@@ -236,6 +242,11 @@ static int vl53l0x_probe(struct i2c_client *client)
return dev_err_probe(&client->dev, PTR_ERR(data->vdd_supply),
"Unable to get VDD regulator\n");
+ data->reset_gpio = devm_gpiod_get_optional(&client->dev, "reset", GPIOD_OUT_HIGH);
+ if (IS_ERR(data->reset_gpio))
+ return dev_err_probe(&client->dev, PTR_ERR(data->reset_gpio),
+ "Cannot get reset GPIO\n");
+
error = vl53l0x_power_on(data);
if (error)
return dev_err_probe(&client->dev, error,