From cae3063affb350469f4980a6e1aadb94b860dac6 Mon Sep 17 00:00:00 2001 From: Shuming Fan Date: Tue, 8 Dec 2020 21:44:42 -0600 Subject: [PATCH 1/2] ASoC: codecs: rt711: mutex between calibration and power state changes Intel validation reports a 'calibration timeout'. Dynamic debug logs show the power state was changed to D3, let's make sure this cannot happen while the calibration is run. BugLink: https://github.com/thesofproject/linux/issues/2611 Signed-off-by: Shuming Fan Signed-off-by: Pierre-Louis Bossart --- sound/soc/codecs/rt711.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sound/soc/codecs/rt711.c b/sound/soc/codecs/rt711.c index 5771c02c34596f..0ef61a0d054ea0 100644 --- a/sound/soc/codecs/rt711.c +++ b/sound/soc/codecs/rt711.c @@ -544,9 +544,12 @@ static int rt711_set_amp_gain_put(struct snd_kcontrol *kcontrol, break; } + mutex_lock(&rt711->calibrate_mutex); if (dapm->bias_level <= SND_SOC_BIAS_STANDBY) regmap_write(rt711->regmap, RT711_SET_AUDIO_POWER_STATE, AC_PWRST_D3); + mutex_unlock(&rt711->calibrate_mutex); + return 0; } From ed02692b7da52d9652406a5a4c70b661f44e151f Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 8 Dec 2020 19:18:52 +0800 Subject: [PATCH 2/2] ASoC: soundwire: reset unattach_request before wait for completion Optimize the logic a bit, we don't have to reset unattach_request after the regmap_sync tag since we only jump to regmap_sync when unattach_request is 0. Signed-off-by: Bard Liao --- sound/soc/codecs/max98373-sdw.c | 3 ++- sound/soc/codecs/rt1308-sdw.c | 3 ++- sound/soc/codecs/rt1316-sdw.c | 3 ++- sound/soc/codecs/rt5682-sdw.c | 3 ++- sound/soc/codecs/rt700-sdw.c | 3 ++- sound/soc/codecs/rt711-sdca-sdw.c | 3 ++- sound/soc/codecs/rt711-sdw.c | 3 ++- sound/soc/codecs/rt715-sdca-sdw.c | 3 ++- sound/soc/codecs/rt715-sdw.c | 3 ++- 9 files changed, 18 insertions(+), 9 deletions(-) diff --git a/sound/soc/codecs/max98373-sdw.c b/sound/soc/codecs/max98373-sdw.c index ad2d5d6a2fe413..4c92f59ad3ec79 100644 --- a/sound/soc/codecs/max98373-sdw.c +++ b/sound/soc/codecs/max98373-sdw.c @@ -265,6 +265,8 @@ static __maybe_unused int max98373_resume(struct device *dev) if (!slave->unattach_request) goto regmap_sync; + slave->unattach_request = 0; + time = wait_for_completion_timeout(&slave->initialization_complete, msecs_to_jiffies(MAX98373_PROBE_TIMEOUT)); if (!time) { @@ -273,7 +275,6 @@ static __maybe_unused int max98373_resume(struct device *dev) } regmap_sync: - slave->unattach_request = 0; regcache_cache_only(max98373->regmap, false); regcache_sync(max98373->regmap); diff --git a/sound/soc/codecs/rt1308-sdw.c b/sound/soc/codecs/rt1308-sdw.c index afd2c3b687ccb0..767a6211a1da3b 100644 --- a/sound/soc/codecs/rt1308-sdw.c +++ b/sound/soc/codecs/rt1308-sdw.c @@ -715,6 +715,8 @@ static int __maybe_unused rt1308_dev_resume(struct device *dev) if (!slave->unattach_request) goto regmap_sync; + slave->unattach_request = 0; + time = wait_for_completion_timeout(&slave->initialization_complete, msecs_to_jiffies(RT1308_PROBE_TIMEOUT)); if (!time) { @@ -723,7 +725,6 @@ static int __maybe_unused rt1308_dev_resume(struct device *dev) } regmap_sync: - slave->unattach_request = 0; regcache_cache_only(rt1308->regmap, false); regcache_sync_region(rt1308->regmap, 0xc000, 0xcfff); diff --git a/sound/soc/codecs/rt1316-sdw.c b/sound/soc/codecs/rt1316-sdw.c index a68a2e11a7f0b5..219eec4a1b51e2 100644 --- a/sound/soc/codecs/rt1316-sdw.c +++ b/sound/soc/codecs/rt1316-sdw.c @@ -719,6 +719,8 @@ static int __maybe_unused rt1316_dev_resume(struct device *dev) if (!slave->unattach_request) goto regmap_sync; + slave->unattach_request = 0; + time = wait_for_completion_timeout(&slave->initialization_complete, msecs_to_jiffies(RT1316_PROBE_TIMEOUT)); if (!time) { @@ -727,7 +729,6 @@ static int __maybe_unused rt1316_dev_resume(struct device *dev) } regmap_sync: - slave->unattach_request = 0; regcache_cache_only(rt1316->regmap, false); regcache_sync(rt1316->regmap); diff --git a/sound/soc/codecs/rt5682-sdw.c b/sound/soc/codecs/rt5682-sdw.c index 35c9d2be9eeb3a..6baffcbf74ecf0 100644 --- a/sound/soc/codecs/rt5682-sdw.c +++ b/sound/soc/codecs/rt5682-sdw.c @@ -741,6 +741,8 @@ static int __maybe_unused rt5682_dev_resume(struct device *dev) if (!slave->unattach_request) goto regmap_sync; + slave->unattach_request = 0; + time = wait_for_completion_timeout(&slave->initialization_complete, msecs_to_jiffies(RT5682_PROBE_TIMEOUT)); if (!time) { @@ -749,7 +751,6 @@ static int __maybe_unused rt5682_dev_resume(struct device *dev) } regmap_sync: - slave->unattach_request = 0; regcache_cache_only(rt5682->regmap, false); regcache_sync(rt5682->regmap); diff --git a/sound/soc/codecs/rt700-sdw.c b/sound/soc/codecs/rt700-sdw.c index 4001612dfd7378..ac0e68e9aff672 100644 --- a/sound/soc/codecs/rt700-sdw.c +++ b/sound/soc/codecs/rt700-sdw.c @@ -504,6 +504,8 @@ static int __maybe_unused rt700_dev_resume(struct device *dev) if (!slave->unattach_request) goto regmap_sync; + slave->unattach_request = 0; + time = wait_for_completion_timeout(&slave->initialization_complete, msecs_to_jiffies(RT700_PROBE_TIMEOUT)); if (!time) { @@ -512,7 +514,6 @@ static int __maybe_unused rt700_dev_resume(struct device *dev) } regmap_sync: - slave->unattach_request = 0; regcache_cache_only(rt700->regmap, false); regcache_sync_region(rt700->regmap, 0x3000, 0x8fff); regcache_sync_region(rt700->regmap, 0x752010, 0x75206b); diff --git a/sound/soc/codecs/rt711-sdca-sdw.c b/sound/soc/codecs/rt711-sdca-sdw.c index 0603ebb00ab731..566e0832804e8a 100644 --- a/sound/soc/codecs/rt711-sdca-sdw.c +++ b/sound/soc/codecs/rt711-sdca-sdw.c @@ -387,6 +387,8 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev) if (!slave->unattach_request) goto regmap_sync; + slave->unattach_request = 0; + time = wait_for_completion_timeout(&slave->initialization_complete, msecs_to_jiffies(RT711_PROBE_TIMEOUT)); if (!time) { @@ -395,7 +397,6 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev) } regmap_sync: - slave->unattach_request = 0; regcache_cache_only(rt711->regmap, false); regcache_sync(rt711->regmap); regcache_cache_only(rt711->mbq_regmap, false); diff --git a/sound/soc/codecs/rt711-sdw.c b/sound/soc/codecs/rt711-sdw.c index 2beb4286d997bf..413a541ad2750a 100644 --- a/sound/soc/codecs/rt711-sdw.c +++ b/sound/soc/codecs/rt711-sdw.c @@ -507,6 +507,8 @@ static int __maybe_unused rt711_dev_resume(struct device *dev) if (!slave->unattach_request) goto regmap_sync; + slave->unattach_request = 0; + time = wait_for_completion_timeout(&slave->initialization_complete, msecs_to_jiffies(RT711_PROBE_TIMEOUT)); if (!time) { @@ -515,7 +517,6 @@ static int __maybe_unused rt711_dev_resume(struct device *dev) } regmap_sync: - slave->unattach_request = 0; regcache_cache_only(rt711->regmap, false); regcache_sync_region(rt711->regmap, 0x3000, 0x8fff); regcache_sync_region(rt711->regmap, 0x752009, 0x752091); diff --git a/sound/soc/codecs/rt715-sdca-sdw.c b/sound/soc/codecs/rt715-sdca-sdw.c index bcced85876b05a..3c3bd3cbcc6ef7 100644 --- a/sound/soc/codecs/rt715-sdca-sdw.c +++ b/sound/soc/codecs/rt715-sdca-sdw.c @@ -230,6 +230,8 @@ static int __maybe_unused rt715_dev_resume(struct device *dev) if (!slave->unattach_request) goto regmap_sync; + slave->unattach_request = 0; + time = wait_for_completion_timeout(&slave->enumeration_complete, msecs_to_jiffies(RT715_PROBE_TIMEOUT)); if (!time) { @@ -238,7 +240,6 @@ static int __maybe_unused rt715_dev_resume(struct device *dev) } regmap_sync: - slave->unattach_request = 0; regcache_cache_only(rt715->regmap, false); regcache_sync_region(rt715->regmap, SDW_SDCA_CTL(FUN_JACK_CODEC, RT715_SDCA_ST_EN, RT715_SDCA_ST_CTRL, diff --git a/sound/soc/codecs/rt715-sdw.c b/sound/soc/codecs/rt715-sdw.c index 71dd3b97a45904..798c95b0872f3e 100644 --- a/sound/soc/codecs/rt715-sdw.c +++ b/sound/soc/codecs/rt715-sdw.c @@ -547,6 +547,8 @@ static int __maybe_unused rt715_dev_resume(struct device *dev) if (!slave->unattach_request) goto regmap_sync; + slave->unattach_request = 0; + time = wait_for_completion_timeout(&slave->initialization_complete, msecs_to_jiffies(RT715_PROBE_TIMEOUT)); if (!time) { @@ -555,7 +557,6 @@ static int __maybe_unused rt715_dev_resume(struct device *dev) } regmap_sync: - slave->unattach_request = 0; regcache_cache_only(rt715->regmap, false); regcache_sync_region(rt715->regmap, 0x3000, 0x8fff); regcache_sync_region(rt715->regmap, 0x752039, 0x752039);