@@ -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
422432free_params :
423433 kfree (params );
@@ -676,6 +686,10 @@ static int sdw_compute_bus_params(struct sdw_bus *bus)
676686 return 0 ;
677687}
678688
689+ #define SDW_DEFAULT_COL 4
690+ #define SDW_COL_RESERVED_FOR_AUDIO 2
691+
692+
679693/**
680694 * sdw_compute_params: Compute bus, transport and port parameters
681695 *
@@ -684,17 +698,28 @@ static int sdw_compute_bus_params(struct sdw_bus *bus)
684698 */
685699int sdw_compute_params (struct sdw_bus * bus , struct sdw_stream_runtime * stream )
686700{
701+ int prev_bpt_hstop = bus -> bpt_hstop ;
687702 int ret ;
688703
689704 /* Computes clock frequency, frame shape and frame frequency */
690705 ret = sdw_compute_bus_params (bus );
691706 if (ret < 0 )
692707 return ret ;
693708
694- bus -> bpt_hstop = bus -> params .col - 1 ;
695- if (stream -> type == SDW_STREAM_BPT ) {
696- sdw_compute_dp0_port_params (bus );
697- return 0 ;
709+ if (stream -> type == SDW_STREAM_BPT && stream -> state == SDW_STREAM_CONFIGURED ) {
710+ /*
711+ * Set the initial bpt_hstop when the BPT stream is preparing and it will be
712+ * updated in sdw_compute_port_params() below.
713+ */
714+ bus -> bpt_hstop = bus -> params .col - 1 ;
715+ /*
716+ * Reserve 2 columns for future audio stream if the bus->params.col is greater
717+ * than SDW_DEFAULT_COL (4) + reserved columns (2). And don't reserve columns
718+ * for future use otherwise. This ensures that the BPT stream will not meet the
719+ * bandwidth issue when there is no audio stream is open.
720+ */
721+ if (bus -> params .col >= (SDW_DEFAULT_COL + SDW_COL_RESERVED_FOR_AUDIO ))
722+ bus -> bpt_hstop -= SDW_COL_RESERVED_FOR_AUDIO ;
698723 }
699724
700725 /* Compute transport and port params */
@@ -704,6 +729,17 @@ int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream)
704729 return ret ;
705730 }
706731
732+ if (stream -> type == SDW_STREAM_BPT ) {
733+ /* No usable data columns left */
734+ if (bus -> bpt_hstop < 1 ) {
735+ dev_err (bus -> dev , "%s: No bandwidth for BPT stream\n" ,
736+ __func__ );
737+ bus -> bpt_hstop = prev_bpt_hstop ;
738+ return - EAGAIN ;
739+ }
740+ sdw_compute_dp0_port_params (bus );
741+ }
742+
707743 return 0 ;
708744}
709745EXPORT_SYMBOL (sdw_compute_params );
0 commit comments