Skip to contentSkip to conversation

ASoC: codecs: wsa88xx: fix codec initialisation

PATCH In review Johan Hovold 4 participants 16 messages Jan 2 – Jan 6

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

cover ASoC: codecs: wsa88xx: fix codec initialisation

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

This series fixes the Qualcomm wsa88xx codec drivers that do unnecessary reinitialisation or potentially fail to initialise at all.

Included is also a related clean up suppressing a related codec variant printk.

Johan

Johan Hovold (4):
ASoC: codecs: wsa883x: fix unnecessary initialisation
ASoC: codecs: wsa881x: fix unnecessary initialisation
ASoC: codecs: wsa884x: fix codec initialisation
ASoC: codecs: wsa883x: suppress variant printk

 sound/soc/codecs/wsa881x.c |  9 +++++++++
 sound/soc/codecs/wsa883x.c | 26 ++++++++++++++++++--------
 sound/soc/codecs/wsa884x.c |  3 +--
 3 files changed, 28 insertions(+), 10 deletions(-)
Signature · 1 line
2.51.2
#1 lore raw

PATCH 1/4 ASoC: codecs: wsa883x: fix unnecessary initialisation

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

This avoids repeated initialisation of the codecs during boot of machines like the Lenovo ThinkPad X13s:

[   11.614523] wsa883x-codec sdw:1:0:0217:0202:00:1: WSA883X Version 1_1, Variant: WSA8835_V2
[   11.618022] wsa883x-codec sdw:1:0:0217:0202:00:1: WSA883X Version 1_1, Variant: WSA8835_V2
[   11.621377] wsa883x-codec sdw:1:0:0217:0202:00:1: WSA883X Version 1_1, Variant: WSA8835_V2
[   11.624065] wsa883x-codec sdw:1:0:0217:0202:00:1: WSA883X Version 1_1, Variant: WSA8835_V2
[   11.631382] wsa883x-codec sdw:1:0:0217:0202:00:2: WSA883X Version 1_1, Variant: WSA8835_V2
[   11.634424] wsa883x-codec sdw:1:0:0217:0202:00:2: WSA883X Version 1_1, Variant: WSA8835_V2
Fixes 43b8c7dc85a1 ("ASoC: codecs: add wsa883x amplifier support")
Cc Srinivas Kandagatla <[email protected]>
---
 sound/soc/codecs/wsa883x.c | 9 +++++++++
 1 file changed, 9 insertions(+)
