linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: richard.zhao@freescale.com (Richard Zhao)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 01/11] dma: imx-sdma: make channel0 operations atomic
Date: Fri, 27 Apr 2012 15:02:55 +0800	[thread overview]
Message-ID: <1335510185-7906-2-git-send-email-richard.zhao@freescale.com> (raw)
In-Reply-To: <1335510185-7906-1-git-send-email-richard.zhao@freescale.com>

device_prep_dma_cyclic may be call in audio trigger function which is
atomic context, so we make it atomic too.

 - change channel0 lock to spinlock.
 - Use polling to wait for channel0 finish running.

Signed-off-by: Lothar Wa?mann <LW@KARO-electronics.de>
Signed-off-by: Richard Zhao <richard.zhao@freescale.com>
---
 drivers/dma/imx-sdma.c |   57 +++++++++++++++++++++++++++--------------------
 1 files changed, 33 insertions(+), 24 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index fddccae..fc49ffa 100644
--- a/drivers/dma/imx-sdma.c
+++ b/drivers/dma/imx-sdma.c
@@ -24,7 +24,7 @@
 #include <linux/mm.h>
 #include <linux/interrupt.h>
 #include <linux/clk.h>
-#include <linux/wait.h>
+#include <linux/delay.h>
 #include <linux/sched.h>
 #include <linux/semaphore.h>
 #include <linux/spinlock.h>
@@ -324,7 +324,7 @@ struct sdma_engine {
 	struct dma_device		dma_device;
 	struct clk			*clk_ipg;
 	struct clk			*clk_ahb;
-	struct mutex			channel_0_lock;
+	spinlock_t		channel_0_lock;
 	struct sdma_script_start_addrs	*script_addrs;
 };
 
@@ -402,19 +402,31 @@ static void sdma_enable_channel(struct sdma_engine *sdma, int channel)
 }
 
 /*
- * sdma_run_channel - run a channel and wait till it's done
+ * sdma_run_channel0 - run a channel and wait till it's done
  */
-static int sdma_run_channel(struct sdma_channel *sdmac)
+static int sdma_run_channel0(struct sdma_channel *sdmac)
 {
 	struct sdma_engine *sdma = sdmac->sdma;
 	int channel = sdmac->channel;
 	int ret;
+	unsigned long timeout = 500;
 
-	init_completion(&sdmac->done);
-
+	if (channel)
+		return -EINVAL;
 	sdma_enable_channel(sdma, channel);
 
-	ret = wait_for_completion_timeout(&sdmac->done, HZ);
+	while (!(ret = readl_relaxed(sdma->regs + SDMA_H_INTR) & 1)) {
+		if (timeout-- <= 0)
+			break;
+		udelay(1);
+	}
+
+	if (ret) {
+		/* Clear the interrupt status */
+		writel_relaxed(ret, sdma->regs + SDMA_H_INTR);
+	} else {
+		dev_err(sdma->dev, "Timeout waiting for CH0 ready\n");
+	}
 
 	return ret ? 0 : -ETIMEDOUT;
 }
