On Thu, Apr 16, 2020 at 04:09:17PM +0200, Linus Walleij wrote: > The manual for the HSCDTD008A gives us a scaling for the > three axis as +/- 2.4mT per axis. > > When I implement this the biggest axis indicates 0.59 Gauss > which is a reasonable measurement for the earths magnetic > which is in the range of 0.25 to 0.65 Gauss on the surface > according to Wikipedia. > > Cc: Nick Reitemeyer <nick.reitemeyer@xxxxxx> > Cc: Stephan Gerhold <stephan@xxxxxxxxxxx> > Cc: Michał Mirosław <mirq-linux@xxxxxxxxxxxx> > Signed-off-by: Linus Walleij <linus.walleij@xxxxxxxxxx> > --- > ChangeLog v1->v2: > - Split out the measurement refactoring. > --- > drivers/iio/magnetometer/ak8974.c | 15 ++++++++++++++- > 1 file changed, 14 insertions(+), 1 deletion(-) > > diff --git a/drivers/iio/magnetometer/ak8974.c b/drivers/iio/magnetometer/ak8974.c > index 5361647b9054..effcdd93e650 100644 > --- a/drivers/iio/magnetometer/ak8974.c > +++ b/drivers/iio/magnetometer/ak8974.c > @@ -603,6 +603,18 @@ static int ak8974_read_raw(struct iio_dev *indio_dev, > *val = outval; > ret = IIO_VAL_INT; > break; > + case IIO_CHAN_INFO_SCALE: > + /* > + * The datasheet for HSCDTF008A, page 3 specifies the > + * range of the sensor as +/- 2.4 mT per axis, which corresponds > + * to +/- 2400 uT = +/- 24 Gauss. So 0x7fff is 24 Gauss and > + * 0xffff is -24 Gauss. To account for the one missing value if > + * we multiply by 1/S16_MAX, instead multiply with 2/U16_MAX. > + */ > + *val = 24 * 2; > + *val2 = U16_MAX; > + ret = IIO_VAL_FRACTIONAL; > + break; Hi, The comment seems wrong. DS mentions that the measurement values are S16, but limited in range (-k to +k, with k = 2^13 or 2^14). So the denominator should be 2^13 or 2^14, and numerator 2.4mT. Best Regards, Michał Mirosław