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
8 changes: 4 additions & 4 deletions drivers/soundwire/generic_bandwidth_allocation.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ static void _sdw_compute_port_params(struct sdw_bus *bus,

/* Run loop for all groups to compute transport parameters */
for (l = 0; l < SDW_MAX_LANES; l++) {
if (l > 0 && !bus->lane_used_bandwidth[l])
if (l > 0 && !bus->params.lane_used_bandwidth[l])
continue;
/* reset hstop for each lane */
hstop = bus->params.col - 1;
Expand Down Expand Up @@ -269,7 +269,7 @@ static int sdw_compute_group_params(struct sdw_bus *bus,
}

for (l = 0; l < SDW_MAX_LANES; l++) {
if (l > 0 && !bus->lane_used_bandwidth[l])
if (l > 0 && !bus->params.lane_used_bandwidth[l])
continue;
/* reset column_needed for each lane */
column_needed = 0;
Expand Down Expand Up @@ -509,7 +509,7 @@ static int get_manager_lane(struct sdw_bus *bus, struct sdw_master_runtime *m_rt
m_rt->stream->params.bps;
}
if (required_bandwidth <=
curr_dr_freq - bus->lane_used_bandwidth[l]) {
curr_dr_freq - bus->params.lane_used_bandwidth[l]) {
/* Check if m_lane is connected to all Peripherals */
if (!is_lane_connected_to_all_peripherals(m_rt,
slave_prop->lane_maps[l])) {
Expand All @@ -520,7 +520,7 @@ static int get_manager_lane(struct sdw_bus *bus, struct sdw_master_runtime *m_rt
}
m_lane = slave_prop->lane_maps[l];
dev_dbg(&s_rt->slave->dev, "M lane %d is used\n", m_lane);
bus->lane_used_bandwidth[l] += required_bandwidth;
bus->params.lane_used_bandwidth[l] += required_bandwidth;
/*
* Use non-zero manager lane, subtract the lane 0
* bandwidth that is already calculated
Expand Down
21 changes: 15 additions & 6 deletions drivers/soundwire/stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -1487,19 +1487,22 @@ 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;

/* Pre-pass: snapshot original bus parameters for all masters */
list_for_each_entry(m_rt, &stream->master_list, stream_node)
m_rt->params_backup = m_rt->bus->params;

/* 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));

/* TODO: Support Asynchronous mode */
if ((prop->max_clk_freq % stream->params.rate) != 0) {
dev_err(bus->dev, "Async mode not supported\n");
return -EINVAL;
ret = -EINVAL;
goto restore_params;
}

if (update_params) {
Expand Down Expand Up @@ -1550,7 +1553,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;
Comment thread
bardliao marked this conversation as resolved.

return ret;
}

Expand Down Expand Up @@ -1802,8 +1811,8 @@ static int _sdw_deprepare_stream(struct sdw_stream_runtime *stream)
bandwidth = m_rt->stream->params.rate * hweight32(p_rt->ch_mask) *
m_rt->stream->params.bps;
multi_lane_bandwidth += bandwidth;
bus->lane_used_bandwidth[p_rt->lane] -= bandwidth;
if (!bus->lane_used_bandwidth[p_rt->lane])
bus->params.lane_used_bandwidth[p_rt->lane] -= bandwidth;
if (!bus->params.lane_used_bandwidth[p_rt->lane])
p_rt->lane = 0;
}
/* TODO: Update this during Device-Device support */
Expand Down
4 changes: 2 additions & 2 deletions include/linux/soundwire/sdw.h
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,7 @@ enum sdw_port_prep_ops {
* @bandwidth: Current bandwidth
* @col: Active columns
* @row: Active rows
* @lane_used_bandwidth: how much bandwidth in bits per second is used by each lane
* @s_data_mode: NORMAL, STATIC or PRBS mode for all Slave ports
* @m_data_mode: NORMAL, STATIC or PRBS mode for all Master ports. The value
* should be the same to detect transmission issues, but can be different to
Expand All @@ -605,6 +606,7 @@ struct sdw_bus_params {
unsigned int bandwidth;
unsigned int col;
unsigned int row;
unsigned int lane_used_bandwidth[SDW_MAX_LANES];
int s_data_mode;
int m_data_mode;
};
Expand Down Expand Up @@ -1030,7 +1032,6 @@ struct sdw_stream_runtime {
* @multi_link: Store bus property that indicates if multi links
* are supported. This flag is populated by drivers after reading
* appropriate firmware (ACPI/DT).
* @lane_used_bandwidth: how much bandwidth in bits per second is used by each lane
* @is_present: indicates whether any peripheral is present on the bus.
*/
struct sdw_bus {
Expand Down Expand Up @@ -1067,7 +1068,6 @@ struct sdw_bus {
struct dentry *debugfs;
#endif
bool multi_link;
unsigned int lane_used_bandwidth[SDW_MAX_LANES];
bool is_present;
};

Expand Down
Loading