ASoC: simple-card: cleanup graph_for_each_link()
simple-card checks DT links 2 times. 1st is for counting DAIs / links to allocating memory, 2nd is for detecting DAIs. To detecting DAIs as CPU-dummy -> dummy-Codec order when DPCM case, it uses loops 2 times. Because of this kind of complex background, it needs to use local varuable for it, and each call-back functions need to care about it. Now, 1st and 2nd DT link check are using same order, thus we can share same code. This patch do it. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Link: https://lore.kernel.org/r/875z1e1tov.wl-kuninori.morimoto.gx@renesas.com Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
a6e8798061
commit
39af7f7a03
@ -129,15 +129,6 @@ static int simple_dai_link_of_dpcm(struct asoc_simple_priv *priv,
|
|||||||
char *prefix = "";
|
char *prefix = "";
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/*
|
|
||||||
* |CPU |Codec : turn
|
|
||||||
* CPU |Pass |return
|
|
||||||
* Codec |return|Pass
|
|
||||||
* np
|
|
||||||
*/
|
|
||||||
if (li->cpu == (np == codec))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
dev_dbg(dev, "link_of DPCM (%pOF)\n", np);
|
dev_dbg(dev, "link_of DPCM (%pOF)\n", np);
|
||||||
|
|
||||||
li->link++;
|
li->link++;
|
||||||
@ -260,15 +251,6 @@ static int simple_dai_link_of(struct asoc_simple_priv *priv,
|
|||||||
char *prefix = "";
|
char *prefix = "";
|
||||||
int ret, single_cpu;
|
int ret, single_cpu;
|
||||||
|
|
||||||
/*
|
|
||||||
* |CPU |Codec : turn
|
|
||||||
* CPU |Pass |return
|
|
||||||
* Codec |return|return
|
|
||||||
* np
|
|
||||||
*/
|
|
||||||
if (!li->cpu || np == codec)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
cpu = np;
|
cpu = np;
|
||||||
node = of_get_parent(np);
|
node = of_get_parent(np);
|
||||||
li->link++;
|
li->link++;
|
||||||
@ -342,7 +324,7 @@ dai_link_of_err:
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int simple_for_each_link(struct asoc_simple_priv *priv,
|
static int __simple_for_each_link(struct asoc_simple_priv *priv,
|
||||||
struct link_info *li,
|
struct link_info *li,
|
||||||
int (*func_noml)(struct asoc_simple_priv *priv,
|
int (*func_noml)(struct asoc_simple_priv *priv,
|
||||||
struct device_node *np,
|
struct device_node *np,
|
||||||
@ -402,11 +384,26 @@ static int simple_for_each_link(struct asoc_simple_priv *priv,
|
|||||||
*/
|
*/
|
||||||
if (dpcm_selectable &&
|
if (dpcm_selectable &&
|
||||||
(num > 2 ||
|
(num > 2 ||
|
||||||
adata.convert_rate || adata.convert_channels))
|
adata.convert_rate || adata.convert_channels)) {
|
||||||
ret = func_dpcm(priv, np, codec, li, is_top);
|
/*
|
||||||
|
* np
|
||||||
|
* |1(CPU)|0(Codec) li->cpu
|
||||||
|
* CPU |Pass |return
|
||||||
|
* Codec |return|Pass
|
||||||
|
*/
|
||||||
|
if (li->cpu != (np == codec))
|
||||||
|
ret = func_dpcm(priv, np, codec, li, is_top);
|
||||||
/* else normal sound */
|
/* else normal sound */
|
||||||
else
|
} else {
|
||||||
ret = func_noml(priv, np, codec, li, is_top);
|
/*
|
||||||
|
* np
|
||||||
|
* |1(CPU)|0(Codec) li->cpu
|
||||||
|
* CPU |Pass |return
|
||||||
|
* Codec |return|return
|
||||||
|
*/
|
||||||
|
if (li->cpu && (np != codec))
|
||||||
|
ret = func_noml(priv, np, codec, li, is_top);
|
||||||
|
}
|
||||||
|
|
||||||
if (ret < 0) {
|
if (ret < 0) {
|
||||||
of_node_put(codec);
|
of_node_put(codec);
|
||||||
@ -424,6 +421,39 @@ static int simple_for_each_link(struct asoc_simple_priv *priv,
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int simple_for_each_link(struct asoc_simple_priv *priv,
|
||||||
|
struct link_info *li,
|
||||||
|
int (*func_noml)(struct asoc_simple_priv *priv,
|
||||||
|
struct device_node *np,
|
||||||
|
struct device_node *codec,
|
||||||
|
struct link_info *li, bool is_top),
|
||||||
|
int (*func_dpcm)(struct asoc_simple_priv *priv,
|
||||||
|
struct device_node *np,
|
||||||
|
struct device_node *codec,
|
||||||
|
struct link_info *li, bool is_top))
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
/*
|
||||||
|
* Detect all CPU first, and Detect all Codec 2nd.
|
||||||
|
*
|
||||||
|
* In Normal sound case, all DAIs are detected
|
||||||
|
* as "CPU-Codec".
|
||||||
|
*
|
||||||
|
* In DPCM sound case,
|
||||||
|
* all CPUs are detected as "CPU-dummy", and
|
||||||
|
* all Codecs are detected as "dummy-Codec".
|
||||||
|
* To avoid random sub-device numbering,
|
||||||
|
* detect "dummy-Codec" in last;
|
||||||
|
*/
|
||||||
|
for (li->cpu = 1; li->cpu >= 0; li->cpu--) {
|
||||||
|
ret = __simple_for_each_link(priv, li, func_noml, func_dpcm);
|
||||||
|
if (ret < 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int simple_parse_of(struct asoc_simple_priv *priv)
|
static int simple_parse_of(struct asoc_simple_priv *priv)
|
||||||
{
|
{
|
||||||
struct device *dev = simple_priv_to_dev(priv);
|
struct device *dev = simple_priv_to_dev(priv);
|
||||||
@ -449,25 +479,11 @@ static int simple_parse_of(struct asoc_simple_priv *priv)
|
|||||||
|
|
||||||
/* Single/Muti DAI link(s) & New style of DT node */
|
/* Single/Muti DAI link(s) & New style of DT node */
|
||||||
memset(&li, 0, sizeof(li));
|
memset(&li, 0, sizeof(li));
|
||||||
for (li.cpu = 1; li.cpu >= 0; li.cpu--) {
|
ret = simple_for_each_link(priv, &li,
|
||||||
/*
|
simple_dai_link_of,
|
||||||
* Detect all CPU first, and Detect all Codec 2nd.
|
simple_dai_link_of_dpcm);
|
||||||
*
|
if (ret < 0)
|
||||||
* In Normal sound case, all DAIs are detected
|
return ret;
|
||||||
* as "CPU-Codec".
|
|
||||||
*
|
|
||||||
* In DPCM sound case,
|
|
||||||
* all CPUs are detected as "CPU-dummy", and
|
|
||||||
* all Codecs are detected as "dummy-Codec".
|
|
||||||
* To avoid random sub-device numbering,
|
|
||||||
* detect "dummy-Codec" in last;
|
|
||||||
*/
|
|
||||||
ret = simple_for_each_link(priv, &li,
|
|
||||||
simple_dai_link_of,
|
|
||||||
simple_dai_link_of_dpcm);
|
|
||||||
if (ret < 0)
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
ret = asoc_simple_parse_card_name(card, PREFIX);
|
ret = asoc_simple_parse_card_name(card, PREFIX);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
@ -483,15 +499,6 @@ static int simple_count_noml(struct asoc_simple_priv *priv,
|
|||||||
struct device_node *codec,
|
struct device_node *codec,
|
||||||
struct link_info *li, bool is_top)
|
struct link_info *li, bool is_top)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* |CPU |Codec : turn
|
|
||||||
* CPU |Pass |return
|
|
||||||
* Codec |return|return
|
|
||||||
* np
|
|
||||||
*/
|
|
||||||
if (!li->cpu || np == codec)
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
li->link += 1;
|
li->link += 1;
|
||||||
li->dais += 2;
|
li->dais += 2;
|
||||||
|
|
||||||
@ -503,15 +510,6 @@ static int simple_count_dpcm(struct asoc_simple_priv *priv,
|
|||||||
struct device_node *codec,
|
struct device_node *codec,
|
||||||
struct link_info *li, bool is_top)
|
struct link_info *li, bool is_top)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* |CPU |Codec : turn
|
|
||||||
* CPU |Pass |return
|
|
||||||
* Codec |return|Pass
|
|
||||||
* np
|
|
||||||
*/
|
|
||||||
if (li->cpu == (np == codec))
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
if (li->cpu) {
|
if (li->cpu) {
|
||||||
li->link++; /* CPU-dummy */
|
li->link++; /* CPU-dummy */
|
||||||
li->dais++;
|
li->dais++;
|
||||||
@ -583,10 +581,9 @@ static void simple_get_dais_count(struct asoc_simple_priv *priv,
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (li->cpu = 1; li->cpu >= 0; li->cpu--)
|
simple_for_each_link(priv, li,
|
||||||
simple_for_each_link(priv, li,
|
simple_count_noml,
|
||||||
simple_count_noml,
|
simple_count_dpcm);
|
||||||
simple_count_dpcm);
|
|
||||||
|
|
||||||
dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
|
dev_dbg(dev, "link %d, dais %d, ccnf %d\n",
|
||||||
li->link, li->dais, li->conf);
|
li->link, li->dais, li->conf);
|
||||||
|
Loading…
Reference in New Issue
Block a user