Received: by 10.192.165.156 with SMTP id m28csp897845imm; Fri, 13 Apr 2018 09:40:26 -0700 (PDT) X-Google-Smtp-Source: AIpwx4+oX0KNUw3KR0wjmgLjsGlmRz+f4xKWnXV8QH/G0dl8xWmnYQ/QyFNsDTLj/fte2WHtez7r X-Received: by 10.98.87.150 with SMTP id i22mr12220025pfj.119.1523637626569; Fri, 13 Apr 2018 09:40:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523637626; cv=none; d=google.com; s=arc-20160816; b=KtcMHAH+upbWB6pQYrzyfZBmpaHABPlQMdnsDmwCUxFLkmJ9ul7LUUFvWxCvxhekn1 8RBXBkdTckdiZ5Z/pWme1I1PZdZVr0YZtPoeVRox5lxZt6DL7Dg52wJ9B+r8ykd7IApM oYnAyPPNUH1lfAaPLblhimw/T0BlBEygCsO4ZOY3D+1T0y7jN8tc3EDOQToeHv8OAJxp 3/N0voGbpVGgCnKqmjXaDaHAhQQUQKFILFIUbDDnVXFJrjel0bXAsQUE9B/xZsp6oECP 0BHGqXP4RKt79YuQWIrefZx8/m+8jd864/g/Imc4hh9ehjeGD9i86nUZBp9Gwnn+fqkg ve2g== 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:cc:to:from :dkim-signature:arc-authentication-results; bh=BsKK31nhh5Rq1Mce4tGGl6rCkS6mqlLVjHlIlGfPL+4=; b=q+m0SP/9ALpamaWLpea91VveziSGWv+LgwaMQ4UYq/udv4yofMCWFsvBOVpx6ybrOs M7Nj/8vFomaYyH82lhaetb7HAVGF/UecQwhy3eIaCbCy/6YXrbHE+pWZv1wUAA7xKYnX fiK2H0lYU1/VVcq+0NLFJ8BbJHyZ6xylKpuXzIFvBJRRm4N4l+gPmSBNAlMTqGOlWWyB l2hQE5ph8i6TOG2IgfmAtstIDIYGhvxnTR1+mY/Qo8BzK81JYKDgIAVkUuTFIXwWe8DI SbHwGcF24oqKDDQ3mvZIpP6R44PYC7FQI95oNz8vKNDlQm4qOzX5mVu7AFuQd5YbAHpQ qUcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vanguardiasur-com-ar.20150623.gappssmtp.com header.s=20150623 header.b=GQQoAU/m; 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 66si343720pgh.491.2018.04.13.09.40.12; Fri, 13 Apr 2018 09:40:26 -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=GQQoAU/m; 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 S1753170AbeDMQiv (ORCPT + 99 others); Fri, 13 Apr 2018 12:38:51 -0400 Received: from mail-qk0-f194.google.com ([209.85.220.194]:39091 "EHLO mail-qk0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752604AbeDMQik (ORCPT ); Fri, 13 Apr 2018 12:38:40 -0400 Received: by mail-qk0-f194.google.com with SMTP id j73so9724394qke.6 for ; Fri, 13 Apr 2018 09:38:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vanguardiasur-com-ar.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BsKK31nhh5Rq1Mce4tGGl6rCkS6mqlLVjHlIlGfPL+4=; b=GQQoAU/m7+NzByXGlDdeXrvdzBmUGM2JERskQURocRmevAVDaNjRtvC/k301OQJkPF w7Fm3RVCmmmxMCo01ExaEELvsxsIwundfu6M/RSD1e4J1Bo7gnEqBXC/9HcIx84D/JPD 2spPORC9vEKjiuI6ECApQcp9LmBqafthodc4IZfhL4FvGdJOF1VF8EYpuniTz7ExBkgk D5mZWLQk0pjHWbzgkb/Wb+6s4Ac1h0GWl/C2hEVX8hzXuwGug/FJV5ox9lbvL7MkkEN4 Zi5dQ6q1iVn806vieO+s0grkDC9wbmNQBCCAwoCdU9a8GvnupIvPk+lo32RdEO2OKe4P Bvrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BsKK31nhh5Rq1Mce4tGGl6rCkS6mqlLVjHlIlGfPL+4=; b=fk3QAphbxLjunn/vxY3A9gRBYov6l0SpCIPWix+Uc6xGhEWay8y4uygIPuq+9jZoIK WWZgrqFK4Fh1W03brhxUExa09jDh2/24JsnhyOfwykPjql08+R3oeARwmq+O577PqFrU /kbCPDB4D3Tm/Hv70XstNS3pC3wfFcb/Gim4+jlQwOOnar+LTtb17M3m+qttsMMwWm7m J9bhU9Qo6cEPqWb86+nIOQSbKLrMmFy46h9BRc5lqq41zDvmP8rB5TV5GpCUTRqHAN6Q pm5TB0Y5IE6qXeMpOEfj+6KSryNNfCzM6pa+6natu6c145baSGTuKbZ+Y8kLpJ+ZyY+G haAA== X-Gm-Message-State: ALQs6tDiMoRzEByIFe2251aYtddLaWkGZUX/wkMa/IWw4idh3T4wAwUN 9e2xnkjMb+rFDGB8qdZ7GTIQHA== X-Received: by 10.55.139.197 with SMTP id n188mr5101624qkd.212.1523637519911; Fri, 13 Apr 2018 09:38:39 -0700 (PDT) Received: from localhost.localdomain ([190.210.56.45]) by smtp.gmail.com with ESMTPSA id t82sm5024687qke.52.2018.04.13.09.38.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 13 Apr 2018 09:38:39 -0700 (PDT) From: =?UTF-8?q?Hern=C3=A1n=20Gonzalez?= To: jic23@kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, Michael.Hennerich@analog.com, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: =?UTF-8?q?Hern=C3=A1n=20Gonzalez?= Subject: [PATCH v2 10/14] staging: iio: ad7746: Add comments Date: Fri, 13 Apr 2018 13:36:47 -0300 Message-Id: <1523637411-8531-11-git-send-email-hernan@vanguardiasur.com.ar> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1523637411-8531-1-git-send-email-hernan@vanguardiasur.com.ar> References: <1523637411-8531-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 | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c index 05506bf9..ef0ebb5 100644 --- a/drivers/staging/iio/cdc/ad7746.c +++ b/drivers/staging/iio/cdc/ad7746.c @@ -429,6 +429,7 @@ static int ad7746_write_raw(struct iio_dev *indio_dev, goto out; } + /* 2^16 in micro */ val = (val2 * 1024) / 15625; switch (chan->type) { @@ -554,6 +555,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) { @@ -565,7 +573,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: @@ -606,6 +620,13 @@ 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; @@ -614,13 +635,13 @@ static int ad7746_read_raw(struct iio_dev *indio_dev, 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; @@ -674,7 +695,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. */ @@ -685,7 +707,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