Some drivers have different flows for hibernation and suspend. If
the driver opportunistically will skip thaw() then it needs a hint
to know what is happening after the hibernate.

Introduce a new symbol pm_hibernation_mode_is_suspend() that drivers
can call to determine if suspending the system for this purpose.

Tested-by: Ionut Nechita <[email protected]>
Signed-off-by: Mario Limonciello (AMD) <[email protected]>
---
 include/linux/suspend.h  | 2 ++
 kernel/power/hibernate.c | 9 +++++++++
 2 files changed, 11 insertions(+)

diff --git a/include/linux/suspend.h b/include/linux/suspend.h
index 317ae31e89b3..4b11efd68729 100644
--- a/include/linux/suspend.h
+++ b/include/linux/suspend.h
@@ -479,6 +479,7 @@ extern void unlock_system_sleep(unsigned int);
 
 extern bool pm_sleep_transition_in_progress(void);
 bool pm_hibernate_is_recovering(void);
+bool pm_hibernation_mode_is_suspend(void);
 
 #else /* !CONFIG_PM_SLEEP */
 
@@ -513,6 +514,7 @@ static inline void unlock_system_sleep(unsigned int flags) 
{}
 
 static inline bool pm_sleep_transition_in_progress(void) { return false; }
 static inline bool pm_hibernate_is_recovering(void) { return false; }
+static inline bool pm_hibernation_mode_is_suspend(void) { return false; }
 
 #endif /* !CONFIG_PM_SLEEP */
 
diff --git a/kernel/power/hibernate.c b/kernel/power/hibernate.c
index 1defe8081e64..a991a1362d77 100644
--- a/kernel/power/hibernate.c
+++ b/kernel/power/hibernate.c
@@ -80,6 +80,15 @@ static const struct platform_hibernation_ops 
*hibernation_ops;
 
 static atomic_t hibernate_atomic = ATOMIC_INIT(1);
 
+/**
+ * pm_hibernation_mode_is_suspend - Check if hibernation has been set to 
suspend
+ */
+bool pm_hibernation_mode_is_suspend(void)
+{
+       return hibernation_mode == HIBERNATION_SUSPEND;
+}
+EXPORT_SYMBOL_GPL(pm_hibernation_mode_is_suspend);
+
 bool hibernate_acquire(void)
 {
        return atomic_add_unless(&hibernate_atomic, -1, 0);
-- 
2.51.0

Reply via email to