From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5A9618E777; Wed, 3 Jul 2024 10:47:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720003667; cv=none; b=No+vprSMnZDc7qEEwYKNlXJKhP4IhTKE+MiPSfPv3Mp3YKH+KsU9SdxldYs55p8z0N9m5xCgDW6FRW9OsYDbiEWKcHiCJ5LU221Zzs4XIjkkMe1piK50BTEhjGUtHoOWEBUnJraJSkgf2Blz2m5dm5XZHZ59Z7SlWn2fdWpH8jM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720003667; c=relaxed/simple; bh=08M8ekhjuzdeYjV4lg2Lp7c+WoCC7+9Y+M637eWPqPo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=FHzdgJVok991QMnvCY/AYMyxVzYCN/hn2yApLdFItHBlw3Ugd6495KYHPJvgxsmCKJTHFvOagEf5cSwM5OWBSV5Aom5f9l3smWkrZhdVVJ38L7zBOBnoe4QB3nd1XQpiCxh12ZCvWJmFg0/GqBN0hmOZXHmM+o/pWZoSpM6+MtI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=RiWxGuhk; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="RiWxGuhk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id EE016C2BD10; Wed, 3 Jul 2024 10:47:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1720003667; bh=08M8ekhjuzdeYjV4lg2Lp7c+WoCC7+9Y+M637eWPqPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RiWxGuhksWPKcetHOgXCftLjnHC2v2AE9Etq6zAAzMko7Dhp5LHVbZnkkyNz7MDjh PHLEZqKiyGV0QFaUIWpVdaIkv0/9TPba6qfATevuk8xaVIM6BHwVh+7zbs6vFdFEFj j5lsuUkVzFDlc4rPrfg6IHPpCZzA/18s4XNOMj54= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Marc Ferland , Stable@vger.kernel.org, Jonathan Cameron , Sasha Levin Subject: [PATCH 4.19 092/139] iio: dac: ad5592r: fix temperature channel scaling value Date: Wed, 3 Jul 2024 12:39:49 +0200 Message-ID: <20240703102833.915176393@linuxfoundation.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240703102830.432293640@linuxfoundation.org> References: <20240703102830.432293640@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ From: Marc Ferland [ Upstream commit 279428df888319bf68f2686934897301a250bb84 ] The scale value for the temperature channel is (assuming Vref=2.5 and the datasheet): 376.7897513 When calculating both val and val2 for the temperature scale we use (3767897513/25) and multiply it by Vref (here I assume 2500mV) to obtain: 2500 * (3767897513/25) ==> 376789751300 Finally we divide with remainder by 10^9 to get: val = 376 val2 = 789751300 However, we return IIO_VAL_INT_PLUS_MICRO (should have been NANO) as the scale type. So when converting the raw temperature value to the 'processed' temperature value we will get (assuming raw=810, offset=-753): processed = (raw + offset) * scale_val = (810 + -753) * 376 = 21432 processed += div((raw + offset) * scale_val2, 10^6) += div((810 + -753) * 789751300, 10^6) += 45015 ==> 66447 ==> 66.4 Celcius instead of the expected 21.5 Celsius. Fix this issue by changing IIO_VAL_INT_PLUS_MICRO to IIO_VAL_INT_PLUS_NANO. Fixes: 56ca9db862bf ("iio: dac: Add support for the AD5592R/AD5593R ADCs/DACs") Signed-off-by: Marc Ferland Link: https://lore.kernel.org/r/20240501150554.1871390-1-marc.ferland@sonatest.com Cc: Signed-off-by: Jonathan Cameron Signed-off-by: Sasha Levin --- drivers/iio/dac/ad5592r-base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/dac/ad5592r-base.c b/drivers/iio/dac/ad5592r-base.c index 427946be41872..414134412a5f8 100644 --- a/drivers/iio/dac/ad5592r-base.c +++ b/drivers/iio/dac/ad5592r-base.c @@ -415,7 +415,7 @@ static int ad5592r_read_raw(struct iio_dev *iio_dev, s64 tmp = *val * (3767897513LL / 25LL); *val = div_s64_rem(tmp, 1000000000LL, val2); - return IIO_VAL_INT_PLUS_MICRO; + return IIO_VAL_INT_PLUS_NANO; } mutex_lock(&st->lock); -- 2.43.0