All of lore.kernel.org
 help / color / mirror / Atom feed
* ti-ads7950: selecting the adc input range
@ 2022-07-08  8:02 Uwe Kleine-König
  2022-07-08  9:28 ` Lars-Peter Clausen
  0 siblings, 1 reply; 6+ messages in thread
From: Uwe Kleine-König @ 2022-07-08  8:02 UTC (permalink / raw)
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen, kernel, Thorsten Scherer

[-- Attachment #1: Type: text/plain, Size: 1016 bytes --]

Hello,

the ADS7950 has a register bit (called TI_ADS7950_CR_RANGE_5V in the
driver) that selects the input range. Depending on that bit the input
range is either [0 .. V_{REF}] or [0 .. 2 * V_{REF}].

The driver currently defaults to setting that bit, so the range is the
big one.

On a machine here however I know the input is in the smaller range and
I'd like to benefit from the higher resolution of the small range. I
wonder how to make this tunable. Should that be done using a firmware
property? ("single-input-range" vs. "double-input-range"? Or input-range
= <1> vs. input-range = <2> which better matches the data sheet that
calls the two modes "Range 1 (0 to V_{REF})" and "Range 2 (0 to
2xV_{REF})") Or should this be made tunable via sysfs? (E.g. by writing
to the scale property? Or a separate property?)

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: ti-ads7950: selecting the adc input range
  2022-07-08  8:02 ti-ads7950: selecting the adc input range Uwe Kleine-König
@ 2022-07-08  9:28 ` Lars-Peter Clausen
  2022-07-08 10:35   ` Nuno Sá
  2022-07-09 17:10   ` Uwe Kleine-König
  0 siblings, 2 replies; 6+ messages in thread
From: Lars-Peter Clausen @ 2022-07-08  9:28 UTC (permalink / raw)
  To: Uwe Kleine-König, Jonathan Cameron
  Cc: linux-iio, kernel, Thorsten Scherer

On 7/8/22 10:02, Uwe Kleine-König wrote:
> Hello,
>
> the ADS7950 has a register bit (called TI_ADS7950_CR_RANGE_5V in the
> driver) that selects the input range. Depending on that bit the input
> range is either [0 .. V_{REF}] or [0 .. 2 * V_{REF}].
>
> The driver currently defaults to setting that bit, so the range is the
> big one.
>
> On a machine here however I know the input is in the smaller range and
> I'd like to benefit from the higher resolution of the small range. I
> wonder how to make this tunable. Should that be done using a firmware
> property? ("single-input-range" vs. "double-input-range"? Or input-range
> = <1> vs. input-range = <2> which better matches the data sheet that
> calls the two modes "Range 1 (0 to V_{REF})" and "Range 2 (0 to
> 2xV_{REF})") Or should this be made tunable via sysfs? (E.g. by writing
> to the scale property? Or a separate property?)

Hi,

Its a bit of a tricky one. You can find arguments for and against 
either. Like "devicetree is for hardware description and not application 
specific configuration data", or "I know which setting I want to use, 
having the kernel apply it makes it a lot easier".

What we've done in the past in the IIO framework is to make the scale 
property writable for such devices. Together with a scale_available 
property to list valid options. This is the most flexible option as it 
allows to change the setting at runtime for applications where it is 
required.

Maybe the right solution is a mix of both, have the property writable by 
default, but allow firmware to restrict the available options based on 
what the system designer though makes sense. E.g. on some boards having 
the ability to switch at runtime makes sense, on others it does not.

- Lars


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

* Re: ti-ads7950: selecting the adc input range
  2022-07-08  9:28 ` Lars-Peter Clausen
@ 2022-07-08 10:35   ` Nuno Sá
  2022-07-16 17:57     ` Jonathan Cameron
  2022-07-09 17:10   ` Uwe Kleine-König
  1 sibling, 1 reply; 6+ messages in thread
From: Nuno Sá @ 2022-07-08 10:35 UTC (permalink / raw)
  To: Lars-Peter Clausen, Uwe Kleine-König, Jonathan Cameron
  Cc: linux-iio, kernel, Thorsten Scherer

