Skip to content

Commit 619b6ae

Browse files
committed
soundwire: generic_bandwidth_allocation: update bpt_hstop
Update bus->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 cd4fb77 commit 619b6ae

2 files changed

Lines changed: 44 additions & 7 deletions

File tree

drivers/soundwire/generic_bandwidth_allocation.c

Lines changed: 41 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->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->bpt_hstop = hstop;
235+
}
226236
}
227237
}
228238
}
@@ -419,7 +429,7 @@ static int sdw_compute_port_params(struct sdw_bus *bus, struct sdw_stream_runtim
419429
if (ret < 0)
420430
goto free_params;
421431

422-
_sdw_compute_port_params(bus, params, group.count);
432+
_sdw_compute_port_params(bus, params, group.count, stream->type == SDW_STREAM_BPT);
423433

424434
free_params:
425435
kfree(params);
@@ -682,6 +692,10 @@ static int sdw_compute_bus_params(struct sdw_bus *bus)
682692
return 0;
683693
}
684694

695+
#define SDW_DEFAULT_COL 4
696+
#define SDW_COL_RESERVED_FOR_AUDIO 2
697+
698+
685699
/**
686700
* sdw_compute_params: Compute bus, transport and port parameters
687701
*
@@ -697,10 +711,20 @@ int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream)
697711
if (ret < 0)
698712
return ret;
699713

700-
bus->bpt_hstop = bus->params.col - 1;
701-
if (stream->type == SDW_STREAM_BPT) {
702-
sdw_compute_dp0_port_params(bus);
703-
return 0;
714+
if (stream->type == SDW_STREAM_BPT && stream->state == SDW_STREAM_CONFIGURED) {
715+
/*
716+
* Set the initial bpt_hstop when the BPT stream is preparing and it will be
717+
* updated in sdw_compute_port_params() below.
718+
*/
719+
bus->bpt_hstop = bus->params.col - 1;
720+
/*
721+
* Reserve 2 columns for future audio stream if the bus->params.col is greater
722+
* than SDW_DEFAULT_COL (4) + reserved columns (2). And don't reserve columns
723+
* for future use otherwise. This ensures that the BPT stream will not meet the
724+
* bandwidth issue when there is no audio stream is open.
725+
*/
726+
if (bus->params.col >= (SDW_DEFAULT_COL + SDW_COL_RESERVED_FOR_AUDIO))
727+
bus->bpt_hstop -= SDW_COL_RESERVED_FOR_AUDIO;
704728
}
705729

706730
/* Compute transport and port params */
@@ -710,6 +734,16 @@ int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream)
710734
return ret;
711735
}
712736

737+
if (stream->type == SDW_STREAM_BPT && stream->state == SDW_STREAM_CONFIGURED) {
738+
/* No usable data columns left */
739+
if (bus->bpt_hstop < 1) {
740+
dev_err(bus->dev, "%s: No bandwidth for BPT stream\n",
741+
__func__);
742+
return -EAGAIN;
743+
}
744+
sdw_compute_dp0_port_params(bus);
745+
}
746+
713747
return 0;
714748
}
715749
EXPORT_SYMBOL(sdw_compute_params);

drivers/soundwire/stream.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1480,13 +1480,15 @@ static int _sdw_prepare_stream(struct sdw_stream_runtime *stream,
14801480
struct sdw_bus *bus;
14811481
struct sdw_master_prop *prop;
14821482
struct sdw_bus_params params;
1483+
int prev_bpt_hstop;
14831484
int ret;
14841485

14851486
/* Prepare Master(s) and Slave(s) port(s) associated with stream */
14861487
list_for_each_entry(m_rt, &stream->master_list, stream_node) {
14871488
bus = m_rt->bus;
14881489
prop = &bus->prop;
14891490
memcpy(&params, &bus->params, sizeof(params));
1491+
prev_bpt_hstop = bus->bpt_hstop;
14901492

14911493
/* TODO: Support Asynchronous mode */
14921494
if ((prop->max_clk_freq % stream->params.rate) != 0) {
@@ -1546,6 +1548,7 @@ static int _sdw_prepare_stream(struct sdw_stream_runtime *stream,
15461548

15471549
restore_params:
15481550
memcpy(&bus->params, &params, sizeof(params));
1551+
bus->bpt_hstop = prev_bpt_hstop;
15491552
return ret;
15501553
}
15511554

0 commit comments

Comments
 (0)