Received: by 10.213.65.68 with SMTP id h4csp1302693imn; Wed, 21 Mar 2018 07:32:44 -0700 (PDT) X-Google-Smtp-Source: AG47ELtRBBwE6JkxbGoKmGPg7AHZAfS+fPJvh5caWACJ8c6UEJKqFVU0MmMwLLKntJKAWi/tzb7W X-Received: by 2002:a17:902:536c:: with SMTP id b99-v6mr13160532pli.399.1521642764861; Wed, 21 Mar 2018 07:32:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1521642764; cv=none; d=google.com; s=arc-20160816; b=ix8zgqQhhdFTo0uLe9hT8ZqxZBFrRuTNJVrzJ1OWeCPEAb+l83Hj0uvtXlWeVfdqoi DGRl04S8httbUtTiUrOQx33e1OaWt/kR6WpFIevzI3Z2dr8URZXzVkDNu+jdYsOVnqWu 0gaHX3VhEk8nuFDGuYc2pwtdJGnnKiki8vLO1ev0QqoK0YsTLTHCpJqcvLPZnKxNeX6k TBv5Vs5iA88w6nKrjhPNDNqIr0v5If4daqrO0Ne7FC/S2TVOyfZ6UJqiyA7fu0nhn7r+ HyneOWKFDqehqVTGTTXSu5oTUemfLIVqfpS3U8RMX/1aUtvpaQVRVgYHOFahIi5bcoxA vcrA== 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:date:subject:to:from :dkim-signature:arc-authentication-results; bh=LK1yVfQQLfpg0ROueYMCyXcrQoKw/MJ7iFhZE50WaIs=; b=IOLrDP3KX7kj3WRLZKmiIGDrYzKlankCiRtwlIyD/sPIqVF93BhBeybKncD6kcVk7q zw2sMkvCXPoQ4ImvUNg3PmKC6Jhn6/lCBPw+Y8IdKlZPP0ECk9r6LXRne1rIOmkw5Zi5 ECfyQAv7hOybo4ael672JY3Ue2Sh/GFXxZGsdIZlPm/Z+nh8RPfgfneP1lIyxlb0LRPK Gch2KNDCkvnLUktLco+h35XlScaUNirWdGaCjMd/43Xy6/F8nYehh+mku2Osl/lHjL0r fLBncYKNksVFa6Qkff52CM+gUOsO2ETpAoNwB4pvnn33T8Es+CpJFMm9NaBo6pWvFPNl iqaQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vanguardiasur-com-ar.20150623.gappssmtp.com header.s=20150623 header.b=J4OcoL5E; 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 n11-v6si1517403plg.236.2018.03.21.07.32.30; Wed, 21 Mar 2018 07:32:44 -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; dkim=pass header.i=@vanguardiasur-com-ar.20150623.gappssmtp.com header.s=20150623 header.b=J4OcoL5E; 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 S1752510AbeCUOag (ORCPT + 99 others); Wed, 21 Mar 2018 10:30:36 -0400 Received: from mail-qk0-f195.google.com ([209.85.220.195]:43324 "EHLO mail-qk0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752447AbeCUOa3 (ORCPT ); Wed, 21 Mar 2018 10:30:29 -0400 Received: by mail-qk0-f195.google.com with SMTP id g184so5612603qkd.10 for ; Wed, 21 Mar 2018 07:30:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vanguardiasur-com-ar.20150623.gappssmtp.com; s=20150623; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LK1yVfQQLfpg0ROueYMCyXcrQoKw/MJ7iFhZE50WaIs=; b=J4OcoL5EICCxK2QfOrOVnmtEMjuEvmzF299lzhyLfpLKOWv9wsYtJyARYbBz5qwXCq zWizSq95dlOx04mdQM3ARWb6IN807bnAuPCQW5BYtQCqejAOn3FY2tcj5oG5Sfv/8hI8 NwmO3B6Uv/w33/juHhCH6NY2vLZ+M38ZkTSaszWnW47esDTfgB20KfROeSAX3G5mpH8t ZBNGbuoixYezionBQFRYCbMwxu04WWlgQihei73Hc2Xg4+j4McN4tx1KNMX7WIDmLjpY 1Gd+fOr0AQ4N/BlMkgciedIgKpC+xQkLLyx1yZ6wMCei/ZUFhBjiKQzcbstzHWjskwVX 2n+w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LK1yVfQQLfpg0ROueYMCyXcrQoKw/MJ7iFhZE50WaIs=; b=oVml81r1ikN49NsaDPSJSHU2ICEy5A22N089hyKcCd0UIBF6cU5Wf1uOjL1PFi7tM2 ha01j5/e4MAKwyBIi6tMsHlPNs2tQ3i7hEGGE94FynW8o7B205Y3DxayRKNIWBkKgFjw GFYxn2wk8abHBt5eUr7AjpxhrV4/nOP6qSOt8SOgjKfxMj5u3ZmrpGH+AaDKlL8htQST opDXtkAT3To3FJwXyErc5H6EoJnhsdX0z/09aIB6CMBlRbJVhh11+r2KU3eG0Alqu76Q eG2nTfx7kWbxXgE2QPZYjHzpYRhEJyhUzrNr94t5Ps5KCFgBlOPRKRYQJE8k3q9XbB7B H6kw== X-Gm-Message-State: AElRT7H5ETJOFpdFSOM+A3bGIKV/DyTFH6tl78o1cJw8QmVvoX1ajRSH Yt5wS3+k7hVjrJIZGBiUEwpPog== X-Received: by 10.55.98.144 with SMTP id w138mr1789410qkb.300.1521642628696; Wed, 21 Mar 2018 07:30:28 -0700 (PDT) Received: from localhost.localdomain ([190.210.56.45]) by smtp.gmail.com with ESMTPSA id g14sm3118592qtk.71.2018.03.21.07.30.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Mar 2018 07:30:28 -0700 (PDT) From: =?UTF-8?q?Hern=C3=A1n=20Gonzalez?= To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, hernan@vanguardiasur.com.ar Subject: [PATCH 08/11] staging: iio: ad7746: Add comments Date: Wed, 21 Mar 2018 11:28:56 -0300 Message-Id: <1521642539-4845-9-git-send-email-hernan@vanguardiasur.com.ar> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1521642539-4845-1-git-send-email-hernan@vanguardiasur.com.ar> References: <1521642539-4845-1-git-send-email-hernan@vanguardiasur.com.ar> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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; 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. + */ + + 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; 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; } -- 2.7.4