Skip to content

Commit

Permalink
Add TechPoint ADC detection
Browse files Browse the repository at this point in the history
  • Loading branch information
dimerr committed Jan 15, 2024
1 parent 102f52a commit c446cb4
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/hal/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ enum SENSORS {
SENSOR_BRIGATES,
SENSOR_GALAXYCORE,
SENSOR_SUPERPIX,
SENSOR_TECHPOINT,
};

typedef struct {
Expand Down
4 changes: 3 additions & 1 deletion src/hal/hisi/hal_hisi.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,14 @@ static unsigned char ssens_addrs[] = {0x60, 0};
static unsigned char omni_addrs[] = {0x60, 0x6c, 0x42, 0};
static unsigned char gc_addrs[] = {0x6e, 0x52, 0x42, 0x78, 0};
static unsigned char superpix_addrs[] = {0x79, 0};
static unsigned char tp_addrs[] = {0x88, 0};

static sensor_addr_t my_possible_i2c_addrs[] = {
{SENSOR_SONY, sony_addrs}, {SENSOR_SOI, soi_addrs},
{SENSOR_ONSEMI, onsemi_addrs}, {SENSOR_SMARTSENS, ssens_addrs},
{SENSOR_OMNIVISION, omni_addrs}, {SENSOR_GALAXYCORE, gc_addrs},
{SENSOR_SUPERPIX, superpix_addrs}, {0, NULL}};
{SENSOR_SUPERPIX, superpix_addrs}, {SENSOR_TECHPOINT, tp_addrs},
{0, NULL}};

static float hisi_get_temp();

Expand Down
22 changes: 20 additions & 2 deletions src/hal/novatek.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include <unistd.h>

#include "chipid.h"
#include "hal/common.h"
#include "tools.h"

Expand All @@ -15,18 +16,21 @@ static unsigned char ssens_addrs[] = {0x60, 0};
static unsigned char omni_addrs[] = {0x6c, 0};
static unsigned char onsemi_addrs[] = {0x20, 0};
static unsigned char gc_addrs[] = {0x6e, 0};
static unsigned char tp_addrs[] = {0x88, 0};

static sensor_addr_t novatek_possible_i2c_addrs[] = {
{SENSOR_SONY, sony_addrs}, {SENSOR_SMARTSENS, ssens_addrs},
{SENSOR_ONSEMI, onsemi_addrs}, {SENSOR_OMNIVISION, omni_addrs},
{SENSOR_GALAXYCORE, gc_addrs}, {0, NULL}};
{SENSOR_GALAXYCORE, gc_addrs}, {SENSOR_TECHPOINT, tp_addrs},
{0, NULL}};

bool novatek_detect_cpu(char *chip_name) {
char buf[256];

if (!line_from_file("/proc/device-tree/model", "Novatek ([A-Z]+[0-9]+)",
buf, sizeof(buf)))
return false;

strcpy(chip_name, buf);
return true;
}
Expand Down Expand Up @@ -55,9 +59,23 @@ float novatek_get_temp() {
return ret;
}

static int novatek_open_i2c_fd() {
int adapter_nr = 0;

if (!strncmp(chip_name, "NA51068", 7) ||
!strncmp(chip_name, "NA51103", 7) || !strncmp(chip_name, "NA51090", 7))
adapter_nr = 1;
char adapter_name[FILENAME_MAX];

snprintf(adapter_name, sizeof(adapter_name), "/dev/i2c-%d", adapter_nr);

return universal_open_sensor_fd(adapter_name);
}

void novatek_setup_hal() {
possible_i2c_addrs = novatek_possible_i2c_addrs;
i2c_change_addr = i2c_changenshift_addr;
i2c_change_addr = i2c_changenshift_addr;
open_i2c_sensor_fd = novatek_open_i2c_fd;
if (!access("/sys/class/thermal/thermal_zone0/temp", R_OK))
hal_temperature = novatek_get_temp;
#ifndef STANDALONE_LIBRARY
Expand Down
26 changes: 26 additions & 0 deletions src/sensors.c
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,28 @@ static int detect_superpix_sensor(sensor_ctx_t *ctx, int fd,
return res;
}

static int detect_techpoint_adc(sensor_ctx_t *ctx, int fd,
unsigned char i2c_addr) {
if (i2c_change_addr(fd, i2c_addr) < 0)
return false;

int prod_msb = i2c_read_register(fd, i2c_addr, 0xfe, 1, 1);
if (prod_msb == -1)
return false;

int prod_lsb = i2c_read_register(fd, i2c_addr, 0xff, 1, 1);
if (prod_lsb == -1)
return false;

int res = prod_msb << 8 | prod_lsb;
if (!res)
return false;
else
sprintf(ctx->sensor_id, "TP%04x", res);

return res;
}

static int detect_possible_sensors(sensor_ctx_t *ctx, int fd,
int (*detect_fn)(sensor_ctx_t *ctx, int,
unsigned char),
Expand Down Expand Up @@ -886,6 +908,10 @@ static bool get_sensor_id_i2c(sensor_ctx_t *ctx) {
strcpy(ctx->vendor, "SuperPix");
ctx->reg_width = 1;
detected = true;
} else if (detect_possible_sensors(ctx, fd, detect_techpoint_adc,
SENSOR_TECHPOINT)) {
strcpy(ctx->vendor, "TechPoint");
detected = true;
}
exit:
close_sensor_fd(fd);
Expand Down

0 comments on commit c446cb4

Please sign in to comment.