Received: by 10.213.65.68 with SMTP id h4csp339361imn; Fri, 23 Mar 2018 05:54:35 -0700 (PDT) X-Google-Smtp-Source: AG47ELsF1fKcz2qf4OEpvGYNMzR88fQl3IfBq+4OmAh78DFe3egUUQmdQr7fBjQyDLJ0CT9xaA8n X-Received: by 10.101.64.68 with SMTP id h4mr2949332pgp.76.1521809675513; Fri, 23 Mar 2018 05:54:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521809675; cv=none; d=google.com; s=arc-20160816; b=w0RvQCZW72wvqcl7D7wKWhyqOdS2RFO6SIUPJkwuNPXL6ui/Hk4YAMOxPOkbQBRpg1 bdmTHTKtZbjNVkqbiWWkvbwmfVKexjKjfK/eiBasKIk++W/OneU/4IMhkwbce/swut1f 39EROyFqSP2ApKZuGB1X2rqJU3ibIgEs7QJwTiOv8sqDKifci+8+/evELjoLv0lAntXV h3qSFtrTP40dvwO5lewz31sDr69nHKhGl2HKneKRa2NAZ/ZgJRsuLREzWkND+TUgWeJl DAHoNaCpqk8Hb1+TaivpmN/eHB7Xhuwl2cg6/zyoze+gIW7WRIosqlfDNNy7fVPkm1LC cgow== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=uVMToluD17fn1/as8jGRHha8D1DqtFUtw5u8Z+Et7u0=; b=CNyELhqijo4LTNmj97jYMaAki57sFI3AMSNlrcbYu0YZV9SMrRSKGHG/b/LrnKrTBx swVvuV0e9EvJ94pYBBZnyuTuwZ82sTEakd0bhWltvLAoCPaCbYRk7OB2rL1JAf8Az8xT oBDPIHZA9fBdEp3XItzEcj07opMNBSHkDIuaz5sXxyXLgTkGIs2dHLoB/PXpZj2uDJ6m HdmrCW37/t/M/h052lswqvpRKy0kmYo8pUNIH+gMXcXB++tIzAg92I7qJE5T0Xvqw9uq oTiRArtGdrh9C6oTuVBCzKqZ3pbcUpyzk+agEsWQuhx4SQd5corh6vll5VxbQ4EKVrBY ouBA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e2si5944951pgs.556.2018.03.23.05.54.20; Fri, 23 Mar 2018 05:54:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752706AbeCWMxE convert rfc822-to-8bit (ORCPT + 99 others); Fri, 23 Mar 2018 08:53:04 -0400 Received: from szxga04-in.huawei.com ([45.249.212.190]:6680 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1752525AbeCWMxC (ORCPT ); Fri, 23 Mar 2018 08:53:02 -0400 Received: from DGGEMS410-HUB.china.huawei.com (unknown [172.30.72.59]) by Forcepoint Email with ESMTP id 8B73FBA902533; Fri, 23 Mar 2018 20:52:45 +0800 (CST) Received: from localhost (10.202.226.45) by DGGEMS410-HUB.china.huawei.com (10.3.19.210) with Microsoft SMTP Server (TLS) id 14.3.361.1; Fri, 23 Mar 2018 20:52:45 +0800 Date: Fri, 23 Mar 2018 12:52:36 +0000 From: Jonathan Cameron To: =?ISO-8859-1?Q?Hern=E1n?= Gonzalez CC: , , , , , , Subject: Re: [PATCH 08/11] staging: iio: ad7746: Add comments Message-ID: <20180323135236.00007d20@huawei.com> In-Reply-To: <1521642539-4845-9-git-send-email-hernan@vanguardiasur.com.ar> References: <1521642539-4845-1-git-send-email-hernan@vanguardiasur.com.ar> <1521642539-4845-9-git-send-email-hernan@vanguardiasur.com.ar> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.31; i686-w64-mingw32) MIME-Version: 1.0 Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8BIT X-Originating-IP: [10.202.226.45] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 21 Mar 2018 11:28:56 -0300 Hern?n Gonzalez wrote: > Add comments to clarify some of the calculations made, specially when > reading or writing values. > > Signed-off-by: Hern?n Gonzalez > --- > drivers/staging/iio/cdc/ad7746.c | 34 ++++++++++++++++++++++++++++------ > 1 file changed, 28 insertions(+), 6 deletions(-) > > diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c > index 8abba71..b6b99e2 100644 > --- a/drivers/staging/iio/cdc/ad7746.c > +++ b/drivers/staging/iio/cdc/ad7746.c > @@ -420,6 +420,7 @@ static int ad7746_write_raw(struct iio_dev *indio_dev, > goto out; > } > > + /* 2^16 in micro */ > val = (val2 * 1024) / 15625; > > switch (chan->type) { > @@ -546,6 +547,13 @@ static int ad7746_read_raw(struct iio_dev *indio_dev, > if (ret < 0) > goto out; > > + /* > + * Either for Capacitance, Voltage or Temperature, > + * the 0x000000 code represents negative full scale, > + * the 0x800000 code represents zero scale, and > + * the 0xFFFFFF code represents positive full scale. > + */ > + > *val = (be32_to_cpu(chip->data.d32) & 0xFFFFFF) - 0x800000; This should be left for userspace to deal with. That is it should be exported as an offset for the various channels rather than applied here. > > switch (chan->type) { > @@ -557,7 +565,13 @@ static int ad7746_read_raw(struct iio_dev *indio_dev, > *val = (*val * 125) / 256; > break; > case IIO_VOLTAGE: > - if (chan->channel == 1) /* supply_raw*/ > + > + /* > + * The voltage from the VDD pin is internally > + * attenuated by 6. Extra space before attenuated. > + */ > + > + if (chan->channel == 1) /* supply_raw */ > *val = *val * 6; > break; > default: > @@ -598,21 +612,28 @@ static int ad7746_read_raw(struct iio_dev *indio_dev, > ret = IIO_VAL_INT; > break; > case IIO_CHAN_INFO_OFFSET: > + > + /* > + * CAPDAC Scale = 21pF_typ / 127 > + * CIN Scale = 8.192pF / 2^24 > + * Offset Scale = CAPDAC Scale / CIN Scale = 338646 > + */ > + > *val = AD7746_CAPDAC_DACP(chip->capdac[chan->channel] > - [chan->differential]) * 338646; > + [chan->differential]) * 338646; This change should have been in the alignment fixing patch, not here. > > ret = IIO_VAL_INT; > break; > case IIO_CHAN_INFO_SCALE: > switch (chan->type) { > case IIO_CAPACITANCE: > - /* 8.192pf / 2^24 */ > + /* CIN Scale: 8.192pf / 2^24 */ > *val = 0; > *val2 = 488; > ret = IIO_VAL_INT_PLUS_NANO; > break; > case IIO_VOLTAGE: > - /* 1170mV / 2^23 */ > + /* VIN Scale: 1170mV / 2^23 */ > *val = 1170; > *val2 = 23; > ret = IIO_VAL_FRACTIONAL_LOG2; > @@ -666,7 +687,8 @@ static struct ad7746_platform_data *ad7746_parse_dt(struct device *dev) > unsigned int tmp; > int ret; > > - /* The default excitation outputs are not inverted, it should be stated > + /* > + * The default excitation outputs are not inverted, it should be stated > * in the dt if needed. > */ > > @@ -678,7 +700,7 @@ static struct ad7746_platform_data *ad7746_parse_dt(struct device *dev) > ret = of_property_read_u32(np, "adi,exclvl", &tmp); > if (ret || tmp > 3) { > dev_warn(dev, "Wrong exclvl value, using default\n"); > - pdata->exclvl = 3; /* default value */ > + pdata->exclvl = 3; > } else { > pdata->exclvl = tmp; > }