]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
iio: adc: ad7768-1: use devm_regulator_get_enable_read_voltage()
authorJonathan Santos <Jonathan.Santos@analog.com>
Sun, 24 Aug 2025 04:10:03 +0000 (01:10 -0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 25 Aug 2025 14:34:20 +0000 (15:34 +0100)
Use devm_regulator_get_enable_read_voltage() function as a standard and
concise way of reading the voltage from the regulator and keep the
regulator enabled. Replace the regulator descriptor with the direct
voltage value in the device struct.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: Marcelo Schmitt <marcelo.schmitt@analog.com>
Signed-off-by: Jonathan Santos <Jonathan.Santos@analog.com>
Link: https://patch.msgid.link/20250824041003.9727-1-Jonathan.Santos@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7768-1.c

index a27591bbf7df0b19bc938ec67b884b2eb151e6af..872c88d0c86cab9f083e38dbc65463676c62001f 100644 (file)
@@ -217,7 +217,7 @@ struct ad7768_state {
        struct spi_device *spi;
        struct regmap *regmap;
        struct regmap *regmap24;
-       struct regulator *vref;
+       int vref_uv;
        struct regulator_dev *vcm_rdev;
        unsigned int vcm_output_sel;
        struct clk *mclk;
@@ -774,7 +774,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
 {
        struct ad7768_state *st = iio_priv(indio_dev);
        const struct iio_scan_type *scan_type;
-       int scale_uv, ret, temp;
+       int ret, temp;
 
        scan_type = iio_get_current_scan_type(indio_dev, chan);
        if (IS_ERR(scan_type))
@@ -795,11 +795,7 @@ static int ad7768_read_raw(struct iio_dev *indio_dev,
                return IIO_VAL_INT;
 
        case IIO_CHAN_INFO_SCALE:
-               scale_uv = regulator_get_voltage(st->vref);
-               if (scale_uv < 0)
-                       return scale_uv;
-
-               *val = (scale_uv * 2) / 1000;
+               *val = (st->vref_uv * 2) / 1000;
                *val2 = scan_type->realbits;
 
                return IIO_VAL_FRACTIONAL_LOG2;
@@ -1132,13 +1128,6 @@ static const struct iio_trigger_ops ad7768_trigger_ops = {
        .validate_device = iio_trigger_validate_own_device,
 };
 
-static void ad7768_regulator_disable(void *data)
-{
-       struct ad7768_state *st = data;
-
-       regulator_disable(st->vref);
-}
-
 static int ad7768_set_channel_label(struct iio_dev *indio_dev,
                                                int num_channels)
 {
@@ -1370,19 +1359,11 @@ static int ad7768_probe(struct spi_device *spi)
                return dev_err_probe(&spi->dev, PTR_ERR(st->regmap24),
                                     "Failed to initialize regmap24");
 
-       st->vref = devm_regulator_get(&spi->dev, "vref");
-       if (IS_ERR(st->vref))
-               return PTR_ERR(st->vref);
-
-       ret = regulator_enable(st->vref);
-       if (ret) {
-               dev_err(&spi->dev, "Failed to enable specified vref supply\n");
-               return ret;
-       }
-
-       ret = devm_add_action_or_reset(&spi->dev, ad7768_regulator_disable, st);
-       if (ret)
-               return ret;
+       ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
+       if (ret < 0)
+               return dev_err_probe(&spi->dev, ret,
+                                    "Failed to get VREF voltage\n");
+       st->vref_uv = ret;
 
        st->mclk = devm_clk_get_enabled(&spi->dev, "mclk");
        if (IS_ERR(st->mclk))