All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakob Hauser <jahau@rocketmail.com>
To: Jonathan Cameron <jic23@kernel.org>
Cc: Lars-Peter Clausen <lars@metafoo.de>,
	Linus Walleij <linus.walleij@linaro.org>,
	Andy Shevchenko <andy.shevchenko@gmail.com>,
	Hans de Goede <hdegoede@redhat.com>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org,
	phone-devel@vger.kernel.org,
	~postmarketos/upstreaming@lists.sr.ht,
	Jakob Hauser <jahau@rocketmail.com>
Subject: [PATCH v2 3/7] iio: magnetometer: yas530: Correct scaling of magnetic axes
Date: Mon, 13 Jun 2022 03:17:10 +0200	[thread overview]
Message-ID: <66eace1d414ad977d8af70c0e1c6b9c74c5bf9bf.1655081082.git.jahau@rocketmail.com> (raw)
In-Reply-To: <cover.1655081082.git.jahau@rocketmail.com>

Looks like YAS530 raw values return picotesla and YAS532 nanotesla. Adapt
comments and scaling.

Cc: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Jakob Hauser <jahau@rocketmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
---
 drivers/iio/magnetometer/yamaha-yas530.c | 28 +++++++++++++++---------
 1 file changed, 18 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/magnetometer/yamaha-yas530.c b/drivers/iio/magnetometer/yamaha-yas530.c
index 2d71ae837bf5..40c81c082782 100644
--- a/drivers/iio/magnetometer/yamaha-yas530.c
+++ b/drivers/iio/magnetometer/yamaha-yas530.c
@@ -310,8 +310,6 @@ static s32 yas5xx_linearize(struct yas5xx *yas5xx, u16 val, int axis)
  * @yo: Y axis out
  * @zo: Z axis out
  * @return: 0 on success or error code
- *
- * Returned values are in nanotesla according to some code.
  */
 static int yas5xx_get_measure(struct yas5xx *yas5xx, s32 *to, s32 *xo, s32 *yo, s32 *zo)
 {
@@ -417,14 +415,24 @@ static int yas5xx_read_raw(struct iio_dev *indio_dev,
 			*val = 1;
 			return IIO_VAL_INT;
 		}
-		/*
-		 * The axis values are in nanotesla according to the vendor
-		 * drivers, but is clearly in microtesla according to
-		 * experiments. Since 1 uT = 0.01 Gauss, we need to divide
-		 * by 100000000 (10^8) to get to Gauss from the raw value.
-		 */
-		*val = 1;
-		*val2 = 100000000;
+		switch (yas5xx->devid) {
+		case YAS530_DEVICE_ID:
+			/*
+			 * Raw values of YAS530 are in picotesla. Devide by
+			 * 100000000 (10^8) to get Gauss.
+			 */
+			*val = 1;
+			*val2 = 100000000;
+			break;
+		case YAS532_DEVICE_ID:
+			/*
+			 * Raw values of YAS532 are in nanotesla. Devide by
+			 * 100000 (10^5) to get Gauss.
+			 */
+			*val = 1;
+			*val2 = 100000;
+			break;
+		}
 		return IIO_VAL_FRACTIONAL;
 	default:
 		/* Unknown request */
-- 
2.35.1


  parent reply	other threads:[~2022-06-13  1:17 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1655081082.git.jahau.ref@rocketmail.com>
2022-06-13  1:15 ` [PATCH v2 0/7] Add support for magnetometer Yamaha YAS537 Jakob Hauser
2022-06-13  1:17   ` [PATCH v2 1/7] iio: magnetometer: yas530: Change data type of hard_offsets to signed Jakob Hauser
2022-06-13  1:17   ` [PATCH v2 2/7] iio: magnetometer: yas530: Change range of data in volatile register Jakob Hauser
2022-06-13  1:17   ` Jakob Hauser [this message]
2022-06-13  1:17   ` [PATCH v2 4/7] iio: magnetometer: yas530: Correct temperature handling Jakob Hauser
2022-06-13 15:01     ` Andy Shevchenko
2022-06-15 21:18       ` Jakob Hauser
2022-06-13  1:17   ` [PATCH v2 5/7] iio: magnetometer: yas530: Change data type of calibration coefficients Jakob Hauser
2022-06-13  1:17   ` [PATCH v2 6/7] iio: magnetometer: yas530: Rename functions and registers Jakob Hauser
2022-06-13  1:17   ` [PATCH v2 7/7] iio: magnetometer: yas530: Add YAS537 variant Jakob Hauser
2022-06-13 15:20     ` Andy Shevchenko
2022-06-13 15:22       ` Andy Shevchenko
2022-06-15 21:51         ` Jakob Hauser
2022-06-15 21:43       ` Jakob Hauser
2022-06-15 22:00         ` Jakob Hauser
2022-06-18 14:15         ` Jonathan Cameron
2022-06-13 15:23   ` [PATCH v2 0/7] Add support for magnetometer Yamaha YAS537 Andy Shevchenko

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=66eace1d414ad977d8af70c0e1c6b9c74c5bf9bf.1655081082.git.jahau@rocketmail.com \
    --to=jahau@rocketmail.com \
    --cc=andy.shevchenko@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=hdegoede@redhat.com \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=phone-devel@vger.kernel.org \
    --cc=~postmarketos/upstreaming@lists.sr.ht \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.