iio: light: Add gain-time-scale helpers
authorMatti Vaittinen <mazziesaccount@gmail.com>
Fri, 31 Mar 2023 12:40:28 +0000 (15:40 +0300)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Mon, 10 Apr 2023 11:26:34 +0000 (12:26 +0100)
commit38416c28e16890b52fdd5eb73479299ec3f062f3
tree3d7d05f20df754870d6b38fef3cfbeb8de0212e4
parentb27f0b40e49f4b109353c62e8eae74f96f842745
iio: light: Add gain-time-scale helpers

Some light sensors can adjust both the HW-gain and integration time.
There are cases where adjusting the integration time has similar impact
to the scale of the reported values as gain setting has.

IIO users do typically expect to handle scale by a single writable 'scale'
entry. Driver should then adjust the gain/time accordingly.

It however is difficult for a driver to know whether it should change
gain or integration time to meet the requested scale. Usually it is
preferred to have longer integration time which usually improves
accuracy, but there may be use-cases where long measurement times can be
an issue. Thus it can be preferable to allow also changing the
integration time - but mitigate the scale impact by also changing the gain
underneath. Eg, if integration time change doubles the measured values,
the driver can reduce the HW-gain to half.

The theory of the computations of gain-time-scale is simple. However,
some people (undersigned) got that implemented wrong for more than once.

Add some gain-time-scale helpers in order to not dublicate errors in all
drivers needing these computations.

Signed-off-by: Matti Vaittinen <mazziesaccount@gmail.com>
Link: https://lore.kernel.org/r/268d418e7cffcdaa2ece6738478bbc57692c213e.1680263956.git.mazziesaccount@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/Kconfig
drivers/iio/Makefile
drivers/iio/industrialio-gts-helper.c [new file with mode: 0644]
include/linux/iio/iio-gts-helper.h [new file with mode: 0644]