Lines Matching +full:back +full:- +full:end
1 // SPDX-License-Identifier: GPL-2.0
9 #include <linux/dma-mapping.h>
11 #include <linux/dma/imx-dma.h>
37 chan->private = param; in filter()
45 struct snd_pcm_runtime *runtime = substream->runtime; in fsl_asrc_dma_complete()
46 struct fsl_asrc_pair *pair = runtime->private_data; in fsl_asrc_dma_complete()
48 pair->pos += snd_pcm_lib_period_bytes(substream); in fsl_asrc_dma_complete()
49 if (pair->pos >= snd_pcm_lib_buffer_bytes(substream)) in fsl_asrc_dma_complete()
50 pair->pos = 0; in fsl_asrc_dma_complete()
58 u8 dir = substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? OUT : IN; in fsl_asrc_dma_prepare_and_submit()
59 struct snd_pcm_runtime *runtime = substream->runtime; in fsl_asrc_dma_prepare_and_submit()
60 struct fsl_asrc_pair *pair = runtime->private_data; in fsl_asrc_dma_prepare_and_submit()
61 struct device *dev = component->dev; in fsl_asrc_dma_prepare_and_submit()
64 /* Prepare and submit Front-End DMA channel */ in fsl_asrc_dma_prepare_and_submit()
65 if (!substream->runtime->no_period_wakeup) in fsl_asrc_dma_prepare_and_submit()
68 pair->pos = 0; in fsl_asrc_dma_prepare_and_submit()
69 pair->desc[!dir] = dmaengine_prep_dma_cyclic( in fsl_asrc_dma_prepare_and_submit()
70 pair->dma_chan[!dir], runtime->dma_addr, in fsl_asrc_dma_prepare_and_submit()
74 if (!pair->desc[!dir]) { in fsl_asrc_dma_prepare_and_submit()
75 dev_err(dev, "failed to prepare slave DMA for Front-End\n"); in fsl_asrc_dma_prepare_and_submit()
76 return -ENOMEM; in fsl_asrc_dma_prepare_and_submit()
79 pair->desc[!dir]->callback = fsl_asrc_dma_complete; in fsl_asrc_dma_prepare_and_submit()
80 pair->desc[!dir]->callback_param = substream; in fsl_asrc_dma_prepare_and_submit()
82 dmaengine_submit(pair->desc[!dir]); in fsl_asrc_dma_prepare_and_submit()
84 /* Prepare and submit Back-End DMA channel */ in fsl_asrc_dma_prepare_and_submit()
85 pair->desc[dir] = dmaengine_prep_dma_cyclic( in fsl_asrc_dma_prepare_and_submit()
86 pair->dma_chan[dir], 0xffff, 64, 64, DMA_DEV_TO_DEV, 0); in fsl_asrc_dma_prepare_and_submit()
87 if (!pair->desc[dir]) { in fsl_asrc_dma_prepare_and_submit()
88 dev_err(dev, "failed to prepare slave DMA for Back-End\n"); in fsl_asrc_dma_prepare_and_submit()
89 return -ENOMEM; in fsl_asrc_dma_prepare_and_submit()
92 dmaengine_submit(pair->desc[dir]); in fsl_asrc_dma_prepare_and_submit()
100 struct snd_pcm_runtime *runtime = substream->runtime; in fsl_asrc_dma_trigger()
101 struct fsl_asrc_pair *pair = runtime->private_data; in fsl_asrc_dma_trigger()
111 dma_async_issue_pending(pair->dma_chan[IN]); in fsl_asrc_dma_trigger()
112 dma_async_issue_pending(pair->dma_chan[OUT]); in fsl_asrc_dma_trigger()
117 dmaengine_terminate_async(pair->dma_chan[OUT]); in fsl_asrc_dma_trigger()
118 dmaengine_terminate_async(pair->dma_chan[IN]); in fsl_asrc_dma_trigger()
121 return -EINVAL; in fsl_asrc_dma_trigger()
134 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in fsl_asrc_dma_hw_params()
137 struct snd_pcm_runtime *runtime = substream->runtime; in fsl_asrc_dma_hw_params()
138 struct fsl_asrc_pair *pair = runtime->private_data; in fsl_asrc_dma_hw_params()
141 struct fsl_asrc *asrc = pair->asrc; in fsl_asrc_dma_hw_params()
144 enum asrc_pair_index index = pair->index; in fsl_asrc_dma_hw_params()
145 struct device *dev = component->dev; in fsl_asrc_dma_hw_params()
147 int stream = substream->stream; in fsl_asrc_dma_hw_params()
155 /* Fetch the Back-End dma_data from DPCM */ in fsl_asrc_dma_hw_params()
157 struct snd_soc_pcm_runtime *be = dpcm->be; in fsl_asrc_dma_hw_params()
161 if (dpcm->fe != rtd) in fsl_asrc_dma_hw_params()
166 dev_be = dai->dev; in fsl_asrc_dma_hw_params()
171 dev_err(dev, "failed to get the substream of Back-End\n"); in fsl_asrc_dma_hw_params()
172 return -EINVAL; in fsl_asrc_dma_hw_params()
175 /* Override dma_data of the Front-End and config its dmaengine */ in fsl_asrc_dma_hw_params()
177 dma_params_fe->addr = asrc->paddr + asrc->get_fifo_addr(!dir, index); in fsl_asrc_dma_hw_params()
178 dma_params_fe->maxburst = dma_params_be->maxburst; in fsl_asrc_dma_hw_params()
180 pair->dma_chan[!dir] = asrc->get_dma_channel(pair, !dir); in fsl_asrc_dma_hw_params()
181 if (!pair->dma_chan[!dir]) { in fsl_asrc_dma_hw_params()
183 return -EINVAL; in fsl_asrc_dma_hw_params()
188 dev_err(dev, "failed to prepare DMA config for Front-End\n"); in fsl_asrc_dma_hw_params()
192 ret = dmaengine_slave_config(pair->dma_chan[!dir], &config_fe); in fsl_asrc_dma_hw_params()
194 dev_err(dev, "failed to config DMA channel for Front-End\n"); in fsl_asrc_dma_hw_params()
198 /* Request and config DMA channel for Back-End */ in fsl_asrc_dma_hw_params()
204 * The Back-End device might have already requested a DMA channel, in fsl_asrc_dma_hw_params()
209 be_chan = soc_component_to_pcm(component_be)->chan[substream->stream]; in fsl_asrc_dma_hw_params()
215 dev_err(dev, "failed to request DMA channel for Back-End\n"); in fsl_asrc_dma_hw_params()
216 return -EINVAL; in fsl_asrc_dma_hw_params()
224 * Back-End device directly via dma_request_chan. in fsl_asrc_dma_hw_params()
226 if (!asrc->use_edma) { in fsl_asrc_dma_hw_params()
227 /* Get DMA request of Back-End */ in fsl_asrc_dma_hw_params()
228 tmp_data = tmp_chan->private; in fsl_asrc_dma_hw_params()
229 pair->dma_data.dma_request = tmp_data->dma_request; in fsl_asrc_dma_hw_params()
230 be_peripheral_type = tmp_data->peripheral_type; in fsl_asrc_dma_hw_params()
234 /* Get DMA request of Front-End */ in fsl_asrc_dma_hw_params()
235 tmp_chan = asrc->get_dma_channel(pair, dir); in fsl_asrc_dma_hw_params()
236 tmp_data = tmp_chan->private; in fsl_asrc_dma_hw_params()
237 pair->dma_data.dma_request2 = tmp_data->dma_request; in fsl_asrc_dma_hw_params()
238 pair->dma_data.peripheral_type = tmp_data->peripheral_type; in fsl_asrc_dma_hw_params()
239 pair->dma_data.priority = tmp_data->priority; in fsl_asrc_dma_hw_params()
242 of_dma_node = pair->dma_chan[!dir]->device->dev->of_node; in fsl_asrc_dma_hw_params()
243 pair->dma_chan[dir] = in fsl_asrc_dma_hw_params()
244 __dma_request_channel(&mask, filter, &pair->dma_data, in fsl_asrc_dma_hw_params()
246 pair->req_dma_chan = true; in fsl_asrc_dma_hw_params()
248 pair->dma_chan[dir] = tmp_chan; in fsl_asrc_dma_hw_params()
249 /* Do not flag to release if we are reusing the Back-End one */ in fsl_asrc_dma_hw_params()
250 pair->req_dma_chan = !be_chan; in fsl_asrc_dma_hw_params()
253 if (!pair->dma_chan[dir]) { in fsl_asrc_dma_hw_params()
254 dev_err(dev, "failed to request DMA channel for Back-End\n"); in fsl_asrc_dma_hw_params()
255 return -EINVAL; in fsl_asrc_dma_hw_params()
258 width = snd_pcm_format_physical_width(asrc->asrc_format); in fsl_asrc_dma_hw_params()
260 return -EINVAL; in fsl_asrc_dma_hw_params()
274 config_be.src_maxburst = dma_params_be->maxburst; in fsl_asrc_dma_hw_params()
276 config_be.dst_maxburst = dma_params_be->maxburst; in fsl_asrc_dma_hw_params()
290 config_be.src_addr = asrc->paddr + asrc->get_fifo_addr(OUT, index); in fsl_asrc_dma_hw_params()
291 config_be.dst_addr = dma_params_be->addr; in fsl_asrc_dma_hw_params()
293 config_be.dst_addr = asrc->paddr + asrc->get_fifo_addr(IN, index); in fsl_asrc_dma_hw_params()
294 config_be.src_addr = dma_params_be->addr; in fsl_asrc_dma_hw_params()
297 ret = dmaengine_slave_config(pair->dma_chan[dir], &config_be); in fsl_asrc_dma_hw_params()
299 dev_err(dev, "failed to config DMA channel for Back-End\n"); in fsl_asrc_dma_hw_params()
300 if (pair->req_dma_chan) in fsl_asrc_dma_hw_params()
301 dma_release_channel(pair->dma_chan[dir]); in fsl_asrc_dma_hw_params()
311 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in fsl_asrc_dma_hw_free()
312 struct snd_pcm_runtime *runtime = substream->runtime; in fsl_asrc_dma_hw_free()
313 struct fsl_asrc_pair *pair = runtime->private_data; in fsl_asrc_dma_hw_free()
316 if (pair->dma_chan[!dir]) in fsl_asrc_dma_hw_free()
317 dma_release_channel(pair->dma_chan[!dir]); in fsl_asrc_dma_hw_free()
319 /* release dev_to_dev chan if we aren't reusing the Back-End one */ in fsl_asrc_dma_hw_free()
320 if (pair->dma_chan[dir] && pair->req_dma_chan) in fsl_asrc_dma_hw_free()
321 dma_release_channel(pair->dma_chan[dir]); in fsl_asrc_dma_hw_free()
323 pair->dma_chan[!dir] = NULL; in fsl_asrc_dma_hw_free()
324 pair->dma_chan[dir] = NULL; in fsl_asrc_dma_hw_free()
332 bool tx = substream->stream == SNDRV_PCM_STREAM_PLAYBACK; in fsl_asrc_dma_startup()
334 struct snd_pcm_runtime *runtime = substream->runtime; in fsl_asrc_dma_startup()
336 struct device *dev = component->dev; in fsl_asrc_dma_startup()
344 ret = snd_pcm_hw_constraint_integer(substream->runtime, in fsl_asrc_dma_startup()
351 pair = kzalloc(sizeof(*pair) + asrc->pair_priv_size, GFP_KERNEL); in fsl_asrc_dma_startup()
353 return -ENOMEM; in fsl_asrc_dma_startup()
355 pair->asrc = asrc; in fsl_asrc_dma_startup()
356 pair->private = (void *)pair + sizeof(struct fsl_asrc_pair); in fsl_asrc_dma_startup()
358 runtime->private_data = pair; in fsl_asrc_dma_startup()
364 ret = asrc->request_pair(1, pair); in fsl_asrc_dma_startup()
371 tmp_chan = asrc->get_dma_channel(pair, dir); in fsl_asrc_dma_startup()
374 ret = -EINVAL; in fsl_asrc_dma_startup()
397 asrc->release_pair(pair); in fsl_asrc_dma_startup()
409 struct snd_pcm_runtime *runtime = substream->runtime; in fsl_asrc_dma_shutdown()
410 struct fsl_asrc_pair *pair = runtime->private_data; in fsl_asrc_dma_shutdown()
416 asrc = pair->asrc; in fsl_asrc_dma_shutdown()
418 if (asrc->pair[pair->index] == pair) in fsl_asrc_dma_shutdown()
419 asrc->pair[pair->index] = NULL; in fsl_asrc_dma_shutdown()
430 struct snd_pcm_runtime *runtime = substream->runtime; in fsl_asrc_dma_pcm_pointer()
431 struct fsl_asrc_pair *pair = runtime->private_data; in fsl_asrc_dma_pcm_pointer()
433 return bytes_to_frames(substream->runtime, pair->pos); in fsl_asrc_dma_pcm_pointer()
439 struct snd_card *card = rtd->card->snd_card; in fsl_asrc_dma_pcm_new()
440 struct snd_pcm *pcm = rtd->pcm; in fsl_asrc_dma_pcm_new()
443 ret = dma_coerce_mask_and_coherent(card->dev, DMA_BIT_MASK(32)); in fsl_asrc_dma_pcm_new()
445 dev_err(card->dev, "failed to set DMA mask\n"); in fsl_asrc_dma_pcm_new()
450 card->dev, FSL_ASRC_DMABUF_SIZE); in fsl_asrc_dma_pcm_new()