@@ -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)
@@ -197,6 +199,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);
}
@@ -208,6 +212,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;
@@ -237,6 +243,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,
Handle the GPIO connected to the XSHUT/RST_N pin of VL53L0X. Signed-off-by: Markuss Broks <markuss.broks@gmail.com> --- drivers/iio/proximity/vl53l0x-i2c.c | 11 +++++++++++ 1 file changed, 11 insertions(+)