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 adc108s102_state {
|
||||||
struct spi_device *spi;
|
struct spi_device *spi;
|
||||||
struct regulator *reg;
|
|
||||||
u32 va_millivolt;
|
u32 va_millivolt;
|
||||||
/* SPI transfer used by triggered buffer handler*/
|
/* SPI transfer used by triggered buffer handler*/
|
||||||
struct spi_transfer ring_xfer;
|
struct spi_transfer ring_xfer;
|
||||||
@ -216,11 +215,6 @@ static const struct iio_info adc108s102_info = {
|
|||||||
.update_scan_mode = &adc108s102_update_scan_mode,
|
.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)
|
static int adc108s102_probe(struct spi_device *spi)
|
||||||
{
|
{
|
||||||
struct adc108s102_state *st;
|
struct adc108s102_state *st;
|
||||||
@ -236,25 +230,9 @@ static int adc108s102_probe(struct spi_device *spi)
|
|||||||
if (ACPI_COMPANION(&spi->dev)) {
|
if (ACPI_COMPANION(&spi->dev)) {
|
||||||
st->va_millivolt = ADC108S102_VA_MV_ACPI_DEFAULT;
|
st->va_millivolt = ADC108S102_VA_MV_ACPI_DEFAULT;
|
||||||
} else {
|
} else {
|
||||||
st->reg = devm_regulator_get(&spi->dev, "vref");
|
ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
|
||||||
if (IS_ERR(st->reg))
|
if (ret < 0)
|
||||||
return PTR_ERR(st->reg);
|
return dev_err_probe(&spi->dev, ret, "failed get vref voltage\n");
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
st->va_millivolt = ret / 1000;
|
st->va_millivolt = ret / 1000;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user