Add display + touch panel info to HW & Fuses screen

This commit is contained in:
Baptiste MOINE committed 2026-05-03 09:42:42 +02:00
1 parent 91b85f2b57
commit d0f0f67247
4 files changed
+253 -2

No files matched your search

+59 -1
View File
@@ -42,8 +42,11 @@ constexpr uint8_t FTS4_CMD_SYSTEM_RESET = 0xA0;
constexpr uint8_t FTS4_CMD_CLEAR_EVENT_STACK = 0xA1;
constexpr uint8_t FTS4_CMD_HW_REG_READ = 0xB6; // also HW_REG_WRITE
constexpr uint8_t FTS4_CMD_SWITCH_SENSE_MODE = 0xC3;
constexpr uint8_t FTS4_CMD_VENDOR = 0xCF;
constexpr uint8_t FTS4_CMD_FB_REG_READ = 0xD0; // also FB_REG_WRITE
constexpr uint8_t FTS4_VENDOR_GPIO_STATE = 0x01;
// ---- FTS4 HW register addresses (accessed via 0xB6) ----
constexpr uint16_t FTS4_HW_REG_CHIP_ID_INFO_ALT = 0x0002; // returns chip_id at bytes [3..4]
constexpr uint16_t FTS4_HW_REG_CHIP_ID_INFO = 0x0004; // returns chip_id at bytes [1..2]
@@ -59,6 +62,7 @@ constexpr uint8_t FTS4_EV_MULTI_TOUCH_ENTER = 0x03;
constexpr uint8_t FTS4_EV_MULTI_TOUCH_LEAVE = 0x04;
constexpr uint8_t FTS4_EV_MULTI_TOUCH_MOTION = 0x05;
constexpr uint8_t FTS4_EV_CONTROLLER_READY = 0x10;
constexpr uint8_t FTS4_EV_VENDOR = 0x20;
// ---- Tegra I²C packet header flags (mmio.h-style bit positions) ----
constexpr uint32_t I2C_HEADER_CONT_XFER = 1u << 15;
@@ -201,10 +205,64 @@ void execute(EmuState *state, uint32_t expected_rx_size) {
break;
}
case FTS4_CMD_FB_REG_READ: { // 0xD0
// FB read of FW info etc — return zeros, Hekate just memcpys the result.
// touch_get_fw_info() does two reads:
// 1. cmd = {0xD0, 0x00, 0x60}; reads 3 bytes. Hekate then forms the
// next address as cmd[1] = buf[2]; cmd[2] = buf[1]; — i.e. the
// payload of the second read lives at offset (buf[2] << 8) | buf[1].
// We hand back {x, 0x70, 0x00} so the second read targets 0x0070.
// 2. cmd = {0xD0, 0x00, 0x70}; reads 9 bytes. Hekate decodes it as
// fw_id = (buf[1] << 24) | (buf[2] << 16) | (buf[3] << 8) | buf[4]
// ftb_ver = (buf[6] << 8) | buf[5]
// fw_rev = (buf[8] << 8) | buf[7]
if (tx_buf.size() >= 3) {
uint16_t fb_off = ((uint16_t)tx_buf[1] << 8) | tx_buf[2];
if (fb_off == 0x0060) {
rx_buf = {0x00, 0x70, 0x00};
break;
}
if (fb_off == 0x0070) {
uint32_t fw = state->touch_fw_id.load();
uint16_t ftb = state->touch_ftb_ver.load();
uint16_t rev = state->touch_fw_rev.load();
rx_buf = {
0x00,
(uint8_t)((fw >> 24) & 0xFF), (uint8_t)((fw >> 16) & 0xFF),
(uint8_t)((fw >> 8) & 0xFF), (uint8_t)(fw & 0xFF),
(uint8_t)(ftb & 0xFF), (uint8_t)((ftb >> 8) & 0xFF),
(uint8_t)(rev & 0xFF), (uint8_t)((rev >> 8) & 0xFF),
};
break;
}
}
// Anything else: zero-pad to whatever the controller expects.
rx_buf.assign(expected_rx_size ? expected_rx_size : 4, 0);
break;
}
case FTS4_CMD_VENDOR: { // 0xCF
// touch_get_panel_vendor() sends one byte (FTS4_VENDOR_GPIO_STATE) and
// waits for an FTS4_EV_VENDOR event whose status byte matches. The event
// payload (tmp[2..]) carries gpio0/gpio1/gpio2, looked up against the
// _panels[] table in Hekate's bdk/input/touch.c. We mirror that table.
static constexpr uint8_t kPanelGpios[][3] = {
{1, 1, 1}, // 0: NISSHA NFT-K12D
{0, 1, 1}, // 1: GiS GGM6 B2X
{0, 0, 0}, // 2: NISSHA NBF-K9A
{1, 0, 0}, // 3: GiS 5.5"
{0, 0, 1}, // 4: Samsung TSP
{1, 0, 1}, // 5: GiS VA 6.2" (Hekate stores idx=-1 for this row)
};
if (tx_buf.size() >= 2 && tx_buf[1] == FTS4_VENDOR_GPIO_STATE) {
uint8_t idx = state->touch_panel_idx.load();
if (idx >= sizeof(kPanelGpios) / sizeof(kPanelGpios[0])) idx = 0;
std::array<uint8_t, 8> ev = {
FTS4_EV_VENDOR, FTS4_VENDOR_GPIO_STATE,
kPanelGpios[idx][0], kPanelGpios[idx][1], kPanelGpios[idx][2],
0, 0, 0,
};
if (ev_stack.size() < 32) ev_stack.push_back(ev);
}
break;
}
case FTS4_CMD_LATEST_EVENT:
case FTS4_CMD_READ_ONE_EVENT:
case FTS4_CMD_READ_ALL_EVENT: {
+78 -1
View File
@@ -534,6 +534,11 @@ void display_write(EmuState *state, uint64_t addr, uint32_t val) {
// PINMUX read-back cache to satisfy polling
static uint32_t pinmux_reg[0x1000 / 4] = {0};
// Forward decls — these handlers live further down this file but are reached
// from misc_read's catch-all routing for DSI accesses.
uint32_t dsi_read(EmuState *state, uint64_t addr);
void dsi_write(EmuState *state, uint64_t addr, uint32_t val);
uint32_t misc_read(EmuState *state, uint64_t addr) {
if (addr >= PINMUX_BASE && addr < PINMUX_BASE + PINMUX_SIZE) {
return pinmux_reg[(addr - PINMUX_BASE) / 4];
@@ -556,7 +561,7 @@ uint32_t misc_read(EmuState *state, uint64_t addr) {
}
// DSI
if (addr >= DSI_BASE && addr < DSI_BASE + DSI_SIZE) {
return 0;
return dsi_read(state, addr);
}
// MC
if (addr >= MC_BASE && addr < MC_BASE + MC_SIZE) {
@@ -1353,6 +1358,76 @@ void emc_write(EmuState *state, uint64_t addr, uint32_t val) {
}
}
// ==================== DSI (display panel ID over MIPI-DSI) ====================
//
// Hekate's display init calls display_dsi_read(MIPI_DCS_GET_DISPLAY_ID, 3, ...)
// to identify the LCD panel. The read sequence:
// 1. send (cmd << 8) | MIPI_DSI_DCS_READ to DSI_WR_DATA, then write
// DSI_TRIGGER = HOST. We capture the requested DCS reg here.
// 2. write DSI_HOST_CONTROL with bit 3 (IMM_BTA) set, then poll until that
// bit clears. We auto-clear it on the next read and prep an RX FIFO.
// 3. read DSI_STATUS for fifo count, then drain DSI_RD_DATA. We expose
// three words: DSI_ESCAPE_CMD, (3 << 8) | DCS_LONG_RD_RES, panel_id_raw.
//
// On any unrecognized DCS read, _panel_id_raw stays at the 0xCCCCCC sentinel
// Hekate seeds, which renders as "Failed to get info!". Default panel reply
// matches a JDI LAM062M109A (0x099310 -> decoded 0x0910).
static constexpr uint32_t DSI_RD_DATA = 0x9 << 2; // 0x024
static constexpr uint32_t DSI_WR_DATA = 0xA << 2; // 0x028
static constexpr uint32_t DSI_HOST_CONTROL = 0xF << 2; // 0x03C
static constexpr uint32_t DSI_TRIGGER = 0x13 << 2; // 0x04C
static constexpr uint32_t DSI_STATUS = 0x15 << 2; // 0x054
static constexpr uint8_t MIPI_DSI_DCS_READ = 0x06;
static constexpr uint8_t MIPI_DCS_GET_DISPLAY_ID = 0x04;
static constexpr uint8_t DSI_ESCAPE_CMD = 0x87;
static constexpr uint8_t DCS_LONG_RD_RES = 0x1C;
static uint8_t g_dsi_pending_dcs_cmd = 0;
static uint32_t g_dsi_rx_fifo[8] = {0};
static uint32_t g_dsi_rx_count = 0;
static uint32_t g_dsi_rx_pos = 0;
static void dsi_prepare_response(EmuState *state) {
if (g_dsi_pending_dcs_cmd != MIPI_DCS_GET_DISPLAY_ID) {
g_dsi_rx_count = 0;
return;
}
g_dsi_rx_fifo[0] = DSI_ESCAPE_CMD;
g_dsi_rx_fifo[1] = (3u << 8) | DCS_LONG_RD_RES;
g_dsi_rx_fifo[2] = state->panel_id_raw.load() & 0xFFFFFF;
g_dsi_rx_count = 3;
g_dsi_rx_pos = 0;
}
uint32_t dsi_read(EmuState *state, uint64_t addr) {
uint32_t offset = (uint32_t)(addr - DSI_BASE);
switch (offset) {
case DSI_STATUS: {
uint32_t left = (g_dsi_rx_pos < g_dsi_rx_count) ? (g_dsi_rx_count - g_dsi_rx_pos) : 0;
return left & 0x1F; // DSI_STATUS_RX_FIFO_SIZE mask
}
case DSI_RD_DATA:
if (g_dsi_rx_pos < g_dsi_rx_count)
return g_dsi_rx_fifo[g_dsi_rx_pos++];
return 0;
case DSI_HOST_CONTROL: return 0; // IMM_BTA always clear (we ack instantly)
case DSI_TRIGGER: return 0; // trigger always clear
default: return 0;
}
(void)state;
}
void dsi_write(EmuState *state, uint64_t addr, uint32_t val) {
uint32_t offset = (uint32_t)(addr - DSI_BASE);
if (offset == DSI_WR_DATA && (val & 0xFF) == MIPI_DSI_DCS_READ) {
g_dsi_pending_dcs_cmd = (val >> 8) & 0xFF;
} else if (offset == DSI_HOST_CONTROL && (val & (1u << 3))) {
dsi_prepare_response(state);
}
}
// ==================== SE (Security Engine) ====================
// Real AES-128 implementation lives in t210/se_engine.cpp. The functions
// below are thin shims so the existing dispatcher routing keeps working.
@@ -1633,6 +1708,8 @@ static void hook_mmio_write(uc_engine *uc, uc_mem_type type, uint64_t address,
} else if (address >= DISPLAY_A_BASE &&
address < DISPLAY_A_BASE + DISPLAY_SIZE) {
display_write(state, address, val);
} else if (address >= DSI_BASE && address < DSI_BASE + DSI_SIZE) {
dsi_write(state, address, val);
} else if (address >= PMC_BASE && address < PMC_BASE + PMC_SIZE) {
pmc_write(state, address, val);
} else if (address >= 0x60007000 && address < 0x60007000 + 0x1000) {