linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Liam Beguin <liambeguin@gmail.com>
To: liambeguin@gmail.com, peda@axentia.se, jic23@kernel.org, lars@metafoo.de
Cc: linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org,
	devicetree@vger.kernel.org, robh+dt@kernel.org
Subject: [PATCH v10 00/14] iio: afe: add temperature rescaling support
Date: Sun, 19 Dec 2021 17:39:39 -0500	[thread overview]
Message-ID: <20211219223953.16074-1-liambeguin@gmail.com> (raw)

Hi Jonathan, Peter,

I left out IIO_VAL_INT overflows for now, so that I can focus on getting
the rest of these changes pulled in, but I don't mind adding a patch for
that later on.

This series focuses on adding temperature rescaling support to the IIO
Analog Front End (AFE) driver.

The first few patches address minor bugs in IIO inkernel functions, and
prepare the AFE driver for the additional features.

The main changes to the AFE driver include an initial Kunit test suite,
support for IIO_VAL_INT_PLUS_{NANO,MICRO} scales, and support for RTDs
and temperature transducer sensors.

Thanks for your time,
Liam

Changes since v9:
- make use of linux/units.h
- reorder commits, fix fract_log2 before merging fract
- keep fractional representation when not overflowing

Changes since v8:
- reword comment
- fix erroneous 64-bit division
- optimize and use 32-bit divisions when values are know to not overflow
- keep IIO_VAL_FRACTIONAL scale when possible, if not default to fixed
  point
- add test cases
- use nano precision in test cases
- simplify offset calculation in rtd_props()

Changes since v7:
- drop gcd() logic in rescale_process_scale()
- use div_s64() instead of do_div() for signed 64-bit divisions
- combine IIO_VAL_FRACTIONAL and IIO_VAL_FRACTIONAL_LOG2 scale cases
- switch to INT_PLUS_NANO when accuracy is lost with FRACTIONAL scales
- rework test logic to allow for small relative error
- rename test variables to align error output messages

Changes since v6:
- rework IIO_VAL_INT_PLUS_{NANO,MICRO} based on Peter's suggestion
- combine IIO_VAL_INT_PLUS_{NANO,MICRO} cases
- add test cases for negative IIO_VAL_INT_PLUS_{NANO,MICRO} corner cases
- force use of positive integers with gcd()
- reduce risk of integer overflow in IIO_VAL_FRACTIONAL_LOG2
- fix duplicate symbol build error
- apply Reviewed-by

Changes since v5:
- add include/linux/iio/afe/rescale.h
- expose functions use to process scale and offset
- add basic iio-rescale kunit test cases
- fix integer overflow case
- improve precision for IIO_VAL_FRACTIONAL_LOG2

Changes since v4:
- only use gcd() when necessary in overflow mitigation
- fix INT_PLUS_{MICRO,NANO} support
- apply Reviewed-by
- fix temperature-transducer bindings

Changes since v3:
- drop unnecessary fallthrough statements
- drop redundant local variables in some calculations
- fix s64 divisions on 32bit platforms by using do_div
- add comment describing iio-rescaler offset calculation
- drop unnecessary MAINTAINERS entry

Changes since v2:
- don't break implicit offset truncations
- make a best effort to get a valid value for fractional types
- drop return value change in iio_convert_raw_to_processed_unlocked()
- don't rely on processed value for offset calculation
- add INT_PLUS_{MICRO,NANO} support in iio-rescale
- revert generic implementation in favor of temperature-sense-rtd and
  temperature-transducer
- add separate section to MAINTAINERS file

Changes since v1:
- rebase on latest iio `testing` branch
- also apply consumer scale on integer channel scale types
- don't break implicit truncation in processed channel offset
  calculation
- drop temperature AFE flavors in favor of a simpler generic
  implementation

