]> git.ipfire.org Git - thirdparty/linux.git/commit - lib/Kconfig
lib: add linear ranges helpers
authorMatti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Fri, 8 May 2020 15:39:35 +0000 (18:39 +0300)
committerMark Brown <broonie@kernel.org>
Fri, 8 May 2020 17:18:11 +0000 (18:18 +0100)
commitd2218d4e4a65f25bd2d38489567012c7db50233c
treeea4e5ca04f11962d1609c98cea9a1b71d5e0f918
parent0e698dfa282211e414076f9dc7e83c1c288314fd
lib: add linear ranges helpers

Many devices have control registers which control some measurable
property. Often a register contains control field so that change in
this field causes linear change in the controlled property. It is not
a rare case that user wants to give 'meaningful' control values and
driver needs to convert them to register field values. Even more
often user wants to 'see' the currently set value - again in
meaningful units - and driver needs to convert the values it reads
from register to these meaningful units. Examples of this include:

- regulators, voltage/current configurations
- power, voltage/current configurations
- clk(?) NCOs

and maybe others I can't think of right now.

Provide a linear_range helper which can do conversion from user value
to register value 'selector'.

The idea here is stolen from regulator framework and patches refactoring
the regulator helpers to use this are following.

Current implementation does not support inversely proportional ranges
but it might be useful if we could support also inversely proportional
ranges?

Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com>
Reviewed-by: Mark Brown <broonie@kernel.org>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/59259bc475e0c800eb4bb163f02528c7c01f7b3a.1588944082.git.matti.vaittinen@fi.rohmeurope.com
Signed-off-by: Mark Brown <broonie@kernel.org>
include/linux/linear_range.h [new file with mode: 0644]
lib/Kconfig
lib/Makefile
lib/linear_ranges.c [new file with mode: 0644]