Debian Codegraph @

src/soc/mediatek/mt8189/mcupm.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
2
3 #include <console/console.h>
4 #include <delay.h>
5 #include <device/mmio.h>
6 #include <soc/addressmap.h>
7 #include <soc/mcu_common.h>
8 #include <soc/mcupm.h>
9 #include <soc/mcupm_plat.h>
10 #include <soc/spm.h>
11 #include <soc/symbols.h>
12
13 static void reset_mcupm(struct mtk_mcu *mcu)
14 {
15 /* Clear abnormal boot register */
16 write32p(ABNORMALBOOT_REG, ABNORMALBOOT_REG_STATUS);
17 write32p(WARMBOOT_REG, WARMBOOT_REG_STATUS);
18 write32(&mcupm_reg->sw_rstn, MCUPM_RSTN_RESET);
19 }
20
21 static struct mtk_mcu mcupm = {
22 .firmware_name = CONFIG_MCUPM_FIRMWARE,
23 .run_address = (void *)MCUPM_SRAM_BASE,
24 .reset = reset_mcupm,
25 };
26
27 void mcupm_init(void)
28 {
29 mcupm.load_buffer = _dram_dma;
30 mcupm.buffer_size = REGION_SIZE(dram_dma);
31
32 /* Set CPUEB as secure master */
33 setbits32(&mtk_spm->poweron_config_set, BIT(15));
34
35 /* Unlock SPM POWERON_CONFIG_EN */
36 setbits32(&mtk_spm->poweron_config_set, SPM_REGWR_CFG_KEY | BCLK_CG_EN_LSB);
37
38 /* Reinit CPUEB_PWR_CON */
39 /* (1) CPUEB MTCMOS */
40 setbits32(&mtk_spm->cpueb_pwr_con, CPUEB_PWR_ON_LSB);
41 setbits32(&mtk_spm->cpueb_pwr_con, CPUEB_PWR_ON_2ND_LSB);
42 u32 pwr_con_mask = SC_CPUEB_PWR_ACK_LSB | SC_CPUEB_PWR_ACK_2ND_LSB;
43 if (!retry(POLLING_ACK_RETRY_COUNTS,
44 ((read32(&mtk_spm->cpueb_pwr_con) & pwr_con_mask) == pwr_con_mask),
45 udelay(1))) {
46 printk(BIOS_ERR, "%s Polling ACK timeout, %#x\n", __func__,
47 read32(&mtk_spm->cpueb_pwr_con));
48 return;
49 }
50
51 clrbits32(&mtk_spm->cpueb_pwr_con, CPUEB_PWR_CLK_DIS_LSB);
52 clrbits32(&mtk_spm->cpueb_pwr_con, CPUEB_PWR_ISO_LSB);
53 setbits32(&mtk_spm->cpueb_pwr_con, CPUEB_PWR_RST_B_LSB);
54
55 /* (2) SRAM leave DORMANT mode */
56 setbits32(&mtk_spm->cpueb_pwr_con, CPUEB_SRAM_SLEEP_B_LSB);
57 if (!retry(POLLING_ACK_RETRY_COUNTS,
58 ((read32(&mtk_spm->cpueb_pwr_con) & SC_CPUEB_SRAM_SLEEP_B_ACK_LSB) != 0),
59 udelay(1))) {
60 printk(BIOS_ERR, "%s Polling SRAM Sleep B ACK timeout, %#x\n", __func__,
61 read32(&mtk_spm->cpueb_pwr_con));
62 return;
63 }
64
65 udelay(1);
66 setbits32(&mtk_spm->cpueb_pwr_con, CPUEB_SRAM_ISOINT_B_LSB);
67 clrbits32(&mtk_spm->cpueb_pwr_con, CPUEB_SRAM_CKISO_LSB);
68
69 /* Power on MCUPM sram */
70 clrbits32(&mtk_spm->cpueb_pwr_con, CPUEB_SRAM_PDN_LSB);
71 pwr_con_mask = SC_CPUEB_SRAM_PDN_ACK_LSB;
72 if (!retry(POLLING_SRAM_RETRY_COUNTS,
73 (read32(&mtk_spm->cpueb_pwr_con) & pwr_con_mask) != pwr_con_mask,
74 udelay(1))) {
75 printk(BIOS_ERR, "%s Polling SRAM Power on timeout, %#x\n", __func__,
76 read32(&mtk_spm->cpueb_pwr_con));
77 return;
78 }
79
80 printk(BIOS_INFO, "%s Power on MCUPM SRAM success\n", __func__);
81
82 write32(&mcupm_reg->sw_rstn, MCUPM_RSTN_RSTN_INIT);
83 if (mtk_init_mcu(&mcupm))
84 die("%s() mtk_init_mcu failed\n", __func__);
85
86 setbits32p(MCUPM_SW_RSTN,
87 MCUPM_CFGREG_SW_RSTN_SW_RSTN | MCUPM_CFGREG_SW_RSTN_DMA_BUSY_MASK);
88
89 printk(BIOS_DEBUG, "mcupm: MCUPM_SRAM_GPR0: %#x, %#x\n",
90 MCUPM_INFO, read32p(MCUPM_INFO));
91 printk(BIOS_DEBUG, "mcupm: MCUPM_SRAM_GPR1: %#x, %#x\n",
92 ABNORMALBOOT_REG, read32p(ABNORMALBOOT_REG));
93 printk(BIOS_DEBUG, "mcupm: MCUPM_SRAM_GPR23: %#x, %#x\n",
94 WARMBOOT_REG, read32p(WARMBOOT_REG));
95 printk(BIOS_DEBUG, "mcupm: MCUPM_SW_RSTN: %#x, %#x\n",
96 MCUPM_SW_RSTN, read32p(MCUPM_SW_RSTN));
97 printk(BIOS_DEBUG, "mcupm: MCUPM_SRAM_BASE: %#x, %#x\n",
98 MCUPM_SRAM_BASE, read32p(MCUPM_SRAM_BASE));
99 printk(BIOS_DEBUG, "%s MCUPM part. load & reset finished\n", __func__);
100 }