Skip to contentSkip to conversation

Asoc Davinci Voicecodec: Added support based on copy_from_user instead of DMA

PATCH In review Raffaele Recalcati 2 participants 2 messages Jul 14, 2010

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Asoc Davinci Voicecodec: Added support based on copy_from_user instead of DMA

From: Davide Bonfanti <[email protected]>

Since DM365 has the same DMA event for McBSP and Voicecodec this two peripherals cannot be used at the same time.
This driver implements Voicecodec without the use of a DMA but with a copy_from_user.
There's a buffer of BUF_SIZE (tested with 2KB) bytes in the driver that is filled with davinci_pcm_copy.
When pcm is running, a TIMER interrupt is activated each 1.36ms in order to fill HW FIFO (dm_vc_irq).
BUG: It happens sometimes that the peripheral stops working so there's a trap.
This driver was tested with timer1 and timer4.
The measures made using a GPIO and scope give a time for copy_from_user about 8/10us (triggered by alsa layer) while TIMER interrupt takes 1.5us.

This patch has been developed against the
http://git.kernel.org/pub/scm/linux/kernel/git/khilman/linux-davinci.git
git tree and tested on bmx board.

---
 sound/soc/davinci/Makefile                   |    1 +
 sound/soc/davinci/davinci-pcm-copyfromuser.c |  333 ++++++++++++++++++++++++++
 sound/soc/davinci/davinci-pcm.h              |    1 +
 sound/soc/soc-core.c                         |   31 ++-
 4 files changed, 354 insertions(+), 12 deletions(-)
 create mode 100644 sound/soc/davinci/davinci-pcm-copyfromuser.c
sound/soc/davinci/Makefile +1 -0
index a93679d..7d6a9a1 100644
@@ -1,5 +1,6 @@
 # DAVINCI Platform Support
 snd-soc-davinci-objs := davinci-pcm.o
+snd-soc-davinci-objs += davinci-pcm-copyfromuser.o
 snd-soc-davinci-i2s-objs := davinci-i2s.o
 snd-soc-davinci-mcasp-objs:= davinci-mcasp.o
 snd-soc-davinci-vcif-objs:= davinci-vcif.o
sound/soc/davinci/davinci-pcm-copyfromuser.c new file +333 -0

333 lines not on this page · raw message

sound/soc/davinci/davinci-pcm.h +1 -0
index 0764944..cb7c2aa 100644
@@ -29,5 +29,6 @@ struct davinci_pcm_dma_params {
 
 
 extern struct snd_soc_platform davinci_soc_platform;
+extern struct snd_soc_platform davinci_soc_platform_copy;
 
 #endif
sound/soc/soc-core.c +19 -12
index ad7f952..696e8b3 100644
@@ -801,7 +801,7 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 	}
 	return 0;
 }
