Received: by 2002:ab2:60d1:0:b0:1f7:5705:b850 with SMTP id i17csp532291lqm; Wed, 1 May 2024 08:06:11 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCX+wk4XoAtmwH4Yt8bC4EpHL96292m3qmWnGTx/tAP4lxDaAVtaa/tNmeVIK2C6xPVU8Po5YQqOss56fez3noIdgKVpaVcsAn4AJTuBCA== X-Google-Smtp-Source: AGHT+IHdFNmHTDbL9tih8ANgXfGVEfs/EUwwEHl/J0OEWawqYcYTFDTJU4eDBCWfvCGczgR3ABHp X-Received: by 2002:a50:c30a:0:b0:572:943a:cdf2 with SMTP id a10-20020a50c30a000000b00572943acdf2mr2139032edb.1.1714575969803; Wed, 01 May 2024 08:06:09 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1714575969; cv=pass; d=google.com; s=arc-20160816; b=0Uir8bwdWwGYd7UKb4JaXUD93J6eGifxUQTnuM4+FFUCX1JEZnu2uVefgQuHTMckWp 9PlcOYWr4JBG2UFXWcJXJjElRgSEItfhpQiNZ1GCywv51SF2hH8P+mol9bnYNzIpDOQT nNQmxFtQtHmVPi5zqKNp1KoR530Un0ks944w8gE4Wbdn5kgXY4p8EWUadJ4ECcCKG5kN /R7Zqqjv/iGkTvjusdQoN6lfkKvvvCKJ25Yx8/+6gVRhKuiyhhwXQI9dmfqhW7Ki7GCB qjBIEKKYdTpg06iLt6pTBHrn00RV+KCs8+EygMU6SkdkduRugQAlOSmFOuMjtzjSFkUQ Xs5w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=Fb5C+Oc43A6y8Mz0LyTdT4dWeHAlemsr8HHVEt5MmiU=; fh=doJ/Hj1+nkz6YlC2UBHwxEnUTb4jOWuyGgzNcfVXr88=; b=uLfaxbBQX0J7GOXpUlwtP29bOcvnrwVp7wYm6UvdtwL5uRXGqJu8vMpXzGZoiJNkqC fN+TpY0u5OEO1wAvYGJXad5IH/LD4lpk6uNSYs818y07EQC4cQ7SjxSCNUX0Zcv9pUSA sQkKV+FmfgIfvCxHMK2MFry1m0bmcj4cakfr5YWnCHlKAuqnhOx7wYIGj0zjvWBcIfML hMkbrRxVYr9VOetEzr479uOoHkGuVlvY3jB/j5znB8cvLm9zFkfbdjsU/rjGEh7oj1Xq CaeywIUCPXqsJJ9cHvAWLy0x2yi15f4QCnCmUVe4Z20u5i7cygS1W1Nwgh7Tjnke4kpY UXuw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DZrR9QJ7; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-165415-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165415-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id v13-20020aa7d64d000000b00572a8a567e2si1114283edr.71.2024.05.01.08.06.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 08:06:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-165415-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=DZrR9QJ7; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-165415-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-165415-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8892F1F21510 for ; Wed, 1 May 2024 15:06:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5A2A12F582; Wed, 1 May 2024 15:06:03 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DZrR9QJ7" Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 806891F176; Wed, 1 May 2024 15:06:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.176 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714575963; cv=none; b=IdijetVErK/HhUn/EozeBDwPTkpixWnV9QX2Jas8lsfyJjPXCTnhMIAWFhhlaiVaYjFSMMkXZ1BLtLKWwP+1Nw402vQHdN2pYz2afyqVWADurRFWHtz7h+V3xiVoNopH74NQVj73NVCNmTfSeGUv8M3s5VLgk4gPHyEBZcpd0X0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714575963; c=relaxed/simple; bh=ZwcoVXh6+PU1Qu8+uoknJ6rPtJiNfbVuHlJ8BsHXYqA=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=tz6UJZP0YrnH5RIKI8OZsxIX3HuVNwK9s99S/NGKIeK+9T2l1eYsmfNUnKsV+Zd4ZGykTMC7KS1Ot65TGR00PS//xfzQUeGSM/sCf1PS/a9TQBdvH7lk8ndI2hVPatmSAeV+wuojM8JdArQoVTXRYEYkR10SCKgQxrKCUd7MzGY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DZrR9QJ7; arc=none smtp.client-ip=209.85.208.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-lj1-f176.google.com with SMTP id 38308e7fff4ca-2df83058d48so57894911fa.1; Wed, 01 May 2024 08:06:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1714575960; x=1715180760; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=Fb5C+Oc43A6y8Mz0LyTdT4dWeHAlemsr8HHVEt5MmiU=; b=DZrR9QJ7kn13Z+/kt5/Hny+CgW8udKSowgsKkI8vnlnFjWMtgoWCscLsMwQ20vJSz3 dTEXbHp/t9qmG29Vt5krBKlu7QCFHvZesdhGEL/KQfQtZhmWjxWsl/4Y+IIau1FWBXVv CTyH3P4a4AN90gXUkncA1ruajt5leGLVxPH6ndNk/fW7P6OGi0FtIhwJYrgBZydi2Pvp rE4+pJbKqeYogq59hp+i3mJZgwdXo9sgUepQHsWklCN8fgW8oA7oXqA4rSsDslImzy/4 ZhXlUCJWBU9QUJxYN+0N9/sIHnyyHqhnBa//YfES+eqneSE5UAp8NBPzs+gpALxtJufk 1pQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1714575960; x=1715180760; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Fb5C+Oc43A6y8Mz0LyTdT4dWeHAlemsr8HHVEt5MmiU=; b=ugYeE+x2viOkjJI0f7ZkG2e2DiwbI3AYzbMgZGeWvX2rU5sE2OVoiSY3GsRi5CVEMX EMxxZmH9lbqhwepkmLAXe+wRIKF7TzkYVtwIJ0woskLOQwjTs2TmXZSOSuQhGlfk50jz kPDbfRLJ0E/JZFC7EqFIAKqbloIF+H5/fubCjyLFPDNttVGiQuPwYBtftX4TVKMGyYTG h3K3Hl6zSCD3+0sR8dgy/y3PQAOdHfcrHdWzuFkTCt9Vc2Tdj69gGqk6xm8cqQYP51a2 67+fY1BqWYh1DhsN7Qx/LrYG37cE0P1pXc6JV4QxR1mapaNwB2wFOL1CpPPIocH2Qe4R 7D/w== X-Forwarded-Encrypted: i=1; AJvYcCXgrO1dGT09a9dE780OPk+vxubmty1ACJPO3Q3neF4sSxlFYkERsoMTerl0sjV2ZVNTRowcFFrcaFbJx8j4Xg7Wq0dyOH2S066I7Uta3nZOmYOTVHqngughxqoU1jO1BHsJ9aNBRGHn X-Gm-Message-State: AOJu0Ywk45MnKDNhrVxz/3qcNOy6JdNg4oG5MC6/KNHxYPdpArZtr3j3 BjjIhBqSslDl4ljrHgtr0BK6etRhI0h/3iv5zGiTP6Xn60uAydE4 X-Received: by 2002:a05:651c:1a07:b0:2df:6524:581a with SMTP id by7-20020a05651c1a0700b002df6524581amr2084004ljb.30.1714575959435; Wed, 01 May 2024 08:05:59 -0700 (PDT) Received: from mfe-desktop.Sonatest.net (ipagstaticip-d73c7528-4de5-0861-800b-03d8b15e3869.sdsl.bell.ca. [174.94.156.236]) by smtp.googlemail.com with ESMTPSA id m17-20020a05600c3b1100b0041b4c293f75sm2493160wms.13.2024.05.01.08.05.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 May 2024 08:05:59 -0700 (PDT) From: marc.ferland@gmail.com X-Google-Original-From: marc.ferland@sonatest.com To: lars@metafoo.de Cc: Michael.Hennerich@analog.com, jic23@kernel.org, linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, Marc Ferland Subject: [PATCH v2] iio: dac: ad5592r: fix temperature channel scaling value Date: Wed, 1 May 2024 11:05:54 -0400 Message-Id: <20240501150554.1871390-1-marc.ferland@sonatest.com> X-Mailer: git-send-email 2.34.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Marc Ferland 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. Signed-off-by: Marc Ferland --- Change in v2: - Improve commit message as suggested by Jonathan. 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 076bc9ecfb49..4763402dbcd6 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); base-commit: 98369dccd2f8e16bf4c6621053af7aa4821dcf8e -- 2.34.1