Skip to content

Commit 4088165

Browse files
committed
Add Novatek chipid via pinmux value
1 parent 14d9f1a commit 4088165

File tree

4 files changed

+60
-36
lines changed

4 files changed

+60
-36
lines changed

src/chipid.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ static const manufacturers_t manufacturers[] = {
4646
#ifdef __arm__
4747
{"SStar", sstar_detect_cpu, VENDOR_SSTAR, sstar_setup_hal},
4848
{"MStar", mstar_detect_cpu, NULL, sstar_setup_hal},
49-
{"Novatek", novatek_detect_cpu, NULL, novatek_setup_hal},
49+
{"Novatek", novatek_detect_cpu, VENDOR_NOVATEK, novatek_setup_hal},
5050
{"Grain", gm_detect_cpu, VENDOR_GM, gm_setup_hal},
5151
{"FH", fh_detect_cpu, VENDOR_FH, fh_setup_hal},
5252
{NULL /* Generic */, rockchip_detect_cpu, VENDOR_ROCKCHIP, rockchip_setup_hal},
@@ -55,6 +55,7 @@ static const manufacturers_t manufacturers[] = {
5555
{NULL, allwinner_detect_cpu, VENDOR_ALLWINNER, allwinner_setup_hal}
5656
#endif
5757
#if defined(__aarch64__) || defined(_M_ARM64)
58+
{NULL, novatek_detect_cpu, VENDOR_NOVATEK, novatek_setup_hal},
5859
{NULL, tegra_detect_cpu, "Nvidia", tegra_setup_hal},
5960
#endif
6061
};

src/chipid.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
#define VENDOR_GOKE "Goke"
1111
#define VENDOR_HISI "HiSilicon"
1212
#define VENDOR_INGENIC "Ingenic"
13+
#define VENDOR_NOVATEK "Novatek"
1314
#define VENDOR_ROCKCHIP "Rockchip"
1415
#define VENDOR_SSTAR "SigmaStar"
1516

src/hal/novatek.c

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
#include "hal/common.h"
1010
#include "tools.h"
1111

12-
// TODO: /proc/nvt_info/nvt_pinmux/chip_id
13-
1412
static unsigned char sony_addrs[] = {0x34, 0};
1513
static unsigned char ssens_addrs[] = {0x60, 0};
1614
static unsigned char omni_addrs[] = {0x6c, 0};
@@ -24,14 +22,49 @@ static sensor_addr_t novatek_possible_i2c_addrs[] = {
2422
{SENSOR_GALAXYCORE, gc_addrs}, {SENSOR_TECHPOINT, tp_addrs},
2523
{0, NULL}};
2624

25+
static bool nvt_get_chip_id() {
26+
uint16_t reg;
27+
unsigned int chip_id = 0;
28+
char buf[8];
29+
char *endptr;
30+
31+
if (line_from_file("/proc/nvt_info/nvt_pinmux/chip_id", "(.+)", buf,
32+
sizeof(buf))) {
33+
34+
reg = (uint16_t)strtol(buf, &endptr, 16);
35+
switch (reg) {
36+
case 0x5021:
37+
strcpy(chip_name, "NT98562");
38+
return true;
39+
case 0x7021:
40+
strcpy(chip_name, "NT98566");
41+
return true;
42+
case 0x8B20:
43+
strcpy(chip_name, "NT98332G");
44+
return true;
45+
}
46+
}
47+
48+
// if (mem_reg(IOADDR_TOP_REG_BASE + TOP_VERSION_REG_OFS, (uint32_t *)&reg,
49+
// OP_READ)) {
50+
// chip_id = (reg >> 16) & 0xFFFF;
51+
// }
52+
// printf("reg %x\n", chip_id);
53+
return false;
54+
}
55+
2756
bool novatek_detect_cpu(char *chip_name) {
2857
char buf[256];
2958

59+
if(nvt_get_chip_id())
60+
return true;
61+
3062
if (!line_from_file("/proc/device-tree/model", "Novatek ([A-Z]+[0-9]+)",
3163
buf, sizeof(buf)))
3264
return false;
3365

3466
strcpy(chip_name, buf);
67+
3568
return true;
3669
}
3770

@@ -82,36 +115,3 @@ void novatek_setup_hal() {
82115
hal_totalmem = novatek_totalmem;
83116
#endif
84117
}
85-
86-
enum CHIP_ID {
87-
CHIP_NA51055 = 0x4821, // NT98525, 128Kb L2, 5M@30
88-
// NT98528, 256Kb L2, 4K@30
89-
CHIP_NA51084 = 0x5021,
90-
CHIP_NA51089 = 0x7021, // NT98562, 64Mb internal RAM
91-
// NT98566, 128Mb internal RAM
92-
CHIP_NA51090 = 0xBC21
93-
};
94-
95-
#define TOP_VERSION_REG_OFS 0xF0
96-
97-
/* na51000, na51089, na51068, na51000, na51090, na51055 */
98-
#define IOADDR_GLOBAL_BASE (0xF0000000)
99-
/* na51090 */
100-
//#define IOADDR_GLOBAL_BASE (0x2F0000000)
101-
102-
/* na51000, na51089, na51000, na51090, na51090, na51055 */
103-
#define IOADDR_TOP_REG_BASE (IOADDR_GLOBAL_BASE + 0x00010000)
104-
/* na51068 */
105-
//#define IOADDR_TOP_REG_BASE (IOADDR_GLOBAL_BASE + 0x0E030000)
106-
107-
static uint32_t nvt_get_chip_id() {
108-
uint32_t reg;
109-
unsigned int chip_id = 0;
110-
111-
if (mem_reg(IOADDR_TOP_REG_BASE + TOP_VERSION_REG_OFS, (uint32_t *)&reg,
112-
OP_READ)) {
113-
chip_id = (reg >> 16) & 0xFFFF;
114-
}
115-
116-
return chip_id;
117-
}

src/hal/novatek.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,26 @@ bool novatek_detect_cpu(char *chip_name);
77
unsigned long novatek_totalmem(unsigned long *media_mem);
88
void novatek_setup_hal();
99

10+
#define TOP_VERSION_REG_OFS 0xF0
11+
12+
/* na51000, na51089, na51068, na51000, na51090, na51055 */
13+
#define IOADDR_GLOBAL_BASE (0xF0000000)
14+
/* na51090 */
15+
//#define IOADDR_GLOBAL_BASE (0x2F0000000)
16+
17+
/* na51000, na51089, na51000, na51090, na51090, na51055 */
18+
#define IOADDR_TOP_REG_BASE (IOADDR_GLOBAL_BASE + 0x00010000)
19+
/* na51068 */
20+
//#define IOADDR_TOP_REG_BASE (IOADDR_GLOBAL_BASE + 0x0E030000)
21+
22+
enum CHIP_ID {
23+
CHIP_NA51055 = 0x4821, // NT98525, 128Kb L2, 5M@30
24+
// NT98528, 256Kb L2, 4K@30
25+
CHIP_NA51084 = 0x5021,
26+
CHIP_NA51089 = 0x7021, // NT98562, 64Mb internal RAM
27+
// NT98566, 128Mb internal RAM
28+
CHIP_NA51090 = 0xBC21,
29+
CHIP_NA51103 = 0x8B20 // NVT98332G
30+
};
31+
1032
#endif /* HAL_NOVATEK_H */

0 commit comments

Comments
 (0)