iio: backend: add support for data source get
authorAngelo Dureghello <adureghello@baylibre.com>
Wed, 9 Apr 2025 18:36:30 +0000 (20:36 +0200)
committerJonathan Cameron <Jonathan.Cameron@huawei.com>
Tue, 22 Apr 2025 18:10:03 +0000 (19:10 +0100)
Add backend support for getting the data source used.

The ad3552r HDL implements an internal ramp generator, so adding the
getter to allow data source get/set by debugfs.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Signed-off-by: Angelo Dureghello <adureghello@baylibre.com>
Link: https://patch.msgid.link/20250409-wip-bl-ad3552r-fixes-v5-3-fb429c3a6515@baylibre.com
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
drivers/iio/industrialio-backend.c
include/linux/iio/backend.h

index a43c8d1..c1eb9ef 100644 (file)
@@ -380,6 +380,34 @@ int iio_backend_data_source_set(struct iio_backend *back, unsigned int chan,
 }
 EXPORT_SYMBOL_NS_GPL(iio_backend_data_source_set, "IIO_BACKEND");
 
+/**
+ * iio_backend_data_source_get - Get current data source
+ * @back: Backend device
+ * @chan: Channel number
+ * @data: Pointer to receive the current source value
+ *
+ * A given backend may have different sources to stream/sync data. This allows
+ * to know what source is in use.
+ *
+ * RETURNS:
+ * 0 on success, negative error number on failure.
+ */
+int iio_backend_data_source_get(struct iio_backend *back, unsigned int chan,
+                               enum iio_backend_data_source *data)
+{
+       int ret;
+
+       ret = iio_backend_op_call(back, data_source_get, chan, data);
+       if (ret)
+               return ret;
+
+       if (*data >= IIO_BACKEND_DATA_SOURCE_MAX)
+               return -EINVAL;
+
+       return 0;
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_data_source_get, "IIO_BACKEND");
+
 /**
  * iio_backend_set_sampling_freq - Set channel sampling rate
  * @back: Backend device
index e45b7df..e59d909 100644 (file)
@@ -84,6 +84,7 @@ enum iio_backend_interface_type {
  * @chan_disable: Disable one channel.
  * @data_format_set: Configure the data format for a specific channel.
  * @data_source_set: Configure the data source for a specific channel.
+ * @data_source_get: Data source getter for a specific channel.
  * @set_sample_rate: Configure the sampling rate for a specific channel.
  * @test_pattern_set: Configure a test pattern.
  * @chan_status: Get the channel status.
@@ -115,6 +116,8 @@ struct iio_backend_ops {
                               const struct iio_backend_data_fmt *data);
        int (*data_source_set)(struct iio_backend *back, unsigned int chan,
                               enum iio_backend_data_source data);
+       int (*data_source_get)(struct iio_backend *back, unsigned int chan,
+                              enum iio_backend_data_source *data);
        int (*set_sample_rate)(struct iio_backend *back, unsigned int chan,
                               u64 sample_rate_hz);
        int (*test_pattern_set)(struct iio_backend *back,
@@ -176,6 +179,8 @@ int iio_backend_data_format_set(struct iio_backend *back, unsigned int chan,
                                const struct iio_backend_data_fmt *data);
 int iio_backend_data_source_set(struct iio_backend *back, unsigned int chan,
                                enum iio_backend_data_source data);
+int iio_backend_data_source_get(struct iio_backend *back, unsigned int chan,
+                               enum iio_backend_data_source *data);
 int iio_backend_set_sampling_freq(struct iio_backend *back, unsigned int chan,
                                  u64 sample_rate_hz);
 int iio_backend_test_pattern_set(struct iio_backend *back,