@@ -8,6 +8,8 @@ industrialio-y := industrialio-core.o industrialio-event.o inkern.o
industrialio-$(CONFIG_IIO_BUFFER) += industrialio-buffer.o
industrialio-$(CONFIG_IIO_TRIGGER) += industrialio-trigger.o
+industrialio-$(CONFIG_IIO_BACKEND) += industrialio-backend.o
+
obj-$(CONFIG_IIO_CONFIGFS) += industrialio-configfs.o
obj-$(CONFIG_IIO_GTS_HELPER) += industrialio-gts-helper.o
obj-$(CONFIG_IIO_SW_DEVICE) += industrialio-sw-device.o
new file mode 100644
@@ -0,0 +1,59 @@
+// SPDX-License-Identifier: GPL-2.0
+/* The industrial I/O core, backend handling functions
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/device.h>
+#include <linux/list.h>
+#include <linux/iio/backend.h>
+
+struct iio_backend *iio_backend_alloc(struct device *parent)
+{
+ struct iio_backend *backend;
+
+ /*
+ * Allocate backend struct
+ * Init backend device & struct
+ */
+
+ return backend;
+};
+EXPORT_SYMBOL(iio_backend_alloc);
+
+int iio_backend_register(struct iio_backend *backend)
+{
+ /*
+ * Add device to device hierarchy
+ * (Call device_add())
+ */
+
+ return 0;
+};
+EXPORT_SYMBOL(iio_backend_register);
+
+void iio_backend_unregister(struct iio_backend *backend)
+{
+ /*
+ * Free backend struct and delete device
+ * (Call device_del())
+ */
+};
+EXPORT_SYMBOL(iio_backend_unregister);
+
+struct iio_backend *iio_backend_get(struct device *dev)
+{
+ struct iio_backend *backend;
+
+ /*
+ * Get backend in from device node
+ * (call fwnode_property_get_reference_args() with io-backends prop)
+ * Allocate backend
+ * Find backend device from phandle
+ * (call bus_find_device_by_fwnode())
+ * Return backend
+ */
+
+ return backend;
+};
+EXPORT_SYMBOL(iio_backend_get);
new file mode 100644
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * The industrial I/O core, backend handling functions
+ *
+ * Author: Olivier Moysan <olivier.moysan@foss.st.com>.
+ */
+
+struct iio_backend_ops;
+
+struct iio_backend {
+ const struct iio_backend_ops *ops;
+ struct module *owner;
+ int id;
+ const char *name;
+ struct device dev;
+ struct list_head list;
+ void *priv;
+};
+
+struct iio_backend_ops {
+ int (*enable)(struct iio_backend *backend);
+ int (*disable)(struct iio_backend *backend);
+ int (*read_raw)(struct iio_backend *backend, int *val, int *val2, long mask);
+};
+
+struct iio_backend *iio_backend_alloc(struct device *parent);
+int iio_backend_register(struct iio_backend *backend);
+void iio_backend_unregister(struct iio_backend *backend);
+struct iio_backend *iio_backend_get(struct device *dev);
Add a new device type in IIO framework. This backend device does not compute channel attributes and does not expose them through sysfs, as done typically in iio-rescale frontend device. Instead, it allows to report information applying to channel attributes through callbacks. These backend devices can be cascaded to represent chained components. An IIO device configured as a consumer of a backend device can compute the channel attributes of the whole chain. Signed-off-by: Olivier Moysan <olivier.moysan@foss.st.com> --- drivers/iio/Makefile | 2 + drivers/iio/industrialio-backend.c | 59 ++++++++++++++++++++++++++++++ include/linux/iio/backend.h | 29 +++++++++++++++ 3 files changed, 90 insertions(+) create mode 100644 drivers/iio/industrialio-backend.c create mode 100644 include/linux/iio/backend.h