1 // SPDX-License-Identifier: GPL-2.0
3 // audio-graph-card2-custom-sample.c
5 // Copyright (C) 2020 Renesas Electronics Corp.
8 #include <linux/module.h>
9 #include <linux/of_gpio.h>
10 #include <linux/platform_device.h>
11 #include <sound/graph_card.h>
14 * Custom driver can have own priv
15 * which includes simple_util_priv.
18 struct simple_util_priv simple_priv;
20 /* custom driver's own params */
24 /* You can get custom_priv from simple_priv */
25 #define simple_to_custom(simple) container_of((simple), struct custom_priv, simple_priv)
27 static int custom_card_probe(struct snd_soc_card *card)
29 struct simple_util_priv *simple_priv = snd_soc_card_get_drvdata(card);
30 struct custom_priv *custom_priv = simple_to_custom(simple_priv);
31 struct device *dev = simple_priv_to_dev(simple_priv);
33 dev_info(dev, "custom probe\n");
35 custom_priv->custom_params = 1;
37 /* you can use generic probe function */
38 return graph_util_card_probe(card);
41 static int custom_hook_pre(struct simple_util_priv *priv)
43 struct device *dev = simple_priv_to_dev(priv);
45 /* You can custom before parsing */
46 dev_info(dev, "hook : %s\n", __func__);
51 static int custom_hook_post(struct simple_util_priv *priv)
53 struct device *dev = simple_priv_to_dev(priv);
54 struct snd_soc_card *card;
56 /* You can custom after parsing */
57 dev_info(dev, "hook : %s\n", __func__);
59 /* overwrite .probe sample */
60 card = simple_priv_to_card(priv);
61 card->probe = custom_card_probe;
66 static int custom_normal(struct simple_util_priv *priv,
67 struct device_node *lnk,
70 struct device *dev = simple_priv_to_dev(priv);
73 * You can custom Normal parsing
74 * before/affter audio_graph2_link_normal()
76 dev_info(dev, "hook : %s\n", __func__);
78 return audio_graph2_link_normal(priv, lnk, li);
81 static int custom_dpcm(struct simple_util_priv *priv,
82 struct device_node *lnk,
85 struct device *dev = simple_priv_to_dev(priv);
88 * You can custom DPCM parsing
89 * before/affter audio_graph2_link_dpcm()
91 dev_info(dev, "hook : %s\n", __func__);
93 return audio_graph2_link_dpcm(priv, lnk, li);
96 static int custom_c2c(struct simple_util_priv *priv,
97 struct device_node *lnk,
100 struct device *dev = simple_priv_to_dev(priv);
103 * You can custom Codec2Codec parsing
104 * before/affter audio_graph2_link_c2c()
106 dev_info(dev, "hook : %s\n", __func__);
108 return audio_graph2_link_c2c(priv, lnk, li);
112 * audio-graph-card2 has many hooks for your customizing.
114 static struct graph2_custom_hooks custom_hooks = {
115 .hook_pre = custom_hook_pre,
116 .hook_post = custom_hook_post,
117 .custom_normal = custom_normal,
118 .custom_dpcm = custom_dpcm,
119 .custom_c2c = custom_c2c,
122 static int custom_startup(struct snd_pcm_substream *substream)
124 struct snd_soc_pcm_runtime *rtd = snd_soc_substream_to_rtd(substream);
125 struct simple_util_priv *priv = snd_soc_card_get_drvdata(rtd->card);
126 struct device *dev = simple_priv_to_dev(priv);
128 dev_info(dev, "custom startup\n");
130 return simple_util_startup(substream);
133 /* You can use custom ops */
134 static const struct snd_soc_ops custom_ops = {
135 .startup = custom_startup,
136 .shutdown = simple_util_shutdown,
137 .hw_params = simple_util_hw_params,
140 static int custom_probe(struct platform_device *pdev)
142 struct custom_priv *custom_priv;
143 struct simple_util_priv *simple_priv;
144 struct device *dev = &pdev->dev;
147 custom_priv = devm_kzalloc(dev, sizeof(*custom_priv), GFP_KERNEL);
151 simple_priv = &custom_priv->simple_priv;
152 simple_priv->ops = &custom_ops; /* customize dai_link ops */
154 /* "audio-graph-card2-custom-sample" is too long */
155 simple_priv->snd_card.name = "card2-custom";
157 /* use audio-graph-card2 parsing with own custom hooks */
158 ret = audio_graph2_parse_of(simple_priv, dev, &custom_hooks);
162 /* customize more if needed */
167 static const struct of_device_id custom_of_match[] = {
168 { .compatible = "audio-graph-card2-custom-sample", },
171 MODULE_DEVICE_TABLE(of, custom_of_match);
173 static struct platform_driver custom_card = {
175 .name = "audio-graph-card2-custom-sample",
176 .of_match_table = custom_of_match,
178 .probe = custom_probe,
179 .remove_new = simple_util_remove,
181 module_platform_driver(custom_card);
183 MODULE_ALIAS("platform:asoc-audio-graph-card2-custom-sample");
184 MODULE_LICENSE("GPL v2");
185 MODULE_DESCRIPTION("ASoC Audio Graph Card2 Custom Sample");