[PATCH 08/11] soundwire: generic_bandwidth_allocation: fix hwidth for skipped block offset
From: Vijendar Mukunda
Date: Sat Nov 07 2026 - 17:14:15 EST
The hwidth computation in sdw_compute_group_params() used bare
payload_bw when calculating the horizontal columns required for a
stream group. The generic transport programming starts payload block
offsets from block_offset 1, so offset 0 is skipped. Without
accounting for that skipped offset, some frame configurations can
program an hstart/hstop payload window that is too narrow.
Introduce sdw_compute_hwidth() which adds 1 to payload_bw before
the ceiling division to account for the skipped slot. Also skip
groups with zero payload_bw before calling sdw_compute_hwidth(),
and skip groups with a resulting hwidth of 0 to avoid emitting
an invalid hstart/hstop range.
Fixes: 9026118f20e2 ("soundwire: Add generic bandwidth allocation algorithm")
Signed-off-by: Poojitha N <Poojitha.N@xxxxxxx>
Signed-off-by: Vijendar Mukunda <Vijendar.Mukunda@xxxxxxx>
---
.../soundwire/generic_bandwidth_allocation.c | 17 +++++++++++++++--
1 file changed, 15 insertions(+), 2 deletions(-)
diff --git a/drivers/soundwire/generic_bandwidth_allocation.c b/drivers/soundwire/generic_bandwidth_allocation.c
index 30a495abe19e..1dd3b2e5420c 100644
--- a/drivers/soundwire/generic_bandwidth_allocation.c
+++ b/drivers/soundwire/generic_bandwidth_allocation.c
@@ -15,6 +15,12 @@
#define SDW_STRM_RATE_GROUPING 1
+static int sdw_compute_hwidth(int col, int payload_bw, int full_bw)
+{
+ /* Account for the initial skipped payload bit at block offset 0. */
+ return (col * (payload_bw + 1) + full_bw - 1) / full_bw;
+}
+
struct sdw_group_params {
unsigned int rate;
unsigned int lane;
@@ -203,6 +209,9 @@ static void _sdw_compute_port_params(struct sdw_bus *bus,
for (i = 0; i < count; i++) {
if (params[i].lane != l)
continue;
+ /* Skip inactive groups to avoid an invalid hstart/hstop range. */
+ if (!params[i].hwidth)
+ continue;
port_bo = 1;
list_for_each_entry(m_rt, &bus->m_rt_list, bus_node) {
@@ -274,9 +283,13 @@ static int sdw_compute_group_params(struct sdw_bus *bus,
for (i = 0; i < group->count; i++) {
if (params[i].lane != l)
continue;
+ /* Inactive groups must not enter the hwidth calculation. */
+ if (!params[i].payload_bw)
+ continue;
- params[i].hwidth = (sel_col * params[i].payload_bw +
- params[i].full_bw - 1) / params[i].full_bw;
+ params[i].hwidth =
+ sdw_compute_hwidth(sel_col, params[i].payload_bw,
+ params[i].full_bw);
column_needed += params[i].hwidth;
/* There is no control column for lane 1 and above */
--
2.53.0