iio: adc: ti-adc108s102: use devm_regulator_get_enable_read_voltage()
Use devm_regulator_get_enable_read_voltage() to simplify the code. Signed-off-by: David Lechner <dlechner@baylibre.com> Link: https://patch.msgid.link/20240621-iio-regulator-refactor-round-2-v1-7-49e50cd0b99a@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
This commit is contained in:
parent
0817c9543c
commit
71c8bea483
@ -58,7 +58,6 @@
|
||||
|
||||
struct adc108s102_state {
|
||||
struct spi_device *spi;
|
||||
struct regulator *reg;
|
||||
u32 va_millivolt;
|
||||
/* SPI transfer used by triggered buffer handler*/
|
||||
struct spi_transfer ring_xfer;
|
||||
@ -216,11 +215,6 @@ static const struct iio_info adc108s102_info = {
|
||||
.update_scan_mode = &adc108s102_update_scan_mode,
|
||||
};
|
||||
|
||||
static void adc108s102_reg_disable(void *reg)
|
||||
{
|
||||
regulator_disable(reg);
|
||||
}
|
||||
|
||||
static int adc108s102_probe(struct spi_device *spi)
|
||||
{
|
||||
struct adc108s102_state *st;
|
||||
@ -236,25 +230,9 @@ static int adc108s102_probe(struct spi_device *spi)
|
||||
if (ACPI_COMPANION(&spi->dev)) {
|
||||
st->va_millivolt = ADC108S102_VA_MV_ACPI_DEFAULT;
|
||||
} else {
|
||||
st->reg = devm_regulator_get(&spi->dev, "vref");
|
||||
if (IS_ERR(st->reg))
|
||||
return PTR_ERR(st->reg);
|
||||
|
||||
ret = regulator_enable(st->reg);
|
||||
if (ret < 0) {
|
||||
dev_err(&spi->dev, "Cannot enable vref regulator\n");
|
||||
return ret;
|
||||
}
|
||||
ret = devm_add_action_or_reset(&spi->dev, adc108s102_reg_disable,
|
||||
st->reg);
|
||||
if (ret)
|
||||
return ret;
|
||||
|
||||
ret = regulator_get_voltage(st->reg);
|
||||
if (ret < 0) {
|
||||
dev_err(&spi->dev, "vref get voltage failed\n");
|
||||
return ret;
|
||||
}
|
||||
ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
|
||||
if (ret < 0)
|
||||
return dev_err_probe(&spi->dev, ret, "failed get vref voltage\n");
|
||||
|
||||
st->va_millivolt = ret / 1000;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user