Received: by 2002:a05:7412:a9a2:b0:e2:908c:2ebd with SMTP id o34csp1192454rdh; Fri, 27 Oct 2023 07:16:47 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFcI+prExWfCFUv1gf5Qif/lUP4W1+2bghL4V8X0CPutURdKQuraW/UcNUVr6GkWFJ3gFk5 X-Received: by 2002:a05:622a:188d:b0:41c:e206:34a8 with SMTP id v13-20020a05622a188d00b0041ce20634a8mr2856076qtc.64.1698416206583; Fri, 27 Oct 2023 07:16:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698416206; cv=none; d=google.com; s=arc-20160816; b=VEtignbMGxjECt0w5akk9IsR2Qu+PP+mLZu/TXavhyhGsEcSxiJa+lP0huCgooFlo0 4FwAZMYdMzf5PpzDq8zkGa5FBeBC06ECs1m/7h1GifEgsO3UG9VJ7c7/Mf2xSQUndQBU WK5aSvVewdo7hA2BqLCrJyyCq88p50IU5pFn/qw/X3ZBsfC3E/clotOKducBrnpks3G8 EA1eMD46qfZiIQVka5LGazKp5boEhvkEn5AkZVHKHs8iS7hMyHZpG5Ff7cUeDbykTdhB KdOmlvXpgHpazo02asxJivTyRZHhy0QXW5UMGjPqBdPVHiQsQJWsnKCADxUJh/md8dKN LlqQ== 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 :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=m/6nEFEQ89tfJC7SpSb8arByNWQgjxywvXU9oo32b38=; fh=tgmQcpzivz7ermYuHUQvGO6fdr2zOrCP3RxTTFTMQck=; b=jmiEDdOSy5ojDhMdGP6MfwQ8U4Q8lRk4FlVzLkPEjybU3of2f3aLJLhCnaSXYUUdoq HzS7yPdegvLJxwo3/Utnm6Ryc2wrxbjELdts97X3xGa6SWBQoc8MaSarO6UnO1yKsfL5 6s90RplDgu/o4g1z34mk2AO8X2JoxnuhCbz/TOTpkLc2O0XqKjpKvJUEAwvfm2yKQZTk WIRaHxoMOktmIonYwhNMlGDDd1lgDRHcmgIn22FKrqdlcyfbzbKPILj9hLK+dUic959+ fBJBBoe56QuEFdGu7FmVVOjHP5KT94kHvmplMpG4VtotK+6s+u47o6PPhJPLYeDB2u1h XvEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AQBhfqtn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id v8-20020a05622a014800b004108aee38e8si801673qtw.122.2023.10.27.07.16.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Oct 2023 07:16:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=AQBhfqtn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by groat.vger.email (Postfix) with ESMTP id 65F778098486; Fri, 27 Oct 2023 07:15:52 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346080AbjJ0OPd (ORCPT + 99 others); Fri, 27 Oct 2023 10:15:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345998AbjJ0OPc (ORCPT ); Fri, 27 Oct 2023 10:15:32 -0400 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1657B8; Fri, 27 Oct 2023 07:15:29 -0700 (PDT) Received: by smtp.kernel.org (Postfix) with ESMTPSA id E3B57C433CA; Fri, 27 Oct 2023 14:15:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1698416129; bh=FeoSFjBClAtXEms1dJG9FSmvqhaVOV5FqfpXbkM0l+E=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=AQBhfqtnIqkANUon/plWcETuTbIxuFHYTXOC5YnH0l4iAG3UAWgwc+jGQJafTzoHD owYdNx1V9LVHi3u6T42PHTalE3Z7yN+6R2FnWRuZovcHePHByCkmqu5QRZo+NNxOdA oPTWYWapwlTXh4lqBpOqmUbt/CukWRfDq8815V63CGJmcFZ9oPU0XIhGSWF4Vu7CKr W6ozmZ3IRISu+lRG7NAB+H/hm1YQ3tQEt4RAHcY6ZLDwHnZFdpaFRYMQWcd+v8ynYi 5EEh0ujBTx/bE6A3BsbX3hBPN0d79bew+/UweWV66whdtWVsNv9HRJb9dtSYlmdW6y NfiCEPiSeZKpg== Date: Fri, 27 Oct 2023 15:15:07 +0100 From: Jonathan Cameron To: Javier Carrasco Cc: Gerald Loacker , Lars-Peter Clausen , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] iio: tmag5273: fix temperature offset Message-ID: <20231027151507.2eac395c@jic23-huawei> In-Reply-To: <20231023-topic-tmag5273x1_temp_offset-v1-1-983dca43292c@wolfvision.net> References: <20231023-topic-tmag5273x1_temp_offset-v1-1-983dca43292c@wolfvision.net> X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.2 required=5.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Fri, 27 Oct 2023 07:15:52 -0700 (PDT) On Mon, 23 Oct 2023 11:50:02 +0200 Javier Carrasco wrote: > The current offset has the scale already applied to it. The ABI > documentation defines the offset parameter as "offset to be added > to [Y]_raw prior to scaling by [Y]_scale in order to > obtain value in the units as specified in [Y]_raw > documentation" > > The right value is obtained at 0 degrees Celsius by the formula provided > in the datasheet: > > T = Tsens_t0 + (Tadc_t - Tadc_t0) / Tadc_res So base units for temperature are milli degrees celsius. T = 1000 * (25 + (adc - 17508) / 60.1) T = 1000/60.1 * (25 * 60.1 + adc - 17508) T = 10000/601 * (-16005.5 + adc) So I think the maths is a little off.. > > where: > T = 0 degrees Celsius > Tsens_t0 (reference temperature) = 25 degrees Celsius > Tadc_t0 (16-bit format for Tsens_t0) = 17508 > Tadc_res = 60.1 LSB/degree Celsius > > The resulting offset is 16605.5, which has been truncated to 16005 to Interesting - the truncated value you have looks good to be but that's not matching with the resulting offset or the value below... > provide an integer value with a precision loss smaller than the 1-LSB > measurement precision. > > Fix the offset to apply its value prior to scaling. > > Signed-off-by: Javier Carrasco > --- > drivers/iio/magnetometer/tmag5273.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/iio/magnetometer/tmag5273.c b/drivers/iio/magnetometer/tmag5273.c > index c5e5c4ad681e..d22ca39007b6 100644 > --- a/drivers/iio/magnetometer/tmag5273.c > +++ b/drivers/iio/magnetometer/tmag5273.c > @@ -356,7 +356,7 @@ static int tmag5273_read_raw(struct iio_dev *indio_dev, > case IIO_CHAN_INFO_OFFSET: > switch (chan->type) { > case IIO_TEMP: > - *val = -266314; > + *val = -16605; > return IIO_VAL_INT; > default: > return -EINVAL; > > --- > base-commit: 05d3ef8bba77c1b5f98d941d8b2d4aeab8118ef1 > change-id: 20231023-topic-tmag5273x1_temp_offset-17774cbce961 > > Best regards,