linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Antoni Pokusinski <apokusinski01@gmail.com>
To: jic23@kernel.org, lars@metafoo.de, andriy.shevchenko@linux.intel.com
Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
	Antoni Pokusinski <apokusinski01@gmail.com>
Subject: [PATCH] iio: magnetometer: si7210: fix magnetic field measurement scale
Date: Sun,  2 Feb 2025 11:07:10 +0100	[thread overview]
Message-ID: <20250202100709.143411-1-apokusinski01@gmail.com> (raw)

Applying the current scale value to the raw magnetic field measurements
gives the result in mT.

Fix the scale by increasing it 10 times, so that the final result after
applying the scale is in Gauss.

Fixes: cb29542a178f ("iio: magnetometer: si7210: add driver for Si7210")
Signed-off-by: Antoni Pokusinski <apokusinski01@gmail.com>
---
 drivers/iio/magnetometer/si7210.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/magnetometer/si7210.c b/drivers/iio/magnetometer/si7210.c
index 43b00d76505a..27e3feba7a0f 100644
--- a/drivers/iio/magnetometer/si7210.c
+++ b/drivers/iio/magnetometer/si7210.c
@@ -203,9 +203,9 @@ static int si7210_read_raw(struct iio_dev *indio_dev,
 	case IIO_CHAN_INFO_SCALE:
 		*val = 0;
 		if (data->curr_scale == 20)
-			*val2 = 1250;
-		else /* data->curr_scale == 200 */
 			*val2 = 12500;
+		else /* data->curr_scale == 200 */
+			*val2 = 125000;
 		return IIO_VAL_INT_PLUS_MICRO;
 	case IIO_CHAN_INFO_OFFSET:
 		*val = -16384;
@@ -274,9 +274,9 @@ static int si7210_write_raw(struct iio_dev *indio_dev,
 
 	switch (mask) {
 	case IIO_CHAN_INFO_SCALE:
-		if (val == 0 && val2 == 1250)
+		if (val == 0 && val2 == 12500)
 			scale = 20;
-		else if (val == 0 && val2 == 12500)
+		else if (val == 0 && val2 == 125000)
 			scale = 200;
 		else
 			return -EINVAL;

base-commit: aa61400ca17e264a4b597e3c0cda011c6b9b3bb5
-- 
2.25.1


             reply	other threads:[~2025-02-02 10:09 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-02-02 10:07 Antoni Pokusinski [this message]
2025-02-03  9:26 ` [PATCH] iio: magnetometer: si7210: fix magnetic field measurement scale Andy Shevchenko
2025-02-03 15:27   ` Jonathan Cameron
2025-02-03 19:39   ` Antoni Pokusinski
2025-02-04 19:24     ` Jonathan Cameron
2025-02-08 13:06       ` 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=20250202100709.143411-1-apokusinski01@gmail.com \
    --to=apokusinski01@gmail.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=jic23@kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).