From a7375b69f1c0cd434fdedef16cd11b03ae5a2e4b Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Sat, 5 Dec 2020 09:18:00 -0600 Subject: [PATCH 01/14] soundwire: bus: add ALERT paranoia check The state machine requires that we first initialize the device after attachment before dealing with alerts. Add an error case if that isn't the case. Signed-off-by: Pierre-Louis Bossart --- drivers/soundwire/bus.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index c7b623875cc571..3848b43fe911dc 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -1748,6 +1748,12 @@ int sdw_handle_slave_status(struct sdw_bus *bus, break; case SDW_SLAVE_ALERT: + if (slave->status != SDW_SLAVE_ATTACHED) { + dev_err(&slave->dev, + "Slave %d reports alert but was not attached before\n", i); + break; + } + ret = sdw_handle_slave_alerts(slave); if (ret) dev_err(&slave->dev, From 91c29d1dcdc940e11df40bc21614419aca765fdb Mon Sep 17 00:00:00 2001 From: Bard Liao Date: Tue, 8 Dec 2020 19:18:52 +0800 Subject: [PATCH 02/14] 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); From 2bf5e538c6e2968e19e68d53de360fa7c2a91b76 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Sat, 5 Dec 2020 09:22:37 -0600 Subject: [PATCH 03/14] soundwire: bus: add better dev_dbg to track complete() calls Add a dev_dbg() log for both enumeration and initialization completion to better track suspend-resume issues. Signed-off-by: Pierre-Louis Bossart --- drivers/soundwire/bus.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 3848b43fe911dc..994ec6e8473a46 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -801,7 +801,7 @@ static void sdw_modify_slave_status(struct sdw_slave *slave, if (status == SDW_SLAVE_UNATTACHED) { dev_dbg(&slave->dev, - "%s: initializing completion for Slave %d\n", + "%s: initializing enumeration and init completion for Slave %d\n", __func__, slave->dev_num); init_completion(&slave->enumeration_complete); @@ -810,7 +810,7 @@ static void sdw_modify_slave_status(struct sdw_slave *slave, } else if ((status == SDW_SLAVE_ATTACHED) && (slave->status == SDW_SLAVE_UNATTACHED)) { dev_dbg(&slave->dev, - "%s: signaling completion for Slave %d\n", + "%s: signaling enumeration completion for Slave %d\n", __func__, slave->dev_num); complete(&slave->enumeration_complete); @@ -1791,8 +1791,13 @@ int sdw_handle_slave_status(struct sdw_bus *bus, if (ret) dev_err(&slave->dev, "Update Slave status failed:%d\n", ret); - if (attached_initializing) + if (attached_initializing) { + dev_dbg(&slave->dev, + "%s: signaling initialization completion for Slave %d\n", + __func__, slave->dev_num); + complete(&slave->initialization_complete); + } } return ret; From 9336db02ab78758827f377824210f59d349ccf12 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Sat, 5 Dec 2020 09:52:01 -0600 Subject: [PATCH 04/14] soundwire: bus: add before and after traces on update_status callback this is very verbose but may be useful to track update_status() progress Signed-off-by: Pierre-Louis Bossart --- drivers/soundwire/bus.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 994ec6e8473a46..03bc6e0a6fb055 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -1657,6 +1657,7 @@ static int sdw_update_slave_status(struct sdw_slave *slave, enum sdw_slave_status status) { unsigned long time; + int ret; if (!slave->probed) { /* @@ -1678,7 +1679,11 @@ static int sdw_update_slave_status(struct sdw_slave *slave, if (!slave->ops || !slave->ops->update_status) return 0; - return slave->ops->update_status(slave, status); + dev_dbg(&slave->dev, "update_status starting\n"); + ret = slave->ops->update_status(slave, status); + dev_dbg(&slave->dev, "update_status done\n"); + + return ret; } /** From 4bf808ec13b574c5416aa8a957d60b4ca9e8c9a6 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Sat, 5 Dec 2020 14:09:16 -0600 Subject: [PATCH 05/14] ASoC: rt711-sdw: add pm_mark_last_busy in resume function make sure the suspend timeout is properly managed. Signed-off-by: Pierre-Louis Bossart --- sound/soc/codecs/rt711-sdca-sdw.c | 4 ++++ sound/soc/codecs/rt711-sdw.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/sound/soc/codecs/rt711-sdca-sdw.c b/sound/soc/codecs/rt711-sdca-sdw.c index 566e0832804e8a..9e2a092d4fcb98 100644 --- a/sound/soc/codecs/rt711-sdca-sdw.c +++ b/sound/soc/codecs/rt711-sdca-sdw.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -401,6 +402,9 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev) regcache_sync(rt711->regmap); regcache_cache_only(rt711->mbq_regmap, false); regcache_sync(rt711->mbq_regmap); + + pm_runtime_mark_last_busy(dev); + return 0; } diff --git a/sound/soc/codecs/rt711-sdw.c b/sound/soc/codecs/rt711-sdw.c index 413a541ad2750a..d41c1eb55f3d74 100644 --- a/sound/soc/codecs/rt711-sdw.c +++ b/sound/soc/codecs/rt711-sdw.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -521,6 +522,8 @@ static int __maybe_unused rt711_dev_resume(struct device *dev) regcache_sync_region(rt711->regmap, 0x3000, 0x8fff); regcache_sync_region(rt711->regmap, 0x752009, 0x752091); + pm_runtime_mark_last_busy(dev); + return 0; } From b608ea61eb1836df7d06741e135e115665cd0e50 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Sat, 5 Dec 2020 09:57:14 -0600 Subject: [PATCH 06/14] ASoC: rt711*: add traces for resume let's see what happens with resume operations. Signed-off-by: Pierre-Louis Bossart --- sound/soc/codecs/rt711-sdca-sdw.c | 6 ++++++ sound/soc/codecs/rt711-sdw.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/sound/soc/codecs/rt711-sdca-sdw.c b/sound/soc/codecs/rt711-sdca-sdw.c index 9e2a092d4fcb98..524c93184bd2d7 100644 --- a/sound/soc/codecs/rt711-sdca-sdw.c +++ b/sound/soc/codecs/rt711-sdca-sdw.c @@ -382,6 +382,8 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev) struct rt711_sdca_priv *rt711 = dev_get_drvdata(dev); unsigned long time; + dev_dbg(&slave->dev, "%s: start\n", __func__); + if (!rt711->hw_init) return 0; @@ -397,6 +399,8 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev) return -ETIMEDOUT; } + dev_dbg(&slave->dev, "%s: regmap_sync\n", __func__); + regmap_sync: regcache_cache_only(rt711->regmap, false); regcache_sync(rt711->regmap); @@ -405,6 +409,8 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev) pm_runtime_mark_last_busy(dev); + dev_dbg(&slave->dev, "%s: done\n", __func__); + return 0; } diff --git a/sound/soc/codecs/rt711-sdw.c b/sound/soc/codecs/rt711-sdw.c index d41c1eb55f3d74..2c3b0b50db57b9 100644 --- a/sound/soc/codecs/rt711-sdw.c +++ b/sound/soc/codecs/rt711-sdw.c @@ -502,6 +502,8 @@ static int __maybe_unused rt711_dev_resume(struct device *dev) struct rt711_priv *rt711 = dev_get_drvdata(dev); unsigned long time; + dev_dbg(&slave->dev, "%s: start\n", __func__); + if (!rt711->hw_init) return 0; @@ -517,6 +519,8 @@ static int __maybe_unused rt711_dev_resume(struct device *dev) return -ETIMEDOUT; } + dev_dbg(&slave->dev, "%s: regmap_sync\n", __func__); + regmap_sync: regcache_cache_only(rt711->regmap, false); regcache_sync_region(rt711->regmap, 0x3000, 0x8fff); @@ -524,6 +528,8 @@ static int __maybe_unused rt711_dev_resume(struct device *dev) pm_runtime_mark_last_busy(dev); + dev_dbg(&slave->dev, "%s: done\n", __func__); + return 0; } From 754a106d270a36ad838efa7cc309c06609983d5b Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Sat, 5 Dec 2020 14:13:41 -0600 Subject: [PATCH 07/14] ASoC: rt711-sdw: add traces for pm_runtime functions Check if there is any issue with system resume? Signed-off-by: Pierre-Louis Bossart --- sound/soc/codecs/rt711-sdca-sdw.c | 24 +++++++++++++++++++++++- sound/soc/codecs/rt711-sdw.c | 24 +++++++++++++++++++++++- 2 files changed, 46 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/rt711-sdca-sdw.c b/sound/soc/codecs/rt711-sdca-sdw.c index 524c93184bd2d7..c5918d40d43674 100644 --- a/sound/soc/codecs/rt711-sdca-sdw.c +++ b/sound/soc/codecs/rt711-sdca-sdw.c @@ -414,9 +414,31 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev) return 0; } +static int __maybe_unused rt711_sdca_dev_suspend_runtime(struct device *dev) +{ + int ret; + + dev_dbg(dev, "%s: start\n", __func__); + ret = rt711_sdca_dev_suspend(dev); + dev_dbg(dev, "%s: done\n", __func__); + + return ret; +} + +static int __maybe_unused rt711_sdca_dev_resume_runtime(struct device *dev) +{ + int ret; + + dev_dbg(dev, "%s: start\n", __func__); + ret = rt711_sdca_dev_resume(dev); + dev_dbg(dev, "%s: done\n", __func__); + + return ret; +} + static const struct dev_pm_ops rt711_sdca_pm = { SET_SYSTEM_SLEEP_PM_OPS(rt711_sdca_dev_suspend, rt711_sdca_dev_resume) - SET_RUNTIME_PM_OPS(rt711_sdca_dev_suspend, rt711_sdca_dev_resume, NULL) + SET_RUNTIME_PM_OPS(rt711_sdca_dev_suspend_runtime, rt711_sdca_dev_resume_runtime, NULL) }; static struct sdw_driver rt711_sdca_sdw_driver = { diff --git a/sound/soc/codecs/rt711-sdw.c b/sound/soc/codecs/rt711-sdw.c index 2c3b0b50db57b9..17e9da0c25fdb8 100644 --- a/sound/soc/codecs/rt711-sdw.c +++ b/sound/soc/codecs/rt711-sdw.c @@ -533,9 +533,31 @@ static int __maybe_unused rt711_dev_resume(struct device *dev) return 0; } +static int __maybe_unused rt711_dev_suspend_runtime(struct device *dev) +{ + int ret; + + dev_dbg(dev, "%s: start\n", __func__); + ret = rt711_dev_suspend(dev); + dev_dbg(dev, "%s: done\n", __func__); + + return ret; +} + +static int __maybe_unused rt711_dev_resume_runtime(struct device *dev) +{ + int ret; + + dev_dbg(dev, "%s: start\n", __func__); + ret = rt711_dev_resume(dev); + dev_dbg(dev, "%s: done\n", __func__); + + return ret; +} + static const struct dev_pm_ops rt711_pm = { SET_SYSTEM_SLEEP_PM_OPS(rt711_dev_suspend, rt711_dev_resume) - SET_RUNTIME_PM_OPS(rt711_dev_suspend, rt711_dev_resume, NULL) + SET_RUNTIME_PM_OPS(rt711_dev_suspend_runtime, rt711_dev_resume_runtime, NULL) }; static struct sdw_driver rt711_sdw_driver = { From 152fd46b9b0e56d25968c91bf4646683512305e0 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Sat, 5 Dec 2020 14:58:46 -0600 Subject: [PATCH 08/14] ASoC: rt711-sdw: more resume traces Signed-off-by: Pierre-Louis Bossart --- sound/soc/codecs/rt711-sdca-sdw.c | 11 +++++++++-- sound/soc/codecs/rt711-sdw.c | 11 +++++++++-- 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/sound/soc/codecs/rt711-sdca-sdw.c b/sound/soc/codecs/rt711-sdca-sdw.c index c5918d40d43674..acd6678e43c0cd 100644 --- a/sound/soc/codecs/rt711-sdca-sdw.c +++ b/sound/soc/codecs/rt711-sdca-sdw.c @@ -384,14 +384,19 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev) dev_dbg(&slave->dev, "%s: start\n", __func__); - if (!rt711->hw_init) + if (!rt711->hw_init) { + dev_dbg(&slave->dev, "%s: done - hw_init not necessary\n", + __func__); return 0; + } if (!slave->unattach_request) goto regmap_sync; slave->unattach_request = 0; + dev_dbg(&slave->dev, "%s: wait_for_completion start\n", __func__); + time = wait_for_completion_timeout(&slave->initialization_complete, msecs_to_jiffies(RT711_PROBE_TIMEOUT)); if (!time) { @@ -399,9 +404,11 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev) return -ETIMEDOUT; } - dev_dbg(&slave->dev, "%s: regmap_sync\n", __func__); + dev_dbg(&slave->dev, "%s: wait_for_completion done\n", __func__); regmap_sync: + dev_dbg(&slave->dev, "%s: regmap_sync\n", __func__); + 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 17e9da0c25fdb8..fda3b5ba471992 100644 --- a/sound/soc/codecs/rt711-sdw.c +++ b/sound/soc/codecs/rt711-sdw.c @@ -504,14 +504,19 @@ static int __maybe_unused rt711_dev_resume(struct device *dev) dev_dbg(&slave->dev, "%s: start\n", __func__); - if (!rt711->hw_init) + if (!rt711->hw_init) { + dev_dbg(&slave->dev, "%s: done - hw_init not necessary\n", + __func__); return 0; + } if (!slave->unattach_request) goto regmap_sync; slave->unattach_request = 0; + dev_dbg(&slave->dev, "%s: wait_for_completion start\n", __func__); + time = wait_for_completion_timeout(&slave->initialization_complete, msecs_to_jiffies(RT711_PROBE_TIMEOUT)); if (!time) { @@ -519,9 +524,11 @@ static int __maybe_unused rt711_dev_resume(struct device *dev) return -ETIMEDOUT; } - dev_dbg(&slave->dev, "%s: regmap_sync\n", __func__); + dev_dbg(&slave->dev, "%s: wait_for_completion done\n", __func__); regmap_sync: + dev_dbg(&slave->dev, "%s: regmap_sync\n", __func__); + regcache_cache_only(rt711->regmap, false); regcache_sync_region(rt711->regmap, 0x3000, 0x8fff); regcache_sync_region(rt711->regmap, 0x752009, 0x752091); From 1045a466d6c375f93575ed2e1e5fbfe85739b2c2 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Sat, 5 Dec 2020 15:04:23 -0600 Subject: [PATCH 09/14] soundwire: intel: add traces for resume Signed-off-by: Pierre-Louis Bossart --- drivers/soundwire/intel.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/soundwire/intel.c b/drivers/soundwire/intel.c index b664cae9be260f..1f804418529b16 100644 --- a/drivers/soundwire/intel.c +++ b/drivers/soundwire/intel.c @@ -1720,6 +1720,8 @@ static int __maybe_unused intel_resume(struct device *dev) return 0; } + dev_dbg(dev, "%s: start\n", __func__); + link_flags = md_flags >> (bus->link_id * 8); multi_link = !(link_flags & SDW_INTEL_MASTER_DISABLE_MULTI_LINK); @@ -1795,6 +1797,9 @@ static int __maybe_unused intel_resume(struct device *dev) */ pm_runtime_mark_last_busy(dev); + dev_dbg(dev, "%s: done\n", __func__); + + return ret; } @@ -1816,6 +1821,8 @@ static int intel_resume_runtime(struct device *dev) return 0; } + dev_dbg(dev, "%s: start\n", __func__); + link_flags = md_flags >> (bus->link_id * 8); multi_link = !(link_flags & SDW_INTEL_MASTER_DISABLE_MULTI_LINK); @@ -1968,6 +1975,8 @@ static int intel_resume_runtime(struct device *dev) ret = -EINVAL; } + dev_dbg(dev, "%s: done\n", __func__); + return ret; } From 8c0a939c49be92783320f9e24384233a2c8c2b77 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Mon, 7 Dec 2020 10:36:16 -0600 Subject: [PATCH 10/14] ASoC: rt711*-sdw: force pm_runtime status as active in resume sequence Fix potential race condition by preventing the pm_runtime resume from being executed while system resume is taking place. Signed-off-by: Pierre-Louis Bossart --- sound/soc/codecs/rt711-sdca-sdw.c | 52 ++++++++++++++++++++++++++++--- sound/soc/codecs/rt711-sdw.c | 52 ++++++++++++++++++++++++++++--- 2 files changed, 94 insertions(+), 10 deletions(-) diff --git a/sound/soc/codecs/rt711-sdca-sdw.c b/sound/soc/codecs/rt711-sdca-sdw.c index acd6678e43c0cd..872793f5c1c485 100644 --- a/sound/soc/codecs/rt711-sdca-sdw.c +++ b/sound/soc/codecs/rt711-sdca-sdw.c @@ -384,6 +384,16 @@ static int __maybe_unused rt711_sdca_dev_resume(struct device *dev) dev_dbg(&slave->dev, "%s: start\n", __func__); + if (pm_runtime_suspended(dev)) { + dev_dbg(dev, "%s: pm_runtime status was suspended, forcing active\n", __func__); + + /* follow required sequence from runtime_pm.rst */ + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + pm_runtime_mark_last_busy(dev); + pm_runtime_enable(dev); + } + if (!rt711->hw_init) { dev_dbg(&slave->dev, "%s: done - hw_init not necessary\n", __func__); @@ -434,13 +444,45 @@ static int __maybe_unused rt711_sdca_dev_suspend_runtime(struct device *dev) static int __maybe_unused rt711_sdca_dev_resume_runtime(struct device *dev) { - int ret; + struct sdw_slave *slave = dev_to_sdw_dev(dev); + struct rt711_sdca_priv *rt711 = dev_get_drvdata(dev); + unsigned long time; - dev_dbg(dev, "%s: start\n", __func__); - ret = rt711_sdca_dev_resume(dev); - dev_dbg(dev, "%s: done\n", __func__); + dev_dbg(&slave->dev, "%s: start\n", __func__); - return ret; + if (!rt711->hw_init) { + dev_dbg(&slave->dev, "%s: done - hw_init not necessary\n", + __func__); + return 0; + } + + if (!slave->unattach_request) + goto regmap_sync; + + dev_dbg(&slave->dev, "%s: wait_for_completion start\n", __func__); + + time = wait_for_completion_timeout(&slave->initialization_complete, + msecs_to_jiffies(RT711_PROBE_TIMEOUT)); + if (!time) { + dev_err(&slave->dev, "Initialization not complete, timed out\n"); + return -ETIMEDOUT; + } + + dev_dbg(&slave->dev, "%s: wait_for_completion done\n", __func__); + +regmap_sync: + dev_dbg(&slave->dev, "%s: regmap_sync\n", __func__); + slave->unattach_request = 0; + regcache_cache_only(rt711->regmap, false); + regcache_sync(rt711->regmap); + regcache_cache_only(rt711->mbq_regmap, false); + regcache_sync(rt711->mbq_regmap); + + pm_runtime_mark_last_busy(dev); + + dev_dbg(&slave->dev, "%s: done\n", __func__); + + return 0; } static const struct dev_pm_ops rt711_sdca_pm = { diff --git a/sound/soc/codecs/rt711-sdw.c b/sound/soc/codecs/rt711-sdw.c index fda3b5ba471992..a78dc972f2423d 100644 --- a/sound/soc/codecs/rt711-sdw.c +++ b/sound/soc/codecs/rt711-sdw.c @@ -504,6 +504,16 @@ static int __maybe_unused rt711_dev_resume(struct device *dev) dev_dbg(&slave->dev, "%s: start\n", __func__); + if (pm_runtime_suspended(dev)) { + dev_dbg(dev, "%s: pm_runtime status was suspended, forcing active\n", __func__); + + /* follow required sequence from runtime_pm.rst */ + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + pm_runtime_mark_last_busy(dev); + pm_runtime_enable(dev); + } + if (!rt711->hw_init) { dev_dbg(&slave->dev, "%s: done - hw_init not necessary\n", __func__); @@ -553,13 +563,45 @@ static int __maybe_unused rt711_dev_suspend_runtime(struct device *dev) static int __maybe_unused rt711_dev_resume_runtime(struct device *dev) { - int ret; + struct sdw_slave *slave = dev_to_sdw_dev(dev); + struct rt711_priv *rt711 = dev_get_drvdata(dev); + unsigned long time; - dev_dbg(dev, "%s: start\n", __func__); - ret = rt711_dev_resume(dev); - dev_dbg(dev, "%s: done\n", __func__); + dev_dbg(&slave->dev, "%s: start\n", __func__); - return ret; + if (!rt711->hw_init) { + dev_dbg(&slave->dev, "%s: done - hw_init not necessary\n", + __func__); + return 0; + } + + if (!slave->unattach_request) + goto regmap_sync; + + dev_dbg(&slave->dev, "%s: wait_for_completion start\n", __func__); + + time = wait_for_completion_timeout(&slave->initialization_complete, + msecs_to_jiffies(RT711_PROBE_TIMEOUT)); + if (!time) { + dev_err(&slave->dev, "Initialization not complete, timed out\n"); + return -ETIMEDOUT; + } + + dev_dbg(&slave->dev, "%s: wait_for_completion done\n", __func__); + +regmap_sync: + dev_dbg(&slave->dev, "%s: regmap_sync\n", __func__); + + slave->unattach_request = 0; + regcache_cache_only(rt711->regmap, false); + regcache_sync_region(rt711->regmap, 0x3000, 0x8fff); + regcache_sync_region(rt711->regmap, 0x752009, 0x752091); + + pm_runtime_mark_last_busy(dev); + + dev_dbg(&slave->dev, "%s: done\n", __func__); + + return 0; } static const struct dev_pm_ops rt711_pm = { From 64983984e996447b2dfbbc08ea2bf19d82c800f9 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Mon, 7 Dec 2020 12:59:50 -0600 Subject: [PATCH 11/14] soundwire: master: force pm_runtime status as active in resume sequence When the pm_runtime status is forced active in a child device, the following error is thrown: [ 6239.434332] kernel: rt711-sdca sdw:0:25d:711:1: runtime PM trying to activate child device sdw:0:25d:711:1 but parent (sdw-master-0) is not active Add the same fix to force pm_runtime status as active when doing a system resume. FIXME: is there a better way of doing this? Signed-off-by: Pierre-Louis Bossart --- drivers/soundwire/master.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/drivers/soundwire/master.c b/drivers/soundwire/master.c index 9b05c9e25ebe48..7434888f1358bb 100644 --- a/drivers/soundwire/master.c +++ b/drivers/soundwire/master.c @@ -107,7 +107,36 @@ static void sdw_master_device_release(struct device *dev) kfree(md); } +static int __maybe_unused sdw_master_device_suspend(struct device *dev) +{ + dev_dbg(dev, "%s: start\n", __func__); + + dev_dbg(dev, "%s: done\n", __func__); + + return 0; +} + +static int __maybe_unused sdw_master_device_resume(struct device *dev) +{ + dev_dbg(dev, "%s: start\n", __func__); + + if (pm_runtime_suspended(dev)) { + dev_dbg(dev, "%s: pm_runtime status was suspended, forcing active\n", __func__); + + /* follow required sequence from runtime_pm.rst */ + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + pm_runtime_mark_last_busy(dev); + pm_runtime_enable(dev); + } + + dev_dbg(dev, "%s: done\n", __func__); + + return 0; +} + static const struct dev_pm_ops master_dev_pm = { + SET_SYSTEM_SLEEP_PM_OPS(sdw_master_device_suspend, sdw_master_device_resume) SET_RUNTIME_PM_OPS(pm_generic_runtime_suspend, pm_generic_runtime_resume, NULL) }; From 125081f8b2203714e75021fd923f8ab2f01ca6a4 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Mon, 7 Dec 2020 18:17:21 -0600 Subject: [PATCH 12/14] ASoC: max98373-sdw: mirror changes in rt711 add traces and force pm_runtime status to be active on system resume. Signed-off-by: Pierre-Louis Bossart --- sound/soc/codecs/max98373-sdw.c | 43 +++++++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/sound/soc/codecs/max98373-sdw.c b/sound/soc/codecs/max98373-sdw.c index 4c92f59ad3ec79..0b4d1f694d8c85 100644 --- a/sound/soc/codecs/max98373-sdw.c +++ b/sound/soc/codecs/max98373-sdw.c @@ -259,14 +259,22 @@ static __maybe_unused int max98373_resume(struct device *dev) struct max98373_priv *max98373 = dev_get_drvdata(dev); unsigned long time; - if (!max98373->hw_init) + dev_dbg(dev, "%s: start\n", __func__); + + if (!max98373->hw_init) { + dev_dbg(dev, "%s: done - hw_init not necessary\n", + __func__); return 0; + } if (!slave->unattach_request) goto regmap_sync; + slave->unattach_request = 0; + dev_dbg(dev, "%s: wait_for_completion start\n", __func__); + time = wait_for_completion_timeout(&slave->initialization_complete, msecs_to_jiffies(MAX98373_PROBE_TIMEOUT)); if (!time) { @@ -274,15 +282,46 @@ static __maybe_unused int max98373_resume(struct device *dev) return -ETIMEDOUT; } + dev_dbg(dev, "%s: wait_for_completion start\n", __func__); + regmap_sync: + dev_dbg(dev, "%s: regmap_sync\n", __func__); + regcache_cache_only(max98373->regmap, false); regcache_sync(max98373->regmap); + pm_runtime_mark_last_busy(dev); + + dev_dbg(dev, "%s: done\n", __func__); + return 0; } +static __maybe_unused int max98373_system_resume(struct device *dev) +{ + int ret; + + dev_dbg(dev, "%s: start\n", __func__); + + if (pm_runtime_suspended(dev)) { + dev_dbg(dev, "%s: pm_runtime status was suspended, forcing active\n", __func__); + + /* follow required sequence from runtime_pm.rst */ + pm_runtime_disable(dev); + pm_runtime_set_active(dev); + pm_runtime_mark_last_busy(dev); + pm_runtime_enable(dev); + } + + ret = max98373_resume(dev); + + dev_dbg(dev, "%s: done\n", __func__); + + return ret; +} + static const struct dev_pm_ops max98373_pm = { - SET_SYSTEM_SLEEP_PM_OPS(max98373_suspend, max98373_resume) + SET_SYSTEM_SLEEP_PM_OPS(max98373_suspend, max98373_system_resume) SET_RUNTIME_PM_OPS(max98373_suspend, max98373_resume, NULL) }; From 1522f09afae9d31ed6f56e5fdb140a50b782ce49 Mon Sep 17 00:00:00 2001 From: Pierre-Louis Bossart Date: Tue, 8 Dec 2020 12:24:00 -0600 Subject: [PATCH 13/14] soundwire/ASoC: add more traces to figure out parity errors Signed-off-by: Pierre-Louis Bossart --- drivers/soundwire/bus.c | 24 +++++++++++++++++++++++- sound/soc/codecs/max98373-sdw.c | 1 + 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/soundwire/bus.c b/drivers/soundwire/bus.c index 03bc6e0a6fb055..48627b53155598 100644 --- a/drivers/soundwire/bus.c +++ b/drivers/soundwire/bus.c @@ -1463,6 +1463,8 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) bool parity_check; bool parity_quirk; + dev_dbg(&slave->dev, "%s: start\n", __func__); + sdw_modify_slave_status(slave, SDW_SLAVE_ALERT); ret = pm_runtime_get_sync(&slave->dev); @@ -1499,6 +1501,8 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) } do { + dev_dbg(&slave->dev, "Interrupt loop count: %d\n", count); + slave_notify = false; /* @@ -1510,12 +1514,20 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) parity_quirk = !slave->first_interrupt_done && (slave->prop.quirks & SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY); + dev_dbg(&slave->dev, + "Parity: SDW_SCP_INT1 0x%02x INT1_MASK 0x%02x first_interrupt_done %d\n", + buf, slave->prop.scp_int1_mask, slave->first_interrupt_done); + if (parity_check && !parity_quirk) dev_err(&slave->dev, "Parity error detected\n"); clear |= SDW_SCP_INT1_PARITY; } if (buf & SDW_SCP_INT1_BUS_CLASH) { + dev_dbg(&slave->dev, + "Bus Clash: SDW_SCP_INT1 0x%02x INT1_MASK 0x%02x first_interrupt_done %d\n", + buf, slave->prop.scp_int1_mask, slave->first_interrupt_done); + if (slave->prop.scp_int1_mask & SDW_SCP_INT1_BUS_CLASH) dev_err(&slave->dev, "Bus clash detected\n"); clear |= SDW_SCP_INT1_BUS_CLASH; @@ -1529,6 +1541,10 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) */ if (buf & SDW_SCP_INT1_IMPL_DEF) { + dev_dbg(&slave->dev, + "Imp-def interrupt: SDW_SCP_INT1 0x%02x INT1_MASK 0x%02x first_interrupt_done %d\n", + buf, slave->prop.scp_int1_mask, slave->first_interrupt_done); + if (slave->prop.scp_int1_mask & SDW_SCP_INT1_IMPL_DEF) { dev_dbg(&slave->dev, "Slave impl defined interrupt\n"); slave_notify = true; @@ -1594,7 +1610,10 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) } /* at this point all initial interrupt sources were handled */ - slave->first_interrupt_done = true; + if (!slave->first_interrupt_done) { + slave->first_interrupt_done = true; + dev_dbg(&slave->dev, "first_interrupt_done set to true\n"); + } /* * Read status again to ensure no new interrupts arrived @@ -1650,6 +1669,8 @@ static int sdw_handle_slave_alerts(struct sdw_slave *slave) pm_runtime_mark_last_busy(&slave->dev); pm_runtime_put_autosuspend(&slave->dev); + dev_dbg(&slave->dev, "%s: done\n", __func__); + return ret; } @@ -1830,6 +1851,7 @@ void sdw_clear_slave_status(struct sdw_bus *bus, u32 request) if (slave->status != SDW_SLAVE_UNATTACHED) { sdw_modify_slave_status(slave, SDW_SLAVE_UNATTACHED); slave->first_interrupt_done = false; + dev_dbg(&slave->dev, "first_interrupt_done set to false\n"); } /* keep track of request, used in pm_runtime resume */ diff --git a/sound/soc/codecs/max98373-sdw.c b/sound/soc/codecs/max98373-sdw.c index 0b4d1f694d8c85..990c4e657bf6d2 100644 --- a/sound/soc/codecs/max98373-sdw.c +++ b/sound/soc/codecs/max98373-sdw.c @@ -334,6 +334,7 @@ static int max98373_read_prop(struct sdw_slave *slave) struct sdw_dpn_prop *dpn; prop->scp_int1_mask = SDW_SCP_INT1_BUS_CLASH | SDW_SCP_INT1_PARITY; + prop->quirks = SDW_SLAVE_QUIRKS_INVALID_INITIAL_PARITY; /* BITMAP: 00001000 Dataport 3 is active */ prop->source_ports = BIT(3); From 76f0080b5147e74b6504053757804321f956a0b7 Mon Sep 17 00:00:00 2001 From: Shuming Fan Date: Tue, 8 Dec 2020 21:44:42 -0600 Subject: [PATCH 14/14] 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; }