xref: /openbmc/linux/include/uapi/sound/asoc.h (revision d2e3cb85)
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 /* DAI physical PCM data formats.
134  * Add new formats to the end of the list.
135  */
136 #define SND_SOC_DAI_FORMAT_I2S          1 /* I2S mode */
137 #define SND_SOC_DAI_FORMAT_RIGHT_J      2 /* Right Justified mode */
138 #define SND_SOC_DAI_FORMAT_LEFT_J       3 /* Left Justified mode */
139 #define SND_SOC_DAI_FORMAT_DSP_A        4 /* L data MSB after FRM LRC */
140 #define SND_SOC_DAI_FORMAT_DSP_B        5 /* L data MSB during FRM LRC */
141 #define SND_SOC_DAI_FORMAT_AC97         6 /* AC97 */
142 #define SND_SOC_DAI_FORMAT_PDM          7 /* Pulse density modulation */
143 
144 /* left and right justified also known as MSB and LSB respectively */
145 #define SND_SOC_DAI_FORMAT_MSB          SND_SOC_DAI_FORMAT_LEFT_J
146 #define SND_SOC_DAI_FORMAT_LSB          SND_SOC_DAI_FORMAT_RIGHT_J
147 
148 /*
149  * Block Header.
150  * This header precedes all object and object arrays below.
151  */
152 struct snd_soc_tplg_hdr {
153 	__le32 magic;		/* magic number */
154 	__le32 abi;		/* ABI version */
155 	__le32 version;		/* optional vendor specific version details */
156 	__le32 type;		/* SND_SOC_TPLG_TYPE_ */
157 	__le32 size;		/* size of this structure */
158 	__le32 vendor_type;	/* optional vendor specific type info */
159 	__le32 payload_size;	/* data bytes, excluding this header */
160 	__le32 index;		/* identifier for block */
161 	__le32 count;		/* number of elements in block */
162 } __attribute__((packed));
163 
164 /* vendor tuple for uuid */
165 struct snd_soc_tplg_vendor_uuid_elem {
166 	__le32 token;
167 	char uuid[16];
168 } __attribute__((packed));
169 
170 /* vendor tuple for a bool/byte/short/word value */
171 struct snd_soc_tplg_vendor_value_elem {
172 	__le32 token;
173 	__le32 value;
174 } __attribute__((packed));
175 
176 /* vendor tuple for string */
177 struct snd_soc_tplg_vendor_string_elem {
178 	__le32 token;
179 	char string[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
180 } __attribute__((packed));
181 
182 struct snd_soc_tplg_vendor_array {
183 	__le32 size;	/* size in bytes of the array, including all elements */
184 	__le32 type;	/* SND_SOC_TPLG_TUPLE_TYPE_ */
185 	__le32 num_elems;	/* number of elements in array */
186 	union {
187 		struct snd_soc_tplg_vendor_uuid_elem uuid[0];
188 		struct snd_soc_tplg_vendor_value_elem value[0];
189 		struct snd_soc_tplg_vendor_string_elem string[0];
190 	};
191 } __attribute__((packed));
192 
193 /*
194  * Private data.
195  * All topology objects may have private data that can be used by the driver or
196  * firmware. Core will ignore this data.
197  */
198 struct snd_soc_tplg_private {
199 	__le32 size;	/* in bytes of private data */
200 	union {
201 		char data[0];
202 		struct snd_soc_tplg_vendor_array array[0];
203 	};
204 } __attribute__((packed));
205 
206 /*
207  * Kcontrol TLV data.
208  */
209 struct snd_soc_tplg_tlv_dbscale {
210 	__le32 min;
211 	__le32 step;
212 	__le32 mute;
213 } __attribute__((packed));
214 
215 struct snd_soc_tplg_ctl_tlv {
216 	__le32 size;	/* in bytes of this structure */
217 	__le32 type;	/* SNDRV_CTL_TLVT_*, type of TLV */
218 	union {
219 		__le32 data[SND_SOC_TPLG_TLV_SIZE];
220 		struct snd_soc_tplg_tlv_dbscale scale;
221 	};
222 } __attribute__((packed));
223 
224 /*
225  * Kcontrol channel data
226  */
227 struct snd_soc_tplg_channel {
228 	__le32 size;	/* in bytes of this structure */
229 	__le32 reg;
230 	__le32 shift;
231 	__le32 id;	/* ID maps to Left, Right, LFE etc */
232 } __attribute__((packed));
233 
234 /*
235  * Genericl Operations IDs, for binding Kcontrol or Bytes ext ops
236  * Kcontrol ops need get/put/info.
237  * Bytes ext ops need get/put.
238  */
239 struct snd_soc_tplg_io_ops {
240 	__le32 get;
241 	__le32 put;
242 	__le32 info;
243 } __attribute__((packed));
244 
245 /*
246  * kcontrol header
247  */
248 struct snd_soc_tplg_ctl_hdr {
249 	__le32 size;	/* in bytes of this structure */
250 	__le32 type;
251 	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
252 	__le32 access;
253 	struct snd_soc_tplg_io_ops ops;
254 	struct snd_soc_tplg_ctl_tlv tlv;
255 } __attribute__((packed));
256 
257 /*
258  * Stream Capabilities
259  */
260 struct snd_soc_tplg_stream_caps {
261 	__le32 size;		/* in bytes of this structure */
262 	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
263 	__le64 formats;	/* supported formats SNDRV_PCM_FMTBIT_* */
264 	__le32 rates;		/* supported rates SNDRV_PCM_RATE_* */
265 	__le32 rate_min;	/* min rate */
266 	__le32 rate_max;	/* max rate */
267 	__le32 channels_min;	/* min channels */
268 	__le32 channels_max;	/* max channels */
269 	__le32 periods_min;	/* min number of periods */
270 	__le32 periods_max;	/* max number of periods */
271 	__le32 period_size_min;	/* min period size bytes */
272 	__le32 period_size_max;	/* max period size bytes */
273 	__le32 buffer_size_min;	/* min buffer size bytes */
274 	__le32 buffer_size_max;	/* max buffer size bytes */
275 	__le32 sig_bits;        /* number of bits of content */
276 } __attribute__((packed));
277 
278 /*
279  * FE or BE Stream configuration supported by SW/FW
280  */
281 struct snd_soc_tplg_stream {
282 	__le32 size;		/* in bytes of this structure */
283 	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* Name of the stream */
284 	__le64 format;		/* SNDRV_PCM_FMTBIT_* */
285 	__le32 rate;		/* SNDRV_PCM_RATE_* */
286 	__le32 period_bytes;	/* size of period in bytes */
287 	__le32 buffer_bytes;	/* size of buffer in bytes */
288 	__le32 channels;	/* channels */
289 } __attribute__((packed));
290 
291 /*
292  * Manifest. List totals for each payload type. Not used in parsing, but will
293  * be passed to the component driver before any other objects in order for any
294  * global component resource allocations.
295  *
296  * File block representation for manifest :-
297  * +-----------------------------------+----+
298  * | struct snd_soc_tplg_hdr           |  1 |
299  * +-----------------------------------+----+
300  * | struct snd_soc_tplg_manifest      |  1 |
301  * +-----------------------------------+----+
302  */
303 struct snd_soc_tplg_manifest {
304 	__le32 size;		/* in bytes of this structure */
305 	__le32 control_elems;	/* number of control elements */
306 	__le32 widget_elems;	/* number of widget elements */
307 	__le32 graph_elems;	/* number of graph elements */
308 	__le32 pcm_elems;	/* number of PCM elements */
309 	__le32 dai_link_elems;	/* number of DAI link elements */
310 	__le32 be_dai_elems;	/* number of BE DAI elements */
311 	__le32 reserved[20];	/* reserved for new ABI element types */
312 	struct snd_soc_tplg_private priv;
313 } __attribute__((packed));
314 
315 /*
316  * Mixer kcontrol.
317  *
318  * File block representation for mixer kcontrol :-
319  * +-----------------------------------+----+
320  * | struct snd_soc_tplg_hdr           |  1 |
321  * +-----------------------------------+----+
322  * | struct snd_soc_tplg_mixer_control |  N |
323  * +-----------------------------------+----+
324  */
325 struct snd_soc_tplg_mixer_control {
326 	struct snd_soc_tplg_ctl_hdr hdr;
327 	__le32 size;	/* in bytes of this structure */
328 	__le32 min;
329 	__le32 max;
330 	__le32 platform_max;
331 	__le32 invert;
332 	__le32 num_channels;
333 	struct snd_soc_tplg_channel channel[SND_SOC_TPLG_MAX_CHAN];
334 	struct snd_soc_tplg_private priv;
335 } __attribute__((packed));
336 
337 /*
338  * Enumerated kcontrol
339  *
340  * File block representation for enum kcontrol :-
341  * +-----------------------------------+----+
342  * | struct snd_soc_tplg_hdr           |  1 |
343  * +-----------------------------------+----+
344  * | struct snd_soc_tplg_enum_control  |  N |
345  * +-----------------------------------+----+
346  */
347 struct snd_soc_tplg_enum_control {
348 	struct snd_soc_tplg_ctl_hdr hdr;
349 	__le32 size;	/* in bytes of this structure */
350 	__le32 num_channels;
351 	struct snd_soc_tplg_channel channel[SND_SOC_TPLG_MAX_CHAN];
352 	__le32 items;
353 	__le32 mask;
354 	__le32 count;
355 	char texts[SND_SOC_TPLG_NUM_TEXTS][SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
356 	__le32 values[SND_SOC_TPLG_NUM_TEXTS * SNDRV_CTL_ELEM_ID_NAME_MAXLEN / 4];
357 	struct snd_soc_tplg_private priv;
358 } __attribute__((packed));
359 
360 /*
361  * Bytes kcontrol
362  *
363  * File block representation for bytes kcontrol :-
364  * +-----------------------------------+----+
365  * | struct snd_soc_tplg_hdr           |  1 |
366  * +-----------------------------------+----+
367  * | struct snd_soc_tplg_bytes_control |  N |
368  * +-----------------------------------+----+
369  */
370 struct snd_soc_tplg_bytes_control {
371 	struct snd_soc_tplg_ctl_hdr hdr;
372 	__le32 size;	/* in bytes of this structure */
373 	__le32 max;
374 	__le32 mask;
375 	__le32 base;
376 	__le32 num_regs;
377 	struct snd_soc_tplg_io_ops ext_ops;
378 	struct snd_soc_tplg_private priv;
379 } __attribute__((packed));
380 
381 /*
382  * DAPM Graph Element
383  *
384  * File block representation for DAPM graph elements :-
385  * +-------------------------------------+----+
386  * | struct snd_soc_tplg_hdr             |  1 |
387  * +-------------------------------------+----+
388  * | struct snd_soc_tplg_dapm_graph_elem |  N |
389  * +-------------------------------------+----+
390  */
391 struct snd_soc_tplg_dapm_graph_elem {
392 	char sink[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
393 	char control[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
394 	char source[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
395 } __attribute__((packed));
396 
397 /*
398  * DAPM Widget.
399  *
400  * File block representation for DAPM widget :-
401  * +-------------------------------------+-----+
402  * | struct snd_soc_tplg_hdr             |  1  |
403  * +-------------------------------------+-----+
404  * | struct snd_soc_tplg_dapm_widget     |  N  |
405  * +-------------------------------------+-----+
406  * |   struct snd_soc_tplg_enum_control  | 0|1 |
407  * |   struct snd_soc_tplg_mixer_control | 0|N |
408  * +-------------------------------------+-----+
409  *
410  * Optional enum or mixer control can be appended to the end of each widget
411  * in the block.
412  */
413 struct snd_soc_tplg_dapm_widget {
414 	__le32 size;		/* in bytes of this structure */
415 	__le32 id;		/* SND_SOC_DAPM_CTL */
416 	char name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
417 	char sname[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
418 
419 	__le32 reg;		/* negative reg = no direct dapm */
420 	__le32 shift;		/* bits to shift */
421 	__le32 mask;		/* non-shifted mask */
422 	__le32 subseq;		/* sort within widget type */
423 	__le32 invert;		/* invert the power bit */
424 	__le32 ignore_suspend;	/* kept enabled over suspend */
425 	__le16 event_flags;
426 	__le16 event_type;
427 	__le32 num_kcontrols;
428 	struct snd_soc_tplg_private priv;
429 	/*
430 	 * kcontrols that relate to this widget
431 	 * follow here after widget private data
432 	 */
433 } __attribute__((packed));
434 
435 
436 /*
437  * Describes SW/FW specific features of PCM (FE DAI & DAI link).
438  *
439  * File block representation for PCM :-
440  * +-----------------------------------+-----+
441  * | struct snd_soc_tplg_hdr           |  1  |
442  * +-----------------------------------+-----+
443  * | struct snd_soc_tplg_pcm           |  N  |
444  * +-----------------------------------+-----+
445  */
446 struct snd_soc_tplg_pcm {
447 	__le32 size;		/* in bytes of this structure */
448 	char pcm_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
449 	char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN];
450 	__le32 pcm_id;		/* unique ID - used to match with DAI link */
451 	__le32 dai_id;		/* unique ID - used to match */
452 	__le32 playback;	/* supports playback mode */
453 	__le32 capture;		/* supports capture mode */
454 	__le32 compress;	/* 1 = compressed; 0 = PCM */
455 	struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* for DAI link */
456 	__le32 num_streams;	/* number of streams */
457 	struct snd_soc_tplg_stream_caps caps[2]; /* playback and capture for DAI */
458 } __attribute__((packed));
459 
460 
461 /*
462  * Describes the BE or CC link runtime supported configs or params
463  *
464  * File block representation for BE/CC link config :-
465  * +-----------------------------------+-----+
466  * | struct snd_soc_tplg_hdr           |  1  |
467  * +-----------------------------------+-----+
468  * | struct snd_soc_tplg_link_config   |  N  |
469  * +-----------------------------------+-----+
470  */
471 struct snd_soc_tplg_link_config {
472 	__le32 size;            /* in bytes of this structure */
473 	__le32 id;              /* unique ID - used to match */
474 	struct snd_soc_tplg_stream stream[SND_SOC_TPLG_STREAM_CONFIG_MAX]; /* supported configs playback and captrure */
475 	__le32 num_streams;     /* number of streams */
476 } __attribute__((packed));
477 
478 /*
479  * Describes SW/FW specific features of BE DAI.
480  *
481  * File block representation for BE DAI :-
482  * +-----------------------------------+-----+
483  * | struct snd_soc_tplg_hdr           |  1  |
484  * +-----------------------------------+-----+
485  * | struct snd_soc_tplg_be_dai        |  N  |
486  * +-----------------------------------+-----+
487  */
488 struct snd_soc_tplg_be_dai {
489 	__le32 size;            /* in bytes of this structure */
490 	char dai_name[SNDRV_CTL_ELEM_ID_NAME_MAXLEN]; /* name - used to match */
491 	__le32 dai_id;          /* unique ID - used to match */
492 	__le32 playback;        /* supports playback mode */
493 	__le32 capture;         /* supports capture mode */
494 	struct snd_soc_tplg_stream_caps caps[2]; /* playback and capture for DAI */
495 	__le32 flag_mask;       /* bitmask of flags to configure */
496 	__le32 flags;           /* SND_SOC_TPLG_DAI_FLGBIT_* */
497 	struct snd_soc_tplg_private priv;
498 } __attribute__((packed));
499 #endif
500