Liam Beguin (14):
  iio: inkern: apply consumer scale on IIO_VAL_INT cases
  iio: inkern: apply consumer scale when no channel scale is available
  iio: inkern: make a best effort on offset calculation
  iio: afe: rescale: expose scale processing function
  iio: afe: rescale: add INT_PLUS_{MICRO,NANO} support
  iio: afe: rescale: add offset support
  iio: afe: rescale: use s64 for temporary scale calculations
  iio: afe: rescale: fix accuracy for small fractional scales
  iio: afe: rescale: reduce risk of integer overflow
  iio: test: add basic tests for the iio-rescale driver
  iio: afe: rescale: add RTD temperature sensor support
  iio: afe: rescale: add temperature transducers
  dt-bindings: iio: afe: add bindings for temperature-sense-rtd
  dt-bindings: iio: afe: add bindings for temperature transducers

 .../iio/afe/temperature-sense-rtd.yaml        | 101 +++
 .../iio/afe/temperature-transducer.yaml       | 114 +++
 drivers/iio/afe/iio-rescale.c                 | 283 ++++++-
 drivers/iio/inkern.c                          |  40 +-
 drivers/iio/test/Kconfig                      |  10 +
 drivers/iio/test/Makefile                     |   1 +
 drivers/iio/test/iio-test-rescale.c           | 705 ++++++++++++++++++
 include/linux/iio/afe/rescale.h               |  34 +
 8 files changed, 1244 insertions(+), 44 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/iio/afe/temperature-sense-rtd.yaml
 create mode 100644 Documentation/devicetree/bindings/iio/afe/temperature-transducer.yaml
 create mode 100644 drivers/iio/test/iio-test-rescale.c
 create mode 100644 include/linux/iio/afe/rescale.h

