1 // SPDX-License-Identifier: GPL-2.0
3 // audio-graph-card2-custom-sample.c
5 // Copyright (C) 2020 Renesas Electronics Corp.
6 // Copyright (C) 2020 Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
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 asoc_simple_priv.
18 struct asoc_simple_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 asoc_simple_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 asoc_graph_card_probe(card);
41 static int custom_hook_pre(struct asoc_simple_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 asoc_simple_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 asoc_simple_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 asoc_simple_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 asoc_simple_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 = asoc_substream_to_rtd(substream);
125 struct asoc_simple_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 asoc_simple_startup(substream);
133 /* You can use custom ops */
134 static const struct snd_soc_ops custom_ops = {
135 .startup = custom_startup,
136 .shutdown = asoc_simple_shutdown,
137 .hw_params = asoc_simple_hw_params,
140 static int custom_probe(struct platform_device *pdev)
142 struct custom_priv *custom_priv;
143 struct asoc_simple_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 /* use audio-graph-card2 parsing with own custom hooks */
155 ret = audio_graph2_parse_of(simple_priv, dev, &custom_hooks);
159 /* customize more if needed */
164 static const struct of_device_id custom_of_match[] = {
165 { .compatible = "audio-graph-card2-custom-sample", },
168 MODULE_DEVICE_TABLE(of, custom_of_match);
170 static struct platform_driver custom_card = {
172 .name = "audio-graph-card2-custom-sample",
173 .of_match_table = custom_of_match,
175 .probe = custom_probe,
176 .remove = asoc_simple_remove,
178 module_platform_driver(custom_card);
180 MODULE_ALIAS("platform:asoc-audio-graph-card2-custom-sample");
181 MODULE_LICENSE("GPL v2");
182 MODULE_DESCRIPTION("ASoC Audio Graph Card2 Custom Sample");
183 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");