ASoC: SDCA: Add NO_DIRECT_COMPLETE flag to class driver
Subsystems (3)
Charles Keepax
maintainerPATCH 1/1 ASoC: SDCA: Add NO_DIRECT_COMPLETE flag to class driver
The SDCA class driver currently expects the device will be fully powered down on system suspend but not on runtime suspend. This is typically required as when audio is not active (ie. runtime suspend) jack detect is expected to still function, but when the whole system is hibernated there is no need to recognise audio jack events. This means the class driver needs to always be informed of a system suspend, so the direct complete optimisation (where PM will skip calling system suspend if the device is runtime suspended) is not appropriate for the SDCA class driver.
Add the NO_DIRECT_COMPLETE flag to prevent this optimisation from running against this driver.
--- sound/soc/sdca/sdca_class_function.c | 2 ++ 1 file changed, 2 insertions(+)
sound/soc/sdca/sdca_class_function.c +2 -0
@@ -377,6 +377,8 @@ static int class_function_probe(struct auxiliary_device *auxdev,if (ret)return ret; +dev_pm_set_driver_flags (dev,DPM_FLAG_NO_DIRECT_COMPLETE ); +pm_runtime_set_autosuspend_delay (dev,200 );pm_runtime_use_autosuspend (dev);pm_runtime_set_active (dev);
Signature · 1 line
2.47.3
Pierre-Louis Bossart
reviewerQuoted 10 lines · Charles Keepax
The SDCA class driver currently expects the device will be fully powered down on system suspend but not on runtime suspend. This is typically required as when audio is not active (ie. runtime suspend) jack detect is expected to still function, but when the whole system is hibernated there is no need to recognise audio jack events. This means the class driver needs to always be informed of a system suspend, so the direct complete optimisation (where PM will skip calling system suspend if the device is runtime suspended) is not appropriate for the SDCA class driver.
Quoted 2 lines
Add the
NO_DIRECT_COMPLETEflag to prevent this optimisation from running against this driver.
Humm, this flag makes sure the class driver .suspend method is called, but does the core also force a pm_runtime resume before?
In other words, what is the state of the device when the system suspend routine is invoked by the PM core when this flag is set?
FWIW, we had a similar problem on the Intel side, and we used the .prepare method to force a pm_runtime resume. If the host was pm_runtime suspended, then we'd bring it back to full power before the system suspend. It may seem overkill but it's required at the hardware level, a system suspend with the clock already stopped isn't supported. If the PM core guaranteed the device state was resumed by adding this flag, then the Intel folks could remove quite a few lines of code.
Going back to this SDCA driver, if the PM core does NOT change the pm_runtime state, then should the class driver perform a full pm_runtime resume and then do the expected system suspend sequence?
Sorry if I am splitting hair, in the past we played with these PM flags and always understood them in the wrong way...
Quoted 18 lines
Signed-off-by Charles Keepax <[email protected]>--- sound/soc/sdca/sdca_class_function.c | 2 ++ 1 file changed, 2 insertions(+)sound/soc/sdca/sdca_class_function.c +2
-0@@ -377,6 +377,8 @@ static int class_function_probe(struct auxiliary_device *auxdev,if (ret)return ret; +dev_pm_set_driver_flags (dev,DPM_FLAG_NO_DIRECT_COMPLETE ); +pm_runtime_set_autosuspend_delay (dev,200 );pm_runtime_use_autosuspend (dev);pm_runtime_set_active (dev);
Charles Keepax
maintainerQuoted 11 lines · Pierre-Louis Bossart
Quoted 10 lines · Charles Keepax
The SDCA class driver currently expects the device will be fully powered down on system suspend but not on runtime suspend. This is typically required as when audio is not active (ie. runtime suspend) jack detect is expected to still function, but when the whole system is hibernated there is no need to recognise audio jack events. This means the class driver needs to always be informed of a system suspend, so the direct complete optimisation (where PM will skip calling system suspend if the device is runtime suspended) is not appropriate for the SDCA class driver.
Quoted 5 lines
Quoted 2 lines
Add the
NO_DIRECT_COMPLETEflag to prevent this optimisation from running against this driver.Humm, this flag makes sure the class driver .suspend method is called, but does the core also force a
pm_runtimeresume before?
Yeah this ensures the suspend method is always called.
Quoted 3 lines
In other words, what is the state of the device when the system suspend routine is invoked by the PM core when this flag is set?
Can be either runtime resumed or suspended.
Quoted 4 lines
Going back to this SDCA driver, if the PM core does NOT change the
pm_runtimestate, then should the class driver perform a fullpm_runtimeresume and then do the expected system suspend sequence?
Yeah we do perform a resume in the system suspend although to be honest its mostly just to force the pm_runtime_force_resume() in the system resume handler to always do a runtime resume.
Quoted 2 lines
Sorry if I am splitting hair, in the past we played with these PM flags and always understood them in the wrong way...
There is definitely a lot of subtlety in this part of the kernel, hence why I CCed the PM people on this patch :-) Its a bit of an odd optimisation this direct complete thing, as far as I can see lots of drives don't run it without really deliberately avoiding it. For SoundWire itself the soundwire host resumes all children before a suspend, which dodges the direct complete. I would imagine a lot of other peripheral buses do similar. For MFD children they are almost always on the same fwnode as their parent so they don't hit it either. Turns out this class driver is the first thing I have worked on that actually hits the direct complete optimimisation as far as I can see.
Thanks,
Charles
Pierre-Louis Bossart
reviewerQuoted 17 lines
Quoted 11 lines
Quoted 11 lines
The SDCA class driver currently expects the device will be fully powered down on system suspend but not on runtime suspend. This is typically required as when audio is not active (ie. runtime suspend) jack detect is expected to still function, but when the whole system is hibernated there is no need to recognise audio jack events. This means the class driver needs to always be informed of a system suspend, so the direct complete optimisation (where PM will skip calling system suspend if the device is runtime suspended) is not appropriate for the SDCA class driver.
Quoted 5 lines
Quoted 2 lines
Add the
NO_DIRECT_COMPLETEflag to prevent this optimisation from running against this driver.Humm, this flag makes sure the class driver .suspend method is called, but does the core also force a
pm_runtimeresume before?
Quoted 7 lines
Yeah this ensures the suspend method is always called.
Quoted 3 lines
In other words, what is the state of the device when the system suspend routine is invoked by the PM core when this flag is set?
Can be either runtime resumed or suspended.
ok, so if the child driver wants to resume to full power it has to be done 'manually', the PM core does not help.
Quoted 8 lines
Quoted 4 lines
Going back to this SDCA driver, if the PM core does NOT change the
pm_runtimestate, then should the class driver perform a fullpm_runtimeresume and then do the expected system suspend sequence?Yeah we do perform a resume in the system suspend although to be honest its mostly just to force the
pm_runtime_force_resume()in the system resume handler to always do a runtime resume.
I think we are talking about different actions...
a) pm_runtime resume BEFORE system suspend. That would be necessary to deal with e.g. clock stop modes that are valid in pm_runtime suspend but not system suspend. It's not clear to me for example if all SDCA chips will support direct transitions from PS3 to PS4, or be ok with power rails cut while in PS3.
b) pm_runtime resume DURING system resume. That may be useful to restore functionality, but it's too late to handle problems that occur during the system suspend phase.
Either way, that's a bit orthogonal to this patch, more a discussion on how to deal with class power management.
Quoted 14 lines
Quoted 2 lines
Sorry if I am splitting hair, in the past we played with these PM flags and always understood them in the wrong way...
There is definitely a lot of subtlety in this part of the kernel, hence why I CCed the PM people on this patch :-) Its a bit of an odd optimisation this direct complete thing, as far as I can see lots of drives don't run it without really deliberately avoiding it. For SoundWire itself the soundwire host resumes all children before a suspend, which dodges the direct complete. I would imagine a lot of other peripheral buses do similar. For MFD children they are almost always on the same fwnode as their parent so they don't hit it either. Turns out this class driver is the first thing I have worked on that actually hits the direct complete optimimisation as far as I can see.
You lost me with this sentence:
"
For SoundWire itself the soundwire host resumes all children before a suspend, which dodges the direct complete. "
If the direct-complete optimization is not used, then do you actually see a different behavior with this NO_DIRECT_COMPLETE flag set?
Charles Keepax
maintainerQuoted 9 lines · Pierre-Louis Bossart
Quoted 8 lines
Quoted 4 lines
Going back to this SDCA driver, if the PM core does NOT change the
pm_runtimestate, then should the class driver perform a fullpm_runtimeresume and then do the expected system suspend sequence?Yeah we do perform a resume in the system suspend although to be honest its mostly just to force the
pm_runtime_force_resume()in the system resume handler to always do a runtime resume.
Quoted 7 lines
I think we are talking about different actions...
a)
pm_runtimeresume BEFORE system suspend. That would be necessary to deal with e.g. clock stop modes that are valid inpm_runtimesuspend but not system suspend. It's not clear to me for example if all SDCA chips will support direct transitions from PS3 to PS4, or be ok with power rails cut while in PS3.
I mean I think this is currently handled at the soundwire level, since the soundwire bus runtime resumes all children for system suspend.
Quoted 10 lines
You lost me with this sentence:
"
For SoundWire itself the soundwire host resumes all children before a suspend, which dodges the direct complete. "If the direct-complete optimization is not used, then do you actually see a different behavior with this
NO_DIRECT_COMPLETEflag set?
The flag is applied to the auxiliary device children of the soundwire device. The direct complete doesn't affect the soundwire device, but it it does affect the function devices children.
Thanks,
Charles
Quoted 8 lines
Quoted 8 lines
You lost me with this sentence:
"
For SoundWire itself the soundwire host resumes all children before a suspend, which dodges the direct complete. "
Quoted 8 lines
Quoted 3 lines
If the direct-complete optimization is not used, then do you actually see a different behavior with this
NO_DIRECT_COMPLETEflag set?The flag is applied to the auxiliary device children of the soundwire device. The direct complete doesn't affect the soundwire device, but it it does affect the function devices children.
Ah ok, yes the host only resumes devices one level down, so the function level isn't affected by the .prepare logic.
I guess I was confused by the 'class driver' title but the change is not in sdca_class.c but in sdca_class_function.c...
The change looks good, so here's my
Mark Brown
maintainerQuoted 11 lines · Charles Keepax
The SDCA class driver currently expects the device will be fully powered down on system suspend but not on runtime suspend. This is typically required as when audio is not active (ie. runtime suspend) jack detect is expected to still function, but when the whole system is hibernated there is no need to recognise audio jack events. This means the class driver needs to always be informed of a system suspend, so the direct complete optimisation (where PM will skip calling system suspend if the device is runtime suspended) is not appropriate for the SDCA class driver.
[...]
Applied to
https://git.kernel.org/pub/scm/linux/kernel/git/broonie/sound.git for-next
Thanks!
[1/1] ASoC: SDCA: Add NO_DIRECT_COMPLETE flag to class driver
commit: 702ce71d32f2c30b4f45b7c6b701d87583c58df8
All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted.
You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed.
If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced.
Please add any relevant lists and maintainers to the CCs when replying to this mail.
Thanks,
Mark