Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions drivers/soundwire/bus.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,8 @@ struct sdw_slave_runtime {
*
* @bus: Bus handle
* @stream: Stream runtime handle
* @params_backup: Snapshot of original bus parameters saved before stream
* preparation, used for rollback recovery on failure.
* @direction: Data direction for Master
* @ch_count: Number of channels handled by the Master for
* this stream, can be zero.
Expand All @@ -166,6 +168,7 @@ struct sdw_slave_runtime {
struct sdw_master_runtime {
struct sdw_bus *bus;
struct sdw_stream_runtime *stream;
struct sdw_bus_params params_backup;
enum sdw_data_direction direction;
unsigned int ch_count;
struct list_head slave_rt_list;
Expand Down
13 changes: 10 additions & 3 deletions drivers/soundwire/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1487,14 +1487,15 @@ static int _sdw_prepare_stream(struct sdw_stream_runtime *stream,
struct sdw_master_runtime *m_rt;
struct sdw_bus *bus;
struct sdw_master_prop *prop;
struct sdw_bus_params params;
int ret;

/* Prepare Master(s) and Slave(s) port(s) associated with stream */
list_for_each_entry(m_rt, &stream->master_list, stream_node) {
bus = m_rt->bus;
prop = &bus->prop;
memcpy(&params, &bus->params, sizeof(params));

/* Snapshot the original params before making any changes */
m_rt->params_backup = bus->params;

/* TODO: Support Asynchronous mode */
if ((prop->max_clk_freq % stream->params.rate) != 0) {
Expand Down Expand Up @@ -1550,7 +1551,13 @@ static int _sdw_prepare_stream(struct sdw_stream_runtime *stream,
return ret;

restore_params:
memcpy(&bus->params, &params, sizeof(params));
/*
* Revert all masters to their snapshotted original parameters.
* Any master that was not modified will safely revert to its own original state.
*/
list_for_each_entry(m_rt, &stream->master_list, stream_node) {
m_rt->bus->params = m_rt->params_backup;
}
return ret;
}

Expand Down
Loading