0001
0002
0003
0004
0005 #include <linux/module.h>
0006 #include "common.h"
0007
0008 int qcom_snd_parse_of(struct snd_soc_card *card)
0009 {
0010 struct device_node *np;
0011 struct device_node *codec = NULL;
0012 struct device_node *platform = NULL;
0013 struct device_node *cpu = NULL;
0014 struct device *dev = card->dev;
0015 struct snd_soc_dai_link *link;
0016 struct of_phandle_args args;
0017 struct snd_soc_dai_link_component *dlc;
0018 int ret, num_links;
0019
0020 ret = snd_soc_of_parse_card_name(card, "model");
0021 if (ret == 0 && !card->name)
0022
0023 ret = snd_soc_of_parse_card_name(card, "qcom,model");
0024 if (ret) {
0025 dev_err(dev, "Error parsing card name: %d\n", ret);
0026 return ret;
0027 }
0028
0029 if (of_property_read_bool(dev->of_node, "widgets")) {
0030 ret = snd_soc_of_parse_audio_simple_widgets(card, "widgets");
0031 if (ret)
0032 return ret;
0033 }
0034
0035
0036 if (of_property_read_bool(dev->of_node, "audio-routing")) {
0037 ret = snd_soc_of_parse_audio_routing(card, "audio-routing");
0038 if (ret)
0039 return ret;
0040 }
0041
0042 if (of_property_read_bool(dev->of_node, "qcom,audio-routing")) {
0043 ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing");
0044 if (ret)
0045 return ret;
0046 }
0047
0048 ret = snd_soc_of_parse_pin_switches(card, "pin-switches");
0049 if (ret)
0050 return ret;
0051
0052 ret = snd_soc_of_parse_aux_devs(card, "aux-devs");
0053 if (ret)
0054 return ret;
0055
0056
0057 num_links = of_get_available_child_count(dev->of_node);
0058
0059
0060 card->dai_link = devm_kcalloc(dev, num_links, sizeof(*link), GFP_KERNEL);
0061 if (!card->dai_link)
0062 return -ENOMEM;
0063
0064 card->num_links = num_links;
0065 link = card->dai_link;
0066
0067 for_each_available_child_of_node(dev->of_node, np) {
0068 dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL);
0069 if (!dlc) {
0070 ret = -ENOMEM;
0071 goto err_put_np;
0072 }
0073
0074 link->cpus = &dlc[0];
0075 link->platforms = &dlc[1];
0076
0077 link->num_cpus = 1;
0078 link->num_platforms = 1;
0079
0080 ret = of_property_read_string(np, "link-name", &link->name);
0081 if (ret) {
0082 dev_err(card->dev, "error getting codec dai_link name\n");
0083 goto err_put_np;
0084 }
0085
0086 cpu = of_get_child_by_name(np, "cpu");
0087 platform = of_get_child_by_name(np, "platform");
0088 codec = of_get_child_by_name(np, "codec");
0089
0090 if (!cpu) {
0091 dev_err(dev, "%s: Can't find cpu DT node\n", link->name);
0092 ret = -EINVAL;
0093 goto err;
0094 }
0095
0096 ret = of_parse_phandle_with_args(cpu, "sound-dai",
0097 "#sound-dai-cells", 0, &args);
0098 if (ret) {
0099 dev_err(card->dev, "%s: error getting cpu phandle\n", link->name);
0100 goto err;
0101 }
0102 link->cpus->of_node = args.np;
0103 link->id = args.args[0];
0104
0105 ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name);
0106 if (ret) {
0107 dev_err_probe(card->dev, ret,
0108 "%s: error getting cpu dai name\n", link->name);
0109 goto err;
0110 }
0111
0112 if (platform) {
0113 link->platforms->of_node = of_parse_phandle(platform,
0114 "sound-dai",
0115 0);
0116 if (!link->platforms->of_node) {
0117 dev_err(card->dev, "%s: platform dai not found\n", link->name);
0118 ret = -EINVAL;
0119 goto err;
0120 }
0121 } else {
0122 link->platforms->of_node = link->cpus->of_node;
0123 }
0124
0125 if (codec) {
0126 ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
0127 if (ret < 0) {
0128 dev_err_probe(card->dev, ret,
0129 "%s: codec dai not found\n", link->name);
0130 goto err;
0131 }
0132
0133 if (platform) {
0134
0135 link->no_pcm = 1;
0136 link->ignore_pmdown_time = 1;
0137 }
0138 } else {
0139
0140 dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL);
0141 if (!dlc) {
0142 ret = -ENOMEM;
0143 goto err;
0144 }
0145
0146 link->codecs = dlc;
0147 link->num_codecs = 1;
0148
0149 link->codecs->dai_name = "snd-soc-dummy-dai";
0150 link->codecs->name = "snd-soc-dummy";
0151 link->dynamic = 1;
0152 }
0153
0154 if (platform || !codec) {
0155
0156 snd_soc_dai_link_set_capabilities(link);
0157 link->ignore_suspend = 1;
0158 link->nonatomic = 1;
0159 }
0160
0161 link->stream_name = link->name;
0162 link++;
0163
0164 of_node_put(cpu);
0165 of_node_put(codec);
0166 of_node_put(platform);
0167 }
0168
0169 return 0;
0170 err:
0171 of_node_put(cpu);
0172 of_node_put(codec);
0173 of_node_put(platform);
0174 err_put_np:
0175 of_node_put(np);
0176 return ret;
0177 }
0178 EXPORT_SYMBOL(qcom_snd_parse_of);
0179
0180 MODULE_LICENSE("GPL v2");