Re: [PATCH v14 03/11] iio: afe: rescale: add offset support

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

 



Hi!

On 2022-02-08 03:04, Liam Beguin wrote:
> This is a preparatory change required for the addition of temperature
> sensing front ends.
> 
> Signed-off-by: Liam Beguin <liambeguin@xxxxxxxxx>
> Reviewed-by: Peter Rosin <peda@xxxxxxxxxx>
> ---
>  drivers/iio/afe/iio-rescale.c   | 81 +++++++++++++++++++++++++++++++++
>  include/linux/iio/afe/rescale.h |  4 ++
>  2 files changed, 85 insertions(+)
> 
> diff --git a/drivers/iio/afe/iio-rescale.c b/drivers/iio/afe/iio-rescale.c
> index f833eb38f8bb..63035b4bce5e 100644
> --- a/drivers/iio/afe/iio-rescale.c
> +++ b/drivers/iio/afe/iio-rescale.c
> @@ -3,6 +3,7 @@
>   * IIO rescale driver
>   *
>   * Copyright (C) 2018 Axentia Technologies AB
> + * Copyright (C) 2022 Liam Beguin <liambeguin@xxxxxxxxx>
>   *
>   * Author: Peter Rosin <peda@xxxxxxxxxx>
>   */
> @@ -82,11 +83,46 @@ int rescale_process_scale(struct rescale *rescale, int scale_type,
>  	}
>  }
>  
> +int rescale_process_offset(struct rescale *rescale, int scale_type,
> +			   int scale, int scale2, int schan_off,
> +			   int *val, int *val2)
> +{
> +	s64 tmp, tmp2;
> +
> +	switch (scale_type) {
> +	case IIO_VAL_FRACTIONAL:
> +		tmp = (s64)rescale->offset * scale2;
> +		*val = div_s64(tmp, scale) + schan_off;
> +		return IIO_VAL_INT;
> +	case IIO_VAL_INT:
> +		*val = div_s64(rescale->offset, scale) + schan_off;
> +		return IIO_VAL_INT;
> +	case IIO_VAL_FRACTIONAL_LOG2:
> +		tmp = (s64)rescale->offset * (1 << scale2);
> +		*val = div_s64(tmp, scale) + schan_off;
> +		return IIO_VAL_INT;
> +	case IIO_VAL_INT_PLUS_NANO:
> +		tmp = (s64)rescale->offset * GIGA;
> +		tmp2 = ((s64)scale * GIGA) + scale2;

Same thing here as in patch 2/11, use NANO or the raw number. GIGA
has no connection to the usage.

> +		*val = div64_s64(tmp, tmp2) + schan_off;
> +		return IIO_VAL_INT;
> +	case IIO_VAL_INT_PLUS_MICRO:
> +		tmp = (s64)rescale->offset * MEGA;
> +		tmp2 = ((s64)scale * MEGA) + scale2;

And MICRO here of course.

Cheers,
Peter

*snip*



[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