Message ID | 0c71001f4c1eba169230caee6640661cec4b979b.1701971344.git.marcelo.schmitt1@gmail.com (mailing list archive) |
---|---|
State | Changes Requested |
Headers | show |
Series | Add support for AD7091R-2/-4/-8 | expand |
On Thu, 7 Dec 2023 15:41:25 -0300 Marcelo Schmitt <marcelo.schmitt@analog.com> wrote: > The ADC needs a voltage reference to work correctly. > Enable AD7091R internal voltage reference if no external vref is > supplied. > > Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com> > --- > drivers/iio/adc/ad7091r-base.c | 9 ++++++--- > drivers/iio/adc/ad7091r-base.h | 1 + > 2 files changed, 7 insertions(+), 3 deletions(-) > > diff --git a/drivers/iio/adc/ad7091r-base.c b/drivers/iio/adc/ad7091r-base.c > index f2cb638b8d77..59a7ec44955d 100644 > --- a/drivers/iio/adc/ad7091r-base.c > +++ b/drivers/iio/adc/ad7091r-base.c > @@ -215,10 +215,13 @@ int ad7091r_probe(struct device *dev, const char *name, > iio_dev->channels = st->chip_info->channels; > > st->vref = devm_regulator_get_optional(dev, "vref"); This does not return NULL, only a valid regulator or an error code. > - if (IS_ERR(st->vref)) { > - if (PTR_ERR(st->vref) == -EPROBE_DEFER) > - return -EPROBE_DEFER; > + if (IS_ERR_OR_NULL(st->vref)) { You still need to explicitly handle deferal here. There might be a perfectly good regulator that just isn't ready yet and if that happens we want to try probing this driver again later rather than papering over it. > + /* Enable internal vref */ > st->vref = NULL; > + ret = regmap_update_bits(st->map, AD7091R_REG_CONF, > + AD7091R_REG_CONF_INT_VREF, BIT(0)); > + if (ret) > + return ret; > } else { > ret = regulator_enable(st->vref); > if (ret) > diff --git a/drivers/iio/adc/ad7091r-base.h b/drivers/iio/adc/ad7091r-base.h > index 9546d0bf1da7..e153c2d7deb5 100644 > --- a/drivers/iio/adc/ad7091r-base.h > +++ b/drivers/iio/adc/ad7091r-base.h > @@ -20,6 +20,7 @@ > #define AD7091R_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6) > > /* AD7091R_REG_CONF */ > +#define AD7091R_REG_CONF_INT_VREF BIT(0) > #define AD7091R_REG_CONF_ALERT_EN BIT(4) > #define AD7091R_REG_CONF_AUTO BIT(8) > #define AD7091R_REG_CONF_CMD BIT(10)
diff --git a/drivers/iio/adc/ad7091r-base.c b/drivers/iio/adc/ad7091r-base.c index f2cb638b8d77..59a7ec44955d 100644 --- a/drivers/iio/adc/ad7091r-base.c +++ b/drivers/iio/adc/ad7091r-base.c @@ -215,10 +215,13 @@ int ad7091r_probe(struct device *dev, const char *name, iio_dev->channels = st->chip_info->channels; st->vref = devm_regulator_get_optional(dev, "vref"); - if (IS_ERR(st->vref)) { - if (PTR_ERR(st->vref) == -EPROBE_DEFER) - return -EPROBE_DEFER; + if (IS_ERR_OR_NULL(st->vref)) { + /* Enable internal vref */ st->vref = NULL; + ret = regmap_update_bits(st->map, AD7091R_REG_CONF, + AD7091R_REG_CONF_INT_VREF, BIT(0)); + if (ret) + return ret; } else { ret = regulator_enable(st->vref); if (ret) diff --git a/drivers/iio/adc/ad7091r-base.h b/drivers/iio/adc/ad7091r-base.h index 9546d0bf1da7..e153c2d7deb5 100644 --- a/drivers/iio/adc/ad7091r-base.h +++ b/drivers/iio/adc/ad7091r-base.h @@ -20,6 +20,7 @@ #define AD7091R_REG_CH_HYSTERESIS(ch) ((ch) * 3 + 6) /* AD7091R_REG_CONF */ +#define AD7091R_REG_CONF_INT_VREF BIT(0) #define AD7091R_REG_CONF_ALERT_EN BIT(4) #define AD7091R_REG_CONF_AUTO BIT(8) #define AD7091R_REG_CONF_CMD BIT(10)
The ADC needs a voltage reference to work correctly. Enable AD7091R internal voltage reference if no external vref is supplied. Signed-off-by: Marcelo Schmitt <marcelo.schmitt@analog.com> --- drivers/iio/adc/ad7091r-base.c | 9 ++++++--- drivers/iio/adc/ad7091r-base.h | 1 + 2 files changed, 7 insertions(+), 3 deletions(-)