]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
soundwire: Move wait for initialisation helper to header
authorCharles Keepax <ckeepax@opensource.cirrus.com>
Tue, 23 Jun 2026 10:18:10 +0000 (11:18 +0100)
committerMark Brown <broonie@kernel.org>
Tue, 23 Jun 2026 11:52:30 +0000 (12:52 +0100)
As SoundWire devices tend to enumerate on the bus after probe, drivers
frequently need to wait for the device to initialise from common driver
code. The common system is to split drivers into a core module and then
a module for each communication bus. These two facts tend to cause
Kconfig issues, the issue tends to be when SOUNDWIRE=m and DRIVER_I2C=y,
this usually selects DRIVER=y. The driver code then wants to call
sdw_slave_wait_for_init(), but this results in calling a module function
from built in code. A depends on SOUNDWIRE | !SOUNDWIRE could be added to
the end driver but this seems slightly off as it adds a lot of counter
intuitive depends.

A simpler solution is to make sdw_slave_wait_for_init() a static inline
function. As part of doing this add a check for the slave device being
NULL acknowledging that this is likely called from code that is shared
between control buses. It does require dropping the call to
sdw_show_ping_status() but this can be added back in end drivers that
used it originally.

Currently this is causing rand config issues on RT5682 and will soon
also cause similar problems on cs42l43.

Acked-by: Vinod Koul <vkoul@kernel.org>
Acked-by: Arnd Bergmann <arnd@arndb.de>
Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
Link: https://patch.msgid.link/20260623101814.24044-2-ckeepax@opensource.cirrus.com
Signed-off-by: Mark Brown <broonie@kernel.org>
drivers/soundwire/bus.c
include/linux/soundwire/sdw.h

index b7bdf19ebb42e6504fa6c05058c78b857c59da94..fe5316d93fefe7f2b49d788352f7bdd41b878fd0 100644 (file)
@@ -1372,34 +1372,6 @@ int sdw_slave_get_current_bank(struct sdw_slave *slave)
 }
 EXPORT_SYMBOL_GPL(sdw_slave_get_current_bank);
 
-/**
- * sdw_slave_wait_for_init - Wait for device initialisation
- * @slave: Pointer to the SoundWire peripheral.
- * @timeout_ms: Timeout in milliseconds.
- *
- * Wait for a peripheral device to enumerate and be initialised by the
- * SoundWire core.
- *
- * Return: Zero on success, and a negative error code on failure.
- */
-int sdw_slave_wait_for_init(struct sdw_slave *slave, int timeout_ms)
-{
-       unsigned long time;
-
-       time = wait_for_completion_timeout(&slave->initialization_complete,
-                                          msecs_to_jiffies(timeout_ms));
-       if (!time) {
-               dev_err(&slave->dev, "Initialization not complete\n");
-               sdw_show_ping_status(slave->bus, true);
-               return -ETIMEDOUT;
-       }
-
-       slave->unattach_request = 0;
-
-       return 0;
-}
-EXPORT_SYMBOL_GPL(sdw_slave_wait_for_init);
-
 static int sdw_slave_set_frequency(struct sdw_slave *slave)
 {
        int scale_index;
index a46cbaec5949122100d42c793f65273bd905356a..b484784e2690de02e5bfb40506273df16cfcef1a 100644 (file)
@@ -11,6 +11,7 @@
 #include <linux/idr.h>
 #include <linux/irq.h>
 #include <linux/irqdomain.h>
+#include <linux/jiffies.h>
 #include <linux/lockdep_types.h>
 #include <linux/mod_devicetable.h>
 #include <linux/mutex.h>
@@ -1093,8 +1094,6 @@ int sdw_slave_get_current_bank(struct sdw_slave *sdev);
 
 int sdw_slave_get_scale_index(struct sdw_slave *slave, u8 *base);
 
-int sdw_slave_wait_for_init(struct sdw_slave *slave, int timeout_ms);
-
 /* messaging and data APIs */
 int sdw_read(struct sdw_slave *slave, u32 addr);
 int sdw_write(struct sdw_slave *slave, u32 addr, u8 value);
@@ -1138,12 +1137,6 @@ static inline int sdw_slave_get_current_bank(struct sdw_slave *sdev)
        return -EINVAL;
 }
 
-static inline int sdw_slave_wait_for_init(struct sdw_slave *slave, int timeout_ms)
-{
-       WARN_ONCE(1, "SoundWire API is disabled");
-       return -EINVAL;
-}
-
 /* messaging and data APIs */
 static inline int sdw_read(struct sdw_slave *slave, u32 addr)
 {
@@ -1207,4 +1200,33 @@ static inline int sdw_update_no_pm(struct sdw_slave *slave, u32 addr, u8 mask, u
 
 #endif /* CONFIG_SOUNDWIRE */
 
+/**
+ * sdw_slave_wait_for_init - Wait for device initialisation
+ * @slave: Pointer to the SoundWire peripheral.
+ * @timeout_ms: Timeout in milliseconds.
+ *
+ * Wait for a peripheral device to enumerate and be initialised by the
+ * SoundWire core.
+ *
+ * Return: Zero on success, and a negative error code on failure.
+ */
+static inline int sdw_slave_wait_for_init(struct sdw_slave *slave, int timeout_ms)
+{
+       unsigned long time;
+
+       if (!slave)
+               return 0;
+
+       time = wait_for_completion_timeout(&slave->initialization_complete,
+                                          msecs_to_jiffies(timeout_ms));
+       if (!time) {
+               dev_err(&slave->dev, "Initialization not complete\n");
+               return -ETIMEDOUT;
+       }
+
+       slave->unattach_request = 0;
+
+       return 0;
+}
+
 #endif /* __SOUNDWIRE_H */