diff options
author | Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> | 2019-03-20 00:56:26 -0400 |
---|---|---|
committer | Mark Brown <broonie@kernel.org> | 2019-03-21 10:52:24 -0400 |
commit | 65a5056b21202eff7f54243e587183f4bb6ed352 (patch) | |
tree | 7e28f41ca4b7a8af17b743aaddb2652554e34420 /sound/soc/generic | |
parent | 629f75440a68220a78aef9d8569831824890c47d (diff) |
ASoC: simple-card-utils: share asoc_simple_card_init_priv()
The difference between simple-card / audio-graph are just using
OF graph style, or not. In other words, other things should be same.
This means, simple-card/audio-graph common functions should be
implemented at simple-card-utils, and its own functions should be
implemented at each files.
Current simple-card / audio-graph are initializing each priv,
but it is same operation.
This patch adds new asoc_simple_card_init_priv() and initialize
priv by same operation.
Signed-off-by: Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
Signed-off-by: Mark Brown <broonie@kernel.org>
Diffstat (limited to 'sound/soc/generic')
-rw-r--r-- | sound/soc/generic/audio-graph-card.c | 45 | ||||
-rw-r--r-- | sound/soc/generic/simple-card-utils.c | 49 | ||||
-rw-r--r-- | sound/soc/generic/simple-card.c | 56 |
3 files changed, 64 insertions, 86 deletions
diff --git a/sound/soc/generic/audio-graph-card.c b/sound/soc/generic/audio-graph-card.c index 605126fb2810..b9a93379098d 100644 --- a/sound/soc/generic/audio-graph-card.c +++ b/sound/soc/generic/audio-graph-card.c | |||
@@ -20,13 +20,6 @@ | |||
20 | #include <linux/string.h> | 20 | #include <linux/string.h> |
21 | #include <sound/simple_card_utils.h> | 21 | #include <sound/simple_card_utils.h> |
22 | 22 | ||
23 | struct link_info { | ||
24 | int dais; /* number of dai */ | ||
25 | int link; /* number of link */ | ||
26 | int conf; /* number of codec_conf */ | ||
27 | int cpu; /* turn for CPU / Codec */ | ||
28 | }; | ||
29 | |||
30 | #define PREFIX "audio-graph-card," | 23 | #define PREFIX "audio-graph-card," |
31 | 24 | ||
32 | static int graph_outdrv_event(struct snd_soc_dapm_widget *w, | 25 | static int graph_outdrv_event(struct snd_soc_dapm_widget *w, |
@@ -526,14 +519,10 @@ static int graph_card_probe(struct snd_soc_card *card) | |||
526 | static int graph_probe(struct platform_device *pdev) | 519 | static int graph_probe(struct platform_device *pdev) |
527 | { | 520 | { |
528 | struct asoc_simple_priv *priv; | 521 | struct asoc_simple_priv *priv; |
529 | struct snd_soc_dai_link *dai_link; | ||
530 | struct simple_dai_props *dai_props; | ||
531 | struct asoc_simple_dai *dais; | ||
532 | struct device *dev = &pdev->dev; | 522 | struct device *dev = &pdev->dev; |
533 | struct snd_soc_card *card; | 523 | struct snd_soc_card *card; |
534 | struct snd_soc_codec_conf *cconf; | ||
535 | struct link_info li; | 524 | struct link_info li; |
536 | int ret, i; | 525 | int ret; |
537 | 526 | ||
538 | /* Allocate the private data and the DAI link array */ | 527 | /* Allocate the private data and the DAI link array */ |
539 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | 528 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
@@ -552,25 +541,9 @@ static int graph_probe(struct platform_device *pdev) | |||
552 | if (!li.link || !li.dais) | 541 | if (!li.link || !li.dais) |
553 | return -EINVAL; | 542 | return -EINVAL; |
554 | 543 | ||
555 | dai_props = devm_kcalloc(dev, li.link, sizeof(*dai_props), GFP_KERNEL); | 544 | ret = asoc_simple_card_init_priv(priv, &li); |
556 | dai_link = devm_kcalloc(dev, li.link, sizeof(*dai_link), GFP_KERNEL); | 545 | if (ret < 0) |
557 | dais = devm_kcalloc(dev, li.dais, sizeof(*dais), GFP_KERNEL); | 546 | return ret; |
558 | cconf = devm_kcalloc(dev, li.conf, sizeof(*cconf), GFP_KERNEL); | ||
559 | if (!dai_props || !dai_link || !dais) | ||
560 | return -ENOMEM; | ||
561 | |||
562 | /* | ||
563 | * Use snd_soc_dai_link_component instead of legacy style | ||
564 | * It is codec only. but cpu/platform will be supported in the future. | ||
565 | * see | ||
566 | * soc-core.c :: snd_soc_init_multicodec() | ||
567 | */ | ||
568 | for (i = 0; i < li.link; i++) { | ||
569 | dai_link[i].codecs = &dai_props[i].codecs; | ||
570 | dai_link[i].num_codecs = 1; | ||
571 | dai_link[i].platforms = &dai_props[i].platforms; | ||
572 | dai_link[i].num_platforms = 1; | ||
573 | } | ||
574 | 547 | ||
575 | priv->pa_gpio = devm_gpiod_get_optional(dev, "pa", GPIOD_OUT_LOW); | 548 | priv->pa_gpio = devm_gpiod_get_optional(dev, "pa", GPIOD_OUT_LOW); |
576 | if (IS_ERR(priv->pa_gpio)) { | 549 | if (IS_ERR(priv->pa_gpio)) { |
@@ -579,16 +552,6 @@ static int graph_probe(struct platform_device *pdev) | |||
579 | return ret; | 552 | return ret; |
580 | } | 553 | } |
581 | 554 | ||
582 | priv->dai_props = dai_props; | ||
583 | priv->dai_link = dai_link; | ||
584 | priv->dais = dais; | ||
585 | priv->codec_conf = cconf; | ||
586 | |||
587 | card->dai_link = dai_link; | ||
588 | card->num_links = li.link; | ||
589 | card->codec_conf = cconf; | ||
590 | card->num_configs = li.conf; | ||
591 | |||
592 | ret = graph_parse_of(priv); | 555 | ret = graph_parse_of(priv); |
593 | if (ret < 0) { | 556 | if (ret < 0) { |
594 | if (ret != -EPROBE_DEFER) | 557 | if (ret != -EPROBE_DEFER) |
diff --git a/sound/soc/generic/simple-card-utils.c b/sound/soc/generic/simple-card-utils.c index ec4a010400a0..697e820bee18 100644 --- a/sound/soc/generic/simple-card-utils.c +++ b/sound/soc/generic/simple-card-utils.c | |||
@@ -630,6 +630,55 @@ int asoc_simple_card_init_jack(struct snd_soc_card *card, | |||
630 | } | 630 | } |
631 | EXPORT_SYMBOL_GPL(asoc_simple_card_init_jack); | 631 | EXPORT_SYMBOL_GPL(asoc_simple_card_init_jack); |
632 | 632 | ||
633 | int asoc_simple_card_init_priv(struct asoc_simple_priv *priv, | ||
634 | struct link_info *li) | ||
635 | { | ||
636 | struct snd_soc_card *card = simple_priv_to_card(priv); | ||
637 | struct device *dev = simple_priv_to_dev(priv); | ||
638 | struct snd_soc_dai_link *dai_link; | ||
639 | struct simple_dai_props *dai_props; | ||
640 | struct asoc_simple_dai *dais; | ||
641 | struct snd_soc_codec_conf *cconf; | ||
642 | int i; | ||
643 | |||
644 | dai_props = devm_kcalloc(dev, li->link, sizeof(*dai_props), GFP_KERNEL); | ||
645 | dai_link = devm_kcalloc(dev, li->link, sizeof(*dai_link), GFP_KERNEL); | ||
646 | dais = devm_kcalloc(dev, li->dais, sizeof(*dais), GFP_KERNEL); | ||
647 | cconf = devm_kcalloc(dev, li->conf, sizeof(*cconf), GFP_KERNEL); | ||
648 | if (!dai_props || !dai_link || !dais) | ||
649 | return -ENOMEM; | ||
650 | |||
651 | /* | ||
652 | * Use snd_soc_dai_link_component instead of legacy style | ||
653 | * It is codec only. but cpu/platform will be supported in the future. | ||
654 | * see | ||
655 | * soc-core.c :: snd_soc_init_multicodec() | ||
656 | * | ||
657 | * "platform" might be removed | ||
658 | * see | ||
659 | * simple-card-utils.c :: asoc_simple_card_canonicalize_platform() | ||
660 | */ | ||
661 | for (i = 0; i < li->link; i++) { | ||
662 | dai_link[i].codecs = &dai_props[i].codecs; | ||
663 | dai_link[i].num_codecs = 1; | ||
664 | dai_link[i].platforms = &dai_props[i].platforms; | ||
665 | dai_link[i].num_platforms = 1; | ||
666 | } | ||
667 | |||
668 | priv->dai_props = dai_props; | ||
669 | priv->dai_link = dai_link; | ||
670 | priv->dais = dais; | ||
671 | priv->codec_conf = cconf; | ||
672 | |||
673 | card->dai_link = priv->dai_link; | ||
674 | card->num_links = li->link; | ||
675 | card->codec_conf = cconf; | ||
676 | card->num_configs = li->conf; | ||
677 | |||
678 | return 0; | ||
679 | } | ||
680 | EXPORT_SYMBOL_GPL(asoc_simple_init_priv); | ||
681 | |||
633 | /* Module information */ | 682 | /* Module information */ |
634 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); | 683 | MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>"); |
635 | MODULE_DESCRIPTION("ALSA SoC Simple Card Utils"); | 684 | MODULE_DESCRIPTION("ALSA SoC Simple Card Utils"); |
diff --git a/sound/soc/generic/simple-card.c b/sound/soc/generic/simple-card.c index 60a88a55c071..4e3e6b34593c 100644 --- a/sound/soc/generic/simple-card.c +++ b/sound/soc/generic/simple-card.c | |||
@@ -15,13 +15,6 @@ | |||
15 | #include <sound/soc-dai.h> | 15 | #include <sound/soc-dai.h> |
16 | #include <sound/soc.h> | 16 | #include <sound/soc.h> |
17 | 17 | ||
18 | struct link_info { | ||
19 | int dais; /* number of dai */ | ||
20 | int link; /* number of link */ | ||
21 | int conf; /* number of codec_conf */ | ||
22 | int cpu; /* turn for CPU / Codec */ | ||
23 | }; | ||
24 | |||
25 | #define DAI "sound-dai" | 18 | #define DAI "sound-dai" |
26 | #define CELL "#sound-dai-cells" | 19 | #define CELL "#sound-dai-cells" |
27 | #define PREFIX "simple-audio-card," | 20 | #define PREFIX "simple-audio-card," |
@@ -564,15 +557,11 @@ static int simple_soc_probe(struct snd_soc_card *card) | |||
564 | static int simple_probe(struct platform_device *pdev) | 557 | static int simple_probe(struct platform_device *pdev) |
565 | { | 558 | { |
566 | struct asoc_simple_priv *priv; | 559 | struct asoc_simple_priv *priv; |
567 | struct snd_soc_dai_link *dai_link; | ||
568 | struct simple_dai_props *dai_props; | ||
569 | struct asoc_simple_dai *dais; | ||
570 | struct device *dev = &pdev->dev; | 560 | struct device *dev = &pdev->dev; |
571 | struct device_node *np = dev->of_node; | 561 | struct device_node *np = dev->of_node; |
572 | struct snd_soc_card *card; | 562 | struct snd_soc_card *card; |
573 | struct snd_soc_codec_conf *cconf; | ||
574 | struct link_info li; | 563 | struct link_info li; |
575 | int ret, i; | 564 | int ret; |
576 | 565 | ||
577 | /* Allocate the private data and the DAI link array */ | 566 | /* Allocate the private data and the DAI link array */ |
578 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); | 567 | priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL); |
@@ -589,35 +578,9 @@ static int simple_probe(struct platform_device *pdev) | |||
589 | if (!li.link || !li.dais) | 578 | if (!li.link || !li.dais) |
590 | return -EINVAL; | 579 | return -EINVAL; |
591 | 580 | ||
592 | dai_props = devm_kcalloc(dev, li.link, sizeof(*dai_props), GFP_KERNEL); | 581 | ret = asoc_simple_card_init_priv(priv, &li); |
593 | dai_link = devm_kcalloc(dev, li.link, sizeof(*dai_link), GFP_KERNEL); | 582 | if (ret < 0) |
594 | dais = devm_kcalloc(dev, li.dais, sizeof(*dais), GFP_KERNEL); | 583 | return ret; |
595 | cconf = devm_kcalloc(dev, li.conf, sizeof(*cconf), GFP_KERNEL); | ||
596 | if (!dai_props || !dai_link || !dais) | ||
597 | return -ENOMEM; | ||
598 | |||
599 | /* | ||
600 | * Use snd_soc_dai_link_component instead of legacy style | ||
601 | * It is codec only. but cpu/platform will be supported in the future. | ||
602 | * see | ||
603 | * soc-core.c :: snd_soc_init_multicodec() | ||
604 | */ | ||
605 | for (i = 0; i < li.link; i++) { | ||
606 | dai_link[i].codecs = &dai_props[i].codecs; | ||
607 | dai_link[i].num_codecs = 1; | ||
608 | dai_link[i].platforms = &dai_props[i].platforms; | ||
609 | dai_link[i].num_platforms = 1; | ||
610 | } | ||
611 | |||
612 | priv->dai_props = dai_props; | ||
613 | priv->dai_link = dai_link; | ||
614 | priv->dais = dais; | ||
615 | priv->codec_conf = cconf; | ||
616 | |||
617 | card->dai_link = priv->dai_link; | ||
618 | card->num_links = li.link; | ||
619 | card->codec_conf = cconf; | ||
620 | card->num_configs = li.conf; | ||
621 | 584 | ||
622 | if (np && of_device_is_available(np)) { | 585 | if (np && of_device_is_available(np)) { |
623 | 586 | ||
@@ -632,6 +595,9 @@ static int simple_probe(struct platform_device *pdev) | |||
632 | struct asoc_simple_card_info *cinfo; | 595 | struct asoc_simple_card_info *cinfo; |
633 | struct snd_soc_dai_link_component *codecs; | 596 | struct snd_soc_dai_link_component *codecs; |
634 | struct snd_soc_dai_link_component *platform; | 597 | struct snd_soc_dai_link_component *platform; |
598 | struct snd_soc_dai_link *dai_link = priv->dai_link; | ||
599 | struct simple_dai_props *dai_props = priv->dai_props; | ||
600 | |||
635 | int dai_idx = 0; | 601 | int dai_idx = 0; |
636 | 602 | ||
637 | cinfo = dev->platform_data; | 603 | cinfo = dev->platform_data; |
@@ -665,10 +631,10 @@ static int simple_probe(struct platform_device *pdev) | |||
665 | dai_link->cpu_dai_name = cinfo->cpu_dai.name; | 631 | dai_link->cpu_dai_name = cinfo->cpu_dai.name; |
666 | dai_link->dai_fmt = cinfo->daifmt; | 632 | dai_link->dai_fmt = cinfo->daifmt; |
667 | dai_link->init = asoc_simple_dai_init; | 633 | dai_link->init = asoc_simple_dai_init; |
668 | memcpy(priv->dai_props->cpu_dai, &cinfo->cpu_dai, | 634 | memcpy(dai_props->cpu_dai, &cinfo->cpu_dai, |
669 | sizeof(*priv->dai_props->cpu_dai)); | 635 | sizeof(*dai_props->cpu_dai)); |
670 | memcpy(priv->dai_props->codec_dai, &cinfo->codec_dai, | 636 | memcpy(dai_props->codec_dai, &cinfo->codec_dai, |
671 | sizeof(*priv->dai_props->codec_dai)); | 637 | sizeof(*dai_props->codec_dai)); |
672 | } | 638 | } |
673 | 639 | ||
674 | snd_soc_card_set_drvdata(card, priv); | 640 | snd_soc_card_set_drvdata(card, priv); |