From c49ba6b00b1365aca5ca72501f463d3ccc35f3f1 Mon Sep 17 00:00:00 2001 From: Dmitry Ermakov <7954832+dimerr@users.noreply.github.com> Date: Tue, 24 Nov 2026 12:23:45 +0000 Subject: [PATCH 1/5] gm: the GM8126 on a mainline kernel, and the OV7720/OV7725 /proc/pmu is the vendor kernel's; the device tree names the chip otherwise. --- src/chipid.c | 1 + src/hal/gm.c | 14 +++++++++++++- src/hal/gm.h | 1 + src/sensors.c | 17 +++++++++++++++++ 4 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/chipid.c b/src/chipid.c index 6a176af9..12952361 100644 --- a/src/chipid.c +++ b/src/chipid.c @@ -70,6 +70,7 @@ static const manufacturers_t manufacturers[] = { #endif #ifdef IPCHW_VENDOR_GM {"Grain", gm_detect_cpu, VENDOR_GM, gm_setup_hal}, + {NULL /* Generic */, gm_dt_detect_cpu, VENDOR_GM, gm_setup_hal}, #endif #ifdef IPCHW_VENDOR_FH {"FH", fh_detect_cpu, VENDOR_FH, fh_setup_hal}, diff --git a/src/hal/gm.c b/src/hal/gm.c index 394f359a..68d656ef 100644 --- a/src/hal/gm.c +++ b/src/hal/gm.c @@ -10,7 +10,8 @@ static unsigned char sony_addrs[] = {0x34, 0}; static unsigned char ssens_addrs[] = {0x60, 0}; -static unsigned char omni_addrs[] = {0x6c, 0}; +/* 0x42: the OV77xx, on GM8126 cameras */ +static unsigned char omni_addrs[] = {0x6c, 0x42, 0}; static unsigned char onsemi_addrs[] = {0x20, 0}; static unsigned char gc_addrs[] = {0x6e, 0}; @@ -30,6 +31,17 @@ bool gm_detect_cpu(char *chip_name) { return true; } +/* A mainline kernel: no /proc/pmu, the device tree names the chip. */ +bool gm_dt_detect_cpu(char *chip_name) { + char buf[256]; + + if (!line_from_file("/proc/device-tree/compatible", + "^grainmedia,gm([0-9]+)", buf, sizeof(buf))) + return false; + sprintf(chip_name, "GM%.4s", buf); + return true; +} + static unsigned long gm_media_mem() { char buf[256]; // Fixme: this seems to be currently allocated size diff --git a/src/hal/gm.h b/src/hal/gm.h index 2c8de741..0b951e3b 100644 --- a/src/hal/gm.h +++ b/src/hal/gm.h @@ -4,6 +4,7 @@ #include bool gm_detect_cpu(char *chip_name); +bool gm_dt_detect_cpu(char *chip_name); unsigned long gm_totalmem(unsigned long *media_mem); void gm_setup_hal(); diff --git a/src/sensors.c b/src/sensors.c index 90db8160..996df3d9 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -798,6 +798,23 @@ static int detect_omni_sensor(sensor_ctx_t *ctx, int fd, if (i2c_change_addr(fd, i2c_addr) < 0) return false; + // The OV77xx have one-byte registers: the product ID at 0x0A, 0x0B and + // the manufacturer's at 0x1C, 0x1D. + if (i2c_addr == 0x42) { + if (i2c_read_register(fd, i2c_addr, 0x0A, 1, 1) != 0x77) + return false; + if (i2c_read_register(fd, i2c_addr, 0x1C, 1, 1) != 0x7F || + i2c_read_register(fd, i2c_addr, 0x1D, 1, 1) != 0xA2) + return false; + // 0x21 is the OV7725, 0x20 the OV7720 + sprintf(ctx->sensor_id, "OV77%02x", + (i2c_read_register(fd, i2c_addr, 0x0B, 1, 1) & 0xff) == 0x21 + ? 0x25 + : 0x20); + ctx->reg_width = 1; + return true; + } + // HISI_V2 needs width 2. Old OmniVision sensors do not provide mfg_id // register. prod_msb = i2c_read_register(fd, i2c_addr, 0x300A, 2, 1); From f863c79f22dd00ab67e9ca8528303f1d122e1a44 Mon Sep 17 00:00:00 2001 From: Dmitry Ermakov <7954832+dimerr@users.noreply.github.com> Date: Tue, 24 Nov 2026 13:24:46 +0000 Subject: [PATCH 2/5] gm: read all of the compatibles, and know the OV77xx version --- src/hal/gm.c | 4 ++-- src/sensors.c | 15 ++++++++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/hal/gm.c b/src/hal/gm.c index 68d656ef..7ffb19c6 100644 --- a/src/hal/gm.c +++ b/src/hal/gm.c @@ -35,8 +35,8 @@ bool gm_detect_cpu(char *chip_name) { bool gm_dt_detect_cpu(char *chip_name) { char buf[256]; - if (!line_from_file("/proc/device-tree/compatible", - "^grainmedia,gm([0-9]+)", buf, sizeof(buf))) + if (!dts_items_by_regex("/proc/device-tree/compatible", + "grainmedia,gm([0-9]+)", buf, sizeof(buf))) return false; sprintf(chip_name, "GM%.4s", buf); return true; diff --git a/src/sensors.c b/src/sensors.c index 996df3d9..ddb7e482 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -806,11 +806,16 @@ static int detect_omni_sensor(sensor_ctx_t *ctx, int fd, if (i2c_read_register(fd, i2c_addr, 0x1C, 1, 1) != 0x7F || i2c_read_register(fd, i2c_addr, 0x1D, 1, 1) != 0xA2) return false; - // 0x21 is the OV7725, 0x20 the OV7720 - sprintf(ctx->sensor_id, "OV77%02x", - (i2c_read_register(fd, i2c_addr, 0x0B, 1, 1) & 0xff) == 0x21 - ? 0x25 - : 0x20); + switch (i2c_read_register(fd, i2c_addr, 0x0B, 1, 1)) { + case 0x21: + sprintf(ctx->sensor_id, "OV7725"); + break; + case 0x20: + sprintf(ctx->sensor_id, "OV7720"); + break; + default: + return false; + } ctx->reg_width = 1; return true; } From 574931560e4bbaa2b5d2336b5730621d7dc9cd7f Mon Sep 17 00:00:00 2001 From: Dmitry Ermakov <7954832+dimerr@users.noreply.github.com> Date: Tue, 24 Nov 2026 13:53:50 +0000 Subject: [PATCH 3/5] gm: read the compatibles without the regex engine --- src/hal/gm.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/hal/gm.c b/src/hal/gm.c index 7ffb19c6..8bdb9162 100644 --- a/src/hal/gm.c +++ b/src/hal/gm.c @@ -1,5 +1,6 @@ #include "hal/gm.h" +#include #include #include @@ -33,13 +34,24 @@ bool gm_detect_cpu(char *chip_name) { /* A mainline kernel: no /proc/pmu, the device tree names the chip. */ bool gm_dt_detect_cpu(char *chip_name) { + static const char prefix[] = "grainmedia,gm"; char buf[256]; - if (!dts_items_by_regex("/proc/device-tree/compatible", - "grainmedia,gm([0-9]+)", buf, sizeof(buf))) + FILE *f = fopen("/proc/device-tree/compatible", "r"); + if (!f) return false; - sprintf(chip_name, "GM%.4s", buf); - return true; + size_t len = fread(buf, 1, sizeof(buf) - 1, f); + fclose(f); + buf[len] = 0; + + /* NUL-separated strings, the board's before the chip's */ + for (char *s = buf; s < buf + len; s += strlen(s) + 1) { + if (!strncmp(s, prefix, sizeof(prefix) - 1)) { + sprintf(chip_name, "GM%.4s", s + sizeof(prefix) - 1); + return true; + } + } + return false; } static unsigned long gm_media_mem() { From 439d021b76e3cd731ea31e9d641a24217eaa31eb Mon Sep 17 00:00:00 2001 From: Dmitry Ermakov <7954832+dimerr@users.noreply.github.com> Date: Tue, 24 Nov 2026 14:04:45 +0000 Subject: [PATCH 4/5] sensors: the OV77xx probe smaller, and only with the Grain Media HAL --- src/sensors.c | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/src/sensors.c b/src/sensors.c index ddb7e482..ffdfe59d 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -798,27 +798,24 @@ static int detect_omni_sensor(sensor_ctx_t *ctx, int fd, if (i2c_change_addr(fd, i2c_addr) < 0) return false; - // The OV77xx have one-byte registers: the product ID at 0x0A, 0x0B and - // the manufacturer's at 0x1C, 0x1D. +#ifdef IPCHW_VENDOR_GM + // The OV77xx have one-byte registers: the manufacturer's ID at 0x1C, the + // product's at 0x0A, whose low byte is the version. The last one read + // tells the OV7725 (0x21) from the OV7720 (0x20). if (i2c_addr == 0x42) { - if (i2c_read_register(fd, i2c_addr, 0x0A, 1, 1) != 0x77) + static const unsigned char id[][2] = { + {0x1C, 0x7F}, {0x1D, 0xA2}, {0x0A, 0x77}}; + for (int i = 0; i < 3; i++) + if (i2c_read_register(fd, i2c_addr, id[i][0], 1, 1) != id[i][1]) + return false; + res = i2c_read_register(fd, i2c_addr, 0x0B, 1, 1); + if ((res | 1) != 0x21) return false; - if (i2c_read_register(fd, i2c_addr, 0x1C, 1, 1) != 0x7F || - i2c_read_register(fd, i2c_addr, 0x1D, 1, 1) != 0xA2) - return false; - switch (i2c_read_register(fd, i2c_addr, 0x0B, 1, 1)) { - case 0x21: - sprintf(ctx->sensor_id, "OV7725"); - break; - case 0x20: - sprintf(ctx->sensor_id, "OV7720"); - break; - default: - return false; - } + strcpy(ctx->sensor_id, res & 1 ? "OV7725" : "OV7720"); ctx->reg_width = 1; return true; } +#endif // HISI_V2 needs width 2. Old OmniVision sensors do not provide mfg_id // register. From 79df1dedd145a1da99cdfa63be49a92abad5987b Mon Sep 17 00:00:00 2001 From: Dmitry Ermakov <7954832+dimerr@users.noreply.github.com> Date: Tue, 24 Nov 2026 14:18:38 +0000 Subject: [PATCH 5/5] gm: the GM8126 in ipctool only, not in ipcinfo --- src/chipid.c | 2 ++ src/hal/gm.c | 9 ++++++++- src/hal/gm.h | 2 ++ src/sensors.c | 2 +- 4 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/chipid.c b/src/chipid.c index 12952361..1dfcff46 100644 --- a/src/chipid.c +++ b/src/chipid.c @@ -70,8 +70,10 @@ static const manufacturers_t manufacturers[] = { #endif #ifdef IPCHW_VENDOR_GM {"Grain", gm_detect_cpu, VENDOR_GM, gm_setup_hal}, +#ifndef STANDALONE_LIBRARY {NULL /* Generic */, gm_dt_detect_cpu, VENDOR_GM, gm_setup_hal}, #endif +#endif #ifdef IPCHW_VENDOR_FH {"FH", fh_detect_cpu, VENDOR_FH, fh_setup_hal}, #endif diff --git a/src/hal/gm.c b/src/hal/gm.c index 8bdb9162..a57bcb5a 100644 --- a/src/hal/gm.c +++ b/src/hal/gm.c @@ -11,8 +11,12 @@ static unsigned char sony_addrs[] = {0x34, 0}; static unsigned char ssens_addrs[] = {0x60, 0}; +#ifndef STANDALONE_LIBRARY /* 0x42: the OV77xx, on GM8126 cameras */ static unsigned char omni_addrs[] = {0x6c, 0x42, 0}; +#else +static unsigned char omni_addrs[] = {0x6c, 0}; +#endif static unsigned char onsemi_addrs[] = {0x20, 0}; static unsigned char gc_addrs[] = {0x6e, 0}; @@ -32,7 +36,9 @@ bool gm_detect_cpu(char *chip_name) { return true; } -/* A mainline kernel: no /proc/pmu, the device tree names the chip. */ +#ifndef STANDALONE_LIBRARY +/* A mainline kernel: no /proc/pmu, the device tree names the chip. The + * GM8126 is old and rare: only ipctool knows it, not ipcinfo. */ bool gm_dt_detect_cpu(char *chip_name) { static const char prefix[] = "grainmedia,gm"; char buf[256]; @@ -53,6 +59,7 @@ bool gm_dt_detect_cpu(char *chip_name) { } return false; } +#endif static unsigned long gm_media_mem() { char buf[256]; diff --git a/src/hal/gm.h b/src/hal/gm.h index 0b951e3b..98933c1e 100644 --- a/src/hal/gm.h +++ b/src/hal/gm.h @@ -4,7 +4,9 @@ #include bool gm_detect_cpu(char *chip_name); +#ifndef STANDALONE_LIBRARY bool gm_dt_detect_cpu(char *chip_name); +#endif unsigned long gm_totalmem(unsigned long *media_mem); void gm_setup_hal(); diff --git a/src/sensors.c b/src/sensors.c index 4a19cb0b..750da4da 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -798,7 +798,7 @@ static int detect_omni_sensor(sensor_ctx_t *ctx, int fd, if (i2c_change_addr(fd, i2c_addr) < 0) return false; -#ifdef IPCHW_VENDOR_GM +#if defined(IPCHW_VENDOR_GM) && !defined(STANDALONE_LIBRARY) // The OV77xx have one-byte registers: the manufacturer's ID at 0x1C, the // product's at 0x0A, whose low byte is the version. The last one read // tells the OV7725 (0x21) from the OV7720 (0x20).