sound/soc/codecs/wsa883x.c +9 -0
index c3046e260cb9..3ffea56aeb0f 100644
@@ -475,6 +475,7 @@ struct wsa883x_priv {
 	int active_ports;
 	int dev_mode;
 	int comp_offset;
+	bool hw_init;
 	/*
 	 * Protects temperature reading code (related to speaker protection) and
 	 * fields: temperature and pa_on.
@@ -1043,6 +1044,9 @@ static int wsa883x_init(struct wsa883x_priv *wsa883x)
 	struct regmap *regmap = wsa883x->regmap;
 	int variant, version, ret;
 
+	if (wsa883x->hw_init)
+		return 0;
+
 	ret = regmap_read(regmap, WSA883X_OTP_REG_0, &variant);
 	if (ret)
 		return ret;
@@ -1085,6 +1089,8 @@ static int wsa883x_init(struct wsa883x_priv *wsa883x)
 				   wsa883x->comp_offset);
 	}
 
+	wsa883x->hw_init = true;
+
 	return 0;
 }
 
@@ -1093,6 +1099,9 @@ static int wsa883x_update_status(struct sdw_slave *slave,
 {
 	struct wsa883x_priv *wsa883x = dev_get_drvdata(&slave->dev);
 
+	if (status == SDW_SLAVE_UNATTACHED)
+		wsa883x->hw_init = false;
+
 	if (status == SDW_SLAVE_ATTACHED && slave->dev_num > 0)
 		return wsa883x_init(wsa883x);
 
Signature · 1 line
2.51.2
Reviewed-by on v1 1/4
#2 lore raw

Re: [PATCH 1/4] ASoC: codecs: wsa883x: fix unnecessary initialisation

Quoted 14 lines · Johan Hovold

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

This avoids repeated initialisation of the codecs during boot of machines like the Lenovo ThinkPad X13s:

[   11.614523] wsa883x-codec sdw:1:0:0217:0202:00:1: WSA883X Version 1_1, Variant: WSA8835_V2
[   11.618022] wsa883x-codec sdw:1:0:0217:0202:00:1: WSA883X Version 1_1, Variant: WSA8835_V2
[   11.621377] wsa883x-codec sdw:1:0:0217:0202:00:1: WSA883X Version 1_1, Variant: WSA8835_V2
[   11.624065] wsa883x-codec sdw:1:0:0217:0202:00:1: WSA883X Version 1_1, Variant: WSA8835_V2
[   11.631382] wsa883x-codec sdw:1:0:0217:0202:00:2: WSA883X Version 1_1, Variant: WSA8835_V2
[   11.634424] wsa883x-codec sdw:1:0:0217:0202:00:2: WSA883X Version 1_1, Variant: WSA8835_V2
Quoted 3 lines
Fixes 43b8c7dc85a1 ("ASoC: codecs: add wsa883x amplifier support")
Cc Srinivas Kandagatla <[email protected]>

Best regards,
Krzysztof

#3 lore raw

PATCH 2/4 ASoC: codecs: wsa881x: fix unnecessary initialisation

In reply to Johan Hovold

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

Fixes a0aab9e1404a ("ASoC: codecs: add wsa881x amplifier support")
Cc Srinivas Kandagatla <[email protected]>
---
 sound/soc/codecs/wsa881x.c | 9 +++++++++
 1 file changed, 9 insertions(+)
sound/soc/codecs/wsa881x.c +9 -0
index d7aca6567c2d..2fc234adca5f 100644
@@ -678,6 +678,7 @@ struct wsa881x_priv {
 	 */
 	unsigned int sd_n_val;
 	int active_ports;
+	bool hw_init;
 	bool port_prepared[WSA881X_MAX_SWR_PORTS];
 	bool port_enable[WSA881X_MAX_SWR_PORTS];
 };
@@ -687,6 +688,9 @@ static void wsa881x_init(struct wsa881x_priv *wsa881x)
 	struct regmap *rm = wsa881x->regmap;
 	unsigned int val = 0;
 
+	if (wsa881x->hw_init)
+		return;
+
 	regmap_register_patch(wsa881x->regmap, wsa881x_rev_2_0,
 			      ARRAY_SIZE(wsa881x_rev_2_0));
 
@@ -724,6 +728,8 @@ static void wsa881x_init(struct wsa881x_priv *wsa881x)
 	regmap_update_bits(rm, WSA881X_OTP_REG_28, 0x3F, 0x3A);
 	regmap_update_bits(rm, WSA881X_BONGO_RESRV_REG1, 0xFF, 0xB2);
 	regmap_update_bits(rm, WSA881X_BONGO_RESRV_REG2, 0xFF, 0x05);
+
+	wsa881x->hw_init = true;
 }
 
 static int wsa881x_component_probe(struct snd_soc_component *comp)
