stream.rst 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  1. =========================
  2. Audio Stream in SoundWire
  3. =========================
  4. An audio stream is a logical or virtual connection created between
  5. (1) System memory buffer(s) and Codec(s)
  6. (2) DSP memory buffer(s) and Codec(s)
  7. (3) FIFO(s) and Codec(s)
  8. (4) Codec(s) and Codec(s)
  9. which is typically driven by a DMA(s) channel through the data link. An
  10. audio stream contains one or more channels of data. All channels within
  11. stream must have same sample rate and same sample size.
  12. Assume a stream with two channels (Left & Right) is opened using SoundWire
  13. interface. Below are some ways a stream can be represented in SoundWire.
  14. Stream Sample in memory (System memory, DSP memory or FIFOs) ::
  15. -------------------------
  16. | L | R | L | R | L | R |
  17. -------------------------
  18. Example 1: Stereo Stream with L and R channels is rendered from Master to
  19. Slave. Both Master and Slave is using single port. ::
  20. +---------------+ Clock Signal +---------------+
  21. | Master +----------------------------------+ Slave |
  22. | Interface | | Interface |
  23. | | | 1 |
  24. | | Data Signal | |
  25. | L + R +----------------------------------+ L + R |
  26. | (Data) | Data Direction | (Data) |
  27. +---------------+ +-----------------------> +---------------+
  28. Example 2: Stereo Stream with L and R channels is captured from Slave to
  29. Master. Both Master and Slave is using single port. ::
  30. +---------------+ Clock Signal +---------------+
  31. | Master +----------------------------------+ Slave |
  32. | Interface | | Interface |
  33. | | | 1 |
  34. | | Data Signal | |
  35. | L + R +----------------------------------+ L + R |
  36. | (Data) | Data Direction | (Data) |
  37. +---------------+ <-----------------------+ +---------------+
  38. Example 3: Stereo Stream with L and R channels is rendered by Master. Each
  39. of the L and R channel is received by two different Slaves. Master and both
  40. Slaves are using single port. ::
  41. +---------------+ Clock Signal +---------------+
  42. | Master +---------+------------------------+ Slave |
  43. | Interface | | | Interface |
  44. | | | | 1 |
  45. | | | Data Signal | |
  46. | L + R +---+------------------------------+ L |
  47. | (Data) | | | Data Direction | (Data) |
  48. +---------------+ | | +-------------> +---------------+
  49. | |
  50. | |
  51. | | +---------------+
  52. | +----------------------> | Slave |
  53. | | Interface |
  54. | | 2 |
  55. | | |
  56. +----------------------------> | R |
  57. | (Data) |
  58. +---------------+
  59. Example 4: Stereo Stream with L and R channel is rendered by two different
  60. Ports of the Master and is received by only single Port of the Slave
  61. interface. ::
  62. +--------------------+
  63. | |
  64. | +--------------+ +----------------+
  65. | | || | |
  66. | | Data Port || L Channel | |
  67. | | 1 |------------+ | |
  68. | | L Channel || | +-----+----+ |
  69. | | (Data) || | L + R Channel || Data | |
  70. | Master +----------+ | +---+---------> || Port | |
  71. | Interface | | || 1 | |
  72. | +--------------+ | || | |
  73. | | || | +----------+ |
  74. | | Data Port |------------+ | |
  75. | | 2 || R Channel | Slave |
  76. | | R Channel || | Interface |
  77. | | (Data) || | 1 |
  78. | +--------------+ Clock Signal | L + R |
  79. | +---------------------------> | (Data) |
  80. +--------------------+ | |
  81. +----------------+
  82. SoundWire Stream Management flow
  83. ================================
  84. Stream definitions
  85. ------------------
  86. (1) Current stream: This is classified as the stream on which operation has
  87. to be performed like prepare, enable, disable, de-prepare etc.
  88. (2) Active stream: This is classified as the stream which is already active
  89. on Bus other than current stream. There can be multiple active streams
  90. on the Bus.
  91. SoundWire Bus manages stream operations for each stream getting
  92. rendered/captured on the SoundWire Bus. This section explains Bus operations
  93. done for each of the stream allocated/released on Bus. Following are the
  94. stream states maintained by the Bus for each of the audio stream.
  95. SoundWire stream states
  96. -----------------------
  97. Below shows the SoundWire stream states and state transition diagram. ::
  98. +-----------+ +------------+ +----------+ +----------+
  99. | ALLOCATED +---->| CONFIGURED +---->| PREPARED +---->| ENABLED |
  100. | STATE | | STATE | | STATE | | STATE |
  101. +-----------+ +------------+ +----------+ +----+-----+
  102. ^
  103. |
  104. |
  105. v
  106. +----------+ +------------+ +----+-----+
  107. | RELEASED |<----------+ DEPREPARED |<-------+ DISABLED |
  108. | STATE | | STATE | | STATE |
  109. +----------+ +------------+ +----------+
  110. NOTE: State transition between prepare and deprepare is supported in Spec
  111. but not in the software (subsystem)
  112. NOTE2: Stream state transition checks need to be handled by caller
  113. framework, for example ALSA/ASoC. No checks for stream transition exist in
  114. SoundWire subsystem.
  115. Stream State Operations
  116. -----------------------
  117. Below section explains the operations done by the Bus on Master(s) and
  118. Slave(s) as part of stream state transitions.
  119. SDW_STREAM_ALLOCATED
  120. ~~~~~~~~~~~~~~~~~~~~
  121. Allocation state for stream. This is the entry state
  122. of the stream. Operations performed before entering in this state:
  123. (1) A stream runtime is allocated for the stream. This stream
  124. runtime is used as a reference for all the operations performed
  125. on the stream.
  126. (2) The resources required for holding stream runtime information are
  127. allocated and initialized. This holds all stream related information
  128. such as stream type (PCM/PDM) and parameters, Master and Slave
  129. interface associated with the stream, stream state etc.
  130. After all above operations are successful, stream state is set to
  131. ``SDW_STREAM_ALLOCATED``.
  132. Bus implements below API for allocate a stream which needs to be called once
  133. per stream. From ASoC DPCM framework, this stream state maybe linked to
  134. .startup() operation.
  135. .. code-block:: c
  136. int sdw_alloc_stream(char * stream_name);
  137. SDW_STREAM_CONFIGURED
  138. ~~~~~~~~~~~~~~~~~~~~~
  139. Configuration state of stream. Operations performed before entering in
  140. this state:
  141. (1) The resources allocated for stream information in SDW_STREAM_ALLOCATED
  142. state are updated here. This includes stream parameters, Master(s)
  143. and Slave(s) runtime information associated with current stream.
  144. (2) All the Master(s) and Slave(s) associated with current stream provide
  145. the port information to Bus which includes port numbers allocated by
  146. Master(s) and Slave(s) for current stream and their channel mask.
  147. After all above operations are successful, stream state is set to
  148. ``SDW_STREAM_CONFIGURED``.
  149. Bus implements below APIs for CONFIG state which needs to be called by
  150. the respective Master(s) and Slave(s) associated with stream. These APIs can
  151. only be invoked once by respective Master(s) and Slave(s). From ASoC DPCM
  152. framework, this stream state is linked to .hw_params() operation.
  153. .. code-block:: c
  154. int sdw_stream_add_master(struct sdw_bus * bus,
  155. struct sdw_stream_config * stream_config,
  156. struct sdw_ports_config * ports_config,
  157. struct sdw_stream_runtime * stream);
  158. int sdw_stream_add_slave(struct sdw_slave * slave,
  159. struct sdw_stream_config * stream_config,
  160. struct sdw_ports_config * ports_config,
  161. struct sdw_stream_runtime * stream);
  162. SDW_STREAM_PREPARED
  163. ~~~~~~~~~~~~~~~~~~~
  164. Prepare state of stream. Operations performed before entering in this state:
  165. (1) Bus parameters such as bandwidth, frame shape, clock frequency,
  166. are computed based on current stream as well as already active
  167. stream(s) on Bus. Re-computation is required to accommodate current
  168. stream on the Bus.
  169. (2) Transport and port parameters of all Master(s) and Slave(s) port(s) are
  170. computed for the current as well as already active stream based on frame
  171. shape and clock frequency computed in step 1.
  172. (3) Computed Bus and transport parameters are programmed in Master(s) and
  173. Slave(s) registers. The banked registers programming is done on the
  174. alternate bank (bank currently unused). Port(s) are enabled for the
  175. already active stream(s) on the alternate bank (bank currently unused).
  176. This is done in order to not disrupt already active stream(s).
  177. (4) Once all the values are programmed, Bus initiates switch to alternate
  178. bank where all new values programmed gets into effect.
  179. (5) Ports of Master(s) and Slave(s) for current stream are prepared by
  180. programming PrepareCtrl register.
  181. After all above operations are successful, stream state is set to
  182. ``SDW_STREAM_PREPARED``.
  183. Bus implements below API for PREPARE state which needs to be called once per
  184. stream. From ASoC DPCM framework, this stream state is linked to
  185. .prepare() operation.
  186. .. code-block:: c
  187. int sdw_prepare_stream(struct sdw_stream_runtime * stream);
  188. SDW_STREAM_ENABLED
  189. ~~~~~~~~~~~~~~~~~~
  190. Enable state of stream. The data port(s) are enabled upon entering this state.
  191. Operations performed before entering in this state:
  192. (1) All the values computed in SDW_STREAM_PREPARED state are programmed
  193. in alternate bank (bank currently unused). It includes programming of
  194. already active stream(s) as well.
  195. (2) All the Master(s) and Slave(s) port(s) for the current stream are
  196. enabled on alternate bank (bank currently unused) by programming
  197. ChannelEn register.
  198. (3) Once all the values are programmed, Bus initiates switch to alternate
  199. bank where all new values programmed gets into effect and port(s)
  200. associated with current stream are enabled.
  201. After all above operations are successful, stream state is set to
  202. ``SDW_STREAM_ENABLED``.
  203. Bus implements below API for ENABLE state which needs to be called once per
  204. stream. From ASoC DPCM framework, this stream state is linked to
  205. .trigger() start operation.
  206. .. code-block:: c
  207. int sdw_enable_stream(struct sdw_stream_runtime * stream);
  208. SDW_STREAM_DISABLED
  209. ~~~~~~~~~~~~~~~~~~~
  210. Disable state of stream. The data port(s) are disabled upon exiting this state.
  211. Operations performed before entering in this state:
  212. (1) All the Master(s) and Slave(s) port(s) for the current stream are
  213. disabled on alternate bank (bank currently unused) by programming
  214. ChannelEn register.
  215. (2) All the current configuration of Bus and active stream(s) are programmed
  216. into alternate bank (bank currently unused).
  217. (3) Once all the values are programmed, Bus initiates switch to alternate
  218. bank where all new values programmed gets into effect and port(s) associated
  219. with current stream are disabled.
  220. After all above operations are successful, stream state is set to
  221. ``SDW_STREAM_DISABLED``.
  222. Bus implements below API for DISABLED state which needs to be called once
  223. per stream. From ASoC DPCM framework, this stream state is linked to
  224. .trigger() stop operation.
  225. .. code-block:: c
  226. int sdw_disable_stream(struct sdw_stream_runtime * stream);
  227. SDW_STREAM_DEPREPARED
  228. ~~~~~~~~~~~~~~~~~~~~~
  229. De-prepare state of stream. Operations performed before entering in this
  230. state:
  231. (1) All the port(s) of Master(s) and Slave(s) for current stream are
  232. de-prepared by programming PrepareCtrl register.
  233. (2) The payload bandwidth of current stream is reduced from the total
  234. bandwidth requirement of bus and new parameters calculated and
  235. applied by performing bank switch etc.
  236. After all above operations are successful, stream state is set to
  237. ``SDW_STREAM_DEPREPARED``.
  238. Bus implements below API for DEPREPARED state which needs to be called once
  239. per stream. From ASoC DPCM framework, this stream state is linked to
  240. .trigger() stop operation.
  241. .. code-block:: c
  242. int sdw_deprepare_stream(struct sdw_stream_runtime * stream);
  243. SDW_STREAM_RELEASED
  244. ~~~~~~~~~~~~~~~~~~~
  245. Release state of stream. Operations performed before entering in this state:
  246. (1) Release port resources for all Master(s) and Slave(s) port(s)
  247. associated with current stream.
  248. (2) Release Master(s) and Slave(s) runtime resources associated with
  249. current stream.
  250. (3) Release stream runtime resources associated with current stream.
  251. After all above operations are successful, stream state is set to
  252. ``SDW_STREAM_RELEASED``.
  253. Bus implements below APIs for RELEASE state which needs to be called by
  254. all the Master(s) and Slave(s) associated with stream. From ASoC DPCM
  255. framework, this stream state is linked to .hw_free() operation.
  256. .. code-block:: c
  257. int sdw_stream_remove_master(struct sdw_bus * bus,
  258. struct sdw_stream_runtime * stream);
  259. int sdw_stream_remove_slave(struct sdw_slave * slave,
  260. struct sdw_stream_runtime * stream);
  261. The .shutdown() ASoC DPCM operation calls below Bus API to release
  262. stream assigned as part of ALLOCATED state.
  263. In .shutdown() the data structure maintaining stream state are freed up.
  264. .. code-block:: c
  265. void sdw_release_stream(struct sdw_stream_runtime * stream);
  266. Not Supported
  267. =============
  268. 1. A single port with multiple channels supported cannot be used between two
  269. streams or across stream. For example a port with 4 channels cannot be used
  270. to handle 2 independent stereo streams even though it's possible in theory
  271. in SoundWire.