iio_adc.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. .. SPDX-License-Identifier: GPL-2.0-only
  2. =========================
  3. IIO Abstractions for ADCs
  4. =========================
  5. 1. Overview
  6. ===========
  7. The IIO subsystem supports many Analog to Digital Converters (ADCs). Some ADCs
  8. have features and characteristics that are supported in specific ways by IIO
  9. device drivers. This documentation describes common ADC features and explains
  10. how they are supported by the IIO subsystem.
  11. 1. ADC Channel Types
  12. ====================
  13. ADCs can have distinct types of inputs, each of them measuring analog voltages
  14. in a slightly different way. An ADC digitizes the analog input voltage over a
  15. span that is often given by the provided voltage reference, the input type, and
  16. the input polarity. The input range allowed to an ADC channel is needed to
  17. determine the scale factor and offset needed to obtain the measured value in
  18. real-world units (millivolts for voltage measurement, milliamps for current
  19. measurement, etc.).
  20. Elaborate designs may have nonlinear characteristics or integrated components
  21. (such as amplifiers and reference buffers) that might also have to be considered
  22. to derive the allowed input range for an ADC. For clarity, the sections below
  23. assume the input range only depends on the provided voltage references, input
  24. type, and input polarity.
  25. There are three general types of ADC inputs (single-ended, differential,
  26. pseudo-differential) and two possible polarities (unipolar, bipolar). The input
  27. type (single-ended, differential, pseudo-differential) is one channel
  28. characteristic, and is completely independent of the polarity (unipolar,
  29. bipolar) aspect. A comprehensive article about ADC input types (on which this
  30. doc is heavily based on) can be found at
  31. https://www.analog.com/en/resources/technical-articles/sar-adc-input-types.html.
  32. 1.1 Single-ended channels
  33. -------------------------
  34. Single-ended channels digitize the analog input voltage relative to ground and
  35. can be either unipolar or bipolar.
  36. 1.1.1 Single-ended Unipolar Channels
  37. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  38. ::
  39. ---------- VREF -------------
  40. ´ ` ´ ` _____________
  41. / \ / \ / |
  42. / \ / \ --- < IN ADC |
  43. \ / \ / \ |
  44. `-´ `-´ \ VREF |
  45. -------- GND (0V) ----------- +-----------+
  46. ^
  47. |
  48. External VREF
  49. The input voltage to a **single-ended unipolar** channel is allowed to swing
  50. from GND to VREF (where VREF is a voltage reference with electrical potential
  51. higher than system ground). The maximum input voltage is also called VFS
  52. (Voltage input Full-Scale), with VFS being determined by VREF. The voltage
  53. reference may be provided from an external supply or derived from the chip power
  54. source.
  55. A single-ended unipolar channel could be described in device tree like the
  56. following example::
  57. adc@0 {
  58. ...
  59. #address-cells = <1>;
  60. #size-cells = <0>;
  61. channel@0 {
  62. reg = <0>;
  63. };
  64. };
  65. One is always allowed to include ADC channel nodes in the device tree. Though,
  66. if the device has a uniform set of inputs (e.g. all inputs are single-ended),
  67. then declaring the channel nodes is optional.
  68. One caveat for devices that support mixed single-ended and differential channels
  69. is that single-ended channel nodes also need to provide a ``single-channel``
  70. property when ``reg`` is an arbitrary number that doesn't match the input pin
  71. number.
  72. See ``Documentation/devicetree/bindings/iio/adc/adc.yaml`` for the complete
  73. documentation of ADC specific device tree properties.
  74. 1.1.2 Single-ended Bipolar Channels
  75. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  76. ::
  77. ---------- +VREF ------------
  78. ´ ` ´ ` _____________________
  79. / \ / \ / |
  80. / \ / \ --- < IN ADC |
  81. \ / \ / \ |
  82. `-´ `-´ \ +VREF -VREF |
  83. ---------- -VREF ------------ +-------------------+
  84. ^ ^
  85. | |
  86. External +VREF ------+ External -VREF
  87. For a **single-ended bipolar** channel, the analog voltage input can go from
  88. -VREF to +VREF (where -VREF is the voltage reference that has the lower
  89. electrical potential while +VREF is the reference with the higher one). Some ADC
  90. chips derive the lower reference from +VREF, others get it from a separate
  91. input. Often, +VREF and -VREF are symmetric but they don't need to be so. When
  92. -VREF is lower than system ground, these inputs are also called single-ended
  93. true bipolar. Also, while there is a relevant difference between bipolar and
  94. true bipolar from the electrical perspective, IIO makes no explicit distinction
  95. between them.
  96. Here's an example device tree description of a single-ended bipolar channel::
  97. adc@0 {
  98. ...
  99. #address-cells = <1>;
  100. #size-cells = <0>;
  101. channel@0 {
  102. reg = <0>;
  103. bipolar;
  104. };
  105. };
  106. 1.2 Differential channels
  107. -------------------------
  108. A differential voltage measurement digitizes the voltage level at the positive
  109. input (IN+) relative to the negative input (IN-) over the -VREF to +VREF span.
  110. In other words, a differential channel measures the potential difference between
  111. IN+ and IN-, which is often denoted by the IN+ - IN- formula.
  112. 1.2.1 Differential Bipolar Channels
  113. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  114. ::
  115. -------- +VREF ------ +-------------------+
  116. ´ ` ´ ` / |
  117. / \ / \ / --- < IN+ |
  118. `-´ `-´ | |
  119. -------- -VREF ------ | |
  120. | ADC |
  121. -------- +VREF ------ | |
  122. ´ ` ´ ` | |
  123. \ / \ / \ --- < IN- |
  124. `-´ `-´ \ +VREF -VREF |
  125. -------- -VREF ------ +-------------------+
  126. ^ ^
  127. | +---- External -VREF
  128. External +VREF
  129. The analog signals to **differential bipolar** inputs are also allowed to swing
  130. from -VREF to +VREF. The bipolar part of the name means that the resulting value
  131. of the difference (IN+ - IN-) can be positive or negative. If -VREF is below
  132. system GND, these are also called differential true bipolar inputs.
  133. Device tree example of a differential bipolar channel::
  134. adc@0 {
  135. ...
  136. #address-cells = <1>;
  137. #size-cells = <0>;
  138. channel@0 {
  139. reg = <0>;
  140. bipolar;
  141. diff-channels = <0 1>;
  142. };
  143. };
  144. In the ADC driver, ``differential = 1`` is set into ``struct iio_chan_spec`` for
  145. the channel. Even though, there are three general input types, ``differential``
  146. is only used to distinguish between differential and non-differential (either
  147. single-ended or pseudo-differential) input types. See
  148. ``include/linux/iio/iio.h`` for more information.
  149. 1.2.2 Differential Unipolar Channels
  150. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  151. For **differential unipolar** channels, the analog voltage at the positive input
  152. must also be higher than the voltage at the negative input. Thus, the actual
  153. input range allowed to a differential unipolar channel is IN- to +VREF. Because
  154. IN+ is allowed to swing with the measured analog signal and the input setup must
  155. guarantee IN+ will not go below IN- (nor IN- will raise above IN+), most
  156. differential unipolar channel setups have IN- fixed to a known voltage that does
  157. not fall within the voltage range expected for the measured signal. That leads
  158. to a setup that is equivalent to a pseudo-differential channel. Thus,
  159. differential unipolar setups can often be supported as pseudo-differential
  160. unipolar channels.
  161. 1.3 Pseudo-differential Channels
  162. --------------------------------
  163. There is a third ADC input type which is called pseudo-differential or
  164. single-ended to differential configuration. A pseudo-differential channel is
  165. similar to a differential channel in that it also measures IN+ relative to IN-.
  166. However, unlike bipolar differential channels, the negative input is limited to
  167. a narrow voltage range (taken as a constant voltage) while only IN+ is allowed
  168. to swing. A pseudo-differential channel can be made out from a differential pair
  169. of inputs by restricting the negative input to a known voltage while allowing
  170. only the positive input to swing. Sometimes, the input provided to IN- is called
  171. common-mode voltage. Besides, some parts have a COM pin that allows single-ended
  172. inputs to be referenced to a common-mode voltage, making them
  173. pseudo-differential channels. Often, the common mode input voltage can be
  174. described in the device tree as a voltage regulator (e.g. ``com-supply``) since
  175. it is basically a constant voltage source.
  176. 1.3.1 Pseudo-differential Unipolar Channels
  177. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  178. ::
  179. -------- +VREF ------ +-------------------+
  180. ´ ` ´ ` / |
  181. / \ / \ / --- < IN+ |
  182. `-´ `-´ | |
  183. --------- IN- ------- | ADC |
  184. | |
  185. Common-mode voltage --> --- < IN- |
  186. \ +VREF -VREF |
  187. +-------------------+
  188. ^ ^
  189. | +---- External -VREF
  190. External +VREF
  191. A **pseudo-differential unipolar** input has the limitations a differential
  192. unipolar channel would have, meaning the analog voltage to the positive input
  193. IN+ must stay within IN- to +VREF. The fixed voltage to IN- is often called
  194. common-mode voltage and it must be within -VREF to +VREF as would be expected
  195. from the signal to any differential channel negative input.
  196. The voltage measured from IN+ is relative to IN- but, unlike differential
  197. channels, pseudo-differential setups are intended to gauge single-ended input
  198. signals. To enable applications to calculate IN+ voltage with respect to system
  199. ground, the IIO channel may provide an ``_offset`` sysfs attribute to be added
  200. to ADC output when converting raw data to voltage units. In many setups, the
  201. common-mode voltage input is at GND level and the ``_offset`` attribute is
  202. omitted due to being always zero.
  203. Device tree example for pseudo-differential unipolar channel::
  204. adc@0 {
  205. ...
  206. #address-cells = <1>;
  207. #size-cells = <0>;
  208. channel@0 {
  209. reg = <0>;
  210. single-channel = <0>;
  211. common-mode-channel = <1>;
  212. };
  213. };
  214. Do not set ``differential`` in the channel ``iio_chan_spec`` struct of
  215. pseudo-differential channels.
  216. 1.3.2 Pseudo-differential Bipolar Channels
  217. ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  218. ::
  219. -------- +VREF ------ +-------------------+
  220. ´ ` ´ ` / |
  221. / \ / \ / --- < IN+ |
  222. `-´ `-´ | |
  223. -------- -VREF ------ | ADC |
  224. | |
  225. Common-mode voltage --> --- < IN- |
  226. \ +VREF -VREF |
  227. +-------------------+
  228. ^ ^
  229. | +---- External -VREF
  230. External +VREF
  231. A **pseudo-differential bipolar** input is not limited by the level at IN- but
  232. it will be limited to -VREF or to GND on the lower end of the input range
  233. depending on the particular ADC. Similar to their unipolar counter parts,
  234. pseudo-differential bipolar channels ought to declare an ``_offset`` attribute
  235. to enable the conversion of raw ADC data to voltage units. For the setup with
  236. IN- connected to GND, ``_offset`` is often omitted.
  237. Device tree example for pseudo-differential bipolar channel::
  238. adc@0 {
  239. ...
  240. #address-cells = <1>;
  241. #size-cells = <0>;
  242. channel@0 {
  243. reg = <0>;
  244. bipolar;
  245. single-channel = <0>;
  246. common-mode-channel = <1>;
  247. };
  248. };