Skip to contentSkip to conversation

Expand SoundWire enumeration helper coverage

PATCH Applied Charles Keepax 4 participants 18 messages Jun 8 – Jun 22

Subsystems (9)
lore
Share & tools
lore

Charles Keepax

author maintainer
#0 lore raw

v3 cover Expand SoundWire enumeration helper coverage

The patch series in [1] added a new helper to remove common boiler plate waiting for a device to enumerate on SoundWire, however, many devices also wait for enumeration during probe. This series updates things to be suitable such that we can call the same helper at probe time when the unattach_request is not valid.

There is one final step outstanding which is to add a core helper that waits for a device to drop off the bus. This is not include in this series and should be the last step of this process.

Thanks,
Charles

[1] https://lore.kernel.org/linux-sound/[email protected]/

Changes since v1:
- Completely remove the attached flag from cs42l43

Changes since v2:
- Corrected some spelling mistakes

Charles Keepax (10):
soundwire: Always wait for initialisation of unattached devices
ASoC: wsa881x: Use new SoundWire enumeration helper
mfd: cs42l43: Use new SoundWire enumeration helper
ASoC: rt5682: Use new SoundWire enumeration helper
ASoC: pm4125: Use new SoundWire enumeration helper
ASoC: wcd937x: Use new SoundWire enumeration helper
ASoC: wcd938x: Use new SoundWire enumeration helper
ASoC: wcd939x: Use new SoundWire enumeration helper
ASoC: SDCA: Use new SoundWire enumeration helper
ASoC: cs35l56: Remove unnecessary conditionals waiting for enumeration

 drivers/mfd/cs42l43-i2c.c      |  2 --
 drivers/mfd/cs42l43-sdw.c      |  7 -----
 drivers/mfd/cs42l43.c          | 15 ++++------
 drivers/soundwire/bus.c        |  3 --
 include/linux/mfd/cs42l43.h    |  2 --
 sound/soc/codecs/cs35l56-sdw.c | 47 +++++++-----------------------
 sound/soc/codecs/cs35l56.h     |  1 -
 sound/soc/codecs/pm4125.c      | 11 ++-----
 sound/soc/codecs/rt5682.c      | 14 +++------
 sound/soc/codecs/wcd937x.c     | 11 ++-----
 sound/soc/codecs/wcd938x.c     | 11 ++-----
 sound/soc/codecs/wcd939x.c     | 11 ++-----
 sound/soc/codecs/wsa881x.c     | 10 +++----
 sound/soc/sdca/sdca_class.c    | 53 ++++------------------------------
 sound/soc/sdca/sdca_class.h    |  3 --
 15 files changed, 41 insertions(+), 160 deletions(-)
Signature · 1 line
2.47.3
author maintainer
#1 lore raw

PATCH v3 1/10 soundwire: Always wait for initialisation of unattached devices

Currently in sdw_slave_wait_for_init() the waiting can be skipped if unattach_request is not set. Doing so was added in [1] likely because the core used to do a complete() on the completion so waiting in the case an unattach hadn't actually happened would block for the full timeout. However patch [2] updated the core to use complete_all() which means that the wait_for_completion() will now simply return if the device is already attached skipping the completion doesn't add much.

Additionally, unattach_request is only set if the host initiates a bus reset. However, the host doing a bus reset is not the only reason a device may be unattached from the bus. Other options could include the driver probing before the device enumerates, a sync-loss, or the device itself powering down.

Removing the skip using unattached_request, doesn't cost much in terms of efficiency and allows the sdw_slave_wait_for_init() helper to be used outside of runtime resume.

[1] b2bd75f806c4 ("soundwire: sdw_slave: track unattach_request to handle all init sequences")
[2] c40d6b3249b1 ("soundwire: fix enumeration completion")

---

Changes since v2:
- Corrected some spelling in the commit message

 drivers/soundwire/bus.c | 3 ---
 1 file changed, 3 deletions(-)
drivers/soundwire/bus.c +0 -3
index ea3a24f805c00..b7bdf19ebb42e 100644
@@ -1386,9 +1386,6 @@ 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) {
Signature · 1 line
2.47.3
author maintainer
#2 lore raw

PATCH v3 2/10 ASoC: wsa881x: Use new SoundWire enumeration helper

In reply to Charles Keepax

Now the new wait for SoundWire enumeration helper no longer depends on unattach_request it can be used for code that also doesn't check this flag. Update the driver to use the new core helper.

---

No change since v2.

 sound/soc/codecs/wsa881x.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)
sound/soc/codecs/wsa881x.c +4 -6
index d15fda648dada..5174614c3e837 100644
@@ -1167,16 +1167,14 @@ static int wsa881x_runtime_resume(struct device *dev)
 	struct sdw_slave *slave = dev_to_sdw_dev(dev);
 	struct regmap *regmap = dev_get_regmap(dev, NULL);
 	struct wsa881x_priv *wsa881x = dev_get_drvdata(dev);
