lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <1543316945.22768.35.camel@analog.com>
Date:   Tue, 27 Nov 2018 11:11:49 +0000
From:   "Popa, Stefan Serban" <StefanSerban.Popa@...log.com>
To:     "giuliano.belinassi@...il.com" <giuliano.belinassi@...il.com>,
        "jic23@...nel.org" <jic23@...nel.org>
CC:     "kernel-usp@...glegroups.com" <kernel-usp@...glegroups.com>,
        "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
        "lars@...afoo.de" <lars@...afoo.de>,
        "knaack.h@....de" <knaack.h@....de>,
        "Ardelean, Alexandru" <alexandru.Ardelean@...log.com>,
        "Hennerich, Michael" <Michael.Hennerich@...log.com>,
        "linux-iio@...r.kernel.org" <linux-iio@...r.kernel.org>,
        "devel@...verdev.osuosl.org" <devel@...verdev.osuosl.org>,
        "pmeerw@...erw.net" <pmeerw@...erw.net>,
        "gregkh@...uxfoundation.org" <gregkh@...uxfoundation.org>,
        "Popa, Stefan Serban" <StefanSerban.Popa@...log.com>
Subject: Re: [PATCH] staging: iio: ad7780: Add gain & filter gpio support

On Lu, 2018-11-26 at 17:24 -0200, Giuliano Belinassi wrote:
Hi, please see bellow

> Hi, thank you for the review
> 
> > 
> > On Thu, 22 Nov 2018 11:01:00 +0000
> > "Popa, Stefan Serban" <StefanSerban.Popa@...log.com> wrote:
> > > 
> > > I think that instead of setting the gain directly, we should use
> > > the IIO_CHAN_INFO_SCALE attribute. At page 12 of the ad7780 datasheet
> > > there
> > > is a formula from which the output code can be calculated:
> > > Code = 2^(N − 1)
> > > × [(AIN × Gain /VREF) + 1]. So, by setting the scale from user space,
> > > the
> > > driver can calculate the correct gain by using the formula above.
> > > Also, it
> > > would be useful to introduce scale available.
> > > Furthermore, there is a new
> > > ad7124 adc driver which does this exact thing. Take a look here: http
> > > s://gi
> > > thub.com/analogdevicesinc/linux/blob/master/drivers/iio/adc/ad7124.c#
> > > L337.
> We have some questions about the code you provided to us:
>   1-) What is exactly the inputs for the write_raw function?

In your write_raw() function you need to add IIO_CHAN_INFO_SCALE case.
Setting the scale from user space looks something like this:
root:/sys/bus/iio/devices/iio:device0> echo 0.000298 > in_voltage_scale .
Furthermore, in your write_raw() function, val=0 and val2=298.
Knowing that full_scale_voltage = Vref / (gain * scale), we can calculate
the gain = Vref / (full_scale_voltage * scale). We only support two gains
(1 and 128), so we need to determine which one fits better with the desired
scale. Finally, all we have left to do is to set the gain. 
 
>   2-) Could you give more details about the math around lines 346-348?
> Is it correct to assume that the multiplication at line 346 won't
> overflow? (vref is an uint)

It is correct that Vref is in microvolts, so for example, Vref of 2.5V  =
2500000000uV. It won't overflow since we use the Vref as nominator, while
full_scale_voltage and scale are the denominators.

> 
> And regarding our code:
>   1-) The val in our write_raw function should be, in case of GAIN, a
> number that best approximate the actual gain value of 1 or 128? For
> instance, if the user inputs 126, we should default to 128?

We should not allow the the user to input the gain, he needs to input the
scale (see the mail from Jonathan and the above explanation). However, if
the calculated gain is one that is not supported, such as 126, we will set
the closest matching value, in this case 128.

>   2-) In the case of FILTER, is it the same? Is the user sending the
> value in mHz (milihertz)?

Yes, it is the same with the FILTER. You need to add
a IIO_CHAN_INFO_SAMP_FREQ case in your write_raw() function. From user
space, the input value should be in Hz, something like this:
root:/sys/bus/iio/devices/iio:device0> echo 10 >
in_voltage_sampling_frequency

> 
> Thank you
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