2 * This library is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) any later version.
7 * This library is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
21 #include <sound/type_compat.h>
22 #include <sound/asound.h>
23 #include <sound/asoc.h>
24 #include <sound/tlv.h>
27 #define tplg_dbg SNDERR
29 #define tplg_dbg(fmt, arg...) do { } while (0)
32 #define TPLG_MAX_PRIV_SIZE (1024 * 128)
34 /** The name of the environment variable containing the tplg directory */
35 #define ALSA_CONFIG_TPLG_VAR "ALSA_CONFIG_TPLG"
41 typedef enum _snd_pcm_rates {
42 SND_PCM_RATE_UNKNOWN = -1,
43 SND_PCM_RATE_5512 = 0,
56 SND_PCM_RATE_CONTINUOUS = 30,
57 SND_PCM_RATE_KNOT = 31,
58 SND_PCM_RATE_LAST = SND_PCM_RATE_KNOT,
68 unsigned int dapm_sort: 1;
77 struct snd_soc_tplg_manifest manifest;
78 void *manifest_pdata; /* copied by builder at file write */
80 /* list of each element type */
81 struct list_head tlv_list;
82 struct list_head widget_list;
83 struct list_head pcm_list;
84 struct list_head dai_list;
85 struct list_head be_list;
86 struct list_head cc_list;
87 struct list_head route_list;
88 struct list_head text_list;
89 struct list_head pdata_list;
90 struct list_head token_list;
91 struct list_head tuple_list;
92 struct list_head manifest_list;
93 struct list_head pcm_config_list;
94 struct list_head pcm_caps_list;
95 struct list_head hw_cfg_list;
97 /* type-specific control lists */
98 struct list_head mixer_list;
99 struct list_head enum_list;
100 struct list_head bytes_ext_list;
103 /* object text references */
106 struct tplg_elem *elem;
107 char id[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
108 struct list_head list;
112 unsigned int num_items;
113 char items[SND_SOC_TPLG_NUM_TEXTS][SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
116 /* element for vendor tokens */
118 char id[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
122 struct tplg_vendor_tokens {
123 unsigned int num_tokens;
124 struct tplg_token token[0];
127 /* element for vendor tuples */
129 char token[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
131 char string[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
132 unsigned char uuid[16];
137 struct tplg_tuple_set {
138 unsigned int type; /* uuid, bool, byte, short, word, string*/
139 unsigned int num_tuples;
140 struct tplg_tuple tuple[0];
143 struct tplg_vendor_tuples {
144 unsigned int num_sets;
145 unsigned int alloc_sets;
146 struct tplg_tuple_set **set;
149 /* topology element */
152 struct tplg_table *table;
154 char id[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
157 enum snd_tplg_type type;
159 int size; /* total size of this object inc pdata and ref objects */
160 int compound_elem; /* dont write this element as individual elem */
161 int vendor_type; /* vendor type for private data */
163 /* UAPI object for this elem */
166 struct snd_soc_tplg_mixer_control *mixer_ctrl;
167 struct snd_soc_tplg_enum_control *enum_ctrl;
168 struct snd_soc_tplg_bytes_control *bytes_ext;
169 struct snd_soc_tplg_dapm_widget *widget;
170 struct snd_soc_tplg_pcm *pcm;
171 struct snd_soc_tplg_dai *dai;
172 struct snd_soc_tplg_link_config *link;/* physical link */
173 struct snd_soc_tplg_dapm_graph_elem *route;
174 struct snd_soc_tplg_stream *stream_cfg;
175 struct snd_soc_tplg_stream_caps *stream_caps;
176 struct snd_soc_tplg_hw_config *hw_cfg;
178 /* these do not map to UAPI structs but are internal only */
179 struct snd_soc_tplg_ctl_tlv *tlv;
180 struct tplg_texts *texts;
181 struct snd_soc_tplg_private *data;
182 struct tplg_vendor_tokens *tokens;
183 struct tplg_vendor_tuples *tuples;
184 struct snd_soc_tplg_manifest *manifest;
187 /* an element may refer to other elements:
188 * a mixer control may refer to a tlv,
189 * a widget may refer to a mixer control array,
190 * a graph may refer to some widgets.
192 struct list_head ref_list;
193 struct list_head list; /* list of all elements with same type */
195 void (*free)(void *obj);
208 size_t printf_buf_size;
222 void (*free)(void *);
223 int (*parse)(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
224 int (*save)(snd_tplg_t *tplg, struct tplg_elem *elem,
225 struct tplg_buf *dst, const char *prefix);
226 int (*gsave)(snd_tplg_t *tplg, int index,
227 struct tplg_buf *dst, const char *prefix);
228 int (*decod)(snd_tplg_t *tplg, size_t pos,
229 struct snd_soc_tplg_hdr *hdr,
230 void *bin, size_t size);
233 extern struct tplg_table tplg_table[];
234 extern unsigned int tplg_table_items;
236 #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ && __SIZEOF_INT__ == 4
237 static inline unsigned int unaligned_get32(void *src)
240 memcpy(&ret, src, sizeof(ret));
243 static inline void unaligned_put32(void *dst, unsigned int val)
245 memcpy(dst, &val, sizeof(val));
249 #define tplg_log(tplg, type, pos, fmt, args...) do { \
250 if ((tplg)->verbose) \
251 tplg_log_((tplg), (type), (pos), (fmt), ##args); \
254 void tplg_log_(snd_tplg_t *tplg, char type, size_t pos, const char *fmt, ...);
256 void *tplg_calloc(struct list_head *heap, size_t size);
257 void tplg_free(struct list_head *heap);
259 int tplg_get_type(int asoc_type);
261 int tplg_parse_compound(snd_tplg_t *tplg, snd_config_t *cfg,
262 int (*fcn)(snd_tplg_t *, snd_config_t *, void *),
265 int tplg_write_data(snd_tplg_t *tplg);
267 int tplg_parse_tlv(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
268 int tplg_parse_text(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
269 int tplg_parse_data(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
270 int tplg_parse_tokens(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
271 int tplg_parse_tuples(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
272 int tplg_parse_manifest_data(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
273 int tplg_parse_control_bytes(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
274 int tplg_parse_control_enum(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
275 int tplg_parse_control_mixer(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
276 int tplg_parse_dapm_graph(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
277 int tplg_parse_dapm_widget(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
278 int tplg_parse_stream_caps(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
279 int tplg_parse_pcm(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
280 int tplg_parse_dai(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
281 int tplg_parse_link(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
282 int tplg_parse_cc(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
283 int tplg_parse_hw_config(snd_tplg_t *tplg, snd_config_t *cfg, void *priv);
285 unsigned int tplg_get_tuple_size(int type);
286 void tplg_free_tuples(void *obj);
288 int tplg_build_data(snd_tplg_t *tplg);
289 int tplg_build_manifest_data(snd_tplg_t *tplg);
290 int tplg_build_controls(snd_tplg_t *tplg);
291 int tplg_build_widgets(snd_tplg_t *tplg);
292 int tplg_build_routes(snd_tplg_t *tplg);
293 int tplg_build_pcm_dai(snd_tplg_t *tplg, unsigned int type);
295 int tplg_copy_data(snd_tplg_t *tplg, struct tplg_elem *elem,
296 struct tplg_ref *ref);
298 int tplg_parse_refs(snd_config_t *cfg, struct tplg_elem *elem,
301 int tplg_ref_add(struct tplg_elem *elem, int type, const char* id);
302 int tplg_ref_add_elem(struct tplg_elem *elem, struct tplg_elem *elem_ref);
304 struct tplg_elem *tplg_elem_new(void);
305 void tplg_elem_free(struct tplg_elem *elem);
306 void tplg_elem_free_list(struct list_head *base);
307 void tplg_elem_insert(struct tplg_elem *elem_p, struct list_head *list);
308 struct tplg_elem *tplg_elem_lookup(struct list_head *base,
312 struct tplg_elem *tplg_elem_type_lookup(snd_tplg_t *tplg,
313 enum snd_tplg_type type);
314 struct tplg_elem* tplg_elem_new_common(snd_tplg_t *tplg,
315 snd_config_t *cfg, const char *name, enum snd_tplg_type type);
317 int tplg_get_integer(snd_config_t *n, int *val, int base);
318 int tplg_get_unsigned(snd_config_t *n, unsigned *val, int base);
320 const char *tplg_channel_name(int type);
321 int tplg_parse_channel(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
322 snd_config_t *cfg, void *private);
324 const char *tplg_ops_name(int type);
325 int tplg_parse_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
326 snd_config_t *cfg, void *private);
327 int tplg_parse_ext_ops(snd_tplg_t *tplg ATTRIBUTE_UNUSED,
328 snd_config_t *cfg, void *private);
330 struct tplg_elem *lookup_pcm_dai_stream(struct list_head *base,
333 int tplg_add_data(snd_tplg_t *tplg, struct tplg_elem *parent,
334 const void *bin, size_t size);
335 int tplg_add_data_bytes(snd_tplg_t *tplg, struct tplg_elem *parent,
336 const char *suffix, const void *bin, size_t size);
337 int tplg_add_mixer_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t);
338 int tplg_add_enum_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t);
339 int tplg_add_bytes_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t);
340 int tplg_add_widget_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t);
341 int tplg_add_graph_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t);
343 int tplg_add_mixer(snd_tplg_t *tplg, struct snd_tplg_mixer_template *mixer,
344 struct tplg_elem **e);
345 int tplg_add_enum(snd_tplg_t *tplg, struct snd_tplg_enum_template *enum_ctl,
346 struct tplg_elem **e);
347 int tplg_add_bytes(snd_tplg_t *tplg, struct snd_tplg_bytes_template *bytes_ctl,
348 struct tplg_elem **e);
350 int tplg_build_pcms(snd_tplg_t *tplg, unsigned int type);
351 int tplg_build_dais(snd_tplg_t *tplg, unsigned int type);
352 int tplg_build_links(snd_tplg_t *tplg, unsigned int type);
353 int tplg_add_link_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t);
354 int tplg_add_pcm_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t);
355 int tplg_add_dai_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t);
357 int tplg_nice_value_format(char *dst, size_t dst_size, unsigned int value);
359 int tplg_save_printf(struct tplg_buf *dst, const char *prefix, const char *fmt, ...);
360 int tplg_save_refs(snd_tplg_t *tplg, struct tplg_elem *elem, unsigned int type,
361 const char *id, struct tplg_buf *dst, const char *pfx);
362 int tplg_save_channels(snd_tplg_t *tplg, struct snd_soc_tplg_channel *channel,
363 unsigned int channel_count, struct tplg_buf *dst, const char *pfx);
364 int tplg_save_ops(snd_tplg_t *tplg, struct snd_soc_tplg_ctl_hdr *hdr,
365 struct tplg_buf *dst, const char *pfx);
366 int tplg_save_ext_ops(snd_tplg_t *tplg, struct snd_soc_tplg_bytes_control *be,
367 struct tplg_buf *dst, const char *pfx);
368 int tplg_save_manifest_data(snd_tplg_t *tplg, struct tplg_elem *elem,
369 struct tplg_buf *dst, const char *pfx);
370 int tplg_save_control_mixer(snd_tplg_t *tplg, struct tplg_elem *elem,
371 struct tplg_buf *dst, const char *pfx);
372 int tplg_save_control_enum(snd_tplg_t *tplg, struct tplg_elem *elem,
373 struct tplg_buf *dst, const char *pfx);
374 int tplg_save_control_bytes(snd_tplg_t *tplg, struct tplg_elem *elem,
375 struct tplg_buf *dst, const char *pfx);
376 int tplg_save_tlv(snd_tplg_t *tplg, struct tplg_elem *elem,
377 struct tplg_buf *dst, const char *pfx);
378 int tplg_save_data(snd_tplg_t *tplg, struct tplg_elem *elem,
379 struct tplg_buf *dst, const char *pfx);
380 int tplg_save_text(snd_tplg_t *tplg, struct tplg_elem *elem,
381 struct tplg_buf *dst, const char *pfx);
382 int tplg_save_tokens(snd_tplg_t *tplg, struct tplg_elem *elem,
383 struct tplg_buf *dst, const char *pfx);
384 int tplg_save_tuples(snd_tplg_t *tplg, struct tplg_elem *elem,
385 struct tplg_buf *dst, const char *pfx);
386 int tplg_save_dapm_graph(snd_tplg_t *tplg, int index,
387 struct tplg_buf *dst, const char *pfx);
388 int tplg_save_dapm_widget(snd_tplg_t *tplg, struct tplg_elem *elem,
389 struct tplg_buf *dst, const char *pfx);
390 int tplg_save_link(snd_tplg_t *tplg, struct tplg_elem *elem,
391 struct tplg_buf *dst, const char *pfx);
392 int tplg_save_cc(snd_tplg_t *tplg, struct tplg_elem *elem,
393 struct tplg_buf *dst, const char *pfx);
394 int tplg_save_pcm(snd_tplg_t *tplg, struct tplg_elem *elem,
395 struct tplg_buf *dst, const char *pfx);
396 int tplg_save_hw_config(snd_tplg_t *tplg, struct tplg_elem *elem,
397 struct tplg_buf *dst, const char *pfx);
398 int tplg_save_stream_caps(snd_tplg_t *tplg, struct tplg_elem *elem,
399 struct tplg_buf *dst, const char *pfx);
400 int tplg_save_dai(snd_tplg_t *tplg, struct tplg_elem *elem,
401 struct tplg_buf *dst, const char *pfx);
403 int tplg_decode_template(snd_tplg_t *tplg,
405 struct snd_soc_tplg_hdr *hdr,
406 snd_tplg_obj_template_t *t);
407 int tplg_decode_manifest_data(snd_tplg_t *tplg, size_t pos,
408 struct snd_soc_tplg_hdr *hdr,
409 void *bin, size_t size);
410 int tplg_decode_control_mixer1(snd_tplg_t *tplg,
411 struct list_head *heap,
412 struct snd_tplg_mixer_template *mt,
414 void *bin, size_t size);
415 int tplg_decode_control_mixer(snd_tplg_t *tplg, size_t pos,
416 struct snd_soc_tplg_hdr *hdr,
417 void *bin, size_t size);
418 int tplg_decode_control_enum1(snd_tplg_t *tplg,
419 struct list_head *heap,
420 struct snd_tplg_enum_template *et,
422 struct snd_soc_tplg_enum_control *ec);
423 int tplg_decode_control_enum(snd_tplg_t *tplg, size_t pos,
424 struct snd_soc_tplg_hdr *hdr,
425 void *bin, size_t size);
426 int tplg_decode_control_bytes1(snd_tplg_t *tplg,
427 struct snd_tplg_bytes_template *bt,
429 void *bin, size_t size);
430 int tplg_decode_control_bytes(snd_tplg_t *tplg, size_t pos,
431 struct snd_soc_tplg_hdr *hdr,
432 void *bin, size_t size);
433 int tplg_decode_data(snd_tplg_t *tplg, size_t pos,
434 struct snd_soc_tplg_hdr *hdr,
435 void *bin, size_t size);
436 int tplg_decode_dapm_graph(snd_tplg_t *tplg, size_t pos,
437 struct snd_soc_tplg_hdr *hdr,
438 void *bin, size_t size);
439 int tplg_decode_dapm_widget(snd_tplg_t *tplg, size_t pos,
440 struct snd_soc_tplg_hdr *hdr,
441 void *bin, size_t size);
442 int tplg_decode_link(snd_tplg_t *tplg, size_t pos,
443 struct snd_soc_tplg_hdr *hdr,
444 void *bin, size_t size);
445 int tplg_decode_cc(snd_tplg_t *tplg, size_t pos,
446 struct snd_soc_tplg_hdr *hdr,
447 void *bin, size_t size);
448 int tplg_decode_pcm(snd_tplg_t *tplg, size_t pos,
449 struct snd_soc_tplg_hdr *hdr,
450 void *bin, size_t size);
451 int tplg_decode_dai(snd_tplg_t *tplg, size_t pos,
452 struct snd_soc_tplg_hdr *hdr,
453 void *bin, size_t size);