All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lars-Peter Clausen <lars@metafoo.de>
To: Mark Brown <broonie@kernel.org>, Liam Girdwood <lgirdwood@gmail.com>
Cc: alsa-devel@alsa-project.org, Lars-Peter Clausen <lars@metafoo.de>,
	Sebastian Reichel <sre@kernel.org>,
	Benoit Cousson <bcousson@baylibre.com>
Subject: [PATCH 3/4] ASoC: Bind aux devs early
Date: Tue,  1 Jul 2014 22:13:47 +0200	[thread overview]
Message-ID: <1404245628-30877-4-git-send-email-lars@metafoo.de> (raw)
In-Reply-To: <1404245628-30877-1-git-send-email-lars@metafoo.de>

Currently in snd_soc_instantiate_card() we only check if the aux dev exists, but
do not yet assign it to its rtd. This means that we need to lookup the aux dev
again in soc_probe_aux_dev(). This patch changes the behavior to assign the aux
dev to the rtd in soc_check_aux_dev() (and renames it to soc_bind_aux_dev()).
This simplifies the implementation a bit and also removes the need for
soc_post_component_init() to know about the specific CODEC that was assigned to
the rtd. The later is necessary for componentization as the code should work for
all types of components not just CODECs. This new behavior is also more in sync
with how soc_bind_dai_link()/soc_probe_link_dais() works.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
---
 sound/soc/soc-core.c | 67 ++++++++++++++++++++--------------------------------
 1 file changed, 25 insertions(+), 42 deletions(-)

diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index c8bdac2..0b870bb 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1286,9 +1286,7 @@ static void rtd_release(struct device *dev)
 	kfree(dev);
 }
 
