Add TI charger stuff to warmboot_main, add 4.x hw_type stuff as well

This commit is contained in:
TuxSH 2018-03-04 14:04:49 +01:00
parent ca80408349
commit 3e128a8b3e
4 changed files with 34 additions and 13 deletions

View file

@ -34,19 +34,19 @@ void clk_enable(car_device_t dev) {
if ((special_reg = get_special_clk_reg(dev))) { if ((special_reg = get_special_clk_reg(dev))) {
MAKE_CAR_REG(special_reg) = get_special_clk_val(dev); MAKE_CAR_REG(special_reg) = get_special_clk_val(dev);
} }
MAKE_CAR_REG(g_clk_reg_offsets[dev >> 5]) |= BIT((dev & 0x1F)); MAKE_CAR_REG(g_clk_reg_offsets[dev >> 5]) |= BIT(dev & 0x1F);
} }
void clk_disable(car_device_t dev) { void clk_disable(car_device_t dev) {
MAKE_CAR_REG(g_clk_reg_offsets[dev >> 5] + 0x004) |= BIT((dev & 0x1F)); MAKE_CAR_REG(g_clk_reg_offsets[dev >> 5] + 0x004) |= BIT(dev & 0x1F);
} }
void rst_enable(car_device_t dev) { void rst_enable(car_device_t dev) {
MAKE_CAR_REG(g_rst_reg_offsets[dev >> 5]) |= BIT((dev & 0x1F)); MAKE_CAR_REG(g_rst_reg_offsets[dev >> 5]) |= BIT(dev & 0x1F);
} }
void rst_disable(car_device_t dev) { void rst_disable(car_device_t dev) {
MAKE_CAR_REG(g_rst_reg_offsets[dev >> 5] + 0x004) |= BIT((dev & 0x1F)); MAKE_CAR_REG(g_rst_reg_offsets[dev >> 5] + 0x004) |= BIT(dev & 0x1F);
} }

View file

@ -5,6 +5,7 @@
#include "utils.h" #include "utils.h"
#include "timers.h" #include "timers.h"
#include "masterkey.h"
/* Prototypes for internal commands. */ /* Prototypes for internal commands. */
void fuse_make_regs_visible(void); void fuse_make_regs_visible(void);
@ -178,18 +179,23 @@ uint32_t fuse_get_dram_id(void) {
/* Derive the Hardware Type using values in the shadow cache */ /* Derive the Hardware Type using values in the shadow cache */
uint32_t fuse_get_hardware_type(void) { uint32_t fuse_get_hardware_type(void) {
/* This function is very different between 4.x and < 4.x */
uint32_t hardware_type = ((FUSE_CHIP_REGS->FUSE_RESERVED_ODM[4] >> 7) & 2) | ((FUSE_CHIP_REGS->FUSE_RESERVED_ODM[4] >> 2) & 1); uint32_t hardware_type = ((FUSE_CHIP_REGS->FUSE_RESERVED_ODM[4] >> 7) & 2) | ((FUSE_CHIP_REGS->FUSE_RESERVED_ODM[4] >> 2) & 1);
if (hardware_type) {
if (hardware_type == 1) { if (mkey_get_revision() >= MASTERKEY_REVISION_400_CURRENT) {
static const uint32_t types[] = {0,1,4,3};
hardware_type |= ((FUSE_CHIP_REGS->FUSE_RESERVED_ODM[4] >> 14) & 0x3C) - 1;
return hardware_type > 3 ? 4 : types[hardware_type];
} else {
if (hardware_type >= 1) {
return hardware_type > 2 ? 3 : hardware_type - 1;
} else if ((FUSE_CHIP_REGS->FUSE_SPARE_BIT[9] & 1) == 0) {
return 0; return 0;
} else {
return 3;
} }
if (hardware_type == 2) {
return 1;
}
} else if ((FUSE_CHIP_REGS->FUSE_SPARE_BIT[9] & 1) == 0) {
return 0;
} }
return 3;
} }
/* Derive the Retail Type using values in the shadow cache */ /* Derive the Retail Type using values in the shadow cache */

View file

@ -16,4 +16,7 @@
#define APB_MISC_SECURE_REGS_APB_SLAVE_SECURITY_ENABLE_REG1_0 MAKE_MISC_REG(0x0C04) #define APB_MISC_SECURE_REGS_APB_SLAVE_SECURITY_ENABLE_REG1_0 MAKE_MISC_REG(0x0C04)
#define APB_MISC_SECURE_REGS_APB_SLAVE_SECURITY_ENABLE_REG2_0 MAKE_MISC_REG(0x0C08) #define APB_MISC_SECURE_REGS_APB_SLAVE_SECURITY_ENABLE_REG2_0 MAKE_MISC_REG(0x0C08)
#define PINMUX_AUX_GEN1_I2C_SCL_0 MAKE_MISC_REG(0x30BC)
#define PINMUX_AUX_GEN1_I2C_SDA_0 MAKE_MISC_REG(0x30C0)
#endif #endif

View file

@ -10,6 +10,9 @@
#include "se.h" #include "se.h"
#include "mc.h" #include "mc.h"
#include "car.h"
#include "i2c.h"
#include "misc.h"
#include "interrupt.h" #include "interrupt.h"
void __attribute__((noreturn)) warmboot_main(void) { void __attribute__((noreturn)) warmboot_main(void) {
@ -42,7 +45,16 @@ void __attribute__((noreturn)) warmboot_main(void) {
/* Make PMC (2.x+), MC (4.x+) registers secure-only */ /* Make PMC (2.x+), MC (4.x+) registers secure-only */
secure_additional_devices(); secure_additional_devices();
/* TODO: car+clkreset stuff, some other mmio (?) */ if (mkey_get_revision() < MASTERKEY_REVISION_400_CURRENT || configitem_get_hardware_type() == 0) {
/* Enable input to I2C1 */
PINMUX_AUX_GEN1_I2C_SCL_0 = 0x40;
PINMUX_AUX_GEN1_I2C_SDA_0 = 0x40;
clkrst_enable(CARDEVICE_I2C1);
i2c_init(0);
i2c_clear_ti_charger_bit_7();
clkrst_disable(CARDEVICE_I2C1);
}
if (mkey_get_revision() >= MASTERKEY_REVISION_400_CURRENT) { if (mkey_get_revision() >= MASTERKEY_REVISION_400_CURRENT) {
setup_4x_mmio(); /* TODO */ setup_4x_mmio(); /* TODO */