Skip to contentSkip to conversation

Add a new SoundWire enumeration helper

PATCH In review Charles Keepax 2 participants 20 messages May 12 – May 13

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v4 cover Add a new SoundWire enumeration helper

Add a new SoundWire enumeration helper function, many drivers have almost identical code in runtime resume so it makes sense to move this to the core.

It is worth noting this is really step one of a larger process, there are a few drivers that do more custom things and are not covered by this series. But this series picks up the low hanging fruit and moves things in a good direction.

The next step is to look at drivers that also wait at probe time, where the unattached_request flag is not going to be valid.

Thanks,
Charles

Changes since v1:
- Add a stub for sdw_slave_wait_for_init()
- Add kerneldoc for sdw_slave_wait_for_init()
- Update cs35l56 as well
- Correct bug in the update of cs42l42

Changes since v2:
- Corrected timeout_us to timeout_ms

Changes since v3:
- Actually fix kernel doc

Charles Keepax (18):
soundwire: Add a helper function to wait for device initialisation
ASoC: cs35l56: Use new SoundWire enumeration helper
ASoC: cs42l42: Use new SoundWire enumeration helper
ASoC: max98363: Use new SoundWire enumeration helper
ASoC: max98373: Use new SoundWire enumeration helper
ASoC: rt700: Use new SoundWire enumeration helper
ASoC: rt711: Use new SoundWire enumeration helper
ASoC: rt712: Use new SoundWire enumeration helper
ASoC: rt715: Use new SoundWire enumeration helper
ASoc: rt721: Use new SoundWire enumeration helper
ASoC: rt722: Use new SoundWire enumeration helper
ASoC: rt1017: Use new SoundWire enumeration helper
ASoC: rt1308: Use new SoundWire enumeration helper
ASoC: rt1316: Use new SoundWire enumeration helper
ASoC: rt1318: Use new SoundWire enumeration helper
ASoC: rt1320: Use new SoundWire enumeration helper
ASoC: rt5682: Use new SoundWire enumeration helper
ASoC: tas2783: Use new SoundWire enumeration helper

 drivers/soundwire/bus.c            | 31 ++++++++++++++++++++++++++++++
 include/linux/soundwire/sdw.h      |  8 ++++++++
 sound/soc/codecs/cs35l56-sdw.c     | 10 ++++------
 sound/soc/codecs/cs42l42-sdw.c     | 11 ++++-------
 sound/soc/codecs/max98363.c        | 17 ++++------------
 sound/soc/codecs/max98373-sdw.c    | 18 ++++-------------
 sound/soc/codecs/rt1017-sdca-sdw.c | 18 ++++-------------
 sound/soc/codecs/rt1308-sdw.c      | 18 ++++-------------
 sound/soc/codecs/rt1316-sdw.c      | 18 ++++-------------
 sound/soc/codecs/rt1318-sdw.c      | 16 ++++-----------
 sound/soc/codecs/rt1320-sdw.c      | 16 ++++-----------
 sound/soc/codecs/rt5682-sdw.c      | 16 ++++-----------
 sound/soc/codecs/rt700-sdw.c       | 18 ++++-------------
 sound/soc/codecs/rt711-sdca-sdw.c  | 16 ++++-----------
 sound/soc/codecs/rt711-sdw.c       | 14 ++++----------
 sound/soc/codecs/rt712-sdca-dmic.c | 19 ++++--------------
 sound/soc/codecs/rt712-sdca-sdw.c  | 16 ++++-----------
 sound/soc/codecs/rt715-sdca-sdw.c  | 18 ++++-------------
 sound/soc/codecs/rt715-sdw.c       | 18 ++++-------------
 sound/soc/codecs/rt721-sdca-sdw.c  | 16 ++++-----------
 sound/soc/codecs/rt722-sdca-sdw.c  | 16 ++++-----------
 sound/soc/codecs/tas2783-sdw.c     | 18 ++++-------------
 22 files changed, 119 insertions(+), 247 deletions(-)
Signature · 1 line
2.47.3
#1 lore raw

PATCH v4 1/18 soundwire: Add a helper function to wait for device initialisation

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.

---

Changes since v3:
- Actually fix kernel doc

 drivers/soundwire/bus.c       | 31 +++++++++++++++++++++++++++++++
 include/linux/soundwire/sdw.h |  8 ++++++++
 2 files changed, 39 insertions(+)
drivers/soundwire/bus.c +31 -0
index fe5316d93fefe..ea3a24f805c00 100644
@@ -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_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;
+
+	if (!slave->unattach_request)
+		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");
+		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;
include/linux/soundwire/sdw.h +8 -0
index 6147eb1fb210d..a46cbaec59491 100644
@@ -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_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);
@@ -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_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)
 {
Signature · 1 line
2.47.3
#2 lore raw

PATCH v4 2/18 ASoC: cs35l56: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/cs35l56-sdw.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
sound/soc/codecs/cs35l56-sdw.c +4 -6
index 9dc47fec1ea04..105d38b1c1878 100644
@@ -436,6 +436,7 @@ static const struct sdw_slave_ops cs35l56_sdw_ops = {
 static int __maybe_unused cs35l56_sdw_handle_unattach(struct cs35l56_private *cs35l56)
 {
 	struct sdw_slave *peripheral = cs35l56->sdw_peripheral;
+	int ret;
 
 	dev_dbg(cs35l56->base.dev, "attached:%u unattach_request:%u in_clock_stop_1:%u\n",
 		cs35l56->sdw_attached, peripheral->unattach_request, cs35l56->sdw_in_clock_stop_1);
@@ -443,13 +444,10 @@ static int __maybe_unused cs35l56_sdw_handle_unattach(struct cs35l56_private *cs
 	if (cs35l56->sdw_in_clock_stop_1 || peripheral->unattach_request) {
 		/* Cannot access registers until bus is re-initialized. */
 		dev_dbg(cs35l56->base.dev, "Wait for initialization_complete\n");
-		if (!wait_for_completion_timeout(&peripheral->initialization_complete,
-						 msecs_to_jiffies(5000))) {
-			dev_err(cs35l56->base.dev, "initialization_complete timed out\n");
-			return -ETIMEDOUT;
-		}
+		ret = sdw_slave_wait_for_init(peripheral, 5000);
+		if (ret)
+			return ret;
 
-		peripheral->unattach_request = 0;
 		cs35l56->sdw_in_clock_stop_1 = false;
 
 		/*
Signature · 1 line
2.47.3
#3 lore raw

PATCH v4 3/18 ASoC: cs42l42: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/cs42l42-sdw.c | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
sound/soc/codecs/cs42l42-sdw.c +4 -7
index d5999ad9ff9b4..b8256ce0b8fbe 100644
@@ -433,19 +433,16 @@ static const struct reg_sequence cs42l42_soft_reboot_seq[] = {
 static int cs42l42_sdw_handle_unattach(struct cs42l42_private *cs42l42)
 {
 	struct sdw_slave *peripheral = cs42l42->sdw_peripheral;
+	int ret;
 
 	if (!peripheral->unattach_request)
 		return 0;
 
 	/* Cannot access registers until master re-attaches. */
 	dev_dbg(&peripheral->dev, "Wait for initialization_complete\n");
-	if (!wait_for_completion_timeout(&peripheral->initialization_complete,
-					 msecs_to_jiffies(5000))) {
-		dev_err(&peripheral->dev, "initialization_complete timed out\n");
-		return -ETIMEDOUT;
-	}
-
-	peripheral->unattach_request = 0;
+	ret = sdw_slave_wait_for_init(peripheral, 5000);
+	if (ret)
+		return ret;
 
 	/*
 	 * After a bus reset there must be a reconfiguration reset to
Signature · 1 line
2.47.3
#4 lore raw

PATCH v4 4/18 ASoC: max98363: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/max98363.c | 17 ++++-------------
 1 file changed, 4 insertions(+), 13 deletions(-)
sound/soc/codecs/max98363.c +4 -13
index 25af78ab30d5c..099dc5bf6195f 100644
@@ -90,24 +90,15 @@ static int max98363_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct max98363_priv *max98363 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!max98363->first_hw_init)
 		return 0;
 
-	if (!slave->unattach_request)
-		goto regmap_sync;
-
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-					   msecs_to_jiffies(MAX98363_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(dev, "Initialization not complete, timed out\n");
-		return -ETIMEDOUT;
-	}
-
-regmap_sync:
+	ret = sdw_slave_wait_for_init(slave, MAX98363_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-	slave->unattach_request = 0;
 	regcache_cache_only(max98363->regmap, false);
 	regcache_sync(max98363->regmap);
 
Signature · 1 line
2.47.3
#5 lore raw

PATCH v4 5/18 ASoC: max98373: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/max98373-sdw.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
sound/soc/codecs/max98373-sdw.c +4 -14
index 16673440218cb..6829fa07c9ecb 100644
@@ -266,25 +266,15 @@ static int max98373_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct max98373_priv *max98373 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!max98373->first_hw_init)
 		return 0;
 
-	if (!slave->unattach_request)
-		goto regmap_sync;
-
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-					   msecs_to_jiffies(MAX98373_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(dev, "Initialization not complete, timed out\n");
-		sdw_show_ping_status(slave->bus, true);
-
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(slave, MAX98373_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(max98373->regmap, false);
 	regcache_sync(max98373->regmap);
 
Signature · 1 line
2.47.3
#6 lore raw

PATCH v4 6/18 ASoC: rt700: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/rt700-sdw.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
sound/soc/codecs/rt700-sdw.c +4 -14
index 9ce36a66fae1d..30fcca210f051 100644
@@ -522,25 +522,15 @@ static int rt700_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt700_priv *rt700 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt700->first_hw_init)
 		return 0;
 
-	if (!slave->unattach_request)
-		goto regmap_sync;
-
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT700_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "Initialization not complete, timed out\n");
-		sdw_show_ping_status(slave->bus, true);
-
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(slave, RT700_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt700->regmap, false);
 	regcache_sync_region(rt700->regmap, 0x3000, 0x8fff);
 	regcache_sync_region(rt700->regmap, 0x752010, 0x75206b);
Signature · 1 line
2.47.3
#7 lore raw

PATCH v4 7/18 ASoC: rt711: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/rt711-sdca-sdw.c | 16 ++++------------
 sound/soc/codecs/rt711-sdw.c      | 14 ++++----------
 2 files changed, 8 insertions(+), 22 deletions(-)
sound/soc/codecs/rt711-sdca-sdw.c +4 -12
index 49dacceddf815..a8164fc3979ab 100644
@@ -438,7 +438,7 @@ static int rt711_sdca_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt711_sdca_priv *rt711 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt711->first_hw_init)
 		return 0;
@@ -451,20 +451,12 @@ static int rt711_sdca_dev_resume(struct device *dev)
 			rt711->disable_irq = false;
 		}
 		mutex_unlock(&rt711->disable_irq_lock);
-		goto regmap_sync;
 	}
 
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT711_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "%s: Initialization not complete, timed out\n", __func__);
-		sdw_show_ping_status(slave->bus, true);
+	ret = sdw_slave_wait_for_init(slave, RT711_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-		return -ETIMEDOUT;
-	}
-
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt711->regmap, false);
 	regcache_sync(rt711->regmap);
 	regcache_cache_only(rt711->mbq_regmap, false);
sound/soc/codecs/rt711-sdw.c +4 -10
index 72ddf4cebdf36..df3c43f2ab6b8 100644
@@ -530,7 +530,7 @@ static int rt711_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt711_priv *rt711 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt711->first_hw_init)
 		return 0;
@@ -542,18 +542,12 @@ static int rt711_dev_resume(struct device *dev)
 			rt711->disable_irq = false;
 		}
 		mutex_unlock(&rt711->disable_irq_lock);
-		goto regmap_sync;
 	}
 
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT711_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "%s: Initialization not complete, timed out\n", __func__);
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(slave, RT711_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt711->regmap, false);
 	regcache_sync_region(rt711->regmap, 0x3000, 0x8fff);
 	regcache_sync_region(rt711->regmap, 0x752009, 0x752091);
Signature · 1 line
2.47.3
#8 lore raw

PATCH v4 8/18 ASoC: rt712: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/rt712-sdca-dmic.c | 19 ++++---------------
 sound/soc/codecs/rt712-sdca-sdw.c  | 16 ++++------------
 2 files changed, 8 insertions(+), 27 deletions(-)
sound/soc/codecs/rt712-sdca-dmic.c +4 -15
index 4d83544ef2049..4c5c2f5ba5edf 100644
@@ -905,26 +905,15 @@ static int rt712_sdca_dmic_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt712_sdca_dmic_priv *rt712 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt712->first_hw_init)
 		return 0;
 
-	if (!slave->unattach_request)
-		goto regmap_sync;
-
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT712_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "%s: Initialization not complete, timed out\n",
-			__func__);
-		sdw_show_ping_status(slave->bus, true);
-
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(slave, RT712_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt712->regmap, false);
 	regcache_sync(rt712->regmap);
 	regcache_cache_only(rt712->mbq_regmap, false);
sound/soc/codecs/rt712-sdca-sdw.c +4 -12
index 8c82887174db2..5817321804736 100644
@@ -450,7 +450,7 @@ static int rt712_sdca_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt712_sdca_priv *rt712 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt712->first_hw_init)
 		return 0;
@@ -464,20 +464,12 @@ static int rt712_sdca_dev_resume(struct device *dev)
 			rt712->disable_irq = false;
 		}
 		mutex_unlock(&rt712->disable_irq_lock);
-		goto regmap_sync;
 	}
 
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT712_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "%s: Initialization not complete, timed out\n", __func__);
-		sdw_show_ping_status(slave->bus, true);
+	ret = sdw_slave_wait_for_init(slave, RT712_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-		return -ETIMEDOUT;
-	}
-
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt712->regmap, false);
 	regcache_sync(rt712->regmap);
 	regcache_cache_only(rt712->mbq_regmap, false);
Signature · 1 line
2.47.3
#9 lore raw

PATCH v4 9/18 ASoC: rt715: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/rt715-sdca-sdw.c | 18 ++++--------------
 sound/soc/codecs/rt715-sdw.c      | 18 ++++--------------
 2 files changed, 8 insertions(+), 28 deletions(-)
sound/soc/codecs/rt715-sdca-sdw.c +4 -14
index 968bc183b8d8c..4b9815b5628db 100644
@@ -224,25 +224,15 @@ static int rt715_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt715_sdca_priv *rt715 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt715->first_hw_init)
 		return 0;
 
-	if (!slave->unattach_request)
-		goto regmap_sync;
+	ret = sdw_slave_wait_for_init(slave, RT715_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-					   msecs_to_jiffies(RT715_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "%s: Initialization not complete, timed out\n", __func__);
-		sdw_show_ping_status(slave->bus, true);
-
-		return -ETIMEDOUT;
-	}
-
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt715->regmap, false);
 	regcache_sync_region(rt715->regmap,
 		SDW_SDCA_CTL(FUN_JACK_CODEC, RT715_SDCA_ST_EN, RT715_SDCA_ST_CTRL,
sound/soc/codecs/rt715-sdw.c +4 -14
index 49c91d015be4d..7f83a8f1a06e9 100644
@@ -501,25 +501,15 @@ static int rt715_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt715_priv *rt715 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt715->first_hw_init)
 		return 0;
 
-	if (!slave->unattach_request)
-		goto regmap_sync;
-
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-					   msecs_to_jiffies(RT715_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "%s: Initialization not complete, timed out\n", __func__);
-		sdw_show_ping_status(slave->bus, true);
-
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(slave, RT715_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt715->regmap, false);
 	regcache_sync_region(rt715->regmap, 0x3000, 0x8fff);
 	regcache_sync_region(rt715->regmap, 0x752039, 0x752039);
Signature · 1 line
2.47.3
#10 lore raw

PATCH v4 10/18 ASoc: rt721: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/rt721-sdca-sdw.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
sound/soc/codecs/rt721-sdca-sdw.c +4 -12
index 6eb8512975b85..58606209316a4 100644
@@ -489,7 +489,7 @@ static int rt721_sdca_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt721_sdca_priv *rt721 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt721->first_hw_init)
 		return 0;
@@ -502,20 +502,12 @@ static int rt721_sdca_dev_resume(struct device *dev)
 			rt721->disable_irq = false;
 		}
 		mutex_unlock(&rt721->disable_irq_lock);
-		goto regmap_sync;
 	}
 
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT721_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "Initialization not complete, timed out\n");
-		sdw_show_ping_status(slave->bus, true);
+	ret = sdw_slave_wait_for_init(slave, RT721_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-		return -ETIMEDOUT;
-	}
-
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt721->regmap, false);
 	regcache_sync(rt721->regmap);
 	regcache_cache_only(rt721->mbq_regmap, false);
Signature · 1 line
2.47.3
#11 lore raw

PATCH v4 11/18 ASoC: rt722: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/rt722-sdca-sdw.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
sound/soc/codecs/rt722-sdca-sdw.c +4 -12
index 0a5b3ffa90daf..a5feba3d0c182 100644
@@ -501,7 +501,7 @@ static int rt722_sdca_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt722_sdca_priv *rt722 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt722->first_hw_init)
 		return 0;
@@ -514,20 +514,12 @@ static int rt722_sdca_dev_resume(struct device *dev)
 			rt722->disable_irq = false;
 		}
 		mutex_unlock(&rt722->disable_irq_lock);
-		goto regmap_sync;
 	}
 
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT722_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "Initialization not complete, timed out\n");
-		sdw_show_ping_status(slave->bus, true);
+	ret = sdw_slave_wait_for_init(slave, RT722_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-		return -ETIMEDOUT;
-	}
-
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt722->regmap, false);
 	regcache_sync(rt722->regmap);
 	return 0;
Signature · 1 line
2.47.3
#12 lore raw

PATCH v4 12/18 ASoC: rt1017: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/rt1017-sdca-sdw.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
sound/soc/codecs/rt1017-sdca-sdw.c +4 -14
index 148b36173a257..d62e8a2536767 100644
@@ -773,25 +773,15 @@ static int rt1017_sdca_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt1017_sdca_priv *rt1017 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt1017->first_hw_init)
 		return 0;
 
-	if (!slave->unattach_request)
-		goto regmap_sync;
-
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT1017_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "Initialization not complete, timed out\n");
-		sdw_show_ping_status(slave->bus, true);
-
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(slave, RT1017_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt1017->regmap, false);
 	regcache_sync(rt1017->regmap);
 
Signature · 1 line
2.47.3
#13 lore raw

PATCH v4 13/18 ASoC: rt1308: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/rt1308-sdw.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
sound/soc/codecs/rt1308-sdw.c +4 -14
index e077d096bc239..39e06a3a75609 100644
@@ -768,25 +768,15 @@ static int rt1308_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt1308_sdw_priv *rt1308 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt1308->first_hw_init)
 		return 0;
 
-	if (!slave->unattach_request)
-		goto regmap_sync;
-
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT1308_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "Initialization not complete, timed out\n");
-		sdw_show_ping_status(slave->bus, true);
-
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(slave, RT1308_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt1308->regmap, false);
 	regcache_sync_region(rt1308->regmap, 0xc000, 0xcfff);
 
Signature · 1 line
2.47.3
#14 lore raw

PATCH v4 14/18 ASoC: rt1316: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/rt1316-sdw.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
sound/soc/codecs/rt1316-sdw.c +4 -14
index 20fc1579eb9cf..1828fd9d5af6a 100644
@@ -745,25 +745,15 @@ static int rt1316_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt1316_sdw_priv *rt1316 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt1316->first_hw_init)
 		return 0;
 
-	if (!slave->unattach_request)
-		goto regmap_sync;
-
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT1316_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "%s: Initialization not complete, timed out\n", __func__);
-		sdw_show_ping_status(slave->bus, true);
-
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(slave, RT1316_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt1316->regmap, false);
 	regcache_sync(rt1316->regmap);
 
Signature · 1 line
2.47.3
#15 lore raw

PATCH v4 15/18 ASoC: rt1318: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/rt1318-sdw.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
sound/soc/codecs/rt1318-sdw.c +4 -12
index d28f1afe68f18..51bd11b92a554 100644
@@ -821,23 +821,15 @@ static int rt1318_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt1318_sdw_priv *rt1318 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt1318->first_hw_init)
 		return 0;
 
-	if (!slave->unattach_request)
-		goto regmap_sync;
-
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT1318_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "%s: Initialization not complete, timed out\n", __func__);
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(slave, RT1318_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt1318->regmap, false);
 	regcache_sync(rt1318->regmap);
 
Signature · 1 line
2.47.3
#16 lore raw

PATCH v4 16/18 ASoC: rt1320: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/rt1320-sdw.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
sound/soc/codecs/rt1320-sdw.c +4 -12
index 192faa431b5e9..13493b85f3c95 100644
@@ -3053,23 +3053,15 @@ static int rt1320_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt1320_sdw_priv *rt1320 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt1320->first_hw_init)
 		return 0;
 
-	if (!slave->unattach_request)
-		goto regmap_sync;
-
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT1320_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "%s: Initialization not complete, timed out\n", __func__);
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(slave, RT1320_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt1320->regmap, false);
 	regcache_sync(rt1320->regmap);
 	regcache_cache_only(rt1320->mbq_regmap, false);
Signature · 1 line
2.47.3
#17 lore raw

PATCH v4 17/18 ASoC: rt5682: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/rt5682-sdw.c | 16 ++++------------
 1 file changed, 4 insertions(+), 12 deletions(-)
sound/soc/codecs/rt5682-sdw.c +4 -12
index fc464538ceffb..ec2a35a0cacde 100644
@@ -754,7 +754,7 @@ static int rt5682_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct rt5682_priv *rt5682 = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	if (!rt5682->first_hw_init)
 		return 0;
@@ -766,20 +766,12 @@ static int rt5682_dev_resume(struct device *dev)
 			rt5682->disable_irq = false;
 		}
 		mutex_unlock(&rt5682->disable_irq_lock);
-		goto regmap_sync;
 	}
 
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-				msecs_to_jiffies(RT5682_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(&slave->dev, "%s: Initialization not complete, timed out\n", __func__);
-		sdw_show_ping_status(slave->bus, true);
-
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(slave, RT5682_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-regmap_sync:
-	slave->unattach_request = 0;
 	regcache_cache_only(rt5682->sdw_regmap, false);
 	regcache_cache_only(rt5682->regmap, false);
 	regcache_sync(rt5682->regmap);
Signature · 1 line
2.47.3
#18 lore raw

PATCH v4 18/18 ASoC: tas2783: Use new SoundWire enumeration helper

In reply to Charles Keepax

Update the driver to use the new core helper that waits for the device to enumerate on SoundWire and be initialised by the SoundWire core.

---

No changes since v3.

 sound/soc/codecs/tas2783-sdw.c | 18 ++++--------------
 1 file changed, 4 insertions(+), 14 deletions(-)
sound/soc/codecs/tas2783-sdw.c +4 -14
index 38009168c5a11..69d03ddc7a0ba 100644
@@ -1082,22 +1082,12 @@ static s32 tas2783_sdca_dev_resume(struct device *dev)
 {
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct tas2783_prv *tas_dev = dev_get_drvdata(dev);
-	unsigned long t;
-
-	if (!slave->unattach_request)
-		goto regmap_sync;
-
-	t = wait_for_completion_timeout(&slave->initialization_complete,
-					msecs_to_jiffies(TAS2783_PROBE_TIMEOUT));
-	if (!t) {
-		dev_err(&slave->dev, "resume: initialization timed out\n");
-		sdw_show_ping_status(slave->bus, true);
-		return -ETIMEDOUT;
-	}
+	int ret;
 
-	slave->unattach_request = 0;
+	ret = sdw_slave_wait_for_init(slave, TAS2783_PROBE_TIMEOUT);
+	if (ret)
+		return ret;
 
-regmap_sync:
 	regcache_cache_only(tas_dev->regmap, false);
 	regcache_sync(tas_dev->regmap);
 	return 0;
Signature · 1 line
2.47.3
maintainer
#19 lore raw
In reply to Charles Keepax
Quoted 6 lines · Charles Keepax

Add a new SoundWire enumeration helper

Add a new SoundWire enumeration helper function, many drivers have almost identical code in runtime resume so it makes sense to move this to the core.

Quoted 6 lines

It is worth noting this is really step one of a larger process, there are a few drivers that do more custom things and are not covered by this series. But this series picks up the low hanging fruit and moves things in a good direction.

[...]

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-7.2

Thanks!

[01/18] soundwire: Add a helper function to wait for device initialisation

        https://git.kernel.org/broonie/sound/c/3492e8b494c1
[02/18] ASoC: cs35l56: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/9dc2b0d599c6
[03/18] ASoC: cs42l42: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/47e2f687b0c5
[04/18] ASoC: max98363: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/7fa0ff88f882
[05/18] ASoC: max98373: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/8e5768eb4eaa
[06/18] ASoC: rt700: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/c5b0783d18a6
[07/18] ASoC: rt711: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/953ee481561b
[08/18] ASoC: rt712: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/d5bd2f7239f6
[09/18] ASoC: rt715: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/e154b2472f6b
[10/18] ASoc: rt721: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/cc05ab0a664e
[11/18] ASoC: rt722: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/0b6401749586
[12/18] ASoC: rt1017: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/ab579acef4bf
[13/18] ASoC: rt1308: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/1ab950b47b3a
[14/18] ASoC: rt1316: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/b7997fcacf94
[15/18] ASoC: rt1318: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/210f109efdfd
[16/18] ASoC: rt1320: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/4461603eda13
[17/18] ASoC: rt5682: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/fee0a8b4f0da
[18/18] ASoC: tas2783: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/ac6d4f298160

All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying to this mail.

Thanks,
Mark