ad4695.rst 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. .. SPDX-License-Identifier: GPL-2.0-only
  2. =============
  3. AD4695 driver
  4. =============
  5. ADC driver for Analog Devices Inc. AD4695 and similar devices. The module name
  6. is ``ad4695``.
  7. Supported devices
  8. =================
  9. The following chips are supported by this driver:
  10. * `AD4695 <https://www.analog.com/AD4695>`_
  11. * `AD4696 <https://www.analog.com/AD4696>`_
  12. * `AD4697 <https://www.analog.com/AD4697>`_
  13. * `AD4698 <https://www.analog.com/AD4698>`_
  14. Supported features
  15. ==================
  16. SPI wiring modes
  17. ----------------
  18. The driver currently supports the following SPI wiring configuration:
  19. 4-wire mode
  20. ^^^^^^^^^^^
  21. In this mode, CNV and CS are tied together and there is a single SDO line.
  22. .. code-block::
  23. +-------------+ +-------------+
  24. | CS |<-+------| CS |
  25. | CNV |<-+ | |
  26. | ADC | | HOST |
  27. | | | |
  28. | SDI |<--------| SDO |
  29. | SDO |-------->| SDI |
  30. | SCLK |<--------| SCLK |
  31. +-------------+ +-------------+
  32. To use this mode, in the device tree, omit the ``cnv-gpios`` and
  33. ``spi-rx-bus-width`` properties.
  34. SPI offload wiring
  35. ^^^^^^^^^^^^^^^^^^
  36. When used with a SPI offload, the supported wiring configuration is:
  37. .. code-block::
  38. +-------------+ +-------------+
  39. | GP0/BUSY |-------->| TRIGGER |
  40. | CS |<--------| CS |
  41. | | | |
  42. | ADC | | SPI |
  43. | | | |
  44. | SDI |<--------| SDO |
  45. | SDO |-------->| SDI |
  46. | SCLK |<--------| SCLK |
  47. | | | |
  48. | | +-------------+
  49. | CNV |<-----+--| PWM |
  50. | | +--| GPIO |
  51. +-------------+ +-------------+
  52. In this case, both the ``cnv-gpios`` and ``pwms`` properties are required.
  53. The ``#trigger-source-cells = <2>`` property is also required to connect back
  54. to the SPI offload. The SPI offload will have ``trigger-sources`` property
  55. with cells to indicate the busy signal and which GPx pin is used, e.g
  56. ``<&ad4695 AD4695_TRIGGER_EVENT_BUSY AD4695_TRIGGER_PIN_GP0>``.
  57. .. seealso:: `SPI offload support`_
  58. Channel configuration
  59. ---------------------
  60. Since the chip supports multiple ways to configure each channel, this must be
  61. described in the device tree based on what is actually wired up to the inputs.
  62. There are three typical configurations:
  63. An ``INx`` pin is used as the positive input with the ``REFGND``, ``COM`` or
  64. the next ``INx`` pin as the negative input.
  65. Pairing with REFGND
  66. ^^^^^^^^^^^^^^^^^^^
  67. Each ``INx`` pin can be used as a pseudo-differential input in conjunction with
  68. the ``REFGND`` pin. The device tree will look like this:
  69. .. code-block::
  70. channel@0 {
  71. reg = <0>; /* IN0 */
  72. };
  73. If no other channel properties are needed (e.g. ``adi,no-high-z``), the channel
  74. node can be omitted entirely.
  75. This will appear on the IIO bus as the ``voltage0`` channel. The processed value
  76. (*raw × scale*) will be the voltage present on the ``IN0`` pin relative to
  77. ``REFGND``. (Offset is always 0 when pairing with ``REFGND``.)
  78. Pairing with COM
  79. ^^^^^^^^^^^^^^^^
  80. Each ``INx`` pin can be used as a pseudo-differential input in conjunction with
  81. the ``COM`` pin. The device tree will look like this:
  82. .. code-block::
  83. com-supply = <&vref_div_2>;
  84. channel@1 {
  85. reg = <1>; /* IN1 */
  86. common-mode-channel = <AD4695_COMMON_MODE_COM>;
  87. bipolar;
  88. };
  89. This will appear on the IIO bus as the ``voltage1`` channel. The processed value
  90. (*(raw + offset) × scale*) will be the voltage measured on the ``IN1`` pin
  91. relative to ``REFGND``. (The offset is determined by the ``com-supply`` voltage.)
  92. The macro comes from:
  93. .. code-block::
  94. #include <dt-bindings/iio/adc/adi,ad4695.h>
  95. Pairing two INx pins
  96. ^^^^^^^^^^^^^^^^^^^^
  97. An even-numbered ``INx`` pin and the following odd-numbered ``INx`` pin can be
  98. used as a pseudo-differential input. The device tree for using ``IN2`` as the
  99. positive input and ``IN3`` as the negative input will look like this:
  100. .. code-block::
  101. in3-supply = <&vref_div_2>;
  102. channel@2 {
  103. reg = <2>; /* IN2 */
  104. common-mode-channel = <3>; /* IN3 */
  105. bipolar;
  106. };
  107. This will appear on the IIO bus as the ``voltage2`` channel. The processed value
  108. (*(raw + offset) × scale*) will be the voltage measured on the ``IN1`` pin
  109. relative to ``REFGND``. (Offset is determined by the ``in3-supply`` voltage.)
  110. VCC supply
  111. ----------
  112. The chip supports being powered by an external LDO via the ``VCC`` input or an
  113. internal LDO via the ``LDO_IN`` input. The driver looks at the device tree to
  114. determine which is being used. If ``ldo-supply`` is present, then the internal
  115. LDO is used. If ``vcc-supply`` is present, then the external LDO is used and
  116. the internal LDO is disabled.
  117. Reference voltage
  118. -----------------
  119. The chip supports an external reference voltage via the ``REF`` input or an
  120. internal buffered reference voltage via the ``REFIN`` input. The driver looks
  121. at the device tree to determine which is being used. If ``ref-supply`` is
  122. present, then the external reference voltage is used and the internal buffer is
  123. disabled. If ``refin-supply`` is present, then the internal buffered reference
  124. voltage is used.
  125. Gain/offset calibration
  126. -----------------------
  127. System calibration is supported using the channel gain and offset registers via
  128. the ``calibscale`` and ``calibbias`` attributes respectively.
  129. Oversampling
  130. ------------
  131. The chip supports per-channel oversampling when SPI offload is being used, with
  132. available oversampling ratios (OSR) of 1 (default), 4, 16, and 64. Enabling
  133. oversampling on a channel raises the effective number of bits of sampled data to
  134. 17 (OSR == 4), 18 (16), or 19 (64), respectively. This can be set via the
  135. ``oversampling_ratio`` attribute.
  136. Setting the oversampling ratio for a channel also changes the sample rate for
  137. that channel, since it requires multiple conversions per 1 sample. Specifically,
  138. the new sampling frequency is the PWM sampling frequency divided by the
  139. particular OSR. This is set automatically by the driver when setting the
  140. ``oversampling_ratio`` attribute. For example, if the device's current
  141. ``sampling_frequency`` is 10000 and an OSR of 4 is set on channel ``voltage0``,
  142. the new reported sampling rate for that channel will be 2500 (ignoring PWM API
  143. rounding), while all others will remain at 10000. Subsequently setting the
  144. sampling frequency to a higher value on that channel will adjust the CNV trigger
  145. period for all channels, e.g. if ``voltage0``'s sampling frequency is adjusted
  146. from 2500 (with an OSR of 4) to 10000, the value reported by
  147. ``in_voltage0_sampling_frequency`` will be 10000, but all other channels will
  148. now report 40000.
  149. For simplicity, the sampling frequency of the device should be set (considering
  150. the highest desired OSR value to be used) first, before configuring oversampling
  151. for specific channels.
  152. Unimplemented features
  153. ----------------------
  154. - Additional wiring modes
  155. - Threshold events
  156. - GPIO support
  157. - CRC support
  158. SPI offload support
  159. ===================
  160. To be able to achieve the maximum sample rate, the driver can be used with the
  161. `AXI SPI Engine`_ to provide SPI offload support.
  162. .. _AXI SPI Engine: http://analogdevicesinc.github.io/hdl/projects/ad469x_fmc/index.html
  163. .. seealso:: `SPI offload wiring`_
  164. When SPI offload is being used, some attributes will be different.
  165. * ``trigger`` directory is removed.
  166. * ``in_voltage0_sampling_frequency`` attributes are added for setting the sample
  167. rate.
  168. * ``in_voltage0_sampling_frequency_available`` attributes are added for querying
  169. the max sample rate.
  170. * ``timestamp`` channel is removed.
  171. * Buffer data format may be different compared to when offload is not used,
  172. e.g. the ``buffer0/in_voltage0_type`` attribute.
  173. Device buffers
  174. ==============
  175. This driver supports hardware triggered buffers. This uses the "advanced
  176. sequencer" feature of the chip to trigger a burst of conversions.
  177. Also see :doc:`iio_devbuf` for more general information.
  178. Effective sample rate for buffered reads
  179. ----------------------------------------
  180. When SPI offload is not used, the sample rate is determined by the trigger that
  181. is manually configured in userspace. All enabled channels will be read in a
  182. burst when the trigger is received.
  183. When SPI offload is used, the sample rate is configured per channel. All
  184. channels will have the same rate, so only one ``in_voltageY_sampling_frequency``
  185. attribute needs to be set. Since this rate determines the delay between each
  186. individual conversion, the effective sample rate for each sample is actually
  187. the sum of the periods of each enabled channel in a buffered read. In other
  188. words, it is the value of the ``in_voltageY_sampling_frequency`` attribute
  189. divided by the number of enabled channels. So if 4 channels are enabled, with
  190. the ``in_voltageY_sampling_frequency`` attributes set to 1 MHz, the effective
  191. sample rate is 250 kHz.
  192. With oversampling enabled, the effective sample rate also depends on the OSR
  193. assigned to each channel. For example, if one of the 4 channels mentioned in the
  194. previous case is configured with an OSR of 4, the effective sample rate for that
  195. channel becomes (1 MHz / 4 ) = 250 kHz. The effective sample rate for all
  196. four channels is then 1 / ( (3 / 1 MHz) + ( 1 / 250 kHz) ) ~= 142.9 kHz. Note
  197. that in this case "sample" refers to one read of all enabled channels (i.e. one
  198. full cycle through the auto-sequencer).