Skip to content

Commit aa2d1ee

Browse files
committed
Merge series "ASoC: qcom: Use qcom_snd_parse_of() for apq8016_sbc" from Stephan Gerhold <[email protected]>:
At the moment we have two separate functions to parse the sound card properties from the device tree: qcom_snd_parse_of() for DPCM and apq8016_sbc_parse_of() without DPCM. These functions are almost identical except for a few minor differences. This patch set extends qcom_snd_parse_of() to handle links without DPCM, so that we can use one common function for all (qcom) machine drivers. Stephan Gerhold (7): ASoC: qcom: Use devm for resource management ASoC: qcom: common: Use snd_soc_dai_link_set_capabilities() ASoC: q6afe: Remove unused q6afe_is_rx_port() function ASoC: qcom: common: Support parsing links without DPCM ASoC: qcom: common: Parse properties with "qcom," prefix ASoC: qcom: apq8016_sbc: Use qcom_snd_parse_of() ASoC: qcom: common: Avoid printing errors for -EPROBE_DEFER sound/soc/qcom/Kconfig | 1 + sound/soc/qcom/apq8016_sbc.c | 120 ++++------------------------------- sound/soc/qcom/apq8096.c | 28 +------- sound/soc/qcom/common.c | 58 ++++++++++------- sound/soc/qcom/qdsp6/q6afe.c | 8 --- sound/soc/qcom/qdsp6/q6afe.h | 1 - sound/soc/qcom/sdm845.c | 40 ++---------- 7 files changed, 59 insertions(+), 197 deletions(-) -- 2.27.0
2 parents 62f2c77 + a63419b commit aa2d1ee

File tree

7 files changed

+59
-197
lines changed

7 files changed

+59
-197
lines changed

sound/soc/qcom/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ config SND_SOC_APQ8016_SBC
3737
tristate "SoC Audio support for APQ8016 SBC platforms"
3838
depends on SND_SOC_QCOM
3939
select SND_SOC_LPASS_APQ8016
40+
select SND_SOC_QCOM_COMMON
4041
help
4142
Support for Qualcomm Technologies LPASS audio block in
4243
APQ8016 SOC-based systems.

sound/soc/qcom/apq8016_sbc.c

Lines changed: 14 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
#include <sound/soc.h>
1717
#include <uapi/linux/input-event-codes.h>
1818
#include <dt-bindings/sound/apq8016-lpass.h>
19+
#include "common.h"
1920

2021
struct apq8016_sbc_data {
22+
struct snd_soc_card card;
2123
void __iomem *mic_iomux;
2224
void __iomem *spkr_iomux;
2325
struct snd_soc_jack jack;
2426
bool jack_setup;
25-
struct snd_soc_dai_link dai_link[]; /* dynamically allocated */
2627
};
2728

2829
#define MIC_CTRL_TER_WS_SLAVE_SEL BIT(21)
@@ -110,107 +111,13 @@ static int apq8016_sbc_dai_init(struct snd_soc_pcm_runtime *rtd)
110111
return 0;
111112
}
112113