@@ -426,17 +438,17 @@ static int sdma_load_script(struct sdma_engine *sdma, void *buf, int size,
 	void *buf_virt;
 	dma_addr_t buf_phys;
 	int ret;
-
-	mutex_lock(&sdma->channel_0_lock);
+	unsigned long flags;
 
 	buf_virt = dma_alloc_coherent(NULL,
 			size,
 			&buf_phys, GFP_KERNEL);
 	if (!buf_virt) {
-		ret = -ENOMEM;
-		goto err_out;
+		return -ENOMEM;
 	}
 
+	spin_lock_irqsave(&sdma->channel_0_lock, flags);
+
 	bd0->mode.command = C0_SETPM;
 	bd0->mode.status = BD_DONE | BD_INTR | BD_WRAP | BD_EXTD;
 	bd0->mode.count = size / 2;
@@ -445,12 +457,11 @@ static int sdma_load_script(struct sdma_engine *sdma, void *buf, int size,
 
 	memcpy(buf_virt, buf, size);
 
-	ret = sdma_run_channel(&sdma->channel[0]);
+	ret = sdma_run_channel0(&sdma->channel[0]);
 
-	dma_free_coherent(NULL, size, buf_virt, buf_phys);
+	spin_unlock_irqrestore(&sdma->channel_0_lock, flags);
 
-err_out:
-	mutex_unlock(&sdma->channel_0_lock);
+	dma_free_coherent(NULL, size, buf_virt, buf_phys);
 
 	return ret;
 }
@@ -539,10 +550,6 @@ static void mxc_sdma_handle_channel(struct sdma_channel *sdmac)
 {
 	complete(&sdmac->done);
 
-	/* not interested in channel 0 interrupts */
-	if (sdmac->channel == 0)
-		return;
-
 	if (sdmac->flags & IMX_DMA_SG_LOOP)
 		sdma_handle_channel_loop(sdmac);
 	else
@@ -555,6 +562,8 @@ static irqreturn_t sdma_int_handler(int irq, void *dev_id)
 	unsigned long stat;
 
 	stat = readl_relaxed(sdma->regs + SDMA_H_INTR);
+	/* not interested in channel 0 interrupts */
+	stat &= ~1;
 	writel_relaxed(stat, sdma->regs + SDMA_H_INTR);
 
 	while (stat) {
@@ -660,6 +669,7 @@ static int sdma_load_context(struct sdma_channel *sdmac)
 	struct sdma_context_data *context = sdma->context;
 	struct sdma_buffer_descriptor *bd0 = sdma->channel[0].bd;
 	int ret;
+	unsigned long flags;
 
 	if (sdmac->direction == DMA_DEV_TO_MEM) {
 		load_address = sdmac->pc_from_device;
@@ -677,7 +687,7 @@ static int sdma_load_context(struct sdma_channel *sdmac)
 	dev_dbg(sdma->dev, "event_mask0 = 0x%08x\n", (u32)sdmac->event_mask[0]);
 	dev_dbg(sdma->dev, "event_mask1 = 0x%08x\n", (u32)sdmac->event_mask[1]);
 
-	mutex_lock(&sdma->channel_0_lock);
+	spin_lock_irqsave(&sdma->channel_0_lock, flags);
 
 	memset(context, 0, sizeof(*context));
 	context->channel_state.pc = load_address;
@@ -696,10 +706,9 @@ static int sdma_load_context(struct sdma_channel *sdmac)
 	bd0->mode.count = sizeof(*context) / 4;
 	bd0->buffer_addr = sdma->context_phys;
 	bd0->ext_buffer_addr = 2048 + (sizeof(*context) / 4) * channel;
+	ret = sdma_run_channel0(&sdma->channel[0]);
 
-	ret = sdma_run_channel(&sdma->channel[0]);
-
-	mutex_unlock(&sdma->channel_0_lock);
+	spin_unlock_irqrestore(&sdma->channel_0_lock, flags);
 
 	return ret;
 }
@@ -1305,7 +1314,7 @@ static int __init sdma_probe(struct platform_device *pdev)
 	if (!sdma)
 		return -ENOMEM;
 
-	mutex_init(&sdma->channel_0_lock);
+	spin_lock_init(&sdma->channel_0_lock);
 
 	sdma->dev = &pdev->dev;
 
-- 
1.7.5.4

  reply	other threads:[~2012-04-27  7:02 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-27  7:02 [PATCH 00/11] enable imx6q_sabrelite sgtl5000 audio support Richard Zhao
2012-04-27  7:02 ` Richard Zhao [this message]
2012-04-27  7:55   ` [PATCH 01/11] dma: imx-sdma: make channel0 operations atomic Sascha Hauer
2012-04-27  9:17     ` Richard Zhao
2012-04-27  8:21   ` Vinod Koul
2012-04-27  8:41     ` Richard Zhao
2012-04-27 10:22       ` Vinod Koul
2012-04-27 11:20         ` Mark Brown
2012-04-27 11:26         ` Richard Zhao
2012-04-27 11:33           ` Russell King - ARM Linux
2012-04-27 13:01             ` Laxman Dewangan
2012-04-27 13:10               ` Russell King - ARM Linux
2012-04-27 13:17                 ` Laxman Dewangan
2012-04-27 13:19                 ` Richard Zhao
2012-04-27  9:18   ` Lothar Waßmann
2012-04-27 13:25     ` Richard Zhao
2012-04-27 15:13       ` Lothar Waßmann
2012-04-27 15:27         ` Huang Shijie
2012-04-27  7:02 ` [PATCH 02/11] ASoC: imx-sgtl5000: add of_node_put when probe fail Richard Zhao
2012-04-27 17:44   ` Mark Brown
2012-04-27  7:02 ` [PATCH 03/11] ASoC: fsl: add sgtl5000 clock support for imx-sgtl5000 Richard Zhao
2012-04-27 17:44   ` Mark Brown
2012-05-01 13:44   ` Shawn Guo
2012-05-02 10:50     ` Richard Zhao
2012-05-02 11:41       ` Mark Brown
2012-05-02 12:12         ` Shawn Guo
2012-05-02 12:22           ` Mark Brown
2012-04-27  7:02 ` [PATCH 04/11] i2c: imx: add pinctrl support Richard Zhao
2012-04-27  8:40   ` Dong Aisheng
2012-04-27  9:15     ` Richard Zhao
2012-04-27  7:02 ` [PATCH 05/11] ARM: imx6q: move imx6q_sabrelite specific code to a dedicated function Richard Zhao
2012-05-01 13:18   ` Shawn Guo
2012-04-27  7:03 ` [PATCH 06/11] ARM: dts: imx6q-sabrelite: add ssi device Richard Zhao
2012-05-01 13:26   ` Shawn Guo
2012-05-02  2:38     ` Shawn Guo
2012-04-27  7:03 ` [PATCH 07/11] ARM: dts: imx6q-sabrelite: add audmux device Richard Zhao
2012-04-27  7:03 ` [PATCH 08/11] ASoC: imx-audmux: add pinctrl support Richard Zhao
2012-04-27  7:03 ` [PATCH 09/11] ARM: imx6q: add ssi1 clk_lookup Richard Zhao
2012-04-27  8:04   ` Sascha Hauer
2012-04-27  9:10     ` Richard Zhao
2012-04-27  9:25       ` Sascha Hauer
2012-04-30  2:01         ` Richard Zhao
2012-04-30 12:18           ` Sascha Hauer
2012-05-02 10:34             ` Richard Zhao
2012-05-02 14:34               ` Shawn Guo
2012-05-02 16:33                 ` Sascha Hauer
2012-04-27  7:03 ` [PATCH 10/11] ARM: imx6q_sabrelite: clkdev_add cko1 for sgtl5000 Richard Zhao
2012-05-01 12:47   ` Shawn Guo
2012-05-01 23:39     ` Shawn Guo
2012-05-02  2:47       ` [alsa-devel] " Fabio Estevam
2012-05-02  3:37         ` Shawn Guo
2012-05-02 11:00     ` Richard Zhao
2012-04-27  7:03 ` [PATCH 11/11] ARM: dts: imx6q-sabrelite: add sound device imx6q-sabrelite-sgtl5000 Richard Zhao
2012-05-01 12:55   ` Shawn Guo
2012-05-02 10:37     ` Richard Zhao

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1335510185-7906-2-git-send-email-richard.zhao@freescale.com \
    --to=richard.zhao@freescale.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).