[PATCH 0/5] iio: core,buffer: re-organize chardev creation
From: Alexandru Ardelean
Date: Fri Apr 10 2020 - 07:56:25 EST
The main intent is to be able to add more chardevs per IIO device, one
for each buffer. To get there, some rework is needed, and one important
facet is to move the creation of the current chardev into
'industrialio-buffer.c', so that control/logic of these chardevs is
localized in that file.
This changeset does that [incrementally] by moving the common chardev
creation from 'industrialio-core.c' to 'industrialio-buffer.c' &
'industrialio-event.c'.
The common chardev is required for both IIO buffers & IIO events.
In order to make this work, the 'iio_device_event_ioctl()' needs to be
passed from 'industrialio-event.c' to 'industrialio-buffer.c' flying past
'industrialio-core.c'. This sounds a bit wrong [at first] but it has the
effect of reducing inter-dependencies between 'industrialio-core.c' to
'industrialio-buffer.c' quite a bit.
The IIO buffer also has a CONFIG_IIO_BUFFER symbol which can turn it
off. No idea how widely this is used [as disabled], but this changeset
also takes that into consideration.
So, now the logic [for __iio_device_register() with regard to chardev
init] is:
1. iio_device_buffers_init() will init buffer and the chardev, if that
works, the 'iio_device_event_ioctl()' will be attached to the chardev
2. if CONFIG_IIO_BUFFER is not defined or 'indio_dev->buffer == NULL'
(no buffter attached), -ENOTSUPP should be returned from
iio_device_buffers_init(), in which case the chardev should be
initialized in 'industrialio-event.c' via
'iio_device_register_event_chrdev()'
One neat side effect of this logic, is that we can also move the buffer
sysfs alloc/cleanup into 'industrialio-buffer.c' under the new
'iio_device_buffers_{un}init()' functions.
Alexandru Ardelean (5):
iio: core: register buffer fileops only if buffer present
iio: buffer: add back-ref from iio_buffer to iio_dev
iio: buffer: move iio buffer chrdev in industrial-buffer.c
iio: buffer: move sysfs alloc/free in industrial-buffer.c
iio: event: move event-only chardev in industrialio-event.c
drivers/iio/iio_core.h | 28 +++----
drivers/iio/industrialio-buffer.c | 130 +++++++++++++++++++++++++-----
drivers/iio/industrialio-core.c | 105 +++---------------------
drivers/iio/industrialio-event.c | 119 ++++++++++++++++++++++++++-
include/linux/iio/buffer_impl.h | 10 +++
include/linux/iio/iio.h | 4 -
6 files changed, 263 insertions(+), 133 deletions(-)
--
2.17.1