Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
CTCaer
GitHub Repository: CTCaer/hekate
Path: blob/master/bdk/soc/ccplex.c
1476 views
1
/*
2
* Copyright (c) 2018 naehrwert
3
* Copyright (c) 2018-2024 CTCaer
4
*
5
* This program is free software; you can redistribute it and/or modify it
6
* under the terms and conditions of the GNU General Public License,
7
* version 2, as published by the Free Software Foundation.
8
*
9
* This program is distributed in the hope it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12
* more details.
13
*
14
* You should have received a copy of the GNU General Public License
15
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16
*/
17
18
#include <memory_map.h>
19
#include <soc/ccplex.h>
20
#include <soc/hw_init.h>
21
#include <soc/i2c.h>
22
#include <soc/clock.h>
23
#include <soc/pmc.h>
24
#include <soc/t210.h>
25
#include <power/max77620.h>
26
#include <power/max7762x.h>
27
#include <power/max77812.h>
28
#include <utils/util.h>
29
30
#define CCPLEX_FLOWCTRL_POWERGATING 0
31
32
static void _ccplex_enable_power_t210()
33
{
34
// Configure GPIO5 and enable output in order to power CPU pmic.
35
max77620_config_gpio(5, MAX77620_GPIO_OUTPUT_ENABLE);
36
37
// Configure CPU pmic.
38
// 1-3.x: MAX77621_NFSR_ENABLE.
39
// 1.0.0-3.x: MAX77621_T_JUNCTION_120 | MAX77621_CKKADV_TRIP_DISABLE | MAX77621_INDUCTOR_NOMINAL.
40
max77621_config_default(REGULATOR_CPU0, MAX77621_CTRL_HOS_CFG);
41
42
// Set voltage and enable cluster power.
43
max7762x_regulator_set_voltage(REGULATOR_CPU0, 950000);
44
max7762x_regulator_enable(REGULATOR_CPU0, true);
45
}
46
47
static void _ccplex_enable_power_t210b01()
48
{
49
// Set voltage and enable cluster power.
50
max7762x_regulator_set_voltage(REGULATOR_CPU1, 800000);
51
max7762x_regulator_enable(REGULATOR_CPU1, true);
52
}
53
54
static void _ccplex_disable_power()
55
{
56
// Disable cluster power.
57
if (hw_get_chip_id() == GP_HIDREV_MAJOR_T210)
58
{
59
max7762x_regulator_enable(REGULATOR_CPU0, false);
60
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_GPIO5, 0);
61
}
62
else
63
max7762x_regulator_enable(REGULATOR_CPU1, false);
64
}
65
66
void ccplex_boot_cpu0(u32 entry, bool lock)
67
{
68
// Set ACTIVE_CLUSER to FAST.
69
FLOW_CTLR(FLOW_CTLR_BPMP_CLUSTER_CONTROL) &= ~CLUSTER_CTRL_ACTIVE_SLOW;
70
71
if (hw_get_chip_id() == GP_HIDREV_MAJOR_T210)
72
_ccplex_enable_power_t210();
73
else
74
_ccplex_enable_power_t210b01();
75
76
clock_enable_pllx();
77
78
// Configure MSELECT source and enable clock to 102MHz.
79
CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_MSELECT) = (0 << 29) | CLK_SRC_DIV(4);
80
CLOCK(CLK_RST_CONTROLLER_CLK_ENB_V_SET) = BIT(CLK_V_MSELECT);
81
82
// Configure initial CPU clock frequency and enable clock.
83
CLOCK(CLK_RST_CONTROLLER_CCLK_BURST_POLICY) = 0x20008888; // PLLX_OUT0_LJ.
84
CLOCK(CLK_RST_CONTROLLER_SUPER_CCLK_DIVIDER) = BIT(31); // SUPER_CDIV_ENB.
85
CLOCK(CLK_RST_CONTROLLER_CLK_ENB_V_SET) = BIT(CLK_V_CPUG);
86
87
clock_enable_coresight();
88
89
// CAR2PMC_CPU_ACK_WIDTH should be set to 0.
90
CLOCK(CLK_RST_CONTROLLER_CPU_SOFTRST_CTRL2) &= 0xFFFFF000;
91
92
// Enable CPU main rail.
93
pmc_enable_partition(POWER_RAIL_CRAIL, ENABLE);
94
// Enable cluster 0 non-CPU rail.
95
pmc_enable_partition(POWER_RAIL_C0NC, ENABLE);
96
// Enable CPU0 rail.
97
pmc_enable_partition(POWER_RAIL_CE0, ENABLE);
98
99
// Request and wait for RAM repair. Needed for the Fast cluster.
100
FLOW_CTLR(FLOW_CTLR_RAM_REPAIR) = RAM_REPAIR_REQ;
101
while (!(FLOW_CTLR(FLOW_CTLR_RAM_REPAIR) & RAM_REPAIR_STS))
102
;
103
104
EXCP_VEC(EVP_CPU_RESET_VECTOR) = 0;
105
106
// Set reset vector.
107
SB(SB_AA64_RESET_LOW) = entry | SB_AA64_RST_AARCH64_MODE_EN;
108
SB(SB_AA64_RESET_HIGH) = 0;
109
110
// Non-secure reset vector write disable.
111
if (lock)
112
{
113
SB(SB_CSR) = SB_CSR_NS_RST_VEC_WR_DIS;
114
(void)SB(SB_CSR);
115
}
116
117
// Tighten up the security aperture.
118
// MC(MC_TZ_SECURITY_CTRL) = 1;
119
120
// Clear MSELECT reset.
121
CLOCK(CLK_RST_CONTROLLER_RST_DEV_V_CLR) = BIT(CLK_V_MSELECT);
122
// Clear NONCPU reset.
123
CLOCK(CLK_RST_CONTROLLER_RST_CPUG_CMPLX_CLR) = BIT(29); // CLR_NONCPURESET.
124
// Clear CPU0 reset.
125
// < 5.x: 0x411F000F, Clear CPU{0,1,2,3} POR and CORE, CX0, L2, and DBG reset.
126
CLOCK(CLK_RST_CONTROLLER_RST_CPUG_CMPLX_CLR) = BIT(30) | BIT(24) | BIT(16) | BIT(0);
127
}
128
129
void ccplex_powergate_cpu0()
130
{
131
#if CCPLEX_FLOWCTRL_POWERGATING
132
// Halt CPU0.
133
FLOW_CTLR(FLOW_CTLR_HALT_CPU0_EVENTS) = HALT_MODE_STOP_UNTIL_IRQ;
134
135
// Powergate cluster via flow control without waiting for WFI.
136
FLOW_CTLR(FLOW_CTLR_CPU0_CSR) = CSR_INTR_FLAG | CSR_EVENT_FLAG | CSR_ENABLE_EXT_CPU_RAIL | CSR_WAIT_WFI_NONE | CSR_ENABLE;
137
138
// Wait for the rail power off to finish.
139
while((FLOW_CTLR(FLOW_CTLR_CPU_PWR_CSR) & CPU_PWR_RAIL_STS_MASK) != CPU_PWR_RAIL_OFF);
140
141
// Set CPU0 to waitevent.
142
FLOW_CTLR(FLOW_CTLR_HALT_CPU0_EVENTS) = HALT_MODE_WAITEVENT;
143
#endif
144
145
// Set CPU0 POR and CORE, CX0, L2, and DBG reset.
146
CLOCK(CLK_RST_CONTROLLER_RST_CPUG_CMPLX_SET) = BIT(30) | BIT(24) | BIT(16) | BIT(0);
147
// Set NONCPU reset.
148
CLOCK(CLK_RST_CONTROLLER_RST_CPUG_CMPLX_SET) = BIT(29);
149
// Set MSELECT reset.
150
CLOCK(CLK_RST_CONTROLLER_RST_DEV_V_SET) = BIT(CLK_V_MSELECT);
151
152
// Disable CE0.
153
pmc_enable_partition(POWER_RAIL_CE0, DISABLE);
154
// Disable cluster 0 non-CPU.
155
pmc_enable_partition(POWER_RAIL_C0NC, DISABLE);
156
// Disable CPU rail.
157
pmc_enable_partition(POWER_RAIL_CRAIL, DISABLE);
158
159
clock_disable_coresight();
160
161
// Clear out MSELECT and CPU clocks.
162
CLOCK(CLK_RST_CONTROLLER_CLK_ENB_V_CLR) = BIT(CLK_V_MSELECT) | BIT(CLK_V_CPUG);
163
164
_ccplex_disable_power();
165
}
166
167