All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/2] iio: adc: ad799x: Implement selecting external reference voltage input on AD7991, AD7995 and AD7999.
@ 2021-09-08 15:25 Florian Boor
  2021-09-08 15:25 ` [PATCH v2 2/2] dt-binding: iio: Add documentation for AD799x driver Florian Boor
  2021-09-11 16:43 ` [PATCH v2 1/2] iio: adc: ad799x: Implement selecting external reference voltage input on AD7991, AD7995 and AD7999 Jonathan Cameron
  0 siblings, 2 replies; 5+ messages in thread
From: Florian Boor @ 2021-09-08 15:25 UTC (permalink / raw)
  To: jic23; +Cc: linux-iio, Jonathan.Cameron, Michael.Hennerich, Florian Boor

Make use of the AD7991_REF_SEL bit and support using the external
reference voltage if 'vref-supply' is present.

Signed-off-by: Florian Boor <florian.boor@kernelconcepts.de>
---

Changes in v2:
- Check if a provided external vref regulator is provided.
- Drop unused setting
- Add ad79xx documentation (second patch)

 drivers/iio/adc/ad799x.c | 21 +++++++++++++++++++--
 1 file changed, 19 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/adc/ad799x.c b/drivers/iio/adc/ad799x.c
index 18bf8386d50a..2ff926a4e9b3 100644
--- a/drivers/iio/adc/ad799x.c
+++ b/drivers/iio/adc/ad799x.c
@@ -770,6 +770,8 @@ static int ad799x_probe(struct i2c_client *client,
 				   const struct i2c_device_id *id)
 {
 	int ret;
+	int extra_config = 0;
+	bool vref_external = true;
 	struct ad799x_state *st;
 	struct iio_dev *indio_dev;
 	const struct ad799x_chip_info *chip_info =
@@ -797,7 +799,15 @@ static int ad799x_probe(struct i2c_client *client,
 	ret = regulator_enable(st->reg);
 	if (ret)
 		return ret;
-	st->vref = devm_regulator_get(&client->dev, "vref");
+		
+	/* check if an external reference is supplied */
+	st->vref = devm_regulator_get_optional(&client->dev, "vref");
+
+	if (PTR_ERR(st->vref) == -ENODEV) {
+		vref_external = false;
+		/* get dummy */
+		st->vref = devm_regulator_get(&client->dev, "vref");
+	}
 	if (IS_ERR(st->vref)) {
 		ret = PTR_ERR(st->vref);
 		goto error_disable_reg;
@@ -806,6 +816,13 @@ static int ad799x_probe(struct i2c_client *client,
 	if (ret)
 		goto error_disable_reg;
 
+	/* use external reference voltage, optional if regulator present */
+	if (vref_external && 
+	   ((st->id == ad7991) || (st->id == ad7995) || (st->id == ad7999))) {
+		dev_info(&client->dev, "Using external reference voltage\n");
+		extra_config |= AD7991_REF_SEL;
+	}
+
 	st->client = client;
 
 	indio_dev->name = id->name;
@@ -815,7 +832,7 @@ static int ad799x_probe(struct i2c_client *client,
 	indio_dev->channels = st->chip_config->channel;
 	indio_dev->num_channels = chip_info->num_channels;
 
-	ret = ad799x_update_config(st, st->chip_config->default_config);
+	ret = ad799x_update_config(st, st->chip_config->default_config | extra_config);
 	if (ret)
 		goto error_disable_vref;
 
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-14 13:21 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-08 15:25 [PATCH v2 1/2] iio: adc: ad799x: Implement selecting external reference voltage input on AD7991, AD7995 and AD7999 Florian Boor
2021-09-08 15:25 ` [PATCH v2 2/2] dt-binding: iio: Add documentation for AD799x driver Florian Boor
2021-09-11 16:34   ` Jonathan Cameron
2021-09-11 16:43 ` [PATCH v2 1/2] iio: adc: ad799x: Implement selecting external reference voltage input on AD7991, AD7995 and AD7999 Jonathan Cameron
2021-09-14 13:21   ` Florian Boor

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.