[PATCH 01/15] soundwire: add sdw_slave_wait_for_initialization helper

From: Bard Liao
Date: Thu Jun 26 2025 - 07:58:17 EST


waiting for slave->initialization_complete is commonly used by SoundWire
codec drivers. Add a helper to reduce the duplicated code.

Signed-off-by: Bard Liao <yung-chuan.liao@xxxxxxxxxxxxxxx>
Reviewed-by: Shuming Fan <shumingf@xxxxxxxxxxx>
Reviewed-by: Charles Keepax <ckeepax@xxxxxxxxxxxxxxxxxxxxx>
---
drivers/soundwire/slave.c | 17 +++++++++++++++++
include/linux/soundwire/sdw.h | 1 +
2 files changed, 18 insertions(+)

diff --git a/drivers/soundwire/slave.c b/drivers/soundwire/slave.c
index d2d99555ec5a..5d45adb28491 100644
--- a/drivers/soundwire/slave.c
+++ b/drivers/soundwire/slave.c
@@ -104,6 +104,23 @@ int sdw_slave_add(struct sdw_bus *bus,
}
EXPORT_SYMBOL(sdw_slave_add);

+int sdw_slave_wait_for_initialization(struct sdw_slave *slave, unsigned int timeout)
+{
+ unsigned long time;
+
+ time = wait_for_completion_timeout(&slave->initialization_complete,
+ msecs_to_jiffies(timeout));
+ if (!time) {
+ dev_err(&slave->dev, "%s: Initialization not complete, timed out\n", __func__);
+ sdw_show_ping_status(slave->bus, true);
+
+ return -ETIMEDOUT;
+ }
+
+ return 0;
+}
+EXPORT_SYMBOL(sdw_slave_wait_for_initialization);
+
#if IS_ENABLED(CONFIG_ACPI)

static bool find_slave(struct sdw_bus *bus,
diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
index 0832776262ac..961a10af12c1 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -1087,6 +1087,7 @@ int sdw_stream_remove_slave(struct sdw_slave *slave,
struct sdw_stream_runtime *stream);

int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base);
+int sdw_slave_wait_for_initialization(struct sdw_slave *slave, unsigned int timeout);

/* messaging and data APIs */
int sdw_read(struct sdw_slave *slave, u32 addr);
--
2.43.0