Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp929016imd; Thu, 1 Nov 2018 07:45:03 -0700 (PDT) X-Google-Smtp-Source: AJdET5fN88n8+QUzDX8AALiB1ij4IdD6OcN5cgDYGcP0ouO5XXy3kHAF6SPf/HJnJIxzyvungz/D X-Received: by 2002:a63:e302:: with SMTP id f2mr7504294pgh.320.1541083503926; Thu, 01 Nov 2018 07:45:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541083503; cv=none; d=google.com; s=arc-20160816; b=WUmJ13x+w7xswB2+kbWkb7MLzghDDMnuS8Ybzy/HmvFiRagFfZFW78vp8/HU9+U5mv nkzbM/6KTBlnuQ/zS3MnDHvGxyAepfkTxpcqwvxSusWqLuiMzPdlcMS1jjlRNZEQm21C Cx1w/lqara+ZndY5BUIasus2h+xZUO5Q5u2qSHWMZZsLUO5JmZCQXFD+T8HHldAkiAj+ 32qHUIlAjx3nn8BaDXpmuYz0apLPgZCHL3m+lHn+3O4738fGuEza1kYf49OsCC3eQWdf +Z8IwbT7f8V8pFO4x++kkI0Fy9g/OwQe03/3LVIEvxNIgmFX/O1j8izN/vlB9LdW6nEt +34g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=o1HuJO1RUvHYO8Q8iTB6hQuobWCheoadrs6aZ7vHCNI=; b=Mo64WmlQLHBCwlrnNZwbmkK//mzG6g2NnCtAzxhlOJgaDLnx+So/n/orCCgZtrl53I o6vocrDocrjpArhYptFgEJdPjjYxCvOYFRt05DiOQApHvTvqInVAcs28pwS0NUoNV7mu 80+eE5EIbhqOPsiqPpGxKl3qE+Z8iri4TUBQIF0FHcmbQkUhVqrZnBXGffAqRq1n8Sfk nDgRO1bMgM52iDPog01GfvKSdY+hn78bwxqKeOzNiay5F2Olfc6WuQLtIjGqPBuG6ARh gBrCX4UKvs/etvTon8/B8fgLQVhAjhGg+g2ADbqsAY76mTEvhcFJUJaj66u0rh/uN+Mu Jwxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=nY10gtsG; 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 o127-v6si37312158pfb.128.2018.11.01.07.44.48; Thu, 01 Nov 2018 07:45:03 -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=nY10gtsG; 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 S1728983AbeKAXqp (ORCPT + 99 others); Thu, 1 Nov 2018 19:46:45 -0400 Received: from mail-qk1-f195.google.com ([209.85.222.195]:44981 "EHLO mail-qk1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728832AbeKAXqp (ORCPT ); Thu, 1 Nov 2018 19:46:45 -0400 Received: by mail-qk1-f195.google.com with SMTP id n12so12381058qkh.11; Thu, 01 Nov 2018 07:43:28 -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:references:mime-version :content-disposition:in-reply-to:user-agent; bh=o1HuJO1RUvHYO8Q8iTB6hQuobWCheoadrs6aZ7vHCNI=; b=nY10gtsG93nvrNjcVAcVuNlAnF+w1oTirQeSx2bZ/VkxfPvH69rp+m3ckEThXQvzvz vi/jgf2hipPe1tUnQ443J8Ld6JZacTZ08WoznWxmFWpaScFGkyRgQhlLQgwKGstxMvPR LIZypJp1hUmuklmJQ2gopUvmzUblfof2S2DKiHAYwQHn7DOJRYHevNkDcCrZIYK8SHgR cwrQDqdfmbvIjDrL4kH5OA/QDoNe0Xifh56YFRel8tr1SJgq7VFCrFLRKlwcT29dpDOO 6WF1Fd3fKRCe2o1mJQWabouYZr5fDJqVPmLMD441335iSRrunhGIuI1VZPp3rjwfO3TK acJQ== 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:references :mime-version:content-disposition:in-reply-to:user-agent; bh=o1HuJO1RUvHYO8Q8iTB6hQuobWCheoadrs6aZ7vHCNI=; b=lW5DaWNPVH4z0qto/7NSgi1rIsGMfrN9zRELFHUXCAwAjq+kKNMst0tonEYVruY+B3 tEoVfLb03kpxOZF9k5ZwCIi0mXSa03rSfIsZ0awZA+UpAiduFfhB0gmUnM+i+zEZY7L0 m0knVsZMLgPdEMw7uQipkNpDu7W9/JxhGpi8Tq+3yxGTezZKLR0067RaZwLz2Ma3VvvL 0XRkwgFc3Zt5PJKVHfpLbKM/I1Qs3KYt9GPQgSLUPa1xMZh85x1ZfrdbJBOK7ylqWueg rAfCIExpC2nix4OnRYmx7X1OgL14IsyUTIJ5xd4ZFfJBF06EvaLufKa8fRLxcS02H6Ti QUAg== X-Gm-Message-State: AGRZ1gLF/wxgqWjf+ataGsU0Qlkap7Y2E5KKRTq5HJV3vK8JLM51DpdE 0oB84+dhZM1U8+MrUXCFcHY= X-Received: by 2002:a37:8006:: with SMTP id b6-v6mr6658028qkd.178.1541083407989; Thu, 01 Nov 2018 07:43:27 -0700 (PDT) Received: from renatolg ([143.107.45.1]) by smtp.gmail.com with ESMTPSA id b134sm1201946qkg.78.2018.11.01.07.43.25 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 01 Nov 2018 07:43:27 -0700 (PDT) Date: Thu, 1 Nov 2018 11:43:23 -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, 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 v3 2/3] staging: iio: ad7780: update voltage on read Message-ID: <1bc4bdf6342d4bc0c2fea17fb3bcd79fabf0e1d1.1541082656.git.renatogeh@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Disposition: inline In-Reply-To: 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, as it read an outdated value set at initialization. It now updates its voltage on read. Signed-off-by: Renato Lui Geh --- Changes in v3: - removed initialization (int voltage_uv = 0) - returns error when voltage_uv is null 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 91e016d534ed..f2a11e9424cd 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -87,12 +87,16 @@ static int ad7780_read_raw(struct iio_dev *indio_dev, long m) { struct ad7780_state *st = iio_priv(indio_dev); + int voltage_uv; switch (m) { case IIO_CHAN_INFO_RAW: return ad_sigma_delta_single_conversion(indio_dev, chan, val); case IIO_CHAN_INFO_SCALE: - *val = st->int_vref_mv * st->gain; + voltage_uv = regulator_get_voltage(st->reg); + if (!voltage_uv) + return -EINVAL; + *val = (voltage_uv / 1000) * st->gain; *val2 = chan->scan_type.realbits - 1; return IIO_VAL_FRACTIONAL_LOG2; case IIO_CHAN_INFO_OFFSET: -- 2.19.1