Skip to contentSkip to conversation

DMA: Add support for Tegra210 ADMA

RFC PATCH Superseded Jon Hunter 4 participants 20 messages Aug 18, 2015 – Aug 28, 2015

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Jon Hunter

author maintainer
#0 lore raw

cover DMA: Add support for Tegra210 ADMA

Add support for Tegra210 Audio DMA (ADMA) controller. This driver is based upon the existing Tegra20-APB DMA driver and a lot of the core code has been re-used.

This is currently being distributed as an RFC to get feedback on the approach and although this has been compile and boot tested, it still needs further functional testing to ensure it is working well.

This series is based upon the Tegra-APB clean-up series [0].

[0] https://lkml.org/lkml/2015/8/6/315

Jon Hunter (7):
DMA: tegra-apb: Correct runtime-pm usage
DMA: tegra-apb: Move code dealing with h/w registers into separate
functions
DMA: tegra-apb: Clean-up and simplify setting up of transfer
parameters
DMA: tegra-apb: Add a function table for functions dealing with
registers
DMA: tegra-apb: Move common code into separate source files
Documentation: DT: Add binding documentation for NVIDIA ADMA
DMA: tegra-adma: Add support for Tegra210 ADMA

 .../devicetree/bindings/dma/tegra210-adma.txt      |   49 +
 drivers/dma/Kconfig                                |   16 +
 drivers/dma/Makefile                               |    2 +
 drivers/dma/tegra-common.c                         |  734 +++++++++++++
 drivers/dma/tegra-common.h                         |  260 +++++
 drivers/dma/tegra20-apb-dma.c                      | 1121 +++-----------------
 drivers/dma/tegra210-adma.c                        |  710 +++++++++++++
 7 files changed, 1928 insertions(+), 964 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/dma/tegra210-adma.txt
 create mode 100644 drivers/dma/tegra-common.c
 create mode 100644 drivers/dma/tegra-common.h
 create mode 100644 drivers/dma/tegra210-adma.c
Signature · 1 line
2.1.4
author maintainer
#1 lore raw

RFC PATCH 1/7 DMA: tegra-apb: Correct runtime-pm usage

The tegra-apb DMA driver enables runtime-pm but never calls pm_runtime_get/put and hence the runtime-pm callbacks are never invoked. The driver manages the clocks by directly calling clk_prepare_enable() and clk_unprepare_disable().

Fix this by replacing the clk_prepare_enable() and clk_disable_unprepare() with pm_runtime_get_sync() and pm_runtime_put(), respectively. Note that the consequence of this is that if runtime-pm is disabled, then the clocks will remain on the entire time the driver is loaded. However, if runtime-pm is disabled, then power is not most likely not a concern.

---
 drivers/dma/tegra20-apb-dma.c | 36 ++++++++++++------------------------
 1 file changed, 12 insertions(+), 24 deletions(-)
drivers/dma/tegra20-apb-dma.c +12 -24
index c8f79dcaaee8..097432ea89fa 100644
@@ -1182,14 +1182,11 @@ static int tegra_dma_alloc_chan_resources(struct dma_chan *dc)
 {
 	struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
 	struct tegra_dma *tdma = tdc->tdma;
-	int ret;
 
 	dma_cookie_init(&tdc->dma_chan);
 	tdc->config_init = false;
-	ret = clk_prepare_enable(tdma->dma_clk);
-	if (ret < 0)
-		dev_err(tdc2dev(tdc), "clk_prepare_enable failed: %d\n", ret);
-	return ret;
+
+	return pm_runtime_get_sync(tdma->dev);
 }
 
 static void tegra_dma_free_chan_resources(struct dma_chan *dc)
@@ -1232,7 +1229,7 @@ static void tegra_dma_free_chan_resources(struct dma_chan *dc)
 		list_del(&sg_req->node);
 		kfree(sg_req);
 	}
-	clk_disable_unprepare(tdma->dma_clk);
+	pm_runtime_put(tdma->dev);
 
 	tdc->slave_id = 0;
 }
@@ -1356,21 +1353,13 @@ static int tegra_dma_probe(struct platform_device *pdev)
 	spin_lock_init(&tdma->global_lock);
 
 	pm_runtime_enable(&pdev->dev);
-	if (!pm_runtime_enabled(&pdev->dev)) {
+	if (!pm_runtime_enabled(&pdev->dev))
 		ret = tegra_dma_runtime_resume(&pdev->dev);
-		if (ret) {
-			dev_err(&pdev->dev, "dma_runtime_resume failed %d\n",
-				ret);
-			goto err_pm_disable;
-		}
-	}
+	else
+		ret = pm_runtime_get_sync(&pdev->dev);
 
-	/* Enable clock before accessing registers */
-	ret = clk_prepare_enable(tdma->dma_clk);
-	if (ret < 0) {
-		dev_err(&pdev->dev, "clk_prepare_enable failed: %d\n", ret);
+	if (ret)
 		goto err_pm_disable;
-	}
 
 	/* Reset DMA controller */
 	reset_control_assert(tdma->rst);
@@ -1382,7 +1371,7 @@ static int tegra_dma_probe(struct platform_device *pdev)
 	tdma_write(tdma, TEGRA_APBDMA_CONTROL, 0);
 	tdma_write(tdma, TEGRA_APBDMA_IRQ_MASK_SET, 0xFFFFFFFFul);
 
-	clk_disable_unprepare(tdma->dma_clk);
+	pm_runtime_put(&pdev->dev);
 
 	INIT_LIST_HEAD(&tdma->dma_dev.channels);
 	for (i = 0; i < cdata->nr_channels; i++) {
@@ -1484,7 +1473,6 @@ err_irq:
 		struct tegra_dma_channel *tdc = &tdma->channels[i];
 		tasklet_kill(&tdc->tasklet);
 	}
-
 err_pm_disable:
 	pm_runtime_disable(&pdev->dev);
 	if (!pm_runtime_status_suspended(&pdev->dev))
@@ -1543,7 +1531,7 @@ static int tegra_dma_pm_suspend(struct device *dev)
 	int ret;
 
 	/* Enable clock before accessing register */
-	ret = tegra_dma_runtime_resume(dev);
+	ret = pm_runtime_get_sync(dev);
 	if (ret < 0)
 		return ret;
 
@@ -1560,7 +1548,7 @@ static int tegra_dma_pm_suspend(struct device *dev)
 	}
 
 	/* Disable clock */
-	tegra_dma_runtime_suspend(dev);
+	pm_runtime_put(dev);
 	return 0;
 }
 
@@ -1571,7 +1559,7 @@ static int tegra_dma_pm_resume(struct device *dev)
 	int ret;
 
 	/* Enable clock before accessing register */
-	ret = tegra_dma_runtime_resume(dev);
+	ret = pm_runtime_get_sync(dev);
 	if (ret < 0)
 		return ret;
 
@@ -1592,7 +1580,7 @@ static int tegra_dma_pm_resume(struct device *dev)
 	}
 
 	/* Disable clock */
-	tegra_dma_runtime_suspend(dev);
+	pm_runtime_put(dev);
 	return 0;
 }
 #endif
Signature · 1 line
2.1.4
#2 lore raw

Re: [RFC PATCH 1/7] DMA: tegra-apb: Correct runtime-pm usage

drivers/dma/tegra20-apb-dma.c static int tegra_dma_pm_suspend(struct device *dev) · line 1534

Quoted 6 lines · Jon Hunter
drivers/dma/tegra20-apb-dma.c +1 -1
@@ -1543,7 +1531,7 @@ static int tegra_dma_pm_suspend(struct device *dev)
 	int ret;
 
 	/* Enable clock before accessing register */
-	ret = tegra_dma_runtime_resume(dev);
+	ret = pm_runtime_get_sync(dev);

why is this required ?

Signature · 1 line
~Vinod
author maintainer
#3 lore raw

Re: [RFC PATCH 1/7] DMA: tegra-apb: Correct runtime-pm usage

Quoted 10 lines · Vinod Koul

drivers/dma/tegra20-apb-dma.c static int tegra_dma_pm_suspend(struct device *dev) · line 1534

Quoted 6 lines · Jon Hunter
drivers/dma/tegra20-apb-dma.c +1 -1
@@ -1543,7 +1531,7 @@ static int tegra_dma_pm_suspend(struct device *dev)
 	int ret;
 
 	/* Enable clock before accessing register */
-	ret = tegra_dma_runtime_resume(dev);
+	ret = pm_runtime_get_sync(dev);

why is this required ?

Because the clock could be disabled when this function is called. This function saves the DMA context so that if the context is lost during suspend, it can be restored.

Cheers
Jon

#4 lore raw

Re: [RFC PATCH 1/7] DMA: tegra-apb: Correct runtime-pm usage

Quoted 13 lines · Jon Hunter
Quoted 10 lines · Vinod Koul

drivers/dma/tegra20-apb-dma.c static int tegra_dma_pm_suspend(struct device *dev) · line 1534

Quoted 6 lines · Jon Hunter
drivers/dma/tegra20-apb-dma.c +1 -1
@@ -1543,7 +1531,7 @@ static int tegra_dma_pm_suspend(struct device *dev)
 	int ret;
 
 	/* Enable clock before accessing register */
-	ret = tegra_dma_runtime_resume(dev);
+	ret = pm_runtime_get_sync(dev);

why is this required ?

Quoted 3 lines

Because the clock could be disabled when this function is called. This function saves the DMA context so that if the context is lost during suspend, it can be restored.

Have you verified this? Coz my understanding is that when PM does suspend it will esnure you are runtime resume if runtime suspended and then will do suspend.
So you do not need to do above

Signature · 1 line
~Vinod
author maintainer
#5 lore raw

Re: [RFC PATCH 1/7] DMA: tegra-apb: Correct runtime-pm usage

Quoted 14 lines · Vinod Koul
Quoted 13 lines · Jon Hunter
Quoted 10 lines · Vinod Koul

drivers/dma/tegra20-apb-dma.c static int tegra_dma_pm_suspend(struct device *dev) · line 1534

Quoted 6 lines · Jon Hunter
drivers/dma/tegra20-apb-dma.c +1 -1
@@ -1543,7 +1531,7 @@ static int tegra_dma_pm_suspend(struct device *dev)
 	int ret;
 
 	/* Enable clock before accessing register */
-	ret = tegra_dma_runtime_resume(dev);
+	ret = pm_runtime_get_sync(dev);

why is this required ?

Quoted 8 lines
Quoted 3 lines

Because the clock could be disabled when this function is called. This function saves the DMA context so that if the context is lost during suspend, it can be restored.

Have you verified this? Coz my understanding is that when PM does suspend it will esnure you are runtime resume if runtime suspended and then will do suspend.
So you do not need to do above

I see what you are saying. I did some testing with ftrace today to trace rpm and suspend/resume calls. If the dma controller is runtime suspended and I do not call pm_runtime_get_sync() above then I do not see any runtime resume of the dma controller prior to suspend. Now I was hoping that this would cause a complete kernel crash but it did not and so the DMA clock did not appear to be needed here (at least on the one board I tested). However, I would not go as far as to remove this and prefer to keep as above.

Furthermore, other drivers do similar things, including the sirf dma controller (see sirf-dma.c).

Cheers
Jon

#6 lore raw

Re: [RFC PATCH 1/7] DMA: tegra-apb: Correct runtime-pm usage

Quoted 25 lines · Jon Hunter
Quoted 14 lines · Vinod Koul
Quoted 13 lines · Jon Hunter
Quoted 10 lines · Vinod Koul

drivers/dma/tegra20-apb-dma.c static int tegra_dma_pm_suspend(struct device *dev) · line 1534

