-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTVInfo.cpp
executable file
·271 lines (246 loc) · 7.12 KB
/
TVInfo.cpp
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <fcntl.h>
#define LOG_TAG "RKTVINFO"
#include <cutils/log.h>
#include <graphics.h>
#include "TVInfo.h"
struct fb_chroma {
__u32 redx; /* in fraction of 1024 */
__u32 greenx;
__u32 bluex;
__u32 whitex;
__u32 redy;
__u32 greeny;
__u32 bluey;
__u32 whitey;
};
struct fb_monspecs {
struct fb_chroma chroma;
struct fb_videomode *modedb; /* mode database */
__u8 manufacturer[4]; /* Manufacturer */
__u8 monitor[14]; /* Monitor String */
__u8 serial_no[14]; /* Serial Number */
__u8 ascii[14]; /* ? */
__u32 modedb_len; /* mode database length */
__u32 model; /* Monitor Model */
__u32 serial; /* Serial Number - Integer */
__u32 year; /* Year manufactured */
__u32 week; /* Week Manufactured */
__u32 hfmin; /* hfreq lower limit (Hz) */
__u32 hfmax; /* hfreq upper limit (Hz) */
__u32 dclkmin; /* pixelclock lower limit (Hz) */
__u32 dclkmax; /* pixelclock upper limit (Hz) */
__u16 input; /* display type - see FB_DISP_* */
__u16 dpms; /* DPMS support - see FB_DPMS_ */
__u16 signal; /* Signal Type - see FB_SIGNAL_* */
__u16 vfmin; /* vfreq lower limit (Hz) */
__u16 vfmax; /* vfreq upper limit (Hz) */
__u16 gamma; /* Gamma - in fractions of 100 */
__u16 gtf : 1; /* supports GTF */
__u16 misc; /* Misc flags - see FB_MISC_* */
__u8 version; /* EDID version... */
__u8 revision; /* ...and revision */
__u8 max_x; /* Maximum horizontal size (cm) */
__u8 max_y; /* Maximum vertical size (cm) */
};
static int IsHDMIConnected(void)
{
FILE *fd = fopen("/sys/class/display/HDMI/connect", "r");
char buf[12];
if(fd) {
memset(buf, 0, 12);
fgets(buf, 12, fd);
fclose(fd);
return atoi(buf);
} else {
return 0;
}
}
static char *itoa(int val, char *buf, unsigned radix)
{
char *p;
char *firstdig;
char temp;
unsigned digval;
p = buf;
if(val <0) {
*p++ = '-';
val = (unsigned long)(-(long)val);
}
firstdig = p;
do {
digval = (unsigned)(val % radix);
val /= radix;
if (digval > 9)
*p++ = (char)(digval - 10 + 'a');
else
*p++ = (char)(digval + '0');
} while(val > 0);
*p-- = '\0 ';
do {
temp = *p;
*p = *firstdig;
*firstdig = temp;
--p;
++firstdig;
} while(firstdig < p);
return buf;
}
int PortingOutputIoctl(HMW_HDMIRK_Ioctl_E op, HMW_VOID* arg)
{
int fd;
struct fb_monspecs monspecs;
HMW_TV_INFO_S *tvinfo = (HMW_TV_INFO_S*)arg;
if (arg == NULL || !IsHDMIConnected() || op != HMW_HDMI_RK_GET_TV_INFO) {
ALOGE("arg %p, HDMI connect %d, OP %d", arg, IsHDMIConnected(), op);
return -1;
}
FILE *ffd = NULL;
char buf[32];
ffd = fopen("/sys/class/display/HDMI/debug", "r");
if (!ffd) {
ALOGE("no hdmi debug node");
return -1;
}
memset(buf, 0, 32);
fgets(buf, 32, ffd);
fclose(ffd);
ALOGD("buf %s", buf);
if (memcmp(buf, "EDID status:Okay", 16)) {
ALOGE("EDID read failed");
return -1;
}
fd = open("/sys/class/display/HDMI/monspecs", O_RDONLY);
if (fd < 0) {
ALOGE("open monspec failed");
return -1;
}
unsigned int length = lseek(fd, 0L, SEEK_END);
lseek(fd, 0L, SEEK_SET);
if (length < sizeof(struct fb_monspecs))
return -1;
int len = read(fd, &monspecs, sizeof(struct fb_monspecs));
close(fd);
if (len != sizeof(struct fb_monspecs)) {
ALOGE("read size is not eqaul to fb_monspecs");
return -1;
}
memcpy(tvinfo->manufName, monspecs.manufacturer, 4);
tvinfo->manufModel = monspecs.model;
tvinfo->manufYear = monspecs.year;
ALOGD("x %d y %d\n", monspecs.max_x, monspecs.max_y);
int size = sqrt(monspecs.max_x * monspecs.max_x + monspecs.max_y * monspecs.max_y)/2.54 + 0.5;
ALOGD("size %d\n", size);
itoa(size, (char *)tvinfo->displaySize, 10);
return 0;
}
enum {
HDMI_COLORIMETRY_EXTEND_XVYCC_601,
HDMI_COLORIMETRY_EXTEND_XVYCC_709,
HDMI_COLORIMETRY_EXTEND_SYCC_601,
HDMI_COLORIMETRY_EXTEND_ADOBE_YCC601,
HDMI_COLORIMETRY_EXTEND_ADOBE_RGB,
HDMI_COLORIMETRY_EXTEND_BT_2020_YCC_C, /*constant luminance*/
HDMI_COLORIMETRY_EXTEND_BT_2020_YCC,
HDMI_COLORIMETRY_EXTEND_BT_2020_RGB,
};
enum hdmi_hdr_eotf {
EOTF_TRADITIONAL_GMMA_SDR = 1,
EOFT_TRADITIONAL_GMMA_HDR = 2,
EOTF_ST_2084 = 4,
};
int HdmiSupportedDataSpace(void)
{
FILE *ffd = NULL;
char buf[64];
int colorimetry, dataspace = 0;
unsigned int eotf;
if (!IsHDMIConnected())
return 0;
ffd = fopen("/sys/class/display/HDMI/color", "r");
if (!ffd) {
ALOGE("no hdmi color node");
return 0;
}
memset(buf, 0, 64);
while(fgets(buf, 64, ffd) != NULL) {
if (!memcmp(buf, "Supported Colorimetry", 21)) {
sscanf(buf, "Supported Colorimetry: %d", &colorimetry);
} else if (!memcmp(buf, "Supported EOTF", 14)) {
sscanf(buf, "Supported EOTF: 0x%x", &eotf);
}
memset(buf, 0, 64);
}
fclose(ffd);
ALOGD("colorimetry %d, eotf 0x%x\n", colorimetry, eotf);
if (colorimetry & HDMI_COLORIMETRY_EXTEND_BT_2020_YCC ||
colorimetry & HDMI_COLORIMETRY_EXTEND_BT_2020_RGB)
dataspace |= HAL_DATASPACE_STANDARD_BT2020;
if (colorimetry & HDMI_COLORIMETRY_EXTEND_BT_2020_YCC_C)
dataspace |= HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE;
if (eotf & EOTF_ST_2084)
dataspace |= HAL_DATASPACE_TRANSFER_ST2084;
return dataspace;
}
int HdmiSetHDR(int enable)
{
FILE *ffd = NULL;
char buf[64];
int eotf;
ffd = fopen("/sys/class/display/HDMI/color", "w");
if (!ffd) {
ALOGE("no hdmi color node");
return -1;
}
if (enable)
eotf = EOTF_ST_2084;
else
eotf = 0;
memset(buf, 0, 64);
sprintf(buf, "hdr=%d", eotf);
ALOGD("%s", buf);
fwrite(buf, 1, strlen(buf), ffd);
fclose(ffd);
return 0;
}
int HdmiSetColorimetry(android_dataspace_t Colorimetry)
{
FILE *ffd = NULL;
char buf[64];
char colorimetry;
ffd = fopen("/sys/class/display/HDMI/color", "w");
if (!ffd) {
ALOGE("no hdmi color node");
return -1;
}
if (Colorimetry == HAL_DATASPACE_STANDARD_BT2020)
colorimetry = HDMI_COLORIMETRY_EXTEND_BT_2020_YCC + 3;
else if (Colorimetry == HAL_DATASPACE_STANDARD_BT2020_CONSTANT_LUMINANCE)
colorimetry = HDMI_COLORIMETRY_EXTEND_BT_2020_YCC_C + 3;
else
colorimetry = 0;
memset(buf, 0, 64);
sprintf(buf, "colorimetry=%d", colorimetry);
fwrite(buf, 1, strlen(buf), ffd);
fclose(ffd);
return 0;
}
#if 0
int main(int argc, char **argv)
{
HMW_TV_INFO_S TVInfo;
int rc = PortingOutputIoctl(HMW_HDMI_RK_GET_TV_INFO, &TVInfo);
if (!rc) {
printf("manufName %s\n", TVInfo.manufName);
printf("manufModel %d\n", TVInfo.manufModel);
printf("manufYear %d\n", TVInfo.manufYear);
printf("displaySize %s\n", TVInfo.displaySize);
} else
printf("failed\n");
HdmiSupportedDataSpace();
return 0;
}
#endif