Lines Matching full:stream
5 * stream.c - SoundWire Bus stream operations.
264 * @m_rt: Master stream runtime
372 * @m_rt: Master stream runtime
639 * explicitly preparing a stream or handling an in sdw_program_params()
640 * already-prepared stream otherwise. in sdw_program_params()
643 m_rt->stream->state == SDW_STREAM_CONFIGURED) in sdw_program_params()
661 if (m_rt->stream->state != SDW_STREAM_ENABLED) in sdw_program_params()
745 * @multi_link: whether this is a multi-link stream with hardware-based sync
777 static int do_bank_switch(struct sdw_stream_runtime *stream) in do_bank_switch() argument
786 m_rt_count = stream->m_rt_count; in do_bank_switch()
788 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in do_bank_switch()
826 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in do_bank_switch()
865 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in do_bank_switch()
877 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in do_bank_switch()
926 struct sdw_stream_runtime *stream) in sdw_slave_port_free() argument
932 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in sdw_slave_port_free()
1077 * @stream_config: Stream configuration
1091 struct sdw_stream_runtime *stream) in sdw_slave_rt_find() argument
1096 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in sdw_slave_rt_find()
1111 * @stream: Stream runtime handle.
1116 struct sdw_stream_runtime *stream) in sdw_slave_rt_free() argument
1120 s_rt = sdw_slave_rt_find(slave, stream); in sdw_slave_rt_free()
1129 struct sdw_stream_runtime *stream) in sdw_master_rt_find() argument
1134 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in sdw_master_rt_find()
1146 * @stream: Stream runtime handle.
1152 struct sdw_stream_runtime *stream) in sdw_master_rt_alloc() argument
1170 insert_after = &stream->master_list; in sdw_master_rt_alloc()
1171 list_for_each_entry_reverse(walk_m_rt, &stream->master_list, stream_node) { in sdw_master_rt_alloc()
1182 m_rt->stream = stream; in sdw_master_rt_alloc()
1193 * @stream_config: Stream configuration
1211 * @stream: Stream runtime handle.
1219 struct sdw_stream_runtime *stream) in sdw_master_rt_free() argument
1225 sdw_slave_port_free(s_rt->slave, stream); in sdw_master_rt_free()
1226 sdw_slave_rt_free(s_rt->slave, stream); in sdw_master_rt_free()
1237 * sdw_config_stream() - Configure the allocated stream
1240 * @stream: SoundWire stream
1241 * @stream_config: Stream configuration for audio stream
1247 struct sdw_stream_runtime *stream, in sdw_config_stream() argument
1252 * Update the stream rate, channel and bps based on data in sdw_config_stream()
1254 * match the rate, bps, stream type and increment number of channels. in sdw_config_stream()
1257 * comparison and allow the value to be set and stored in stream in sdw_config_stream()
1259 if (stream->params.rate && in sdw_config_stream()
1260 stream->params.rate != stream_config->frame_rate) { in sdw_config_stream()
1261 dev_err(dev, "rate not matching, stream:%s\n", stream->name); in sdw_config_stream()
1265 if (stream->params.bps && in sdw_config_stream()
1266 stream->params.bps != stream_config->bps) { in sdw_config_stream()
1267 dev_err(dev, "bps not matching, stream:%s\n", stream->name); in sdw_config_stream()
1271 stream->type = stream_config->type; in sdw_config_stream()
1272 stream->params.rate = stream_config->frame_rate; in sdw_config_stream()
1273 stream->params.bps = stream_config->bps; in sdw_config_stream()
1277 stream->params.ch_count += stream_config->ch_count; in sdw_config_stream()
1316 * @stream: SoundWire stream
1319 * stream to reconfigure the bus.
1320 * NOTE: This function is called from SoundWire stream ops and is
1323 static void sdw_acquire_bus_lock(struct sdw_stream_runtime *stream) in sdw_acquire_bus_lock() argument
1329 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in sdw_acquire_bus_lock()
1339 * @stream: SoundWire stream
1342 * NOTE: This function is called from SoundWire stream ops and is
1345 static void sdw_release_bus_lock(struct sdw_stream_runtime *stream) in sdw_release_bus_lock() argument
1351 list_for_each_entry_reverse(m_rt, &stream->master_list, stream_node) { in sdw_release_bus_lock()
1357 static int _sdw_prepare_stream(struct sdw_stream_runtime *stream, in _sdw_prepare_stream() argument
1366 /* Prepare Master(s) and Slave(s) port(s) associated with stream */ in _sdw_prepare_stream()
1367 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_prepare_stream()
1373 if ((prop->max_clk_freq % stream->params.rate) != 0) { in _sdw_prepare_stream()
1381 bus->params.bandwidth += m_rt->stream->params.rate * in _sdw_prepare_stream()
1382 m_rt->ch_count * m_rt->stream->params.bps; in _sdw_prepare_stream()
1403 ret = do_bank_switch(stream); in _sdw_prepare_stream()
1409 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_prepare_stream()
1421 stream->state = SDW_STREAM_PREPARED; in _sdw_prepare_stream()
1431 * sdw_prepare_stream() - Prepare SoundWire stream
1433 * @stream: Soundwire stream
1435 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1437 int sdw_prepare_stream(struct sdw_stream_runtime *stream) in sdw_prepare_stream() argument
1442 if (!stream) { in sdw_prepare_stream()
1443 pr_err("SoundWire: Handle not found for stream\n"); in sdw_prepare_stream()
1447 sdw_acquire_bus_lock(stream); in sdw_prepare_stream()
1449 if (stream->state == SDW_STREAM_PREPARED) { in sdw_prepare_stream()
1454 if (stream->state != SDW_STREAM_CONFIGURED && in sdw_prepare_stream()
1455 stream->state != SDW_STREAM_DEPREPARED && in sdw_prepare_stream()
1456 stream->state != SDW_STREAM_DISABLED) { in sdw_prepare_stream()
1458 __func__, stream->name, stream->state); in sdw_prepare_stream()
1464 * when the stream is DISABLED, this means sdw_prepare_stream() in sdw_prepare_stream()
1469 if (stream->state == SDW_STREAM_DISABLED) in sdw_prepare_stream()
1472 ret = _sdw_prepare_stream(stream, update_params); in sdw_prepare_stream()
1475 sdw_release_bus_lock(stream); in sdw_prepare_stream()
1480 static int _sdw_enable_stream(struct sdw_stream_runtime *stream) in _sdw_enable_stream() argument
1486 /* Enable Master(s) and Slave(s) port(s) associated with stream */ in _sdw_enable_stream()
1487 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_enable_stream()
1506 ret = do_bank_switch(stream); in _sdw_enable_stream()
1512 stream->state = SDW_STREAM_ENABLED; in _sdw_enable_stream()
1517 * sdw_enable_stream() - Enable SoundWire stream
1519 * @stream: Soundwire stream
1521 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1523 int sdw_enable_stream(struct sdw_stream_runtime *stream) in sdw_enable_stream() argument
1527 if (!stream) { in sdw_enable_stream()
1528 pr_err("SoundWire: Handle not found for stream\n"); in sdw_enable_stream()
1532 sdw_acquire_bus_lock(stream); in sdw_enable_stream()
1534 if (stream->state == SDW_STREAM_ENABLED) { in sdw_enable_stream()
1539 if (stream->state != SDW_STREAM_PREPARED && in sdw_enable_stream()
1540 stream->state != SDW_STREAM_DISABLED) { in sdw_enable_stream()
1542 __func__, stream->name, stream->state); in sdw_enable_stream()
1547 ret = _sdw_enable_stream(stream); in sdw_enable_stream()
1550 sdw_release_bus_lock(stream); in sdw_enable_stream()
1555 static int _sdw_disable_stream(struct sdw_stream_runtime *stream) in _sdw_disable_stream() argument
1560 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_disable_stream()
1570 stream->state = SDW_STREAM_DISABLED; in _sdw_disable_stream()
1572 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_disable_stream()
1583 ret = do_bank_switch(stream); in _sdw_disable_stream()
1590 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_disable_stream()
1605 * sdw_disable_stream() - Disable SoundWire stream
1607 * @stream: Soundwire stream
1609 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1611 int sdw_disable_stream(struct sdw_stream_runtime *stream) in sdw_disable_stream() argument
1615 if (!stream) { in sdw_disable_stream()
1616 pr_err("SoundWire: Handle not found for stream\n"); in sdw_disable_stream()
1620 sdw_acquire_bus_lock(stream); in sdw_disable_stream()
1622 if (stream->state == SDW_STREAM_DISABLED) { in sdw_disable_stream()
1627 if (stream->state != SDW_STREAM_ENABLED) { in sdw_disable_stream()
1629 __func__, stream->name, stream->state); in sdw_disable_stream()
1634 ret = _sdw_disable_stream(stream); in sdw_disable_stream()
1637 sdw_release_bus_lock(stream); in sdw_disable_stream()
1642 static int _sdw_deprepare_stream(struct sdw_stream_runtime *stream) in _sdw_deprepare_stream() argument
1648 list_for_each_entry(m_rt, &stream->master_list, stream_node) { in _sdw_deprepare_stream()
1659 bus->params.bandwidth -= m_rt->stream->params.rate * in _sdw_deprepare_stream()
1660 m_rt->ch_count * m_rt->stream->params.bps; in _sdw_deprepare_stream()
1680 stream->state = SDW_STREAM_DEPREPARED; in _sdw_deprepare_stream()
1681 return do_bank_switch(stream); in _sdw_deprepare_stream()
1685 * sdw_deprepare_stream() - Deprepare SoundWire stream
1687 * @stream: Soundwire stream
1689 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1691 int sdw_deprepare_stream(struct sdw_stream_runtime *stream) in sdw_deprepare_stream() argument
1695 if (!stream) { in sdw_deprepare_stream()
1696 pr_err("SoundWire: Handle not found for stream\n"); in sdw_deprepare_stream()
1700 sdw_acquire_bus_lock(stream); in sdw_deprepare_stream()
1702 if (stream->state == SDW_STREAM_DEPREPARED) { in sdw_deprepare_stream()
1707 if (stream->state != SDW_STREAM_PREPARED && in sdw_deprepare_stream()
1708 stream->state != SDW_STREAM_DISABLED) { in sdw_deprepare_stream()
1710 __func__, stream->name, stream->state); in sdw_deprepare_stream()
1715 ret = _sdw_deprepare_stream(stream); in sdw_deprepare_stream()
1718 sdw_release_bus_lock(stream); in sdw_deprepare_stream()
1731 /* Set stream pointer on all DAIs */ in set_stream()
1733 ret = snd_soc_dai_set_stream(dai, sdw_stream, substream->stream); in set_stream()
1735 dev_err(rtd->dev, "failed to set stream pointer on dai %s\n", dai->name); in set_stream()
1744 * sdw_alloc_stream() - Allocate and return stream runtime
1746 * @stream_name: SoundWire stream name
1748 * Allocates a SoundWire stream runtime instance.
1749 * sdw_alloc_stream should be called only once per stream. Typically
1754 struct sdw_stream_runtime *stream; in sdw_alloc_stream() local
1756 stream = kzalloc(sizeof(*stream), GFP_KERNEL); in sdw_alloc_stream()
1757 if (!stream) in sdw_alloc_stream()
1760 stream->name = stream_name; in sdw_alloc_stream()
1761 INIT_LIST_HEAD(&stream->master_list); in sdw_alloc_stream()
1762 stream->state = SDW_STREAM_ALLOCATED; in sdw_alloc_stream()
1763 stream->m_rt_count = 0; in sdw_alloc_stream()
1765 return stream; in sdw_alloc_stream()
1770 * sdw_startup_stream() - Startup SoundWire stream
1772 * @sdw_substream: Soundwire stream
1774 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1784 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) in sdw_startup_stream()
1794 dev_err(rtd->dev, "alloc stream failed for substream DAI %s\n", substream->name); in sdw_startup_stream()
1814 * sdw_shutdown_stream() - Shutdown SoundWire stream
1816 * @sdw_substream: Soundwire stream
1818 * Documentation/driver-api/soundwire/stream.rst explains this API in detail
1827 /* Find stream from first CPU DAI */ in sdw_shutdown_stream()
1830 sdw_stream = snd_soc_dai_get_stream(dai, substream->stream); in sdw_shutdown_stream()
1833 dev_err(rtd->dev, "no stream found for DAI %s\n", dai->name); in sdw_shutdown_stream()
1847 * sdw_release_stream() - Free the assigned stream runtime
1849 * @stream: SoundWire stream runtime
1851 * sdw_release_stream should be called only once per stream
1853 void sdw_release_stream(struct sdw_stream_runtime *stream) in sdw_release_stream() argument
1855 kfree(stream); in sdw_release_stream()
1860 * sdw_stream_add_master() - Allocate and add master runtime to a stream
1863 * @stream_config: Stream configuration for audio stream
1864 * @port_config: Port configuration for audio stream
1866 * @stream: SoundWire stream
1872 struct sdw_stream_runtime *stream) in sdw_stream_add_master() argument
1885 if (!bus->multi_link && stream->m_rt_count > 0) { in sdw_stream_add_master()
1896 m_rt = sdw_master_rt_find(bus, stream); in sdw_stream_add_master()
1898 m_rt = sdw_master_rt_alloc(bus, stream); in sdw_stream_add_master()
1900 dev_err(bus->dev, "%s: Master runtime alloc failed for stream:%s\n", in sdw_stream_add_master()
1901 __func__, stream->name); in sdw_stream_add_master()
1914 stream->m_rt_count++; in sdw_stream_add_master()
1921 ret = sdw_config_stream(bus->dev, stream, stream_config, false); in sdw_stream_add_master()
1934 sdw_master_rt_free(m_rt, stream); in sdw_stream_add_master()
1945 * @stream: SoundWire stream
1947 * This removes and frees port_rt and master_rt from a stream
1950 struct sdw_stream_runtime *stream) in sdw_stream_remove_master() argument
1957 &stream->master_list, stream_node) { in sdw_stream_remove_master()
1962 sdw_master_rt_free(m_rt, stream); in sdw_stream_remove_master()
1963 stream->m_rt_count--; in sdw_stream_remove_master()
1966 if (list_empty(&stream->master_list)) in sdw_stream_remove_master()
1967 stream->state = SDW_STREAM_RELEASED; in sdw_stream_remove_master()
1976 * sdw_stream_add_slave() - Allocate and add master/slave runtime to a stream
1979 * @stream_config: Stream configuration for audio stream
1980 * @stream: SoundWire stream
1981 * @port_config: Port configuration for audio stream
1985 * to the Stream.
1992 struct sdw_stream_runtime *stream) in sdw_stream_add_slave() argument
2007 m_rt = sdw_master_rt_find(slave->bus, stream); in sdw_stream_add_slave()
2013 m_rt = sdw_master_rt_alloc(slave->bus, stream); in sdw_stream_add_slave()
2015 dev_err(&slave->dev, "%s: Master runtime alloc failed for stream:%s\n", in sdw_stream_add_slave()
2016 __func__, stream->name); in sdw_stream_add_slave()
2024 s_rt = sdw_slave_rt_find(slave, stream); in sdw_stream_add_slave()
2028 dev_err(&slave->dev, "Slave runtime alloc failed for stream:%s\n", in sdw_stream_add_slave()
2029 stream->name); in sdw_stream_add_slave()
2051 ret = sdw_config_stream(&slave->dev, stream, stream_config, true); in sdw_stream_add_slave()
2060 * Change stream state to CONFIGURED on first Slave add. in sdw_stream_add_slave()
2061 * Bus is not aware of number of Slave(s) in a stream at this in sdw_stream_add_slave()
2063 * change stream state to CONFIGURED. in sdw_stream_add_slave()
2065 stream->state = SDW_STREAM_CONFIGURED; in sdw_stream_add_slave()
2075 sdw_master_rt_free(m_rt, stream); in sdw_stream_add_slave()
2077 sdw_slave_rt_free(slave, stream); in sdw_stream_add_slave()
2088 * @stream: SoundWire stream
2090 * This removes and frees port_rt and slave_rt from a stream
2093 struct sdw_stream_runtime *stream) in sdw_stream_remove_slave() argument
2097 sdw_slave_port_free(slave, stream); in sdw_stream_remove_slave()
2098 sdw_slave_rt_free(slave, stream); in sdw_stream_remove_slave()