Commit 2867ccf4 authored by David Lechner's avatar David Lechner Committed by Jonathan Cameron

iio: adc: ti-ads8688: use devm_regulator_get_enable_read_voltage()

Use devm_regulator_get_enable_read_voltage() to simplify the code.
Signed-off-by: default avatarDavid Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20240621-iio-regulator-refactor-round-2-v1-8-49e50cd0b99a@baylibre.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 71c8bea4
...@@ -65,7 +65,6 @@ struct ads8688_state { ...@@ -65,7 +65,6 @@ struct ads8688_state {
struct mutex lock; struct mutex lock;
const struct ads8688_chip_info *chip_info; const struct ads8688_chip_info *chip_info;
struct spi_device *spi; struct spi_device *spi;
struct regulator *reg;
unsigned int vref_mv; unsigned int vref_mv;
enum ads8688_range range[8]; enum ads8688_range range[8];
union { union {
...@@ -423,21 +422,11 @@ static int ads8688_probe(struct spi_device *spi) ...@@ -423,21 +422,11 @@ static int ads8688_probe(struct spi_device *spi)
st = iio_priv(indio_dev); st = iio_priv(indio_dev);
st->reg = devm_regulator_get_optional(&spi->dev, "vref"); ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
if (!IS_ERR(st->reg)) { if (ret < 0 && ret != -ENODEV)
ret = regulator_enable(st->reg); return ret;
if (ret)
return ret;
ret = regulator_get_voltage(st->reg);
if (ret < 0)
goto err_regulator_disable;
st->vref_mv = ret / 1000; st->vref_mv = ret == -ENODEV ? ADS8688_VREF_MV : ret / 1000;
} else {
/* Use internal reference */
st->vref_mv = ADS8688_VREF_MV;
}
st->chip_info = &ads8688_chip_info_tbl[spi_get_device_id(spi)->driver_data]; st->chip_info = &ads8688_chip_info_tbl[spi_get_device_id(spi)->driver_data];
...@@ -460,7 +449,7 @@ static int ads8688_probe(struct spi_device *spi) ...@@ -460,7 +449,7 @@ static int ads8688_probe(struct spi_device *spi)
ret = iio_triggered_buffer_setup(indio_dev, NULL, ads8688_trigger_handler, NULL); ret = iio_triggered_buffer_setup(indio_dev, NULL, ads8688_trigger_handler, NULL);
if (ret < 0) { if (ret < 0) {
dev_err(&spi->dev, "iio triggered buffer setup failed\n"); dev_err(&spi->dev, "iio triggered buffer setup failed\n");
goto err_regulator_disable; return ret;
} }
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
...@@ -472,23 +461,15 @@ static int ads8688_probe(struct spi_device *spi) ...@@ -472,23 +461,15 @@ static int ads8688_probe(struct spi_device *spi)
err_buffer_cleanup: err_buffer_cleanup:
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
err_regulator_disable:
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
return ret; return ret;
} }
static void ads8688_remove(struct spi_device *spi) static void ads8688_remove(struct spi_device *spi)
{ {
struct iio_dev *indio_dev = spi_get_drvdata(spi); struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct ads8688_state *st = iio_priv(indio_dev);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
iio_triggered_buffer_cleanup(indio_dev); iio_triggered_buffer_cleanup(indio_dev);
if (!IS_ERR(st->reg))
regulator_disable(st->reg);
} }
static const struct spi_device_id ads8688_id[] = { static const struct spi_device_id ads8688_id[] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment