diff options
Diffstat (limited to 'sound/soc/davinci/davinci-i2s.c')
-rw-r--r-- | sound/soc/davinci/davinci-i2s.c | 85 |
1 files changed, 62 insertions, 23 deletions
diff --git a/sound/soc/davinci/davinci-i2s.c b/sound/soc/davinci/davinci-i2s.c index 4ae707048021..6362ca05506e 100644 --- a/sound/soc/davinci/davinci-i2s.c +++ b/sound/soc/davinci/davinci-i2s.c | |||
@@ -97,12 +97,24 @@ enum { | |||
97 | DAVINCI_MCBSP_WORD_32, | 97 | DAVINCI_MCBSP_WORD_32, |
98 | }; | 98 | }; |
99 | 99 | ||
100 | static const unsigned char data_type[SNDRV_PCM_FORMAT_S32_LE + 1] = { | ||
101 | [SNDRV_PCM_FORMAT_S8] = 1, | ||
102 | [SNDRV_PCM_FORMAT_S16_LE] = 2, | ||
103 | [SNDRV_PCM_FORMAT_S32_LE] = 4, | ||
104 | }; | ||
105 | |||
106 | static const unsigned char asp_word_length[SNDRV_PCM_FORMAT_S32_LE + 1] = { | ||
107 | [SNDRV_PCM_FORMAT_S8] = DAVINCI_MCBSP_WORD_8, | ||
108 | [SNDRV_PCM_FORMAT_S16_LE] = DAVINCI_MCBSP_WORD_16, | ||
109 | [SNDRV_PCM_FORMAT_S32_LE] = DAVINCI_MCBSP_WORD_32, | ||
110 | }; | ||
111 | |||
112 | static const unsigned char double_fmt[SNDRV_PCM_FORMAT_S32_LE + 1] = { | ||
113 | [SNDRV_PCM_FORMAT_S8] = SNDRV_PCM_FORMAT_S16_LE, | ||
114 | [SNDRV_PCM_FORMAT_S16_LE] = SNDRV_PCM_FORMAT_S32_LE, | ||
115 | }; | ||
116 | |||
100 | struct davinci_mcbsp_dev { | 117 | struct davinci_mcbsp_dev { |
101 | /* | ||
102 | * dma_params must be first because rtd->dai->cpu_dai->private_data | ||
103 | * is cast to a pointer of an array of struct davinci_pcm_dma_params in | ||
104 | * davinci_pcm_open. | ||
105 | */ | ||
106 | struct davinci_pcm_dma_params dma_params[2]; | 118 | struct davinci_pcm_dma_params dma_params[2]; |
107 | void __iomem *base; | 119 | void __iomem *base; |
108 | #define MOD_DSP_A 0 | 120 | #define MOD_DSP_A 0 |
@@ -110,6 +122,27 @@ struct davinci_mcbsp_dev { | |||
110 | int mode; | 122 | int mode; |
111 | u32 pcr; | 123 | u32 pcr; |
112 | struct clk *clk; | 124 | struct clk *clk; |
125 | /* | ||
126 | * Combining both channels into 1 element will at least double the | ||
127 | * amount of time between servicing the dma channel, increase | ||
128 | * effiency, and reduce the chance of overrun/underrun. But, | ||
129 | * it will result in the left & right channels being swapped. | ||
130 | * | ||
131 | * If relabeling the left and right channels is not possible, | ||
132 | * you may want to let the codec know to swap them back. | ||
133 | * | ||
134 | * It may allow x10 the amount of time to service dma requests, | ||
135 | * if the codec is master and is using an unnecessarily fast bit clock | ||
136 | * (ie. tlvaic23b), independent of the sample rate. So, having an | ||
137 | * entire frame at once means it can be serviced at the sample rate | ||
138 | * instead of the bit clock rate. | ||
139 | * | ||
140 | * In the now unlikely case that an underrun still | ||
141 | * occurs, both the left and right samples will be repeated | ||
142 | * so that no pops are heard, and the left and right channels | ||
143 | * won't end up being swapped because of the underrun. | ||
144 | */ | ||
145 | unsigned enable_channel_combine:1; | ||
113 | }; | 146 | }; |
114 | 147 | ||
115 | static inline void davinci_mcbsp_write_reg(struct davinci_mcbsp_dev *dev, | 148 | static inline void davinci_mcbsp_write_reg(struct davinci_mcbsp_dev *dev, |
@@ -349,6 +382,8 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, | |||
349 | int mcbsp_word_length; | 382 | int mcbsp_word_length; |
350 | unsigned int rcr, xcr, srgr; | 383 | unsigned int rcr, xcr, srgr; |
351 | u32 spcr; | 384 | u32 spcr; |
385 | snd_pcm_format_t fmt; | ||
386 | unsigned element_cnt = 1; | ||
352 | 387 | ||
353 | /* general line settings */ | 388 | /* general line settings */ |
354 | spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); | 389 | spcr = davinci_mcbsp_read_reg(dev, DAVINCI_MCBSP_SPCR_REG); |
@@ -378,27 +413,24 @@ static int davinci_i2s_hw_params(struct snd_pcm_substream *substream, | |||
378 | xcr |= DAVINCI_MCBSP_XCR_XDATDLY(1); | 413 | xcr |= DAVINCI_MCBSP_XCR_XDATDLY(1); |
379 | } | 414 | } |
380 | /* Determine xfer data type */ | 415 | /* Determine xfer data type */ |
381 | switch (params_format(params)) { | 416 | fmt = params_format(params); |
382 | case SNDRV_PCM_FORMAT_S8: | 417 | if ((fmt > SNDRV_PCM_FORMAT_S32_LE) || !data_type[fmt]) { |
383 | dma_params->data_type = 1; | ||
384 | mcbsp_word_length = DAVINCI_MCBSP_WORD_8; | ||
385 | break; | ||
386 | case SNDRV_PCM_FORMAT_S16_LE: | ||
387 | dma_params->data_type = 2; | ||
388 | mcbsp_word_length = DAVINCI_MCBSP_WORD_16; | ||
389 | break; | ||
390 | case SNDRV_PCM_FORMAT_S32_LE: | ||
391 | dma_params->data_type = 4; | ||
392 | mcbsp_word_length = DAVINCI_MCBSP_WORD_32; | ||
393 | break; | ||
394 | default: | ||
395 | printk(KERN_WARNING "davinci-i2s: unsupported PCM format\n"); | 418 | printk(KERN_WARNING "davinci-i2s: unsupported PCM format\n"); |
396 | return -EINVAL; | 419 | return -EINVAL; |
397 | } | 420 | } |
398 | 421 | ||
399 | dma_params->acnt = dma_params->data_type; | 422 | if (params_channels(params) == 2) { |
400 | rcr |= DAVINCI_MCBSP_RCR_RFRLEN1(1); | 423 | element_cnt = 2; |
401 | xcr |= DAVINCI_MCBSP_XCR_XFRLEN1(1); | 424 | if (double_fmt[fmt] && dev->enable_channel_combine) { |
425 | element_cnt = 1; | ||
426 | fmt = double_fmt[fmt]; | ||
427 | } | ||
428 | } | ||
429 | dma_params->acnt = dma_params->data_type = data_type[fmt]; | ||
430 | dma_params->fifo_level = 0; | ||
431 | mcbsp_word_length = asp_word_length[fmt]; | ||
432 | rcr |= DAVINCI_MCBSP_RCR_RFRLEN1(element_cnt - 1); | ||
433 | xcr |= DAVINCI_MCBSP_XCR_XFRLEN1(element_cnt - 1); | ||
402 | 434 | ||
403 | rcr |= DAVINCI_MCBSP_RCR_RWDLEN1(mcbsp_word_length) | | 435 | rcr |= DAVINCI_MCBSP_RCR_RWDLEN1(mcbsp_word_length) | |
404 | DAVINCI_MCBSP_RCR_RWDLEN2(mcbsp_word_length); | 436 | DAVINCI_MCBSP_RCR_RWDLEN2(mcbsp_word_length); |
@@ -513,7 +545,13 @@ static int davinci_i2s_probe(struct platform_device *pdev) | |||
513 | ret = -ENOMEM; | 545 | ret = -ENOMEM; |
514 | goto err_release_region; | 546 | goto err_release_region; |
515 | } | 547 | } |
516 | 548 | if (pdata) { | |
549 | dev->enable_channel_combine = pdata->enable_channel_combine; | ||
550 | dev->dma_params[SNDRV_PCM_STREAM_PLAYBACK].sram_size = | ||
551 | pdata->sram_size_playback; | ||
552 | dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].sram_size = | ||
553 | pdata->sram_size_capture; | ||
554 | } | ||
517 | dev->clk = clk_get(&pdev->dev, NULL); | 555 | dev->clk = clk_get(&pdev->dev, NULL); |
518 | if (IS_ERR(dev->clk)) { | 556 | if (IS_ERR(dev->clk)) { |
519 | ret = -ENODEV; | 557 | ret = -ENODEV; |
@@ -547,6 +585,7 @@ static int davinci_i2s_probe(struct platform_device *pdev) | |||
547 | dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = res->start; | 585 | dev->dma_params[SNDRV_PCM_STREAM_CAPTURE].channel = res->start; |
548 | 586 | ||
549 | davinci_i2s_dai.private_data = dev; | 587 | davinci_i2s_dai.private_data = dev; |
588 | davinci_i2s_dai.dma_data = dev->dma_params; | ||
550 | ret = snd_soc_register_dai(&davinci_i2s_dai); | 589 | ret = snd_soc_register_dai(&davinci_i2s_dai); |
551 | if (ret != 0) | 590 | if (ret != 0) |
552 | goto err_free_mem; | 591 | goto err_free_mem; |