Skip to content

Commit 118205d

Browse files
stephan-ghbroonie
authored andcommitted
ASoC: qcom: apq8016_sbc: Use qcom_snd_parse_of()
Now that we have updated qcom_snd_parse_of() to handle the device tree bindings used for apq8016_sbc, update the apq8016_sbc driver to use the common function and remove the duplicated code. Signed-off-by: Stephan Gerhold <[email protected]> Tested-by: Srinivas Kandagatla <[email protected]> Reviewed-by: Srinivas Kandagatla <[email protected]> Cc: Srinivas Kandagatla <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent f0d67fd commit 118205d

File tree

2 files changed

+15
-106
lines changed

2 files changed

+15
-106
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

0 commit comments

Comments
 (0)