Commit 17029e49 authored by Kuninori Morimoto's avatar Kuninori Morimoto Committed by Mark Brown

ASoC: simple-card: add link_info

Current simple-card is parsing DAI link for both "normal sound" and
"DPCM sound". On this driver, it needs to count and parse
DAIs/Links/Codec Conf from each links.
Then, counting/parsing link loop are very similar, but using different
implementation. Because of this background, the link loop code is very
mysterious. Mystery code will be trouble in the future.

To preparing cleanup code, this patch adds link_info which handles
number of DAIs/Links/Codec Conf, and CPU/Codec turn.
Signed-off-by: default avatarKuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: default avatarMark Brown <broonie@kernel.org>
parent 7adee60e
...@@ -33,6 +33,13 @@ struct simple_card_data { ...@@ -33,6 +33,13 @@ struct simple_card_data {
struct snd_soc_codec_conf *codec_conf; struct snd_soc_codec_conf *codec_conf;
}; };
struct link_info {
int dais; /* number of dai */
int link; /* number of link */
int conf; /* number of codec_conf */
int cpu; /* turn for CPU / Codec */
};
#define simple_priv_to_card(priv) (&(priv)->snd_card) #define simple_priv_to_card(priv) (&(priv)->snd_card)
#define simple_priv_to_props(priv, i) ((priv)->dai_props + (i)) #define simple_priv_to_props(priv, i) ((priv)->dai_props + (i))
#define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev) #define simple_priv_to_dev(priv) (simple_priv_to_card(priv)->dev)
...@@ -185,25 +192,27 @@ static int asoc_simple_card_dai_link_of_dpcm(struct device_node *top, ...@@ -185,25 +192,27 @@ static int asoc_simple_card_dai_link_of_dpcm(struct device_node *top,
struct device_node *np, struct device_node *np,
struct device_node *codec, struct device_node *codec,
struct simple_card_data *priv, struct simple_card_data *priv,
int *dai_idx, int link_idx, struct link_info *li,
int *conf_idx, int is_fe,
bool is_top_level_node) bool is_top_level_node)
{ {
struct device *dev = simple_priv_to_dev(priv); struct device *dev = simple_priv_to_dev(priv);
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, link_idx); struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
struct simple_dai_props *dai_props = simple_priv_to_props(priv, link_idx); struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
struct asoc_simple_dai *dai; struct asoc_simple_dai *dai;
struct snd_soc_dai_link_component *codecs = dai_link->codecs; struct snd_soc_dai_link_component *codecs = dai_link->codecs;
char prop[128]; char prop[128];
char *prefix = ""; char *prefix = "";
int ret; int ret;
dev_dbg(dev, "link_of DPCM (%pOF)\n", np);
li->link++;
/* For single DAI link & old style of DT node */ /* For single DAI link & old style of DT node */
if (is_top_level_node) if (is_top_level_node)
prefix = PREFIX; prefix = PREFIX;
if (is_fe) { if (np != codec) {
int is_single_links = 0; int is_single_links = 0;
/* BE is dummy */ /* BE is dummy */
...@@ -216,7 +225,7 @@ static int asoc_simple_card_dai_link_of_dpcm(struct device_node *top, ...@@ -216,7 +225,7 @@ static int asoc_simple_card_dai_link_of_dpcm(struct device_node *top,
dai_link->dpcm_merged_format = 1; dai_link->dpcm_merged_format = 1;
dai = dai =
dai_props->cpu_dai = &priv->dais[(*dai_idx)++]; dai_props->cpu_dai = &priv->dais[li->dais++];
ret = asoc_simple_card_parse_cpu(np, dai_link, DAI, CELL, ret = asoc_simple_card_parse_cpu(np, dai_link, DAI, CELL,
&is_single_links); &is_single_links);
...@@ -247,10 +256,10 @@ static int asoc_simple_card_dai_link_of_dpcm(struct device_node *top, ...@@ -247,10 +256,10 @@ static int asoc_simple_card_dai_link_of_dpcm(struct device_node *top,
dai_link->be_hw_params_fixup = asoc_simple_card_be_hw_params_fixup; dai_link->be_hw_params_fixup = asoc_simple_card_be_hw_params_fixup;
dai = dai =
dai_props->codec_dai = &priv->dais[(*dai_idx)++]; dai_props->codec_dai = &priv->dais[li->dais++];
cconf = cconf =
dai_props->codec_conf = &priv->codec_conf[(*conf_idx)++]; dai_props->codec_conf = &priv->codec_conf[li->conf++];
ret = asoc_simple_card_parse_codec(np, dai_link, DAI, CELL); ret = asoc_simple_card_parse_codec(np, dai_link, DAI, CELL);
if (ret < 0) if (ret < 0)
...@@ -306,12 +315,12 @@ static int asoc_simple_card_dai_link_of_dpcm(struct device_node *top, ...@@ -306,12 +315,12 @@ static int asoc_simple_card_dai_link_of_dpcm(struct device_node *top,
static int asoc_simple_card_dai_link_of(struct device_node *top, static int asoc_simple_card_dai_link_of(struct device_node *top,
struct device_node *node, struct device_node *node,
struct simple_card_data *priv, struct simple_card_data *priv,
int *dai_idx, int link_idx, struct link_info *li,
bool is_top_level_node) bool is_top_level_node)
{ {
struct device *dev = simple_priv_to_dev(priv); struct device *dev = simple_priv_to_dev(priv);
struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, link_idx); struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
struct simple_dai_props *dai_props = simple_priv_to_props(priv, link_idx); struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
struct asoc_simple_dai *cpu_dai; struct asoc_simple_dai *cpu_dai;
struct asoc_simple_dai *codec_dai; struct asoc_simple_dai *codec_dai;
struct device_node *cpu = NULL; struct device_node *cpu = NULL;
...@@ -321,6 +330,10 @@ static int asoc_simple_card_dai_link_of(struct device_node *top, ...@@ -321,6 +330,10 @@ static int asoc_simple_card_dai_link_of(struct device_node *top,
char *prefix = ""; char *prefix = "";
int ret, single_cpu; int ret, single_cpu;
li->link++;
dev_dbg(dev, "link_of (%pOF)\n", node);
/* For single DAI link & old style of DT node */ /* For single DAI link & old style of DT node */
if (is_top_level_node) if (is_top_level_node)
prefix = PREFIX; prefix = PREFIX;
...@@ -347,9 +360,9 @@ static int asoc_simple_card_dai_link_of(struct device_node *top, ...@@ -347,9 +360,9 @@ static int asoc_simple_card_dai_link_of(struct device_node *top,
} }
cpu_dai = cpu_dai =
dai_props->cpu_dai = &priv->dais[(*dai_idx)++]; dai_props->cpu_dai = &priv->dais[li->dais++];
codec_dai = codec_dai =
dai_props->codec_dai = &priv->dais[(*dai_idx)++]; dai_props->codec_dai = &priv->dais[li->dais++];
ret = asoc_simple_card_parse_daifmt(dev, node, codec, ret = asoc_simple_card_parse_daifmt(dev, node, codec,
prefix, &dai_link->dai_fmt); prefix, &dai_link->dai_fmt);
...@@ -454,9 +467,8 @@ static int asoc_simple_card_parse_of(struct simple_card_data *priv) ...@@ -454,9 +467,8 @@ static int asoc_simple_card_parse_of(struct simple_card_data *priv)
struct device_node *np; struct device_node *np;
struct device_node *codec; struct device_node *codec;
struct asoc_simple_card_data adata; struct asoc_simple_card_data adata;
bool is_fe; struct link_info li;
int ret, loop; int ret, loop;
int dai_idx, link_idx, conf_idx;
if (!top) if (!top)
return -EINVAL; return -EINVAL;
...@@ -470,10 +482,8 @@ static int asoc_simple_card_parse_of(struct simple_card_data *priv) ...@@ -470,10 +482,8 @@ static int asoc_simple_card_parse_of(struct simple_card_data *priv)
return ret; return ret;
/* 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));
loop = 1; loop = 1;
link_idx = 0;
dai_idx = 0;
conf_idx = 0;
node = of_get_child_by_name(top, PREFIX "dai-link"); node = of_get_child_by_name(top, PREFIX "dai-link");
if (!node) { if (!node) {
node = dev->of_node; node = dev->of_node;
...@@ -495,19 +505,16 @@ static int asoc_simple_card_parse_of(struct simple_card_data *priv) ...@@ -495,19 +505,16 @@ static int asoc_simple_card_parse_of(struct simple_card_data *priv)
if (!codec) if (!codec)
return -ENODEV; return -ENODEV;
is_fe = (np != codec);
ret = asoc_simple_card_dai_link_of_dpcm( ret = asoc_simple_card_dai_link_of_dpcm(
top, node, np, codec, priv, top, node, np, codec, priv,
&dai_idx, link_idx++, &conf_idx, &li, !loop);
is_fe, !loop);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
} else { } else {
ret = asoc_simple_card_dai_link_of( ret = asoc_simple_card_dai_link_of(
top, node, priv, top, node, priv,
&dai_idx, link_idx++, !loop); &li, !loop);
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
...@@ -525,9 +532,7 @@ static int asoc_simple_card_parse_of(struct simple_card_data *priv) ...@@ -525,9 +532,7 @@ static int asoc_simple_card_parse_of(struct simple_card_data *priv)
} }
static void asoc_simple_card_get_dais_count(struct device *dev, static void asoc_simple_card_get_dais_count(struct device *dev,
int *link_num, struct link_info *li)
int *dais_num,
int *ccnf_num)
{ {
struct device_node *top = dev->of_node; struct device_node *top = dev->of_node;
struct device_node *node; struct device_node *node;
...@@ -583,9 +588,9 @@ static void asoc_simple_card_get_dais_count(struct device *dev, ...@@ -583,9 +588,9 @@ static void asoc_simple_card_get_dais_count(struct device *dev,
* => 1 ccnf = 1xdummy-Codec * => 1 ccnf = 1xdummy-Codec
*/ */
if (!top) { if (!top) {
(*link_num) = 1; li->link = 1;
(*dais_num) = 2; li->dais = 2;
(*ccnf_num) = 0; li->conf = 0;
return; return;
} }
...@@ -602,13 +607,13 @@ static void asoc_simple_card_get_dais_count(struct device *dev, ...@@ -602,13 +607,13 @@ static void asoc_simple_card_get_dais_count(struct device *dev,
asoc_simple_card_get_conversion(dev, np, &adata); asoc_simple_card_get_conversion(dev, np, &adata);
num = of_get_child_count(node); num = of_get_child_count(node);
(*dais_num) += num; li->dais += num;
if (num > 2 || if (num > 2 ||
adata.convert_rate || adata.convert_channels) { adata.convert_rate || adata.convert_channels) {
(*link_num) += num; li->link += num;
(*ccnf_num)++; li->conf++;
} else { } else {
(*link_num)++; li->link++;
} }
node = of_get_next_child(top, node); node = of_get_next_child(top, node);
} while (loop && node); } while (loop && node);
...@@ -640,7 +645,7 @@ static int asoc_simple_card_probe(struct platform_device *pdev) ...@@ -640,7 +645,7 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
struct device_node *np = dev->of_node; struct device_node *np = dev->of_node;
struct snd_soc_card *card; struct snd_soc_card *card;
struct snd_soc_codec_conf *cconf; struct snd_soc_codec_conf *cconf;
int lnum = 0, dnum = 0, cnum = 0; struct link_info li;
int ret, i; int ret, i;
/* Allocate the private data and the DAI link array */ /* Allocate the private data and the DAI link array */
...@@ -648,14 +653,15 @@ static int asoc_simple_card_probe(struct platform_device *pdev) ...@@ -648,14 +653,15 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
if (!priv) if (!priv)
return -ENOMEM; return -ENOMEM;
asoc_simple_card_get_dais_count(dev, &lnum, &dnum, &cnum); memset(&li, 0, sizeof(li));
if (!lnum || !dnum) asoc_simple_card_get_dais_count(dev, &li);
if (!li.link || !li.dais)
return -EINVAL; return -EINVAL;
dai_props = devm_kcalloc(dev, lnum, sizeof(*dai_props), GFP_KERNEL); dai_props = devm_kcalloc(dev, li.link, sizeof(*dai_props), GFP_KERNEL);
dai_link = devm_kcalloc(dev, lnum, sizeof(*dai_link), GFP_KERNEL); dai_link = devm_kcalloc(dev, li.link, sizeof(*dai_link), GFP_KERNEL);
dais = devm_kcalloc(dev, dnum, sizeof(*dais), GFP_KERNEL); dais = devm_kcalloc(dev, li.dais, sizeof(*dais), GFP_KERNEL);
cconf = devm_kcalloc(dev, cnum, sizeof(*cconf), GFP_KERNEL); cconf = devm_kcalloc(dev, li.conf, sizeof(*cconf), GFP_KERNEL);
if (!dai_props || !dai_link || !dais) if (!dai_props || !dai_link || !dais)
return -ENOMEM; return -ENOMEM;
...@@ -665,7 +671,7 @@ static int asoc_simple_card_probe(struct platform_device *pdev) ...@@ -665,7 +671,7 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
* see * see
* soc-core.c :: snd_soc_init_multicodec() * soc-core.c :: snd_soc_init_multicodec()
*/ */
for (i = 0; i < lnum; i++) { for (i = 0; i < li.link; i++) {
dai_link[i].codecs = &dai_props[i].codecs; dai_link[i].codecs = &dai_props[i].codecs;
dai_link[i].num_codecs = 1; dai_link[i].num_codecs = 1;
dai_link[i].platform = &dai_props[i].platform; dai_link[i].platform = &dai_props[i].platform;
...@@ -681,9 +687,9 @@ static int asoc_simple_card_probe(struct platform_device *pdev) ...@@ -681,9 +687,9 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
card->owner = THIS_MODULE; card->owner = THIS_MODULE;
card->dev = dev; card->dev = dev;
card->dai_link = priv->dai_link; card->dai_link = priv->dai_link;
card->num_links = lnum; card->num_links = li.link;
card->codec_conf = cconf; card->codec_conf = cconf;
card->num_configs = cnum; card->num_configs = li.conf;
card->probe = asoc_simple_soc_card_probe; card->probe = asoc_simple_soc_card_probe;
if (np && of_device_is_available(np)) { if (np && of_device_is_available(np)) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment