Skip to contentSkip to conversation

ASoC: Allow platform drivers to have no ops structure

PATCH In review Mark Brown 4 participants 12 messages Apr 27, 2011

Subsystems (3)
lore
Share & tools
lore

Mark Brown

author
#0 lore raw

PATCH 1/5 ASoC: Allow platform drivers to have no ops structure

---
 sound/soc/soc-core.c |   49 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 30 insertions(+), 19 deletions(-)
sound/soc/soc-core.c +30 -19
index a6f37d4..cb93b79 100644
@@ -545,6 +545,12 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 
 	mutex_lock(&pcm_mutex);
 
+	/* CODEC<->CODEC DAI link, no CPU interface */
+	if (rtd->dai_link->no_cpu) {
+		ret = -EINVAL;
+		goto out;
+	}
+
 	/* startup the audio subsystem */
 	if (cpu_dai->driver->ops->startup) {
 		ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
@@ -555,7 +561,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 		}
 	}
 
-	if (platform->driver->ops->open) {
+	if (platform->driver->ops && platform->driver->ops->open) {
 		ret = platform->driver->ops->open(substream);
 		if (ret < 0) {
 			printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
@@ -685,7 +691,7 @@ machine_err:
 		codec_dai->driver->ops->shutdown(substream, codec_dai);
 
 codec_dai_err:
-	if (platform->driver->ops->close)
+	if (platform->driver->ops && platform->driver->ops->close)
 		platform->driver->ops->close(substream);
 
 platform_err:
@@ -767,7 +773,7 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
 	if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
 		rtd->dai_link->ops->shutdown(substream);
 
-	if (platform->driver->ops->close)
+	if (platform->driver->ops && platform->driver->ops->close)
 		platform->driver->ops->close(substream);
 	cpu_dai->runtime = NULL;
 
@@ -810,7 +816,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
 		}
 	}
 
-	if (platform->driver->ops->prepare) {
+	if (platform->driver->ops && platform->driver->ops->prepare) {
 		ret = platform->driver->ops->prepare(substream);
 		if (ret < 0) {
 			printk(KERN_ERR "asoc: platform prepare error\n");
@@ -899,7 +905,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
 		}
 	}
 
-	if (platform->driver->ops->hw_params) {
+	if (platform->driver->ops && platform->driver->ops->hw_params) {
 		ret = platform->driver->ops->hw_params(substream, params);
 		if (ret < 0) {
 			printk(KERN_ERR "asoc: platform %s hw params failed\n",
@@ -952,7 +958,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
 		rtd->dai_link->ops->hw_free(substream);
 
 	/* free any DMA resources */
-	if (platform->driver->ops->hw_free)
+	if (platform->driver->ops && platform->driver->ops->hw_free)
 		platform->driver->ops->hw_free(substream);
 
 	/* now free hw params for the DAIs  */
@@ -980,7 +986,7 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
 			return ret;
 	}
 
-	if (platform->driver->ops->trigger) {
+	if (platform->driver->ops && platform->driver->ops->trigger) {
 		ret = platform->driver->ops->trigger(substream, cmd);
 		if (ret < 0)
 			return ret;
@@ -1009,7 +1015,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
 	snd_pcm_uframes_t offset = 0;
 	snd_pcm_sframes_t delay = 0;
 
-	if (platform->driver->ops->pointer)
+	if (platform->driver->ops && platform->driver->ops->pointer)
 		offset = platform->driver->ops->pointer(substream);
 
 	if (cpu_dai->driver->ops->delay)
@@ -2125,13 +2131,15 @@ static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 
 	rtd->pcm = pcm;
 	pcm->private_data = rtd;
-	soc_pcm_ops.mmap = platform->driver->ops->mmap;
-	soc_pcm_ops.pointer = platform->driver->ops->pointer;
-	soc_pcm_ops.ioctl = platform->driver->ops->ioctl;
-	soc_pcm_ops.copy = platform->driver->ops->copy;
-	soc_pcm_ops.silence = platform->driver->ops->silence;
-	soc_pcm_ops.ack = platform->driver->ops->ack;
-	soc_pcm_ops.page = platform->driver->ops->page;
+	if (platform->driver->ops) {
+		soc_pcm_ops.mmap = platform->driver->ops->mmap;
+		soc_pcm_ops.pointer = platform->driver->ops->pointer;
+		soc_pcm_ops.ioctl = platform->driver->ops->ioctl;
+		soc_pcm_ops.copy = platform->driver->ops->copy;
+		soc_pcm_ops.silence = platform->driver->ops->silence;
+		soc_pcm_ops.ack = platform->driver->ops->ack;
+		soc_pcm_ops.page = platform->driver->ops->page;
+	}
 
 	if (playback)
 		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
@@ -2139,10 +2147,13 @@ static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 	if (capture)
 		snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
 
-	ret = platform->driver->pcm_new(rtd->card->snd_card, codec_dai, pcm);
-	if (ret < 0) {
-		printk(KERN_ERR "asoc: platform pcm constructor failed\n");
-		return ret;
+	if (platform->driver->pcm_new) {
+		ret = platform->driver->pcm_new(rtd->card->snd_card,
+						codec_dai, pcm);
+		if (ret < 0) {
+			pr_err("asoc: platform pcm constructor failed\n");
+			return ret;
+		}
 	}
 
 	pcm->private_free = platform->driver->pcm_free;
Signature · 1 line
1.7.4.1
author
#1 lore raw

PATCH 2/5 ASoC: Add more natural support for no-DMA DAIs

Since we can now support multiple platforms allow machines to not specify a platform in a DAI link. Since the rest of the code requires that we have a struct device for all objects we do this by substituting in a dummy device that we register automatically.

---
 sound/soc/soc-core.c  |   15 +++++++++----
 sound/soc/soc-utils.c |   55 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 65 insertions(+), 5 deletions(-)
sound/soc/soc-core.c +10 -5
index cb93b79..e851aa7 100644
@@ -1357,13 +1357,18 @@ find_codec:
 			dai_link->codec_name);
 
 find_platform:
-	/* do we already have the CODEC DAI for this link ? */
-	if (rtd->platform) {
+	/* do we need a platform? */
+	if (rtd->platform)
 		goto out;
-	}
-	/* no, then find CPU DAI from registered DAIs*/
+
+	/* if there's no platform we match on the empty platform */
+	platform_name = dai_link->platform_name;
+	if (!platform_name)
+		platform_name = "snd-soc-dummy";
+
+	/* no, then find one from the set of registered platforms */
 	list_for_each_entry(platform, &platform_list, list) {
-		if (!strcmp(platform->name, dai_link->platform_name)) {
+		if (!strcmp(platform->name, platform_name)) {
 			rtd->platform = platform;
 			goto out;
 		}
sound/soc/soc-utils.c +55 -0

64 lines not on this page · raw message

Signature · 1 line
1.7.4.1
Acked-by on v1 2/5
#2 lore raw

Re: [PATCH 2/5] ASoC: Add more natural support for no-DMA DAIs

Quoted 6 lines · Mark Brown

Since we can now support multiple platforms allow machines to not specify a platform in a DAI link. Since the rest of the code requires that we have a struct device for all objects we do this by substituting in a dummy device that we register automatically.

2-5 as well...

author
#3 lore raw

PATCH 3/5 ASoC: Don't specify the DMA driver for Speyside baseband link

In reply to Mark Brown
---
 sound/soc/samsung/speyside.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
sound/soc/samsung/speyside.c +0 -1
index 337855a..360a333 100644
@@ -183,7 +183,6 @@ static struct snd_soc_dai_link speyside_dai[] = {
 		.cpu_dai_name = "wm8915-aif2",
 		.codec_dai_name = "wm1250-ev1",
 		.codec_name = "wm1250-ev1.1-0027",
-		.platform_name = "samsung-audio",
 		.ops = &speyside_ops,
 		.ignore_suspend = 1,
 	},
Signature · 1 line
1.7.4.1
author
#4 lore raw

PATCH 4/5 ASoC: Don't specify the DMA driver for OpenMoko baseband link

In reply to Mark Brown
---
 sound/soc/samsung/neo1973_wm8753.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
sound/soc/samsung/neo1973_wm8753.c +0 -1
index 4522309..16152ed 100644
@@ -432,7 +432,6 @@ static struct snd_soc_dai_link neo1973_dai[] = {
 { /* Voice via BT */
 	.name = "Bluetooth",
 	.stream_name = "Voice",
-	.platform_name = "samsung-audio",
 	.cpu_dai_name = "dfbmcs320-pcm",
 	.codec_dai_name = "wm8753-voice",
 	.codec_name = "wm8753-codec.0-001a",
Signature · 1 line
1.7.4.1
author
#5 lore raw

PATCH 5/5 ASoC: Don't specify the DMA driver for Goni baseband link

In reply to Mark Brown
---
 sound/soc/samsung/goni_wm8994.c |    1 -
 1 files changed, 0 insertions(+), 1 deletions(-)
sound/soc/samsung/goni_wm8994.c +0 -1
index 0e80dae..eb6d72e 100644
@@ -246,7 +246,6 @@ static struct snd_soc_dai_link goni_dai[] = {
 	.stream_name = "Voice",
 	.cpu_dai_name = "goni-voice-dai",
 	.codec_dai_name = "wm8994-aif2",
-	.platform_name = "samsung-audio",
 	.codec_name = "wm8994-codec.0-001a",
 	.ops = &goni_voice_ops,
 },
Signature · 1 line
1.7.4.1
#6 lore raw
In reply to Mark Brown
Quoted 12 lines · Mark Brown
---
 sound/soc/soc-core.c |   49 ++++++++++++++++++++++++++++++-------------------
 1 files changed, 30 insertions(+), 19 deletions(-)
sound/soc/soc-core.c +0 -0
index a6f37d4..cb93b79 100644
@@ -545,6 +545,12 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 
 	mutex_lock(&pcm_mutex);

sound/soc/soc-core.c static int soc_pcm_open(struct snd_pcm_substream *substream) · line 556

Quoted 10 lines
sound/soc/soc-core.c +6 -0
 
+	/* CODEC<->CODEC DAI link, no CPU interface */
+	if (rtd->dai_link->no_cpu) {
+		ret = -EINVAL;
+		goto out;
+	}
+
 	/* startup the audio subsystem */
 	if (cpu_dai->driver->ops->startup) {
 		ret = cpu_dai->driver->ops->startup(substream, cpu_dai);

This hunk looks as if it belongs to a different series. There is currently no 'no_cpu' field in the snd_soc_dai_link struct.

- Lars

author
#7 lore raw
Quoted 2 lines · Lars-Peter Clausen

This hunk looks as if it belongs to a different series. There is currently no 'no_cpu' field in the snd_soc_dai_link struct.

Yes, it does. Please review assuming that's dropped.

#9 lore raw
In reply to Mark Brown
Quoted 125 lines · Mark Brown

---
 sound/soc/soc-core.c |   49 ++++++++++++++++++++++++++++++-------------------

 1 files changed, 30 insertions(+), 19 deletions(-)
sound/soc/soc-core.c +7 -1
index a6f37d4..cb93b79 100644
@@ -545,6 +545,12 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
 
        mutex_lock(&pcm_mutex);
 
+       /* CODEC<->CODEC DAI link, no CPU interface */
+       if (rtd->dai_link->no_cpu) {
+               ret = -EINVAL;
+               goto out;
+       }
+
        /* startup the audio subsystem */
        if (cpu_dai->driver->ops->startup) {
                ret = cpu_dai->driver->ops->startup(substream, cpu_dai);
@@ -555,7 +561,7 @@ static int soc_pcm_open(struct snd_pcm_substream *substream)
                }
        }
 
-       if (platform->driver->ops->open) {
+       if (platform->driver->ops && platform->driver->ops->open) {
                ret = platform->driver->ops->open(substream);
                if (ret < 0) {
                        printk(KERN_ERR "asoc: can't open platform %s\n", platform->name);
@@ -685,7 +691,7 @@ machine_err:
                codec_dai->driver->ops->shutdown(substream, codec_dai);
 

 codec_dai_err:
-       if (platform->driver->ops->close)
+       if (platform->driver->ops && platform->driver->ops->close) platform->driver->ops->close(substream);

 platform_err:

sound/soc/soc-core.c +15 -17
@@ -767,7 +773,7 @@ static int soc_codec_close(struct snd_pcm_substream *substream)
        if (rtd->dai_link->ops && rtd->dai_link->ops->shutdown)
                rtd->dai_link->ops->shutdown(substream);
 
-       if (platform->driver->ops->close)
+       if (platform->driver->ops && platform->driver->ops->close)
                platform->driver->ops->close(substream);
        cpu_dai->runtime = NULL;
 
@@ -810,7 +816,7 @@ static int soc_pcm_prepare(struct snd_pcm_substream *substream)
                }
        }
 
-       if (platform->driver->ops->prepare) {
+       if (platform->driver->ops && platform->driver->ops->prepare) {
                ret = platform->driver->ops->prepare(substream);
                if (ret < 0) {
                        printk(KERN_ERR "asoc: platform prepare error\n");
@@ -899,7 +905,7 @@ static int soc_pcm_hw_params(struct snd_pcm_substream *substream,
                }
        }
 
-       if (platform->driver->ops->hw_params) {
+       if (platform->driver->ops && platform->driver->ops->hw_params) {
                ret = platform->driver->ops->hw_params(substream, params);
                if (ret < 0) {
                        printk(KERN_ERR "asoc: platform %s hw params failed\n",
@@ -952,7 +958,7 @@ static int soc_pcm_hw_free(struct snd_pcm_substream *substream)
                rtd->dai_link->ops->hw_free(substream);
 
        /* free any DMA resources */
-       if (platform->driver->ops->hw_free)
+       if (platform->driver->ops && platform->driver->ops->hw_free)
                platform->driver->ops->hw_free(substream);
 
        /* now free hw params for the DAIs  */
@@ -980,7 +986,7 @@ static int soc_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
                        return ret;
        }
 
-       if (platform->driver->ops->trigger) {
+       if (platform->driver->ops && platform->driver->ops->trigger) {
                ret = platform->driver->ops->trigger(substream, cmd);
                if (ret < 0)
                        return ret;
@@ -1009,7 +1015,7 @@ static snd_pcm_uframes_t soc_pcm_pointer(struct snd_pcm_substream *substream)
        snd_pcm_uframes_t offset = 0;
        snd_pcm_sframes_t delay = 0;
 
-       if (platform->driver->ops->pointer)
+       if (platform->driver->ops && platform->driver->ops->pointer)
                offset = platform->driver->ops->pointer(substream);
 
        if (cpu_dai->driver->ops->delay)
@@ -2125,13 +2131,15 @@ static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
 
        rtd->pcm = pcm;
        pcm->private_data = rtd;
-       soc_pcm_ops.mmap = platform->driver->ops->mmap;
-       soc_pcm_ops.pointer = platform->driver->ops->pointer;
-       soc_pcm_ops.ioctl = platform->driver->ops->ioctl;
-       soc_pcm_ops.copy = platform->driver->ops->copy;
-       soc_pcm_ops.silence = platform->driver->ops->silence;
-       soc_pcm_ops.ack = platform->driver->ops->ack;
-       soc_pcm_ops.page = platform->driver->ops->page;
+       if (platform->driver->ops) {
+               soc_pcm_ops.mmap = platform->driver->ops->mmap;
+               soc_pcm_ops.pointer = platform->driver->ops->pointer;
+               soc_pcm_ops.ioctl = platform->driver->ops->ioctl;
+               soc_pcm_ops.copy = platform->driver->ops->copy;
+               soc_pcm_ops.silence = platform->driver->ops->silence;
+               soc_pcm_ops.ack = platform->driver->ops->ack;
+               soc_pcm_ops.page = platform->driver->ops->page;
+       }
 
        if (playback)
                snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &soc_pcm_ops);
@@ -2139,10 +2147,13 @@ static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num)
        if (capture)
                snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &soc_pcm_ops);
 
-       ret = platform->driver->pcm_new(rtd->card->snd_card, codec_dai, pcm);
-       if (ret < 0) {
-               printk(KERN_ERR "asoc: platform pcm constructor failed\n");
-               return ret;

sound/soc/soc-core.c static int soc_new_pcm(struct snd_soc_pcm_runtime *rtd, int num) · line 2159

Quoted 10 lines
sound/soc/soc-core.c +7 -0
+       if (platform->driver->pcm_new) {
+               ret = platform->driver->pcm_new(rtd->card->snd_card,
+                                               codec_dai, pcm);
+               if (ret < 0) {
+                       pr_err("asoc: platform pcm constructor failed\n");
+                       return ret;
+               }
        }
 
        pcm->private_free = platform->driver->pcm_free;

I have nothing against this approach, but just a thought... Is there any option like having 'dummy' versions of cpu, codec and dma dais, maybe ops too, and have machine drivers explicitly use them. That will preserve what has always been expected off of ASoC drivers and keep the
core 'simple' (not to mean the checks you add above are serious overhead).

Thanks.
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel

author
#10 lore raw

On Thu, Apr 28, 2011 at 12:17:46AM +0530, Jassi Brar wrote:

Please delete unneeded context, makes it much easier to find your text...

Quoted 7 lines

I have nothing against this approach, but just a thought... Is there any option like having 'dummy' versions of cpu, codec and dma dais, maybe ops too, and have machine drivers explicitly use them. That will preserve what has always been expected off of ASoC drivers and keep the
core 'simple' (not to mean the checks you add above are serious overhead).

I considered that, my thought was mostly that it's better for the core to do a bit of work than for each user to have to do typing. I'd probably have gone the other way if we weren't already having to check to see if the op itself was there - this is why there's a dummy driver created and substituted in where there's no platform at all. Had I done the second patch first I'd probably never have written this one but it seemed like something someone might come up with another sane use case for some time.

In the DAIs we're actually substituting a dummy ops in but we shouldn't really be doing that as it ought to be possible for the drivers to be const.

Acked-by
#11 lore raw
Quoted 4 lines · Mark Brown

On Thu, Apr 28, 2011 at 12:17:46AM +0530, Jassi Brar wrote:

Please delete unneeded context, makes it much easier to find your text...

There wasn't anything to quote from changelog and my comments encompass your every change, so I commented at the end.

Quoted 17 lines
Quoted 7 lines

I have nothing against this approach, but just a thought... Is there any option like having 'dummy' versions of cpu, codec and dma dais, maybe ops too, and have machine drivers explicitly use them. That will preserve what has always been expected off of ASoC drivers and keep the
core 'simple' (not to mean the checks you add above are serious overhead).

I considered that, my thought was mostly that it's better for the core to do a bit of work than for each user to have to do typing.  I'd probably have gone the other way if we weren't already having to check to see if the op itself was there - this is why there's a dummy driver created and substituted in where there's no platform at all.  Had I done the second patch first I'd probably never have written this one but it seemed like something someone might come up with another sane use case for some time.

Quoted 3 lines

In the DAIs we're actually substituting a dummy ops in but we shouldn't really be doing that as it ought to be possible for the drivers to be const.

OK.

_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel