According to Jonathan, variable reference voltages are very rare. It is
unlikely it is needed, and supporting it makes the code a bit more
complex.
Simplify the driver and drop the variable vref support.
Suggested-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
---
Revision History:
v2:
- New patch
---
drivers/iio/adc/ti-adc128s052.c | 29 ++++++-----------------------
1 file changed, 6 insertions(+), 23 deletions(-)
diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
index 0f93c6266527..0bfe4e558c69 100644
--- a/drivers/iio/adc/ti-adc128s052.c
+++ b/drivers/iio/adc/ti-adc128s052.c
@@ -29,13 +29,12 @@ struct adc128_configuration {
struct adc128 {
struct spi_device *spi;
- struct regulator *reg;
/*
* Serialize the SPI 'write-channel + read data' accesses and protect
* the shared buffer.
*/
struct mutex lock;
-
+ int vref;
union {
__be16 rx_buffer;
u8 tx_buffer[2];
@@ -82,11 +81,7 @@ static int adc128_read_raw(struct iio_dev *indio_dev,
case IIO_CHAN_INFO_SCALE:
- ret = regulator_get_voltage(adc->reg);
- if (ret < 0)
- return ret;
-
- *val = ret / 1000;
+ *val = adc->vref / 1000;
*val2 = 12;
return IIO_VAL_FRACTIONAL_LOG2;
@@ -156,11 +151,6 @@ static const struct iio_info adc128_info = {
.read_raw = adc128_read_raw,
};
-static void adc128_disable_regulator(void *reg)
-{
- regulator_disable(reg);
-}
-
static int adc128_probe(struct spi_device *spi)
{
const struct adc128_configuration *config;
@@ -184,17 +174,10 @@ static int adc128_probe(struct spi_device *spi)
indio_dev->channels = config->channels;
indio_dev->num_channels = config->num_channels;
- adc->reg = devm_regulator_get(&spi->dev, config->refname);
- if (IS_ERR(adc->reg))
- return PTR_ERR(adc->reg);
-
- ret = regulator_enable(adc->reg);
- if (ret < 0)
- return ret;
- ret = devm_add_action_or_reset(&spi->dev, adc128_disable_regulator,
- adc->reg);
- if (ret)
- return ret;
+ adc->vref = devm_regulator_get_enable_read_voltage(&spi->dev,
+ config->refname);
+ if (adc->vref < 0)
+ return adc->vref;
if (config->num_other_regulators) {
ret = devm_regulator_bulk_get_enable(&spi->dev,
--
2.49.0
On 4/2/25 1:10 AM, Matti Vaittinen wrote:
> According to Jonathan, variable reference voltages are very rare. It is
> unlikely it is needed, and supporting it makes the code a bit more
> complex.
There is also around 60 other drivers where we could do something like this
in case anyone is bored. :-p
>
> Simplify the driver and drop the variable vref support.
>
> Suggested-by: Jonathan Cameron <jic23@kernel.org>
> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> ---
> Revision History:
> v2:
> - New patch
> ---
> drivers/iio/adc/ti-adc128s052.c | 29 ++++++-----------------------
> 1 file changed, 6 insertions(+), 23 deletions(-)
>
> diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
> index 0f93c6266527..0bfe4e558c69 100644
> --- a/drivers/iio/adc/ti-adc128s052.c
> +++ b/drivers/iio/adc/ti-adc128s052.c
> @@ -29,13 +29,12 @@ struct adc128_configuration {
> struct adc128 {
> struct spi_device *spi;
>
> - struct regulator *reg;
> /*
> * Serialize the SPI 'write-channel + read data' accesses and protect
> * the shared buffer.
> */
> struct mutex lock;
> -
> + int vref;
Units in the name are helpful: vref_uv.
Could also consider doing division in probe and storing vref_mv instead
since we never use the microvolts part.
> union {
> __be16 rx_buffer;
> u8 tx_buffer[2];
On Wed, 2 Apr 2025 15:49:01 -0500
David Lechner <dlechner@baylibre.com> wrote:
> On 4/2/25 1:10 AM, Matti Vaittinen wrote:
> > According to Jonathan, variable reference voltages are very rare. It is
> > unlikely it is needed, and supporting it makes the code a bit more
> > complex.
>
> There is also around 60 other drivers where we could do something like this
> in case anyone is bored. :-p
Hmm. It would be a gamble but also a nice cleanup.
We 'might' meet a case where someone notices it but seems fairly unlikely...
J
>
> >
> > Simplify the driver and drop the variable vref support.
> >
> > Suggested-by: Jonathan Cameron <jic23@kernel.org>
> > Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
> > ---
> > Revision History:
> > v2:
> > - New patch
> > ---
> > drivers/iio/adc/ti-adc128s052.c | 29 ++++++-----------------------
> > 1 file changed, 6 insertions(+), 23 deletions(-)
> >
> > diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
> > index 0f93c6266527..0bfe4e558c69 100644
> > --- a/drivers/iio/adc/ti-adc128s052.c
> > +++ b/drivers/iio/adc/ti-adc128s052.c
> > @@ -29,13 +29,12 @@ struct adc128_configuration {
> > struct adc128 {
> > struct spi_device *spi;
> >
> > - struct regulator *reg;
> > /*
> > * Serialize the SPI 'write-channel + read data' accesses and protect
> > * the shared buffer.
> > */
> > struct mutex lock;
> > -
> > + int vref;
>
> Units in the name are helpful: vref_uv.
>
> Could also consider doing division in probe and storing vref_mv instead
> since we never use the microvolts part.
>
> > union {
> > __be16 rx_buffer;
> > u8 tx_buffer[2];
>
On 02/04/2025 23:49, David Lechner wrote:
> On 4/2/25 1:10 AM, Matti Vaittinen wrote:
>> According to Jonathan, variable reference voltages are very rare. It is
>> unlikely it is needed, and supporting it makes the code a bit more
>> complex.
>
> There is also around 60 other drivers where we could do something like this
> in case anyone is bored. :-p
>
>>
>> Simplify the driver and drop the variable vref support.
>>
>> Suggested-by: Jonathan Cameron <jic23@kernel.org>
>> Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
>> ---
>> Revision History:
>> v2:
>> - New patch
>> ---
>> drivers/iio/adc/ti-adc128s052.c | 29 ++++++-----------------------
>> 1 file changed, 6 insertions(+), 23 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ti-adc128s052.c b/drivers/iio/adc/ti-adc128s052.c
>> index 0f93c6266527..0bfe4e558c69 100644
>> --- a/drivers/iio/adc/ti-adc128s052.c
>> +++ b/drivers/iio/adc/ti-adc128s052.c
>> @@ -29,13 +29,12 @@ struct adc128_configuration {
>> struct adc128 {
>> struct spi_device *spi;
>>
>> - struct regulator *reg;
>> /*
>> * Serialize the SPI 'write-channel + read data' accesses and protect
>> * the shared buffer.
>> */
>> struct mutex lock;
>> -
>> + int vref;
>
> Units in the name are helpful: vref_uv.
>
> Could also consider doing division in probe and storing vref_mv instead
> since we never use the microvolts part.
Ah, thanks for the suggestions. I agree with both.
>
>> union {
>> __be16 rx_buffer;
>> u8 tx_buffer[2];
>
Yours,
-- Matti
© 2016 - 2026 Red Hat, Inc.