sensor: vl53l0x: pm resume fix
When active XSHUT resets the chip so we must re-initialise chip when resuming from PM suspend. Signed-off-by: Nick Ward <nix.ward@gmail.com>
This commit is contained in:
parent
d30ec30a85
commit
ee3b9c117e
1 changed files with 30 additions and 30 deletions
|
@ -300,36 +300,6 @@ static const struct sensor_driver_api vl53l0x_api_funcs = {
|
|||
.channel_get = vl53l0x_channel_get,
|
||||
};
|
||||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
static int vl53l0x_pm_action(const struct device *dev,
|
||||
enum pm_device_action action)
|
||||
{
|
||||
const struct vl53l0x_config *const config = dev->config;
|
||||
int ret;
|
||||
|
||||
switch (action) {
|
||||
case PM_DEVICE_ACTION_RESUME:
|
||||
ret = gpio_pin_set_dt(&config->xshut, 0);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("[%s] XSHUT pin inactive", dev->name);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
case PM_DEVICE_ACTION_SUSPEND:
|
||||
ret = gpio_pin_set_dt(&config->xshut, 1);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("[%s] XSHUT pin active", dev->name);
|
||||
return ret;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int vl53l0x_init(const struct device *dev)
|
||||
{
|
||||
int r;
|
||||
|
@ -378,6 +348,36 @@ static int vl53l0x_init(const struct device *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_PM_DEVICE
|
||||
static int vl53l0x_pm_action(const struct device *dev,
|
||||
enum pm_device_action action)
|
||||
{
|
||||
const struct vl53l0x_config *const config = dev->config;
|
||||
int ret;
|
||||
|
||||
switch (action) {
|
||||
case PM_DEVICE_ACTION_RESUME:
|
||||
ret = vl53l0x_init(dev);
|
||||
if (ret != 0) {
|
||||
LOG_ERR("resume init: %d", ret);
|
||||
}
|
||||
break;
|
||||
case PM_DEVICE_ACTION_SUSPEND:
|
||||
/* HW Standby */
|
||||
ret = gpio_pin_set_dt(&config->xshut, 1);
|
||||
if (ret < 0) {
|
||||
LOG_ERR("[%s] XSHUT pin active", dev->name);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = -ENOTSUP;
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#define VL53L0X_INIT(inst) \
|
||||
static struct vl53l0x_config vl53l0x_##inst##_config = { \
|
||||
.i2c = I2C_DT_SPEC_INST_GET(inst), \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue