Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/chipid.c
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
31 changes: 31 additions & 0 deletions src/hal/gm.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "hal/gm.h"

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

Expand All @@ -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};

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions src/hal/gm.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#include <stdbool.h>

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();

Expand Down
19 changes: 19 additions & 0 deletions src/sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down