diff --git a/src/chipid.c b/src/chipid.c index 6a176af..1dfcff4 100644 --- a/src/chipid.c +++ b/src/chipid.c @@ -70,6 +70,9 @@ 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}, diff --git a/src/hal/gm.c b/src/hal/gm.c index 394f359..a57bcb5 100644 --- a/src/hal/gm.c +++ b/src/hal/gm.c @@ -1,5 +1,6 @@ #include "hal/gm.h" +#include #include #include @@ -10,7 +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}; @@ -30,6 +36,31 @@ bool gm_detect_cpu(char *chip_name) { return true; } +#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]; + + FILE *f = fopen("/proc/device-tree/compatible", "r"); + if (!f) + return false; + 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; +} +#endif + 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 2c8de74..98933c1 100644 --- a/src/hal/gm.h +++ b/src/hal/gm.h @@ -4,6 +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 d955503..750da4d 100644 --- a/src/sensors.c +++ b/src/sensors.c @@ -798,6 +798,25 @@ static int detect_omni_sensor(sensor_ctx_t *ctx, int fd, if (i2c_change_addr(fd, i2c_addr) < 0) return false; +#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). + if (i2c_addr == 0x42) { + 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; + 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. prod_msb = i2c_read_register(fd, i2c_addr, 0x300A, 2, 1);