-static int soc_aux_dev_init(struct snd_soc_card *card,
-			    struct snd_soc_codec *codec,
-			    int num)
+static int soc_aux_dev_init(struct snd_soc_card *card, int num)
 {
 	struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
 	struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
@@ -1298,13 +1296,11 @@ static int soc_aux_dev_init(struct snd_soc_card *card,
 
 	/* do machine specific initialization */
 	if (aux_dev->init) {
-		ret = aux_dev->init(&codec->dapm);
+		ret = aux_dev->init(&rtd->codec->dapm);
 		if (ret < 0)
 			return ret;
 	}
 
-	rtd->codec = codec;
-
 	return 0;
 }
 
@@ -1327,7 +1323,6 @@ static int soc_dai_link_init(struct snd_soc_card *card, int num)
 }
 
 static int soc_post_component_init(struct snd_soc_card *card,
-				   struct snd_soc_codec *codec,
 				   int num, int dailess)
 {
 	struct snd_soc_dai_link *dai_link = NULL;
@@ -1345,7 +1340,7 @@ static int soc_post_component_init(struct snd_soc_card *card,
 		aux_dev = &card->aux_dev[num];
 		rtd = &card->rtd_aux[num];
 		name = aux_dev->name;
-		ret = soc_aux_dev_init(card, codec, num);
+		ret = soc_aux_dev_init(card, num);
 	}
 
 	if (ret < 0) {
@@ -1380,13 +1375,13 @@ static int soc_post_component_init(struct snd_soc_card *card,
 	/* add DAPM sysfs entries for this codec */
 	ret = snd_soc_dapm_sys_add(rtd->dev);
 	if (ret < 0)
-		dev_err(codec->dev,
+		dev_err(rtd->dev,
 			"ASoC: failed to add codec dapm sysfs entries: %d\n", ret);
 
 	/* add codec sysfs entries */
 	ret = device_create_file(rtd->dev, &dev_attr_codec_reg);
 	if (ret < 0)
-		dev_err(codec->dev,
+		dev_err(rtd->dev,
 			"ASoC: failed to add codec sysfs files: %d\n", ret);
 
 #ifdef CONFIG_DEBUG_FS
@@ -1551,7 +1546,7 @@ static int soc_probe_link_dais(struct snd_soc_card *card, int num, int order)
 	if (order != SND_SOC_COMP_ORDER_LAST)
 		return 0;
 
-	ret = soc_post_component_init(card, codec, num, 0);
+	ret = soc_post_component_init(card, num, 0);
 	if (ret)
 		return ret;
 
@@ -1649,51 +1644,39 @@ static void soc_unregister_ac97_dai_link(struct snd_soc_pcm_runtime *rtd)
 }
 #endif
 
-static int soc_check_aux_dev(struct snd_soc_card *card, int num)
-{
-	struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
-	const char *codecname = aux_dev->codec_name;
-	struct snd_soc_codec *codec;
-
-	codec = soc_find_codec(aux_dev->codec_of_node, aux_dev->codec_name);
-	if (codec)
-		return 0;
-	if (aux_dev->codec_of_node)
-		codecname = of_node_full_name(aux_dev->codec_of_node);
-
-	dev_err(card->dev, "ASoC: %s not registered\n", codecname);
-	return -EPROBE_DEFER;
-}
-
-static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
+static int soc_bind_aux_dev(struct snd_soc_card *card, int num)
 {
+	struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
 	struct snd_soc_aux_dev *aux_dev = &card->aux_dev[num];
 	const char *codecname = aux_dev->codec_name;
-	int ret = -ENODEV;
-	struct snd_soc_codec *codec;
 
-	codec = soc_find_codec(aux_dev->codec_of_node, aux_dev->codec_name);
-	if (!codec) {
+	rtd->codec = soc_find_codec(aux_dev->codec_of_node, codecname);
+	if (!rtd->codec) {
 		if (aux_dev->codec_of_node)
 			codecname = of_node_full_name(aux_dev->codec_of_node);
 
-		/* codec not found */
-		dev_err(card->dev, "ASoC: codec %s not found", codecname);
+		dev_err(card->dev, "ASoC: %s not registered\n", codecname);
 		return -EPROBE_DEFER;
 	}
 
-	if (codec->probed) {
-		dev_err(codec->dev, "ASoC: codec already probed");
+	return 0;
+}
+
+static int soc_probe_aux_dev(struct snd_soc_card *card, int num)
+{
+	struct snd_soc_pcm_runtime *rtd = &card->rtd_aux[num];
+	int ret;
+
+	if (rtd->codec->probed) {
+		dev_err(rtd->codec->dev, "ASoC: codec already probed\n");
 		return -EBUSY;
 	}
 
-	ret = soc_probe_codec(card, codec);
+	ret = soc_probe_codec(card, rtd->codec);
 	if (ret < 0)
 		return ret;
 
-	ret = soc_post_component_init(card, codec, num, 1);
-
-	return ret;
+	return soc_post_component_init(card, num, 1);
 }
 
 static void soc_remove_aux_dev(struct snd_soc_card *card, int num)
@@ -1745,9 +1728,9 @@ static int snd_soc_instantiate_card(struct snd_soc_card *card)
 			goto base_error;
 	}
 
-	/* check aux_devs too */
+	/* bind aux_devs too */
 	for (i = 0; i < card->num_aux_devs; i++) {
-		ret = soc_check_aux_dev(card, i);
+		ret = soc_bind_aux_dev(card, i);
 		if (ret != 0)
 			goto base_error;
 	}
-- 
1.8.0

  parent reply	other threads:[~2014-07-01 20:13 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-07-01 20:13 [PATCH 0/4] ASoC: Aux dev initialization cleanup Lars-Peter Clausen
2014-07-01 20:13 ` [PATCH 1/4] ASoC: Remove duplicated rtd->codec initialization Lars-Peter Clausen
2014-07-01 20:13 ` [PATCH 2/4] ASoC: Replace soc_find_matching_codec() with soc_find_codec() Lars-Peter Clausen
2014-07-01 20:13 ` Lars-Peter Clausen [this message]
2014-07-01 20:13 ` [PATCH 4/4] ASoC: Move non-shared code paths out of snd_soc_post_component_init() Lars-Peter Clausen
2014-07-02 20:24 ` [PATCH 0/4] ASoC: Aux dev initialization cleanup Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1404245628-30877-4-git-send-email-lars@metafoo.de \
    --to=lars@metafoo.de \
    --cc=alsa-devel@alsa-project.org \
    --cc=bcousson@baylibre.com \
    --cc=broonie@kernel.org \
    --cc=lgirdwood@gmail.com \
    --cc=sre@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.