iio: dac: ti-dac5571: make vref regulator optional
PATCH 1/1 iio: dac: ti-dac5571: make vref regulator optional
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.
--- drivers/iio/dac/ti-dac5571.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)
drivers/iio/dac/ti-dac5571.c +22 -8
@@ -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 ; }
Signature · 1 line
2.18.0
Jonathan Cameron
maintainerQuoted 6 lines · On Fri, 24 Aug 2018 22:24:47 +0200 Marcus Folkesson…
The
vrefregulator is declared as optional in the device-tree binding, but the driver does require it.Go for the device-tree binding and make the
vrefregulator optional.Signed-off-by Marcus Folkesson <[email protected]>
Hmm.
If you do a voltage get on a stub regulator it will return an error (IIRC).
So I am unconvinced this actually makes any real difference?
What am I missing?
Jonathan
Quoted 23 lines
--- drivers/iio/dac/ti-dac5571.c | 30 ++++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 8 deletions(-)drivers/iio/dac/ti-dac5571.c +3
-1@@ -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" );
drivers/iio/dac/ti-dac5571.c static int dac5571_probe(struct i2c_client *client, · line 348
Quoted 10 lines
drivers/iio/dac/ti-dac5571.c +8
-2-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);
That is as likely as not a deferred probe so it should not be as noisy as this. It may happen during a normal boot process a lot of times.
Quoted 34 lines
drivers/iio/dac/ti-dac5571.c +11
-5+ } - 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 ; }