Quoted 6 lines · Jon Hunter
drivers/dma/tegra20-apb-dma.c +1 -1
@@ -1543,7 +1531,7 @@ static int tegra_dma_pm_suspend(struct device *dev)
 	int ret;
 
 	/* Enable clock before accessing register */
-	ret = tegra_dma_runtime_resume(dev);
+	ret = pm_runtime_get_sync(dev);

why is this required ?

Quoted 8 lines
Quoted 3 lines

Because the clock could be disabled when this function is called. This function saves the DMA context so that if the context is lost during suspend, it can be restored.

Have you verified this? Coz my understanding is that when PM does suspend it will esnure you are runtime resume if runtime suspended and then will do suspend.
So you do not need to do above

Quoted 8 lines

I see what you are saying. I did some testing with ftrace today to trace rpm and suspend/resume calls. If the dma controller is runtime suspended and I do not call pm_runtime_get_sync() above then I do not see any runtime resume of the dma controller prior to suspend. Now I was hoping that this would cause a complete kernel crash but it did not and so the DMA clock did not appear to be needed here (at least on the one board I tested). However, I would not go as far as to remove this and prefer to keep as above.

Okay am adding Rafael here for his recommendations.

I have tested in past and if my driver was runtime suspended we were resumed prior to being suspended. So I am not sure why you did not see that behaviour, and if that is right we don't need to force resume here

Signature · 1 line
~Vinod
#7 lore raw

Re: [RFC PATCH 1/7] DMA: tegra-apb: Correct runtime-pm usage

Quoted 35 lines · Vinod Koul
Quoted 25 lines · Jon Hunter
Quoted 14 lines · Vinod Koul
Quoted 13 lines · Jon Hunter
Quoted 10 lines · Vinod Koul

drivers/dma/tegra20-apb-dma.c static int tegra_dma_pm_suspend(struct device *dev) · line 1534

Quoted 6 lines · Jon Hunter
drivers/dma/tegra20-apb-dma.c +1 -1
@@ -1543,7 +1531,7 @@ static int tegra_dma_pm_suspend(struct device *dev)
 	int ret;
 
 	/* Enable clock before accessing register */
-	ret = tegra_dma_runtime_resume(dev);
+	ret = pm_runtime_get_sync(dev);

why is this required ?

Quoted 8 lines
Quoted 3 lines

Because the clock could be disabled when this function is called. This function saves the DMA context so that if the context is lost during suspend, it can be restored.

Have you verified this? Coz my understanding is that when PM does suspend it will esnure you are runtime resume if runtime suspended and then will do suspend.
So you do not need to do above

Quoted 8 lines

I see what you are saying. I did some testing with ftrace today to trace rpm and suspend/resume calls. If the dma controller is runtime suspended and I do not call pm_runtime_get_sync() above then I do not see any runtime resume of the dma controller prior to suspend. Now I was hoping that this would cause a complete kernel crash but it did not and so the DMA clock did not appear to be needed here (at least on the one board I tested). However, I would not go as far as to remove this and prefer to keep as above.

Quoted 1 line

Okay am adding Rafael here for his recommendations.

Well, and what is the question I'm supposed to answer, exactly?

I was in Seattle last week, so haven't been following this closely.

Quoted 3 lines

I have tested in past and if my driver was runtime suspended we were resumed prior to being suspended. So I am not sure why you did not see that behaviour, and if that is right we don't need to force resume here

We're adding code for skipping runtime-resume-before-system-suspend, because it is not desirable in general.

The rule of thumb is that if you know you need to change the device's settings (eg. because of wakeup being enabled or not) for system suspend and that requires the device to be resumed, resume it. It can stay suspended otherwise.

Thanks,
Rafael

author maintainer
#8 lore raw

Re: [RFC PATCH 1/7] DMA: tegra-apb: Correct runtime-pm usage

Quoted 46 lines · Rafael J. Wysocki
Quoted 35 lines · Vinod Koul
Quoted 25 lines · Jon Hunter
Quoted 14 lines · Vinod Koul
Quoted 13 lines · Jon Hunter
Quoted 10 lines · Vinod Koul

Review static int tegra_dma_pm_suspend(struct device *dev) · line 1534

Quoted 6 lines · Jon Hunter
(quoted diff) +1 -1
@@ -1543,7 +1531,7 @@ static int tegra_dma_pm_suspend(struct device *dev)
 	int ret;
 
 	/* Enable clock before accessing register */
-	ret = tegra_dma_runtime_resume(dev);
+	ret = pm_runtime_get_sync(dev);

why is this required ?

Quoted 8 lines
Quoted 3 lines

Because the clock could be disabled when this function is called. This function saves the DMA context so that if the context is lost during suspend, it can be restored.

Have you verified this? Coz my understanding is that when PM does suspend it will esnure you are runtime resume if runtime suspended and then will do suspend.
So you do not need to do above

Quoted 8 lines

I see what you are saying. I did some testing with ftrace today to trace rpm and suspend/resume calls. If the dma controller is runtime suspended and I do not call pm_runtime_get_sync() above then I do not see any runtime resume of the dma controller prior to suspend. Now I was hoping that this would cause a complete kernel crash but it did not and so the DMA clock did not appear to be needed here (at least on the one board I tested). However, I would not go as far as to remove this and prefer to keep as above.

Quoted 1 line

Okay am adding Rafael here for his recommendations.

Well, and what is the question I'm supposed to answer, exactly?

I was in Seattle last week, so haven't been following this closely.

Quoted 3 lines

I have tested in past and if my driver was runtime suspended we were resumed prior to being suspended. So I am not sure why you did not see that behaviour, and if that is right we don't need to force resume here

Quoted 7 lines

We're adding code for skipping runtime-resume-before-system-suspend, because it is not desirable in general.

The rule of thumb is that if you know you need to change the device's settings (eg. because of wakeup being enabled or not) for system suspend and that requires the device to be resumed, resume it. It can stay suspended otherwise.

Thanks Rafael.

Vinod, thinking about this some more, I am wondering if it is just better to get rid of the suspend/resume callbacks and simply handling the state in the runtime suspend/resume callbacks. I think that would be safe too, because once the clock has been disabled, then who knows what the context state will be.

Cheers
Jon

#9 lore raw

Re: [RFC PATCH 1/7] DMA: tegra-apb: Correct runtime-pm usage

Quoted 45 lines · Jon Hunter
Quoted 37 lines · Rafael J. Wysocki
Quoted 28 lines · Vinod Koul
Quoted 19 lines · Jon Hunter
Quoted 11 lines · Vinod Koul
Quoted 10 lines · Jon Hunter
Quoted 9 lines · Vinod Koul

Review static int tegra_dma_pm_suspend(struct device *dev) · line 1534

Quoted 6 lines · Jon Hunter
(quoted diff) +1 -1
@@ -1543,7 +1531,7 @@ static int tegra_dma_pm_suspend(struct device *dev)
  	int ret;
 
  	/* Enable clock before accessing register */
-	ret = tegra_dma_runtime_resume(dev);
+	ret = pm_runtime_get_sync(dev);

why is this required ?

Quoted 7 lines
Quoted 3 lines

Because the clock could be disabled when this function is called. This function saves the DMA context so that if the context is lost during suspend, it can be restored.

Have you verified this? Coz my understanding is that when PM does suspend it will esnure you are runtime resume if runtime suspended and then will do suspend.
So you do not need to do above

Quoted 8 lines

I see what you are saying. I did some testing with ftrace today to trace rpm and suspend/resume calls. If the dma controller is runtime suspended and I do not call pm_runtime_get_sync() above then I do not see any runtime resume of the dma controller prior to suspend. Now I was hoping that this would cause a complete kernel crash but it did not and so the DMA clock did not appear to be needed here (at least on the one board I tested). However, I would not go as far as to remove this and prefer to keep as above.

Quoted 1 line

Okay am adding Rafael here for his recommendations.

Well, and what is the question I'm supposed to answer, exactly?

I was in Seattle last week, so haven't been following this closely.

Quoted 3 lines

I have tested in past and if my driver was runtime suspended we were resumed prior to being suspended. So I am not sure why you did not see that behaviour, and if that is right we don't need to force resume here

Quoted 7 lines

We're adding code for skipping runtime-resume-before-system-suspend, because it is not desirable in general.

The rule of thumb is that if you know you need to change the device's settings (eg. because of wakeup being enabled or not) for system suspend and that requires the device to be resumed, resume it. It can stay suspended otherwise.

Quoted 7 lines

Thanks Rafael.

Vinod, thinking about this some more, I am wondering if it is just better to get rid of the suspend/resume callbacks and simply handling the state in the runtime suspend/resume callbacks. I think that would be safe too, because once the clock has been disabled, then who knows what the context state will be.

One caveat here: system suspend may be invoked at any time, so you need to ensure that the device is properly suspended when that happens.

I believe you at least need a ->suspend callback for that.

Cheers,
Rafael

author maintainer
#10 lore raw

Re: [RFC PATCH 1/7] DMA: tegra-apb: Correct runtime-pm usage

Quoted 1 line · Rafael J. Wysocki

On 8/25/2015 11:37 AM, Jon Hunter wrote:

[snip]

Quoted 10 lines
Quoted 5 lines

Vinod, thinking about this some more, I am wondering if it is just better to get rid of the suspend/resume callbacks and simply handling the state in the runtime suspend/resume callbacks. I think that would be safe too, because once the clock has been disabled, then who knows what the context state will be.

One caveat here: system suspend may be invoked at any time, so you need to ensure that the device is properly suspended when that happens.

I believe you at least need a ->suspend callback for that.

Thanks, makes sense.

On a related note, I see a few drivers, including this DMA driver doing the following in the driver ->remove callback.

    pm_runtime_disable(&pdev->dev);
        !pm_runtime_status_suspended(&pdev->dev))
            tegra_dma_runtime_suspend(&pdev->dev);

I understand that the code is trying to ensure that the device is suspended regardless of whether rpm is enabled or not in the kernel config. However, looking at the pm_runtime_status_suspended() function, AFAICT, it will always return false above as the disable_depth will be greater than 0. So I am concerned that the tegra_dma_runtime_suspend() is called even when not needed? However, I could also be missing something here.

Cheers
Jon

author maintainer
#11 lore raw

RFC PATCH 2/7 DMA: tegra-apb: Move code dealing with h/w registers into separate functions

In reply to Jon Hunter

In preparation for adding the Tegra210 ADMA driver, that is based upon the Tegra20-APB DMA driver, move code that accesses hardware registers into specific functions. The Tegra210 ADMA and Tegra20-APB DMA drivers are not compatible from a hardware register perspective, but the drivers are very much the same. Hence, by isolating code that deals with the hardware registers it will then be possible to add a function table to call code that accesses the hardware registers and re-use the common driver code for both DMAs.

---
 drivers/dma/tegra20-apb-dma.c | 277 ++++++++++++++++++++++++++----------------
 1 file changed, 170 insertions(+), 107 deletions(-)
drivers/dma/tegra20-apb-dma.c +170 -107
index 097432ea89fa..e552a4efef71 100644
@@ -359,6 +359,18 @@ static int tegra_dma_slave_config(struct dma_chan *dc,
 	return 0;
 }
 
+static u32 tegra_dma_get_xfer_count(struct tegra_dma_channel *tdc)
+{
+	u32 wcount;
+
+	if (tdc->tdma->chip_data->support_separate_wcount_reg)
+		wcount = tdc_read(tdc, TEGRA_APBDMA_CHAN_WORD_TRANSFER);
+	else
+		wcount = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
+
+	return (wcount & TEGRA_APBDMA_STATUS_COUNT_MASK) - 4;
+}
+
 static void tegra_dma_global_pause(struct tegra_dma_channel *tdc,
 	bool wait_for_burst_complete)
 {
@@ -394,6 +406,38 @@ out:
 	spin_unlock(&tdma->global_lock);
 }
 
