189634f99SSanyog Kale========================= 289634f99SSanyog KaleAudio Stream in SoundWire 389634f99SSanyog Kale========================= 489634f99SSanyog Kale 589634f99SSanyog KaleAn audio stream is a logical or virtual connection created between 689634f99SSanyog Kale 789634f99SSanyog Kale (1) System memory buffer(s) and Codec(s) 889634f99SSanyog Kale 989634f99SSanyog Kale (2) DSP memory buffer(s) and Codec(s) 1089634f99SSanyog Kale 1189634f99SSanyog Kale (3) FIFO(s) and Codec(s) 1289634f99SSanyog Kale 1389634f99SSanyog Kale (4) Codec(s) and Codec(s) 1489634f99SSanyog Kale 1589634f99SSanyog Kalewhich is typically driven by a DMA(s) channel through the data link. An 1689634f99SSanyog Kaleaudio stream contains one or more channels of data. All channels within 1789634f99SSanyog Kalestream must have same sample rate and same sample size. 1889634f99SSanyog Kale 1989634f99SSanyog KaleAssume a stream with two channels (Left & Right) is opened using SoundWire 2089634f99SSanyog Kaleinterface. Below are some ways a stream can be represented in SoundWire. 2189634f99SSanyog Kale 2289634f99SSanyog KaleStream Sample in memory (System memory, DSP memory or FIFOs) :: 2389634f99SSanyog Kale 2489634f99SSanyog Kale ------------------------- 2589634f99SSanyog Kale | L | R | L | R | L | R | 2689634f99SSanyog Kale ------------------------- 2789634f99SSanyog Kale 2889634f99SSanyog KaleExample 1: Stereo Stream with L and R channels is rendered from Master to 2989634f99SSanyog KaleSlave. Both Master and Slave is using single port. :: 3089634f99SSanyog Kale 3189634f99SSanyog Kale +---------------+ Clock Signal +---------------+ 3289634f99SSanyog Kale | Master +----------------------------------+ Slave | 3389634f99SSanyog Kale | Interface | | Interface | 3489634f99SSanyog Kale | | | 1 | 3589634f99SSanyog Kale | | Data Signal | | 3689634f99SSanyog Kale | L + R +----------------------------------+ L + R | 3789634f99SSanyog Kale | (Data) | Data Direction | (Data) | 3889634f99SSanyog Kale +---------------+ +-----------------------> +---------------+ 3989634f99SSanyog Kale 4089634f99SSanyog Kale 4189634f99SSanyog KaleExample 2: Stereo Stream with L and R channels is captured from Slave to 4289634f99SSanyog KaleMaster. Both Master and Slave is using single port. :: 4389634f99SSanyog Kale 4489634f99SSanyog Kale 4589634f99SSanyog Kale +---------------+ Clock Signal +---------------+ 4689634f99SSanyog Kale | Master +----------------------------------+ Slave | 4789634f99SSanyog Kale | Interface | | Interface | 4889634f99SSanyog Kale | | | 1 | 4989634f99SSanyog Kale | | Data Signal | | 5089634f99SSanyog Kale | L + R +----------------------------------+ L + R | 5189634f99SSanyog Kale | (Data) | Data Direction | (Data) | 5289634f99SSanyog Kale +---------------+ <-----------------------+ +---------------+ 5389634f99SSanyog Kale 5489634f99SSanyog Kale 5589634f99SSanyog KaleExample 3: Stereo Stream with L and R channels is rendered by Master. Each 5689634f99SSanyog Kaleof the L and R channel is received by two different Slaves. Master and both 5789634f99SSanyog KaleSlaves are using single port. :: 5889634f99SSanyog Kale 5989634f99SSanyog Kale +---------------+ Clock Signal +---------------+ 6089634f99SSanyog Kale | Master +---------+------------------------+ Slave | 6189634f99SSanyog Kale | Interface | | | Interface | 6289634f99SSanyog Kale | | | | 1 | 6389634f99SSanyog Kale | | | Data Signal | | 6489634f99SSanyog Kale | L + R +---+------------------------------+ L | 6589634f99SSanyog Kale | (Data) | | | Data Direction | (Data) | 6689634f99SSanyog Kale +---------------+ | | +-------------> +---------------+ 6789634f99SSanyog Kale | | 6889634f99SSanyog Kale | | 6989634f99SSanyog Kale | | +---------------+ 7089634f99SSanyog Kale | +----------------------> | Slave | 7189634f99SSanyog Kale | | Interface | 7289634f99SSanyog Kale | | 2 | 7389634f99SSanyog Kale | | | 7489634f99SSanyog Kale +----------------------------> | R | 7589634f99SSanyog Kale | (Data) | 7689634f99SSanyog Kale +---------------+ 7789634f99SSanyog Kale 7801de9950SPierre-Louis BossartExample 4: Stereo Stream with L and R channels is rendered by 7901de9950SPierre-Louis BossartMaster. Both of the L and R channels are received by two different 8001de9950SPierre-Louis BossartSlaves. Master and both Slaves are using single port handling 8101de9950SPierre-Louis BossartL+R. Each Slave device processes the L + R data locally, typically 8201de9950SPierre-Louis Bossartbased on static configuration or dynamic orientation, and may drive 8301de9950SPierre-Louis Bossartone or more speakers. :: 8489634f99SSanyog Kale 8501de9950SPierre-Louis Bossart +---------------+ Clock Signal +---------------+ 8601de9950SPierre-Louis Bossart | Master +---------+------------------------+ Slave | 8701de9950SPierre-Louis Bossart | Interface | | | Interface | 8801de9950SPierre-Louis Bossart | | | | 1 | 8901de9950SPierre-Louis Bossart | | | Data Signal | | 9001de9950SPierre-Louis Bossart | L + R +---+------------------------------+ L + R | 9101de9950SPierre-Louis Bossart | (Data) | | | Data Direction | (Data) | 9201de9950SPierre-Louis Bossart +---------------+ | | +-------------> +---------------+ 9301de9950SPierre-Louis Bossart | | 9401de9950SPierre-Louis Bossart | | 9501de9950SPierre-Louis Bossart | | +---------------+ 9601de9950SPierre-Louis Bossart | +----------------------> | Slave | 9701de9950SPierre-Louis Bossart | | Interface | 9801de9950SPierre-Louis Bossart | | 2 | 9901de9950SPierre-Louis Bossart | | | 10001de9950SPierre-Louis Bossart +----------------------------> | L + R | 10101de9950SPierre-Louis Bossart | (Data) | 10201de9950SPierre-Louis Bossart +---------------+ 10301de9950SPierre-Louis Bossart 10401de9950SPierre-Louis BossartExample 5: Stereo Stream with L and R channel is rendered by two different 10589634f99SSanyog KalePorts of the Master and is received by only single Port of the Slave 10689634f99SSanyog Kaleinterface. :: 10789634f99SSanyog Kale 10889634f99SSanyog Kale +--------------------+ 10989634f99SSanyog Kale | | 11089634f99SSanyog Kale | +--------------+ +----------------+ 11189634f99SSanyog Kale | | || | | 11289634f99SSanyog Kale | | Data Port || L Channel | | 11389634f99SSanyog Kale | | 1 |------------+ | | 11489634f99SSanyog Kale | | L Channel || | +-----+----+ | 11589634f99SSanyog Kale | | (Data) || | L + R Channel || Data | | 11689634f99SSanyog Kale | Master +----------+ | +---+---------> || Port | | 11789634f99SSanyog Kale | Interface | | || 1 | | 11889634f99SSanyog Kale | +--------------+ | || | | 11989634f99SSanyog Kale | | || | +----------+ | 12089634f99SSanyog Kale | | Data Port |------------+ | | 12189634f99SSanyog Kale | | 2 || R Channel | Slave | 12289634f99SSanyog Kale | | R Channel || | Interface | 12389634f99SSanyog Kale | | (Data) || | 1 | 12489634f99SSanyog Kale | +--------------+ Clock Signal | L + R | 12589634f99SSanyog Kale | +---------------------------> | (Data) | 12689634f99SSanyog Kale +--------------------+ | | 12789634f99SSanyog Kale +----------------+ 12889634f99SSanyog Kale 12901de9950SPierre-Louis BossartExample 6: Stereo Stream with L and R channel is rendered by 2 Masters, each 1308cf3f9cfSSanyog Kalerendering one channel, and is received by two different Slaves, each 1318cf3f9cfSSanyog Kalereceiving one channel. Both Masters and both Slaves are using single port. :: 1328cf3f9cfSSanyog Kale 1338cf3f9cfSSanyog Kale +---------------+ Clock Signal +---------------+ 1348cf3f9cfSSanyog Kale | Master +----------------------------------+ Slave | 1358cf3f9cfSSanyog Kale | Interface | | Interface | 1368cf3f9cfSSanyog Kale | 1 | | 1 | 1378cf3f9cfSSanyog Kale | | Data Signal | | 1388cf3f9cfSSanyog Kale | L +----------------------------------+ L | 1398cf3f9cfSSanyog Kale | (Data) | Data Direction | (Data) | 1408cf3f9cfSSanyog Kale +---------------+ +-----------------------> +---------------+ 1418cf3f9cfSSanyog Kale 1428cf3f9cfSSanyog Kale +---------------+ Clock Signal +---------------+ 1438cf3f9cfSSanyog Kale | Master +----------------------------------+ Slave | 1448cf3f9cfSSanyog Kale | Interface | | Interface | 1458cf3f9cfSSanyog Kale | 2 | | 2 | 1468cf3f9cfSSanyog Kale | | Data Signal | | 1478cf3f9cfSSanyog Kale | R +----------------------------------+ R | 1488cf3f9cfSSanyog Kale | (Data) | Data Direction | (Data) | 1498cf3f9cfSSanyog Kale +---------------+ +-----------------------> +---------------+ 1508cf3f9cfSSanyog Kale 15101de9950SPierre-Louis BossartExample 7: Stereo Stream with L and R channel is rendered by 2 15201de9950SPierre-Louis BossartMasters, each rendering both channels. Each Slave receives L + R. This 15301de9950SPierre-Louis Bossartis the same application as Example 4 but with Slaves placed on 15401de9950SPierre-Louis Bossartseparate links. :: 15501de9950SPierre-Louis Bossart 15601de9950SPierre-Louis Bossart +---------------+ Clock Signal +---------------+ 15701de9950SPierre-Louis Bossart | Master +----------------------------------+ Slave | 15801de9950SPierre-Louis Bossart | Interface | | Interface | 15901de9950SPierre-Louis Bossart | 1 | | 1 | 16001de9950SPierre-Louis Bossart | | Data Signal | | 16101de9950SPierre-Louis Bossart | L + R +----------------------------------+ L + R | 16201de9950SPierre-Louis Bossart | (Data) | Data Direction | (Data) | 16301de9950SPierre-Louis Bossart +---------------+ +-----------------------> +---------------+ 16401de9950SPierre-Louis Bossart 16501de9950SPierre-Louis Bossart +---------------+ Clock Signal +---------------+ 16601de9950SPierre-Louis Bossart | Master +----------------------------------+ Slave | 16701de9950SPierre-Louis Bossart | Interface | | Interface | 16801de9950SPierre-Louis Bossart | 2 | | 2 | 16901de9950SPierre-Louis Bossart | | Data Signal | | 17001de9950SPierre-Louis Bossart | L + R +----------------------------------+ L + R | 17101de9950SPierre-Louis Bossart | (Data) | Data Direction | (Data) | 17201de9950SPierre-Louis Bossart +---------------+ +-----------------------> +---------------+ 17301de9950SPierre-Louis Bossart 17401de9950SPierre-Louis BossartExample 8: 4-channel Stream is rendered by 2 Masters, each rendering a 17501de9950SPierre-Louis Bossart2 channels. Each Slave receives 2 channels. :: 17601de9950SPierre-Louis Bossart 17701de9950SPierre-Louis Bossart +---------------+ Clock Signal +---------------+ 17801de9950SPierre-Louis Bossart | Master +----------------------------------+ Slave | 17901de9950SPierre-Louis Bossart | Interface | | Interface | 18001de9950SPierre-Louis Bossart | 1 | | 1 | 18101de9950SPierre-Louis Bossart | | Data Signal | | 18201de9950SPierre-Louis Bossart | L1 + R1 +----------------------------------+ L1 + R1 | 18301de9950SPierre-Louis Bossart | (Data) | Data Direction | (Data) | 18401de9950SPierre-Louis Bossart +---------------+ +-----------------------> +---------------+ 18501de9950SPierre-Louis Bossart 18601de9950SPierre-Louis Bossart +---------------+ Clock Signal +---------------+ 18701de9950SPierre-Louis Bossart | Master +----------------------------------+ Slave | 18801de9950SPierre-Louis Bossart | Interface | | Interface | 18901de9950SPierre-Louis Bossart | 2 | | 2 | 19001de9950SPierre-Louis Bossart | | Data Signal | | 19101de9950SPierre-Louis Bossart | L2 + R2 +----------------------------------+ L2 + R2 | 19201de9950SPierre-Louis Bossart | (Data) | Data Direction | (Data) | 19301de9950SPierre-Louis Bossart +---------------+ +-----------------------> +---------------+ 19401de9950SPierre-Louis Bossart 19501de9950SPierre-Louis BossartNote1: In multi-link cases like above, to lock, one would acquire a global 1968cf3f9cfSSanyog Kalelock and then go on locking bus instances. But, in this case the caller 1978cf3f9cfSSanyog Kaleframework(ASoC DPCM) guarantees that stream operations on a card are 1988cf3f9cfSSanyog Kalealways serialized. So, there is no race condition and hence no need for 1998cf3f9cfSSanyog Kaleglobal lock. 2008cf3f9cfSSanyog Kale 20101de9950SPierre-Louis BossartNote2: A Slave device may be configured to receive all channels 20201de9950SPierre-Louis Bossarttransmitted on a link for a given Stream (Example 4) or just a subset 20301de9950SPierre-Louis Bossartof the data (Example 3). The configuration of the Slave device is not 20401de9950SPierre-Louis Bossarthandled by a SoundWire subsystem API, but instead by the 20501de9950SPierre-Louis Bossartsnd_soc_dai_set_tdm_slot() API. The platform or machine driver will 20601de9950SPierre-Louis Bossarttypically configure which of the slots are used. For Example 4, the 20701de9950SPierre-Louis Bossartsame slots would be used by all Devices, while for Example 3 the Slave 20801de9950SPierre-Louis BossartDevice1 would use e.g. Slot 0 and Slave device2 slot 1. 20901de9950SPierre-Louis Bossart 21001de9950SPierre-Louis BossartNote3: Multiple Sink ports can extract the same information for the 21101de9950SPierre-Louis Bossartsame bitSlots in the SoundWire frame, however multiple Source ports 21201de9950SPierre-Louis Bossartshall be configured with different bitSlot configurations. This is the 21301de9950SPierre-Louis Bossartsame limitation as with I2S/PCM TDM usages. 21401de9950SPierre-Louis Bossart 21589634f99SSanyog KaleSoundWire Stream Management flow 21689634f99SSanyog Kale================================ 21789634f99SSanyog Kale 21889634f99SSanyog KaleStream definitions 21989634f99SSanyog Kale------------------ 22089634f99SSanyog Kale 22189634f99SSanyog Kale (1) Current stream: This is classified as the stream on which operation has 22289634f99SSanyog Kale to be performed like prepare, enable, disable, de-prepare etc. 22389634f99SSanyog Kale 22489634f99SSanyog Kale (2) Active stream: This is classified as the stream which is already active 22589634f99SSanyog Kale on Bus other than current stream. There can be multiple active streams 22689634f99SSanyog Kale on the Bus. 22789634f99SSanyog Kale 22889634f99SSanyog KaleSoundWire Bus manages stream operations for each stream getting 22989634f99SSanyog Kalerendered/captured on the SoundWire Bus. This section explains Bus operations 23089634f99SSanyog Kaledone for each of the stream allocated/released on Bus. Following are the 23189634f99SSanyog Kalestream states maintained by the Bus for each of the audio stream. 23289634f99SSanyog Kale 23389634f99SSanyog Kale 23489634f99SSanyog KaleSoundWire stream states 23589634f99SSanyog Kale----------------------- 23689634f99SSanyog Kale 23789634f99SSanyog KaleBelow shows the SoundWire stream states and state transition diagram. :: 23889634f99SSanyog Kale 23989634f99SSanyog Kale +-----------+ +------------+ +----------+ +----------+ 24089634f99SSanyog Kale | ALLOCATED +---->| CONFIGURED +---->| PREPARED +---->| ENABLED | 24189634f99SSanyog Kale | STATE | | STATE | | STATE | | STATE | 24259528807SPierre-Louis Bossart +-----------+ +------------+ +---+--+---+ +----+-----+ 24359528807SPierre-Louis Bossart ^ ^ ^ 24459528807SPierre-Louis Bossart | | | 24559528807SPierre-Louis Bossart __| |___________ | 24659528807SPierre-Louis Bossart | | | 24759528807SPierre-Louis Bossart v | v 24859528807SPierre-Louis Bossart +----------+ +-----+------+ +-+--+-----+ 24989634f99SSanyog Kale | RELEASED |<----------+ DEPREPARED |<-------+ DISABLED | 25089634f99SSanyog Kale | STATE | | STATE | | STATE | 25189634f99SSanyog Kale +----------+ +------------+ +----------+ 25289634f99SSanyog Kale 25359528807SPierre-Louis BossartNOTE: State transitions between ``SDW_STREAM_ENABLED`` and 25459528807SPierre-Louis Bossart``SDW_STREAM_DISABLED`` are only relevant when then INFO_PAUSE flag is 25559528807SPierre-Louis Bossartsupported at the ALSA/ASoC level. Likewise the transition between 25659528807SPierre-Louis Bossart``SDW_DISABLED_STATE`` and ``SDW_PREPARED_STATE`` depends on the 25759528807SPierre-Louis BossartINFO_RESUME flag. 25889634f99SSanyog Kale 25959528807SPierre-Louis BossartNOTE2: The framework implements basic state transition checks, but 26059528807SPierre-Louis Bossartdoes not e.g. check if a transition from DISABLED to ENABLED is valid 26159528807SPierre-Louis Bossarton a specific platform. Such tests need to be added at the ALSA/ASoC 26259528807SPierre-Louis Bossartlevel. 26389634f99SSanyog Kale 26489634f99SSanyog KaleStream State Operations 26589634f99SSanyog Kale----------------------- 26689634f99SSanyog Kale 26789634f99SSanyog KaleBelow section explains the operations done by the Bus on Master(s) and 26889634f99SSanyog KaleSlave(s) as part of stream state transitions. 26989634f99SSanyog Kale 27089634f99SSanyog KaleSDW_STREAM_ALLOCATED 27189634f99SSanyog Kale~~~~~~~~~~~~~~~~~~~~ 27289634f99SSanyog Kale 27389634f99SSanyog KaleAllocation state for stream. This is the entry state 27489634f99SSanyog Kaleof the stream. Operations performed before entering in this state: 27589634f99SSanyog Kale 27689634f99SSanyog Kale (1) A stream runtime is allocated for the stream. This stream 27789634f99SSanyog Kale runtime is used as a reference for all the operations performed 27889634f99SSanyog Kale on the stream. 27989634f99SSanyog Kale 28089634f99SSanyog Kale (2) The resources required for holding stream runtime information are 28189634f99SSanyog Kale allocated and initialized. This holds all stream related information 28289634f99SSanyog Kale such as stream type (PCM/PDM) and parameters, Master and Slave 28389634f99SSanyog Kale interface associated with the stream, stream state etc. 28489634f99SSanyog Kale 28589634f99SSanyog KaleAfter all above operations are successful, stream state is set to 28689634f99SSanyog Kale``SDW_STREAM_ALLOCATED``. 28789634f99SSanyog Kale 28889634f99SSanyog KaleBus implements below API for allocate a stream which needs to be called once 28989634f99SSanyog Kaleper stream. From ASoC DPCM framework, this stream state maybe linked to 29089634f99SSanyog Kale.startup() operation. 29189634f99SSanyog Kale 29289634f99SSanyog Kale.. code-block:: c 293502c00d9SRandy Dunlap 29489634f99SSanyog Kale int sdw_alloc_stream(char * stream_name); 29589634f99SSanyog Kale 296*4550569bSPierre-Louis BossartThe SoundWire core provides a sdw_startup_stream() helper function, 297*4550569bSPierre-Louis Bossarttypically called during a dailink .startup() callback, which performs 298*4550569bSPierre-Louis Bossartstream allocation and sets the stream pointer for all DAIs 299*4550569bSPierre-Louis Bossartconnected to a stream. 30089634f99SSanyog Kale 30189634f99SSanyog KaleSDW_STREAM_CONFIGURED 30289634f99SSanyog Kale~~~~~~~~~~~~~~~~~~~~~ 30389634f99SSanyog Kale 30489634f99SSanyog KaleConfiguration state of stream. Operations performed before entering in 30589634f99SSanyog Kalethis state: 30689634f99SSanyog Kale 30789634f99SSanyog Kale (1) The resources allocated for stream information in SDW_STREAM_ALLOCATED 30889634f99SSanyog Kale state are updated here. This includes stream parameters, Master(s) 30989634f99SSanyog Kale and Slave(s) runtime information associated with current stream. 31089634f99SSanyog Kale 31189634f99SSanyog Kale (2) All the Master(s) and Slave(s) associated with current stream provide 31289634f99SSanyog Kale the port information to Bus which includes port numbers allocated by 31389634f99SSanyog Kale Master(s) and Slave(s) for current stream and their channel mask. 31489634f99SSanyog Kale 31589634f99SSanyog KaleAfter all above operations are successful, stream state is set to 31689634f99SSanyog Kale``SDW_STREAM_CONFIGURED``. 31789634f99SSanyog Kale 31889634f99SSanyog KaleBus implements below APIs for CONFIG state which needs to be called by 31989634f99SSanyog Kalethe respective Master(s) and Slave(s) associated with stream. These APIs can 32089634f99SSanyog Kaleonly be invoked once by respective Master(s) and Slave(s). From ASoC DPCM 32189634f99SSanyog Kaleframework, this stream state is linked to .hw_params() operation. 32289634f99SSanyog Kale 32389634f99SSanyog Kale.. code-block:: c 324502c00d9SRandy Dunlap 32589634f99SSanyog Kale int sdw_stream_add_master(struct sdw_bus * bus, 32689634f99SSanyog Kale struct sdw_stream_config * stream_config, 32789634f99SSanyog Kale struct sdw_ports_config * ports_config, 32889634f99SSanyog Kale struct sdw_stream_runtime * stream); 32989634f99SSanyog Kale 33089634f99SSanyog Kale int sdw_stream_add_slave(struct sdw_slave * slave, 33189634f99SSanyog Kale struct sdw_stream_config * stream_config, 33289634f99SSanyog Kale struct sdw_ports_config * ports_config, 33389634f99SSanyog Kale struct sdw_stream_runtime * stream); 33489634f99SSanyog Kale 33589634f99SSanyog Kale 33689634f99SSanyog KaleSDW_STREAM_PREPARED 33789634f99SSanyog Kale~~~~~~~~~~~~~~~~~~~ 33889634f99SSanyog Kale 33989634f99SSanyog KalePrepare state of stream. Operations performed before entering in this state: 34089634f99SSanyog Kale 34159528807SPierre-Louis Bossart (0) Steps 1 and 2 are omitted in the case of a resume operation, 34259528807SPierre-Louis Bossart where the bus bandwidth is known. 34359528807SPierre-Louis Bossart 34489634f99SSanyog Kale (1) Bus parameters such as bandwidth, frame shape, clock frequency, 34589634f99SSanyog Kale are computed based on current stream as well as already active 34689634f99SSanyog Kale stream(s) on Bus. Re-computation is required to accommodate current 34789634f99SSanyog Kale stream on the Bus. 34889634f99SSanyog Kale 34989634f99SSanyog Kale (2) Transport and port parameters of all Master(s) and Slave(s) port(s) are 35089634f99SSanyog Kale computed for the current as well as already active stream based on frame 35189634f99SSanyog Kale shape and clock frequency computed in step 1. 35289634f99SSanyog Kale 35389634f99SSanyog Kale (3) Computed Bus and transport parameters are programmed in Master(s) and 35489634f99SSanyog Kale Slave(s) registers. The banked registers programming is done on the 35589634f99SSanyog Kale alternate bank (bank currently unused). Port(s) are enabled for the 35689634f99SSanyog Kale already active stream(s) on the alternate bank (bank currently unused). 35789634f99SSanyog Kale This is done in order to not disrupt already active stream(s). 35889634f99SSanyog Kale 35989634f99SSanyog Kale (4) Once all the values are programmed, Bus initiates switch to alternate 36089634f99SSanyog Kale bank where all new values programmed gets into effect. 36189634f99SSanyog Kale 36289634f99SSanyog Kale (5) Ports of Master(s) and Slave(s) for current stream are prepared by 36389634f99SSanyog Kale programming PrepareCtrl register. 36489634f99SSanyog Kale 36589634f99SSanyog KaleAfter all above operations are successful, stream state is set to 36689634f99SSanyog Kale``SDW_STREAM_PREPARED``. 36789634f99SSanyog Kale 36859528807SPierre-Louis BossartBus implements below API for PREPARE state which needs to be called 36959528807SPierre-Louis Bossartonce per stream. From ASoC DPCM framework, this stream state is linked 37059528807SPierre-Louis Bossartto .prepare() operation. Since the .trigger() operations may not 37159528807SPierre-Louis Bossartfollow the .prepare(), a direct transition from 37259528807SPierre-Louis Bossart``SDW_STREAM_PREPARED`` to ``SDW_STREAM_DEPREPARED`` is allowed. 37389634f99SSanyog Kale 37489634f99SSanyog Kale.. code-block:: c 375502c00d9SRandy Dunlap 37689634f99SSanyog Kale int sdw_prepare_stream(struct sdw_stream_runtime * stream); 37789634f99SSanyog Kale 37889634f99SSanyog Kale 37989634f99SSanyog KaleSDW_STREAM_ENABLED 38089634f99SSanyog Kale~~~~~~~~~~~~~~~~~~ 38189634f99SSanyog Kale 38289634f99SSanyog KaleEnable state of stream. The data port(s) are enabled upon entering this state. 38389634f99SSanyog KaleOperations performed before entering in this state: 38489634f99SSanyog Kale 38589634f99SSanyog Kale (1) All the values computed in SDW_STREAM_PREPARED state are programmed 38689634f99SSanyog Kale in alternate bank (bank currently unused). It includes programming of 38789634f99SSanyog Kale already active stream(s) as well. 38889634f99SSanyog Kale 38989634f99SSanyog Kale (2) All the Master(s) and Slave(s) port(s) for the current stream are 39089634f99SSanyog Kale enabled on alternate bank (bank currently unused) by programming 39189634f99SSanyog Kale ChannelEn register. 39289634f99SSanyog Kale 39389634f99SSanyog Kale (3) Once all the values are programmed, Bus initiates switch to alternate 39489634f99SSanyog Kale bank where all new values programmed gets into effect and port(s) 39589634f99SSanyog Kale associated with current stream are enabled. 39689634f99SSanyog Kale 39789634f99SSanyog KaleAfter all above operations are successful, stream state is set to 39889634f99SSanyog Kale``SDW_STREAM_ENABLED``. 39989634f99SSanyog Kale 40089634f99SSanyog KaleBus implements below API for ENABLE state which needs to be called once per 40189634f99SSanyog Kalestream. From ASoC DPCM framework, this stream state is linked to 40289634f99SSanyog Kale.trigger() start operation. 40389634f99SSanyog Kale 40489634f99SSanyog Kale.. code-block:: c 405502c00d9SRandy Dunlap 40689634f99SSanyog Kale int sdw_enable_stream(struct sdw_stream_runtime * stream); 40789634f99SSanyog Kale 40889634f99SSanyog KaleSDW_STREAM_DISABLED 40989634f99SSanyog Kale~~~~~~~~~~~~~~~~~~~ 41089634f99SSanyog Kale 41189634f99SSanyog KaleDisable state of stream. The data port(s) are disabled upon exiting this state. 41289634f99SSanyog KaleOperations performed before entering in this state: 41389634f99SSanyog Kale 41489634f99SSanyog Kale (1) All the Master(s) and Slave(s) port(s) for the current stream are 41589634f99SSanyog Kale disabled on alternate bank (bank currently unused) by programming 41689634f99SSanyog Kale ChannelEn register. 41789634f99SSanyog Kale 41889634f99SSanyog Kale (2) All the current configuration of Bus and active stream(s) are programmed 41989634f99SSanyog Kale into alternate bank (bank currently unused). 42089634f99SSanyog Kale 42189634f99SSanyog Kale (3) Once all the values are programmed, Bus initiates switch to alternate 42289634f99SSanyog Kale bank where all new values programmed gets into effect and port(s) associated 42389634f99SSanyog Kale with current stream are disabled. 42489634f99SSanyog Kale 42589634f99SSanyog KaleAfter all above operations are successful, stream state is set to 42689634f99SSanyog Kale``SDW_STREAM_DISABLED``. 42789634f99SSanyog Kale 42889634f99SSanyog KaleBus implements below API for DISABLED state which needs to be called once 42989634f99SSanyog Kaleper stream. From ASoC DPCM framework, this stream state is linked to 43089634f99SSanyog Kale.trigger() stop operation. 43189634f99SSanyog Kale 43259528807SPierre-Louis BossartWhen the INFO_PAUSE flag is supported, a direct transition to 43359528807SPierre-Louis Bossart``SDW_STREAM_ENABLED`` is allowed. 43459528807SPierre-Louis Bossart 43559528807SPierre-Louis BossartFor resume operations where ASoC will use the .prepare() callback, the 43659528807SPierre-Louis Bossartstream can transition from ``SDW_STREAM_DISABLED`` to 43759528807SPierre-Louis Bossart``SDW_STREAM_PREPARED``, with all required settings restored but 43859528807SPierre-Louis Bossartwithout updating the bandwidth and bit allocation. 43959528807SPierre-Louis Bossart 44089634f99SSanyog Kale.. code-block:: c 441502c00d9SRandy Dunlap 44289634f99SSanyog Kale int sdw_disable_stream(struct sdw_stream_runtime * stream); 44389634f99SSanyog Kale 44489634f99SSanyog Kale 44589634f99SSanyog KaleSDW_STREAM_DEPREPARED 44689634f99SSanyog Kale~~~~~~~~~~~~~~~~~~~~~ 44789634f99SSanyog Kale 44889634f99SSanyog KaleDe-prepare state of stream. Operations performed before entering in this 44989634f99SSanyog Kalestate: 45089634f99SSanyog Kale 45189634f99SSanyog Kale (1) All the port(s) of Master(s) and Slave(s) for current stream are 45289634f99SSanyog Kale de-prepared by programming PrepareCtrl register. 45389634f99SSanyog Kale 45489634f99SSanyog Kale (2) The payload bandwidth of current stream is reduced from the total 45589634f99SSanyog Kale bandwidth requirement of bus and new parameters calculated and 45689634f99SSanyog Kale applied by performing bank switch etc. 45789634f99SSanyog Kale 45889634f99SSanyog KaleAfter all above operations are successful, stream state is set to 45989634f99SSanyog Kale``SDW_STREAM_DEPREPARED``. 46089634f99SSanyog Kale 46159528807SPierre-Louis BossartBus implements below API for DEPREPARED state which needs to be called 46259528807SPierre-Louis Bossartonce per stream. ALSA/ASoC do not have a concept of 'deprepare', and 46359528807SPierre-Louis Bossartthe mapping from this stream state to ALSA/ASoC operation may be 46459528807SPierre-Louis Bossartimplementation specific. 46559528807SPierre-Louis Bossart 46659528807SPierre-Louis BossartWhen the INFO_PAUSE flag is supported, the stream state is linked to 46759528807SPierre-Louis Bossartthe .hw_free() operation - the stream is not deprepared on a 46859528807SPierre-Louis BossartTRIGGER_STOP. 46959528807SPierre-Louis Bossart 47059528807SPierre-Louis BossartOther implementations may transition to the ``SDW_STREAM_DEPREPARED`` 47159528807SPierre-Louis Bossartstate on TRIGGER_STOP, should they require a transition through the 47259528807SPierre-Louis Bossart``SDW_STREAM_PREPARED`` state. 47389634f99SSanyog Kale 47489634f99SSanyog Kale.. code-block:: c 475502c00d9SRandy Dunlap 47689634f99SSanyog Kale int sdw_deprepare_stream(struct sdw_stream_runtime * stream); 47789634f99SSanyog Kale 47889634f99SSanyog Kale 47989634f99SSanyog KaleSDW_STREAM_RELEASED 48089634f99SSanyog Kale~~~~~~~~~~~~~~~~~~~ 48189634f99SSanyog Kale 48289634f99SSanyog KaleRelease state of stream. Operations performed before entering in this state: 48389634f99SSanyog Kale 48489634f99SSanyog Kale (1) Release port resources for all Master(s) and Slave(s) port(s) 48589634f99SSanyog Kale associated with current stream. 48689634f99SSanyog Kale 48789634f99SSanyog Kale (2) Release Master(s) and Slave(s) runtime resources associated with 48889634f99SSanyog Kale current stream. 48989634f99SSanyog Kale 49089634f99SSanyog Kale (3) Release stream runtime resources associated with current stream. 49189634f99SSanyog Kale 49289634f99SSanyog KaleAfter all above operations are successful, stream state is set to 49389634f99SSanyog Kale``SDW_STREAM_RELEASED``. 49489634f99SSanyog Kale 49589634f99SSanyog KaleBus implements below APIs for RELEASE state which needs to be called by 49689634f99SSanyog Kaleall the Master(s) and Slave(s) associated with stream. From ASoC DPCM 49789634f99SSanyog Kaleframework, this stream state is linked to .hw_free() operation. 49889634f99SSanyog Kale 49989634f99SSanyog Kale.. code-block:: c 500502c00d9SRandy Dunlap 50189634f99SSanyog Kale int sdw_stream_remove_master(struct sdw_bus * bus, 50289634f99SSanyog Kale struct sdw_stream_runtime * stream); 50389634f99SSanyog Kale int sdw_stream_remove_slave(struct sdw_slave * slave, 50489634f99SSanyog Kale struct sdw_stream_runtime * stream); 50589634f99SSanyog Kale 50689634f99SSanyog Kale 50789634f99SSanyog KaleThe .shutdown() ASoC DPCM operation calls below Bus API to release 50889634f99SSanyog Kalestream assigned as part of ALLOCATED state. 50989634f99SSanyog Kale 51089634f99SSanyog KaleIn .shutdown() the data structure maintaining stream state are freed up. 51189634f99SSanyog Kale 51289634f99SSanyog Kale.. code-block:: c 513502c00d9SRandy Dunlap 51489634f99SSanyog Kale void sdw_release_stream(struct sdw_stream_runtime * stream); 51589634f99SSanyog Kale 516*4550569bSPierre-Louis BossartThe SoundWire core provides a sdw_shutdown_stream() helper function, 517*4550569bSPierre-Louis Bossarttypically called during a dailink .shutdown() callback, which clears 518*4550569bSPierre-Louis Bossartthe stream pointer for all DAIS connected to a stream and releases the 519*4550569bSPierre-Louis Bossartmemory allocated for the stream. 520*4550569bSPierre-Louis Bossart 52189634f99SSanyog KaleNot Supported 52289634f99SSanyog Kale============= 52389634f99SSanyog Kale 52489634f99SSanyog Kale1. A single port with multiple channels supported cannot be used between two 52589634f99SSanyog Kale streams or across stream. For example a port with 4 channels cannot be used 52689634f99SSanyog Kale to handle 2 independent stereo streams even though it's possible in theory 52789634f99SSanyog Kale in SoundWire. 528