mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Hernán Gonzalez" <hernan@vanguardiasur.com.ar>
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	[thread overview]
Message-ID: <1521642539-4845-9-git-send-email-hernan@vanguardiasur.com.ar> (raw)
In-Reply-To: <1521642539-4845-1-git-send-email-hernan@vanguardiasur.com.ar>

Add comments to clarify some of the calculations made, specially when
reading or writing values.

Signed-off-by: Hernán Gonzalez <hernan@vanguardiasur.com.ar>
---
 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

  parent reply	other threads:[~2018-03-21 14:30 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-21 14:28 [PATCH 00/11] Move ad7746 out of staging Hernán Gonzalez
2018-03-21 14:28 ` [PATCH 01/11] staging: iio: ad7746: Adjust arguments to match open parenthesis Hernán Gonzalez
2018-03-23 12:36   ` Jonathan Cameron
2018-03-21 14:28 ` [PATCH 02/11] staging: iio: ad7746: Fix multiple line dereference Hernán Gonzalez
2018-03-21 14:28 ` [PATCH 03/11] staging: iio: ad7746: Reorder includes alphabetically Hernán Gonzalez
2018-03-21 14:28 ` [PATCH 04/11] staging: iio: ad7746: Reorder variable declarations Hernán Gonzalez
2018-03-23 12:40   ` Jonathan Cameron
2018-03-21 14:28 ` [PATCH 05/11] staging: iio: ad7746: Remove unused defines Hernán Gonzalez
2018-03-23 12:44   ` Jonathan Cameron
2018-03-21 14:28 ` [PATCH 06/11] staging: iio: ad7746: Add dt-bindings Hernán Gonzalez
2018-03-23 12:46   ` Jonathan Cameron
2018-03-21 14:28 ` [PATCH 07/11] staging: iio: ad7746: Add remove() Hernán Gonzalez
2018-03-23 12:48   ` Jonathan Cameron
2018-03-21 14:28 ` Hernán Gonzalez [this message]
2018-03-23 12:52   ` [PATCH 08/11] staging: iio: ad7746: Add comments Jonathan Cameron
2018-03-21 14:28 ` [PATCH 09/11] staging: iio: ad7746: Add devicetree bindings documentation Hernán Gonzalez
2018-03-23 12:54   ` Jonathan Cameron
2018-03-21 14:28 ` [PATCH 10/11] staging: iio: ad7746: Rename sysfs attrs to comply with the ABI Hernán Gonzalez
2018-03-23 12:57   ` Jonathan Cameron
2018-03-21 14:28 ` [PATCH 11/11] Move cdc ad7746 driver out of staging to mainline iio Hernán Gonzalez
2018-03-23 10:21   ` kbuild test robot
2018-03-23 12:33     ` Jonathan Cameron
2018-03-23 12:59   ` Jonathan Cameron
2018-03-23 13:04 ` [PATCH 00/11] Move ad7746 out of staging Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1521642539-4845-9-git-send-email-hernan@vanguardiasur.com.ar \
    --to=hernan@vanguardiasur.com.ar \
    --cc=Michael.Hennerich@analog.com \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®