+static u32 tegra_dma_irq_status(struct tegra_dma_channel *tdc)
+{
+	u32 status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
+
+	return status & TEGRA_APBDMA_STATUS_ISE_EOC;
+}
+
+static u32 tegra_dma_irq_clear(struct tegra_dma_channel *tdc)
+{
+	u32 status = tegra_dma_irq_status(tdc);
+
+	if (status) {
+		dev_dbg(tdc2dev(tdc), "%s():clearing interrupt\n", __func__);
+		tdc_write(tdc, TEGRA_APBDMA_CHAN_STATUS, status);
+	}
+
+	return status;
+}
+
+static void tegra_dma_program(struct tegra_dma_channel *tdc,
+			      struct tegra_dma_sg_req *nsg_req)
+{
+	tdc_write(tdc, TEGRA_APBDMA_CHAN_APBPTR, nsg_req->ch_regs.apb_ptr);
+	tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBPTR, nsg_req->ch_regs.ahb_ptr);
+	if (tdc->tdma->chip_data->support_separate_wcount_reg)
+		tdc_write(tdc, TEGRA_APBDMA_CHAN_WCOUNT,
+			  nsg_req->ch_regs.wcount);
+	tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR,
+		  nsg_req->ch_regs.csr | TEGRA_APBDMA_CSR_ENB);
+	nsg_req->configured = true;
+}
+
 static void tegra_dma_pause(struct tegra_dma_channel *tdc,
 	bool wait_for_burst_complete)
 {
@@ -423,7 +467,6 @@ static void tegra_dma_resume(struct tegra_dma_channel *tdc)
 static void tegra_dma_stop(struct tegra_dma_channel *tdc)
 {
 	u32 csr;
-	u32 status;
 
 	/* Disable interrupts */
 	csr = tdc_read(tdc, TEGRA_APBDMA_CHAN_CSR);
@@ -435,11 +478,8 @@ static void tegra_dma_stop(struct tegra_dma_channel *tdc)
 	tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR, csr);
 
 	/* Clear interrupt status if it is there */
-	status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
-	if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
-		dev_dbg(tdc2dev(tdc), "%s():clearing interrupt\n", __func__);
-		tdc_write(tdc, TEGRA_APBDMA_CHAN_STATUS, status);
-	}
+	tegra_dma_irq_clear(tdc);
+
 	tdc->busy = false;
 }
 
@@ -478,13 +518,13 @@ static void tegra_dma_configure_for_next(struct tegra_dma_channel *tdc,
 	 * load new configuration.
 	 */
 	tegra_dma_pause(tdc, false);
-	status  = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
+	status = tegra_dma_irq_status(tdc);
 
 	/*
 	 * If interrupt is pending then do nothing as the ISR will handle
 	 * the programing for new request.
 	 */
-	if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
+	if (status) {
 		dev_err(tdc2dev(tdc),
 			"Skipping new configuration as interrupt is pending\n");
 		tegra_dma_resume(tdc);
@@ -492,15 +532,7 @@ static void tegra_dma_configure_for_next(struct tegra_dma_channel *tdc,
 	}
 
 	/* Safe to program new configuration */
-	tdc_write(tdc, TEGRA_APBDMA_CHAN_APBPTR, nsg_req->ch_regs.apb_ptr);
-	tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBPTR, nsg_req->ch_regs.ahb_ptr);
-	if (tdc->tdma->chip_data->support_separate_wcount_reg)
-		tdc_write(tdc, TEGRA_APBDMA_CHAN_WCOUNT,
-						nsg_req->ch_regs.wcount);
-	tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR,
-				nsg_req->ch_regs.csr | TEGRA_APBDMA_CSR_ENB);
-	nsg_req->configured = true;
-
+	tegra_dma_program(tdc, nsg_req);
 	tegra_dma_resume(tdc);
 }
 
@@ -534,10 +566,10 @@ static void tdc_configure_next_head_desc(struct tegra_dma_channel *tdc)
 	}
 }
 
-static inline int get_current_xferred_count(struct tegra_dma_channel *tdc,
-	struct tegra_dma_sg_req *sg_req, unsigned long status)
+static inline int get_current_xferred_count(struct tegra_dma_sg_req *sg_req,
+					    unsigned long wcount)
 {
-	return sg_req->req_len - (status & TEGRA_APBDMA_STATUS_COUNT_MASK) - 4;
+	return sg_req->req_len - wcount;
 }
 
 static void tegra_dma_abort_all(struct tegra_dma_channel *tdc)
@@ -683,9 +715,8 @@ static irqreturn_t tegra_dma_isr(int irq, void *dev_id)
 
 	spin_lock_irqsave(&tdc->lock, flags);
 
