Linux IIO development
 help / color / mirror / Atom feed
* iio: dac: ad5624r_spi.c - use of scan_type
@ 2024-12-18  8:38 Matti Vaittinen
  2024-12-18 20:53 ` David Lechner
  0 siblings, 1 reply; 4+ messages in thread
From: Matti Vaittinen @ 2024-12-18  8:38 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	linux-iio, linux-kernel

Hi dee Ho peeps,

I started drafting a driver for a ROHM DAC. I took a quick look at the 
ad5624r_spi.c, and the use of the 'scan_type' -field in the struct 
iio_chan_spec puzzled me.

I think this field is used by the driver to convert the data from user 
to register format while performing the INDIO_DIRECT_MODE raw writes. I 
don't spot any buffer usage. Furthermore, as far as I can say the 'sign' 
and 'storagebits' are unused.

My understanding has been that the scan_type is only intended for 
parsing the buffered values, and usually when the data direction is from 
driver to user.

I suppose I shouldn't copy the ad5624r_spi.c use of scan_type to a new 
driver. I'm somewhat tempted to send a patch which drops the scan_type 
from the ad5624r_spi.c, and adds the 'realbits' and 'shift' to the 
driver's internal struct ad5624r_state. This, however, will change the 
interface to userland so maybe it's best to not do that.

I wonder if I am missing something? (That wouldn't be unheard of XD). If 
not, then at least a documentary patch with a comment "don't do this in 
new drivers" might be Ok, or how do you see this?

Yours,
	-- Matti

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

* Re: iio: dac: ad5624r_spi.c - use of scan_type
  2024-12-18  8:38 iio: dac: ad5624r_spi.c - use of scan_type Matti Vaittinen
@ 2024-12-18 20:53 ` David Lechner
  2024-12-19  6:05   ` Matti Vaittinen
  0 siblings, 1 reply; 4+ messages in thread
From: David Lechner @ 2024-12-18 20:53 UTC (permalink / raw)
  To: Matti Vaittinen, Matti Vaittinen
  Cc: Lars-Peter Clausen, Michael Hennerich, Jonathan Cameron,
	linux-iio, linux-kernel

On 12/18/24 2:38 AM, Matti Vaittinen wrote:
> Hi dee Ho peeps,
> 
> I started drafting a driver for a ROHM DAC. I took a quick look at the ad5624r_spi.c, and the use of the 'scan_type' -field in the struct iio_chan_spec puzzled me.
> 
> I think this field is used by the driver to convert the data from user to register format while performing the INDIO_DIRECT_MODE raw writes. I don't spot any buffer usage. Furthermore, as far as I can say the 'sign' and 'storagebits' are unused.
> 
> My understanding has been that the scan_type is only intended for parsing the buffered values, and usually when the data direction is from driver to user.
> 
> I suppose I shouldn't copy the ad5624r_spi.c use of scan_type to a new driver. I'm somewhat tempted to send a patch which drops the scan_type from the ad5624r_spi.c, and adds the 'realbits' and 'shift' to the driver's internal struct ad5624r_state. This, however, will change the interface to userland so maybe it's best to not do that.
> 
> I wonder if I am missing something? (That wouldn't be unheard of XD). If not, then at least a documentary patch with a comment "don't do this in new drivers" might be Ok, or how do you see this?
> 
> Yours,
>     -- Matti
> 

I think scan_type is a convenient place to store this information even if
buffers aren't implemented. The struct is there whether we use it or not, so
might as well use it. And if buffer support is ever added, that is one less
thing to do (removing the duplicate fields).

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

* Re: iio: dac: ad5624r_spi.c - use of scan_type
  2024-12-18 20:53 ` David Lechner
@ 2024-12-19  6:05   ` Matti Vaittinen
  2024-12-19 12:20     ` Jonathan Cameron
  0 siblings, 1 reply; 4+ messages in thread
From: Matti Vaittinen @ 2024-12-19  6:05 UTC (permalink / raw)
  To: Lars-Peter Clausen, David Lechner, Matti Vaittinen
  Cc: Michael Hennerich, Jonathan Cameron, linux-iio, linux-kernel

On 18/12/2024 22:53, David Lechner wrote:
> On 12/18/24 2:38 AM, Matti Vaittinen wrote:
>> Hi dee Ho peeps,
>>
>> I started drafting a driver for a ROHM DAC. I took a quick look at the ad5624r_spi.c, and the use of the 'scan_type' -field in the struct iio_chan_spec puzzled me.
>>
>> I think this field is used by the driver to convert the data from user to register format while performing the INDIO_DIRECT_MODE raw writes. I don't spot any buffer usage. Furthermore, as far as I can say the 'sign' and 'storagebits' are unused.
>>
>> My understanding has been that the scan_type is only intended for parsing the buffered values, and usually when the data direction is from driver to user.
>>
>> I suppose I shouldn't copy the ad5624r_spi.c use of scan_type to a new driver. I'm somewhat tempted to send a patch which drops the scan_type from the ad5624r_spi.c, and adds the 'realbits' and 'shift' to the driver's internal struct ad5624r_state. This, however, will change the interface to userland so maybe it's best to not do that.

I think I was wrong here. I suppose plain scan_type population does not 
result user visible entries if buffer is not created. So, confusion 
stays in driver - but it also means changes wouldn't impact the userland.

