@@ -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}
@@ -421,7 +431,7 @@ static int sdw_compute_port_params(struct sdw_bus *bus, struct sdw_stream_runtim
421431 if (ret < 0 )
422432 goto free_params ;
423433
424- _sdw_compute_port_params (bus , params , group .count );
434+ _sdw_compute_port_params (bus , params , group .count , stream -> type == SDW_STREAM_BPT );
425435
426436free_params :
427437 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 ) {
736+ /* If there is only one column left, just use normal write. */
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}
713747EXPORT_SYMBOL (sdw_compute_params );
0 commit comments