public inbox for linux-iio@vger.kernel.org
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Javier Carrasco <javier.carrasco@wolfvision.net>
Cc: Gerald Loacker <gerald.loacker@wolfvision.net>,
	Lars-Peter Clausen <lars@metafoo.de>,
	linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2] iio: tmag5273: fix temperature offset
Date: Sat, 25 Nov 2023 15:14:49 +0000	[thread overview]
Message-ID: <20231125151449.42f2f2ed@jic23-huawei> (raw)
In-Reply-To: <9879beec-05fc-4fc6-af62-d771e238954e@wolfvision.net>

On Tue, 21 Nov 2023 06:48:39 +0100
Javier Carrasco <javier.carrasco@wolfvision.net> wrote:

> The current offset has the scale already applied to it. The ABI
> documentation defines the offset parameter as "offset to be added
> to <type>[Y]_raw prior to scaling by <type>[Y]_scale in order to
> obtain value in the <type> units as specified in <type>[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
> 
> 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 16005.5, which has been truncated to 16005 to
> 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 <javier.carrasco@wolfvision.net>
Applied to the fixes-togreg branch of iio.git and marked for stable. Thanks,

Jonathan

> ---
> Changes in v2:
> - Fixed typo in the offset value (16005 instead of 16605) (Jonathan Cameron)
> 
> - Link to v1:
> https://lore.kernel.org/r/20231023-topic-tmag5273x1_temp_offset-v1-1-983dca43292c@wolfvision.net
> ---
>  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..e8c4ca142d21 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 = -16005;
>  			return IIO_VAL_INT;
>  		default:
>  			return -EINVAL;
> 
> ---
> base-commit: 05d3ef8bba77c1b5f98d941d8b2d4aeab8118ef1
> change-id: 20231023-topic-tmag5273x1_temp_offset-17774cbce961
> 
> Best regards,


      reply	other threads:[~2023-11-25 15:14 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-11-21  5:48 [PATCH v2] iio: tmag5273: fix temperature offset Javier Carrasco
2023-11-25 15:14 ` Jonathan Cameron [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231125151449.42f2f2ed@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=gerald.loacker@wolfvision.net \
    --cc=javier.carrasco@wolfvision.net \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox