From 3e128a8b3e690170d131f4dc77fecc6be044479e Mon Sep 17 00:00:00 2001 From: TuxSH Date: Sun, 4 Mar 2018 14:04:49 +0100 Subject: [PATCH] Add TI charger stuff to warmboot_main, add 4.x hw_type stuff as well --- exosphere/src/car.c | 8 ++++---- exosphere/src/fuse.c | 22 ++++++++++++++-------- exosphere/src/misc.h | 3 +++ exosphere/src/warmboot_main.c | 14 +++++++++++++- 4 files changed, 34 insertions(+), 13 deletions(-) diff --git a/exosphere/src/car.c b/exosphere/src/car.c index 689f2d888..a9e69e72b 100644 --- a/exosphere/src/car.c +++ b/exosphere/src/car.c @@ -34,19 +34,19 @@ void clk_enable(car_device_t dev) { if ((special_reg = get_special_clk_reg(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) { - 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) { - 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) { - 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); } diff --git a/exosphere/src/fuse.c b/exosphere/src/fuse.c index a88b13490..e3cf5ba74 100644 --- a/exosphere/src/fuse.c +++ b/exosphere/src/fuse.c @@ -5,6 +5,7 @@ #include "utils.h" #include "timers.h" +#include "masterkey.h" /* Prototypes for internal commands. */ 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 */ 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); - 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; + } 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 */ diff --git a/exosphere/src/misc.h b/exosphere/src/misc.h index de19c152b..08950aeb7 100644 --- a/exosphere/src/misc.h +++ b/exosphere/src/misc.h @@ -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_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 diff --git a/exosphere/src/warmboot_main.c b/exosphere/src/warmboot_main.c index d21b0cd9e..1b3a3ea72 100644 --- a/exosphere/src/warmboot_main.c +++ b/exosphere/src/warmboot_main.c @@ -10,6 +10,9 @@ #include "se.h" #include "mc.h" +#include "car.h" +#include "i2c.h" +#include "misc.h" #include "interrupt.h" 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 */ 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) { setup_4x_mmio(); /* TODO */