From 61598093bbdd283a7edc367d900f223070ead8d2 Mon Sep 17 00:00:00 2001 From: hc <hc@nodka.com> Date: Fri, 10 May 2024 07:43:03 +0000 Subject: [PATCH] add ax88772C AX88772C_eeprom_tools --- kernel/kernel/power/wakeup_reason.c | 111 ++++++++++++++++++++++++++----------------------------- 1 files changed, 52 insertions(+), 59 deletions(-) diff --git a/kernel/kernel/power/wakeup_reason.c b/kernel/kernel/power/wakeup_reason.c index e8f68d3..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,7 +41,14 @@ const char *irq_name; }; -static DEFINE_RAW_SPINLOCK(wakeup_reason_lock); +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 */ static LIST_HEAD(parent_irqs); /* unordered */ @@ -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 */ @@ -149,17 +152,22 @@ { unsigned long flags; - raw_spin_lock_irqsave(&wakeup_reason_lock, 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) { - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); + spin_unlock_irqrestore(&wakeup_reason_lock, flags); return; } if (find_node_in_list(&parent_irqs, irq) == NULL) add_sibling_node_sorted(&leaf_irqs, irq); - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); + wakeup_reason = RESUME_IRQ; + spin_unlock_irqrestore(&wakeup_reason_lock, flags); } void log_threaded_irq_wakeup_reason(int irq, int parent_irq) @@ -177,10 +185,15 @@ if (!capture_reasons) return; - raw_spin_lock_irqsave(&wakeup_reason_lock, 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 || (find_node_in_list(&leaf_irqs, irq) != NULL)) { - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); + spin_unlock_irqrestore(&wakeup_reason_lock, flags); return; } @@ -196,27 +209,31 @@ } } - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); + 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) { unsigned long flags; - raw_spin_lock_irqsave(&wakeup_reason_lock, flags); + spin_lock_irqsave(&wakeup_reason_lock, flags); /* Suspend abort or abnormal wake reason has already been logged. */ - if (suspend_abort || abnormal_wake) { - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); + 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); - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); + spin_unlock_irqrestore(&wakeup_reason_lock, flags); } void log_suspend_abort_reason(const char *fmt, ...) @@ -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,20 +254,20 @@ __log_abort_or_abnormal_wake(false, fmt, args); va_end(args); } +EXPORT_SYMBOL_GPL(log_abnormal_wakeup_reason); void clear_wakeup_reasons(void) { unsigned long flags; - raw_spin_lock_irqsave(&wakeup_reason_lock, flags); + spin_lock_irqsave(&wakeup_reason_lock, flags); delete_list(&leaf_irqs); delete_list(&parent_irqs); - suspend_abort = false; - abnormal_wake = false; + wakeup_reason = RESUME_NONE; capture_reasons = true; - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); + spin_unlock_irqrestore(&wakeup_reason_lock, flags); } static void print_wakeup_sources(void) @@ -257,26 +275,26 @@ struct wakeup_irq_node *n; unsigned long flags; - raw_spin_lock_irqsave(&wakeup_reason_lock, flags); + spin_lock_irqsave(&wakeup_reason_lock, flags); capture_reasons = false; - if (suspend_abort) { + if (wakeup_reason == RESUME_ABORT) { pr_info("Abort: %s\n", non_irq_wake_reason); - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); + 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"); - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); + spin_unlock_irqrestore(&wakeup_reason_lock, flags); } static ssize_t last_resume_reason_show(struct kobject *kobj, @@ -286,25 +304,25 @@ struct wakeup_irq_node *n; unsigned long flags; - raw_spin_lock_irqsave(&wakeup_reason_lock, flags); + 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); - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); + 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); - raw_spin_unlock_irqrestore(&wakeup_reason_lock, flags); + spin_unlock_irqrestore(&wakeup_reason_lock, flags); return buf_offset; } @@ -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