All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/3] ASoC: DaVinci: i2s, reduce underruns by combining into 1 element
@ 2009-08-31 23:31 Troy Kisky
  2009-08-31 23:31 ` [PATCH 2/3] ASoC: DaVinci: pcm, rename variables in prep for ping/pong Troy Kisky
  2009-09-01 10:53 ` [PATCH 1/3] ASoC: DaVinci: i2s, reduce underruns by combining into 1 element Mark Brown
  0 siblings, 2 replies; 33+ messages in thread
From: Troy Kisky @ 2009-08-31 23:31 UTC (permalink / raw)
  To: davinci-linux-open-source; +Cc: avm, alsa-devel, broonie, Troy Kisky

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

Signed-off-by: Troy Kisky <troy.kisky@boundarydevices.com>
--
This applies to Kevin's temp/asoc branch
---
 arch/arm/mach-davinci/include/mach/asp.h |    6 ++
 sound/soc/davinci/davinci-i2s.c          |   74 ++++++++++++++++++++++--------
 2 files changed, 61 insertions(+), 19 deletions(-)

diff --git a/arch/arm/mach-davinci/include/mach/asp.h b/arch/arm/mach-davinci/include/mach/asp.h
index 18e4ce3..a3d2aa1 100644
--- a/arch/arm/mach-davinci/include/mach/asp.h
+++ b/arch/arm/mach-davinci/include/mach/asp.h
@@ -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 disable_channel_combine:1;
 
 	/* McASP specific fields */
 	int tdm_slots;
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c
index 12a6c54..081b2d4 100644
--- a/sound/soc/davinci/davinci-i2s.c
+++ b/sound/soc/davinci/davinci-i2s.c
@@ -97,6 +97,23 @@ enum {
 	DAVINCI_MCBSP_WORD_32,
 };
 
+static const unsigned char data_type[SNDRV_PCM_FORMAT_S32_LE + 1] = {
+	[SNDRV_PCM_FORMAT_S8]		= 1,
+	[SNDRV_PCM_FORMAT_S16_LE]	= 2,
+	[SNDRV_PCM_FORMAT_S32_LE]	= 4,
+};
+
+static const unsigned char asp_word_length[SNDRV_PCM_FORMAT_S32_LE + 1] = {
+	[SNDRV_PCM_FORMAT_S8]		= DAVINCI_MCBSP_WORD_8,
+	[SNDRV_PCM_FORMAT_S16_LE]	= DAVINCI_MCBSP_WORD_16,
+	[SNDRV_PCM_FORMAT_S32_LE]	= DAVINCI_MCBSP_WORD_32,
+};
+
+static const unsigned char double_fmt[SNDRV_PCM_FORMAT_S32_LE + 1] = {
+	[SNDRV_PCM_FORMAT_S8]		= SNDRV_PCM_FORMAT_S16_LE,
+	[SNDRV_PCM_FORMAT_S16_LE]	= SNDRV_PCM_FORMAT_S32_LE,
+};
+
 static struct davinci_pcm_dma_params davinci_i2s_pcm_out = {
 	.name = "I2S PCM Stereo out",
 };
@@ -113,6 +130,27 @@ struct davinci_mcbsp_dev {
 	u32				pcr;
 	struct clk			*clk;
 	struct davinci_pcm_dma_params	*dma_params[2];
+	/*
+	 * Combining both channels into 1 element will at least double the
+	 * amount of time between servicing the dma channel, increase
+	 * effiency, and reduce the chance of overrun/underrun. But,
+	 * it will result in the left & right channels being swapped.
+	 *
+	 * If relabeling the left and right channels is not possible,
+	 * you may want to let the codec know to swap them back.
+	 *
+	 * It may allow x10 the amount of time to service dma requests,
+	 * if the codec is master and is using an unnecessarily fast bit clock
+	 * (ie. tlvaic23b), independent of the sample rate. So, having an
+	 * entire frame at once means it can be serviced at the sample rate
+	 * instead of the bit clock rate.
+	 *
+	 * In the now unlikely case that an underrun still
+	 * occurs, both the left and right samples will be repeated
+	 * so that no pops are heard, and the left and right channels
+	 * won't end up being swapped because of the underrun.
+	 */
+	unsigned disable_channel_combine:1;
 };
 
 static inline void davinci_mcbsp_write_reg(struct davinci_mcbsp_dev *dev,
@@ -359,6 +397,8 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
 	int mcbsp_word_length;
 	unsigned int rcr, xcr, srgr;
 	u32 spcr;
+	snd_pcm_format_t fmt;
+	unsigned element_cnt = 1;
 
 	/* general line settings */
 	spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG);
@@ -388,27 +428,22 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream,
 		xcr |= DAVINCI_MCBSP_XCR_XDATDLY(1);
 	}
 	/* Determine xfer data type */
