Re: [PATCH v14 02/11] iio: afe: rescale: add INT_PLUS_{MICRO,NANO} support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Peter,

On Thu, Feb 10, 2022 at 05:42:25PM +0100, Peter Rosin wrote:
> Hi!
> 
> As usual, sorry for my low bandwidth.

No worries, I understand. It's been pretty slow on my end as well.

Thanks for still making time for this :-)

> On 2022-02-08 03:04, Liam Beguin wrote:
> > Some ADCs use IIO_VAL_INT_PLUS_{NANO,MICRO} scale types.
> > Add support for these to allow using the iio-rescaler with them.
> > 
> > Signed-off-by: Liam Beguin <liambeguin@xxxxxxxxx>
> > Reviewed-by: Peter Rosin <peda@xxxxxxxxxx>
> > ---
> >  drivers/iio/afe/iio-rescale.c | 35 +++++++++++++++++++++++++++++++++++
> >  1 file changed, 35 insertions(+)

...

> > @@ -41,6 +45,37 @@ int rescale_process_scale(struct rescale *rescale, int scale_type,
> >  		tmp *= rescale->numerator;
> >  		tmp = div_s64(tmp, 1000000000LL);
> >  		*val = tmp;
> > +		return scale_type;
> > +	case IIO_VAL_INT_PLUS_NANO:
> > +	case IIO_VAL_INT_PLUS_MICRO:
> > +		mult = scale_type == IIO_VAL_INT_PLUS_NANO ? GIGA : MEGA;
> 
> By now, we all agree that the big numbers in this context have nothing
> to do with unit prefixes of physical quantities, so the macros are not
> really appropriate. However, in this case we have IIO_VAL_INT_PLUS_NANO
> and IIO_VAL_INT_PLUS_MICRO. Not using "NANO : MICRO" here, and instead
> go with "GIGA : MEGA" is just plain silly, if you ask me.
> 
> So, either "NANO : MICRO" or "1000000000 : 1000000".
> 
> I'm not sold on the macros. I frankly don't see all that much value
> in them and am perfectly fine with raw numbers. To me, it just looks
> like someone has read somewhere that constants should not appear in
> the code, and from that concluded that #define TEN 10 is a good thing
> without thinking very much about it. There is also the possibility
> that someone who has never seen these defines thinks MEGA is 2^20
> instead of 10^6, because that is a much more likely candidate for a
> define in the frist place (not everybody knows all the digits of
> 1048576 by heart and 1 << 20 many times require extra brackets that
> might make it look more complicated than it needs to be).
> 
> Back to this case; the connection to the naming of IIO_VAL_INT_PLUS_NANO
> (and ..._MICRO) makes it ok to use the defines. So if you feel strongly
> about not using "1000000000 : 1000000" I'm ok with that.

I like that the macros make the number of zeros more "obvious" in a
sense, but honestly at this point, I'd rather go back to not using them.
Depending on who you ask, one way makes more sense than the other, at
least with the raw values, there's no ambiguity.

Cheers,
Liam

> Cheers,
> Peter



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux