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#include "mod_info_packet.h"
27#include "core_types.h"
28#include "dc_types.h"
29#include "mod_shared.h"
30#include "mod_freesync.h"
31#include "dc.h"
32
33enum vsc_packet_revision {
34 vsc_packet_undefined = 0,
35
36 vsc_packet_rev1 = 1,
37
38 vsc_packet_rev2 = 2,
39
40 vsc_packet_rev3 = 3,
41
42 vsc_packet_rev4 = 4,
43
44 vsc_packet_rev5 = 5,
45};
46
47#define HDMI_INFOFRAME_TYPE_VENDOR 0x81
48#define HF_VSIF_VERSION 1
49
50
51#define VTEM_PB0 0
52#define VTEM_PB1 1
53#define VTEM_PB2 2
54#define VTEM_PB3 3
55#define VTEM_PB4 4
56#define VTEM_PB5 5
57#define VTEM_PB6 6
58
59#define VTEM_MD0 7
60#define VTEM_MD1 8
61#define VTEM_MD2 9
62#define VTEM_MD3 10
63
64
65
66
67#define MASK_VTEM_PB0__RESERVED0 0x01
68#define MASK_VTEM_PB0__SYNC 0x02
69#define MASK_VTEM_PB0__VFR 0x04
70#define MASK_VTEM_PB0__AFR 0x08
71#define MASK_VTEM_PB0__DS_TYPE 0x30
72
73
74
75
76#define MASK_VTEM_PB0__END 0x40
77#define MASK_VTEM_PB0__NEW 0x80
78
79
80#define MASK_VTEM_PB1__RESERVED1 0xFF
81
82
83#define MASK_VTEM_PB2__ORGANIZATION_ID 0xFF
84
85
86
87
88
89#define MASK_VTEM_PB3__DATA_SET_TAG_MSB 0xFF
90
91#define MASK_VTEM_PB4__DATA_SET_TAG_LSB 0xFF
92
93#define MASK_VTEM_PB5__DATA_SET_LENGTH_MSB 0xFF
94
95#define MASK_VTEM_PB6__DATA_SET_LENGTH_LSB 0xFF
96
97
98
99
100
101#define MASK_VTEM_MD0__VRR_EN 0x01
102#define MASK_VTEM_MD0__M_CONST 0x02
103#define MASK_VTEM_MD0__QMS_EN 0x04
104#define MASK_VTEM_MD0__RESERVED2 0x08
105#define MASK_VTEM_MD0__FVA_FACTOR_M1 0xF0
106
107
108#define MASK_VTEM_MD1__BASE_VFRONT 0xFF
109
110
111#define MASK_VTEM_MD2__BASE_REFRESH_RATE_98 0x03
112#define MASK_VTEM_MD2__RB 0x04
113#define MASK_VTEM_MD2__NEXT_TFR 0xF8
114
115
116#define MASK_VTEM_MD3__BASE_REFRESH_RATE_07 0xFF
117
118enum ColorimetryRGBDP {
119 ColorimetryRGB_DP_sRGB = 0,
120 ColorimetryRGB_DP_AdobeRGB = 3,
121 ColorimetryRGB_DP_P3 = 4,
122 ColorimetryRGB_DP_CustomColorProfile = 5,
123 ColorimetryRGB_DP_ITU_R_BT2020RGB = 6,
124};
125enum ColorimetryYCCDP {
126 ColorimetryYCC_DP_ITU601 = 0,
127 ColorimetryYCC_DP_ITU709 = 1,
128 ColorimetryYCC_DP_AdobeYCC = 5,
129 ColorimetryYCC_DP_ITU2020YCC = 6,
130 ColorimetryYCC_DP_ITU2020YCbCr = 7,
131};
132
133void mod_build_vsc_infopacket(const struct dc_stream_state *stream,
134 struct dc_info_packet *info_packet,
135 enum dc_color_space cs)
136{
137 unsigned int vsc_packet_revision = vsc_packet_undefined;
138 unsigned int i;
139 unsigned int pixelEncoding = 0;
140 unsigned int colorimetryFormat = 0;
141 bool stereo3dSupport = false;
142
143 if (stream->timing.timing_3d_format != TIMING_3D_FORMAT_NONE && stream->view_format != VIEW_3D_FORMAT_NONE) {
144 vsc_packet_revision = vsc_packet_rev1;
145 stereo3dSupport = true;
146 }
147
148
149 if (stream->link->psr_settings.psr_version != DC_PSR_VERSION_UNSUPPORTED)
150 vsc_packet_revision = vsc_packet_rev2;
151
152
153 if (stream->use_vsc_sdp_for_colorimetry)
154 vsc_packet_revision = vsc_packet_rev5;
155
156
157
158
159 if (vsc_packet_revision == vsc_packet_undefined)
160 return;
161
162 if (vsc_packet_revision == vsc_packet_rev2) {
163
164 info_packet->hb0 = 0x00;
165
166
167
168 info_packet->hb1 = 0x07;
169
170
171
172 info_packet->hb2 = 0x02;
173
174
175
176 info_packet->hb3 = 0x08;
177
178 for (i = 0; i < 28; i++)
179 info_packet->sb[i] = 0;
180
181 info_packet->valid = true;
182 }
183
184 if (vsc_packet_revision == vsc_packet_rev1) {
185
186 info_packet->hb0 = 0x00;
187 info_packet->hb1 = 0x07;
188 info_packet->hb2 = 0x01;
189 info_packet->hb3 = 0x01;
190
191 info_packet->valid = true;
192 }
193
194 if (stereo3dSupport) {
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 switch (stream->timing.timing_3d_format) {
223 case TIMING_3D_FORMAT_HW_FRAME_PACKING:
224 case TIMING_3D_FORMAT_SW_FRAME_PACKING:
225 case TIMING_3D_FORMAT_TOP_AND_BOTTOM:
226 case TIMING_3D_FORMAT_TB_SW_PACKED:
227 info_packet->sb[0] = 0x02;
228 break;
229 case TIMING_3D_FORMAT_DP_HDMI_INBAND_FA:
230 case TIMING_3D_FORMAT_INBAND_FA:
231 info_packet->sb[0] = 0x01;
232 break;
233 case TIMING_3D_FORMAT_SIDE_BY_SIDE:
234 case TIMING_3D_FORMAT_SBS_SW_PACKED:
235 info_packet->sb[0] = 0x04;
236 break;
237 default:
238 info_packet->sb[0] = 0x00;
239 break;
240 }
241
242 }
243
244
245
246
247
248
249
250
251
252
253
254
255 if (vsc_packet_revision == vsc_packet_rev5) {
256
257 info_packet->hb0 = 0x00;
258
259 info_packet->hb1 = 0x07;
260
261 info_packet->hb2 = 0x05;
262
263 info_packet->hb3 = 0x13;
264
265 info_packet->valid = true;
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315 switch (stream->timing.pixel_encoding) {
316 case PIXEL_ENCODING_RGB:
317 pixelEncoding = 0x0;
318 break;
319 case PIXEL_ENCODING_YCBCR444:
320 pixelEncoding = 0x1;
321 break;
322 case PIXEL_ENCODING_YCBCR422:
323 pixelEncoding = 0x2;
324 break;
325 case PIXEL_ENCODING_YCBCR420:
326 pixelEncoding = 0x3;
327 break;
328 default:
329 pixelEncoding = 0x0;
330 break;
331 }
332
333
334 switch (stream->timing.pixel_encoding) {
335 case PIXEL_ENCODING_RGB:
336 if ((cs == COLOR_SPACE_SRGB) ||
337 (cs == COLOR_SPACE_SRGB_LIMITED))
338 colorimetryFormat = ColorimetryRGB_DP_sRGB;
339 else if (cs == COLOR_SPACE_ADOBERGB)
340 colorimetryFormat = ColorimetryRGB_DP_AdobeRGB;
341 else if ((cs == COLOR_SPACE_2020_RGB_FULLRANGE) ||
342 (cs == COLOR_SPACE_2020_RGB_LIMITEDRANGE))
343 colorimetryFormat = ColorimetryRGB_DP_ITU_R_BT2020RGB;
344 break;
345
346 case PIXEL_ENCODING_YCBCR444:
347 case PIXEL_ENCODING_YCBCR422:
348 case PIXEL_ENCODING_YCBCR420:
349
350
351
352 if (cs == COLOR_SPACE_YCBCR601)
353 colorimetryFormat = ColorimetryYCC_DP_ITU601;
354 else if (cs == COLOR_SPACE_YCBCR709)
355 colorimetryFormat = ColorimetryYCC_DP_ITU709;
356 else if (cs == COLOR_SPACE_ADOBERGB)
357 colorimetryFormat = ColorimetryYCC_DP_AdobeYCC;
358 else if (cs == COLOR_SPACE_2020_YCBCR)
359 colorimetryFormat = ColorimetryYCC_DP_ITU2020YCbCr;
360 break;
361
362 default:
363 colorimetryFormat = ColorimetryRGB_DP_sRGB;
364 break;
365 }
366
367 info_packet->sb[16] = (pixelEncoding << 4) | colorimetryFormat;
368
369
370 switch (stream->timing.display_color_depth) {
371 case COLOR_DEPTH_666:
372
373
374
375 info_packet->sb[17] = 0;
376 break;
377 case COLOR_DEPTH_888:
378 info_packet->sb[17] = 1;
379 break;
380 case COLOR_DEPTH_101010:
381 info_packet->sb[17] = 2;
382 break;
383 case COLOR_DEPTH_121212:
384 info_packet->sb[17] = 3;
385 break;
386
387 case COLOR_DEPTH_161616:
388 info_packet->sb[17] = 4;
389 break;
390 default:
391 info_packet->sb[17] = 0;
392 break;
393 }
394
395
396 if ((cs == COLOR_SPACE_SRGB_LIMITED) ||
397 (cs == COLOR_SPACE_2020_RGB_LIMITEDRANGE) ||
398 (pixelEncoding != 0x0)) {
399 info_packet->sb[17] |= 0x80;
400 }
401
402
403
404
405
406
407
408
409 info_packet->sb[18] = 0;
410 }
411}
412
413
414
415
416
417
418
419
420void mod_build_hf_vsif_infopacket(const struct dc_stream_state *stream,
421 struct dc_info_packet *info_packet)
422{
423 unsigned int length = 5;
424 bool hdmi_vic_mode = false;
425 uint8_t checksum = 0;
426 uint32_t i = 0;
427 enum dc_timing_3d_format format;
428
429 info_packet->valid = false;
430 format = stream->timing.timing_3d_format;
431 if (stream->view_format == VIEW_3D_FORMAT_NONE)
432 format = TIMING_3D_FORMAT_NONE;
433
434 if (stream->timing.hdmi_vic != 0
435 && stream->timing.h_total >= 3840
436 && stream->timing.v_total >= 2160
437 && format == TIMING_3D_FORMAT_NONE)
438 hdmi_vic_mode = true;
439
440 if ((format == TIMING_3D_FORMAT_NONE) && !hdmi_vic_mode)
441 return;
442
443 info_packet->sb[1] = 0x03;
444 info_packet->sb[2] = 0x0C;
445 info_packet->sb[3] = 0x00;
446
447 if (format != TIMING_3D_FORMAT_NONE)
448 info_packet->sb[4] = (2 << 5);
449
450 else if (hdmi_vic_mode)
451 info_packet->sb[4] = (1 << 5);
452
453 switch (format) {
454 case TIMING_3D_FORMAT_HW_FRAME_PACKING:
455 case TIMING_3D_FORMAT_SW_FRAME_PACKING:
456 info_packet->sb[5] = (0x0 << 4);
457 break;
458
459 case TIMING_3D_FORMAT_SIDE_BY_SIDE:
460 case TIMING_3D_FORMAT_SBS_SW_PACKED:
461 info_packet->sb[5] = (0x8 << 4);
462 length = 6;
463 break;
464
465 case TIMING_3D_FORMAT_TOP_AND_BOTTOM:
466 case TIMING_3D_FORMAT_TB_SW_PACKED:
467 info_packet->sb[5] = (0x6 << 4);
468 break;
469
470 default:
471 break;
472 }
473
474 if (hdmi_vic_mode)
475 info_packet->sb[5] = stream->timing.hdmi_vic;
476
477 info_packet->hb0 = HDMI_INFOFRAME_TYPE_VENDOR;
478 info_packet->hb1 = 0x01;
479 info_packet->hb2 = (uint8_t) (length);
480
481 checksum += info_packet->hb0;
482 checksum += info_packet->hb1;
483 checksum += info_packet->hb2;
484
485 for (i = 1; i <= length; i++)
486 checksum += info_packet->sb[i];
487
488 info_packet->sb[0] = (uint8_t) (0x100 - checksum);
489
490 info_packet->valid = true;
491}
492
493