2018-11-27 09:45:43 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018 naehrwert
|
2024-05-19 07:07:06 +00:00
|
|
|
* Copyright (c) 2018-2024 CTCaer
|
2018-11-27 09:45:43 +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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
|
2020-06-14 13:45:45 +00:00
|
|
|
#include <soc/hw_init.h>
|
2020-12-28 03:19:23 +00:00
|
|
|
#include <display/di.h>
|
2022-10-11 03:41:38 +00:00
|
|
|
#include <display/vic.h>
|
2020-06-14 13:45:45 +00:00
|
|
|
#include <input/joycon.h>
|
|
|
|
#include <input/touch.h>
|
|
|
|
#include <sec/se.h>
|
|
|
|
#include <sec/se_t210.h>
|
|
|
|
#include <soc/bpmp.h>
|
|
|
|
#include <soc/clock.h>
|
|
|
|
#include <soc/fuse.h>
|
|
|
|
#include <soc/gpio.h>
|
|
|
|
#include <soc/i2c.h>
|
|
|
|
#include <soc/pinmux.h>
|
|
|
|
#include <soc/pmc.h>
|
|
|
|
#include <soc/uart.h>
|
2022-06-27 07:22:19 +00:00
|
|
|
#include <soc/timer.h>
|
2020-06-14 13:45:45 +00:00
|
|
|
#include <soc/t210.h>
|
|
|
|
#include <mem/mc.h>
|
|
|
|
#include <mem/minerva.h>
|
|
|
|
#include <mem/sdram.h>
|
|
|
|
#include <power/bq24193.h>
|
|
|
|
#include <power/max77620.h>
|
|
|
|
#include <power/max7762x.h>
|
|
|
|
#include <power/regulator_5v.h>
|
2022-01-15 21:58:27 +00:00
|
|
|
#include <storage/sd.h>
|
2020-06-14 13:45:45 +00:00
|
|
|
#include <storage/sdmmc.h>
|
|
|
|
#include <thermal/fan.h>
|
2021-01-14 15:58:23 +00:00
|
|
|
#include <thermal/tmp451.h>
|
2020-06-14 13:45:45 +00:00
|
|
|
#include <utils/util.h>
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2019-03-07 21:41:07 +00:00
|
|
|
extern boot_cfg_t b_cfg;
|
2020-01-19 13:22:59 +00:00
|
|
|
extern volatile nyx_storage_t *nyx_str;
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2021-10-01 11:32:42 +00:00
|
|
|
u32 hw_rst_status;
|
|
|
|
u32 hw_rst_reason;
|
2019-09-09 13:56:37 +00:00
|
|
|
|
2020-06-26 15:42:31 +00:00
|
|
|
u32 hw_get_chip_id()
|
|
|
|
{
|
|
|
|
if (((APB_MISC(APB_MISC_GP_HIDREV) >> 4) & 0xF) >= GP_HIDREV_MAJOR_T210B01)
|
|
|
|
return GP_HIDREV_MAJOR_T210B01;
|
|
|
|
else
|
|
|
|
return GP_HIDREV_MAJOR_T210;
|
|
|
|
}
|
|
|
|
|
2021-10-01 11:32:42 +00:00
|
|
|
/*
|
|
|
|
* CLK_OSC - 38.4 MHz crystal.
|
|
|
|
* CLK_M - 19.2 MHz (osc/2).
|
|
|
|
* CLK_S - 32.768 KHz (from PMIC).
|
|
|
|
* SCLK - 204MHz init (-> 408MHz -> OC).
|
|
|
|
* HCLK - 204MHz init (-> 408MHz -> OC).
|
|
|
|
* PCLK - 68MHz init (-> 136MHz -> OC/4).
|
|
|
|
*/
|
|
|
|
|
2020-10-20 08:53:28 +00:00
|
|
|
static void _config_oscillators()
|
2018-11-27 09:45:43 +00:00
|
|
|
{
|
2019-09-09 13:56:37 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_SPARE_REG0) = (CLOCK(CLK_RST_CONTROLLER_SPARE_REG0) & 0xFFFFFFF3) | 4; // Set CLK_M_DIVISOR to 2.
|
2022-07-11 19:10:11 +00:00
|
|
|
SYSCTR0(SYSCTR0_CNTFID0) = 19200000; // Set counter frequency.
|
|
|
|
TMR(TIMERUS_USEC_CFG) = 0x45F; // For 19.2MHz clk_m.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_OSC_CTRL) = 0x50000071; // Set OSC to 38.4MHz and drive strength.
|
2019-09-09 13:56:37 +00:00
|
|
|
|
2019-10-18 15:02:06 +00:00
|
|
|
PMC(APBDEV_PMC_OSC_EDPD_OVER) = (PMC(APBDEV_PMC_OSC_EDPD_OVER) & 0xFFFFFF81) | 0xE; // Set LP0 OSC drive strength.
|
2019-09-09 13:56:37 +00:00
|
|
|
PMC(APBDEV_PMC_OSC_EDPD_OVER) = (PMC(APBDEV_PMC_OSC_EDPD_OVER) & 0xFFBFFFFF) | PMC_OSC_EDPD_OVER_OSC_CTRL_OVER;
|
2022-07-11 19:10:11 +00:00
|
|
|
PMC(APBDEV_PMC_CNTRL2) = (PMC(APBDEV_PMC_CNTRL2) & 0xFFFFEFFF) | PMC_CNTRL2_HOLD_CKE_LOW_EN;
|
|
|
|
PMC(APB_MISC_GP_ASDBGREG) = (PMC(APB_MISC_GP_ASDBGREG) & 0xFCFFFFFF) | (2 << 24); // CFG2TMC_RAM_SVOP_PDP.
|
2019-09-09 13:56:37 +00:00
|
|
|
|
2022-07-11 19:10:11 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_SYSTEM_RATE) = 0x10; // Set HCLK div to 2 and PCLK div to 1.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_PLLMB_BASE) &= 0xBFFFFFFF; // PLLMB disable.
|
2019-09-09 13:56:37 +00:00
|
|
|
|
2023-06-09 07:33:11 +00:00
|
|
|
PMC(APBDEV_PMC_TSC_MULT) = (PMC(APBDEV_PMC_TSC_MULT) & 0xFFFF0000) | 0x249F; // 0x249F = 19200000 * (16 / 32.768 kHz).
|
2019-09-09 13:56:37 +00:00
|
|
|
|
2022-07-11 19:10:11 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_SYS) = 0; // Set BPMP/SCLK div to 1.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = 0x20004444; // Set BPMP/SCLK source to Run and PLLP_OUT2 (204MHz).
|
2019-09-09 13:56:37 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_SUPER_SCLK_DIVIDER) = 0x80000000; // Enable SUPER_SDIV to 1.
|
2022-07-11 19:10:11 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_SYSTEM_RATE) = 2; // Set HCLK div to 1 and PCLK div to 3.
|
2018-11-27 09:45:43 +00:00
|
|
|
}
|
|
|
|
|
2024-05-19 07:07:06 +00:00
|
|
|
void hw_config_arbiter(bool reset)
|
|
|
|
{
|
|
|
|
if (reset)
|
|
|
|
{
|
|
|
|
ARB_PRI(ARB_PRIO_CPU_PRIORITY) = 0x0040090;
|
|
|
|
ARB_PRI(ARB_PRIO_COP_PRIORITY) = 0x12024C2;
|
|
|
|
ARB_PRI(ARB_PRIO_VCP_PRIORITY) = 0x2201209;
|
|
|
|
ARB_PRI(ARB_PRIO_DMA_PRIORITY) = 0x320365B;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ARB_PRI(ARB_PRIO_CPU_PRIORITY) = 0x12412D1;
|
|
|
|
ARB_PRI(ARB_PRIO_COP_PRIORITY) = 0x0000000;
|
|
|
|
ARB_PRI(ARB_PRIO_VCP_PRIORITY) = 0x220244A;
|
|
|
|
ARB_PRI(ARB_PRIO_DMA_PRIORITY) = 0x320369B;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-11 06:18:55 +00:00
|
|
|
// The uart is skipped for Copper, Hoag and Calcio. Used in Icosa, Iowa and Aula.
|
2020-06-26 15:42:31 +00:00
|
|
|
static void _config_gpios(bool nx_hoag)
|
2018-11-27 09:45:43 +00:00
|
|
|
{
|
2020-07-17 15:08:27 +00:00
|
|
|
// Clamp inputs when tristated.
|
|
|
|
APB_MISC(APB_MISC_PP_PINMUX_GLOBAL) = 0;
|
|
|
|
|
2020-06-26 15:42:31 +00:00
|
|
|
if (!nx_hoag)
|
|
|
|
{
|
2023-02-11 21:08:32 +00:00
|
|
|
// Turn Joy-Con detect on. (GPIO mode and input logic for UARTB/C TX pins.)
|
2020-06-26 15:42:31 +00:00
|
|
|
PINMUX_AUX(PINMUX_AUX_UART2_TX) = 0;
|
|
|
|
PINMUX_AUX(PINMUX_AUX_UART3_TX) = 0;
|
2023-02-11 21:08:32 +00:00
|
|
|
gpio_direction_input(GPIO_PORT_G, GPIO_PIN_0);
|
|
|
|
gpio_direction_input(GPIO_PORT_D, GPIO_PIN_1);
|
2020-06-26 15:42:31 +00:00
|
|
|
}
|
|
|
|
|
2022-05-13 00:56:59 +00:00
|
|
|
// Set Joy-Con IsAttached pinmux. Shared with UARTB/UARTC TX.
|
2020-06-26 15:42:31 +00:00
|
|
|
PINMUX_AUX(PINMUX_AUX_GPIO_PE6) = PINMUX_INPUT_ENABLE | PINMUX_TRISTATE;
|
|
|
|
PINMUX_AUX(PINMUX_AUX_GPIO_PH6) = PINMUX_INPUT_ENABLE | PINMUX_TRISTATE;
|
|
|
|
|
2023-02-11 21:08:32 +00:00
|
|
|
// Configure Joy-Con IsAttached pins. Shared with UARTB/UARTC TX.
|
|
|
|
gpio_direction_input(GPIO_PORT_E, GPIO_PIN_6);
|
|
|
|
gpio_direction_input(GPIO_PORT_H, GPIO_PIN_6);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
pinmux_config_i2c(I2C_1);
|
|
|
|
pinmux_config_i2c(I2C_5);
|
|
|
|
pinmux_config_uart(UART_A);
|
|
|
|
|
|
|
|
// Configure volume up/down as inputs.
|
2023-02-11 21:08:32 +00:00
|
|
|
gpio_direction_input(GPIO_PORT_X, GPIO_PIN_6 | GPIO_PIN_7);
|
2019-09-09 13:56:37 +00:00
|
|
|
|
2023-02-11 21:08:32 +00:00
|
|
|
// Configure HOME as input. (Shared with UARTB RTS).
|
2022-01-15 23:05:42 +00:00
|
|
|
PINMUX_AUX(PINMUX_AUX_BUTTON_HOME) = PINMUX_INPUT_ENABLE | PINMUX_TRISTATE;
|
2023-02-11 21:08:32 +00:00
|
|
|
gpio_direction_input(GPIO_PORT_Y, GPIO_PIN_1);
|
|
|
|
|
|
|
|
// Power button can be configured for hoag here. Only SKU where it's connected.
|
2018-11-27 09:45:43 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 08:53:28 +00:00
|
|
|
static void _config_pmc_scratch()
|
2018-11-27 09:45:43 +00:00
|
|
|
{
|
2020-07-17 15:08:27 +00:00
|
|
|
PMC(APBDEV_PMC_SCRATCH20) &= 0xFFF3FFFF; // Unset Debug console from Customer Option.
|
2022-10-11 03:16:38 +00:00
|
|
|
PMC(APBDEV_PMC_SCRATCH190) &= 0xFFFFFFFE; // Unset WDT_DURING_BR.
|
2019-09-09 13:56:37 +00:00
|
|
|
PMC(APBDEV_PMC_SECURE_SCRATCH21) |= PMC_FUSE_PRIVATEKEYDISABLE_TZ_STICKY_BIT;
|
2018-11-27 09:45:43 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 08:53:28 +00:00
|
|
|
static void _mbist_workaround()
|
2018-11-27 09:45:43 +00:00
|
|
|
{
|
2020-07-17 13:50:17 +00:00
|
|
|
// Make sure Audio clocks are enabled before accessing I2S.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_V) |= BIT(CLK_V_AHUB);
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_Y) |= BIT(CLK_Y_APE);
|
2019-02-23 22:59:33 +00:00
|
|
|
|
2019-09-12 20:11:17 +00:00
|
|
|
// Set mux output to SOR1 clock switch.
|
2018-11-27 09:45:43 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_SOR1) = (CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_SOR1) | 0x8000) & 0xFFFFBFFF;
|
2019-09-12 20:11:17 +00:00
|
|
|
// Enabled PLLD and set csi to PLLD for test pattern generation.
|
2019-09-09 13:56:37 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_PLLD_BASE) |= 0x40800000;
|
2019-09-12 20:11:17 +00:00
|
|
|
|
2020-07-17 13:50:17 +00:00
|
|
|
// Clear per-clock resets for APE/VIC/HOST1X/DISP1.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_RST_DEV_Y_CLR) = BIT(CLK_Y_APE);
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_RST_DEV_X_CLR) = BIT(CLK_X_VIC);
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_CLR) = BIT(CLK_L_HOST1X) | BIT(CLK_L_DISP1);
|
2018-11-27 09:45:43 +00:00
|
|
|
usleep(2);
|
|
|
|
|
2019-09-12 20:11:17 +00:00
|
|
|
// I2S channels to master and disable SLCG.
|
2018-11-27 09:45:43 +00:00
|
|
|
I2S(I2S1_CTRL) |= I2S_CTRL_MASTER_EN;
|
|
|
|
I2S(I2S1_CG) &= ~I2S_CG_SLCG_ENABLE;
|
|
|
|
I2S(I2S2_CTRL) |= I2S_CTRL_MASTER_EN;
|
|
|
|
I2S(I2S2_CG) &= ~I2S_CG_SLCG_ENABLE;
|
|
|
|
I2S(I2S3_CTRL) |= I2S_CTRL_MASTER_EN;
|
|
|
|
I2S(I2S3_CG) &= ~I2S_CG_SLCG_ENABLE;
|
|
|
|
I2S(I2S4_CTRL) |= I2S_CTRL_MASTER_EN;
|
|
|
|
I2S(I2S4_CG) &= ~I2S_CG_SLCG_ENABLE;
|
|
|
|
I2S(I2S5_CTRL) |= I2S_CTRL_MASTER_EN;
|
|
|
|
I2S(I2S5_CG) &= ~I2S_CG_SLCG_ENABLE;
|
2019-09-12 20:11:17 +00:00
|
|
|
|
2022-10-11 03:41:38 +00:00
|
|
|
// Set SLCG overrides.
|
2019-09-09 13:56:37 +00:00
|
|
|
DISPLAY_A(_DIREG(DC_COM_DSC_TOP_CTL)) |= 4; // DSC_SLCG_OVERRIDE.
|
2022-10-11 03:41:38 +00:00
|
|
|
VIC(VIC_THI_SLCG_OVERRIDE_LOW_A) = 0xFFFFFFFF;
|
2018-11-27 09:45:43 +00:00
|
|
|
usleep(2);
|
|
|
|
|
2020-07-17 13:50:17 +00:00
|
|
|
// Set per-clock reset for APE/VIC/HOST1X/DISP1.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_RST_DEV_Y_SET) = BIT(CLK_Y_APE);
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_RST_DEV_L_SET) = BIT(CLK_L_HOST1X) | BIT(CLK_L_DISP1);
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_RST_DEV_X_SET) = BIT(CLK_X_VIC);
|
2019-09-12 20:11:17 +00:00
|
|
|
|
|
|
|
// Enable specific clocks and disable all others.
|
2020-07-17 13:50:17 +00:00
|
|
|
// CLK L Devices.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_H) =
|
|
|
|
BIT(CLK_H_PMC) |
|
|
|
|
BIT(CLK_H_FUSE);
|
|
|
|
// CLK H Devices.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_L) =
|
|
|
|
BIT(CLK_L_RTC) |
|
|
|
|
BIT(CLK_L_TMR) |
|
|
|
|
BIT(CLK_L_GPIO) |
|
|
|
|
BIT(CLK_L_BPMP_CACHE_CTRL);
|
|
|
|
// CLK U Devices.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_U) =
|
|
|
|
BIT(CLK_U_CSITE) |
|
|
|
|
BIT(CLK_U_IRAMA) |
|
|
|
|
BIT(CLK_U_IRAMB) |
|
|
|
|
BIT(CLK_U_IRAMC) |
|
|
|
|
BIT(CLK_U_IRAMD) |
|
|
|
|
BIT(CLK_U_BPMP_CACHE_RAM);
|
|
|
|
// CLK V Devices.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_V) =
|
|
|
|
BIT(CLK_V_MSELECT) |
|
|
|
|
BIT(CLK_V_APB2APE) |
|
|
|
|
BIT(CLK_V_SPDIF_DOUBLER) |
|
|
|
|
BIT(CLK_V_SE);
|
|
|
|
// CLK W Devices.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_W) =
|
|
|
|
BIT(CLK_W_PCIERX0) |
|
|
|
|
BIT(CLK_W_PCIERX1) |
|
|
|
|
BIT(CLK_W_PCIERX2) |
|
|
|
|
BIT(CLK_W_PCIERX3) |
|
|
|
|
BIT(CLK_W_PCIERX4) |
|
|
|
|
BIT(CLK_W_PCIERX5) |
|
|
|
|
BIT(CLK_W_ENTROPY) |
|
|
|
|
BIT(CLK_W_MC1);
|
|
|
|
// CLK X Devices.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_X) =
|
|
|
|
BIT(CLK_X_MC_CAPA) |
|
|
|
|
BIT(CLK_X_MC_CBPA) |
|
|
|
|
BIT(CLK_X_MC_CPU) |
|
|
|
|
BIT(CLK_X_MC_BBC) |
|
|
|
|
BIT(CLK_X_GPU) |
|
|
|
|
BIT(CLK_X_DBGAPB) |
|
|
|
|
BIT(CLK_X_PLLG_REF);
|
|
|
|
// CLK Y Devices.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_Y) =
|
|
|
|
BIT(CLK_Y_MC_CDPA) |
|
|
|
|
BIT(CLK_Y_MC_CCPA);
|
2019-09-12 20:11:17 +00:00
|
|
|
|
|
|
|
// Disable clock gate overrides.
|
2018-11-27 09:45:43 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRA) = 0;
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRB) = 0;
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRC) = 0;
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRD) = 0;
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_LVL2_CLK_GATE_OVRE) = 0;
|
2019-09-12 20:11:17 +00:00
|
|
|
|
|
|
|
// Set child clock sources.
|
2020-07-17 15:08:27 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_PLLD_BASE) &= 0x1F7FFFFF; // Disable PLLD and set reference clock and csi clock.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_SOR1) &= 0xFFFF3FFF; // Set SOR1 to automatic muxing of safe clock (24MHz) or SOR1 clk switch.
|
2022-07-11 19:10:11 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_VI) = (CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_VI) & 0x1FFFFFFF) | 0x80000000; // Set clock source to PLLP_OUT.
|
2019-09-12 20:11:17 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_HOST1X) = (CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_HOST1X) & 0x1FFFFFFF) | 0x80000000; // Set clock source to PLLP_OUT.
|
2022-07-11 19:10:11 +00:00
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_NVENC) = (CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_NVENC) & 0x1FFFFFFF) | 0x80000000; // Set clock source to PLLP_OUT.
|
2018-11-27 09:45:43 +00:00
|
|
|
}
|
|
|
|
|
2020-10-20 08:53:28 +00:00
|
|
|
static void _config_se_brom()
|
2018-11-27 09:45:43 +00:00
|
|
|
{
|
2021-08-28 13:46:15 +00:00
|
|
|
// Enable Fuse visibility.
|
2020-03-21 20:13:18 +00:00
|
|
|
clock_enable_fuse(true);
|
|
|
|
|
2021-08-28 13:46:15 +00:00
|
|
|
// Try to set SBK from fuses. If patched, skip.
|
|
|
|
fuse_set_sbk();
|
|
|
|
|
|
|
|
// Lock SSK (although it's not set and unused anyways).
|
|
|
|
// se_key_acc_ctrl(15, SE_KEY_TBL_DIS_KEYREAD_FLAG);
|
2018-11-27 09:45:43 +00:00
|
|
|
|
|
|
|
// This memset needs to happen here, else TZRAM will behave weirdly later on.
|
2022-10-11 03:16:38 +00:00
|
|
|
memset((void *)TZRAM_BASE, 0, TZRAM_SIZE);
|
2019-03-07 22:19:04 +00:00
|
|
|
PMC(APBDEV_PMC_CRYPTO_OP) = PMC_CRYPTO_OP_SE_ENABLE;
|
2023-03-31 06:11:55 +00:00
|
|
|
|
|
|
|
// Clear SE interrupts.
|
|
|
|
SE(SE_INT_STATUS_REG) = SE_INT_OP_DONE | SE_INT_OUT_DONE | SE_INT_OUT_LL_BUF_WR | SE_INT_IN_DONE | SE_INT_IN_LL_BUF_RD;
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2021-10-01 11:32:42 +00:00
|
|
|
// Save reset reason.
|
|
|
|
hw_rst_status = PMC(APBDEV_PMC_SCRATCH200);
|
|
|
|
hw_rst_reason = PMC(APBDEV_PMC_RST_STATUS) & PMC_RST_STATUS_MASK;
|
|
|
|
|
|
|
|
// Clear the boot reason to avoid problems later.
|
2023-03-31 06:11:55 +00:00
|
|
|
PMC(APBDEV_PMC_SCRATCH200) = 0;
|
|
|
|
PMC(APBDEV_PMC_RST_STATUS) = PMC_RST_STATUS_POR;
|
2018-11-28 19:26:16 +00:00
|
|
|
APB_MISC(APB_MISC_PP_STRAPPING_OPT_A) = (APB_MISC(APB_MISC_PP_STRAPPING_OPT_A) & 0xF0) | (7 << 10);
|
2018-11-27 09:45:43 +00:00
|
|
|
}
|
|
|
|
|
2024-06-04 22:35:05 +00:00
|
|
|
static void _config_regulators(bool tegra_t210, bool nx_hoag)
|
2018-11-27 09:45:43 +00:00
|
|
|
{
|
2020-12-11 15:25:59 +00:00
|
|
|
// Set RTC/AO domain to POR voltage.
|
|
|
|
if (tegra_t210)
|
2021-01-04 00:41:15 +00:00
|
|
|
max7762x_regulator_set_voltage(REGULATOR_LDO4, 1000000);
|
2020-12-11 15:25:59 +00:00
|
|
|
|
2020-04-06 02:54:45 +00:00
|
|
|
// Disable low battery shutdown monitor.
|
|
|
|
max77620_low_battery_monitor_config(false);
|
|
|
|
|
2024-07-02 14:56:20 +00:00
|
|
|
// Power on all relevant rails in case we came out of warmboot. Only keep MEM/MEM_COMP and SDMMC1 states.
|
|
|
|
PMC(APBDEV_PMC_NO_IOPOWER) &= PMC_NO_IOPOWER_MEM_COMP | PMC_NO_IOPOWER_SDMMC1 | PMC_NO_IOPOWER_MEM;
|
|
|
|
|
2024-06-08 09:21:15 +00:00
|
|
|
// Make sure SDMMC1 IO/Core are powered off.
|
2021-01-04 00:41:15 +00:00
|
|
|
max7762x_regulator_enable(REGULATOR_LDO2, false);
|
2023-12-25 02:07:26 +00:00
|
|
|
gpio_write(GPIO_PORT_E, GPIO_PIN_4, GPIO_LOW);
|
2024-07-02 14:56:20 +00:00
|
|
|
PMC(APBDEV_PMC_NO_IOPOWER) |= PMC_NO_IOPOWER_SDMMC1;
|
|
|
|
(void)PMC(APBDEV_PMC_NO_IOPOWER);
|
2020-03-21 20:13:18 +00:00
|
|
|
sd_power_cycle_time_start = get_tmr_ms();
|
|
|
|
|
2024-06-08 09:21:15 +00:00
|
|
|
// Disable backup battery charger.
|
2019-02-15 23:23:14 +00:00
|
|
|
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_CNFGBBC, MAX77620_CNFGBBC_RESISTOR_1K);
|
2024-06-08 09:21:15 +00:00
|
|
|
|
|
|
|
// Set PWR delay for forced shutdown off to 6s.
|
|
|
|
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, MAX77620_ONOFFCNFG1_RSVD | (3 << MAX77620_ONOFFCNFG1_MRT_SHIFT));
|
2019-02-23 22:59:33 +00:00
|
|
|
|
2020-06-26 15:42:31 +00:00
|
|
|
if (tegra_t210)
|
|
|
|
{
|
|
|
|
// Configure all Flexible Power Sequencers for MAX77620.
|
2024-06-08 09:21:15 +00:00
|
|
|
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_FPS_CFG0, (7 << MAX77620_FPS_TIME_PERIOD_SHIFT) | (0 << MAX77620_FPS_EN_SRC_SHIFT));
|
2020-06-26 15:42:31 +00:00
|
|
|
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_FPS_CFG1, (7 << MAX77620_FPS_TIME_PERIOD_SHIFT) | (1 << MAX77620_FPS_EN_SRC_SHIFT));
|
|
|
|
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_FPS_CFG2, (7 << MAX77620_FPS_TIME_PERIOD_SHIFT));
|
|
|
|
max77620_regulator_config_fps(REGULATOR_LDO4);
|
|
|
|
max77620_regulator_config_fps(REGULATOR_LDO8);
|
|
|
|
max77620_regulator_config_fps(REGULATOR_SD0);
|
|
|
|
max77620_regulator_config_fps(REGULATOR_SD1);
|
|
|
|
max77620_regulator_config_fps(REGULATOR_SD3);
|
|
|
|
|
2024-06-08 09:21:15 +00:00
|
|
|
// Set GPIO3 to FPS0 for SYS 3V3 EN. Enabled when FPS0 is enabled.
|
|
|
|
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_FPS_GPIO3, (4 << MAX77620_FPS_PU_PERIOD_SHIFT) | (2 << MAX77620_FPS_PD_PERIOD_SHIFT));
|
2020-06-26 15:42:31 +00:00
|
|
|
|
|
|
|
// Set vdd_core voltage to 1.125V.
|
2021-01-04 00:41:15 +00:00
|
|
|
max7762x_regulator_set_voltage(REGULATOR_SD0, 1125000);
|
|
|
|
|
2024-06-08 09:21:15 +00:00
|
|
|
// Power down CPU/GPU regulators after L4T warmboot.
|
2021-01-04 00:41:15 +00:00
|
|
|
max77620_config_gpio(5, MAX77620_GPIO_OUTPUT_DISABLE);
|
|
|
|
max77620_config_gpio(6, MAX77620_GPIO_OUTPUT_DISABLE);
|
|
|
|
|
|
|
|
// Set POR configuration.
|
|
|
|
max77621_config_default(REGULATOR_CPU0, MAX77621_CTRL_POR_CFG);
|
|
|
|
max77621_config_default(REGULATOR_GPU0, MAX77621_CTRL_POR_CFG);
|
2020-06-26 15:42:31 +00:00
|
|
|
}
|
2024-06-04 22:33:15 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// Tegra X1+ set vdd_core voltage to 1.05V.
|
2021-01-04 00:41:15 +00:00
|
|
|
max7762x_regulator_set_voltage(REGULATOR_SD0, 1050000);
|
2024-06-04 22:33:15 +00:00
|
|
|
|
|
|
|
// Power on SD2 regulator for supplying LDO0/1/8.
|
|
|
|
max7762x_regulator_set_voltage(REGULATOR_SD2, 1325000);
|
|
|
|
|
|
|
|
// Set slew rate and enable SD2 regulator.
|
|
|
|
i2c_send_byte(I2C_5, MAX77620_I2C_ADDR, MAX77620_REG_SD2_CFG, (1 << MAX77620_SD_SR_SHIFT) |
|
|
|
|
(MAX77620_POWER_MODE_NORMAL << MAX77620_SD_POWER_MODE_SHIFT) |
|
|
|
|
MAX77620_SD_CFG1_FSRADE_SD_ENABLE);
|
2024-06-04 22:35:05 +00:00
|
|
|
|
|
|
|
// Enable LDO8 on HOAG as it also powers I2C1 IO pads.
|
|
|
|
if (nx_hoag)
|
|
|
|
{
|
|
|
|
max7762x_regulator_set_voltage(REGULATOR_LDO8, 2800000);
|
|
|
|
max7762x_regulator_enable(REGULATOR_LDO8, true);
|
|
|
|
}
|
2024-06-04 22:33:15 +00:00
|
|
|
}
|
2019-09-12 20:11:17 +00:00
|
|
|
}
|
|
|
|
|
2020-07-17 15:08:27 +00:00
|
|
|
void hw_init()
|
2019-09-12 20:11:17 +00:00
|
|
|
{
|
2023-02-11 21:08:32 +00:00
|
|
|
// Get Chip ID and SKU.
|
2020-06-26 15:42:31 +00:00
|
|
|
bool tegra_t210 = hw_get_chip_id() == GP_HIDREV_MAJOR_T210;
|
|
|
|
bool nx_hoag = fuse_read_hw_type() == FUSE_NX_HW_TYPE_HOAG;
|
|
|
|
|
2019-09-12 20:11:17 +00:00
|
|
|
// Bootrom stuff we skipped by going through rcm.
|
|
|
|
_config_se_brom();
|
|
|
|
//FUSE(FUSE_PRIVATEKEYDISABLE) = 0x11;
|
2023-06-09 07:33:11 +00:00
|
|
|
|
|
|
|
// Unset APB2JTAG_OVERRIDE_EN and OBS_OVERRIDE_EN.
|
|
|
|
SYSREG(AHB_AHB_SPARE_REG) &= 0xFFFFFF9F;
|
|
|
|
PMC(APBDEV_PMC_SCRATCH49) &= 0xFFFFFFFC;
|
2019-09-12 20:11:17 +00:00
|
|
|
|
2020-07-17 15:08:27 +00:00
|
|
|
// Perform Memory Built-In Self Test WAR if T210.
|
2020-06-26 15:42:31 +00:00
|
|
|
if (tegra_t210)
|
|
|
|
_mbist_workaround();
|
2020-07-17 15:08:27 +00:00
|
|
|
|
2024-07-02 14:59:14 +00:00
|
|
|
// Make sure PLLP_OUT3/4 is set to 408 MHz and enabled.
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_PLLP_OUTB) = 0x30003;
|
|
|
|
|
2020-07-17 15:08:27 +00:00
|
|
|
// Enable Security Engine clock.
|
2019-09-12 20:11:17 +00:00
|
|
|
clock_enable_se();
|
|
|
|
|
2021-08-28 13:46:15 +00:00
|
|
|
// Enable Fuse visibility.
|
2019-09-12 20:11:17 +00:00
|
|
|
clock_enable_fuse(true);
|
2019-12-04 19:31:39 +00:00
|
|
|
|
2020-07-17 15:08:27 +00:00
|
|
|
// Disable Fuse programming.
|
2019-09-12 20:11:17 +00:00
|
|
|
fuse_disable_program();
|
|
|
|
|
2020-07-17 15:08:27 +00:00
|
|
|
// Enable clocks to Memory controllers and disable AHB redirect.
|
2019-09-12 20:11:17 +00:00
|
|
|
mc_enable();
|
|
|
|
|
2020-07-17 15:08:27 +00:00
|
|
|
// Initialize counters, CLKM, BPMP and other clocks based on 38.4MHz oscillator.
|
2019-09-12 20:11:17 +00:00
|
|
|
_config_oscillators();
|
2020-07-17 15:08:27 +00:00
|
|
|
|
|
|
|
// Initialize pin configuration.
|
2020-06-26 15:42:31 +00:00
|
|
|
_config_gpios(nx_hoag);
|
2019-09-12 20:11:17 +00:00
|
|
|
|
2023-10-12 03:59:15 +00:00
|
|
|
// Enable CL-DVFS clock unconditionally to avoid issues with I2C5 sharing.
|
2019-09-12 20:11:17 +00:00
|
|
|
clock_enable_cl_dvfs();
|
|
|
|
|
2020-07-17 15:08:27 +00:00
|
|
|
// Enable clocks to I2C1 and I2CPWR.
|
2019-09-12 20:11:17 +00:00
|
|
|
clock_enable_i2c(I2C_1);
|
|
|
|
clock_enable_i2c(I2C_5);
|
|
|
|
|
2020-07-17 15:08:27 +00:00
|
|
|
// Enable clock to TZRAM.
|
2019-09-12 20:11:17 +00:00
|
|
|
clock_enable_tzram();
|
|
|
|
|
2020-06-26 15:42:31 +00:00
|
|
|
// Initialize I2C5, mandatory for PMIC.
|
2019-09-12 20:11:17 +00:00
|
|
|
i2c_init(I2C_5);
|
|
|
|
|
2024-06-04 22:35:05 +00:00
|
|
|
// Initialize various regulators based on Erista/Mariko platform.
|
|
|
|
_config_regulators(tegra_t210, nx_hoag);
|
2020-06-26 15:42:31 +00:00
|
|
|
|
|
|
|
// Initialize I2C1 for various power related devices.
|
|
|
|
i2c_init(I2C_1);
|
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
_config_pmc_scratch(); // Missing from 4.x+
|
|
|
|
|
2020-07-17 15:08:27 +00:00
|
|
|
// Set BPMP/SCLK to PLLP_OUT (408MHz).
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = 0x20003333;
|
|
|
|
|
2022-01-20 10:13:35 +00:00
|
|
|
// Power on T210B01 shadow TZRAM and lock the reg.
|
2020-06-26 15:42:31 +00:00
|
|
|
if (!tegra_t210)
|
|
|
|
{
|
2022-07-11 19:10:11 +00:00
|
|
|
PMC(APBDEV_PMC_TZRAM_PWR_CNTRL) &= ~PMC_TZRAM_PWR_CNTRL_SD;
|
2022-01-20 10:13:35 +00:00
|
|
|
PMC(APBDEV_PMC_TZRAM_NON_SEC_DISABLE) = PMC_TZRAM_DISABLE_REG_WRITE | PMC_TZRAM_DISABLE_REG_READ;
|
2022-07-11 19:10:11 +00:00
|
|
|
PMC(APBDEV_PMC_TZRAM_SEC_DISABLE) = PMC_TZRAM_DISABLE_REG_WRITE | PMC_TZRAM_DISABLE_REG_READ;
|
2020-06-26 15:42:31 +00:00
|
|
|
}
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2024-05-19 07:07:06 +00:00
|
|
|
// Set arbiter.
|
|
|
|
hw_config_arbiter(false);
|
|
|
|
|
2020-07-17 15:08:27 +00:00
|
|
|
// Initialize External memory controller and configure DRAM parameters.
|
2018-11-27 09:45:43 +00:00
|
|
|
sdram_init();
|
2019-06-30 00:55:19 +00:00
|
|
|
|
|
|
|
bpmp_mmu_enable();
|
2022-12-19 03:14:39 +00:00
|
|
|
|
|
|
|
// Enable HOST1X used by every display module (DC, VIC, NVDEC, NVENC, TSEC, etc).
|
|
|
|
clock_enable_host1x();
|
2024-06-02 04:44:22 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_UART_PORT
|
|
|
|
// Setup debug uart port.
|
|
|
|
#if (DEBUG_UART_PORT == UART_B)
|
|
|
|
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO);
|
|
|
|
#elif (DEBUG_UART_PORT == UART_C)
|
|
|
|
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_SPIO);
|
|
|
|
#endif
|
|
|
|
pinmux_config_uart(DEBUG_UART_PORT);
|
|
|
|
clock_enable_uart(DEBUG_UART_PORT);
|
|
|
|
uart_init(DEBUG_UART_PORT, DEBUG_UART_BAUDRATE, UART_AO_TX_AO_RX);
|
|
|
|
uart_invert(DEBUG_UART_PORT, DEBUG_UART_INVERT, UART_INVERT_TXD);
|
|
|
|
#endif
|
2018-11-27 09:45:43 +00:00
|
|
|
}
|
|
|
|
|
2024-05-19 07:49:25 +00:00
|
|
|
void hw_deinit(bool coreboot, u32 bl_magic)
|
2018-11-27 09:45:43 +00:00
|
|
|
{
|
2023-02-11 21:13:41 +00:00
|
|
|
bool tegra_t210 = hw_get_chip_id() == GP_HIDREV_MAJOR_T210;
|
2020-06-13 15:16:29 +00:00
|
|
|
|
2023-02-22 12:48:43 +00:00
|
|
|
// Scale down BPMP clock.
|
|
|
|
bpmp_clk_rate_set(BPMP_CLK_NORMAL);
|
|
|
|
|
2022-01-20 11:19:48 +00:00
|
|
|
#ifdef BDK_HW_EXTRA_DEINIT
|
2022-10-11 03:41:38 +00:00
|
|
|
// Disable temperature sensor, touchscreen, 5V regulators, Joy-Con and VIC.
|
|
|
|
vic_end();
|
2021-01-14 15:58:23 +00:00
|
|
|
tmp451_end();
|
2024-06-07 14:14:05 +00:00
|
|
|
fan_set_duty(0);
|
2021-01-14 15:58:23 +00:00
|
|
|
touch_power_off();
|
2020-06-13 15:16:29 +00:00
|
|
|
jc_deinit();
|
2021-01-11 19:30:59 +00:00
|
|
|
regulator_5v_disable(REGULATOR_5V_ALL);
|
2020-06-13 15:16:29 +00:00
|
|
|
#endif
|
|
|
|
|
2023-02-11 21:13:41 +00:00
|
|
|
// set DRAM clock to 204MHz.
|
2019-06-30 00:49:33 +00:00
|
|
|
minerva_change_freq(FREQ_204);
|
2020-01-14 21:41:15 +00:00
|
|
|
nyx_str->mtc_cfg.init_done = 0;
|
2019-06-30 00:49:33 +00:00
|
|
|
|
2023-02-22 12:48:43 +00:00
|
|
|
// Flush/disable MMU cache.
|
2023-02-11 21:13:41 +00:00
|
|
|
bpmp_mmu_disable();
|
|
|
|
|
2024-05-19 07:07:06 +00:00
|
|
|
// Reset arbiter.
|
|
|
|
hw_config_arbiter(true);
|
|
|
|
|
2018-11-27 09:45:43 +00:00
|
|
|
// Re-enable clocks to Audio Processing Engine as a workaround to hanging.
|
2023-02-11 21:13:41 +00:00
|
|
|
if (tegra_t210)
|
|
|
|
{
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_V) |= BIT(CLK_V_AHUB);
|
|
|
|
CLOCK(CLK_RST_CONTROLLER_CLK_OUT_ENB_Y) |= BIT(CLK_Y_APE);
|
|
|
|
}
|
2018-11-27 09:45:43 +00:00
|
|
|
|
2021-01-04 17:03:50 +00:00
|
|
|
// Do coreboot mitigations.
|
|
|
|
if (coreboot)
|
2018-11-27 09:45:43 +00:00
|
|
|
{
|
|
|
|
msleep(10);
|
|
|
|
|
|
|
|
clock_disable_cl_dvfs();
|
|
|
|
|
2023-02-11 21:08:32 +00:00
|
|
|
// Disable Joy-con detect in order to restore UART TX.
|
2018-11-27 09:45:43 +00:00
|
|
|
gpio_config(GPIO_PORT_G, GPIO_PIN_0, GPIO_MODE_SPIO);
|
|
|
|
gpio_config(GPIO_PORT_D, GPIO_PIN_1, GPIO_MODE_SPIO);
|
2021-01-04 17:03:50 +00:00
|
|
|
|
|
|
|
// Reinstate SD controller power.
|
2024-06-08 09:16:07 +00:00
|
|
|
PMC(APBDEV_PMC_NO_IOPOWER) &= ~PMC_NO_IOPOWER_SDMMC1;
|
2018-11-27 09:45:43 +00:00
|
|
|
}
|
|
|
|
|
2021-04-11 06:18:55 +00:00
|
|
|
// Seamless display or display power off.
|
|
|
|
switch (bl_magic)
|
|
|
|
{
|
|
|
|
case BL_MAGIC_CRBOOT_SLD:;
|
|
|
|
// Set pwm to 0%, switch to gpio mode and restore pwm duty.
|
|
|
|
u32 brightness = display_get_backlight_brightness();
|
|
|
|
display_backlight_brightness(0, 1000);
|
|
|
|
gpio_config(GPIO_PORT_V, GPIO_PIN_0, GPIO_MODE_GPIO);
|
|
|
|
display_backlight_brightness(brightness, 0);
|
|
|
|
break;
|
2022-12-19 03:22:55 +00:00
|
|
|
case BL_MAGIC_L4TLDR_SLD:
|
2023-02-11 21:13:41 +00:00
|
|
|
// Do not disable display or backlight at all.
|
2022-12-19 03:22:55 +00:00
|
|
|
break;
|
2021-04-11 06:18:55 +00:00
|
|
|
default:
|
|
|
|
display_end();
|
2022-12-19 03:14:39 +00:00
|
|
|
clock_disable_host1x();
|
2021-04-11 06:18:55 +00:00
|
|
|
}
|
2018-12-07 20:00:19 +00:00
|
|
|
}
|