[PATCH v2 1/5] iio: backend: Add calibration source interface

From: Marcelo Schmitt

Date: Fri Nov 27 2026 - 16:52:38 EST


Some ADC front-ends group and send data from a single channel over a
configurable number of LVDS serial lanes and may also need to perform a
data frame calibration before capture can start. During a channel interface
calibration, the front-end device driver usually requests the channel
status multiple times to find out the optimal calibration point.

However, the backend channel status interface doesn't provide which
specific serial lane or data frame flagged errors when they occur. The lack
of error source information prevents proper calibration of channels
comprised of multiple serial lanes.

Instead, the backend may have a separate error source mask configuration to
restrict which digital interface source will have its errors reported
through iio_backend_chan_status(). With that, each serial lane can be
calibrated independently, enabling multiple lane LVDS channels to be
properly calibrated and supported.

Add a backend operation for selecting the calibration source (data lane or
data frame) so that device drivers can perform the calibration of both the
data frame and data lanes. Backends are expected to report every error
source when IIO_BACKEND_CALIB_SOURCE_NONE is selected.

Signed-off-by: Marcelo Schmitt <marcelo.schmitt@xxxxxxxxxx>
---
drivers/iio/industrialio-backend.c | 28 ++++++++++++++++++++++++++++
include/linux/iio/backend.h | 22 ++++++++++++++++++++++
2 files changed, 50 insertions(+)

diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c
index 7cc227818618..aaf11cceb145 100644
--- a/drivers/iio/industrialio-backend.c
+++ b/drivers/iio/industrialio-backend.c
@@ -869,6 +869,34 @@ int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout_us)
}
EXPORT_SYMBOL_NS_GPL(iio_backend_interface_data_align, "IIO_BACKEND");

+/**
+ * iio_backend_calibration_source_set - Select the monitored error source.
+ * @back: Backend device
+ * @source: Error source to monitor.
+ * @lane: Data lane to monitor. Only meaningful for when
+ * @source == IIO_BACKEND_CALIB_SOURCE_DATA_LANE.
+ *
+ * Some ADC front-ends group and send data from a single channel over a
+ * configurable number of LVDS serial lanes and may also need to perform a data
+ * frame calibration before capture can start. However, the backend channel
+ * status interface doesn't provide which specific serial lane or data frame has
+ * flagged errors when they occur. Instead, the backend may have an error mask
+ * setting to restrict which digital interface source may have errors reported
+ * through iio_backend_chan_status(). This is useful for channels that are made
+ * out of multiple physical data lanes so that each data lane can be calibrated
+ * individually.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_calibration_source_set(struct iio_backend *back,
+ enum iio_backend_calib_source source,
+ unsigned int lane)
+{
+ return iio_backend_op_call(back, calibration_source_set, source, lane);
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_calibration_source_set, "IIO_BACKEND");
+
/**
* iio_backend_num_lanes_set - Number of lanes enabled.
* @back: Backend device
diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h
index 93d5f2073cc3..5a59bc1025da 100644
--- a/include/linux/iio/backend.h
+++ b/include/linux/iio/backend.h
@@ -76,6 +76,20 @@ enum iio_backend_interface_type {
IIO_BACKEND_INTERFACE_MAX
};

+/**
+ * enum iio_backend_calib_source - Digital interface error source
+ * @IIO_BACKEND_CALIB_SOURCE_NONE: Report every error source.
+ * @IIO_BACKEND_CALIB_SOURCE_DATA_LANE: Report errors of a single data lane.
+ * @IIO_BACKEND_CALIB_SOURCE_FRAME: Report errors of the frame signal.
+ * @IIO_BACKEND_CALIB_SOURCE_MAX: Number of error sources.
+ */
+enum iio_backend_calib_source {
+ IIO_BACKEND_CALIB_SOURCE_NONE,
+ IIO_BACKEND_CALIB_SOURCE_DATA_LANE,
+ IIO_BACKEND_CALIB_SOURCE_FRAME,
+ IIO_BACKEND_CALIB_SOURCE_MAX
+};
+
enum iio_backend_filter_type {
IIO_BACKEND_FILTER_TYPE_DISABLED,
IIO_BACKEND_FILTER_TYPE_SINC1,
@@ -132,6 +146,8 @@ enum iio_backend_capabilities {
* @debugfs_reg_access: Read or write register value of backend.
* @filter_type_set: Set filter type.
* @interface_data_align: Perform the data alignment process.
+ * @calibration_source_set: Select the error source monitored during
+ * interface calibration.
* @num_lanes_set: Set the number of lanes enabled.
* @crc_enable: Enable direction-specific CRC handling.
* @crc_disable: Disable direction-specific CRC handling.
@@ -190,6 +206,9 @@ struct iio_backend_ops {
int (*filter_type_set)(struct iio_backend *back,
enum iio_backend_filter_type type);
int (*interface_data_align)(struct iio_backend *back, u32 timeout_us);
+ int (*calibration_source_set)(struct iio_backend *back,
+ enum iio_backend_calib_source source,
+ unsigned int lane);
int (*num_lanes_set)(struct iio_backend *back, unsigned int num_lanes);
int (*crc_enable)(struct iio_backend *back);
int (*crc_disable)(struct iio_backend *back);
@@ -240,6 +259,9 @@ int devm_iio_backend_request_buffer(struct device *dev,
int iio_backend_filter_type_set(struct iio_backend *back,
enum iio_backend_filter_type type);
int iio_backend_interface_data_align(struct iio_backend *back, u32 timeout_us);
+int iio_backend_calibration_source_set(struct iio_backend *back,
+ enum iio_backend_calib_source source,
+ unsigned int lane);
int iio_backend_num_lanes_set(struct iio_backend *back, unsigned int num_lanes);
int iio_backend_crc_enable(struct iio_backend *back);
int iio_backend_crc_disable(struct iio_backend *back);
--
2.53.0