113-
static struct apq8016_sbc_data *apq8016_sbc_parse_of(struct snd_soc_card *card)
114+
static void apq8016_sbc_add_ops(struct snd_soc_card *card)
114115
{
115-
struct device *dev = card->dev;
116116
struct snd_soc_dai_link *link;
117-
struct device_node *np, *codec, *cpu, *node = dev->of_node;
118-
struct apq8016_sbc_data *data;
119-
struct snd_soc_dai_link_component *dlc;
120-
int ret, num_links;
121-
122-
ret = snd_soc_of_parse_card_name(card, "qcom,model");
123-
if (ret) {
124-
dev_err(dev, "Error parsing card name: %d\n", ret);
125-
return ERR_PTR(ret);
126-
}
127-
128-
/* DAPM routes */
129-
if (of_property_read_bool(node, "qcom,audio-routing")) {
130-
ret = snd_soc_of_parse_audio_routing(card,
131-
"qcom,audio-routing");
132-
if (ret)
133-
return ERR_PTR(ret);
134-
}
135-
136-
137-
/* Populate links */
138-
num_links = of_get_child_count(node);
139-
140-
/* Allocate the private data and the DAI link array */
141-
data = devm_kzalloc(dev,
142-
struct_size(data, dai_link, num_links),
143-
GFP_KERNEL);
144-
if (!data)
145-
return ERR_PTR(-ENOMEM);
146-
147-
card->dai_link = &data->dai_link[0];
148-
card->num_links = num_links;
149-
150-
link = data->dai_link;
151-
152-
for_each_child_of_node(node, np) {
153-
dlc = devm_kzalloc(dev, 2 * sizeof(*dlc), GFP_KERNEL);
154-
if (!dlc)
155-
return ERR_PTR(-ENOMEM);
156-
157-
link->cpus = &dlc[0];
158-
link->platforms = &dlc[1];
159-
160-
link->num_cpus = 1;
161-
link->num_platforms = 1;
162-
163-
cpu = of_get_child_by_name(np, "cpu");
164-
codec = of_get_child_by_name(np, "codec");
165-
166-
if (!cpu || !codec) {
167-
dev_err(dev, "Can't find cpu/codec DT node\n");
168-
ret = -EINVAL;
169-
goto error;
170-
}
117+
int i;
171118

172-
link->cpus->of_node = of_parse_phandle(cpu, "sound-dai", 0);
173-
if (!link->cpus->of_node) {
174-
dev_err(card->dev, "error getting cpu phandle\n");
175-
ret = -EINVAL;
176-
goto error;
177-
}
178-
179-
ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name);
180-
if (ret) {
181-
dev_err(card->dev, "error getting cpu dai name\n");
182-
goto error;
183-
}
184-
185-
ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
186-
187-
if (ret < 0) {
188-
dev_err(card->dev, "error getting codec dai name\n");
189-
goto error;
190-
}
191-
192-
link->platforms->of_node = link->cpus->of_node;
193-
ret = of_property_read_string(np, "link-name", &link->name);
194-
if (ret) {
195-
dev_err(card->dev, "error getting codec dai_link name\n");
196-
goto error;
197-
}
198-
199-
link->stream_name = link->name;
119+
for_each_card_prelinks(card, i, link)
200120
link->init = apq8016_sbc_dai_init;
201-
link++;
202-
203-
of_node_put(cpu);
204-
of_node_put(codec);
205-
}
206-
207-
return data;
208-
209-
error:
210-
of_node_put(np);
211-
of_node_put(cpu);
212-
of_node_put(codec);
213-
return ERR_PTR(ret);
214121
}
215122

216123
static const struct snd_soc_dapm_widget apq8016_sbc_dapm_widgets[] = {
@@ -228,20 +135,20 @@ static int apq8016_sbc_platform_probe(struct platform_device *pdev)
228135
struct snd_soc_card *card;
229136
struct apq8016_sbc_data *data;
230137
struct resource *res;
138+
int ret;
231139

232-
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
233-
if (!card)
140+
data = devm_kzalloc(dev, sizeof(*data), GFP_KERNEL);
141+
if (!data)
234142
return -ENOMEM;
235143

144+
card = &data->card;
236145
card->dev = dev;
237146
card->dapm_widgets = apq8016_sbc_dapm_widgets;
238147
card->num_dapm_widgets = ARRAY_SIZE(apq8016_sbc_dapm_widgets);
239-
data = apq8016_sbc_parse_of(card);
240-
if (IS_ERR(data)) {
241-
dev_err(&pdev->dev, "Error resolving dai links: %ld\n",
242-
PTR_ERR(data));
243-
return PTR_ERR(data);
244-
}
148+
149+
ret = qcom_snd_parse_of(card);
150+
if (ret)
151+
return ret;
245152

246153
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mic-iomux");
247154
data->mic_iomux = devm_ioremap_resource(dev, res);
@@ -255,6 +162,7 @@ static int apq8016_sbc_platform_probe(struct platform_device *pdev)
255162

256163
snd_soc_card_set_drvdata(card, data);
257164

165+
apq8016_sbc_add_ops(card);
258166
return devm_snd_soc_register_card(&pdev->dev, card);
259167
}
260168

