Linux IIO development
 help / color / mirror / Atom feed
From: Sean Nyekjaer <sean@geanix.com>
To: Jonathan Cameron <jic23@kernel.org>,
	 Marcelo Schmitt <marcelo.schmitt1@gmail.com>,
	 Lars-Peter Clausen <lars@metafoo.de>,
	 Andy Shevchenko <andy.shevchenko@gmail.com>
Cc: Jonathan Cameron <Jonathan.Cameron@huawei.com>,
	 linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org,
	 Sean Nyekjaer <sean@geanix.com>,
	stable@vger.kernel.org
Subject: [PATCH v2 1/2] iio: accel: fxls8962af: Fix temperature calculation
Date: Fri, 02 May 2025 08:15:06 +0200	[thread overview]
Message-ID: <20250502-fxls-v2-1-e1af65f1aa6c@geanix.com> (raw)
In-Reply-To: <20250502-fxls-v2-0-e1af65f1aa6c@geanix.com>

According to spec temperature should be returned in milli degrees Celsius.
Add in_temp_scale to calculate from Celsius to milli Celsius.

Fixes: a3e0b51884ee ("iio: accel: add support for FXLS8962AF/FXLS8964AF accelerometers")
Cc: stable@vger.kernel.org
Signed-off-by: Sean Nyekjaer <sean@geanix.com>
---
 drivers/iio/accel/fxls8962af-core.c | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/accel/fxls8962af-core.c b/drivers/iio/accel/fxls8962af-core.c
index bf1d3923a181798a1c884ee08b62d86ab5aed26f..f515222e008493687921879a0b0ef44fd4ae5d10 100644
--- a/drivers/iio/accel/fxls8962af-core.c
+++ b/drivers/iio/accel/fxls8962af-core.c
@@ -134,6 +134,8 @@
 
 /* Raw temp channel offset */
 #define FXLS8962AF_TEMP_CENTER_VAL		25
+/* Raw temp channel scale */
+#define FXLS8962AF_TEMP_SCALE			1000
 
 #define FXLS8962AF_AUTO_SUSPEND_DELAY_MS	2000
 
@@ -439,8 +441,16 @@ static int fxls8962af_read_raw(struct iio_dev *indio_dev,
 		*val = FXLS8962AF_TEMP_CENTER_VAL;
 		return IIO_VAL_INT;
 	case IIO_CHAN_INFO_SCALE:
-		*val = 0;
-		return fxls8962af_read_full_scale(data, val2);
+		switch (chan->type) {
+		case IIO_TEMP:
+			*val = FXLS8962AF_TEMP_SCALE;
+			return IIO_VAL_INT;
+		case IIO_ACCEL:
+			*val = 0;
+			return fxls8962af_read_full_scale(data, val2);
+		default:
+			return -EINVAL;
+		}
 	case IIO_CHAN_INFO_SAMP_FREQ:
 		return fxls8962af_read_samp_freq(data, val, val2);
 	default:
@@ -736,6 +746,7 @@ static const struct iio_event_spec fxls8962af_event[] = {
 	.type = IIO_TEMP, \
 	.address = FXLS8962AF_TEMP_OUT, \
 	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | \
+			      BIT(IIO_CHAN_INFO_SCALE) | \
 			      BIT(IIO_CHAN_INFO_OFFSET),\
 	.scan_index = -1, \
 	.scan_type = { \

-- 
2.47.1


  reply	other threads:[~2025-05-02  6:15 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-02  6:15 [PATCH v2 0/2] iio: accel: fxls8962af: Fix temperature readings Sean Nyekjaer
2025-05-02  6:15 ` Sean Nyekjaer [this message]
2025-05-02 14:19   ` [PATCH v2 1/2] iio: accel: fxls8962af: Fix temperature calculation Andy Shevchenko
2025-05-04 15:46     ` Jonathan Cameron
2025-05-03 13:41   ` Marcelo Schmitt
2025-05-02  6:15 ` [PATCH v2 2/2] iio: accel: fxls8962af: Fix sign temperature scan element Sean Nyekjaer
2025-05-03 13:57   ` Marcelo Schmitt
2025-05-04 15:49     ` Jonathan Cameron

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=20250502-fxls-v2-1-e1af65f1aa6c@geanix.com \
    --to=sean@geanix.com \
    --cc=Jonathan.Cameron@huawei.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcelo.schmitt1@gmail.com \
    --cc=stable@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