aboutsummaryrefslogtreecommitdiff
path: root/deps/sysobj_early/include/util_edid.h
blob: d2fe947b98bf647b94f7098fe06999647ecf894e (plain)
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
/*
 * sysobj - https://github.com/bp0/verbose-spork
 * Copyright (C) 2018  Burt P. <pburt0@gmail.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 */

#ifndef __UTIL_EDID_H__
#define __UTIL_EDID_H__

#define _GNU_SOURCE
#include <stdint.h>  /* for *int*_t types */
#include <glib.h>

typedef struct _edid edid;

typedef struct {
    edid *e;
    uint32_t offset;
} edid_addy;

typedef struct {
    char *str;
    uint16_t len;
    uint8_t is_product_name;
    uint8_t is_serial;
} DisplayIDString;

typedef struct {
    uint8_t version;
    uint8_t extension_length;
    uint8_t primary_use_case;
    uint8_t extension_count;
    uint16_t blocks;
    uint8_t checksum_ok;
} DisplayIDMeta;

typedef struct {
    edid_addy addy;
    union {
        uint8_t tag;
        uint8_t type;
    };
    uint8_t revision;
    uint8_t len;
    uint8_t bounds_ok;
} DisplayIDBlock;

typedef struct {
    edid_addy addy;
    uint8_t interface;
    uint8_t supports_hdcp;
    uint8_t exists;
} DIExtData;

/* order by rising priority */
enum {
    OUTSRC_INVALID = -1,
    OUTSRC_EDID    =  0,
    OUTSRC_ETB,
    OUTSRC_STD,
    OUTSRC_DTD,
    OUTSRC_CEA_DTD,
    OUTSRC_SVD,

    OUTSRC_DID_TYPE_I,
    OUTSRC_DID_TYPE_VI,
    OUTSRC_DID_TYPE_VII,
};

typedef struct {
    float horiz_cm, vert_cm;
    float diag_cm, diag_in;
    int horiz_blanking, vert_blanking;
    int horiz_pixels, vert_lines, vert_pixels;
    float vert_freq_hz;
    uint8_t is_interlaced;
    uint8_t is_preferred;
    int stereo_mode;
    uint64_t pixel_clock_khz;
    int src; /* enum OUTSRC_* */
    uint64_t pixels; /* h*v: easier to compare */
    char class_inch[12];
} edid_output;

struct edid_std {
    uint8_t *ptr;
    edid_output out;
};

struct edid_dtd {
    edid_addy addy;
    uint8_t cea_ext; /* in a CEA block vs one of the regular EDID descriptors */
    edid_output out;
    uint8_t bounds_ok;
};

struct edid_svd {
    uint8_t v;
    uint8_t is_native;
    edid_output out;
};

struct edid_sad {
    uint8_t v[3];
    uint8_t format, channels, freq_bits;
    int depth_bits; /* format 1 */
    int max_kbps;   /* formats 2-8 */
};

struct edid_cea_block {
    edid_addy addy;
    int type, len;
    uint8_t bounds_ok;
};

struct edid_descriptor {
    edid_addy addy;
    uint8_t type;
    char text[14];
};

struct edid_manf_date {
    uint8_t week;
    uint8_t is_model_year; /* ignore week */
    uint16_t year;
    int std; /* enum STD_* */
};

enum {
    VEN_TYPE_INVALID = 0,
    VEN_TYPE_PNP,
    VEN_TYPE_OUI,
};

typedef struct {
    //TODO: union?
    char pnp[4];
    uint32_t oui;
    uint8_t type; /* enum VEN_TYPE_* */
} edid_ven;

enum {
    STD_EDID         = 0,
    STD_EEDID        = 1,
    STD_EIACEA861    = 2,
    STD_DISPLAYID    = 3,
    STD_DISPLAYID20  = 4,
};

typedef struct _edid {
    union {
        void* data;
        uint8_t* u8;
        uint16_t* u16;
    };
    unsigned int len;

    /* enum STD_* */
    int std;

    uint8_t ver_major, ver_minor;
    uint8_t checksum_ok; /* first 128-byte block only */
    uint8_t ext_blocks, ext_blocks_ok, ext_blocks_fail;
    uint8_t *ext_ok;

    int etb_count;
    edid_output etbs[24];

    int std_count;
    struct edid_std stds[8];

    int dtd_count;
    struct edid_dtd *dtds;

    int cea_block_count;
    struct edid_cea_block *cea_blocks;

    int svd_count;
    struct edid_svd *svds;

    int sad_count;
    struct edid_sad *sads;

    edid_ven ven;
    struct edid_descriptor d[4];
    /* point into d[].text */
    char *name;
    char *serial;
    char *ut1;
    char *ut2;

    uint8_t a_or_d; /* 0 = analog, 1 = digital */
    uint8_t interface; /* digital interface */
    uint8_t bpc;       /* digital bpc */
    uint16_t product;
    uint32_t n_serial;
    struct edid_manf_date dom;
    edid_output img;
    edid_output img_svd;
    edid_output img_max;
    uint32_t speaker_alloc_bits;

    DIExtData di;

    DisplayIDMeta did;
    int did_block_count;
    DisplayIDBlock *did_blocks;
    int did_string_count;
    DisplayIDString *did_strings;

    int didt_count;
    edid_output *didts;

    GString *msg_log;
} edid;
edid *edid_new(const char *data, unsigned int len);
edid *edid_new_from_hex(const char *hex_string);
edid *edid_new_from_file(const char *path);
void edid_free(edid *e);
char *edid_dump_hex(edid *e, int tabs, int breaks);

const char *edid_standard(int std);
const char *edid_output_src(int src);
const char *edid_interface(int type);
const char *edid_di_interface(int type);
const char *edid_descriptor_type(int type);
const char *edid_ext_block_type(int type);
const char *edid_cea_block_type(int type);
const char *edid_cea_audio_type(int type);

char *edid_output_describe(edid_output *out);
char *edid_base_descriptor_describe(struct edid_descriptor *d);
char *edid_dtd_describe(struct edid_dtd *dtd, int dump_bytes);
char *edid_cea_block_describe(struct edid_cea_block *blk);
char *edid_cea_audio_describe(struct edid_sad *sad);
char *edid_cea_speaker_allocation_describe(int bitfield, int short_version);
const char *edid_did_block_type(int type);
char *edid_did_block_describe(DisplayIDBlock *blk);

char *edid_dump2(edid *e);

#endif