sound/soc/qcom/apq8096.c

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -109,39 +109,18 @@ static int apq8096_platform_probe(struct platform_device *pdev)
109109
struct device *dev = &pdev->dev;
110110
int ret;
111111

112-
card = kzalloc(sizeof(*card), GFP_KERNEL);
112+
card = devm_kzalloc(dev, sizeof(*card), GFP_KERNEL);
113113
if (!card)
114114
return -ENOMEM;
115115

116116
card->dev = dev;
117117
dev_set_drvdata(dev, card);
118118
ret = qcom_snd_parse_of(card);
119119
if (ret)
120-
goto err;
120+
return ret;
121121

122122
apq8096_add_be_ops(card);
123-
ret = snd_soc_register_card(card);
124-
if (ret)
125-
goto err_card_register;
126-
127-
return 0;
128-
129-
err_card_register:
130-
kfree(card->dai_link);
131-
err:
132-
kfree(card);
133-
return ret;
134-
}
135-
136-
static int apq8096_platform_remove(struct platform_device *pdev)
137-
{
138-
struct snd_soc_card *card = dev_get_drvdata(&pdev->dev);
139-
140-
snd_soc_unregister_card(card);
141-
kfree(card->dai_link);
142-
kfree(card);
143-
144-
return 0;
123+
return devm_snd_soc_register_card(dev, card);
145124
}
146125

