1 /*
2 * Copyright (c) 2025, Mediatek Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7 #include <constraints/mt_spm_rc_api.h>
8 #include <lpm_v2/mt_lpm_smc.h>
9 #include <mt_plat_spm_setting.h>
10 #include <mt_spm_common.h>
11
12 /*
13 * CIRQ will respresent interrupt which type is edge
14 * when gic mask. But if the 26 clk have turned off before
15 * then cirq won't work normally.
16 * So we need to set irq pending for specific wakeup source.
17 */
18 #ifndef MTK_PLAT_CIRQ_UNSUPPORT
mt_spm_irq_remain_dump(struct mt_irqremain * irqs,uint32_t irq_index,struct wake_status * wakeup)19 static void mt_spm_irq_remain_dump(struct mt_irqremain *irqs,
20 uint32_t irq_index,
21 struct wake_status *wakeup)
22 {
23 INFO("[SPM] r12=0x%08x(0x%08x), irq:%u(0x%08x) set pending\n",
24 wakeup->tr.comm.r12,
25 wakeup->md32pcm_wakeup_sta,
26 irqs->wakeupsrc[irq_index],
27 irqs->irqs[irq_index]);
28 }
29
do_irqs_delivery(struct mt_irqremain * irqs,struct wake_status * wakeup)30 void do_irqs_delivery(struct mt_irqremain *irqs,
31 struct wake_status *wakeup)
32 {
33 uint32_t idx;
34
35 if (!irqs || !wakeup)
36 return;
37
38 for (idx = 0; idx < irqs->count; idx++) {
39 if ((wakeup->tr.comm.raw_sta & irqs->wakeupsrc[idx]) ||
40 (wakeup->tr.comm.r12 & irqs->wakeupsrc[idx])) {
41 if ((irqs->wakeupsrc_cat[idx] & MT_IRQ_REMAIN_CAT_LOG))
42 mt_spm_irq_remain_dump(irqs, idx, wakeup);
43 }
44 }
45 }
46 #endif
47