[PATCH 02/15] ASoC: rt722: wait codec init in hw_params

From: Bard Liao
Date: Thu Jun 26 2025 - 07:59:00 EST


Move regmap sync to rt722_sdca_update_status() when unattach_request
is set, and only do regmap sync in resume when no reattach needed.
And move waiting codec init to hw_params when the codec really need to
be initialized. The change can shorten the resume time.

Signed-off-by: Bard Liao <yung-chuan.liao@xxxxxxxxxxxxxxx>
Reviewed-by: Shuming Fan <shumingf@xxxxxxxxxxx>
Reviewed-by: Charles Keepax <ckeepax@xxxxxxxxxxxxxxxxxxxxx>
---
sound/soc/codecs/rt722-sdca-sdw.c | 26 ++++++++++++++------------
sound/soc/codecs/rt722-sdca.c | 6 ++++++
2 files changed, 20 insertions(+), 12 deletions(-)

diff --git a/sound/soc/codecs/rt722-sdca-sdw.c b/sound/soc/codecs/rt722-sdca-sdw.c
index 70700bdb80a1..b72d169bf15e 100644
--- a/sound/soc/codecs/rt722-sdca-sdw.c
+++ b/sound/soc/codecs/rt722-sdca-sdw.c
@@ -209,6 +209,7 @@ static int rt722_sdca_update_status(struct sdw_slave *slave,
enum sdw_slave_status status)
{
struct rt722_sdca_priv *rt722 = dev_get_drvdata(&slave->dev);
+ int ret;

if (status == SDW_SLAVE_UNATTACHED)
rt722->hw_init = false;
@@ -236,7 +237,18 @@ static int rt722_sdca_update_status(struct sdw_slave *slave,
return 0;

/* perform I/O transfers required for Slave initialization */
- return rt722_sdca_io_init(&slave->dev, slave);
+ ret = rt722_sdca_io_init(&slave->dev, slave);
+ if (ret < 0) {
+ dev_err(&slave->dev, "IO init failed: %d\n", ret);
+ return ret;
+ }
+
+ if (slave->unattach_request) {
+ regcache_cache_only(rt722->regmap, false);
+ regcache_sync(rt722->regmap);
+ }
+
+ return ret;
}

static int rt722_sdca_read_prop(struct sdw_slave *slave)
@@ -495,13 +507,10 @@ static int rt722_sdca_dev_system_suspend(struct device *dev)
return rt722_sdca_dev_suspend(dev);
}

-#define RT722_PROBE_TIMEOUT 5000
-
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;

if (!rt722->first_hw_init)
return 0;
@@ -517,14 +526,7 @@ static int rt722_sdca_dev_resume(struct device *dev)
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);
-
- return -ETIMEDOUT;
- }
+ return 0;

regmap_sync:
slave->unattach_request = 0;
diff --git a/sound/soc/codecs/rt722-sdca.c b/sound/soc/codecs/rt722-sdca.c
index ac9588284a95..68ba252467d0 100644
--- a/sound/soc/codecs/rt722-sdca.c
+++ b/sound/soc/codecs/rt722-sdca.c
@@ -1114,6 +1114,8 @@ static void rt722_sdca_shutdown(struct snd_pcm_substream *substream,
snd_soc_dai_set_dma_data(dai, substream, NULL);
}

+#define RT722_PROBE_TIMEOUT 5000
+
static int rt722_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
@@ -1168,6 +1170,10 @@ static int rt722_sdca_pcm_hw_params(struct snd_pcm_substream *substream,
port_config.ch_mask = GENMASK(num_channels - 1, 0);
port_config.num = port;

+ retval = sdw_slave_wait_for_initialization(rt722->slave, RT722_PROBE_TIMEOUT);
+ if (retval < 0)
+ return retval;
+
retval = sdw_stream_add_slave(rt722->slave, &stream_config,
&port_config, 1, sdw_stream);
if (retval) {
--
2.43.0