Range-diff against v9:
 -:  ------------ >  1:  ae3cc93baee6 iio: inkern: apply consumer scale on IIO_VAL_INT cases
 -:  ------------ >  2:  06f66e7f7403 iio: inkern: apply consumer scale when no channel scale is available
 -:  ------------ >  3:  2dbf6b3bbaeb iio: inkern: make a best effort on offset calculation
 -:  ------------ >  4:  b083cf307268 iio: afe: rescale: expose scale processing function
 1:  a0bde29ecc8c !  5:  f46b59690e46 iio: afe: rescale: add INT_PLUS_{MICRO,NANO} support
    @@ Commit message
         Signed-off-by: Liam Beguin <lvb@xiphos.com>
     
      ## drivers/iio/afe/iio-rescale.c ##
    -@@ drivers/iio/afe/iio-rescale.c: int rescale_process_scale(struct rescale *rescale, int scale_type,
    +@@
    + #include <linux/of_device.h>
    + #include <linux/platform_device.h>
    + #include <linux/property.h>
    ++#include <linux/units.h>
    + 
    + int rescale_process_scale(struct rescale *rescale, int scale_type,
      			  int *val, int *val2)
      {
      	unsigned long long tmp;
    @@ drivers/iio/afe/iio-rescale.c: int rescale_process_scale(struct rescale *rescale
     +		return scale_type;
     +	case IIO_VAL_INT_PLUS_NANO:
     +	case IIO_VAL_INT_PLUS_MICRO:
    -+		if (scale_type == IIO_VAL_INT_PLUS_NANO)
    -+			mult = 1000000000LL;
    -+		else
    -+			mult = 1000000LL;
    ++		mult = scale_type == IIO_VAL_INT_PLUS_NANO ? NANO : MICRO;
    ++
     +		/*
     +		 * For IIO_VAL_INT_PLUS_{MICRO,NANO} scale types if either *val
     +		 * OR *val2 is negative the schan scale is negative, i.e.
 2:  c3d0e6248033 =  6:  80701b87cdf4 iio: afe: rescale: add offset support
 3:  2a81fa735103 =  7:  a3d8fb812678 iio: afe: rescale: use s64 for temporary scale calculations
 4:  8315548d0fce <  -:  ------------ iio: afe: rescale: reduce risk of integer overflow
 5:  223ed0569cd2 !  8:  b83947d96676 iio: afe: rescale: fix accuracy for small fractional scales
    @@ drivers/iio/afe/iio-rescale.c: int rescale_process_scale(struct rescale *rescale
     +		if (!rem)
     +			return scale_type;
     +
    -+		if (scale_type == IIO_VAL_FRACTIONAL)
    -+			tmp = *val2;
    -+		else
    -+			tmp = 1 << *val2;
    ++		tmp = 1 << *val2;
     +
     +		rem2 = *val % (int)tmp;
     +		*val = *val / (int)tmp;
    @@ drivers/iio/afe/iio-rescale.c: int rescale_process_scale(struct rescale *rescale
     +		return IIO_VAL_INT_PLUS_NANO;
      	case IIO_VAL_INT_PLUS_NANO:
      	case IIO_VAL_INT_PLUS_MICRO:
    - 		if (scale_type == IIO_VAL_INT_PLUS_NANO)
    + 		mult = scale_type == IIO_VAL_INT_PLUS_NANO ? NANO : MICRO;
 -:  ------------ >  9:  c42c8121bcdf iio: afe: rescale: reduce risk of integer overflow
 6:  90044efdf8be = 10:  6c87d491a275 iio: test: add basic tests for the iio-rescale driver
 7:  c4ed463e5fb0 = 11:  3f3d1939b17c iio: afe: rescale: add RTD temperature sensor support
 8:  ff2f0dc248a7 = 12:  0c83d15f3b92 iio: afe: rescale: add temperature transducers
 9:  84bc1f7d1ab5 = 13:  55af6c9391f8 dt-bindings: iio: afe: add bindings for temperature-sense-rtd
10:  1b76cfb37e23 = 14:  8f9cd46c702e dt-bindings: iio: afe: add bindings for temperature transducers

base-commit: 2b6bff0b122785f09cfbdc34b1aa9edceea6e4c1
-- 
2.34.0


             reply	other threads:[~2021-12-19 22:40 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-19 22:39 Liam Beguin [this message]
2021-12-19 22:39 ` [PATCH v10 01/14] iio: inkern: apply consumer scale on IIO_VAL_INT cases Liam Beguin
2021-12-19 22:39 ` [PATCH v10 02/14] iio: inkern: apply consumer scale when no channel scale is available Liam Beguin
2021-12-19 22:39 ` [PATCH v10 03/14] iio: inkern: make a best effort on offset calculation Liam Beguin
2021-12-21  5:42   ` Andy Shevchenko
2021-12-21 17:50     ` Liam Beguin
2021-12-19 22:39 ` [PATCH v10 04/14] iio: afe: rescale: expose scale processing function Liam Beguin
     [not found]   ` <CAHp75VdfPf6FMvkGqhhQg5e5XE1cgE-K8seobe5n0yGarnPGtQ@mail.gmail.com>
2021-12-21  5:43     ` Andy Shevchenko
2021-12-22  2:28       ` Liam Beguin
2021-12-19 22:39 ` [PATCH v10 05/14] iio: afe: rescale: add INT_PLUS_{MICRO,NANO} support Liam Beguin
2021-12-19 22:39 ` [PATCH v10 06/14] iio: afe: rescale: add offset support Liam Beguin
2021-12-19 22:39 ` [PATCH v10 07/14] iio: afe: rescale: use s64 for temporary scale calculations Liam Beguin
2021-12-19 22:39 ` [PATCH v10 08/14] iio: afe: rescale: fix accuracy for small fractional scales Liam Beguin
2021-12-19 22:39 ` [PATCH v10 09/14] iio: afe: rescale: reduce risk of integer overflow Liam Beguin
2021-12-19 22:39 ` [PATCH v10 10/14] iio: test: add basic tests for the iio-rescale driver Liam Beguin
2021-12-21  7:09   ` kernel test robot
2021-12-21  8:03   ` kernel test robot
2021-12-19 22:39 ` [PATCH v10 11/14] iio: afe: rescale: add RTD temperature sensor support Liam Beguin
2021-12-19 22:39 ` [PATCH v10 12/14] iio: afe: rescale: add temperature transducers Liam Beguin
2021-12-19 22:39 ` [PATCH v10 13/14] dt-bindings: iio: afe: add bindings for temperature-sense-rtd Liam Beguin
2021-12-19 22:39 ` [PATCH v10 14/14] dt-bindings: iio: afe: add bindings for temperature transducers Liam Beguin
2021-12-20 21:37 ` [PATCH v10 00/14] iio: afe: add temperature rescaling support Peter Rosin
2021-12-22  3:29   ` Liam Beguin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20211219223953.16074-1-liambeguin@gmail.com \
    --to=liambeguin@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peda@axentia.se \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).