xref: /openbmc/linux/include/uapi/sound/asoc.h (revision dc31e741)
1 /*
2  * uapi/sound/asoc.h -- ALSA SoC Firmware Controls and DAPM
3  *
4  * Copyright (C) 2012 Texas Instruments Inc.
5  * Copyright (C) 2015 Intel Corporation.
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License version 2 as
9  * published by the Free Software Foundation.
10  *
11  * Simple file API to load FW that includes mixers, coefficients, DAPM graphs,
12  * algorithms, equalisers, DAIs, widgets etc.
13 */
14 
15 #ifndef __LINUX_UAPI_SND_ASOC_H
16 #define __LINUX_UAPI_SND_ASOC_H
17 
18 #include <linux/types.h>
19 #include <sound/asound.h>
20 
21 #ifndef __KERNEL__
22 #error This API is an early revision and not enabled in the current
23 #error kernel release, it will be enabled in a future kernel version
24 #error with incompatible changes to what is here.
25 #endif
26 
27 /*
28  * Maximum number of channels topology kcontrol can represent.
29  */
30 #define SND_SOC_TPLG_MAX_CHAN		8
31 
32 /*
33  * Maximum number of PCM formats capability
34  */
35 #define SND_SOC_TPLG_MAX_FORMATS	16
36 
37 /*
38  * Maximum number of PCM stream configs
39  */
40 #define SND_SOC_TPLG_STREAM_CONFIG_MAX  8
41 
42 /* individual kcontrol info types - can be mixed with other types */
43 #define SND_SOC_TPLG_CTL_VOLSW		1
44 #define SND_SOC_TPLG_CTL_VOLSW_SX	2
45 #define SND_SOC_TPLG_CTL_VOLSW_XR_SX	3
46 #define SND_SOC_TPLG_CTL_ENUM		4
47 #define SND_SOC_TPLG_CTL_BYTES		5
48 #define SND_SOC_TPLG_CTL_ENUM_VALUE	6
49 #define SND_SOC_TPLG_CTL_RANGE		7
50 #define SND_SOC_TPLG_CTL_STROBE		8
51 
52 
53 /* individual widget kcontrol info types - can be mixed with other types */
54 #define SND_SOC_TPLG_DAPM_CTL_VOLSW		64
55 #define SND_SOC_TPLG_DAPM_CTL_ENUM_DOUBLE	65
56 #define SND_SOC_TPLG_DAPM_CTL_ENUM_VIRT		66
57 #define SND_SOC_TPLG_DAPM_CTL_ENUM_VALUE	67
58 #define SND_SOC_TPLG_DAPM_CTL_PIN		68
59 
60 /* DAPM widget types - add new items to the end */
61 #define SND_SOC_TPLG_DAPM_INPUT		0
62 #define SND_SOC_TPLG_DAPM_OUTPUT	1
63 #define SND_SOC_TPLG_DAPM_MUX		2
64 #define SND_SOC_TPLG_DAPM_MIXER		3
65 #define SND_SOC_TPLG_DAPM_PGA		4
66 #define SND_SOC_TPLG_DAPM_OUT_DRV	5
67 #define SND_SOC_TPLG_DAPM_ADC		6
68 #define SND_SOC_TPLG_DAPM_DAC		7
69 #define SND_SOC_TPLG_DAPM_SWITCH	8
70 #define SND_SOC_TPLG_DAPM_PRE		9
71 #define SND_SOC_TPLG_DAPM_POST		10
72 #define SND_SOC_TPLG_DAPM_AIF_IN	11
73 #define SND_SOC_TPLG_DAPM_AIF_OUT	12
74 #define SND_SOC_TPLG_DAPM_DAI_IN	13
75 #define SND_SOC_TPLG_DAPM_DAI_OUT	14
76 #define SND_SOC_TPLG_DAPM_DAI_LINK	15
77 #define SND_SOC_TPLG_DAPM_LAST		SND_SOC_TPLG_DAPM_DAI_LINK
78 
79 /* Header magic number and string sizes */
80 #define SND_SOC_TPLG_MAGIC		0x41536F43 /* ASoC */
81 
82 /* string sizes */
83 #define SND_SOC_TPLG_NUM_TEXTS		16
84 
85 /* ABI version */
86 #define SND_SOC_TPLG_ABI_VERSION	0x5
87 
88 /* Max size of TLV data */
89 #define SND_SOC_TPLG_TLV_SIZE		32
90 
91 /*
92  * File and Block header data types.
93  * Add new generic and vendor types to end of list.
94  * Generic types are handled by the core whilst vendors types are passed
95  * to the component drivers for handling.
96  */
97 #define SND_SOC_TPLG_TYPE_MIXER		1
98 #define SND_SOC_TPLG_TYPE_BYTES		2
99 #define SND_SOC_TPLG_TYPE_ENUM		3
100 #define SND_SOC_TPLG_TYPE_DAPM_GRAPH	4
101 #define SND_SOC_TPLG_TYPE_DAPM_WIDGET	5
102 #define SND_SOC_TPLG_TYPE_DAI_LINK	6
103 #define SND_SOC_TPLG_TYPE_PCM		7
104 #define SND_SOC_TPLG_TYPE_MANIFEST	8
105 #define SND_SOC_TPLG_TYPE_CODEC_LINK	9
106 #define SND_SOC_TPLG_TYPE_BACKEND_LINK	10
107 #define SND_SOC_TPLG_TYPE_PDATA		11
108 #define SND_SOC_TPLG_TYPE_BE_DAI	12
109 #define SND_SOC_TPLG_TYPE_MAX		SND_SOC_TPLG_TYPE_BE_DAI
110 
111 /* vendor block IDs - please add new vendor types to end */
112 #define SND_SOC_TPLG_TYPE_VENDOR_FW	1000
113 #define SND_SOC_TPLG_TYPE_VENDOR_CONFIG	1001
114 #define SND_SOC_TPLG_TYPE_VENDOR_COEFF	1002
115 #define SND_SOC_TPLG_TYPEVENDOR_CODEC	1003
116 
117 #define SND_SOC_TPLG_STREAM_PLAYBACK	0
118 #define SND_SOC_TPLG_STREAM_CAPTURE	1
119 
120 /* vendor tuple types */
121 #define SND_SOC_TPLG_TUPLE_TYPE_UUID	0
122 #define SND_SOC_TPLG_TUPLE_TYPE_STRING	1
123 #define SND_SOC_TPLG_TUPLE_TYPE_BOOL	2
124 #define SND_SOC_TPLG_TUPLE_TYPE_BYTE	3
125 #define SND_SOC_TPLG_TUPLE_TYPE_WORD	4
126 #define SND_SOC_TPLG_TUPLE_TYPE_SHORT	5
127 
128 /* BE DAI flags */
129 #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_RATES         (1 << 0)
130 #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_CHANNELS      (1 << 1)
131 #define SND_SOC_TPLG_DAI_FLGBIT_SYMMETRIC_SAMPLEBITS    (1 << 2)
132 
133 /*
134  * Block Header.
135  * This header precedes all object and object arrays below.
136  */
137 struct snd_soc_tplg_hdr {
138 	__le32 magic;		/* magic number */
139 	__le32 abi;		/* ABI version */
140 	__le32 version;		/* optional vendor specific version details */
141 	__le32 type;		/* SND_SOC_TPLG_TYPE_ */
142 	__le32 size;		/* size of this structure */
143 	__le32 vendor_type;	/* optional vendor specific type info */
144 	__le32 payload_size;	/* data bytes, excluding this header */
145 	__le32 index;		/* identifier for block */
146 	__le32 count;		/* number of elements in block */
147 } __attribute__((packed));
148 
149 /* vendor tuple for uuid */
150 struct snd_soc_tplg_vendor_uuid_elem {
151 	__le32 token;
152 	char uuid[16];
153 } __attribute__((packed));
154 
155 /* vendor tuple for a bool/byte/short/word value */
156 struct snd_soc_tplg_vendor_value_elem {
157 	__le32 token;
158 	__le32 value;
159 } __attribute__((packed));
160 
161 /* vendor tuple for string */
162 struct snd_soc_tplg_vendor_string_elem {
163 	__le32 token;
164 	char string[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
165 } __attribute__((packed));
166 
167 struct snd_soc_tplg_vendor_array {
168 	__le32 size;	/* size in bytes of the array, including all elements */
169 	__le32 type;	/* SND_SOC_TPLG_TUPLE_TYPE_ */
170 	__le32 num_elems;	/* number of elements in array */
171 	union {
172 		struct snd_soc_tplg_vendor_uuid_elem uuid[0];
173 		struct snd_soc_tplg_vendor_value_elem value[0];
174 		struct snd_soc_tplg_vendor_string_elem string[0];
175 	};
176 } __attribute__((packed));
177 
178 /*
179  * Private data.
180  * All topology objects may have private data that can be used by the driver or
181  * firmware. Core will ignore this data.
182  */
183 struct snd_soc_tplg_private {
184 	__le32 size;	/* in bytes of private data */
185 	union {
186 		char data[0];
187 		struct snd_soc_tplg_vendor_array array[0];
188 	};
189 } __attribute__((packed));
190 
191 /*
192  * Kcontrol TLV data.
193  */
194 struct snd_soc_tplg_tlv_dbscale {
195 	__le32 min;
196 	__le32 step;
197 	__le32 mute;
198 } __attribute__((packed));
199 
200 struct snd_soc_tplg_ctl_tlv {
201 	__le32 size;	/* in bytes of this structure */
202 	__le32 type;	/* SNDRV_CTL_TLVT_*, type of TLV */
203 	union {
204 		__le32 data[SND_SOC_TPLG_TLV_SIZE];
205 		struct snd_soc_tplg_tlv_dbscale scale;
206 	};
207 } __attribute__((packed));
208 
209 /*
210  * Kcontrol channel data
211  */
212 struct snd_soc_tplg_channel {
213 	__le32 size;	/* in bytes of this structure */
214 	__le32 reg;
215 	__le32 shift;
216 	__le32 id;	/* ID maps to Left, Right, LFE etc */
217 } __attribute__((packed));
218 
219 /*
220  * Genericl Operations IDs, for binding Kcontrol or Bytes ext ops
221  * Kcontrol ops need get/put/info.
222  * Bytes ext ops need get/put.
223  */
224 struct snd_soc_tplg_io_ops {
225 	__le32 get;
226 	__le32 put;
227 	__le32 info;
228 } __attribute__((packed));
229 
230 /*
231  * kcontrol header
232  */
233 struct snd_soc_tplg_ctl_hdr {
234 	__le32 size;	/* in bytes of this structure */
235 	__le32 type;
236 	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
237 	__le32 access;
238 	struct snd_soc_tplg_io_ops ops;
239 	struct snd_soc_tplg_ctl_tlv tlv;
240 } __attribute__((packed));
241 
242 /*
243  * Stream Capabilities
244  */
245 struct snd_soc_tplg_stream_caps {
246 	__le32 size;		/* in bytes of this structure */
247 	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
248 	__le64 formats;	/* supported formats SNDRV_PCM_FMTBIT_* */
249 	__le32 rates;		/* supported rates SNDRV_PCM_RATE_* */
250 	__le32 rate_min;	/* min rate */
251 	__le32 rate_max;	/* max rate */
252 	__le32 channels_min;	/* min channels */
253 	__le32 channels_max;	/* max channels */
254 	__le32 periods_min;	/* min number of periods */
255 	__le32 periods_max;	/* max number of periods */
256 	__le32 period_size_min;	/* min period size bytes */
257 	__le32 period_size_max;	/* max period size bytes */
258 	__le32 buffer_size_min;	/* min buffer size bytes */
259 	__le32 buffer_size_max;	/* max buffer size bytes */
260 } __attribute__((packed));
261 
262 /*
263  * FE or BE Stream configuration supported by SW/FW
264  */
265 struct snd_soc_tplg_stream {
266 	__le32 size;		/* in bytes of this structure */
267 	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* Name of the stream */
268 	__le64 format;		/* SNDRV_PCM_FMTBIT_* */
269 	__le32 rate;		/* SNDRV_PCM_RATE_* */
270 	__le32 period_bytes;	/* size of period in bytes */
271 	__le32 buffer_bytes;	/* size of buffer in bytes */
272 	__le32 channels;	/* channels */
273 } __attribute__((packed));
274 
275 /*
276  * Manifest. List totals for each payload type. Not used in parsing, but will
277  * be passed to the component driver before any other objects in order for any
278  * global component resource allocations.
279  *
280  * File block representation for manifest :-
281  * +-----------------------------------+----+
282  * | struct snd_soc_tplg_hdr           |  1 |
283  * +-----------------------------------+----+
284  * | struct snd_soc_tplg_manifest      |  1 |
285  * +-----------------------------------+----+
286  */
287 struct snd_soc_tplg_manifest {
288 	__le32 size;		/* in bytes of this structure */
289 	__le32 control_elems;	/* number of control elements */
290 	__le32 widget_elems;	/* number of widget elements */
291 	__le32 graph_elems;	/* number of graph elements */
292 	__le32 pcm_elems;	/* number of PCM elements */
293 	__le32 dai_link_elems;	/* number of DAI link elements */
294 	__le32 be_dai_elems;	/* number of BE DAI elements */
295 	__le32 reserved[20];	/* reserved for new ABI element types */
296 	struct snd_soc_tplg_private priv;
297 } __attribute__((packed));
298 
299 /*
300  * Mixer kcontrol.
301  *
302  * File block representation for mixer kcontrol :-
303  * +-----------------------------------+----+
304  * | struct snd_soc_tplg_hdr           |  1 |
305  * +-----------------------------------+----+
306  * | struct snd_soc_tplg_mixer_control |  N |
307  * +-----------------------------------+----+
308  */
309 struct snd_soc_tplg_mixer_control {
310 	struct snd_soc_tplg_ctl_hdr hdr;
311 	__le32 size;	/* in bytes of this structure */
312 	__le32 min;
313 	__le32 max;
314 	__le32 platform_max;
315 	__le32 invert;
316 	__le32 num_channels;
317 	struct snd_soc_tplg_channel channel[SND_SOC_TPLG_MAX_CHAN];
318 	struct snd_soc_tplg_private priv;
319 } __attribute__((packed));
320 
321 /*
322  * Enumerated kcontrol
323  *
324  * File block representation for enum kcontrol :-
325  * +-----------------------------------+----+
326  * | struct snd_soc_tplg_hdr           |  1 |
327  * +-----------------------------------+----+
328  * | struct snd_soc_tplg_enum_control  |  N |
329  * +-----------------------------------+----+
330  */
331 struct snd_soc_tplg_enum_control {
332 	struct snd_soc_tplg_ctl_hdr hdr;
333 	__le32 size;	/* in bytes of this structure */
334 	__le32 num_channels;
335 	struct snd_soc_tplg_channel channel[SND_SOC_TPLG_MAX_CHAN];
336 	__le32 items;
337 	__le32 mask;
338 	__le32 count;
339 	char texts[SND_SOC_TPLG_NUM_TEXTS][SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
340 	__le32 values[SND_SOC_TPLG_NUM_TEXTS * SNDRV_CTL_ELEM_ID_NAME_MAXLEN / 4];
341 	struct snd_soc_tplg_private priv;
342 } __attribute__((packed));
343 
344 /*
345  * Bytes kcontrol
346  *
347  * File block representation for bytes kcontrol :-
348  * +-----------------------------------+----+
349  * | struct snd_soc_tplg_hdr           |  1 |
350  * +-----------------------------------+----+
351  * | struct snd_soc_tplg_bytes_control |  N |
352  * +-----------------------------------+----+
353  */
354 struct snd_soc_tplg_bytes_control {
355 	struct snd_soc_tplg_ctl_hdr hdr;
356 	__le32 size;	/* in bytes of this structure */
357 	__le32 max;
358 	__le32 mask;
359 	__le32 base;
360 	__le32 num_regs;
361 	struct snd_soc_tplg_io_ops ext_ops;
362 	struct snd_soc_tplg_private priv;
363 } __attribute__((packed));
364 
365 /*
366  * DAPM Graph Element
367  *
368  * File block representation for DAPM graph elements :-
369  * +-------------------------------------+----+
370  * | struct snd_soc_tplg_hdr             |  1 |
371  * +-------------------------------------+----+
372  * | struct snd_soc_tplg_dapm_graph_elem |  N |
373  * +-------------------------------------+----+
374  */
375 struct snd_soc_tplg_dapm_graph_elem {
376 	char sink[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
377 	char control[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
378 	char source[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
379 } __attribute__((packed));
380 
381 /*
382  * DAPM Widget.
383  *
384  * File block representation for DAPM widget :-
385  * +-------------------------------------+-----+
386  * | struct snd_soc_tplg_hdr             |  1  |
387  * +-------------------------------------+-----+
388  * | struct snd_soc_tplg_dapm_widget     |  N  |
389  * +-------------------------------------+-----+
390  * |   struct snd_soc_tplg_enum_control  | 0|1 |
391  * |   struct snd_soc_tplg_mixer_control | 0|N |
392  * +-------------------------------------+-----+
393  *
394  * Optional enum or mixer control can be appended to the end of each widget
395  * in the block.
396  */
397 struct snd_soc_tplg_dapm_widget {
398 	__le32 size;		/* in bytes of this structure */
399 	__le32 id;		/* SND_SOC_DAPM_CTL */
400 	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
401 	char sname[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
402 
403 	__le32 reg;		/* negative reg = no direct dapm */
404 	__le32 shift;		/* bits to shift */
405 	__le32 mask;		/* non-shifted mask */
406 	__le32 subseq;		/* sort within widget type */
407 	__le32 invert;		/* invert the power bit */
408 	__le32 ignore_suspend;	/* kept enabled over suspend */
409 	__le16 event_flags;
410 	__le16 event_type;
411 	__le32 num_kcontrols;
412 	struct snd_soc_tplg_private priv;
413 	/*
414 	 * kcontrols that relate to this widget
415 	 * follow here after widget private data
416 	 */
417 } __attribute__((packed));
418 
419 
420 /*
421  * Describes SW/FW specific features of PCM (FE DAI & DAI link).
422  *
423  * File block representation for PCM :-
424  * +-----------------------------------+-----+
425  * | struct snd_soc_tplg_hdr           |  1  |
426  * +-----------------------------------+-----+
427  * | struct snd_soc_tplg_pcm           |  N  |
428  * +-----------------------------------+-----+
429  */
430 struct snd_soc_tplg_pcm {
431 	__le32 size;		/* in bytes of this structure */
432 	char pcm_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
433 	char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
434 	__le32 pcm_id;		/* unique ID - used to match with DAI link */
435 	__le32 dai_id;		/* unique ID - used to match */
436 	__le32 playback;	/* supports playback mode */
437 	__le32 capture;		/* supports capture mode */
438 	__le32 compress;	/* 1 = compressed; 0 = PCM */
439 	struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* for DAI link */
440 	__le32 num_streams;	/* number of streams */
441 	struct snd_soc_tplg_stream_caps caps[2]; /* playback and capture for DAI */
442 } __attribute__((packed));
443 
444 
445 /*
446  * Describes the BE or CC link runtime supported configs or params
447  *
448  * File block representation for BE/CC link config :-
449  * +-----------------------------------+-----+
450  * | struct snd_soc_tplg_hdr           |  1  |
451  * +-----------------------------------+-----+
452  * | struct snd_soc_tplg_link_config   |  N  |
453  * +-----------------------------------+-----+
454  */
455 struct snd_soc_tplg_link_config {
456 	__le32 size;            /* in bytes of this structure */
457 	__le32 id;              /* unique ID - used to match */
458 	struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */
459 	__le32 num_streams;     /* number of streams */
460 } __attribute__((packed));
461 
462 /*
463  * Describes SW/FW specific features of BE DAI.
464  *
465  * File block representation for BE DAI :-
466  * +-----------------------------------+-----+
467  * | struct snd_soc_tplg_hdr           |  1  |
468  * +-----------------------------------+-----+
469  * | struct snd_soc_tplg_be_dai        |  N  |
470  * +-----------------------------------+-----+
471  */
472 struct snd_soc_tplg_be_dai {
473 	__le32 size;            /* in bytes of this structure */
474 	char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* name - used to match */
475 	__le32 dai_id;          /* unique ID - used to match */
476 	__le32 playback;        /* supports playback mode */
477 	__le32 capture;         /* supports capture mode */
478 	struct snd_soc_tplg_stream_caps caps[2]; /* playback and capture for DAI */
479 	__le32 flag_mask;       /* bitmask of flags to configure */
480 	__le32 flags;           /* SND_SOC_TPLG_DAI_FLGBIT_* */
481 	struct snd_soc_tplg_private priv;
482 } __attribute__((packed));
483 #endif
484