-	switch (params_format(params)) {
-	case SNDRV_PCM_FORMAT_S8:
-		dma_params->data_type = 1;
-		mcbsp_word_length = DAVINCI_MCBSP_WORD_8;
-		break;
-	case SNDRV_PCM_FORMAT_S16_LE:
-		dma_params->data_type = 2;
-		mcbsp_word_length = DAVINCI_MCBSP_WORD_16;
-		break;
-	case SNDRV_PCM_FORMAT_S32_LE:
-		dma_params->data_type = 4;
-		mcbsp_word_length = DAVINCI_MCBSP_WORD_32;
-		break;
-	default:
+	fmt = params_format(params);
+	if ((fmt > SNDRV_PCM_FORMAT_S32_LE) || !data_type[fmt]) {
 		printk(KERN_WARNING "davinci-i2s: unsupported PCM format\n");
 		return -EINVAL;
 	}
-
-	dma_params->acnt  = dma_params->data_type;
-	rcr |= DAVINCI_MCBSP_RCR_RFRLEN1(1);
-	xcr |= DAVINCI_MCBSP_XCR_XFRLEN1(1);
+	if (params_channels(params) == 2) {
+		element_cnt = 2;
+		if (double_fmt[fmt] && !dev->disable_channel_combine) {
+			element_cnt = 1;
+			fmt = double_fmt[fmt];
+		}
+	}
+	dma_params->acnt = dma_params->data_type = data_type[fmt];
+	mcbsp_word_length = asp_word_length[fmt];
+	rcr |= DAVINCI_MCBSP_RCR_RFRLEN1(element_cnt - 1);
+	xcr |= DAVINCI_MCBSP_XCR_XFRLEN1(element_cnt - 1);
 
 	rcr |= DAVINCI_MCBSP_RCR_RWDLEN1(mcbsp_word_length) |
 		DAVINCI_MCBSP_RCR_RWDLEN2(mcbsp_word_length);
@@ -524,7 +559,8 @@ static int davinci_i2s_probe(struct platform_device *pdev)
 		ret = -ENOMEM;
 		goto err_release_region;
 	}
-
+	if (pdata)
+		dev->disable_channel_combine = pdata->disable_channel_combine;
 	dev->clk = clk_get(&pdev->dev, NULL);
 	if (IS_ERR(dev->clk)) {
 		ret = -ENODEV;
-- 
1.5.6.3

^ permalink raw reply related	[flat|nested] 33+ messages in thread

end of thread, other threads:[~2009-10-01 18:46 UTC | newest]

Thread overview: 33+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-08-31 23:31 [PATCH 1/3] ASoC: DaVinci: i2s, reduce underruns by combining into 1 element Troy Kisky
2009-08-31 23:31 ` [PATCH 2/3] ASoC: DaVinci: pcm, rename variables in prep for ping/pong Troy Kisky
2009-08-31 23:31   ` [PATCH 3/3] ASoC: DaVinci: pcm, fix underrun by using sram Troy Kisky
2009-09-02 22:01   ` [PATCH 2/3] ASoC: DaVinci: pcm, rename variables in prep for ping/pong Mark Brown
2009-09-03  0:15     ` Troy Kisky
2009-09-03 12:17       ` Mark Brown
     [not found]       ` <4A9F0A8C.1040509-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2009-09-03 16:43         ` [alsa-devel] " Nori, Sekhar
2009-09-03 18:55           ` Troy Kisky
     [not found]             ` <4AA0113D.9030605-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2009-09-09 12:08               ` [alsa-devel] " Nori, Sekhar
     [not found]                 ` <B85A65D85D7EB246BE421B3FB0FBB59301DD74F519-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2009-09-09 12:33                   ` Caglar Akyuz
     [not found]                     ` <200909091533.58702.caglarakyuz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2009-09-09 13:05                       ` Nori, Sekhar
     [not found]                         ` <B85A65D85D7EB246BE421B3FB0FBB59301DD74F59E-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2009-09-09 13:22                           ` Narnakaje, Snehaprabha
2009-09-09 13:28                             ` Mark Brown
2009-09-29 10:46                   ` [alsa-devel] " Nori, Sekhar
     [not found]                     ` <B85A65D85D7EB246BE421B3FB0FBB59301DDAB3EB5-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2009-09-29 15:21                       ` Mani, Arun
     [not found]                         ` <7A436F7769CA33409C6B44B358BFFF0C012A458365-EovWT4A8QTWIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2009-10-01 18:13                           ` Nori, Sekhar
     [not found]                             ` <B85A65D85D7EB246BE421B3FB0FBB59301DDB71445-/tLxBxkBPtCIQmiDNMet8wC/G2K4zDHf@public.gmane.org>
2009-10-01 18:46                               ` Steve Chen
2009-09-29 22:09                     ` Troy Kisky
     [not found]                       ` <4AC28588.9030802-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2009-09-29 22:25                         ` [alsa-devel] " Steve Chen
2009-09-29 22:31                           ` Troy Kisky
     [not found]                             ` <4AC28AD0.7000600-Q5RJGjKts06CY9SHAMCTRUEOCMrvLtNR@public.gmane.org>
2009-09-29 23:24                               ` [alsa-devel] " Steve Chen
2009-09-03 19:06   ` David Brownell
2009-09-03 19:24     ` Troy Kisky
2009-09-03 21:36       ` David Brownell
2009-09-03 22:38         ` Troy Kisky
2009-09-01 10:53 ` [PATCH 1/3] ASoC: DaVinci: i2s, reduce underruns by combining into 1 element Mark Brown
2009-09-01 18:23   ` Troy Kisky
2009-09-01 19:03     ` Mark Brown
2009-09-01 19:19       ` Troy Kisky
2009-09-01 20:28         ` Mark Brown
2009-09-01 20:42           ` Troy Kisky
2009-09-01 21:22             ` Mark Brown
2009-09-01 21:34               ` Troy Kisky

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.