hw init: Cosmetic refactoring

This commit is contained in:
CTCaer 2020-07-17 18:08:27 +03:00
parent 638a3909c5
commit 32e58d2bb3
9 changed files with 46 additions and 29 deletions

View file

@ -73,14 +73,17 @@ void _config_oscillators()
PMC(APBDEV_PMC_TSC_MULT) = (PMC(APBDEV_PMC_TSC_MULT) & 0xFFFF0000) | 0x249F; //0x249F = 19200000 * (16 / 32.768 kHz) PMC(APBDEV_PMC_TSC_MULT) = (PMC(APBDEV_PMC_TSC_MULT) & 0xFFFF0000) | 0x249F; //0x249F = 19200000 * (16 / 32.768 kHz)
CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_SYS) = 0; // Set SCLK div to 1. CLOCK(CLK_RST_CONTROLLER_CLK_SOURCE_SYS) = 0; // Set BPMP/SCLK div to 1.
CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = 0x20004444; // Set clk source to Run and PLLP_OUT2 (204MHz). CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = 0x20004444; // Set BPMP/SCLK source to Run and PLLP_OUT2 (204MHz).
CLOCK(CLK_RST_CONTROLLER_SUPER_SCLK_DIVIDER) = 0x80000000; // Enable SUPER_SDIV to 1. CLOCK(CLK_RST_CONTROLLER_SUPER_SCLK_DIVIDER) = 0x80000000; // Enable SUPER_SDIV to 1.
CLOCK(CLK_RST_CONTROLLER_CLK_SYSTEM_RATE) = 2; // Set HCLK div to 1 and PCLK div to 3. CLOCK(CLK_RST_CONTROLLER_CLK_SYSTEM_RATE) = 2; // Set HCLK div to 1 and PCLK div to 3.
} }
void _config_gpios() void _config_gpios()
{ {
// Clamp inputs when tristated.
APB_MISC(APB_MISC_PP_PINMUX_GLOBAL) = 0;
PINMUX_AUX(PINMUX_AUX_UART2_TX) = 0; PINMUX_AUX(PINMUX_AUX_UART2_TX) = 0;
PINMUX_AUX(PINMUX_AUX_UART3_TX) = 0; PINMUX_AUX(PINMUX_AUX_UART3_TX) = 0;
@ -317,7 +320,7 @@ void _config_regulators()
MAX77621_CKKADV_TRIP_150mV_PER_US | MAX77621_INDUCTOR_NOMINAL); MAX77621_CKKADV_TRIP_150mV_PER_US | MAX77621_INDUCTOR_NOMINAL);
} }
void config_hw() void hw_init()
{ {
// Bootrom stuff we skipped by going through rcm. // Bootrom stuff we skipped by going through rcm.
_config_se_brom(); _config_se_brom();
@ -325,19 +328,25 @@ void config_hw()
SYSREG(AHB_AHB_SPARE_REG) &= 0xFFFFFF9F; // Unset APB2JTAG_OVERRIDE_EN and OBS_OVERRIDE_EN. SYSREG(AHB_AHB_SPARE_REG) &= 0xFFFFFF9F; // Unset APB2JTAG_OVERRIDE_EN and OBS_OVERRIDE_EN.
PMC(APBDEV_PMC_SCRATCH49) = PMC(APBDEV_PMC_SCRATCH49) & 0xFFFFFFFC; PMC(APBDEV_PMC_SCRATCH49) = PMC(APBDEV_PMC_SCRATCH49) & 0xFFFFFFFC;
// Perform Memory Built-In Self Test WAR if T210.
_mbist_workaround(); _mbist_workaround();
// Enable Security Engine clock.
clock_enable_se(); clock_enable_se();
// Enable fuse clock. // Enable Fuse clock.
clock_enable_fuse(true); clock_enable_fuse(true);
// Disable fuse programming. // Disable Fuse programming.
fuse_disable_program(); fuse_disable_program();
// Enable clocks to Memory controllers and disable AHB redirect.
mc_enable(); mc_enable();
// Initialize counters, CLKM, BPMP and other clocks based on 38.4MHz oscillator.
_config_oscillators(); _config_oscillators();
APB_MISC(APB_MISC_PP_PINMUX_GLOBAL) = 0;
// Initialize pin configuration.
_config_gpios(); _config_gpios();
#ifdef DEBUG_UART_PORT #ifdef DEBUG_UART_PORT
@ -345,34 +354,42 @@ void config_hw()
uart_init(DEBUG_UART_PORT, 115200); uart_init(DEBUG_UART_PORT, 115200);
#endif #endif
// Enable Dynamic Voltage and Frequency Scaling device clock.
clock_enable_cl_dvfs(); clock_enable_cl_dvfs();
// Enable clocks to I2C1 and I2CPWR.
clock_enable_i2c(I2C_1); clock_enable_i2c(I2C_1);
clock_enable_i2c(I2C_5); clock_enable_i2c(I2C_5);
// Enable clock to TZRAM.
clock_enable_tzram(); clock_enable_tzram();
// Initialize I2C5, mandatory for PMIC comms.
i2c_init(I2C_1); i2c_init(I2C_1);
i2c_init(I2C_5); i2c_init(I2C_5);
// Enable charger in case it's disabled. // Enable charger in case it's disabled.
bq24193_enable_charger(); bq24193_enable_charger();
// Initialize various regulators based on Erista/Mariko platform.
_config_regulators(); _config_regulators();
_config_pmc_scratch(); // Missing from 4.x+ _config_pmc_scratch(); // Missing from 4.x+
CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = 0x20003333; // Set SCLK to PLLP_OUT (408MHz). // Set BPMP/SCLK to PLLP_OUT (408MHz).
CLOCK(CLK_RST_CONTROLLER_SCLK_BURST_POLICY) = 0x20003333;
// Initialize External memory controller and configure DRAM parameters.
sdram_init(); sdram_init();
bpmp_mmu_enable(); bpmp_mmu_enable();
// Clear flags from PMC_SCRATCH0 // L4T: Clear flags from PMC_SCRATCH0.
PMC(APBDEV_PMC_SCRATCH0) &= ~PMC_SCRATCH0_MODE_PAYLOAD; PMC(APBDEV_PMC_SCRATCH0) &= ~PMC_SCRATCH0_MODE_PAYLOAD;
} }
void reconfig_hw_workaround(bool extra_reconfig, u32 magic) void hw_reinit_workaround(bool extra_reconfig, u32 magic)
{ {
// Disable BPMP max clock. // Disable BPMP max clock.
bpmp_clk_rate_set(BPMP_CLK_NORMAL); bpmp_clk_rate_set(BPMP_CLK_NORMAL);

View file

@ -20,7 +20,7 @@
#include <utils/types.h> #include <utils/types.h>
void config_hw(); void hw_init();
void reconfig_hw_workaround(bool extra_reconfig, u32 magic); void hw_reinit_workaround(bool extra_reconfig, u32 magic);
#endif #endif

View file

@ -135,7 +135,7 @@ void panic(u32 val)
void reboot_normal() void reboot_normal()
{ {
sd_end(); sd_end();
reconfig_hw_workaround(false, 0); hw_reinit_workaround(false, 0);
panic(0x21); // Bypass fuse programming in package1. panic(0x21); // Bypass fuse programming in package1.
} }
@ -143,7 +143,7 @@ void reboot_normal()
void reboot_rcm() void reboot_rcm()
{ {
sd_end(); sd_end();
reconfig_hw_workaround(false, 0); hw_reinit_workaround(false, 0);
PMC(APBDEV_PMC_SCRATCH0) = PMC_SCRATCH0_MODE_RCM; PMC(APBDEV_PMC_SCRATCH0) = PMC_SCRATCH0_MODE_RCM;
PMC(APBDEV_PMC_CNTRL) |= PMC_CNTRL_MAIN_RST; PMC(APBDEV_PMC_CNTRL) |= PMC_CNTRL_MAIN_RST;
@ -155,7 +155,7 @@ void reboot_rcm()
void power_off() void power_off()
{ {
sd_end(); sd_end();
reconfig_hw_workaround(false, 0); hw_reinit_workaround(false, 0);
// Stop the alarm, in case we injected and powered off too fast. // Stop the alarm, in case we injected and powered off too fast.
max77620_rtc_stop_alarm(); max77620_rtc_stop_alarm();

View file

@ -243,7 +243,7 @@ int reboot_to_sept(const u8 *tsec_fw, u32 kb, ini_sec_t *cfg_sec)
PMC(APBDEV_PMC_SCRATCH33) = SEPT_PRI_ADDR; PMC(APBDEV_PMC_SCRATCH33) = SEPT_PRI_ADDR;
PMC(APBDEV_PMC_SCRATCH40) = 0x6000F208; PMC(APBDEV_PMC_SCRATCH40) = 0x6000F208;
reconfig_hw_workaround(false, 0); hw_reinit_workaround(false, 0);
(*sept)(); (*sept)();

View file

@ -255,12 +255,12 @@ int launch_payload(char *path, bool update)
else else
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, ALIGN(size, 0x10)); reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, ALIGN(size, 0x10));
reconfig_hw_workaround(false, byte_swap_32(*(u32 *)(buf + size - sizeof(u32)))); hw_reinit_workaround(false, byte_swap_32(*(u32 *)(buf + size - sizeof(u32))));
} }
else else
{ {
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, 0x7000); reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, 0x7000);
reconfig_hw_workaround(true, 0); hw_reinit_workaround(true, 0);
} }
// Some cards (Sandisk U1), do not like a fast power cycle. Wait min 100ms. // Some cards (Sandisk U1), do not like a fast power cycle. Wait min 100ms.
@ -1459,7 +1459,7 @@ extern void pivot_stack(u32 stack_top);
void ipl_main() void ipl_main()
{ {
// Do initial HW configuration. This is compatible with consecutive reruns without a reset. // Do initial HW configuration. This is compatible with consecutive reruns without a reset.
config_hw(); hw_init();
// Pivot the stack so we have enough space. // Pivot the stack so we have enough space.
pivot_stack(IPL_STACK_TOP); pivot_stack(IPL_STACK_TOP);

View file

@ -862,7 +862,7 @@ static void _launch_hos(u8 autoboot, u8 autoboot_list)
sd_end(); sd_end();
reconfig_hw_workaround(false, 0); hw_reinit_workaround(false, 0);
// Mitigate L4T Joy-Con driver issue. // Mitigate L4T Joy-Con driver issue.
if ((autoboot & 0x80) && h_cfg.bootwait < 2) if ((autoboot & 0x80) && h_cfg.bootwait < 2)
@ -882,7 +882,7 @@ void reload_nyx()
sd_end(); sd_end();
reconfig_hw_workaround(false, 0); hw_reinit_workaround(false, 0);
// Some cards (Sandisk U1), do not like a fast power cycle. Wait min 100ms. // Some cards (Sandisk U1), do not like a fast power cycle. Wait min 100ms.
sdmmc_storage_init_wait_sd(); sdmmc_storage_init_wait_sd();

View file

@ -867,7 +867,7 @@ static lv_res_t _action_reboot_twrp(lv_obj_t * btns, const char * txt)
sd_end(); sd_end();
reconfig_hw_workaround(false, 0); hw_reinit_workaround(false, 0);
(*main_ptr)(); (*main_ptr)();
} }

