From 297b60346df8beafee954a0fd7c2d64f33f3b9bc Mon Sep 17 00:00:00 2001
From: hc <hc@nodka.com>
Date: Sat, 11 May 2024 01:44:05 +0000
Subject: [PATCH] rtl8211F_led_control

---
 kernel/kernel/power/wakeup_reason.c |   75 +++++++++++++++++--------------------
 1 files changed, 34 insertions(+), 41 deletions(-)

diff --git a/kernel/kernel/power/wakeup_reason.c b/kernel/kernel/power/wakeup_reason.c
index 0a5f97a..8fefaa3 100644
--- a/kernel/kernel/power/wakeup_reason.c
+++ b/kernel/kernel/power/wakeup_reason.c
@@ -27,9 +27,6 @@
 #include <linux/notifier.h>
 #include <linux/suspend.h>
 #include <linux/slab.h>
-#if defined(CONFIG_ROCKCHIP_SIP)
-#include <linux/rockchip/rockchip_sip.h>
-#endif
 
 /*
  * struct wakeup_irq_node - stores data and relationships for IRQs logged as
@@ -44,6 +41,13 @@
 	const char *irq_name;
 };
 
+enum wakeup_reason_flag {
+	RESUME_NONE = 0,
+	RESUME_IRQ,
+	RESUME_ABORT,
+	RESUME_ABNORMAL,
+};
+
 static DEFINE_SPINLOCK(wakeup_reason_lock);
 
 static LIST_HEAD(leaf_irqs);   /* kept in ascending IRQ sorted order */
@@ -56,8 +60,7 @@
 static struct kobject *kobj;
 
 static bool capture_reasons;
-static bool suspend_abort;
-static bool abnormal_wake;
+static int wakeup_reason;
 static char non_irq_wake_reason[MAX_SUSPEND_ABORT_LEN];
 
 static ktime_t last_monotime; /* monotonic time before last suspend */
@@ -150,6 +153,10 @@
 	unsigned long flags;
 
 	spin_lock_irqsave(&wakeup_reason_lock, flags);
+	if (wakeup_reason == RESUME_ABNORMAL || wakeup_reason == RESUME_ABORT) {
+		spin_unlock_irqrestore(&wakeup_reason_lock, flags);
+		return;
+	}
 
 	if (!capture_reasons) {
 		spin_unlock_irqrestore(&wakeup_reason_lock, flags);
@@ -159,6 +166,7 @@
 	if (find_node_in_list(&parent_irqs, irq) == NULL)
 		add_sibling_node_sorted(&leaf_irqs, irq);
 
+	wakeup_reason = RESUME_IRQ;
 	spin_unlock_irqrestore(&wakeup_reason_lock, flags);
 }
 
@@ -179,6 +187,11 @@
 
 	spin_lock_irqsave(&wakeup_reason_lock, flags);
 
+	if (wakeup_reason == RESUME_ABNORMAL || wakeup_reason == RESUME_ABORT) {
+		spin_unlock_irqrestore(&wakeup_reason_lock, flags);
+		return;
+	}
+
 	if (!capture_reasons || (find_node_in_list(&leaf_irqs, irq) != NULL)) {
 		spin_unlock_irqrestore(&wakeup_reason_lock, flags);
 		return;
@@ -198,6 +211,7 @@
 
 	spin_unlock_irqrestore(&wakeup_reason_lock, flags);
 }
+EXPORT_SYMBOL_GPL(log_threaded_irq_wakeup_reason);
 
 static void __log_abort_or_abnormal_wake(bool abort, const char *fmt,
 					 va_list args)
@@ -207,13 +221,16 @@
 	spin_lock_irqsave(&wakeup_reason_lock, flags);
 
 	/* Suspend abort or abnormal wake reason has already been logged. */
-	if (suspend_abort || abnormal_wake) {
+	if (wakeup_reason != RESUME_NONE) {
 		spin_unlock_irqrestore(&wakeup_reason_lock, flags);
 		return;
 	}
 
-	suspend_abort = abort;
-	abnormal_wake = !abort;
+	if (abort)
+		wakeup_reason = RESUME_ABORT;
+	else
+		wakeup_reason = RESUME_ABNORMAL;
+
 	vsnprintf(non_irq_wake_reason, MAX_SUSPEND_ABORT_LEN, fmt, args);
 
 	spin_unlock_irqrestore(&wakeup_reason_lock, flags);
@@ -227,6 +244,7 @@
 	__log_abort_or_abnormal_wake(true, fmt, args);
 	va_end(args);
 }
+EXPORT_SYMBOL_GPL(log_suspend_abort_reason);
 
 void log_abnormal_wakeup_reason(const char *fmt, ...)
 {
@@ -236,6 +254,7 @@
 	__log_abort_or_abnormal_wake(false, fmt, args);
 	va_end(args);
 }
+EXPORT_SYMBOL_GPL(log_abnormal_wakeup_reason);
 
 void clear_wakeup_reasons(void)
 {
@@ -245,8 +264,7 @@
 
 	delete_list(&leaf_irqs);
 	delete_list(&parent_irqs);
-	suspend_abort = false;
-	abnormal_wake = false;
+	wakeup_reason = RESUME_NONE;
 	capture_reasons = true;
 
 	spin_unlock_irqrestore(&wakeup_reason_lock, flags);
@@ -261,17 +279,17 @@
 
 	capture_reasons = false;
 
-	if (suspend_abort) {
+	if (wakeup_reason == RESUME_ABORT) {
 		pr_info("Abort: %s\n", non_irq_wake_reason);
 		spin_unlock_irqrestore(&wakeup_reason_lock, flags);
 		return;
 	}
 
-	if (!list_empty(&leaf_irqs))
+	if (wakeup_reason == RESUME_IRQ && !list_empty(&leaf_irqs))
 		list_for_each_entry(n, &leaf_irqs, siblings)
 			pr_info("Resume caused by IRQ %d, %s\n", n->irq,
 				n->irq_name);
-	else if (abnormal_wake)
+	else if (wakeup_reason == RESUME_ABNORMAL)
 		pr_info("Resume caused by %s\n", non_irq_wake_reason);
 	else
 		pr_info("Resume cause unknown\n");
@@ -288,19 +306,19 @@
 
 	spin_lock_irqsave(&wakeup_reason_lock, flags);
 
-	if (suspend_abort) {
+	if (wakeup_reason == RESUME_ABORT) {
 		buf_offset = scnprintf(buf, PAGE_SIZE, "Abort: %s",
 				       non_irq_wake_reason);
 		spin_unlock_irqrestore(&wakeup_reason_lock, flags);
 		return buf_offset;
 	}
 
-	if (!list_empty(&leaf_irqs))
+	if (wakeup_reason == RESUME_IRQ && !list_empty(&leaf_irqs))
 		list_for_each_entry(n, &leaf_irqs, siblings)
 			buf_offset += scnprintf(buf + buf_offset,
 						PAGE_SIZE - buf_offset,
 						"%d %s\n", n->irq, n->irq_name);
-	else if (abnormal_wake)
+	else if (wakeup_reason == RESUME_ABNORMAL)
 		buf_offset = scnprintf(buf, PAGE_SIZE, "-1 %s",
 				       non_irq_wake_reason);
 
@@ -340,37 +358,12 @@
 		       sleep_time.tv_nsec);
 }
 
-#if defined(CONFIG_ROCKCHIP_SIP)
-static ssize_t total_suspend_wfi_time_show(struct kobject *kobj,
-					   struct kobj_attribute *attr,
-					   char *buf)
-{
-	struct arm_smccc_res res;
-	unsigned long wfi_time_ms;
-
-	res = sip_smc_get_suspend_info(SUSPEND_WFI_TIME_MS);
-	if (res.a0)
-		wfi_time_ms = 0;
-	else
-		wfi_time_ms = res.a1;
-
-	return sprintf(buf, "%lu.%02lu\n", wfi_time_ms / MSEC_PER_SEC,
-		       (wfi_time_ms % MSEC_PER_SEC) / 10);
-}
-#endif
-
 static struct kobj_attribute resume_reason = __ATTR_RO(last_resume_reason);
 static struct kobj_attribute suspend_time = __ATTR_RO(last_suspend_time);
-#if defined(CONFIG_ROCKCHIP_SIP)
-static struct kobj_attribute suspend_wfi_time = __ATTR_RO(total_suspend_wfi_time);
-#endif
 
 static struct attribute *attrs[] = {
 	&resume_reason.attr,
 	&suspend_time.attr,
-#if defined(CONFIG_ROCKCHIP_SIP)
-	&suspend_wfi_time.attr,
-#endif
 	NULL,
 };
 static struct attribute_group attr_group = {

--
Gitblit v1.6.2