spi: Provide core support for full duplex devices
Geert Uytterhoeven
geert at linux-m68k.org
Wed Feb 19 08:32:28 EST 2014
On Wed, Feb 19, 2014 at 2:04 PM, Mark Brown <broonie at kernel.org> wrote:
> 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.
Do you mean the fact that you need to transmit dummy data on this particular
hardware, or that you need to know the direction for Dual/Quad transfers,
and don't need dummy data for the latter?
It actually makes sense from a hardware point of view:
- Single SPI transfers are full-duplex. For every bit of output, there's a bit
of input. As this is SPI master, not slave, the master controls everything
based on the availability of data in the output FIFO.
- Dual/Quad SPI transfers are half duplex:
Transmission is controlled by the master, based on the availability of
data in the output FIFO.
Reception is also controlled by the master, but as there's no data to
output, this is handled based on the amount of space in the RX FIFO.
>> 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
So let's hope all DMA-capable hardware has scatter/gather support, or an
IOMMU ;-)
>> 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.
You forgot the smiley ;-)
While in general I care a lot about readability (code is read more than it's
written), using a ternary operator for chosing between valid data and a
dummy zero is fine, IMHO.
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert at linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
More information about the linux-mtd
mailing list