iio: dac: ltc2688: Simplify using devm_regulator_*get_enable()
authorMatti Vaittinen <mazziesaccount@gmail.com>
Fri, 19 Aug 2022 19:19:17 +0000 (22:19 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Wed, 23 Nov 2022 19:44:00 +0000 (19:44 +0000)
Use devm_regulator_bulk_get_enable() instead of open coded bulk-get,
bulk-enable, add-action-to-disable-at-detach - pattern.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/a29493f594c84b3bd852e462bbd3e591a8575a27.1660934107.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/dac/ltc2688.c

index 28bdde2d30889df87a427e71595cc2828abe35ca..fc8eb53c65be3b365f04a1b47e167613184d684e 100644 (file)
@@ -84,7 +84,6 @@ struct ltc2688_chan {
 struct ltc2688_state {
        struct spi_device *spi;
        struct regmap *regmap;
-       struct regulator_bulk_data regulators[2];
        struct ltc2688_chan channels[LTC2688_DAC_CHANNELS];
        struct iio_chan_spec *iio_chan;
        /* lock to protect against multiple access to the device and shared data */
@@ -902,13 +901,6 @@ static int ltc2688_setup(struct ltc2688_state *st, struct regulator *vref)
                               LTC2688_CONFIG_EXT_REF);
 }
 
-static void ltc2688_disable_regulators(void *data)
-{
-       struct ltc2688_state *st = data;
-
-       regulator_bulk_disable(ARRAY_SIZE(st->regulators), st->regulators);
-}
-
 static void ltc2688_disable_regulator(void *regulator)
 {
        regulator_disable(regulator);
@@ -965,6 +957,7 @@ static const struct iio_info ltc2688_info = {
 
 static int ltc2688_probe(struct spi_device *spi)
 {
+       static const char * const regulators[] = { "vcc", "iovcc" };
        struct ltc2688_state *st;
        struct iio_dev *indio_dev;
        struct regulator *vref_reg;
@@ -988,21 +981,11 @@ static int ltc2688_probe(struct spi_device *spi)
                return dev_err_probe(dev, PTR_ERR(st->regmap),
                                     "Failed to init regmap");
 
-       st->regulators[0].supply = "vcc";
-       st->regulators[1].supply = "iovcc";
-       ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(st->regulators),
-                                     st->regulators);
-       if (ret)
-               return dev_err_probe(dev, ret, "Failed to get regulators\n");
-
-       ret = regulator_bulk_enable(ARRAY_SIZE(st->regulators), st->regulators);
+       ret = devm_regulator_bulk_get_enable(dev, ARRAY_SIZE(regulators),
+                                            regulators);
        if (ret)
                return dev_err_probe(dev, ret, "Failed to enable regulators\n");
 
-       ret = devm_add_action_or_reset(dev, ltc2688_disable_regulators, st);
-       if (ret)
-               return ret;
-
        vref_reg = devm_regulator_get_optional(dev, "vref");
        if (IS_ERR(vref_reg)) {
                if (PTR_ERR(vref_reg) != -ENODEV)