>>
>> I wonder if I am missing something? (That wouldn't be unheard of XD). If not, then at least a documentary patch with a comment "don't do this in new drivers" might be Ok, or how do you see this?
>>
>> Yours,
>>      -- Matti
>>
> 
> I think scan_type is a convenient place to store this information even if
> buffers aren't implemented. The struct is there whether we use it or not,

Valid point.

> so
> might as well use it. And if buffer support is ever added, that is one less
> thing to do (removing the duplicate fields).

I find populating the scan_type still somewhat confusing for a reader. 
Kinda willing to hear what Jonathan thinks of it, he probably has 
broadest view on how to keep things consistent in IIO. If it is usual to 
use the scan_type without buffer, then this is totally fine with me.

I suppose the shifts and amount of bits are constants? In that regard 
one could also just use a define, which would make it possible to not 
add this information to any of the structs.

Out of the curiosity, do we use 'input buffers' in IIO? This far I've 
mostly worked with IIO devices focusing on output.

Thanks for sharing your opinion!

Yours,
	-- Matti


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

* Re: iio: dac: ad5624r_spi.c - use of scan_type
  2024-12-19  6:05   ` Matti Vaittinen
@ 2024-12-19 12:20     ` Jonathan Cameron
  0 siblings, 0 replies; 4+ messages in thread
From: Jonathan Cameron @ 2024-12-19 12:20 UTC (permalink / raw)
  To: Matti Vaittinen
  Cc: Lars-Peter Clausen, David Lechner, Matti Vaittinen,
	Michael Hennerich, linux-iio, linux-kernel

On Thu, 19 Dec 2024 08:05:17 +0200
Matti Vaittinen <mazziesaccount@gmail.com> wrote:

> On 18/12/2024 22:53, David Lechner wrote:
> > On 12/18/24 2:38 AM, Matti Vaittinen wrote:  
> >> Hi dee Ho peeps,
> >>
> >> I started drafting a driver for a ROHM DAC. I took a quick look at the ad5624r_spi.c, and the use of the 'scan_type' -field in the struct iio_chan_spec puzzled me.
> >>
> >> I think this field is used by the driver to convert the data from user to register format while performing the INDIO_DIRECT_MODE raw writes. I don't spot any buffer usage. Furthermore, as far as I can say the 'sign' and 'storagebits' are unused.
> >>
> >> My understanding has been that the scan_type is only intended for parsing the buffered values, and usually when the data direction is from driver to user.
> >>
> >> I suppose I shouldn't copy the ad5624r_spi.c use of scan_type to a new driver. I'm somewhat tempted to send a patch which drops the scan_type from the ad5624r_spi.c, and adds the 'realbits' and 'shift' to the driver's internal struct ad5624r_state. This, however, will change the interface to userland so maybe it's best to not do that.  
> 
> I think I was wrong here. I suppose plain scan_type population does not 
> result user visible entries if buffer is not created. So, confusion 
> stays in driver - but it also means changes wouldn't impact the userland.
> 
> >>
> >> I wonder if I am missing something? (That wouldn't be unheard of XD). If not, then at least a documentary patch with a comment "don't do this in new drivers" might be Ok, or how do you see this?
> >>
> >> Yours,
> >>      -- Matti
> >>  
> > 
> > I think scan_type is a convenient place to store this information even if
> > buffers aren't implemented. The struct is there whether we use it or not,  
> 
> Valid point.
> 
> > so
> > might as well use it. And if buffer support is ever added, that is one less
> > thing to do (removing the duplicate fields).  
> 
> I find populating the scan_type still somewhat confusing for a reader. 
> Kinda willing to hear what Jonathan thinks of it, he probably has 
> broadest view on how to keep things consistent in IIO. If it is usual to 
> use the scan_type without buffer, then this is totally fine with me.

I'm against filling it in if there is no use being made of it (which people
sometimes do) but I don't mind it being used for this sort of purpose.
The reasoning being that we wouldn't want duplication if buffered mode
was supported, and this is just using it in the way we would use it
under those circumstances.

I'm also against carrying it around if it's actually a constant, so bring
this in only when dealing with a driver supporting multiple values (either
multiple devices or channels where this is the only difference).

> 
> I suppose the shifts and amount of bits are constants? In that regard 
> one could also just use a define, which would make it possible to not 
> add this information to any of the structs.

Absolutely. If there is only one value used and no buffered support I'd
prefer to see it as a define used inline in the code.  The usual principle
of don't generalize until you need to applies here.


> 
> Out of the curiosity, do we use 'input buffers' in IIO? This far I've 
> mostly worked with IIO devices focusing on output.

There are some.  Look for IIO_BUFFER_DIRECTION_OUT. Eg. dac/ad3552r.c

It's relatively new infrastructure and for many DACs we support it isn't
worth the effort as they are more about tuning a signal than waveform
generation etc. Hence, not that many drivers yet and some of those
are using the IIO backend stuff with fpga IPs to get the data rates.

Jonathan

> 
> Thanks for sharing your opinion!
> 
> Yours,
> 	-- Matti
> 


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

end of thread, other threads:[~2024-12-19 12:20 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-12-18  8:38 iio: dac: ad5624r_spi.c - use of scan_type Matti Vaittinen
2024-12-18 20:53 ` David Lechner
2024-12-19  6:05   ` Matti Vaittinen
2024-12-19 12:20     ` Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox