topology.h 27 KB

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