0001
0002
0003
0004
0005
0006
0007
0008 #include <linux/module.h>
0009 #include <linux/of_gpio.h>
0010 #include <linux/platform_device.h>
0011 #include <sound/graph_card.h>
0012
0013
0014
0015
0016
0017 struct custom_priv {
0018 struct asoc_simple_priv simple_priv;
0019
0020
0021 int custom_params;
0022 };
0023
0024
0025 #define simple_to_custom(simple) container_of((simple), struct custom_priv, simple_priv)
0026
0027 static int custom_card_probe(struct snd_soc_card *card)
0028 {
0029 struct asoc_simple_priv *simple_priv = snd_soc_card_get_drvdata(card);
0030 struct custom_priv *custom_priv = simple_to_custom(simple_priv);
0031 struct device *dev = simple_priv_to_dev(simple_priv);
0032
0033 dev_info(dev, "custom probe\n");
0034
0035 custom_priv->custom_params = 1;
0036
0037
0038 return asoc_graph_card_probe(card);
0039 }
0040
0041 static int custom_hook_pre(struct asoc_simple_priv *priv)
0042 {
0043 struct device *dev = simple_priv_to_dev(priv);
0044
0045
0046 dev_info(dev, "hook : %s\n", __func__);
0047
0048 return 0;
0049 }
0050
0051 static int custom_hook_post(struct asoc_simple_priv *priv)
0052 {
0053 struct device *dev = simple_priv_to_dev(priv);
0054 struct snd_soc_card *card;
0055
0056
0057 dev_info(dev, "hook : %s\n", __func__);
0058
0059
0060 card = simple_priv_to_card(priv);
0061 card->probe = custom_card_probe;
0062
0063 return 0;
0064 }
0065
0066 static int custom_normal(struct asoc_simple_priv *priv,
0067 struct device_node *lnk,
0068 struct link_info *li)
0069 {
0070 struct device *dev = simple_priv_to_dev(priv);
0071
0072
0073
0074
0075
0076 dev_info(dev, "hook : %s\n", __func__);
0077
0078 return audio_graph2_link_normal(priv, lnk, li);
0079 }
0080
0081 static int custom_dpcm(struct asoc_simple_priv *priv,
0082 struct device_node *lnk,
0083 struct link_info *li)
0084 {
0085 struct device *dev = simple_priv_to_dev(priv);
0086
0087
0088
0089
0090
0091 dev_info(dev, "hook : %s\n", __func__);
0092
0093 return audio_graph2_link_dpcm(priv, lnk, li);
0094 }
0095
0096 static int custom_c2c(struct asoc_simple_priv *priv,
0097 struct device_node *lnk,
0098 struct link_info *li)
0099 {
0100 struct device *dev = simple_priv_to_dev(priv);
0101
0102
0103
0104
0105
0106 dev_info(dev, "hook : %s\n", __func__);
0107
0108 return audio_graph2_link_c2c(priv, lnk, li);
0109 }
0110
0111
0112
0113
0114 static struct graph2_custom_hooks custom_hooks = {
0115 .hook_pre = custom_hook_pre,
0116 .hook_post = custom_hook_post,
0117 .custom_normal = custom_normal,
0118 .custom_dpcm = custom_dpcm,
0119 .custom_c2c = custom_c2c,
0120 };
0121
0122 static int custom_startup(struct snd_pcm_substream *substream)
0123 {
0124 struct snd_soc_pcm_runtime *rtd = asoc_substream_to_rtd(substream);
0125 struct asoc_simple_priv *priv = snd_soc_card_get_drvdata(rtd->card);
0126 struct device *dev = simple_priv_to_dev(priv);
0127
0128 dev_info(dev, "custom startup\n");
0129
0130 return asoc_simple_startup(substream);
0131 }
0132
0133
0134 static const struct snd_soc_ops custom_ops = {
0135 .startup = custom_startup,
0136 .shutdown = asoc_simple_shutdown,
0137 .hw_params = asoc_simple_hw_params,
0138 };
0139
0140 static int custom_probe(struct platform_device *pdev)
0141 {
0142 struct custom_priv *custom_priv;
0143 struct asoc_simple_priv *simple_priv;
0144 struct device *dev = &pdev->dev;
0145 int ret;
0146
0147 custom_priv = devm_kzalloc(dev, sizeof(*custom_priv), GFP_KERNEL);
0148 if (!custom_priv)
0149 return -ENOMEM;
0150
0151 simple_priv = &custom_priv->simple_priv;
0152 simple_priv->ops = &custom_ops;
0153
0154
0155 ret = audio_graph2_parse_of(simple_priv, dev, &custom_hooks);
0156 if (ret < 0)
0157 return ret;
0158
0159
0160
0161 return 0;
0162 }
0163
0164 static const struct of_device_id custom_of_match[] = {
0165 { .compatible = "audio-graph-card2-custom-sample", },
0166 {},
0167 };
0168 MODULE_DEVICE_TABLE(of, custom_of_match);
0169
0170 static struct platform_driver custom_card = {
0171 .driver = {
0172 .name = "audio-graph-card2-custom-sample",
0173 .of_match_table = custom_of_match,
0174 },
0175 .probe = custom_probe,
0176 .remove = asoc_simple_remove,
0177 };
0178 module_platform_driver(custom_card);
0179
0180 MODULE_ALIAS("platform:asoc-audio-graph-card2-custom-sample");
0181 MODULE_LICENSE("GPL v2");
0182 MODULE_DESCRIPTION("ASoC Audio Graph Card2 Custom Sample");
0183 MODULE_AUTHOR("Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>");