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

iio: backend: add API for interface tuning

This is in preparation for supporting interface tuning in one for the
devices using the axi-adc backend. The new added interfaces are all
needed for that calibration:

* iio_backend_test_pattern_set();
* iio_backend_chan_status();
* iio_backend_iodelay_set();
* iio_backend_data_sample_trigger().

Interface tuning is the process of going through a set of known points
(typically by the frontend), change some clk or data delays (or both)
and send/receive some known signal (so called test patterns in this
change). The receiving end (either frontend or the backend) is
responsible for validating the signal and see if it's good or not. The
goal for all of this is to come up with ideal delays at the data
interface level so we can have a proper, more reliable data transfer.

Also note that for some devices we can change the sampling rate
(which typically means changing some reference clock) and that can
affect the data interface. In that case, it's import to run the tuning
algorithm again as the values we had before may no longer be the best (or
even valid) ones.

Signed-off-by: Nuno Sa <nuno.sa@analog.com>
Link: https://lore.kernel.org/r/20240426-ad9467-new-features-v2-2-6361fc3ba1cc@analog.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Nuno Sa and committed by
Jonathan Cameron
c66eabcc 09415814

+122
+86
drivers/iio/industrialio-backend.c
··· 226 226 } 227 227 EXPORT_SYMBOL_NS_GPL(iio_backend_set_sampling_freq, IIO_BACKEND); 228 228 229 + /** 230 + * iio_backend_test_pattern_set - Configure a test pattern 231 + * @back: Backend device 232 + * @chan: Channel number 233 + * @pattern: Test pattern 234 + * 235 + * Configure a test pattern on the backend. This is typically used for 236 + * calibrating the timings on the data digital interface. 237 + * 238 + * RETURNS: 239 + * 0 on success, negative error number on failure. 240 + */ 241 + int iio_backend_test_pattern_set(struct iio_backend *back, 242 + unsigned int chan, 243 + enum iio_backend_test_pattern pattern) 244 + { 245 + if (pattern >= IIO_BACKEND_TEST_PATTERN_MAX) 246 + return -EINVAL; 247 + 248 + return iio_backend_op_call(back, test_pattern_set, chan, pattern); 249 + } 250 + EXPORT_SYMBOL_NS_GPL(iio_backend_test_pattern_set, IIO_BACKEND); 251 + 252 + /** 253 + * iio_backend_chan_status - Get the channel status 254 + * @back: Backend device 255 + * @chan: Channel number 256 + * @error: Error indication 257 + * 258 + * Get the current state of the backend channel. Typically used to check if 259 + * there were any errors sending/receiving data. 260 + * 261 + * RETURNS: 262 + * 0 on success, negative error number on failure. 263 + */ 264 + int iio_backend_chan_status(struct iio_backend *back, unsigned int chan, 265 + bool *error) 266 + { 267 + return iio_backend_op_call(back, chan_status, chan, error); 268 + } 269 + EXPORT_SYMBOL_NS_GPL(iio_backend_chan_status, IIO_BACKEND); 270 + 271 + /** 272 + * iio_backend_iodelay_set - Set digital I/O delay 273 + * @back: Backend device 274 + * @lane: Lane number 275 + * @taps: Number of taps 276 + * 277 + * Controls delays on sending/receiving data. One usecase for this is to 278 + * calibrate the data digital interface so we get the best results when 279 + * transferring data. Note that @taps has no unit since the actual delay per tap 280 + * is very backend specific. Hence, frontend devices typically should go through 281 + * an array of @taps (the size of that array should typically match the size of 282 + * calibration points on the frontend device) and call this API. 283 + * 284 + * RETURNS: 285 + * 0 on success, negative error number on failure. 286 + */ 287 + int iio_backend_iodelay_set(struct iio_backend *back, unsigned int lane, 288 + unsigned int taps) 289 + { 290 + return iio_backend_op_call(back, iodelay_set, lane, taps); 291 + } 292 + EXPORT_SYMBOL_NS_GPL(iio_backend_iodelay_set, IIO_BACKEND); 293 + 294 + /** 295 + * iio_backend_data_sample_trigger - Control when to sample data 296 + * @back: Backend device 297 + * @trigger: Data trigger 298 + * 299 + * Mostly useful for input backends. Configures the backend for when to sample 300 + * data (eg: rising vs falling edge). 301 + * 302 + * RETURNS: 303 + * 0 on success, negative error number on failure. 304 + */ 305 + int iio_backend_data_sample_trigger(struct iio_backend *back, 306 + enum iio_backend_sample_trigger trigger) 307 + { 308 + if (trigger >= IIO_BACKEND_SAMPLE_TRIGGER_MAX) 309 + return -EINVAL; 310 + 311 + return iio_backend_op_call(back, data_sample_trigger, trigger); 312 + } 313 + EXPORT_SYMBOL_NS_GPL(iio_backend_data_sample_trigger, IIO_BACKEND); 314 + 229 315 static void iio_backend_free_buffer(void *arg) 230 316 { 231 317 struct iio_backend_buffer_pair *pair = arg;
+36
include/linux/iio/backend.h
··· 49 49 bool enable; 50 50 }; 51 51 52 + /* vendor specific from 32 */ 53 + enum iio_backend_test_pattern { 54 + IIO_BACKEND_NO_TEST_PATTERN, 55 + /* modified prbs9 */ 56 + IIO_BACKEND_ADI_PRBS_9A = 32, 57 + IIO_BACKEND_TEST_PATTERN_MAX 58 + }; 59 + 60 + enum iio_backend_sample_trigger { 61 + IIO_BACKEND_SAMPLE_TRIGGER_EDGE_FALLING, 62 + IIO_BACKEND_SAMPLE_TRIGGER_EDGE_RISING, 63 + IIO_BACKEND_SAMPLE_TRIGGER_MAX 64 + }; 65 + 52 66 /** 53 67 * struct iio_backend_ops - operations structure for an iio_backend 54 68 * @enable: Enable backend. ··· 72 58 * @data_format_set: Configure the data format for a specific channel. 73 59 * @data_source_set: Configure the data source for a specific channel. 74 60 * @set_sample_rate: Configure the sampling rate for a specific channel. 61 + * @test_pattern_set: Configure a test pattern. 62 + * @chan_status: Get the channel status. 63 + * @iodelay_set: Set digital I/O delay. 64 + * @data_sample_trigger: Control when to sample data. 75 65 * @request_buffer: Request an IIO buffer. 76 66 * @free_buffer: Free an IIO buffer. 77 67 * @extend_chan_spec: Extend an IIO channel. ··· 93 75 enum iio_backend_data_source data); 94 76 int (*set_sample_rate)(struct iio_backend *back, unsigned int chan, 95 77 u64 sample_rate_hz); 78 + int (*test_pattern_set)(struct iio_backend *back, 79 + unsigned int chan, 80 + enum iio_backend_test_pattern pattern); 81 + int (*chan_status)(struct iio_backend *back, unsigned int chan, 82 + bool *error); 83 + int (*iodelay_set)(struct iio_backend *back, unsigned int chan, 84 + unsigned int taps); 85 + int (*data_sample_trigger)(struct iio_backend *back, 86 + enum iio_backend_sample_trigger trigger); 96 87 struct iio_buffer *(*request_buffer)(struct iio_backend *back, 97 88 struct iio_dev *indio_dev); 98 89 void (*free_buffer)(struct iio_backend *back, ··· 124 97 enum iio_backend_data_source data); 125 98 int iio_backend_set_sampling_freq(struct iio_backend *back, unsigned int chan, 126 99 u64 sample_rate_hz); 100 + int iio_backend_test_pattern_set(struct iio_backend *back, 101 + unsigned int chan, 102 + enum iio_backend_test_pattern pattern); 103 + int iio_backend_chan_status(struct iio_backend *back, unsigned int chan, 104 + bool *error); 105 + int iio_backend_iodelay_set(struct iio_backend *back, unsigned int lane, 106 + unsigned int taps); 107 + int iio_backend_data_sample_trigger(struct iio_backend *back, 108 + enum iio_backend_sample_trigger trigger); 127 109 int devm_iio_backend_request_buffer(struct device *dev, 128 110 struct iio_backend *back, 129 111 struct iio_dev *indio_dev);