Skip to contentSkip to conversation

ASoC: SDCA: restore the settings if power is lost during suspend

PATCH In review [email protected] 3 participants 5 messages Apr 8

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

PATCH 1/1 ASoC: SDCA: restore the settings if power is lost during suspend

From: Shuming Fan <[email protected]>

We should restore the MIPI-defined registers when the device is attached.
If a function status interrupt occurs, the device will trigger an interrupt to reload the settings.

---
 sound/soc/sdca/sdca_class.c      |  4 ++++
 sound/soc/sdca/sdca_interrupts.c | 10 +++++++++-
 2 files changed, 13 insertions(+), 1 deletion(-)
sound/soc/sdca/sdca_class.c +4 -0
index 7af4e5d1b347..d1feaa57eae7 100644
@@ -49,6 +49,10 @@ static int class_sdw_update_status(struct sdw_slave *sdw, enum sdw_slave_status
 		drv->attached = true;
 
 		complete(&drv->device_attach);
+
+		/* resync the MIPI-defined registers if the device loses power */
+		regcache_mark_dirty(drv->dev_regmap);
+		regcache_sync(drv->dev_regmap);
 		break;
 	case SDW_SLAVE_UNATTACHED:
 		dev_dbg(drv->dev, "device detach\n");
sound/soc/sdca/sdca_interrupts.c +9 -1
index 1838dabcdf60..ee69486e6b68 100644
@@ -24,6 +24,7 @@
 #include <sound/sdca_interrupts.h>
 #include <sound/sdca_jack.h>
 #include <sound/sdca_ump.h>
+#include <sound/sdca_regmap.h>
 #include <sound/soc-component.h>
 #include <sound/soc.h>
 
@@ -121,7 +122,14 @@ static irqreturn_t function_status_handler(int irq, void *data)
 
 		switch (mask) {
 		case SDCA_CTL_ENTITY_0_FUNCTION_NEEDS_INITIALIZATION:
-			//FIXME: Add init writes
+			dev_info(dev, "%s function needs initialisation\n", interrupt->function->desc->name);
+			ret = sdca_regmap_write_init(dev, interrupt->device_regmap,
+					     interrupt->function);
+			if (ret)
+				return ret;
+			/* resync the function registers */
+			regcache_mark_dirty(interrupt->function_regmap);
+			regcache_sync(interrupt->function_regmap);
 			break;
 		case SDCA_CTL_ENTITY_0_FUNCTION_FAULT:
 			dev_err(dev, "function fault\n");
Signature · 1 line
2.53.0
maintainer
#1 lore raw
Quoted 5 lines · On Wed, Apr 08, 2026 at 04:56:07PM +0800, [email protected] wrote:

From: Shuming Fan <[email protected]>

We should restore the MIPI-defined registers when the device is attached.
If a function status interrupt occurs, the device will trigger an interrupt to reload the settings.

Are you actually hitting this in practice? What is the situation where the device loses power but it isn't covered by the normal suspend/resume flow?

Thanks,
Charles

#2 lore raw
Quoted 10 lines · On Wed, Apr 08, 2026 at 04:56:07PM +0800, [email protected] wrote:
Quoted 4 lines

From: Shuming Fan <[email protected]>

We should restore the MIPI-defined registers when the device is attached. If a function status interrupt occurs, the device will trigger an interrupt to

reload the settings.

Quoted 1 line

Are you actually hitting this in practice? What is the situation where the device loses power but it isn't covered by the normal suspend/resume flow?

This is a scenario where the machine enters hibernation and cuts power to the codec. I simulated this case and verified that it works as expected.

maintainer
#3 lore raw
Quoted 5 lines · Shuming [范書銘]
Quoted 5 lines · On Wed, Apr 08, 2026 at 04:56:07PM +0800, [email protected] wrote:
Quoted 4 lines

From: Shuming Fan <[email protected]>

We should restore the MIPI-defined registers when the device is attached. If a function status interrupt occurs, the device will trigger an interrupt to

Quoted 9 lines
Quoted 5 lines

reload the settings.

Quoted 1 line

Are you actually hitting this in practice? What is the situation where the device loses power but it isn't covered by the normal suspend/resume flow?

This is a scenario where the machine enters hibernation and cuts power to the codec. I simulated this case and verified that it works as expected.

But in that case the suspend/resume callback should be called and the cache should be synchronised on that path. Are you not seeing those run?

Thanks,
Charles

#4 lore raw
In reply to Shuming [范書銘]
Quoted 5 lines · Shuming [范書銘]
Quoted 5 lines · On Wed, Apr 08, 2026 at 04:56:07PM +0800, [email protected] wrote:
Quoted 4 lines

From: Shuming Fan <[email protected]>

We should restore the MIPI-defined registers when the device is attached. If a function status interrupt occurs, the device will trigger an interrupt to

Quoted 9 lines
Quoted 5 lines

reload the settings.

Quoted 1 line

Are you actually hitting this in practice? What is the situation where the device loses power but it isn't covered by the normal suspend/resume flow?

This is a scenario where the machine enters hibernation and cuts power to the codec. I simulated this case and verified that it works as expected.

class_runtime_resume() already does:

	regcache_mark_dirty(drv->dev_regmap);

	ret = regcache_sync(drv->dev_regmap);