Skip to content

Commit a8b26c2

Browse files
tachicialexjic23
authored andcommitted
iio: dac: ad7303: use regulator get optional to check for ext supply
Previously, the code was using the of_read_property_bool() to check if an external regulator was provided. However, this is redundant, as it's more simple/direct to just ask the regulator is provided, via a `devm_regulator_get_optional()` call. Signed-off-by: Alexandru Tachici <[email protected]> Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 3922f93 commit a8b26c2

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

drivers/iio/dac/ad7303.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include <linux/slab.h>
1313
#include <linux/sysfs.h>
1414
#include <linux/regulator/consumer.h>
15-
#include <linux/of.h>
1615

1716
#include <linux/iio/iio.h>
1817
#include <linux/iio/sysfs.h>
@@ -202,7 +201,6 @@ static int ad7303_probe(struct spi_device *spi)
202201
const struct spi_device_id *id = spi_get_device_id(spi);
203202
struct iio_dev *indio_dev;
204203
struct ad7303_state *st;
205-
bool ext_ref;
206204
int ret;
207205

208206
indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st));
@@ -224,24 +222,15 @@ static int ad7303_probe(struct spi_device *spi)
224222
if (ret)
225223
return ret;
226224

227-
if (spi->dev.of_node) {
228-
ext_ref = of_property_read_bool(spi->dev.of_node,
229-
"REF-supply");
230-
} else {
231-
struct ad7303_platform_data *pdata = spi->dev.platform_data;
232-
if (pdata && pdata->use_external_ref)
233-
ext_ref = true;
234-
else
235-
ext_ref = false;
236-
}
237-
238-
if (ext_ref) {
239-
st->vref_reg = devm_regulator_get(&spi->dev, "REF");
240-
if (IS_ERR(st->vref_reg)) {
241-
ret = PTR_ERR(st->vref_reg);
225+
st->vref_reg = devm_regulator_get_optional(&spi->dev, "REF");
226+
if (IS_ERR(st->vref_reg)) {
227+
ret = PTR_ERR(st->vref_reg);
228+
if (ret != -ENODEV)
242229
goto err_disable_vdd_reg;
243-
}
230+
st->vref_reg = NULL;
231+
}
244232

233+
if (st->vref_reg) {
245234
ret = regulator_enable(st->vref_reg);
246235
if (ret)
247236
goto err_disable_vdd_reg;

0 commit comments

Comments
 (0)