Re: [PATCH] iio: mxs-lradc: Fix temperature offset

From: Alexandre Belloni
Date: Tue Oct 06 2015 - 20:45:11 EST


Hi,

On 07/10/2015 at 01:19:09 +0200, Marek Vasut wrote :
> >>/* The calculated value from the ADC is in Kelvin, we
> >>* want Celsius for hwmon so the offset is
> >>- * -272.15 * scale
> >>+ * -273.15 * scale
> >>*/
> >>- *val = -1075;
> >>- *val2 = 691699;
> >>+ *val = -1079;
> >>+ *val2 = 644268;
> >>
> >
> >i think it would be nice to break down the calculation of these magic values in
> >a second patch.
>
> Indeed, I agree. I hope Alexandre can send another patch for that soon :-)
>

On my side, I'm not sure this is worth more than a comment. If
necessary, I can write that the datasheet specifies that the scale is
4/1.012 here also.

Else you end up with something like that (naive implementation):

#define SCALE (4 * 1000 / 1012)

val = -273150000 * SCALE / 1000000;
val2 = 273150000 * SCALE + 1000000 * val;

I don't feel this is any clearer because we can't use floating points in
the kernel anyway.

--
Alexandre Belloni, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/