Re: [PATCH v2 7/8] iio: afe: rescale: add temperature sensor support

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi!

On 2021-06-07 16:47, Liam Beguin wrote:
> From: Liam Beguin <lvb@xxxxxxxxxx>
> 
> Add support for linear temperature sensors. This is meant to work with
> different kinds of analog front ends such as RTDs (resistance
> thermometers), voltage IC sensors (like the LTC2997), and current IC
> sensors (see AD590).
> 
> Signed-off-by: Liam Beguin <lvb@xxxxxxxxxx>
> ---
>  drivers/iio/afe/iio-rescale.c | 25 +++++++++++++++++++++++++
>  1 file changed, 25 insertions(+)
> 
> diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c
> index 3d445c76dbb2..9e3c7e2b47cd 100644
> --- a/drivers/iio/afe/iio-rescale.c
> +++ b/drivers/iio/afe/iio-rescale.c
> @@ -272,10 +272,29 @@ static int rescale_voltage_divider_props(struct device *dev,
>  	return 0;
>  }
>  
> +static int rescale_temp_sense_amplifier_props(struct device *dev,
> +					      struct rescale *rescale)
> +{
> +	s32 gain_mult = 1;
> +	s32 gain_div = 1;
> +	s32 offset = 0;
> +
> +	device_property_read_u32(dev, "sense-gain-mult", &gain_mult);
> +	device_property_read_u32(dev, "sense-gain-div", &gain_div);
> +	device_property_read_u32(dev, "sense-offset-millicelsius", &offset);
> +
> +	rescale->numerator = gain_mult;
> +	rescale->denominator = gain_div;
> +	rescale->offset = offset * gain_div / gain_mult;

This should be done with 64-bit math, no? After all, An offset of
approximately 300000 is not unexpected, and that's quite big to
scale with 32-bit math.

Cheers,
Peter

> +
> +	return 0;
> +}
> +
>  enum rescale_variant {
>  	CURRENT_SENSE_AMPLIFIER,
>  	CURRENT_SENSE_SHUNT,
>  	VOLTAGE_DIVIDER,
> +	TEMP_SENSE_AMPLIFIER,
>  };
>  
>  static const struct rescale_cfg rescale_cfg[] = {
> @@ -291,6 +310,10 @@ static const struct rescale_cfg rescale_cfg[] = {
>  		.type = IIO_VOLTAGE,
>  		.props = rescale_voltage_divider_props,
>  	},
> +	[TEMP_SENSE_AMPLIFIER] = {
> +		.type = IIO_TEMP,
> +		.props = rescale_temp_sense_amplifier_props,
> +	},
>  };
>  
>  static const struct of_device_id rescale_match[] = {
> @@ -300,6 +323,8 @@ static const struct of_device_id rescale_match[] = {
>  	  .data = &rescale_cfg[CURRENT_SENSE_SHUNT], },
>  	{ .compatible = "voltage-divider",
>  	  .data = &rescale_cfg[VOLTAGE_DIVIDER], },
> +	{ .compatible = "temperature-sense-amplifier",
> +	  .data = &rescale_cfg[TEMP_SENSE_AMPLIFIER], },
>  	{ /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(of, rescale_match);
> 



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Input]     [Linux Kernel]     [Linux SCSI]     [X.org]

  Powered by Linux