On Fri, 2022-07-08 at 11:28 +0200, Lars-Peter Clausen wrote:
> On 7/8/22 10:02, Uwe Kleine-König wrote:
> > Hello,
> > 
> > the ADS7950 has a register bit (called TI_ADS7950_CR_RANGE_5V in
> > the
> > driver) that selects the input range. Depending on that bit the
> > input
> > range is either [0 .. V_{REF}] or [0 .. 2 * V_{REF}].
> > 
> > The driver currently defaults to setting that bit, so the range is
> > the
> > big one.
> > 
> > On a machine here however I know the input is in the smaller range
> > and
> > I'd like to benefit from the higher resolution of the small range.
> > I
> > wonder how to make this tunable. Should that be done using a
> > firmware
> > property? ("single-input-range" vs. "double-input-range"? Or input-
> > range
> > = <1> vs. input-range = <2> which better matches the data sheet
> > that
> > calls the two modes "Range 1 (0 to V_{REF})" and "Range 2 (0 to
> > 2xV_{REF})") Or should this be made tunable via sysfs? (E.g. by
> > writing
> > to the scale property? Or a separate property?)
> 
> Hi,
> 
> Its a bit of a tricky one. You can find arguments for and against 
> either. Like "devicetree is for hardware description and not
> application 
> specific configuration data", or "I know which setting I want to use,
> having the kernel apply it makes it a lot easier".
> 
> What we've done in the past in the IIO framework is to make the scale
> property writable for such devices. Together with a scale_available 
> property to list valid options. This is the most flexible option as
> it 
> allows to change the setting at runtime for applications where it is 
> required.
> 

Yes, it's a tricky one and I have the feeling that thoughts about this
are changing frequently :).

Well, this feels identical to what I had in a DAC [1] I recently
upstreamed. IIRC, on the first version of the series or during
discussion on the RFC I also had in mind to make it configurable
through sysfs but Jonathan advised me to go with a fw property.

[1]:https://elixir.bootlin.com/linux/latest/source/drivers/iio/dac/ltc2688.c#L786

- Nuno Sá

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

* Re: ti-ads7950: selecting the adc input range
  2022-07-08  9:28 ` Lars-Peter Clausen
  2022-07-08 10:35   ` Nuno Sá
@ 2022-07-09 17:10   ` Uwe Kleine-König
  2022-07-09 18:17     ` Lars-Peter Clausen
  1 sibling, 1 reply; 6+ messages in thread
From: Uwe Kleine-König @ 2022-07-09 17:10 UTC (permalink / raw)
  To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio, Thorsten Scherer, kernel

[-- Attachment #1: Type: text/plain, Size: 2461 bytes --]

Hello,

On Fri, Jul 08, 2022 at 11:28:35AM +0200, Lars-Peter Clausen wrote:
> On 7/8/22 10:02, Uwe Kleine-König wrote:
> > Hello,
> > 
> > the ADS7950 has a register bit (called TI_ADS7950_CR_RANGE_5V in the
> > driver) that selects the input range. Depending on that bit the input
> > range is either [0 .. V_{REF}] or [0 .. 2 * V_{REF}].
> > 
> > The driver currently defaults to setting that bit, so the range is the
> > big one.
> > 
> > On a machine here however I know the input is in the smaller range and
> > I'd like to benefit from the higher resolution of the small range. I
> > wonder how to make this tunable. Should that be done using a firmware
> > property? ("single-input-range" vs. "double-input-range"? Or input-range
> > = <1> vs. input-range = <2> which better matches the data sheet that
> > calls the two modes "Range 1 (0 to V_{REF})" and "Range 2 (0 to
> > 2xV_{REF})") Or should this be made tunable via sysfs? (E.g. by writing
> > to the scale property? Or a separate property?)
> 
> Its a bit of a tricky one. You can find arguments for and against either.
> Like "devicetree is for hardware description and not application specific
> configuration data", or "I know which setting I want to use, having the
> kernel apply it makes it a lot easier".

The latter is usually not a good reason that the dt people would accept
:-)

> What we've done in the past in the IIO framework is to make the scale
> property writable for such devices. Together with a scale_available property
> to list valid options. This is the most flexible option as it allows to
> change the setting at runtime for applications where it is required.

Which driver would you recommend me to study for that approach?

> Maybe the right solution is a mix of both, have the property writable by
> default, but allow firmware to restrict the available options based on what
> the system designer though makes sense. E.g. on some boards having the
> ability to switch at runtime makes sense, on others it does not.

I can imagine that the board designer says: The input range is 0..5V, so
better don't restrict the range to 0..2.5V. And I'd expect the dt people
to accept such a binding. Unfortunately for me that's the wrong
direction :-)

Best regards
Uwe

-- 
Pengutronix e.K.                           | Uwe Kleine-König            |
Industrial Linux Solutions                 | https://www.pengutronix.de/ |

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

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

