mirror of
https://github.com/torvalds/linux.git
synced 2026-09-24 06:24:02 +02:00
iio: proximity: cleanup fixes for vl53l1x-i2c
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@intel.com> Reviewed-by: Nuno Sá <nuno.sa@analog.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com> Signed-off-by: Siratul Islam <email@sirat.me> Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
parent
24221b0370
commit
9fb6c7ba7b
|
|
@ -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,17 @@ 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 +244,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 +274,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 +469,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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user