From 2fd728594c39e2069cabf81b6a1968364809013b Mon Sep 17 00:00:00 2001 From: Michael Hennerich Date: Mon, 30 Oct 2023 12:54:55 +0100 Subject: [PATCH] iio: frequency: ad9528: Fix vcc regulator EPROBE_DEFER handling Use devm_regulator_get_enable() and eliminate some boilerplate code. This will also allow the deferred probe mechanism to re-probe if the regulator is not yet available. Signed-off-by: Michael Hennerich --- drivers/iio/frequency/ad9528.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/drivers/iio/frequency/ad9528.c b/drivers/iio/frequency/ad9528.c index a3d828b622123b..edc54adfd9bba8 100644 --- a/drivers/iio/frequency/ad9528.c +++ b/drivers/iio/frequency/ad9528.c @@ -268,7 +268,6 @@ struct ad9528_outputs { struct ad9528_state { struct spi_device *spi; - struct regulator *reg; struct ad9528_platform_data *pdata; struct ad9528_outputs output[AD9528_NUM_CHAN]; struct iio_chan_spec ad9528_channels[AD9528_NUM_CHAN]; @@ -1656,13 +1655,6 @@ struct ad9528_platform_data *ad9528_parse_dt(struct device *dev) } #endif -static void ad9528_reg_disable(void *data) -{ - struct regulator *reg = data; - - regulator_disable(reg); -} - static int ad9528_probe(struct spi_device *spi) { struct ad9528_platform_data *pdata; @@ -1677,6 +1669,11 @@ static int ad9528_probe(struct spi_device *spi) if (PTR_ERR(clk) == -EPROBE_DEFER) return -EPROBE_DEFER; + ret = devm_regulator_get_enable(&spi->dev, "vcc"); + if (ret) + return dev_err_probe(&spi->dev, ret, + "Failed to get vcc regulator"); + if (spi->dev.of_node) pdata = ad9528_parse_dt(&spi->dev); else @@ -1699,18 +1696,6 @@ static int ad9528_probe(struct spi_device *spi) mutex_init(&st->lock); - st->reg = devm_regulator_get(&spi->dev, "vcc"); - if (!IS_ERR(st->reg)) { - ret = regulator_enable(st->reg); - if (ret) - return ret; - - ret = devm_add_action_or_reset(&spi->dev, ad9528_reg_disable, - st->reg); - if (ret) - return ret; - } - st->sysref_req_gpio = devm_gpiod_get_optional(&spi->dev, "sysref-req", GPIOD_OUT_LOW); if (IS_ERR(st->sysref_req_gpio))