Skip to content

Commit

Permalink
staging: iio: ad9832: Use devm_regulator_get_enable()
Browse files Browse the repository at this point in the history
The regulators are only enabled at probe(), hence replace the boilerplate
code by making use of devm_regulator_get_enable() helper.

Signed-off-by: Saalim Quadri <danascape@gmail.com>
Link: https://patch.msgid.link/20250306000040.1550656-1-danascape@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
  • Loading branch information
Saalim Quadri authored and Jonathan Cameron committed Mar 11, 2025
1 parent 85a1159 commit 33220e1
Showing 1 changed file with 4 additions and 33 deletions.
37 changes: 4 additions & 33 deletions drivers/staging/iio/frequency/ad9832.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,6 @@
/**
* struct ad9832_state - driver instance specific data
* @spi: spi_device
* @avdd: supply regulator for the analog section
* @dvdd: supply regulator for the digital section
* @mclk: external master clock
* @ctrl_fp: cached frequency/phase control word
* @ctrl_ss: cached sync/selsrc control word
Expand All @@ -94,8 +92,6 @@

struct ad9832_state {
struct spi_device *spi;
struct regulator *avdd;
struct regulator *dvdd;
struct clk *mclk;
unsigned short ctrl_fp;
unsigned short ctrl_ss;
Expand Down Expand Up @@ -297,11 +293,6 @@ static const struct iio_info ad9832_info = {
.attrs = &ad9832_attribute_group,
};

static void ad9832_reg_disable(void *reg)
{
regulator_disable(reg);
}

static int ad9832_probe(struct spi_device *spi)
{
struct ad9832_platform_data *pdata = dev_get_platdata(&spi->dev);
Expand All @@ -320,33 +311,13 @@ static int ad9832_probe(struct spi_device *spi)

st = iio_priv(indio_dev);

st->avdd = devm_regulator_get(&spi->dev, "avdd");
if (IS_ERR(st->avdd))
return PTR_ERR(st->avdd);

ret = regulator_enable(st->avdd);
if (ret) {
dev_err(&spi->dev, "Failed to enable specified AVDD supply\n");
return ret;
}

ret = devm_add_action_or_reset(&spi->dev, ad9832_reg_disable, st->avdd);
ret = devm_regulator_get_enable(&spi->dev, "avdd");
if (ret)
return ret;

st->dvdd = devm_regulator_get(&spi->dev, "dvdd");
if (IS_ERR(st->dvdd))
return PTR_ERR(st->dvdd);
return dev_err_probe(&spi->dev, ret, "failed to enable specified AVDD voltage\n");

ret = regulator_enable(st->dvdd);
if (ret) {
dev_err(&spi->dev, "Failed to enable specified DVDD supply\n");
return ret;
}

ret = devm_add_action_or_reset(&spi->dev, ad9832_reg_disable, st->dvdd);
ret = devm_regulator_get_enable(&spi->dev, "dvdd");
if (ret)
return ret;
return dev_err_probe(&spi->dev, ret, "Failed to enable specified DVDD supply\n");

st->mclk = devm_clk_get_enabled(&spi->dev, "mclk");
if (IS_ERR(st->mclk))
Expand Down

0 comments on commit 33220e1

Please sign in to comment.