Received: by 2002:a05:6358:bb9e:b0:b9:5105:a5b4 with SMTP id df30csp4462812rwb; Tue, 6 Sep 2022 07:54:42 -0700 (PDT) X-Google-Smtp-Source: AA6agR4TnnGkJCT2Tg3J/dZSZ2N7IZ5ExjrJuZWgFKKyf4AdXsT5Kiz/RRcjrywmYBHRnGft/zj+ X-Received: by 2002:a05:6a00:1307:b0:53a:9663:1bd6 with SMTP id j7-20020a056a00130700b0053a96631bd6mr34516162pfu.55.1662476082475; Tue, 06 Sep 2022 07:54:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662476082; cv=none; d=google.com; s=arc-20160816; b=ZkQ3lLXNAXJCxKwRCIsMWOCg1Y63SbIPTwoWCwyRVR4HPld4GVZgSL0E9oxp07qHe2 eO9YBP9sf768H51xOPGkk/eCAsPZNM4f3L/4RgvIcGmVdR3dfyNvMN2t5MI9NqKyX0sy SwbvNHFeN8+nckdVokp7CbqY3au07tBC0+blIuIhO3DpbDfIrxDG8/ws1hgjvopW9aWe yckGNtSrVY2mou5GLmnjuX7wezTlkKHE45qNi5rnteePSw+bk1GblDnyJ8WbKp9mEchZ jGgAwQmQTaYawG1a337FuI1lzAVSIfxC8R2UcepLQ1swn/Z77ULbNIAnq7NN0wGr/+GQ 4z1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=v7D2AK8HTXd/eGWbSFW61Y+MuHwu8x2MxY0yWEeHKe8=; b=ctcfwvtZX/eGi7PDchUbHA0ii5chJKtOTLVLZvCWIbcP6zAofiGUIxsPLxOEVr0Zcv F/cjw7pH94V6MI8AFjRP4tjnHVrdXV0BCCNhK+hZKBQ0aU+U8XiXOqxyg8MC/Ncf+EQu m2ytdG+ZFgYPT+/n65MDQTtTohgdillUyraqKz3hqgUwaMVEuJA1PBmg9Skl0vpwM4Iv Z9DYmvo4xgUtf161SZTyYixF2T1NIGAaApGwSgmhvM+3zNt/vngcCvlSOUEIQbff11XD F/6TItJB/kCNzcL7gLP52YRir73yjWLFJXuiXTofdQMCDu++QQd4zah7vc2Zn4nFrnzt ecSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t5jmnSc4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id n15-20020a63ee4f000000b0042c3dd6e3ecsi14403109pgk.527.2022.09.06.07.54.31; Tue, 06 Sep 2022 07:54:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=t5jmnSc4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240612AbiIFNec (ORCPT + 99 others); Tue, 6 Sep 2022 09:34:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240628AbiIFNdr (ORCPT ); Tue, 6 Sep 2022 09:33:47 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8B427696B; Tue, 6 Sep 2022 06:33:08 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id AD5C861545; Tue, 6 Sep 2022 13:33:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id AF026C433C1; Tue, 6 Sep 2022 13:33:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1662471187; bh=mobJGZFcfs84x6ygQFCoWpjPrj+Z9cYKBuqWlUjkdtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=t5jmnSc4tYvFQOr3V8YwzGSMwVctUVXKnXFxNuS+WBDXkL2bjzlCidtPhKrZSU5AZ 6iFS2hQsg0xOAv+N2RKBzfQ0LeXwgo+1OcRABsKA7ouarzdLR6VunVNDZuX5UaRkUx 4/Dz9zWSYK34iNPjUblr9aLxZMku2fI12f55LT9k= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Marcus Folkesson , Andy Shevchenko , Stable@vger.kernel.org, Jonathan Cameron Subject: [PATCH 5.10 28/80] iio: adc: mcp3911: use correct formula for AD conversion Date: Tue, 6 Sep 2022 15:30:25 +0200 Message-Id: <20220906132818.125326445@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220906132816.936069583@linuxfoundation.org> References: <20220906132816.936069583@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Marcus Folkesson commit 9e2238e3ae40d371a1130226e0e740aa1601efa6 upstream. The ADC conversion is actually not rail-to-rail but with a factor 1.5. Make use of this factor when calculating actual voltage. Fixes: 3a89b289df5d ("iio: adc: add support for mcp3911") Signed-off-by: Marcus Folkesson Reviewed-by: Andy Shevchenko Link: https://lore.kernel.org/r/20220722130726.7627-4-marcus.folkesson@gmail.com Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Greg Kroah-Hartman --- drivers/iio/adc/mcp3911.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) --- a/drivers/iio/adc/mcp3911.c +++ b/drivers/iio/adc/mcp3911.c @@ -38,8 +38,8 @@ #define MCP3911_CHANNEL(x) (MCP3911_REG_CHANNEL0 + x * 3) #define MCP3911_OFFCAL(x) (MCP3911_REG_OFFCAL_CH0 + x * 6) -/* Internal voltage reference in uV */ -#define MCP3911_INT_VREF_UV 1200000 +/* Internal voltage reference in mV */ +#define MCP3911_INT_VREF_MV 1200 #define MCP3911_REG_READ(reg, id) ((((reg) << 1) | ((id) << 5) | (1 << 0)) & 0xff) #define MCP3911_REG_WRITE(reg, id) ((((reg) << 1) | ((id) << 5) | (0 << 0)) & 0xff) @@ -137,11 +137,18 @@ static int mcp3911_read_raw(struct iio_d *val = ret / 1000; } else { - *val = MCP3911_INT_VREF_UV; + *val = MCP3911_INT_VREF_MV; } - *val2 = 24; - ret = IIO_VAL_FRACTIONAL_LOG2; + /* + * For 24bit Conversion + * Raw = ((Voltage)/(Vref) * 2^23 * Gain * 1.5 + * Voltage = Raw * (Vref)/(2^23 * Gain * 1.5) + */ + + /* val2 = (2^23 * 1.5) */ + *val2 = 12582912; + ret = IIO_VAL_FRACTIONAL; break; }