-
+#if 0
 /* ASoC PCM operations */
 static struct snd_pcm_ops soc_pcm_ops = {
 	.open		= soc_pcm_open,
@@ -811,7 +811,7 @@ static struct snd_pcm_ops soc_pcm_ops = {
 	.prepare	= soc_pcm_prepare,
 	.trigger	= soc_pcm_trigger,
 };
-
+#endif
 #ifdef CONFIG_PM
 /* powers down audio subsystem for suspend */
 static int soc_suspend(struct device *dev)
@@ -1306,6 +1306,7 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
 	struct snd_pcm *pcm;
 	char new_name[64];
 	int ret = 0, playback = 0, capture = 0;
+	struct snd_pcm_ops *soc_pcm_ops;
 
 	rtd = kzalloc(sizeof(struct snd_soc_pcm_runtime), GFP_KERNEL);
 	if (rtd == NULL)
@@ -1335,19 +1336,25 @@ static int soc_new_pcm(struct snd_soc_device *socdev,
 
 	dai_link->pcm = pcm;
 	pcm->private_data = rtd;
-	soc_pcm_ops.mmap = platform->pcm_ops->mmap;
-	soc_pcm_ops.pointer = platform->pcm_ops->pointer;
-	soc_pcm_ops.ioctl = platform->pcm_ops->ioctl;
-	soc_pcm_ops.copy = platform->pcm_ops->copy;
-	soc_pcm_ops.silence = platform->pcm_ops->silence;
-	soc_pcm_ops.ack = platform->pcm_ops->ack;
-	soc_pcm_ops.page = platform->pcm_ops->page;
+	soc_pcm_ops = kmalloc(sizeof(struct snd_pcm_ops), GFP_KERNEL);
+	soc_pcm_ops->open		= soc_pcm_open;
+	soc_pcm_ops->close		= soc_codec_close;
+	soc_pcm_ops->hw_params	= soc_pcm_hw_params;
+	soc_pcm_ops->hw_free	= soc_pcm_hw_free;
+	soc_pcm_ops->prepare	= soc_pcm_prepare;
+	soc_pcm_ops->trigger	= soc_pcm_trigger;
+	soc_pcm_ops->mmap = platform->pcm_ops->mmap;
+	soc_pcm_ops->pointer = platform->pcm_ops->pointer;
+	soc_pcm_ops->ioctl = platform->pcm_ops->ioctl;
+	soc_pcm_ops->copy = platform->pcm_ops->copy;
+	soc_pcm_ops->silence = platform->pcm_ops->silence;
+	soc_pcm_ops->ack = platform->pcm_ops->ack;
+	soc_pcm_ops->page = platform->pcm_ops->page;
 
 	if (playback)
-		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
-
+		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, soc_pcm_ops);
 	if (capture)
-		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
+		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, soc_pcm_ops);
 
 	ret = platform->pcm_new(codec->card, codec_dai, pcm);
 	if (ret < 0) {
Signature · 1 line
1.7.0.4
#1 lore raw
Quoted 4 lines · Raffaele Recalcati

From: Davide Bonfanti <[email protected]>

Since DM365 has the same DMA event for McBSP and Voicecodec this two peripherals cannot be used at the same time.

Please try to format your patches as documented in SubmittingPatches - you don't want all this indentation you're introducing in the start of the changelog. There's also other stuff with regard to coding style and so on that it'd be useful for you to look at.

Quoted 2 lines

This driver implements Voicecodec without the use of a DMA but with a copy_from_user.

Why is this specific to the voice CODEC? Shouldn't this be generally usable, and wouldn't it be better if the DMA driver were able to do some automatic fallback here so that in cases where DMA can be used it will be?

I had thought from the discussion on original submission that the two devices were mutually exclusive for other reasons anyway.

sound/soc/davinci/davinci-pcm-copyfromuser.c line 43

Quoted 8 lines
sound/soc/davinci/davinci-pcm-copyfromuser.c new file +8 -0
+/* Timer register offsets */
+#define PID12                   0x00
+#define TIM12                   0x10
+#define TIM34                   0x14
+#define PRD12                   0x18
+#define PRD34                   0x1c
+#define TCR                     0x20
+#define TGCR                    0x24

This timer stuff all looks rather like it should be in whatever other code manages the timers - as it stands it'll get into a fight with anything else trying to use them. I'd expect something like this to use hrtimers to get high resolution time rather than banging the timer hardware directly.

sound/soc/davinci/davinci-pcm-copyfromuser.c line 80

Quoted 2 lines
sound/soc/davinci/davinci-pcm-copyfromuser.c new file +2 -0
+int pointer_sub;
+u16 local_buffer[BUF_SIZE/2];

Should BUF_SIZE not be a configuration option, or dynamically configured at runtime?

Quoted 4 lines

+/*
+ * ppcm = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
+ * &pcm_hardware_playback : &pcm_hardware_capture;
+ */

Remove this if it's not used.

sound/soc/davinci/davinci-pcm-copyfromuser.c line 152

Quoted 2 lines
sound/soc/davinci/davinci-pcm-copyfromuser.c new file +2 -0
+	__raw_writel(0x0, IO_ADDRESS(0x01D0C008));
+	__raw_writel(0x7400, IO_ADDRESS(0x01D0C004));

This could do with being substantially clearer... There's quite a few other magic numbers in the code which need fixing.

sound/soc/davinci/davinci-pcm-copyfromuser.c line 166

Quoted 8 lines
sound/soc/davinci/davinci-pcm-copyfromuser.c new file +8 -0
+static int davinci_pcm_close(struct snd_pcm_substream *substream)
+{
+	struct snd_pcm_runtime *runtime = substream->runtime;
+	struct clk *clk;
+
+	clk = clk_get(NULL, TIMER);
+	if (!IS_ERR(clk))
+		clk_disable(clk);

As with your previous patch you're going to be leaking clocks all over - you should be balancing your clk_get() with clk_put().

sound/soc/davinci/davinci-pcm-copyfromuser.c line 317

Quoted 5 lines
sound/soc/davinci/davinci-pcm-copyfromuser.c new file +5 -0
+struct snd_soc_platform davinci_soc_platform_copy = {
+	.name =		"davinci-audio-copy",
+	.pcm_ops =	&davinci_pcm_ops,
+	.pcm_new =	davinci_pcm_new,
+}; EXPORT_SYMBOL_GPL(davinci_soc_platform_copy);

Fix your formatting here.

Quoted 11 lines

+++ b/sound/soc/soc-core.c

sound/soc/soc-core.c +1 -1
@@ -801,7 +801,7 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 	}
 	return 0;
 }
-
+#if 0
 /* ASoC PCM operations */
 static struct snd_pcm_ops soc_pcm_ops = {
 	.open		= soc_pcm_open,

sound/soc/soc-core.c static struct snd_pcm_ops soc_pcm_ops = { · line 814

Quoted 5 lines
sound/soc/soc-core.c +1 -1
@@ -811,7 +811,7 @@ static struct snd_pcm_ops soc_pcm_ops = {
 	.prepare	= soc_pcm_prepare,
 	.trigger	= soc_pcm_trigger,
 };
-
+#endif

Um....? I'm not entirely sure what this and the rest of the changes in the file are supposed to do but they weren't mentioned at all in the changelog. If this is needed it should be a separate change with a proper changelog explaining what's going on.