iio: magnetometer: yas530: Correct scaling of magnetic axes
authorJakob Hauser <jahau@rocketmail.com>
Fri, 12 Aug 2022 21:54:08 +0000 (23:54 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 15 Aug 2022 21:30:03 +0000 (22:30 +0100)
Looks like YAS530 raw values return picotesla and YAS532 nanotesla. Adapt
comments and scaling.

Signed-off-by: Jakob Hauser <jahau@rocketmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>
Link: https://lore.kernel.org/r/053ab05cb9a0f6b0536ab5e0de57009f513c6f81.1660337264.git.jahau@rocketmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/magnetometer/yamaha-yas530.c

index 76bff4818461b60d8e24895b86b052880679f30f..199d83013e6f25ea7ae0f8c681fdb3d14ed8fff3 100644 (file)
@@ -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,27 @@ 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. Divide by
+                        * 100000000 (10^8) to get Gauss.
+                        */
+                       *val = 1;
+                       *val2 = 100000000;
+                       break;
+               case YAS532_DEVICE_ID:
+                       /*
+                        * Raw values of YAS532 are in nanotesla. Divide by
+                        * 100000 (10^5) to get Gauss.
+                        */
+                       *val = 1;
+                       *val2 = 100000;
+                       break;
+               default:
+                       dev_err(yas5xx->dev, "unknown device type\n");
+                       return -EINVAL;
+               }
                return IIO_VAL_FRACTIONAL;
        default:
                /* Unknown request */