alsa-devel.alsa-project.org archive mirror
 help / color / mirror / Atom feed
From: Richard Zhao <richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
To: linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org
Cc: shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
	dan.j.williams-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org,
	lrg-l0cyMroinI0@public.gmane.org,
	broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org,
	vinod.koul-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org,
	dong.aisheng-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	timur-KZfg59tc24xl57MIdRCFDg@public.gmane.org,
	Richard Zhao
	<richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
Subject: [PATCH V2 01/11] dma: imx-sdma: make channel0 operations atomic
Date: Wed, 9 May 2012 19:33:00 +0800	[thread overview]
Message-ID: <1336563190-19974-2-git-send-email-richard.zhao@freescale.com> (raw)
In-Reply-To: <1336563190-19974-1-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>

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: Richard Zhao <richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
---
 drivers/dma/imx-sdma.c |   57 ++++++++++++++++++++++++++---------------------
 1 files changed, 31 insertions(+), 26 deletions(-)

diff --git a/drivers/dma/imx-sdma.c b/drivers/dma/imx-sdma.c
index fddccae..4fd48eb 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,27 @@ 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_engine *sdma)
 {
-	struct sdma_engine *sdma = sdmac->sdma;
-	int channel = sdmac->channel;
 	int ret;
+	unsigned long timeout = 500;
 
-	init_completion(&sdmac->done);
+	sdma_enable_channel(sdma, 0);
 
-	sdma_enable_channel(sdma, channel);
+	while (!(ret = readl_relaxed(sdma->regs + SDMA_H_INTR) & 1)) {
+		if (timeout-- <= 0)
+			break;
+		udelay(1);
+	}
 
-	ret = wait_for_completion_timeout(&sdmac->done, HZ);
+	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 +434,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 +453,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);
 
-	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 +546,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 +558,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 +665,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 +683,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 +702,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);
 
