]>
Commit | Line | Data |
---|---|---|
8a978234 LG |
1 | /* |
2 | * soc-topology.c -- ALSA SoC Topology | |
3 | * | |
4 | * Copyright (C) 2012 Texas Instruments Inc. | |
5 | * Copyright (C) 2015 Intel Corporation. | |
6 | * | |
7 | * Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com> | |
8 | * K, Mythri P <mythri.p.k@intel.com> | |
9 | * Prusty, Subhransu S <subhransu.s.prusty@intel.com> | |
10 | * B, Jayachandran <jayachandran.b@intel.com> | |
11 | * Abdullah, Omair M <omair.m.abdullah@intel.com> | |
12 | * Jin, Yao <yao.jin@intel.com> | |
13 | * Lin, Mengdong <mengdong.lin@intel.com> | |
14 | * | |
15 | * This program is free software; you can redistribute it and/or modify it | |
16 | * under the terms of the GNU General Public License as published by the | |
17 | * Free Software Foundation; either version 2 of the License, or (at your | |
18 | * option) any later version. | |
19 | * | |
20 | * Add support to read audio firmware topology alongside firmware text. The | |
21 | * topology data can contain kcontrols, DAPM graphs, widgets, DAIs, DAI links, | |
22 | * equalizers, firmware, coefficients etc. | |
23 | * | |
24 | * This file only manages the core ALSA and ASoC components, all other bespoke | |
25 | * firmware topology data is passed to component drivers for bespoke handling. | |
26 | */ | |
27 | ||
28 | #include <linux/kernel.h> | |
29 | #include <linux/export.h> | |
30 | #include <linux/list.h> | |
31 | #include <linux/firmware.h> | |
32 | #include <linux/slab.h> | |
33 | #include <sound/soc.h> | |
34 | #include <sound/soc-dapm.h> | |
35 | #include <sound/soc-topology.h> | |
28a87eeb | 36 | #include <sound/tlv.h> |
8a978234 LG |
37 | |
38 | /* | |
39 | * We make several passes over the data (since it wont necessarily be ordered) | |
40 | * and process objects in the following order. This guarantees the component | |
41 | * drivers will be ready with any vendor data before the mixers and DAPM objects | |
42 | * are loaded (that may make use of the vendor data). | |
43 | */ | |
44 | #define SOC_TPLG_PASS_MANIFEST 0 | |
45 | #define SOC_TPLG_PASS_VENDOR 1 | |
46 | #define SOC_TPLG_PASS_MIXER 2 | |
47 | #define SOC_TPLG_PASS_WIDGET 3 | |
1a8e7fab ML |
48 | #define SOC_TPLG_PASS_PCM_DAI 4 |
49 | #define SOC_TPLG_PASS_GRAPH 5 | |
50 | #define SOC_TPLG_PASS_PINS 6 | |
0038be9a | 51 | #define SOC_TPLG_PASS_BE_DAI 7 |
593d9e52 | 52 | #define SOC_TPLG_PASS_LINK 8 |
8a978234 LG |
53 | |
54 | #define SOC_TPLG_PASS_START SOC_TPLG_PASS_MANIFEST | |
593d9e52 | 55 | #define SOC_TPLG_PASS_END SOC_TPLG_PASS_LINK |
8a978234 | 56 | |
583958fa ML |
57 | /* |
58 | * Old version of ABI structs, supported for backward compatibility. | |
59 | */ | |
60 | ||
61 | /* Manifest v4 */ | |
62 | struct snd_soc_tplg_manifest_v4 { | |
63 | __le32 size; /* in bytes of this structure */ | |
64 | __le32 control_elems; /* number of control elements */ | |
65 | __le32 widget_elems; /* number of widget elements */ | |
66 | __le32 graph_elems; /* number of graph elements */ | |
67 | __le32 pcm_elems; /* number of PCM elements */ | |
68 | __le32 dai_link_elems; /* number of DAI link elements */ | |
69 | struct snd_soc_tplg_private priv; | |
70 | } __packed; | |
71 | ||
55726dc9 ML |
72 | /* Stream Capabilities v4 */ |
73 | struct snd_soc_tplg_stream_caps_v4 { | |
74 | __le32 size; /* in bytes of this structure */ | |
75 | char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | |
76 | __le64 formats; /* supported formats SNDRV_PCM_FMTBIT_* */ | |
77 | __le32 rates; /* supported rates SNDRV_PCM_RATE_* */ | |
78 | __le32 rate_min; /* min rate */ | |
79 | __le32 rate_max; /* max rate */ | |
80 | __le32 channels_min; /* min channels */ | |
81 | __le32 channels_max; /* max channels */ | |
82 | __le32 periods_min; /* min number of periods */ | |
83 | __le32 periods_max; /* max number of periods */ | |
84 | __le32 period_size_min; /* min period size bytes */ | |
85 | __le32 period_size_max; /* max period size bytes */ | |
86 | __le32 buffer_size_min; /* min buffer size bytes */ | |
87 | __le32 buffer_size_max; /* max buffer size bytes */ | |
88 | } __packed; | |
89 | ||
90 | /* PCM v4 */ | |
91 | struct snd_soc_tplg_pcm_v4 { | |
92 | __le32 size; /* in bytes of this structure */ | |
93 | char pcm_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | |
94 | char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; | |
95 | __le32 pcm_id; /* unique ID - used to match with DAI link */ | |
96 | __le32 dai_id; /* unique ID - used to match */ | |
97 | __le32 playback; /* supports playback mode */ | |
98 | __le32 capture; /* supports capture mode */ | |
99 | __le32 compress; /* 1 = compressed; 0 = PCM */ | |
100 | struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* for DAI link */ | |
101 | __le32 num_streams; /* number of streams */ | |
102 | struct snd_soc_tplg_stream_caps_v4 caps[2]; /* playback and capture for DAI */ | |
103 | } __packed; | |
104 | ||
593d9e52 ML |
105 | /* Physical link config v4 */ |
106 | struct snd_soc_tplg_link_config_v4 { | |
107 | __le32 size; /* in bytes of this structure */ | |
108 | __le32 id; /* unique ID - used to match */ | |
109 | struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */ | |
110 | __le32 num_streams; /* number of streams */ | |
111 | } __packed; | |
112 | ||
583958fa | 113 | /* topology context */ |
8a978234 LG |
114 | struct soc_tplg { |
115 | const struct firmware *fw; | |
116 | ||
117 | /* runtime FW parsing */ | |
118 | const u8 *pos; /* read postion */ | |
119 | const u8 *hdr_pos; /* header position */ | |
120 | unsigned int pass; /* pass number */ | |
121 | ||
122 | /* component caller */ | |
123 | struct device *dev; | |
124 | struct snd_soc_component *comp; | |
125 | u32 index; /* current block index */ | |
126 | u32 req_index; /* required index, only loaded/free matching blocks */ | |
127 | ||
88a17d8f | 128 | /* vendor specific kcontrol operations */ |
8a978234 LG |
129 | const struct snd_soc_tplg_kcontrol_ops *io_ops; |
130 | int io_ops_count; | |
131 | ||
1a3232d2 ML |
132 | /* vendor specific bytes ext handlers, for TLV bytes controls */ |
133 | const struct snd_soc_tplg_bytes_ext_ops *bytes_ext_ops; | |
134 | int bytes_ext_ops_count; | |
135 | ||
8a978234 LG |
136 | /* optional fw loading callbacks to component drivers */ |
137 | struct snd_soc_tplg_ops *ops; | |
138 | }; | |
139 | ||
140 | static int soc_tplg_process_headers(struct soc_tplg *tplg); | |
141 | static void soc_tplg_complete(struct soc_tplg *tplg); | |
142 | struct snd_soc_dapm_widget * | |
143 | snd_soc_dapm_new_control_unlocked(struct snd_soc_dapm_context *dapm, | |
144 | const struct snd_soc_dapm_widget *widget); | |
145 | struct snd_soc_dapm_widget * | |
146 | snd_soc_dapm_new_control(struct snd_soc_dapm_context *dapm, | |
147 | const struct snd_soc_dapm_widget *widget); | |
148 | ||
149 | /* check we dont overflow the data for this control chunk */ | |
150 | static int soc_tplg_check_elem_count(struct soc_tplg *tplg, size_t elem_size, | |
151 | unsigned int count, size_t bytes, const char *elem_type) | |
152 | { | |
153 | const u8 *end = tplg->pos + elem_size * count; | |
154 | ||
155 | if (end > tplg->fw->data + tplg->fw->size) { | |
156 | dev_err(tplg->dev, "ASoC: %s overflow end of data\n", | |
157 | elem_type); | |
158 | return -EINVAL; | |
159 | } | |
160 | ||
161 | /* check there is enough room in chunk for control. | |
162 | extra bytes at the end of control are for vendor data here */ | |
163 | if (elem_size * count > bytes) { | |
164 | dev_err(tplg->dev, | |
165 | "ASoC: %s count %d of size %zu is bigger than chunk %zu\n", | |
166 | elem_type, count, elem_size, bytes); | |
167 | return -EINVAL; | |
168 | } | |
169 | ||
170 | return 0; | |
171 | } | |
172 | ||
173 | static inline int soc_tplg_is_eof(struct soc_tplg *tplg) | |
174 | { | |
175 | const u8 *end = tplg->hdr_pos; | |
176 | ||
177 | if (end >= tplg->fw->data + tplg->fw->size) | |
178 | return 1; | |
179 | return 0; | |
180 | } | |
181 | ||
182 | static inline unsigned long soc_tplg_get_hdr_offset(struct soc_tplg *tplg) | |
183 | { | |
184 | return (unsigned long)(tplg->hdr_pos - tplg->fw->data); | |
185 | } | |
186 | ||
187 | static inline unsigned long soc_tplg_get_offset(struct soc_tplg *tplg) | |
188 | { | |
189 | return (unsigned long)(tplg->pos - tplg->fw->data); | |
190 | } | |
191 | ||
192 | /* mapping of Kcontrol types and associated operations. */ | |
193 | static const struct snd_soc_tplg_kcontrol_ops io_ops[] = { | |
194 | {SND_SOC_TPLG_CTL_VOLSW, snd_soc_get_volsw, | |
195 | snd_soc_put_volsw, snd_soc_info_volsw}, | |
196 | {SND_SOC_TPLG_CTL_VOLSW_SX, snd_soc_get_volsw_sx, | |
197 | snd_soc_put_volsw_sx, NULL}, | |
198 | {SND_SOC_TPLG_CTL_ENUM, snd_soc_get_enum_double, | |
199 | snd_soc_put_enum_double, snd_soc_info_enum_double}, | |
200 | {SND_SOC_TPLG_CTL_ENUM_VALUE, snd_soc_get_enum_double, | |
201 | snd_soc_put_enum_double, NULL}, | |
202 | {SND_SOC_TPLG_CTL_BYTES, snd_soc_bytes_get, | |
203 | snd_soc_bytes_put, snd_soc_bytes_info}, | |
204 | {SND_SOC_TPLG_CTL_RANGE, snd_soc_get_volsw_range, | |
205 | snd_soc_put_volsw_range, snd_soc_info_volsw_range}, | |
206 | {SND_SOC_TPLG_CTL_VOLSW_XR_SX, snd_soc_get_xr_sx, | |
207 | snd_soc_put_xr_sx, snd_soc_info_xr_sx}, | |
208 | {SND_SOC_TPLG_CTL_STROBE, snd_soc_get_strobe, | |
209 | snd_soc_put_strobe, NULL}, | |
210 | {SND_SOC_TPLG_DAPM_CTL_VOLSW, snd_soc_dapm_get_volsw, | |
2c57d478 | 211 | snd_soc_dapm_put_volsw, snd_soc_info_volsw}, |
8a978234 LG |
212 | {SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE, snd_soc_dapm_get_enum_double, |
213 | snd_soc_dapm_put_enum_double, snd_soc_info_enum_double}, | |
214 | {SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT, snd_soc_dapm_get_enum_double, | |
215 | snd_soc_dapm_put_enum_double, NULL}, | |
216 | {SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE, snd_soc_dapm_get_enum_double, | |
217 | snd_soc_dapm_put_enum_double, NULL}, | |
218 | {SND_SOC_TPLG_DAPM_CTL_PIN, snd_soc_dapm_get_pin_switch, | |
219 | snd_soc_dapm_put_pin_switch, snd_soc_dapm_info_pin_switch}, | |
220 | }; | |
221 | ||
222 | struct soc_tplg_map { | |
223 | int uid; | |
224 | int kid; | |
225 | }; | |
226 | ||
227 | /* mapping of widget types from UAPI IDs to kernel IDs */ | |
228 | static const struct soc_tplg_map dapm_map[] = { | |
229 | {SND_SOC_TPLG_DAPM_INPUT, snd_soc_dapm_input}, | |
230 | {SND_SOC_TPLG_DAPM_OUTPUT, snd_soc_dapm_output}, | |
231 | {SND_SOC_TPLG_DAPM_MUX, snd_soc_dapm_mux}, | |
232 | {SND_SOC_TPLG_DAPM_MIXER, snd_soc_dapm_mixer}, | |
233 | {SND_SOC_TPLG_DAPM_PGA, snd_soc_dapm_pga}, | |
234 | {SND_SOC_TPLG_DAPM_OUT_DRV, snd_soc_dapm_out_drv}, | |
235 | {SND_SOC_TPLG_DAPM_ADC, snd_soc_dapm_adc}, | |
236 | {SND_SOC_TPLG_DAPM_DAC, snd_soc_dapm_dac}, | |
237 | {SND_SOC_TPLG_DAPM_SWITCH, snd_soc_dapm_switch}, | |
238 | {SND_SOC_TPLG_DAPM_PRE, snd_soc_dapm_pre}, | |
239 | {SND_SOC_TPLG_DAPM_POST, snd_soc_dapm_post}, | |
240 | {SND_SOC_TPLG_DAPM_AIF_IN, snd_soc_dapm_aif_in}, | |
241 | {SND_SOC_TPLG_DAPM_AIF_OUT, snd_soc_dapm_aif_out}, | |
242 | {SND_SOC_TPLG_DAPM_DAI_IN, snd_soc_dapm_dai_in}, | |
243 | {SND_SOC_TPLG_DAPM_DAI_OUT, snd_soc_dapm_dai_out}, | |
244 | {SND_SOC_TPLG_DAPM_DAI_LINK, snd_soc_dapm_dai_link}, | |
245 | }; | |
246 | ||
247 | static int tplc_chan_get_reg(struct soc_tplg *tplg, | |
248 | struct snd_soc_tplg_channel *chan, int map) | |
249 | { | |
250 | int i; | |
251 | ||
252 | for (i = 0; i < SND_SOC_TPLG_MAX_CHAN; i++) { | |
253 | if (chan[i].id == map) | |
254 | return chan[i].reg; | |
255 | } | |
256 | ||
257 | return -EINVAL; | |
258 | } | |
259 | ||
260 | static int tplc_chan_get_shift(struct soc_tplg *tplg, | |
261 | struct snd_soc_tplg_channel *chan, int map) | |
262 | { | |
263 | int i; | |
264 | ||
265 | for (i = 0; i < SND_SOC_TPLG_MAX_CHAN; i++) { | |
266 | if (chan[i].id == map) | |
267 | return chan[i].shift; | |
268 | } | |
269 | ||
270 | return -EINVAL; | |
271 | } | |
272 | ||
273 | static int get_widget_id(int tplg_type) | |
274 | { | |
275 | int i; | |
276 | ||
277 | for (i = 0; i < ARRAY_SIZE(dapm_map); i++) { | |
278 | if (tplg_type == dapm_map[i].uid) | |
279 | return dapm_map[i].kid; | |
280 | } | |
281 | ||
282 | return -EINVAL; | |
283 | } | |
284 | ||
8a978234 LG |
285 | static inline void soc_bind_err(struct soc_tplg *tplg, |
286 | struct snd_soc_tplg_ctl_hdr *hdr, int index) | |
287 | { | |
288 | dev_err(tplg->dev, | |
289 | "ASoC: invalid control type (g,p,i) %d:%d:%d index %d at 0x%lx\n", | |
290 | hdr->ops.get, hdr->ops.put, hdr->ops.info, index, | |
291 | soc_tplg_get_offset(tplg)); | |
292 | } | |
293 | ||
294 | static inline void soc_control_err(struct soc_tplg *tplg, | |
295 | struct snd_soc_tplg_ctl_hdr *hdr, const char *name) | |
296 | { | |
297 | dev_err(tplg->dev, | |
298 | "ASoC: no complete mixer IO handler for %s type (g,p,i) %d:%d:%d at 0x%lx\n", | |
299 | name, hdr->ops.get, hdr->ops.put, hdr->ops.info, | |
300 | soc_tplg_get_offset(tplg)); | |
301 | } | |
302 | ||
303 | /* pass vendor data to component driver for processing */ | |
304 | static int soc_tplg_vendor_load_(struct soc_tplg *tplg, | |
305 | struct snd_soc_tplg_hdr *hdr) | |
306 | { | |
307 | int ret = 0; | |
308 | ||
309 | if (tplg->comp && tplg->ops && tplg->ops->vendor_load) | |
310 | ret = tplg->ops->vendor_load(tplg->comp, hdr); | |
311 | else { | |
312 | dev_err(tplg->dev, "ASoC: no vendor load callback for ID %d\n", | |
313 | hdr->vendor_type); | |
314 | return -EINVAL; | |
315 | } | |
316 | ||
317 | if (ret < 0) | |
318 | dev_err(tplg->dev, | |
319 | "ASoC: vendor load failed at hdr offset %ld/0x%lx for type %d:%d\n", | |
320 | soc_tplg_get_hdr_offset(tplg), | |
321 | soc_tplg_get_hdr_offset(tplg), | |
322 | hdr->type, hdr->vendor_type); | |
323 | return ret; | |
324 | } | |
325 | ||
326 | /* pass vendor data to component driver for processing */ | |
327 | static int soc_tplg_vendor_load(struct soc_tplg *tplg, | |
328 | struct snd_soc_tplg_hdr *hdr) | |
329 | { | |
330 | if (tplg->pass != SOC_TPLG_PASS_VENDOR) | |
331 | return 0; | |
332 | ||
333 | return soc_tplg_vendor_load_(tplg, hdr); | |
334 | } | |
335 | ||
336 | /* optionally pass new dynamic widget to component driver. This is mainly for | |
337 | * external widgets where we can assign private data/ops */ | |
338 | static int soc_tplg_widget_load(struct soc_tplg *tplg, | |
339 | struct snd_soc_dapm_widget *w, struct snd_soc_tplg_dapm_widget *tplg_w) | |
340 | { | |
341 | if (tplg->comp && tplg->ops && tplg->ops->widget_load) | |
342 | return tplg->ops->widget_load(tplg->comp, w, tplg_w); | |
343 | ||
344 | return 0; | |
345 | } | |
346 | ||
64527e8a ML |
347 | /* pass DAI configurations to component driver for extra intialization */ |
348 | static int soc_tplg_dai_load(struct soc_tplg *tplg, | |
349 | struct snd_soc_dai_driver *dai_drv) | |
8a978234 | 350 | { |
64527e8a ML |
351 | if (tplg->comp && tplg->ops && tplg->ops->dai_load) |
352 | return tplg->ops->dai_load(tplg->comp, dai_drv); | |
8a978234 LG |
353 | |
354 | return 0; | |
355 | } | |
356 | ||
acfc7d46 ML |
357 | /* pass link configurations to component driver for extra intialization */ |
358 | static int soc_tplg_dai_link_load(struct soc_tplg *tplg, | |
359 | struct snd_soc_dai_link *link) | |
360 | { | |
361 | if (tplg->comp && tplg->ops && tplg->ops->link_load) | |
362 | return tplg->ops->link_load(tplg->comp, link); | |
363 | ||
364 | return 0; | |
365 | } | |
366 | ||
8a978234 LG |
367 | /* tell the component driver that all firmware has been loaded in this request */ |
368 | static void soc_tplg_complete(struct soc_tplg *tplg) | |
369 | { | |
370 | if (tplg->comp && tplg->ops && tplg->ops->complete) | |
371 | tplg->ops->complete(tplg->comp); | |
372 | } | |
373 | ||
374 | /* add a dynamic kcontrol */ | |
375 | static int soc_tplg_add_dcontrol(struct snd_card *card, struct device *dev, | |
376 | const struct snd_kcontrol_new *control_new, const char *prefix, | |
377 | void *data, struct snd_kcontrol **kcontrol) | |
378 | { | |
379 | int err; | |
380 | ||
381 | *kcontrol = snd_soc_cnew(control_new, data, control_new->name, prefix); | |
382 | if (*kcontrol == NULL) { | |
383 | dev_err(dev, "ASoC: Failed to create new kcontrol %s\n", | |
384 | control_new->name); | |
385 | return -ENOMEM; | |
386 | } | |
387 | ||
388 | err = snd_ctl_add(card, *kcontrol); | |
389 | if (err < 0) { | |
390 | dev_err(dev, "ASoC: Failed to add %s: %d\n", | |
391 | control_new->name, err); | |
392 | return err; | |
393 | } | |
394 | ||
395 | return 0; | |
396 | } | |
397 | ||
398 | /* add a dynamic kcontrol for component driver */ | |
399 | static int soc_tplg_add_kcontrol(struct soc_tplg *tplg, | |
400 | struct snd_kcontrol_new *k, struct snd_kcontrol **kcontrol) | |
401 | { | |
402 | struct snd_soc_component *comp = tplg->comp; | |
403 | ||
404 | return soc_tplg_add_dcontrol(comp->card->snd_card, | |
405 | comp->dev, k, NULL, comp, kcontrol); | |
406 | } | |
407 | ||
408 | /* remove a mixer kcontrol */ | |
409 | static void remove_mixer(struct snd_soc_component *comp, | |
410 | struct snd_soc_dobj *dobj, int pass) | |
411 | { | |
412 | struct snd_card *card = comp->card->snd_card; | |
413 | struct soc_mixer_control *sm = | |
414 | container_of(dobj, struct soc_mixer_control, dobj); | |
415 | const unsigned int *p = NULL; | |
416 | ||
417 | if (pass != SOC_TPLG_PASS_MIXER) | |
418 | return; | |
419 | ||
420 | if (dobj->ops && dobj->ops->control_unload) | |
421 | dobj->ops->control_unload(comp, dobj); | |
422 | ||
423 | if (sm->dobj.control.kcontrol->tlv.p) | |
424 | p = sm->dobj.control.kcontrol->tlv.p; | |
425 | snd_ctl_remove(card, sm->dobj.control.kcontrol); | |
426 | list_del(&sm->dobj.list); | |
427 | kfree(sm); | |
428 | kfree(p); | |
429 | } | |
430 | ||
431 | /* remove an enum kcontrol */ | |
432 | static void remove_enum(struct snd_soc_component *comp, | |
433 | struct snd_soc_dobj *dobj, int pass) | |
434 | { | |
435 | struct snd_card *card = comp->card->snd_card; | |
436 | struct soc_enum *se = container_of(dobj, struct soc_enum, dobj); | |
437 | int i; | |
438 | ||
439 | if (pass != SOC_TPLG_PASS_MIXER) | |
440 | return; | |
441 | ||
442 | if (dobj->ops && dobj->ops->control_unload) | |
443 | dobj->ops->control_unload(comp, dobj); | |
444 | ||
445 | snd_ctl_remove(card, se->dobj.control.kcontrol); | |
446 | list_del(&se->dobj.list); | |
447 | ||
448 | kfree(se->dobj.control.dvalues); | |
449 | for (i = 0; i < se->items; i++) | |
450 | kfree(se->dobj.control.dtexts[i]); | |
451 | kfree(se); | |
452 | } | |
453 | ||
454 | /* remove a byte kcontrol */ | |
455 | static void remove_bytes(struct snd_soc_component *comp, | |
456 | struct snd_soc_dobj *dobj, int pass) | |
457 | { | |
458 | struct snd_card *card = comp->card->snd_card; | |
459 | struct soc_bytes_ext *sb = | |
460 | container_of(dobj, struct soc_bytes_ext, dobj); | |
461 | ||
462 | if (pass != SOC_TPLG_PASS_MIXER) | |
463 | return; | |
464 | ||
465 | if (dobj->ops && dobj->ops->control_unload) | |
466 | dobj->ops->control_unload(comp, dobj); | |
467 | ||
468 | snd_ctl_remove(card, sb->dobj.control.kcontrol); | |
469 | list_del(&sb->dobj.list); | |
470 | kfree(sb); | |
471 | } | |
472 | ||
473 | /* remove a widget and it's kcontrols - routes must be removed first */ | |
474 | static void remove_widget(struct snd_soc_component *comp, | |
475 | struct snd_soc_dobj *dobj, int pass) | |
476 | { | |
477 | struct snd_card *card = comp->card->snd_card; | |
478 | struct snd_soc_dapm_widget *w = | |
479 | container_of(dobj, struct snd_soc_dapm_widget, dobj); | |
480 | int i; | |
481 | ||
482 | if (pass != SOC_TPLG_PASS_WIDGET) | |
483 | return; | |
484 | ||
485 | if (dobj->ops && dobj->ops->widget_unload) | |
486 | dobj->ops->widget_unload(comp, dobj); | |
487 | ||
488 | /* | |
489 | * Dynamic Widgets either have 1 enum kcontrol or 1..N mixers. | |
490 | * The enum may either have an array of values or strings. | |
491 | */ | |
492 | if (dobj->widget.kcontrol_enum) { | |
493 | /* enumerated widget mixer */ | |
494 | struct soc_enum *se = | |
495 | (struct soc_enum *)w->kcontrols[0]->private_value; | |
496 | ||
497 | snd_ctl_remove(card, w->kcontrols[0]); | |
498 | ||
499 | kfree(se->dobj.control.dvalues); | |
500 | for (i = 0; i < se->items; i++) | |
501 | kfree(se->dobj.control.dtexts[i]); | |
502 | ||
503 | kfree(se); | |
504 | kfree(w->kcontrol_news); | |
505 | } else { | |
506 | /* non enumerated widget mixer */ | |
507 | for (i = 0; i < w->num_kcontrols; i++) { | |
508 | struct snd_kcontrol *kcontrol = w->kcontrols[i]; | |
509 | struct soc_mixer_control *sm = | |
510 | (struct soc_mixer_control *) kcontrol->private_value; | |
511 | ||
512 | kfree(w->kcontrols[i]->tlv.p); | |
513 | ||
514 | snd_ctl_remove(card, w->kcontrols[i]); | |
515 | kfree(sm); | |
516 | } | |
517 | kfree(w->kcontrol_news); | |
518 | } | |
519 | /* widget w is freed by soc-dapm.c */ | |
520 | } | |
521 | ||
64527e8a ML |
522 | /* remove DAI configurations */ |
523 | static void remove_dai(struct snd_soc_component *comp, | |
8a978234 LG |
524 | struct snd_soc_dobj *dobj, int pass) |
525 | { | |
64527e8a ML |
526 | struct snd_soc_dai_driver *dai_drv = |
527 | container_of(dobj, struct snd_soc_dai_driver, dobj); | |
528 | ||
8a978234 LG |
529 | if (pass != SOC_TPLG_PASS_PCM_DAI) |
530 | return; | |
531 | ||
64527e8a ML |
532 | if (dobj->ops && dobj->ops->dai_unload) |
533 | dobj->ops->dai_unload(comp, dobj); | |
8a978234 | 534 | |
8f27c4ab | 535 | kfree(dai_drv->name); |
8a978234 | 536 | list_del(&dobj->list); |
64527e8a | 537 | kfree(dai_drv); |
8a978234 LG |
538 | } |
539 | ||
acfc7d46 ML |
540 | /* remove link configurations */ |
541 | static void remove_link(struct snd_soc_component *comp, | |
542 | struct snd_soc_dobj *dobj, int pass) | |
543 | { | |
544 | struct snd_soc_dai_link *link = | |
545 | container_of(dobj, struct snd_soc_dai_link, dobj); | |
546 | ||
547 | if (pass != SOC_TPLG_PASS_PCM_DAI) | |
548 | return; | |
549 | ||
550 | if (dobj->ops && dobj->ops->link_unload) | |
551 | dobj->ops->link_unload(comp, dobj); | |
552 | ||
8f27c4ab ML |
553 | kfree(link->name); |
554 | kfree(link->stream_name); | |
555 | kfree(link->cpu_dai_name); | |
556 | ||
acfc7d46 ML |
557 | list_del(&dobj->list); |
558 | snd_soc_remove_dai_link(comp->card, link); | |
559 | kfree(link); | |
560 | } | |
561 | ||
8a978234 LG |
562 | /* bind a kcontrol to it's IO handlers */ |
563 | static int soc_tplg_kcontrol_bind_io(struct snd_soc_tplg_ctl_hdr *hdr, | |
564 | struct snd_kcontrol_new *k, | |
2b5cdb91 | 565 | const struct soc_tplg *tplg) |
8a978234 | 566 | { |
2b5cdb91 | 567 | const struct snd_soc_tplg_kcontrol_ops *ops; |
1a3232d2 | 568 | const struct snd_soc_tplg_bytes_ext_ops *ext_ops; |
2b5cdb91 | 569 | int num_ops, i; |
8a978234 | 570 | |
1a3232d2 ML |
571 | if (hdr->ops.info == SND_SOC_TPLG_CTL_BYTES |
572 | && k->iface & SNDRV_CTL_ELEM_IFACE_MIXER | |
573 | && k->access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE | |
574 | && k->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK) { | |
575 | struct soc_bytes_ext *sbe; | |
576 | struct snd_soc_tplg_bytes_control *be; | |
577 | ||
578 | sbe = (struct soc_bytes_ext *)k->private_value; | |
579 | be = container_of(hdr, struct snd_soc_tplg_bytes_control, hdr); | |
580 | ||
581 | /* TLV bytes controls need standard kcontrol info handler, | |
582 | * TLV callback and extended put/get handlers. | |
583 | */ | |
f4be978b | 584 | k->info = snd_soc_bytes_info_ext; |
1a3232d2 ML |
585 | k->tlv.c = snd_soc_bytes_tlv_callback; |
586 | ||
587 | ext_ops = tplg->bytes_ext_ops; | |
588 | num_ops = tplg->bytes_ext_ops_count; | |
589 | for (i = 0; i < num_ops; i++) { | |
590 | if (!sbe->put && ext_ops[i].id == be->ext_ops.put) | |
591 | sbe->put = ext_ops[i].put; | |
592 | if (!sbe->get && ext_ops[i].id == be->ext_ops.get) | |
593 | sbe->get = ext_ops[i].get; | |
594 | } | |
595 | ||
596 | if (sbe->put && sbe->get) | |
597 | return 0; | |
598 | else | |
599 | return -EINVAL; | |
600 | } | |
8a978234 | 601 | |
88a17d8f | 602 | /* try and map vendor specific kcontrol handlers first */ |
2b5cdb91 ML |
603 | ops = tplg->io_ops; |
604 | num_ops = tplg->io_ops_count; | |
8a978234 LG |
605 | for (i = 0; i < num_ops; i++) { |
606 | ||
2b5cdb91 | 607 | if (k->put == NULL && ops[i].id == hdr->ops.put) |
8a978234 | 608 | k->put = ops[i].put; |
2b5cdb91 | 609 | if (k->get == NULL && ops[i].id == hdr->ops.get) |
8a978234 | 610 | k->get = ops[i].get; |
2b5cdb91 | 611 | if (k->info == NULL && ops[i].id == hdr->ops.info) |
8a978234 LG |
612 | k->info = ops[i].info; |
613 | } | |
614 | ||
88a17d8f | 615 | /* vendor specific handlers found ? */ |
8a978234 LG |
616 | if (k->put && k->get && k->info) |
617 | return 0; | |
618 | ||
88a17d8f | 619 | /* none found so try standard kcontrol handlers */ |
2b5cdb91 ML |
620 | ops = io_ops; |
621 | num_ops = ARRAY_SIZE(io_ops); | |
88a17d8f | 622 | for (i = 0; i < num_ops; i++) { |
8a978234 | 623 | |
88a17d8f ML |
624 | if (k->put == NULL && ops[i].id == hdr->ops.put) |
625 | k->put = ops[i].put; | |
626 | if (k->get == NULL && ops[i].id == hdr->ops.get) | |
627 | k->get = ops[i].get; | |
8a978234 | 628 | if (k->info == NULL && ops[i].id == hdr->ops.info) |
88a17d8f | 629 | k->info = ops[i].info; |
8a978234 LG |
630 | } |
631 | ||
88a17d8f | 632 | /* standard handlers found ? */ |
8a978234 LG |
633 | if (k->put && k->get && k->info) |
634 | return 0; | |
635 | ||
636 | /* nothing to bind */ | |
637 | return -EINVAL; | |
638 | } | |
639 | ||
640 | /* bind a widgets to it's evnt handlers */ | |
641 | int snd_soc_tplg_widget_bind_event(struct snd_soc_dapm_widget *w, | |
642 | const struct snd_soc_tplg_widget_events *events, | |
643 | int num_events, u16 event_type) | |
644 | { | |
645 | int i; | |
646 | ||
647 | w->event = NULL; | |
648 | ||
649 | for (i = 0; i < num_events; i++) { | |
650 | if (event_type == events[i].type) { | |
651 | ||
652 | /* found - so assign event */ | |
653 | w->event = events[i].event_handler; | |
654 | return 0; | |
655 | } | |
656 | } | |
657 | ||
658 | /* not found */ | |
659 | return -EINVAL; | |
660 | } | |
661 | EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_bind_event); | |
662 | ||
663 | /* optionally pass new dynamic kcontrol to component driver. */ | |
664 | static int soc_tplg_init_kcontrol(struct soc_tplg *tplg, | |
665 | struct snd_kcontrol_new *k, struct snd_soc_tplg_ctl_hdr *hdr) | |
666 | { | |
667 | if (tplg->comp && tplg->ops && tplg->ops->control_load) | |
668 | return tplg->ops->control_load(tplg->comp, k, hdr); | |
669 | ||
670 | return 0; | |
671 | } | |
672 | ||
8a978234 | 673 | |
28a87eeb ML |
674 | static int soc_tplg_create_tlv_db_scale(struct soc_tplg *tplg, |
675 | struct snd_kcontrol_new *kc, struct snd_soc_tplg_tlv_dbscale *scale) | |
676 | { | |
677 | unsigned int item_len = 2 * sizeof(unsigned int); | |
678 | unsigned int *p; | |
8a978234 | 679 | |
28a87eeb ML |
680 | p = kzalloc(item_len + 2 * sizeof(unsigned int), GFP_KERNEL); |
681 | if (!p) | |
8a978234 LG |
682 | return -ENOMEM; |
683 | ||
28a87eeb ML |
684 | p[0] = SNDRV_CTL_TLVT_DB_SCALE; |
685 | p[1] = item_len; | |
686 | p[2] = scale->min; | |
687 | p[3] = (scale->step & TLV_DB_SCALE_MASK) | |
688 | | (scale->mute ? TLV_DB_SCALE_MUTE : 0); | |
689 | ||
690 | kc->tlv.p = (void *)p; | |
691 | return 0; | |
692 | } | |
693 | ||
694 | static int soc_tplg_create_tlv(struct soc_tplg *tplg, | |
695 | struct snd_kcontrol_new *kc, struct snd_soc_tplg_ctl_hdr *tc) | |
696 | { | |
697 | struct snd_soc_tplg_ctl_tlv *tplg_tlv; | |
698 | ||
699 | if (!(tc->access & SNDRV_CTL_ELEM_ACCESS_TLV_READWRITE)) | |
700 | return 0; | |
8a978234 | 701 | |
1a3232d2 | 702 | if (!(tc->access & SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK)) { |
28a87eeb ML |
703 | tplg_tlv = &tc->tlv; |
704 | switch (tplg_tlv->type) { | |
705 | case SNDRV_CTL_TLVT_DB_SCALE: | |
706 | return soc_tplg_create_tlv_db_scale(tplg, kc, | |
707 | &tplg_tlv->scale); | |
708 | ||
709 | /* TODO: add support for other TLV types */ | |
710 | default: | |
711 | dev_dbg(tplg->dev, "Unsupported TLV type %d\n", | |
712 | tplg_tlv->type); | |
713 | return -EINVAL; | |
714 | } | |
715 | } | |
8a978234 LG |
716 | |
717 | return 0; | |
718 | } | |
719 | ||
720 | static inline void soc_tplg_free_tlv(struct soc_tplg *tplg, | |
721 | struct snd_kcontrol_new *kc) | |
722 | { | |
723 | kfree(kc->tlv.p); | |
724 | } | |
725 | ||
726 | static int soc_tplg_dbytes_create(struct soc_tplg *tplg, unsigned int count, | |
727 | size_t size) | |
728 | { | |
729 | struct snd_soc_tplg_bytes_control *be; | |
730 | struct soc_bytes_ext *sbe; | |
731 | struct snd_kcontrol_new kc; | |
732 | int i, err; | |
733 | ||
734 | if (soc_tplg_check_elem_count(tplg, | |
735 | sizeof(struct snd_soc_tplg_bytes_control), count, | |
736 | size, "mixer bytes")) { | |
737 | dev_err(tplg->dev, "ASoC: Invalid count %d for byte control\n", | |
738 | count); | |
739 | return -EINVAL; | |
740 | } | |
741 | ||
742 | for (i = 0; i < count; i++) { | |
743 | be = (struct snd_soc_tplg_bytes_control *)tplg->pos; | |
744 | ||
745 | /* validate kcontrol */ | |
746 | if (strnlen(be->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | |
747 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | |
748 | return -EINVAL; | |
749 | ||
750 | sbe = kzalloc(sizeof(*sbe), GFP_KERNEL); | |
751 | if (sbe == NULL) | |
752 | return -ENOMEM; | |
753 | ||
754 | tplg->pos += (sizeof(struct snd_soc_tplg_bytes_control) + | |
755 | be->priv.size); | |
756 | ||
757 | dev_dbg(tplg->dev, | |
758 | "ASoC: adding bytes kcontrol %s with access 0x%x\n", | |
759 | be->hdr.name, be->hdr.access); | |
760 | ||
761 | memset(&kc, 0, sizeof(kc)); | |
762 | kc.name = be->hdr.name; | |
763 | kc.private_value = (long)sbe; | |
764 | kc.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
765 | kc.access = be->hdr.access; | |
766 | ||
767 | sbe->max = be->max; | |
768 | sbe->dobj.type = SND_SOC_DOBJ_BYTES; | |
769 | sbe->dobj.ops = tplg->ops; | |
770 | INIT_LIST_HEAD(&sbe->dobj.list); | |
771 | ||
772 | /* map io handlers */ | |
2b5cdb91 | 773 | err = soc_tplg_kcontrol_bind_io(&be->hdr, &kc, tplg); |
8a978234 LG |
774 | if (err) { |
775 | soc_control_err(tplg, &be->hdr, be->hdr.name); | |
776 | kfree(sbe); | |
777 | continue; | |
778 | } | |
779 | ||
780 | /* pass control to driver for optional further init */ | |
781 | err = soc_tplg_init_kcontrol(tplg, &kc, | |
782 | (struct snd_soc_tplg_ctl_hdr *)be); | |
783 | if (err < 0) { | |
784 | dev_err(tplg->dev, "ASoC: failed to init %s\n", | |
785 | be->hdr.name); | |
786 | kfree(sbe); | |
787 | continue; | |
788 | } | |
789 | ||
790 | /* register control here */ | |
791 | err = soc_tplg_add_kcontrol(tplg, &kc, | |
792 | &sbe->dobj.control.kcontrol); | |
793 | if (err < 0) { | |
794 | dev_err(tplg->dev, "ASoC: failed to add %s\n", | |
795 | be->hdr.name); | |
796 | kfree(sbe); | |
797 | continue; | |
798 | } | |
799 | ||
800 | list_add(&sbe->dobj.list, &tplg->comp->dobj_list); | |
801 | } | |
802 | return 0; | |
803 | ||
804 | } | |
805 | ||
806 | static int soc_tplg_dmixer_create(struct soc_tplg *tplg, unsigned int count, | |
807 | size_t size) | |
808 | { | |
809 | struct snd_soc_tplg_mixer_control *mc; | |
810 | struct soc_mixer_control *sm; | |
811 | struct snd_kcontrol_new kc; | |
812 | int i, err; | |
813 | ||
814 | if (soc_tplg_check_elem_count(tplg, | |
815 | sizeof(struct snd_soc_tplg_mixer_control), | |
816 | count, size, "mixers")) { | |
817 | ||
818 | dev_err(tplg->dev, "ASoC: invalid count %d for controls\n", | |
819 | count); | |
820 | return -EINVAL; | |
821 | } | |
822 | ||
823 | for (i = 0; i < count; i++) { | |
824 | mc = (struct snd_soc_tplg_mixer_control *)tplg->pos; | |
825 | ||
826 | /* validate kcontrol */ | |
827 | if (strnlen(mc->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | |
828 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | |
829 | return -EINVAL; | |
830 | ||
831 | sm = kzalloc(sizeof(*sm), GFP_KERNEL); | |
832 | if (sm == NULL) | |
833 | return -ENOMEM; | |
834 | tplg->pos += (sizeof(struct snd_soc_tplg_mixer_control) + | |
835 | mc->priv.size); | |
836 | ||
837 | dev_dbg(tplg->dev, | |
838 | "ASoC: adding mixer kcontrol %s with access 0x%x\n", | |
839 | mc->hdr.name, mc->hdr.access); | |
840 | ||
841 | memset(&kc, 0, sizeof(kc)); | |
842 | kc.name = mc->hdr.name; | |
843 | kc.private_value = (long)sm; | |
844 | kc.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
845 | kc.access = mc->hdr.access; | |
846 | ||
847 | /* we only support FL/FR channel mapping atm */ | |
848 | sm->reg = tplc_chan_get_reg(tplg, mc->channel, | |
849 | SNDRV_CHMAP_FL); | |
850 | sm->rreg = tplc_chan_get_reg(tplg, mc->channel, | |
851 | SNDRV_CHMAP_FR); | |
852 | sm->shift = tplc_chan_get_shift(tplg, mc->channel, | |
853 | SNDRV_CHMAP_FL); | |
854 | sm->rshift = tplc_chan_get_shift(tplg, mc->channel, | |
855 | SNDRV_CHMAP_FR); | |
856 | ||
857 | sm->max = mc->max; | |
858 | sm->min = mc->min; | |
859 | sm->invert = mc->invert; | |
860 | sm->platform_max = mc->platform_max; | |
861 | sm->dobj.index = tplg->index; | |
862 | sm->dobj.ops = tplg->ops; | |
863 | sm->dobj.type = SND_SOC_DOBJ_MIXER; | |
864 | INIT_LIST_HEAD(&sm->dobj.list); | |
865 | ||
866 | /* map io handlers */ | |
2b5cdb91 | 867 | err = soc_tplg_kcontrol_bind_io(&mc->hdr, &kc, tplg); |
8a978234 LG |
868 | if (err) { |
869 | soc_control_err(tplg, &mc->hdr, mc->hdr.name); | |
870 | kfree(sm); | |
871 | continue; | |
872 | } | |
873 | ||
874 | /* pass control to driver for optional further init */ | |
875 | err = soc_tplg_init_kcontrol(tplg, &kc, | |
876 | (struct snd_soc_tplg_ctl_hdr *) mc); | |
877 | if (err < 0) { | |
878 | dev_err(tplg->dev, "ASoC: failed to init %s\n", | |
879 | mc->hdr.name); | |
880 | kfree(sm); | |
881 | continue; | |
882 | } | |
883 | ||
884 | /* create any TLV data */ | |
28a87eeb | 885 | soc_tplg_create_tlv(tplg, &kc, &mc->hdr); |
8a978234 LG |
886 | |
887 | /* register control here */ | |
888 | err = soc_tplg_add_kcontrol(tplg, &kc, | |
889 | &sm->dobj.control.kcontrol); | |
890 | if (err < 0) { | |
891 | dev_err(tplg->dev, "ASoC: failed to add %s\n", | |
892 | mc->hdr.name); | |
893 | soc_tplg_free_tlv(tplg, &kc); | |
894 | kfree(sm); | |
895 | continue; | |
896 | } | |
897 | ||
898 | list_add(&sm->dobj.list, &tplg->comp->dobj_list); | |
899 | } | |
900 | ||
901 | return 0; | |
902 | } | |
903 | ||
904 | static int soc_tplg_denum_create_texts(struct soc_enum *se, | |
905 | struct snd_soc_tplg_enum_control *ec) | |
906 | { | |
907 | int i, ret; | |
908 | ||
909 | se->dobj.control.dtexts = | |
910 | kzalloc(sizeof(char *) * ec->items, GFP_KERNEL); | |
911 | if (se->dobj.control.dtexts == NULL) | |
912 | return -ENOMEM; | |
913 | ||
914 | for (i = 0; i < ec->items; i++) { | |
915 | ||
916 | if (strnlen(ec->texts[i], SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | |
917 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) { | |
918 | ret = -EINVAL; | |
919 | goto err; | |
920 | } | |
921 | ||
922 | se->dobj.control.dtexts[i] = kstrdup(ec->texts[i], GFP_KERNEL); | |
923 | if (!se->dobj.control.dtexts[i]) { | |
924 | ret = -ENOMEM; | |
925 | goto err; | |
926 | } | |
927 | } | |
928 | ||
929 | return 0; | |
930 | ||
931 | err: | |
932 | for (--i; i >= 0; i--) | |
933 | kfree(se->dobj.control.dtexts[i]); | |
934 | kfree(se->dobj.control.dtexts); | |
935 | return ret; | |
936 | } | |
937 | ||
938 | static int soc_tplg_denum_create_values(struct soc_enum *se, | |
939 | struct snd_soc_tplg_enum_control *ec) | |
940 | { | |
941 | if (ec->items > sizeof(*ec->values)) | |
942 | return -EINVAL; | |
943 | ||
376c0afe AH |
944 | se->dobj.control.dvalues = kmemdup(ec->values, |
945 | ec->items * sizeof(u32), | |
946 | GFP_KERNEL); | |
8a978234 LG |
947 | if (!se->dobj.control.dvalues) |
948 | return -ENOMEM; | |
949 | ||
8a978234 LG |
950 | return 0; |
951 | } | |
952 | ||
953 | static int soc_tplg_denum_create(struct soc_tplg *tplg, unsigned int count, | |
954 | size_t size) | |
955 | { | |
956 | struct snd_soc_tplg_enum_control *ec; | |
957 | struct soc_enum *se; | |
958 | struct snd_kcontrol_new kc; | |
959 | int i, ret, err; | |
960 | ||
961 | if (soc_tplg_check_elem_count(tplg, | |
962 | sizeof(struct snd_soc_tplg_enum_control), | |
963 | count, size, "enums")) { | |
964 | ||
965 | dev_err(tplg->dev, "ASoC: invalid count %d for enum controls\n", | |
966 | count); | |
967 | return -EINVAL; | |
968 | } | |
969 | ||
970 | for (i = 0; i < count; i++) { | |
971 | ec = (struct snd_soc_tplg_enum_control *)tplg->pos; | |
972 | tplg->pos += (sizeof(struct snd_soc_tplg_enum_control) + | |
973 | ec->priv.size); | |
974 | ||
975 | /* validate kcontrol */ | |
976 | if (strnlen(ec->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | |
977 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | |
978 | return -EINVAL; | |
979 | ||
980 | se = kzalloc((sizeof(*se)), GFP_KERNEL); | |
981 | if (se == NULL) | |
982 | return -ENOMEM; | |
983 | ||
984 | dev_dbg(tplg->dev, "ASoC: adding enum kcontrol %s size %d\n", | |
985 | ec->hdr.name, ec->items); | |
986 | ||
987 | memset(&kc, 0, sizeof(kc)); | |
988 | kc.name = ec->hdr.name; | |
989 | kc.private_value = (long)se; | |
990 | kc.iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
991 | kc.access = ec->hdr.access; | |
992 | ||
993 | se->reg = tplc_chan_get_reg(tplg, ec->channel, SNDRV_CHMAP_FL); | |
994 | se->shift_l = tplc_chan_get_shift(tplg, ec->channel, | |
995 | SNDRV_CHMAP_FL); | |
996 | se->shift_r = tplc_chan_get_shift(tplg, ec->channel, | |
997 | SNDRV_CHMAP_FL); | |
998 | ||
999 | se->items = ec->items; | |
1000 | se->mask = ec->mask; | |
1001 | se->dobj.index = tplg->index; | |
1002 | se->dobj.type = SND_SOC_DOBJ_ENUM; | |
1003 | se->dobj.ops = tplg->ops; | |
1004 | INIT_LIST_HEAD(&se->dobj.list); | |
1005 | ||
1006 | switch (ec->hdr.ops.info) { | |
1007 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE: | |
1008 | case SND_SOC_TPLG_CTL_ENUM_VALUE: | |
1009 | err = soc_tplg_denum_create_values(se, ec); | |
1010 | if (err < 0) { | |
1011 | dev_err(tplg->dev, | |
1012 | "ASoC: could not create values for %s\n", | |
1013 | ec->hdr.name); | |
1014 | kfree(se); | |
1015 | continue; | |
1016 | } | |
1017 | /* fall through and create texts */ | |
1018 | case SND_SOC_TPLG_CTL_ENUM: | |
1019 | case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE: | |
1020 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT: | |
1021 | err = soc_tplg_denum_create_texts(se, ec); | |
1022 | if (err < 0) { | |
1023 | dev_err(tplg->dev, | |
1024 | "ASoC: could not create texts for %s\n", | |
1025 | ec->hdr.name); | |
1026 | kfree(se); | |
1027 | continue; | |
1028 | } | |
1029 | break; | |
1030 | default: | |
1031 | dev_err(tplg->dev, | |
1032 | "ASoC: invalid enum control type %d for %s\n", | |
1033 | ec->hdr.ops.info, ec->hdr.name); | |
1034 | kfree(se); | |
1035 | continue; | |
1036 | } | |
1037 | ||
1038 | /* map io handlers */ | |
2b5cdb91 | 1039 | err = soc_tplg_kcontrol_bind_io(&ec->hdr, &kc, tplg); |
8a978234 LG |
1040 | if (err) { |
1041 | soc_control_err(tplg, &ec->hdr, ec->hdr.name); | |
1042 | kfree(se); | |
1043 | continue; | |
1044 | } | |
1045 | ||
1046 | /* pass control to driver for optional further init */ | |
1047 | err = soc_tplg_init_kcontrol(tplg, &kc, | |
1048 | (struct snd_soc_tplg_ctl_hdr *) ec); | |
1049 | if (err < 0) { | |
1050 | dev_err(tplg->dev, "ASoC: failed to init %s\n", | |
1051 | ec->hdr.name); | |
1052 | kfree(se); | |
1053 | continue; | |
1054 | } | |
1055 | ||
1056 | /* register control here */ | |
1057 | ret = soc_tplg_add_kcontrol(tplg, | |
1058 | &kc, &se->dobj.control.kcontrol); | |
1059 | if (ret < 0) { | |
1060 | dev_err(tplg->dev, "ASoC: could not add kcontrol %s\n", | |
1061 | ec->hdr.name); | |
1062 | kfree(se); | |
1063 | continue; | |
1064 | } | |
1065 | ||
1066 | list_add(&se->dobj.list, &tplg->comp->dobj_list); | |
1067 | } | |
1068 | ||
1069 | return 0; | |
1070 | } | |
1071 | ||
1072 | static int soc_tplg_kcontrol_elems_load(struct soc_tplg *tplg, | |
1073 | struct snd_soc_tplg_hdr *hdr) | |
1074 | { | |
1075 | struct snd_soc_tplg_ctl_hdr *control_hdr; | |
1076 | int i; | |
1077 | ||
1078 | if (tplg->pass != SOC_TPLG_PASS_MIXER) { | |
1079 | tplg->pos += hdr->size + hdr->payload_size; | |
1080 | return 0; | |
1081 | } | |
1082 | ||
1083 | dev_dbg(tplg->dev, "ASoC: adding %d kcontrols at 0x%lx\n", hdr->count, | |
1084 | soc_tplg_get_offset(tplg)); | |
1085 | ||
1086 | for (i = 0; i < hdr->count; i++) { | |
1087 | ||
1088 | control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos; | |
1089 | ||
06eb49f7 ML |
1090 | if (control_hdr->size != sizeof(*control_hdr)) { |
1091 | dev_err(tplg->dev, "ASoC: invalid control size\n"); | |
1092 | return -EINVAL; | |
1093 | } | |
1094 | ||
8a978234 LG |
1095 | switch (control_hdr->ops.info) { |
1096 | case SND_SOC_TPLG_CTL_VOLSW: | |
1097 | case SND_SOC_TPLG_CTL_STROBE: | |
1098 | case SND_SOC_TPLG_CTL_VOLSW_SX: | |
1099 | case SND_SOC_TPLG_CTL_VOLSW_XR_SX: | |
1100 | case SND_SOC_TPLG_CTL_RANGE: | |
1101 | case SND_SOC_TPLG_DAPM_CTL_VOLSW: | |
1102 | case SND_SOC_TPLG_DAPM_CTL_PIN: | |
1103 | soc_tplg_dmixer_create(tplg, 1, hdr->payload_size); | |
1104 | break; | |
1105 | case SND_SOC_TPLG_CTL_ENUM: | |
1106 | case SND_SOC_TPLG_CTL_ENUM_VALUE: | |
1107 | case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE: | |
1108 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT: | |
1109 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE: | |
1110 | soc_tplg_denum_create(tplg, 1, hdr->payload_size); | |
1111 | break; | |
1112 | case SND_SOC_TPLG_CTL_BYTES: | |
1113 | soc_tplg_dbytes_create(tplg, 1, hdr->payload_size); | |
1114 | break; | |
1115 | default: | |
1116 | soc_bind_err(tplg, control_hdr, i); | |
1117 | return -EINVAL; | |
1118 | } | |
1119 | } | |
1120 | ||
1121 | return 0; | |
1122 | } | |
1123 | ||
1124 | static int soc_tplg_dapm_graph_elems_load(struct soc_tplg *tplg, | |
1125 | struct snd_soc_tplg_hdr *hdr) | |
1126 | { | |
1127 | struct snd_soc_dapm_context *dapm = &tplg->comp->dapm; | |
1128 | struct snd_soc_dapm_route route; | |
1129 | struct snd_soc_tplg_dapm_graph_elem *elem; | |
1130 | int count = hdr->count, i; | |
1131 | ||
1132 | if (tplg->pass != SOC_TPLG_PASS_GRAPH) { | |
1133 | tplg->pos += hdr->size + hdr->payload_size; | |
1134 | return 0; | |
1135 | } | |
1136 | ||
1137 | if (soc_tplg_check_elem_count(tplg, | |
1138 | sizeof(struct snd_soc_tplg_dapm_graph_elem), | |
1139 | count, hdr->payload_size, "graph")) { | |
1140 | ||
1141 | dev_err(tplg->dev, "ASoC: invalid count %d for DAPM routes\n", | |
1142 | count); | |
1143 | return -EINVAL; | |
1144 | } | |
1145 | ||
1146 | dev_dbg(tplg->dev, "ASoC: adding %d DAPM routes\n", count); | |
1147 | ||
1148 | for (i = 0; i < count; i++) { | |
1149 | elem = (struct snd_soc_tplg_dapm_graph_elem *)tplg->pos; | |
1150 | tplg->pos += sizeof(struct snd_soc_tplg_dapm_graph_elem); | |
1151 | ||
1152 | /* validate routes */ | |
1153 | if (strnlen(elem->source, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | |
1154 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | |
1155 | return -EINVAL; | |
1156 | if (strnlen(elem->sink, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | |
1157 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | |
1158 | return -EINVAL; | |
1159 | if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | |
1160 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | |
1161 | return -EINVAL; | |
1162 | ||
1163 | route.source = elem->source; | |
1164 | route.sink = elem->sink; | |
1165 | route.connected = NULL; /* set to NULL atm for tplg users */ | |
1166 | if (strnlen(elem->control, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == 0) | |
1167 | route.control = NULL; | |
1168 | else | |
1169 | route.control = elem->control; | |
1170 | ||
1171 | /* add route, but keep going if some fail */ | |
1172 | snd_soc_dapm_add_routes(dapm, &route, 1); | |
1173 | } | |
1174 | ||
1175 | return 0; | |
1176 | } | |
1177 | ||
1178 | static struct snd_kcontrol_new *soc_tplg_dapm_widget_dmixer_create( | |
1179 | struct soc_tplg *tplg, int num_kcontrols) | |
1180 | { | |
1181 | struct snd_kcontrol_new *kc; | |
1182 | struct soc_mixer_control *sm; | |
1183 | struct snd_soc_tplg_mixer_control *mc; | |
1184 | int i, err; | |
1185 | ||
4ca7deb1 | 1186 | kc = kcalloc(num_kcontrols, sizeof(*kc), GFP_KERNEL); |
8a978234 LG |
1187 | if (kc == NULL) |
1188 | return NULL; | |
1189 | ||
1190 | for (i = 0; i < num_kcontrols; i++) { | |
1191 | mc = (struct snd_soc_tplg_mixer_control *)tplg->pos; | |
1192 | sm = kzalloc(sizeof(*sm), GFP_KERNEL); | |
1193 | if (sm == NULL) | |
1194 | goto err; | |
1195 | ||
1196 | tplg->pos += (sizeof(struct snd_soc_tplg_mixer_control) + | |
1197 | mc->priv.size); | |
1198 | ||
1199 | /* validate kcontrol */ | |
1200 | if (strnlen(mc->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | |
1201 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | |
1202 | goto err_str; | |
1203 | ||
1204 | dev_dbg(tplg->dev, " adding DAPM widget mixer control %s at %d\n", | |
1205 | mc->hdr.name, i); | |
1206 | ||
1207 | kc[i].name = mc->hdr.name; | |
1208 | kc[i].private_value = (long)sm; | |
1209 | kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
1210 | kc[i].access = mc->hdr.access; | |
1211 | ||
1212 | /* we only support FL/FR channel mapping atm */ | |
1213 | sm->reg = tplc_chan_get_reg(tplg, mc->channel, | |
1214 | SNDRV_CHMAP_FL); | |
1215 | sm->rreg = tplc_chan_get_reg(tplg, mc->channel, | |
1216 | SNDRV_CHMAP_FR); | |
1217 | sm->shift = tplc_chan_get_shift(tplg, mc->channel, | |
1218 | SNDRV_CHMAP_FL); | |
1219 | sm->rshift = tplc_chan_get_shift(tplg, mc->channel, | |
1220 | SNDRV_CHMAP_FR); | |
1221 | ||
1222 | sm->max = mc->max; | |
1223 | sm->min = mc->min; | |
1224 | sm->invert = mc->invert; | |
1225 | sm->platform_max = mc->platform_max; | |
1226 | sm->dobj.index = tplg->index; | |
1227 | INIT_LIST_HEAD(&sm->dobj.list); | |
1228 | ||
1229 | /* map io handlers */ | |
2b5cdb91 | 1230 | err = soc_tplg_kcontrol_bind_io(&mc->hdr, &kc[i], tplg); |
8a978234 LG |
1231 | if (err) { |
1232 | soc_control_err(tplg, &mc->hdr, mc->hdr.name); | |
1233 | kfree(sm); | |
1234 | continue; | |
1235 | } | |
1236 | ||
1237 | /* pass control to driver for optional further init */ | |
1238 | err = soc_tplg_init_kcontrol(tplg, &kc[i], | |
1239 | (struct snd_soc_tplg_ctl_hdr *)mc); | |
1240 | if (err < 0) { | |
1241 | dev_err(tplg->dev, "ASoC: failed to init %s\n", | |
1242 | mc->hdr.name); | |
1243 | kfree(sm); | |
1244 | continue; | |
1245 | } | |
1246 | } | |
1247 | return kc; | |
1248 | ||
1249 | err_str: | |
1250 | kfree(sm); | |
1251 | err: | |
1252 | for (--i; i >= 0; i--) | |
1253 | kfree((void *)kc[i].private_value); | |
1254 | kfree(kc); | |
1255 | return NULL; | |
1256 | } | |
1257 | ||
1258 | static struct snd_kcontrol_new *soc_tplg_dapm_widget_denum_create( | |
1259 | struct soc_tplg *tplg) | |
1260 | { | |
1261 | struct snd_kcontrol_new *kc; | |
1262 | struct snd_soc_tplg_enum_control *ec; | |
1263 | struct soc_enum *se; | |
1264 | int i, err; | |
1265 | ||
1266 | ec = (struct snd_soc_tplg_enum_control *)tplg->pos; | |
1267 | tplg->pos += (sizeof(struct snd_soc_tplg_enum_control) + | |
1268 | ec->priv.size); | |
1269 | ||
1270 | /* validate kcontrol */ | |
1271 | if (strnlen(ec->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | |
1272 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | |
1273 | return NULL; | |
1274 | ||
1275 | kc = kzalloc(sizeof(*kc), GFP_KERNEL); | |
1276 | if (kc == NULL) | |
1277 | return NULL; | |
1278 | ||
1279 | se = kzalloc(sizeof(*se), GFP_KERNEL); | |
1280 | if (se == NULL) | |
1281 | goto err; | |
1282 | ||
1283 | dev_dbg(tplg->dev, " adding DAPM widget enum control %s\n", | |
1284 | ec->hdr.name); | |
1285 | ||
1286 | kc->name = ec->hdr.name; | |
1287 | kc->private_value = (long)se; | |
1288 | kc->iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
1289 | kc->access = ec->hdr.access; | |
1290 | ||
1291 | /* we only support FL/FR channel mapping atm */ | |
1292 | se->reg = tplc_chan_get_reg(tplg, ec->channel, SNDRV_CHMAP_FL); | |
1293 | se->shift_l = tplc_chan_get_shift(tplg, ec->channel, SNDRV_CHMAP_FL); | |
1294 | se->shift_r = tplc_chan_get_shift(tplg, ec->channel, SNDRV_CHMAP_FR); | |
1295 | ||
1296 | se->items = ec->items; | |
1297 | se->mask = ec->mask; | |
1298 | se->dobj.index = tplg->index; | |
1299 | ||
1300 | switch (ec->hdr.ops.info) { | |
1301 | case SND_SOC_TPLG_CTL_ENUM_VALUE: | |
1302 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE: | |
1303 | err = soc_tplg_denum_create_values(se, ec); | |
1304 | if (err < 0) { | |
1305 | dev_err(tplg->dev, "ASoC: could not create values for %s\n", | |
1306 | ec->hdr.name); | |
1307 | goto err_se; | |
1308 | } | |
1309 | /* fall through to create texts */ | |
1310 | case SND_SOC_TPLG_CTL_ENUM: | |
1311 | case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE: | |
1312 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT: | |
1313 | err = soc_tplg_denum_create_texts(se, ec); | |
1314 | if (err < 0) { | |
1315 | dev_err(tplg->dev, "ASoC: could not create texts for %s\n", | |
1316 | ec->hdr.name); | |
1317 | goto err_se; | |
1318 | } | |
1319 | break; | |
1320 | default: | |
1321 | dev_err(tplg->dev, "ASoC: invalid enum control type %d for %s\n", | |
1322 | ec->hdr.ops.info, ec->hdr.name); | |
1323 | goto err_se; | |
1324 | } | |
1325 | ||
1326 | /* map io handlers */ | |
2b5cdb91 | 1327 | err = soc_tplg_kcontrol_bind_io(&ec->hdr, kc, tplg); |
8a978234 LG |
1328 | if (err) { |
1329 | soc_control_err(tplg, &ec->hdr, ec->hdr.name); | |
1330 | goto err_se; | |
1331 | } | |
1332 | ||
1333 | /* pass control to driver for optional further init */ | |
1334 | err = soc_tplg_init_kcontrol(tplg, kc, | |
1335 | (struct snd_soc_tplg_ctl_hdr *)ec); | |
1336 | if (err < 0) { | |
1337 | dev_err(tplg->dev, "ASoC: failed to init %s\n", | |
1338 | ec->hdr.name); | |
1339 | goto err_se; | |
1340 | } | |
1341 | ||
1342 | return kc; | |
1343 | ||
1344 | err_se: | |
1345 | /* free values and texts */ | |
1346 | kfree(se->dobj.control.dvalues); | |
1347 | for (i = 0; i < ec->items; i++) | |
1348 | kfree(se->dobj.control.dtexts[i]); | |
1349 | ||
1350 | kfree(se); | |
1351 | err: | |
1352 | kfree(kc); | |
1353 | ||
1354 | return NULL; | |
1355 | } | |
1356 | ||
1357 | static struct snd_kcontrol_new *soc_tplg_dapm_widget_dbytes_create( | |
1358 | struct soc_tplg *tplg, int count) | |
1359 | { | |
1360 | struct snd_soc_tplg_bytes_control *be; | |
1361 | struct soc_bytes_ext *sbe; | |
1362 | struct snd_kcontrol_new *kc; | |
1363 | int i, err; | |
1364 | ||
4ca7deb1 | 1365 | kc = kcalloc(count, sizeof(*kc), GFP_KERNEL); |
8a978234 LG |
1366 | if (!kc) |
1367 | return NULL; | |
1368 | ||
1369 | for (i = 0; i < count; i++) { | |
1370 | be = (struct snd_soc_tplg_bytes_control *)tplg->pos; | |
1371 | ||
1372 | /* validate kcontrol */ | |
1373 | if (strnlen(be->hdr.name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | |
1374 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | |
1375 | goto err; | |
1376 | ||
1377 | sbe = kzalloc(sizeof(*sbe), GFP_KERNEL); | |
1378 | if (sbe == NULL) | |
1379 | goto err; | |
1380 | ||
1381 | tplg->pos += (sizeof(struct snd_soc_tplg_bytes_control) + | |
1382 | be->priv.size); | |
1383 | ||
1384 | dev_dbg(tplg->dev, | |
1385 | "ASoC: adding bytes kcontrol %s with access 0x%x\n", | |
1386 | be->hdr.name, be->hdr.access); | |
1387 | ||
8a978234 LG |
1388 | kc[i].name = be->hdr.name; |
1389 | kc[i].private_value = (long)sbe; | |
1390 | kc[i].iface = SNDRV_CTL_ELEM_IFACE_MIXER; | |
1391 | kc[i].access = be->hdr.access; | |
1392 | ||
1393 | sbe->max = be->max; | |
1394 | INIT_LIST_HEAD(&sbe->dobj.list); | |
1395 | ||
1396 | /* map standard io handlers and check for external handlers */ | |
2b5cdb91 | 1397 | err = soc_tplg_kcontrol_bind_io(&be->hdr, &kc[i], tplg); |
8a978234 LG |
1398 | if (err) { |
1399 | soc_control_err(tplg, &be->hdr, be->hdr.name); | |
1400 | kfree(sbe); | |
1401 | continue; | |
1402 | } | |
1403 | ||
1404 | /* pass control to driver for optional further init */ | |
1405 | err = soc_tplg_init_kcontrol(tplg, &kc[i], | |
1406 | (struct snd_soc_tplg_ctl_hdr *)be); | |
1407 | if (err < 0) { | |
1408 | dev_err(tplg->dev, "ASoC: failed to init %s\n", | |
1409 | be->hdr.name); | |
1410 | kfree(sbe); | |
1411 | continue; | |
1412 | } | |
1413 | } | |
1414 | ||
1415 | return kc; | |
1416 | ||
1417 | err: | |
1418 | for (--i; i >= 0; i--) | |
1419 | kfree((void *)kc[i].private_value); | |
1420 | ||
1421 | kfree(kc); | |
1422 | return NULL; | |
1423 | } | |
1424 | ||
1425 | static int soc_tplg_dapm_widget_create(struct soc_tplg *tplg, | |
1426 | struct snd_soc_tplg_dapm_widget *w) | |
1427 | { | |
1428 | struct snd_soc_dapm_context *dapm = &tplg->comp->dapm; | |
1429 | struct snd_soc_dapm_widget template, *widget; | |
1430 | struct snd_soc_tplg_ctl_hdr *control_hdr; | |
1431 | struct snd_soc_card *card = tplg->comp->card; | |
1432 | int ret = 0; | |
1433 | ||
1434 | if (strnlen(w->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | |
1435 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | |
1436 | return -EINVAL; | |
1437 | if (strnlen(w->sname, SNDRV_CTL_ELEM_ID_NAME_MAXLEN) == | |
1438 | SNDRV_CTL_ELEM_ID_NAME_MAXLEN) | |
1439 | return -EINVAL; | |
1440 | ||
1441 | dev_dbg(tplg->dev, "ASoC: creating DAPM widget %s id %d\n", | |
1442 | w->name, w->id); | |
1443 | ||
1444 | memset(&template, 0, sizeof(template)); | |
1445 | ||
1446 | /* map user to kernel widget ID */ | |
1447 | template.id = get_widget_id(w->id); | |
1448 | if (template.id < 0) | |
1449 | return template.id; | |
1450 | ||
1451 | template.name = kstrdup(w->name, GFP_KERNEL); | |
1452 | if (!template.name) | |
1453 | return -ENOMEM; | |
1454 | template.sname = kstrdup(w->sname, GFP_KERNEL); | |
1455 | if (!template.sname) { | |
1456 | ret = -ENOMEM; | |
1457 | goto err; | |
1458 | } | |
1459 | template.reg = w->reg; | |
1460 | template.shift = w->shift; | |
1461 | template.mask = w->mask; | |
6dc6db79 | 1462 | template.subseq = w->subseq; |
8a978234 LG |
1463 | template.on_val = w->invert ? 0 : 1; |
1464 | template.off_val = w->invert ? 1 : 0; | |
1465 | template.ignore_suspend = w->ignore_suspend; | |
1466 | template.event_flags = w->event_flags; | |
1467 | template.dobj.index = tplg->index; | |
1468 | ||
1469 | tplg->pos += | |
1470 | (sizeof(struct snd_soc_tplg_dapm_widget) + w->priv.size); | |
1471 | if (w->num_kcontrols == 0) { | |
1472 | template.num_kcontrols = 0; | |
1473 | goto widget; | |
1474 | } | |
1475 | ||
1476 | control_hdr = (struct snd_soc_tplg_ctl_hdr *)tplg->pos; | |
1477 | dev_dbg(tplg->dev, "ASoC: template %s has %d controls of type %x\n", | |
1478 | w->name, w->num_kcontrols, control_hdr->type); | |
1479 | ||
1480 | switch (control_hdr->ops.info) { | |
1481 | case SND_SOC_TPLG_CTL_VOLSW: | |
1482 | case SND_SOC_TPLG_CTL_STROBE: | |
1483 | case SND_SOC_TPLG_CTL_VOLSW_SX: | |
1484 | case SND_SOC_TPLG_CTL_VOLSW_XR_SX: | |
1485 | case SND_SOC_TPLG_CTL_RANGE: | |
1486 | case SND_SOC_TPLG_DAPM_CTL_VOLSW: | |
1487 | template.num_kcontrols = w->num_kcontrols; | |
1488 | template.kcontrol_news = | |
1489 | soc_tplg_dapm_widget_dmixer_create(tplg, | |
1490 | template.num_kcontrols); | |
1491 | if (!template.kcontrol_news) { | |
1492 | ret = -ENOMEM; | |
1493 | goto hdr_err; | |
1494 | } | |
1495 | break; | |
1496 | case SND_SOC_TPLG_CTL_ENUM: | |
1497 | case SND_SOC_TPLG_CTL_ENUM_VALUE: | |
1498 | case SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE: | |
1499 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT: | |
1500 | case SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE: | |
1501 | template.dobj.widget.kcontrol_enum = 1; | |
1502 | template.num_kcontrols = 1; | |
1503 | template.kcontrol_news = | |
1504 | soc_tplg_dapm_widget_denum_create(tplg); | |
1505 | if (!template.kcontrol_news) { | |
1506 | ret = -ENOMEM; | |
1507 | goto hdr_err; | |
1508 | } | |
1509 | break; | |
1510 | case SND_SOC_TPLG_CTL_BYTES: | |
1511 | template.num_kcontrols = w->num_kcontrols; | |
1512 | template.kcontrol_news = | |
1513 | soc_tplg_dapm_widget_dbytes_create(tplg, | |
1514 | template.num_kcontrols); | |
1515 | if (!template.kcontrol_news) { | |
1516 | ret = -ENOMEM; | |
1517 | goto hdr_err; | |
1518 | } | |
1519 | break; | |
1520 | default: | |
1521 | dev_err(tplg->dev, "ASoC: invalid widget control type %d:%d:%d\n", | |
1522 | control_hdr->ops.get, control_hdr->ops.put, | |
1523 | control_hdr->ops.info); | |
1524 | ret = -EINVAL; | |
1525 | goto hdr_err; | |
1526 | } | |
1527 | ||
1528 | widget: | |
1529 | ret = soc_tplg_widget_load(tplg, &template, w); | |
1530 | if (ret < 0) | |
1531 | goto hdr_err; | |
1532 | ||
1533 | /* card dapm mutex is held by the core if we are loading topology | |
1534 | * data during sound card init. */ | |
1535 | if (card->instantiated) | |
1536 | widget = snd_soc_dapm_new_control(dapm, &template); | |
1537 | else | |
1538 | widget = snd_soc_dapm_new_control_unlocked(dapm, &template); | |
1539 | if (widget == NULL) { | |
1540 | dev_err(tplg->dev, "ASoC: failed to create widget %s controls\n", | |
1541 | w->name); | |
8ae3ea48 | 1542 | ret = -ENOMEM; |
8a978234 LG |
1543 | goto hdr_err; |
1544 | } | |
1545 | ||
1546 | widget->dobj.type = SND_SOC_DOBJ_WIDGET; | |
1547 | widget->dobj.ops = tplg->ops; | |
1548 | widget->dobj.index = tplg->index; | |
8ea41674 JK |
1549 | kfree(template.sname); |
1550 | kfree(template.name); | |
8a978234 LG |
1551 | list_add(&widget->dobj.list, &tplg->comp->dobj_list); |
1552 | return 0; | |
1553 | ||
1554 | hdr_err: | |
1555 | kfree(template.sname); | |
1556 | err: | |
1557 | kfree(template.name); | |
1558 | return ret; | |
1559 | } | |
1560 | ||
1561 | static int soc_tplg_dapm_widget_elems_load(struct soc_tplg *tplg, | |
1562 | struct snd_soc_tplg_hdr *hdr) | |
1563 | { | |
1564 | struct snd_soc_tplg_dapm_widget *widget; | |
1565 | int ret, count = hdr->count, i; | |
1566 | ||
1567 | if (tplg->pass != SOC_TPLG_PASS_WIDGET) | |
1568 | return 0; | |
1569 | ||
1570 | dev_dbg(tplg->dev, "ASoC: adding %d DAPM widgets\n", count); | |
1571 | ||
1572 | for (i = 0; i < count; i++) { | |
1573 | widget = (struct snd_soc_tplg_dapm_widget *) tplg->pos; | |
06eb49f7 ML |
1574 | if (widget->size != sizeof(*widget)) { |
1575 | dev_err(tplg->dev, "ASoC: invalid widget size\n"); | |
1576 | return -EINVAL; | |
1577 | } | |
1578 | ||
8a978234 | 1579 | ret = soc_tplg_dapm_widget_create(tplg, widget); |
7de76b62 | 1580 | if (ret < 0) { |
8a978234 LG |
1581 | dev_err(tplg->dev, "ASoC: failed to load widget %s\n", |
1582 | widget->name); | |
7de76b62 ML |
1583 | return ret; |
1584 | } | |
8a978234 LG |
1585 | } |
1586 | ||
1587 | return 0; | |
1588 | } | |
1589 | ||
1590 | static int soc_tplg_dapm_complete(struct soc_tplg *tplg) | |
1591 | { | |
1592 | struct snd_soc_card *card = tplg->comp->card; | |
1593 | int ret; | |
1594 | ||
1595 | /* Card might not have been registered at this point. | |
1596 | * If so, just return success. | |
1597 | */ | |
1598 | if (!card || !card->instantiated) { | |
1599 | dev_warn(tplg->dev, "ASoC: Parent card not yet available," | |
1600 | "Do not add new widgets now\n"); | |
1601 | return 0; | |
1602 | } | |
1603 | ||
1604 | ret = snd_soc_dapm_new_widgets(card); | |
1605 | if (ret < 0) | |
1606 | dev_err(tplg->dev, "ASoC: failed to create new widgets %d\n", | |
1607 | ret); | |
1608 | ||
1609 | return 0; | |
1610 | } | |
1611 | ||
b6b6e4d6 ML |
1612 | static void set_stream_info(struct snd_soc_pcm_stream *stream, |
1613 | struct snd_soc_tplg_stream_caps *caps) | |
1614 | { | |
1615 | stream->stream_name = kstrdup(caps->name, GFP_KERNEL); | |
1616 | stream->channels_min = caps->channels_min; | |
1617 | stream->channels_max = caps->channels_max; | |
1618 | stream->rates = caps->rates; | |
1619 | stream->rate_min = caps->rate_min; | |
1620 | stream->rate_max = caps->rate_max; | |
1621 | stream->formats = caps->formats; | |
f918e169 | 1622 | stream->sig_bits = caps->sig_bits; |
b6b6e4d6 ML |
1623 | } |
1624 | ||
0038be9a ML |
1625 | static void set_dai_flags(struct snd_soc_dai_driver *dai_drv, |
1626 | unsigned int flag_mask, unsigned int flags) | |
1627 | { | |
1628 | if (flag_mask & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES) | |
1629 | dai_drv->symmetric_rates = | |
1630 | flags & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES ? 1 : 0; | |
1631 | ||
1632 | if (flag_mask & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS) | |
1633 | dai_drv->symmetric_channels = | |
1634 | flags & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS ? | |
1635 | 1 : 0; | |
1636 | ||
1637 | if (flag_mask & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS) | |
1638 | dai_drv->symmetric_samplebits = | |
1639 | flags & SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS ? | |
1640 | 1 : 0; | |
1641 | } | |
1642 | ||
64527e8a ML |
1643 | static int soc_tplg_dai_create(struct soc_tplg *tplg, |
1644 | struct snd_soc_tplg_pcm *pcm) | |
1645 | { | |
1646 | struct snd_soc_dai_driver *dai_drv; | |
1647 | struct snd_soc_pcm_stream *stream; | |
1648 | struct snd_soc_tplg_stream_caps *caps; | |
1649 | int ret; | |
1650 | ||
1651 | dai_drv = kzalloc(sizeof(struct snd_soc_dai_driver), GFP_KERNEL); | |
1652 | if (dai_drv == NULL) | |
1653 | return -ENOMEM; | |
1654 | ||
8f27c4ab ML |
1655 | if (strlen(pcm->dai_name)) |
1656 | dai_drv->name = kstrdup(pcm->dai_name, GFP_KERNEL); | |
64527e8a ML |
1657 | dai_drv->id = pcm->dai_id; |
1658 | ||
1659 | if (pcm->playback) { | |
1660 | stream = &dai_drv->playback; | |
1661 | caps = &pcm->caps[SND_SOC_TPLG_STREAM_PLAYBACK]; | |
b6b6e4d6 | 1662 | set_stream_info(stream, caps); |
64527e8a ML |
1663 | } |
1664 | ||
1665 | if (pcm->capture) { | |
1666 | stream = &dai_drv->capture; | |
1667 | caps = &pcm->caps[SND_SOC_TPLG_STREAM_CAPTURE]; | |
b6b6e4d6 | 1668 | set_stream_info(stream, caps); |
64527e8a ML |
1669 | } |
1670 | ||
1671 | /* pass control to component driver for optional further init */ | |
1672 | ret = soc_tplg_dai_load(tplg, dai_drv); | |
1673 | if (ret < 0) { | |
1674 | dev_err(tplg->comp->dev, "ASoC: DAI loading failed\n"); | |
1675 | kfree(dai_drv); | |
1676 | return ret; | |
1677 | } | |
1678 | ||
1679 | dai_drv->dobj.index = tplg->index; | |
1680 | dai_drv->dobj.ops = tplg->ops; | |
1681 | dai_drv->dobj.type = SND_SOC_DOBJ_PCM; | |
1682 | list_add(&dai_drv->dobj.list, &tplg->comp->dobj_list); | |
1683 | ||
1684 | /* register the DAI to the component */ | |
1685 | return snd_soc_register_dai(tplg->comp, dai_drv); | |
1686 | } | |
1687 | ||
717a8e72 ML |
1688 | static void set_link_flags(struct snd_soc_dai_link *link, |
1689 | unsigned int flag_mask, unsigned int flags) | |
1690 | { | |
1691 | if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES) | |
1692 | link->symmetric_rates = | |
1693 | flags & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_RATES ? 1 : 0; | |
1694 | ||
1695 | if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS) | |
1696 | link->symmetric_channels = | |
1697 | flags & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_CHANNELS ? | |
1698 | 1 : 0; | |
1699 | ||
1700 | if (flag_mask & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS) | |
1701 | link->symmetric_samplebits = | |
1702 | flags & SND_SOC_TPLG_LNK_FLGBIT_SYMMETRIC_SAMPLEBITS ? | |
1703 | 1 : 0; | |
1704 | } | |
1705 | ||
67d1c21e | 1706 | /* create the FE DAI link */ |
ab4bc5ee | 1707 | static int soc_tplg_fe_link_create(struct soc_tplg *tplg, |
acfc7d46 ML |
1708 | struct snd_soc_tplg_pcm *pcm) |
1709 | { | |
1710 | struct snd_soc_dai_link *link; | |
1711 | int ret; | |
1712 | ||
1713 | link = kzalloc(sizeof(struct snd_soc_dai_link), GFP_KERNEL); | |
1714 | if (link == NULL) | |
1715 | return -ENOMEM; | |
1716 | ||
8f27c4ab ML |
1717 | if (strlen(pcm->pcm_name)) { |
1718 | link->name = kstrdup(pcm->pcm_name, GFP_KERNEL); | |
1719 | link->stream_name = kstrdup(pcm->pcm_name, GFP_KERNEL); | |
1720 | } | |
b84fff5a | 1721 | link->id = pcm->pcm_id; |
acfc7d46 | 1722 | |
8f27c4ab ML |
1723 | if (strlen(pcm->dai_name)) |
1724 | link->cpu_dai_name = kstrdup(pcm->dai_name, GFP_KERNEL); | |
1725 | ||
67d1c21e GS |
1726 | link->codec_name = "snd-soc-dummy"; |
1727 | link->codec_dai_name = "snd-soc-dummy-dai"; | |
1728 | ||
1729 | /* enable DPCM */ | |
1730 | link->dynamic = 1; | |
1731 | link->dpcm_playback = pcm->playback; | |
1732 | link->dpcm_capture = pcm->capture; | |
717a8e72 ML |
1733 | if (pcm->flag_mask) |
1734 | set_link_flags(link, pcm->flag_mask, pcm->flags); | |
67d1c21e | 1735 | |
acfc7d46 ML |
1736 | /* pass control to component driver for optional further init */ |
1737 | ret = soc_tplg_dai_link_load(tplg, link); | |
1738 | if (ret < 0) { | |
1739 | dev_err(tplg->comp->dev, "ASoC: FE link loading failed\n"); | |
1740 | kfree(link); | |
1741 | return ret; | |
1742 | } | |
1743 | ||
1744 | link->dobj.index = tplg->index; | |
1745 | link->dobj.ops = tplg->ops; | |
1746 | link->dobj.type = SND_SOC_DOBJ_DAI_LINK; | |
1747 | list_add(&link->dobj.list, &tplg->comp->dobj_list); | |
1748 | ||
1749 | snd_soc_add_dai_link(tplg->comp->card, link); | |
1750 | return 0; | |
1751 | } | |
1752 | ||
1753 | /* create a FE DAI and DAI link from the PCM object */ | |
64527e8a ML |
1754 | static int soc_tplg_pcm_create(struct soc_tplg *tplg, |
1755 | struct snd_soc_tplg_pcm *pcm) | |
1756 | { | |
acfc7d46 ML |
1757 | int ret; |
1758 | ||
1759 | ret = soc_tplg_dai_create(tplg, pcm); | |
1760 | if (ret < 0) | |
1761 | return ret; | |
1762 | ||
ab4bc5ee | 1763 | return soc_tplg_fe_link_create(tplg, pcm); |
64527e8a ML |
1764 | } |
1765 | ||
55726dc9 ML |
1766 | /* copy stream caps from the old version 4 of source */ |
1767 | static void stream_caps_new_ver(struct snd_soc_tplg_stream_caps *dest, | |
1768 | struct snd_soc_tplg_stream_caps_v4 *src) | |
1769 | { | |
1770 | dest->size = sizeof(*dest); | |
1771 | memcpy(dest->name, src->name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); | |
1772 | dest->formats = src->formats; | |
1773 | dest->rates = src->rates; | |
1774 | dest->rate_min = src->rate_min; | |
1775 | dest->rate_max = src->rate_max; | |
1776 | dest->channels_min = src->channels_min; | |
1777 | dest->channels_max = src->channels_max; | |
1778 | dest->periods_min = src->periods_min; | |
1779 | dest->periods_max = src->periods_max; | |
1780 | dest->period_size_min = src->period_size_min; | |
1781 | dest->period_size_max = src->period_size_max; | |
1782 | dest->buffer_size_min = src->buffer_size_min; | |
1783 | dest->buffer_size_max = src->buffer_size_max; | |
1784 | } | |
1785 | ||
1786 | /** | |
1787 | * pcm_new_ver - Create the new version of PCM from the old version. | |
1788 | * @tplg: topology context | |
1789 | * @src: older version of pcm as a source | |
1790 | * @pcm: latest version of pcm created from the source | |
1791 | * | |
1792 | * Support from vesion 4. User should free the returned pcm manually. | |
1793 | */ | |
1794 | static int pcm_new_ver(struct soc_tplg *tplg, | |
1795 | struct snd_soc_tplg_pcm *src, | |
1796 | struct snd_soc_tplg_pcm **pcm) | |
1797 | { | |
1798 | struct snd_soc_tplg_pcm *dest; | |
1799 | struct snd_soc_tplg_pcm_v4 *src_v4; | |
1800 | int i; | |
1801 | ||
1802 | *pcm = NULL; | |
1803 | ||
1804 | if (src->size != sizeof(*src_v4)) { | |
1805 | dev_err(tplg->dev, "ASoC: invalid PCM size\n"); | |
1806 | return -EINVAL; | |
1807 | } | |
1808 | ||
1809 | dev_warn(tplg->dev, "ASoC: old version of PCM\n"); | |
1810 | src_v4 = (struct snd_soc_tplg_pcm_v4 *)src; | |
1811 | dest = kzalloc(sizeof(*dest), GFP_KERNEL); | |
1812 | if (!dest) | |
1813 | return -ENOMEM; | |
1814 | ||
1815 | dest->size = sizeof(*dest); /* size of latest abi version */ | |
1816 | memcpy(dest->pcm_name, src_v4->pcm_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); | |
1817 | memcpy(dest->dai_name, src_v4->dai_name, SNDRV_CTL_ELEM_ID_NAME_MAXLEN); | |
1818 | dest->pcm_id = src_v4->pcm_id; | |
1819 | dest->dai_id = src_v4->dai_id; | |
1820 | dest->playback = src_v4->playback; | |
1821 | dest->capture = src_v4->capture; | |
1822 | dest->compress = src_v4->compress; | |
1823 | dest->num_streams = src_v4->num_streams; | |
1824 | for (i = 0; i < dest->num_streams; i++) | |
1825 | memcpy(&dest->stream[i], &src_v4->stream[i], | |
1826 | sizeof(struct snd_soc_tplg_stream)); | |
1827 | ||
1828 | for (i = 0; i < 2; i++) | |
1829 | stream_caps_new_ver(&dest->caps[i], &src_v4->caps[i]); | |
1830 | ||
1831 | *pcm = dest; | |
1832 | return 0; | |
1833 | } | |
1834 | ||
64527e8a | 1835 | static int soc_tplg_pcm_elems_load(struct soc_tplg *tplg, |
8a978234 LG |
1836 | struct snd_soc_tplg_hdr *hdr) |
1837 | { | |
55726dc9 | 1838 | struct snd_soc_tplg_pcm *pcm, *_pcm; |
8a978234 | 1839 | int count = hdr->count; |
55726dc9 ML |
1840 | int i, err; |
1841 | bool abi_match; | |
8a978234 LG |
1842 | |
1843 | if (tplg->pass != SOC_TPLG_PASS_PCM_DAI) | |
1844 | return 0; | |
1845 | ||
55726dc9 ML |
1846 | /* check the element size and count */ |
1847 | pcm = (struct snd_soc_tplg_pcm *)tplg->pos; | |
1848 | if (pcm->size > sizeof(struct snd_soc_tplg_pcm) | |
1849 | || pcm->size < sizeof(struct snd_soc_tplg_pcm_v4)) { | |
1850 | dev_err(tplg->dev, "ASoC: invalid size %d for PCM elems\n", | |
1851 | pcm->size); | |
1852 | return -EINVAL; | |
1853 | } | |
1854 | ||
8a978234 | 1855 | if (soc_tplg_check_elem_count(tplg, |
55726dc9 | 1856 | pcm->size, count, |
8a978234 LG |
1857 | hdr->payload_size, "PCM DAI")) { |
1858 | dev_err(tplg->dev, "ASoC: invalid count %d for PCM DAI elems\n", | |
1859 | count); | |
1860 | return -EINVAL; | |
1861 | } | |
1862 | ||
64527e8a | 1863 | for (i = 0; i < count; i++) { |
55726dc9 ML |
1864 | pcm = (struct snd_soc_tplg_pcm *)tplg->pos; |
1865 | ||
1866 | /* check ABI version by size, create a new version of pcm | |
1867 | * if abi not match. | |
1868 | */ | |
1869 | if (pcm->size == sizeof(*pcm)) { | |
1870 | abi_match = true; | |
1871 | _pcm = pcm; | |
1872 | } else { | |
1873 | abi_match = false; | |
1874 | err = pcm_new_ver(tplg, pcm, &_pcm); | |
06eb49f7 ML |
1875 | } |
1876 | ||
55726dc9 ML |
1877 | /* create the FE DAIs and DAI links */ |
1878 | soc_tplg_pcm_create(tplg, _pcm); | |
1879 | ||
717a8e72 ML |
1880 | /* offset by version-specific struct size and |
1881 | * real priv data size | |
1882 | */ | |
1883 | tplg->pos += pcm->size + _pcm->priv.size; | |
1884 | ||
55726dc9 ML |
1885 | if (!abi_match) |
1886 | kfree(_pcm); /* free the duplicated one */ | |
64527e8a ML |
1887 | } |
1888 | ||
8a978234 | 1889 | dev_dbg(tplg->dev, "ASoC: adding %d PCM DAIs\n", count); |
8a978234 | 1890 | |
8a978234 | 1891 | return 0; |
8a978234 LG |
1892 | } |
1893 | ||
593d9e52 ML |
1894 | /** |
1895 | * set_link_hw_format - Set the HW audio format of the physical DAI link. | |
1896 | * @tplg: topology context | |
1897 | * @cfg: physical link configs. | |
1898 | * | |
1899 | * Topology context contains a list of supported HW formats (configs) and | |
1900 | * a default format ID for the physical link. This function will use this | |
1901 | * default ID to choose the HW format to set the link's DAI format for init. | |
1902 | */ | |
1903 | static void set_link_hw_format(struct snd_soc_dai_link *link, | |
1904 | struct snd_soc_tplg_link_config *cfg) | |
1905 | { | |
1906 | struct snd_soc_tplg_hw_config *hw_config; | |
1907 | unsigned char bclk_master, fsync_master; | |
1908 | unsigned char invert_bclk, invert_fsync; | |
1909 | int i; | |
1910 | ||
1911 | for (i = 0; i < cfg->num_hw_configs; i++) { | |
1912 | hw_config = &cfg->hw_config[i]; | |
1913 | if (hw_config->id != cfg->default_hw_config_id) | |
1914 | continue; | |
1915 | ||
1916 | link->dai_fmt = hw_config->fmt & SND_SOC_DAIFMT_FORMAT_MASK; | |
1917 | ||
1918 | /* clock signal polarity */ | |
1919 | invert_bclk = hw_config->invert_bclk; | |
1920 | invert_fsync = hw_config->invert_fsync; | |
1921 | if (!invert_bclk && !invert_fsync) | |
1922 | link->dai_fmt |= SND_SOC_DAIFMT_NB_NF; | |
1923 | else if (!invert_bclk && invert_fsync) | |
1924 | link->dai_fmt |= SND_SOC_DAIFMT_NB_IF; | |
1925 | else if (invert_bclk && !invert_fsync) | |
1926 | link->dai_fmt |= SND_SOC_DAIFMT_IB_NF; | |
1927 | else | |
1928 | link->dai_fmt |= SND_SOC_DAIFMT_IB_IF; | |
1929 | ||
1930 | /* clock masters */ | |
1931 | bclk_master = hw_config->bclk_master; | |
1932 | fsync_master = hw_config->fsync_master; | |
1933 | if (!bclk_master && !fsync_master) | |
1934 | link->dai_fmt |= SND_SOC_DAIFMT_CBM_CFM; | |
1935 | else if (bclk_master && !fsync_master) | |
1936 | link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFM; | |
1937 | else if (!bclk_master && fsync_master) | |
1938 | link->dai_fmt |= SND_SOC_DAIFMT_CBM_CFS; | |
1939 | else | |
1940 | link->dai_fmt |= SND_SOC_DAIFMT_CBS_CFS; | |
1941 | } | |
1942 | } | |
1943 | ||
1944 | /** | |
1945 | * link_new_ver - Create a new physical link config from the old | |
1946 | * version of source. | |
1947 | * @toplogy: topology context | |
1948 | * @src: old version of phyical link config as a source | |
1949 | * @link: latest version of physical link config created from the source | |
1950 | * | |
1951 | * Support from vesion 4. User need free the returned link config manually. | |
1952 | */ | |
1953 | static int link_new_ver(struct soc_tplg *tplg, | |
1954 | struct snd_soc_tplg_link_config *src, | |
1955 | struct snd_soc_tplg_link_config **link) | |
1956 | { | |
1957 | struct snd_soc_tplg_link_config *dest; | |
1958 | struct snd_soc_tplg_link_config_v4 *src_v4; | |
1959 | int i; | |
1960 | ||
1961 | *link = NULL; | |
1962 | ||
1963 | if (src->size != sizeof(struct snd_soc_tplg_link_config_v4)) { | |
1964 | dev_err(tplg->dev, "ASoC: invalid physical link config size\n"); | |
1965 | return -EINVAL; | |
1966 | } | |
1967 | ||
1968 | dev_warn(tplg->dev, "ASoC: old version of physical link config\n"); | |
1969 | ||
1970 | src_v4 = (struct snd_soc_tplg_link_config_v4 *)src; | |
1971 | dest = kzalloc(sizeof(*dest), GFP_KERNEL); | |
1972 | if (!dest) | |
1973 | return -ENOMEM; | |
1974 | ||
1975 | dest->size = sizeof(*dest); | |
1976 | dest->id = src_v4->id; | |
1977 | dest->num_streams = src_v4->num_streams; | |
1978 | for (i = 0; i < dest->num_streams; i++) | |
1979 | memcpy(&dest->stream[i], &src_v4->stream[i], | |
1980 | sizeof(struct snd_soc_tplg_stream)); | |
1981 | ||
1982 | *link = dest; | |
1983 | return 0; | |
1984 | } | |
1985 | ||
1986 | /* Find and configure an existing physical DAI link */ | |
1987 | static int soc_tplg_link_config(struct soc_tplg *tplg, | |
1988 | struct snd_soc_tplg_link_config *cfg) | |
1989 | { | |
1990 | struct snd_soc_dai_link *link; | |
1991 | const char *name, *stream_name; | |
1992 | int ret; | |
1993 | ||
1994 | name = strlen(cfg->name) ? cfg->name : NULL; | |
1995 | stream_name = strlen(cfg->stream_name) ? cfg->stream_name : NULL; | |
1996 | ||
1997 | link = snd_soc_find_dai_link(tplg->comp->card, cfg->id, | |
1998 | name, stream_name); | |
1999 | if (!link) { | |
2000 | dev_err(tplg->dev, "ASoC: physical link %s (id %d) not exist\n", | |
2001 | name, cfg->id); | |
2002 | return -EINVAL; | |
2003 | } | |
2004 | ||
2005 | /* hw format */ | |
2006 | if (cfg->num_hw_configs) | |
2007 | set_link_hw_format(link, cfg); | |
2008 | ||
2009 | /* flags */ | |
2010 | if (cfg->flag_mask) | |
2011 | set_link_flags(link, cfg->flag_mask, cfg->flags); | |
2012 | ||
2013 | /* pass control to component driver for optional further init */ | |
2014 | ret = soc_tplg_dai_link_load(tplg, link); | |
2015 | if (ret < 0) { | |
2016 | dev_err(tplg->dev, "ASoC: physical link loading failed\n"); | |
2017 | return ret; | |
2018 | } | |
2019 | ||
2020 | return 0; | |
2021 | } | |
2022 | ||
2023 | ||
2024 | /* Load physical link config elements from the topology context */ | |
2025 | static int soc_tplg_link_elems_load(struct soc_tplg *tplg, | |
2026 | struct snd_soc_tplg_hdr *hdr) | |
2027 | { | |
2028 | struct snd_soc_tplg_link_config *link, *_link; | |
2029 | int count = hdr->count; | |
2030 | int i, ret; | |
2031 | bool abi_match; | |
2032 | ||
2033 | if (tplg->pass != SOC_TPLG_PASS_LINK) { | |
2034 | tplg->pos += hdr->size + hdr->payload_size; | |
2035 | return 0; | |
2036 | }; | |
2037 | ||
2038 | /* check the element size and count */ | |
2039 | link = (struct snd_soc_tplg_link_config *)tplg->pos; | |
2040 | if (link->size > sizeof(struct snd_soc_tplg_link_config) | |
2041 | || link->size < sizeof(struct snd_soc_tplg_link_config_v4)) { | |
2042 | dev_err(tplg->dev, "ASoC: invalid size %d for physical link elems\n", | |
2043 | link->size); | |
2044 | return -EINVAL; | |
2045 | } | |
2046 | ||
2047 | if (soc_tplg_check_elem_count(tplg, | |
2048 | link->size, count, | |
2049 | hdr->payload_size, "physical link config")) { | |
2050 | dev_err(tplg->dev, "ASoC: invalid count %d for physical link elems\n", | |
2051 | count); | |
2052 | return -EINVAL; | |
2053 | } | |
2054 | ||
2055 | /* config physical DAI links */ | |
2056 | for (i = 0; i < count; i++) { | |
2057 | link = (struct snd_soc_tplg_link_config *)tplg->pos; | |
2058 | if (link->size == sizeof(*link)) { | |
2059 | abi_match = true; | |
2060 | _link = link; | |
2061 | } else { | |
2062 | abi_match = false; | |
2063 | ret = link_new_ver(tplg, link, &_link); | |
2064 | if (ret < 0) | |
2065 | return ret; | |
2066 | } | |
2067 | ||
2068 | ret = soc_tplg_link_config(tplg, _link); | |
2069 | if (ret < 0) | |
2070 | return ret; | |
2071 | ||
2072 | /* offset by version-specific struct size and | |
2073 | * real priv data size | |
2074 | */ | |
2075 | tplg->pos += link->size + _link->priv.size; | |
2076 | ||
2077 | if (!abi_match) | |
2078 | kfree(_link); /* free the duplicated one */ | |
2079 | } | |
2080 | ||
2081 | return 0; | |
2082 | } | |
2083 | ||
0038be9a ML |
2084 | /* * |
2085 | * soc_tplg_be_dai_config - Find and configure an existing BE DAI. | |
2086 | * @tplg: topology context | |
2087 | * @be: topology BE DAI configs. | |
2088 | * | |
2089 | * The BE dai should already be registered by the platform driver. The | |
2090 | * platform driver should specify the BE DAI name and ID for matching. | |
2091 | */ | |
2092 | static int soc_tplg_be_dai_config(struct soc_tplg *tplg, | |
2093 | struct snd_soc_tplg_be_dai *be) | |
2094 | { | |
2095 | struct snd_soc_dai_link_component dai_component = {0}; | |
2096 | struct snd_soc_dai *dai; | |
2097 | struct snd_soc_dai_driver *dai_drv; | |
2098 | struct snd_soc_pcm_stream *stream; | |
2099 | struct snd_soc_tplg_stream_caps *caps; | |
2100 | int ret; | |
2101 | ||
2102 | dai_component.dai_name = be->dai_name; | |
2103 | dai = snd_soc_find_dai(&dai_component); | |
2104 | if (!dai) { | |
2105 | dev_err(tplg->dev, "ASoC: BE DAI %s not registered\n", | |
2106 | be->dai_name); | |
2107 | return -EINVAL; | |
2108 | } | |
2109 | ||
2110 | if (be->dai_id != dai->id) { | |
2111 | dev_err(tplg->dev, "ASoC: BE DAI %s id mismatch\n", | |
2112 | be->dai_name); | |
2113 | return -EINVAL; | |
2114 | } | |
2115 | ||
2116 | dai_drv = dai->driver; | |
2117 | if (!dai_drv) | |
2118 | return -EINVAL; | |
2119 | ||
2120 | if (be->playback) { | |
2121 | stream = &dai_drv->playback; | |
2122 | caps = &be->caps[SND_SOC_TPLG_STREAM_PLAYBACK]; | |
2123 | set_stream_info(stream, caps); | |
2124 | } | |
2125 | ||
2126 | if (be->capture) { | |
2127 | stream = &dai_drv->capture; | |
2128 | caps = &be->caps[SND_SOC_TPLG_STREAM_CAPTURE]; | |
2129 | set_stream_info(stream, caps); | |
2130 | } | |
2131 | ||
2132 | if (be->flag_mask) | |
2133 | set_dai_flags(dai_drv, be->flag_mask, be->flags); | |
2134 | ||
2135 | /* pass control to component driver for optional further init */ | |
2136 | ret = soc_tplg_dai_load(tplg, dai_drv); | |
2137 | if (ret < 0) { | |
2138 | dev_err(tplg->comp->dev, "ASoC: DAI loading failed\n"); | |
2139 | return ret; | |
2140 | } | |
2141 | ||
2142 | return 0; | |
2143 | } | |
2144 | ||
2145 | static int soc_tplg_be_dai_elems_load(struct soc_tplg *tplg, | |
2146 | struct snd_soc_tplg_hdr *hdr) | |
2147 | { | |
2148 | struct snd_soc_tplg_be_dai *be; | |
2149 | int count = hdr->count; | |
2150 | int i; | |
2151 | ||
2152 | if (tplg->pass != SOC_TPLG_PASS_BE_DAI) | |
2153 | return 0; | |
2154 | ||
2155 | /* config the existing BE DAIs */ | |
2156 | for (i = 0; i < count; i++) { | |
2157 | be = (struct snd_soc_tplg_be_dai *)tplg->pos; | |
2158 | if (be->size != sizeof(*be)) { | |
2159 | dev_err(tplg->dev, "ASoC: invalid BE DAI size\n"); | |
2160 | return -EINVAL; | |
2161 | } | |
2162 | ||
2163 | soc_tplg_be_dai_config(tplg, be); | |
2164 | tplg->pos += (sizeof(*be) + be->priv.size); | |
2165 | } | |
2166 | ||
2167 | dev_dbg(tplg->dev, "ASoC: Configure %d BE DAIs\n", count); | |
2168 | return 0; | |
2169 | } | |
2170 | ||
583958fa ML |
2171 | /** |
2172 | * manifest_new_ver - Create a new version of manifest from the old version | |
2173 | * of source. | |
2174 | * @toplogy: topology context | |
2175 | * @src: old version of manifest as a source | |
2176 | * @manifest: latest version of manifest created from the source | |
2177 | * | |
2178 | * Support from vesion 4. Users need free the returned manifest manually. | |
2179 | */ | |
2180 | static int manifest_new_ver(struct soc_tplg *tplg, | |
2181 | struct snd_soc_tplg_manifest *src, | |
2182 | struct snd_soc_tplg_manifest **manifest) | |
2183 | { | |
2184 | struct snd_soc_tplg_manifest *dest; | |
2185 | struct snd_soc_tplg_manifest_v4 *src_v4; | |
2186 | ||
2187 | *manifest = NULL; | |
2188 | ||
2189 | if (src->size != sizeof(*src_v4)) { | |
2190 | dev_err(tplg->dev, "ASoC: invalid manifest size\n"); | |
2191 | return -EINVAL; | |
2192 | } | |
2193 | ||
2194 | dev_warn(tplg->dev, "ASoC: old version of manifest\n"); | |
2195 | ||
2196 | src_v4 = (struct snd_soc_tplg_manifest_v4 *)src; | |
2197 | dest = kzalloc(sizeof(*dest) + src_v4->priv.size, GFP_KERNEL); | |
2198 | if (!dest) | |
2199 | return -ENOMEM; | |
2200 | ||
2201 | dest->size = sizeof(*dest); /* size of latest abi version */ | |
2202 | dest->control_elems = src_v4->control_elems; | |
2203 | dest->widget_elems = src_v4->widget_elems; | |
2204 | dest->graph_elems = src_v4->graph_elems; | |
2205 | dest->pcm_elems = src_v4->pcm_elems; | |
2206 | dest->dai_link_elems = src_v4->dai_link_elems; | |
2207 | dest->priv.size = src_v4->priv.size; | |
2208 | if (dest->priv.size) | |
2209 | memcpy(dest->priv.data, src_v4->priv.data, | |
2210 | src_v4->priv.size); | |
2211 | ||
2212 | *manifest = dest; | |
2213 | return 0; | |
2214 | } | |
0038be9a | 2215 | |
8a978234 | 2216 | static int soc_tplg_manifest_load(struct soc_tplg *tplg, |
0038be9a | 2217 | struct snd_soc_tplg_hdr *hdr) |
8a978234 | 2218 | { |
583958fa ML |
2219 | struct snd_soc_tplg_manifest *manifest, *_manifest; |
2220 | bool abi_match; | |
2221 | int err; | |
8a978234 LG |
2222 | |
2223 | if (tplg->pass != SOC_TPLG_PASS_MANIFEST) | |
2224 | return 0; | |
2225 | ||
2226 | manifest = (struct snd_soc_tplg_manifest *)tplg->pos; | |
06eb49f7 | 2227 | |
583958fa ML |
2228 | /* check ABI version by size, create a new manifest if abi not match */ |
2229 | if (manifest->size == sizeof(*manifest)) { | |
2230 | abi_match = true; | |
2231 | _manifest = manifest; | |
2232 | } else { | |
2233 | abi_match = false; | |
2234 | err = manifest_new_ver(tplg, manifest, &_manifest); | |
2235 | if (err < 0) | |
2236 | return err; | |
2237 | } | |
8a978234 | 2238 | |
583958fa | 2239 | /* pass control to component driver for optional further init */ |
8a978234 | 2240 | if (tplg->comp && tplg->ops && tplg->ops->manifest) |
583958fa ML |
2241 | return tplg->ops->manifest(tplg->comp, _manifest); |
2242 | ||
2243 | if (!abi_match) /* free the duplicated one */ | |
2244 | kfree(_manifest); | |
8a978234 | 2245 | |
8a978234 LG |
2246 | return 0; |
2247 | } | |
2248 | ||
2249 | /* validate header magic, size and type */ | |
2250 | static int soc_valid_header(struct soc_tplg *tplg, | |
2251 | struct snd_soc_tplg_hdr *hdr) | |
2252 | { | |
2253 | if (soc_tplg_get_hdr_offset(tplg) >= tplg->fw->size) | |
2254 | return 0; | |
2255 | ||
06eb49f7 ML |
2256 | if (hdr->size != sizeof(*hdr)) { |
2257 | dev_err(tplg->dev, | |
2258 | "ASoC: invalid header size for type %d at offset 0x%lx size 0x%zx.\n", | |
2259 | hdr->type, soc_tplg_get_hdr_offset(tplg), | |
2260 | tplg->fw->size); | |
2261 | return -EINVAL; | |
2262 | } | |
2263 | ||
8a978234 LG |
2264 | /* big endian firmware objects not supported atm */ |
2265 | if (hdr->magic == cpu_to_be32(SND_SOC_TPLG_MAGIC)) { | |
2266 | dev_err(tplg->dev, | |
2267 | "ASoC: pass %d big endian not supported header got %x at offset 0x%lx size 0x%zx.\n", | |
2268 | tplg->pass, hdr->magic, | |
2269 | soc_tplg_get_hdr_offset(tplg), tplg->fw->size); | |
2270 | return -EINVAL; | |
2271 | } | |
2272 | ||
2273 | if (hdr->magic != SND_SOC_TPLG_MAGIC) { | |
2274 | dev_err(tplg->dev, | |
2275 | "ASoC: pass %d does not have a valid header got %x at offset 0x%lx size 0x%zx.\n", | |
2276 | tplg->pass, hdr->magic, | |
2277 | soc_tplg_get_hdr_offset(tplg), tplg->fw->size); | |
2278 | return -EINVAL; | |
2279 | } | |
2280 | ||
288b8da7 ML |
2281 | /* Support ABI from version 4 */ |
2282 | if (hdr->abi > SND_SOC_TPLG_ABI_VERSION | |
2283 | || hdr->abi < SND_SOC_TPLG_ABI_VERSION_MIN) { | |
8a978234 LG |
2284 | dev_err(tplg->dev, |
2285 | "ASoC: pass %d invalid ABI version got 0x%x need 0x%x at offset 0x%lx size 0x%zx.\n", | |
2286 | tplg->pass, hdr->abi, | |
2287 | SND_SOC_TPLG_ABI_VERSION, soc_tplg_get_hdr_offset(tplg), | |
2288 | tplg->fw->size); | |
2289 | return -EINVAL; | |
2290 | } | |
2291 | ||
2292 | if (hdr->payload_size == 0) { | |
2293 | dev_err(tplg->dev, "ASoC: header has 0 size at offset 0x%lx.\n", | |
2294 | soc_tplg_get_hdr_offset(tplg)); | |
2295 | return -EINVAL; | |
2296 | } | |
2297 | ||
2298 | if (tplg->pass == hdr->type) | |
2299 | dev_dbg(tplg->dev, | |
2300 | "ASoC: Got 0x%x bytes of type %d version %d vendor %d at pass %d\n", | |
2301 | hdr->payload_size, hdr->type, hdr->version, | |
2302 | hdr->vendor_type, tplg->pass); | |
2303 | ||
2304 | return 1; | |
2305 | } | |
2306 | ||
2307 | /* check header type and call appropriate handler */ | |
2308 | static int soc_tplg_load_header(struct soc_tplg *tplg, | |
2309 | struct snd_soc_tplg_hdr *hdr) | |
2310 | { | |
2311 | tplg->pos = tplg->hdr_pos + sizeof(struct snd_soc_tplg_hdr); | |
2312 | ||
2313 | /* check for matching ID */ | |
2314 | if (hdr->index != tplg->req_index && | |
2315 | hdr->index != SND_SOC_TPLG_INDEX_ALL) | |
2316 | return 0; | |
2317 | ||
2318 | tplg->index = hdr->index; | |
2319 | ||
2320 | switch (hdr->type) { | |
2321 | case SND_SOC_TPLG_TYPE_MIXER: | |
2322 | case SND_SOC_TPLG_TYPE_ENUM: | |
2323 | case SND_SOC_TPLG_TYPE_BYTES: | |
2324 | return soc_tplg_kcontrol_elems_load(tplg, hdr); | |
2325 | case SND_SOC_TPLG_TYPE_DAPM_GRAPH: | |
2326 | return soc_tplg_dapm_graph_elems_load(tplg, hdr); | |
2327 | case SND_SOC_TPLG_TYPE_DAPM_WIDGET: | |
2328 | return soc_tplg_dapm_widget_elems_load(tplg, hdr); | |
2329 | case SND_SOC_TPLG_TYPE_PCM: | |
64527e8a | 2330 | return soc_tplg_pcm_elems_load(tplg, hdr); |
0038be9a ML |
2331 | case SND_SOC_TPLG_TYPE_BE_DAI: |
2332 | return soc_tplg_be_dai_elems_load(tplg, hdr); | |
593d9e52 ML |
2333 | case SND_SOC_TPLG_TYPE_DAI_LINK: |
2334 | case SND_SOC_TPLG_TYPE_BACKEND_LINK: | |
2335 | /* physical link configurations */ | |
2336 | return soc_tplg_link_elems_load(tplg, hdr); | |
8a978234 LG |
2337 | case SND_SOC_TPLG_TYPE_MANIFEST: |
2338 | return soc_tplg_manifest_load(tplg, hdr); | |
2339 | default: | |
2340 | /* bespoke vendor data object */ | |
2341 | return soc_tplg_vendor_load(tplg, hdr); | |
2342 | } | |
2343 | ||
2344 | return 0; | |
2345 | } | |
2346 | ||
2347 | /* process the topology file headers */ | |
2348 | static int soc_tplg_process_headers(struct soc_tplg *tplg) | |
2349 | { | |
2350 | struct snd_soc_tplg_hdr *hdr; | |
2351 | int ret; | |
2352 | ||
2353 | tplg->pass = SOC_TPLG_PASS_START; | |
2354 | ||
2355 | /* process the header types from start to end */ | |
2356 | while (tplg->pass <= SOC_TPLG_PASS_END) { | |
2357 | ||
2358 | tplg->hdr_pos = tplg->fw->data; | |
2359 | hdr = (struct snd_soc_tplg_hdr *)tplg->hdr_pos; | |
2360 | ||
2361 | while (!soc_tplg_is_eof(tplg)) { | |
2362 | ||
2363 | /* make sure header is valid before loading */ | |
2364 | ret = soc_valid_header(tplg, hdr); | |
2365 | if (ret < 0) | |
2366 | return ret; | |
2367 | else if (ret == 0) | |
2368 | break; | |
2369 | ||
2370 | /* load the header object */ | |
2371 | ret = soc_tplg_load_header(tplg, hdr); | |
2372 | if (ret < 0) | |
2373 | return ret; | |
2374 | ||
2375 | /* goto next header */ | |
2376 | tplg->hdr_pos += hdr->payload_size + | |
2377 | sizeof(struct snd_soc_tplg_hdr); | |
2378 | hdr = (struct snd_soc_tplg_hdr *)tplg->hdr_pos; | |
2379 | } | |
2380 | ||
2381 | /* next data type pass */ | |
2382 | tplg->pass++; | |
2383 | } | |
2384 | ||
2385 | /* signal DAPM we are complete */ | |
2386 | ret = soc_tplg_dapm_complete(tplg); | |
2387 | if (ret < 0) | |
2388 | dev_err(tplg->dev, | |
2389 | "ASoC: failed to initialise DAPM from Firmware\n"); | |
2390 | ||
2391 | return ret; | |
2392 | } | |
2393 | ||
2394 | static int soc_tplg_load(struct soc_tplg *tplg) | |
2395 | { | |
2396 | int ret; | |
2397 | ||
2398 | ret = soc_tplg_process_headers(tplg); | |
2399 | if (ret == 0) | |
2400 | soc_tplg_complete(tplg); | |
2401 | ||
2402 | return ret; | |
2403 | } | |
2404 | ||
2405 | /* load audio component topology from "firmware" file */ | |
2406 | int snd_soc_tplg_component_load(struct snd_soc_component *comp, | |
2407 | struct snd_soc_tplg_ops *ops, const struct firmware *fw, u32 id) | |
2408 | { | |
2409 | struct soc_tplg tplg; | |
2410 | ||
2411 | /* setup parsing context */ | |
2412 | memset(&tplg, 0, sizeof(tplg)); | |
2413 | tplg.fw = fw; | |
2414 | tplg.dev = comp->dev; | |
2415 | tplg.comp = comp; | |
2416 | tplg.ops = ops; | |
2417 | tplg.req_index = id; | |
2418 | tplg.io_ops = ops->io_ops; | |
2419 | tplg.io_ops_count = ops->io_ops_count; | |
1a3232d2 ML |
2420 | tplg.bytes_ext_ops = ops->bytes_ext_ops; |
2421 | tplg.bytes_ext_ops_count = ops->bytes_ext_ops_count; | |
8a978234 LG |
2422 | |
2423 | return soc_tplg_load(&tplg); | |
2424 | } | |
2425 | EXPORT_SYMBOL_GPL(snd_soc_tplg_component_load); | |
2426 | ||
2427 | /* remove this dynamic widget */ | |
2428 | void snd_soc_tplg_widget_remove(struct snd_soc_dapm_widget *w) | |
2429 | { | |
2430 | /* make sure we are a widget */ | |
2431 | if (w->dobj.type != SND_SOC_DOBJ_WIDGET) | |
2432 | return; | |
2433 | ||
2434 | remove_widget(w->dapm->component, &w->dobj, SOC_TPLG_PASS_WIDGET); | |
2435 | } | |
2436 | EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_remove); | |
2437 | ||
2438 | /* remove all dynamic widgets from this DAPM context */ | |
2439 | void snd_soc_tplg_widget_remove_all(struct snd_soc_dapm_context *dapm, | |
2440 | u32 index) | |
2441 | { | |
2442 | struct snd_soc_dapm_widget *w, *next_w; | |
8a978234 LG |
2443 | |
2444 | list_for_each_entry_safe(w, next_w, &dapm->card->widgets, list) { | |
2445 | ||
2446 | /* make sure we are a widget with correct context */ | |
2447 | if (w->dobj.type != SND_SOC_DOBJ_WIDGET || w->dapm != dapm) | |
2448 | continue; | |
2449 | ||
2450 | /* match ID */ | |
2451 | if (w->dobj.index != index && | |
2452 | w->dobj.index != SND_SOC_TPLG_INDEX_ALL) | |
2453 | continue; | |
8a978234 LG |
2454 | /* check and free and dynamic widget kcontrols */ |
2455 | snd_soc_tplg_widget_remove(w); | |
b97e2698 | 2456 | snd_soc_dapm_free_widget(w); |
8a978234 | 2457 | } |
fd589a1b | 2458 | snd_soc_dapm_reset_cache(dapm); |
8a978234 LG |
2459 | } |
2460 | EXPORT_SYMBOL_GPL(snd_soc_tplg_widget_remove_all); | |
2461 | ||
2462 | /* remove dynamic controls from the component driver */ | |
2463 | int snd_soc_tplg_component_remove(struct snd_soc_component *comp, u32 index) | |
2464 | { | |
2465 | struct snd_soc_dobj *dobj, *next_dobj; | |
2466 | int pass = SOC_TPLG_PASS_END; | |
2467 | ||
2468 | /* process the header types from end to start */ | |
2469 | while (pass >= SOC_TPLG_PASS_START) { | |
2470 | ||
2471 | /* remove mixer controls */ | |
2472 | list_for_each_entry_safe(dobj, next_dobj, &comp->dobj_list, | |
2473 | list) { | |
2474 | ||
2475 | /* match index */ | |
2476 | if (dobj->index != index && | |
2477 | dobj->index != SND_SOC_TPLG_INDEX_ALL) | |
2478 | continue; | |
2479 | ||
2480 | switch (dobj->type) { | |
2481 | case SND_SOC_DOBJ_MIXER: | |
2482 | remove_mixer(comp, dobj, pass); | |
2483 | break; | |
2484 | case SND_SOC_DOBJ_ENUM: | |
2485 | remove_enum(comp, dobj, pass); | |
2486 | break; | |
2487 | case SND_SOC_DOBJ_BYTES: | |
2488 | remove_bytes(comp, dobj, pass); | |
2489 | break; | |
2490 | case SND_SOC_DOBJ_WIDGET: | |
2491 | remove_widget(comp, dobj, pass); | |
2492 | break; | |
2493 | case SND_SOC_DOBJ_PCM: | |
64527e8a | 2494 | remove_dai(comp, dobj, pass); |
8a978234 | 2495 | break; |
acfc7d46 ML |
2496 | case SND_SOC_DOBJ_DAI_LINK: |
2497 | remove_link(comp, dobj, pass); | |
2498 | break; | |
8a978234 LG |
2499 | default: |
2500 | dev_err(comp->dev, "ASoC: invalid component type %d for removal\n", | |
2501 | dobj->type); | |
2502 | break; | |
2503 | } | |
2504 | } | |
2505 | pass--; | |
2506 | } | |
2507 | ||
2508 | /* let caller know if FW can be freed when no objects are left */ | |
2509 | return !list_empty(&comp->dobj_list); | |
2510 | } | |
2511 | EXPORT_SYMBOL_GPL(snd_soc_tplg_component_remove); |