Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | // Copyright (c) 2018, Linaro Limited. |
| 3 | // Copyright (c) 2018, The Linux Foundation. All rights reserved. |
| 4 | |
| 5 | #include <linux/module.h> |
| 6 | #include "common.h" |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 7 | #include "qdsp6/q6afe.h" |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 8 | |
| 9 | int qcom_snd_parse_of(struct snd_soc_card *card) |
| 10 | { |
| 11 | struct device_node *np; |
| 12 | struct device_node *codec = NULL; |
| 13 | struct device_node *platform = NULL; |
| 14 | struct device_node *cpu = NULL; |
| 15 | struct device *dev = card->dev; |
| 16 | struct snd_soc_dai_link *link; |
| 17 | struct of_phandle_args args; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 18 | struct snd_soc_dai_link_component *dlc; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 19 | int ret, num_links; |
| 20 | |
| 21 | ret = snd_soc_of_parse_card_name(card, "model"); |
| 22 | if (ret) { |
| 23 | dev_err(dev, "Error parsing card name: %d\n", ret); |
| 24 | return ret; |
| 25 | } |
| 26 | |
| 27 | /* DAPM routes */ |
| 28 | if (of_property_read_bool(dev->of_node, "audio-routing")) { |
| 29 | ret = snd_soc_of_parse_audio_routing(card, |
| 30 | "audio-routing"); |
| 31 | if (ret) |
| 32 | return ret; |
| 33 | } |
| 34 | |
| 35 | /* Populate links */ |
| 36 | num_links = of_get_child_count(dev->of_node); |
| 37 | |
| 38 | /* Allocate the DAI link array */ |
| 39 | card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL); |
| 40 | if (!card->dai_link) |
| 41 | return -ENOMEM; |
| 42 | |
| 43 | card->num_links = num_links; |
| 44 | link = card->dai_link; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 45 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 46 | for_each_child_of_node(dev->of_node, np) { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 47 | dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL); |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 48 | if (!dlc) { |
| 49 | ret = -ENOMEM; |
| 50 | goto err; |
| 51 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 52 | |
| 53 | link->cpus = &dlc[0]; |
| 54 | link->platforms = &dlc[1]; |
| 55 | |
| 56 | link->num_cpus = 1; |
| 57 | link->num_platforms = 1; |
| 58 | |
| 59 | ret = of_property_read_string(np, "link-name", &link->name); |
| 60 | if (ret) { |
| 61 | dev_err(card->dev, "error getting codec dai_link name\n"); |
| 62 | goto err; |
| 63 | } |
| 64 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 65 | cpu = of_get_child_by_name(np, "cpu"); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 66 | platform = of_get_child_by_name(np, "platform"); |
| 67 | codec = of_get_child_by_name(np, "codec"); |
| 68 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 69 | if (!cpu) { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 70 | dev_err(dev, "%s: Can't find cpu DT node\n", link->name); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 71 | ret = -EINVAL; |
| 72 | goto err; |
| 73 | } |
| 74 | |
| 75 | ret = of_parse_phandle_with_args(cpu, "sound-dai", |
| 76 | "#sound-dai-cells", 0, &args); |
| 77 | if (ret) { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 78 | dev_err(card->dev, "%s: error getting cpu phandle\n", link->name); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 79 | goto err; |
| 80 | } |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 81 | link->cpus->of_node = args.np; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 82 | link->id = args.args[0]; |
| 83 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 84 | ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 85 | if (ret) { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 86 | dev_err(card->dev, "%s: error getting cpu dai name\n", link->name); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 87 | goto err; |
| 88 | } |
| 89 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 90 | if (codec && platform) { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 91 | link->platforms->of_node = of_parse_phandle(platform, |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 92 | "sound-dai", |
| 93 | 0); |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 94 | if (!link->platforms->of_node) { |
| 95 | dev_err(card->dev, "%s: platform dai not found\n", link->name); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 96 | ret = -EINVAL; |
| 97 | goto err; |
| 98 | } |
| 99 | |
| 100 | ret = snd_soc_of_get_dai_link_codecs(dev, codec, link); |
| 101 | if (ret < 0) { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 102 | dev_err(card->dev, "%s: codec dai not found\n", link->name); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 103 | goto err; |
| 104 | } |
| 105 | link->no_pcm = 1; |
| 106 | link->ignore_pmdown_time = 1; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 107 | |
| 108 | if (q6afe_is_rx_port(link->id)) { |
| 109 | link->dpcm_playback = 1; |
| 110 | link->dpcm_capture = 0; |
| 111 | } else { |
| 112 | link->dpcm_playback = 0; |
| 113 | link->dpcm_capture = 1; |
| 114 | } |
| 115 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 116 | } else { |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 117 | dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL); |
| 118 | if (!dlc) |
| 119 | return -ENOMEM; |
| 120 | |
| 121 | link->codecs = dlc; |
| 122 | link->num_codecs = 1; |
| 123 | |
| 124 | link->platforms->of_node = link->cpus->of_node; |
| 125 | link->codecs->dai_name = "snd-soc-dummy-dai"; |
| 126 | link->codecs->name = "snd-soc-dummy"; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 127 | link->dynamic = 1; |
Olivier Deprez | 0e64123 | 2021-09-23 10:07:05 +0200 | [diff] [blame^] | 128 | link->dpcm_playback = 1; |
| 129 | link->dpcm_capture = 1; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | link->ignore_suspend = 1; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 133 | link->nonatomic = 1; |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 134 | link->stream_name = link->name; |
| 135 | link++; |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 136 | |
| 137 | of_node_put(cpu); |
| 138 | of_node_put(codec); |
| 139 | of_node_put(platform); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | return 0; |
| 143 | err: |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame] | 144 | of_node_put(np); |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 145 | of_node_put(cpu); |
| 146 | of_node_put(codec); |
| 147 | of_node_put(platform); |
| 148 | kfree(card->dai_link); |
| 149 | return ret; |
| 150 | } |
| 151 | EXPORT_SYMBOL(qcom_snd_parse_of); |
| 152 | |
| 153 | MODULE_LICENSE("GPL v2"); |