-	status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
-	if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
-		tdc_write(tdc, TEGRA_APBDMA_CHAN_STATUS, status);
+	status = tegra_dma_irq_clear(tdc);
+	if (status) {
 		tdc->isr_handler(tdc, false);
 		tasklet_schedule(&tdc->tasklet);
 		spin_unlock_irqrestore(&tdc->lock, flags);
@@ -762,16 +793,13 @@ static int tegra_dma_terminate_all(struct dma_chan *dc)
 	/* Pause DMA before checking the queue status */
 	tegra_dma_pause(tdc, true);
 
-	status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
-	if (status & TEGRA_APBDMA_STATUS_ISE_EOC) {
+	status = tegra_dma_irq_status(tdc);
+	if (status) {
 		dev_dbg(tdc2dev(tdc), "%s():handling isr\n", __func__);
 		tdc->isr_handler(tdc, true);
-		status = tdc_read(tdc, TEGRA_APBDMA_CHAN_STATUS);
 	}
-	if (tdc->tdma->chip_data->support_separate_wcount_reg)
-		wcount = tdc_read(tdc, TEGRA_APBDMA_CHAN_WORD_TRANSFER);
-	else
-		wcount = status;
+
+	wcount = tegra_dma_get_xfer_count(tdc);
 
 	was_busy = tdc->busy;
 	tegra_dma_stop(tdc);
@@ -780,7 +808,7 @@ static int tegra_dma_terminate_all(struct dma_chan *dc)
 		sgreq = list_first_entry(&tdc->pending_sg_req,
 					typeof(*sgreq), node);
 		sgreq->dma_desc->bytes_transferred +=
-				get_current_xferred_count(tdc, sgreq, wcount);
+				get_current_xferred_count(sgreq, wcount);
 	}
 	tegra_dma_resume(tdc);
 
@@ -865,11 +893,27 @@ static inline int get_bus_width(struct tegra_dma_channel *tdc,
 }
 
 static inline int get_burst_size(struct tegra_dma_channel *tdc,
-	u32 burst_size, enum dma_slave_buswidth slave_bw, int len)
+				 enum dma_transfer_direction direction,
+				 int len)
 {
+	enum dma_slave_buswidth slave_bw;
+	u32 burst_size;
 	int burst_byte;
 	int burst_ahb_width;
 
+	switch (direction) {
+	case DMA_MEM_TO_DEV:
+		burst_size = tdc->dma_sconfig.dst_maxburst;
+		slave_bw = tdc->dma_sconfig.dst_addr_width;
+		break;
+	case DMA_DEV_TO_MEM:
+		burst_size = tdc->dma_sconfig.src_maxburst;
+		slave_bw = tdc->dma_sconfig.src_addr_width;
+		break;
+	default:
+		return TEGRA_APBDMA_AHBSEQ_BURST_1;
+	}
+
 	/*
 	 * burst_size from client is in terms of the bus_width.
 	 * convert them into AHB memory width which is 4 byte.
@@ -894,29 +938,23 @@ static inline int get_burst_size(struct tegra_dma_channel *tdc,
 		return TEGRA_APBDMA_AHBSEQ_BURST_8;
 }
 
-static int get_transfer_param(struct tegra_dma_channel *tdc,
-	enum dma_transfer_direction direction, unsigned long *apb_addr,
-	unsigned long *apb_seq,	unsigned long *csr, unsigned int *burst_size,
-	enum dma_slave_buswidth *slave_bw)
+static int tegra_dma_get_xfer_params(struct tegra_dma_channel *tdc,
+				     struct tegra_dma_channel_regs *ch_regs,
+				     enum dma_transfer_direction direction)
 {
-
 	switch (direction) {
 	case DMA_MEM_TO_DEV:
-		*apb_addr = tdc->dma_sconfig.dst_addr;
-		*apb_seq = get_bus_width(tdc, tdc->dma_sconfig.dst_addr_width);
-		*burst_size = tdc->dma_sconfig.dst_maxburst;
-		*slave_bw = tdc->dma_sconfig.dst_addr_width;
-		*csr = TEGRA_APBDMA_CSR_DIR;
+		ch_regs->apb_ptr = tdc->dma_sconfig.dst_addr;
+		ch_regs->apb_seq = get_bus_width(tdc,
+					tdc->dma_sconfig.dst_addr_width);
+		ch_regs->csr = TEGRA_APBDMA_CSR_DIR;
 		return 0;
-
 	case DMA_DEV_TO_MEM:
-		*apb_addr = tdc->dma_sconfig.src_addr;
-		*apb_seq = get_bus_width(tdc, tdc->dma_sconfig.src_addr_width);
-		*burst_size = tdc->dma_sconfig.src_maxburst;
-		*slave_bw = tdc->dma_sconfig.src_addr_width;
-		*csr = 0;
+		ch_regs->apb_ptr = tdc->dma_sconfig.src_addr;
+		ch_regs->apb_seq = get_bus_width(tdc,
+					tdc->dma_sconfig.src_addr_width);
+		ch_regs->csr = 0;
 		return 0;
-
 	default:
 		dev_err(tdc2dev(tdc), "Dma direction is not supported\n");
 		return -EINVAL;
@@ -924,6 +962,60 @@ static int get_transfer_param(struct tegra_dma_channel *tdc,
 	return -EINVAL;
 }
 
+static int tegra_dma_get_xfer_params_sg(struct tegra_dma_channel *tdc,
+					struct tegra_dma_sg_req *sg_req,
+					enum dma_transfer_direction direction,
+					unsigned int flags)
+{
+	struct tegra_dma_channel_regs *ch_regs = &sg_req->ch_regs;
+	int ret;
+
+	ret = tegra_dma_get_xfer_params(tdc, ch_regs, direction);
+	if (ret < 0)
+		return ret;
+
+	ch_regs->ahb_seq = TEGRA_APBDMA_AHBSEQ_INTR_ENB;
+	ch_regs->ahb_seq |= TEGRA_APBDMA_AHBSEQ_WRAP_NONE <<
+					TEGRA_APBDMA_AHBSEQ_WRAP_SHIFT;
+	ch_regs->ahb_seq |= TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_32;
+
+	ch_regs->csr |= TEGRA_APBDMA_CSR_ONCE | TEGRA_APBDMA_CSR_FLOW;
+	ch_regs->csr |= tdc->slave_id << TEGRA_APBDMA_CSR_REQ_SEL_SHIFT;
+	if (flags & DMA_PREP_INTERRUPT)
+		ch_regs->csr |= TEGRA_APBDMA_CSR_IE_EOC;
+
+	ch_regs->apb_seq |= TEGRA_APBDMA_APBSEQ_WRAP_WORD_1;
+
+	return 0;
+}
+
+static int tegra_dma_get_xfer_params_cyclic(struct tegra_dma_channel *tdc,
+					struct tegra_dma_sg_req *sg_req,
+					enum dma_transfer_direction direction,
+					unsigned int flags)
+{
+	struct tegra_dma_channel_regs *ch_regs = &sg_req->ch_regs;
+	int ret;
+
+	ret = tegra_dma_get_xfer_params(tdc, ch_regs, direction);
+	if (ret < 0)
+		return ret;
+
+	ch_regs->ahb_seq = TEGRA_APBDMA_AHBSEQ_INTR_ENB;
+	ch_regs->ahb_seq |= TEGRA_APBDMA_AHBSEQ_WRAP_NONE <<
+					TEGRA_APBDMA_AHBSEQ_WRAP_SHIFT;
+	ch_regs->ahb_seq |= TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_32;
+
+	ch_regs->csr |= TEGRA_APBDMA_CSR_FLOW;
+	if (flags & DMA_PREP_INTERRUPT)
+		ch_regs->csr |= TEGRA_APBDMA_CSR_IE_EOC;
+	ch_regs->csr |= tdc->slave_id << TEGRA_APBDMA_CSR_REQ_SEL_SHIFT;
+
+	ch_regs->apb_seq |= TEGRA_APBDMA_APBSEQ_WRAP_WORD_1;
+
+	return 0;
+}
+
 static void tegra_dma_prep_wcount(struct tegra_dma_channel *tdc,
 	struct tegra_dma_channel_regs *ch_regs, u32 len)
 {
@@ -935,6 +1027,24 @@ static void tegra_dma_prep_wcount(struct tegra_dma_channel *tdc,
 		ch_regs->csr |= len_field;
 }
 
+static void tegra_dma_set_xfer_params(struct tegra_dma_channel *tdc,
+				      struct tegra_dma_sg_req *sg_req,
+				      struct tegra_dma_sg_req *sg_base,
+				      enum dma_transfer_direction direction,
+				      u32 mem, u32 len)
+{
+	sg_req->ch_regs.ahb_seq |= get_burst_size(tdc, direction, len);
+	sg_req->ch_regs.apb_ptr = sg_base->ch_regs.apb_ptr;
+	sg_req->ch_regs.ahb_ptr = mem;
+	sg_req->ch_regs.csr = sg_base->ch_regs.csr;
+	tegra_dma_prep_wcount(tdc, &sg_req->ch_regs, len);
+	sg_req->ch_regs.apb_seq = sg_base->ch_regs.apb_seq;
+	sg_req->ch_regs.ahb_seq = sg_base->ch_regs.ahb_seq;
+	sg_req->configured = false;
+	sg_req->last_sg = false;
+	sg_req->req_len = len;
+}
+
 static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg(
 	struct dma_chan *dc, struct scatterlist *sgl, unsigned int sg_len,
 	enum dma_transfer_direction direction, unsigned long flags,
@@ -942,13 +1052,10 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg(
 {
 	struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
 	struct tegra_dma_desc *dma_desc;
-	unsigned int	    i;
-	struct scatterlist      *sg;
-	unsigned long csr, ahb_seq, apb_ptr, apb_seq;
+	unsigned int i;
+	struct scatterlist *sg;
 	struct list_head req_list;
-	struct tegra_dma_sg_req  *sg_req = NULL;
-	u32 burst_size;
-	enum dma_slave_buswidth slave_bw;
+	struct tegra_dma_sg_req sg_base, *sg_req = NULL;
 
 	if (!tdc->config_init) {
 		dev_err(tdc2dev(tdc), "dma channel is not configured\n");
@@ -959,24 +1066,11 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg(
 		return NULL;
 	}
 
-	if (get_transfer_param(tdc, direction, &apb_ptr, &apb_seq, &csr,
-				&burst_size, &slave_bw) < 0)
+	if (tegra_dma_get_xfer_params_sg(tdc, &sg_base, direction, flags) < 0)
 		return NULL;
 
 	INIT_LIST_HEAD(&req_list);
 
-	ahb_seq = TEGRA_APBDMA_AHBSEQ_INTR_ENB;
-	ahb_seq |= TEGRA_APBDMA_AHBSEQ_WRAP_NONE <<
-					TEGRA_APBDMA_AHBSEQ_WRAP_SHIFT;
-	ahb_seq |= TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_32;
-
-	csr |= TEGRA_APBDMA_CSR_ONCE | TEGRA_APBDMA_CSR_FLOW;
-	csr |= tdc->slave_id << TEGRA_APBDMA_CSR_REQ_SEL_SHIFT;
-	if (flags & DMA_PREP_INTERRUPT)
-		csr |= TEGRA_APBDMA_CSR_IE_EOC;
-
-	apb_seq |= TEGRA_APBDMA_APBSEQ_WRAP_WORD_1;
-
 	dma_desc = tegra_dma_desc_get(tdc);
 	if (!dma_desc) {
 		dev_err(tdc2dev(tdc), "Dma descriptors not available\n");
@@ -1011,19 +1105,11 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg(
 			return NULL;
 		}
 
-		ahb_seq |= get_burst_size(tdc, burst_size, slave_bw, len);
 		dma_desc->bytes_requested += len;
 
-		sg_req->ch_regs.apb_ptr = apb_ptr;
-		sg_req->ch_regs.ahb_ptr = mem;
-		sg_req->ch_regs.csr = csr;
-		tegra_dma_prep_wcount(tdc, &sg_req->ch_regs, len);
-		sg_req->ch_regs.apb_seq = apb_seq;
-		sg_req->ch_regs.ahb_seq = ahb_seq;
-		sg_req->configured = false;
-		sg_req->last_sg = false;
+		tegra_dma_set_xfer_params(tdc, sg_req, &sg_base, direction,
+					  mem, len);
 		sg_req->dma_desc = dma_desc;
-		sg_req->req_len = len;
 
 		list_add_tail(&sg_req->node, &dma_desc->tx_list);
 	}
@@ -1056,13 +1142,10 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_dma_cyclic(
 {
 	struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
 	struct tegra_dma_desc *dma_desc = NULL;
-	struct tegra_dma_sg_req  *sg_req = NULL;
-	unsigned long csr, ahb_seq, apb_ptr, apb_seq;
+	struct tegra_dma_sg_req sg_base, *sg_req = NULL;
 	int len;
 	size_t remain_len;
 	dma_addr_t mem = buf_addr;
-	u32 burst_size;
-	enum dma_slave_buswidth slave_bw;
 
 	if (!buf_len || !period_len) {
 		dev_err(tdc2dev(tdc), "Invalid buffer/period len\n");
@@ -1101,22 +1184,10 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_dma_cyclic(
 		return NULL;
 	}
 
-	if (get_transfer_param(tdc, direction, &apb_ptr, &apb_seq, &csr,
-				&burst_size, &slave_bw) < 0)
+	if (tegra_dma_get_xfer_params_cyclic(tdc, &sg_base, direction,
+					     flags) < 0)
 		return NULL;
 
-	ahb_seq = TEGRA_APBDMA_AHBSEQ_INTR_ENB;
-	ahb_seq |= TEGRA_APBDMA_AHBSEQ_WRAP_NONE <<
-					TEGRA_APBDMA_AHBSEQ_WRAP_SHIFT;
-	ahb_seq |= TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_32;
-
-	csr |= TEGRA_APBDMA_CSR_FLOW;
-	if (flags & DMA_PREP_INTERRUPT)
-		csr |= TEGRA_APBDMA_CSR_IE_EOC;
-	csr |= tdc->slave_id << TEGRA_APBDMA_CSR_REQ_SEL_SHIFT;
-
-	apb_seq |= TEGRA_APBDMA_APBSEQ_WRAP_WORD_1;
-
 	dma_desc = tegra_dma_desc_get(tdc);
 	if (!dma_desc) {
 		dev_err(tdc2dev(tdc), "not enough descriptors available\n");
@@ -1140,17 +1211,9 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_dma_cyclic(
 			return NULL;
 		}
 
-		ahb_seq |= get_burst_size(tdc, burst_size, slave_bw, len);
-		sg_req->ch_regs.apb_ptr = apb_ptr;
-		sg_req->ch_regs.ahb_ptr = mem;
-		sg_req->ch_regs.csr = csr;
-		tegra_dma_prep_wcount(tdc, &sg_req->ch_regs, len);
-		sg_req->ch_regs.apb_seq = apb_seq;
-		sg_req->ch_regs.ahb_seq = ahb_seq;
-		sg_req->configured = false;
-		sg_req->last_sg = false;
+		tegra_dma_set_xfer_params(tdc, sg_req, &sg_base, direction,
+					  mem, len);
 		sg_req->dma_desc = dma_desc;
-		sg_req->req_len = len;
 
 		list_add_tail(&sg_req->node, &dma_desc->tx_list);
 		remain_len -= len;
Signature · 1 line
2.1.4
author maintainer
#12 lore raw

RFC PATCH 3/7 DMA: tegra-apb: Clean-up and simplify setting up of transfer parameters

In reply to Jon Hunter

Most of the DMA transfer parameters that are configured for scatter-gather or cyclic transfers are the same. Therefore, move the setup of common parameters into the tegra_dma_get_xfer_params() function used for both scatter-gather and cyclic transfers.

Note that TEGRA_APBDMA_AHBSEQ_WRAP_NONE is defined as 0 and so this setting can be completely removed.

---
 drivers/dma/tegra20-apb-dma.c | 53 ++++++++++++++++---------------------------
 1 file changed, 19 insertions(+), 34 deletions(-)
drivers/dma/tegra20-apb-dma.c +19 -34
index e552a4efef71..c1eb25075756 100644
@@ -940,7 +940,8 @@ static inline int get_burst_size(struct tegra_dma_channel *tdc,
 
 static int tegra_dma_get_xfer_params(struct tegra_dma_channel *tdc,
 				     struct tegra_dma_channel_regs *ch_regs,
-				     enum dma_transfer_direction direction)
+				     enum dma_transfer_direction direction,
+				     unsigned int flags)
 {
 	switch (direction) {
 	case DMA_MEM_TO_DEV:
@@ -948,48 +949,32 @@ static int tegra_dma_get_xfer_params(struct tegra_dma_channel *tdc,
 		ch_regs->apb_seq = get_bus_width(tdc,
 					tdc->dma_sconfig.dst_addr_width);
 		ch_regs->csr = TEGRA_APBDMA_CSR_DIR;
-		return 0;
+		break;
 	case DMA_DEV_TO_MEM:
 		ch_regs->apb_ptr = tdc->dma_sconfig.src_addr;
 		ch_regs->apb_seq = get_bus_width(tdc,
 					tdc->dma_sconfig.src_addr_width);
 		ch_regs->csr = 0;
-		return 0;
+		break;
 	default:
 		dev_err(tdc2dev(tdc), "Dma direction is not supported\n");
 		return -EINVAL;
 	}
-	return -EINVAL;
-}
-
-static int tegra_dma_get_xfer_params_sg(struct tegra_dma_channel *tdc,
-					struct tegra_dma_sg_req *sg_req,
-					enum dma_transfer_direction direction,
-					unsigned int flags)
-{
-	struct tegra_dma_channel_regs *ch_regs = &sg_req->ch_regs;
-	int ret;
-
-	ret = tegra_dma_get_xfer_params(tdc, ch_regs, direction);
-	if (ret < 0)
-		return ret;
 
+	ch_regs->apb_seq |= TEGRA_APBDMA_APBSEQ_WRAP_WORD_1;
 	ch_regs->ahb_seq = TEGRA_APBDMA_AHBSEQ_INTR_ENB;
-	ch_regs->ahb_seq |= TEGRA_APBDMA_AHBSEQ_WRAP_NONE <<
-					TEGRA_APBDMA_AHBSEQ_WRAP_SHIFT;
 	ch_regs->ahb_seq |= TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_32;
 
-	ch_regs->csr |= TEGRA_APBDMA_CSR_ONCE | TEGRA_APBDMA_CSR_FLOW;
+	ch_regs->csr |= TEGRA_APBDMA_CSR_FLOW;
 	ch_regs->csr |= tdc->slave_id << TEGRA_APBDMA_CSR_REQ_SEL_SHIFT;
+
 	if (flags & DMA_PREP_INTERRUPT)
 		ch_regs->csr |= TEGRA_APBDMA_CSR_IE_EOC;
 
-	ch_regs->apb_seq |= TEGRA_APBDMA_APBSEQ_WRAP_WORD_1;
-
 	return 0;
 }
 
-static int tegra_dma_get_xfer_params_cyclic(struct tegra_dma_channel *tdc,
+static int tegra_dma_get_xfer_params_sg(struct tegra_dma_channel *tdc,
 					struct tegra_dma_sg_req *sg_req,
 					enum dma_transfer_direction direction,
 					unsigned int flags)
@@ -997,23 +982,23 @@ static int tegra_dma_get_xfer_params_cyclic(struct tegra_dma_channel *tdc,
 	struct tegra_dma_channel_regs *ch_regs = &sg_req->ch_regs;
 	int ret;
 
-	ret = tegra_dma_get_xfer_params(tdc, ch_regs, direction);
+	ret = tegra_dma_get_xfer_params(tdc, ch_regs, direction, flags);
 	if (ret < 0)
 		return ret;
 
-	ch_regs->ahb_seq = TEGRA_APBDMA_AHBSEQ_INTR_ENB;
-	ch_regs->ahb_seq |= TEGRA_APBDMA_AHBSEQ_WRAP_NONE <<
-					TEGRA_APBDMA_AHBSEQ_WRAP_SHIFT;
-	ch_regs->ahb_seq |= TEGRA_APBDMA_AHBSEQ_BUS_WIDTH_32;
+	ch_regs->csr |= TEGRA_APBDMA_CSR_ONCE;
 
-	ch_regs->csr |= TEGRA_APBDMA_CSR_FLOW;
-	if (flags & DMA_PREP_INTERRUPT)
-		ch_regs->csr |= TEGRA_APBDMA_CSR_IE_EOC;
-	ch_regs->csr |= tdc->slave_id << TEGRA_APBDMA_CSR_REQ_SEL_SHIFT;
+	return 0;
+}
 
-	ch_regs->apb_seq |= TEGRA_APBDMA_APBSEQ_WRAP_WORD_1;
+static int tegra_dma_get_xfer_params_cyclic(struct tegra_dma_channel *tdc,
+					struct tegra_dma_sg_req *sg_req,
+					enum dma_transfer_direction direction,
+					unsigned int flags)
+{
+	struct tegra_dma_channel_regs *ch_regs = &sg_req->ch_regs;
 
-	return 0;
+	return tegra_dma_get_xfer_params(tdc, ch_regs, direction, flags);
 }
 
 static void tegra_dma_prep_wcount(struct tegra_dma_channel *tdc,
Signature · 1 line
2.1.4
author maintainer
#13 lore raw

RFC PATCH 4/7 DMA: tegra-apb: Add a function table for functions dealing with registers

In reply to Jon Hunter

In preparation for adding the Tegra210 ADMA driver, add a function table for calling functions that access hardware registers. This way code that is common between the Tegra20-APB DMA and Tegra210 DMA driver can be moved into a separate source file and used by both DMA drivers.

Note that all function pointers in the table are compulsory and so no checking that the function pointer is valid is performed.

---
 drivers/dma/tegra20-apb-dma.c | 92 +++++++++++++++++++++++++++++++++----------
 1 file changed, 71 insertions(+), 21 deletions(-)
drivers/dma/tegra20-apb-dma.c +71 -21
index c1eb25075756..7947acdf23db 100644
@@ -209,6 +209,33 @@ struct tegra_dma_channel {
 	struct tegra_dma_channel_regs	channel_reg;
 };
 
+struct tegra_dma_ops {
+	u32 (*get_xfer_count)(struct tegra_dma_channel *tdc);
+	int (*get_xfer_params_cyclic)(struct tegra_dma_channel *tdc,
+				      struct tegra_dma_sg_req *sg_req,
+				      enum dma_transfer_direction direction,
+				      unsigned int flags);
+	int (*get_xfer_params_sg)(struct tegra_dma_channel *tdc,
+				  struct tegra_dma_sg_req *sg_req,
+				  enum dma_transfer_direction direction,
+				  unsigned int flags);
+	u32 (*irq_clear)(struct tegra_dma_channel *tdc);
+	u32 (*irq_status)(struct tegra_dma_channel *tdc);
+	void (*pause)(struct tegra_dma_channel *tdc,
+		      bool wait_for_burst_complete);
+	void (*program)(struct tegra_dma_channel *tdc,
+			struct tegra_dma_sg_req *sg_req);
+	void (*resume)(struct tegra_dma_channel *tdc);
+	void (*set_xfer_params)(struct tegra_dma_channel *tdc,
+				struct tegra_dma_sg_req *sg_req,
+				struct tegra_dma_sg_req *sg_base,
+				enum dma_transfer_direction direction,
+				u32 mem, u32 len);
+	void (*start)(struct tegra_dma_channel *tdc,
+		      struct tegra_dma_sg_req *sg_req);
+	void (*stop)(struct tegra_dma_channel *tdc);
+};
+
 /* tegra_dma: Tegra DMA specific information */
 struct tegra_dma {
 	struct dma_device		dma_dev;
@@ -218,6 +245,7 @@ struct tegra_dma {
 	spinlock_t			global_lock;
 	void __iomem			*base_addr;
 	const struct tegra_dma_chip_data *chip_data;
+	const struct tegra_dma_ops	*ops;
 
 	/*
 	 * Counter for managing global pausing of the DMA controller.
@@ -504,6 +532,7 @@ static void tegra_dma_start(struct tegra_dma_channel *tdc,
 static void tegra_dma_configure_for_next(struct tegra_dma_channel *tdc,
 		struct tegra_dma_sg_req *nsg_req)
 {
+	const struct tegra_dma_ops *ops = tdc->tdma->ops;
 	unsigned long status;
 
 	/*
@@ -517,8 +546,8 @@ static void tegra_dma_configure_for_next(struct tegra_dma_channel *tdc,
 	 * If there is already IEC status then interrupt handler need to
 	 * load new configuration.
 	 */
-	tegra_dma_pause(tdc, false);
-	status = tegra_dma_irq_status(tdc);
+	ops->pause(tdc, false);
+	status = ops->irq_status(tdc);
 
 	/*
 	 * If interrupt is pending then do nothing as the ISR will handle
@@ -527,17 +556,18 @@ static void tegra_dma_configure_for_next(struct tegra_dma_channel *tdc,
 	if (status) {
 		dev_err(tdc2dev(tdc),
 			"Skipping new configuration as interrupt is pending\n");
-		tegra_dma_resume(tdc);
+		ops->resume(tdc);
 		return;
 	}
 
 	/* Safe to program new configuration */
-	tegra_dma_program(tdc, nsg_req);
-	tegra_dma_resume(tdc);
+	ops->program(tdc, nsg_req);
+	ops->resume(tdc);
 }
 
 static void tdc_start_head_req(struct tegra_dma_channel *tdc)
 {
+	const struct tegra_dma_ops *ops = tdc->tdma->ops;
 	struct tegra_dma_sg_req *sg_req;
 
 	if (list_empty(&tdc->pending_sg_req))
@@ -545,7 +575,7 @@ static void tdc_start_head_req(struct tegra_dma_channel *tdc)
 
 	sg_req = list_first_entry(&tdc->pending_sg_req,
 					typeof(*sg_req), node);
-	tegra_dma_start(tdc, sg_req);
+	ops->start(tdc, sg_req);
 	sg_req->configured = true;
 	tdc->busy = true;
 }
@@ -599,11 +629,12 @@ static void tegra_dma_abort_all(struct tegra_dma_channel *tdc)
 static bool handle_continuous_head_request(struct tegra_dma_channel *tdc,
 		struct tegra_dma_sg_req *last_sg_req, bool to_terminate)
 {
+	const struct tegra_dma_ops *ops = tdc->tdma->ops;
 	struct tegra_dma_sg_req *hsgreq = NULL;
 
 	if (list_empty(&tdc->pending_sg_req)) {
 		dev_err(tdc2dev(tdc), "Dma is running without req\n");
-		tegra_dma_stop(tdc);
+		ops->stop(tdc);
 		return false;
 	}
 
@@ -614,7 +645,7 @@ static bool handle_continuous_head_request(struct tegra_dma_channel *tdc,
 	 */
 	hsgreq = list_first_entry(&tdc->pending_sg_req, typeof(*hsgreq), node);
 	if (!hsgreq->configured) {
-		tegra_dma_stop(tdc);
+		ops->stop(tdc);
 		dev_err(tdc2dev(tdc), "Error in dma transfer, aborting dma\n");
 		tegra_dma_abort_all(tdc);
 		return false;
@@ -710,12 +741,13 @@ static void tegra_dma_tasklet(unsigned long data)
 static irqreturn_t tegra_dma_isr(int irq, void *dev_id)
 {
 	struct tegra_dma_channel *tdc = dev_id;
+	const struct tegra_dma_ops *ops = tdc->tdma->ops;
 	unsigned long status;
 	unsigned long flags;
 
 	spin_lock_irqsave(&tdc->lock, flags);
 
-	status = tegra_dma_irq_clear(tdc);
+	status = ops->irq_clear(tdc);
 	if (status) {
 		tdc->isr_handler(tdc, false);
 		tasklet_schedule(&tdc->tasklet);
@@ -774,6 +806,7 @@ end:
 static int tegra_dma_terminate_all(struct dma_chan *dc)
 {
 	struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+	const struct tegra_dma_ops *ops = tdc->tdma->ops;
 	struct tegra_dma_sg_req *sgreq;
 	struct tegra_dma_desc *dma_desc;
 	unsigned long flags;
@@ -791,18 +824,18 @@ static int tegra_dma_terminate_all(struct dma_chan *dc)
 		goto skip_dma_stop;
 
 	/* Pause DMA before checking the queue status */
-	tegra_dma_pause(tdc, true);
+	ops->pause(tdc, true);
 
-	status = tegra_dma_irq_status(tdc);
+	status = ops->irq_status(tdc);
 	if (status) {
 		dev_dbg(tdc2dev(tdc), "%s():handling isr\n", __func__);
 		tdc->isr_handler(tdc, true);
 	}
 
-	wcount = tegra_dma_get_xfer_count(tdc);
+	wcount = ops->get_xfer_count(tdc);
 
 	was_busy = tdc->busy;
-	tegra_dma_stop(tdc);
+	ops->stop(tdc);
 
 	if (!list_empty(&tdc->pending_sg_req) && was_busy) {
 		sgreq = list_first_entry(&tdc->pending_sg_req,
@@ -810,7 +843,7 @@ static int tegra_dma_terminate_all(struct dma_chan *dc)
 		sgreq->dma_desc->bytes_transferred +=
 				get_current_xferred_count(sgreq, wcount);
 	}
-	tegra_dma_resume(tdc);
+	ops->resume(tdc);
 
 skip_dma_stop:
 	tegra_dma_abort_all(tdc);
@@ -1036,6 +1069,7 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg(
 	void *context)
 {
 	struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+	const struct tegra_dma_ops *ops = tdc->tdma->ops;
 	struct tegra_dma_desc *dma_desc;
 	unsigned int i;
 	struct scatterlist *sg;
@@ -1051,7 +1085,7 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg(
 		return NULL;
 	}
 
-	if (tegra_dma_get_xfer_params_sg(tdc, &sg_base, direction, flags) < 0)
+	if (ops->get_xfer_params_sg(tdc, &sg_base, direction, flags) < 0)
 		return NULL;
 
 	INIT_LIST_HEAD(&req_list);
@@ -1092,8 +1126,8 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_slave_sg(
 
 		dma_desc->bytes_requested += len;
 
-		tegra_dma_set_xfer_params(tdc, sg_req, &sg_base, direction,
-					  mem, len);
+		ops->set_xfer_params(tdc, sg_req, &sg_base, direction, mem,
+				     len);
 		sg_req->dma_desc = dma_desc;
 
 		list_add_tail(&sg_req->node, &dma_desc->tx_list);
@@ -1126,6 +1160,7 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_dma_cyclic(
 	unsigned long flags)
 {
 	struct tegra_dma_channel *tdc = to_tegra_dma_chan(dc);
+	const struct tegra_dma_ops *ops = tdc->tdma->ops;
 	struct tegra_dma_desc *dma_desc = NULL;
 	struct tegra_dma_sg_req sg_base, *sg_req = NULL;
 	int len;
@@ -1169,8 +1204,7 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_dma_cyclic(
 		return NULL;
 	}
 
-	if (tegra_dma_get_xfer_params_cyclic(tdc, &sg_base, direction,
-					     flags) < 0)
+	if (ops->get_xfer_params_cyclic(tdc, &sg_base, direction, flags) < 0)
 		return NULL;
 
 	dma_desc = tegra_dma_desc_get(tdc);
@@ -1196,8 +1230,8 @@ static struct dma_async_tx_descriptor *tegra_dma_prep_dma_cyclic(
 			return NULL;
 		}
 
-		tegra_dma_set_xfer_params(tdc, sg_req, &sg_base, direction,
-					  mem, len);
+		ops->set_xfer_params(tdc, sg_req, &sg_base, direction, mem,
+				     len);
 		sg_req->dma_desc = dma_desc;
 
 		list_add_tail(&sg_req->node, &dma_desc->tx_list);
@@ -1354,6 +1388,20 @@ static const struct of_device_id tegra_dma_of_match[] = {
 };
 MODULE_DEVICE_TABLE(of, tegra_dma_of_match);
 
+static const struct tegra_dma_ops tegra_apb_ops = {
+	.get_xfer_count		= tegra_dma_get_xfer_count,
+	.get_xfer_params_cyclic	= tegra_dma_get_xfer_params_cyclic,
+	.get_xfer_params_sg	= tegra_dma_get_xfer_params_sg,
+	.irq_clear		= tegra_dma_irq_clear,
+	.irq_status		= tegra_dma_irq_status,
+	.pause			= tegra_dma_pause,
+	.program		= tegra_dma_program,
+	.resume			= tegra_dma_resume,
+	.set_xfer_params	= tegra_dma_set_xfer_params,
+	.start			= tegra_dma_start,
+	.stop			= tegra_dma_stop,
+};
+
 static int tegra_dma_probe(struct platform_device *pdev)
 {
 	struct resource	*res;
@@ -1495,6 +1543,8 @@ static int tegra_dma_probe(struct platform_device *pdev)
 	tdma->dma_dev.device_tx_status = tegra_dma_tx_status;
 	tdma->dma_dev.device_issue_pending = tegra_dma_issue_pending;
 
+	tdma->ops = &tegra_apb_ops;
+
 	ret = dma_async_device_register(&tdma->dma_dev);
 	if (ret < 0) {
 		dev_err(&pdev->dev,
Signature · 1 line
2.1.4
author maintainer
#14 lore raw

RFC PATCH 5/7 DMA: tegra-apb: Move common code into separate source files

In reply to Jon Hunter

Move code that is common between the Tegra20-APB DMA and Tegra210 ADMA driver into separate source files.

---
 drivers/dma/Kconfig           |   4 +
 drivers/dma/Makefile          |   1 +
 drivers/dma/tegra-common.c    | 733 ++++++++++++++++++++++++++++++++++
 drivers/dma/tegra-common.h    | 226 +++++++++++
 drivers/dma/tegra20-apb-dma.c | 910 +-----------------------------------------
 5 files changed, 972 insertions(+), 902 deletions(-)
 create mode 100644 drivers/dma/tegra-common.c
 create mode 100644 drivers/dma/tegra-common.h
drivers/dma/Kconfig +4 -0
index ff50af3f1bb0..dd79b0bf0876 100644
@@ -189,10 +189,14 @@ 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_COMMON
+	bool
+
 config TEGRA20_APB_DMA
 	bool "NVIDIA Tegra20 APB DMA support"
 	depends on ARCH_TEGRA
 	select DMA_ENGINE
+	select TEGRA_DMA_COMMON
 	help
 	  Support for the NVIDIA Tegra20 APB DMA controller driver. The
 	  DMA controller is having multiple DMA channel which can be
drivers/dma/Makefile +1 -0
index 264eb3c52446..d9c2bf5ef0bd 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_SIRF_DMA) += sirf-dma.o
 obj-$(CONFIG_TI_EDMA) += edma.o
 obj-$(CONFIG_STE_DMA40) += ste_dma40.o ste_dma40_ll.o
 obj-$(CONFIG_TEGRA20_APB_DMA) += tegra20-apb-dma.o
+obj-$(CONFIG_TEGRA_DMA_COMMON) += tegra-common.o
 obj-$(CONFIG_S3C24XX_DMAC) += s3c24xx-dma.o
 obj-$(CONFIG_PL330_DMA) += pl330.o
 obj-$(CONFIG_PCH_DMA) += pch_dma.o
drivers/dma/tegra-common.c new file +733 -0

733 lines not on this page · raw message

drivers/dma/tegra-common.h new file +226 -0

226 lines not on this page · raw message

drivers/dma/tegra20-apb-dma.c +8 -902

973 lines not on this page · raw message

Signature · 1 line
2.1.4
author maintainer
#15 lore raw

RFC PATCH 6/7 Documentation: DT: Add binding documentation for NVIDIA ADMA

In reply to Jon Hunter

Add device-tree binding documentation for the Tegra210 Audio DMA controller.

Cc Rob Herring <[email protected]>
Cc Pawel Moll <[email protected]>
Cc Mark Rutland <[email protected]>
Cc Ian Campbell <[email protected]>
Cc Kumar Gala <[email protected]>
---
 .../devicetree/bindings/dma/tegra210-adma.txt      | 49 ++++++++++++++++++++++
 1 file changed, 49 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/dma/tegra210-adma.txt
Documentation/devicetree/bindings/dma/tegra210-adma.txt new file +49 -0
new file mode 100644
index 000000000000..38310d7e7e77
@@ -0,0 +1,49 @@
+* NVIDIA Tegra Audio DMA controller
+
+Required properties:
+- compatible: Should be "nvidia,<chip>-adma"
+- reg: Should contain DMA registers location and length. This should include
+  all of the per-channel registers.
+- interrupt-parent: Phandle to the interrupt parent controller.
+- interrupts: Should contain all of the per-channel DMA interrupts.
+- clocks: Must contain two entries, one for the power-domain clock and one
+  for the module clock.
+  See ../clocks/clock-bindings.txt for details.
+- #dma-cells : Must be <1>. This dictates the length of DMA specifiers in
+  client nodes' dmas properties. The specifier represents the DMA request
+  select value for the peripheral. For more details, consult the Tegra TRM's
+  documentation of the APB DMA channel control register REQ_SEL field.
+
+Examples:
+
+adma: adma@702e2000 {
+	compatible = "nvidia,tegra210-adma";
+	reg = <0x0 0x702e2000 0x0 0x2000>;
+	interrupt-parent = <&tegra_agic>;
+	interrupts = <GIC_SPI INT_ADMA_EOT0 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT1 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT2 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT3 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT4 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT5 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT6 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT7 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT8 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT9 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT10 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT11 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT12 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT13 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT14 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT15 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT16 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT17 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT18 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT19 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT20 IRQ_TYPE_LEVEL_HIGH>,
+		     <GIC_SPI INT_ADMA_EOT21 IRQ_TYPE_LEVEL_HIGH>;
+	clocks = <&tegra_car TEGRA210_CLK_D_AUDIO>,
+		 <&tegra_car TEGRA210_CLK_ADMA_APE>;
+	clock-names = "adma", "adma.ape";
+	#dma-cells = <1>;
+};
Signature · 6 lines
2.1.4

--
To unsubscribe from this list: send the line "unsubscribe devicetree" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#16 lore raw

RFC PATCH 7/7 DMA: tegra-adma: Add support for Tegra210 ADMA

In reply to Jon Hunter

Add support for the Tegra210 Audio DMA controller that is used for transferring data between system memory and the Audio sub-system.

This driver is based upon the work by Dara Ramesh <[email protected]>.

---
 drivers/dma/Kconfig           |  12 +
 drivers/dma/Makefile          |   1 +
 drivers/dma/tegra-common.c    |   3 +-
 drivers/dma/tegra-common.h    |  42 ++-
 drivers/dma/tegra20-apb-dma.c |  37 +--
 drivers/dma/tegra210-adma.c   | 710 ++++++++++++++++++++++++++++++++++++++++++
 6 files changed, 782 insertions(+), 23 deletions(-)
 create mode 100644 drivers/dma/tegra210-adma.c
drivers/dma/Kconfig +12 -0
index dd79b0bf0876..25b474965d66 100644
@@ -205,6 +205,18 @@ config TEGRA20_APB_DMA
 	  This DMA controller transfers data from memory to peripheral fifo
 	  or vice versa. It does not support memory to memory data transfer.
 
+config TEGRA210_ADMA
+	bool "NVIDIA Tegra210 ADMA support"
+	depends on ARCH_TEGRA
+	select DMA_ENGINE
+	select TEGRA_DMA_COMMON
+	help
+	  Support for the NVIDIA Tegra210 ADMA controller driver. The
+	  DMA controller is having multiple DMA channel and it configured
+	  for audio. This DMA controller transfers data from memory to
+	  peripheral fifo or vice versa. It does not support memory to
+	  memory data transfer.
+
 config S3C24XX_DMAC
 	tristate "Samsung S3C24XX DMA support"
 	depends on ARCH_S3C24XX
drivers/dma/Makefile +1 -0
index d9c2bf5ef0bd..9c5b8afc53a1 100644
@@ -32,6 +32,7 @@ obj-$(CONFIG_SIRF_DMA) += sirf-dma.o
 obj-$(CONFIG_TI_EDMA) += edma.o
 obj-$(CONFIG_STE_DMA40) += ste_dma40.o ste_dma40_ll.o
 obj-$(CONFIG_TEGRA20_APB_DMA) += tegra20-apb-dma.o
+obj-$(CONFIG_TEGRA210_ADMA) += tegra210-adma.o
 obj-$(CONFIG_TEGRA_DMA_COMMON) += tegra-common.o
 obj-$(CONFIG_S3C24XX_DMAC) += s3c24xx-dma.o
 obj-$(CONFIG_PL330_DMA) += pl330.o
drivers/dma/tegra-common.c +2 -1
index fff0a143f5bb..b3f7e3322c15 100644
@@ -620,7 +620,8 @@ struct dma_async_tx_descriptor *tegra_dma_prep_dma_cyclic(
 		return NULL;
 	}
 
-	if (ops->get_xfer_params_cyclic(tdc, &sg_base, direction, flags) < 0)
+	if (ops->get_xfer_params_cyclic(tdc, &sg_base, buf_len, period_len,
+					direction, flags) < 0)
 		return NULL;
 
 	dma_desc = tegra_dma_desc_get(tdc);
drivers/dma/tegra-common.h +38 -4

90 lines not on this page · raw message

drivers/dma/tegra20-apb-dma.c +19 -18
index 0895732aaa28..b800f10860eb 100644
@@ -188,13 +188,13 @@ static u32 tegra_dma_irq_clear(struct tegra_dma_channel *tdc)
 static void tegra_dma_program(struct tegra_dma_channel *tdc,
 			      struct tegra_dma_sg_req *nsg_req)
 {
-	tdc_write(tdc, TEGRA_APBDMA_CHAN_APBPTR, nsg_req->ch_regs.apb_ptr);
-	tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBPTR, nsg_req->ch_regs.ahb_ptr);
+	tdc_write(tdc, TEGRA_APBDMA_CHAN_APBPTR, nsg_req->apb_ch_regs.apb_ptr);
+	tdc_write(tdc, TEGRA_APBDMA_CHAN_AHBPTR, nsg_req->apb_ch_regs.ahb_ptr);
 	if (tdc->tdma->chip_data->support_separate_wcount_reg)
 		tdc_write(tdc, TEGRA_APBDMA_CHAN_WCOUNT,
-			  nsg_req->ch_regs.wcount);
+			  nsg_req->apb_ch_regs.wcount);
 	tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR,
-		  nsg_req->ch_regs.csr | TEGRA_APBDMA_CSR_ENB);
+		  nsg_req->apb_ch_regs.csr | TEGRA_APBDMA_CSR_ENB);
 	nsg_req->configured = true;
 }
 
@@ -246,7 +246,7 @@ static void tegra_dma_stop(struct tegra_dma_channel *tdc)
 static void tegra_dma_start(struct tegra_dma_channel *tdc,
 		struct tegra_dma_sg_req *sg_req)
 {
-	struct tegra_dma_channel_regs *ch_regs = &sg_req->ch_regs;
+	struct tegra_apb_chan_regs *ch_regs = &sg_req->apb_ch_regs;
 
 	tdc_write(tdc, TEGRA_APBDMA_CHAN_CSR, ch_regs->csr);
 	tdc_write(tdc, TEGRA_APBDMA_CHAN_APBSEQ, ch_regs->apb_seq);
@@ -327,7 +327,7 @@ static inline int get_burst_size(struct tegra_dma_channel *tdc,
 }
 
 static int tegra_dma_get_xfer_params(struct tegra_dma_channel *tdc,
-				     struct tegra_dma_channel_regs *ch_regs,
+				     struct tegra_apb_chan_regs *ch_regs,
 				     enum dma_transfer_direction direction,
 				     unsigned int flags)
 {
@@ -367,7 +367,7 @@ static int tegra_dma_get_xfer_params_sg(struct tegra_dma_channel *tdc,
 					enum dma_transfer_direction direction,
 					unsigned int flags)
 {
-	struct tegra_dma_channel_regs *ch_regs = &sg_req->ch_regs;
+	struct tegra_apb_chan_regs *ch_regs = &sg_req->apb_ch_regs;
 	int ret;
 
 	ret = tegra_dma_get_xfer_params(tdc, ch_regs, direction, flags);
@@ -381,16 +381,17 @@ static int tegra_dma_get_xfer_params_sg(struct tegra_dma_channel *tdc,
 
 static int tegra_dma_get_xfer_params_cyclic(struct tegra_dma_channel *tdc,
 					struct tegra_dma_sg_req *sg_req,
+					size_t buf_len, size_t period_len,
 					enum dma_transfer_direction direction,
 					unsigned int flags)
 {
-	struct tegra_dma_channel_regs *ch_regs = &sg_req->ch_regs;
+	struct tegra_apb_chan_regs *ch_regs = &sg_req->apb_ch_regs;
 
 	return tegra_dma_get_xfer_params(tdc, ch_regs, direction, flags);
 }
 
 static void tegra_dma_prep_wcount(struct tegra_dma_channel *tdc,
-	struct tegra_dma_channel_regs *ch_regs, u32 len)
+	struct tegra_apb_chan_regs *ch_regs, u32 len)
 {
 	u32 len_field = (len - 4) & 0xFFFC;
 
@@ -406,13 +407,13 @@ static void tegra_dma_set_xfer_params(struct tegra_dma_channel *tdc,
 				      enum dma_transfer_direction direction,
 				      u32 mem, u32 len)
 {
-	sg_req->ch_regs.ahb_seq |= get_burst_size(tdc, direction, len);
-	sg_req->ch_regs.apb_ptr = sg_base->ch_regs.apb_ptr;
-	sg_req->ch_regs.ahb_ptr = mem;
-	sg_req->ch_regs.csr = sg_base->ch_regs.csr;
-	tegra_dma_prep_wcount(tdc, &sg_req->ch_regs, len);
-	sg_req->ch_regs.apb_seq = sg_base->ch_regs.apb_seq;
-	sg_req->ch_regs.ahb_seq = sg_base->ch_regs.ahb_seq;
+	sg_req->apb_ch_regs.ahb_seq |= get_burst_size(tdc, direction, len);
+	sg_req->apb_ch_regs.apb_ptr = sg_base->apb_ch_regs.apb_ptr;
+	sg_req->apb_ch_regs.ahb_ptr = mem;
+	sg_req->apb_ch_regs.csr = sg_base->apb_ch_regs.csr;
+	tegra_dma_prep_wcount(tdc, &sg_req->apb_ch_regs, len);
+	sg_req->apb_ch_regs.apb_seq = sg_base->apb_ch_regs.apb_seq;
+	sg_req->apb_ch_regs.ahb_seq = sg_base->apb_ch_regs.ahb_seq;
 	sg_req->configured = false;
 	sg_req->last_sg = false;
 	sg_req->req_len = len;
@@ -742,7 +743,7 @@ static int tegra_dma_pm_suspend(struct device *dev)
 	tdma->reg_gen = tdma_read(tdma, TEGRA_APBDMA_GENERAL);
 	for (i = 0; i < tdma->chip_data->nr_channels; i++) {
 		struct tegra_dma_channel *tdc = &tdma->channels[i];
-		struct tegra_dma_channel_regs *ch_reg = &tdc->channel_reg;
+		struct tegra_apb_chan_regs *ch_reg = &tdc->apb_ch_regs;
 
 		ch_reg->csr = tdc_read(tdc, TEGRA_APBDMA_CHAN_CSR);
 		ch_reg->ahb_ptr = tdc_read(tdc, TEGRA_APBDMA_CHAN_AHBPTR);
@@ -773,7 +774,7 @@ static int tegra_dma_pm_resume(struct device *dev)
 
 	for (i = 0; i < tdma->chip_data->nr_channels; i++) {
 		struct tegra_dma_channel *tdc = &tdma->channels[i];
-		struct tegra_dma_channel_regs *ch_reg = &tdc->channel_reg;
+		struct tegra_apb_chan_regs *ch_reg = &tdc->apb_ch_regs;
 
 		tdc_write(tdc, TEGRA_APBDMA_CHAN_APBSEQ, ch_reg->apb_seq);
 		tdc_write(tdc, TEGRA_APBDMA_CHAN_APBPTR, ch_reg->apb_ptr);
drivers/dma/tegra210-adma.c new file +710 -0

710 lines not on this page · raw message

Signature · 1 line
2.1.4
#17 lore raw

Re: [RFC PATCH 7/7] DMA: tegra-adma: Add support for Tegra210 ADMA

drivers/dma/tegra210-adma.c line 110

Quoted 2 lines · Jon Hunter
drivers/dma/tegra210-adma.c new file +2 -0
+#define AHUB_TO_MEMORY						2
+#define MEMORY_TO_AHUB						4

namespace this aptly as well

drivers/dma/tegra210-adma.c line 204

Quoted 5 lines
drivers/dma/tegra210-adma.c new file +5 -0
+static void tegra_adma_stop(struct tegra_dma_channel *tdc)
+{
+	u32 status;
+
+	/* TODO: Do we need to disable interrupts here? */

when?

drivers/dma/tegra210-adma.c line 232

Quoted 13 lines
drivers/dma/tegra210-adma.c new file +13 -0
+static void tegra_adma_start(struct tegra_dma_channel *tdc,
+		struct tegra_dma_sg_req *sg_req)
+{
+	struct tegra_adma_chan_regs *ch_regs = &sg_req->adma_ch_regs;
+
+	/* Update transfer done count for position calculation */
+	tdc->adma_ch_regs.tc = ch_regs->tc;
+	tdc_write(tdc, ADMA_CH_TC, ch_regs->tc);
+	tdc_write(tdc, ADMA_CH_CTRL, ch_regs->ctrl);
+	tdc_write(tdc, ADMA_CH_LOWER_SOURCE_ADDR, ch_regs->src_ptr);
+	tdc_write(tdc, ADMA_CH_LOWER_TARGET_ADDR, ch_regs->tgt_ptr);
+	tdc_write(tdc, ADMA_CH_AHUB_FIFO_CTRL, ch_regs->ahub_fifo_ctrl);
+	tdc_write(tdc, ADMA_CH_CONFIG, ch_regs->config);

empty line here please

Quoted 10 lines
drivers/dma/tegra210-adma.c new file +10 -0
+static int tegra_adma_get_xfer_params(struct tegra_dma_channel *tdc,
+				      struct tegra_adma_chan_regs *ch_regs,
+				      enum dma_transfer_direction direction)
+{
+	u32 burst_size, ctrl, ctrl_mask, slave_id, fifo_mask, fifo_shift;
+
+	ch_regs->ahub_fifo_ctrl = tdc_read(tdc, ADMA_CH_AHUB_FIFO_CTRL);
+	ch_regs->config = tdc_read(tdc, ADMA_CH_CONFIG);
+	ch_regs->ctrl = tdc_read(tdc, ADMA_CH_CTRL);
+	slave_id = tdc->dma_sconfig.slave_id;

drivers/dma/tegra210-adma.c line 256

Quoted 10 lines
drivers/dma/tegra210-adma.c new file +10 -0
+
+	switch (direction) {
+	case DMA_MEM_TO_DEV:
+		burst_size = fls(tdc->dma_sconfig.dst_maxburst);
+		ctrl_mask = ADMA_CH_CTRL_TX_REQUEST_SELECT_MASK;
+		ctrl = MEMORY_TO_AHUB << ADMA_CH_CTRL_TRANSFER_DIRECTION_SHIFT;
+		ctrl |= slave_id << ADMA_CH_CTRL_TX_REQUEST_SELECT_SHIFT;
+		fifo_mask = ADMA_CH_AHUB_FIFO_CTRL_TX_FIFO_SIZE_MASK;
+		fifo_shift = ADMA_CH_AHUB_FIFO_CTRL_TX_FIFO_SIZE_SHIFT;
+		break;

Empty line here pls

drivers/dma/tegra210-adma.c line 264

Quoted 8 lines
drivers/dma/tegra210-adma.c new file +8 -0
+	case DMA_DEV_TO_MEM:
+		burst_size = fls(tdc->dma_sconfig.src_maxburst);
+		ctrl_mask = ADMA_CH_CTRL_RX_REQUEST_SELECT_MASK;
+		ctrl = AHUB_TO_MEMORY << ADMA_CH_CTRL_TRANSFER_DIRECTION_SHIFT;
+		ctrl |= slave_id << ADMA_CH_CTRL_RX_REQUEST_SELECT_SHIFT;
+		fifo_mask = ADMA_CH_AHUB_FIFO_CTRL_RX_FIFO_SIZE_MASK;
+		fifo_shift = ADMA_CH_AHUB_FIFO_CTRL_RX_FIFO_SIZE_SHIFT;
+		break;

here too...

Quoted 6 lines
drivers/dma/tegra210-adma.c new file +6 -0
+	default:
+		dev_err(tdc2dev(tdc), "Dma direction is not supported\n");
+		return -EINVAL;
+	}
+
+	if (!burst_size || burst_size > ADMA_BURSTSIZE_16)

drivers/dma/tegra210-adma.c line 280

Quoted 10 lines
drivers/dma/tegra210-adma.c new file +10 -0
+		burst_size = ADMA_BURSTSIZE_16;
+
+	ch_regs->ahub_fifo_ctrl &= ~fifo_mask;
+	ch_regs->ahub_fifo_ctrl |= ADMA_FIFO_DEFAULT_SIZE << fifo_shift;
+	ch_regs->config &= ~ADMA_CH_CONFIG_BURST_SIZE_MASK;
+	ch_regs->config |= burst_size << ADMA_CH_CONFIG_BURST_SIZE_SHIFT;
+	ch_regs->ctrl &= ~(ctrl_mask | ADMA_CH_CTRL_TRANSFER_DIRECTION_MASK);
+	ch_regs->ctrl |= ctrl;
+
+	return -EINVAL;

??

drivers/dma/tegra210-adma.c line 634

Quoted 7 lines
drivers/dma/tegra210-adma.c new file +7 -0
+static int tegra_adma_pm_suspend(struct device *dev)
+{
+	struct tegra_dma *tdma = dev_get_drvdata(dev);
+	int i;
+	int ret;
+
+	ret = pm_runtime_get_sync(dev);

why is this required :)

drivers/dma/tegra210-adma.c line 661

Quoted 7 lines
drivers/dma/tegra210-adma.c new file +7 -0
+static int tegra_adma_pm_resume(struct device *dev)
+{
+	struct tegra_dma *tdma = dev_get_drvdata(dev);
+	int i;
+	int ret;
+
+	ret = pm_runtime_get_sync(dev);

and this

Signature · 1 line
~Vinod
author maintainer
#18 lore raw

Re: [RFC PATCH 7/7] DMA: tegra-adma: Add support for Tegra210 ADMA

Quoted 6 lines · Vinod Koul

drivers/dma/tegra210-adma.c line 110

Quoted 2 lines · Jon Hunter
drivers/dma/tegra210-adma.c new file +2 -0
+#define AHUB_TO_MEMORY						2
+#define MEMORY_TO_AHUB						4

namespace this aptly as well

Quoted 7 lines

drivers/dma/tegra210-adma.c line 204

Quoted 5 lines
drivers/dma/tegra210-adma.c new file +5 -0
+static void tegra_adma_stop(struct tegra_dma_channel *tdc)
+{
+	u32 status;
+
+	/* TODO: Do we need to disable interrupts here? */

when?

Once everyone is happy with the RFC in general.

Quoted 6 lines
Quoted 6 lines
drivers/dma/tegra210-adma.c new file +6 -0
+static void tegra_adma_start(struct tegra_dma_channel *tdc,
+		struct tegra_dma_sg_req *sg_req)
+{
+	struct tegra_adma_chan_regs *ch_regs = &sg_req->adma_ch_regs;
+
+	/* Update transfer done count for position calculation */
Quoted 8 lines

drivers/dma/tegra210-adma.c line 232

Quoted 7 lines
drivers/dma/tegra210-adma.c new file +7 -0
+	tdc->adma_ch_regs.tc = ch_regs->tc;
+	tdc_write(tdc, ADMA_CH_TC, ch_regs->tc);
+	tdc_write(tdc, ADMA_CH_CTRL, ch_regs->ctrl);
+	tdc_write(tdc, ADMA_CH_LOWER_SOURCE_ADDR, ch_regs->src_ptr);
+	tdc_write(tdc, ADMA_CH_LOWER_TARGET_ADDR, ch_regs->tgt_ptr);
+	tdc_write(tdc, ADMA_CH_AHUB_FIFO_CTRL, ch_regs->ahub_fifo_ctrl);
+	tdc_write(tdc, ADMA_CH_CONFIG, ch_regs->config);

empty line here please

Ok.

Quoted 13 lines
Quoted 13 lines
drivers/dma/tegra210-adma.c new file +13 -0
+static int tegra_adma_get_xfer_params(struct tegra_dma_channel *tdc,
+				      struct tegra_adma_chan_regs *ch_regs,
+				      enum dma_transfer_direction direction)
+{
+	u32 burst_size, ctrl, ctrl_mask, slave_id, fifo_mask, fifo_shift;
+
+	ch_regs->ahub_fifo_ctrl = tdc_read(tdc, ADMA_CH_AHUB_FIFO_CTRL);
+	ch_regs->config = tdc_read(tdc, ADMA_CH_CONFIG);
+	ch_regs->ctrl = tdc_read(tdc, ADMA_CH_CTRL);
+	slave_id = tdc->dma_sconfig.slave_id;
+
+	switch (direction) {
+	case DMA_MEM_TO_DEV:
Quoted 8 lines

drivers/dma/tegra210-adma.c line 256

Quoted 7 lines
drivers/dma/tegra210-adma.c new file +7 -0
+		burst_size = fls(tdc->dma_sconfig.dst_maxburst);
+		ctrl_mask = ADMA_CH_CTRL_TX_REQUEST_SELECT_MASK;
+		ctrl = MEMORY_TO_AHUB << ADMA_CH_CTRL_TRANSFER_DIRECTION_SHIFT;
+		ctrl |= slave_id << ADMA_CH_CTRL_TX_REQUEST_SELECT_SHIFT;
+		fifo_mask = ADMA_CH_AHUB_FIFO_CTRL_TX_FIFO_SIZE_MASK;
+		fifo_shift = ADMA_CH_AHUB_FIFO_CTRL_TX_FIFO_SIZE_SHIFT;
+		break;

Empty line here pls

Ok, any reason why? Other dma drivers don't appear to do this.

Quoted 20 lines

drivers/dma/tegra210-adma.c line 264

Quoted 8 lines
drivers/dma/tegra210-adma.c new file +8 -0
+	case DMA_DEV_TO_MEM:
+		burst_size = fls(tdc->dma_sconfig.src_maxburst);
+		ctrl_mask = ADMA_CH_CTRL_RX_REQUEST_SELECT_MASK;
+		ctrl = AHUB_TO_MEMORY << ADMA_CH_CTRL_TRANSFER_DIRECTION_SHIFT;
+		ctrl |= slave_id << ADMA_CH_CTRL_RX_REQUEST_SELECT_SHIFT;
+		fifo_mask = ADMA_CH_AHUB_FIFO_CTRL_RX_FIFO_SIZE_MASK;
+		fifo_shift = ADMA_CH_AHUB_FIFO_CTRL_RX_FIFO_SIZE_SHIFT;
+		break;

here too...

Quoted 9 lines
drivers/dma/tegra210-adma.c new file +9 -0
+	default:
+		dev_err(tdc2dev(tdc), "Dma direction is not supported\n");
+		return -EINVAL;
+	}
+
+	if (!burst_size || burst_size > ADMA_BURSTSIZE_16)
+		burst_size = ADMA_BURSTSIZE_16;
+
+	ch_regs->ahub_fifo_ctrl &= ~fifo_mask;
Quoted 8 lines

drivers/dma/tegra210-adma.c line 280

Quoted 7 lines
drivers/dma/tegra210-adma.c new file +7 -0
+	ch_regs->ahub_fifo_ctrl |= ADMA_FIFO_DEFAULT_SIZE << fifo_shift;
+	ch_regs->config &= ~ADMA_CH_CONFIG_BURST_SIZE_MASK;
+	ch_regs->config |= burst_size << ADMA_CH_CONFIG_BURST_SIZE_SHIFT;
+	ch_regs->ctrl &= ~(ctrl_mask | ADMA_CH_CTRL_TRANSFER_DIRECTION_MASK);
+	ch_regs->ctrl |= ctrl;
+
+	return -EINVAL;

??

Thanks. That's an error. Will fix.

Quoted 8 lines

drivers/dma/tegra210-adma.c line 634

Quoted 7 lines
drivers/dma/tegra210-adma.c new file +7 -0
+static int tegra_adma_pm_suspend(struct device *dev)
+{
+	struct tegra_dma *tdma = dev_get_drvdata(dev);
+	int i;
+	int ret;
+
+	ret = pm_runtime_get_sync(dev);

why is this required :)

To ensure that the clocks are enabled before the registers are read. This function saves the dma context before suspend, in case the hardware state is lost.

Quoted 8 lines

drivers/dma/tegra210-adma.c line 661

Quoted 7 lines
drivers/dma/tegra210-adma.c new file +7 -0
+static int tegra_adma_pm_resume(struct device *dev)
+{
+	struct tegra_dma *tdma = dev_get_drvdata(dev);
+	int i;
+	int ret;
+
+	ret = pm_runtime_get_sync(dev);

and this

Same here.

Cheers
Jon

#19 lore raw

Re: [RFC PATCH 7/7] DMA: tegra-adma: Add support for Tegra210 ADMA

Quoted 22 lines · Jon Hunter
Quoted 13 lines
Quoted 13 lines
drivers/dma/tegra210-adma.c new file +13 -0
+static int tegra_adma_get_xfer_params(struct tegra_dma_channel *tdc,
+				      struct tegra_adma_chan_regs *ch_regs,
+				      enum dma_transfer_direction direction)
+{
+	u32 burst_size, ctrl, ctrl_mask, slave_id, fifo_mask, fifo_shift;
+
+	ch_regs->ahub_fifo_ctrl = tdc_read(tdc, ADMA_CH_AHUB_FIFO_CTRL);
+	ch_regs->config = tdc_read(tdc, ADMA_CH_CONFIG);
+	ch_regs->ctrl = tdc_read(tdc, ADMA_CH_CTRL);
+	slave_id = tdc->dma_sconfig.slave_id;
+
+	switch (direction) {
+	case DMA_MEM_TO_DEV:
Quoted 8 lines

drivers/dma/tegra210-adma.c line 256

Quoted 7 lines
drivers/dma/tegra210-adma.c new file +7 -0
+		burst_size = fls(tdc->dma_sconfig.dst_maxburst);
+		ctrl_mask = ADMA_CH_CTRL_TX_REQUEST_SELECT_MASK;
+		ctrl = MEMORY_TO_AHUB << ADMA_CH_CTRL_TRANSFER_DIRECTION_SHIFT;
+		ctrl |= slave_id << ADMA_CH_CTRL_TX_REQUEST_SELECT_SHIFT;
+		fifo_mask = ADMA_CH_AHUB_FIFO_CTRL_TX_FIFO_SIZE_MASK;
+		fifo_shift = ADMA_CH_AHUB_FIFO_CTRL_TX_FIFO_SIZE_SHIFT;
+		break;

Empty line here pls

Quoted 1 line

Ok, any reason why? Other dma drivers don't appear to do this.

This improves readablity. It is a good idea to sprinkle empty lines between logial blocks

Quoted 9 lines
Quoted 8 lines

drivers/dma/tegra210-adma.c line 634

Quoted 7 lines
drivers/dma/tegra210-adma.c new file +7 -0
+static int tegra_adma_pm_suspend(struct device *dev)
+{
+	struct tegra_dma *tdma = dev_get_drvdata(dev);
+	int i;
+	int ret;
+
+	ret = pm_runtime_get_sync(dev);

why is this required :)

Quoted 3 lines

To ensure that the clocks are enabled before the registers are read. This function saves the dma context before suspend, in case the hardware state is lost.

I think same reason here too, so based on my other argument, this may not be required!

Signature · 1 line
~Vinod