Devicetree
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Cosmin-Gabriel Tanislav <cosmin-gabriel.tanislav.xa@renesas.com>
Cc: "David Lechner" <dlechner@baylibre.com>,
	"Nuno Sá" <nuno.sa@analog.com>,
	"Andy Shevchenko" <andy@kernel.org>,
	"Rob Herring" <robh@kernel.org>,
	"Krzysztof Kozlowski" <krzk+dt@kernel.org>,
	"Conor Dooley" <conor+dt@kernel.org>,
	"Geert Uytterhoeven" <geert+renesas@glider.be>,
	"magnus.damm" <magnus.damm@gmail.com>,
	"linux-iio@vger.kernel.org" <linux-iio@vger.kernel.org>,
	"linux-renesas-soc@vger.kernel.org"
	<linux-renesas-soc@vger.kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH 5/9] iio: adc: rzt2h: implement DMA buffer support
Date: Fri, 4 Sep 2026 04:11:38 +0100	[thread overview]
Message-ID: <20260904041138.77b6f76f@jic23-huawei> (raw)
In-Reply-To: <TYRPR01MB15619584AE0D8737B439D317185B62@TYRPR01MB15619.jpnprd01.prod.outlook.com>

On Thu, 3 Sep 2026 07:49:29 +0000
Cosmin-Gabriel Tanislav <cosmin-gabriel.tanislav.xa@renesas.com> wrote:

> > From: Jonathan Cameron <jic23@kernel.org>
> > Sent: Saturday, August 29, 2026 4:21 AM
> >   
> > > Implement buffered capture using a cyclic DMA transfer into a kfifo
> > > buffer to support continuous high-rate sampling.
> > >
> > > On buffer enable, switch the ADC to continuous conversion mode and start
> > > a cyclic DMA transfer over the active channels.
> > >
> > > Because the DMA controller does not support native scatter-gather, and
> > > because of the cyclic DMA setup, transfers must be done in widths
> > > covering all the enabled channels.
> > >
> > > Since DMA transfer width must be a power of two and aligned to its size,
> > > cover the smallest power-of-two-aligned group of channel registers
> > > spanning the enabled channels.
> > >
> > > Split the cyclic buffer into fixed-size periods. On each period
> > > completion, bump a pending counter and wake a consumer kthread from the
> > > DMA callback.
> > >
> > > For every completed period, gather the enabled channels out of the DMA
> > > layout into the scan layout the IIO core expects and push each scan
> > > with iio_push_to_buffers().  
> > 
> > Could you instead use the available_scan_masks infrastructure.  bit annoying
> > to specify the full list but isn't that long I think with 16 channels
> > 
> > 16 x single
> > 8 x double,
> > 4 x quads
> > 2 x octect
> > 1 x all of them.
> > 
> > The the IIO demux in (sits behind the push_to_buffers path if
> > we have available_scan_masks set) will then deal with repacking
> > the data if necessary.
> >   
> 
> Hi Jonathan.
> 
> There are a couple reasons why I haven't used available_scan_masks.
> 
> Our limitation is on the DMA side. It cannot do scatter-gather in a
> single descriptor, and we need to copy all the channels for each
> completion IRQ. This is why we have to copy all the enabled channels
> in a single block, and the base address needs to have the same
> alignment as the block size.
> 
> My initial naive implementation copied all 16 channels (32 bytes) all
> the time, but at that size the DMAC quickly hits a wall where it doesn't
> service the ADC's completion signals anymore, at ~220k requests per
> second.
> 
> Optimizing the DMA window allows us to avoid losing samples when the
> enabled channels are densely packed. Enabling only channel 0 and 15
> still hits the DMAC performance wall though, for example.
> 
> If we were to use available_scan_masks, the ADC would have to enable the
> extra channels too, since it would have no knowledge of whether a
> channel is enabled legitimately or for alignment purposes. The ADC scans
> each channel iteratively, not in parallel, so sampling rate would be
> affected because of the extra enabled channels. Besides that, this would
> be transparent to the user, but it would reuse the last set sampling
> frequency values, which affect the sampling rate without the user even
> knowing.

