Re: [PATCH v3 2/4] iio: industrialio-backend: support backend capabilities
From: Tomas Melin
Date: Thu Jan 15 2026 - 02:49:21 EST
Hi,
On 14/01/2026 14:28, Jonathan Cameron wrote:
> On Wed, 14 Jan 2026 10:45:51 +0000
> Tomas Melin <tomas.melin@xxxxxxxxxxx> 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@xxxxxxxxxxx>
> Hi Tomas,
>
> One thing inline.
>
> Thanks
>
> Jonathan
>
>
>> ---
>> drivers/iio/industrialio-backend.c | 17 +++++++++++++++++
>> include/linux/iio/backend.h | 17 +++++++++++++++++
>> 2 files changed, 34 insertions(+)
>>
>> diff --git a/drivers/iio/industrialio-backend.c b/drivers/iio/industrialio-backend.c
>> index 447b694d6d5f72dc6f018b1697fdb88e555bd61e..0a98fdd5df9db6cc233af819ac5243ba8cd5266f 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,21 @@ 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:
>> + * Non-zero value if backend has all the requested capabilities,
>
> It doesn't... back->caps = 0x1, caps = 0x3 returns 0x1 which
> is non-zero. I'd do
> return (back->caps & caps) == caps;
>
> Though that also rather strongly indicates this would be better returning
> a bool.
Thanks for pointing this out, will fix and change to boolean return value.
Thanks,
Tomas
>
>
>> + * 0 otherwise.
>> + */
>> +int iio_backend_has_caps(struct iio_backend *back, u32 caps)
>> +{
>> + return back->caps & caps;
>> +}
>> +EXPORT_SYMBOL_NS_GPL(iio_backend_has_caps, "IIO_BACKEND");
>
>
>