spi: Provide core support for full duplex devices

Mark Brown broonie at kernel.org
Wed Feb 19 08:04:07 EST 2014


On Tue, Feb 18, 2014 at 10:59:09AM +0100, Geert Uytterhoeven wrote:

> For Dual/Quad transfers, which are half-duplex, the buffer pointer for the
> unused direction must be NULL, so the driver knows in which direction to
> transfer. Hence SPI_MASTER_MUST_TX cannot be set for Dual/Quad
> capable SPI master.

This is a particularly thoughtless hardware design it has to be said.

> I'm also worried about the buffer allocation. With m25p80 and mtchar, the
> transfer buffer can be quite large (up to 4 MiB in my case), and this can be
> triggered from userspace.

That's readily fixable for DMA capable drivers, we can just repeatedly
transfer the same page (or whatever).  PIO drivers have big problems
with such large transfers anyway but could also easily have the transfer
segmented for them in a similar way.  Once we do these things we ought
to be able to avoid having to free the buffer on idle (though a memory
pressure notifier is probably polite) which helps too.  What's there
currently is very much a first pass implementation so things work,
there's plenty of room for optimisation.

> Alternatively, to avoid the memory allocation, you could zero rx_buf,
> and use rx_buf for both tx and rx? That may break some DMA setups,
> though.

As you say it's not clever for DMA and means you have to do the memset()
each time you use the buffer.

> Concluding, for PIO mode, I'm still in favor of using

>     data = tx_buf ? *tx_buf++ : DUMMY_DATA;

> in the SPI master driver itself.

With the ternery operator for legibility of course.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL: <http://lists.infradead.org/pipermail/linux-mtd/attachments/20140219/4c2a9334/attachment.sig>


More information about the linux-mtd mailing list