diff mbox series

[v14,09/11] iio: afe: rescale: add temperature transducers

Message ID 20220208020441.3081162-10-liambeguin@gmail.com (mailing list archive)
State Superseded
Headers show
Series iio: afe: add temperature rescaling support | expand

Commit Message

Liam Beguin Feb. 8, 2022, 2:04 a.m. UTC
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>
---
 drivers/iio/afe/iio-rescale.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

Comments

Andy Shevchenko Feb. 8, 2022, 1:46 p.m. UTC | #1
On Tue, Feb 8, 2022 at 4:04 AM Liam Beguin <liambeguin@gmail.com> wrote:
>
> 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.

...

> +       rescale->offset = div_s64((s64)offset * rescale->denominator,
> +                                 rescale->numerator);

Wonder if we can use mult_frac() here. Would it require 64-bit division?
Liam Beguin Feb. 9, 2022, 4:38 p.m. UTC | #2
Hi Andy,

On Tue, Feb 08, 2022 at 03:46:27PM +0200, Andy Shevchenko wrote:
> On Tue, Feb 8, 2022 at 4:04 AM Liam Beguin <liambeguin@gmail.com> wrote:
> >
> > 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.
> 
> ...
> 
> > +       rescale->offset = div_s64((s64)offset * rescale->denominator,
> > +                                 rescale->numerator);
> 
> Wonder if we can use mult_frac() here. Would it require 64-bit division?

Same here, I'd rather keep it as is, especially if you plan on adding
helpers later on for struct u32_fract.

Cheers,
Liam

> -- 
> With Best Regards,
> Andy Shevchenko
diff mbox series

Patch

diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c
index beadf9fc0ee0..45297530b878 100644
--- a/drivers/iio/afe/iio-rescale.c
+++ b/drivers/iio/afe/iio-rescale.c
@@ -441,11 +441,37 @@  static int rescale_temp_sense_rtd_props(struct device *dev,
 	return 0;
 }
 
+static int rescale_temp_transducer_props(struct device *dev,
+					 struct rescale *rescale)
+{
+	s32 offset = 0;
+	s32 sense = 1;
+	s32 alpha;
+	int ret;
+
+	device_property_read_u32(dev, "sense-offset-millicelsius", &offset);
+	device_property_read_u32(dev, "sense-resistor-ohms", &sense);
+	ret = device_property_read_u32(dev, "alpha-ppm-per-celsius", &alpha);
+	if (ret) {
+		dev_err(dev, "failed to read alpha-ppm-per-celsius: %d\n", ret);
+		return ret;
+	}
+
+	rescale->numerator = MEGA;
+	rescale->denominator = alpha * sense;
+
+	rescale->offset = div_s64((s64)offset * rescale->denominator,
+				  rescale->numerator);
+
+	return 0;
+}
+
 enum rescale_variant {
 	CURRENT_SENSE_AMPLIFIER,
 	CURRENT_SENSE_SHUNT,
 	VOLTAGE_DIVIDER,
 	TEMP_SENSE_RTD,
+	TEMP_TRANSDUCER,
 };
 
 static const struct rescale_cfg rescale_cfg[] = {
@@ -465,6 +491,10 @@  static const struct rescale_cfg rescale_cfg[] = {
 		.type = IIO_TEMP,
 		.props = rescale_temp_sense_rtd_props,
 	},
+	[TEMP_TRANSDUCER] = {
+		.type = IIO_TEMP,
+		.props = rescale_temp_transducer_props,
+	},
 };
 
 static const struct of_device_id rescale_match[] = {
@@ -476,6 +506,8 @@  static const struct of_device_id rescale_match[] = {
 	  .data = &rescale_cfg[VOLTAGE_DIVIDER], },
 	{ .compatible = "temperature-sense-rtd",
 	  .data = &rescale_cfg[TEMP_SENSE_RTD], },
+	{ .compatible = "temperature-transducer",
+	  .data = &rescale_cfg[TEMP_TRANSDUCER], },
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(of, rescale_match);