2018-03-26 23:04:16 +00:00
|
|
|
/*
|
2018-08-05 11:40:32 +00:00
|
|
|
* Copyright (c) 2018 naehrwert
|
2020-06-26 16:02:37 +00:00
|
|
|
* Copyright (c) 2018-2020 CTCaer
|
2018-08-05 11:40:32 +00:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms and conditions of the GNU General Public License,
|
|
|
|
* version 2, as published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2018-03-26 23:04:16 +00:00
|
|
|
|
2020-06-14 13:45:45 +00:00
|
|
|
#include <soc/ccplex.h>
|
2020-06-26 16:02:37 +00:00
|
|
|
#include <soc/fuse.h>
|
|
|
|
#include <soc/hw_init.h>
|
2020-06-14 13:45:45 +00:00
|
|
|
#include <soc/i2c.h>
|
|
|
|
#include <soc/clock.h>
|
|
|
|
#include <soc/pmc.h>
|
|
|
|
#include <soc/t210.h>
|
|
|
|
#include <power/max77620.h>
|
|
|
|
#include <power/max7762x.h>
|
2020-06-26 16:02:37 +00:00
|
|
|
#include <power/max77812.h>
|
2020-07-17 21:42:53 +00:00
|
|
|
#include <utils/util.h>
|
2018-03-14 23:26:19 +00:00
|
|
|
|
2020-06-26 16:02:37 +00:00
|
|
|
void _ccplex_enable_power_t210()
|
2018-03-14 23:26:19 +00:00
|
|
|
{
|
2019-02-15 23:23:14 +00:00
|
|
|
u8 tmp = i2c_recv_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_AME_GPIO); // Get current pinmuxing
|
2020-11-25 23:41:45 +00:00
|
|
|
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_AME_GPIO, tmp & ~BIT(5)); // Disable GPIO5 pinmuxing.
|
2018-09-18 21:11:18 +00:00
|
|
|
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_GPIO5, MAX77620_CNFG_GPIO_DRV_PUSHPULL | MAX77620_CNFG_GPIO_OUTPUT_VAL_HIGH);
|
2018-03-14 23:26:19 +00:00
|
|
|
|
2018-08-05 11:40:32 +00:00
|
|
|
// Enable cores power.
|
2018-11-10 12:11:42 +00:00
|
|
|
// 1-3.x: MAX77621_NFSR_ENABLE.
|
2018-09-18 21:11:18 +00:00
|
|
|
i2c_send_byte(I2C_5, MAX77621_CPU_I2C_ADDR, MAX77621_CONTROL1_REG,
|
2019-09-01 00:55:43 +00:00
|
|
|
MAX77621_AD_ENABLE | MAX77621_NFSR_ENABLE | MAX77621_SNS_ENABLE | MAX77621_RAMP_12mV_PER_US);
|
2018-11-10 12:11:42 +00:00
|
|
|
// 1.0.0-3.x: MAX77621_T_JUNCTION_120 | MAX77621_CKKADV_TRIP_DISABLE | MAX77621_INDUCTOR_NOMINAL.
|
2018-09-18 21:11:18 +00:00
|
|
|
i2c_send_byte(I2C_5, MAX77621_CPU_I2C_ADDR, MAX77621_CONTROL2_REG,
|
2018-11-10 12:11:42 +00:00
|
|
|
MAX77621_T_JUNCTION_120 | MAX77621_WDTMR_ENABLE | MAX77621_CKKADV_TRIP_75mV_PER_US| MAX77621_INDUCTOR_NOMINAL);
|
2019-09-09 12:48:49 +00:00
|
|
|
i2c_send_byte(I2C_5, MAX77621_CPU_I2C_ADDR, MAX77621_VOUT_REG, MAX77621_VOUT_ENABLE | MAX77621_VOUT_0_95V);
|
2020-06-13 23:02:26 +00:00
|
|
|
i2c_send_byte(I2C_5, MAX77621_CPU_I2C_ADDR, MAX77621_VOUT_DVS_REG, MAX77621_VOUT_ENABLE | MAX77621_VOUT_0_95V);
|
2018-03-14 23:26:19 +00:00
|
|
|
}
|
|
|
|
|
2020-06-26 16:02:37 +00:00
|
|
|
void _ccplex_enable_power_t210b01()
|
|
|
|
{
|
2020-12-26 14:34:12 +00:00
|
|
|
u8 pmic_cpu_addr = !(FUSE(FUSE_RESERVED_ODM28_T210B01) & 1) ? MAX77812_PHASE31_CPU_I2C_ADDR : MAX77812_PHASE211_CPU_I2C_ADDR;
|
2020-06-26 16:02:37 +00:00
|
|
|
u8 tmp = i2c_recv_byte(I2C_5, pmic_cpu_addr, MAX77812_REG_EN_CTRL);
|
|
|
|
i2c_send_byte(I2C_5, pmic_cpu_addr, MAX77812_REG_EN_CTRL, tmp | MAX77812_EN_CTRL_EN_M4);
|
|
|
|
i2c_send_byte(I2C_5, pmic_cpu_addr, MAX77812_REG_M4_VOUT, MAX77812_M4_VOUT_0_80V);
|
|
|
|
}
|
|
|
|
|
2020-06-13 22:09:17 +00:00
|
|
|
void ccplex_boot_cpu0(u32 entry)
|
2018-03-14 23:26:19 +00:00
|
|
|
{
|
2018-08-05 11:40:32 +00:00
|
|
|
// Set ACTIVE_CLUSER to FAST.
|
2018-03-14 23:26:19 +00:00
|
|
|
FLOW_CTLR(FLOW_CTLR_BPMP_CLUSTER_CONTROL) &= 0xFFFFFFFE;
|
|
|
|
|
2020-06-26 16:02:37 +00:00
|
|
|
if (hw_get_chip_id() == GP_HIDREV_MAJOR_T210)
|
|
|
|
_ccplex_enable_power_t210();
|
|
|
|
else
|
|
|
|
_ccplex_enable_power_t210b01();
|
2018-03-14 23:26:19 +00:00
|
|
|
|
2020-12-26 15:28:08 +00:00
|
|
|
// Enable PLLX and set it to 300 MHz.
|
|
|
|
if (!(CLOCK(CLK_RST_CONTROLLER_PLLX_BASE) & PLLX_BASE_ENABLE)) // PLLX_ENABLE.
|
2018-03-14 23:26:19 +00:00
|
|
|
{
|
2019-12-04 19:31:39 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_PLLX_MISC_3) &= 0xFFFFFFF7; // Disable IDDQ.
|
2018-07-04 15:39:26 +00:00
|
|
|
usleep(2);
|
2020-12-26 15:28:08 +00:00
|
|
|
|
|
|
|
// Bypass dividers.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_PLLX_BASE) = PLLX_BASE_BYPASS | (4 << 20) | (78 << 8) | 2; // P div: 4 (5), N div: 78, M div: 2.
|
|
|
|
// Disable bypass
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_PLLX_BASE) = (4 << 20) | (78 << 8) | 2;
|
|
|
|
// Set PLLX_LOCK_ENABLE.
|
2018-06-08 09:42:24 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_PLLX_MISC) = (CLOCK(CLK_RST_CONTROLLER_PLLX_MISC) & 0xFFFBFFFF) | 0x40000;
|
2020-12-26 15:28:08 +00:00
|
|
|
// Enable PLLX.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_PLLX_BASE) = PLLX_BASE_ENABLE | (4 << 20) | (78 << 8) | 2;
|
2018-03-14 23:26:19 +00:00
|
|
|
}
|
2020-12-26 15:28:08 +00:00
|
|
|
// Wait for PLL to stabilize.
|
|
|
|
while (!(CLOCK(CLK_RST_CONTROLLER_PLLX_BASE) & PLLX_BASE_LOCK))
|
2018-03-14 23:26:19 +00:00
|
|
|
;
|
|
|
|
|
2020-12-26 15:28:08 +00:00
|
|
|
// Configure MSELECT source and enable clock to 102MHz.
|
2018-06-08 09:42:24 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_MSELECT) = (CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_MSELECT) & 0x1FFFFF00) | 6;
|
2020-12-26 15:28:08 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_ENB_V_SET) = BIT(CLK_V_MSELECT);
|
2018-05-01 05:15:48 +00:00
|
|
|
|
2018-08-05 11:40:32 +00:00
|
|
|
// Configure initial CPU clock frequency and enable clock.
|
2020-12-26 15:28:08 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CCLK_BURST_POLICY) = 0x20008888; // PLLX_OUT0_LJ.
|
2018-05-01 05:15:48 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_SUPER_CCLK_DIVIDER) = 0x80000000;
|
2020-07-17 13:50:17 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_ENB_V_SET) = BIT(CLK_V_CPUG);
|
2018-03-14 23:26:19 +00:00
|
|
|
|
|
|
|
clock_enable_coresight();
|
|
|
|
|
2018-08-05 11:40:32 +00:00
|
|
|
// CAR2PMC_CPU_ACK_WIDTH should be set to 0.
|
2018-06-08 09:42:24 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CPU_SOFTRST_CTRL2) &= 0xFFFFF000;
|
2018-03-14 23:26:19 +00:00
|
|
|
|
2020-12-26 15:20:26 +00:00
|
|
|
// Enable CPU main rail.
|
|
|
|
pmc_enable_partition(POWER_RAIL_CRAIL, ENABLE);
|
2020-07-17 21:42:53 +00:00
|
|
|
// Enable cluster 0 non-CPU rail.
|
2020-12-26 15:20:26 +00:00
|
|
|
pmc_enable_partition(POWER_RAIL_C0NC, ENABLE);
|
|
|
|
// Enable CPU0 rail.
|
|
|
|
pmc_enable_partition(POWER_RAIL_CE0, ENABLE);
|
2018-03-14 23:26:19 +00:00
|
|
|
|
2018-08-05 11:40:32 +00:00
|
|
|
// Request and wait for RAM repair.
|
2018-03-14 23:26:19 +00:00
|
|
|
FLOW_CTLR(FLOW_CTLR_RAM_REPAIR) = 1;
|
|
|
|
while (!(FLOW_CTLR(FLOW_CTLR_RAM_REPAIR) & 2))
|
|
|
|
;
|
|
|
|
|
2018-11-10 12:11:42 +00:00
|
|
|
EXCP_VEC(EVP_CPU_RESET_VECTOR) = 0;
|
2018-03-14 23:26:19 +00:00
|
|
|
|
2018-08-05 11:40:32 +00:00
|
|
|
// Set reset vector.
|
2019-09-09 13:56:37 +00:00
|
|
|
SB(SB_AA64_RESET_LOW) = entry | SB_AA64_RST_AARCH64_MODE_EN;
|
2018-03-14 23:26:19 +00:00
|
|
|
SB(SB_AA64_RESET_HIGH) = 0;
|
2018-08-05 11:40:32 +00:00
|
|
|
// Non-secure reset vector write disable.
|
2019-09-09 13:56:37 +00:00
|
|
|
SB(SB_CSR) = SB_CSR_NS_RST_VEC_WR_DIS;
|
2018-05-01 05:15:48 +00:00
|
|
|
(void)SB(SB_CSR);
|
2018-03-14 23:26:19 +00:00
|
|
|
|
2019-12-04 19:31:39 +00:00
|
|
|
// Tighten up the security aperture.
|
|
|
|
// MC(MC_TZ_SECURITY_CTRL) = 1;
|
|
|
|
|
2018-08-05 11:40:32 +00:00
|
|
|
// Clear MSELECT reset.
|
2020-12-26 15:28:08 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_RST_DEV_V_CLR) = BIT(CLK_V_MSELECT);
|
2018-08-05 11:40:32 +00:00
|
|
|
// Clear NONCPU reset.
|
2018-05-01 05:15:48 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_RST_CPUG_CMPLX_CLR) = 0x20000000;
|
2018-11-20 19:32:54 +00:00
|
|
|
// Clear CPU0 reset.
|
|
|
|
// < 5.x: 0x411F000F, Clear CPU{0,1,2,3} POR and CORE, CX0, L2, and DBG reset.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_RST_CPUG_CMPLX_CLR) = 0x41010001;
|
2018-03-14 23:26:19 +00:00
|
|
|
}
|