1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2018, Linaro Limited
4 #include <linux/soc/qcom/apr.h>
5 #include <linux/module.h>
6 #include <linux/component.h>
7 #include <linux/platform_device.h>
8 #include <linux/of_device.h>
10 #include <sound/soc-dapm.h>
11 #include <sound/pcm.h>
13 static int apq8096_be_hw_params_fixup(struct snd_soc_pcm_runtime
*rtd
,
14 struct snd_pcm_hw_params
*params
)
16 struct snd_interval
*rate
= hw_param_interval(params
,
17 SNDRV_PCM_HW_PARAM_RATE
);
18 struct snd_interval
*channels
= hw_param_interval(params
,
19 SNDRV_PCM_HW_PARAM_CHANNELS
);
21 rate
->min
= rate
->max
= 48000;
22 channels
->min
= channels
->max
= 2;
27 static int apq8096_sbc_parse_of(struct snd_soc_card
*card
)
29 struct device_node
*np
;
30 struct device_node
*codec
= NULL
;
31 struct device_node
*platform
= NULL
;
32 struct device_node
*cpu
= NULL
;
33 struct device
*dev
= card
->dev
;
34 struct snd_soc_dai_link
*link
;
37 ret
= snd_soc_of_parse_card_name(card
, "qcom,model");
39 dev_err(dev
, "Error parsing card name: %d\n", ret
);
44 if (of_property_read_bool(dev
->of_node
, "qcom,audio-routing")) {
45 ret
= snd_soc_of_parse_audio_routing(card
,
46 "qcom,audio-routing");
52 num_links
= of_get_child_count(dev
->of_node
);
54 /* Allocate the DAI link array */
55 card
->dai_link
= kcalloc(num_links
, sizeof(*link
), GFP_KERNEL
);
59 card
->num_links
= num_links
;
60 link
= card
->dai_link
;
62 for_each_child_of_node(dev
->of_node
, np
) {
63 cpu
= of_get_child_by_name(np
, "cpu");
65 dev_err(dev
, "Can't find cpu DT node\n");
70 link
->cpu_of_node
= of_parse_phandle(cpu
, "sound-dai", 0);
71 if (!link
->cpu_of_node
) {
72 dev_err(card
->dev
, "error getting cpu phandle\n");
77 ret
= snd_soc_of_get_dai_name(cpu
, &link
->cpu_dai_name
);
79 dev_err(card
->dev
, "error getting cpu dai name\n");
83 platform
= of_get_child_by_name(np
, "platform");
84 codec
= of_get_child_by_name(np
, "codec");
85 if (codec
&& platform
) {
86 link
->platform_of_node
= of_parse_phandle(platform
,
89 if (!link
->platform_of_node
) {
90 dev_err(card
->dev
, "platform dai not found\n");
95 ret
= snd_soc_of_get_dai_link_codecs(dev
, codec
, link
);
97 dev_err(card
->dev
, "codec dai not found\n");
101 link
->ignore_pmdown_time
= 1;
102 link
->be_hw_params_fixup
= apq8096_be_hw_params_fixup
;
104 link
->platform_of_node
= link
->cpu_of_node
;
105 link
->codec_dai_name
= "snd-soc-dummy-dai";
106 link
->codec_name
= "snd-soc-dummy";
110 link
->ignore_suspend
= 1;
111 ret
= of_property_read_string(np
, "link-name", &link
->name
);
113 dev_err(card
->dev
, "error getting codec dai_link name\n");
117 link
->dpcm_playback
= 1;
118 link
->dpcm_capture
= 1;
119 link
->stream_name
= link
->name
;
127 of_node_put(platform
);
128 kfree(card
->dai_link
);
132 static int apq8096_bind(struct device
*dev
)
134 struct snd_soc_card
*card
;
137 card
= kzalloc(sizeof(*card
), GFP_KERNEL
);
141 component_bind_all(dev
, card
);
143 ret
= apq8096_sbc_parse_of(card
);
145 dev_err(dev
, "Error parsing OF data\n");
149 ret
= snd_soc_register_card(card
);
156 component_unbind_all(dev
, card
);
161 static void apq8096_unbind(struct device
*dev
)
163 struct snd_soc_card
*card
= dev_get_drvdata(dev
);
165 snd_soc_unregister_card(card
);
166 component_unbind_all(dev
, card
);
167 kfree(card
->dai_link
);
171 static const struct component_master_ops apq8096_ops
= {
172 .bind
= apq8096_bind
,
173 .unbind
= apq8096_unbind
,
176 static int apq8016_compare_of(struct device
*dev
, void *data
)
178 return dev
->of_node
== data
;
181 static void apq8016_release_of(struct device
*dev
, void *data
)
186 static int add_audio_components(struct device
*dev
,
187 struct component_match
**matchptr
)
189 struct device_node
*np
, *platform
, *cpu
, *node
, *dai_node
;
193 for_each_child_of_node(node
, np
) {
194 cpu
= of_get_child_by_name(np
, "cpu");
196 dai_node
= of_parse_phandle(cpu
, "sound-dai", 0);
197 of_node_get(dai_node
);
198 component_match_add_release(dev
, matchptr
,
204 platform
= of_get_child_by_name(np
, "platform");
206 dai_node
= of_parse_phandle(platform
, "sound-dai", 0);
207 component_match_add_release(dev
, matchptr
,
217 static int apq8096_platform_probe(struct platform_device
*pdev
)
219 struct component_match
*match
= NULL
;
222 ret
= add_audio_components(&pdev
->dev
, &match
);
226 return component_master_add_with_match(&pdev
->dev
, &apq8096_ops
, match
);
229 static int apq8096_platform_remove(struct platform_device
*pdev
)
231 component_master_del(&pdev
->dev
, &apq8096_ops
);
236 static const struct of_device_id msm_snd_apq8096_dt_match
[] = {
237 {.compatible
= "qcom,apq8096-sndcard"},
241 MODULE_DEVICE_TABLE(of
, msm_snd_apq8096_dt_match
);
243 static struct platform_driver msm_snd_apq8096_driver
= {
244 .probe
= apq8096_platform_probe
,
245 .remove
= apq8096_platform_remove
,
247 .name
= "msm-snd-apq8096",
248 .owner
= THIS_MODULE
,
249 .of_match_table
= msm_snd_apq8096_dt_match
,
252 module_platform_driver(msm_snd_apq8096_driver
);
253 MODULE_AUTHOR("Srinivas Kandagatla <srinivas.kandagatla@linaro.org");
254 MODULE_DESCRIPTION("APQ8096 ASoC Machine Driver");
255 MODULE_LICENSE("GPL v2");