OSDN Git Service

topology: ABI - Update physical DAI link configurations to ABI v5
[android-x86/external-alsa-lib.git] / include / topology.h
1 /*
2  *
3  *  This library is free software; you can redistribute it and/or modify
4  *  it under the terms of the GNU Lesser General Public License as
5  *  published by the Free Software Foundation; either version 2.1 of
6  *  the License, or (at your option) any later version.
7  *
8  *  This program is distributed in the hope that it will be useful,
9  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *  GNU Lesser General Public License for more details.
12  *
13  *  You should have received a copy of the GNU Lesser General Public
14  *  License along with this library; if not, write to the Free Software
15  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16  *
17  *  Copyright (C) 2015 Intel Corporation
18  *
19  */
20
21 #ifndef __ALSA_TOPOLOGY_H
22 #define __ALSA_TOPOLOGY_H
23
24 #include <stdint.h>
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30 /**
31  * \defgroup topology Topology Interface
32  * \{
33  */
34
35 /*! \page topology ALSA Topology Interface
36  *
37  * The topology interface allows developers to define DSP topologies in a text
38  * file format and to convert the text topology to a binary topology
39  * representation that can be understood by the kernel. The topology core
40  * currently recognises the following object types :-
41  *
42  *  * Controls (mixer, enumerated and byte) including TLV data.
43  *  * PCMs (FE and BE configurations and capabilities)
44  *  * DAPM widgets
45  *  * DAPM graph elements.
46  *  * Private data for each object type.
47  *  * Manifest (containing count of each object type)
48  *
49  * <h3>Topology File Format</h3>
50  *
51  * The topology text format uses the standard ALSA configuration file format to
52  * describe each topology object type. This allows topology objects to include
53  * other topology objects as part of their definition. i.e. a TLV data object
54  * can be shared amongst many control objects that use the same TLV data.
55  *
56  *
57  * <h4>Controls</h4>
58  * Topology audio controls can belong to three different types :-
59  *   * Mixer control
60  *   * Enumerated control
61  *   * Byte control
62  *
63  * Each control type can contain TLV data, private data, operations and also
64  * belong to widget objects.<br>
65  *
66  * <h5>Control Operations</h5>
67  * Driver Kcontrol callback info(), get() and put() operations are mapped with
68  * the CTL ops section in topology configuration files. The ctl ops section can
69  * assign operations using the standard names (listed below) for the standard
70  * kcontrol types or use ID numbers (>256) to map to bespoke driver controls.<br>
71  *
72  * <pre>
73  *
74  *      ops."ctl" {
75  *              info "volsw"
76  *              get "257"
77  *              put "257"
78  *      }
79  *
80  * </pre>
81  *
82  * This mapping shows info() using the standard "volsw" info callback whilst
83  * the get() and put() are mapped to bespoke driver callbacks. <br>
84  *
85  * The Standard operations names for control get(), put() and info calls
86  * are :-
87  *  * volsw
88  *  * volsw_sx
89  *  * volsw_xr_sx
90  *  * enum
91  *  * bytes
92  *  * enum_value
93  *  * range
94  *  * strobe
95  *
96 * <h5>Control Access</h5>
97  * Controls access can be specified using the "access" section. If no "access"
98  * section is defined then default RW access flags are set for normal and TLV
99  * controls.
100  *
101  * <pre>
102  *      access [
103  *              read
104  *              write
105  *              tlv_command
106  *      ]
107  * </pre>
108  *
109  * The standard access flags are as follows :-
110  *  * read
111  *  * write
112  *  * read_write
113  *  * volatile
114  *  * timestamp
115  *  * tlv_read
116  *  * tlv_write
117  *  * tlv_read_write
118  *  * tlv_command
119  *  * inactive
120  *  * lock
121  *  * owner
122  *  * tlv_callback
123  *  * user
124  *
125  * <h5>Control TLV Data</h5>
126  * Controls can also use TLV data to represent dB information. This can be done
127  * by defining a TLV section and using the TLV section within the control.
128  * The TLV data for DBScale types are defined as follows :-
129  *
130  * <pre>
131  *      scale {
132  *              min "-9000"
133  *              step "300"
134  *              mute "1"
135  *      }
136  * </pre>
137  *
138  * Where the meanings and values for min, step and mute are exactly the same
139  * as defined in driver code.
140  *
141  * <h5>Control Channel Mapping</h5>
142  * Controls can also specify which channels they are mapped with. This is useful
143  * for userspace as it allows applications to determine the correct control
144  * channel for Left and Right etc. Channel maps are defined as follows :-
145  *
146  * <pre>
147  *      channel."name" {
148  *              reg "0"
149  *              shift "0"
150  *      }
151  * </pre>
152  *
153  * The channel map reg is the register offset for the control, shift is the
154  * bit shift within the register for the channel and the section name is the
155  * channel name and can be one of the following :-
156  *
157  * <pre>
158  *  * mono              # mono stream
159  *  * fl                # front left
160  *  * fr                # front right
161  *  * rl                # rear left
162  *  * rr                # rear right
163  *  * fc                # front center
164  *  * lfe               # LFE
165  *  * sl                # side left
166  *  * sr                # side right
167  *  * rc                # rear center
168  *  * flc               # front left center
169  *  * frc               # front right center
170  *  * rlc               # rear left center
171  *  * rrc               # rear right center
172  *  * flw               # front left wide
173  *  * frw               # front right wide
174  *  * flh               # front left high
175  *  * fch               # front center high
176  *  * frh               # front right high
177  *  * tc                # top center
178  *  * tfl               # top front left
179  *  * tfr               # top front right
180  *  * tfc               # top front center
181  *  * trl               # top rear left
182  *  * trr               # top rear right
183  *  * trc               # top rear center
184  *  * tflc              # top front left center
185  *  * tfrc              # top front right center
186  *  * tsl               # top side left
187  *  * tsr               # top side right
188  *  * llfe              # left LFE
189  *  * rlfe              # right LFE
190  *  * bc                # bottom center
191  *  * blc               # bottom left center
192  *  * brc               # bottom right center
193  * </pre>
194  *
195  *  <h5>Control Private Data</h5>
196  * Controls can also have private data. This can be done by defining a private
197  * data section and including the section within the control. The private data
198  * section is defined as follows :-
199  *
200  * <pre>
201  * SectionData."pdata for EQU1" {
202  *      file "/path/to/file"
203  *      bytes "0x12,0x34,0x56,0x78"
204  *      shorts "0x1122,0x3344,0x5566,0x7788"
205  *      words "0xaabbccdd,0x11223344,0x66aa77bb,0xefef1234"
206  *      tuples "section id of the vendor tuples"
207  * };
208  * </pre>
209  * The file, bytes, shorts, words and tuples keywords are all mutually
210  * exclusive as the private data should only be taken from one source.
211  * The private data can either be read from a separate file or defined in
212  * the topology file using the bytes, shorts, words or tuples keywords.
213  * The keyword tuples is to define vendor specific tuples. Please refer to
214  * section Vendor Tokens and Vendor tuples.
215  *
216  * <h5>How to define an element with private data</h5>
217  * An element can refer to a single data section or multiple data
218  * sections.
219  *
220  * <h6>To refer to a single data section:</h6>
221  * <pre>
222  * Sectionxxx."element name" {
223  *    ...
224  *      data "name of data section"             # optional private data
225  * }
226  * </pre>
227  *
228  * <h6>To refer to multiple data sections:</h6>
229  * <pre>
230  * Sectionxxx."element name" {
231  *      ...
232  *      data [                                          # optional private data
233  *              "name of 1st data section"
234  *              "name of 2nd data section"
235  *              ...
236  *      ]
237  * }
238  * </pre>
239  * And data of these sections will be merged in the same order as they are
240  * in the list, as the element's private data for kernel.
241  *
242  * </pre>
243  *
244  *  <h6>Vendor Tokens</h6>
245  * A vendor token list is defined as a new section. Each token element is
246  * a pair of string ID and integer value. And both the ID and value are
247  * vendor-specific.
248  *
249  * <pre>
250  * SectionVendorTokens."id of the vendor tokens" {
251  *      comment "optional comments"
252  *      VENDOR_TOKEN_ID1 "1"
253  *      VENDOR_TOKEN_ID2 "2"
254  *      VENDOR_TOKEN_ID3 "3"
255  *      ...
256  * }
257  * </pre>
258  *
259  *  <h6>Vendor Tuples</h6>
260  * Vendor tuples are defined as a new section. It contains a reference to
261  * a vendor token list and several tuple arrays.
262  * All arrays share a vendor token list, defined by the tokens keyword.
263  * Each tuple array is for a specific type, defined by the string following
264  * the tuples keyword. Supported types are: string, uuid, bool, byte,
265  * short and word.
266  *
267  * <pre>
268  * SectionVendorTuples."id of the vendor tuples" {
269  *      tokens "id of the vendor tokens"
270  *
271  *      tuples."string" {
272  *              VENDOR_TOKEN_ID1 "character string"
273  *              ...
274  *      }
275  *
276  *      tuples."uuid" {                 # 16 characters separated by commas
277  *              VENDOR_TOKEN_ID2 "0x01,0x02,...,0x0f"
278  *              ...
279  *      }
280  *
281  *      tuples."bool" {
282  *              VENDOR_TOKEN_ID3 "true/false"
283  *              ...
284  *      }
285  *
286  *      tuples."byte" {
287  *              VENDOR_TOKEN_ID4 "0x11"
288  *              VENDOR_TOKEN_ID5 "0x22"
289  *              ...
290  *      }
291  *
292  *      tuples."short" {
293  *              VENDOR_TOKEN_ID6 "0x1122"
294  *              VENDOR_TOKEN_ID7 "0x3344"
295  *              ...
296  *      }
297  *
298  *      tuples."word" {
299  *              VENDOR_TOKEN_ID8 "0x11223344"
300  *              VENDOR_TOKEN_ID9 "0x55667788"
301  *              ...
302  *      }
303  * }
304  * </pre>
305  * To define multiple vendor tuples of same type, please append some
306  * characters after the type string ("string", "uuid", "bool", "byte", "short"
307  * or "word"), to avoid ID duplication in the SectionVendorTuples.<br>
308  * The parser will check the first few characters in ID to get the tuple type.
309  * Here is an example:
310  * <pre>
311  * SectionVendorTuples."id of the vendor tuples" {
312  *    ...
313  *      tuples."word.module0" {
314  *              VENDOR_TOKEN_PARAM_ID1 "0x00112233"
315  *              VENDOR_TOKEN_PARAM_ID2 "0x44556677"
316  *              ...
317  *      }
318  *
319  *      tuples."word.module2" {
320  *              VENDOR_TOKEN_PARAM_ID1 "0x11223344"
321  *              VENDOR_TOKEN_PARAM_ID2 "0x55667788"
322  *              ...
323  *      }
324  *      ...
325  * }
326  *
327  * </pre>
328  *
329  * <h5>Mixer Controls</h5>
330  * A mixer control is defined as a new section that can include channel mapping,
331  * TLV data, callback operations and private data. The mixer section also
332  * includes a few other config options that are shown here :-
333  *
334  * <pre>
335  * SectionControlMixer."mixer name" {
336  *      comment "optional comments"
337  *
338  *      index "1"                       # Index number
339  *
340  *      channel."name" {                # Channel maps
341  *         ....
342  *      }
343  *
344  *      ops."ctl" {                     # Ops callback functions
345  *         ....
346  *      }
347  *
348  *      max "32"                        # Max control value
349  *      invert "0"                      # Whether control values are inverted
350  *
351  *      tlv "tld_data"                  # optional TLV data
352  *
353  *      data "pdata for mixer1"         # optional private data
354  * }
355  * </pre>
356  *
357  * The section name is used to define the mixer name. The index number can be
358  * used to identify topology objects groups. This allows driver operations on
359  * objects with index number N and can be used to add/remove pipelines of
360  * objects whilst other objects are unaffected.
361  *
362  * <h5>Byte Controls</h5>
363  * A byte control is defined as a new section that can include channel mapping,
364  * TLV data, callback operations and private data. The bytes section also
365  * includes a few other config options that are shown here :-
366  *
367  * <pre>
368  * SectionControlBytes."name" {
369  *      comment "optional comments"
370  *
371  *      index "1"                       # Index number
372  *
373  *      channel."name" {                # Channel maps
374  *         ....
375  *      }
376  *
377  *      ops."ctl" {                     # Ops callback functions
378  *         ....
379  *      }
380  *
381  *      base "0"                        # Register base
382  *      num_regs "16"                   # Number of registers
383  *      mask "0xff"                     # Mask
384  *      max "255"                       # Maximum value
385  *
386  *      tlv "tld_data"                  # optional TLV data
387  *
388  *      data "pdata for mixer1"         # optional private data
389  * }
390  * </pre>
391  *
392  * <h5>Enumerated Controls</h5>
393  * A enumerated control is defined as a new section (like mixer and byte) that
394  * can include channel mapping, callback operations, private data and
395  * text strings to represent the enumerated control options.<br>
396  *
397  * The text strings for the enumerated controls are defined in a separate
398  * section as follows :-
399  *
400  * <pre>
401  * SectionText."name" {
402  *
403  *              Values [
404  *                      "value1"
405  *                      "value2"
406                         "value3"
407  *              ]
408  * }
409  * </pre>
410  *
411  * All the enumerated text values are listed in the values list.<br>
412  * The enumerated control is similar to the other controls and defined as
413  * follows :-
414  *
415  * <pre>
416  * SectionControlMixer."name" {
417  *      comment "optional comments"
418  *
419  *      index "1"                       # Index number
420  *
421  *      texts "EQU1"                    # Enumerated text items
422  *
423  *      channel."name" {                # Channel maps
424  *         ....
425  *      }
426  *
427  *      ops."ctl" {                     # Ops callback functions
428  *         ....
429  *      }
430  *
431  *      data "pdata for mixer1"         # optional private data
432  * }
433  * </pre>
434  *
435  * <h4>DAPM Graph</h4>
436  * DAPM graphs can easily be defined using the topology file. The format is
437  * very similar to the DAPM graph kernel format. :-
438  *
439  * <pre>
440  * SectionGraph."dsp" {
441  *      index "1"                       # Index number
442  *
443  *      lines [
444  *              "sink1, control, source1"
445  *              "sink2, , source2"
446  *      ]
447  * }
448  * </pre>
449  *
450  * The lines in the graph are defined as a variable size list of sinks,
451  * controls and sources. The control name is optional as some graph lines have
452  * no associated controls. The section name can be used to differentiate the
453  * graph with other graphs, it's not used by the kernel atm.
454  *
455  * <h4>DAPM Widgets</h4>
456  * DAPM widgets are similar to controls in that they can include many other
457  * objects. Widgets can contain private data, mixer controls and enum controls.
458  *
459  * The following widget types are supported and match the driver types :-
460  *
461  *  * input
462  *  * output
463  *  * mux
464  *  * mixer
465  *  * pga
466  *  * out_drv
467  *  * adc
468  *  * dac
469  *  * switch
470  *  * pre
471  *  * post
472  *  * aif_in
473  *  * aif_out
474  *  * dai_in
475  *  * dai_out
476  *  * dai_link
477  *
478  * Widgets are defined as follows :-
479  *
480  * <pre>
481  * SectionWidget."name" {
482  *
483  *      index "1"                       # Index number
484  *
485  *      type "aif_in"                   # Widget type - detailed above
486  *      stream_name "name"              # Stream name
487  *
488  *      no_pm "true"                    # No PM control bit.
489  *      reg "20"                        # PM bit register offset
490  *      shift "0"                       # PM bit register shift
491  *      invert "1                       # PM bit is inverted
492  *      subseq "8"                      # subsequence number
493  *
494  *      event_type "1"                  # DAPM widget event type
495  *      event_flags "1"                 # DAPM widget event flags
496  *
497  *      mixer "name"                    # Optional Mixer Control
498  *      enum "name"                     # Optional Enum Control
499  *
500  *      data "name"                     # optional private data
501  * }
502  * </pre>
503  *
504  * The section name is the widget name. The mixer and enum fields are mutually
505  * exclusive and used to include controls into the widget. The index and data
506  * fields are the same for widgets as they are for controls whilst the other
507  * fields map on very closely to the driver widget fields.
508  *
509  * <h5>Widget Private Data</h5>
510  * Widget can have private data. For the format of the private data, please
511  * refer to section Control Private Data.
512  *
513  * <h4>PCM Capabilities</h4>
514  * Topology can also define the capabilities of FE and BE PCMs. Capabilities
515  * can be defined with the following section :-
516  *
517  * <pre>
518  * SectionPCMCapabilities."name" {
519  *
520  *      formats "S24_LE,S16_LE"         # Supported formats
521  *      rate_min "48000"                # Max supported sample rate
522  *      rate_max "48000"                # Min supported sample rate
523  *      channels_min "2"                # Min number of channels
524  *      channels_max "2"                # max number of channels
525  * }
526  * </pre>
527  * The supported formats use the same naming convention as the driver macros.
528  * The PCM capabilities name can be referred to and included by BE, PCM and
529  * Codec <-> codec topology sections.
530  *
531  * <h4>PCM Configurations</h4>
532  * PCM runtime configurations can be defined for playback and capture stream
533  * directions with the following section  :-
534  *
535  * <pre>
536  * SectionPCMConfig."name" {
537  *
538  *      config."playback" {             # playback config
539  *              format "S16_LE"         # playback format
540  *              rate "48000"            # playback sample rate
541  *              channels "2"            # playback channels
542  *              tdm_slot "0xf"          # playback TDM slot
543  *      }
544  *
545  *      config."capture" {              # capture config
546  *              format "S16_LE"         # capture format
547  *              rate "48000"            # capture sample rate
548  *              channels "2"            # capture channels
549  *              tdm_slot "0xf"          # capture TDM slot
550  *      }
551  * }
552  * </pre>
553  *
554  * The supported formats use the same naming convention as the driver macros.
555  * The PCM configuration name can be referred to and included by BE, PCM and
556  * Codec <-> codec topology sections.
557  *
558  * <h4>PCM Configurations</h4>
559  * PCM, BE and Codec to Codec link sections define the supported capabilities
560  * and configurations for supported playback and capture streams. The
561  * definitions and content for PCMs, BE and Codec links are the same with the
562  * exception of the section type :-
563  *
564  * <pre>
565  * SectionPCM."name" {
566  *      ....
567  * }
568  * SectionBE."name" {
569  *      ....
570  * }
571  * SectionCC."name" {
572  *      ....
573  * }
574  * </pre>
575  *
576  * The section types above should be used for PCMs, Back Ends and Codec to Codec
577  * links respectively.<br>
578  *
579  * The data for each section is defined as follows :-
580  *
581  * <pre>
582  * SectionPCM."name" {
583  *
584  *      index "1"                       # Index number
585  *
586  *      id "0"                          # used for binding to the PCM
587  *
588  *      dai."name of front-end DAI" {
589  *              id "0"          # used for binding to the front-end DAI
590  *      }
591  *
592  *      pcm."playback" {
593  *              capabilities "capabilities1"    # capabilities for playback
594  *
595  *              configs [               # supported configs for playback
596  *                      "config1"
597  *                      "config2"
598  *              ]
599  *      }
600  *
601  *      pcm."capture" {
602  *              capabilities "capabilities2"    # capabilities for capture
603  *
604  *              configs [               # supported configs for capture
605  *                      "config1"
606  *                      "config2"
607  *                      "config3"
608  *              ]
609  *      }
610  *
611  *      # Optional boolean flags
612  *      symmetric_rates                 "true"
613  *      symmetric_channels              "true"
614  *      symmetric_sample_bits           "false"
615  *
616  *      data "name"                     # optional private data
617  * }
618  * </pre>
619  *
620  * <h4>Manifest Private Data</h4>
621  * Manfiest may have private data. Users need to define a manifest section
622  * and add the references to 1 or multiple data sections. Please refer to
623  * section 'How to define an element with private data'. <br>
624  * And the text conf file can have at most 1 manifest section. <br><br>
625  *
626  * Manifest section is defined as follows :-
627  *
628  * <pre>
629  * SectionManifest"name" {
630  *
631  *      data "name"                     # optional private data
632  * }
633  * </pre>
634  *
635  * <h4>Include other files</h4>
636  * Users may include other files in a text conf file via alsaconf syntax
637  * <path/to/configuration-file>. This allows users to define common info
638  * in separate files (e.g. vendor tokens, tuples) and share them for
639  * different platforms, thus save the total size of config files. <br>
640  * Users can also specifiy additional configuraiton directories relative
641  * to "/usr/share/alsa/" to search the included files,  via alsaconf syntax
642  * <searchfdir:/relative-path/to/usr/share/alsa>. <br><br>
643  *
644  * For example, file A and file B are two text conf files for platform X,
645  * they will be installed to /usr/share/alsa/topology/platformx. If we
646  * need file A to include file B, in file A we can add: <br>
647  *
648  * <searchdir:topology/platformx> <br>
649  * <name-of-file-B> <br><br>
650  *
651  * ALSA conf will search and open an included file in the following order
652  * of priority:
653  *  1. directly open the file by its name;
654  *  2. search for the file name in "/usr/share/alsa";
655  *  3. search for the file name in user specified subdirectories under
656  *     "/usr/share/alsa".
657  *
658  * The order of the included files need not to be same as their
659  * dependencies, since the topology library will load them all before
660  * parsing their dependencies. <br>
661  *
662  * The configuration directories defined by a file will only be used to search
663  * the files included by this file.
664  */
665
666 /** Maximum number of channels supported in one control */
667 #define SND_TPLG_MAX_CHAN               8
668
669 /** Topology context */
670 typedef struct snd_tplg snd_tplg_t;
671
672 /** Topology object types */
673 enum snd_tplg_type {
674         SND_TPLG_TYPE_TLV = 0,          /*!< TLV Data */
675         SND_TPLG_TYPE_MIXER,            /*!< Mixer control*/
676         SND_TPLG_TYPE_ENUM,             /*!< Enumerated control */
677         SND_TPLG_TYPE_TEXT,             /*!< Text data */
678         SND_TPLG_TYPE_DATA,             /*!< Private data */
679         SND_TPLG_TYPE_BYTES,            /*!< Byte control */
680         SND_TPLG_TYPE_STREAM_CONFIG,    /*!< PCM Stream configuration */
681         SND_TPLG_TYPE_STREAM_CAPS,      /*!< PCM Stream capabilities */
682         SND_TPLG_TYPE_PCM,              /*!< PCM stream device */
683         SND_TPLG_TYPE_DAPM_WIDGET,      /*!< DAPM widget */
684         SND_TPLG_TYPE_DAPM_GRAPH,       /*!< DAPM graph elements */
685         SND_TPLG_TYPE_BE,               /*!< BE DAI link */
686         SND_TPLG_TYPE_CC,               /*!< Hostless codec <-> codec link */
687         SND_TPLG_TYPE_MANIFEST,         /*!< Topology manifest */
688         SND_TPLG_TYPE_TOKEN,            /*!< Vendor tokens */
689         SND_TPLG_TYPE_TUPLE,            /*!< Vendor tuples */
690 };
691
692 /**
693  * \brief Create a new topology parser instance.
694  * \return New topology parser instance
695  */
696 snd_tplg_t *snd_tplg_new(void);
697
698 /**
699  * \brief Free a topology parser instance.
700  * \param tplg Topology parser instance
701  */
702 void snd_tplg_free(snd_tplg_t *tplg);
703
704 /**
705  * \brief Parse and build topology text file into binary file.
706  * \param tplg Topology instance.
707  * \param infile Topology text input file to be parsed
708  * \param outfile Binary topology output file.
709  * \return Zero on success, otherwise a negative error code
710  */
711 int snd_tplg_build_file(snd_tplg_t *tplg, const char *infile,
712         const char *outfile);
713
714 /**
715  * \brief Enable verbose reporting of binary file output
716  * \param tplg Topology Instance
717  * \param verbose Enable verbose output level if non zero
718  */
719 void snd_tplg_verbose(snd_tplg_t *tplg, int verbose);
720
721 /** \struct snd_tplg_tlv_template
722  * \brief Template type for all TLV objects.
723  */
724 struct snd_tplg_tlv_template {
725         int type;        /*!< TLV type SNDRV_CTL_TLVT_ */
726 };
727
728 /** \struct snd_tplg_tlv_dbscale_template
729  * \brief Template type for TLV Scale objects.
730  */
731 struct snd_tplg_tlv_dbscale_template {
732         struct snd_tplg_tlv_template hdr;       /*!< TLV type header */
733         int min;                        /*!< dB minimum value in 0.1dB */
734         int step;                       /*!< dB step size in 0.1dB */
735         int mute;                       /*!< is min dB value mute ? */
736 };
737
738 /** \struct snd_tplg_channel_template
739  * \brief Template type for single channel mapping.
740  */
741 struct snd_tplg_channel_elem {
742         int size;       /*!< size in bytes of this structure */
743         int reg;        /*!< channel control register */
744         int shift;      /*!< channel shift for control bits */
745         int id;         /*!< ID maps to Left, Right, LFE etc */
746 };
747
748 /** \struct snd_tplg_channel_map_template
749  * \brief Template type for channel mapping.
750  */
751 struct snd_tplg_channel_map_template {
752         int num_channels;       /*!< number of channel mappings */
753         struct snd_tplg_channel_elem channel[SND_TPLG_MAX_CHAN];        /*!< mapping */
754 };
755
756 /** \struct snd_tplg_pdata_template
757  * \brief Template type for private data objects.
758  */
759 struct snd_tplg_pdata_template {
760         unsigned int length;    /*!< data length */
761         const void *data;       /*!< data */
762 };
763
764 /** \struct snd_tplg_io_ops_template
765  * \brief Template type for object operations mapping.
766  */
767 struct snd_tplg_io_ops_template {
768         int get;        /*!< get callback ID */
769         int put;        /*!< put callback ID */
770         int info;       /*!< info callback ID */
771 };
772
773 /** \struct snd_tplg_ctl_template
774  * \brief Template type for control objects.
775  */
776 struct snd_tplg_ctl_template {
777         int type;               /*!< Control type */
778         const char *name;       /*!< Control name */
779         int access;             /*!< Control access */
780         struct snd_tplg_io_ops_template ops;    /*!< operations */
781         struct snd_tplg_tlv_template *tlv; /*!< non NULL means we have TLV data */
782 };
783
784 /** \struct snd_tplg_mixer_template
785  * \brief Template type for mixer control objects.
786  */
787 struct snd_tplg_mixer_template {
788         struct snd_tplg_ctl_template hdr;       /*!< control type header */
789         struct snd_tplg_channel_map_template *map;      /*!< channel map */
790         int min;        /*!< min value for mixer */
791         int max;        /*!< max value for mixer */
792         int platform_max;       /*!< max value for platform control */
793         int invert;     /*!< whether controls bits are inverted */
794         struct snd_soc_tplg_private *priv;      /*!< control private data */
795 };
796
797 /** \struct snd_tplg_enum_template
798  * \brief Template type for enumerated control objects.
799  */
800 struct snd_tplg_enum_template {
801         struct snd_tplg_ctl_template hdr;       /*!< control type header */
802         struct snd_tplg_channel_map_template *map;      /*!< channel map */
803         int items;      /*!< number of enumerated items in control */
804         int mask;       /*!< register mask size */
805         const char **texts;     /*!< control text items */
806         const int **values;     /*!< control value items */
807         struct snd_soc_tplg_private *priv;      /*!< control private data */
808 };
809
810 /** \struct snd_tplg_bytes_template
811  * \brief Template type for TLV Scale objects.
812  */
813 struct snd_tplg_bytes_template {
814         struct snd_tplg_ctl_template hdr;       /*!< control type header */
815         int max;                /*!< max byte control value */
816         int mask;               /*!< byte control mask */
817         int base;               /*!< base register */
818         int num_regs;           /*!< number of registers */
819         struct snd_tplg_io_ops_template ext_ops;        /*!< ops mapping */
820         struct snd_soc_tplg_private *priv;      /*!< control private data */
821 };
822
823 /** \struct snd_tplg_graph_elem
824  * \brief Template type for single DAPM graph element.
825  */
826 struct snd_tplg_graph_elem {
827         const char *src;        /*!< source widget name */
828         const char *ctl;        /*!< control name or NULL if no control */
829         const char *sink;       /*!< sink widget name */
830 };
831
832 /** \struct snd_tplg_graph_template
833  * \brief Template type for array of DAPM graph elements.
834  */
835 struct snd_tplg_graph_template {
836         int count;              /*!< Number of graph elements */
837         struct snd_tplg_graph_elem elem[0];     /*!< graph elements */
838 };
839
840 /** \struct snd_tplg_widget_template
841  * \brief Template type for DAPM widget objects.
842  */
843 struct snd_tplg_widget_template {
844         int id;                 /*!< SND_SOC_DAPM_CTL */
845         const char *name;       /*!< widget name */
846         const char *sname;      /*!< stream name (certain widgets only) */
847         int reg;                /*!< negative reg = no direct dapm */
848         int shift;              /*!< bits to shift */
849         int mask;               /*!< non-shifted mask */
850         int subseq;             /*!< sort within widget type */
851         unsigned int invert;            /*!< invert the power bit */
852         unsigned int ignore_suspend;    /*!< kept enabled over suspend */
853         unsigned short event_flags;     /*!< PM event sequence flags */
854         unsigned short event_type;      /*!< PM event sequence type */
855         struct snd_soc_tplg_private *priv;      /*!< widget private data */
856         int num_ctls;                   /*!< Number of controls used by widget */
857         struct snd_tplg_ctl_template *ctl[0];   /*!< array of widget controls */
858 };
859
860 /** \struct snd_tplg_stream_template
861  * \brief Stream configurations.
862  */
863 struct snd_tplg_stream_template {
864         const char *name;       /*!< name of the stream config */
865         int format;             /*!< SNDRV_PCM_FMTBIT_* */
866         int rate;               /*!< SNDRV_PCM_RATE_* */
867         int period_bytes;       /*!< size of period in bytes */
868         int buffer_bytes;       /*!< size of buffer in bytes. */
869         int channels;           /*!< number of channels */
870 };
871
872 /** \struct snd_tplg_stream_caps_template
873  * \brief Stream Capabilities.
874  */
875 struct snd_tplg_stream_caps_template {
876         const char *name;       /*!< name of the stream caps */
877         uint64_t formats;       /*!< supported formats SNDRV_PCM_FMTBIT_* */
878         unsigned int rates;     /*!< supported rates SNDRV_PCM_RATE_* */
879         unsigned int rate_min;  /*!< min rate */
880         unsigned int rate_max;  /*!< max rate */
881         unsigned int channels_min;      /*!< min channels */
882         unsigned int channels_max;      /*!< max channels */
883         unsigned int periods_min;       /*!< min number of periods */
884         unsigned int periods_max;       /*!< max number of periods */
885         unsigned int period_size_min;   /*!< min period size bytes */
886         unsigned int period_size_max;   /*!< max period size bytes */
887         unsigned int buffer_size_min;   /*!< min buffer size bytes */
888         unsigned int buffer_size_max;   /*!< max buffer size bytes */
889         unsigned int sig_bits;          /*!< number of bits of content */
890 };
891
892 /** \struct snd_tplg_pcm_template
893  * \brief Template type for PCM (FE DAI & DAI links).
894  */
895 struct snd_tplg_pcm_template {
896         const char *pcm_name;   /*!< PCM stream name */
897         const char *dai_name;   /*!< DAI name */
898         unsigned int pcm_id;    /*!< unique ID - used to match */
899         unsigned int dai_id;    /*!< unique ID - used to match */
900         unsigned int playback;  /*!< supports playback mode */
901         unsigned int capture;   /*!< supports capture mode */
902         unsigned int compress;  /*!< 1 = compressed; 0 = PCM */
903         struct snd_tplg_stream_caps_template *caps[2]; /*!< playback & capture for DAI */
904         unsigned int flag_mask; /*!< bitmask of flags to configure */
905         unsigned int flags;     /*!< flag value SND_SOC_TPLG_LNK_FLGBIT_* */
906         struct snd_soc_tplg_private *priv;      /*!< private data */
907         int num_streams;        /*!< number of supported configs */
908         struct snd_tplg_stream_template stream[0]; /*!< supported configs */
909 };
910
911 /** \struct snd_tplg_link_template
912  * \brief Template type for BE and CC DAI Links.
913  */
914 struct snd_tplg_link_template {
915         const char *name;       /*!< link name */
916         int id; /*!< unique ID - used to match with existing BE and CC links */
917         int num_streams;        /*!< number of configs */
918         struct snd_tplg_stream_template stream[0]; /*!< supported configs */
919 };
920
921 /** \struct snd_tplg_obj_template
922  * \brief Generic Template Object
923  */
924 typedef struct snd_tplg_obj_template {
925         enum snd_tplg_type type;        /*!< template object type */
926         int index;              /*!< group index for object */
927         int version;            /*!< optional vendor specific version details */
928         int vendor_type;        /*!< optional vendor specific type info */
929         union {
930                 struct snd_tplg_widget_template *widget;        /*!< DAPM widget */
931                 struct snd_tplg_mixer_template *mixer;          /*!< Mixer control */
932                 struct snd_tplg_bytes_template *bytes_ctl;      /*!< Bytes control */
933                 struct snd_tplg_enum_template *enum_ctl;        /*!< Enum control */
934                 struct snd_tplg_graph_template *graph;          /*!< Graph elements */
935                 struct snd_tplg_pcm_template *pcm;              /*!< PCM elements */
936                 struct snd_tplg_link_template *link;            /*!< BE and CC Links */
937         };
938 } snd_tplg_obj_template_t;
939
940 /**
941  * \brief Register topology template object.
942  * \param tplg Topology instance.
943  * \param t Template object.
944  * \return Zero on success, otherwise a negative error code
945  */
946 int snd_tplg_add_object(snd_tplg_t *tplg, snd_tplg_obj_template_t *t);
947
948 /**
949  * \brief Build all registered topology data into binary file.
950  * \param tplg Topology instance.
951  * \param outfile Binary topology output file.
952  * \return Zero on success, otherwise a negative error code
953  */
954 int snd_tplg_build(snd_tplg_t *tplg, const char *outfile);
955
956 /**
957  * \brief Attach private data to topology manifest.
958  * \param tplg Topology instance.
959  * \param data Private data.
960  * \param len Length of data in bytes.
961  * \return Zero on success, otherwise a negative error code
962  */
963 int snd_tplg_set_manifest_data(snd_tplg_t *tplg, const void *data, int len);
964
965 /**
966  * \brief Set an optional vendor specific version number.
967  * \param tplg Topology instance.
968  * \param version Vendor specific version number.
969  * \return Zero on success, otherwise a negative error code
970  */
971 int snd_tplg_set_version(snd_tplg_t *tplg, unsigned int version);
972
973 /* \} */
974
975 #ifdef __cplusplus
976 }
977 #endif
978
979 #endif /* __ALSA_TOPOLOGY_H */