ASoC: core - improve probe/remove ordering

To be SQUASHED

Signed-off-by: Liam Girdwood <lrg@ti.com>
diff --git a/include/sound/soc-dai.h b/include/sound/soc-dai.h
index 3082c4e..bda171e 100644
--- a/include/sound/soc-dai.h
+++ b/include/sound/soc-dai.h
@@ -213,8 +213,8 @@
 	unsigned int symmetric_rates:1;
 
 	/* probe ordering - for components with runtime dependencies */
-	bool late_probe;
-	bool early_remove;
+	int probe_order;
+	int remove_order;
 };
 
 /*
diff --git a/include/sound/soc.h b/include/sound/soc.h
index 1885104..5b5de41 100644
--- a/include/sound/soc.h
+++ b/include/sound/soc.h
@@ -202,6 +202,15 @@
 #define SOC_VALUE_ENUM_SINGLE_DECL(name, xreg, xshift, xmask, xtexts, xvalues) \
 	SOC_VALUE_ENUM_DOUBLE_DECL(name, xreg, xshift, xshift, xmask, xtexts, xvalues)
 
+/*
+ * Component probe and remove ordering levels for components with runtime
+ * dependencies.
+ */
+#define SND_SOC_COMP_ORDER_FIRST		-2
+#define SND_SOC_COMP_ORDER_EARLY		-1
+#define SND_SOC_COMP_ORDER_NORMAL		0
+#define SND_SOC_COMP_ORDER_LATE		1
+#define SND_SOC_COMP_ORDER_LAST		2
 
 /* DAI Link Host Mode Support */
 #define SND_SOC_DAI_LINK_NO_HOST		0x1
@@ -640,8 +649,8 @@
 			     enum snd_soc_dapm_type, int);
 
 	/* probe ordering - for components with runtime dependencies */
-	bool late_probe;
-	bool early_remove;
+	int probe_order;
+	int remove_order;
 
 	/* codec stream completion event */
 	int (*stream_event)(struct snd_soc_dapm_context *dapm);
@@ -670,8 +679,8 @@
 	struct snd_pcm_ops *ops;
 
 	/* probe ordering - for components with runtime dependencies */
-	bool late_probe;
-	bool early_remove;
+	int probe_order;
+	int remove_order;
 
 	int (*stream_event)(struct snd_soc_dapm_context *dapm);
 	int (*bespoke_trigger)(struct snd_pcm_substream *, int);
diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
index 2deebdd..92f96d3 100644
--- a/sound/soc/soc-core.c
+++ b/sound/soc/soc-core.c
@@ -1547,7 +1547,7 @@
 	module_put(codec->dev->driver->owner);
 }
 
