Skip to contentSkip to conversation

ASoC: DaVinci: remove requirement that dma_params is 1st in structure

PATCH In review Troy Kisky 4 participants 6 messages Nov 16, 2009 – Jul 13, 2010 1 message not in the archive

Subsystems (5)
lore
Share & tools
lore

Troy Kisky

author
#0 lore raw

PATCH 1/4 ASoC: DaVinci: remove requirement that dma_params is 1st in structure

Remove requirement that dma_params is 1st in the structures davinci_audio_dev and davinci_mcbsp_dev.

---
 sound/soc/davinci/davinci-i2s.c   |    6 +-----
 sound/soc/davinci/davinci-mcasp.c |    1 +
 sound/soc/davinci/davinci-mcasp.h |    5 -----
 sound/soc/davinci/davinci-pcm.c   |    7 ++++---
 4 files changed, 6 insertions(+), 13 deletions(-)
sound/soc/davinci/davinci-i2s.c +1 -5
index 4ae7070..9e69a4e 100644
@@ -98,11 +98,6 @@ enum {
 };
 
 struct davinci_mcbsp_dev {
-	/*
-	 * dma_params must be first because rtd->dai->cpu_dai->private_data
-	 * is cast to a pointer of an array of struct davinci_pcm_dma_params in
-	 * davinci_pcm_open.
-	 */
 	struct davinci_pcm_dma_params	dma_params[2];
 	void __iomem			*base;
 #define MOD_DSP_A	0
@@ -547,6 +542,7 @@ static int davinci_i2s_probe(struct platform_device *pdev)
 	dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = res->start;
 
 	davinci_i2s_dai.private_data = dev;
+	davinci_i2s_dai.dma_data = dev->dma_params;
 	ret = snd_soc_register_dai(&davinci_i2s_dai);
 	if (ret != 0)
 		goto err_free_mem;
sound/soc/davinci/davinci-mcasp.c +1 -0
index 5d1f98a..5023915 100644
@@ -907,6 +907,7 @@ static int davinci_mcasp_probe(struct platform_device *pdev)
 
 	dma_data->channel = res->start;
 	davinci_mcasp_dai[pdata->op_mode].private_data = dev;
+	davinci_mcasp_dai[pdata->op_mode].dma_data = dev->dma_params;
 	davinci_mcasp_dai[pdata->op_mode].dev = &pdev->dev;
 	ret = snd_soc_register_dai(&davinci_mcasp_dai[pdata->op_mode]);
 
sound/soc/davinci/davinci-mcasp.h +0 -5
index 9d179cc..582c924 100644
@@ -39,11 +39,6 @@ enum {
 };
 
 struct davinci_audio_dev {
-	/*
-	 * dma_params must be first because rtd->dai->cpu_dai->private_data
-	 * is cast to a pointer of an array of struct davinci_pcm_dma_params in
-	 * davinci_pcm_open.
-	 */
 	struct davinci_pcm_dma_params dma_params[2];
 	void __iomem *base;
 	int sample_rate;
sound/soc/davinci/davinci-pcm.c +4 -3
index c73a915..c2c2e85 100644
@@ -238,10 +238,11 @@ static int davinci_pcm_open(struct snd_pcm_substream *substream)
 	struct davinci_runtime_data *prtd;
 	int ret = 0;
 	struct snd_soc_pcm_runtime *rtd = substream->private_data;
-	struct davinci_pcm_dma_params *pa = rtd->dai->cpu_dai->private_data;
-	struct davinci_pcm_dma_params *params = &pa[substream->stream];
-	if (!params)
+	struct davinci_pcm_dma_params *pa = rtd->dai->cpu_dai->dma_data;
+	struct davinci_pcm_dma_params *params;
+	if (!pa)
 		return -ENODEV;
+	params = &pa[substream->stream];
 
 	snd_soc_set_runtime_hwparams(substream, &davinci_pcm_hardware);
 	/* ensure that buffer size is a multiple of period size */
Signature · 1 line
1.5.6.3
#1 lore raw

PATCH 2/4 ASoC: DaVinci: i2s, reduce underruns by combining into 1 element

Allow the left and right 16 bit samples to be shifted out as 1 32 bit sample.

---
 arch/arm/mach-davinci/include/mach/asp.h |    6 ++
 sound/soc/davinci/davinci-i2s.c          |   74 ++++++++++++++++++++++--------
 2 files changed, 61 insertions(+), 19 deletions(-)
arch/arm/mach-davinci/include/mach/asp.h +6 -0
index 18e4ce3..019c647 100644
@@ -51,6 +51,12 @@ struct snd_platform_data {
 	u32 rx_dma_offset;
 	enum dma_event_q eventq_no;	/* event queue number */
 	unsigned int codec_fmt;
+	/*
+	 * Allowing this is more efficient and eliminates left and right swaps
+	 * caused by underruns, but will swap the left and right channels
+	 * when compared to previous behavior.
+	 */
+	unsigned enable_channel_combine:1;
 
 	/* McASP specific fields */
 	int tdm_slots;
sound/soc/davinci/davinci-i2s.c +55 -19

107 lines not on this page · raw message

Signature · 1 line
1.5.6.3
#2 lore raw

PATCH 3/4 ASoC: DaVinci: pcm, rename variables in prep for ping/pong

Rename variable master_lch to asp_channel
Rename variable slave_lch to asp_link[0]
Rename local variables:
lch to link
count to asp_count
src to asp_src
dst to asp_dst

---
 sound/soc/davinci/davinci-pcm.c |   64 +++++++++++++++++++-------------------
 1 files changed, 32 insertions(+), 32 deletions(-)
sound/soc/davinci/davinci-pcm.c +32 -32
index c2c2e85..7757010 100644
@@ -51,8 +51,8 @@ static struct snd_pcm_hardware davinci_pcm_hardware = {
 struct davinci_runtime_data {
 	spinlock_t lock;
 	int period;		/* current DMA period */
-	int master_lch;		/* Master DMA channel */
-	int slave_lch;		/* linked parameter RAM reload slot */
+	int asp_channel;	/* Master DMA channel */
+	int asp_link[2];	/* asp parameter link channel, ping/pong */
 	struct davinci_pcm_dma_params *params;	/* DMA params */
 };
 
@@ -60,7 +60,7 @@ static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
 {
 	struct davinci_runtime_data *prtd = substream->runtime->private_data;
 	struct snd_pcm_runtime *runtime = substream->runtime;
-	int lch = prtd->slave_lch;
+	int link = prtd->asp_link[0];
 	unsigned int period_size;
 	unsigned int dma_offset;
 	dma_addr_t dma_pos;
@@ -75,7 +75,7 @@ static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
 	dma_pos = runtime->dma_addr + dma_offset;
 
 	pr_debug("davinci_pcm: audio_set_dma_params_play channel = %d "
-		"dma_ptr = %x period_size=%x\n", lch, dma_pos, period_size);
+		"dma_ptr = %x period_size=%x\n", link, dma_pos, period_size);
 
 	data_type = prtd->params->data_type;
 	count = period_size / data_type;
@@ -93,23 +93,23 @@ static void davinci_pcm_enqueue_dma(struct snd_pcm_substream *substream)
 	}
 
 	acnt = prtd->params->acnt;
-	edma_set_src(lch, src, INCR, W8BIT);
-	edma_set_dest(lch, dst, INCR, W8BIT);
-	edma_set_src_index(lch, src_bidx, 0);
-	edma_set_dest_index(lch, dst_bidx, 0);
-	edma_set_transfer_params(lch, acnt, count, 1, 0, ASYNC);
+	edma_set_src(link, src, INCR, W8BIT);
+	edma_set_dest(link, dst, INCR, W8BIT);
+	edma_set_src_index(link, src_bidx, 0);
+	edma_set_dest_index(link, dst_bidx, 0);
+	edma_set_transfer_params(link, acnt, count, 1, 0, ASYNC);
 
 	prtd->period++;
 	if (unlikely(prtd->period >= runtime->periods))
 		prtd->period = 0;
 }
 
-static void davinci_pcm_dma_irq(unsigned lch, u16 ch_status, void *data)
+static void davinci_pcm_dma_irq(unsigned link, u16 ch_status, void *data)
 {
 	struct snd_pcm_substream *substream = data;
 	struct davinci_runtime_data *prtd = substream->runtime->private_data;
 
-	pr_debug("davinci_pcm: lch=%d, status=0x%x\n", lch, ch_status);
+	pr_debug("davinci_pcm: link=%d, status=0x%x\n", link, ch_status);
 
 	if (unlikely(ch_status != DMA_COMPLETE))
 		return;
@@ -135,15 +135,15 @@ static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
 				  EVENTQ_0);
 	if (ret < 0)
 		return ret;
-	prtd->master_lch = ret;
+	prtd->asp_channel = ret;
 
 	/* Request parameter RAM reload slot */
-	ret = edma_alloc_slot(EDMA_CTLR(prtd->master_lch), EDMA_SLOT_ANY);
+	ret = edma_alloc_slot(EDMA_CTLR(prtd->asp_channel), EDMA_SLOT_ANY);
 	if (ret < 0) {
-		edma_free_channel(prtd->master_lch);
+		edma_free_channel(prtd->asp_channel);
 		return ret;
 	}
-	prtd->slave_lch = ret;
+	prtd->asp_link[0] = ret;
 
 	/* Issue transfer completion IRQ when the channel completes a
 	 * transfer, then always reload from the same slot (by a kind
@@ -154,10 +154,10 @@ static int davinci_pcm_dma_request(struct snd_pcm_substream *substream)
 	 * the buffer and its length (ccnt) ... use it as a template
 	 * so davinci_pcm_enqueue_dma() takes less time in IRQ.
 	 */
-	edma_read_slot(prtd->slave_lch, &p_ram);
-	p_ram.opt |= TCINTEN | EDMA_TCC(EDMA_CHAN_SLOT(prtd->master_lch));
-	p_ram.link_bcntrld = EDMA_CHAN_SLOT(prtd->slave_lch) << 5;
-	edma_write_slot(prtd->slave_lch, &p_ram);
+	edma_read_slot(prtd->asp_link[0], &p_ram);
+	p_ram.opt |= TCINTEN | EDMA_TCC(EDMA_CHAN_SLOT(prtd->asp_channel));
+	p_ram.link_bcntrld = EDMA_CHAN_SLOT(prtd->asp_link[0]) << 5;
+	edma_write_slot(prtd->asp_link[0], &p_ram);
 
 	return 0;
 }
@@ -173,12 +173,12 @@ static int davinci_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 	case SNDRV_PCM_TRIGGER_START:
 	case SNDRV_PCM_TRIGGER_RESUME:
 	case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
-		edma_start(prtd->master_lch);
+		edma_start(prtd->asp_channel);
 		break;
 	case SNDRV_PCM_TRIGGER_STOP:
 	case SNDRV_PCM_TRIGGER_SUSPEND:
 	case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
-		edma_stop(prtd->master_lch);
+		edma_stop(prtd->asp_channel);
 		break;
 	default:
 		ret = -EINVAL;
@@ -199,8 +199,8 @@ static int davinci_pcm_prepare(struct snd_pcm_substream *substream)
 	davinci_pcm_enqueue_dma(substream);
 
 	/* Copy self-linked parameter RAM entry into master channel */
-	edma_read_slot(prtd->slave_lch, &temp);
-	edma_write_slot(prtd->master_lch, &temp);
+	edma_read_slot(prtd->asp_link[0], &temp);
+	edma_write_slot(prtd->asp_channel, &temp);
 	davinci_pcm_enqueue_dma(substream);
 
 	return 0;
@@ -212,20 +212,20 @@ davinci_pcm_pointer(struct snd_pcm_substream *substream)
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct davinci_runtime_data *prtd = runtime->private_data;
 	unsigned int offset;
-	dma_addr_t count;
-	dma_addr_t src, dst;
+	int asp_count;
+	dma_addr_t asp_src, asp_dst;
 
 	spin_lock(&prtd->lock);
 
-	edma_get_position(prtd->master_lch, &src, &dst);
+	edma_get_position(prtd->asp_channel, &asp_src, &asp_dst);
 	if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
-		count = src - runtime->dma_addr;
+		asp_count = asp_src - runtime->dma_addr;
 	else
-		count = dst - runtime->dma_addr;
+		asp_count = asp_dst - runtime->dma_addr;
 
 	spin_unlock(&prtd->lock);
 
-	offset = bytes_to_frames(runtime, count);
+	offset = bytes_to_frames(runtime, asp_count);
 	if (offset >= runtime->buffer_size)
 		offset = 0;
 
@@ -274,10 +274,10 @@ static int davinci_pcm_close(struct snd_pcm_substream *substream)
 	struct snd_pcm_runtime *runtime = substream->runtime;
 	struct davinci_runtime_data *prtd = runtime->private_data;
 
-	edma_unlink(prtd->slave_lch);
+	edma_unlink(prtd->asp_link[0]);
 
-	edma_free_slot(prtd->slave_lch);
-	edma_free_channel(prtd->master_lch);
+	edma_free_slot(prtd->asp_link[0]);
+	edma_free_channel(prtd->asp_channel);
 
 	kfree(prtd);
 
Signature · 1 line
1.5.6.3
#3 lore raw

PATCH 4/4 ASoC: DaVinci: pcm, fix underrun by using sram

Fix underruns by using dma to copy 1st to sram in a ping/pong buffer style and then copying from the sram to the ASP. This also has the advantage of tolerating very long interrupt latency on dma completion.

---
 arch/arm/mach-davinci/include/mach/asp.h |    2 +
 sound/soc/davinci/davinci-i2s.c          |    7 +-
 sound/soc/davinci/davinci-pcm.c          |  512 +++++++++++++++++++++++++++---
 sound/soc/davinci/davinci-pcm.h          |    1 +
 4 files changed, 476 insertions(+), 46 deletions(-)
arch/arm/mach-davinci/include/mach/asp.h +2 -0
index 019c647..e07f70e 100644
@@ -57,6 +57,8 @@ struct snd_platform_data {
 	 * when compared to previous behavior.
 	 */
 	unsigned enable_channel_combine:1;
+	unsigned sram_size_playback;
+	unsigned sram_size_capture;
 
 	/* McASP specific fields */
 	int tdm_slots;
sound/soc/davinci/davinci-i2s.c +6 -1
index 771cabe..1d3a678 100644
@@ -543,8 +543,13 @@ static int davinci_i2s_probe(struct platform_device *pdev)
 		ret = -ENOMEM;
 		goto err_release_region;
 	}
-	if (pdata)
+	if (pdata) {
 		dev->enable_channel_combine = pdata->enable_channel_combine;
+		dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].sram_size =
+			pdata->sram_size_playback;
+		dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].sram_size =
+			pdata->sram_size_capture;
+	}
 	dev->clk = clk_get(&pdev->dev, NULL);
 	if (IS_ERR(dev->clk)) {
 		ret = -ENODEV;
sound/soc/davinci/davinci-pcm.c +467 -45

655 lines not on this page · raw message

sound/soc/davinci/davinci-pcm.h +1 -0
index 8746606..ca995ca 100644
@@ -20,6 +20,7 @@ struct davinci_pcm_dma_params {
 	int channel;			/* sync dma channel ID */
 	unsigned short acnt;
 	dma_addr_t dma_addr;		/* device physical address for DMA */
+	unsigned sram_size;
 	enum dma_event_q eventq_no;	/* event queue number */
 	unsigned char data_type;	/* xfer data type */
 	unsigned char convert_mono_stereo;
Signature · 1 line
1.5.6.3

A message that is not in the archive (sent off-list or not yet received): 1258415554-31069-4-git-send-email-troy.kisky-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org

#5 lore raw

RE: [PATCH 4/4] ASoC: DaVinci: pcm, fix underrun by using sram

Hi Troy,

Quoted 7 lines · Troy Kisky

Fix underruns by using dma to copy 1st to sram in a ping/pong buffer style and then copying from the sram to the ASP. This also has the advantage of tolerating very long interrupt latency on dma completion.

[...]

sound/soc/davinci/davinci-pcm.c static void davinci_pcm_dma_irq(unsigned link, u16 ch_status, void *data) · line 361

Quoted 13 lines
sound/soc/davinci/davinci-pcm.c +13 -0
+static int request_ping_pong(struct snd_pcm_substream *substream,
+             struct davinci_runtime_data *prtd,
+             struct snd_dma_buffer *iram_dma)
+{
+     dma_addr_t asp_src_ping;
+     dma_addr_t asp_dst_ping;
+     int link;
+     struct davinci_pcm_dma_params *dma_data = prtd->params;
+
+     /* Request ram master channel */
+     link = prtd->ram_channel = edma_alloc_channel(EDMA_CHANNEL_ANY,
+                               davinci_pcm_dma_irq, substream,
+                               EVENTQ_1);

What is the reason for choosing EVENTQ_1 for this channel? EVENTQ_0 is already being used for ASP channel.

I imagine it will be much easier to tune the queue usage in the system if all of audio data was using the same queue.

I am working on a patch which lets platform specify the event queues for audio DMA. I am not sure if I really need to make a provision for two different queues to be specified - that's why I ask.

Thanks,
Sekhar

#6 lore raw
In reply to Troy Kisky
Quoted 4 lines · Troy Kisky

Remove requirement that dma_params is 1st in the structures davinci_audio_dev and davinci_mcbsp_dev.

I've applied this patch but patches 2-4 don't apply against current ASoC, even with a three way merge. Could you please check against current ASoC at

git://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound-2.6.git for-2.6.33

and resend? The patches look good and it's good to see that the default has been changed to avoid channel swapping but they appear to have been generated against an older tree.