Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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 <mmaslanka@google.com>
Reviewed-by: Hans de Goede <hdegoede@redhat.com>
Link: https://lore.kernel.org/r/20240812184150.1079924-1-mmaslanka@google.com
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>

authored by

Marek Maslanka and committed by
Daniel Lezcano
56bd72e9 a7456d7d

+45
+32
drivers/clocksource/acpi_pm.c
··· 25 25 #include <asm/io.h> 26 26 #include <asm/time.h> 27 27 28 + static void *suspend_resume_cb_data; 29 + 30 + static void (*suspend_resume_callback)(void *data, bool suspend); 31 + 28 32 /* 29 33 * The I/O port the PMTMR resides at. 30 34 * The location is detected during setup_arch(), ··· 62 58 return v2; 63 59 } 64 60 61 + void acpi_pmtmr_register_suspend_resume_callback(void (*cb)(void *data, bool suspend), void *data) 62 + { 63 + suspend_resume_callback = cb; 64 + suspend_resume_cb_data = data; 65 + } 66 + EXPORT_SYMBOL_GPL(acpi_pmtmr_register_suspend_resume_callback); 67 + 68 + void acpi_pmtmr_unregister_suspend_resume_callback(void) 69 + { 70 + suspend_resume_callback = NULL; 71 + suspend_resume_cb_data = NULL; 72 + } 73 + EXPORT_SYMBOL_GPL(acpi_pmtmr_unregister_suspend_resume_callback); 74 + 75 + static void acpi_pm_suspend(struct clocksource *cs) 76 + { 77 + if (suspend_resume_callback) 78 + suspend_resume_callback(suspend_resume_cb_data, true); 79 + } 80 + 81 + static void acpi_pm_resume(struct clocksource *cs) 82 + { 83 + if (suspend_resume_callback) 84 + suspend_resume_callback(suspend_resume_cb_data, false); 85 + } 86 + 65 87 static u64 acpi_pm_read(struct clocksource *cs) 66 88 { 67 89 return (u64)read_pmtmr(); ··· 99 69 .read = acpi_pm_read, 100 70 .mask = (u64)ACPI_PM_MASK, 101 71 .flags = CLOCK_SOURCE_IS_CONTINUOUS, 72 + .suspend = acpi_pm_suspend, 73 + .resume = acpi_pm_resume, 102 74 }; 103 75 104 76
+13
include/linux/acpi_pmtmr.h
··· 26 26 return acpi_pm_read_verified() & ACPI_PM_MASK; 27 27 } 28 28 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 + 29 42 #else 30 43 31 44 static inline u32 acpi_pm_read_early(void)