Commit 706e2c88 authored by Shengjiu Wang's avatar Shengjiu Wang Committed by Mark Brown

ASoC: fsl_asrc_dma: Reuse the dma channel if available in Back-End

The dma channel has been requested by Back-End cpu dai driver already.
If fsl_asrc_dma requests dma chan with same dma:tx symlink, then
there will be below warning with SDMA.

[   48.174236] fsl-esai-dai 2024000.esai: Cannot create DMA dma:tx symlink

So if we can reuse the dma channel of Back-End, then the issue can be
fixed.

In order to get the dma channel which is already requested in Back-End.
we use the exported two functions (snd_soc_lookup_component_nolocked
and soc_component_to_pcm). If we can get the dma channel, then reuse it,
if can't, then request a new one.
Signed-off-by: default avatarShengjiu Wang <shengjiu.wang@nxp.com>
Reviewed-by: default avatarNicolin Chen <nicoleotsuka@gmail.com>
Link: https://lore.kernel.org/r/3a79f0442cb4930c633cf72145cfe95a45b9c78e.1591947428.git.shengjiu.wang@nxp.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent a9a21e1e
...@@ -135,6 +135,8 @@ static int fsl_asrc_dma_hw_params(struct snd_soc_component *component, ...@@ -135,6 +135,8 @@ static int fsl_asrc_dma_hw_params(struct snd_soc_component *component,
struct snd_dmaengine_dai_dma_data *dma_params_be = NULL; struct snd_dmaengine_dai_dma_data *dma_params_be = NULL;
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct fsl_asrc_pair *pair = runtime->private_data; struct fsl_asrc_pair *pair = runtime->private_data;
struct dma_chan *tmp_chan = NULL, *be_chan = NULL;
struct snd_soc_component *component_be = NULL;
struct fsl_asrc *asrc = pair->asrc; struct fsl_asrc *asrc = pair->asrc;
struct dma_slave_config config_fe, config_be; struct dma_slave_config config_fe, config_be;
enum asrc_pair_index index = pair->index; enum asrc_pair_index index = pair->index;
...@@ -142,7 +144,6 @@ static int fsl_asrc_dma_hw_params(struct snd_soc_component *component, ...@@ -142,7 +144,6 @@ static int fsl_asrc_dma_hw_params(struct snd_soc_component *component,
int stream = substream->stream; int stream = substream->stream;
struct imx_dma_data *tmp_data; struct imx_dma_data *tmp_data;
struct snd_soc_dpcm *dpcm; struct snd_soc_dpcm *dpcm;
struct dma_chan *tmp_chan;
struct device *dev_be; struct device *dev_be;
u8 dir = tx ? OUT : IN; u8 dir = tx ? OUT : IN;
dma_cap_mask_t mask; dma_cap_mask_t mask;
...@@ -197,18 +198,30 @@ static int fsl_asrc_dma_hw_params(struct snd_soc_component *component, ...@@ -197,18 +198,30 @@ static int fsl_asrc_dma_hw_params(struct snd_soc_component *component,
dma_cap_set(DMA_SLAVE, mask); dma_cap_set(DMA_SLAVE, mask);
dma_cap_set(DMA_CYCLIC, mask); dma_cap_set(DMA_CYCLIC, mask);
/*
* The Back-End device might have already requested a DMA channel,
* so try to reuse it first, and then request a new one upon NULL.
*/
component_be = snd_soc_lookup_component_nolocked(dev_be, SND_DMAENGINE_PCM_DRV_NAME);
if (component_be) {
be_chan = soc_component_to_pcm(component_be)->chan[substream->stream];
tmp_chan = be_chan;
}
if (!tmp_chan)
tmp_chan = dma_request_slave_channel(dev_be, tx ? "tx" : "rx");
/* /*
* An EDMA DEV_TO_DEV channel is fixed and bound with DMA event of each * An EDMA DEV_TO_DEV channel is fixed and bound with DMA event of each
* peripheral, unlike SDMA channel that is allocated dynamically. So no * peripheral, unlike SDMA channel that is allocated dynamically. So no
* need to configure dma_request and dma_request2, but get dma_chan via * need to configure dma_request and dma_request2, but get dma_chan of
* dma_request_slave_channel directly with dma name of Front-End device * Back-End device directly via dma_request_slave_channel.
*/ */
if (!asrc->use_edma) { if (!asrc->use_edma) {
/* Get DMA request of Back-End */ /* Get DMA request of Back-End */
tmp_chan = dma_request_slave_channel(dev_be, tx ? "tx" : "rx");
tmp_data = tmp_chan->private; tmp_data = tmp_chan->private;
pair->dma_data.dma_request = tmp_data->dma_request; pair->dma_data.dma_request = tmp_data->dma_request;
dma_release_channel(tmp_chan); if (!be_chan)
dma_release_channel(tmp_chan);
/* Get DMA request of Front-End */ /* Get DMA request of Front-End */
tmp_chan = asrc->get_dma_channel(pair, dir); tmp_chan = asrc->get_dma_channel(pair, dir);
...@@ -221,6 +234,8 @@ static int fsl_asrc_dma_hw_params(struct snd_soc_component *component, ...@@ -221,6 +234,8 @@ static int fsl_asrc_dma_hw_params(struct snd_soc_component *component,
pair->dma_chan[dir] = pair->dma_chan[dir] =
dma_request_channel(mask, filter, &pair->dma_data); dma_request_channel(mask, filter, &pair->dma_data);
} else { } else {
if (!be_chan)
dma_release_channel(tmp_chan);
pair->dma_chan[dir] = pair->dma_chan[dir] =
asrc->get_dma_channel(pair, dir); asrc->get_dma_channel(pair, dir);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment