Andy Shevchenko
d272cfc3f0
iio: afe: rescale: Make use of device properties
...
Convert the module to be property provider agnostic and allow
it to be used on non-OF platforms.
Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com >
Link: https://lore.kernel.org/r/20220413190117.29814-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2022-04-28 19:22:54 +01:00
Liam Beguin
03e7d21ee1
iio: afe: rescale: add temperature transducers
...
A temperature transducer is a device that converts a thermal quantity
into any other physical quantity. This patch adds support for
temperature to voltage (like the LTC2997) and temperature to current
(like the AD590) linear transducers.
In both cases these are assumed to be connected to a voltage ADC.
Signed-off-by: Liam Beguin <liambeguin@gmail.com >
Reviewed-by: Peter Rosin <peda@axentia.se >
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com >
Link: https://lore.kernel.org/r/20220213025739.2561834-9-liambeguin@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2022-02-28 10:22:24 +00:00
Liam Beguin
278fe1d2d3
iio: afe: rescale: add RTD temperature sensor support
...
An RTD (Resistance Temperature Detector) is a kind of temperature
sensor used to get a linear voltage to temperature reading within a
give range (usually 0 to 100 degrees Celsius). Common types of RTDs
include PT100, PT500, and PT1000.
Signed-off-by: Liam Beguin <liambeguin@gmail.com >
Reviewed-by: Peter Rosin <peda@axentia.se >
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com >
Link: https://lore.kernel.org/r/20220213025739.2561834-8-liambeguin@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2022-02-28 10:22:24 +00:00
Liam Beguin
2eb30577f2
iio: afe: rescale: reduce risk of integer overflow
...
Reduce the risk of integer overflow by doing the scale calculation on
a 64-bit integer. Since the rescaling is only performed on *val, reuse
the IIO_VAL_FRACTIONAL_LOG2 case.
Signed-off-by: Liam Beguin <liambeguin@gmail.com >
Reviewed-by: Peter Rosin <peda@axentia.se >
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com >
Link: https://lore.kernel.org/r/20220213025739.2561834-6-liambeguin@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2022-02-27 13:38:22 +00:00
Liam Beguin
f5fc003d48
iio: afe: rescale: fix accuracy for small fractional scales
...
The approximation caused by integer divisions can be costly on smaller
scale values since the decimal part is significant compared to the
integer part. Switch to an IIO_VAL_INT_PLUS_NANO scale type in such
cases to maintain accuracy.
Signed-off-by: Liam Beguin <liambeguin@gmail.com >
Reviewed-by: Peter Rosin <peda@axentia.se >
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com >
Link: https://lore.kernel.org/r/20220213025739.2561834-5-liambeguin@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2022-02-27 13:38:16 +00:00
Liam Beguin
a29c328365
iio: afe: rescale: add offset support
...
This is a preparatory change required for the addition of temperature
sensing front ends.
Signed-off-by: Liam Beguin <liambeguin@gmail.com >
Reviewed-by: Peter Rosin <peda@axentia.se >
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com >
Link: https://lore.kernel.org/r/20220213025739.2561834-4-liambeguin@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2022-02-27 13:38:10 +00:00
Liam Beguin
701ee14da9
iio: afe: rescale: add INT_PLUS_{MICRO,NANO} support
...
Some ADCs use IIO_VAL_INT_PLUS_{NANO,MICRO} scale types.
Add support for these to allow using the iio-rescaler with them.
Signed-off-by: Liam Beguin <liambeguin@gmail.com >
Reviewed-by: Peter Rosin <peda@axentia.se >
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com >
Link: https://lore.kernel.org/r/20220213025739.2561834-3-liambeguin@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2022-02-27 13:38:05 +00:00
Liam Beguin
bc437f7515
iio: afe: rescale: expose scale processing function
...
In preparation for the addition of kunit tests, expose the logic
responsible for combining channel scales.
Signed-off-by: Liam Beguin <liambeguin@gmail.com >
Reviewed-by: Peter Rosin <peda@axentia.se >
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com >
Link: https://lore.kernel.org/r/20220213025739.2561834-2-liambeguin@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2022-02-27 13:37:49 +00:00
Liam Beguin
cd717ac6f6
iio: afe: rescale: reorder includes
...
Includes should be ordered alphabetically which is already the case,
but follow what is done in other drivers by separation IIO specific
headers with a blank line.
Signed-off-by: Liam Beguin <liambeguin@gmail.com >
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com >
Link: https://lore.kernel.org/r/20220108205319.2046348-6-liambeguin@gmail.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2022-01-30 14:38:03 +00:00
Liam Beguin
51593106b6
iio: afe: rescale: use s64 for temporary scale calculations
...
All four scaling coefficients can take signed values.
Make tmp a signed 64-bit integer and switch to div_s64() to preserve
signs during 64-bit divisions.
Fixes: 8b74816b5a ("iio: afe: rescale: new driver")
Signed-off-by: Liam Beguin <liambeguin@gmail.com >
Reviewed-by: Peter Rosin <peda@axentia.se >
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com >
Link: https://lore.kernel.org/r/20220108205319.2046348-5-liambeguin@gmail.com
Cc: <Stable@vger.kernel.org >
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2022-01-30 14:38:03 +00:00
Linus Walleij
53ebee9499
iio: afe: iio-rescale: Support processed channels
...
It happens that an ADC will only provide raw or processed
voltage conversion channels. (adc/ab8500-gpadc.c).
On the Samsung GT-I9070 this is used for a light sensor
and current sense amplifier so we need to think of something.
The idea is to allow processed channels and scale them
with 1/1 and then the rescaler can modify the result
on top.
Link: https://lore.kernel.org/linux-iio/20201101232211.1194304-1-linus.walleij@linaro.org/
Cc: Peter Rosin <peda@axentia.se >
Signed-off-by: Linus Walleij <linus.walleij@linaro.org >
Reviewed-by: Peter Rosin <peda@axentia.se >
Link: https://lore.kernel.org/r/20210518092741.403080-1-linus.walleij@linaro.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2021-06-03 18:24:13 +01:00
Krzysztof Kozlowski
bfa96be8a4
iio: afe: iio-rescale: Simplify with dev_err_probe()
...
Common pattern of handling deferred probe can be simplified with
dev_err_probe(). Less code and also it prints the error value.
Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org >
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com >
Acked-by: Peter Rosin <peda@axentia.se >
Link: https://lore.kernel.org/r/20200829064726.26268-9-krzk@kernel.org
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2020-09-03 19:40:50 +01:00
Alexandru Ardelean
d3be83244c
iio: remove explicit IIO device parent assignment
...
This patch applies the semantic patch:
@@
expression I, P, SP;
@@
I = devm_iio_device_alloc(P, SP);
...
- I->dev.parent = P;
It updates 302 files and does 307 deletions.
This semantic patch also removes some comments like
'/* Establish that the iio_dev is a child of the i2c device */'
But this is is only done in case where the block is left empty.
The patch does not seem to cover all cases. It looks like in some cases a
different variable is used in some cases to assign the parent, but it
points to the same reference.
In other cases, the block covered by ... may be just too big to be covered
by the semantic patch.
However, this looks pretty good as well, as it does cover a big bulk of the
drivers that should remove the parent assignment.
Signed-off-by: Alexandru Ardelean <alexandru.ardelean@analog.com >
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2020-06-14 11:49:59 +01:00
Peter Rosin
8b74816b5a
iio: afe: rescale: new driver
...
If an ADC channel measures the midpoint of a voltage divider, the
interesting voltage is often the voltage over the full resistance.
E.g. if the full voltage is too big for the ADC to handle.
Likewise, if an ADC channel measures the voltage across a shunt
resistor, with or without amplification, the interesting value is
often the current through the resistor.
This driver solves these problems by allowing to linearly scale a channel
and/or by allowing changes to the type of the channel.
Signed-off-by: Peter Rosin <peda@axentia.se >
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com >
2018-04-28 18:03:22 +01:00