PM: domains: Power off[on] domain in hibernate .freeze[thaw]_noirq hook
authorShawn Guo <shawn.guo@linaro.org>
Wed, 2 Nov 2022 14:21:04 +0000 (22:21 +0800)
committerRafael J. Wysocki <rafael.j.wysocki@intel.com>
Thu, 3 Nov 2022 18:40:58 +0000 (19:40 +0100)
commitebb486bed2c36c3c4053ee9d55ef66d11030694a
treed4d1ee38a245451e6b21aa75222f323fb44ef318
parentd9cc34fe0aae7e9df236be046a853fc63e889026
PM: domains: Power off[on] domain in hibernate .freeze[thaw]_noirq hook

On platforms which use SHUTDOWN as hibernation mode, the genpd noirq
hooks will be called like below.

    genpd_freeze_noirq()         genpd_restore_noirq()
          ↓                            ↑
    Create snapshot image        Restore target kernel
          ↓                            ↑
    genpd_thaw_noirq()           genpd_freeze_noirq()
          ↓                            ↑
    Write snapshot image         Read snapshot image
          ↓                            ↑
    power_down()                 Kernel boot

As of today suspend hooks genpd_suspend[resume]_noirq() manages domain
on/off state, but hibernate hooks genpd_freeze[thaw]_noirq() doesn't.
This results in a different behavior of domain power state between suspend
and hibernate freeze, i.e. domain is powered off for the former while on
for the later.  It causes a problem on platforms like i.MX where the
domain needs to be powered on/off by calling clock and regulator interface.
When the platform restores from hibernation, the domain is off in hardware
and genpd_restore_noirq() tries to power it on, but will never succeed
because software state of domain (clock and regulator) is left on from the
last hibernate freeze, so kernel thinks that clock and regulator are
enabled while they are actually not turned on in hardware.  The
consequence would be that devices in the power domain will access
registers without clock or power, and cause hardware lockup.

Power off[on] domain in hibernate .freeze[thaw]_noirq hook for reasons:

- Align the behavior between suspend and hibernate freeze.
- Have power state of domains stay in sync between hardware and software
  for hibernate freeze, and thus fix the lockup issue seen on i.MX
  platform.

Signed-off-by: Shawn Guo <shawn.guo@linaro.org>
Reviewed-by: Ulf Hansson <ulf.hansson@linaro.org>
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
drivers/base/power/domain.c