@@ -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
424434free_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}
715749EXPORT_SYMBOL (sdw_compute_params );
0 commit comments