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

From: Marcelo Schmitt

Date: Wed Nov 18 2026 - 08:03:51 EST


Some ADC front-ends send data over a configurable number of LVDS serial
lanes and may also need to have the data frame calibrated before capture
can start.

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.

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

diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c
index fbf5c39d7655..682d5f735071 100644
--- a/drivers/iio/industrialio-backend.c
+++ b/drivers/iio/industrialio-backend.c
@@ -869,6 +869,29 @@ 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
+ * %IIO_BACKEND_CALIB_SOURCE_DATA_LANE.
+ *
+ * Restrict the error reported through iio_backend_chan_status() to a single
+ * source of the digital interface so that each lane can be calibrated
+ * independently. Backends are expected to report every error source again
+ * once %IIO_BACKEND_CALIB_SOURCE_NONE is selected.
+ *
+ * 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 9c16b695a602..6f28e2d016f7 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.39.2