From 84e6555de7c0fc6b8029250b017e113a15493cb5 Mon Sep 17 00:00:00 2001 From: AI Dev Date: Thu, 3 Dec 2026 13:44:37 +0000 Subject: [PATCH 1/2] sensors: name a GC4653 on Hi3516CV610 without wedging it A Vatilon H80 (Hi3516CV613, GC4653 at 0x52) comes up on OpenIPC with no video: ipcinfo --short-sensor finds nothing, dmesg fills with bsp-i2c "wait idle abort", and load_hisilicon gives up on an unknown sensor (OpenIPC/firmware#3071). Setting sensor=gc4653 by hand makes it stream. #271 found the cause and left it for later: on this SoC a one-byte register address followed by a repeated start wedges a GC4653, which takes two-byte addresses, until the sensor is reset. The GalaxyCore probe reads its byte-address ID that way first (since #238, to spare an SP2305), and 0x52 is visited by no other probe, so the sensor is always wedged before the two-byte read that would name it. On HISI_OT the byte-address read is now a one-byte write ending in a stop and a separate read -- the two transfers #271 showed the GC4653 survives, and the two-phase write and read of SCCB that GalaxyCore parts take. A part with one-byte addresses is still named before any two-byte address reaches it. Other chips keep the single transfer. sensors_test models the wedge: without this change it reports the GC4653 lost and the bus wedged; with it, GC4653 at two-byte width, GC2063 at one, and the golden fingerprint unchanged. --- src/sensors.c | 25 +++++++++++- src/sensors_test.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 121 insertions(+), 2 deletions(-) diff --git a/src/sensors.c b/src/sensors.c index a620b99..06244e9 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -18,6 +18,7 @@ #include "chipid.h" #include "cjson/cJSON.h" #include "hal/common.h" +#include "hal/hisi/hal_hisi.h" #include "hal/xm.h" #include "ipchw.h" #include "sensors.h" @@ -927,12 +928,32 @@ static int detect_omni_sensor(sensor_ctx_t *ctx, int fd, return true; } +/* The Hi3516CV610 back-end reads a register as one transfer: the address, + * then a repeated start. A GC4653 takes two-byte addresses, and one byte + * followed by a repeated start wedges it -- every later transfer on the bus + * fails until the sensor is reset (#271, isolated there one transfer at a + * time). It sits at 0x52, which only this probe visits, so on those boards + * detection found nothing and the camera came up without video + * (OpenIPC/firmware#3071). The same #271 measurements showed that a one-byte + * write ending in a stop and a read on its own both leave it answering, so + * there the byte-address read is those two transfers. That is the two-phase + * write and read of SCCB, which GalaxyCore parts take. Replaceable so that + * sensors_test can watch it. */ +static read_register_t galaxycore_split_read = universal_i2c_read_register; + +static int galaxycore_narrow_read(int fd, unsigned char i2c_addr, + unsigned int reg) { + if (chip_generation == HISI_OT) + return galaxycore_split_read(fd, i2c_addr, reg, 1, 1); + return i2c_read_register(fd, i2c_addr, reg, 1, 1); +} + /* A GalaxyCore ID read a byte-address at a time, 0 when it is not one. */ static int galaxycore_narrow_id(int fd, unsigned char i2c_addr) { - int prod_msb = i2c_read_register(fd, i2c_addr, 0xf0, 1, 1); + int prod_msb = galaxycore_narrow_read(fd, i2c_addr, 0xf0); if (prod_msb == -1) return 0; - int prod_lsb = i2c_read_register(fd, i2c_addr, 0xf1, 1, 1); + int prod_lsb = galaxycore_narrow_read(fd, i2c_addr, 0xf1); if (prod_lsb == -1) return 0; return prod_msb << 8 | prod_lsb; diff --git a/src/sensors_test.c b/src/sensors_test.c index 6a7315f..958a78a 100644 --- a/src/sensors_test.c +++ b/src/sensors_test.c @@ -121,6 +121,10 @@ static int mock_change_addr(int fd, unsigned char addr) { static const char *mock_vendor = "HiSilicon"; const char *getchipvendor() { return mock_vendor; } const char *getchipname() { return "mock"; } +/* chipid.c defines it, and is left out for the reason above. 0 is no + * generation in particular, so every probe takes its common path unless a + * check sets one. */ +int chip_generation; /* ---- one scenario per identification path ------------------------------ */ @@ -483,6 +487,99 @@ static void check_galaxycore_reg_width(void) { } } +/* ---- a GC4653 on a Hi3516CV610 ---------------------------------------- */ + +/* On that SoC the register read is one transfer, the address and then a + * repeated start, and a one-byte address sent that way to a GC4653 wedges it: + * nothing on the bus answers again until the sensor is reset. The byte-address + * ID has to reach it as a write ending in a stop and a separate read, which it + * survives, and the two-byte ID then names it. A part with one-byte addresses, + * the GC2063 of the same boards, is still named without a two-byte address + * reaching it -- the SP2305 check below is the reason that matters. */ +static bool ot_gc_wide; /* the part takes two-byte addresses */ +static bool ot_gc_wedged; +static int ot_gc_wide_reads; +static int ot_gc_split_reads; + +static int ot_gc_read(int fd, unsigned char addr, uint32_t reg, + unsigned int reg_width, unsigned int data_width) { + (void)fd; + (void)data_width; + if (addr != mock_addr || ot_gc_wedged) + return -1; + if (reg_width == 2) + ot_gc_wide_reads++; + if (ot_gc_wide) { + if (reg_width == 1) { + ot_gc_wedged = true; + return -1; + } + return reg == 0x3f0 ? 0x46 : reg == 0x3f1 ? 0x53 : 0x00; + } + if (reg_width == 2) + return 0x00; /* a write to registers 0x03 and 0x04, as far as it knows */ + return reg == 0xf0 ? 0x20 : reg == 0xf1 ? 0x63 : 0x00; +} + +/* What the separate write and read return: a GC4653 was left with half an + * address, and answers with whatever its pointer holds. */ +static int ot_gc_split(int fd, unsigned char addr, uint32_t reg, + unsigned int reg_width, unsigned int data_width) { + (void)fd; + (void)reg_width; + (void)data_width; + if (addr != mock_addr || ot_gc_wedged) + return -1; + ot_gc_split_reads++; + if (ot_gc_wide) + return 0x00; + return reg == 0xf0 ? 0x20 : reg == 0xf1 ? 0x63 : 0x00; +} + +static void check_galaxycore_on_cv610(void) { + static const struct { + int generation; + bool wide; + const char *want; + unsigned int want_width; + bool split; + } cases[] = { + {HISI_OT, true, "GC4653", 2, true}, + {HISI_OT, false, "GC2063", 1, true}, + /* Elsewhere the read stays one transfer: the wedge is the part's + * answer to this SoC's back-end, and nothing says other buses want + * anything different. */ + {HISI_V4, false, "GC2063", 1, false}, + }; + sensor_ctx_t ctx; + + i2c_read_register = ot_gc_read; + galaxycore_split_read = ot_gc_split; + for (size_t i = 0; i < ARRCNT(cases); i++) { + chip_generation = cases[i].generation; + ot_gc_wide = cases[i].wide; + ot_gc_wedged = false; + ot_gc_wide_reads = ot_gc_split_reads = 0; + memset(&ctx, 0, sizeof(ctx)); + + bool found = detect_galaxycore_sensor(&ctx, 0, mock_addr); + CHECK(found); + CHECK(!strcmp(ctx.sensor_id, cases[i].want)); + CHECK(ctx.reg_width == cases[i].want_width); + CHECK(!ot_gc_wedged); + CHECK((ot_gc_split_reads > 0) == cases[i].split); + if (!cases[i].wide) + CHECK(ot_gc_wide_reads == 0); + if (!found || strcmp(ctx.sensor_id, cases[i].want) || ot_gc_wedged) + fprintf(stderr, " (%s on %#x: got \"%s\", %s)\n", + cases[i].want, cases[i].generation, ctx.sensor_id, + ot_gc_wedged ? "bus wedged" : "bus fine"); + } + chip_generation = 0; + galaxycore_split_read = universal_i2c_read_register; + i2c_read_register = mock_read; +} + /* The two IDs SmartSens gives to different parts depending on the SoC. */ static void check_vendor_dependent(void) { static const struct { @@ -924,6 +1021,7 @@ int main(int argc, char **argv) { check_vendor_dependent(); check_smartsens_variants(); check_galaxycore_reg_width(); + check_galaxycore_on_cv610(); check_probe_restores_console(); check_superpix_spared_by_galaxycore(); check_sensor_ports(); From 0cedd35892cbfb6c24663f9aa66f83700acbd92d Mon Sep 17 00:00:00 2001 From: AI Dev Date: Thu, 3 Dec 2026 13:56:50 +0000 Subject: [PATCH 2/2] sensors: the CV610 GalaxyCore split read keeps a swept bus's timeout count The split read calls past the reader get_sensor_id_on_swept_bus() installs, so on a bus that had already timed out twice the GalaxyCore probe still waited out the controller's timeout once per address. It now goes through the same count, and sensors_test checks that it stops touching such a bus after SWEEP_BUS_TIMEOUTS. The preferred bus never took that reader and is unaffected. --- src/sensors.c | 34 +++++++++++++++++++++++++++------- src/sensors_test.c | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+), 7 deletions(-) diff --git a/src/sensors.c b/src/sensors.c index 06244e9..dc10172 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -941,11 +941,24 @@ static int detect_omni_sensor(sensor_ctx_t *ctx, int fd, * sensors_test can watch it. */ static read_register_t galaxycore_split_read = universal_i2c_read_register; +static int sweep_read_register(int fd, unsigned char i2c_addr, + unsigned int reg_addr, unsigned int reg_width, + unsigned int data_width); +static int sweep_counted_read(read_register_t read, int fd, + unsigned char i2c_addr, unsigned int reg_addr, + unsigned int reg_width, unsigned int data_width); + static int galaxycore_narrow_read(int fd, unsigned char i2c_addr, unsigned int reg) { - if (chip_generation == HISI_OT) - return galaxycore_split_read(fd, i2c_addr, reg, 1, 1); - return i2c_read_register(fd, i2c_addr, reg, 1, 1); + if (chip_generation != HISI_OT) + return i2c_read_register(fd, i2c_addr, reg, 1, 1); + /* On a swept bus this goes past the reader the sweep installed, so it + * keeps that reader's count: once the bus has timed out it is not + * touched again from here either. */ + if (i2c_read_register == sweep_read_register) + return sweep_counted_read(galaxycore_split_read, fd, i2c_addr, reg, 1, + 1); + return galaxycore_split_read(fd, i2c_addr, reg, 1, 1); } /* A GalaxyCore ID read a byte-address at a time, 0 when it is not one. */ @@ -1376,14 +1389,14 @@ static int detect_possible_sensors(sensor_ctx_t *ctx, int fd, static read_register_t sweep_bus_read; static int sweep_timeouts; -static int sweep_read_register(int fd, unsigned char i2c_addr, - unsigned int reg_addr, unsigned int reg_width, - unsigned int data_width) { +static int sweep_counted_read(read_register_t read, int fd, + unsigned char i2c_addr, unsigned int reg_addr, + unsigned int reg_width, unsigned int data_width) { if (sweep_timeouts >= SWEEP_BUS_TIMEOUTS) return -1; errno = 0; - int val = sweep_bus_read(fd, i2c_addr, reg_addr, reg_width, data_width); + int val = read(fd, i2c_addr, reg_addr, reg_width, data_width); if (val == -1 && errno == ETIMEDOUT) sweep_timeouts++; else @@ -1391,6 +1404,13 @@ static int sweep_read_register(int fd, unsigned char i2c_addr, return val; } +static int sweep_read_register(int fd, unsigned char i2c_addr, + unsigned int reg_addr, unsigned int reg_width, + unsigned int data_width) { + return sweep_counted_read(sweep_bus_read, fd, i2c_addr, reg_addr, + reg_width, data_width); +} + static bool get_sensor_id_i2c(sensor_ctx_t *ctx) { bool detected = false; int fd = open_i2c_sensor_fd(i2c_adapter_nr); diff --git a/src/sensors_test.c b/src/sensors_test.c index 958a78a..4ef69ab 100644 --- a/src/sensors_test.c +++ b/src/sensors_test.c @@ -23,6 +23,7 @@ * * CHECK rather than assert(), matching reginfo_test.c and longse_test.c: the * release flags carry -DNDEBUG, which compiles assert() out entirely. */ +#include #include #include #include @@ -580,6 +581,42 @@ static void check_galaxycore_on_cv610(void) { i2c_read_register = mock_read; } +/* The split read goes past the reader a bus sweep installs, and has to keep + * its count anyway: a swept bus that keeps timing out is left alone, and the + * GalaxyCore probe's four addresses must not each wait out the timeout again. */ +static int ot_timeout_calls; + +static int ot_timeout_split(int fd, unsigned char addr, uint32_t reg, + unsigned int reg_width, unsigned int data_width) { + (void)fd; + (void)addr; + (void)reg; + (void)reg_width; + (void)data_width; + ot_timeout_calls++; + errno = ETIMEDOUT; + return -1; +} + +static void check_galaxycore_split_read_keeps_sweep_cutoff(void) { + chip_generation = HISI_OT; + galaxycore_split_read = ot_timeout_split; + sweep_bus_read = mock_read; + i2c_read_register = sweep_read_register; + sweep_timeouts = 0; + ot_timeout_calls = 0; + + for (int i = 0; i < 4; i++) + CHECK(galaxycore_narrow_read(0, mock_addr, 0xf0) == -1); + CHECK(ot_timeout_calls == SWEEP_BUS_TIMEOUTS); + CHECK(sweep_timeouts == SWEEP_BUS_TIMEOUTS); + + chip_generation = 0; + galaxycore_split_read = universal_i2c_read_register; + i2c_read_register = mock_read; + sweep_timeouts = 0; +} + /* The two IDs SmartSens gives to different parts depending on the SoC. */ static void check_vendor_dependent(void) { static const struct { @@ -1022,6 +1059,7 @@ int main(int argc, char **argv) { check_smartsens_variants(); check_galaxycore_reg_width(); check_galaxycore_on_cv610(); + check_galaxycore_split_read_keeps_sweep_cutoff(); check_probe_restores_console(); check_superpix_spared_by_galaxycore(); check_sensor_ports();