@@ -1067,6 +1073,9 @@ static int wsa881x_update_status(struct sdw_slave *slave,
 {
 	struct wsa881x_priv *wsa881x = dev_get_drvdata(&slave->dev);
 
+	if (status == SDW_SLAVE_UNATTACHED)
+		wsa881x->hw_init = false;
+
 	if (status == SDW_SLAVE_ATTACHED && slave->dev_num > 0)
 		wsa881x_init(wsa881x);
 
Signature · 1 line
2.51.2
Reviewed-by on v1 2/4
#4 lore raw

Re: [PATCH 2/4] ASoC: codecs: wsa881x: fix unnecessary initialisation

Quoted 9 lines · Johan Hovold

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

Fixes a0aab9e1404a ("ASoC: codecs: add wsa881x amplifier support")
Cc Srinivas Kandagatla <[email protected]>

---

Best regards,
Krzysztof

#5 lore raw

PATCH 3/4 ASoC: codecs: wsa884x: fix codec initialisation

In reply to Johan Hovold

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

Fix the inverted hw_init flag which was set to false instead of true after initialisation which defeats its purpose and may result in repeated unnecessary initialisation.

Similarly, the initial state of the flag was also inverted so that the codec would only be initialised and brought out of regmap cache only mode if its status first transitions to UNATTACHED.

Fixes aa21a7d4f68a ("ASoC: codecs: wsa884x: Add WSA884x family of speakers")
Cc Krzysztof Kozlowski <[email protected]>
---
 sound/soc/codecs/wsa884x.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
sound/soc/codecs/wsa884x.c +1 -2
index 887edd2be705..6c6b497657d0 100644
@@ -1534,7 +1534,7 @@ static void wsa884x_init(struct wsa884x_priv *wsa884x)
 
 	wsa884x_set_gain_parameters(wsa884x);
 
-	wsa884x->hw_init = false;
+	wsa884x->hw_init = true;
 }
 
 static int wsa884x_update_status(struct sdw_slave *slave,
@@ -2109,7 +2109,6 @@ static int wsa884x_probe(struct sdw_slave *pdev,
 
 	/* Start in cache-only until device is enumerated */
 	regcache_cache_only(wsa884x->regmap, true);
-	wsa884x->hw_init = true;
 
 	if (IS_REACHABLE(CONFIG_HWMON)) {
 		struct device *hwmon;
Signature · 1 line
2.51.2
#6 lore raw

Re: [PATCH 3/4] ASoC: codecs: wsa884x: fix codec initialisation

Quoted 7 lines · Johan Hovold

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

Fix the inverted hw_init flag which was set to false instead of true after initialisation which defeats its purpose and may result in repeated unnecessary initialisation.

Either it results or it does not, not "may". If the device moves to UNATTACHED state flag should be probably set to "true". This is the bug.

Quoted 4 lines

Similarly, the initial state of the flag was also inverted so that the codec would only be initialised and brought out of regmap cache only mode if its status first transitions to UNATTACHED.

Maybe that's confusing wording but existing code was intentional and IMO almost correct. The flag is saying - we need hw init - that's why it is set to true in the probe and to false AFTER the proper hw initialization which is done after ATTACHED state.

If you find naming confusing, maybe rename it to other style or fix the false -> true when going to unattached stat, but not everything at once.

Best regards,
Krzysztof

#7 lore raw

Re: [PATCH 3/4] ASoC: codecs: wsa884x: fix codec initialisation

Quoted 10 lines · Krzysztof Kozlowski
Quoted 7 lines · Johan Hovold

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

Fix the inverted hw_init flag which was set to false instead of true after initialisation which defeats its purpose and may result in repeated unnecessary initialisation.

Either it results or it does not, not "may".

No, it depends on whether update_status() is called with the same status more than once. So "may" is correct here.

Quoted 2 lines

If the device moves to
UNATTACHED state flag should be probably set to "true". This is the bug.

No, update_status() has:

	if (wsa884x->hw_init || status != SDW_SLAVE_ATTACHED)
		return 0;

	...

	wsa884x_init(wsa884x);

so if you set hw_init to true then init is never called when status is changed to ATTACHED.

Quoted 9 lines
Quoted 4 lines

Similarly, the initial state of the flag was also inverted so that the codec would only be initialised and brought out of regmap cache only mode if its status first transitions to UNATTACHED.

Maybe that's confusing wording but existing code was intentional and IMO almost correct. The flag is saying - we need hw init - that's why it is set to true in the probe and to false AFTER the proper hw initialization which is done after ATTACHED state.

All other codec drivers have hw_init mean that init has been done and the check in update_status() reflects that too so this driver is still broken.

Johan

#8 lore raw

Re: [PATCH 3/4] ASoC: codecs: wsa884x: fix codec initialisation

Quoted 27 lines · Johan Hovold
Quoted 10 lines · Krzysztof Kozlowski
Quoted 7 lines · Johan Hovold

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

Fix the inverted hw_init flag which was set to false instead of true after initialisation which defeats its purpose and may result in repeated unnecessary initialisation.

Either it results or it does not, not "may".

No, it depends on whether update_status() is called with the same status more than once. So "may" is correct here.

Quoted 2 lines

If the device moves to
UNATTACHED state flag should be probably set to "true". This is the bug.

No, update_status() has:

	if (wsa884x->hw_init || status != SDW_SLAVE_ATTACHED)
		return 0;

	...

	wsa884x_init(wsa884x);
Quoted 2 lines

so if you set hw_init to true then init is never called when status is changed to ATTACHED.

Uh, indeed, so this was supposed to be !wsa884x->hw_init... or indeed your meaning. This also means that this was never passing above if() and the init() was never called.

regcache was probably synced via runtime PM, so at least that part worked.

Did you test this driver on actual device how it affects the behavior?

Quoted 6 lines
Quoted 6 lines
Quoted 5 lines

Similarly, the initial state of the flag was also inverted so that the codec would only be initialised and brought out of regmap cache only mode if its status first transitions to UNATTACHED.

Quoted 8 lines
Quoted 4 lines

Maybe that's confusing wording but existing code was intentional and IMO almost correct. The flag is saying - we need hw init - that's why it is set to true in the probe and to false AFTER the proper hw initialization which is done after ATTACHED state.

All other codec drivers have hw_init mean that init has been done and the check in update_status() reflects that too so this driver is still broken.

ok

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH 3/4] ASoC: codecs: wsa884x: fix codec initialisation

Quoted 23 lines · Krzysztof Kozlowski
Quoted 19 lines · Johan Hovold
Quoted 8 lines · Krzysztof Kozlowski
Quoted 7 lines · Johan Hovold

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

Fix the inverted hw_init flag which was set to false instead of true after initialisation which defeats its purpose and may result in repeated unnecessary initialisation.

No, update_status() has:

	if (wsa884x->hw_init || status != SDW_SLAVE_ATTACHED)
		return 0;

	...

	wsa884x_init(wsa884x);
Quoted 2 lines

so if you set hw_init to true then init is never called when status is changed to ATTACHED.

Quoted 7 lines

Uh, indeed, so this was supposed to be !wsa884x->hw_init... or indeed your meaning. This also means that this was never passing above if() and the init() was never called.

regcache was probably synced via runtime PM, so at least that part worked.

Did you test this driver on actual device how it affects the behavior?

No, I don't have a device that uses this codec anymore.

If you could give it a spin that would be great. It seems we have been depending on reset values or an UNATTACHED => ATTACHED transition so far.

Johan

#10 lore raw

Re: [PATCH 3/4] ASoC: codecs: wsa884x: fix codec initialisation

Quoted 13 lines · Johan Hovold
Quoted 13 lines
Quoted 6 lines
	...

	wsa884x_init(wsa884x);

so if you set hw_init to true then init is never called when status is changed to ATTACHED.

Uh, indeed, so this was supposed to be !wsa884x->hw_init... or indeed your meaning. This also means that this was never passing above if() and the init() was never called.

regcache was probably synced via runtime PM, so at least that part worked.

Quoted 7 lines
Quoted 1 line

Did you test this driver on actual device how it affects the behavior?

No, I don't have a device that uses this codec anymore.

If you could give it a spin that would be great. It seems we have been depending on reset values or an UNATTACHED => ATTACHED transition so far.

I can test it, maybe after the weekend.

Best regards,
Krzysztof

Reviewed-by Tested-by on v1 3/4
#11 lore raw

Re: [PATCH 3/4] ASoC: codecs: wsa884x: fix codec initialisation

In reply to Johan Hovold
Quoted 12 lines · Johan Hovold

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

Fix the inverted hw_init flag which was set to false instead of true after initialisation which defeats its purpose and may result in repeated unnecessary initialisation.

Similarly, the initial state of the flag was also inverted so that the codec would only be initialised and brought out of regmap cache only mode if its status first transitions to UNATTACHED.

Quoted 5 lines
Fixes aa21a7d4f68a ("ASoC: codecs: wsa884x: Add WSA884x family of speakers")
Cc Krzysztof Kozlowski <[email protected]>

---

Tested on Lenovo T14s:

Best regards,
Krzysztof

#12 lore raw

PATCH 4/4 ASoC: codecs: wsa883x: suppress variant printk

In reply to Johan Hovold

Drivers should generally be silent on successful probe.

Demote the codec variant printk to debug level and instead add a warning in case an unknown variant is ever encountered.

---
 sound/soc/codecs/wsa883x.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)
sound/soc/codecs/wsa883x.c +9 -8
index 3ffea56aeb0f..468d2b38a22a 100644
@@ -1058,22 +1058,23 @@ static int wsa883x_init(struct wsa883x_priv *wsa883x)
 
 	switch (variant) {
 	case WSA8830:
-		dev_info(wsa883x->dev, "WSA883X Version 1_%d, Variant: WSA8830\n",
-			 version);
+		dev_dbg(wsa883x->dev, "WSA883X Version 1_%d, Variant: WSA8830\n",
+			version);
 		break;
 	case WSA8835:
-		dev_info(wsa883x->dev, "WSA883X Version 1_%d, Variant: WSA8835\n",
-			 version);
+		dev_dbg(wsa883x->dev, "WSA883X Version 1_%d, Variant: WSA8835\n",
+			version);
 		break;
 	case WSA8832:
-		dev_info(wsa883x->dev, "WSA883X Version 1_%d, Variant: WSA8832\n",
-			 version);
+		dev_dbg(wsa883x->dev, "WSA883X Version 1_%d, Variant: WSA8832\n",
+			version);
 		break;
 	case WSA8835_V2:
-		dev_info(wsa883x->dev, "WSA883X Version 1_%d, Variant: WSA8835_V2\n",
-			 version);
+		dev_dbg(wsa883x->dev, "WSA883X Version 1_%d, Variant: WSA8835_V2\n",
+			version);
 		break;
 	default:
+		dev_warn(wsa883x->dev, "unknown variant: %d\n", variant);
 		break;
 	}
 
Signature · 1 line
2.51.2
Reviewed-by on v1 4/4
#13 lore raw

Re: [PATCH 4/4] ASoC: codecs: wsa883x: suppress variant printk

Quoted 10 lines · Johan Hovold

Drivers should generally be silent on successful probe.

Demote the codec variant printk to debug level and instead add a warning in case an unknown variant is ever encountered.

---
 sound/soc/codecs/wsa883x.c | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

Best regards,
Krzysztof

Reviewed-by on the v1 series
#14 lore raw
In reply to Johan Hovold
Quoted 4 lines · Johan Hovold

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

Quoted 9 lines

This series fixes the Qualcomm wsa88xx codec drivers that do unnecessary reinitialisation or potentially fail to initialise at all.

Included is also a related clean up suppressing a related codec variant printk.

Johan

Thanks Johan for cleaning this up.

--srini

Quoted 11 lines

Johan Hovold (4):
ASoC: codecs: wsa883x: fix unnecessary initialisation
ASoC: codecs: wsa881x: fix unnecessary initialisation
ASoC: codecs: wsa884x: fix codec initialisation
ASoC: codecs: wsa883x: suppress variant printk

 sound/soc/codecs/wsa881x.c |  9 +++++++++
 sound/soc/codecs/wsa883x.c | 26 ++++++++++++++++++--------
 sound/soc/codecs/wsa884x.c |  3 +--
 3 files changed, 28 insertions(+), 10 deletions(-)
maintainer
#15 lore raw
In reply to Johan Hovold
Quoted 8 lines · Johan Hovold

The soundwire update_status() callback may be called multiple times with the same ATTACHED status but initialisation should only be done when transitioning from UNATTACHED to ATTACHED.

This series fixes the Qualcomm wsa88xx codec drivers that do unnecessary reinitialisation or potentially fail to initialise at all.

[...]

Applied to

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

Thanks!

[1/4] ASoC: codecs: wsa883x: fix unnecessary initialisation

      commit: 49aadf830eb048134d33ad7329d92ecff45d8dbb
[2/4] ASoC: codecs: wsa881x: fix unnecessary initialisation
      commit: 29d71b8a5a40708b3eed9ba4953bfc2312c9c776
[3/4] ASoC: codecs: wsa884x: fix codec initialisation
      commit: 120f3e6ff76209ee2f62a64e5e7e9d70274df42b
[4/4] ASoC: codecs: wsa883x: suppress variant printk
      commit: 46a16d89d097ac2c93b63382a37d60aa7f21dc71

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