Skip to content

Commit

Permalink
iio: frequency: ad9528: Fix vcc regulator EPROBE_DEFER handling
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
mhennerich authored and nunojsa committed Oct 30, 2023
1 parent 9197af5 commit 2fd7285
Showing 1 changed file with 5 additions and 20 deletions.
25 changes: 5 additions & 20 deletions drivers/iio/frequency/ad9528.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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))
Expand Down

0 comments on commit 2fd7285

Please sign in to comment.