-	unsigned long time;
+	int ret;
 
 	gpiod_direction_output(wsa881x->sd_n, 0);
 
-	time = wait_for_completion_timeout(&slave->initialization_complete,
-					   msecs_to_jiffies(WSA881X_PROBE_TIMEOUT));
-	if (!time) {
-		dev_err(dev, "Initialization not complete, timed out\n");
+	ret = sdw_slave_wait_for_init(slave, WSA881X_PROBE_TIMEOUT);
+	if (ret) {
 		gpiod_direction_output(wsa881x->sd_n, 1);
-		return -ETIMEDOUT;
+		return ret;
 	}
 
 	regcache_cache_only(regmap, false);
Signature · 1 line
2.47.3
author maintainer
#3 lore raw

PATCH v3 3/10 mfd: cs42l43: Use new SoundWire enumeration helper

In reply to Charles Keepax

Now the new wait for SoundWire enumeration helper no longer depends on unattach_request it is safe to use from probe time. Update the driver to use the new core helper.

---

No change since v2.

 drivers/mfd/cs42l43-i2c.c   |  2 --
 drivers/mfd/cs42l43-sdw.c   |  7 -------
 drivers/mfd/cs42l43.c       | 15 ++++++---------
 include/linux/mfd/cs42l43.h |  2 --
 4 files changed, 6 insertions(+), 20 deletions(-)
drivers/mfd/cs42l43-i2c.c +0 -2
index 0a0ab5e549a5a..4db452b41220d 100644
@@ -45,8 +45,6 @@ static int cs42l43_i2c_probe(struct i2c_client *i2c)
 
 	cs42l43->dev = &i2c->dev;
 	cs42l43->irq = i2c->irq;
-	/* A device on an I2C is always attached by definition. */
-	cs42l43->attached = true;
 	cs42l43->variant_id = (long)device_get_match_data(cs42l43->dev);
 
 	cs42l43->regmap = devm_regmap_init_i2c(i2c, &cs42l43_i2c_regmap);
drivers/mfd/cs42l43-sdw.c +0 -7
index 794c983781750..2b87ae2d79c51 100644
@@ -100,17 +100,10 @@ static int cs42l43_sdw_update_status(struct sdw_slave *sdw, enum sdw_slave_statu
 
 		sdw_write_no_pm(sdw, CS42L43_GEN_INT_MASK_1,
 				CS42L43_INT_STAT_GEN1_MASK);
-
-		cs42l43->attached = true;
-
-		complete(&cs42l43->device_attach);
 		break;
 	case SDW_SLAVE_UNATTACHED:
 		dev_dbg(cs42l43->dev, "Device detach\n");
 
-		cs42l43->attached = false;
-
-		reinit_completion(&cs42l43->device_attach);
 		complete(&cs42l43->device_detach);
 		break;
 	default:
drivers/mfd/cs42l43.c +6 -9
index 166881751e698..cb1e175586bd1 100644
@@ -586,15 +586,13 @@ static int cs42l43_soft_reset(struct cs42l43 *cs42l43)
  */
 static int cs42l43_wait_for_attach(struct cs42l43 *cs42l43)
 {
-	if (!cs42l43->attached) {
-		unsigned long timeout = msecs_to_jiffies(CS42L43_SDW_ATTACH_TIMEOUT_MS);
-		unsigned long time;
+	int ret;
 
-		time = wait_for_completion_timeout(&cs42l43->device_attach, timeout);
-		if (!time) {
-			dev_err(cs42l43->dev, "Timed out waiting for device re-attach\n");
-			return -ETIMEDOUT;
-		}
+	if (cs42l43->sdw) {
+		ret = sdw_slave_wait_for_init(cs42l43->sdw,
+					      CS42L43_SDW_ATTACH_TIMEOUT_MS);
+		if (ret)
+			return ret;
 	}
 
 	regcache_cache_only(cs42l43->regmap, false);
@@ -1120,7 +1118,6 @@ int cs42l43_dev_probe(struct cs42l43 *cs42l43)
 	dev_set_drvdata(cs42l43->dev, cs42l43);
 
 	mutex_init(&cs42l43->pll_lock);
-	init_completion(&cs42l43->device_attach);
 	init_completion(&cs42l43->device_detach);
 	init_completion(&cs42l43->firmware_download);
 	INIT_WORK(&cs42l43->boot_work, cs42l43_boot_work);
include/linux/mfd/cs42l43.h +0 -2
index ff0f7e365a19f..8e993fb535e68 100644
@@ -86,7 +86,6 @@ struct cs42l43 {
 	struct regmap_irq_chip_data *irq_data;
 
 	struct work_struct boot_work;
-	struct completion device_attach;
 	struct completion device_detach;
 	struct completion firmware_download;
 	int firmware_error;
@@ -96,7 +95,6 @@ struct cs42l43 {
 	struct mutex pll_lock;
 
 	bool sdw_pll_active;
-	bool attached;
 	bool hw_lock;
 	long variant_id;
 };
Signature · 1 line
2.47.3
maintainer Applied
#4 lore raw

Re: (subset) [PATCH v3 03/10] mfd: cs42l43: Use new SoundWire enumeration helper

Quoted 3 lines · Charles Keepax

Now the new wait for SoundWire enumeration helper no longer depends on unattach_request it is safe to use from probe time. Update the driver to use the new core helper.

Applied, thanks!

[03/10] mfd: cs42l43: Use new SoundWire enumeration helper

        commit: bbd4169932ae54394a61ab26905b483967543f5b

--
Lee Jones [李琼斯]

author maintainer
#5 lore raw

PATCH v3 4/10 ASoC: rt5682: Use new SoundWire enumeration helper

In reply to Charles Keepax

Now the new wait for SoundWire enumeration helper no longer depends on unattach_request it is safe to use from probe time. Update the driver to use the new core helper.

---

No change since v2.

 sound/soc/codecs/rt5682.c | 14 ++++----------
 1 file changed, 4 insertions(+), 10 deletions(-)
sound/soc/codecs/rt5682.c +4 -10
index d39f8e4f3474c..4b82e07d3b2c7 100644
@@ -2929,20 +2929,14 @@ static int rt5682_probe(struct snd_soc_component *component)
 {
 	struct rt5682_priv *rt5682 = snd_soc_component_get_drvdata(component);
 	struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
-	struct sdw_slave *slave;
-	unsigned long time;
+	int ret;
 
 	rt5682->component = component;
 
 	if (rt5682->is_sdw) {
-		slave = rt5682->slave;
-		time = wait_for_completion_timeout(
-			&slave->initialization_complete,
-			msecs_to_jiffies(RT5682_PROBE_TIMEOUT));
-		if (!time) {
-			dev_err(&slave->dev, "Initialization not complete, timed out\n");
-			return -ETIMEDOUT;
-		}
+		ret = sdw_slave_wait_for_init(rt5682->slave, RT5682_PROBE_TIMEOUT);
+		if (ret)
+			return ret;
 	}
 
 	snd_soc_dapm_disable_pin(dapm, "MICBIAS");
Signature · 1 line
2.47.3
author maintainer
#6 lore raw

PATCH v3 5/10 ASoC: pm4125: Use new SoundWire enumeration helper

In reply to Charles Keepax

Now the new wait for SoundWire enumeration helper no longer depends on unattach_request it is safe to use from probe time. Update the driver to use the new core helper.

---

No change since v2.

 sound/soc/codecs/pm4125.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
sound/soc/codecs/pm4125.c +3 -8
index 1f0a3f5389f1b..29655175ea289 100644
@@ -1309,17 +1309,12 @@ static int pm4125_irq_init(struct pm4125_priv *pm4125, struct device *dev)
 static int pm4125_soc_codec_probe(struct snd_soc_component *component)
 {
 	struct pm4125_priv *pm4125 = snd_soc_component_get_drvdata(component);
-	struct sdw_slave *tx_sdw_dev = pm4125->tx_sdw_dev;
 	struct device *dev = component->dev;
-	unsigned long time_left;
 	int i, ret;
 
-	time_left = wait_for_completion_timeout(&tx_sdw_dev->initialization_complete,
-						msecs_to_jiffies(5000));
-	if (!time_left) {
-		dev_err(dev, "soundwire device init timeout\n");
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(pm4125->tx_sdw_dev, 5000);
+	if (ret)
+		return ret;
 
 	snd_soc_component_init_regmap(component, pm4125->regmap);
 	ret = pm_runtime_resume_and_get(dev);
Signature · 1 line
2.47.3
author maintainer
#7 lore raw

PATCH v3 6/10 ASoC: wcd937x: Use new SoundWire enumeration helper

In reply to Charles Keepax

Now the new wait for SoundWire enumeration helper no longer depends on unattach_request it is safe to use from probe time. Update the driver to use the new core helper.

---

No change since v2.

 sound/soc/codecs/wcd937x.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
sound/soc/codecs/wcd937x.c +3 -8
index 72a53f95d6887..e0169e783ee96 100644
@@ -2499,18 +2499,13 @@ static int wcd937x_soc_codec_probe(struct snd_soc_component *component)
 {
 	struct snd_soc_dapm_context *dapm = snd_soc_component_to_dapm(component);
 	struct wcd937x_priv *wcd937x = snd_soc_component_get_drvdata(component);
-	struct sdw_slave *tx_sdw_dev = wcd937x->tx_sdw_dev;
 	struct device *dev = component->dev;
-	unsigned long time_left;
 	int i, ret;
 	u32 chipid;
 
-	time_left = wait_for_completion_timeout(&tx_sdw_dev->initialization_complete,
-						msecs_to_jiffies(5000));
-	if (!time_left) {
-		dev_err(dev, "soundwire device init timeout\n");
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(wcd937x->tx_sdw_dev, 5000);
+	if (ret)
+		return ret;
 
 	snd_soc_component_init_regmap(component, wcd937x->regmap);
 	ret = pm_runtime_resume_and_get(dev);
Signature · 1 line
2.47.3
author maintainer
#8 lore raw

PATCH v3 7/10 ASoC: wcd938x: Use new SoundWire enumeration helper

In reply to Charles Keepax

Now the new wait for SoundWire enumeration helper no longer depends on unattach_request it is safe to use from probe time. Update the driver to use the new core helper.

---

No change since v2.

 sound/soc/codecs/wcd938x.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
sound/soc/codecs/wcd938x.c +3 -8
index cb0a0bfdb6e32..c69e18667a85b 100644
@@ -3016,18 +3016,13 @@ static int wcd938x_irq_init(struct wcd938x_priv *wcd, struct device *dev)
 static int wcd938x_soc_codec_probe(struct snd_soc_component *component)
 {
 	struct wcd938x_priv *wcd938x = snd_soc_component_get_drvdata(component);
-	struct sdw_slave *tx_sdw_dev = wcd938x->tx_sdw_dev;
 	struct device *dev = component->dev;
-	unsigned long time_left;
 	unsigned int variant;
 	int ret, i;
 
-	time_left = wait_for_completion_timeout(&tx_sdw_dev->initialization_complete,
-						msecs_to_jiffies(2000));
-	if (!time_left) {
-		dev_err(dev, "soundwire device init timeout\n");
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(wcd938x->tx_sdw_dev, 2000);
+	if (ret)
+		return ret;
 
 	snd_soc_component_init_regmap(component, wcd938x->regmap);
 
Signature · 1 line
2.47.3
author maintainer
#9 lore raw

PATCH v3 8/10 ASoC: wcd939x: Use new SoundWire enumeration helper

In reply to Charles Keepax

Now the new wait for SoundWire enumeration helper no longer depends on unattach_request it is safe to use from probe time. Update the driver to use the new core helper.

---

No change since v2.

 sound/soc/codecs/wcd939x.c | 11 +++--------
 1 file changed, 3 insertions(+), 8 deletions(-)
sound/soc/codecs/wcd939x.c +3 -8
index 01f1a08f48e65..010d124667224 100644
@@ -2968,17 +2968,12 @@ static int wcd939x_irq_init(struct wcd939x_priv *wcd, struct device *dev)
 static int wcd939x_soc_codec_probe(struct snd_soc_component *component)
 {
 	struct wcd939x_priv *wcd939x = snd_soc_component_get_drvdata(component);
-	struct sdw_slave *tx_sdw_dev = wcd939x->tx_sdw_dev;
 	struct device *dev = component->dev;
-	unsigned long time_left;
 	int ret, i;
 
-	time_left = wait_for_completion_timeout(&tx_sdw_dev->initialization_complete,
-						msecs_to_jiffies(2000));
-	if (!time_left) {
-		dev_err(dev, "soundwire device init timeout\n");
-		return -ETIMEDOUT;
-	}
+	ret = sdw_slave_wait_for_init(wcd939x->tx_sdw_dev, 2000);
+	if (ret)
+		return ret;
 
 	snd_soc_component_init_regmap(component, wcd939x->regmap);
 
Signature · 1 line
2.47.3
author maintainer
#10 lore raw

PATCH v3 9/10 ASoC: SDCA: Use new SoundWire enumeration helper

In reply to Charles Keepax

Now the new wait for SoundWire enumeration helper no longer depends on unattach_request it is safe to use from probe time. Update the driver to use the new core helper.

---

No change since v2.

 sound/soc/sdca/sdca_class.c | 53 ++++---------------------------------
 sound/soc/sdca/sdca_class.h |  3 ---
 2 files changed, 5 insertions(+), 51 deletions(-)
sound/soc/sdca/sdca_class.c +5 -48
index a6a3da8de4371..6937a91ddfb9b 100644
@@ -38,35 +38,8 @@ static int class_read_prop(struct sdw_slave *sdw)
 	return 0;
 }
 
-static int class_sdw_update_status(struct sdw_slave *sdw, enum sdw_slave_status status)
-{
-	struct sdca_class_drv *drv = dev_get_drvdata(&sdw->dev);
-
-	switch (status) {
-	case SDW_SLAVE_ATTACHED:
-		dev_dbg(drv->dev, "device attach\n");
-
-		drv->attached = true;
-
-		complete(&drv->device_attach);
-		break;
-	case SDW_SLAVE_UNATTACHED:
-		dev_dbg(drv->dev, "device detach\n");
-
-		drv->attached = false;
-
-		reinit_completion(&drv->device_attach);
-		break;
-	default:
-		break;
-	}
-
-	return 0;
-}
-
 static const struct sdw_slave_ops class_sdw_ops = {
 	.read_prop	= class_read_prop,
-	.update_status	= class_sdw_update_status,
 };
 
 static void class_regmap_lock(void *data)
@@ -83,24 +56,6 @@ static void class_regmap_unlock(void *data)
 	mutex_unlock(lock);
 }
 
-static int class_wait_for_attach(struct sdca_class_drv *drv)
-{
-	if (!drv->attached) {
-		unsigned long timeout = msecs_to_jiffies(CLASS_SDW_ATTACH_TIMEOUT_MS);
-		unsigned long time;
-
-		time = wait_for_completion_timeout(&drv->device_attach, timeout);
-		if (!time) {
-			dev_err(drv->dev, "timed out waiting for device re-attach\n");
-			return -ETIMEDOUT;
-		}
-	}
-
-	regcache_cache_only(drv->dev_regmap, false);
-
-	return 0;
-}
-
 static bool class_dev_regmap_volatile(struct device *dev, unsigned int reg)
 {
 	switch (reg) {
@@ -151,10 +106,12 @@ static void class_boot_work(struct work_struct *work)
 						  boot_work);
 	int ret;
 
-	ret = class_wait_for_attach(drv);
+	ret = sdw_slave_wait_for_init(drv->sdw, CLASS_SDW_ATTACH_TIMEOUT_MS);
 	if (ret)
 		goto err;
 
+	regcache_cache_only(drv->dev_regmap, false);
+
 	drv->irq_info = sdca_irq_allocate(drv->dev, drv->dev_regmap,
 					  drv->sdw->irq);
 	if (IS_ERR(drv->irq_info))
@@ -206,7 +163,6 @@ static int class_sdw_probe(struct sdw_slave *sdw, const struct sdw_device_id *id
 	dev_set_drvdata(drv->dev, drv);
 
 	INIT_WORK(&drv->boot_work, class_boot_work);
-	init_completion(&drv->device_attach);
 
 	dev_config->lock_arg = &drv->regmap_lock;
 
@@ -290,10 +246,11 @@ static int class_runtime_resume(struct device *dev)
 	struct sdca_class_drv *drv = dev_get_drvdata(dev);
 	int ret;
 
-	ret = class_wait_for_attach(drv);
+	ret = sdw_slave_wait_for_init(drv->sdw, CLASS_SDW_ATTACH_TIMEOUT_MS);
 	if (ret)
 		goto err;
 
+	regcache_cache_only(drv->dev_regmap, false);
 	regcache_mark_dirty(drv->dev_regmap);
 
 	ret = regcache_sync(drv->dev_regmap);
sound/soc/sdca/sdca_class.h +0 -3
index 8b63e62485e64..57f7f8d08f497 100644
@@ -30,9 +30,6 @@ struct sdca_class_drv {
 	/* Serialise function initialisations */
 	struct mutex init_lock;
 	struct work_struct boot_work;
-	struct completion device_attach;
-
-	bool attached;
 };
 
 #endif /* __SDCA_CLASS_H__ */
Signature · 1 line
2.47.3
author maintainer
#11 lore raw

PATCH v3 10/10 ASoC: cs35l56: Remove unnecessary conditionals waiting for enumeration

In reply to Charles Keepax

Commit [1] updated the core to use complete_all() which means that the wait_for_completion() will now simply return if the device is already attached, so skipping the completion isn't required anymore. Update the code to simply call sdw_slave_wait_for_init() unconditionally.

[1] c40d6b3249b1 ("soundwire: fix enumeration completion")

---

No change since v2.

 sound/soc/codecs/cs35l56-sdw.c | 47 ++++++++--------------------------
 sound/soc/codecs/cs35l56.h     |  1 -
 2 files changed, 10 insertions(+), 38 deletions(-)
sound/soc/codecs/cs35l56-sdw.c +10 -37
index 847e88f3b2044..0a55b93b96f96 100644
@@ -330,7 +330,6 @@ static int cs35l56_sdw_update_status(struct sdw_slave *peripheral,
 
 	switch (status) {
 	case SDW_SLAVE_ATTACHED:
-		cs35l56->sdw_in_clock_stop_1 = false;
 		if (cs35l56->sdw_attached)
 			break;
 
@@ -352,31 +351,10 @@ static int cs35l56_sdw_update_status(struct sdw_slave *peripheral,
 	return 0;
 }
 
-static int __maybe_unused cs35l56_sdw_clk_stop(struct sdw_slave *peripheral,
-					       enum sdw_clk_stop_mode mode,
-					       enum sdw_clk_stop_type type)
-{
-	struct cs35l56_private *cs35l56 = dev_get_drvdata(&peripheral->dev);
-
-	dev_dbg(cs35l56->base.dev, "%s: clock_stop_mode%d stage:%d\n", __func__, mode, type);
-
-	switch (type) {
-	case SDW_CLK_POST_PREPARE:
-		if (mode == SDW_CLK_STOP_MODE1)
-			cs35l56->sdw_in_clock_stop_1 = true;
-		else
-			cs35l56->sdw_in_clock_stop_1 = false;
-		return 0;
-	default:
-		return 0;
-	}
-}
-
 static const struct sdw_slave_ops cs35l56_sdw_ops = {
 	.read_prop = cs35l56_sdw_read_prop,
 	.interrupt_callback = cs35l56_sdw_interrupt,
 	.update_status = cs35l56_sdw_update_status,
-	.clk_stop = cs35l56_sdw_clk_stop,
 };
 
 static int __maybe_unused cs35l56_sdw_handle_unattach(struct cs35l56_private *cs35l56)
@@ -384,23 +362,18 @@ static int __maybe_unused cs35l56_sdw_handle_unattach(struct cs35l56_private *cs
 	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);
+	dev_dbg(cs35l56->base.dev, "attached:%u unattach_request:%u\n",
+		cs35l56->sdw_attached, peripheral->unattach_request);
 
-	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");
-		ret = sdw_slave_wait_for_init(peripheral, 5000);
-		if (ret)
-			return ret;
-
-		cs35l56->sdw_in_clock_stop_1 = false;
+	/* Cannot access registers until bus is re-initialized. */
+	ret = sdw_slave_wait_for_init(peripheral, 5000);
+	if (ret)
+		return ret;
 
-		/*
-		 * Don't call regcache_mark_dirty(), we can't be sure that the
-		 * Manager really did issue a Bus Reset.
-		 */
-	}
+	/*
+	 * Don't call regcache_mark_dirty(), we can't be sure that the
+	 * Manager really did issue a Bus Reset.
+	 */
 
 	return 0;
 }
sound/soc/codecs/cs35l56.h +0 -1
index 6a27ef2b7569a..9acd2e7e17c93 100644
@@ -43,7 +43,6 @@ struct cs35l56_private {
 	bool sdw_irq_no_unmask;
 	bool soft_resetting;
 	bool sdw_attached;
-	bool sdw_in_clock_stop_1;
 	struct completion init_completion;
 
 	int speaker_id;
Signature · 1 line
2.47.3
maintainer
#12 lore raw

Re: (subset) [PATCH v3 00/10] Expand SoundWire enumeration helper coverage

In reply to Charles Keepax
Quoted 9 lines · Charles Keepax

Expand SoundWire enumeration helper coverage

The patch series in [1] added a new helper to remove common boiler plate waiting for a device to enumerate on SoundWire, however, many devices also wait for enumeration during probe. This series updates things to be suitable such that we can call the same helper at probe time when the unattach_request is not valid.

[...]

Applied to

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

Thanks!

[01/10] soundwire: Always wait for initialisation of unattached devices

        https://git.kernel.org/broonie/sound/c/5677a551f458
[02/10] ASoC: wsa881x: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/f0eb67c618ee
[04/10] ASoC: rt5682: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/933feddee4d7
[05/10] ASoC: pm4125: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/ae636c93299d
[06/10] ASoC: wcd937x: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/ec1028e3f077
[07/10] ASoC: wcd938x: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/d6fc2c7051a6
[08/10] ASoC: wcd939x: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/4e006504ac95
[09/10] ASoC: SDCA: Use new SoundWire enumeration helper
        https://git.kernel.org/broonie/sound/c/90a49e0f1652
[10/10] ASoC: cs35l56: Remove unnecessary conditionals waiting for enumeration
        https://git.kernel.org/broonie/sound/c/890b61d3a8c9

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

#13 lore raw
In reply to Charles Keepax
Quoted 6 lines

The patch series in [1] added a new helper to remove common boiler plate waiting for a device to enumerate on SoundWire, however, many devices also wait for enumeration during probe. This series updates things to be suitable such that we can call the same helper at probe time when the unattach_request is not valid.

So if we are no longer testing for unattach_request, should this be definition and its use be removed? Looks like there were multiple evolutions since the initial patch
"soundwire: sdw_slave: track unattach_request to handle all init sequences",
is an additional cleanup needed?

Quoted 3 lines

There is one final step outstanding which is to add a core helper that waits for a device to drop off the bus. This is not include in this series and should be the last step of this process.

Humm, I am not following why the core needs to wait for a device to drop off.
If there's a bus reset or device reset, it's almost immediate.
It the devices loses sync then the core wouldn't wait either since it's not expecting the device to drop-off.

author maintainer
#14 lore raw
Quoted 11 lines · Pierre-Louis Bossart
Quoted 6 lines

The patch series in [1] added a new helper to remove common boiler plate waiting for a device to enumerate on SoundWire, however, many devices also wait for enumeration during probe. This series updates things to be suitable such that we can call the same helper at probe time when the unattach_request is not valid.

So if we are no longer testing for unattach_request, should this be definition and its use be removed? Looks like there were multiple evolutions since the initial patch
"soundwire: sdw_slave: track unattach_request to handle all init sequences",
is an additional cleanup needed?

There are still a couple of end drivers that use unattach_request to attempt to track if the device was reset. I suspect that is likely better done other ways but its very hard stuff to change without detailed knowledge of the specific devices.

I think our only part still using this is cs42l42 which I think someone has the power to test internally, so we could look at that at some point in the future. But I am not comfortable changing the realtek or ess parts using this myself.

Quoted 8 lines
Quoted 3 lines

There is one final step outstanding which is to add a core helper that waits for a device to drop off the bus. This is not include in this series and should be the last step of this process.

Humm, I am not following why the core needs to wait for a device to drop off. If there's a bus reset or device reset, it's almost immediate. It the devices loses sync then the core wouldn't wait either since it's not expecting the device to drop-off.

The problem is mostly from the device side. This usually comes up from a device reset. So the driver does a reset, device drops off the bus, the device driver doesn't want to carry on until it knows the device is back on the bus. So naively one calls sdw_slave_wait_for_init() but there is nothing the ensures the core saw the bus disconnection before that call so it might immediately succeed, causing the driver to attempt to access a missing device.

Yeah the fall of the bus is fast but so are processors, you need to actually ensure you can't shortcut the wait. Although typing this it occurs to me it probably doesn't have to be a wait one can probably just manually reinit the initalization_complete completion. But hopefully I will get this series ready soon and we can discuss on there.

Thanks,
Charles

#15 lore raw
Quoted 13 lines · Charles Keepax
Quoted 11 lines · Pierre-Louis Bossart
Quoted 6 lines

The patch series in [1] added a new helper to remove common boiler plate waiting for a device to enumerate on SoundWire, however, many devices also wait for enumeration during probe. This series updates things to be suitable such that we can call the same helper at probe time when the unattach_request is not valid.

So if we are no longer testing for unattach_request, should this be definition and its use be removed? Looks like there were multiple evolutions since the initial patch
"soundwire: sdw_slave: track unattach_request to handle all init sequences",
is an additional cleanup needed?

Quoted 4 lines

There are still a couple of end drivers that use unattach_request to attempt to track if the device was reset. I suspect that is likely better done other ways but its very hard stuff to change without detailed knowledge of the specific devices.

ok, it looks like a more difficult change than a basic cleanup.

Quoted 23 lines

I think our only part still using this is cs42l42 which I think someone has the power to test internally, so we could look at that at some point in the future. But I am not comfortable changing the realtek or ess parts using this myself.

Quoted 8 lines
Quoted 3 lines

There is one final step outstanding which is to add a core helper that waits for a device to drop off the bus. This is not include in this series and should be the last step of this process.

Humm, I am not following why the core needs to wait for a device to drop off. If there's a bus reset or device reset, it's almost immediate. It the devices loses sync then the core wouldn't wait either since it's not expecting the device to drop-off.

The problem is mostly from the device side. This usually comes up from a device reset. So the driver does a reset, device drops off the bus, the device driver doesn't want to carry on until it knows the device is back on the bus. So naively one calls sdw_slave_wait_for_init() but there is nothing the ensures the core saw the bus disconnection before that call so it might immediately succeed, causing the driver to attempt to access a missing device.

Quoted 6 lines

Yeah the fall of the bus is fast but so are processors, you need to actually ensure you can't shortcut the wait. Although typing this it occurs to me it probably doesn't have to be a wait one can probably just manually reinit the initalization_complete completion. But hopefully I will get this series ready soon and we can discuss on there.

Don't we already have the interface to detect a device was UNATTACHED?
In theory the core will invoke the update_status() callback on every status change. Each driver would use the information to know when the UNATTACHED happened and likewise when the device is enumerated/initialized again. So far most drivers just return and do nothing when an UNATTACHED status is reported.

The only thing we can't control at the moment is that when a device reports as device0, the core will enumerate it and attempt to initialize it. If additional time is needed prior to the enumeration, we don't have the hooks for it - that would not be quite standard behavior anyways.

author maintainer
#16 lore raw
Quoted 18 lines · Pierre-Louis Bossart
Quoted 10 lines · Charles Keepax

On Fri, Jun 19, 2026 at 03:41:44PM +0200, Pierre-Louis Bossart wrote:
The problem is mostly from the device side. This usually comes up from a device reset. So the driver does a reset, device drops off the bus, the device driver doesn't want to carry on until it knows the device is back on the bus. So naively one calls sdw_slave_wait_for_init() but there is nothing the ensures the core saw the bus disconnection before that call so it might immediately succeed, causing the driver to attempt to access a missing device.

Quoted 6 lines

Yeah the fall of the bus is fast but so are processors, you need to actually ensure you can't shortcut the wait. Although typing this it occurs to me it probably doesn't have to be a wait one can probably just manually reinit the initalization_complete completion. But hopefully I will get this series ready soon and we can discuss on there.

Quoted 6 lines

Don't we already have the interface to detect a device was UNATTACHED? In theory the core will invoke the update_status() callback on every status change. Each driver would use the information to know when the UNATTACHED happened and likewise when the device is enumerated/initialized again. So far most drivers just return and do nothing when an UNATTACHED status is reported.

Yeah so update_status() is the normal mechanism for a driver to know if it becomes unattached AFAIK. Indeed what this is working up to is removing the code in cs42l43 that uses that to track if the device is attached. Although also now you can also use the intialization_complete completion for this purpose too, since it was moved to complete_all().

Quoted 5 lines

The only thing we can't control at the moment is that when a device reports as device0, the core will enumerate it and attempt to initialize it. If additional time is needed prior to the enumeration, we don't have the hooks for it - that would not be quite standard behavior anyways.

Its not really about additional time, there is always time, events in the real world are not instant.

Thread 1 (driver) Thread 2 (core)
----------------- ---------------
Reset device
call wait_for_init()
reinit_completion()

You need something to ensure that wait_for_init() doesn't skip the completion before the core calls reinit_completion(). Or are you saying there is already a mechanism that prevents this that I am missing?

Thanks,
Charles

#17 lore raw
Quoted 48 lines · Charles Keepax
Quoted 18 lines · Pierre-Louis Bossart
Quoted 10 lines · Charles Keepax

On Fri, Jun 19, 2026 at 03:41:44PM +0200, Pierre-Louis Bossart wrote:
The problem is mostly from the device side. This usually comes up from a device reset. So the driver does a reset, device drops off the bus, the device driver doesn't want to carry on until it knows the device is back on the bus. So naively one calls sdw_slave_wait_for_init() but there is nothing the ensures the core saw the bus disconnection before that call so it might immediately succeed, causing the driver to attempt to access a missing device.

Quoted 6 lines

Yeah the fall of the bus is fast but so are processors, you need to actually ensure you can't shortcut the wait. Although typing this it occurs to me it probably doesn't have to be a wait one can probably just manually reinit the initalization_complete completion. But hopefully I will get this series ready soon and we can discuss on there.

Quoted 6 lines

Don't we already have the interface to detect a device was UNATTACHED? In theory the core will invoke the update_status() callback on every status change. Each driver would use the information to know when the UNATTACHED happened and likewise when the device is enumerated/initialized again. So far most drivers just return and do nothing when an UNATTACHED status is reported.

Yeah so update_status() is the normal mechanism for a driver to know if it becomes unattached AFAIK. Indeed what this is working up to is removing the code in cs42l43 that uses that to track if the device is attached. Although also now you can also use the intialization_complete completion for this purpose too, since it was moved to complete_all().

Quoted 5 lines

The only thing we can't control at the moment is that when a device reports as device0, the core will enumerate it and attempt to initialize it. If additional time is needed prior to the enumeration, we don't have the hooks for it - that would not be quite standard behavior anyways.

Its not really about additional time, there is always time, events in the real world are not instant.

Thread 1 (driver) Thread 2 (core)
----------------- ---------------
Reset device
call wait_for_init()
reinit_completion()

Quoted 4 lines

You need something to ensure that wait_for_init() doesn't skip the completion before the core calls reinit_completion(). Or are you saying there is already a mechanism that prevents this that I am missing?

Ah ok I see what you are trying to do.
I am afraid we don't have a mechanism to do what your Thread1 describes, but you could alternatively have a less sequential mechanism where you only do the reset, and then the rest of the initialization is done in the update_status() callback. Your Thread1 would be implemented in two disjoint parts with no need for waiting.

The completions were meant for the suspend/resume cases mostly. I am not sure we want to use completion or any other synchronization between core and peripheral driver, it'd be introducing even more races.

Anyways, best to follow-up with next series, my comments are speculative and probably somewhat off-track..