Skip to content

Commit 3ec94d6

Browse files
committed
soundwire: subtract BPT columns in bandwidth calculation
When a BPT stream is running, we should subtract the columns that is used by the BPT stream in bandwidth calculation. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
1 parent 82b6d10 commit 3ec94d6

1 file changed

Lines changed: 38 additions & 4 deletions

File tree

drivers/soundwire/generic_bandwidth_allocation.c

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -267,8 +267,16 @@ static int sdw_compute_group_params(struct sdw_bus *bus,
267267
*/
268268
if (m_rt->stream->state != SDW_STREAM_ENABLED &&
269269
m_rt->stream->state != SDW_STREAM_PREPARED &&
270-
m_rt->stream->state != SDW_STREAM_DISABLED)
270+
m_rt->stream->state != SDW_STREAM_DISABLED) {
271271
continue;
272+
} else if (m_rt->stream->type == SDW_STREAM_BPT) {
273+
/*
274+
* If any BPT stream is running, exclude the BPT columns
275+
* BPT: col 0.. bus->bpt_hstop
276+
* Audio: col bus->bpt_hstop + 1 .. bus->params.col - 1
277+
*/
278+
sel_col = bus->params.col - bus->bpt_hstop - 1;
279+
}
272280
}
273281

274282
/* Don't count BPT stream bandwidth, it will use the remaining bandwidth */
@@ -303,8 +311,12 @@ static int sdw_compute_group_params(struct sdw_bus *bus,
303311
/* There is no control column for lane 1 and above */
304312
if (column_needed > sel_col)
305313
return -EINVAL;
306-
/* Column 0 is control column on lane 0 */
307-
if (params[i].lane == 0 && column_needed > sel_col - 1)
314+
/*
315+
* Column 0 is control column on lane 0, but sel_col is already excludes
316+
* column 0 when it is less than bus->params.col.
317+
*/
318+
if (sel_col < bus->params.col && params[i].lane == 0 &&
319+
column_needed > sel_col - 1)
308320
return -EINVAL;
309321
}
310322
}
@@ -570,8 +582,10 @@ static int sdw_compute_bus_params(struct sdw_bus *bus)
570582
struct sdw_master_runtime *m_rt;
571583
struct sdw_slave_runtime *s_rt;
572584
unsigned int curr_dr_freq = 0;
585+
bool is_bpt_running = false;
573586
int i, l, clk_values, ret;
574587
bool is_gear = false;
588+
int available_col;
575589
int m_lane = 0;
576590
u32 *clk_buf;
577591

@@ -596,6 +610,12 @@ static int sdw_compute_bus_params(struct sdw_bus *bus)
596610
m_rt->stream->state < SDW_STREAM_DEPREPARED) {
597611
clk_values = 1;
598612
clk_buf = NULL;
613+
/*
614+
* If any BPT stream is active, the available audio columns should exclude
615+
* the BPT columns
616+
*/
617+
if (m_rt->stream->state >= SDW_STREAM_PREPARED)
618+
is_bpt_running = true;
599619
}
600620
}
601621

@@ -618,7 +638,21 @@ static int sdw_compute_bus_params(struct sdw_bus *bus)
618638

619639
total_col = curr_dr_freq / mstr_prop->default_frame_rate / mstr_prop->default_row;
620640

621-
if (curr_dr_freq * (total_col - 1) >=
641+
/*
642+
* available columns for audio stream on lane 0:
643+
* - exclude control column 0
644+
* - if BPT is active, also exclude columns 1..bpt_hstop used by DP0
645+
*/
646+
if (is_bpt_running)
647+
available_col = total_col - bus->bpt_hstop - 1;
648+
else
649+
available_col = total_col - 1;
650+
651+
if (available_col <= 0)
652+
continue;
653+
654+
/* Keep formula consistent with sdw_select_row_col() */
655+
if (curr_dr_freq * available_col >=
622656
bus->params.bandwidth * total_col)
623657
break;
624658

0 commit comments

Comments
 (0)