Commit a98461d7 authored by Eva Rachel Retuya's avatar Eva Rachel Retuya Committed by Jonathan Cameron

staging: iio: ad9832: add DVDD regulator

The AD9832/AD9835 is supplied with two power sources: AVDD as analog
supply voltage and DVDD as digital supply voltage.

Attempt to fetch and enable the regulator 'dvdd'. Bail out if any error
occurs.
Suggested-by: default avatarLars-Peter Clausen <lars@metafoo.de>
Signed-off-by: default avatarEva Rachel Retuya <eraretuya@gmail.com>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 9d154814
...@@ -222,10 +222,22 @@ static int ad9832_probe(struct spi_device *spi) ...@@ -222,10 +222,22 @@ static int ad9832_probe(struct spi_device *spi)
return ret; return ret;
} }
st->dvdd = devm_regulator_get(&spi->dev, "dvdd");
if (IS_ERR(st->dvdd)) {
ret = PTR_ERR(st->dvdd);
goto error_disable_reg;
}
ret = regulator_enable(st->dvdd);
if (ret) {
dev_err(&spi->dev, "Failed to enable specified DVDD supply\n");
goto error_disable_reg;
}
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
if (!indio_dev) { if (!indio_dev) {
ret = -ENOMEM; ret = -ENOMEM;
goto error_disable_reg; goto error_disable_dvdd;
} }
spi_set_drvdata(spi, indio_dev); spi_set_drvdata(spi, indio_dev);
st = iio_priv(indio_dev); st = iio_priv(indio_dev);
...@@ -280,39 +292,41 @@ static int ad9832_probe(struct spi_device *spi) ...@@ -280,39 +292,41 @@ static int ad9832_probe(struct spi_device *spi)
ret = spi_sync(st->spi, &st->msg); ret = spi_sync(st->spi, &st->msg);
if (ret) { if (ret) {
dev_err(&spi->dev, "device init failed\n"); dev_err(&spi->dev, "device init failed\n");
goto error_disable_reg; goto error_disable_dvdd;
} }
ret = ad9832_write_frequency(st, AD9832_FREQ0HM, pdata->freq0); ret = ad9832_write_frequency(st, AD9832_FREQ0HM, pdata->freq0);
if (ret) if (ret)
goto error_disable_reg; goto error_disable_dvdd;
ret = ad9832_write_frequency(st, AD9832_FREQ1HM, pdata->freq1); ret = ad9832_write_frequency(st, AD9832_FREQ1HM, pdata->freq1);
if (ret) if (ret)
goto error_disable_reg; goto error_disable_dvdd;
ret = ad9832_write_phase(st, AD9832_PHASE0H, pdata->phase0); ret = ad9832_write_phase(st, AD9832_PHASE0H, pdata->phase0);
if (ret) if (ret)
goto error_disable_reg; goto error_disable_dvdd;
ret = ad9832_write_phase(st, AD9832_PHASE1H, pdata->phase1); ret = ad9832_write_phase(st, AD9832_PHASE1H, pdata->phase1);
if (ret) if (ret)
goto error_disable_reg; goto error_disable_dvdd;
ret = ad9832_write_phase(st, AD9832_PHASE2H, pdata->phase2); ret = ad9832_write_phase(st, AD9832_PHASE2H, pdata->phase2);
if (ret) if (ret)
goto error_disable_reg; goto error_disable_dvdd;
ret = ad9832_write_phase(st, AD9832_PHASE3H, pdata->phase3); ret = ad9832_write_phase(st, AD9832_PHASE3H, pdata->phase3);
if (ret) if (ret)
goto error_disable_reg; goto error_disable_dvdd;
ret = iio_device_register(indio_dev); ret = iio_device_register(indio_dev);
if (ret) if (ret)
goto error_disable_reg; goto error_disable_dvdd;
return 0; return 0;
error_disable_dvdd:
regulator_disable(st->dvdd);
error_disable_reg: error_disable_reg:
regulator_disable(reg); regulator_disable(reg);
...@@ -325,6 +339,7 @@ static int ad9832_remove(struct spi_device *spi) ...@@ -325,6 +339,7 @@ static int ad9832_remove(struct spi_device *spi)
struct ad9832_state *st = iio_priv(indio_dev); struct ad9832_state *st = iio_priv(indio_dev);
iio_device_unregister(indio_dev); iio_device_unregister(indio_dev);
regulator_disable(st->dvdd);
regulator_disable(st->reg); regulator_disable(st->reg);
return 0; return 0;
......
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
* struct ad9832_state - driver instance specific data * struct ad9832_state - driver instance specific data
* @spi: spi_device * @spi: spi_device
* @reg: supply regulator * @reg: supply regulator
* @dvdd: supply regulator for the digital section
* @mclk: external master clock * @mclk: external master clock
* @ctrl_fp: cached frequency/phase control word * @ctrl_fp: cached frequency/phase control word
* @ctrl_ss: cached sync/selsrc control word * @ctrl_ss: cached sync/selsrc control word
...@@ -77,6 +78,7 @@ ...@@ -77,6 +78,7 @@
struct ad9832_state { struct ad9832_state {
struct spi_device *spi; struct spi_device *spi;
struct regulator *reg; struct regulator *reg;
struct regulator *dvdd;
unsigned long mclk; unsigned long mclk;
unsigned short ctrl_fp; unsigned short ctrl_fp;
unsigned short ctrl_ss; unsigned short ctrl_ss;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment