The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Charles Keepax <ckeepax@opensource.cirrus.com>
To: broonie@kernel.org, vkoul@kernel.org
Cc: lgirdwood@gmail.com, pierre-louis.bossart@linux.dev,
	yung-chuan.liao@linux.intel.com, peter.ujfalusi@linux.intel.com,
	oder_chiou@realtek.com, jack.yu@realtek.com,
	shumingf@realtek.com, niranjan.hy@ti.com, shenghao-ding@ti.com,
	kevin-lu@ti.com, baojun.xu@ti.com, sen@ti.com,
	linux-sound@vger.kernel.org, linux-kernel@vger.kernel.org,
	patches@opensource.cirrus.com
Subject: [PATCH v2 01/18] soundwire: Add a helper function to wait for device initialisation
Date: Mon, 11 May 2026 15:10:12 +0100	[thread overview]
Message-ID: <20260511141029.851125-2-ckeepax@opensource.cirrus.com> (raw)
In-Reply-To: <20260511141029.851125-1-ckeepax@opensource.cirrus.com>

Add a new helper function to wait for the device to enumerate
and be initialised by the SoundWire core. Most of the SoundWire
drivers have very similar boiler plate code in their runtime
resume, and that boiler plate tends to access various internals
of the SoundWire structs which is a mild layering violation.

Adding a new core helper function greatly eases both of these
issues.

Signed-off-by: Charles Keepax <ckeepax@opensource.cirrus.com>
---

Changes since v1:
 - Add stub for when soundwire not built in.
 - Add missing kerneldoc

 drivers/soundwire/bus.c       | 31 +++++++++++++++++++++++++++++++
 include/linux/soundwire/sdw.h |  8 ++++++++
 2 files changed, 39 insertions(+)

diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c
index fe5316d93fefe..037c51a3874ea 100644
--- a/drivers/soundwire/bus.c
+++ b/drivers/soundwire/bus.c
@@ -1372,6 +1372,37 @@ 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_us: Timeout in microseconds.
+ *
+ * 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_us)
+{
+	unsigned long time;
+
+	if (!slave->unattach_request)
+		return 0;
+
+	time = wait_for_completion_timeout(&slave->initialization_complete,
+					   msecs_to_jiffies(timeout_us));
+	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;
diff --git a/include/linux/soundwire/sdw.h b/include/linux/soundwire/sdw.h
index 6147eb1fb210d..7e5818d989294 100644
--- a/include/linux/soundwire/sdw.h
+++ b/include/linux/soundwire/sdw.h
@@ -1093,6 +1093,8 @@ 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);
+
 /* messaging and data APIs */
 int sdw_read(struct sdw_slave *slave, u32 addr);
 int sdw_write(struct sdw_slave *slave, u32 addr, u8 value);
@@ -1136,6 +1138,12 @@ 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)
+{
+	WARN_ONCE(1, "SoundWire API is disabled");
+	return -EINVAL;
+}
+
 /* messaging and data APIs */
 static inline int sdw_read(struct sdw_slave *slave, u32 addr)
 {
-- 
2.47.3


  reply	other threads:[~2026-05-11 14:11 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 14:10 [PATCH v2 00/18] Add a new SoundWire enumeration helper Charles Keepax
2026-05-11 14:10 ` Charles Keepax [this message]
2026-05-11 16:21   ` [PATCH v2 01/18] soundwire: Add a helper function to wait for device initialisation Vinod Koul
2026-05-12  0:51   ` Mark Brown
2026-05-12  8:39     ` Charles Keepax
2026-05-11 14:10 ` [PATCH v2 02/18] ASoC: cs35l56: Use new SoundWire enumeration helper Charles Keepax
2026-05-11 14:10 ` [PATCH v2 03/18] ASoC: cs42l42: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 04/18] ASoC: max98363: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 05/18] ASoC: max98373: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 06/18] ASoC: rt700: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 07/18] ASoC: rt711: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 08/18] ASoC: rt712: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 09/18] ASoC: rt715: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 10/18] ASoc: rt721: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 11/18] ASoC: rt722: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 12/18] ASoC: rt1017: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 13/18] ASoC: rt1308: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 14/18] ASoC: rt1316: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 15/18] ASoC: rt1318: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 16/18] ASoC: rt1320: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 17/18] ASoC: rt5682: " Charles Keepax
2026-05-11 14:10 ` [PATCH v2 18/18] ASoC: tas2783: " Charles Keepax

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260511141029.851125-2-ckeepax@opensource.cirrus.com \
    --to=ckeepax@opensource.cirrus.com \
    --cc=baojun.xu@ti.com \
    --cc=broonie@kernel.org \
    --cc=jack.yu@realtek.com \
    --cc=kevin-lu@ti.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-sound@vger.kernel.org \
    --cc=niranjan.hy@ti.com \
    --cc=oder_chiou@realtek.com \
    --cc=patches@opensource.cirrus.com \
    --cc=peter.ujfalusi@linux.intel.com \
    --cc=pierre-louis.bossart@linux.dev \
    --cc=sen@ti.com \
    --cc=shenghao-ding@ti.com \
    --cc=shumingf@realtek.com \
    --cc=vkoul@kernel.org \
    --cc=yung-chuan.liao@linux.intel.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox