1 // SPDX-License-Identifier: GPL-2.0
3 // ASoC Audio Graph Card2 support
5 // Copyright (C) 2020 Renesas Electronics Corp.
6 // Copyright (C) 2020 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
8 // based on ${LINUX}/sound/soc/generic/audio-graph-card.c
10 #include <linux/device.h>
11 #include <linux/gpio.h>
12 #include <linux/gpio/consumer.h>
13 #include <linux/module.h>
15 #include <linux/of_device.h>
16 #include <linux/of_gpio.h>
17 #include <linux/of_graph.h>
18 #include <linux/platform_device.h>
19 #include <linux/string.h>
20 #include <sound/graph_card.h>
22 /************************************
24 ************************************
39 You can set daifmt at ports/port/endpoint.
40 It uses *latest* format, and *share* master settings.
42 sample0: left_j, bitclock-master, frame-master
43 sample1: i2s, bitclock-master
45 If there was no settings, *Codec* will be
46 bitclock/frame provider as default.
50 "format" property is no longer needed on DT if both CPU/Codec drivers are
51 supporting snd_soc_dai_ops :: .auto_selectable_formats.
53 snd_soc_runtime_get_dai_fmt()
56 linux/sound/soc/sh/rcar/core.c
57 linux/sound/soc/codecs/ak4613.c
58 linux/sound/soc/codecs/pcm3168a.c
59 linux/sound/soc/soc-utils.c
60 linux/sound/soc/generic/test-component.c
62 ************************************
64 ************************************
69 compatible = "audio-graph-card2";
77 cpu_ep: endpoint { remote-endpoint = <&codec_ep>; }; };
81 port { codec_ep: endpoint { remote-endpoint = <&cpu_ep>; }; };
84 ************************************
86 ************************************
88 It has connection part (= X) and list part (= y).
89 links indicates connection part of CPU side (= A).
92 CPU1 --(y) | | <-(X)--(X)-> | | (y)-- Codec1
93 CPU2 --(y) | | | | (y)-- Codec2
97 compatible = "audio-graph-card2";
103 (X) (A) mcpu: port@0 { mcpu0_ep: endpoint { remote-endpoint = <&mcodec0_ep>; }; };
104 (y) port@1 { mcpu1_ep: endpoint { remote-endpoint = <&cpu1_ep>; }; };
105 (y) port@2 { mcpu2_ep: endpoint { remote-endpoint = <&cpu2_ep>; }; };
108 (X) port@0 { mcodec0_ep: endpoint { remote-endpoint = <&mcpu0_ep>; }; };
109 (y) port@1 { mcodec1_ep: endpoint { remote-endpoint = <&codec1_ep>; }; };
110 (y) port@2 { mcodec2_ep: endpoint { remote-endpoint = <&codec2_ep>; }; };
119 port@0 { cpu1_ep: endpoint { remote-endpoint = <&mcpu1_ep>; }; };
120 port@1 { cpu2_ep: endpoint { remote-endpoint = <&mcpu2_ep>; }; };
126 port@0 { codec1_ep: endpoint { remote-endpoint = <&mcodec1_ep>; }; };
127 port@1 { codec2_ep: endpoint { remote-endpoint = <&mcodec2_ep>; }; };
131 ************************************
133 ************************************
137 PCM0 <--> * fe0 be0 * <--> DAI0: Codec Headset
138 PCM1 <--> * fe1 be1 * <--> DAI1: Codec Speakers
139 PCM2 <--> * fe2 be2 * <--> DAI2: MODEM
140 PCM3 <--> * fe3 be3 * <--> DAI3: BT
141 * be4 * <--> DAI4: DMIC
142 * be5 * <--> DAI5: FM
146 compatible = "audio-graph-card2";
149 routing = "xxx Playback", "xxx Playback",
150 "xxx Playback", "xxx Playback",
151 "xxx Playback", "xxx Playback";
153 // indicate all Front-End, Back-End
154 links = <&fe0, &fe1, ...,
160 fe0: port@0 { fe0_ep: endpoint { remote-endpoint = <&pcm0_ep>; }; };
161 fe1: port@1 { fe1_ep: endpoint { remote-endpoint = <&pcm1_ep>; }; };
166 be0: port@0 { be0_ep: endpoint { remote-endpoint = <&dai0_ep>; }; };
167 be1: port@1 { be1_ep: endpoint { remote-endpoint = <&dai1_ep>; }; };
177 port@0 { pcm0_ep: endpoint { remote-endpoint = <&fe0_ep>; }; };
178 port@1 { pcm1_ep: endpoint { remote-endpoint = <&fe1_ep>; }; };
185 port@0 { dai0_ep: endpoint { remote-endpoint = <&be0_ep>; }; };
186 port@1 { dai1_ep: endpoint { remote-endpoint = <&be1_ep>; }; };
191 ************************************
193 ************************************
201 compatible = "audio-graph-card2";
203 routing = "OUT" ,"DAI1 Playback",
204 "DAI0 Capture", "IN";
211 c2c: port@0 { c2cf_ep: endpoint { remote-endpoint = <&codec0_ep>; }; };
212 port@1 { c2cb_ep: endpoint { remote-endpoint = <&codec1_ep>; }; };
221 codec0_ep: endpoint { remote-endpoint = <&c2cf_ep>; }; };
222 port@1 { codec1_ep: endpoint { remote-endpoint = <&c2cb_ep>; }; };
233 GRAPH_MULTI, /* don't use ! Use this only in __graph_get_type() */
236 #define GRAPH_NODENAME_MULTI "multi"
237 #define GRAPH_NODENAME_DPCM "dpcm"
238 #define GRAPH_NODENAME_C2C "codec2codec"
240 #define port_to_endpoint(port) of_get_child_by_name(port, "endpoint")
242 static enum graph_type __graph_get_type(struct device_node *lnk)
244 struct device_node *np, *parent_np;
250 * => lnk: port@0 { ... };
255 np = of_get_parent(lnk);
256 if (of_node_name_eq(np, "ports")) {
257 parent_np = of_get_parent(np);
262 if (of_node_name_eq(np, GRAPH_NODENAME_MULTI)) {
267 if (of_node_name_eq(np, GRAPH_NODENAME_DPCM)) {
272 if (of_node_name_eq(np, GRAPH_NODENAME_C2C)) {
285 static enum graph_type graph_get_type(struct asoc_simple_priv *priv,
286 struct device_node *lnk)
288 enum graph_type type = __graph_get_type(lnk);
290 /* GRAPH_MULTI here means GRAPH_NORMAL */
291 if (type == GRAPH_MULTI)
296 struct device *dev = simple_priv_to_dev(priv);
297 const char *str = "Normal";
301 if (asoc_graph_is_ports0(lnk))
302 str = "DPCM Front-End";
304 str = "DPCM Back-End";
313 dev_dbg(dev, "%pOF (%s)", lnk, str);
319 static int graph_lnk_is_multi(struct device_node *lnk)
321 return __graph_get_type(lnk) == GRAPH_MULTI;
324 static struct device_node *graph_get_next_multi_ep(struct device_node **port)
326 struct device_node *ports = of_get_parent(*port);
327 struct device_node *ep = NULL;
328 struct device_node *rep = NULL;
333 * => lnk: port@0 { ... };
334 * port@1 { ep { ... = rep0 } };
335 * port@2 { ep { ... = rep1 } };
346 *port = of_get_next_child(ports, *port);
349 } while (!of_node_name_eq(*port, "port"));
352 ep = port_to_endpoint(*port);
353 rep = of_graph_get_remote_endpoint(ep);
362 static const struct snd_soc_ops graph_ops = {
363 .startup = asoc_simple_startup,
364 .shutdown = asoc_simple_shutdown,
365 .hw_params = asoc_simple_hw_params,
368 static void graph_parse_convert(struct device_node *ep,
369 struct simple_dai_props *props)
371 struct device_node *port = of_get_parent(ep);
372 struct device_node *ports = of_get_parent(port);
373 struct asoc_simple_data *adata = &props->adata;
375 if (of_node_name_eq(ports, "ports"))
376 asoc_simple_parse_convert(ports, NULL, adata);
377 asoc_simple_parse_convert(port, NULL, adata);
378 asoc_simple_parse_convert(ep, NULL, adata);
384 static void graph_parse_mclk_fs(struct device_node *ep,
385 struct simple_dai_props *props)
387 struct device_node *port = of_get_parent(ep);
388 struct device_node *ports = of_get_parent(port);
390 if (of_node_name_eq(ports, "ports"))
391 of_property_read_u32(ports, "mclk-fs", &props->mclk_fs);
392 of_property_read_u32(port, "mclk-fs", &props->mclk_fs);
393 of_property_read_u32(ep, "mclk-fs", &props->mclk_fs);
399 static int __graph_parse_node(struct asoc_simple_priv *priv,
400 enum graph_type gtype,
401 struct device_node *ep,
402 struct link_info *li,
405 struct device *dev = simple_priv_to_dev(priv);
406 struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
407 struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
408 struct snd_soc_dai_link_component *dlc;
409 struct asoc_simple_dai *dai;
410 int ret, is_single_links = 0;
413 dlc = asoc_link_to_cpu(dai_link, idx);
414 dai = simple_props_to_dai_cpu(dai_props, idx);
416 dlc = asoc_link_to_codec(dai_link, idx);
417 dai = simple_props_to_dai_codec(dai_props, idx);
420 graph_parse_mclk_fs(ep, dai_props);
422 ret = asoc_graph_parse_dai(dev, ep, dlc, &is_single_links);
426 ret = asoc_simple_parse_tdm(ep, dai);
430 ret = asoc_simple_parse_tdm_width_map(dev, ep, dai);
434 ret = asoc_simple_parse_clk(dev, ep, dai, dlc);
441 if (!dai_link->name) {
442 struct snd_soc_dai_link_component *cpus = dlc;
443 struct snd_soc_dai_link_component *codecs = asoc_link_to_codec(dai_link, idx);
444 char *cpu_multi = "";
445 char *codec_multi = "";
447 if (dai_link->num_cpus > 1)
448 cpu_multi = "_multi";
449 if (dai_link->num_codecs > 1)
450 codec_multi = "_multi";
454 /* run is_cpu only. see audio_graph2_link_normal() */
456 asoc_simple_set_dailink_name(dev, dai_link, "%s%s-%s%s",
457 cpus->dai_name, cpu_multi,
458 codecs->dai_name, codec_multi);
462 asoc_simple_set_dailink_name(dev, dai_link, "fe.%pOFP.%s%s",
463 cpus->of_node, cpus->dai_name, cpu_multi);
465 asoc_simple_set_dailink_name(dev, dai_link, "be.%pOFP.%s%s",
466 codecs->of_node, codecs->dai_name, codec_multi);
469 /* run is_cpu only. see audio_graph2_link_c2c() */
471 asoc_simple_set_dailink_name(dev, dai_link, "c2c.%s%s-%s%s",
472 cpus->dai_name, cpu_multi,
473 codecs->dai_name, codec_multi);
481 * Check "prefix" from top node
484 if (!is_cpu && gtype == GRAPH_DPCM) {
485 struct snd_soc_dai_link_component *codecs = asoc_link_to_codec(dai_link, idx);
486 struct snd_soc_codec_conf *cconf = simple_props_to_codec_conf(dai_props, idx);
487 struct device_node *rport = of_get_parent(ep);
488 struct device_node *rports = of_get_parent(rport);
490 if (of_node_name_eq(rports, "ports"))
491 snd_soc_of_parse_node_prefix(rports, cconf, codecs->of_node, "prefix");
492 snd_soc_of_parse_node_prefix(rport, cconf, codecs->of_node, "prefix");
499 struct snd_soc_dai_link_component *cpus = dlc;
500 struct snd_soc_dai_link_component *platforms = asoc_link_to_platform(dai_link, idx);
502 asoc_simple_canonicalize_cpu(cpus, is_single_links);
503 asoc_simple_canonicalize_platform(platforms, cpus);
509 static int graph_parse_node(struct asoc_simple_priv *priv,
510 enum graph_type gtype,
511 struct device_node *port,
512 struct link_info *li, int is_cpu)
514 struct device_node *ep;
517 if (graph_lnk_is_multi(port)) {
522 for (idx = 0;; idx++) {
523 ep = graph_get_next_multi_ep(&port);
527 ret = __graph_parse_node(priv, gtype, ep,
534 /* Single CPU / Codec */
535 ep = port_to_endpoint(port);
536 ret = __graph_parse_node(priv, gtype, ep, li, is_cpu, 0);
543 static void graph_parse_daifmt(struct device_node *node,
544 unsigned int *daifmt, unsigned int *bit_frame)
549 * see also above "daifmt" explanation
569 * It can be judged it is provider
570 * if (A) or (B) or (C) has bitclock-master / frame-master flag.
574 *bit_frame |= snd_soc_daifmt_parse_clock_provider_as_bitmap(node, NULL);
576 #define update_daifmt(name) \
577 if (!(*daifmt & SND_SOC_DAIFMT_##name##_MASK) && \
578 (fmt & SND_SOC_DAIFMT_##name##_MASK)) \
579 *daifmt |= fmt & SND_SOC_DAIFMT_##name##_MASK
584 * This function is called by (C) -> (B) -> (A) order.
585 * Set if applicable part was not yet set.
587 fmt = snd_soc_daifmt_parse_format(node, NULL);
588 update_daifmt(FORMAT);
589 update_daifmt(CLOCK);
593 static void graph_link_init(struct asoc_simple_priv *priv,
594 struct device_node *port,
595 struct link_info *li,
598 struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
599 struct device_node *ep;
600 struct device_node *ports;
601 unsigned int daifmt = 0, daiclk = 0;
602 unsigned int bit_frame = 0;
604 if (graph_lnk_is_multi(port)) {
606 ep = graph_get_next_multi_ep(&port);
607 port = of_get_parent(ep);
609 ep = port_to_endpoint(port);
612 ports = of_get_parent(port);
626 graph_parse_daifmt(ep, &daifmt, &bit_frame); /* (C) */
627 graph_parse_daifmt(port, &daifmt, &bit_frame); /* (B) */
628 if (of_node_name_eq(ports, "ports"))
629 graph_parse_daifmt(ports, &daifmt, &bit_frame); /* (A) */
633 * We need to flip clock_provider if it was CPU node,
634 * because it is Codec base.
636 daiclk = snd_soc_daifmt_clock_provider_from_bitmap(bit_frame);
638 daiclk = snd_soc_daifmt_clock_provider_flipped(daiclk);
640 dai_link->dai_fmt = daifmt | daiclk;
641 dai_link->init = asoc_simple_dai_init;
642 dai_link->ops = &graph_ops;
644 dai_link->ops = priv->ops;
647 int audio_graph2_link_normal(struct asoc_simple_priv *priv,
648 struct device_node *lnk,
649 struct link_info *li)
651 struct device_node *cpu_port = lnk;
652 struct device_node *cpu_ep = port_to_endpoint(cpu_port);
653 struct device_node *codec_port = of_graph_get_remote_port(cpu_ep);
659 * __graph_parse_node() :: DAI Naming
661 ret = graph_parse_node(priv, GRAPH_NORMAL, codec_port, li, 0);
666 * call CPU, and set DAI Name
668 ret = graph_parse_node(priv, GRAPH_NORMAL, cpu_port, li, 1);
672 graph_link_init(priv, cpu_port, li, 1);
674 of_node_put(codec_port);
679 EXPORT_SYMBOL_GPL(audio_graph2_link_normal);
681 int audio_graph2_link_dpcm(struct asoc_simple_priv *priv,
682 struct device_node *lnk,
683 struct link_info *li)
685 struct device_node *ep = port_to_endpoint(lnk);
686 struct device_node *rep = of_graph_get_remote_endpoint(ep);
687 struct device_node *rport = of_graph_get_remote_port(ep);
688 struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
689 struct simple_dai_props *dai_props = simple_priv_to_props(priv, li->link);
690 int is_cpu = asoc_graph_is_ports0(lnk);
698 * => lnk: port@0 { ep: { ... = rep }; };
709 * rport: port@0 { rep: { ... = ep } };
714 * setup CPU here, Codec is already set as dummy.
716 * asoc_simple_init_priv()
718 dai_link->dynamic = 1;
719 dai_link->dpcm_merged_format = 1;
721 ret = graph_parse_node(priv, GRAPH_DPCM, rport, li, 1);
733 * => lnk: port@0 { ep: { ... = rep; }; };
740 * rport: port@0 { rep: { ... = ep; }; };
745 * setup Codec here, CPU is already set as dummy.
747 * asoc_simple_init_priv()
751 dai_link->no_pcm = 1;
752 dai_link->be_hw_params_fixup = asoc_simple_be_hw_params_fixup;
754 ret = graph_parse_node(priv, GRAPH_DPCM, rport, li, 0);
759 graph_parse_convert(ep, dai_props); /* at node of <dpcm> */
760 graph_parse_convert(rep, dai_props); /* at node of <CPU/Codec> */
762 snd_soc_dai_link_set_capabilities(dai_link);
764 graph_link_init(priv, rport, li, is_cpu);
772 EXPORT_SYMBOL_GPL(audio_graph2_link_dpcm);
774 int audio_graph2_link_c2c(struct asoc_simple_priv *priv,
775 struct device_node *lnk,
776 struct link_info *li)
778 struct snd_soc_dai_link *dai_link = simple_priv_to_link(priv, li->link);
779 struct device_node *port0, *port1, *ports;
780 struct device_node *codec0_port, *codec1_port;
781 struct device_node *ep0, *ep1;
789 * => lnk: port@0 { c2c0_ep: { ... = codec0_ep; }; };
790 * port@1 { c2c1_ep: { ... = codec1_ep; }; };
796 * port@0 { codec0_ep: ... }; };
797 * port@1 { codec1_ep: ... }; };
803 ports = of_get_parent(port0);
804 port1 = of_get_next_child(ports, lnk);
807 * Card2 can use original Codec2Codec settings if DT has.
808 * It will use default settings if no settings on DT.
810 * asoc_simple_init_for_codec2codec()
812 * Add more settings here if needed
814 of_property_read_u32(ports, "rate", &val);
816 struct device *dev = simple_priv_to_dev(priv);
817 struct snd_soc_pcm_stream *c2c_conf;
819 c2c_conf = devm_kzalloc(dev, sizeof(*c2c_conf), GFP_KERNEL);
823 c2c_conf->formats = SNDRV_PCM_FMTBIT_S32_LE; /* update ME */
824 c2c_conf->rates = SNDRV_PCM_RATE_8000_384000;
826 c2c_conf->rate_max = val;
827 c2c_conf->channels_min =
828 c2c_conf->channels_max = 2; /* update ME */
830 dai_link->c2c_params = c2c_conf;
831 dai_link->num_c2c_params = 1;
834 ep0 = port_to_endpoint(port0);
835 ep1 = port_to_endpoint(port1);
837 codec0_port = of_graph_get_remote_port(ep0);
838 codec1_port = of_graph_get_remote_port(ep1);
843 * __graph_parse_node() :: DAI Naming
845 ret = graph_parse_node(priv, GRAPH_C2C, codec1_port, li, 0);
850 * call CPU, and set DAI Name
852 ret = graph_parse_node(priv, GRAPH_C2C, codec0_port, li, 1);
856 graph_link_init(priv, codec0_port, li, 1);
860 of_node_put(codec0_port);
861 of_node_put(codec1_port);
869 EXPORT_SYMBOL_GPL(audio_graph2_link_c2c);
871 static int graph_link(struct asoc_simple_priv *priv,
872 struct graph2_custom_hooks *hooks,
873 enum graph_type gtype,
874 struct device_node *lnk,
875 struct link_info *li)
877 struct device *dev = simple_priv_to_dev(priv);
878 GRAPH2_CUSTOM func = NULL;
883 if (hooks && hooks->custom_normal)
884 func = hooks->custom_normal;
886 func = audio_graph2_link_normal;
889 if (hooks && hooks->custom_dpcm)
890 func = hooks->custom_dpcm;
892 func = audio_graph2_link_dpcm;
895 if (hooks && hooks->custom_c2c)
896 func = hooks->custom_c2c;
898 func = audio_graph2_link_c2c;
905 dev_err(dev, "non supported gtype (%d)\n", gtype);
909 ret = func(priv, lnk, li);
918 static int graph_counter(struct device_node *lnk)
925 * => lnk: port@0 { ... };
932 * ignore first lnk part
934 if (graph_lnk_is_multi(lnk))
935 return of_graph_get_endpoint_count(of_get_parent(lnk)) - 1;
943 static int graph_count_normal(struct asoc_simple_priv *priv,
944 struct device_node *lnk,
945 struct link_info *li)
947 struct device_node *cpu_port = lnk;
948 struct device_node *cpu_ep = port_to_endpoint(cpu_port);
949 struct device_node *codec_port = of_graph_get_remote_port(cpu_ep);
953 * => lnk: port { endpoint { .. }; };
957 * DON'T REMOVE platforms
959 * simple-card.c :: simple_count_noml()
961 li->num[li->link].cpus =
962 li->num[li->link].platforms = graph_counter(cpu_port);
964 li->num[li->link].codecs = graph_counter(codec_port);
967 of_node_put(codec_port);
972 static int graph_count_dpcm(struct asoc_simple_priv *priv,
973 struct device_node *lnk,
974 struct link_info *li)
976 struct device_node *ep = port_to_endpoint(lnk);
977 struct device_node *rport = of_graph_get_remote_port(ep);
983 * => lnk: port@0 { endpoint { ... }; };
988 * => lnk: port@0 { endpoint { ... }; };
994 if (asoc_graph_is_ports0(lnk)) {
996 * DON'T REMOVE platforms
998 * simple-card.c :: simple_count_noml()
1000 li->num[li->link].cpus = graph_counter(rport); /* FE */
1001 li->num[li->link].platforms = graph_counter(rport);
1003 li->num[li->link].codecs = graph_counter(rport); /* BE */
1012 static int graph_count_c2c(struct asoc_simple_priv *priv,
1013 struct device_node *lnk,
1014 struct link_info *li)
1016 struct device_node *ports = of_get_parent(lnk);
1017 struct device_node *port0 = lnk;
1018 struct device_node *port1 = of_get_next_child(ports, lnk);
1019 struct device_node *ep0 = port_to_endpoint(port0);
1020 struct device_node *ep1 = port_to_endpoint(port1);
1021 struct device_node *codec0 = of_graph_get_remote_port(ep0);
1022 struct device_node *codec1 = of_graph_get_remote_port(ep1);
1029 * => lnk: port@0 { endpoint { ... }; };
1030 * port@1 { endpoint { ... }; };
1035 * DON'T REMOVE platforms
1037 * simple-card.c :: simple_count_noml()
1039 li->num[li->link].cpus =
1040 li->num[li->link].platforms = graph_counter(codec0);
1042 li->num[li->link].codecs = graph_counter(codec1);
1048 of_node_put(codec0);
1049 of_node_put(codec1);
1054 static int graph_count(struct asoc_simple_priv *priv,
1055 struct graph2_custom_hooks *hooks,
1056 enum graph_type gtype,
1057 struct device_node *lnk,
1058 struct link_info *li)
1060 struct device *dev = simple_priv_to_dev(priv);
1061 GRAPH2_CUSTOM func = NULL;
1064 if (li->link >= SNDRV_MAX_LINKS) {
1065 dev_err(dev, "too many links\n");
1071 func = graph_count_normal;
1074 func = graph_count_dpcm;
1077 func = graph_count_c2c;
1084 dev_err(dev, "non supported gtype (%d)\n", gtype);
1088 ret = func(priv, lnk, li);
1097 static int graph_for_each_link(struct asoc_simple_priv *priv,
1098 struct graph2_custom_hooks *hooks,
1099 struct link_info *li,
1100 int (*func)(struct asoc_simple_priv *priv,
1101 struct graph2_custom_hooks *hooks,
1102 enum graph_type gtype,
1103 struct device_node *lnk,
1104 struct link_info *li))
1106 struct of_phandle_iterator it;
1107 struct device *dev = simple_priv_to_dev(priv);
1108 struct device_node *node = dev->of_node;
1109 struct device_node *lnk;
1110 enum graph_type gtype;
1113 /* loop for all listed CPU port */
1114 of_for_each_phandle(&it, rc, node, "links", NULL, 0) {
1117 gtype = graph_get_type(priv, lnk);
1119 ret = func(priv, hooks, gtype, lnk, li);
1127 int audio_graph2_parse_of(struct asoc_simple_priv *priv, struct device *dev,
1128 struct graph2_custom_hooks *hooks)
1130 struct snd_soc_card *card = simple_priv_to_card(priv);
1131 struct link_info *li;
1134 li = devm_kzalloc(dev, sizeof(*li), GFP_KERNEL);
1138 card->probe = asoc_graph_card_probe;
1139 card->owner = THIS_MODULE;
1142 if ((hooks) && (hooks)->hook_pre) {
1143 ret = (hooks)->hook_pre(priv);
1148 ret = graph_for_each_link(priv, hooks, li, graph_count);
1154 ret = asoc_simple_init_priv(priv, li);
1158 priv->pa_gpio = devm_gpiod_get_optional(dev, "pa", GPIOD_OUT_LOW);
1159 if (IS_ERR(priv->pa_gpio)) {
1160 ret = PTR_ERR(priv->pa_gpio);
1161 dev_err(dev, "failed to get amplifier gpio: %d\n", ret);
1165 ret = asoc_simple_parse_widgets(card, NULL);
1169 ret = asoc_simple_parse_routing(card, NULL);
1173 memset(li, 0, sizeof(*li));
1174 ret = graph_for_each_link(priv, hooks, li, graph_link);
1178 ret = asoc_simple_parse_card_name(card, NULL);
1182 snd_soc_card_set_drvdata(card, priv);
1184 if ((hooks) && (hooks)->hook_post) {
1185 ret = (hooks)->hook_post(priv);
1190 asoc_simple_debug_info(priv);
1192 ret = devm_snd_soc_register_card(dev, card);
1194 devm_kfree(dev, li);
1197 dev_err_probe(dev, ret, "parse error\n");
1201 EXPORT_SYMBOL_GPL(audio_graph2_parse_of);
1203 static int graph_probe(struct platform_device *pdev)
1205 struct asoc_simple_priv *priv;
1206 struct device *dev = &pdev->dev;
1208 /* Allocate the private data and the DAI link array */
1209 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
1213 return audio_graph2_parse_of(priv, dev, NULL);
1216 static const struct of_device_id graph_of_match[] = {
1217 { .compatible = "audio-graph-card2", },
1220 MODULE_DEVICE_TABLE(of, graph_of_match);
1222 static struct platform_driver graph_card = {
1224 .name = "asoc-audio-graph-card2",
1225 .pm = &snd_soc_pm_ops,
1226 .of_match_table = graph_of_match,
1228 .probe = graph_probe,
1229 .remove = asoc_simple_remove,
1231 module_platform_driver(graph_card);
1233 MODULE_ALIAS("platform:asoc-audio-graph-card2");
1234 MODULE_LICENSE("GPL v2");
1235 MODULE_DESCRIPTION("ASoC Audio Graph Card2");
1236 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");