xref: /linux/Documentation/iio/iio_adc.rst (revision 4f9786035f9e519db41375818e1d0b5f20da2f10)
1*9b4b9791SMarcelo Schmitt.. SPDX-License-Identifier: GPL-2.0-only
2*9b4b9791SMarcelo Schmitt
3*9b4b9791SMarcelo Schmitt=========================
4*9b4b9791SMarcelo SchmittIIO Abstractions for ADCs
5*9b4b9791SMarcelo Schmitt=========================
6*9b4b9791SMarcelo Schmitt
7*9b4b9791SMarcelo Schmitt1. Overview
8*9b4b9791SMarcelo Schmitt===========
9*9b4b9791SMarcelo Schmitt
10*9b4b9791SMarcelo SchmittThe IIO subsystem supports many Analog to Digital Converters (ADCs). Some ADCs
11*9b4b9791SMarcelo Schmitthave features and characteristics that are supported in specific ways by IIO
12*9b4b9791SMarcelo Schmittdevice drivers. This documentation describes common ADC features and explains
13*9b4b9791SMarcelo Schmitthow they are supported by the IIO subsystem.
14*9b4b9791SMarcelo Schmitt
15*9b4b9791SMarcelo Schmitt1. ADC Channel Types
16*9b4b9791SMarcelo Schmitt====================
17*9b4b9791SMarcelo Schmitt
18*9b4b9791SMarcelo SchmittADCs can have distinct types of inputs, each of them measuring analog voltages
19*9b4b9791SMarcelo Schmittin a slightly different way. An ADC digitizes the analog input voltage over a
20*9b4b9791SMarcelo Schmittspan that is often given by the provided voltage reference, the input type, and
21*9b4b9791SMarcelo Schmittthe input polarity. The input range allowed to an ADC channel is needed to
22*9b4b9791SMarcelo Schmittdetermine the scale factor and offset needed to obtain the measured value in
23*9b4b9791SMarcelo Schmittreal-world units (millivolts for voltage measurement, milliamps for current
24*9b4b9791SMarcelo Schmittmeasurement, etc.).
25*9b4b9791SMarcelo Schmitt
26*9b4b9791SMarcelo SchmittElaborate designs may have nonlinear characteristics or integrated components
27*9b4b9791SMarcelo Schmitt(such as amplifiers and reference buffers) that might also have to be considered
28*9b4b9791SMarcelo Schmittto derive the allowed input range for an ADC. For clarity, the sections below
29*9b4b9791SMarcelo Schmittassume the input range only depends on the provided voltage references, input
30*9b4b9791SMarcelo Schmitttype, and input polarity.
31*9b4b9791SMarcelo Schmitt
32*9b4b9791SMarcelo SchmittThere are three general types of ADC inputs (single-ended, differential,
33*9b4b9791SMarcelo Schmittpseudo-differential) and two possible polarities (unipolar, bipolar). The input
34*9b4b9791SMarcelo Schmitttype (single-ended, differential, pseudo-differential) is one channel
35*9b4b9791SMarcelo Schmittcharacteristic, and is completely independent of the polarity (unipolar,
36*9b4b9791SMarcelo Schmittbipolar) aspect. A comprehensive article about ADC input types (on which this
37*9b4b9791SMarcelo Schmittdoc is heavily based on) can be found at
38*9b4b9791SMarcelo Schmitthttps://www.analog.com/en/resources/technical-articles/sar-adc-input-types.html.
39*9b4b9791SMarcelo Schmitt
40*9b4b9791SMarcelo Schmitt1.1 Single-ended channels
41*9b4b9791SMarcelo Schmitt-------------------------
42*9b4b9791SMarcelo Schmitt
43*9b4b9791SMarcelo SchmittSingle-ended channels digitize the analog input voltage relative to ground and
44*9b4b9791SMarcelo Schmittcan be either unipolar or bipolar.
45*9b4b9791SMarcelo Schmitt
46*9b4b9791SMarcelo Schmitt1.1.1 Single-ended Unipolar Channels
47*9b4b9791SMarcelo Schmitt^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
48*9b4b9791SMarcelo Schmitt
49*9b4b9791SMarcelo Schmitt::
50*9b4b9791SMarcelo Schmitt
51*9b4b9791SMarcelo Schmitt  ---------- VREF -------------
52*9b4b9791SMarcelo Schmitt      ´ `           ´ `                  _____________
53*9b4b9791SMarcelo Schmitt    /     \       /     \               /             |
54*9b4b9791SMarcelo Schmitt   /       \     /       \         --- <  IN    ADC   |
55*9b4b9791SMarcelo Schmitt            \   /         \   /         \             |
56*9b4b9791SMarcelo Schmitt             `-´           `-´           \       VREF |
57*9b4b9791SMarcelo Schmitt  -------- GND (0V) -----------           +-----------+
58*9b4b9791SMarcelo Schmitt                                                  ^
59*9b4b9791SMarcelo Schmitt                                                  |
60*9b4b9791SMarcelo Schmitt                                             External VREF
61*9b4b9791SMarcelo Schmitt
62*9b4b9791SMarcelo SchmittThe input voltage to a **single-ended unipolar** channel is allowed to swing
63*9b4b9791SMarcelo Schmittfrom GND to VREF (where VREF is a voltage reference with electrical potential
64*9b4b9791SMarcelo Schmitthigher than system ground). The maximum input voltage is also called VFS
65*9b4b9791SMarcelo Schmitt(Voltage input Full-Scale), with VFS being determined by VREF. The voltage
66*9b4b9791SMarcelo Schmittreference may be provided from an external supply or derived from the chip power
67*9b4b9791SMarcelo Schmittsource.
68*9b4b9791SMarcelo Schmitt
69*9b4b9791SMarcelo SchmittA single-ended unipolar channel could be described in device tree like the
70*9b4b9791SMarcelo Schmittfollowing example::
71*9b4b9791SMarcelo Schmitt
72*9b4b9791SMarcelo Schmitt    adc@0 {
73*9b4b9791SMarcelo Schmitt        ...
74*9b4b9791SMarcelo Schmitt        #address-cells = <1>;
75*9b4b9791SMarcelo Schmitt        #size-cells = <0>;
76*9b4b9791SMarcelo Schmitt
77*9b4b9791SMarcelo Schmitt        channel@0 {
78*9b4b9791SMarcelo Schmitt            reg = <0>;
79*9b4b9791SMarcelo Schmitt        };
80*9b4b9791SMarcelo Schmitt    };
81*9b4b9791SMarcelo Schmitt
82*9b4b9791SMarcelo SchmittOne is always allowed to include ADC channel nodes in the device tree. Though,
83*9b4b9791SMarcelo Schmittif the device has a uniform set of inputs (e.g. all inputs are single-ended),
84*9b4b9791SMarcelo Schmittthen declaring the channel nodes is optional.
85*9b4b9791SMarcelo Schmitt
86*9b4b9791SMarcelo SchmittOne caveat for devices that support mixed single-ended and differential channels
87*9b4b9791SMarcelo Schmittis that single-ended channel nodes also need to provide a ``single-channel``
88*9b4b9791SMarcelo Schmittproperty when ``reg`` is an arbitrary number that doesn't match the input pin
89*9b4b9791SMarcelo Schmittnumber.
90*9b4b9791SMarcelo Schmitt
91*9b4b9791SMarcelo SchmittSee ``Documentation/devicetree/bindings/iio/adc/adc.yaml`` for the complete
92*9b4b9791SMarcelo Schmittdocumentation of ADC specific device tree properties.
93*9b4b9791SMarcelo Schmitt
94*9b4b9791SMarcelo Schmitt
95*9b4b9791SMarcelo Schmitt1.1.2 Single-ended Bipolar Channels
96*9b4b9791SMarcelo Schmitt^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
97*9b4b9791SMarcelo Schmitt
98*9b4b9791SMarcelo Schmitt::
99*9b4b9791SMarcelo Schmitt
100*9b4b9791SMarcelo Schmitt  ---------- +VREF ------------
101*9b4b9791SMarcelo Schmitt      ´ `           ´ `                  _____________________
102*9b4b9791SMarcelo Schmitt    /     \       /     \               /                     |
103*9b4b9791SMarcelo Schmitt   /       \     /       \         --- <  IN          ADC     |
104*9b4b9791SMarcelo Schmitt            \   /         \   /         \                     |
105*9b4b9791SMarcelo Schmitt             `-´           `-´           \       +VREF  -VREF |
106*9b4b9791SMarcelo Schmitt  ---------- -VREF ------------           +-------------------+
107*9b4b9791SMarcelo Schmitt                                                  ^       ^
108*9b4b9791SMarcelo Schmitt                                                  |       |
109*9b4b9791SMarcelo Schmitt                             External +VREF ------+  External -VREF
110*9b4b9791SMarcelo Schmitt
111*9b4b9791SMarcelo SchmittFor a **single-ended bipolar** channel, the analog voltage input can go from
112*9b4b9791SMarcelo Schmitt-VREF to +VREF (where -VREF is the voltage reference that has the lower
113*9b4b9791SMarcelo Schmittelectrical potential while +VREF is the reference with the higher one). Some ADC
114*9b4b9791SMarcelo Schmittchips derive the lower reference from +VREF, others get it from a separate
115*9b4b9791SMarcelo Schmittinput. Often, +VREF and -VREF are symmetric but they don't need to be so. When
116*9b4b9791SMarcelo Schmitt-VREF is lower than system ground, these inputs are also called single-ended
117*9b4b9791SMarcelo Schmitttrue bipolar. Also, while there is a relevant difference between bipolar and
118*9b4b9791SMarcelo Schmitttrue bipolar from the electrical perspective, IIO makes no explicit distinction
119*9b4b9791SMarcelo Schmittbetween them.
120*9b4b9791SMarcelo Schmitt
121*9b4b9791SMarcelo SchmittHere's an example device tree description of a single-ended bipolar channel::
122*9b4b9791SMarcelo Schmitt
123*9b4b9791SMarcelo Schmitt    adc@0 {
124*9b4b9791SMarcelo Schmitt        ...
125*9b4b9791SMarcelo Schmitt        #address-cells = <1>;
126*9b4b9791SMarcelo Schmitt        #size-cells = <0>;
127*9b4b9791SMarcelo Schmitt
128*9b4b9791SMarcelo Schmitt        channel@0 {
129*9b4b9791SMarcelo Schmitt            reg = <0>;
130*9b4b9791SMarcelo Schmitt            bipolar;
131*9b4b9791SMarcelo Schmitt        };
132*9b4b9791SMarcelo Schmitt    };
133*9b4b9791SMarcelo Schmitt
134*9b4b9791SMarcelo Schmitt1.2 Differential channels
135*9b4b9791SMarcelo Schmitt-------------------------
136*9b4b9791SMarcelo Schmitt
137*9b4b9791SMarcelo SchmittA differential voltage measurement digitizes the voltage level at the positive
138*9b4b9791SMarcelo Schmittinput (IN+) relative to the negative input (IN-) over the -VREF to +VREF span.
139*9b4b9791SMarcelo SchmittIn other words, a differential channel measures the potential difference between
140*9b4b9791SMarcelo SchmittIN+ and IN-, which is often denoted by the IN+ - IN- formula.
141*9b4b9791SMarcelo Schmitt
142*9b4b9791SMarcelo Schmitt1.2.1 Differential Bipolar Channels
143*9b4b9791SMarcelo Schmitt^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
144*9b4b9791SMarcelo Schmitt
145*9b4b9791SMarcelo Schmitt::
146*9b4b9791SMarcelo Schmitt
147*9b4b9791SMarcelo Schmitt  -------- +VREF ------         +-------------------+
148*9b4b9791SMarcelo Schmitt    ´ `       ´ `              /                    |
149*9b4b9791SMarcelo Schmitt  /     \   /     \   /   --- <  IN+                |
150*9b4b9791SMarcelo Schmitt         `-´       `-´         |                    |
151*9b4b9791SMarcelo Schmitt  -------- -VREF ------        |                    |
152*9b4b9791SMarcelo Schmitt                               |            ADC     |
153*9b4b9791SMarcelo Schmitt  -------- +VREF ------        |                    |
154*9b4b9791SMarcelo Schmitt        ´ `       ´ `          |                    |
155*9b4b9791SMarcelo Schmitt  \   /     \   /     \   --- <  IN-                |
156*9b4b9791SMarcelo Schmitt   `-´       `-´               \       +VREF  -VREF |
157*9b4b9791SMarcelo Schmitt  -------- -VREF ------         +-------------------+
158*9b4b9791SMarcelo Schmitt                                         ^       ^
159*9b4b9791SMarcelo Schmitt                                         |       +---- External -VREF
160*9b4b9791SMarcelo Schmitt                                  External +VREF
161*9b4b9791SMarcelo Schmitt
162*9b4b9791SMarcelo SchmittThe analog signals to **differential bipolar** inputs are also allowed to swing
163*9b4b9791SMarcelo Schmittfrom -VREF to +VREF. The bipolar part of the name means that the resulting value
164*9b4b9791SMarcelo Schmittof the difference (IN+ - IN-) can be positive or negative. If -VREF is below
165*9b4b9791SMarcelo Schmittsystem GND, these are also called differential true bipolar inputs.
166*9b4b9791SMarcelo Schmitt
167*9b4b9791SMarcelo SchmittDevice tree example of a differential bipolar channel::
168*9b4b9791SMarcelo Schmitt
169*9b4b9791SMarcelo Schmitt    adc@0 {
170*9b4b9791SMarcelo Schmitt        ...
171*9b4b9791SMarcelo Schmitt        #address-cells = <1>;
172*9b4b9791SMarcelo Schmitt        #size-cells = <0>;
173*9b4b9791SMarcelo Schmitt
174*9b4b9791SMarcelo Schmitt        channel@0 {
175*9b4b9791SMarcelo Schmitt            reg = <0>;
176*9b4b9791SMarcelo Schmitt            bipolar;
177*9b4b9791SMarcelo Schmitt            diff-channels = <0 1>;
178*9b4b9791SMarcelo Schmitt        };
179*9b4b9791SMarcelo Schmitt    };
180*9b4b9791SMarcelo Schmitt
181*9b4b9791SMarcelo SchmittIn the ADC driver, ``differential = 1`` is set into ``struct iio_chan_spec`` for
182*9b4b9791SMarcelo Schmittthe channel. Even though, there are three general input types, ``differential``
183*9b4b9791SMarcelo Schmittis only used to distinguish between differential and non-differential (either
184*9b4b9791SMarcelo Schmittsingle-ended or pseudo-differential) input types. See
185*9b4b9791SMarcelo Schmitt``include/linux/iio/iio.h`` for more information.
186*9b4b9791SMarcelo Schmitt
187*9b4b9791SMarcelo Schmitt1.2.2 Differential Unipolar Channels
188*9b4b9791SMarcelo Schmitt^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
189*9b4b9791SMarcelo Schmitt
190*9b4b9791SMarcelo SchmittFor **differential unipolar** channels, the analog voltage at the positive input
191*9b4b9791SMarcelo Schmittmust also be higher than the voltage at the negative input. Thus, the actual
192*9b4b9791SMarcelo Schmittinput range allowed to a differential unipolar channel is IN- to +VREF. Because
193*9b4b9791SMarcelo SchmittIN+ is allowed to swing with the measured analog signal and the input setup must
194*9b4b9791SMarcelo Schmittguarantee IN+ will not go below IN- (nor IN- will raise above IN+), most
195*9b4b9791SMarcelo Schmittdifferential unipolar channel setups have IN- fixed to a known voltage that does
196*9b4b9791SMarcelo Schmittnot fall within the voltage range expected for the measured signal. That leads
197*9b4b9791SMarcelo Schmittto a setup that is equivalent to a pseudo-differential channel. Thus,
198*9b4b9791SMarcelo Schmittdifferential unipolar setups can often be supported as pseudo-differential
199*9b4b9791SMarcelo Schmittunipolar channels.
200*9b4b9791SMarcelo Schmitt
201*9b4b9791SMarcelo Schmitt1.3 Pseudo-differential Channels
202*9b4b9791SMarcelo Schmitt--------------------------------
203*9b4b9791SMarcelo Schmitt
204*9b4b9791SMarcelo SchmittThere is a third ADC input type which is called pseudo-differential or
205*9b4b9791SMarcelo Schmittsingle-ended to differential configuration. A pseudo-differential channel is
206*9b4b9791SMarcelo Schmittsimilar to a differential channel in that it also measures IN+ relative to IN-.
207*9b4b9791SMarcelo SchmittHowever, unlike bipolar differential channels, the negative input is limited to
208*9b4b9791SMarcelo Schmitta narrow voltage range (taken as a constant voltage) while only IN+ is allowed
209*9b4b9791SMarcelo Schmittto swing. A pseudo-differential channel can be made out from a differential pair
210*9b4b9791SMarcelo Schmittof inputs by restricting the negative input to a known voltage while allowing
211*9b4b9791SMarcelo Schmittonly the positive input to swing. Sometimes, the input provided to IN- is called
212*9b4b9791SMarcelo Schmittcommon-mode voltage. Besides, some parts have a COM pin that allows single-ended
213*9b4b9791SMarcelo Schmittinputs to be referenced to a common-mode voltage, making them
214*9b4b9791SMarcelo Schmittpseudo-differential channels. Often, the common mode input voltage can be
215*9b4b9791SMarcelo Schmittdescribed in the device tree as a voltage regulator (e.g. ``com-supply``) since
216*9b4b9791SMarcelo Schmittit is basically a constant voltage source.
217*9b4b9791SMarcelo Schmitt
218*9b4b9791SMarcelo Schmitt1.3.1 Pseudo-differential Unipolar Channels
219*9b4b9791SMarcelo Schmitt^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
220*9b4b9791SMarcelo Schmitt
221*9b4b9791SMarcelo Schmitt::
222*9b4b9791SMarcelo Schmitt
223*9b4b9791SMarcelo Schmitt  -------- +VREF ------          +-------------------+
224*9b4b9791SMarcelo Schmitt    ´ `       ´ `               /                    |
225*9b4b9791SMarcelo Schmitt  /     \   /     \   /    --- <  IN+                |
226*9b4b9791SMarcelo Schmitt         `-´       `-´          |                    |
227*9b4b9791SMarcelo Schmitt  --------- IN- -------         |            ADC     |
228*9b4b9791SMarcelo Schmitt                                |                    |
229*9b4b9791SMarcelo Schmitt  Common-mode voltage -->  --- <  IN-                |
230*9b4b9791SMarcelo Schmitt                                \       +VREF  -VREF |
231*9b4b9791SMarcelo Schmitt                                 +-------------------+
232*9b4b9791SMarcelo Schmitt                                         ^       ^
233*9b4b9791SMarcelo Schmitt                                         |       +---- External -VREF
234*9b4b9791SMarcelo Schmitt                                  External +VREF
235*9b4b9791SMarcelo Schmitt
236*9b4b9791SMarcelo SchmittA **pseudo-differential unipolar** input has the limitations a differential
237*9b4b9791SMarcelo Schmittunipolar channel would have, meaning the analog voltage to the positive input
238*9b4b9791SMarcelo SchmittIN+ must stay within IN- to +VREF. The fixed voltage to IN- is often called
239*9b4b9791SMarcelo Schmittcommon-mode voltage and it must be within -VREF to +VREF as would be expected
240*9b4b9791SMarcelo Schmittfrom the signal to any differential channel negative input.
241*9b4b9791SMarcelo Schmitt
242*9b4b9791SMarcelo SchmittThe voltage measured from IN+ is relative to IN- but, unlike differential
243*9b4b9791SMarcelo Schmittchannels, pseudo-differential setups are intended to gauge single-ended input
244*9b4b9791SMarcelo Schmittsignals. To enable applications to calculate IN+ voltage with respect to system
245*9b4b9791SMarcelo Schmittground, the IIO channel may provide an ``_offset`` sysfs attribute to be added
246*9b4b9791SMarcelo Schmittto ADC output when converting raw data to voltage units. In many setups, the
247*9b4b9791SMarcelo Schmittcommon-mode voltage input is at GND level and the ``_offset`` attribute is
248*9b4b9791SMarcelo Schmittomitted due to being always zero.
249*9b4b9791SMarcelo Schmitt
250*9b4b9791SMarcelo SchmittDevice tree example for pseudo-differential unipolar channel::
251*9b4b9791SMarcelo Schmitt
252*9b4b9791SMarcelo Schmitt    adc@0 {
253*9b4b9791SMarcelo Schmitt        ...
254*9b4b9791SMarcelo Schmitt        #address-cells = <1>;
255*9b4b9791SMarcelo Schmitt        #size-cells = <0>;
256*9b4b9791SMarcelo Schmitt
257*9b4b9791SMarcelo Schmitt        channel@0 {
258*9b4b9791SMarcelo Schmitt            reg = <0>;
259*9b4b9791SMarcelo Schmitt            single-channel = <0>;
260*9b4b9791SMarcelo Schmitt            common-mode-channel = <1>;
261*9b4b9791SMarcelo Schmitt        };
262*9b4b9791SMarcelo Schmitt    };
263*9b4b9791SMarcelo Schmitt
264*9b4b9791SMarcelo SchmittDo not set ``differential`` in the channel ``iio_chan_spec`` struct of
265*9b4b9791SMarcelo Schmittpseudo-differential channels.
266*9b4b9791SMarcelo Schmitt
267*9b4b9791SMarcelo Schmitt1.3.2 Pseudo-differential Bipolar Channels
268*9b4b9791SMarcelo Schmitt^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
269*9b4b9791SMarcelo Schmitt
270*9b4b9791SMarcelo Schmitt::
271*9b4b9791SMarcelo Schmitt
272*9b4b9791SMarcelo Schmitt  -------- +VREF ------          +-------------------+
273*9b4b9791SMarcelo Schmitt    ´ `       ´ `               /                    |
274*9b4b9791SMarcelo Schmitt  /     \   /     \   /    --- <  IN+                |
275*9b4b9791SMarcelo Schmitt         `-´       `-´          |                    |
276*9b4b9791SMarcelo Schmitt  -------- -VREF ------         |            ADC     |
277*9b4b9791SMarcelo Schmitt                                |                    |
278*9b4b9791SMarcelo Schmitt  Common-mode voltage -->  --- <  IN-                |
279*9b4b9791SMarcelo Schmitt                                \       +VREF  -VREF |
280*9b4b9791SMarcelo Schmitt                                 +-------------------+
281*9b4b9791SMarcelo Schmitt                                          ^       ^
282*9b4b9791SMarcelo Schmitt                                          |       +---- External -VREF
283*9b4b9791SMarcelo Schmitt                                   External +VREF
284*9b4b9791SMarcelo Schmitt
285*9b4b9791SMarcelo SchmittA **pseudo-differential bipolar** input is not limited by the level at IN- but
286*9b4b9791SMarcelo Schmittit will be limited to -VREF or to GND on the lower end of the input range
287*9b4b9791SMarcelo Schmittdepending on the particular ADC. Similar to their unipolar counter parts,
288*9b4b9791SMarcelo Schmittpseudo-differential bipolar channels ought to declare an ``_offset`` attribute
289*9b4b9791SMarcelo Schmittto enable the conversion of raw ADC data to voltage units. For the setup with
290*9b4b9791SMarcelo SchmittIN- connected to GND, ``_offset`` is often omitted.
291*9b4b9791SMarcelo Schmitt
292*9b4b9791SMarcelo SchmittDevice tree example for pseudo-differential bipolar channel::
293*9b4b9791SMarcelo Schmitt
294*9b4b9791SMarcelo Schmitt    adc@0 {
295*9b4b9791SMarcelo Schmitt        ...
296*9b4b9791SMarcelo Schmitt        #address-cells = <1>;
297*9b4b9791SMarcelo Schmitt        #size-cells = <0>;
298*9b4b9791SMarcelo Schmitt
299*9b4b9791SMarcelo Schmitt        channel@0 {
300*9b4b9791SMarcelo Schmitt            reg = <0>;
301*9b4b9791SMarcelo Schmitt            bipolar;
302*9b4b9791SMarcelo Schmitt            single-channel = <0>;
303*9b4b9791SMarcelo Schmitt            common-mode-channel = <1>;
304*9b4b9791SMarcelo Schmitt        };
305*9b4b9791SMarcelo Schmitt    };
306