* Re: ti-ads7950: selecting the adc input range
  2022-07-09 17:10   ` Uwe Kleine-König
@ 2022-07-09 18:17     ` Lars-Peter Clausen
  0 siblings, 0 replies; 6+ messages in thread
From: Lars-Peter Clausen @ 2022-07-09 18:17 UTC (permalink / raw)
  To: Uwe Kleine-König
  Cc: Jonathan Cameron, linux-iio, Thorsten Scherer, kernel

On 7/9/22 19:10, Uwe Kleine-König wrote:
>
>> What we've done in the past in the IIO framework is to make the scale
>> property writable for such devices. Together with a scale_available property
>> to list valid options. This is the most flexible option as it allows to
>> change the setting at runtime for applications where it is required.
> Which driver would you recommend me to study for that approach?

The closest to what you want is probably ti-ads1015. You need to

  * implement the read_avail callback to get the possible values
  * set info_mask_shared_by_all_available to BIT(IIO_CHAN_INFO_SCALE)
    for the channels
  * implement the write_raw callback and handle IIO_CHAN_INFO_SCALE to
    update the setting
  * handle IIO_CHAN_INFO_SCALE in the read_raw callback to report the
    current scale


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

* Re: ti-ads7950: selecting the adc input range
  2022-07-08 10:35   ` Nuno Sá
@ 2022-07-16 17:57     ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2022-07-16 17:57 UTC (permalink / raw)
  To: Nuno Sá
  Cc: Lars-Peter Clausen, Uwe Kleine-König, linux-iio, kernel,
	Thorsten Scherer

On Fri, 08 Jul 2022 12:35:19 +0200
Nuno Sá <noname.nuno@gmail.com> wrote:

> On Fri, 2022-07-08 at 11:28 +0200, Lars-Peter Clausen wrote:
> > On 7/8/22 10:02, Uwe Kleine-König wrote:  
> > > Hello,
> > > 
> > > the ADS7950 has a register bit (called TI_ADS7950_CR_RANGE_5V in
> > > the
> > > driver) that selects the input range. Depending on that bit the
> > > input
> > > range is either [0 .. V_{REF}] or [0 .. 2 * V_{REF}].
> > > 
> > > The driver currently defaults to setting that bit, so the range is
> > > the
> > > big one.
> > > 
> > > On a machine here however I know the input is in the smaller range
> > > and
> > > I'd like to benefit from the higher resolution of the small range.
> > > I
> > > wonder how to make this tunable. Should that be done using a
> > > firmware
> > > property? ("single-input-range" vs. "double-input-range"? Or input-
> > > range
> > > = <1> vs. input-range = <2> which better matches the data sheet
> > > that
> > > calls the two modes "Range 1 (0 to V_{REF})" and "Range 2 (0 to
> > > 2xV_{REF})") Or should this be made tunable via sysfs? (E.g. by
> > > writing
> > > to the scale property? Or a separate property?)  
> > 
> > Hi,
> > 
> > Its a bit of a tricky one. You can find arguments for and against 
> > either. Like "devicetree is for hardware description and not
> > application 
> > specific configuration data", or "I know which setting I want to use,
> > having the kernel apply it makes it a lot easier".
> > 
> > What we've done in the past in the IIO framework is to make the scale
> > property writable for such devices. Together with a scale_available 
> > property to list valid options. This is the most flexible option as
> > it 
> > allows to change the setting at runtime for applications where it is 
> > required.
> >   
> 
> Yes, it's a tricky one and I have the feeling that thoughts about this
> are changing frequently :).
> 
> Well, this feels identical to what I had in a DAC [1] I recently
> upstreamed. IIRC, on the first version of the series or during
> discussion on the RFC I also had in mind to make it configurable
> through sysfs but Jonathan advised me to go with a fw property.

DACs sometimes have a safety issue (you can fry boards if you set them wrong
and it's not unheard of for designers to make them safe for only a particular
range on a multirange DAC).
Assuming this ADC is sensible that shouldn't be the case here... (famous
last words ;)

Jonathan

> 
> [1]:https://elixir.bootlin.com/linux/latest/source/drivers/iio/dac/ltc2688.c#L786
> 
> - Nuno Sá


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

end of thread, other threads:[~2022-07-16 17:47 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-08  8:02 ti-ads7950: selecting the adc input range Uwe Kleine-König
2022-07-08  9:28 ` Lars-Peter Clausen
2022-07-08 10:35   ` Nuno Sá
2022-07-16 17:57     ` Jonathan Cameron
2022-07-09 17:10   ` Uwe Kleine-König
2022-07-09 18:17     ` Lars-Peter Clausen

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.