From nobody Mon Sep 8 08:43:34 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 91E1EECAAD8 for ; Tue, 13 Sep 2022 17:12:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232102AbiIMRMA (ORCPT ); Tue, 13 Sep 2022 13:12:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232532AbiIMRLc (ORCPT ); Tue, 13 Sep 2022 13:11:32 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C5339568A; Tue, 13 Sep 2022 09:00:29 -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 ams.source.kernel.org (Postfix) with ESMTPS id 442CCB80F92; Tue, 13 Sep 2022 14:27:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4F46C433D7; Tue, 13 Sep 2022 14:27:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1663079230; bh=mobJGZFcfs84x6ygQFCoWpjPrj+Z9cYKBuqWlUjkdtg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=w5o93PNfwh1sM9qGO3j/GCe5ttaiCr0evK7ibLMRZpHAZoSmVjKVQ5P/7yYMmur/4 83gzA7wWL0lYuTWHOZ1zmRVLKVXThYrPU0So2sB2wS0Qztv+fltJ0ps3sSV+nh4Wmb 0S2ziRoJ14x8Mu1rfvErm1m5IRfEpAVKKNbcilyE= 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.4 027/108] iio: adc: mcp3911: use correct formula for AD conversion Date: Tue, 13 Sep 2022 16:05:58 +0200 Message-Id: <20220913140354.803984066@linuxfoundation.org> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220913140353.549108748@linuxfoundation.org> References: <20220913140353.549108748@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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@gmai= l.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) =20 -/* Internal voltage reference in uV */ -#define MCP3911_INT_VREF_UV 1200000 +/* Internal voltage reference in mV */ +#define MCP3911_INT_VREF_MV 1200 =20 #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 =20 *val =3D ret / 1000; } else { - *val =3D MCP3911_INT_VREF_UV; + *val =3D MCP3911_INT_VREF_MV; } =20 - *val2 =3D 24; - ret =3D IIO_VAL_FRACTIONAL_LOG2; + /* + * For 24bit Conversion + * Raw =3D ((Voltage)/(Vref) * 2^23 * Gain * 1.5 + * Voltage =3D Raw * (Vref)/(2^23 * Gain * 1.5) + */ + + /* val2 =3D (2^23 * 1.5) */ + *val2 =3D 12582912; + ret =3D IIO_VAL_FRACTIONAL; break; }