From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-lf0-f44.google.com ([209.85.215.44]:33925 "EHLO mail-lf0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753843AbcGTOQV (ORCPT ); Wed, 20 Jul 2016 10:16:21 -0400 Received: by mail-lf0-f44.google.com with SMTP id l69so39350236lfg.1 for ; Wed, 20 Jul 2016 07:16:20 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <1468576754-3273-1-git-send-email-quentin.schulz@free-electrons.com> <1468576754-3273-3-git-send-email-quentin.schulz@free-electrons.com> From: Crt Mori Date: Wed, 20 Jul 2016 16:15:39 +0200 Message-ID: Subject: Re: [PATCH v2 2/4] iio: adc: add support for Allwinner SoCs ADC To: Quentin Schulz Cc: Jonathan Cameron , jdelvare@suse.com, Guenter Roeck , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , maxime.ripard@free-electrons.com, wens@csie.org, lee.jones@linaro.org, linux-kernel@vger.kernel.org, linux-hwmon@vger.kernel.org, Linux Iio , linux-arm-kernel@lists.infradead.org, thomas.petazzoni@free-electrons.com, antoine.tenart@free-electrons.com Content-Type: text/plain; charset=UTF-8 Sender: linux-hwmon-owner@vger.kernel.org List-Id: linux-hwmon@vger.kernel.org On 20 July 2016 at 14:37, Quentin Schulz wrote: > On 18/07/2016 15:18, Jonathan Cameron wrote: > [...] >>> + >>> + if (!wait_for_completion_timeout(&info->completion, >>> + msecs_to_jiffies(100))) { >>> + ret = -ETIMEDOUT; >>> + goto out; >>> + } >>> + >>> + if (info->flags & SUNXI_GPADC_ARCH_SUN4I) >>> + *val = info->temp_data * 133 - 257000; >> Why report as processed? I'd just report them as raw with the scale >> and offset provided. It's not a big thing, but if we can leave it so >> that the conversion only occurs when desired, why not? >> >> For in kernel users, this all happen 'automagically' anyway ;) >> > > Mmmmh, in the code above we apply the scale on the raw value and then > the offset. While in iio_convert_raw_to_processed > (http://lxr.free-electrons.com/source/drivers/iio/inkern.c#L507), the > offset is applied before the scale. > > The way would be to factorize the computation by scale: > Now: *val = raw * scale + offset > Then: *val = (raw + offset/scale) * scale > > But the offset is an integer and offset/scale is therefore rounded. > Currently, we have the following values: > sun4i: -257000/133 = -1932.3308270676691 > sun5i: -144700/100 = -1447 > sun6i: -271000/167 = -1622.754491017964 > > Do we accept such rounding? How much does this rounding bring as mistake on end result and is this acceptable for you? You can always multiply it by 1000 or more to get the precision you want out. > > If not, we either stay with the processed value in read_raw or patch > inkern to add an offset to apply after having applied the scale to the > raw value (val2 from iio_channel_read is yet unused with > IIO_CHAN_INFO_OFFSET for example, we could use that to specify an > offset2 to apply after the switch(scale_type)-case). > > [...] > Quentin > From mboxrd@z Thu Jan 1 00:00:00 1970 From: cmo@melexis.com (Crt Mori) Date: Wed, 20 Jul 2016 16:15:39 +0200 Subject: [PATCH v2 2/4] iio: adc: add support for Allwinner SoCs ADC In-Reply-To: References: <1468576754-3273-1-git-send-email-quentin.schulz@free-electrons.com> <1468576754-3273-3-git-send-email-quentin.schulz@free-electrons.com> Message-ID: To: linux-arm-kernel@lists.infradead.org List-Id: linux-arm-kernel.lists.infradead.org On 20 July 2016 at 14:37, Quentin Schulz wrote: > On 18/07/2016 15:18, Jonathan Cameron wrote: > [...] >>> + >>> + if (!wait_for_completion_timeout(&info->completion, >>> + msecs_to_jiffies(100))) { >>> + ret = -ETIMEDOUT; >>> + goto out; >>> + } >>> + >>> + if (info->flags & SUNXI_GPADC_ARCH_SUN4I) >>> + *val = info->temp_data * 133 - 257000; >> Why report as processed? I'd just report them as raw with the scale >> and offset provided. It's not a big thing, but if we can leave it so >> that the conversion only occurs when desired, why not? >> >> For in kernel users, this all happen 'automagically' anyway ;) >> > > Mmmmh, in the code above we apply the scale on the raw value and then > the offset. While in iio_convert_raw_to_processed > (http://lxr.free-electrons.com/source/drivers/iio/inkern.c#L507), the > offset is applied before the scale. > > The way would be to factorize the computation by scale: > Now: *val = raw * scale + offset > Then: *val = (raw + offset/scale) * scale > > But the offset is an integer and offset/scale is therefore rounded. > Currently, we have the following values: > sun4i: -257000/133 = -1932.3308270676691 > sun5i: -144700/100 = -1447 > sun6i: -271000/167 = -1622.754491017964 > > Do we accept such rounding? How much does this rounding bring as mistake on end result and is this acceptable for you? You can always multiply it by 1000 or more to get the precision you want out. > > If not, we either stay with the processed value in read_raw or patch > inkern to add an offset to apply after having applied the scale to the > raw value (val2 from iio_channel_read is yet unused with > IIO_CHAN_INFO_OFFSET for example, we could use that to specify an > offset2 to apply after the switch(scale_type)-case). > > [...] > Quentin >