On Tue, Feb 25, 2020 at 10:53:01AM +0200, Matti Vaittinen wrote: > 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. > > Signed-off-by: Matti Vaittinen <matti.vaittinen@xxxxxxxxxxxxxxxxx> > --- > > Changes since rfc-v3: > - Kerneldoc fixes > - Corrected commit message typo meaningfull => meaningful > > drivers/base/Kconfig | 3 + > drivers/base/Makefile | 1 + > drivers/base/linear_ranges.c | 246 +++++++++++++++++++++++++++++++++++ Why in drivers/base/ ? Why not in lib/ ? > include/linux/linear_range.h | 48 +++++++ > 4 files changed, 298 insertions(+) > create mode 100644 drivers/base/linear_ranges.c > create mode 100644 include/linux/linear_range.h > > diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig > index 5f0bc74d2409..636b6fa8e499 100644 > --- a/drivers/base/Kconfig > +++ b/drivers/base/Kconfig > @@ -209,4 +209,7 @@ config GENERIC_ARCH_TOPOLOGY > appropriate scaling, sysfs interface for reading capacity values at > runtime. > > +config LINEAR_RANGES > + tristate No help text at all??? > +EXPORT_SYMBOL(linear_range_values_in_range); EXPORT_SYMBOL_GPL() for all of these? I have to ask... > @@ -0,0 +1,48 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later */ Are you sure about the "or later"? Again, I have to ask. > +/* Copyright (C) 2020 ROHM Semiconductors */ > + > +#ifndef LINEAR_RANGE_H > +#define LINEAR_RANGE_H > + > +#include <linux/types.h> Why is this needed? thanks, greg k-h