linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Arnd Bergmann <arnd@arndb.de>
To: linux-arm-kernel@lists.infradead.org
Cc: linux-kernel@vger.kernel.org, Kukjin Kim <kgene.kim@samsung.com>,
	linux-samsung-soc@vger.kernel.org, Arnd Bergmann <arnd@arndb.de>,
	alsa-devel@alsa-project.org,
	Mark Brown <broonie@opensource.wolfsonmicro.com>,
	Liam Girdwood <lgirdwood@gmail.com>
Subject: [PATCH 20/30] ASoC: samsung: convert to dmaengine API
Date: Thu, 11 Apr 2013 02:05:02 +0200	[thread overview]
Message-ID: <1365638712-1028578-21-git-send-email-arnd@arndb.de> (raw)
In-Reply-To: <1365638712-1028578-1-git-send-email-arnd@arndb.de>

In order to build the exynos kernel with CONFIG_ARCH_MULTIPLATFORM,
we must convert all users of the Samsung private DMA interface to
the generic dmaengine API. This version of the patch adds the
generic dmaengine API as an alternative to the existing samsung
specific one. Once all the older platforms provide support for
the common dmaengine interfaces, we can remove the old code.

Signed-off-by: Arnd Bergmann <arnd@arndb.de>
Cc: alsa-devel@alsa-project.org
Cc: Mark Brown <broonie@opensource.wolfsonmicro.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>
---
 sound/soc/samsung/dma.c   | 219 ++++++++++++++++++++++++++++++++++++++++++++++
 sound/soc/samsung/dma.h   |  15 +++-
 sound/soc/samsung/i2s.c   |   2 -
 sound/soc/samsung/pcm.c   |   1 -
 sound/soc/samsung/spdif.c |   1 -
 5 files changed, 232 insertions(+), 6 deletions(-)

diff --git a/sound/soc/samsung/dma.c b/sound/soc/samsung/dma.c
index 21b7926..9fd53df 100644
--- a/sound/soc/samsung/dma.c
+++ b/sound/soc/samsung/dma.c
@@ -22,8 +22,14 @@
 #include <sound/pcm_params.h>
 
 #include <asm/dma.h>
+
+#ifdef CONFIG_SAMSUNG_DMADEV
 #include <mach/hardware.h>
 #include <mach/dma.h>
+#else
+#include <linux/dmaengine.h>
+#include <linux/amba/pl330.h>
+#endif
 
 #include "dma.h"
 
