Lines Matching +full:static +full:- +full:config
1 // SPDX-License-Identifier: GPL-2.0+
4 // Author: Lars-Peter Clausen <lars@metafoo.de>
13 #include <linux/dma-mapping.h>
18 static unsigned int prealloc_buffer_size_kbytes = 512;
28 static struct device *dmaengine_dma_dev(struct dmaengine_pcm *pcm,
31 if (!pcm->chan[substream->stream])
34 return pcm->chan[substream->stream]->device->dev;
38 * snd_dmaengine_pcm_prepare_slave_config() - Generic prepare_slave_config callback
41 * @slave_config: DMA slave config to prepare
46 * snd_hwparams_to_dma_slave_config to fill in the slave config based on the
57 if (rtd->dai_link->num_cpus > 1) {
58 dev_err(rtd->dev,
60 return -EINVAL;
76 static int dmaengine_pcm_hw_params(struct snd_soc_component *component,
85 if (!pcm->config->prepare_slave_config)
90 ret = pcm->config->prepare_slave_config(substream, params, &slave_config);
97 static int
104 struct dma_chan *chan = pcm->chan[substream->stream];
108 if (rtd->dai_link->num_cpus > 1) {
109 dev_err(rtd->dev,
111 return -EINVAL;
114 if (pcm->config->pcm_hardware)
116 pcm->config->pcm_hardware);
125 hw.period_bytes_min = dma_data->maxburst * DMA_SLAVE_BUSWIDTH_8_BYTES;
130 hw.fifo_size = dma_data->fifo_size;
132 if (pcm->flags & SND_DMAENGINE_PCM_FLAG_NO_RESIDUE)
148 static int dmaengine_pcm_open(struct snd_soc_component *component,
152 struct dma_chan *chan = pcm->chan[substream->stream];
162 static int dmaengine_pcm_close(struct snd_soc_component *component,
168 static int dmaengine_pcm_trigger(struct snd_soc_component *component,
174 static struct dma_chan *dmaengine_pcm_compat_request_channel(
182 if (rtd->dai_link->num_cpus > 1) {
183 dev_err(rtd->dev,
190 if ((pcm->flags & SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX) && pcm->chan[0])
191 return pcm->chan[0];
193 if (pcm->config->compat_request_channel)
194 return pcm->config->compat_request_channel(rtd, substream);
196 return snd_dmaengine_pcm_request_channel(pcm->config->compat_filter_fn,
197 dma_data->filter_data);
200 static bool dmaengine_pcm_can_report_residue(struct device *dev,
219 static int dmaengine_pcm_new(struct snd_soc_component *component,
223 const struct snd_dmaengine_pcm_config *config = pcm->config;
224 struct device *dev = component->dev;
229 if (config->prealloc_buffer_size)
230 prealloc_buffer_size = config->prealloc_buffer_size;
234 if (config->pcm_hardware && config->pcm_hardware->buffer_bytes_max)
235 max_buffer_size = config->pcm_hardware->buffer_bytes_max;
240 struct snd_pcm_substream *substream = rtd->pcm->streams[i].substream;
244 if (!pcm->chan[i] && config->chan_names[i])
245 pcm->chan[i] = dma_request_slave_channel(dev,
246 config->chan_names[i]);
248 if (!pcm->chan[i] && (pcm->flags & SND_DMAENGINE_PCM_FLAG_COMPAT)) {
249 pcm->chan[i] = dmaengine_pcm_compat_request_channel(
253 if (!pcm->chan[i]) {
254 dev_err(component->dev,
256 return -EINVAL;
265 if (!dmaengine_pcm_can_report_residue(dev, pcm->chan[i]))
266 pcm->flags |= SND_DMAENGINE_PCM_FLAG_NO_RESIDUE;
268 if (rtd->pcm->streams[i].pcm->name[0] == '\0') {
269 strscpy_pad(rtd->pcm->streams[i].pcm->name,
270 rtd->pcm->streams[i].pcm->id,
271 sizeof(rtd->pcm->streams[i].pcm->name));
278 static snd_pcm_uframes_t dmaengine_pcm_pointer(
284 if (pcm->flags & SND_DMAENGINE_PCM_FLAG_NO_RESIDUE)
290 static int dmaengine_copy(struct snd_soc_component *component,
295 struct snd_pcm_runtime *runtime = substream->runtime;
299 unsigned long bytes) = pcm->config->process;
300 bool is_playback = substream->stream == SNDRV_PCM_STREAM_PLAYBACK;
301 void *dma_ptr = runtime->dma_area + hwoff +
302 channel * (runtime->dma_bytes / runtime->channels);
306 return -EFAULT;
316 return -EFAULT;
321 static int dmaengine_pcm_sync_stop(struct snd_soc_component *component,
327 static const struct snd_soc_component_driver dmaengine_pcm_component = {
339 static const struct snd_soc_component_driver dmaengine_pcm_component_process = {
352 static const char * const dmaengine_pcm_dma_channel_names[] = {
357 static int dmaengine_pcm_request_chan_of(struct dmaengine_pcm *pcm,
358 struct device *dev, const struct snd_dmaengine_pcm_config *config)
364 if ((pcm->flags & SND_DMAENGINE_PCM_FLAG_NO_DT) || (!dev->of_node &&
365 !(config->dma_dev && config->dma_dev->of_node)))
368 if (config->dma_dev) {
376 dev_name(config->dma_dev));
377 dev = config->dma_dev;
381 if (pcm->flags & SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX)
382 name = "rx-tx";
385 if (config->chan_names[i])
386 name = config->chan_names[i];
394 if (PTR_ERR(chan) == -EPROBE_DEFER)
395 return -EPROBE_DEFER;
396 pcm->chan[i] = NULL;
398 pcm->chan[i] = chan;
400 if (pcm->flags & SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX)
404 if (pcm->flags & SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX)
405 pcm->chan[1] = pcm->chan[0];
410 static void dmaengine_pcm_release_chan(struct dmaengine_pcm *pcm)
415 if (!pcm->chan[i])
417 dma_release_channel(pcm->chan[i]);
418 if (pcm->flags & SND_DMAENGINE_PCM_FLAG_HALF_DUPLEX)
423 static const struct snd_dmaengine_pcm_config snd_dmaengine_pcm_default_config = {
428 * snd_dmaengine_pcm_register - Register a dmaengine based PCM device
430 * @config: Platform specific PCM configuration
434 const struct snd_dmaengine_pcm_config *config, unsigned int flags)
442 return -ENOMEM;
445 pcm->component.debugfs_prefix = "dma";
447 if (!config)
448 config = &snd_dmaengine_pcm_default_config;
449 pcm->config = config;
450 pcm->flags = flags;
452 if (config->name)
453 pcm->component.name = config->name;
455 ret = dmaengine_pcm_request_chan_of(pcm, dev, config);
459 if (config->process)
464 ret = snd_soc_component_initialize(&pcm->component, driver, dev);
468 ret = snd_soc_add_component(&pcm->component, NULL, 0);
482 * snd_dmaengine_pcm_unregister - Removes a dmaengine based PCM device
499 snd_soc_unregister_component_by_driver(dev, component->driver);