Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

doc: iio: ad4695: describe oversampling support

Add a section to the ad4695 documentation describing how to use the
oversampling feature. Also add some clarification on how the
oversampling ratio influences effective sample rate in the offload
section.

Signed-off-by: Trevor Gamblin <tgamblin@baylibre.com>
Tested-by: David Lechner <dlechner@baylibre.com>
Link: https://patch.msgid.link/20250109-ad4695-oversampling-v2-2-a46ac487082c@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Trevor Gamblin and committed by
Jonathan Cameron
c26b0854 67d63185

+35 -1
+35 -1
Documentation/iio/ad4695.rst
··· 179 179 System calibration is supported using the channel gain and offset registers via 180 180 the ``calibscale`` and ``calibbias`` attributes respectively. 181 181 182 + Oversampling 183 + ------------ 184 + 185 + The chip supports per-channel oversampling when SPI offload is being used, with 186 + available oversampling ratios (OSR) of 1 (default), 4, 16, and 64. Enabling 187 + oversampling on a channel raises the effective number of bits of sampled data to 188 + 17 (OSR == 4), 18 (16), or 19 (64), respectively. This can be set via the 189 + ``oversampling_ratio`` attribute. 190 + 191 + Setting the oversampling ratio for a channel also changes the sample rate for 192 + that channel, since it requires multiple conversions per 1 sample. Specifically, 193 + the new sampling frequency is the PWM sampling frequency divided by the 194 + particular OSR. This is set automatically by the driver when setting the 195 + ``oversampling_ratio`` attribute. For example, if the device's current 196 + ``sampling_frequency`` is 10000 and an OSR of 4 is set on channel ``voltage0``, 197 + the new reported sampling rate for that channel will be 2500 (ignoring PWM API 198 + rounding), while all others will remain at 10000. Subsequently setting the 199 + sampling frequency to a higher value on that channel will adjust the CNV trigger 200 + period for all channels, e.g. if ``voltage0``'s sampling frequency is adjusted 201 + from 2500 (with an OSR of 4) to 10000, the value reported by 202 + ``in_voltage0_sampling_frequency`` will be 10000, but all other channels will 203 + now report 40000. 204 + 205 + For simplicity, the sampling frequency of the device should be set (considering 206 + the highest desired OSR value to be used) first, before configuring oversampling 207 + for specific channels. 208 + 182 209 Unimplemented features 183 210 ---------------------- 184 211 185 212 - Additional wiring modes 186 213 - Threshold events 187 - - Oversampling 188 214 - GPIO support 189 215 - CRC support 190 216 ··· 259 233 divided by the number of enabled channels. So if 4 channels are enabled, with 260 234 the ``in_voltageY_sampling_frequency`` attributes set to 1 MHz, the effective 261 235 sample rate is 250 kHz. 236 + 237 + With oversampling enabled, the effective sample rate also depends on the OSR 238 + assigned to each channel. For example, if one of the 4 channels mentioned in the 239 + previous case is configured with an OSR of 4, the effective sample rate for that 240 + channel becomes (1 MHz / 4 ) = 250 kHz. The effective sample rate for all 241 + four channels is then 1 / ( (3 / 1 MHz) + ( 1 / 250 kHz) ) ~= 142.9 kHz. Note 242 + that in this case "sample" refers to one read of all enabled channels (i.e. one 243 + full cycle through the auto-sequencer).