| 1 |
|
| 2 |
|
| 3 |
#include <console/console.h> |
| 4 |
#include <delay.h> |
| 5 |
#include <device/mmio.h> |
| 6 |
#include <soc/mcu_common.h> |
| 7 |
#include <soc/mcupm.h> |
| 8 |
#include <soc/mcupm_plat.h> |
| 9 |
#include <soc/symbols.h> |
| 10 |
|
| 11 |
static int eb_sleep_protect(void) |
| 12 |
{ |
| 13 |
|
| 14 |
setbits32p(MCU_PORT_SET_W1C_0, CPUEB_PROTECT_EN_0 | CPUEB_PROTECT_EN_1); |
| 15 |
|
| 16 |
|
| 17 |
if (!retry(POLLING_MCU_RETRY_COUNTS, |
| 18 |
(read32p(MCU_PORT_SET_R0_0) & |
| 19 |
(CPUEB_PROTECT_RDY_0 | CPUEB_PROTECT_RDY_1)) == 0, udelay(1))) { |
| 20 |
printk(BIOS_ERR, |
| 21 |
"[EB_SPMC] CPUEB_PROTECT_RDY not set after %d us, value %#x\n", |
| 22 |
POLLING_MCU_RETRY_COUNTS, read32p(MCU_PORT_SET_R0_0)); |
| 23 |
return -1; |
| 24 |
} |
| 25 |
|
| 26 |
return 0; |
| 27 |
} |
| 28 |
|
| 29 |
static int set_cpueb_state(bool state_valid) |
| 30 |
{ |
| 31 |
if (state_valid) |
| 32 |
setbits32p(SPM_MCUPM_SPMC_CON, CPUEB_STATE_VALID); |
| 33 |
else |
| 34 |
clrbits32p(SPM_MCUPM_SPMC_CON, CPUEB_STATE_VALID); |
| 35 |
|
| 36 |
if (!retry(POLLING_ACK_RETRY_COUNTS, |
| 37 |
((read32p(SPM_MCUPM_SPMC_CON) & CPUEB_STATE_FINISH_ACK) != 0) == state_valid, |
| 38 |
udelay(1))) { |
| 39 |
printk(BIOS_ERR, "[EB_SPMC] Polling ACK timeout, %#x\n", |
| 40 |
read32p(SPM_MCUPM_SPMC_CON)); |
| 41 |
return -1; |
| 42 |
} |
| 43 |
|
| 44 |
return 0; |
| 45 |
} |
| 46 |
|
| 47 |
static int eb_spmc_spm(void) |
| 48 |
{ |
| 49 |
|
| 50 |
setbits32p(POWERON_CONFIG_EN_MCU, SPM_REGWR_CFG_KEY | BCLK_CG_EN_LSB); |
| 51 |
|
| 52 |
|
| 53 |
setbits32p(SPM_MCUPM_SPMC_CON, REQ_PWR_ON); |
| 54 |
|
| 55 |
clrbits32p(SPM_MCUPM_SPMC_CON, REQ_MEM_RET); |
| 56 |
|
| 57 |
|
| 58 |
if (set_cpueb_state(true)) |
| 59 |
return -1; |
| 60 |
|
| 61 |
|
| 62 |
if (set_cpueb_state(false)) |
| 63 |
return -1; |
| 64 |
|
| 65 |
return eb_sleep_protect(); |
| 66 |
} |
| 67 |
|
| 68 |
static int eb_spmc(void) |
| 69 |
{ |
| 70 |
uint32_t spmc_status = (read32p(CPUEB_SPMC_STATUS) >> CPUEB_SPMC_STATUS_OFFSET) & |
| 71 |
CPUEB_SPMC_STATUS_MASK; |
| 72 |
int ret; |
| 73 |
|
| 74 |
switch (spmc_status) { |
| 75 |
case CPUEB_FSM_STATE_OFF: |
| 76 |
case CPUEB_FSM_STATE_ON: |
| 77 |
case CPUEB_FSM_STATE_RET: |
| 78 |
case CPUEB_FSM_STATE_FUNC_RET: |
| 79 |
printk(BIOS_INFO, "[EB_SPMC] spmc_status = %#x\n", spmc_status); |
| 80 |
ret = eb_spmc_spm(); |
| 81 |
break; |
| 82 |
default: |
| 83 |
printk(BIOS_ERR, "[EB_SPMC] EB SPMC in wrong state, spmc_status = %#x\n", |
| 84 |
spmc_status); |
| 85 |
ret = -1; |
| 86 |
break; |
| 87 |
} |
| 88 |
|
| 89 |
return ret; |
| 90 |
} |
| 91 |
|
| 92 |
static void reset_mcupm(struct mtk_mcu *mcu) |
| 93 |
{ |
| 94 |
|
| 95 |
write32p(ABNORMALBOOT_REG, ABNORMALBOOT_REG_STATUS); |
| 96 |
write32p(WARMBOOT_REG, WARMBOOT_REG_STATUS); |
| 97 |
write32(&mcupm_reg->sw_rstn, MCUPM_RSTN_RESET); |
| 98 |
|
| 99 |
write32p(MCUPM_SW_RSTN, |
| 100 |
MCUPM_CFGREG_SW_RSTN_SW_RSTN | MCUPM_CFGREG_SW_RSTN_DMA_BUSY_MASK); |
| 101 |
} |
| 102 |
|
| 103 |
static struct mtk_mcu mcupm = { |
| 104 |
.firmware_name = CONFIG_MCUPM_FIRMWARE, |
| 105 |
.run_address = (void *)MCUPM_SRAM_BASE, |
| 106 |
.reset = reset_mcupm, |
| 107 |
}; |
| 108 |
|
| 109 |
void mcupm_init(void) |
| 110 |
{ |
| 111 |
mcupm.load_buffer = _dram_dma; |
| 112 |
mcupm.buffer_size = REGION_SIZE(dram_dma); |
| 113 |
|
| 114 |
|
| 115 |
printk(BIOS_INFO, "Before: DEVAPC_MCUPM = %#x\n", |
| 116 |
read32p(DEVAPC_INFRA_SECU_AO_SEC_REPLACE_0)); |
| 117 |
setbits32p(DEVAPC_INFRA_SECU_AO_SEC_REPLACE_0, BIT(15)); |
| 118 |
printk(BIOS_INFO, "After: DEVAPC_MCUPM = %#x\n", |
| 119 |
read32p(DEVAPC_INFRA_SECU_AO_SEC_REPLACE_0)); |
| 120 |
|
| 121 |
if (eb_spmc() != 0) |
| 122 |
die("%s: eb sram power on failed\n", __func__); |
| 123 |
write32(&mcupm_reg->sw_rstn, MCUPM_RSTN_RSTN_INIT); |
| 124 |
if (mtk_init_mcu(&mcupm)) |
| 125 |
die("%s: failed\n", __func__); |
| 126 |
} |