@@ -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 *
@@ -691,10 +705,20 @@ int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream)
691705 if (ret < 0 )
692706 return ret ;
693707
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 ;
708+ if (stream -> type == SDW_STREAM_BPT && stream -> state == SDW_STREAM_CONFIGURED ) {
709+ /*
710+ * Set the initial bpt_hstop when the BPT stream is preparing and it will be
711+ * updated in sdw_compute_port_params() below.
712+ */
713+ bus -> bpt_hstop = bus -> params .col - 1 ;
714+ /*
715+ * Reserve 2 columns for future audio stream if the bus->params.col is greater
716+ * than SDW_DEFAULT_COL (4) + reserved columns (2). And don't reserve columns
717+ * for future use otherwise. This ensures that the BPT stream will not meet the
718+ * bandwidth issue when there is no audio stream is open.
719+ */
720+ if (bus -> params .col >= (SDW_DEFAULT_COL + SDW_COL_RESERVED_FOR_AUDIO ))
721+ bus -> bpt_hstop -= SDW_COL_RESERVED_FOR_AUDIO ;
698722 }
699723
700724 /* Compute transport and port params */
@@ -704,6 +728,16 @@ int sdw_compute_params(struct sdw_bus *bus, struct sdw_stream_runtime *stream)
704728 return ret ;
705729 }
706730
731+ if (stream -> type == SDW_STREAM_BPT ) {
732+ /* If there is only one column left, just use normal write. */
733+ if (bus -> bpt_hstop < 1 ) {
734+ dev_err (bus -> dev , "%s: No bandwidth for BPT stream\n" ,
735+ __func__ );
736+ return - EAGAIN ;
737+ }
738+ sdw_compute_dp0_port_params (bus );
739+ }
740+
707741 return 0 ;
708742}
709743EXPORT_SYMBOL (sdw_compute_params );
0 commit comments