From b8ae0d3282be6618df88f46fb02046919d91d397 Mon Sep 17 00:00:00 2001 From: Dmitry Ilyin <6576495+widgetii@users.noreply.github.com> Date: Wed, 27 May 2026 11:02:24 +0300 Subject: [PATCH] sensor: fix IMX335 misdetected as IMX347 after WDR cycle (#157) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 0x3057 is Y_OUT_SIZE[12:0] MSB (host-writable, V-reflection), not a chip ID — Sony image sensors have no dedicated chip ID register. After majestic configures IMX335 for WDR with vertical cropping, Y_OUT_SIZE drops to ~0x0604 and 0x3057 reads 0x06, colliding with IMX347's reset default, so detect_sony_sensor commits to IMX347 and majestic fails with "No matches for 'imx347_i2c'". Cross-check with OB cropping registers 0x3072 (AREA2_WIDTH_1 LSB) and 0x3074 (AREA3_ST_ADR_1 LSB), which have distinct datasheet defaults (IMX335: 0x28/0xB0, IMX347: 0x14/0x3C) and survive majestic init. When they match the IMX335 fingerprint, fall through to the existing 0x316A IMX335 path instead of committing to IMX347. The originally proposed (0x316A & 0xFC) == 0x7C check alone is not a discriminator: IMX347's datasheet (p.40) shows the same fixed bits as IMX335 — it's an INCKSEL4 shape, not a chip identifier. Co-Authored-By: Claude Opus 4.7 (1M context) --- src/sensors.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/sensors.c b/src/sensors.c index 77f4f0d..960a0c2 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -158,12 +158,19 @@ static int detect_sony_sensor(sensor_ctx_t *ctx, int fd, if (i2c_change_addr(fd, i2c_addr) < 0) return false; - // HINT: 0x3057 also can be used for IMX335 (chip_id == 0x07) - // OR 0x3415 == 0x20 && 0x3418 == 0x27 + // 0x3057 is Y_OUT_SIZE MSB (host-writable), not a chip ID — Sony + // sensors have no dedicated chip ID register. IMX335 can read 0x06 + // here after a WDR-cropping cycle (#157). Disambiguate via OB + // cropping defaults that survive majestic init: + // IMX335: 0x3072=0x28, 0x3074=0xB0 + // IMX347: 0x3072=0x14, 0x3074=0x3C int chip_id = READ(0x57); if (chip_id == 0x06) { - sprintf(ctx->sensor_id, "IMX347"); - return true; + if (!(READ(0x72) == 0x28 && READ(0x74) == 0xB0)) { + sprintf(ctx->sensor_id, "IMX347"); + return true; + } + // IMX335 with reprogrammed Y_OUT_SIZE — fall through to 0x316A. } if (READ(0x41C) == 0x47) {