Received: by 2002:ac0:aa62:0:0:0:0:0 with SMTP id w31-v6csp1886533ima; Thu, 25 Oct 2018 06:34:26 -0700 (PDT) X-Google-Smtp-Source: AJdET5ddwQKW+wfayJpKauG9IrdyibslujYvUaeOUEFzS/0yNXdiwxFIFX3hrLMkwQEb6d8hNb6I X-Received: by 2002:a62:7701:: with SMTP id s1-v6mr1608608pfc.159.1540474466123; Thu, 25 Oct 2018 06:34:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540474466; cv=none; d=google.com; s=arc-20160816; b=wS7y/D1uP525HdAuXEl1pqQU4/ioBLsmeL5GbiEq+jLpKIX2ZNQ7iScWzxfHpfNTfl rqnPOw3szoD3rQedZdvArsVzc2Smp+6UdjNRwLGPT91GcLk4C17AfASGeIc660kePoes m5+zCHqF9WdABT8k2X65wtQ98Q8OeMa0TQviuDVEuLObrvCcKQOcNy34S1e9xI3BNs+/ n70g3a6CfqPXf5xIMm9WRVNE/PfvQqsPOm2h36/3ihC8+OMsOljnBO4Xw7vyQSOq5j0V 0T7iLFGaUgIs4WPRvD5mEwYgALzV4XZoEoSaJQiXruL/t0FeJXaNvQd866QPfA9EQ+m2 0YNA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:content-disposition :mime-version:message-id:subject:cc:to:from:date:dkim-signature; bh=aoQwXLUABqhn/lJKD95mvDe1OgsY4lA2OFgkXLoK+jo=; b=IsPgcGZEH8nVslL8OYN/3/L7yqX8Hu3YzBuESBMEJnrAr9tgdNcxS61JPW7fsV9Iru ChiZ1t32p6G2Ax3tfOrWKcnyjePgUhJ3LYHwWbkOueHjWtgA5fzGrluUWxgHOcwChG6X Tk0zkBpx+2Y9oFRM0V+HZsUgEBJLi5XMoj65/eu119ZWaytXFcuzHhu+xw+Wiici6uoS 4sQLzBDnBmnAPP6OE19W6P5ddgeFhp8xejK5qBpXX6BVPzLm7I2DfAycOZsPE93qmnD+ sMF6DdwneAPWAn1wmnzUudwQwnDIGRmXHQoZKYj3o0JalFHGkbV/QeuacqQuKRdn3Q9+ 0mdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=ZVxJbJyR; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f32-v6si7749172pgf.203.2018.10.25.06.33.55; Thu, 25 Oct 2018 06:34: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=@gmail.com header.s=20161025 header.b=ZVxJbJyR; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727656AbeJYWFT (ORCPT + 99 others); Thu, 25 Oct 2018 18:05:19 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:34830 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727276AbeJYWFT (ORCPT ); Thu, 25 Oct 2018 18:05:19 -0400 Received: by mail-qk1-f195.google.com with SMTP id v68-v6so5677356qka.2; Thu, 25 Oct 2018 06:32:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=aoQwXLUABqhn/lJKD95mvDe1OgsY4lA2OFgkXLoK+jo=; b=ZVxJbJyRAbu8NYES1iGOkZhkonbeZfo0o8dIytY88LonlpYFG0qA6V5/5kwGyAz9Nw kGvpItkEjrcXooLrkikPvhNYcJilPLC7GvcSTnX76eCB8O44zOqSir47S1bQGcouSb9l QBD/JHVtmJicNHjNJYybDrGFggZzvE31BCk5WjCa4GxbX2Fgmhtj7m97RsERYEaVTVj3 pkmHKtSKDgRaw07sjF0oJkWtkiksbcF4UFLzoxowoQZhdETaPzpuBbZnVpk7NCZVx81Q auXi6hiSs2QACm8dMvddv7tDglAr4F9GOMfOOrrLa9pRakQutgffG+vrDXOqEjZ9CXwc aDTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=aoQwXLUABqhn/lJKD95mvDe1OgsY4lA2OFgkXLoK+jo=; b=r95NTJfK3WovUbT/2fbwG7g+bXHV4yAaS5DP4pBDf/s+vRVTcnibQj4Xe/wld1IzhO /hlPI8RdPoWs72/OiL1OPZD5UibIeGEZHS+fP9Xj7jwuaav777YBbeOQG3apUS/j5uhd EG4vJUO5nF2UJbIFQAlkglVVxvWOvRpU+N/9MOb7vMMQWvjEikXeg7ZX+Jr7gn2CgwuV SPWrRV99F8p5Ar0P9Yo7UVkgPKnXwcvYvZQLVvUzqry4KK85ErJTj1nChJzLa+VQgC4N LnW1HKWeM7YRL7brJoePnxSOkKweTX6JqVec4bkpVEMXVZo90bTkJDEIZ92cpcVykpA1 KD2g== X-Gm-Message-State: AGRZ1gLPghq8LnlvrBQvEIJKDMVsKKI7hFnX8ZK15yYvB/1dthRMUxQF itN6SKdzgHKUX3MfCrGhkXE= X-Received: by 2002:a37:2e05:: with SMTP id u5-v6mr1435437qkh.38.1540474352151; Thu, 25 Oct 2018 06:32:32 -0700 (PDT) Received: from renatolg ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id e5-v6sm3892422qtr.17.2018.10.25.06.32.28 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 25 Oct 2018 06:32:31 -0700 (PDT) Date: Thu, 25 Oct 2018 10:32:26 -0300 From: Renato Lui Geh To: lars@metafoo.de, Michael.Hennerich@analog.com, jic23@kernel.org, knaack.h@gmx.de, pmeerw@pmeerw.net, gregkh@linuxfoundation.org, alexandru.Ardelean@analog.com, stefan.popa@analog.com, giuliano.belinassi@usp.br Cc: linux-iio@vger.kernel.org, devel@driverdev.osuosl.org, linux-kernel@vger.kernel.org, kernel-usp@googlegroups.com Subject: [PATCH] staging: iio: ad7780: update voltage on read Message-ID: <20181025133223.kn7cjlyep7bmx2mm@renatolg> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline User-Agent: NeoMutt/20180716 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The ad7780 driver previously did not read the correct device output. This patch fixes two issues. - The driver read an outdated value set at initialization. It now updates its voltage on read. - Variable val subtracted an uninitialized value on IIO_CHAN_INFO_OFFSET. This was fixed by assiging the correct value instead. Signed-off-by: Renato Lui Geh --- drivers/staging/iio/adc/ad7780.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index b67412db0318..06700fe554a2 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -87,16 +87,20 @@ static int ad7780_read_raw(struct iio_dev *indio_dev, long m) { struct ad7780_state *st = iio_priv(indio_dev); + int voltage_uv = 0; switch (m) { case IIO_CHAN_INFO_RAW: return ad_sigma_delta_single_conversion(indio_dev, chan, val); case IIO_CHAN_INFO_SCALE: + voltage_uv = regulator_get_voltage(st->reg); + if (voltage_uv) + st->int_vref_mv = voltage_uv/1000; *val = st->int_vref_mv * st->gain; *val2 = chan->scan_type.realbits - 1; return IIO_VAL_FRACTIONAL_LOG2; case IIO_CHAN_INFO_OFFSET: - *val -= (1 << (chan->scan_type.realbits - 1)); + *val = -(1 << (chan->scan_type.realbits - 1)); return IIO_VAL_INT; } -- 2.19.1