Ok.  So if this was a common thing I'd suggest we might expose an extra
mask that presents what the various consumers have requested, but I'd
not go to that effort for the first driver that could use it.

> 
> If there are any extra enabled channels, iio_demux() would have to copy
> all the data again. We need to keep our own copy inside the driver to
> unswap the ADC's 16-bit data registers out of each 32-bit word.

Ah. Yes, with a copy already happening might as well make it just one.

> 
> The available_scan_masks table would have to be computed at runtime
> since not all instances of the ADC have 16 channels.

Given these are fairly small, that might just be selection from a set
of options.

> Also the use of
> devm_iio_adc_device_alloc_chaninfo_se() means that we allow gaps in the
> channels themselves. scan_index is set incrementally anyway, so it can
> get out of sync with the channel index, and that would need extra
> handling when building the table.

Ah. That would make life trickier.

> 
> Let me know what you think and what the direction should be.

This info is more than enough to convince me that it isn't worth
using the core demux stuff. Thanks for all the details!

Jonathan

  reply	other threads:[~2026-09-04  3:11 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-28 14:59 [PATCH 0/9] iio: adc: rzt2h: add DMA buffer support Cosmin Tanislav
2026-08-28 14:59 ` [PATCH 1/9] iio: adc: rzt2h: remove unused struct rzt2h_adc::max_channels Cosmin Tanislav
2026-08-28 14:59 ` [PATCH 2/9] iio: adc: rzt2h: store IRQ in private state Cosmin Tanislav
2026-08-28 14:59 ` [PATCH 3/9] iio: adc: rzt2h: store the physical address " Cosmin Tanislav
2026-08-28 14:59 ` [PATCH 4/9] iio: adc: rzt2h: claim direct mode on single reads Cosmin Tanislav
2026-08-28 15:15   ` sashiko-bot
2026-08-28 14:59 ` [PATCH 5/9] iio: adc: rzt2h: implement DMA buffer support Cosmin Tanislav
2026-08-28 15:13   ` sashiko-bot
2026-08-29  1:20   ` Jonathan Cameron
2026-08-29  1:24     ` Jonathan Cameron
2026-09-03  7:49     ` Cosmin-Gabriel Tanislav
2026-09-04  3:11       ` Jonathan Cameron [this message]
2026-08-28 14:59 ` [PATCH 6/9] iio: adc: rzt2h: expose sampling frequency Cosmin Tanislav
2026-08-28 15:14   ` sashiko-bot
2026-08-28 14:59 ` [PATCH 7/9] dt-bindings: iio: adc: renesas,r9a09g077-adc: document DMA support Cosmin Tanislav
2026-08-28 15:14   ` sashiko-bot
2026-08-28 16:21   ` Conor Dooley
2026-08-28 17:17     ` Geert Uytterhoeven
2026-08-31 15:16       ` Conor Dooley
2026-08-28 14:59 ` [PATCH 8/9] arm64: dts: renesas: r9a09g077: Wire up DMA support for ADC Cosmin Tanislav
2026-08-28 14:59 ` [PATCH 9/9] arm64: dts: renesas: r9a09g087: " Cosmin Tanislav

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=20260904041138.77b6f76f@jic23-huawei \
    --to=jic23@kernel.org \
    --cc=andy@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=cosmin-gabriel.tanislav.xa@renesas.com \
    --cc=devicetree@vger.kernel.org \
    --cc=dlechner@baylibre.com \
    --cc=geert+renesas@glider.be \
    --cc=krzk+dt@kernel.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-renesas-soc@vger.kernel.org \
    --cc=magnus.damm@gmail.com \
    --cc=nuno.sa@analog.com \
    --cc=robh@kernel.org \
    /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