Skip to contentSkip to conversation

dmaengine: tegra: add dma driver

PATCH Superseded Laxman Dewangan 2 participants 5 messages May 11, 2012 – May 23, 2012

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore

Laxman Dewangan

author maintainer
#0 lore raw

v3 cover dmaengine: tegra: add dma driver

This series add NVIDIA Tegra's APB dma controller driver based on dmaengine. There is already old driver in mach-tegra/dma.c and we want to get rid of this old style driver which exposes private apis.
Once this driver get through, there will be series of patches to move all existing driver to use the dmaengine based driver and old mach-tegra/dma.c will get deleted. This driver has following feature than old one:
- better queue managment.
- Cyclic transfer supports.
- Platform driver.
- Full support for device tree.
- Multiple bug fixes over old driver.

Changes from V1:
- Incorportaed review comments from Vinod.
- get rid of the tegra_dma header.
- Having clock control through runtime pm.
- Remove regmap support.

Changes from V2:
- Taken care of aall review comments provided by Vinod.
- Drop cyclic_half notify mode of dma and implemented as cyclic only. This will make the this patch as simple. Also this can be achive by cyclic once mode. If require, we will add later.
- Remove goto most of places.
- Remove the cookie_complete() in aborted case.
- Remove callback when terminating.
- Macro names are now namespaced.
- Message prints are well formated to have in 1 or 2 line.

Laxman Dewangan (2):
dma: dmaengine: add slave req id in slave_config
dma: tegra: add dmaengine based dma driver

 drivers/dma/Kconfig       |   13 +
 drivers/dma/Makefile      |    1 +
 drivers/dma/tegra_dma.c   | 1594 +++++++++++++++++++++++++++++++++++++++++++++
 include/linux/dmaengine.h |    4 +
 4 files changed, 1612 insertions(+), 0 deletions(-)
 create mode 100644 drivers/dma/tegra_dma.c
author maintainer
#1 lore raw

PATCH v3 1/2 dma: dmaengine: add slave req id in slave_config

The DMA controller like Nvidia's Tegra Dma controller supports the different slave requestor id from different slave. This need to be configure in dma controller to handle the request properly.

Adding the slave-id in the slave configuration so that information can be passed from client when configuring for slave.

---

Changes from V2:
- Make slave_id as unsigned.

 include/linux/dmaengine.h |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
