0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #include <linux/module.h>
0015 #include <linux/init.h>
0016 #include <linux/platform_device.h>
0017 #include <linux/slab.h>
0018 #include <linux/dma-mapping.h>
0019 #include <linux/dmaengine.h>
0020 #include <linux/atmel-ssc.h>
0021
0022 #include <sound/core.h>
0023 #include <sound/pcm.h>
0024 #include <sound/pcm_params.h>
0025 #include <sound/soc.h>
0026 #include <sound/dmaengine_pcm.h>
0027
0028 #include "atmel-pcm.h"
0029
0030
0031
0032
0033 static const struct snd_pcm_hardware atmel_pcm_dma_hardware = {
0034 .info = SNDRV_PCM_INFO_MMAP |
0035 SNDRV_PCM_INFO_MMAP_VALID |
0036 SNDRV_PCM_INFO_INTERLEAVED |
0037 SNDRV_PCM_INFO_RESUME |
0038 SNDRV_PCM_INFO_PAUSE,
0039 .period_bytes_min = 256,
0040 .period_bytes_max = 2 * 0xffff,
0041 .periods_min = 8,
0042 .periods_max = 1024,
0043 .buffer_bytes_max = 512 * 1024,
0044 };
0045
0046
0047
0048
0049
0050
0051
0052 static void atmel_pcm_dma_irq(u32 ssc_sr,
0053 struct snd_pcm_substream *substream)
0054 {
0055 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0056 struct atmel_pcm_dma_params *prtd;
0057
0058 prtd = snd_soc_dai_get_dma_data(asoc_rtd_to_cpu(rtd, 0), substream);
0059
0060 if (ssc_sr & prtd->mask->ssc_error) {
0061 if (snd_pcm_running(substream))
0062 pr_warn("atmel-pcm: buffer %s on %s (SSC_SR=%#x)\n",
0063 substream->stream == SNDRV_PCM_STREAM_PLAYBACK
0064 ? "underrun" : "overrun", prtd->name,
0065 ssc_sr);
0066
0067
0068 ssc_writex(prtd->ssc->regs, SSC_CR, prtd->mask->ssc_disable);
0069 snd_pcm_stop_xrun(substream);
0070
0071
0072 ssc_readx(prtd->ssc->regs, SSC_RHR);
0073 ssc_readx(prtd->ssc->regs, SSC_SR);
0074 }
0075 }
0076
0077 static int atmel_pcm_configure_dma(struct snd_pcm_substream *substream,
0078 struct snd_pcm_hw_params *params, struct dma_slave_config *slave_config)
0079 {
0080 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0081 struct atmel_pcm_dma_params *prtd;
0082 struct ssc_device *ssc;
0083 int ret;
0084
0085 prtd = snd_soc_dai_get_dma_data(asoc_rtd_to_cpu(rtd, 0), substream);
0086 ssc = prtd->ssc;
0087
0088 ret = snd_hwparams_to_dma_slave_config(substream, params, slave_config);
0089 if (ret) {
0090 pr_err("atmel-pcm: hwparams to dma slave configure failed\n");
0091 return ret;
0092 }
0093
0094 slave_config->dst_addr = ssc->phybase + SSC_THR;
0095 slave_config->dst_maxburst = 1;
0096
0097 slave_config->src_addr = ssc->phybase + SSC_RHR;
0098 slave_config->src_maxburst = 1;
0099
0100 prtd->dma_intr_handler = atmel_pcm_dma_irq;
0101
0102 return 0;
0103 }
0104
0105 static const struct snd_dmaengine_pcm_config atmel_dmaengine_pcm_config = {
0106 .prepare_slave_config = atmel_pcm_configure_dma,
0107 .pcm_hardware = &atmel_pcm_dma_hardware,
0108 .prealloc_buffer_size = 64 * 1024,
0109 };
0110
0111 int atmel_pcm_dma_platform_register(struct device *dev)
0112 {
0113 return devm_snd_dmaengine_pcm_register(dev,
0114 &atmel_dmaengine_pcm_config, 0);
0115 }
0116 EXPORT_SYMBOL(atmel_pcm_dma_platform_register);
0117
0118 MODULE_AUTHOR("Bo Shen <voice.shen@atmel.com>");
0119 MODULE_DESCRIPTION("Atmel DMA based PCM module");
0120 MODULE_LICENSE("GPL");