-	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 +1310,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

  parent reply	other threads:[~2012-05-09 11:33 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-09 11:32 [PATCH V2 00/11] enable imx6q_sabrelite sgtl5000 audio support Richard Zhao
     [not found] ` <1336563190-19974-1-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-05-09 11:33   ` Richard Zhao [this message]
     [not found]     ` <1336563190-19974-2-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-05-10  3:53       ` [PATCH V2 01/11] dma: imx-sdma: make channel0 operations atomic Vinod Koul
2012-05-10  6:34         ` Shawn Guo
     [not found]           ` <20120510063446.GA17875-rvtDTF3kK1ictlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2012-05-10 12:37             ` Shawn Guo
     [not found]               ` <20120510123749.GO17875-rvtDTF3kK1ictlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2012-05-11  2:52                 ` Vinod Koul
2012-05-11  3:02                   ` Shawn Guo
2012-05-11  6:32       ` Vinod Koul
2012-05-11  7:14         ` [PATCH Rebase 1/1] " Richard Zhao
     [not found]           ` <1336720467-29770-1-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-05-11  8:33             ` [alsa-devel] " Vinod Koul
2012-05-09 11:33   ` [PATCH V2 02/11] ARM: dts: imx6q-sabrelite: add i2c1 pinctrl support Richard Zhao
     [not found]     ` <1336563190-19974-3-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-05-10  6:20       ` Dong Aisheng
2012-05-09 11:33   ` [PATCH V2 03/11] ASoC: imx-audmux: add " Richard Zhao
2012-05-09 16:00     ` Mark Brown
     [not found]       ` <20120509160005.GG3955-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-05-10  0:35         ` Richard Zhao
     [not found]           ` <20120510003532.GG2982-iWYTGMXpHj9ITqJhDdzsOjpauB2SiJktrE5yTffgRl4@public.gmane.org>
2012-05-10  6:39             ` Shawn Guo
2012-05-10  8:44               ` Mark Brown
2012-05-10  9:05                 ` Richard Zhao
     [not found]                   ` <20120510090459.GH2982-iWYTGMXpHj9ITqJhDdzsOjpauB2SiJktrE5yTffgRl4@public.gmane.org>
2012-05-10  9:27                     ` Mark Brown
     [not found]                       ` <20120510092733.GH3908-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-05-10 10:23                         ` Richard Zhao
     [not found]                           ` <20120510102309.GK2982-iWYTGMXpHj9ITqJhDdzsOjpauB2SiJktrE5yTffgRl4@public.gmane.org>
2012-05-10 12:26                             ` Linus Walleij
     [not found]                               ` <CACRpkdah3956QLZZ1wTw1PcZ90wWX=Ta9j45jjzWsBtT=nm8-g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-05-10 13:41                                 ` Richard Zhao
     [not found]                                   ` <20120510134120.GM2982-iWYTGMXpHj9ITqJhDdzsOjpauB2SiJktrE5yTffgRl4@public.gmane.org>
2012-05-10 14:00                                     ` Linus Walleij
2012-05-11  5:32                                 ` Shawn Guo
     [not found]                                   ` <20120511053218.GT17875-rvtDTF3kK1ictlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2012-05-11 12:29                                     ` Linus Walleij
     [not found]                                       ` <CACRpkdY3Ga0soie+tsALxA1yhzXbyVOj_HbLLWOjRPz6cMLqtQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-05-11 13:27                                         ` Arnd Bergmann
2012-05-10 15:48                     ` [alsa-devel] " Stephen Warren
     [not found]                 ` <20120510084403.GA3908-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-05-10  9:07                   ` Shawn Guo
     [not found]                     ` <20120510090715.GF17875-rvtDTF3kK1ictlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2012-05-10  9:25                       ` Mark Brown
     [not found]                         ` <20120510092536.GG3908-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-05-10 12:32                           ` Shawn Guo
2012-05-10 12:20                     ` Linus Walleij
     [not found]     ` <1336563190-19974-4-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-05-10  3:28       ` Dong Aisheng
2012-05-09 11:33   ` [PATCH V2 04/11] ARM: dts: imx6q-sabrelite: add audmux " Richard Zhao
2012-05-10  3:29     ` Dong Aisheng
2012-05-09 11:33   ` [PATCH V2 05/11] ARM: imx6q: add ssi1_ipg clk_lookup Richard Zhao
2012-05-09 11:33   ` [PATCH V2 06/11] ASoC: fsl_ssi: convert to use devm_clk_get Richard Zhao
     [not found]     ` <1336563190-19974-7-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-05-09 11:50       ` Mark Brown
     [not found]         ` <20120509115041.GM3955-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-05-09 11:59           ` Shawn Guo
     [not found]             ` <CAAQ0ZWSiRysfkUnu2ZoDXFtiJz-nfrQ-DTKOgCpKpCe5LpQj3Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-05-09 12:01               ` Mark Brown
2012-05-09 12:03               ` Shawn Guo
2012-05-09 16:09       ` Timur Tabi
2012-05-09 11:33   ` [PATCH V2 07/11] ARM: imx6q_sabrelite: clk_register_clkdev cko1 for sgtl5000 Richard Zhao
2012-05-09 11:33   ` [PATCH V2 08/11] ARM: dts: imx6q-sabrelite: add sound device imx6q-sabrelite-sgtl5000 Richard Zhao
     [not found]     ` <1336563190-19974-9-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-05-10  6:48       ` Shawn Guo
2012-05-10  9:34         ` Richard Zhao
     [not found]           ` <20120510093444.GI2982-iWYTGMXpHj9ITqJhDdzsOjpauB2SiJktrE5yTffgRl4@public.gmane.org>
2012-05-10  9:41             ` Shawn Guo
2012-05-10  9:45               ` Mark Brown
     [not found]                 ` <20120510094508.GN3908-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-05-10 10:18                   ` Richard Zhao
2012-05-10 11:49                   ` Shawn Guo
     [not found]                     ` <20120510114956.GI17875-rvtDTF3kK1ictlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2012-05-10 15:48                       ` [alsa-devel] " Shawn Guo
     [not found]               ` <20120510094113.GG17875-rvtDTF3kK1ictlrPMvKcciBecyulp+rMXqFh9Ls21Oc@public.gmane.org>
2012-05-10  9:45                 ` Shawn Guo
2012-05-09 11:33   ` [PATCH V2 09/11] ARM: dts: imx6q-sabrelite: add serial2 pinctrl support Richard Zhao
     [not found]     ` <1336563190-19974-10-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-05-10  3:33       ` Dong Aisheng
2012-05-09 11:33   ` [PATCH V2 10/11] ARM: imx6q: change clkdev device name from xxxx.uart to xxxx.serial Richard Zhao
     [not found]     ` <1336563190-19974-11-git-send-email-richard.zhao-KZfg59tc24xl57MIdRCFDg@public.gmane.org>
2012-05-10  6:51       ` Shawn Guo
2012-05-09 11:33   ` [PATCH V2 11/11] ARM: imx6q: change clkdev device name from xxxx.enet to xxxx.ethernet Richard Zhao
2012-05-11  6:30   ` [PATCH V2 00/11] enable imx6q_sabrelite sgtl5000 audio support Shawn Guo
2012-05-21 12:59   ` Richard Zhao
     [not found]     ` <20120521125930.GC6206-iWYTGMXpHj9ITqJhDdzsOjpauB2SiJktrE5yTffgRl4@public.gmane.org>
2012-05-21 14:45       ` Mark Brown
2012-05-22  1:39         ` Richard Zhao
     [not found]           ` <20120522013920.GE6206-iWYTGMXpHj9ITqJhDdzsOjpauB2SiJktrE5yTffgRl4@public.gmane.org>
2012-05-22  9:56             ` Mark Brown

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=1336563190-19974-2-git-send-email-richard.zhao@freescale.com \
    --to=richard.zhao-kzfg59tc24xl57midrcfdg@public.gmane.org \
    --cc=alsa-devel-K7yf7f+aM1XWsZ/bQMPhNw@public.gmane.org \
    --cc=ben-linux-elnMNo+KYs3YtjvyW6yDsg@public.gmane.org \
    --cc=broonie-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org \
    --cc=dan.j.williams-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=dong.aisheng-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=kernel-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=lrg-l0cyMroinI0@public.gmane.org \
    --cc=shawn.guo-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=timur-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
    --cc=vinod.koul-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org \
    --cc=w.sang-bIcnvbaLZ9MEGnE8C9+IrQ@public.gmane.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).