2018-09-07 15:00:13 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 naehrwert
|
2020-01-24 10:10:40 +00:00
|
|
|
* Copyright (c) 2018-2020 Atmosphère-NX
|
2018-09-07 15:00:13 +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/>.
|
|
|
|
*/
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2018-08-18 16:59:33 +00:00
|
|
|
#include <stdint.h>
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2018-08-18 16:59:33 +00:00
|
|
|
#include "cluster.h"
|
|
|
|
#include "flow.h"
|
|
|
|
#include "sysreg.h"
|
|
|
|
#include "i2c.h"
|
|
|
|
#include "car.h"
|
2020-12-07 18:39:23 +00:00
|
|
|
#include "fuse.h"
|
2018-11-17 21:50:31 +00:00
|
|
|
#include "mc.h"
|
2018-08-18 16:59:33 +00:00
|
|
|
#include "timers.h"
|
|
|
|
#include "pmc.h"
|
|
|
|
#include "max77620.h"
|
2020-12-07 18:39:23 +00:00
|
|
|
#include "max77812.h"
|
2018-08-18 16:59:33 +00:00
|
|
|
|
2020-12-07 18:39:23 +00:00
|
|
|
/* Determine the current SoC for Mariko specific code. */
|
|
|
|
static bool is_soc_mariko() {
|
|
|
|
return (fuse_get_soc_type() == 1);
|
2018-08-18 16:59:33 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 18:39:23 +00:00
|
|
|
static void cluster_enable_power(uint32_t regulator) {
|
|
|
|
switch (regulator) {
|
|
|
|
case 0: /* Regulator_Max77621 */
|
2021-01-01 01:37:57 +00:00
|
|
|
{
|
|
|
|
uint8_t val = 0;
|
|
|
|
i2c_query(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_AME_GPIO, &val, 1);
|
|
|
|
val &= 0xDF;
|
|
|
|
i2c_send(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_AME_GPIO, &val, 1);
|
|
|
|
val = 0x09;
|
|
|
|
i2c_send(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_GPIO5, &val, 1);
|
|
|
|
val = 0x20;
|
|
|
|
i2c_send(I2C_5, MAX77621_CPU_I2C_ADDR, 0x02, &val, 1);
|
|
|
|
val = 0x8D;
|
|
|
|
i2c_send(I2C_5, MAX77621_CPU_I2C_ADDR, 0x03, &val, 1);
|
|
|
|
val = 0xB7;
|
|
|
|
i2c_send(I2C_5, MAX77621_CPU_I2C_ADDR, 0x00, &val, 1);
|
|
|
|
val = 0xB7;
|
|
|
|
i2c_send(I2C_5, MAX77621_CPU_I2C_ADDR, 0x01, &val, 1);
|
|
|
|
}
|
2020-12-07 18:39:23 +00:00
|
|
|
break;
|
|
|
|
case 1: /* Regulator_Max77812PhaseConfiguration31 */
|
2021-01-01 01:37:57 +00:00
|
|
|
{
|
|
|
|
uint8_t val = 0;
|
|
|
|
i2c_query(I2C_5, MAX77812_PHASE31_CPU_I2C_ADDR, MAX77812_REG_EN_CTRL, &val, 1);
|
|
|
|
if (val) {
|
|
|
|
val |= 0x40;
|
|
|
|
i2c_send(I2C_5, MAX77812_PHASE31_CPU_I2C_ADDR, MAX77812_REG_EN_CTRL, &val, 1);
|
|
|
|
}
|
|
|
|
val = 0x6E;
|
|
|
|
i2c_send(I2C_5, MAX77812_PHASE31_CPU_I2C_ADDR, MAX77812_REG_M4_VOUT, &val, 1);
|
2020-12-07 18:39:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 2: /* Regulator_Max77812PhaseConfiguration211 */
|
2021-01-01 01:37:57 +00:00
|
|
|
{
|
|
|
|
uint8_t val = 0;
|
|
|
|
i2c_query(I2C_5, MAX77812_PHASE211_CPU_I2C_ADDR, MAX77812_REG_EN_CTRL, &val, 1);
|
|
|
|
if (val) {
|
|
|
|
val |= 0x40;
|
|
|
|
i2c_send(I2C_5, MAX77812_PHASE211_CPU_I2C_ADDR, MAX77812_REG_EN_CTRL, &val, 1);
|
|
|
|
}
|
|
|
|
val = 0x6E;
|
|
|
|
i2c_send(I2C_5, MAX77812_PHASE211_CPU_I2C_ADDR, MAX77812_REG_M4_VOUT, &val, 1);
|
2020-12-07 18:39:23 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
default: return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cluster_pmc_enable_partition(uint32_t part, uint32_t toggle) {
|
2018-08-18 16:59:33 +00:00
|
|
|
volatile tegra_pmc_t *pmc = pmc_get_regs();
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2018-08-18 16:59:33 +00:00
|
|
|
/* Check if the partition has already been turned on. */
|
2020-12-07 18:39:23 +00:00
|
|
|
if (pmc->pwrgate_status & part) {
|
|
|
|
return;
|
|
|
|
}
|
2018-08-18 16:59:33 +00:00
|
|
|
|
|
|
|
uint32_t i = 5001;
|
2020-12-07 18:39:23 +00:00
|
|
|
while (pmc->pwrgate_toggle & 0x100) {
|
2018-08-18 16:59:33 +00:00
|
|
|
udelay(1);
|
|
|
|
i--;
|
2020-12-07 18:39:23 +00:00
|
|
|
if (i < 1) {
|
|
|
|
return;
|
|
|
|
}
|
2018-08-18 16:59:33 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 18:39:23 +00:00
|
|
|
/* Turn the partition on. */
|
2018-08-18 16:59:33 +00:00
|
|
|
pmc->pwrgate_toggle = (toggle | 0x100);
|
|
|
|
|
|
|
|
i = 5001;
|
2020-12-07 18:39:23 +00:00
|
|
|
while (i > 0) {
|
|
|
|
/* Check if the partition has already been turned on. */
|
|
|
|
if (pmc->pwrgate_status & part) {
|
2018-08-18 16:59:33 +00:00
|
|
|
break;
|
2020-12-07 18:39:23 +00:00
|
|
|
}
|
2018-08-18 16:59:33 +00:00
|
|
|
udelay(1);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-18 18:54:23 +00:00
|
|
|
void cluster_boot_cpu0(uint32_t entry) {
|
2020-12-07 18:39:23 +00:00
|
|
|
volatile tegra_car_t *car = car_get_regs();
|
2020-12-18 18:54:23 +00:00
|
|
|
bool is_mariko = is_soc_mariko();
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2020-12-07 18:39:23 +00:00
|
|
|
/* Set ACTIVE_CLUSER to FAST. */
|
|
|
|
FLOW_CTLR_BPMP_CLUSTER_CONTROL_0 &= 0xFFFFFFFE;
|
|
|
|
|
|
|
|
/* Enable VddCpu. */
|
2020-12-18 18:54:23 +00:00
|
|
|
cluster_enable_power(is_mariko ? fuse_get_regulator() : 0);
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2020-12-07 18:39:23 +00:00
|
|
|
if (!(car->pllx_base & 0x40000000)) {
|
|
|
|
car->pllx_misc3 &= 0xFFFFFFF7;
|
|
|
|
udelay(2);
|
2020-12-18 18:54:23 +00:00
|
|
|
if (!is_mariko) {
|
|
|
|
car->pllx_base = 0x80404E02;
|
|
|
|
car->pllx_base = 0x404E02;
|
|
|
|
}
|
2020-12-07 18:39:23 +00:00
|
|
|
car->pllx_misc = ((car->pllx_misc & 0xFFFBFFFF) | 0x40000);
|
|
|
|
car->pllx_base = 0x40404E02;
|
|
|
|
}
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2020-12-07 18:39:23 +00:00
|
|
|
while (!(car->pllx_base & 0x8000000)) {
|
|
|
|
/* Wait. */
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set MSELECT clock. */
|
|
|
|
clk_enable(CARDEVICE_MSELECT);
|
|
|
|
|
|
|
|
/* Configure initial CPU clock frequency and enable clock. */
|
|
|
|
car->cclk_brst_pol = 0x20008888;
|
|
|
|
car->super_cclk_div = 0x80000000;
|
|
|
|
car->clk_enb_v_set = 1;
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2020-12-07 18:39:23 +00:00
|
|
|
/* Reboot CORESIGHT. */
|
|
|
|
clkrst_reboot(CARDEVICE_CORESIGHT);
|
|
|
|
|
|
|
|
/* Set CAR2PMC_CPU_ACK_WIDTH to 0. */
|
|
|
|
car->cpu_softrst_ctrl2 &= 0xFFFFF000;
|
|
|
|
|
|
|
|
/* Enable CPU rail. */
|
|
|
|
cluster_pmc_enable_partition(1, 0);
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2020-12-07 18:39:23 +00:00
|
|
|
/* Enable cluster 0 non-CPU. */
|
|
|
|
cluster_pmc_enable_partition(0x8000, 15);
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2020-12-07 18:39:23 +00:00
|
|
|
/* Enable CE0. */
|
|
|
|
cluster_pmc_enable_partition(0x4000, 14);
|
|
|
|
|
|
|
|
/* Request and wait for RAM repair. */
|
|
|
|
FLOW_CTLR_RAM_REPAIR_0 = 1;
|
|
|
|
while (!(FLOW_CTLR_RAM_REPAIR_0 & 2)) {
|
|
|
|
/* Wait. */
|
|
|
|
}
|
|
|
|
|
|
|
|
MAKE_EXCP_VEC_REG(0x100) = 0;
|
|
|
|
|
|
|
|
/* Set reset vector. */
|
|
|
|
SB_AA64_RESET_LOW_0 = (entry | 1);
|
|
|
|
SB_AA64_RESET_HIGH_0 = 0;
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2020-12-07 18:39:23 +00:00
|
|
|
/* Non-secure reset vector write disable. */
|
|
|
|
SB_CSR_0 = 2;
|
|
|
|
(void)SB_CSR_0;
|
|
|
|
|
|
|
|
/* Set CPU_STRICT_TZ_APERTURE_CHECK. */
|
|
|
|
/* NOTE: This breaks Exosphère. */
|
|
|
|
/* MAKE_MC_REG(MC_TZ_SECURITY_CTRL) = 1; */
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2020-12-07 18:39:23 +00:00
|
|
|
/* Clear MSELECT reset. */
|
|
|
|
rst_disable(CARDEVICE_MSELECT);
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2020-12-18 18:54:23 +00:00
|
|
|
if (!is_mariko) {
|
|
|
|
/* Clear NONCPU reset. */
|
|
|
|
car->rst_cpug_cmplx_clr = 0x20000000;
|
2020-12-07 18:39:23 +00:00
|
|
|
}
|
2021-01-01 01:37:57 +00:00
|
|
|
|
2020-12-18 18:54:23 +00:00
|
|
|
/* Clear CPU{0} POR and CORE, CX0, L2, and DBG reset.*/
|
|
|
|
car->rst_cpug_cmplx_clr = 0x41010001;
|
2020-12-07 18:39:23 +00:00
|
|
|
}
|