1*4e8327ccSRadu Sabau.. SPDX-License-Identifier: GPL-2.0-only 2*4e8327ccSRadu Sabau 3*4e8327ccSRadu Sabau============= 4*4e8327ccSRadu SabauAD4691 driver 5*4e8327ccSRadu Sabau============= 6*4e8327ccSRadu Sabau 7*4e8327ccSRadu SabauADC driver for Analog Devices Inc. AD4691 family of multichannel SAR ADCs. 8*4e8327ccSRadu SabauThe module name is ``ad4691``. 9*4e8327ccSRadu Sabau 10*4e8327ccSRadu Sabau 11*4e8327ccSRadu SabauSupported devices 12*4e8327ccSRadu Sabau================= 13*4e8327ccSRadu Sabau 14*4e8327ccSRadu SabauThe following chips are supported by this driver: 15*4e8327ccSRadu Sabau 16*4e8327ccSRadu Sabau* `AD4691 <https://www.analog.com/en/products/ad4691.html>`_ — 16-channel, 500 kSPS 17*4e8327ccSRadu Sabau* `AD4692 <https://www.analog.com/en/products/ad4692.html>`_ — 16-channel, 1 MSPS 18*4e8327ccSRadu Sabau* `AD4693 <https://www.analog.com/en/products/ad4693.html>`_ — 8-channel, 500 kSPS 19*4e8327ccSRadu Sabau* `AD4694 <https://www.analog.com/en/products/ad4694.html>`_ — 8-channel, 1 MSPS 20*4e8327ccSRadu Sabau 21*4e8327ccSRadu Sabau 22*4e8327ccSRadu SabauIIO channels 23*4e8327ccSRadu Sabau============ 24*4e8327ccSRadu Sabau 25*4e8327ccSRadu SabauEach physical ADC input maps to one IIO voltage channel. The AD4691 and AD4692 26*4e8327ccSRadu Sabauexpose 16 channels (``voltage0`` through ``voltage15``); the AD4693 and AD4694 27*4e8327ccSRadu Sabauexpose 8 channels (``voltage0`` through ``voltage7``). 28*4e8327ccSRadu Sabau 29*4e8327ccSRadu SabauAll channels share a common scale (``in_voltage_scale``), derived from the 30*4e8327ccSRadu Sabaureference voltage. Each channel exposes: 31*4e8327ccSRadu Sabau 32*4e8327ccSRadu Sabau* ``in_voltageN_raw`` — single-shot ADC result 33*4e8327ccSRadu Sabau 34*4e8327ccSRadu SabauThe following attributes are shared across all channels: 35*4e8327ccSRadu Sabau 36*4e8327ccSRadu Sabau* ``in_voltage_sampling_frequency`` — effective output rate, defined as the 37*4e8327ccSRadu Sabau internal oscillator frequency divided by the oversampling ratio. Writing this 38*4e8327ccSRadu Sabau attribute selects the nearest achievable rate for the current OSR; the value 39*4e8327ccSRadu Sabau read back reflects the actual rate after snapping to the closest valid 40*4e8327ccSRadu Sabau oscillator entry. 41*4e8327ccSRadu Sabau* ``in_voltage_sampling_frequency_available`` — list of achievable effective 42*4e8327ccSRadu Sabau rates for the current oversampling ratio. The list updates dynamically when 43*4e8327ccSRadu Sabau the oversampling ratio changes. 44*4e8327ccSRadu Sabau 45*4e8327ccSRadu SabauThe following attributes are shared across all channels and only available in 46*4e8327ccSRadu SabauCNV Burst Mode: 47*4e8327ccSRadu Sabau 48*4e8327ccSRadu Sabau* ``in_voltage_oversampling_ratio`` — hardware oversampling depth applied to 49*4e8327ccSRadu Sabau all channels; see `Oversampling`_ below. 50*4e8327ccSRadu Sabau* ``in_voltage_oversampling_ratio_available`` — valid ratios: 1, 2, 4, 8, 16, 51*4e8327ccSRadu Sabau 32. 52*4e8327ccSRadu Sabau 53*4e8327ccSRadu Sabau 54*4e8327ccSRadu SabauOperating modes 55*4e8327ccSRadu Sabau=============== 56*4e8327ccSRadu Sabau 57*4e8327ccSRadu SabauThe driver supports two operating modes, selected automatically from the 58*4e8327ccSRadu Sabaudevice tree at probe time. 59*4e8327ccSRadu Sabau 60*4e8327ccSRadu SabauManual Mode 61*4e8327ccSRadu Sabau----------- 62*4e8327ccSRadu Sabau 63*4e8327ccSRadu SabauSelected when no ``pwms`` property is present in the device tree. The CNV pin 64*4e8327ccSRadu Sabauis tied to the SPI chip-select: every CS assertion triggers a conversion and 65*4e8327ccSRadu Sabaureturns the previous result. A user-defined IIO trigger (e.g. hrtimer trigger) 66*4e8327ccSRadu Sabaudrives the buffer. 67*4e8327ccSRadu Sabau 68*4e8327ccSRadu SabauOversampling is not supported in Manual Mode. 69*4e8327ccSRadu Sabau 70*4e8327ccSRadu SabauCNV Burst Mode 71*4e8327ccSRadu Sabau-------------- 72*4e8327ccSRadu Sabau 73*4e8327ccSRadu SabauSelected when a ``pwms`` property is present in the device tree. A PWM drives 74*4e8327ccSRadu Sabauthe CNV pin at the configured conversion rate. A GP pin wired to the SoC and 75*4e8327ccSRadu Sabaudeclared in the device tree signals DATA_READY at the end of each burst, 76*4e8327ccSRadu Sabautriggering a readout of all active channel results into the IIO buffer. 77*4e8327ccSRadu Sabau 78*4e8327ccSRadu SabauThe buffer output rate is controlled by the ``sampling_frequency`` attribute 79*4e8327ccSRadu Sabauon the IIO buffer. In practice the PWM rate should be set low enough to allow 80*4e8327ccSRadu Sabauthe SPI readout to complete before the next conversion burst begins. 81*4e8327ccSRadu Sabau 82*4e8327ccSRadu SabauAutonomous Mode (idle / single-shot) 83*4e8327ccSRadu Sabau------------------------------------- 84*4e8327ccSRadu Sabau 85*4e8327ccSRadu SabauWhen the IIO buffer is disabled, ``in_voltageN_raw`` reads perform a single 86*4e8327ccSRadu Sabauconversion on the requested channel using the internal oscillator. The 87*4e8327ccSRadu Sabauoscillator is started and stopped around each read to save power. 88*4e8327ccSRadu Sabau 89*4e8327ccSRadu Sabau 90*4e8327ccSRadu SabauOversampling 91*4e8327ccSRadu Sabau============ 92*4e8327ccSRadu Sabau 93*4e8327ccSRadu SabauIn CNV Burst Mode a shared hardware accumulator averages a configurable number 94*4e8327ccSRadu Sabauof successive conversions across all active channels. The result is always a 95*4e8327ccSRadu Sabau16-bit mean, so the buffer data type (shown in ``buffer0/in_voltageN_type``) 96*4e8327ccSRadu Sabauis unaffected by the oversampling ratio. Valid ratios are 1, 2, 4, 8, 16 and 97*4e8327ccSRadu Sabau32; the default is 1 (no averaging). Oversampling is not supported in Manual 98*4e8327ccSRadu SabauMode. 99*4e8327ccSRadu Sabau 100*4e8327ccSRadu Sabau.. code-block:: bash 101*4e8327ccSRadu Sabau 102*4e8327ccSRadu Sabau # Set oversampling ratio to 16 (shared across all channels) 103*4e8327ccSRadu Sabau echo 16 > /sys/bus/iio/devices/iio:device0/in_voltage_oversampling_ratio 104*4e8327ccSRadu Sabau 105*4e8327ccSRadu Sabau # Read the resulting effective sampling frequency 106*4e8327ccSRadu Sabau cat /sys/bus/iio/devices/iio:device0/in_voltage_sampling_frequency 107*4e8327ccSRadu Sabau 108*4e8327ccSRadu SabauWriting ``in_voltage_oversampling_ratio`` stores the new shared depth and snaps 109*4e8327ccSRadu Sabauthe internal oscillator to the largest valid table entry that is both less than 110*4e8327ccSRadu Sabauor equal to ``old_effective_rate × new_osr`` and evenly divisible by 111*4e8327ccSRadu Sabau``new_osr``. This preserves an integer read-back of 112*4e8327ccSRadu Sabau``in_voltage_sampling_frequency`` after the change and keeps the oscillator as 113*4e8327ccSRadu Sabauclose as possible to the previous effective rate. 114*4e8327ccSRadu Sabau 115*4e8327ccSRadu Sabau 116*4e8327ccSRadu SabauReference voltage 117*4e8327ccSRadu Sabau================= 118*4e8327ccSRadu Sabau 119*4e8327ccSRadu SabauThe driver supports two reference configurations, mutually exclusive: 120*4e8327ccSRadu Sabau 121*4e8327ccSRadu Sabau* **External reference** (``ref-supply``): a voltage between 2.4 V and 5.25 V 122*4e8327ccSRadu Sabau supplied externally. 123*4e8327ccSRadu Sabau* **Buffered internal reference** (``refin-supply``): an internal reference 124*4e8327ccSRadu Sabau buffer is enabled by the driver. 125*4e8327ccSRadu Sabau 126*4e8327ccSRadu SabauExactly one of ``ref-supply`` or ``refin-supply`` must be present in the 127*4e8327ccSRadu Sabaudevice tree. The reference voltage determines the full-scale range reported 128*4e8327ccSRadu Sabauvia ``in_voltage_scale``. 129*4e8327ccSRadu Sabau 130*4e8327ccSRadu Sabau 131*4e8327ccSRadu SabauLDO supply 132*4e8327ccSRadu Sabau========== 133*4e8327ccSRadu Sabau 134*4e8327ccSRadu SabauThe chip contains an internal LDO that powers part of the analog front-end. 135*4e8327ccSRadu SabauThe supply configuration is mutually exclusive: 136*4e8327ccSRadu Sabau 137*4e8327ccSRadu Sabau* **External VDD** (``vdd-supply``): an external 1.8 V supply is used directly; 138*4e8327ccSRadu Sabau the internal LDO is disabled. 139*4e8327ccSRadu Sabau* **Internal LDO** (``ldo-in-supply``): the internal LDO is enabled and fed 140*4e8327ccSRadu Sabau from the ``ldo-in`` regulator. Use this when no external 1.8 V VDD is present. 141*4e8327ccSRadu Sabau 142*4e8327ccSRadu SabauExactly one of ``vdd-supply`` or ``ldo-in-supply`` must be provided. 143*4e8327ccSRadu Sabau 144*4e8327ccSRadu Sabau 145*4e8327ccSRadu SabauReset 146*4e8327ccSRadu Sabau===== 147*4e8327ccSRadu Sabau 148*4e8327ccSRadu SabauThe driver supports two reset mechanisms: 149*4e8327ccSRadu Sabau 150*4e8327ccSRadu Sabau* **Hardware reset** (``reset-gpios`` in device tree): the GPIO line is 151*4e8327ccSRadu Sabau asserted then deasserted at probe; the driver waits 300 µs for the chip 152*4e8327ccSRadu Sabau to complete its internal reset sequence before accepting SPI commands. 153*4e8327ccSRadu Sabau* **Software reset** (fallback when ``reset-gpios`` is absent): written 154*4e8327ccSRadu Sabau automatically at probe. 155*4e8327ccSRadu Sabau 156*4e8327ccSRadu Sabau 157*4e8327ccSRadu SabauGP pins and interrupts 158*4e8327ccSRadu Sabau====================== 159*4e8327ccSRadu Sabau 160*4e8327ccSRadu SabauThe chip exposes up to four general-purpose (GP) pins. In CNV Burst Mode 161*4e8327ccSRadu Sabau(non-offload), one GP pin must be wired to an interrupt-capable SoC input and 162*4e8327ccSRadu Sabaudeclared in the device tree using the ``interrupts`` and ``interrupt-names`` 163*4e8327ccSRadu Sabauproperties. The ``interrupt-names`` value identifies which GP pin is used 164*4e8327ccSRadu Sabau(``"gp0"`` through ``"gp3"``). 165*4e8327ccSRadu Sabau 166*4e8327ccSRadu SabauExample device tree fragment:: 167*4e8327ccSRadu Sabau 168*4e8327ccSRadu Sabau adc@0 { 169*4e8327ccSRadu Sabau compatible = "adi,ad4692"; 170*4e8327ccSRadu Sabau ... 171*4e8327ccSRadu Sabau interrupt-parent = <&gpio0>; 172*4e8327ccSRadu Sabau interrupts = <17 IRQ_TYPE_LEVEL_HIGH>; 173*4e8327ccSRadu Sabau interrupt-names = "gp0"; 174*4e8327ccSRadu Sabau }; 175*4e8327ccSRadu Sabau 176*4e8327ccSRadu Sabau 177*4e8327ccSRadu SabauSPI offload support 178*4e8327ccSRadu Sabau=================== 179*4e8327ccSRadu Sabau 180*4e8327ccSRadu SabauWhen a SPI offload engine (e.g. the AXI SPI Engine) is present, the driver 181*4e8327ccSRadu Sabauuses DMA-backed transfers for CPU-independent, high-throughput data capture. 182*4e8327ccSRadu SabauSPI offload is detected automatically at probe; if no offload hardware is 183*4e8327ccSRadu Sabauavailable the driver falls back to the software triggered-buffer path. 184*4e8327ccSRadu Sabau 185*4e8327ccSRadu SabauTwo SPI offload sub-modes exist: 186*4e8327ccSRadu Sabau 187*4e8327ccSRadu SabauCNV Burst offload 188*4e8327ccSRadu Sabau----------------- 189*4e8327ccSRadu Sabau 190*4e8327ccSRadu SabauUsed when a ``pwms`` property is present and SPI offload is available. The PWM 191*4e8327ccSRadu Sabaudrives CNV at the configured rate; on DATA_READY the offload engine reads all 192*4e8327ccSRadu Sabauactive channel results and streams them directly to the IIO DMA buffer with no 193*4e8327ccSRadu SabauCPU involvement. The GP pin used as DATA_READY trigger is supplied by the 194*4e8327ccSRadu Sabautrigger-source consumer at buffer enable time; no ``interrupt-names`` entry is 195*4e8327ccSRadu Sabaurequired. 196*4e8327ccSRadu Sabau 197*4e8327ccSRadu SabauManual offload 198*4e8327ccSRadu Sabau-------------- 199*4e8327ccSRadu Sabau 200*4e8327ccSRadu SabauUsed when no ``pwms`` property is present and SPI offload is available. A 201*4e8327ccSRadu Sabauperiodic SPI offload trigger controls the conversion rate and the offload engine 202*4e8327ccSRadu Sabaustreams results directly to the IIO DMA buffer. 203*4e8327ccSRadu Sabau 204*4e8327ccSRadu SabauThe ``sampling_frequency`` attribute on the IIO buffer controls the trigger 205*4e8327ccSRadu Sabaurate (in Hz). The initial rate is 100 kHz. 206*4e8327ccSRadu Sabau 207*4e8327ccSRadu SabauOversampling is not supported in Manual Mode. 208*4e8327ccSRadu Sabau 209*4e8327ccSRadu Sabau 210*4e8327ccSRadu SabauBuffer data format 211*4e8327ccSRadu Sabau================== 212*4e8327ccSRadu Sabau 213*4e8327ccSRadu SabauThe sample format in the IIO buffer depends on whether SPI offload is in use. 214*4e8327ccSRadu Sabau 215*4e8327ccSRadu SabauSoftware triggered-buffer path (no SPI offload) 216*4e8327ccSRadu Sabau------------------------------------------------ 217*4e8327ccSRadu Sabau 218*4e8327ccSRadu SabauEach active channel occupies one 16-bit big-endian slot (``storagebits=16``, 219*4e8327ccSRadu Sabau``endianness=be``). Active channels are packed densely in scan-index order, 220*4e8327ccSRadu Sabaufollowed by a 64-bit software timestamp appended by the IIO core. 221*4e8327ccSRadu Sabau 222*4e8327ccSRadu SabauSPI offload path 223*4e8327ccSRadu Sabau---------------- 224*4e8327ccSRadu Sabau 225*4e8327ccSRadu SabauEach active channel occupies one 16-bit CPU-native slot (``storagebits=16``, 226*4e8327ccSRadu Sabau``endianness=cpu``). The SPI offload engine streams 16-bit words directly from 227*4e8327ccSRadu Sabauthe SPI Engine into the DMA buffer; no software timestamp is appended. 228