View file

@ -226,7 +226,7 @@ int reboot_to_sept(const u8 *tsec_fw, u32 kb)
PMC(APBDEV_PMC_SCRATCH33) = SEPT_PRI_ADDR; PMC(APBDEV_PMC_SCRATCH33) = SEPT_PRI_ADDR;
PMC(APBDEV_PMC_SCRATCH40) = 0x6000F208; PMC(APBDEV_PMC_SCRATCH40) = 0x6000F208;
reconfig_hw_workaround(false, 0); hw_reinit_workaround(false, 0);
(*sept)(); (*sept)();

View file

@ -185,12 +185,12 @@ lv_res_t launch_payload(lv_obj_t *list)
if (size < 0x30000) if (size < 0x30000)
{ {
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, ALIGN(size, 0x10)); reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, ALIGN(size, 0x10));
reconfig_hw_workaround(false, byte_swap_32(*(u32 *)(buf + size - sizeof(u32)))); hw_reinit_workaround(false, byte_swap_32(*(u32 *)(buf + size - sizeof(u32))));
} }
else else
{ {
reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, 0x7000); reloc_patcher(PATCHED_RELOC_ENTRY, EXT_PAYLOAD_ADDR, 0x7000);
reconfig_hw_workaround(true, 0); hw_reinit_workaround(true, 0);
} }
void (*ext_payload_ptr)() = (void *)EXT_PAYLOAD_ADDR; void (*ext_payload_ptr)() = (void *)EXT_PAYLOAD_ADDR;