Skip to content

Commit 56bd72e

Browse files
MaslankaMarekdlezcano
authored andcommitted
clocksource: acpi_pm: Add external callback for suspend/resume
Provides the capability to register an external callback for the ACPI PM timer, which is called during the suspend and resume processes. Signed-off-by: Marek Maslanka <[email protected]> Reviewed-by: Hans de Goede <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Daniel Lezcano <[email protected]>
1 parent a7456d7 commit 56bd72e

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

drivers/clocksource/acpi_pm.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
#include <asm/io.h>
2626
#include <asm/time.h>
2727

28+
static void *suspend_resume_cb_data;
29+
30+
static void (*suspend_resume_callback)(void *data, bool suspend);
31+
2832
/*
2933
* The I/O port the PMTMR resides at.
3034
* The location is detected during setup_arch(),
@@ -58,6 +62,32 @@ u32 acpi_pm_read_verified(void)
5862
return v2;
5963
}
6064

65+
void acpi_pmtmr_register_suspend_resume_callback(void (*cb)(void *data, bool suspend), void *data)
66+
{
67+
suspend_resume_callback = cb;
68+
suspend_resume_cb_data = data;
69+
}
70+
EXPORT_SYMBOL_GPL(acpi_pmtmr_register_suspend_resume_callback);
71+
72+
void acpi_pmtmr_unregister_suspend_resume_callback(void)
73+
{
74+
suspend_resume_callback = NULL;
75+
suspend_resume_cb_data = NULL;
76+
}
77+
EXPORT_SYMBOL_GPL(acpi_pmtmr_unregister_suspend_resume_callback);
78+
79+
static void acpi_pm_suspend(struct clocksource *cs)
80+
{
81+
if (suspend_resume_callback)
82+
suspend_resume_callback(suspend_resume_cb_data, true);
83+
}
84+
85+
static void acpi_pm_resume(struct clocksource *cs)
86+
{
87+
if (suspend_resume_callback)
88+
suspend_resume_callback(suspend_resume_cb_data, false);
89+
}
90+
6191
static u64 acpi_pm_read(struct clocksource *cs)
6292
{
6393
return (u64)read_pmtmr();
@@ -69,6 +99,8 @@ static struct clocksource clocksource_acpi_pm = {
6999
.read = acpi_pm_read,
70100
.mask = (u64)ACPI_PM_MASK,
71101
.flags = CLOCK_SOURCE_IS_CONTINUOUS,
102+
.suspend = acpi_pm_suspend,
103+
.resume = acpi_pm_resume,
72104
};
73105

74106

include/linux/acpi_pmtmr.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@ static inline u32 acpi_pm_read_early(void)
2626
return acpi_pm_read_verified() & ACPI_PM_MASK;
2727
}
2828

29+
/**
30+
* Register callback for suspend and resume event
31+
*
32+
* @cb Callback triggered on suspend and resume
33+
* @data Data passed with the callback
34+
*/
35+
void acpi_pmtmr_register_suspend_resume_callback(void (*cb)(void *data, bool suspend), void *data);
36+
37+
/**
38+
* Remove registered callback for suspend and resume event
39+
*/
40+
void acpi_pmtmr_unregister_suspend_resume_callback(void);
41+
2942
#else
3043

3144
static inline u32 acpi_pm_read_early(void)

0 commit comments

Comments
 (0)