]> git.ipfire.org Git - thirdparty/kernel/stable.git/commit
iio: Add inverse unit conversion macros
authorLars-Peter Clausen <lars@metafoo.de>
Wed, 5 Aug 2015 13:38:14 +0000 (15:38 +0200)
committerJonathan Cameron <jic23@kernel.org>
Sat, 8 Aug 2015 11:50:40 +0000 (12:50 +0100)
commitc689a923c867eac40ed3826c1d9328edea8b6bc7
tree6b7d6b740e3a1a9bf8d5f9d017956433775ddf33
parent8166537283b31d7abaae9e56bd48fbbc30cdc579
iio: Add inverse unit conversion macros

Add inverse unit conversion macro to convert from standard IIO units to
units that might be used by some devices.

Those are useful in combination with scale factors that are specified as
IIO_VAL_FRACTIONAL. Typically the denominator for those specifications will
contain the maximum raw value the sensor will generate and the numerator
the value it maps to in a specific unit. Sometimes datasheets specify those
in different units than the standard IIO units (e.g. degree/s instead of
rad/s) and so we need to do a unit conversion.

From a mathematical point of view it does not make a difference whether we
apply the unit conversion to the numerator or the inverse unit conversion
to the denominator since (x / y) / z = x / (y * z). But as the denominator
is typically a larger value and we are rounding both the numerator and
denominator to integer values using the later method gives us a better
precision (E.g. the relative error is smaller if we round 8000.3 to 8000
rather than rounding 8.3 to 8).

This is where in inverse unit conversion macros will be used.

Marked for stable as used by some upcoming fixes.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
include/linux/iio/iio.h