-static void soc_remove_dai_link(struct snd_soc_card *card, int num, int early)
+static void soc_remove_dai_link(struct snd_soc_card *card, int num, int order)
 {
 	struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
 	struct snd_soc_codec *codec = rtd->codec;
@@ -1565,7 +1565,7 @@
 
 	/* remove the CODEC DAI */
 	if (codec_dai && codec_dai->probed &&
-			codec_dai->driver->early_remove == early) {
+			codec_dai->driver->remove_order == order) {
 		if (codec_dai->driver->remove) {
 			err = codec_dai->driver->remove(codec_dai);
 			if (err < 0)
@@ -1578,7 +1578,7 @@
 
 	/* remove the platform */
 	if (platform && platform->probed &&
-			platform->driver->early_remove == early) {
+			platform->driver->remove_order == order) {
 		if (platform->driver->remove) {
 			err = platform->driver->remove(platform);
 			if (err < 0)
@@ -1591,12 +1591,12 @@
 
 	/* remove the CODEC */
 	if (codec && codec->probed &&
-			codec->driver->early_remove == early)
+			codec->driver->remove_order == order)
 		soc_remove_codec(codec);
 
 	/* remove the cpu_dai */
 	if (cpu_dai && cpu_dai->probed &&
-			cpu_dai->driver->early_remove == early) {
+			cpu_dai->driver->remove_order == order) {
 		if (cpu_dai->driver->remove) {
 			err = cpu_dai->driver->remove(cpu_dai);
 			if (err < 0)
@@ -1610,13 +1610,13 @@
 
 static void soc_remove_dai_links(struct snd_soc_card *card)
 {
-	int i;
+	int dai, order;
 
-	for (i = 0; i < card->num_rtd; i++)
-			soc_remove_dai_link(card, i, 1); /* early remove */
-	for (i = 0; i < card->num_rtd; i++)
-		soc_remove_dai_link(card, i, 0); /* late remove */
-
+	for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
+			order++) {
+		for (dai = 0; dai < card->num_rtd; dai++)
+			soc_remove_dai_link(card, dai, order);
+	}
 	card->num_rtd = 0;
 }
 
@@ -1773,7 +1773,7 @@
 	return 0;
 }
 
-static int soc_probe_dai_link(struct snd_soc_card *card, int num, int late)
+static int soc_probe_dai_link(struct snd_soc_card *card, int num, int order)
 {
 	struct snd_soc_dai_link *dai_link = &card->dai_link[num];
 	struct snd_soc_pcm_runtime *rtd = &card->rtd[num];
@@ -1782,7 +1782,8 @@
 	struct snd_soc_dai *codec_dai = rtd->codec_dai, *cpu_dai = rtd->cpu_dai;
 	int ret;
 
-	dev_dbg(card->dev, "probe %s dai link %d late %d\n", card->name, num, late);
+	dev_dbg(card->dev, "probe %s dai link %d late %d\n",
+			card->name, num, order);
 
 	/* config components */
 	codec_dai->codec = codec;
@@ -1796,7 +1797,7 @@
 
 	/* probe the cpu_dai */
 	if (!cpu_dai->probed &&
-			cpu_dai->driver->late_probe == late) {
+			cpu_dai->driver->probe_order == order) {
 		if (!try_module_get(cpu_dai->dev->driver->owner))
 			return -ENODEV;
 
@@ -1816,7 +1817,7 @@
 
 	/* probe the CODEC */
 	if (!codec->probed &&
-			codec->driver->late_probe == late) {
+			codec->driver->probe_order == order) {
 		ret = soc_probe_codec(card, codec);
 		if (ret < 0)
 			return ret;
@@ -1824,7 +1825,7 @@
 
 	/* probe the platform */
 	if (!platform->probed &&
-			platform->driver->late_probe == late) {
+			platform->driver->probe_order == order) {
 		if (!try_module_get(platform->dev->driver->owner))
 			return -ENODEV;
 
@@ -1844,7 +1845,7 @@
 	}
 
 	/* probe the CODEC DAI */
-	if (!codec_dai->probed && codec_dai->driver->late_probe == late) {
+	if (!codec_dai->probed && codec_dai->driver->probe_order == order) {
 		if (!try_module_get(codec_dai->dev->driver->owner))
 			return -ENODEV;
 		if (codec_dai->driver->probe) {
@@ -1862,8 +1863,8 @@
 		list_add(&codec_dai->card_list, &card->dai_dev_list);
 	}
 
-	/* complete DAI probe during late probe */
-	if (!late)
+	/* complete DAI probe during last probe */
+	if (order != SND_SOC_COMP_ORDER_LAST)
 		return 0;
 
 	/* DAPM dai link stream work */
@@ -2006,7 +2007,7 @@
 	struct snd_soc_codec *codec;
 	struct snd_soc_codec_conf *codec_conf;
 	enum snd_soc_compress_type compress_type;
-	int ret, i;
+	int ret, i, order;
 
 	mutex_lock(&card->mutex);
 
@@ -2085,21 +2086,15 @@
 	}
 
 	/* early DAI link probe */
-	for (i = 0; i < card->num_links; i++) {
-		ret = soc_probe_dai_link(card, i, 0);
-		if (ret < 0) {
-			pr_err("asoc: failed to instantiate card %s: %d\n",
+	for (order = SND_SOC_COMP_ORDER_FIRST; order <= SND_SOC_COMP_ORDER_LAST;
+			order++) {
+		for (i = 0; i < card->num_links; i++) {
+			ret = soc_probe_dai_link(card, i, order);
+			if (ret < 0) {
+				pr_err("asoc: failed to instantiate card %s: %d\n",
 			       card->name, ret);
-			goto probe_dai_err;
-		}
-	}
-	/* late DAI link probe */
-	for (i = 0; i < card->num_links; i++) {
-		ret = soc_probe_dai_link(card, i, 1);
-		if (ret < 0) {
-			pr_err("asoc: failed to instantiate card %s: %d\n",
-			       card->name, ret);
-			goto probe_dai_err;
+				goto probe_dai_err;
+			}
 		}
 	}