topology.h 33 KB

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