147126
static const struct of_device_id msm_snd_apq8096_dt_match[] = {
@@ -153,7 +132,6 @@ MODULE_DEVICE_TABLE(of, msm_snd_apq8096_dt_match);
153132

154133
static struct platform_driver msm_snd_apq8096_driver = {
155134
.probe = apq8096_platform_probe,
156-
.remove = apq8096_platform_remove,
157135
.driver = {
158136
.name = "msm-snd-apq8096",
159137
.of_match_table = msm_snd_apq8096_dt_match,

sound/soc/qcom/common.c

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
#include <linux/module.h>
66
#include "common.h"
7-
#include "qdsp6/q6afe.h"
87

98
int qcom_snd_parse_of(struct snd_soc_card *card)
109
{
@@ -19,15 +18,23 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
1918
int ret, num_links;
2019

2120
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");
2224
if (ret) {
2325
dev_err(dev, "Error parsing card name: %d\n", ret);
2426
return ret;
2527
}
2628

2729
/* DAPM routes */
2830
if (of_property_read_bool(dev->of_node, "audio-routing")) {
29-
ret = snd_soc_of_parse_audio_routing(card,
30-
"audio-routing");
31+
ret = snd_soc_of_parse_audio_routing(card, "audio-routing");
32+
if (ret)
33+
return ret;
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");
3138
if (ret)
3239
return ret;
3340
}
@@ -36,7 +43,7 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
3643
num_links = of_get_child_count(dev->of_node);
3744

3845
/* Allocate the DAI link array */
39-
card->dai_link = kcalloc(num_links, sizeof(*link), GFP_KERNEL);
46+
card->dai_link = devm_kcalloc(dev, num_links, sizeof(*link), GFP_KERNEL);
4047
if (!card->dai_link)
4148
return -ENOMEM;
4249

@@ -81,11 +88,13 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
8188

8289
ret = snd_soc_of_get_dai_name(cpu, &link->cpus->dai_name);
8390
if (ret) {
84-
dev_err(card->dev, "%s: error getting cpu dai name\n", link->name);
91+
if (ret != -EPROBE_DEFER)
92+
dev_err(card->dev, "%s: error getting cpu dai name: %d\n",
93+
link->name, ret);
8594
goto err;
8695
}
8796

88-
if (codec && platform) {
97+
if (platform) {
8998
link->platforms->of_node = of_parse_phandle(platform,
9099
"sound-dai",
91100
0);
@@ -94,41 +103,45 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
94103
ret = -EINVAL;
95104
goto err;
96105
}
106+
} else {
107+
link->platforms->of_node = link->cpus->of_node;
108+
}
97109

110+
if (codec) {
98111
ret = snd_soc_of_get_dai_link_codecs(dev, codec, link);
99112
if (ret < 0) {
100-
dev_err(card->dev, "%s: codec dai not found\n", link->name);
113+
if (ret != -EPROBE_DEFER)
114+
dev_err(card->dev, "%s: codec dai not found: %d\n",
115+
link->name, ret);
101116
goto err;
102117
}
103-
link->no_pcm = 1;
104-
link->ignore_pmdown_time = 1;
105-
106-
if (q6afe_is_rx_port(link->id)) {
107-
link->dpcm_playback = 1;
108-
link->dpcm_capture = 0;
109-
} else {
110-
link->dpcm_playback = 0;
111-
link->dpcm_capture = 1;
112-
}
113118

119+
if (platform) {
120+
/* DPCM backend */
121+
link->no_pcm = 1;
122+
link->ignore_pmdown_time = 1;
123+
}
114124
} else {
125+
/* DPCM frontend */
115126
dlc = devm_kzalloc(dev, sizeof(*dlc), GFP_KERNEL);
116127
if (!dlc)
117128
return -ENOMEM;
118129

119130
link->codecs = dlc;
120131
link->num_codecs = 1;
121132

122-
link->platforms->of_node = link->cpus->of_node;
123133
link->codecs->dai_name = "snd-soc-dummy-dai";
124134
link->codecs->name = "snd-soc-dummy";
125135
link->dynamic = 1;
126-
link->dpcm_playback = 1;
127-
link->dpcm_capture = 1;
128136
}
129137

130-
link->ignore_suspend = 1;
131-
link->nonatomic = 1;
138+
if (platform || !codec) {
139+
/* DPCM */
140+
snd_soc_dai_link_set_capabilities(link);
141+
link->ignore_suspend = 1;
142+
link->nonatomic = 1;
143+
}
144+
132145
link->stream_name = link->name;
133146
link++;
134147

@@ -143,7 +156,6 @@ int qcom_snd_parse_of(struct snd_soc_card *card)
143156
of_node_put(cpu);
144157
of_node_put(codec);
145158
of_node_put(platform);
146-
kfree(card->dai_link);
147159
return ret;
148160
}
149161
EXPORT_SYMBOL(qcom_snd_parse_of);

sound/soc/qcom/qdsp6/q6afe.c

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -800,14 +800,6 @@ int q6afe_get_port_id(int index)
800800
}
801801
EXPORT_SYMBOL_GPL(q6afe_get_port_id);
802802

803-
int q6afe_is_rx_port(int index)
804-
{
805-
if (index < 0 || index >= AFE_PORT_MAX)
806-
return -EINVAL;
807-
808-
return port_maps[index].is_rx;
809-
}
810-
EXPORT_SYMBOL_GPL(q6afe_is_rx_port);
811803
static int afe_apr_send_pkt(struct q6afe *afe, struct apr_pkt *pkt,
812804
struct q6afe_port *port)
813805
{

sound/soc/qcom/qdsp6/q6afe.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,6 @@ int q6afe_port_start(struct q6afe_port *port);
198198
int q6afe_port_stop(struct q6afe_port *port);
199199
void q6afe_port_put(struct q6afe_port *port);
200200
int q6afe_get_port_id(int index);
201-
int q6afe_is_rx_port(int index);
202201
void q6afe_hdmi_port_prepare(struct q6afe_port *port,
203202
struct q6afe_hdmi_cfg *cfg);
204203
void q6afe_slim_port_prepare(struct q6afe_port *port,

0 commit comments

Comments
 (0)