Debian Codegraph @

src/soc/mediatek/mt8196/mminfra.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 #include <console/console.h>
4 #include <device/mmio.h>
5 #include <soc/addressmap.h>
6 #include <soc/mminfra.h>
7 #include <soc/spm_mtcmos.h>
8 #include <stddef.h>
9 #include <string.h>
10 #include <timer.h>
11 #include <types.h>
12
13 #define TIMEOUT_US 20
14
15 static void wait_for_write_done(u32 write_reg, u32 status_reg, u32 val)
16 {
17 write32p(write_reg, val);
18
19 if (!wait_us(TIMEOUT_US, read32p(status_reg) == val))
20 die("Wait write done timeout\n");
21 }
22
23 static void mm_gce_lock_prot_en(void)
24 {
25 setbits32p(MMINFRA_GCE_PROT_EN,
26 GCE_D_SLEEPPORT_RX_EN | GCE_D_HAND_SLEEPPORT_RX_EN |
27 GCE_D_HAND_SLEEPPORT_TX_EN | GCE_M_SLEEPPORT_RX_EN |
28 GCE_M_HAND_SLEEPPORT_RX_EN | GCE_M_HAND_SLEEPPORT_TX_EN);
29 write32p(MMINFRA_GCE_DDREN_SEL, 0);
30 }
31
32 static void mm_gce_release_prot_en(void)
33 {
34 write32p(MMINFRA_GCE_PROT_EN, 0);
35 write32p(MMINFRA_GCE_DDREN_SEL, 0x1);
36 }
37
38 static void mm_infra0_lock_prot_en(void)
39 {
40 wait_for_write_done(MMINFRA_MM0_GALS_PROT_TX_EN,
41 MMINFRA_MM0_GALS_PROT_TX_RDY, 0xff);
42 wait_for_write_done(MMINFRA_MM0_GALS_PROT_RX_EN,
43 MMINFRA_MM0_GALS_PROT_RX_RDY, 0xfffff);
44 }
45
46 static void mm_infra0_release_prot_en(void)
47 {
48 write32p(MMINFRA_MM0_GALS_PROT_RX_EN, 0);
49 write32p(MMINFRA_MM0_GALS_PROT_TX_EN, 0);
50 }
51
52 static void mm_infra1_lock_prot_en(void)
53 {
54 mm_gce_lock_prot_en();
55 wait_for_write_done(MMINFRA_MM1_GALS_PROT_TX_EN,
56 MMINFRA_MM1_GALS_PROT_TX_RDY, 0x3f);
57 wait_for_write_done(MMINFRA_MM1_GALS_PROT_RX_EN,
58 MMINFRA_MM1_GALS_PROT_RX_RDY, 0xf);
59 }
60
61 static void mm_infra1_release_prot_en(void)
62 {
63 write32p(MMINFRA_MM1_GALS_PROT_RX_EN, 0);
64 write32p(MMINFRA_MM1_GALS_PROT_TX_EN, 0);
65 mm_gce_release_prot_en();
66 }
67
68 static int pd_mm_infra0_pre_on(void)
69 {
70 setbits32p(MMPC_PM_BOOT_UP_PWR_CON, MM_INFRA0_PM_BOOT_UP | MM_INFRA1_PM_BOOT_UP);
71 return 0;
72 }
73
74 static int pd_mm_infra0_post_on(void)
75 {
76 mm_infra0_release_prot_en();
77 return 0;
78 }
79
80 static int pd_mm_infra0_pre_off(void)
81 {
82 mm_infra0_lock_prot_en();
83 return 0;
84 }
85
86 static int pd_mm_infra1_post_on(void)
87 {
88 mm_infra1_release_prot_en();
89 write32p(VLP_AO_RSVD6, 0x1);
90 return 0;
91 }
92
93 static int pd_mm_infra1_pre_off(void)
94 {
95 mm_infra1_lock_prot_en();
96 return 0;
97 }
98
99 static struct mtcmos_cb mm_infra0_pb_cb = {
100 .pre_on = pd_mm_infra0_pre_on,
101 .post_on = pd_mm_infra0_post_on,
102 .pre_off = pd_mm_infra0_pre_off,
103 };
104
105 static struct mtcmos_cb mm_infra1_pb_cb = {
106 .post_on = pd_mm_infra1_post_on,
107 .pre_off = pd_mm_infra1_pre_off,
108 };
109
110 void mminfra_post_init(void)
111 {
112 if (mtcmos_cb_register(MTCMOS_ID_MM_INFRA0, &mm_infra0_pb_cb))
113 return;
114
115 mtcmos_cb_register(MTCMOS_ID_MM_INFRA1, &mm_infra1_pb_cb);
116 }