Skip to content

Commit 97d68a4

Browse files
committed
soundwire: update bpt_hstop
Update bus->params.bpt_hstop to record the hstop of the BPT stream. And return -EAGAIN when there is no bandwidth for the BPT stream. Signed-off-by: Bard Liao <yung-chuan.liao@linux.intel.com>
1 parent 7efcda4 commit 97d68a4

1 file changed

Lines changed: 46 additions & 7 deletions

File tree

drivers/soundwire/generic_bandwidth_allocation.c

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -190,8 +190,8 @@ static void sdw_compute_master_ports(struct sdw_master_runtime *m_rt,
190190
sdw_compute_slave_ports(m_rt, &t_data);
191191
}
192192

193-
static void _sdw_compute_port_params(struct sdw_bus *bus,
194-
struct sdw_group_params *params, int count)
193+
static void _sdw_compute_port_params(struct sdw_bus *bus, struct sdw_group_params *params,
194+
int count, bool update_bpt_hstop)
195195
{
196196
struct sdw_master_runtime *m_rt;
197197
int port_bo, i, l;
@@ -223,6 +223,16 @@ static void _sdw_compute_port_params(struct sdw_bus *bus,
223223
}
224224

225225
hstop = hstop - params[i].hwidth;
226+
if (l == 0 && update_bpt_hstop && bus->params.bpt_hstop > hstop) {
227+
/* Assume BPT stream uses lane 0 */
228+
/*
229+
* hstart = hstop - params->hwidth + 1.
230+
* At this point after hstop = hstop - params[i].hwidth above,
231+
* the hstart is equal to hstop + 1, and bus->bpt_hstop should
232+
* be hstart - 1. so we can set bpt_hstop to hstop directly.
233+
*/
234+
bus->params.bpt_hstop = hstop;
235+
}
226236
}
227237
}
228238
}
@@ -422,7 +432,7 @@ static int sdw_compute_port_params(struct sdw_bus *bus, struct sdw_stream_runtim
422432
if (ret < 0)
423433
goto free_params;
424434

425-
_sdw_compute_port_params(bus, params, group.count);
435+
_sdw_compute_port_params(bus, params, group.count, stream->type == SDW_STREAM_BPT);
426436

427437
free_params:
428438
kfree(params);
@@ -685,6 +695,10 @@ static int sdw_compute_bus_params(struct sdw_bus *bus)
685695
return 0;
686696
}
687697

698+
#define SDW_DEFAULT_COL 4
699+
#define SDW_COL_RESERVED_FOR_AUDIO 2
700+
701+
688702
/**
689703
* sdw_compute_params: Compute bus, transport and port parameters
690704
*
@@ -700,10 +714,25 @@ int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream)
700714
if (ret < 0)
701715
return ret;
702716

703-
bus->params.bpt_hstop = bus->params.col - 1;
704-
if (stream->type == SDW_STREAM_BPT) {
705-
sdw_compute_dp0_port_params(bus);
706-
return 0;
717+
/*
718+
* stream->state is set to SDW_STREAM_DEPREPARED at the beginning of _sdw_deprepare_stream
719+
* In other words, if the stream->type != SDW_STREAM_DEPAREPARED means sdw_compute_params()
720+
* is called from _sdw_prepare_stream() and the stream is preparing.
721+
*/
722+
if (stream->type == SDW_STREAM_BPT && stream->state != SDW_STREAM_DEPREPARED) {
723+
/*
724+
* Set the initial bpt_hstop when the BPT stream is preparing and it will be
725+
* updated in sdw_compute_port_params() below.
726+
*/
727+
bus->params.bpt_hstop = bus->params.col - 1;
728+
/*
729+
* Reserve 2 columns for future audio stream if the bus->params.col is greater
730+
* than SDW_DEFAULT_COL (4) + reserved columns (2). And don't reserve columns
731+
* for future use otherwise. This ensures that the BPT stream will not meet the
732+
* bandwidth issue when there is no audio stream is open.
733+
*/
734+
if (bus->params.col >= (SDW_DEFAULT_COL + SDW_COL_RESERVED_FOR_AUDIO))
735+
bus->params.bpt_hstop -= SDW_COL_RESERVED_FOR_AUDIO;
707736
}
708737

709738
/* Compute transport and port params */
@@ -713,6 +742,16 @@ int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream)
713742
return ret;
714743
}
715744

745+
if (stream->type == SDW_STREAM_BPT && stream->state != SDW_STREAM_DEPREPARED) {
746+
/* No usable data columns left */
747+
if (bus->params.bpt_hstop < 1) {
748+
dev_err(bus->dev, "%s: No bandwidth for BPT stream\n",
749+
__func__);
750+
return -EAGAIN;
751+
}
752+
sdw_compute_dp0_port_params(bus);
753+
}
754+
716755
return 0;
717756
}
718757
EXPORT_SYMBOL(sdw_compute_params);

0 commit comments

Comments
 (0)