diff mbox

[01/10,v3] ASoC: core: add snd_soc_get_dai_drv() to get DAI driver

Message ID 87lhiteic9.wl%kuninori.morimoto.gx@renesas.com (mailing list archive)
State New, archived
Headers show

Commit Message

Kuninori Morimoto March 19, 2015, 4:12 a.m. UTC
From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>

Sometimes sound card driver want to get cpu/codec driver.
This patch adds snd_soc_get_dai_drv() and enable it.

Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
---
v2 -> v3

 - keep .of_xlate_dai_name

 include/sound/soc.h  |  1 +
 sound/soc/soc-core.c | 69 ++++++++++++++++++++++++++++++++++++----------------
 2 files changed, 49 insertions(+), 21 deletions(-)

Comments

Mark Brown March 22, 2015, 6:08 p.m. UTC | #1
On Thu, Mar 19, 2015 at 04:12:50AM +0000, Kuninori Morimoto wrote:
> From: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
> 
> Sometimes sound card driver want to get cpu/codec driver.
> This patch adds snd_soc_get_dai_drv() and enable it.

Why would a sound card driver need to get the DAI driver?  The changelog
should explain this.
Kuninori Morimoto March 23, 2015, 7:14 a.m. UTC | #2
Hi Mark

> > Sometimes sound card driver want to get cpu/codec driver.
> > This patch adds snd_soc_get_dai_drv() and enable it.
> 
> Why would a sound card driver need to get the DAI driver?  The changelog
> should explain this.

Because, sound card needs to set dai_link->dpcm_playback / dai_link->dpcm_capture
on soc_new_pcm() if it was DPCM. but, it is depends on CPU/Codec driver.
So, sound card driver need to get DAI driver, and consider it.
I will add this explain in v4
Mark Brown March 23, 2015, 7:01 p.m. UTC | #3
On Mon, Mar 23, 2015 at 07:14:51AM +0000, Kuninori Morimoto wrote:
> > > Sometimes sound card driver want to get cpu/codec driver.
> > > This patch adds snd_soc_get_dai_drv() and enable it.

> > Why would a sound card driver need to get the DAI driver?  The changelog
> > should explain this.

> Because, sound card needs to set dai_link->dpcm_playback / dai_link->dpcm_capture
> on soc_new_pcm() if it was DPCM. but, it is depends on CPU/Codec driver.
> So, sound card driver need to get DAI driver, and consider it.
> I will add this explain in v4

Hrm, I see.  This doesn't feel quite elegant - can we do something like
factor this check out into the core here?  It feels like something the
card driver ought not to need to worry about.
Kuninori Morimoto March 24, 2015, 12:06 a.m. UTC | #4
Hi Mark

> > Because, sound card needs to set dai_link->dpcm_playback / dai_link->dpcm_capture
> > on soc_new_pcm() if it was DPCM. but, it is depends on CPU/Codec driver.
> > So, sound card driver need to get DAI driver, and consider it.
> > I will add this explain in v4
> 
> Hrm, I see.  This doesn't feel quite elegant - can we do something like
> factor this check out into the core here?  It feels like something the
> card driver ought not to need to worry about.

OK, I will reconsider it.
diff mbox

Patch

diff --git a/include/sound/soc.h b/include/sound/soc.h
index bc6cfab..35f7aa5c 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -1508,6 +1508,7 @@  unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
 				     const char *prefix,
 				     struct device_node **bitclkmaster,
 				     struct device_node **framemaster);
+struct snd_soc_dai_driver *snd_soc_get_dai_drv(struct of_phandle_args *args);
 int snd_soc_of_get_dai_name(struct device_node *of_node,
 			    const char **dai_name);
 int snd_soc_of_get_dai_link_codecs(struct device *dev,
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index a85bd42..89eac2b 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -3454,6 +3454,47 @@  unsigned int snd_soc_of_parse_daifmt(struct device_node *np,
 }
 EXPORT_SYMBOL_GPL(snd_soc_of_parse_daifmt);
 
+static struct snd_soc_dai_driver
+*_snd_soc_get_dai_drv(struct of_phandle_args *args,
+		      struct snd_soc_component *pos)
+{
+	int id = -1;
+
+	switch (args->args_count) {
+	case 0:
+		id = 0; /* same as dai_drv[0] */
+		break;
+	case 1:
+		id = args->args[0];
+		break;
+	}
+
+	if (id < 0 || id >= pos->num_dai)
+		return NULL;
+
+	return  pos->dai_drv + id;
+}
+
+struct snd_soc_dai_driver
+*snd_soc_get_dai_drv(struct of_phandle_args *args)
+{
+	struct snd_soc_dai_driver *drv = NULL;
+	struct snd_soc_component *pos;
+
+	mutex_lock(&client_mutex);
+	list_for_each_entry(pos, &component_list, list) {
+		if (pos->dev->of_node != args->np)
+			continue;
+
+		drv = _snd_soc_get_dai_drv(args, pos);
+		break;
+	}
+	mutex_unlock(&client_mutex);
+
+	return drv;
+}
+EXPORT_SYMBOL_GPL(snd_soc_get_dai_drv);
+
 static int snd_soc_get_dai_name(struct of_phandle_args *args,
 				const char **dai_name)
 {
@@ -3470,30 +3511,16 @@  static int snd_soc_get_dai_name(struct of_phandle_args *args,
 							     args,
 							     dai_name);
 		} else {
-			int id = -1;
+			struct snd_soc_dai_driver *drv;
 
-			switch (args->args_count) {
-			case 0:
-				id = 0; /* same as dai_drv[0] */
-				break;
-			case 1:
-				id = args->args[0];
-				break;
-			default:
-				/* not supported */
-				break;
-			}
+			drv = _snd_soc_get_dai_drv(args, pos);
+			if (drv) {
+				ret = 0;
 
-			if (id < 0 || id >= pos->num_dai) {
-				ret = -EINVAL;
-				continue;
+				*dai_name = drv->name;
+				if (!*dai_name)
+					*dai_name = pos->name;
 			}
-
-			ret = 0;
-
-			*dai_name = pos->dai_drv[id].name;
-			if (!*dai_name)
-				*dai_name = pos->name;
 		}
 
 		break;