mtspmc.c 4.05 KB
Newer Older
James Liao's avatar
James Liao committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
 * Copyright (c) 2020, MediaTek Inc. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#include <assert.h>

#include <common/debug.h>
#include <drivers/delay_timer.h>
#include <lib/mmio.h>

#include <mcucfg.h>
#include <mtspmc.h>
#include <mtspmc_private.h>


18
void mcucfg_disable_gic_wakeup(unsigned int cluster, unsigned int cpu)
James Liao's avatar
James Liao committed
19
20
21
22
{
	mmio_setbits_32(MCUCFG_CPC_FLOW_CTRL_CFG, GIC_WAKEUP_IGNORE(cpu));
}

23
void mcucfg_enable_gic_wakeup(unsigned int cluster, unsigned int cpu)
James Liao's avatar
James Liao committed
24
25
26
27
{
	mmio_clrbits_32(MCUCFG_CPC_FLOW_CTRL_CFG, GIC_WAKEUP_IGNORE(cpu));
}

28
void mcucfg_set_bootaddr(unsigned int cluster, unsigned int cpu, uintptr_t bootaddr)
James Liao's avatar
James Liao committed
29
30
31
32
33
34
{
	assert(cluster == 0U);

	mmio_write_32(per_cpu(cluster, cpu, MCUCFG_BOOTADDR), bootaddr);
}

35
uintptr_t mcucfg_get_bootaddr(unsigned int cluster, unsigned int cpu)
James Liao's avatar
James Liao committed
36
37
38
39
40
41
{
	assert(cluster == 0U);

	return (uintptr_t)mmio_read_32(per_cpu(cluster, cpu, MCUCFG_BOOTADDR));
}

42
void mcucfg_init_archstate(unsigned int cluster, unsigned int cpu, bool arm64)
James Liao's avatar
James Liao committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{
	uint32_t reg;

	assert(cluster == 0U);

	reg = per_cluster(cluster, MCUCFG_INITARCH);

	if (arm64) {
		mmio_setbits_32(reg, MCUCFG_INITARCH_CPU_BIT(cpu));
	} else {
		mmio_clrbits_32(reg, MCUCFG_INITARCH_CPU_BIT(cpu));
	}
}

/**
 * Return subsystem's power state.
 *
60
 * @mask: mask to MCUCFG_CPC_SPMC_PWR_STATUS to query the power state
James Liao's avatar
James Liao committed
61
62
63
64
65
66
67
 *        of one subsystem.
 * RETURNS:
 * 0 (the subsys was powered off)
 * 1 (the subsys was powered on)
 */
bool spm_get_powerstate(uint32_t mask)
{
68
	return (mmio_read_32(MCUCFG_CPC_SPMC_PWR_STATUS) & mask) != 0U;
James Liao's avatar
James Liao committed
69
70
}

71
bool spm_get_cluster_powerstate(unsigned int cluster)
James Liao's avatar
James Liao committed
72
73
74
{
	assert(cluster == 0U);

75
	return spm_get_powerstate(BIT(14));
James Liao's avatar
James Liao committed
76
77
}

78
bool spm_get_cpu_powerstate(unsigned int cluster, unsigned int cpu)
James Liao's avatar
James Liao committed
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{
	uint32_t mask = BIT(cpu);

	assert(cluster == 0U);

	return spm_get_powerstate(mask);
}

int spmc_init(void)
{
	INFO("SPM: enable CPC mode\n");

	mmio_write_32(SPM_POWERON_CONFIG_EN, PROJECT_CODE | BCLK_CG_EN);

	mmio_setbits_32(per_cpu(0, 1, SPM_CPU_PWR), PWR_RST_B);
	mmio_setbits_32(per_cpu(0, 2, SPM_CPU_PWR), PWR_RST_B);
	mmio_setbits_32(per_cpu(0, 3, SPM_CPU_PWR), PWR_RST_B);
	mmio_setbits_32(per_cpu(0, 4, SPM_CPU_PWR), PWR_RST_B);
	mmio_setbits_32(per_cpu(0, 5, SPM_CPU_PWR), PWR_RST_B);
	mmio_setbits_32(per_cpu(0, 6, SPM_CPU_PWR), PWR_RST_B);
	mmio_setbits_32(per_cpu(0, 7, SPM_CPU_PWR), PWR_RST_B);

	mmio_clrbits_32(SPM_MCUSYS_PWR_CON, RESETPWRON_CONFIG);
	mmio_clrbits_32(SPM_MP0_CPUTOP_PWR_CON, RESETPWRON_CONFIG);
	mmio_clrbits_32(per_cpu(0, 0, SPM_CPU_PWR), RESETPWRON_CONFIG);

	mmio_setbits_32(MCUCFG_CPC_FLOW_CTRL_CFG, CPC_CTRL_ENABLE);
106
	mmio_setbits_32(MCUCFG_CPC_FLOW_CTRL_CFG, SSPM_CORE_PWR_ON_EN);
James Liao's avatar
James Liao committed
107
108
109
110
111
112
113
114
115
116

	return 0;
}

/**
 * Power on a core with specified cluster and core index
 *
 * @cluster: the cluster ID of the CPU which to be powered on
 * @cpu: the CPU ID of the CPU which to be powered on
 */
117
void spm_poweron_cpu(unsigned int cluster, unsigned int cpu)
James Liao's avatar
James Liao committed
118
{
119
120
	uintptr_t cpu_pwr_con = per_cpu(cluster, cpu, SPM_CPU_PWR);

James Liao's avatar
James Liao committed
121
122
123
124
125
	/* set to 0 after BIG VPROC bulk on & before B-core power on seq. */
	if (cpu >= 4U) {
		mmio_write_32(DREQ20_BIG_VPROC_ISO, 0U);
	}

126
	mmio_setbits_32(cpu_pwr_con, PWR_ON);
James Liao's avatar
James Liao committed
127
128

	while (!spm_get_cpu_powerstate(cluster, cpu)) {
129
130
		mmio_clrbits_32(cpu_pwr_con, PWR_ON);
		mmio_setbits_32(cpu_pwr_con, PWR_ON);
James Liao's avatar
James Liao committed
131
132
133
134
135
136
137
138
139
	}
}

/**
 * Power off a core with specified cluster and core index
 *
 * @cluster: the cluster ID of the CPU which to be powered off
 * @cpu: the CPU ID of the CPU which to be powered off
 */
140
void spm_poweroff_cpu(unsigned int cluster, unsigned int cpu)
James Liao's avatar
James Liao committed
141
142
143
144
145
146
147
148
149
150
{
	/* Set mp0_spmc_pwr_on_cpuX = 0 */
	mmio_clrbits_32(per_cpu(cluster, cpu, SPM_CPU_PWR), PWR_ON);
}

/**
 * Power off a cluster with specified index
 *
 * @cluster: the cluster index which to be powered off
 */
151
void spm_poweroff_cluster(unsigned int cluster)
James Liao's avatar
James Liao committed
152
153
154
155
156
157
158
159
160
161
{
	/* No need to power on/off cluster on single cluster platform */
	assert(false);
}

/**
 * Power on a cluster with specified index
 *
 * @cluster: the cluster index which to be powered on
 */
162
void spm_poweron_cluster(unsigned int cluster)
James Liao's avatar
James Liao committed
163
164
165
166
{
	/* No need to power on/off cluster on single cluster platform */
	assert(false);
}