Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

iio: industrialio-backend: support backend capabilities

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.

Reviewed-by: Nuno Sá <nuno.sa@analog.com>
Reviewed-by: David Lechner <dlechner@baylibre.com>
Signed-off-by: Tomas Melin <tomas.melin@vaisala.com>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>

authored by

Tomas Melin and committed by
Jonathan Cameron
88440208 6de23f81

+40
+16
drivers/iio/industrialio-backend.c
··· 56 56 void *priv; 57 57 const char *name; 58 58 unsigned int cached_reg_addr; 59 + u32 caps; 59 60 /* 60 61 * This index is relative to the frontend. Meaning that for 61 62 * frontends with multiple backends, this will be the index of this ··· 775 774 } 776 775 EXPORT_SYMBOL_NS_GPL(iio_backend_extend_chan_spec, "IIO_BACKEND"); 777 776 777 + /** 778 + * iio_backend_has_caps - Check if backend has specific capabilities 779 + * @back: Backend device 780 + * @caps: Capabilities to check 781 + * 782 + * RETURNS: 783 + * True if backend has all the requested capabilities, false otherwise. 784 + */ 785 + bool iio_backend_has_caps(struct iio_backend *back, u32 caps) 786 + { 787 + return (back->caps & caps) == caps; 788 + } 789 + EXPORT_SYMBOL_NS_GPL(iio_backend_has_caps, "IIO_BACKEND"); 790 + 778 791 static void iio_backend_release(void *arg) 779 792 { 780 793 struct iio_backend *back = arg; ··· 1129 1114 1130 1115 back->ops = info->ops; 1131 1116 back->name = info->name; 1117 + back->caps = info->caps; 1132 1118 back->owner = dev->driver->owner; 1133 1119 back->dev = dev; 1134 1120 back->priv = priv;
+24
include/linux/iio/backend.h
··· 85 85 }; 86 86 87 87 /** 88 + * enum iio_backend_capabilities - Backend capabilities 89 + * Backend capabilities can be used by frontends to check if a given 90 + * functionality is supported by the backend. This is useful for frontend 91 + * devices which are expected to work with alternative backend 92 + * implementations. Capabilities are loosely coupled with operations, 93 + * meaning that a capability requires certain operations to be implemented 94 + * by the backend. A capability might be mapped to a single operation or 95 + * multiple operations. 96 + * 97 + * @IIO_BACKEND_CAP_CALIBRATION: Backend supports digital interface 98 + * calibration. Calibration procedure is device specific. 99 + * @IIO_BACKEND_CAP_BUFFER: Support for IIO buffer interface. 100 + * @IIO_BACKEND_CAP_ENABLE: Backend can be explicitly enabled/disabled. 101 + */ 102 + enum iio_backend_capabilities { 103 + IIO_BACKEND_CAP_CALIBRATION = BIT(0), 104 + IIO_BACKEND_CAP_BUFFER = BIT(1), 105 + IIO_BACKEND_CAP_ENABLE = BIT(2), 106 + }; 107 + 108 + /** 88 109 * struct iio_backend_ops - operations structure for an iio_backend 89 110 * @enable: Enable backend. 90 111 * @disable: Disable backend. ··· 200 179 * struct iio_backend_info - info structure for an iio_backend 201 180 * @name: Backend name. 202 181 * @ops: Backend operations. 182 + * @caps: Backend capabilities. (bitmask of enum iio_backend_capabilities). 203 183 */ 204 184 struct iio_backend_info { 205 185 const char *name; 206 186 const struct iio_backend_ops *ops; 187 + u32 caps; 207 188 }; 208 189 209 190 int iio_backend_chan_enable(struct iio_backend *back, unsigned int chan); ··· 258 235 long mask); 259 236 int iio_backend_extend_chan_spec(struct iio_backend *back, 260 237 struct iio_chan_spec *chan); 238 + bool iio_backend_has_caps(struct iio_backend *back, u32 caps); 261 239 void *iio_backend_get_priv(const struct iio_backend *conv); 262 240 struct iio_backend *devm_iio_backend_get(struct device *dev, const char *name); 263 241 struct iio_backend *devm_iio_backend_fwnode_get(struct device *dev,