@@ -62,11 +68,13 @@ struct runtime_data {
 
 static void audio_buffdone(void *data);
 
+#ifdef CONFIG_SAMSUNG_DMADEV
 /* dma_enqueue
  *
  * place a dma buffer onto the queue for the dma system
  * to handle.
  */
+
 static void dma_enqueue(struct snd_pcm_substream *substream)
 {
 	struct runtime_data *prtd = substream->runtime->private_data;
@@ -265,6 +273,217 @@ static int dma_trigger(struct snd_pcm_substream *substream, int cmd)
 
 	return ret;
 }
+#else
+/* dma_enqueue
+ *
+ * place a dma buffer onto the queue for the dma system
+ * to handle.
+ */
+
+static void dma_enqueue(struct snd_pcm_substream *substream)
+{
+	struct runtime_data *prtd = substream->runtime->private_data;
+	dma_addr_t pos = prtd->dma_pos;
+	unsigned long period = prtd->dma_period;
+	unsigned int limit;
+	enum dma_transfer_direction direction;
+	struct dma_chan *chan = prtd->params->ch;
+	struct dma_async_tx_descriptor *desc;
+
+	pr_debug("Entered %s\n", __func__);
+
+	limit = (prtd->dma_end - prtd->dma_start) / prtd->dma_period;
+
+	pr_debug("%s: loaded %d, limit %d\n",
+				__func__, prtd->dma_loaded, limit);
+
+	direction = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK
+		     ? DMA_MEM_TO_DEV : DMA_DEV_TO_MEM);
+
+	while (prtd->dma_loaded < limit) {
+		pr_debug("dma_loaded: %d\n", prtd->dma_loaded);
+
+		if ((pos + period) > prtd->dma_end) {
+			period  = prtd->dma_end - pos;
+			pr_debug("%s: corrected dma len %ld\n",
+					__func__, period);
+		}
+
+		desc = dmaengine_prep_dma_cyclic(chan, pos,
+			 prtd->dma_period*limit, period, direction,
+			DMA_PREP_INTERRUPT | DMA_CTRL_ACK);
+
+		if (desc) {
+			desc->callback = audio_buffdone;
+			desc->callback_param = substream;
+			dmaengine_submit(desc);
+		}
+
+		prtd->dma_loaded++;
+		pos += period;
+		if (pos >= prtd->dma_end)
+			pos = prtd->dma_start;
+	}
+
+	prtd->dma_pos = pos;
+}
+
+static void audio_buffdone(void *data)
+{
+	struct snd_pcm_substream *substream = data;
+	struct runtime_data *prtd = substream->runtime->private_data;
+
+	pr_debug("Entered %s\n", __func__);
+
+	if (prtd->state & ST_RUNNING) {
+		prtd->dma_pos += prtd->dma_period;
+		if (prtd->dma_pos >= prtd->dma_end)
+			prtd->dma_pos = prtd->dma_start;
+
+		if (substream)
+			snd_pcm_period_elapsed(substream);
+	}
+}
+
+static int dma_hw_params(struct snd_pcm_substream *substream,
+	struct snd_pcm_hw_params *params)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	struct runtime_data *prtd = runtime->private_data;
+	struct snd_soc_pcm_runtime *rtd = substream->private_data;
+	unsigned long totbytes = params_buffer_bytes(params);
+	struct s3c_dma_params *dma =
+		snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
+
+	pr_debug("Entered %s\n", __func__);
+
+	/* return if this is a bufferless transfer e.g.
+	 * codec <--> BT codec or GSM modem -- lg FIXME */
+	if (!dma)
+		return 0;
+
+	/* this may get called several times by oss emulation
+	 * with different params -HW */
+	if (prtd->params == NULL) {
+		struct dma_slave_config config;
+		dma_cap_mask_t mask;
+
+		/* prepare DMA */
+		prtd->params = dma;
+
+		pr_debug("params %p, channel %d\n", prtd->params,
+			 prtd->params->channel);
+
+		dma_cap_zero(mask);
+		dma_cap_set(DMA_CYCLIC, mask);
+
+		prtd->params->ch = dma_request_slave_channel_compat(mask,
+			pl330_filter, (void *)prtd->params->channel,
+			rtd->cpu_dai->dev, prtd->params->ch_name);
+
+		memset(&config, 0, sizeof(struct dma_slave_config));
+
+		if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+			config.direction = DMA_MEM_TO_DEV;
+			config.dst_addr = prtd->params->dma_addr;
+			config.dst_addr_width = prtd->params->dma_size;
+			config.dst_maxburst = 1;
+			dmaengine_slave_config(prtd->params->ch, &config);
+		} else {
+			config.direction = DMA_DEV_TO_MEM;
+			config.src_addr = prtd->params->dma_addr;
+			config.src_addr_width = prtd->params->dma_size;
+			config.src_maxburst = 1;
+			dmaengine_slave_config(prtd->params->ch, &config);
+		}
+	}
+
+	snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
+
+	runtime->dma_bytes = totbytes;
+
+	spin_lock_irq(&prtd->lock);
+	prtd->dma_loaded = 0;
+	prtd->dma_period = params_period_bytes(params);
+	prtd->dma_start = runtime->dma_addr;
+	prtd->dma_pos = prtd->dma_start;
+	prtd->dma_end = prtd->dma_start + totbytes;
+	spin_unlock_irq(&prtd->lock);
+
+	return 0;
+}
+
+static int dma_hw_free(struct snd_pcm_substream *substream)
+{
+	struct runtime_data *prtd = substream->runtime->private_data;
+
+	pr_debug("Entered %s\n", __func__);
+
+	snd_pcm_set_runtime_buffer(substream, NULL);
+
+	if (prtd->params) {
+		dmaengine_terminate_all(prtd->params->ch);
+		dma_release_channel(prtd->params->ch);
+		prtd->params = NULL;
+	}
+
+	return 0;
+}
+
+static int dma_prepare(struct snd_pcm_substream *substream)
+{
+	struct runtime_data *prtd = substream->runtime->private_data;
+	int ret = 0;
+
+	pr_debug("Entered %s\n", __func__);
+
+	/* return if this is a bufferless transfer e.g.
+	 * codec <--> BT codec or GSM modem -- lg FIXME */
+	if (!prtd->params)
+		return 0;
+
+	/* flush the DMA channel */
+	dmaengine_terminate_all(prtd->params->ch);
+
+	prtd->dma_loaded = 0;
+	prtd->dma_pos = prtd->dma_start;
+
+	/* enqueue dma buffers */
+	dma_enqueue(substream);
+
+	return ret;
+}
+
+static int dma_trigger(struct snd_pcm_substream *substream, int cmd)
+{
+	struct runtime_data *prtd = substream->runtime->private_data;
+	int ret = 0;
+
+	pr_debug("Entered %s\n", __func__);
+
+	spin_lock(&prtd->lock);
+
+	switch (cmd) {
+	case SNDRV_PCM_TRIGGER_START:
+		prtd->state |= ST_RUNNING;
+		dma_async_issue_pending(prtd->params->ch);
+		break;
+
+	case SNDRV_PCM_TRIGGER_STOP:
+		prtd->state &= ~ST_RUNNING;
+		dmaengine_terminate_all(prtd->params->ch);
+		break;
+
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	spin_unlock(&prtd->lock);
+
+	return ret;
+}
+#endif
 
 static snd_pcm_uframes_t
 dma_pointer(struct snd_pcm_substream *substream)
diff --git a/sound/soc/samsung/dma.h b/sound/soc/samsung/dma.h
index 189a7a6..6bd1857 100644
--- a/sound/soc/samsung/dma.h
+++ b/sound/soc/samsung/dma.h
@@ -12,13 +12,24 @@
 #ifndef _S3C_AUDIO_H
 #define _S3C_AUDIO_H
 
+#ifdef CONFIG_SAMSUNG_DMADEV
+#include <mach/dma.h>
+#endif
+
 struct s3c_dma_params {
+#ifdef CONFIG_SAMSUNG_DMADEV
 	struct s3c2410_dma_client *client;	/* stream identifier */
+	unsigned ch;
+	struct samsung_dma_ops *ops;
+#else
+	struct s3c2410_dma_client {
+		char *name;			/* unused */
+	} *client;
+	struct dma_chan *ch;
+#endif
 	int channel;				/* Channel ID */
 	dma_addr_t dma_addr;
 	int dma_size;			/* Size of the DMA transfer */
-	unsigned ch;
-	struct samsung_dma_ops *ops;
 	char *ch_name;
 };
 
diff --git a/sound/soc/samsung/i2s.c b/sound/soc/samsung/i2s.c
index d7231e3..61f2622 100644
--- a/sound/soc/samsung/i2s.c
+++ b/sound/soc/samsung/i2s.c
@@ -22,8 +22,6 @@
 #include <sound/soc.h>
 #include <sound/pcm_params.h>
 
-#include <mach/dma.h>
-
 #include <linux/platform_data/asoc-s3c.h>
 
 #include "dma.h"
diff --git a/sound/soc/samsung/pcm.c b/sound/soc/samsung/pcm.c
index 13bab79..b5f267c 100644
--- a/sound/soc/samsung/pcm.c
+++ b/sound/soc/samsung/pcm.c
@@ -20,7 +20,6 @@
 #include <sound/pcm_params.h>
 
 #include <linux/platform_data/asoc-s3c.h>
-#include <mach/dma.h>
 
 #include "dma.h"
 #include "pcm.h"
diff --git a/sound/soc/samsung/spdif.c b/sound/soc/samsung/spdif.c
index 5008e5b..ee792aa 100644
--- a/sound/soc/samsung/spdif.c
+++ b/sound/soc/samsung/spdif.c
@@ -18,7 +18,6 @@
 #include <sound/pcm_params.h>
 
 #include <linux/platform_data/asoc-s3c.h>
-#include <mach/dma.h>
 
 #include "dma.h"
 #include "spdif.h"
-- 
1.8.1.2


  parent reply	other threads:[~2013-04-11  0:09 UTC|newest]

Thread overview: 71+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-04-11  0:04 [PATCH 00/30] ARM: exynos multiplatform support Arnd Bergmann
2013-04-11  0:04 ` [PATCH 01/30] ARM: exynos: introduce EXYNOS_ATAGS symbol Arnd Bergmann
2013-04-11  0:04 ` [PATCH 02/30] ARM: exynos: prepare for sparse IRQ Arnd Bergmann
2013-04-11  0:17   ` Kyungmin Park
2013-04-11  0:04 ` [PATCH 03/30] ARM: exynos: move debug-macro.S to include/debug/ Arnd Bergmann
2013-04-11  0:04 ` [PATCH 04/30] ARM: samsung: move mfc device definition to s5p-dev-mfc.c Arnd Bergmann
2013-04-11  0:04 ` [PATCH 05/30] tty: serial/samsung: prepare for common clock API Arnd Bergmann
2013-04-11  0:04 ` [PATCH 06/30] tty: serial/samsung: make register definitions global Arnd Bergmann
2013-04-11  0:04 ` [PATCH 07/30] tty: serial/samsung: fix modular build Arnd Bergmann
2013-04-11  0:04 ` [PATCH 08/30] i2c: s3c2410: make header file local Arnd Bergmann
2013-04-14 12:20   ` Wolfram Sang
2013-04-14 17:01     ` Heiko Stübner
2013-04-11  0:04 ` [PATCH 09/30] mmc: sdhci-s3c: remove platform dependencies Arnd Bergmann
2013-04-11  1:06   ` Chris Ball
2013-04-11  0:04 ` [PATCH 10/30] usb: exynos: do not include plat/usb-phy.h Arnd Bergmann
2013-04-11 20:25   ` Greg Kroah-Hartman
2013-04-11 20:49     ` [PATCH v3] " Arnd Bergmann
2013-04-11  0:04 ` [PATCH 11/30] [media] exynos: remove unnecessary header inclusions Arnd Bergmann
2013-04-11  0:13   ` Mauro Carvalho Chehab
2013-04-11  9:07     ` Sylwester Nawrocki
2013-04-11 10:52       ` Arnd Bergmann
2013-04-11  0:04 ` [PATCH 12/30] video/exynos: " Arnd Bergmann
2013-04-11  5:07   ` Jingoo Han
2013-04-11 11:51   ` Tomi Valkeinen
2013-04-11 12:08     ` Arnd Bergmann
2013-04-11  0:04 ` [PATCH 13/30] video/s3c: move platform_data out of arch/arm Arnd Bergmann
2013-04-11  4:34   ` Jingoo Han
2013-04-11  5:12   ` Jingoo Han
2013-04-11  0:04 ` [PATCH 14/30] thermal/exynos: remove unnecessary header inclusions Arnd Bergmann
2013-04-11  1:19   ` Eduardo Valentin
2013-04-11 23:26     ` Zhang Rui
2013-04-11  0:04 ` [PATCH 15/30] mtd: onenand/samsung: make regs-onenand.h file local Arnd Bergmann
2013-04-11  0:18   ` Kyungmin Park
2013-04-11  0:04 ` [PATCH 16/30] rtc: s3c: make header " Arnd Bergmann
2013-04-11  0:04 ` [PATCH 17/30] pwm: samsung: repair the worst MMIO abuses Arnd Bergmann
2013-04-12  7:06   ` Thierry Reding
2013-04-12  7:46     ` Tomasz Figa
2013-04-11  0:05 ` [PATCH 18/30] ASoC: samsung: move plat/ headers to local directory Arnd Bergmann
2013-04-11 16:47   ` Mark Brown
2013-04-11 17:08     ` Arnd Bergmann
2013-04-11 17:19       ` Mark Brown
2013-04-11 19:02         ` [PATCH] ASoC: samsung: fix neo1973-wm8753 compilation Heiko Stübner
2013-04-12 12:13           ` Mark Brown
2013-04-12 11:04         ` [alsa-devel] [PATCH 18/30] ASoC: samsung: move plat/ headers to local directory Lars-Peter Clausen
2013-04-12 11:26           ` Mark Brown
2013-04-11  0:05 ` [PATCH 19/30] ASoC: samsung: use irq resource for idma Arnd Bergmann
2013-04-11 16:48   ` Mark Brown
2013-04-11  0:05 ` Arnd Bergmann [this message]
2013-04-11 14:27   ` [PATCH 20/30] ASoC: samsung: convert to dmaengine API Mark Brown
2013-04-11 14:47     ` Arnd Bergmann
2013-04-11 15:42       ` Mark Brown
2013-04-12 19:27       ` [alsa-devel] " Lars-Peter Clausen
2013-04-15 11:04         ` Mark Brown
2013-04-11  0:05 ` [PATCH 21/30] ASoC: samsung/i2s: fix module_device_table Arnd Bergmann
2013-04-11 16:48   ` Mark Brown
2013-04-11  0:05 ` [PATCH 22/30] ASoC: samsung/idma: export idma_reg_addr_init Arnd Bergmann
2013-04-11 16:48   ` Mark Brown
2013-04-11  0:05 ` [PATCH 23/30] clk: exynos: prepare for multiplatform Arnd Bergmann
2013-04-11  0:05 ` [PATCH 24/30] clocksource: exynos_mct: remove platform header dependency Arnd Bergmann
2013-04-11  0:05 ` [PATCH 25/30] irqchip: exynos: pass max combiner number to combiner_init Arnd Bergmann
2013-04-11  0:05 ` [PATCH 26/30] irqchip: exynos: allocate combiner_data dynamically Arnd Bergmann
2013-04-11  0:05 ` [PATCH 27/30] irqchip: exynos: localize irq lookup for ATAGS Arnd Bergmann
2013-04-11  0:05 ` [PATCH 28/30] irqchip: exynos: pass irq_base from platform Arnd Bergmann
2013-04-11  0:05 ` [PATCH 29/30] spi: s3c64xx: move to generic dmaengine API Arnd Bergmann
2013-04-11 16:55   ` Mark Brown
2013-04-11 20:42     ` [PATCH v2] " Arnd Bergmann
2013-04-12 12:55       ` Mark Brown
2013-04-17 14:46       ` Mark Brown
2013-04-17 20:05   ` [PATCH 29/30] " Arnd Bergmann
2013-04-18 16:46     ` Mark Brown
2013-04-11  0:05 ` [PATCH 30/30] ARM: exynos: enable multiplatform support Arnd Bergmann

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=1365638712-1028578-21-git-send-email-arnd@arndb.de \
    --to=arnd@arndb.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=broonie@opensource.wolfsonmicro.com \
    --cc=kgene.kim@samsung.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-samsung-soc@vger.kernel.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).