include/linux/dmaengine.h +4 -0
index 1082698..9732396 100644
@@ -338,6 +338,9 @@ enum dma_slave_buswidth {
  * @device_fc: Flow Controller Settings. Only valid for slave channels. Fill
  * with 'true' if peripheral should be flow controller. Direction will be
  * selected at Runtime.
+ * @slave_id: Slave requester id. Only valid for slave channels. The dma
+ * slave peripheral will have unique id as dma requester which need to be
+ * pass as slave config.
  *
  * This struct is passed in as configuration data to a DMA engine
  * in order to set up a certain channel for DMA transport at runtime.
@@ -365,6 +368,7 @@ struct dma_slave_config {
 	u32 src_maxburst;
 	u32 dst_maxburst;
 	bool device_fc;
+	unsigned int slave_id;
 };
 
 static inline const char *dma_chan_name(struct dma_chan *chan)
Signature · 1 line
1.7.1.1
author maintainer
#2 lore raw

PATCH v3 2/2 dma: tegra: add dmaengine based dma driver

In reply to Laxman Dewangan

Adding dmaengine based NVIDIA's Tegra APB DMA driver. This driver support the slave mode of data transfer from peripheral to memory and vice versa.
The driver supports for the cyclic and non-cyclic mode of data transfer.

---
Changes from V1:
- Incorportaed review comments from Vinod.
- get rid of the tegra_dma header.
- Having clock control through runtime pm.
- Remove regmap support.

Changes from V2:
- Taken care of aall review comments provided by Vinod.
- Drop cyclic_half notify mode of dma and implemented as cyclic only. This will make the this patch as simple. Also this can be achive by cyclic once mode. If require, we will add later.
- Remove goto most of places.
- Remove the cookie_complete() in aborted case.
- Remove callback when terminating.
- Macro names are now namespaced.
- Message prints are well formated to have in 1 or 2 line.

 drivers/dma/Kconfig     |   13 +
 drivers/dma/Makefile    |    1 +
 drivers/dma/tegra_dma.c | 1594 +++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 1608 insertions(+), 0 deletions(-)
 create mode 100644 drivers/dma/tegra_dma.c
drivers/dma/Kconfig +13 -0
index ef378b5..26d9a23 100644
@@ -148,6 +148,19 @@ config TXX9_DMAC
 	  Support the TXx9 SoC internal DMA controller.  This can be
 	  integrated in chips such as the Toshiba TX4927/38/39.
 
+config TEGRA_DMA
+	bool "NVIDIA Tegra DMA support"
+	depends on ARCH_TEGRA
+	select DMA_ENGINE
+	help
+	  Support for the NVIDIA Tegra DMA controller driver. The DMA
+	  controller is having multiple DMA channel which can be configured
+	  for different peripherals like audio, UART, SPI, I2C etc which is
+	  in APB bus.
+	  This DMA controller transfers data from memory to peripheral fifo
+	  address or vice versa. It does not support memory to memory data
+	  transfer.
+
 config SH_DMAE
 	tristate "Renesas SuperH DMAC support"
 	depends on (SUPERH && SH_DMA) || (ARM && ARCH_SHMOBILE)
drivers/dma/Makefile +1 -0
index 86b795b..3aaa63a 100644
@@ -23,6 +23,7 @@ obj-$(CONFIG_MXS_DMA) += mxs-dma.o
 obj-$(CONFIG_TIMB_DMA) += timb_dma.o
 obj-$(CONFIG_SIRF_DMA) += sirf-dma.o
 obj-$(CONFIG_STE_DMA40) += ste_dma40.o ste_dma40_ll.o
+obj-$(CONFIG_TEGRA_DMA) += tegra_dma.o
 obj-$(CONFIG_PL330_DMA) += pl330.o
 obj-$(CONFIG_PCH_DMA) += pch_dma.o
 obj-$(CONFIG_AMBA_PL08X) += amba-pl08x.o
drivers/dma/tegra_dma.c new file +1594 -0

1,594 lines not on this page · raw message

Signature · 1 line
1.7.1.1
#3 lore raw

Re: [PATCH V3 2/2] dma: tegra: add dmaengine based dma driver

drivers/dma/Kconfig config TXX9_DMAC · line 151

Quoted 9 lines · Laxman Dewangan

Adding dmaengine based NVIDIA's Tegra APB DMA driver. This driver support the slave mode of data transfer from peripheral to memory and vice versa.
The driver supports for the cyclic and non-cyclic mode of data transfer.

drivers/dma/Kconfig +1 -0
 
+config TEGRA_DMA

Could we name this TEGRA20_APB_DMA

Rational being: Include the version number so that if there's ever a newer version that requires a new driver, we won't have to rename this. Also, there is an AHB DMA engine too, even if it's quite unlikely we'll ever write a driver for it.

drivers/dma/Kconfig config TXX9_DMAC · line 156

Quoted 1 line
drivers/dma/Kconfig +1 -0
+	  Support for the NVIDIA Tegra DMA controller driver. The DMA
                                      ^

Similarly, probably best to insert the word "APB" here.

drivers/dma/tegra_dma.c

Quoted 1 line
drivers/dma/tegra_dma.c +0 -0

Can we name this tegra20-apb-dma.c for similar reasons?

Quoted 1 line

+#define GEN_ENABLE BIT(31)

...

drivers/dma/tegra_dma.c line 49

Quoted 3 lines
drivers/dma/tegra_dma.c +3 -0
+#define CSR_ENB				BIT(31)
+#define CSR_IE_EOC			BIT(30)
+#define CSR_HOLD			BIT(29)

...

It looks like there are still quite a few macros that aren't namespaced (prefixed with TEGRA_APBDMA). I don't care too much about this since they're inside this one file, but I think this is something Vinod wanted you to fix?

Quoted 1 line

+struct tegra_dma_channel {

...

Quoted 6 lines
drivers/dma/tegra_dma.c +6 -0
+	/* Different lists for managing the requests */
+	struct list_head	free_sg_req;
+	struct list_head	pending_sg_req;
+	struct list_head	free_dma_desc;
+	struct list_head	wait_ack_dma_desc;
+	struct list_head	cb_desc;

...

drivers/dma/tegra_dma.c line 270

Quoted 2 lines
drivers/dma/tegra_dma.c +2 -0
+static int tegra_dma_allocate_desc(struct tegra_dma_channel *tdc,
+		int ndma_desc, int nsg_req)

The queue management here seems a lot more complex than other drivers I briefly looked at, which don't (a) allocate multiple descriptors at once or (b) maintain a pool of free descriptors. I guess if this all works it's fine, but it sure makes it harder for me to understand the driver and review it. I'd personally love to have seen a much simpler driver and then add these optimizations later if they prove worthwhile.

(As an aside, it seems like if this descriptor management logic is worthwhile, it should be part of the dmaengine core, not individual drivers)

Quoted 1 line

+static irqreturn_t tegra_dma_isr(int irq, void *dev_id)

...

drivers/dma/tegra_dma.c line 749

Quoted 3 lines
drivers/dma/tegra_dma.c +3 -0
+	if (status & STATUS_ISE_EOC) {
+		tdc_write(tdc, TEGRA_APBDMA_CHAN_STATUS, status);
+		if (!list_empty(&tdc->cb_desc)) {

Given that the tasklet is just running the completion callbacks, is this condition really an error? Can't you just add some more entries onto the tail of the list of callbacks for the tasklet?

Quoted 4 lines
drivers/dma/tegra_dma.c +4 -0
+			dev_err(tdc2dev(tdc),
+				"Int before tasklet handled, Stopping DMA\n");
+			tegra_dma_stop(tdc);
+			tdc->isr_handler(tdc, true);

drivers/dma/tegra_dma.c line 763

Quoted 10 lines
drivers/dma/tegra_dma.c +10 -0
+			tegra_dma_abort_all(tdc);
+			/* Schedule tasklet to make callback */
+			tasklet_schedule(&tdc->tasklet);
+			goto end;
+		}
+		tdc->isr_handler(tdc, false);
+		tasklet_schedule(&tdc->tasklet);
+	} else {
+		dev_info(tdc2dev(tdc),
+			"Interrupt already handled status 0x%08lx\n", status);

Shouldn't this cause IRQ_NONE to be returned?

Quoted 12 lines
drivers/dma/tegra_dma.c +10 -0
+	}
+
+end:
+	spin_unlock_irqrestore(&tdc->lock, flags);
+	return IRQ_HANDLED;
+}
 
+static void tegra_dma_terminate_all(struct dma_chan *dc)
+{
 
+	if (!tdc->busy)
+		goto skip_dma_stop;

drivers/dma/tegra_dma.c line 840

Quoted 10 lines
drivers/dma/tegra_dma.c +10 -0
+
+	/* Pause DMA before checking the queue status */
+	tegra_dma_pause(tdc, true);
+
+	status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
+	if (status & STATUS_ISE_EOC) {
+		dev_dbg(tdc2dev(tdc), "%s():handling isr\n", __func__);
+		tdc->isr_handler(tdc, true);
+		status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
+	}

In the termination case, do we really need to run the isr handler? Presumably since the DMA is being aborted, the caller doesn't really care about getting the absolute latest up-to-date information, so the fact that something completed within the last EGRA_APBDMA_BURST_COMPLETE_TIME micro-seconds isn't something it's worth determining?

drivers/dma/tegra_dma.c line 1378

Quoted 3 lines
drivers/dma/tegra_dma.c +2 -0
+static int __devinit tegra_dma_probe(struct platform_device *pdev)
 
+	tdma->dma_clk = clk_get(&pdev->dev, NULL);

Since this won't be applied until 3.6, I think you can use devm_clk_get() here.

Quoted 1 line

+static int tegra_dma_suspend_noirq(struct device *dev)

Why do we need to implement the _noirq variants for system suspend/resume? In the mainline kernel, the existence of deferred probe most likely means we don't need to use _noirq any more.

drivers/dma/tegra_dma.c line 1570

Quoted 3 lines
drivers/dma/tegra_dma.c +3 -0
+static struct platform_driver tegra_dmac_driver = {
+	.driver = {
+		.name	= "tegra30-apbdma",

Probably better be tegra20-apbdma, since that's the first chip this driver supports.

drivers/dma/tegra_dma.c line 1583

Quoted 5 lines
drivers/dma/tegra_dma.c +5 -0
+static int __init tegra_dmac_init(void)
+{
+	return platform_driver_register(&tegra_dmac_driver);
+}
+arch_initcall_sync(tegra_dmac_init);

Can we make this a module_init() instead of an arch_initcall?

drivers/dma/tegra_dma.c line 1589

Quoted 5 lines
drivers/dma/tegra_dma.c +5 -0
+static void __exit tegra_dmac_exit(void)
+{
+	platform_driver_unregister(&tegra_dmac_driver);
+}
+module_exit(tegra_dmac_exit);

If so, the above 11 lines can be replaced with:

module_platform_driver(tegra_dmac_driver);

Overall, I haven't reviewed the driver's interaction with dmaengine too much since I'm not familiar with dmaengine. I think Vinod has been covering those aspects fine. However, I did try to follow the DMA HW programming, and I think it does avoid the problems we were trying to solve in the existing APB DMA driver, perhaps mainly because dmaengine doesn't expose quite as many functions to client code.

So overall, aside from the comments above, this looks good.

author maintainer
#4 lore raw

Re: [PATCH V3 2/2] dma: tegra: add dmaengine based dma driver

Quoted 8 lines · Stephen Warren

drivers/dma/Kconfig

Quoted 6 lines · Laxman Dewangan

Adding dmaengine based NVIDIA's Tegra APB DMA driver. This driver support the slave mode of data transfer from peripheral to memory and vice versa.
The driver supports for the cyclic and non-cyclic mode of data transfer.

drivers/dma/Kconfig +0 -0

I have taken care of all your comments. Few clarification here.

Quoted 11 lines

drivers/dma/Kconfig

Quoted 2 lines
drivers/dma/Kconfig +2 -0
+static int tegra_dma_allocate_desc(struct tegra_dma_channel *tdc,
+		int ndma_desc, int nsg_req)

The queue management here seems a lot more complex than other drivers I briefly looked at, which don't (a) allocate multiple descriptors at once or (b) maintain a pool of free descriptors. I guess if this all works it's fine, but it sure makes it harder for me to understand the driver and review it. I'd personally love to have seen a much simpler driver and then add these optimizations later if they prove worthwhile.

(As an aside, it seems like if this descriptor management logic is worthwhile, it should be part of the dmaengine core, not individual drivers)

This is done by Russel in one of his patch as virt_dma. I will use that later on, not on this series of patch as it is not available now.

Quoted 5 lines

Given that the tasklet is just running the completion callbacks, is this condition really an error? Can't you just add some more entries onto the tail of the list of callbacks for the tasklet?

Taken care. Using ref count and calling clalback multiple times here. There was discussion on this topic and I went as per suggestion on that topic.

Quoted 7 lines
Quoted 7 lines
drivers/dma/Kconfig +7 -0
+	/* Pause DMA before checking the queue status */
+	tegra_dma_pause(tdc, true);
+
+	status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
+	if (status&  STATUS_ISE_EOC) {
+		dev_dbg(tdc2dev(tdc), "%s():handling isr\n", __func__);
+		tdc->isr_handler(tdc, true);
Quoted 9 lines

drivers/dma/Kconfig

Quoted 2 lines
drivers/dma/Kconfig +2 -0
+		status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
+	}

In the termination case, do we really need to run the isr handler? Presumably since the DMA is being aborted, the caller doesn't really care about getting the absolute latest up-to-date information, so the fact that something completed within the last EGRA_APBDMA_BURST_COMPLETE_TIME micro-seconds isn't something it's worth determining?

For serial case, we will need this info as on the serial communication, we will use abort most of time. Reson is that we do not know how much data is goign to arrive and so program dma for larger size and based on uart controller interrupt, abort dma and get actual bytes transfered by dma.

Quoted 4 lines

drivers/dma/Kconfig

Quoted 1 line
drivers/dma/Kconfig +1 -0
+	tdma->dma_clk = clk_get(&pdev->dev, NULL);

Since this won't be applied until 3.6, I think you can use devm_clk_get() here.

Will use on later patch as on Vinod's tree may not have this change now.

Quoted 5 lines
Quoted 1 line

+static int tegra_dma_suspend_noirq(struct device *dev)

Why do we need to implement the _noirq variants for system suspend/resume? In the mainline kernel, the existence of deferred probe most likely means we don't need to use _noirq any more.

Removed.

Quoted 4 lines

If so, the above 11 lines can be replaced with:

module_platform_driver(tegra_dmac_driver);

Done.

Quoted 8 lines

Overall, I haven't reviewed the driver's interaction with dmaengine too much since I'm not familiar with dmaengine. I think Vinod has been covering those aspects fine. However, I did try to follow the DMA HW programming, and I think it does avoid the problems we were trying to solve in the existing APB DMA driver, perhaps mainly because dmaengine doesn't expose quite as many functions to client code.

So overall, aside from the comments above, this looks good.

Thanks for review,