From: "Nuno Sá" <noname.nuno@gmail.com>
To: "David Lechner" <dlechner@baylibre.com>,
"Mark Brown" <broonie@kernel.org>,
"Jonathan Cameron" <jic23@kernel.org>,
"Rob Herring" <robh+dt@kernel.org>,
"Krzysztof Kozlowski" <krzysztof.kozlowski+dt@linaro.org>,
"Conor Dooley" <conor+dt@kernel.org>,
"Michael Hennerich" <michael.hennerich@analog.com>,
"Nuno Sá" <nuno.sa@analog.com>,
"Frank Rowand" <frowand.list@gmail.com>
Cc: "Thierry Reding" <thierry.reding@gmail.com>,
"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
"Jonathan Corbet" <corbet@lwn.net>,
linux-spi@vger.kernel.org, linux-iio@vger.kernel.org,
devicetree@vger.kernel.org, linux-doc@vger.kernel.org,
linux-pwm@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH 08/13] iio: buffer: add new hardware triggered buffer driver
Date: Thu, 11 Jan 2024 10:24:54 +0100 [thread overview]
Message-ID: <bd64938e170f967803f244d401c641d1679d0aee.camel@gmail.com> (raw)
In-Reply-To: <20240109-axi-spi-engine-series-3-v1-8-e42c6a986580@baylibre.com>
On Wed, 2024-01-10 at 13:49 -0600, David Lechner wrote:
> This adds a new hardware triggered buffer driver for the IIO subsystem.
> This driver is intended to be used by IIO device drivers that have
> a hardware buffer that is triggered by a hardware signal.
>
> It is expected that components such as those providing a backend via the
> IIO backend framework will provide the actual implementation of this
> functionality by registering a matching device on the auxiliary bus.
> The auxiliary bus was chosen since it allows us to make use of existing
> kernel infrastructure instead of implementing our own registration and
> lookup system.
>
> Signed-off-by: David Lechner <dlechner@baylibre.com>
> ---
> Documentation/driver-api/driver-model/devres.rst | 1 +
> drivers/iio/buffer/Kconfig | 7 ++
> drivers/iio/buffer/Makefile | 1 +
> .../iio/buffer/industrialio-hw-triggered-buffer.c | 104
> +++++++++++++++++++++
> include/linux/iio/hw_triggered_buffer.h | 14 +++
> include/linux/iio/hw_triggered_buffer_impl.h | 16 ++++
> 6 files changed, 143 insertions(+)
>
> diff --git a/Documentation/driver-api/driver-model/devres.rst
> b/Documentation/driver-api/driver-model/devres.rst
> index c5f99d834ec5..b23d4a2b68a6 100644
> --- a/Documentation/driver-api/driver-model/devres.rst
> +++ b/Documentation/driver-api/driver-model/devres.rst
> @@ -296,6 +296,7 @@ IIO
> devm_iio_channel_get()
> devm_iio_channel_get_all()
> devm_iio_hw_consumer_alloc()
> + devm_iio_hw_triggered_buffer_setup()
> devm_fwnode_iio_channel_get_by_name()
>
> INPUT
> diff --git a/drivers/iio/buffer/Kconfig b/drivers/iio/buffer/Kconfig
> index 047b931591a9..925c5bf074bc 100644
> --- a/drivers/iio/buffer/Kconfig
> +++ b/drivers/iio/buffer/Kconfig
> @@ -53,3 +53,10 @@ config IIO_TRIGGERED_BUFFER
> select IIO_KFIFO_BUF
> help
> Provides helper functions for setting up triggered buffers.
> +
> +config IIO_HW_TRIGGERED_BUFFER
> + tristate "Industrial I/O hardware triggered buffer support"
> + select AUXILIARY_BUS
> + select IIO_TRIGGER
> + help
> + Provides helper functions for setting up hardware triggered
> buffers.
> diff --git a/drivers/iio/buffer/Makefile b/drivers/iio/buffer/Makefile
> index 1403eb2f9409..d1142bb20f61 100644
> --- a/drivers/iio/buffer/Makefile
> +++ b/drivers/iio/buffer/Makefile
> @@ -9,4 +9,5 @@ obj-$(CONFIG_IIO_BUFFER_DMA) += industrialio-buffer-dma.o
> obj-$(CONFIG_IIO_BUFFER_DMAENGINE) += industrialio-buffer-dmaengine.o
> obj-$(CONFIG_IIO_BUFFER_HW_CONSUMER) += industrialio-hw-consumer.o
> obj-$(CONFIG_IIO_TRIGGERED_BUFFER) += industrialio-triggered-buffer.o
> +obj-$(CONFIG_IIO_HW_TRIGGERED_BUFFER) += industrialio-hw-triggered-buffer.o
> obj-$(CONFIG_IIO_KFIFO_BUF) += kfifo_buf.o
> diff --git a/drivers/iio/buffer/industrialio-hw-triggered-buffer.c
> b/drivers/iio/buffer/industrialio-hw-triggered-buffer.c
> new file mode 100644
> index 000000000000..7a8a71066b0e
> --- /dev/null
> +++ b/drivers/iio/buffer/industrialio-hw-triggered-buffer.c
> @@ -0,0 +1,104 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2024 Analog Devices, Inc.
> + * Copyright (c) 2024 BayLibre, SAS
> + */
> +
> +#include <linux/auxiliary_bus.h>
> +#include <linux/container_of.h>
> +#include <linux/export.h>
> +#include <linux/module.h>
> +#include <linux/iio/hw_triggered_buffer_impl.h>
> +#include <linux/iio/iio.h>
> +#include <linux/iio/buffer.h>
> +#include <linux/iio/trigger.h>
> +
> +static int iio_hw_triggered_buffer_match(struct device *dev, const void
> *match)
> +{
> + return dev->parent == match;
> +}
> +
> +static struct iio_hw_triggered_buffer_device
> +*iio_hw_trigger_buffer_get(struct device *match)
> +{
> + struct auxiliary_device *adev;
> +
> + adev = auxiliary_find_device(NULL, match,
> iio_hw_triggered_buffer_match);
> + if (!adev)
> + return ERR_PTR(-ENOENT);
> +
> + return container_of(adev, struct iio_hw_triggered_buffer_device,
> adev);
> +}
> +
> +static void iio_hw_trigger_buffer_put(void *dev)
> +{
> + put_device(dev);
> +}
> +
> +/**
> + * devm_iio_hw_triggered_buffer_setup - Setup a hardware triggered buffer
> + * @dev: Device for devm management
> + * @indio_dev: An unconfigured/partially configured IIO device struct
> + * @match: Device for matching the auxiliary bus device that provides
> the
> + * interface to the hardware triggered buffer
> + * @ops: Buffer setup functions to use for this IIO device
> + *
> + * Return: 0 on success, negative error code on failure.
> + *
> + * This function will search all registered hardware triggered buffers for
> one
> + * that matches the given indio_dev. If found, it will be used to setup both
> + * the trigger and the buffer on the indio_dev.
> + */
> +int devm_iio_hw_triggered_buffer_setup(struct device *dev,
> + struct iio_dev *indio_dev,
> + struct device *match,
> + const struct iio_buffer_setup_ops
> *ops)
> +{
> + struct iio_hw_triggered_buffer_device *hw;
> + int ret;
> +
> + hw = iio_hw_trigger_buffer_get(match);
> + if (IS_ERR(hw))
> + return PTR_ERR(hw);
> +
> + ret = devm_add_action_or_reset(dev, iio_hw_trigger_buffer_put, &hw-
> >adev.dev);
> + if (ret)
> + return ret;
> +
> + indio_dev->modes |= INDIO_HW_BUFFER_TRIGGERED;
> + indio_dev->trig = iio_trigger_get(hw->trig);
> + indio_dev->setup_ops = ops;
> +
> + return iio_device_attach_buffer(indio_dev, hw->buffer);
> +}
> +EXPORT_SYMBOL_GPL(devm_iio_hw_triggered_buffer_setup);
> +
> +static int iio_hw_trigger_buffer_probe(struct auxiliary_device *adev,
> + const struct auxiliary_device_id *id)
> +{
> + struct iio_hw_triggered_buffer_device *hw =
> + container_of(adev, struct iio_hw_triggered_buffer_device,
> adev);
> +
> + if (!hw->buffer || !hw->trig)
> + return -EINVAL;
> +
> + return 0;
> +}
> +
> +static const struct auxiliary_device_id iio_hw_trigger_buffer_id_table[] = {
> + { }
> +};
> +MODULE_DEVICE_TABLE(auxiliary, iio_hw_trigger_buffer_id_table);
> +
> +static struct auxiliary_driver iio_hw_trigger_buffer_driver = {
> + .driver = {
> + .name = "iio-hw-triggered-buffer",
> + },
> + .probe = iio_hw_trigger_buffer_probe,
> + .id_table = iio_hw_trigger_buffer_id_table,
> +};
> +module_auxiliary_driver(iio_hw_trigger_buffer_driver);
This is one more example why I think the whole thing is overly complicated. If
I'm understanding things right, we have the spi controller creating platform
devices that will be probed by the new IIO offload driver that then creates an
auxiliary device that is probed by this driver. Even by looking at the probe
function, it already feels to me that something is architecturally wrong (as we
are essentially doing error handling in there).
One idea that just occurred to me now is to perhaps extend the IIO inkernel
interface so that we can split the logic a bit and have IIO devices consuming or
taking ownership of buffers created by other devices. Hmm, maybe not that good
of an idea :(
- Nuno Sá
next prev parent reply other threads:[~2024-01-11 9:21 UTC|newest]
Thread overview: 51+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-10 19:49 [PATCH 00/13] spi: axi-spi-engine: add offload support David Lechner
2024-01-10 19:49 ` [PATCH 01/13] spi: add core support for controllers with offload capabilities David Lechner
2024-01-10 21:36 ` Mark Brown
2024-01-11 20:54 ` David Lechner
2024-01-11 21:32 ` David Lechner
2024-01-11 21:49 ` Mark Brown
2024-01-12 9:03 ` David Jander
2024-01-12 20:09 ` David Lechner
2024-03-04 23:21 ` David Lechner
2024-03-05 18:50 ` Mark Brown
2024-03-09 17:54 ` Jonathan Cameron
2024-01-11 8:49 ` Nuno Sá
2024-01-11 13:33 ` Mark Brown
2024-01-11 14:11 ` Nuno Sá
2024-01-11 15:41 ` Mark Brown
2024-01-12 7:26 ` Nuno Sá
2024-01-10 19:49 ` [PATCH 02/13] scripts: dtc: checks: don't warn on SPI non-peripheral child nodes David Lechner
2024-01-11 22:03 ` Rob Herring
2024-01-10 19:49 ` [PATCH 03/13] spi: do not attempt to register DT nodes without @ in name David Lechner
2024-01-10 21:37 ` Mark Brown
2024-01-10 19:49 ` [PATCH 04/13] spi: dt-bindings: adi,axi-spi-engine: add offload bindings David Lechner
2024-01-10 23:14 ` Rob Herring
2024-01-11 0:06 ` David Lechner
2024-01-11 9:14 ` Nuno Sá
2024-01-11 9:07 ` Nuno Sá
2024-01-10 19:49 ` [PATCH 05/13] spi: axi-spi-engine: add SPI offload support David Lechner
2024-01-10 21:39 ` Mark Brown
2024-01-10 22:31 ` David Lechner
2024-01-11 13:00 ` Mark Brown
2024-01-11 17:57 ` David Lechner
2024-01-10 19:49 ` [PATCH 06/13] iio: buffer: add hardware triggered buffer support David Lechner
2024-01-12 12:37 ` Jonathan Cameron
2024-01-12 15:42 ` David Lechner
2024-01-12 16:50 ` Nuno Sá
2024-01-10 19:49 ` [PATCH 07/13] iio: buffer: dmaengine: add INDIO_HW_BUFFER_TRIGGERED flag David Lechner
2024-01-10 19:49 ` [PATCH 08/13] iio: buffer: add new hardware triggered buffer driver David Lechner
2024-01-11 9:24 ` Nuno Sá [this message]
2024-01-10 19:49 ` [PATCH 09/13] bus: auxiliary: increase AUXILIARY_NAME_SIZE David Lechner
2024-01-10 19:49 ` [PATCH 10/13] iio: buffer: dmaengine: export devm_iio_dmaengine_buffer_alloc() David Lechner
2024-01-12 12:37 ` Jonathan Cameron
2024-01-12 14:55 ` David Lechner
2024-01-10 19:49 ` [PATCH 11/13] dt-bindings: iio: offload: add binding for PWM/DMA triggered buffer David Lechner
2024-01-10 21:25 ` Rob Herring
2024-01-10 22:56 ` Rob Herring
2024-01-10 19:49 ` [PATCH 12/13] iio: offload: add new PWM triggered DMA buffer driver David Lechner
2024-01-11 9:31 ` Nuno Sá
2024-01-11 14:59 ` Nuno Sá
2024-01-12 12:51 ` Jonathan Cameron
2024-01-12 13:19 ` Nuno Sá
2024-01-12 12:45 ` Jonathan Cameron
2024-01-10 19:49 ` [PATCH 13/13] iio: adc: ad7380: add SPI offload support David Lechner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=bd64938e170f967803f244d401c641d1679d0aee.camel@gmail.com \
--to=noname.nuno@gmail.com \
--cc=broonie@kernel.org \
--cc=conor+dt@kernel.org \
--cc=corbet@lwn.net \
--cc=devicetree@vger.kernel.org \
--cc=dlechner@baylibre.com \
--cc=frowand.list@gmail.com \
--cc=jic23@kernel.org \
--cc=krzysztof.kozlowski+dt@linaro.org \
--cc=linux-doc@vger.kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pwm@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=michael.hennerich@analog.com \
--cc=nuno.sa@analog.com \
--cc=robh+dt@kernel.org \
--cc=thierry.reding@gmail.com \
--cc=u.kleine-koenig@pengutronix.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).