Skip to content

Commit 15cca8e

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 d463cba commit 15cca8e

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
}
@@ -417,7 +427,7 @@ static int sdw_compute_port_params(struct sdw_bus *bus, struct sdw_stream_runtim
417427
if (ret < 0)
418428
goto free_params;
419429

420-
_sdw_compute_port_params(bus, params, group.count);
430+
_sdw_compute_port_params(bus, params, group.count, stream->type == SDW_STREAM_BPT);
421431

422432
free_params:
423433
kfree(params);
@@ -680,6 +690,10 @@ static int sdw_compute_bus_params(struct sdw_bus *bus)
680690
return 0;
681691
}
682692

693+
#define SDW_DEFAULT_COL 4
694+
#define SDW_COL_RESERVED_FOR_AUDIO 2
695+
696+
683697
/**
684698
* sdw_compute_params: Compute bus, transport and port parameters
685699
*
@@ -695,10 +709,20 @@ int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream)
695709
if (ret < 0)
696710
return ret;
697711

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

704728
/* Compute transport and port params */
@@ -708,6 +732,16 @@ int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream)
708732
return ret;
709733
}
710734

735+
if (stream->type == SDW_STREAM_BPT && stream->state == SDW_STREAM_CONFIGURED) {
736+
/* No usable data columns left */
737+
if (bus->bpt_hstop < 1) {
738+
dev_err(bus->dev, "%s: No bandwidth for BPT stream\n",
739+
__func__);
740+
return -EAGAIN;
741+
}
742+
sdw_compute_dp0_port_params(bus);
743+
}
744+
711745
return 0;
712746
}
713747
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)