xref: /OK3568_Linux_fs/kernel/Documentation/driver-api/soundwire/stream.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun=========================
2*4882a593SmuzhiyunAudio Stream in SoundWire
3*4882a593Smuzhiyun=========================
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunAn audio stream is a logical or virtual connection created between
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun  (1) System memory buffer(s) and Codec(s)
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun  (2) DSP memory buffer(s) and Codec(s)
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun  (3) FIFO(s) and Codec(s)
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun  (4) Codec(s) and Codec(s)
14*4882a593Smuzhiyun
15*4882a593Smuzhiyunwhich is typically driven by a DMA(s) channel through the data link. An
16*4882a593Smuzhiyunaudio stream contains one or more channels of data. All channels within
17*4882a593Smuzhiyunstream must have same sample rate and same sample size.
18*4882a593Smuzhiyun
19*4882a593SmuzhiyunAssume a stream with two channels (Left & Right) is opened using SoundWire
20*4882a593Smuzhiyuninterface. Below are some ways a stream can be represented in SoundWire.
21*4882a593Smuzhiyun
22*4882a593SmuzhiyunStream Sample in memory (System memory, DSP memory or FIFOs) ::
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun	-------------------------
25*4882a593Smuzhiyun	| L | R | L | R | L | R |
26*4882a593Smuzhiyun	-------------------------
27*4882a593Smuzhiyun
28*4882a593SmuzhiyunExample 1: Stereo Stream with L and R channels is rendered from Master to
29*4882a593SmuzhiyunSlave. Both Master and Slave is using single port. ::
30*4882a593Smuzhiyun
31*4882a593Smuzhiyun	+---------------+                    Clock Signal  +---------------+
32*4882a593Smuzhiyun	|    Master     +----------------------------------+     Slave     |
33*4882a593Smuzhiyun	|   Interface   |                                  |   Interface   |
34*4882a593Smuzhiyun	|               |                                  |       1       |
35*4882a593Smuzhiyun	|               |                     Data Signal  |               |
36*4882a593Smuzhiyun	|    L  +  R    +----------------------------------+    L  +  R    |
37*4882a593Smuzhiyun	|     (Data)    |     Data Direction               |     (Data)    |
38*4882a593Smuzhiyun	+---------------+  +----------------------->       +---------------+
39*4882a593Smuzhiyun
40*4882a593Smuzhiyun
41*4882a593SmuzhiyunExample 2: Stereo Stream with L and R channels is captured from Slave to
42*4882a593SmuzhiyunMaster. Both Master and Slave is using single port. ::
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun
45*4882a593Smuzhiyun	+---------------+                    Clock Signal  +---------------+
46*4882a593Smuzhiyun	|    Master     +----------------------------------+     Slave     |
47*4882a593Smuzhiyun	|   Interface   |                                  |   Interface   |
48*4882a593Smuzhiyun	|               |                                  |       1       |
49*4882a593Smuzhiyun	|               |                     Data Signal  |               |
50*4882a593Smuzhiyun	|    L  +  R    +----------------------------------+    L  +  R    |
51*4882a593Smuzhiyun	|     (Data)    |     Data Direction               |     (Data)    |
52*4882a593Smuzhiyun	+---------------+  <-----------------------+       +---------------+
53*4882a593Smuzhiyun
54*4882a593Smuzhiyun
55*4882a593SmuzhiyunExample 3: Stereo Stream with L and R channels is rendered by Master. Each
56*4882a593Smuzhiyunof the L and R channel is received by two different Slaves. Master and both
57*4882a593SmuzhiyunSlaves are using single port. ::
58*4882a593Smuzhiyun
59*4882a593Smuzhiyun	+---------------+                    Clock Signal  +---------------+
60*4882a593Smuzhiyun	|    Master     +---------+------------------------+     Slave     |
61*4882a593Smuzhiyun	|   Interface   |         |                        |   Interface   |
62*4882a593Smuzhiyun	|               |         |                        |       1       |
63*4882a593Smuzhiyun	|               |         |           Data Signal  |               |
64*4882a593Smuzhiyun	|    L  +  R    +---+------------------------------+       L       |
65*4882a593Smuzhiyun	|     (Data)    |   |     |    Data Direction      |     (Data)    |
66*4882a593Smuzhiyun	+---------------+   |     |   +------------->      +---------------+
67*4882a593Smuzhiyun	                    |     |
68*4882a593Smuzhiyun	                    |     |
69*4882a593Smuzhiyun	                    |     |                        +---------------+
70*4882a593Smuzhiyun	                    |     +----------------------> |     Slave     |
71*4882a593Smuzhiyun	                    |                              |   Interface   |
72*4882a593Smuzhiyun	                    |                              |       2       |
73*4882a593Smuzhiyun	                    |                              |               |
74*4882a593Smuzhiyun	                    +----------------------------> |       R       |
75*4882a593Smuzhiyun	                                                   |     (Data)    |
76*4882a593Smuzhiyun	                                                   +---------------+
77*4882a593Smuzhiyun
78*4882a593SmuzhiyunExample 4: Stereo Stream with L and R channels is rendered by
79*4882a593SmuzhiyunMaster. Both of the L and R channels are received by two different
80*4882a593SmuzhiyunSlaves. Master and both Slaves are using single port handling
81*4882a593SmuzhiyunL+R. Each Slave device processes the L + R data locally, typically
82*4882a593Smuzhiyunbased on static configuration or dynamic orientation, and may drive
83*4882a593Smuzhiyunone or more speakers. ::
84*4882a593Smuzhiyun
85*4882a593Smuzhiyun	+---------------+                    Clock Signal  +---------------+
86*4882a593Smuzhiyun	|    Master     +---------+------------------------+     Slave     |
87*4882a593Smuzhiyun	|   Interface   |         |                        |   Interface   |
88*4882a593Smuzhiyun	|               |         |                        |       1       |
89*4882a593Smuzhiyun	|               |         |           Data Signal  |               |
90*4882a593Smuzhiyun	|    L  +  R    +---+------------------------------+     L + R     |
91*4882a593Smuzhiyun	|     (Data)    |   |     |    Data Direction      |     (Data)    |
92*4882a593Smuzhiyun	+---------------+   |     |   +------------->      +---------------+
93*4882a593Smuzhiyun	                    |     |
94*4882a593Smuzhiyun	                    |     |
95*4882a593Smuzhiyun	                    |     |                        +---------------+
96*4882a593Smuzhiyun	                    |     +----------------------> |     Slave     |
97*4882a593Smuzhiyun	                    |                              |   Interface   |
98*4882a593Smuzhiyun	                    |                              |       2       |
99*4882a593Smuzhiyun	                    |                              |               |
100*4882a593Smuzhiyun	                    +----------------------------> |     L + R     |
101*4882a593Smuzhiyun	                                                   |     (Data)    |
102*4882a593Smuzhiyun	                                                   +---------------+
103*4882a593Smuzhiyun
104*4882a593SmuzhiyunExample 5: Stereo Stream with L and R channel is rendered by two different
105*4882a593SmuzhiyunPorts of the Master and is received by only single Port of the Slave
106*4882a593Smuzhiyuninterface. ::
107*4882a593Smuzhiyun
108*4882a593Smuzhiyun	+--------------------+
109*4882a593Smuzhiyun	|                    |
110*4882a593Smuzhiyun	|     +--------------+                             +----------------+
111*4882a593Smuzhiyun	|     |             ||                             |                |
112*4882a593Smuzhiyun	|     |  Data Port  ||  L Channel                  |                |
113*4882a593Smuzhiyun	|     |      1      |------------+                 |                |
114*4882a593Smuzhiyun	|     |  L Channel  ||           |                 +-----+----+     |
115*4882a593Smuzhiyun	|     |   (Data)    ||           |   L + R Channel ||    Data |     |
116*4882a593Smuzhiyun	| Master  +----------+           | +---+---------> ||    Port |     |
117*4882a593Smuzhiyun	| Interface          |           |                 ||     1   |     |
118*4882a593Smuzhiyun	|     +--------------+           |                 ||         |     |
119*4882a593Smuzhiyun	|     |             ||           |                 +----------+     |
120*4882a593Smuzhiyun	|     |  Data Port  |------------+                 |                |
121*4882a593Smuzhiyun	|     |      2      ||  R Channel                  |     Slave      |
122*4882a593Smuzhiyun	|     |  R Channel  ||                             |   Interface    |
123*4882a593Smuzhiyun	|     |   (Data)    ||                             |       1        |
124*4882a593Smuzhiyun	|     +--------------+         Clock Signal        |     L  +  R    |
125*4882a593Smuzhiyun	|                    +---------------------------> |      (Data)    |
126*4882a593Smuzhiyun	+--------------------+                             |                |
127*4882a593Smuzhiyun							   +----------------+
128*4882a593Smuzhiyun
129*4882a593SmuzhiyunExample 6: Stereo Stream with L and R channel is rendered by 2 Masters, each
130*4882a593Smuzhiyunrendering one channel, and is received by two different Slaves, each
131*4882a593Smuzhiyunreceiving one channel. Both Masters and both Slaves are using single port. ::
132*4882a593Smuzhiyun
133*4882a593Smuzhiyun	+---------------+                    Clock Signal  +---------------+
134*4882a593Smuzhiyun	|    Master     +----------------------------------+     Slave     |
135*4882a593Smuzhiyun	|   Interface   |                                  |   Interface   |
136*4882a593Smuzhiyun	|       1       |                                  |       1       |
137*4882a593Smuzhiyun	|               |                     Data Signal  |               |
138*4882a593Smuzhiyun	|       L       +----------------------------------+       L       |
139*4882a593Smuzhiyun	|     (Data)    |     Data Direction               |     (Data)    |
140*4882a593Smuzhiyun	+---------------+  +----------------------->       +---------------+
141*4882a593Smuzhiyun
142*4882a593Smuzhiyun	+---------------+                    Clock Signal  +---------------+
143*4882a593Smuzhiyun	|    Master     +----------------------------------+     Slave     |
144*4882a593Smuzhiyun	|   Interface   |                                  |   Interface   |
145*4882a593Smuzhiyun	|       2       |                                  |       2       |
146*4882a593Smuzhiyun	|               |                     Data Signal  |               |
147*4882a593Smuzhiyun	|       R       +----------------------------------+       R       |
148*4882a593Smuzhiyun	|     (Data)    |     Data Direction               |     (Data)    |
149*4882a593Smuzhiyun	+---------------+  +----------------------->       +---------------+
150*4882a593Smuzhiyun
151*4882a593SmuzhiyunExample 7: Stereo Stream with L and R channel is rendered by 2
152*4882a593SmuzhiyunMasters, each rendering both channels. Each Slave receives L + R. This
153*4882a593Smuzhiyunis the same application as Example 4 but with Slaves placed on
154*4882a593Smuzhiyunseparate links. ::
155*4882a593Smuzhiyun
156*4882a593Smuzhiyun	+---------------+                    Clock Signal  +---------------+
157*4882a593Smuzhiyun	|    Master     +----------------------------------+     Slave     |
158*4882a593Smuzhiyun	|   Interface   |                                  |   Interface   |
159*4882a593Smuzhiyun	|       1       |                                  |       1       |
160*4882a593Smuzhiyun	|               |                     Data Signal  |               |
161*4882a593Smuzhiyun	|     L + R     +----------------------------------+     L + R     |
162*4882a593Smuzhiyun	|     (Data)    |     Data Direction               |     (Data)    |
163*4882a593Smuzhiyun	+---------------+  +----------------------->       +---------------+
164*4882a593Smuzhiyun
165*4882a593Smuzhiyun	+---------------+                    Clock Signal  +---------------+
166*4882a593Smuzhiyun	|    Master     +----------------------------------+     Slave     |
167*4882a593Smuzhiyun	|   Interface   |                                  |   Interface   |
168*4882a593Smuzhiyun	|       2       |                                  |       2       |
169*4882a593Smuzhiyun	|               |                     Data Signal  |               |
170*4882a593Smuzhiyun	|     L + R     +----------------------------------+     L + R     |
171*4882a593Smuzhiyun	|     (Data)    |     Data Direction               |     (Data)    |
172*4882a593Smuzhiyun	+---------------+  +----------------------->       +---------------+
173*4882a593Smuzhiyun
174*4882a593SmuzhiyunExample 8: 4-channel Stream is rendered by 2 Masters, each rendering a
175*4882a593Smuzhiyun2 channels. Each Slave receives 2 channels. ::
176*4882a593Smuzhiyun
177*4882a593Smuzhiyun	+---------------+                    Clock Signal  +---------------+
178*4882a593Smuzhiyun	|    Master     +----------------------------------+     Slave     |
179*4882a593Smuzhiyun	|   Interface   |                                  |   Interface   |
180*4882a593Smuzhiyun	|       1       |                                  |       1       |
181*4882a593Smuzhiyun	|               |                     Data Signal  |               |
182*4882a593Smuzhiyun	|    L1 + R1    +----------------------------------+    L1 + R1    |
183*4882a593Smuzhiyun	|     (Data)    |     Data Direction               |     (Data)    |
184*4882a593Smuzhiyun	+---------------+  +----------------------->       +---------------+
185*4882a593Smuzhiyun
186*4882a593Smuzhiyun	+---------------+                    Clock Signal  +---------------+
187*4882a593Smuzhiyun	|    Master     +----------------------------------+     Slave     |
188*4882a593Smuzhiyun	|   Interface   |                                  |   Interface   |
189*4882a593Smuzhiyun	|       2       |                                  |       2       |
190*4882a593Smuzhiyun	|               |                     Data Signal  |               |
191*4882a593Smuzhiyun	|     L2 + R2   +----------------------------------+    L2 + R2    |
192*4882a593Smuzhiyun	|     (Data)    |     Data Direction               |     (Data)    |
193*4882a593Smuzhiyun	+---------------+  +----------------------->       +---------------+
194*4882a593Smuzhiyun
195*4882a593SmuzhiyunNote1: In multi-link cases like above, to lock, one would acquire a global
196*4882a593Smuzhiyunlock and then go on locking bus instances. But, in this case the caller
197*4882a593Smuzhiyunframework(ASoC DPCM) guarantees that stream operations on a card are
198*4882a593Smuzhiyunalways serialized. So, there is no race condition and hence no need for
199*4882a593Smuzhiyunglobal lock.
200*4882a593Smuzhiyun
201*4882a593SmuzhiyunNote2: A Slave device may be configured to receive all channels
202*4882a593Smuzhiyuntransmitted on a link for a given Stream (Example 4) or just a subset
203*4882a593Smuzhiyunof the data (Example 3). The configuration of the Slave device is not
204*4882a593Smuzhiyunhandled by a SoundWire subsystem API, but instead by the
205*4882a593Smuzhiyunsnd_soc_dai_set_tdm_slot() API. The platform or machine driver will
206*4882a593Smuzhiyuntypically configure which of the slots are used. For Example 4, the
207*4882a593Smuzhiyunsame slots would be used by all Devices, while for Example 3 the Slave
208*4882a593SmuzhiyunDevice1 would use e.g. Slot 0 and Slave device2 slot 1.
209*4882a593Smuzhiyun
210*4882a593SmuzhiyunNote3: Multiple Sink ports can extract the same information for the
211*4882a593Smuzhiyunsame bitSlots in the SoundWire frame, however multiple Source ports
212*4882a593Smuzhiyunshall be configured with different bitSlot configurations. This is the
213*4882a593Smuzhiyunsame limitation as with I2S/PCM TDM usages.
214*4882a593Smuzhiyun
215*4882a593SmuzhiyunSoundWire Stream Management flow
216*4882a593Smuzhiyun================================
217*4882a593Smuzhiyun
218*4882a593SmuzhiyunStream definitions
219*4882a593Smuzhiyun------------------
220*4882a593Smuzhiyun
221*4882a593Smuzhiyun  (1) Current stream: This is classified as the stream on which operation has
222*4882a593Smuzhiyun      to be performed like prepare, enable, disable, de-prepare etc.
223*4882a593Smuzhiyun
224*4882a593Smuzhiyun  (2) Active stream: This is classified as the stream which is already active
225*4882a593Smuzhiyun      on Bus other than current stream. There can be multiple active streams
226*4882a593Smuzhiyun      on the Bus.
227*4882a593Smuzhiyun
228*4882a593SmuzhiyunSoundWire Bus manages stream operations for each stream getting
229*4882a593Smuzhiyunrendered/captured on the SoundWire Bus. This section explains Bus operations
230*4882a593Smuzhiyundone for each of the stream allocated/released on Bus. Following are the
231*4882a593Smuzhiyunstream states maintained by the Bus for each of the audio stream.
232*4882a593Smuzhiyun
233*4882a593Smuzhiyun
234*4882a593SmuzhiyunSoundWire stream states
235*4882a593Smuzhiyun-----------------------
236*4882a593Smuzhiyun
237*4882a593SmuzhiyunBelow shows the SoundWire stream states and state transition diagram. ::
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun	+-----------+     +------------+     +----------+     +----------+
240*4882a593Smuzhiyun	| ALLOCATED +---->| CONFIGURED +---->| PREPARED +---->| ENABLED  |
241*4882a593Smuzhiyun	|   STATE   |     |    STATE   |     |  STATE   |     |  STATE   |
242*4882a593Smuzhiyun	+-----------+     +------------+     +---+--+---+     +----+-----+
243*4882a593Smuzhiyun	                                         ^  ^              ^
244*4882a593Smuzhiyun				                 |  |              |
245*4882a593Smuzhiyun				               __|  |___________   |
246*4882a593Smuzhiyun				              |                 |  |
247*4882a593Smuzhiyun	                                      v                 |  v
248*4882a593Smuzhiyun	         +----------+           +-----+------+        +-+--+-----+
249*4882a593Smuzhiyun	         | RELEASED |<----------+ DEPREPARED |<-------+ DISABLED |
250*4882a593Smuzhiyun	         |  STATE   |           |   STATE    |        |  STATE   |
251*4882a593Smuzhiyun	         +----------+           +------------+        +----------+
252*4882a593Smuzhiyun
253*4882a593SmuzhiyunNOTE: State transitions between ``SDW_STREAM_ENABLED`` and
254*4882a593Smuzhiyun``SDW_STREAM_DISABLED`` are only relevant when then INFO_PAUSE flag is
255*4882a593Smuzhiyunsupported at the ALSA/ASoC level. Likewise the transition between
256*4882a593Smuzhiyun``SDW_DISABLED_STATE`` and ``SDW_PREPARED_STATE`` depends on the
257*4882a593SmuzhiyunINFO_RESUME flag.
258*4882a593Smuzhiyun
259*4882a593SmuzhiyunNOTE2: The framework implements basic state transition checks, but
260*4882a593Smuzhiyundoes not e.g. check if a transition from DISABLED to ENABLED is valid
261*4882a593Smuzhiyunon a specific platform. Such tests need to be added at the ALSA/ASoC
262*4882a593Smuzhiyunlevel.
263*4882a593Smuzhiyun
264*4882a593SmuzhiyunStream State Operations
265*4882a593Smuzhiyun-----------------------
266*4882a593Smuzhiyun
267*4882a593SmuzhiyunBelow section explains the operations done by the Bus on Master(s) and
268*4882a593SmuzhiyunSlave(s) as part of stream state transitions.
269*4882a593Smuzhiyun
270*4882a593SmuzhiyunSDW_STREAM_ALLOCATED
271*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~
272*4882a593Smuzhiyun
273*4882a593SmuzhiyunAllocation state for stream. This is the entry state
274*4882a593Smuzhiyunof the stream. Operations performed before entering in this state:
275*4882a593Smuzhiyun
276*4882a593Smuzhiyun  (1) A stream runtime is allocated for the stream. This stream
277*4882a593Smuzhiyun      runtime is used as a reference for all the operations performed
278*4882a593Smuzhiyun      on the stream.
279*4882a593Smuzhiyun
280*4882a593Smuzhiyun  (2) The resources required for holding stream runtime information are
281*4882a593Smuzhiyun      allocated and initialized. This holds all stream related information
282*4882a593Smuzhiyun      such as stream type (PCM/PDM) and parameters, Master and Slave
283*4882a593Smuzhiyun      interface associated with the stream, stream state etc.
284*4882a593Smuzhiyun
285*4882a593SmuzhiyunAfter all above operations are successful, stream state is set to
286*4882a593Smuzhiyun``SDW_STREAM_ALLOCATED``.
287*4882a593Smuzhiyun
288*4882a593SmuzhiyunBus implements below API for allocate a stream which needs to be called once
289*4882a593Smuzhiyunper stream. From ASoC DPCM framework, this stream state maybe linked to
290*4882a593Smuzhiyun.startup() operation.
291*4882a593Smuzhiyun
292*4882a593Smuzhiyun.. code-block:: c
293*4882a593Smuzhiyun
294*4882a593Smuzhiyun  int sdw_alloc_stream(char * stream_name);
295*4882a593Smuzhiyun
296*4882a593SmuzhiyunThe SoundWire core provides a sdw_startup_stream() helper function,
297*4882a593Smuzhiyuntypically called during a dailink .startup() callback, which performs
298*4882a593Smuzhiyunstream allocation and sets the stream pointer for all DAIs
299*4882a593Smuzhiyunconnected to a stream.
300*4882a593Smuzhiyun
301*4882a593SmuzhiyunSDW_STREAM_CONFIGURED
302*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~
303*4882a593Smuzhiyun
304*4882a593SmuzhiyunConfiguration state of stream. Operations performed before entering in
305*4882a593Smuzhiyunthis state:
306*4882a593Smuzhiyun
307*4882a593Smuzhiyun  (1) The resources allocated for stream information in SDW_STREAM_ALLOCATED
308*4882a593Smuzhiyun      state are updated here. This includes stream parameters, Master(s)
309*4882a593Smuzhiyun      and Slave(s) runtime information associated with current stream.
310*4882a593Smuzhiyun
311*4882a593Smuzhiyun  (2) All the Master(s) and Slave(s) associated with current stream provide
312*4882a593Smuzhiyun      the port information to Bus which includes port numbers allocated by
313*4882a593Smuzhiyun      Master(s) and Slave(s) for current stream and their channel mask.
314*4882a593Smuzhiyun
315*4882a593SmuzhiyunAfter all above operations are successful, stream state is set to
316*4882a593Smuzhiyun``SDW_STREAM_CONFIGURED``.
317*4882a593Smuzhiyun
318*4882a593SmuzhiyunBus implements below APIs for CONFIG state which needs to be called by
319*4882a593Smuzhiyunthe respective Master(s) and Slave(s) associated with stream. These APIs can
320*4882a593Smuzhiyunonly be invoked once by respective Master(s) and Slave(s). From ASoC DPCM
321*4882a593Smuzhiyunframework, this stream state is linked to .hw_params() operation.
322*4882a593Smuzhiyun
323*4882a593Smuzhiyun.. code-block:: c
324*4882a593Smuzhiyun
325*4882a593Smuzhiyun  int sdw_stream_add_master(struct sdw_bus * bus,
326*4882a593Smuzhiyun		struct sdw_stream_config * stream_config,
327*4882a593Smuzhiyun		struct sdw_ports_config * ports_config,
328*4882a593Smuzhiyun		struct sdw_stream_runtime * stream);
329*4882a593Smuzhiyun
330*4882a593Smuzhiyun  int sdw_stream_add_slave(struct sdw_slave * slave,
331*4882a593Smuzhiyun		struct sdw_stream_config * stream_config,
332*4882a593Smuzhiyun		struct sdw_ports_config * ports_config,
333*4882a593Smuzhiyun		struct sdw_stream_runtime * stream);
334*4882a593Smuzhiyun
335*4882a593Smuzhiyun
336*4882a593SmuzhiyunSDW_STREAM_PREPARED
337*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~
338*4882a593Smuzhiyun
339*4882a593SmuzhiyunPrepare state of stream. Operations performed before entering in this state:
340*4882a593Smuzhiyun
341*4882a593Smuzhiyun  (0) Steps 1 and 2 are omitted in the case of a resume operation,
342*4882a593Smuzhiyun      where the bus bandwidth is known.
343*4882a593Smuzhiyun
344*4882a593Smuzhiyun  (1) Bus parameters such as bandwidth, frame shape, clock frequency,
345*4882a593Smuzhiyun      are computed based on current stream as well as already active
346*4882a593Smuzhiyun      stream(s) on Bus. Re-computation is required to accommodate current
347*4882a593Smuzhiyun      stream on the Bus.
348*4882a593Smuzhiyun
349*4882a593Smuzhiyun  (2) Transport and port parameters of all Master(s) and Slave(s) port(s) are
350*4882a593Smuzhiyun      computed for the current as well as already active stream based on frame
351*4882a593Smuzhiyun      shape and clock frequency computed in step 1.
352*4882a593Smuzhiyun
353*4882a593Smuzhiyun  (3) Computed Bus and transport parameters are programmed in Master(s) and
354*4882a593Smuzhiyun      Slave(s) registers. The banked registers programming is done on the
355*4882a593Smuzhiyun      alternate bank (bank currently unused). Port(s) are enabled for the
356*4882a593Smuzhiyun      already active stream(s) on the alternate bank (bank currently unused).
357*4882a593Smuzhiyun      This is done in order to not disrupt already active stream(s).
358*4882a593Smuzhiyun
359*4882a593Smuzhiyun  (4) Once all the values are programmed, Bus initiates switch to alternate
360*4882a593Smuzhiyun      bank where all new values programmed gets into effect.
361*4882a593Smuzhiyun
362*4882a593Smuzhiyun  (5) Ports of Master(s) and Slave(s) for current stream are prepared by
363*4882a593Smuzhiyun      programming PrepareCtrl register.
364*4882a593Smuzhiyun
365*4882a593SmuzhiyunAfter all above operations are successful, stream state is set to
366*4882a593Smuzhiyun``SDW_STREAM_PREPARED``.
367*4882a593Smuzhiyun
368*4882a593SmuzhiyunBus implements below API for PREPARE state which needs to be called
369*4882a593Smuzhiyunonce per stream. From ASoC DPCM framework, this stream state is linked
370*4882a593Smuzhiyunto .prepare() operation. Since the .trigger() operations may not
371*4882a593Smuzhiyunfollow the .prepare(), a direct transition from
372*4882a593Smuzhiyun``SDW_STREAM_PREPARED`` to ``SDW_STREAM_DEPREPARED`` is allowed.
373*4882a593Smuzhiyun
374*4882a593Smuzhiyun.. code-block:: c
375*4882a593Smuzhiyun
376*4882a593Smuzhiyun  int sdw_prepare_stream(struct sdw_stream_runtime * stream);
377*4882a593Smuzhiyun
378*4882a593Smuzhiyun
379*4882a593SmuzhiyunSDW_STREAM_ENABLED
380*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~
381*4882a593Smuzhiyun
382*4882a593SmuzhiyunEnable state of stream. The data port(s) are enabled upon entering this state.
383*4882a593SmuzhiyunOperations performed before entering in this state:
384*4882a593Smuzhiyun
385*4882a593Smuzhiyun  (1) All the values computed in SDW_STREAM_PREPARED state are programmed
386*4882a593Smuzhiyun      in alternate bank (bank currently unused). It includes programming of
387*4882a593Smuzhiyun      already active stream(s) as well.
388*4882a593Smuzhiyun
389*4882a593Smuzhiyun  (2) All the Master(s) and Slave(s) port(s) for the current stream are
390*4882a593Smuzhiyun      enabled on alternate bank (bank currently unused) by programming
391*4882a593Smuzhiyun      ChannelEn register.
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun  (3) Once all the values are programmed, Bus initiates switch to alternate
394*4882a593Smuzhiyun      bank where all new values programmed gets into effect and port(s)
395*4882a593Smuzhiyun      associated with current stream are enabled.
396*4882a593Smuzhiyun
397*4882a593SmuzhiyunAfter all above operations are successful, stream state is set to
398*4882a593Smuzhiyun``SDW_STREAM_ENABLED``.
399*4882a593Smuzhiyun
400*4882a593SmuzhiyunBus implements below API for ENABLE state which needs to be called once per
401*4882a593Smuzhiyunstream. From ASoC DPCM framework, this stream state is linked to
402*4882a593Smuzhiyun.trigger() start operation.
403*4882a593Smuzhiyun
404*4882a593Smuzhiyun.. code-block:: c
405*4882a593Smuzhiyun
406*4882a593Smuzhiyun  int sdw_enable_stream(struct sdw_stream_runtime * stream);
407*4882a593Smuzhiyun
408*4882a593SmuzhiyunSDW_STREAM_DISABLED
409*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~
410*4882a593Smuzhiyun
411*4882a593SmuzhiyunDisable state of stream. The data port(s) are disabled upon exiting this state.
412*4882a593SmuzhiyunOperations performed before entering in this state:
413*4882a593Smuzhiyun
414*4882a593Smuzhiyun  (1) All the Master(s) and Slave(s) port(s) for the current stream are
415*4882a593Smuzhiyun      disabled on alternate bank (bank currently unused) by programming
416*4882a593Smuzhiyun      ChannelEn register.
417*4882a593Smuzhiyun
418*4882a593Smuzhiyun  (2) All the current configuration of Bus and active stream(s) are programmed
419*4882a593Smuzhiyun      into alternate bank (bank currently unused).
420*4882a593Smuzhiyun
421*4882a593Smuzhiyun  (3) Once all the values are programmed, Bus initiates switch to alternate
422*4882a593Smuzhiyun      bank where all new values programmed gets into effect and port(s) associated
423*4882a593Smuzhiyun      with current stream are disabled.
424*4882a593Smuzhiyun
425*4882a593SmuzhiyunAfter all above operations are successful, stream state is set to
426*4882a593Smuzhiyun``SDW_STREAM_DISABLED``.
427*4882a593Smuzhiyun
428*4882a593SmuzhiyunBus implements below API for DISABLED state which needs to be called once
429*4882a593Smuzhiyunper stream. From ASoC DPCM framework, this stream state is linked to
430*4882a593Smuzhiyun.trigger() stop operation.
431*4882a593Smuzhiyun
432*4882a593SmuzhiyunWhen the INFO_PAUSE flag is supported, a direct transition to
433*4882a593Smuzhiyun``SDW_STREAM_ENABLED`` is allowed.
434*4882a593Smuzhiyun
435*4882a593SmuzhiyunFor resume operations where ASoC will use the .prepare() callback, the
436*4882a593Smuzhiyunstream can transition from ``SDW_STREAM_DISABLED`` to
437*4882a593Smuzhiyun``SDW_STREAM_PREPARED``, with all required settings restored but
438*4882a593Smuzhiyunwithout updating the bandwidth and bit allocation.
439*4882a593Smuzhiyun
440*4882a593Smuzhiyun.. code-block:: c
441*4882a593Smuzhiyun
442*4882a593Smuzhiyun  int sdw_disable_stream(struct sdw_stream_runtime * stream);
443*4882a593Smuzhiyun
444*4882a593Smuzhiyun
445*4882a593SmuzhiyunSDW_STREAM_DEPREPARED
446*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~~~
447*4882a593Smuzhiyun
448*4882a593SmuzhiyunDe-prepare state of stream. Operations performed before entering in this
449*4882a593Smuzhiyunstate:
450*4882a593Smuzhiyun
451*4882a593Smuzhiyun  (1) All the port(s) of Master(s) and Slave(s) for current stream are
452*4882a593Smuzhiyun      de-prepared by programming PrepareCtrl register.
453*4882a593Smuzhiyun
454*4882a593Smuzhiyun  (2) The payload bandwidth of current stream is reduced from the total
455*4882a593Smuzhiyun      bandwidth requirement of bus and new parameters calculated and
456*4882a593Smuzhiyun      applied by performing bank switch etc.
457*4882a593Smuzhiyun
458*4882a593SmuzhiyunAfter all above operations are successful, stream state is set to
459*4882a593Smuzhiyun``SDW_STREAM_DEPREPARED``.
460*4882a593Smuzhiyun
461*4882a593SmuzhiyunBus implements below API for DEPREPARED state which needs to be called
462*4882a593Smuzhiyunonce per stream. ALSA/ASoC do not have a concept of 'deprepare', and
463*4882a593Smuzhiyunthe mapping from this stream state to ALSA/ASoC operation may be
464*4882a593Smuzhiyunimplementation specific.
465*4882a593Smuzhiyun
466*4882a593SmuzhiyunWhen the INFO_PAUSE flag is supported, the stream state is linked to
467*4882a593Smuzhiyunthe .hw_free() operation - the stream is not deprepared on a
468*4882a593SmuzhiyunTRIGGER_STOP.
469*4882a593Smuzhiyun
470*4882a593SmuzhiyunOther implementations may transition to the ``SDW_STREAM_DEPREPARED``
471*4882a593Smuzhiyunstate on TRIGGER_STOP, should they require a transition through the
472*4882a593Smuzhiyun``SDW_STREAM_PREPARED`` state.
473*4882a593Smuzhiyun
474*4882a593Smuzhiyun.. code-block:: c
475*4882a593Smuzhiyun
476*4882a593Smuzhiyun  int sdw_deprepare_stream(struct sdw_stream_runtime * stream);
477*4882a593Smuzhiyun
478*4882a593Smuzhiyun
479*4882a593SmuzhiyunSDW_STREAM_RELEASED
480*4882a593Smuzhiyun~~~~~~~~~~~~~~~~~~~
481*4882a593Smuzhiyun
482*4882a593SmuzhiyunRelease state of stream. Operations performed before entering in this state:
483*4882a593Smuzhiyun
484*4882a593Smuzhiyun  (1) Release port resources for all Master(s) and Slave(s) port(s)
485*4882a593Smuzhiyun      associated with current stream.
486*4882a593Smuzhiyun
487*4882a593Smuzhiyun  (2) Release Master(s) and Slave(s) runtime resources associated with
488*4882a593Smuzhiyun      current stream.
489*4882a593Smuzhiyun
490*4882a593Smuzhiyun  (3) Release stream runtime resources associated with current stream.
491*4882a593Smuzhiyun
492*4882a593SmuzhiyunAfter all above operations are successful, stream state is set to
493*4882a593Smuzhiyun``SDW_STREAM_RELEASED``.
494*4882a593Smuzhiyun
495*4882a593SmuzhiyunBus implements below APIs for RELEASE state which needs to be called by
496*4882a593Smuzhiyunall the Master(s) and Slave(s) associated with stream. From ASoC DPCM
497*4882a593Smuzhiyunframework, this stream state is linked to .hw_free() operation.
498*4882a593Smuzhiyun
499*4882a593Smuzhiyun.. code-block:: c
500*4882a593Smuzhiyun
501*4882a593Smuzhiyun  int sdw_stream_remove_master(struct sdw_bus * bus,
502*4882a593Smuzhiyun		struct sdw_stream_runtime * stream);
503*4882a593Smuzhiyun  int sdw_stream_remove_slave(struct sdw_slave * slave,
504*4882a593Smuzhiyun		struct sdw_stream_runtime * stream);
505*4882a593Smuzhiyun
506*4882a593Smuzhiyun
507*4882a593SmuzhiyunThe .shutdown() ASoC DPCM operation calls below Bus API to release
508*4882a593Smuzhiyunstream assigned as part of ALLOCATED state.
509*4882a593Smuzhiyun
510*4882a593SmuzhiyunIn .shutdown() the data structure maintaining stream state are freed up.
511*4882a593Smuzhiyun
512*4882a593Smuzhiyun.. code-block:: c
513*4882a593Smuzhiyun
514*4882a593Smuzhiyun  void sdw_release_stream(struct sdw_stream_runtime * stream);
515*4882a593Smuzhiyun
516*4882a593SmuzhiyunThe SoundWire core provides a sdw_shutdown_stream() helper function,
517*4882a593Smuzhiyuntypically called during a dailink .shutdown() callback, which clears
518*4882a593Smuzhiyunthe stream pointer for all DAIS connected to a stream and releases the
519*4882a593Smuzhiyunmemory allocated for the stream.
520*4882a593Smuzhiyun
521*4882a593SmuzhiyunNot Supported
522*4882a593Smuzhiyun=============
523*4882a593Smuzhiyun
524*4882a593Smuzhiyun1. A single port with multiple channels supported cannot be used between two
525*4882a593Smuzhiyun   streams or across stream. For example a port with 4 channels cannot be used
526*4882a593Smuzhiyun   to handle 2 independent stereo streams even though it's possible in theory
527*4882a593Smuzhiyun   in SoundWire.
528