Skip to content

Commit 128f65c

Browse files
committed
ASoC: rt1318: wait codec init in hw_params
Move regmap sync to rt1318_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@linux.intel.com>
1 parent bd1d8a5 commit 128f65c

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

sound/soc/codecs/rt1318-sdw.c

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,7 @@ static int rt1318_update_status(struct sdw_slave *slave,
445445
enum sdw_slave_status status)
446446
{
447447
struct rt1318_sdw_priv *rt1318 = dev_get_drvdata(&slave->dev);
448+
int ret;
448449

449450
if (status == SDW_SLAVE_UNATTACHED)
450451
rt1318->hw_init = false;
@@ -457,7 +458,18 @@ static int rt1318_update_status(struct sdw_slave *slave,
457458
return 0;
458459

459460
/* perform I/O transfers required for Slave initialization */
460-
return rt1318_io_init(&slave->dev, slave);
461+
ret = rt1318_io_init(&slave->dev, slave);
462+
if (ret < 0) {
463+
dev_err(&slave->dev, "%s: I/O init failed: %d\n", __func__, ret);
464+
return ret;
465+
}
466+
467+
if (slave->unattach_request) {
468+
regcache_cache_only(rt1318->regmap, false);
469+
regcache_sync(rt1318->regmap);
470+
}
471+
472+
return ret;
461473
}
462474

463475
static int rt1318_classd_event(struct snd_soc_dapm_widget *w,
@@ -560,6 +572,8 @@ static void rt1318_sdw_shutdown(struct snd_pcm_substream *substream,
560572
snd_soc_dai_set_dma_data(dai, substream, NULL);
561573
}
562574

575+
#define RT1318_PROBE_TIMEOUT 5000
576+
563577
static int rt1318_sdw_hw_params(struct snd_pcm_substream *substream,
564578
struct snd_pcm_hw_params *params, struct snd_soc_dai *dai)
565579
{
@@ -603,6 +617,10 @@ static int rt1318_sdw_hw_params(struct snd_pcm_substream *substream,
603617
port_config.ch_mask = ch_mask;
604618
port_config.num = port;
605619

620+
retval = sdw_slave_wait_for_initialization(rt1318->sdw_slave, RT1318_PROBE_TIMEOUT);
621+
if (retval < 0)
622+
return retval;
623+
606624
retval = sdw_stream_add_slave(rt1318->sdw_slave, &stream_config,
607625
&port_config, 1, sdw_stream);
608626
if (retval) {
@@ -818,26 +836,18 @@ static int rt1318_dev_suspend(struct device *dev)
818836
return 0;
819837
}
820838

821-
#define RT1318_PROBE_TIMEOUT 5000
822-
823839
static int rt1318_dev_resume(struct device *dev)
824840
{
825841
struct sdw_slave *slave = dev_to_sdw_dev(dev);
826842
struct rt1318_sdw_priv *rt1318 = dev_get_drvdata(dev);
827-
unsigned long time;
828843

829844
if (!rt1318->first_hw_init)
830845
return 0;
831846

832847
if (!slave->unattach_request)
833848
goto regmap_sync;
834849

835-
time = wait_for_completion_timeout(&slave->initialization_complete,
836-
msecs_to_jiffies(RT1318_PROBE_TIMEOUT));
837-
if (!time) {
838-
dev_err(&slave->dev, "%s: Initialization not complete, timed out\n", __func__);
839-
return -ETIMEDOUT;
840-
}
850+
return 0;
841851

842852
regmap_sync:
843853
slave->unattach_request = 0;

0 commit comments

Comments
 (0)