linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] iio: dac: ti-dac5571: make vref regulator optional
@ 2018-08-24 20:24 Marcus Folkesson
  2018-08-25  8:55 ` Jonathan Cameron
  0 siblings, 1 reply; 2+ messages in thread
From: Marcus Folkesson @ 2018-08-24 20:24 UTC (permalink / raw)
  To: Jonathan Cameron, Hartmut Knaack, Lars-Peter Clausen,
	Peter Meerwald-Stadler
  Cc: linux-iio, linux-kernel, Marcus Folkesson

The `vref` regulator is declared as optional in the device-tree binding,
but the driver does require it.

Go for the device-tree binding and make the `vref` regulator optional.

Signed-off-by: Marcus Folkesson <marcus.folkesson@gmail.com>
---
 drivers/iio/dac/ti-dac5571.c | 30 ++++++++++++++++++++++--------
 1 file changed, 22 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/dac/ti-dac5571.c b/drivers/iio/dac/ti-dac5571.c
index f6dcd8bce2b0..bf21cc312096 100644
--- a/drivers/iio/dac/ti-dac5571.c
+++ b/drivers/iio/dac/ti-dac5571.c
@@ -251,6 +251,9 @@ static int dac5571_read_raw(struct iio_dev *indio_dev,
 		return IIO_VAL_INT;
 
 	case IIO_CHAN_INFO_SCALE:
+		if (!data->vref)
+			return -EOPNOTSUPP;
+
 		ret = regulator_get_voltage(data->vref);
 		if (ret < 0)
 			return ret;
@@ -335,13 +338,21 @@ static int dac5571_probe(struct i2c_client *client,
 	indio_dev->num_channels = spec->num_channels;
 	data->spec = spec;
 
-	data->vref = devm_regulator_get(dev, "vref");
-	if (IS_ERR(data->vref))
-		return PTR_ERR(data->vref);
+	data->vref = devm_regulator_get_optional(dev, "vref");
+	if (IS_ERR(data->vref)) {
+		if (PTR_ERR(data->vref) == -ENODEV) {
+			data->vref = NULL;
+		} else {
+			dev_err(dev, "failed to get regulator (%ld)\n",
+					PTR_ERR(data->vref));
+			return PTR_ERR(data->vref);
+		}
 
-	ret = regulator_enable(data->vref);
-	if (ret < 0)
-		return ret;
+	} else {
+		ret = regulator_enable(data->vref);
+		if (ret)
+			return ret;
+	}
 
 	mutex_init(&data->lock);
 
@@ -373,7 +384,9 @@ static int dac5571_probe(struct i2c_client *client,
 	return 0;
 
  err:
-	regulator_disable(data->vref);
+	if (data->vref)
+		regulator_disable(data->vref);
+
 	return ret;
 }
 
@@ -383,7 +396,8 @@ static int dac5571_remove(struct i2c_client *i2c)
 	struct dac5571_data *data = iio_priv(indio_dev);
 
 	iio_device_unregister(indio_dev);
-	regulator_disable(data->vref);
+	if (data->vref)
+		regulator_disable(data->vref);
 
 	return 0;
 }
-- 
2.18.0

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

end of thread, other threads:[~2018-08-25 12:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-08-24 20:24 [PATCH] iio: dac: ti-dac5571: make vref regulator optional Marcus Folkesson
2018-08-25  8:55 ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).