diff --git a/fusee/fusee-primary/src/hwinit.c b/fusee/fusee-primary/src/hwinit.c index adc701ce4..ea156cc02 100644 --- a/fusee/fusee-primary/src/hwinit.c +++ b/fusee/fusee-primary/src/hwinit.c @@ -34,8 +34,7 @@ #include "timers.h" #include "uart.h" -void config_oscillators() -{ +static void config_oscillators(void) { volatile tegra_car_t *car = car_get_regs(); volatile tegra_pmc_t *pmc = pmc_get_regs(); @@ -57,8 +56,7 @@ void config_oscillators() car->clk_sys_rate = 2; } -void config_gpios() -{ +static void config_gpios_erista(void) { volatile tegra_pinmux_t *pinmux = pinmux_get_regs(); pinmux->uart2_tx = 0; @@ -79,15 +77,50 @@ void config_gpios() i2c_config(I2C_5); uart_config(UART_A); - /* Configure volume up/down as inputs. */ + /* Configure volume up/down buttons as inputs. */ gpio_configure_mode(GPIO_BUTTON_VOL_UP, GPIO_MODE_GPIO); gpio_configure_mode(GPIO_BUTTON_VOL_DOWN, GPIO_MODE_GPIO); gpio_configure_direction(GPIO_BUTTON_VOL_UP, GPIO_DIRECTION_INPUT); gpio_configure_direction(GPIO_BUTTON_VOL_DOWN, GPIO_DIRECTION_INPUT); } -void config_pmc_scratch() -{ +static void config_gpios_mariko(void) { + volatile tegra_pinmux_t *pinmux = pinmux_get_regs(); + uint32_t hardware_type = fuse_get_hardware_type(); + + /* Only for HardwareType_Iowa and HardwareType_Five. */ + if ((hardware_type == 3) || (hardware_type == 5)) { + pinmux->uart2_tx = 0; + pinmux->uart3_tx = 0; + gpio_configure_mode(TEGRA_GPIO(G, 0), GPIO_MODE_GPIO); + gpio_configure_mode(TEGRA_GPIO(D, 1), GPIO_MODE_GPIO); + gpio_configure_direction(TEGRA_GPIO(G, 0), GPIO_DIRECTION_INPUT); + gpio_configure_direction(TEGRA_GPIO(D, 1), GPIO_DIRECTION_INPUT); + } + + pinmux->pe6 = PINMUX_INPUT; + pinmux->ph6 = PINMUX_INPUT; + gpio_configure_mode(TEGRA_GPIO(E, 6), GPIO_MODE_GPIO); + gpio_configure_mode(TEGRA_GPIO(H, 6), GPIO_MODE_GPIO); + gpio_configure_direction(TEGRA_GPIO(E, 6), GPIO_DIRECTION_INPUT); + gpio_configure_direction(TEGRA_GPIO(H, 6), GPIO_DIRECTION_INPUT); + + i2c_config(I2C_1); + i2c_config(I2C_5); + uart_config(UART_A); + + /* Configure volume up/down buttons as inputs. */ + gpio_configure_mode(GPIO_BUTTON_VOL_UP, GPIO_MODE_GPIO); + gpio_configure_mode(GPIO_BUTTON_VOL_DOWN, GPIO_MODE_GPIO); + gpio_configure_direction(GPIO_BUTTON_VOL_UP, GPIO_DIRECTION_INPUT); + gpio_configure_direction(GPIO_BUTTON_VOL_DOWN, GPIO_DIRECTION_INPUT); + + /* Configure home button as input. */ + gpio_configure_mode(TEGRA_GPIO(Y, 1), GPIO_MODE_GPIO); + gpio_configure_direction(TEGRA_GPIO(Y, 1), GPIO_DIRECTION_INPUT); +} + +static void config_pmc_scratch(void) { volatile tegra_pmc_t *pmc = pmc_get_regs(); pmc->scratch20 &= 0xFFF3FFFF; @@ -95,8 +128,7 @@ void config_pmc_scratch() pmc->secure_scratch21 |= 0x10; } -void mbist_workaround() -{ +static void mbist_workaround(void) { volatile tegra_car_t *car = car_get_regs(); car->clk_source_sor1 = ((car->clk_source_sor1 | 0x8000) & 0xFFFFBFFF); @@ -151,8 +183,7 @@ void mbist_workaround() car->clk_source_nvenc = ((car->clk_source_nvenc & 0x1FFFFFFF) | 0x80000000); } -void config_se_brom() -{ +static void config_se_brom(void) { volatile tegra_fuse_chip_common_t *fuse_chip = fuse_chip_common_get_regs(); volatile tegra_se_t *se = se_get_regs(); volatile tegra_pmc_t *pmc = pmc_get_regs(); @@ -178,8 +209,7 @@ void config_se_brom() pmc->reset_status = 0; } -void nx_hwinit() -{ +void nx_hwinit_erista(bool enable_log) { volatile tegra_pmc_t *pmc = pmc_get_regs(); volatile tegra_car_t *car = car_get_regs(); @@ -210,13 +240,13 @@ void nx_hwinit() /* Configure GPIOs. */ /* NOTE: [3.0.0+] Part of the GPIO configuration is skipped if the unit is SDEV. */ /* NOTE: [6.0.0+] The GPIO configuration's order was changed a bit. */ - config_gpios(); + config_gpios_erista(); - /* Uncomment for UART debugging. */ - /* - clkrst_reboot(CARDEVICE_UARTC); - uart_init(UART_C, 115200); - */ + /* UART debugging. */ + if (enable_log) { + clkrst_reboot(CARDEVICE_UARTA); + uart_init(UART_A, 115200); + } /* Reboot CL-DVFS. */ clkrst_reboot(CARDEVICE_CL_DVFS); @@ -294,4 +324,74 @@ void nx_hwinit() /* Save SDRAM LP0 parameters. */ sdram_lp0_save_params(sdram_get_params()); +} + +void nx_hwinit_mariko(bool enable_log) { + volatile tegra_car_t *car = car_get_regs(); + + /* Enable SE clock. */ + clkrst_reboot(CARDEVICE_SE); + + /* Initialize the fuse driver. */ + fuse_init(); + + /* Initialize the memory controller. */ + mc_enable(); + + /* Configure oscillators. */ + config_oscillators(); + + /* Disable pinmux tristate input clamping. */ + APB_MISC_PP_PINMUX_GLOBAL_0 = 0; + + /* Configure GPIOs. */ + config_gpios_mariko(); + + /* UART debugging. */ + if (enable_log) { + clkrst_reboot(CARDEVICE_UARTA); + uart_init(UART_A, 115200); + } + + /* Enable CL-DVFS clock. */ + clkrst_reboot(CARDEVICE_CL_DVFS); + + /* Enable I2C1 clock. */ + clkrst_reboot(CARDEVICE_I2C1); + + /* Enable I2C5 clock. */ + clkrst_reboot(CARDEVICE_I2C5); + + /* Enable TZRAM clock. */ + clkrst_reboot(CARDEVICE_TZRAM); + + /* Initialize I2C5. */ + i2c_init(I2C_5); + + /* Configure the PMIC. */ + uint8_t val = 0x40; + i2c_send(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_CNFGBBC, &val, 1); + val = 0x78; + i2c_send(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_ONOFFCNFG1, &val, 1); + + /* Configure SD0 voltage. */ + val = 0x24; + i2c_send(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_SD0, &val, 1); + + /* Enable LDO8 in HardwareType_Hoag only. */ + if (fuse_get_hardware_type() == 2) { + val = 0xE8; + i2c_send(I2C_5, MAX77620_PWR_I2C_ADDR, MAX77620_REG_LDO8_CFG, &val, 1); + } + + /* Initialize I2C1. */ + i2c_init(I2C_1); + + /* Set super clock burst policy. */ + car->sclk_brst_pol = ((car->sclk_brst_pol & 0xFFFF8888) | 0x3333); + + /* Mariko only PMC configuration. */ + MAKE_PMC_REG(0xBE8) &= 0xFFFFFFFE; + MAKE_PMC_REG(0xBF0) = 0x3; + MAKE_PMC_REG(0xBEC) = 0x3; } \ No newline at end of file diff --git a/fusee/fusee-primary/src/hwinit.h b/fusee/fusee-primary/src/hwinit.h index a165346e8..f14638eb0 100644 --- a/fusee/fusee-primary/src/hwinit.h +++ b/fusee/fusee-primary/src/hwinit.h @@ -19,9 +19,12 @@ #ifndef FUSEE_HWINIT_H_ #define FUSEE_HWINIT_H_ +#include + #define I2S_BASE 0x702D1000 #define MAKE_I2S_REG(n) MAKE_REG32(I2S_BASE + n) -void nx_hwinit(); +void nx_hwinit_mariko(bool enable_log); +void nx_hwinit_erista(bool enable_log); #endif diff --git a/fusee/fusee-primary/src/main.c b/fusee/fusee-primary/src/main.c index adfaa5310..f908a8578 100644 --- a/fusee/fusee-primary/src/main.c +++ b/fusee/fusee-primary/src/main.c @@ -17,6 +17,7 @@ #include "utils.h" #include "exception_handlers.h" #include "panic.h" +#include "fuse.h" #include "hwinit.h" #include "di.h" #include "timers.h" @@ -118,7 +119,11 @@ static void cleanup_display(void) { static void setup_env(void) { /* Initialize hardware. */ - nx_hwinit(); + if (fuse_get_soc_type() == 1) { + nx_hwinit_mariko(false); + } else { + nx_hwinit_erista(false); + } /* Set up the exception handlers. */ setup_exception_handlers();