ASoC: add for_each_link_codecs() macro
ALSA SoC snd_soc_dai_link has snd_soc_dai_link_component array for codecs. To be more readable code, this patch adds new for_each_link_codecs() macro, and replace existing code to it. Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Mark Brown <broonie@kernel.org>
This commit is contained in:
parent
18d545bb25
commit
3db769f177
|
@ -978,6 +978,10 @@ struct snd_soc_dai_link {
|
||||||
struct list_head list; /* DAI link list of the soc card */
|
struct list_head list; /* DAI link list of the soc card */
|
||||||
struct snd_soc_dobj dobj; /* For topology */
|
struct snd_soc_dobj dobj; /* For topology */
|
||||||
};
|
};
|
||||||
|
#define for_each_link_codecs(link, i, codec) \
|
||||||
|
for ((i) = 0; \
|
||||||
|
((i) < link->num_codecs) && ((codec) = &link->codecs[i]); \
|
||||||
|
(i)++)
|
||||||
|
|
||||||
struct snd_soc_codec_conf {
|
struct snd_soc_codec_conf {
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -97,14 +97,15 @@ static void axg_card_clean_references(struct axg_card *priv)
|
||||||
{
|
{
|
||||||
struct snd_soc_card *card = &priv->card;
|
struct snd_soc_card *card = &priv->card;
|
||||||
struct snd_soc_dai_link *link;
|
struct snd_soc_dai_link *link;
|
||||||
|
struct snd_soc_dai_link_component *codec;
|
||||||
int i, j;
|
int i, j;
|
||||||
|
|
||||||
if (card->dai_link) {
|
if (card->dai_link) {
|
||||||
for (i = 0; i < card->num_links; i++) {
|
for (i = 0; i < card->num_links; i++) {
|
||||||
link = &card->dai_link[i];
|
link = &card->dai_link[i];
|
||||||
of_node_put(link->cpu_of_node);
|
of_node_put(link->cpu_of_node);
|
||||||
for (j = 0; j < link->num_codecs; j++)
|
for_each_link_codecs(link, j, codec)
|
||||||
of_node_put(link->codecs[j].of_node);
|
of_node_put(codec->of_node);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1071,6 +1071,7 @@ static int soc_init_dai_link(struct snd_soc_card *card,
|
||||||
struct snd_soc_dai_link *link)
|
struct snd_soc_dai_link *link)
|
||||||
{
|
{
|
||||||
int i, ret;
|
int i, ret;
|
||||||
|
struct snd_soc_dai_link_component *codec;
|
||||||
|
|
||||||
ret = snd_soc_init_platform(card, link);
|
ret = snd_soc_init_platform(card, link);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
|
@ -1084,19 +1085,19 @@ static int soc_init_dai_link(struct snd_soc_card *card,
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < link->num_codecs; i++) {
|
for_each_link_codecs(link, i, codec) {
|
||||||
/*
|
/*
|
||||||
* Codec must be specified by 1 of name or OF node,
|
* Codec must be specified by 1 of name or OF node,
|
||||||
* not both or neither.
|
* not both or neither.
|
||||||
*/
|
*/
|
||||||
if (!!link->codecs[i].name ==
|
if (!!codec->name ==
|
||||||
!!link->codecs[i].of_node) {
|
!!codec->of_node) {
|
||||||
dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
|
dev_err(card->dev, "ASoC: Neither/both codec name/of_node are set for %s\n",
|
||||||
link->name);
|
link->name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
/* Codec DAI name must be specified */
|
/* Codec DAI name must be specified */
|
||||||
if (!link->codecs[i].dai_name) {
|
if (!codec->dai_name) {
|
||||||
dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
|
dev_err(card->dev, "ASoC: codec_dai_name not set for %s\n",
|
||||||
link->name);
|
link->name);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -3796,10 +3797,10 @@ EXPORT_SYMBOL_GPL(snd_soc_of_get_dai_name);
|
||||||
*/
|
*/
|
||||||
void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link)
|
void snd_soc_of_put_dai_link_codecs(struct snd_soc_dai_link *dai_link)
|
||||||
{
|
{
|
||||||
struct snd_soc_dai_link_component *component = dai_link->codecs;
|
struct snd_soc_dai_link_component *component;
|
||||||
int index;
|
int index;
|
||||||
|
|
||||||
for (index = 0; index < dai_link->num_codecs; index++, component++) {
|
for_each_link_codecs(dai_link, index, component) {
|
||||||
if (!component->of_node)
|
if (!component->of_node)
|
||||||
break;
|
break;
|
||||||
of_node_put(component->of_node);
|
of_node_put(component->of_node);
|
||||||
|
@ -3851,9 +3852,7 @@ int snd_soc_of_get_dai_link_codecs(struct device *dev,
|
||||||
dai_link->num_codecs = num_codecs;
|
dai_link->num_codecs = num_codecs;
|
||||||
|
|
||||||
/* Parse the list */
|
/* Parse the list */
|
||||||
for (index = 0, component = dai_link->codecs;
|
for_each_link_codecs(dai_link, index, component) {
|
||||||
index < dai_link->num_codecs;
|
|
||||||
index++, component++) {
|
|
||||||
ret = of_parse_phandle_with_args(of_node, name,
|
ret = of_parse_phandle_with_args(of_node, name,
|
||||||
"#sound-dai-cells",
|
"#sound-dai-cells",
|
||||||
index, &args);
|
index, &args);
|
||||||
|
|
Loading…
Reference in New Issue