diff mbox series

ASoC: apple: mca: Postpone requesting of DMA channels

Message ID 20220905074030.1293-1-povik+lin@cutebit.org (mailing list archive)
State Accepted
Commit 4ec8179c212fb1530df4a1df6db75756c06da5f6
Headers show
Series ASoC: apple: mca: Postpone requesting of DMA channels | expand

Commit Message

Martin Povišer Sept. 5, 2022, 7:40 a.m. UTC
Move the requesting of DMA channels further down from 'probe' to
'pcm_new'. This is to spare the allocated DMA channel resources as we
typically only ever use one or two of the clusters for PCM streaming.
Before we would request DMA channels for all clusters.

(This is prompted by a change in the Audio DMA Controller driver, which
will now be allocating cache SRAM to channels.)

Signed-off-by: Martin Povišer <povik+lin@cutebit.org>
---
 sound/soc/apple/mca.c | 79 +++++++++++++++++++++++++------------------
 1 file changed, 46 insertions(+), 33 deletions(-)

Comments

Mark Brown Sept. 5, 2022, 3:38 p.m. UTC | #1
On Mon, 5 Sep 2022 09:40:30 +0200, Martin Povišer wrote:
> Move the requesting of DMA channels further down from 'probe' to
> 'pcm_new'. This is to spare the allocated DMA channel resources as we
> typically only ever use one or two of the clusters for PCM streaming.
> Before we would request DMA channels for all clusters.
> 
> (This is prompted by a change in the Audio DMA Controller driver, which
> will now be allocating cache SRAM to channels.)
> 
> [...]

Applied to

   https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next

Thanks!

[1/1] ASoC: apple: mca: Postpone requesting of DMA channels
      commit: 4ec8179c212fb1530df4a1df6db75756c06da5f6

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark
diff mbox series

Patch

diff --git a/sound/soc/apple/mca.c b/sound/soc/apple/mca.c
index aa67d57c9a9b..69643524796e 100644
--- a/sound/soc/apple/mca.c
+++ b/sound/soc/apple/mca.c
@@ -885,6 +885,43 @@  static snd_pcm_uframes_t mca_pointer(struct snd_soc_component *component,
 	return snd_dmaengine_pcm_pointer(substream);
 }
 
+static struct dma_chan *mca_request_dma_channel(struct mca_cluster *cl, unsigned int stream)
+{
+	bool is_tx = (stream == SNDRV_PCM_STREAM_PLAYBACK);
+#ifndef USE_RXB_FOR_CAPTURE
+	char *name = devm_kasprintf(cl->host->dev, GFP_KERNEL,
+				    is_tx ? "tx%da" : "rx%da", cl->no);
+#else
+	char *name = devm_kasprintf(cl->host->dev, GFP_KERNEL,
+				    is_tx ? "tx%da" : "rx%db", cl->no);
+#endif
+	return of_dma_request_slave_channel(cl->host->dev->of_node, name);
+
+}
+
+static void mca_pcm_free(struct snd_soc_component *component,
+			 struct snd_pcm *pcm)
+{
+	struct snd_soc_pcm_runtime *rtd = snd_pcm_chip(pcm);
+	struct mca_cluster *cl = mca_dai_to_cluster(asoc_rtd_to_cpu(rtd, 0));
+	unsigned int i;
+
+	if (rtd->dai_link->no_pcm)
+		return;
+
+	for_each_pcm_streams(i) {
+		struct snd_pcm_substream *substream =
+			rtd->pcm->streams[i].substream;
+
+		if (!substream || !cl->dma_chans[i])
+			continue;
+
+		dma_release_channel(cl->dma_chans[i]);
+		cl->dma_chans[i] = NULL;
+	}
+}
+
+
 static int mca_pcm_new(struct snd_soc_component *component,
 		       struct snd_soc_pcm_runtime *rtd)
 {
@@ -897,17 +934,21 @@  static int mca_pcm_new(struct snd_soc_component *component,
 	for_each_pcm_streams(i) {
 		struct snd_pcm_substream *substream =
 			rtd->pcm->streams[i].substream;
-		struct dma_chan *chan = cl->dma_chans[i];
+		struct dma_chan *chan;
 
 		if (!substream)
 			continue;
 
-		if (!chan) {
-			dev_err(component->dev, "missing DMA channel for stream %d on SERDES %d\n",
-				i, cl->no);
+		chan = mca_request_dma_channel(cl, i);
+
+		if (IS_ERR_OR_NULL(chan)) {
+			dev_err(component->dev, "unable to obtain DMA channel (stream %d cluster %d): %pe\n",
+				i, cl->no, chan);
+			mca_pcm_free(component, rtd->pcm);
 			return -EINVAL;
 		}
 
+		cl->dma_chans[i] = chan;
 		snd_pcm_set_managed_buffer(substream, SNDRV_DMA_TYPE_DEV_IRAM,
 					   chan->device->dev, 512 * 1024 * 6,
 					   SIZE_MAX);
@@ -924,6 +965,7 @@  static const struct snd_soc_component_driver mca_component = {
 	.trigger = mca_trigger,
 	.pointer = mca_pointer,
 	.pcm_construct = mca_pcm_new,
+	.pcm_destruct = mca_pcm_free,
 };
 
 static void apple_mca_release(struct mca_data *mca)
@@ -1019,7 +1061,6 @@  static int apple_mca_probe(struct platform_device *pdev)
 		struct snd_soc_dai_driver *fe =
 			&dai_drivers[mca->nclusters + i];
 		struct snd_soc_dai_driver *be = &dai_drivers[i];
-		int stream;
 
 		cl->host = mca;
 		cl->no = i;
@@ -1041,34 +1082,6 @@  static int apple_mca_probe(struct platform_device *pdev)
 			goto err_release;
 		}
 
-		for_each_pcm_streams(stream) {
-			struct dma_chan *chan;
-			bool is_tx = (stream == SNDRV_PCM_STREAM_PLAYBACK);
-#ifndef USE_RXB_FOR_CAPTURE
-			char *name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
-						    is_tx ? "tx%da" : "rx%da",
-						    i);
-#else
-			char *name = devm_kasprintf(&pdev->dev, GFP_KERNEL,
-						    is_tx ? "tx%da" : "rx%db",
-						    i);
-#endif
-
-			chan = of_dma_request_slave_channel(pdev->dev.of_node,
-							    name);
-			if (IS_ERR(chan)) {
-				if (PTR_ERR(chan) != -EPROBE_DEFER)
-					dev_err(&pdev->dev,
-						"no %s DMA channel: %ld\n",
-						name, PTR_ERR(chan));
-
-				ret = PTR_ERR(chan);
-				goto err_release;
-			}
-
-			cl->dma_chans[stream] = chan;
-		}
-
 		fe->id = i;
 		fe->name =
 			devm_kasprintf(&pdev->dev, GFP_KERNEL, "mca-pcm-%d", i);