Skip to content

Commit b8d8f9a

Browse files
morimotobroonie
authored andcommitted
ASoC: simple-scu-card: care link / dai count
In DPCM case, it uses CPU-dummy / dummy-Codec dai links. If sound card is caring only DPCM, link count = dai count, but, if non DPCM case, link count != dai count. Now, we want to merge simple-card and simple-scu-card, then, we need to care both link / dai count more carefly This patch cares it, and prepare for merging simple card Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent da32d65 commit b8d8f9a

File tree

1 file changed

+83
-7
lines changed

1 file changed

+83
-7
lines changed

sound/soc/generic/simple-scu-card.c

Lines changed: 83 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -256,25 +256,101 @@ static int asoc_simple_card_parse_of(struct simple_card_data *priv)
256256
return 0;
257257
}
258258

259+
static void asoc_simple_card_get_dais_count(struct device *dev,
260+
int *link_num,
261+
int *dais_num,
262+
int *ccnf_num)
263+
{
264+
struct device_node *top = dev->of_node;
265+
struct device_node *node;
266+
int loop;
267+
int num;
268+
269+
/*
270+
* link_num : number of links.
271+
* CPU-Codec / CPU-dummy / dummy-Codec
272+
* dais_num : number of DAIs
273+
* ccnf_num : number of codec_conf
274+
* same number for "dummy-Codec"
275+
*
276+
* ex1)
277+
* CPU0 --- Codec0 link : 5
278+
* CPU1 --- Codec1 dais : 7
279+
* CPU2 -/ ccnf : 1
280+
* CPU3 --- Codec2
281+
*
282+
* => 5 links = 2xCPU-Codec + 2xCPU-dummy + 1xdummy-Codec
283+
* => 7 DAIs = 4xCPU + 3xCodec
284+
* => 1 ccnf = 1xdummy-Codec
285+
*
286+
* ex2)
287+
* CPU0 --- Codec0 link : 5
288+
* CPU1 --- Codec1 dais : 6
289+
* CPU2 -/ ccnf : 1
290+
* CPU3 -/
291+
*
292+
* => 5 links = 1xCPU-Codec + 3xCPU-dummy + 1xdummy-Codec
293+
* => 6 DAIs = 4xCPU + 2xCodec
294+
* => 1 ccnf = 1xdummy-Codec
295+
*
296+
* ex3)
297+
* CPU0 --- Codec0 link : 6
298+
* CPU1 -/ dais : 6
299+
* CPU2 --- Codec1 ccnf : 2
300+
* CPU3 -/
301+
*
302+
* => 6 links = 0xCPU-Codec + 4xCPU-dummy + 2xdummy-Codec
303+
* => 6 DAIs = 4xCPU + 2xCodec
304+
* => 2 ccnf = 2xdummy-Codec
305+
*/
306+
if (!top) {
307+
(*link_num) = 1;
308+
(*dais_num) = 2;
309+
(*ccnf_num) = 0;
310+
return;
311+
}
312+
313+
loop = 1;
314+
node = of_get_child_by_name(top, PREFIX "dai-link");
315+
if (!node) {
316+
node = top;
317+
loop = 0;
318+
}
319+
320+
do {
321+
num = of_get_child_count(node);
322+
(*dais_num) += num;
323+
if (num > 2) {
324+
(*link_num) += num;
325+
(*ccnf_num)++;
326+
} else {
327+
(*link_num)++;
328+
}
329+
node = of_get_next_child(top, node);
330+
} while (loop && node);
331+
}
332+
259333
static int asoc_simple_card_probe(struct platform_device *pdev)
260334
{
261335
struct simple_card_data *priv;
262336
struct snd_soc_dai_link *dai_link;
263337
struct simple_dai_props *dai_props;
264338
struct snd_soc_card *card;
265339
struct device *dev = &pdev->dev;
266-
struct device_node *np = dev->of_node;
267-
int num, ret, i;
340+
int ret, i;
341+
int lnum = 0, dnum = 0, cnum = 0;
268342

269343
/* Allocate the private data */
270344
priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
271345
if (!priv)
272346
return -ENOMEM;
273347

274-
num = of_get_child_count(np);
348+
asoc_simple_card_get_dais_count(dev, &lnum, &dnum, &cnum);
349+
if (!lnum || !dnum)
350+
return -EINVAL;
275351

276-
dai_props = devm_kcalloc(dev, num, sizeof(*dai_props), GFP_KERNEL);
277-
dai_link = devm_kcalloc(dev, num, sizeof(*dai_link), GFP_KERNEL);
352+
dai_props = devm_kcalloc(dev, lnum, sizeof(*dai_props), GFP_KERNEL);
353+
dai_link = devm_kcalloc(dev, lnum, sizeof(*dai_link), GFP_KERNEL);
278354
if (!dai_props || !dai_link)
279355
return -ENOMEM;
280356

@@ -284,7 +360,7 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
284360
* see
285361
* soc-core.c :: snd_soc_init_multicodec()
286362
*/
287-
for (i = 0; i < num; i++) {
363+
for (i = 0; i < lnum; i++) {
288364
dai_link[i].codecs = &dai_props[i].codecs;
289365
dai_link[i].num_codecs = 1;
290366
dai_link[i].platform = &dai_props[i].platform;
@@ -298,7 +374,7 @@ static int asoc_simple_card_probe(struct platform_device *pdev)
298374
card->owner = THIS_MODULE;
299375
card->dev = dev;
300376
card->dai_link = priv->dai_link;
301-
card->num_links = num;
377+
card->num_links = lnum;
302378
card->codec_conf = &priv->codec_conf;
303379
card->num_configs = 1;
304380

0 commit comments

Comments
 (0)