linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Rosin <peda@axentia.se>
To: linux-kernel@vger.kernel.org
Cc: Peter Rosin <peda@axentia.se>,
	Jonathan Cameron <jic23@kernel.org>,
	Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	"David S. Miller" <davem@davemloft.net>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Linus Walleij <linus.walleij@linaro.org>,
	Randy Dunlap <rdunlap@infradead.org>,
	linux-iio@vger.kernel.org, devicetree@vger.kernel.org
Subject: [PATCH 2/3] dt-bindings: iio: wrapper: add io-channel-unit-converter
Date: Mon, 19 Mar 2018 18:02:45 +0100	[thread overview]
Message-ID: <20180319170246.26830-3-peda@axentia.se> (raw)
In-Reply-To: <20180319170246.26830-1-peda@axentia.se>

Allow linear scaling and modification of the type of an io-channel.

When an ADC channel measures the midpoint of a voltage divider, the
interesting voltage is often the voltage over the full resistance
of the divider. Likewise, measuring the voltage over a resistor is
often a way to get to the current through it.

This binding allows description of such hardware which is external
to the ADC.

Signed-off-by: Peter Rosin <peda@axentia.se>
---
 .../iio/wrapper/io-channel-unit-converter.txt      | 84 ++++++++++++++++++++++
 MAINTAINERS                                        |  6 ++
 2 files changed, 90 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/iio/wrapper/io-channel-unit-converter.txt

diff --git a/Documentation/devicetree/bindings/iio/wrapper/io-channel-unit-converter.txt b/Documentation/devicetree/bindings/iio/wrapper/io-channel-unit-converter.txt
new file mode 100644
index 000000000000..23af661abe32
--- /dev/null
+++ b/Documentation/devicetree/bindings/iio/wrapper/io-channel-unit-converter.txt
@@ -0,0 +1,84 @@
+I/O channel unit converter bindings
+
+Allow linear scaling and modification of the type of an io-channel.
+
+When an ADC channel measures the midpoint of a voltage divider, the
+interesting voltage is often the voltage over the full resistance
+of the divider. Likewise, measuring the voltage over a resistor is
+often a way to get to the current through it.
+
+Required properties:
+- compatible : "io-channel-unit-converter"
+- io-channels : Channel node of the parent channel.
+- io-channel-names : Should be "parent".
+
+Optional properties:
+- numerator : The parent channel scale is multiplied by this value (default 1).
+- denominator : The parent channel scale is divided by this value (default 1).
+- type : The type of the wrapped channel is modified to this type. The default
+	 is to use the same type as the parent channel. Recognized types are:
+		"voltage"
+		"current"
+
+Example 1:
+The system voltage is circa 12V, but divided down with a 22/200
+voltage divider to adjust it to the ADC range.
+
+SYSV        ADC       GND
+  +          +         +
+  |  .-----. | .----.  |
+  '--| 200 |-+-| 22 |--'
+     '-----'   '----'
+
+sysv {
+	compatible = "io-channel-unit-converter";
+	io-channles = <&maxadc 1>;
+	io-channel-names = "parent";
+
+	/* multiply the ADC voltage by 222/22 to get the system voltage */
+	numerator = <222>; /* 200 + 22 */
+	denominator = <22>;
+}
+
+&spi {
+	maxadc: adc@0 {
+		compatible = "maxim,max1027";
+	      	reg = <0>;
+		#io-channel-cells = <1>;
+		interrupt-parent = <&gpio5>;
+		interrupts = <15 IRQ_TYPE_EDGE_RISING>;
+		spi-max-frequency = <1000000>;
+	};
+};
+
+Example 2:
+The system current is measured by measuring the voltage over a
+3.3 ohm resistor.
+
+sysi {
+	compatible = "io-channel-unit-converter";
+	io-channles = <&tiadc 0>;
+	io-channel-names = "parent";
+
+	/* divide the ADC voltage by 33/10 (i.e. 3.3) to get current */
+	numerator = <10>;
+	denominator = <33>;
+	type = "current";
+}
+
+&i2c {
+	tiadc: adc@48 {
+		compatible = "ti,ads1015";
+	      	reg = <0x48>;
+		#io-channel-cells = <1>;
+
+		#address-cells = <1>;
+		#size-cells = <0>;
+
+		channel@0 { /* IN0,IN1 differential */
+			reg = <0>;
+			ti,gain = <1>;
+			ti,datarate = <4>;
+		};
+	};
+};
diff --git a/MAINTAINERS b/MAINTAINERS
index 96e5503bfb60..5dd555c7b1b0 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -6884,6 +6884,12 @@ F:	drivers/staging/iio/
 F:	include/linux/iio/
 F:	tools/iio/
 
+IIO UNIT CONVERTER
+M:	Peter Rosin <peda@axentia.se>
+L:	linux-iio@vger.kernel.org
+S:	Maintained
+F:	Documentation/devicetree/bindings/iio/wrapper/io-channel-unit-converter.txt
+
 IKANOS/ADI EAGLE ADSL USB DRIVER
 M:	Matthieu Castet <castet.matthieu@free.fr>
 M:	Stanislaw Gruszka <stf_xl@wp.pl>
-- 
2.11.0

  parent reply	other threads:[~2018-03-19 17:02 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-19 17:02 [PATCH 0/3] iio: add unit converter Peter Rosin
2018-03-19 17:02 ` [PATCH 1/3] iio: rename the multiplexer category to wrapper Peter Rosin
2018-03-19 18:36   ` Randy Dunlap
2018-03-19 17:02 ` Peter Rosin [this message]
2018-03-24 13:53   ` [PATCH 2/3] dt-bindings: iio: wrapper: add io-channel-unit-converter Jonathan Cameron
2018-03-24 14:06     ` Jonathan Cameron
2018-03-26 22:23   ` Rob Herring
2018-03-27  8:01     ` Peter Rosin
2018-03-28  2:29       ` Phil Reid
2018-03-29 13:55       ` Rob Herring
2018-03-30 22:38         ` Peter Rosin
2018-03-19 17:02 ` [PATCH 3/3] iio: wrapper: unit-converter: new driver Peter Rosin
2018-03-24 14:03   ` Jonathan Cameron
2018-03-27  7:42     ` Peter Rosin
2018-03-27 13:22       ` Jonathan Cameron
2018-03-27 13:32         ` Peter Rosin
2018-03-30  9:24           ` Jonathan Cameron
2018-03-23 13:14 ` [PATCH 0/3] iio: add unit converter Jonathan Cameron
2018-03-23 13:59   ` Peter Rosin
2018-03-24 13:48     ` Jonathan Cameron
2018-03-24 16:34       ` Linus Walleij
2018-03-24 17:47         ` Jonathan Cameron

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=20180319170246.26830-3-peda@axentia.se \
    --to=peda@axentia.se \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=mchehab@kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=rdunlap@infradead.org \
    --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).