Not all backends support the full set of capabilities provided by the
industrialio-backend framework. Capability bits can be used in frontends
and backends for checking for a certain feature set, or if using
related functions can be expected to fail.
Capability bits should be set by a compatible backend and provided when
registering the backend.
Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
---
drivers/iio/industrialio-backend.c | 16 ++++++++++++++++
include/linux/iio/backend.h | 25 +++++++++++++++++++++++++
2 files changed, 41 insertions(+)
diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c
index 447b694d6d5f72dc6f018b1697fdb88e555bd61e..1afd00763da9e1f07160990fe3f729cbb7295d7f 100644
--- a/drivers/iio/industrialio-backend.c
+++ b/drivers/iio/industrialio-backend.c
@@ -56,6 +56,7 @@ struct iio_backend {
void *priv;
const char *name;
unsigned int cached_reg_addr;
+ u32 caps;
/*
* This index is relative to the frontend. Meaning that for
* frontends with multiple backends, this will be the index of this
@@ -774,6 +775,20 @@ int iio_backend_extend_chan_spec(struct iio_backend *back,
}
EXPORT_SYMBOL_NS_GPL(iio_backend_extend_chan_spec, "IIO_BACKEND");
+/**
+ * iio_backend_has_caps - Check if backend has specific capabilities
+ * @back: Backend device
+ * @caps: Capabilities to check
+ *
+ * RETURNS:
+ * True if backend has all the requested capabilities, false otherwise.
+ */
+bool iio_backend_has_caps(struct iio_backend *back, u32 caps)
+{
+ return (back->caps & caps) == caps;
+}
+EXPORT_SYMBOL_NS_GPL(iio_backend_has_caps, "IIO_BACKEND");
+
static void iio_backend_release(void *arg)
{
struct iio_backend *back = arg;
@@ -1114,6 +1129,7 @@ int devm_iio_backend_register(struct device *dev,
back->ops = info->ops;
back->name = info->name;
+ back->caps = info->caps;
back->owner = dev->driver->owner;
back->dev = dev;
back->priv = priv;
diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h
index 7f815f3fed6ae34c65ffc579d5101020fc9bd336..ac80abb71bbca88c3f6313d8d67b9c7ace076ceb 100644
--- a/include/linux/iio/backend.h
+++ b/include/linux/iio/backend.h
@@ -84,6 +84,28 @@ enum iio_backend_filter_type {
IIO_BACKEND_FILTER_TYPE_MAX
};
+/**
+ * enum iio_backend_capabilities - Backend capabilities
+ * Backend capabilities can be used by frontends to check if a given
+ * functionality is supported by the backend. This is useful for frontend
+ * devices which are expected to work with alternative backend
+ * implementations. Capabilities are loosely coupled with operations,
+ * meaning that a capability requires certain operations to be implemented
+ * by the backend. A capability might be mapped to a single operation or
+ * multiple operations.
+ *
+ * @IIO_BACKEND_CAP_CALIBRATION: Backend supports digital interface
+ * calibration. Calibration procedure is device specific.
+ * @IIO_BACKEND_CAP_BUFFERING: Backend supports buffering.
+ * @IIO_BACKEND_CAP_ALWAYS_ON: Backend does not need to be explicitly
+ * enabled/disabled. It is always on.
+ */
+enum iio_backend_capabilities {
+ IIO_BACKEND_CAP_CALIBRATION = BIT(0),
+ IIO_BACKEND_CAP_BUFFERING = BIT(1),
+ IIO_BACKEND_CAP_ALWAYS_ON = BIT(2),
+};
+
/**
* struct iio_backend_ops - operations structure for an iio_backend
* @enable: Enable backend.
@@ -179,10 +201,12 @@ struct iio_backend_ops {
* struct iio_backend_info - info structure for an iio_backend
* @name: Backend name.
* @ops: Backend operations.
+ * @caps: Backend capabilities. @see iio_backend_capabilities
*/
struct iio_backend_info {
const char *name;
const struct iio_backend_ops *ops;
+ u32 caps;
};
int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan);
@@ -235,6 +259,7 @@ int iio_backend_read_raw(struct iio_backend *back,
long mask);
int iio_backend_extend_chan_spec(struct iio_backend *back,
struct iio_chan_spec *chan);
+bool iio_backend_has_caps(struct iio_backend *back, u32 caps);
void *iio_backend_get_priv(const struct iio_backend *conv);
struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name);
struct iio_backend *devm_iio_backend_fwnode_get(struct device *dev,
--
2.47.3
On Wed, 21 Jan 2026 12:08:30 +0000
Tomas Melin <tomas.melin@vaisala.com> wrote:
> Not all backends support the full set of capabilities provided by the
> industrialio-backend framework. Capability bits can be used in frontends
> and backends for checking for a certain feature set, or if using
> related functions can be expected to fail.
>
> Capability bits should be set by a compatible backend and provided when
> registering the backend.
>
> Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
One question on the 'sense' of the cap that controls whether it's
always on. It's the sort of question that I'm not sure has a perfect answer.
> diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h
> index 7f815f3fed6ae34c65ffc579d5101020fc9bd336..ac80abb71bbca88c3f6313d8d67b9c7ace076ceb 100644
> --- a/include/linux/iio/backend.h
> +++ b/include/linux/iio/backend.h
> @@ -84,6 +84,28 @@ enum iio_backend_filter_type {
> IIO_BACKEND_FILTER_TYPE_MAX
> };
>
> +/**
> + * enum iio_backend_capabilities - Backend capabilities
> + * Backend capabilities can be used by frontends to check if a given
> + * functionality is supported by the backend. This is useful for frontend
> + * devices which are expected to work with alternative backend
> + * implementations. Capabilities are loosely coupled with operations,
> + * meaning that a capability requires certain operations to be implemented
> + * by the backend. A capability might be mapped to a single operation or
> + * multiple operations.
> + *
> + * @IIO_BACKEND_CAP_CALIBRATION: Backend supports digital interface
> + * calibration. Calibration procedure is device specific.
> + * @IIO_BACKEND_CAP_BUFFERING: Backend supports buffering.
> + * @IIO_BACKEND_CAP_ALWAYS_ON: Backend does not need to be explicitly
> + * enabled/disabled. It is always on.
I'd like opinions on this one. To me it sound backwards though I can
see why you'd go this way.
Either the backend is capable of being enabled / disabled
in which case we have to further assume at boot it is disabled
(which is the dodgy bit!)
Or the backend is always on. To me that's not a capability,
it's a limitation.
My slight preference is for a capability meaning we 'can'
do something so the 1st option.
> + */
> +enum iio_backend_capabilities {
> + IIO_BACKEND_CAP_CALIBRATION = BIT(0),
> + IIO_BACKEND_CAP_BUFFERING = BIT(1),
> + IIO_BACKEND_CAP_ALWAYS_ON = BIT(2),
> +};
> +
> /**
> * struct iio_backend_ops - operations structure for an iio_backend
> * @enable: Enable backend.
> @@ -179,10 +201,12 @@ struct iio_backend_ops {
> * struct iio_backend_info - info structure for an iio_backend
> * @name: Backend name.
> * @ops: Backend operations.
> + * @caps: Backend capabilities. @see iio_backend_capabilities
> */
> struct iio_backend_info {
> const char *name;
> const struct iio_backend_ops *ops;
> + u32 caps;
> };
>
> int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan);
> @@ -235,6 +259,7 @@ int iio_backend_read_raw(struct iio_backend *back,
> long mask);
> int iio_backend_extend_chan_spec(struct iio_backend *back,
> struct iio_chan_spec *chan);
> +bool iio_backend_has_caps(struct iio_backend *back, u32 caps);
> void *iio_backend_get_priv(const struct iio_backend *conv);
> struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name);
> struct iio_backend *devm_iio_backend_fwnode_get(struct device *dev,
>
Hi,
On 22/01/2026 22:43, Jonathan Cameron wrote:
> On Wed, 21 Jan 2026 12:08:30 +0000
> Tomas Melin <tomas.melin@vaisala.com> wrote:
>
>> Not all backends support the full set of capabilities provided by the
>> industrialio-backend framework. Capability bits can be used in frontends
>> and backends for checking for a certain feature set, or if using
>> related functions can be expected to fail.
>>
>> Capability bits should be set by a compatible backend and provided when
>> registering the backend.
>>
>> Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
>
> One question on the 'sense' of the cap that controls whether it's
> always on. It's the sort of question that I'm not sure has a perfect answer.
Agreed, it is not as clear as the other bits. I'll give my reasoning below.
>
>
>> diff --git a/include/linux/iio/backend.h b/include/linux/iio/backend.h
>> index 7f815f3fed6ae34c65ffc579d5101020fc9bd336..ac80abb71bbca88c3f6313d8d67b9c7ace076ceb 100644
>> --- a/include/linux/iio/backend.h
>> +++ b/include/linux/iio/backend.h
>> @@ -84,6 +84,28 @@ enum iio_backend_filter_type {
>> IIO_BACKEND_FILTER_TYPE_MAX
>> };
>>
>> +/**
>> + * enum iio_backend_capabilities - Backend capabilities
>> + * Backend capabilities can be used by frontends to check if a given
>> + * functionality is supported by the backend. This is useful for frontend
>> + * devices which are expected to work with alternative backend
>> + * implementations. Capabilities are loosely coupled with operations,
>> + * meaning that a capability requires certain operations to be implemented
>> + * by the backend. A capability might be mapped to a single operation or
>> + * multiple operations.
>> + *
>> + * @IIO_BACKEND_CAP_CALIBRATION: Backend supports digital interface
>> + * calibration. Calibration procedure is device specific.
>> + * @IIO_BACKEND_CAP_BUFFERING: Backend supports buffering.
>> + * @IIO_BACKEND_CAP_ALWAYS_ON: Backend does not need to be explicitly
>> + * enabled/disabled. It is always on.
> I'd like opinions on this one. To me it sound backwards though I can
> see why you'd go this way.
> Either the backend is capable of being enabled / disabled
> in which case we have to further assume at boot it is disabled
> (which is the dodgy bit!)
>
> Or the backend is always on. To me that's not a capability,
> it's a limitation.
I pondered about this too, but ended up having the bit this way around.
The logic being that backend is capable of working even if not
explicitly enabled/disabled. So looking at it from that perspective it
would be a capability. And assumption being that typically the
enabling/disabling is required, checking if the capability to omit
enabling seemed logical to me.
Thanks,
Tomas
>
> My slight preference is for a capability meaning we 'can'
> do something so the 1st option.
>
>> + */
>> +enum iio_backend_capabilities {
>> + IIO_BACKEND_CAP_CALIBRATION = BIT(0),
>> + IIO_BACKEND_CAP_BUFFERING = BIT(1),
>> + IIO_BACKEND_CAP_ALWAYS_ON = BIT(2),
>> +};
>> +
>> /**
>> * struct iio_backend_ops - operations structure for an iio_backend
>> * @enable: Enable backend.
>> @@ -179,10 +201,12 @@ struct iio_backend_ops {
>> * struct iio_backend_info - info structure for an iio_backend
>> * @name: Backend name.
>> * @ops: Backend operations.
>> + * @caps: Backend capabilities. @see iio_backend_capabilities
>> */
>> struct iio_backend_info {
>> const char *name;
>> const struct iio_backend_ops *ops;
>> + u32 caps;
>> };
>>
>> int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan);
>> @@ -235,6 +259,7 @@ int iio_backend_read_raw(struct iio_backend *back,
>> long mask);
>> int iio_backend_extend_chan_spec(struct iio_backend *back,
>> struct iio_chan_spec *chan);
>> +bool iio_backend_has_caps(struct iio_backend *back, u32 caps);
>> void *iio_backend_get_priv(const struct iio_backend *conv);
>> struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name);
>> struct iio_backend *devm_iio_backend_fwnode_get(struct device *dev,
>>
>
© 2016 - 2026 Red Hat, Inc.