diff mbox series

[v4,1/2] clocksource: acpi_pm: Add external callback for suspend/resume

Message ID 20240809131343.1173369-1-mmaslanka@google.com (mailing list archive)
State Superseded, archived
Headers show
Series [v4,1/2] clocksource: acpi_pm: Add external callback for suspend/resume | expand

Commit Message

Marek Maślanka Aug. 9, 2024, 1:13 p.m. UTC
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>

---
Changes in v4:
- No changes as this was introduced as a separated patch after the v3
  review.
- Link to v3: https://lore.kernel.org/lkml/20240730120546.1042515-1-mmaslanka@google.com/
---
---
 drivers/clocksource/acpi_pm.c | 27 +++++++++++++++++++++++++++
 drivers/clocksource/acpi_pm.h | 16 ++++++++++++++++
 2 files changed, 43 insertions(+)
 create mode 100644 drivers/clocksource/acpi_pm.h

Comments

Thomas Gleixner Aug. 9, 2024, 7:15 p.m. UTC | #1
On Fri, Aug 09 2024 at 13:13, Marek Maslanka wrote:
> --- a/drivers/clocksource/acpi_pm.c
> +++ b/drivers/clocksource/acpi_pm.c
> @@ -25,6 +25,12 @@
>  #include <asm/io.h>
>  #include <asm/time.h>
>  
> +#include "acpi_pm.h"

include/linux/acpi_pmtmr.h please

> +static void *suspend_resume_cb_data;
> +
> +static void (*suspend_resume_callback)(void *data, bool suspend);
> +
>  /*
>   * The I/O port the PMTMR resides at.
>   * The location is detected during setup_arch(),
> @@ -58,6 +64,25 @@ u32 acpi_pm_read_verified(void)
>  	return v2;
>  }
>  
> +void acpi_pm_register_suspend_resume_callback(void (*cb)(void *data, bool suspend),
> +					      void *data)

No line break required. Also the name wants to be acpi_pmtmr_... for the
global visible function so that it can't be confused with the power
management related acpi_pm_* functions

Thanks,

        tglx
diff mbox series

Patch

diff --git a/drivers/clocksource/acpi_pm.c b/drivers/clocksource/acpi_pm.c
index 82338773602ca..c629f5462bc0f 100644
--- a/drivers/clocksource/acpi_pm.c
+++ b/drivers/clocksource/acpi_pm.c
@@ -25,6 +25,12 @@ 
 #include <asm/io.h>
 #include <asm/time.h>
 
+#include "acpi_pm.h"
+
+static void *suspend_resume_cb_data;
+
+static void (*suspend_resume_callback)(void *data, bool suspend);
+
 /*
  * The I/O port the PMTMR resides at.
  * The location is detected during setup_arch(),
@@ -58,6 +64,25 @@  u32 acpi_pm_read_verified(void)
 	return v2;
 }
 
+void acpi_pm_register_suspend_resume_callback(void (*cb)(void *data, bool suspend),
+					      void *data)
+{
+	suspend_resume_callback = cb;
+	suspend_resume_cb_data = data;
+}
+
+static void acpi_pm_suspend(struct clocksource *cs)
+{
+	if (suspend_resume_callback)
+		suspend_resume_callback(suspend_resume_cb_data, true);
+}
+
+static void acpi_pm_resume(struct clocksource *cs)
+{
+	if (suspend_resume_callback)
+		suspend_resume_callback(suspend_resume_cb_data, false);
+}
+
 static u64 acpi_pm_read(struct clocksource *cs)
 {
 	return (u64)read_pmtmr();
@@ -69,6 +94,8 @@  static struct clocksource clocksource_acpi_pm = {
 	.read		= acpi_pm_read,
 	.mask		= (u64)ACPI_PM_MASK,
 	.flags		= CLOCK_SOURCE_IS_CONTINUOUS,
+	.suspend	= acpi_pm_suspend,
+	.resume		= acpi_pm_resume,
 };
 
 
diff --git a/drivers/clocksource/acpi_pm.h b/drivers/clocksource/acpi_pm.h
new file mode 100644
index 0000000000000..c932899f04282
--- /dev/null
+++ b/drivers/clocksource/acpi_pm.h
@@ -0,0 +1,16 @@ 
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef __ACPI_PM_H__
+#define __ACPI_PM_H__
+
+#include <linux/types.h>
+
+/**
+ * Register callback for suspend and resume event
+ *
+ * @cb Callback triggered on suspend and resume
+ * @data Data passed with the callback
+ */
+void acpi_pm_register_suspend_resume_callback(void (*cb)(void *data, bool suspend),
+					      void *data);
+
+#endif