| .. | .. |
|---|
| 14 | 14 | struct device *dev = card->dev; |
|---|
| 15 | 15 | struct snd_soc_dai_link *link; |
|---|
| 16 | 16 | struct of_phandle_args args; |
|---|
| 17 | + struct snd_soc_dai_link_component *dlc; |
|---|
| 17 | 18 | int ret, num_links; |
|---|
| 18 | 19 | |
|---|
| 19 | 20 | ret = snd_soc_of_parse_card_name(card, "model"); |
|---|
| 21 | + if (ret == 0 && !card->name) |
|---|
| 22 | + /* Deprecated, only for compatibility with old device trees */ |
|---|
| 23 | + ret = snd_soc_of_parse_card_name(card, "qcom,model"); |
|---|
| 20 | 24 | if (ret) { |
|---|
| 21 | 25 | dev_err(dev, "Error parsing card name: %d\n", ret); |
|---|
| 22 | 26 | return ret; |
|---|
| .. | .. |
|---|
| 24 | 28 | |
|---|
| 25 | 29 | /* DAPM routes */ |
|---|
| 26 | 30 | if (of_property_read_bool(dev->of_node, "audio-routing")) { |
|---|
| 27 | | - ret = snd_soc_of_parse_audio_routing(card, |
|---|
| 28 | | - "audio-routing"); |
|---|
| 31 | + ret = snd_soc_of_parse_audio_routing(card, "audio-routing"); |
|---|
| 29 | 32 | if (ret) |
|---|
| 30 | 33 | return ret; |
|---|
| 31 | 34 | } |
|---|
| 35 | + /* Deprecated, only for compatibility with old device trees */ |
|---|
| 36 | + if (of_property_read_bool(dev->of_node, "qcom,audio-routing")) { |
|---|
| 37 | + ret = snd_soc_of_parse_audio_routing(card, "qcom,audio-routing"); |
|---|
| 38 | + if (ret) |
|---|
| 39 | + return ret; |
|---|
| 40 | + } |
|---|
| 41 | + |
|---|
| 42 | + ret = snd_soc_of_parse_aux_devs(card, "aux-devs"); |
|---|
| 43 | + if (ret) |
|---|
| 44 | + return ret; |
|---|
| 32 | 45 | |
|---|
| 33 | 46 | /* Populate links */ |
|---|
| 34 | 47 | num_links = of_get_child_count(dev->of_node); |
|---|
| 35 | 48 | |
|---|
| 36 | 49 | /* Allocate the DAI link array */ |
|---|
| 37 | | - card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL); |
|---|
| 50 | + card->dai_link = devm_kcalloc(dev, num_links, sizeof(*link), GFP_KERNEL); |
|---|
| 38 | 51 | if (!card->dai_link) |
|---|
| 39 | 52 | return -ENOMEM; |
|---|
| 40 | 53 | |
|---|
| 41 | 54 | card->num_links = num_links; |
|---|
| 42 | 55 | link = card->dai_link; |
|---|
| 56 | + |
|---|
| 43 | 57 | for_each_child_of_node(dev->of_node, np) { |
|---|
| 58 | + dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL); |
|---|
| 59 | + if (!dlc) { |
|---|
| 60 | + ret = -ENOMEM; |
|---|
| 61 | + goto err_put_np; |
|---|
| 62 | + } |
|---|
| 63 | + |
|---|
| 64 | + link->cpus = &dlc[0]; |
|---|
| 65 | + link->platforms = &dlc[1]; |
|---|
| 66 | + |
|---|
| 67 | + link->num_cpus = 1; |
|---|
| 68 | + link->num_platforms = 1; |
|---|
| 69 | + |
|---|
| 70 | + ret = of_property_read_string(np, "link-name", &link->name); |
|---|
| 71 | + if (ret) { |
|---|
| 72 | + dev_err(card->dev, "error getting codec dai_link name\n"); |
|---|
| 73 | + goto err_put_np; |
|---|
| 74 | + } |
|---|
| 75 | + |
|---|
| 44 | 76 | cpu = of_get_child_by_name(np, "cpu"); |
|---|
| 45 | 77 | platform = of_get_child_by_name(np, "platform"); |
|---|
| 46 | 78 | codec = of_get_child_by_name(np, "codec"); |
|---|
| 47 | 79 | |
|---|
| 48 | 80 | if (!cpu) { |
|---|
| 49 | | - dev_err(dev, "Can't find cpu DT node\n"); |
|---|
| 81 | + dev_err(dev, "%s: Can't find cpu DT node\n", link->name); |
|---|
| 50 | 82 | ret = -EINVAL; |
|---|
| 51 | 83 | goto err; |
|---|
| 52 | 84 | } |
|---|
| .. | .. |
|---|
| 54 | 86 | ret = of_parse_phandle_with_args(cpu, "sound-dai", |
|---|
| 55 | 87 | "#sound-dai-cells", 0, &args); |
|---|
| 56 | 88 | if (ret) { |
|---|
| 57 | | - dev_err(card->dev, "error getting cpu phandle\n"); |
|---|
| 89 | + dev_err(card->dev, "%s: error getting cpu phandle\n", link->name); |
|---|
| 58 | 90 | goto err; |
|---|
| 59 | 91 | } |
|---|
| 60 | | - link->cpu_of_node = args.np; |
|---|
| 92 | + link->cpus->of_node = args.np; |
|---|
| 61 | 93 | link->id = args.args[0]; |
|---|
| 62 | 94 | |
|---|
| 63 | | - ret = snd_soc_of_get_dai_name(cpu, &link->cpu_dai_name); |
|---|
| 95 | + ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name); |
|---|
| 64 | 96 | if (ret) { |
|---|
| 65 | | - dev_err(card->dev, "error getting cpu dai name\n"); |
|---|
| 97 | + if (ret != -EPROBE_DEFER) |
|---|
| 98 | + dev_err(card->dev, "%s: error getting cpu dai name: %d\n", |
|---|
| 99 | + link->name, ret); |
|---|
| 66 | 100 | goto err; |
|---|
| 67 | 101 | } |
|---|
| 68 | 102 | |
|---|
| 69 | | - if (codec && platform) { |
|---|
| 70 | | - link->platform_of_node = of_parse_phandle(platform, |
|---|
| 103 | + if (platform) { |
|---|
| 104 | + link->platforms->of_node = of_parse_phandle(platform, |
|---|
| 71 | 105 | "sound-dai", |
|---|
| 72 | 106 | 0); |
|---|
| 73 | | - if (!link->platform_of_node) { |
|---|
| 74 | | - dev_err(card->dev, "platform dai not found\n"); |
|---|
| 107 | + if (!link->platforms->of_node) { |
|---|
| 108 | + dev_err(card->dev, "%s: platform dai not found\n", link->name); |
|---|
| 75 | 109 | ret = -EINVAL; |
|---|
| 76 | 110 | goto err; |
|---|
| 77 | 111 | } |
|---|
| 112 | + } else { |
|---|
| 113 | + link->platforms->of_node = link->cpus->of_node; |
|---|
| 114 | + } |
|---|
| 78 | 115 | |
|---|
| 116 | + if (codec) { |
|---|
| 79 | 117 | ret = snd_soc_of_get_dai_link_codecs(dev, codec, link); |
|---|
| 80 | 118 | if (ret < 0) { |
|---|
| 81 | | - dev_err(card->dev, "codec dai not found\n"); |
|---|
| 119 | + if (ret != -EPROBE_DEFER) |
|---|
| 120 | + dev_err(card->dev, "%s: codec dai not found: %d\n", |
|---|
| 121 | + link->name, ret); |
|---|
| 82 | 122 | goto err; |
|---|
| 83 | 123 | } |
|---|
| 84 | | - link->no_pcm = 1; |
|---|
| 85 | | - link->ignore_pmdown_time = 1; |
|---|
| 124 | + |
|---|
| 125 | + if (platform) { |
|---|
| 126 | + /* DPCM backend */ |
|---|
| 127 | + link->no_pcm = 1; |
|---|
| 128 | + link->ignore_pmdown_time = 1; |
|---|
| 129 | + } |
|---|
| 86 | 130 | } else { |
|---|
| 87 | | - link->platform_of_node = link->cpu_of_node; |
|---|
| 88 | | - link->codec_dai_name = "snd-soc-dummy-dai"; |
|---|
| 89 | | - link->codec_name = "snd-soc-dummy"; |
|---|
| 131 | + /* DPCM frontend */ |
|---|
| 132 | + dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL); |
|---|
| 133 | + if (!dlc) { |
|---|
| 134 | + ret = -ENOMEM; |
|---|
| 135 | + goto err; |
|---|
| 136 | + } |
|---|
| 137 | + |
|---|
| 138 | + link->codecs = dlc; |
|---|
| 139 | + link->num_codecs = 1; |
|---|
| 140 | + |
|---|
| 141 | + link->codecs->dai_name = "snd-soc-dummy-dai"; |
|---|
| 142 | + link->codecs->name = "snd-soc-dummy"; |
|---|
| 90 | 143 | link->dynamic = 1; |
|---|
| 91 | 144 | } |
|---|
| 92 | 145 | |
|---|
| 93 | | - link->ignore_suspend = 1; |
|---|
| 94 | | - ret = of_property_read_string(np, "link-name", &link->name); |
|---|
| 95 | | - if (ret) { |
|---|
| 96 | | - dev_err(card->dev, "error getting codec dai_link name\n"); |
|---|
| 97 | | - goto err; |
|---|
| 146 | + if (platform || !codec) { |
|---|
| 147 | + /* DPCM */ |
|---|
| 148 | + snd_soc_dai_link_set_capabilities(link); |
|---|
| 149 | + link->ignore_suspend = 1; |
|---|
| 150 | + link->nonatomic = 1; |
|---|
| 98 | 151 | } |
|---|
| 99 | 152 | |
|---|
| 100 | | - link->dpcm_playback = 1; |
|---|
| 101 | | - link->dpcm_capture = 1; |
|---|
| 102 | 153 | link->stream_name = link->name; |
|---|
| 103 | 154 | link++; |
|---|
| 104 | 155 | |
|---|
| .. | .. |
|---|
| 109 | 160 | |
|---|
| 110 | 161 | return 0; |
|---|
| 111 | 162 | err: |
|---|
| 112 | | - of_node_put(np); |
|---|
| 113 | 163 | of_node_put(cpu); |
|---|
| 114 | 164 | of_node_put(codec); |
|---|
| 115 | 165 | of_node_put(platform); |
|---|
| 116 | | - kfree(card->dai_link); |
|---|
| 166 | +err_put_np: |
|---|
| 167 | + of_node_put(np); |
|---|
| 117 | 168 | return ret; |
|---|
| 118 | 169 | } |
|---|
| 119 | 170 | EXPORT_SYMBOL(qcom_snd_parse_of); |
|---|