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
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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
|
/* Copyright (c) 2017-2018, The Linux Foundation. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* 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.
*/
#include <drm/drm_edid.h>
#include "sde_kms.h"
#include "sde_edid_parser.h"
/* TODO: copy from drm_edid.c and mdss_hdmi_edid.c. remove if using ELD */
#define DBC_START_OFFSET 4
#define EDID_DTD_LEN 18
enum data_block_types {
RESERVED,
AUDIO_DATA_BLOCK,
VIDEO_DATA_BLOCK,
VENDOR_SPECIFIC_DATA_BLOCK,
SPEAKER_ALLOCATION_DATA_BLOCK,
VESA_DTC_DATA_BLOCK,
RESERVED2,
USE_EXTENDED_TAG
};
static u8 *sde_find_edid_extension(struct edid *edid, int ext_id)
{
u8 *edid_ext = NULL;
int i;
/* No EDID or EDID extensions */
if (edid == NULL || edid->extensions == 0)
return NULL;
/* Find CEA extension */
for (i = 0; i < edid->extensions; i++) {
edid_ext = (u8 *)edid + EDID_LENGTH * (i + 1);
if (edid_ext[0] == ext_id)
break;
}
if (i == edid->extensions)
return NULL;
return edid_ext;
}
static u8 *sde_find_cea_extension(struct edid *edid)
{
return sde_find_edid_extension(edid, SDE_CEA_EXT);
}
static int
sde_cea_db_payload_len(const u8 *db)
{
return db[0] & 0x1f;
}
static int
sde_cea_db_tag(const u8 *db)
{
return db[0] >> 5;
}
static int
sde_cea_revision(const u8 *cea)
{
return cea[1];
}
static int
sde_cea_db_offsets(const u8 *cea, int *start, int *end)
{
/* Data block offset in CEA extension block */
*start = 4;
*end = cea[2];
if (*end == 0)
*end = 127;
if (*end < 4 || *end > 127)
return -ERANGE;
return 0;
}
#define sde_for_each_cea_db(cea, i, start, end) \
for ((i) = (start); \
(i) < (end) && (i) + sde_cea_db_payload_len(&(cea)[(i)]) < (end); \
(i) += sde_cea_db_payload_len(&(cea)[(i)]) + 1)
static bool sde_cea_db_is_hdmi_hf_vsdb(const u8 *db)
{
int hdmi_id;
if (sde_cea_db_tag(db) != VENDOR_SPECIFIC_DATA_BLOCK)
return false;
if (sde_cea_db_payload_len(db) < 7)
return false;
hdmi_id = db[1] | (db[2] << 8) | (db[3] << 16);
return hdmi_id == HDMI_IEEE_OUI_HF;
}
static u8 *sde_edid_find_extended_tag_block(struct edid *edid, int blk_id)
{
u8 *db = NULL;
u8 *cea = NULL;
if (!edid) {
pr_err("%s: invalid input\n", __func__);
return NULL;
}
cea = sde_find_cea_extension(edid);
if (cea && sde_cea_revision(cea) >= 3) {
int i, start, end;
if (sde_cea_db_offsets(cea, &start, &end))
return NULL;
sde_for_each_cea_db(cea, i, start, end) {
db = &cea[i];
if ((sde_cea_db_tag(db) == SDE_EXTENDED_TAG) &&
(db[1] == blk_id))
return db;
}
}
return NULL;
}
static u8 *
sde_edid_find_block(struct edid *edid, int blk_id)
{
u8 *db = NULL;
u8 *cea = NULL;
if (!edid) {
pr_err("%s: invalid input\n", __func__);
return NULL;
}
cea = sde_find_cea_extension(edid);
if (cea && sde_cea_revision(cea) >= 3) {
int i, start, end;
if (sde_cea_db_offsets(cea, &start, &end))
return 0;
sde_for_each_cea_db(cea, i, start, end) {
db = &cea[i];
if (sde_cea_db_tag(db) == blk_id)
return db;
}
}
return NULL;
}
static const u8 *_sde_edid_find_block(const u8 *in_buf, u32 start_offset,
u8 type, u8 *len)
{
/* the start of data block collection, start of Video Data Block */
u32 offset = start_offset;
u32 dbc_offset = in_buf[2];
SDE_EDID_DEBUG("%s +", __func__);
/*
* * edid buffer 1, byte 2 being 4 means no non-DTD/Data block
* collection present.
* * edid buffer 1, byte 2 being 0 means no non-DTD/DATA block
* collection present and no DTD data present.
*/
if ((dbc_offset == 0) || (dbc_offset == 4)) {
SDE_ERROR("EDID: no DTD or non-DTD data present\n");
return NULL;
}
while (offset < dbc_offset) {
u8 block_len = in_buf[offset] & 0x1F;
if ((offset + block_len <= dbc_offset) &&
(in_buf[offset] >> 5) == type) {
*len = block_len;
SDE_EDID_DEBUG("block=%d found @ 0x%x w/ len=%d\n",
type, offset, block_len);
return in_buf + offset;
}
offset += 1 + block_len;
}
return NULL;
}
static void sde_edid_extract_vendor_id(struct sde_edid_ctrl *edid_ctrl)
{
char *vendor_id;
u32 id_codes;
SDE_EDID_DEBUG("%s +", __func__);
if (!edid_ctrl) {
SDE_ERROR("%s: invalid input\n", __func__);
return;
}
vendor_id = edid_ctrl->vendor_id;
id_codes = ((u32)edid_ctrl->edid->mfg_id[0] << 8) +
edid_ctrl->edid->mfg_id[1];
vendor_id[0] = 'A' - 1 + ((id_codes >> 10) & 0x1F);
vendor_id[1] = 'A' - 1 + ((id_codes >> 5) & 0x1F);
vendor_id[2] = 'A' - 1 + (id_codes & 0x1F);
vendor_id[3] = 0;
SDE_EDID_DEBUG("vendor id is %s ", vendor_id);
SDE_EDID_DEBUG("%s -", __func__);
}
static void sde_edid_set_y420_support(struct drm_connector *connector,
u32 video_format)
{
u8 cea_mode = 0;
struct drm_display_mode *mode;
u32 mode_fmt_flags = 0;
/* Need to add Y420 support flag to the modes */
list_for_each_entry(mode, &connector->probed_modes, head) {
/* Cache the format flags before clearing */
mode_fmt_flags = mode->flags;
/* Clear the RGB/YUV format flags before calling upstream API */
mode->flags &= ~SDE_DRM_MODE_FLAG_FMT_MASK;
cea_mode = drm_match_cea_mode(mode);
/* Restore the format flags */
mode->flags = mode_fmt_flags;
if ((cea_mode != 0) && (cea_mode == video_format)) {
SDE_EDID_DEBUG("%s found match for %d ", __func__,
video_format);
mode->flags |= DRM_MODE_FLAG_SUPPORTS_YUV;
}
}
}
static void sde_edid_parse_Y420CMDB(
struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl,
const u8 *db)
{
u8 cmdb_len = 0;
u8 svd_len = 0;
const u8 *svd = NULL;
u32 i = 0;
u32 video_format = 0;
u32 num_cmdb_svd = 0;
const u32 mult = 8;
if (!edid_ctrl) {
DEV_ERR("%s: edid_ctrl is NULL\n", __func__);
return;
}
if (!db) {
DEV_ERR("%s: invalid input\n", __func__);
return;
}
SDE_EDID_DEBUG("%s +\n", __func__);
cmdb_len = db[0] & 0x1f;
if (cmdb_len < 1)
return;
svd = sde_edid_find_block(edid_ctrl->edid, VIDEO_DATA_BLOCK);
if (svd) {
/*moving to the next byte as vic info begins there*/
svd_len = svd[0] & 0x1f;
++svd;
}
if (cmdb_len == 1)
num_cmdb_svd = svd_len;
else {
num_cmdb_svd = (cmdb_len - 1) * mult;
if (num_cmdb_svd > svd_len)
num_cmdb_svd = svd_len;
}
for (i = 0; i < num_cmdb_svd; i++) {
video_format = *(svd + i) & 0x7F;
/*
* If cmdb_len is 1, it means all SVDs support YUV
* Else, we check each byte of the cmdb bitmap bitwise
* and match those bits with the formats populated
* during the parsing of the Video Data Blocks.
* Refer to CTA 861-F section 7.5.11 YCBCR 4:2:0 Capability
* Map Data Block for more details on this.
*/
if (cmdb_len == 1 || (db[2 + i / mult] & (1 << (i % mult))))
sde_edid_set_y420_support(connector, video_format);
}
SDE_EDID_DEBUG("%s -\n", __func__);
}
static void sde_edid_parse_Y420VDB(
struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl,
const u8 *db)
{
u8 len = db[0] & 0x1f;
u32 i = 0;
u32 video_format = 0;
if (!edid_ctrl) {
DEV_ERR("%s: invalid input\n", __func__);
return;
}
SDE_EDID_DEBUG("%s +\n", __func__);
/* Offset to byte 3 */
db += 2;
for (i = 0; i < len - 1; i++) {
video_format = *(db + i) & 0x7F;
/*
* mode was already added in get_modes()
* only need to set the Y420 support flag
*/
sde_edid_set_y420_support(connector, video_format);
}
SDE_EDID_DEBUG("%s -", __func__);
}
static void sde_edid_set_mode_format(
struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl)
{
const u8 *db = NULL;
struct drm_display_mode *mode;
SDE_EDID_DEBUG("%s +\n", __func__);
/* Set YUV mode support flags for YCbcr420VDB */
db = sde_edid_find_extended_tag_block(edid_ctrl->edid,
Y420_VIDEO_DATA_BLOCK);
if (db)
sde_edid_parse_Y420VDB(connector, edid_ctrl, db);
else
SDE_EDID_DEBUG("YCbCr420 VDB is not present\n");
/* Set RGB supported on all modes where YUV is not set */
list_for_each_entry(mode, &connector->probed_modes, head) {
if (!(mode->flags & DRM_MODE_FLAG_SUPPORTS_YUV))
mode->flags |= DRM_MODE_FLAG_SUPPORTS_RGB;
}
db = sde_edid_find_extended_tag_block(edid_ctrl->edid,
Y420_CAPABILITY_MAP_DATA_BLOCK);
if (db)
sde_edid_parse_Y420CMDB(connector, edid_ctrl, db);
else
SDE_EDID_DEBUG("YCbCr420 CMDB is not present\n");
/*
* As per HDMI 2.0 spec, a sink supporting any modes
* requiring more than 340Mhz clock rate should support
* SCDC as well. This is required because we need the SCDC
* channel to set the TMDS clock ratio. However in cases
* where the TV publishes such a mode in its list of modes
* but does not have SCDC support as per HDMI HFVSDB block
* remove RGB mode support from the flags. Currently, in
* the list of modes not having deep color support only RGB
* modes shall requre a clock of 340Mhz and above such as the
* 4K@60fps case. All other modes shall be YUV.
* Deep color case is handled separately while choosing the
* best mode in the _sde_hdmi_choose_best_format API where
* we enable deep color only if it satisfies both source and
* sink requirements. However, that API assumes that at least
* RGB mode is supported on the mode. Hence, it would be better
* to remove the format support flags while parsing the EDID
* itself if it doesn't satisfy the HDMI spec requirement.
*/
list_for_each_entry(mode, &connector->probed_modes, head) {
if ((mode->clock > MIN_SCRAMBLER_REQ_RATE) &&
!connector->scdc_present) {
mode->flags &= ~DRM_MODE_FLAG_SUPPORTS_RGB;
}
}
SDE_EDID_DEBUG("%s -\n", __func__);
}
static void _sde_edid_update_dc_modes(
struct drm_connector *connector, struct sde_edid_ctrl *edid_ctrl)
{
int i, start, end;
u8 *edid_ext, *hdmi;
struct drm_display_info *disp_info;
u32 hdmi_dc_yuv_modes = 0;
SDE_EDID_DEBUG("%s +\n", __func__);
if (!connector || !edid_ctrl) {
SDE_ERROR("invalid input\n");
return;
}
disp_info = &connector->display_info;
edid_ext = sde_find_cea_extension(edid_ctrl->edid);
if (!edid_ext) {
SDE_ERROR("no cea extension\n");
return;
}
if (sde_cea_db_offsets(edid_ext, &start, &end))
return;
sde_for_each_cea_db(edid_ext, i, start, end) {
if (sde_cea_db_is_hdmi_hf_vsdb(&edid_ext[i])) {
hdmi = &edid_ext[i];
if (sde_cea_db_payload_len(hdmi) < 7)
continue;
if (hdmi[7] & DRM_EDID_YCBCR420_DC_30) {
hdmi_dc_yuv_modes |= DRM_EDID_YCBCR420_DC_30;
SDE_EDID_DEBUG("Y420 30-bit supported\n");
}
if (hdmi[7] & DRM_EDID_YCBCR420_DC_36) {
hdmi_dc_yuv_modes |= DRM_EDID_YCBCR420_DC_36;
SDE_EDID_DEBUG("Y420 36-bit supported\n");
}
if (hdmi[7] & DRM_EDID_YCBCR420_DC_48) {
hdmi_dc_yuv_modes |= DRM_EDID_YCBCR420_DC_36;
SDE_EDID_DEBUG("Y420 48-bit supported\n");
}
}
}
disp_info->edid_hdmi_dc_modes |= hdmi_dc_yuv_modes;
SDE_EDID_DEBUG("%s -\n", __func__);
}
static void _sde_edid_extract_audio_data_blocks(
struct sde_edid_ctrl *edid_ctrl)
{
u8 len = 0;
u8 adb_max = 0;
const u8 *adb = NULL;
u32 offset = DBC_START_OFFSET;
u8 *cea = NULL;
if (!edid_ctrl) {
SDE_ERROR("invalid edid_ctrl\n");
return;
}
SDE_EDID_DEBUG("%s +", __func__);
cea = sde_find_cea_extension(edid_ctrl->edid);
if (!cea) {
SDE_DEBUG("CEA extension not found\n");
return;
}
edid_ctrl->adb_size = 0;
memset(edid_ctrl->audio_data_block, 0,
sizeof(edid_ctrl->audio_data_block));
do {
len = 0;
adb = _sde_edid_find_block(cea, offset, AUDIO_DATA_BLOCK,
&len);
if ((adb == NULL) || (len > MAX_AUDIO_DATA_BLOCK_SIZE ||
adb_max >= MAX_NUMBER_ADB)) {
if (!edid_ctrl->adb_size) {
SDE_DEBUG("No/Invalid Audio Data Block\n");
return;
}
continue;
}
memcpy(edid_ctrl->audio_data_block + edid_ctrl->adb_size,
adb + 1, len);
offset = (adb - cea) + 1 + len;
edid_ctrl->adb_size += len;
adb_max++;
} while (adb);
SDE_EDID_DEBUG("%s -", __func__);
}
static void _sde_edid_extract_speaker_allocation_data(
struct sde_edid_ctrl *edid_ctrl)
{
u8 len;
const u8 *sadb = NULL;
u8 *cea = NULL;
if (!edid_ctrl) {
SDE_ERROR("invalid edid_ctrl\n");
return;
}
SDE_EDID_DEBUG("%s +", __func__);
cea = sde_find_cea_extension(edid_ctrl->edid);
if (!cea) {
SDE_DEBUG("CEA extension not found\n");
return;
}
sadb = _sde_edid_find_block(cea, DBC_START_OFFSET,
SPEAKER_ALLOCATION_DATA_BLOCK, &len);
if ((sadb == NULL) || (len != MAX_SPKR_ALLOC_DATA_BLOCK_SIZE)) {
SDE_DEBUG("No/Invalid Speaker Allocation Data Block\n");
return;
}
memcpy(edid_ctrl->spkr_alloc_data_block, sadb + 1, len);
edid_ctrl->sadb_size = len;
SDE_EDID_DEBUG("speaker alloc data SP byte = %08x %s%s%s%s%s%s%s\n",
sadb[1],
(sadb[1] & BIT(0)) ? "FL/FR," : "",
(sadb[1] & BIT(1)) ? "LFE," : "",
(sadb[1] & BIT(2)) ? "FC," : "",
(sadb[1] & BIT(3)) ? "RL/RR," : "",
(sadb[1] & BIT(4)) ? "RC," : "",
(sadb[1] & BIT(5)) ? "FLC/FRC," : "",
(sadb[1] & BIT(6)) ? "RLC/RRC," : "");
SDE_EDID_DEBUG("%s -", __func__);
}
struct sde_edid_ctrl *sde_edid_init(void)
{
struct sde_edid_ctrl *edid_ctrl = NULL;
SDE_EDID_DEBUG("%s +\n", __func__);
edid_ctrl = kzalloc(sizeof(*edid_ctrl), GFP_KERNEL);
if (!edid_ctrl) {
SDE_ERROR("edid_ctrl alloc failed\n");
return NULL;
}
memset((edid_ctrl), 0, sizeof(*edid_ctrl));
SDE_EDID_DEBUG("%s -\n", __func__);
return edid_ctrl;
}
void sde_free_edid(void **input)
{
struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(*input);
SDE_EDID_DEBUG("%s +", __func__);
kfree(edid_ctrl->edid);
edid_ctrl->edid = NULL;
}
void sde_edid_deinit(void **input)
{
struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(*input);
SDE_EDID_DEBUG("%s +", __func__);
sde_free_edid((void *)&edid_ctrl);
kfree(edid_ctrl);
SDE_EDID_DEBUG("%s -", __func__);
}
int _sde_edid_update_modes(struct drm_connector *connector,
void *input)
{
int rc = 0;
struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(input);
struct drm_display_info *disp_info;
disp_info = &connector->display_info;
if (disp_info)
disp_info->edid_hdmi_dc_modes = 0;
SDE_EDID_DEBUG("%s +", __func__);
if (edid_ctrl->edid) {
drm_mode_connector_update_edid_property(connector,
edid_ctrl->edid);
rc = drm_add_edid_modes(connector, edid_ctrl->edid);
sde_edid_set_mode_format(connector, edid_ctrl);
_sde_edid_update_dc_modes(connector, edid_ctrl);
SDE_EDID_DEBUG("%s -", __func__);
return rc;
}
drm_mode_connector_update_edid_property(connector, NULL);
SDE_EDID_DEBUG("%s null edid -", __func__);
return rc;
}
bool sde_detect_hdmi_monitor(void *input)
{
struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(input);
return drm_detect_hdmi_monitor(edid_ctrl->edid);
}
void sde_get_edid(struct drm_connector *connector,
struct i2c_adapter *adapter, void **input)
{
struct sde_edid_ctrl *edid_ctrl = (struct sde_edid_ctrl *)(*input);
edid_ctrl->edid = drm_get_edid(connector, adapter);
SDE_EDID_DEBUG("%s +\n", __func__);
if (!edid_ctrl->edid)
SDE_ERROR("EDID read failed\n");
if (edid_ctrl->edid) {
sde_edid_extract_vendor_id(edid_ctrl);
_sde_edid_extract_audio_data_blocks(edid_ctrl);
_sde_edid_extract_speaker_allocation_data(edid_ctrl);
}
SDE_EDID_DEBUG("%s -\n", __func__);
};
|