Skip to contentSkip to conversation

spi: davinci: Allow device tree devices to use DMA

PATCH RESEND In review David Lechner 3 participants 6 messages Jan 6, 2017 – Jan 13, 2017 SPI

lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 spi: davinci: Allow device tree devices to use DMA

This allows SPI devices specified in a device tree to use DMA when the master controller.

Since device tree is supposed to only describe the hardware, adding such a configuration option to device tree would not be acceptable. So, this is the best we can do for now to get SPI devices working with DMA.

Unfortunately, this excludes the possibility of using one SPI device with DMA and one without on the same master.

---

When I originally submitted this patch, there was some discussion as to whether dspi->dma_rx should be changed to return an error rather than being null.

However, I prefer it the way it is and don't see a compelling reason to change it.

 drivers/spi/spi-davinci.c | 4 ++++
 1 file changed, 4 insertions(+)
drivers/spi/spi-davinci.c +4 -0
index d36c11b..c6cf73a 100644
@@ -388,6 +388,7 @@ static int davinci_spi_setup_transfer(struct spi_device *spi,
 static int davinci_spi_of_setup(struct spi_device *spi)
 {
 	struct davinci_spi_config *spicfg = spi->controller_data;
+	struct davinci_spi *dspi = spi_master_get_devdata(spi->master);
 	struct device_node *np = spi->dev.of_node;
 	u32 prop;
 
@@ -400,6 +401,9 @@ static int davinci_spi_of_setup(struct spi_device *spi)
 		if (!of_property_read_u32(np, "ti,spi-wdelay", &prop))
 			spicfg->wdelay = (u8)prop;
 		spi->controller_data = spicfg;
+		/* Use DMA for device if master supports it */
+		if (dspi->dma_rx)
+			spicfg->io_type = SPI_IO_TYPE_DMA;
 	}
 
 	return 0;
Signature · 1 line
2.7.4
maintainer
#1 lore raw
Quoted 9 lines · David Lechner

This allows SPI devices specified in a device tree to use DMA when the master controller.

Since device tree is supposed to only describe the hardware, adding such a configuration option to device tree would not be acceptable. So, this is the best we can do for now to get SPI devices working with DMA.

Unfortunately, this excludes the possibility of using one SPI device with DMA and one without on the same master.

Why would you ever want to do that? What would ever make sense about not using DMA if it's available and the transfer is suitably large, or conversely why would one want to force DMA even if PIO would be more performant?

Quoted 5 lines

When I originally submitted this patch, there was some discussion as to whether dspi->dma_rx should be changed to return an error rather than being null.

However, I prefer it the way it is and don't see a compelling reason to change it.

I don't know what the above comment means, sorry (and don't recall
having seen any earlier versions of this).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170109/ce442c16/attachment.sig>

#2 lore raw
Quoted 9 lines · Mark Brown
Quoted 6 lines · David Lechner

This allows SPI devices specified in a device tree to use DMA when the master controller.

Since device tree is supposed to only describe the hardware, adding such a configuration option to device tree would not be acceptable. So, this is the best we can do for now to get SPI devices working with DMA.

Quoted 7 lines
Quoted 2 lines

Unfortunately, this excludes the possibility of using one SPI device with DMA and one without on the same master.

Why would you ever want to do that? What would ever make sense about not using DMA if it's available and the transfer is suitably large, or conversely why would one want to force DMA even if PIO would be more performant?

I don't particularly want to do that, but that is the way the spi-davinci driver currently works. The choice between DMA or PIO is specified in the platform data on a per-device basis.

What I get from your remarks is that this is wrong and it needs to be fixed. If that is so, could someone please point out a driver that does it the right way and I will try to fix it.

Quoted 10 lines
Quoted 6 lines

When I originally submitted this patch, there was some discussion as to whether dspi->dma_rx should be changed to return an error rather than being null.

However, I prefer it the way it is and don't see a compelling reason to change it.

I don't know what the above comment means, sorry (and don't recall having seen any earlier versions of this).

FWIW, you can find the previous conversation at
https://patchwork.kernel.org/patch/9437901/

maintainer
#3 lore raw
Quoted 11 lines · David Lechner
Quoted 9 lines · Mark Brown
Quoted 2 lines · David Lechner

Unfortunately, this excludes the possibility of using one SPI device with DMA and one without on the same master.

Why would you ever want to do that? What would ever make sense about not using DMA if it's available and the transfer is suitably large, or conversely why would one want to force DMA even if PIO would be more performant?

Quoted 7 lines

I don't particularly want to do that, but that is the way the spi-davinci driver currently works. The choice between DMA or PIO is specified in the platform data on a per-device basis.

What I get from your remarks is that this is wrong and it needs to be fixed. If that is so, could someone please point out a driver that does it the right way and I will try to fix it.

Pretty much any driver doing DMA... off the top of my head the i.MX and Samsung drivers ought to be reasonable examples. If you've got time to look at fixing the driver the other thing that jumps out with it is the use of a threaded interrupt handler with no actual handling in the thread, that looks like some magic timing based hack which seems risky (or completely unneeded which would be better).

Quoted 11 lines
Quoted 8 lines
Quoted 5 lines

When I originally submitted this patch, there was some discussion as to whether dspi->dma_rx should be changed to return an error rather than being null.

However, I prefer it the way it is and don't see a compelling reason to change it.

I don't know what the above comment means, sorry (and don't recall having seen any earlier versions of this).

FWIW, you can find the previous conversation at
https://patchwork.kernel.org/patch/9437901/

What Sekhar is saying there is right, it is better style to use an error
pointer rather than NULL as someone could potentially come up with a way
to make NULL a valid pointer in the API. But it doesn't matter greatly.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170110/aac7bf99/attachment.sig>

#4 lore raw
In reply to David Lechner
Quoted 2 lines · David Lechner

This allows SPI devices specified in a device tree to use DMA when the master controller.

Enabling DMA for spi-davinci isn't quite ready yet since this driver is blindly using dma_map_single() on addresses passed in. MTD seems to use vmalloc'd buffers, which cannot be passed direclty to dma_map_single().

I thinks this driver needs an update to use spi_map_buf() to be able to handle vmalloc'd buffers before always enabling DMA.

Kevin

maintainer
#5 lore raw
Quoted 2 lines · Kevin Hilman

I thinks this driver needs an update to use spi_map_buf() to be able to handle vmalloc'd buffers before always enabling DMA.

Right. As I said elsewhere in the thread the driver looks like it needs
some very serious TLC based on a quick scan through.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: not available
URL: <http://lists.infradead.org/pipermail/linux-arm-kernel/attachments/20170113/c376e85e/attachment-0001.sig>