@@ -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
427437free_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,20 @@ 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+ if (stream -> type == SDW_STREAM_BPT && stream -> state == SDW_STREAM_CONFIGURED ) {
718+ /*
719+ * Set the initial bpt_hstop when the BPT stream is preparing and it will be
720+ * updated in sdw_compute_port_params() below.
721+ */
722+ bus -> params .bpt_hstop = bus -> params .col - 1 ;
723+ /*
724+ * Reserve 2 columns for future audio stream if the bus->params.col is greater
725+ * than SDW_DEFAULT_COL (4) + reserved columns (2). And don't reserve columns
726+ * for future use otherwise. This ensures that the BPT stream will not meet the
727+ * bandwidth issue when there is no audio stream is open.
728+ */
729+ if (bus -> params .col >= (SDW_DEFAULT_COL + SDW_COL_RESERVED_FOR_AUDIO ))
730+ bus -> params .bpt_hstop -= SDW_COL_RESERVED_FOR_AUDIO ;
707731 }
708732
709733 /* Compute transport and port params */
@@ -713,6 +737,16 @@ int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream)
713737 return ret ;
714738 }
715739
740+ if (stream -> type == SDW_STREAM_BPT && stream -> state == SDW_STREAM_CONFIGURED ) {
741+ /* No usable data columns left */
742+ if (bus -> params .bpt_hstop < 1 ) {
743+ dev_err (bus -> dev , "%s: No bandwidth for BPT stream\n" ,
744+ __func__ );
745+ return - EAGAIN ;
746+ }
747+ sdw_compute_dp0_port_params (bus );
748+ }
749+
716750 return 0 ;
717751}
718752EXPORT_SYMBOL (sdw_compute_params );
0 commit comments