aboutsummaryrefslogtreecommitdiffstats
path: root/sound/soc/soc-generic-dmaengine-pcm.c
diff options
context:
space:
mode:
authorLars-Peter Clausen <lars@metafoo.de>2013-10-08 09:08:00 -0400
committerMark Brown <broonie@linaro.org>2013-10-19 16:26:06 -0400
commitfa654e085300e9c222ef931bc0702a9df2542666 (patch)
tree8ad9f7ff04029d67b46fe76478541d8512109a94 /sound/soc/soc-generic-dmaengine-pcm.c
parentc0de42bf595238e9dd593405ebc2992cc8470732 (diff)
ASoC: dmaengine-pcm: Provide default config
This patch adds some default settings for the generic dmaengine PCM driver for the case that no config has been supplied. The following defaults are used: * Use snd_dmaengine_pcm_prepare_slave_config for preparing the DMA slave config. * 512kB for the prealloc buffer size. This value has been chosen based on 'feels about right' and is not backed up by any scientific facts. We may need to come up with something smarter in the future but it should work fine for now. With this infrastructure in place we can finally write DAI drivers which are independent of the DMA controller they are connected to. This is e.g. useful if the DAI IP core is reused across different SoCs, but the SoCs uses different DMA controllers. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Mark Brown <broonie@linaro.org>
Diffstat (limited to 'sound/soc/soc-generic-dmaengine-pcm.c')
-rw-r--r--sound/soc/soc-generic-dmaengine-pcm.c30
1 files changed, 24 insertions, 6 deletions
diff --git a/sound/soc/soc-generic-dmaengine-pcm.c b/sound/soc/soc-generic-dmaengine-pcm.c
index c39e19e84c8a..99f9495c1c40 100644
--- a/sound/soc/soc-generic-dmaengine-pcm.c
+++ b/sound/soc/soc-generic-dmaengine-pcm.c
@@ -84,12 +84,19 @@ static int dmaengine_pcm_hw_params(struct snd_pcm_substream *substream,
84 struct snd_soc_pcm_runtime *rtd = substream->private_data; 84 struct snd_soc_pcm_runtime *rtd = substream->private_data;
85 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform); 85 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform);
86 struct dma_chan *chan = snd_dmaengine_pcm_get_chan(substream); 86 struct dma_chan *chan = snd_dmaengine_pcm_get_chan(substream);
87 int (*prepare_slave_config)(struct snd_pcm_substream *substream,
88 struct snd_pcm_hw_params *params,
89 struct dma_slave_config *slave_config);
87 struct dma_slave_config slave_config; 90 struct dma_slave_config slave_config;
88 int ret; 91 int ret;
89 92
90 if (pcm->config->prepare_slave_config) { 93 if (!pcm->config)
91 ret = pcm->config->prepare_slave_config(substream, params, 94 prepare_slave_config = snd_dmaengine_pcm_prepare_slave_config;
92 &slave_config); 95 else
96 prepare_slave_config = pcm->config->prepare_slave_config;
97
98 if (prepare_slave_config) {
99 ret = prepare_slave_config(substream, params, &slave_config);
93 if (ret) 100 if (ret)
94 return ret; 101 return ret;
95 102
@@ -112,7 +119,7 @@ static int dmaengine_pcm_set_runtime_hwparams(struct snd_pcm_substream *substrea
112 struct snd_pcm_hardware hw; 119 struct snd_pcm_hardware hw;
113 int ret; 120 int ret;
114 121
115 if (pcm->config->pcm_hardware) 122 if (pcm->config && pcm->config->pcm_hardware)
116 return snd_soc_set_runtime_hwparams(substream, 123 return snd_soc_set_runtime_hwparams(substream,
117 pcm->config->pcm_hardware); 124 pcm->config->pcm_hardware);
118 125
@@ -177,9 +184,20 @@ static int dmaengine_pcm_new(struct snd_soc_pcm_runtime *rtd)
177 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform); 184 struct dmaengine_pcm *pcm = soc_platform_to_pcm(rtd->platform);
178 const struct snd_dmaengine_pcm_config *config = pcm->config; 185 const struct snd_dmaengine_pcm_config *config = pcm->config;
179 struct snd_pcm_substream *substream; 186 struct snd_pcm_substream *substream;
187 size_t prealloc_buffer_size;
188 size_t max_buffer_size;
180 unsigned int i; 189 unsigned int i;
181 int ret; 190 int ret;
182 191
192 if (config && config->prealloc_buffer_size) {
193 prealloc_buffer_size = config->prealloc_buffer_size;
194 max_buffer_size = config->pcm_hardware->buffer_bytes_max;
195 } else {
196 prealloc_buffer_size = 512 * 1024;
197 max_buffer_size = SIZE_MAX;
198 }
199
200
183 for (i = SNDRV_PCM_STREAM_PLAYBACK; i <= SNDRV_PCM_STREAM_CAPTURE; i++) { 201 for (i = SNDRV_PCM_STREAM_PLAYBACK; i <= SNDRV_PCM_STREAM_CAPTURE; i++) {
184 substream = rtd->pcm->streams[i].substream; 202 substream = rtd->pcm->streams[i].substream;
185 if (!substream) 203 if (!substream)
@@ -200,8 +218,8 @@ static int dmaengine_pcm_new(struct snd_soc_pcm_runtime *rtd)
200 ret = snd_pcm_lib_preallocate_pages(substream, 218 ret = snd_pcm_lib_preallocate_pages(substream,
201 SNDRV_DMA_TYPE_DEV, 219 SNDRV_DMA_TYPE_DEV,
202 dmaengine_dma_dev(pcm, substream), 220 dmaengine_dma_dev(pcm, substream),
203 config->prealloc_buffer_size, 221 prealloc_buffer_size,
204 config->pcm_hardware->buffer_bytes_max); 222 max_buffer_size);
205 if (ret) 223 if (ret)
206 goto err_free; 224 goto err_free;
207 } 225 }