Skip to content

Commit 8f485a1

Browse files
dlechjic23
authored andcommitted
iio: adc: ad7793: use devm_regulator_get_enable_read_voltage
This makes use of the new devm_regulator_get_enable_read_voltage() function to reduce boilerplate code. Signed-off-by: David Lechner <dlechner@baylibre.com> Reviewed-by: Nuno Sa <nuno.sa@analog.com> Link: https://patch.msgid.link/20240612-iio-adc-ref-supply-refactor-v2-4-fa622e7354e9@baylibre.com Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
1 parent c53ccb4 commit 8f485a1

File tree

1 file changed

+3
-21
lines changed

1 file changed

+3
-21
lines changed

drivers/iio/adc/ad7793.c

Lines changed: 3 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ struct ad7793_chip_info {
152152

153153
struct ad7793_state {
154154
const struct ad7793_chip_info *chip_info;
155-
struct regulator *reg;
156155
u16 int_vref_mv;
157156
u16 mode;
158157
u16 conf;
@@ -769,11 +768,6 @@ static const struct ad7793_chip_info ad7793_chip_info_tbl[] = {
769768
},
770769
};
771770

772-
static void ad7793_reg_disable(void *reg)
773-
{
774-
regulator_disable(reg);
775-
}
776-
777771
static int ad7793_probe(struct spi_device *spi)
778772
{
779773
const struct ad7793_platform_data *pdata = spi->dev.platform_data;
@@ -800,23 +794,11 @@ static int ad7793_probe(struct spi_device *spi)
800794
ad_sd_init(&st->sd, indio_dev, spi, &ad7793_sigma_delta_info);
801795

802796
if (pdata->refsel != AD7793_REFSEL_INTERNAL) {
803-
st->reg = devm_regulator_get(&spi->dev, "refin");
804-
if (IS_ERR(st->reg))
805-
return PTR_ERR(st->reg);
806-
807-
ret = regulator_enable(st->reg);
808-
if (ret)
809-
return ret;
810-
811-
ret = devm_add_action_or_reset(&spi->dev, ad7793_reg_disable, st->reg);
812-
if (ret)
797+
ret = devm_regulator_get_enable_read_voltage(&spi->dev, "refin");
798+
if (ret < 0)
813799
return ret;
814800

815-
vref_mv = regulator_get_voltage(st->reg);
816-
if (vref_mv < 0)
817-
return vref_mv;
818-
819-
vref_mv /= 1000;
801+
vref_mv = ret / 1000;
820802
} else {
821803
vref_mv = 1170; /* Build-in ref */
822804
}

0 commit comments

Comments
 (0)