1 // SPDX-License-Identifier: GPL-2.0
2 // Copyright (c) 2018, Linaro Limited.
3 // Copyright (c) 2018, The Linux Foundation. All rights reserved.
5 #include <linux/module.h>
6 #include <sound/jack.h>
7 #include <linux/input-event-codes.h>
8 #include "qdsp6/q6afe.h"
11 int qcom_snd_parse_of(struct snd_soc_card *card)
13 struct device_node *np;
14 struct device_node *codec = NULL;
15 struct device_node *platform = NULL;
16 struct device_node *cpu = NULL;
17 struct device *dev = card->dev;
18 struct snd_soc_dai_link *link;
19 struct of_phandle_args args;
20 struct snd_soc_dai_link_component *dlc;
23 ret = snd_soc_of_parse_card_name(card, "model");
24 if (ret == 0 && !card->name)
25 /* Deprecated, only for compatibility with old device trees */
26 ret = snd_soc_of_parse_card_name(card, "qcom,model");
28 dev_err(dev, "Error parsing card name: %d\n", ret);
32 if (of_property_read_bool(dev->of_node, "widgets")) {
33 ret = snd_soc_of_parse_audio_simple_widgets(card, "widgets");
39 if (of_property_read_bool(dev->of_node, "audio-routing")) {
40 ret = snd_soc_of_parse_audio_routing(card, "audio-routing");
44 /* Deprecated, only for compatibility with old device trees */
45 if (of_property_read_bool(dev->of_node, "qcom,audio-routing")) {
46 ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
51 ret = snd_soc_of_parse_pin_switches(card, "pin-switches");
55 ret = snd_soc_of_parse_aux_devs(card, "aux-devs");
60 num_links = of_get_available_child_count(dev->of_node);
62 /* Allocate the DAI link array */
63 card->dai_link = devm_kcalloc(dev, num_links, sizeof(*link), GFP_KERNEL);
67 card->num_links = num_links;
68 link = card->dai_link;
70 for_each_available_child_of_node(dev->of_node, np) {
71 dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL);
78 link->platforms = &dlc[1];
81 link->num_platforms = 1;
83 ret = of_property_read_string(np, "link-name", &link->name);
85 dev_err(card->dev, "error getting codec dai_link name\n");
89 cpu = of_get_child_by_name(np, "cpu");
90 platform = of_get_child_by_name(np, "platform");
91 codec = of_get_child_by_name(np, "codec");
94 dev_err(dev, "%s: Can't find cpu DT node\n", link->name);
99 ret = of_parse_phandle_with_args(cpu, "sound-dai",
100 "#sound-dai-cells", 0, &args);
102 dev_err(card->dev, "%s: error getting cpu phandle\n", link->name);
105 link->cpus->of_node = args.np;
106 link->id = args.args[0];
108 ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name);
110 dev_err_probe(card->dev, ret,
111 "%s: error getting cpu dai name\n", link->name);
116 link->platforms->of_node = of_parse_phandle(platform,
119 if (!link->platforms->of_node) {
120 dev_err(card->dev, "%s: platform dai not found\n", link->name);
125 link->platforms->of_node = link->cpus->of_node;
129 ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
131 dev_err_probe(card->dev, ret,
132 "%s: codec dai not found\n", link->name);
139 link->ignore_pmdown_time = 1;
143 dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL);
150 link->num_codecs = 1;
152 link->codecs->dai_name = "snd-soc-dummy-dai";
153 link->codecs->name = "snd-soc-dummy";
157 if (platform || !codec) {
159 snd_soc_dai_link_set_capabilities(link);
160 link->ignore_suspend = 1;
164 link->stream_name = link->name;
169 of_node_put(platform);
176 of_node_put(platform);
181 EXPORT_SYMBOL_GPL(qcom_snd_parse_of);
183 int qcom_snd_wcd_jack_setup(struct snd_soc_pcm_runtime *rtd,
184 struct snd_soc_jack *jack, bool *jack_setup)
186 struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(rtd, 0);
187 struct snd_soc_dai *codec_dai = asoc_rtd_to_codec(rtd, 0);
188 struct snd_soc_card *card = rtd->card;
192 rval = snd_soc_card_jack_new(card, "Headset Jack",
193 SND_JACK_HEADSET | SND_JACK_LINEOUT |
194 SND_JACK_MECHANICAL |
195 SND_JACK_BTN_0 | SND_JACK_BTN_1 |
196 SND_JACK_BTN_2 | SND_JACK_BTN_3 |
197 SND_JACK_BTN_4 | SND_JACK_BTN_5,
201 dev_err(card->dev, "Unable to add Headphone Jack\n");
205 snd_jack_set_key(jack->jack, SND_JACK_BTN_0, KEY_MEDIA);
206 snd_jack_set_key(jack->jack, SND_JACK_BTN_1, KEY_VOICECOMMAND);
207 snd_jack_set_key(jack->jack, SND_JACK_BTN_2, KEY_VOLUMEUP);
208 snd_jack_set_key(jack->jack, SND_JACK_BTN_3, KEY_VOLUMEDOWN);
212 switch (cpu_dai->id) {
213 case TX_CODEC_DMA_TX_0:
214 case TX_CODEC_DMA_TX_1:
215 case TX_CODEC_DMA_TX_2:
216 case TX_CODEC_DMA_TX_3:
217 for_each_rtd_codec_dais(rtd, i, codec_dai) {
218 rval = snd_soc_component_set_jack(codec_dai->component,
220 if (rval != 0 && rval != -ENOTSUPP) {
221 dev_warn(card->dev, "Failed to set jack: %d\n", rval);
234 EXPORT_SYMBOL_GPL(qcom_snd_wcd_jack_setup);
235 MODULE_LICENSE("GPL v2");