forked from OE4T/tegra-eeprom-tool
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcvm.c
89 lines (77 loc) · 1.58 KB
/
cvm.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/*
* cvm.c
*
* SoC-specific functions.
*
* Copyright (c) 2020 Matthew Madison
*/
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include "cvm.h"
static const struct cvm_i2c_address_s cvm_addr[TEGRA_SOCTYPE_COUNT] = {
[TEGRA_SOCTYPE_186] = { 7, 0x50 },
[TEGRA_SOCTYPE_194] = { 0, 0x50 },
[TEGRA_SOCTYPE_210] = { 2, 0x50 },
};
/*
* cvm_soctype
*/
tegra_soctype_t
cvm_soctype (void) {
ssize_t typelen;
int fd;
char soctype[65];
unsigned long chipid;
fd = open("/sys/module/tegra_fuse/parameters/tegra_chip_id", O_RDONLY);
if (fd < 0)
return TEGRA_SOCTYPE_INVALID;
typelen = read(fd, soctype, sizeof(soctype)-1);
close(fd);
if (typelen < 0)
return TEGRA_SOCTYPE_INVALID;
while (typelen > 0 && soctype[typelen-1] == '\n') typelen--;
soctype[typelen] = '\0';
chipid = strtoul(soctype, NULL, 10);
switch (chipid) {
case 0x18:
return TEGRA_SOCTYPE_186;
case 0x19:
return TEGRA_SOCTYPE_194;
case 0x21:
return TEGRA_SOCTYPE_210;
default:
break;
}
return TEGRA_SOCTYPE_INVALID;
} /* cvm_soctype */
/*
* cvm_soctype_name
*/
const char *
cvm_soctype_name (tegra_soctype_t soctype)
{
switch (soctype) {
case TEGRA_SOCTYPE_186:
return "Tegra186";
case TEGRA_SOCTYPE_194:
return "Tegra194";
case TEGRA_SOCTYPE_210:
return "Tegra210";
default:
break;
}
return "INVALID";
} /* cvm_soctype_name */
/*
* cvm_i2c_address
*/
const cvm_i2c_address_t *
cvm_i2c_address (void) {
tegra_soctype_t s = cvm_soctype();
if (s == TEGRA_SOCTYPE_INVALID)
return NULL;
return &cvm_addr[s];
} /* cvm_i2c_address*/