iio: adc: ad7606: simplify using devm_regulator_get_enable()
authorMatti Vaittinen <mazziesaccount@gmail.com>
Fri, 19 Aug 2022 19:20:18 +0000 (22:20 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 23 Nov 2022 19:44:00 +0000 (19:44 +0000)
Drop open-coded pattern: 'devm_regulator_get(), regulator_enable(),
add_action_or_reset(regulator_disable)' and use the
devm_regulator_get_enable() and drop the pointer to the regulator.
This simplifies code and makes it less tempting to add manual control
for the regulator which is also controlled by devm.

Whilst here also switch to dev_err_probe() to provide more information
if a deferred probe occurs.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Acked-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/521c52f5a9bdc2db04d5775b36df4b233ae338da.1660934107.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/adc/ad7606.c
drivers/iio/adc/ad7606.h

index ba24f99523e01e71744ab9d6d62f6f5facaad394..dd6b603f65eadbed7c9d0df6159672e0058cdf22 100644 (file)
@@ -557,13 +557,6 @@ static const struct iio_trigger_ops ad7606_trigger_ops = {
        .validate_device = iio_trigger_validate_own_device,
 };
 
-static void ad7606_regulator_disable(void *data)
-{
-       struct ad7606_state *st = data;
-
-       regulator_disable(st->reg);
-}
-
 int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
                 const char *name, unsigned int id,
                 const struct ad7606_bus_ops *bops)
@@ -589,19 +582,10 @@ int ad7606_probe(struct device *dev, int irq, void __iomem *base_address,
        st->scale_avail = ad7606_scale_avail;
        st->num_scales = ARRAY_SIZE(ad7606_scale_avail);
 
-       st->reg = devm_regulator_get(dev, "avcc");
-       if (IS_ERR(st->reg))
-               return PTR_ERR(st->reg);
-
-       ret = regulator_enable(st->reg);
-       if (ret) {
-               dev_err(dev, "Failed to enable specified AVcc supply\n");
-               return ret;
-       }
-
-       ret = devm_add_action_or_reset(dev, ad7606_regulator_disable, st);
+       ret = devm_regulator_get_enable(dev, "avcc");
        if (ret)
-               return ret;
+               return dev_err_probe(dev, ret,
+                                    "Failed to enable specified AVcc supply\n");
 
        st->chip_info = &ad7606_chip_info_tbl[id];
 
index 2dc4f599f9df9b18ec23c41e716cb46cce11548d..0c6a88cc469585fd8b491b5d93643f8acde8fd46 100644 (file)
@@ -62,7 +62,6 @@ struct ad7606_chip_info {
  * struct ad7606_state - driver instance specific data
  * @dev                pointer to kernel device
  * @chip_info          entry in the table of chips that describes this device
- * @reg                regulator info for the power supply of the device
  * @bops               bus operations (SPI or parallel)
  * @range              voltage range selection, selects which scale to apply
  * @oversampling       oversampling selection
@@ -92,7 +91,6 @@ struct ad7606_chip_info {
 struct ad7606_state {
        struct device                   *dev;
        const struct ad7606_chip_info   *chip_info;
-       struct regulator                *reg;
        const struct ad7606_bus_ops     *bops;
        unsigned int                    range[16];
        unsigned int                    oversampling;