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
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
|
/*
* Copyright (C) 2012 Google, Inc.
*
* This software is licensed under the terms of the GNU General Public
* License version 2, as published by the Free Software Foundation, and
* may be copied, distributed, and modified under those terms.
*
* 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 <linux/i2c.h>
#include <linux/delay.h>
#include <linux/fb.h>
#include <linux/sched.h>
#include <linux/workqueue.h>
#include <linux/module.h>
#include <uapi/linux/v4l2-dv-timings.h>
#include "hdmi.h"
#define EDID_SEGMENT_ADDR (0x60 >> 1)
#define EDID_ADDR (0xA0 >> 1)
#define EDID_SEGMENT_IGNORE (2)
#define EDID_BLOCK_SIZE 128
#define EDID_SEGMENT(x) ((x) >> 1)
#define EDID_OFFSET(x) (((x) & 1) * EDID_BLOCK_SIZE)
#define EDID_EXTENSION_FLAG 0x7E
#define EDID_NATIVE_FORMAT 0x83
#define EDID_BASIC_AUDIO (1 << 6)
#define EDID_3D_STRUCTURE_ALL 0x1
#define EDID_3D_STRUCTURE_MASK 0x2
#define EDID_3D_FP_MASK (1)
#define EDID_3D_TB_MASK (1 << 6)
#define EDID_3D_SBS_MASK (1 << 8)
#define EDID_3D_FP 0
#define EDID_3D_TB 6
#define EDID_3D_SBS 8
#ifdef CONFIG_OF
static const struct of_device_id edid_device_table[] = {
{ .compatible = "samsung,exynos5-edid_driver" },
{},
};
MODULE_DEVICE_TABLE(of, edid_device_table);
#endif
static struct i2c_client *edid_client;
/* Structure for Checking 3D Mandatory Format in EDID */
static const struct edid_3d_mandatory_preset {
struct v4l2_dv_timings dv_timings;
u16 xres;
u16 yres;
u16 refresh;
u32 vmode;
u32 s3d;
} edid_3d_mandatory_presets[] = {
{ V4L2_DV_BT_CEA_1280X720P60_FP, 1280, 720, 60, FB_VMODE_NONINTERLACED, EDID_3D_FP },
{ V4L2_DV_BT_CEA_1280X720P60_TB, 1280, 720, 60, FB_VMODE_NONINTERLACED, EDID_3D_TB },
{ V4L2_DV_BT_CEA_1280X720P50_FP, 1280, 720, 50, FB_VMODE_NONINTERLACED, EDID_3D_FP },
{ V4L2_DV_BT_CEA_1280X720P50_TB, 1280, 720, 50, FB_VMODE_NONINTERLACED, EDID_3D_TB },
{ V4L2_DV_BT_CEA_1920X1080P24_FP, 1920, 1080, 24, FB_VMODE_NONINTERLACED, EDID_3D_FP },
{ V4L2_DV_BT_CEA_1920X1080P24_TB, 1920, 1080, 24, FB_VMODE_NONINTERLACED, EDID_3D_TB },
};
static struct edid_preset {
struct v4l2_dv_timings dv_timings;
u16 xres;
u16 yres;
u16 refresh;
u32 vmode;
char *name;
bool supported;
} edid_presets[] = {
{ V4L2_DV_BT_CEA_720X480P59_94, 720, 480, 59, FB_VMODE_NONINTERLACED, "480p@59.94" },
{ V4L2_DV_BT_CEA_720X576P50, 720, 576, 50, FB_VMODE_NONINTERLACED, "576p@50" },
{ V4L2_DV_BT_CEA_1280X720P50, 1280, 720, 50, FB_VMODE_NONINTERLACED, "720p@50" },
{ V4L2_DV_BT_CEA_1280X720P60, 1280, 720, 60, FB_VMODE_NONINTERLACED, "720p@60" },
{ V4L2_DV_BT_CEA_1920X1080P24, 1920, 1080, 24, FB_VMODE_NONINTERLACED, "1080p@24" },
{ V4L2_DV_BT_CEA_1920X1080P25, 1920, 1080, 25, FB_VMODE_NONINTERLACED, "1080p@25" },
{ V4L2_DV_BT_CEA_1920X1080P30, 1920, 1080, 30, FB_VMODE_NONINTERLACED, "1080p@30" },
{ V4L2_DV_BT_CEA_1920X1080P50, 1920, 1080, 50, FB_VMODE_NONINTERLACED, "1080p@50" },
{ V4L2_DV_BT_CEA_1920X1080P60, 1920, 1080, 60, FB_VMODE_NONINTERLACED, "1080p@60" },
{ V4L2_DV_BT_CEA_3840X2160P24, 3840, 2160, 24, FB_VMODE_NONINTERLACED, "2160p@24" },
{ V4L2_DV_BT_CEA_3840X2160P25, 3840, 2160, 25, FB_VMODE_NONINTERLACED, "2160p@25" },
{ V4L2_DV_BT_CEA_3840X2160P30, 3840, 2160, 30, FB_VMODE_NONINTERLACED, "2160p@30" },
{ V4L2_DV_BT_CEA_4096X2160P24, 4096, 2160, 24, FB_VMODE_NONINTERLACED, "(4096x)2160p@24" },
#ifndef CONFIG_SEC_MHL_SUPPORT
{ V4L2_DV_BT_CEA_1920X1080I50, 1920, 1080, 50, FB_VMODE_INTERLACED, "1080i@50" },
{ V4L2_DV_BT_CEA_1920X1080I60, 1920, 1080, 60, FB_VMODE_INTERLACED, "1080i@60" },
#endif
};
static struct edid_3d_preset {
struct v4l2_dv_timings dv_timings;
u16 xres;
u16 yres;
u16 refresh;
u32 vmode;
u32 s3d;
char *name;
bool supported;
} edid_3d_presets[] = {
{ V4L2_DV_BT_CEA_1280X720P60_SB_HALF, 1280, 720, 60,
FB_VMODE_NONINTERLACED, EDID_3D_SBS, "720p@60_SBS" },
{ V4L2_DV_BT_CEA_1280X720P60_TB, 1280, 720, 60,
FB_VMODE_NONINTERLACED, EDID_3D_TB, "720p@60_TB" },
{ V4L2_DV_BT_CEA_1280X720P50_SB_HALF, 1280, 720, 50,
FB_VMODE_NONINTERLACED, EDID_3D_SBS, "720p@50_SBS" },
{ V4L2_DV_BT_CEA_1280X720P50_TB, 1280, 720, 50,
FB_VMODE_NONINTERLACED, EDID_3D_TB, "720p@50_TB" },
{ V4L2_DV_BT_CEA_1920X1080P24_FP, 1920, 1080, 24,
FB_VMODE_NONINTERLACED, EDID_3D_FP, "1080p@24_FP" },
{ V4L2_DV_BT_CEA_1920X1080P24_SB_HALF, 1920, 1080, 24,
FB_VMODE_NONINTERLACED, EDID_3D_SBS, "1080p@24_SBS" },
{ V4L2_DV_BT_CEA_1920X1080P24_TB, 1920, 1080, 24,
FB_VMODE_NONINTERLACED, EDID_3D_TB, "1080p@24_TB" },
{ V4L2_DV_BT_CEA_1920X1080I60_SB_HALF, 1920, 1080, 60,
FB_VMODE_INTERLACED, EDID_3D_SBS, "1080i@60_SBS" },
{ V4L2_DV_BT_CEA_1920X1080I50_SB_HALF, 1920, 1080, 50,
FB_VMODE_INTERLACED, EDID_3D_SBS, "1080i@50_SBS" },
{ V4L2_DV_BT_CEA_1920X1080P60_SB_HALF, 1920, 1080, 60,
FB_VMODE_NONINTERLACED, EDID_3D_SBS, "1080p@60_SBS" },
{ V4L2_DV_BT_CEA_1920X1080P60_TB, 1920, 1080, 60,
FB_VMODE_NONINTERLACED, EDID_3D_TB, "1080p@60_TB" },
{ V4L2_DV_BT_CEA_1920X1080P30_SB_HALF, 1920, 1080, 30,
FB_VMODE_NONINTERLACED, EDID_3D_SBS, "1080p@30_SBS" },
{ V4L2_DV_BT_CEA_1920X1080P30_TB, 1920, 1080, 30,
FB_VMODE_NONINTERLACED, EDID_3D_TB, "1080p@30_TB" },
};
static struct v4l2_dv_timings preferred_preset;
static u32 edid_misc;
static int max_audio_channels;
static int audio_bit_rates;
static int audio_sample_rates;
static u32 source_phy_addr;
#ifdef CONFIG_SEC_MHL_EDID
static u8 exynos_hdmi_edid[EDID_MAX_LENGTH];
static enum MHL_MAX_RESOLUTION mhl_max_res = MHL_1080P_30;
int hdmi_forced_resolution = -1;
int hdmi_get_datablock_offset(u8 *edid, enum extension_edid_db datablock,
int *offset)
{
int i = 0, length = 0;
u8 current_byte, disp;
if (edid[0x7e] == 0x00)
return 1;
disp = edid[(0x80) + 2];
pr_info("HDMI: Extension block present db %d %x\n", datablock, disp);
if (disp == 0x4)
return 1;
i = 0x80 + 0x4;
while (i < (0x80 + disp)) {
current_byte = edid[i];
if ((current_byte >> 5) == datablock) {
*offset = i;
pr_info("HDMI: datablock %d %d\n", datablock, *offset);
return 0;
} else {
length = (current_byte &
HDMI_EDID_EX_DATABLOCK_LEN_MASK) + 1;
i += length;
}
}
return 1;
}
int hdmi_send_audio_info(int onoff, struct hdmi_device *hdev)
{
int offset, j = 0, length = 0;
enum extension_edid_db vsdb;
u16 audio_info = 0, data_byte = 0;
char *edid = (char *) exynos_hdmi_edid;
if (onoff) {
/* get audio channel info */
vsdb = DATABLOCK_AUDIO;
if (!hdmi_get_datablock_offset(edid, vsdb, &offset)) {
data_byte = edid[offset];
length = data_byte & HDMI_EDID_EX_DATABLOCK_LEN_MASK;
if (length >= HDMI_AUDIO_FORMAT_MAX_LENGTH)
length = HDMI_AUDIO_FORMAT_MAX_LENGTH;
for (j = 1 ; j < length ; j++) {
if (j%3 == 1) {
data_byte = edid[offset + j];
audio_info |= 1 << (data_byte & 0x07);
}
}
pr_info("HDMI: Audio supported ch = %d\n", audio_info);
}
/* get speaker info */
vsdb = DATABLOCK_SPEAKERS;
if (!hdmi_get_datablock_offset(edid, vsdb, &offset)) {
data_byte = edid[offset + 1];
pr_info("HDMI: speaker alloc = %d\n",
(data_byte & 0x7F));
audio_info |= (data_byte & 0x7F) << 8;
}
pr_info("HDMI: Audio info = %d\n", audio_info);
}
return audio_info;
}
#ifdef CONFIG_SAMSUNG_MHL_8240
int exynos_get_edid(u8 *edid, int size, u8 link_mode)
{
mhl_max_res = MHL_1080P_30;
pr_info("%s: size=%d\n", __func__, size);
if (size > EDID_MAX_LENGTH) {
pr_err("%s: size is over %d\n", __func__, size);
return -1;
}
memcpy(exynos_hdmi_edid, edid, size);
if (!(link_mode & (0x1 << 3)))
mhl_max_res = MHL_1080P_30;
else
mhl_max_res = MHL_1080P_60;
pr_info("%s, link_mode= %d max_resolution %d\n", __func__, link_mode, mhl_max_res);
return 0;
}
EXPORT_SYMBOL(exynos_get_edid);
#else /* CONFIG_SAMSUNG_MHL_8240 */
enum MHL_MAX_RESOLUTION check_mhl_max_resolution(u8 mhl_ver, int
mhl_link_mode, int tmds_speed)
{
bool support_ppixel_mode =
mhl_link_mode & MHL_DEV_VID_LINK_SUPP_PPIXEL ? true : false;
bool support_16ppixel_mode =
mhl_link_mode & MHL_DEV_VID_LINK_SUPP_16BPP ? true : false;
if (mhl_ver < 0x20 && !support_ppixel_mode)
return MHL_1080P_30;
else if (mhl_ver < 0x30 && support_ppixel_mode)
return MHL_1080P_60;
else if (mhl_ver >= 0x30) {
if (tmds_speed == MHL_XDC_TMDS_150)
return MHL_576P_50;
else if (tmds_speed == MHL_XDC_TMDS_300)
return MHL_1080P_30;
else if (!support_16ppixel_mode)
return MHL_1080P_60;
else
return MHL_UHD;
}
return MHL_1080P_60;
}
int exynos_get_edid(u8 *edid, int size, u8 mhl_ver, int mhl_link_mode,
int tmds_speed)
{
mhl_max_res = MHL_1080P_30;
if (size > EDID_MAX_LENGTH) {
pr_err("%s: size is over %d\n", __func__, size);
return -1;
}
memcpy(exynos_hdmi_edid, edid, size);
mhl_max_res = check_mhl_max_resolution(mhl_ver, mhl_link_mode, tmds_speed);
pr_info("%s, mhl_ver 0x%02x link_mode= %d tmds_speed= %d max_resolution %d\n",
__func__, mhl_ver, mhl_link_mode, tmds_speed, mhl_max_res);
return 0;
}
EXPORT_SYMBOL(exynos_get_edid);
#endif /* CONFIG_SAMSUNG_MHL_8240 */
#else /* CONFIG_SEC_MHL_EDID */
static int edid_i2c_read(struct hdmi_device *hdev, u8 segment, u8 offset,
u8 *buf, size_t len)
{
struct device *dev = hdev->dev;
struct i2c_client *i2c = edid_client;
int cnt = 0;
int ret;
struct i2c_msg msg[] = {
{
.addr = EDID_SEGMENT_ADDR,
.flags = segment ? 0 : I2C_M_IGNORE_NAK,
.len = 1,
.buf = &segment
},
{
.addr = EDID_ADDR,
.flags = 0,
.len = 1,
.buf = &offset
},
{
.addr = EDID_ADDR,
.flags = I2C_M_RD,
.len = len,
.buf = buf
}
};
if (!i2c)
return -ENODEV;
do {
/*
* If the HS-I2C is used for DDC(EDID),
* shouldn't write the segment pointer.
*/
if (hdev->ip_ver == IP_VER_TV_7I) {
ret = i2c_transfer(i2c->adapter, &msg[1],
EDID_SEGMENT_IGNORE);
if (ret == EDID_SEGMENT_IGNORE)
break;
} else {
ret = i2c_transfer(i2c->adapter, msg, ARRAY_SIZE(msg));
if (ret == ARRAY_SIZE(msg))
break;
}
dev_dbg(dev, "%s: can't read data, retry %d\n", __func__, cnt);
msleep(25);
cnt++;
} while (cnt < 5);
if (cnt == 5) {
dev_err(dev, "%s: can't read data, timeout\n", __func__);
return -ETIME;
}
return 0;
}
static int
edid_read_block(struct hdmi_device *hdev, int block, u8 *buf, size_t len)
{
struct device *dev = hdev->dev;
int ret, i;
u8 segment = EDID_SEGMENT(block);
u8 offset = EDID_OFFSET(block);
u8 sum = 0;
if (len < EDID_BLOCK_SIZE)
return -EINVAL;
ret = edid_i2c_read(hdev, segment, offset, buf, EDID_BLOCK_SIZE);
if (ret)
return ret;
for (i = 0; i < EDID_BLOCK_SIZE; i++)
sum += buf[i];
if (sum) {
dev_err(dev, "%s: checksum error block=%d sum=%d\n", __func__,
block, sum);
return -EPROTO;
}
return 0;
}
#endif /* CONFIG_SEC_MHL_EDID */
static int edid_read(struct hdmi_device *hdev, u8 **data)
{
#ifdef CONFIG_SEC_MHL_EDID
*data = exynos_hdmi_edid;
return 1 + (s8)exynos_hdmi_edid[0x7e];
#else
u8 block0[EDID_BLOCK_SIZE];
u8 *edid;
int block = 0;
int block_cnt, ret;
ret = edid_read_block(hdev, 0, block0, sizeof(block0));
if (ret)
return ret;
block_cnt = block0[EDID_EXTENSION_FLAG] + 1;
edid = kmalloc(block_cnt * EDID_BLOCK_SIZE, GFP_KERNEL);
if (!edid)
return -ENOMEM;
memcpy(edid, block0, sizeof(block0));
while (++block < block_cnt) {
ret = edid_read_block(hdev, block,
edid + block * EDID_BLOCK_SIZE,
EDID_BLOCK_SIZE);
if ((edid[EDID_NATIVE_FORMAT] & EDID_BASIC_AUDIO) >> 6)
edid_misc = FB_MISC_HDMI;
if (ret) {
kfree(edid);
return ret;
}
}
*data = edid;
return block_cnt;
#endif /* CONFIG_SEC_MHL_EDID */
}
static unsigned int get_ud_timing(struct fb_vendor *vsdb, unsigned int vic_idx)
{
unsigned char val = 0;
unsigned int idx = 0;
val = vsdb->vic_data[vic_idx];
switch (val) {
case 0x01:
idx = 0;
break;
case 0x02:
idx = 1;
break;
case 0x03:
idx = 2;
break;
case 0x04:
idx = 3;
break;
}
return idx;
}
static struct edid_preset *edid_find_preset(const struct fb_videomode *mode)
{
struct edid_preset *preset = edid_presets;
int i;
for (i = 0; i < ARRAY_SIZE(edid_presets); i++, preset++) {
#ifdef CONFIG_SEC_MHL_EDID
if (mhl_max_res == MHL_576P_50 && !(strncmp(preset->name, "720p@50", 10)))
return NULL;
else if (mhl_max_res == MHL_1080P_30 && !(strncmp(preset->name, "1080p@50", 10)))
return NULL;
else if (mhl_max_res == MHL_1080P_60 && !(strncmp(preset->name, "2160p@24", 10)))
return NULL;
#endif
if (mode->refresh == preset->refresh &&
mode->xres == preset->xres &&
mode->yres == preset->yres &&
mode->vmode == preset->vmode) {
return preset;
}
}
return NULL;
}
static struct edid_3d_preset *edid_find_3d_mandatory_preset(const struct
edid_3d_mandatory_preset *mandatory)
{
struct edid_3d_preset *s3d_preset = edid_3d_presets;
int i;
for (i = 0; i < ARRAY_SIZE(edid_3d_presets); i++, s3d_preset++) {
if (mandatory->refresh == s3d_preset->refresh &&
mandatory->xres == s3d_preset->xres &&
mandatory->yres == s3d_preset->yres &&
mandatory->s3d == s3d_preset->s3d) {
return s3d_preset;
}
}
return NULL;
}
static void edid_find_3d_preset(struct fb_video *vic, struct fb_vendor *vsdb)
{
struct edid_3d_preset *s3d_preset = edid_3d_presets;
int i;
if ((vsdb->s3d_structure_all & EDID_3D_FP_MASK) >> EDID_3D_FP) {
s3d_preset = edid_3d_presets;
for (i = 0; i < ARRAY_SIZE(edid_3d_presets); i++, s3d_preset++) {
if (vic->refresh == s3d_preset->refresh &&
vic->xres == s3d_preset->xres &&
vic->yres == s3d_preset->yres &&
vic->vmode == s3d_preset->vmode &&
EDID_3D_FP == s3d_preset->s3d) {
if (s3d_preset->supported == false) {
s3d_preset->supported = true;
pr_info("EDID: found %s",
s3d_preset->name);
}
}
}
}
if ((vsdb->s3d_structure_all & EDID_3D_TB_MASK) >> EDID_3D_TB) {
s3d_preset = edid_3d_presets;
for (i = 0; i < ARRAY_SIZE(edid_3d_presets); i++, s3d_preset++) {
if (vic->refresh == s3d_preset->refresh &&
vic->xres == s3d_preset->xres &&
vic->yres == s3d_preset->yres &&
EDID_3D_TB == s3d_preset->s3d) {
if (s3d_preset->supported == false) {
s3d_preset->supported = true;
pr_info("EDID: found %s",
s3d_preset->name);
}
}
}
}
if ((vsdb->s3d_structure_all & EDID_3D_SBS_MASK) >> EDID_3D_SBS) {
s3d_preset = edid_3d_presets;
for (i = 0; i < ARRAY_SIZE(edid_3d_presets); i++, s3d_preset++) {
if (vic->refresh == s3d_preset->refresh &&
vic->xres == s3d_preset->xres &&
vic->yres == s3d_preset->yres &&
EDID_3D_SBS == s3d_preset->s3d) {
if (s3d_preset->supported == false) {
s3d_preset->supported = true;
pr_info("EDID: found %s",
s3d_preset->name);
}
}
}
}
}
static void edid_find_3d_more_preset(struct fb_video *vic, char s3d_structure)
{
struct edid_3d_preset *s3d_preset = edid_3d_presets;
int i;
for (i = 0; i < ARRAY_SIZE(edid_3d_presets); i++, s3d_preset++) {
if (vic->refresh == s3d_preset->refresh &&
vic->xres == s3d_preset->xres &&
vic->yres == s3d_preset->yres &&
vic->vmode == s3d_preset->vmode &&
s3d_structure == s3d_preset->s3d) {
if (s3d_preset->supported == false) {
s3d_preset->supported = true;
pr_info("EDID: found %s", s3d_preset->name);
}
}
}
}
static void edid_use_default_preset(void)
{
int i;
preferred_preset = hdmi_conf[HDMI_DEFAULT_TIMINGS_IDX].dv_timings;
for (i = 0; i < ARRAY_SIZE(edid_presets); i++)
edid_presets[i].supported =
v4l_match_dv_timings(&edid_presets[i].dv_timings,
&preferred_preset, 0);
/* Default EDID setting is DVI */
/* max_audio_channels = 2; */
}
void edid_extension_update(struct fb_monspecs *specs)
{
struct edid_3d_preset *s3d_preset;
struct edid_preset *ud_preset;
const struct edid_3d_mandatory_preset *s3d_mandatory
= edid_3d_mandatory_presets;
unsigned int udmode_idx, vic_idx;
bool first = true;
int i;
if (!specs->vsdb)
return;
/* number of 128bytes blocks to follow */
source_phy_addr = specs->vsdb->phy_addr;
/* find 3D mandatory preset */
if (specs->vsdb->s3d_present) {
for (i = 0; i < ARRAY_SIZE(edid_3d_mandatory_presets);
i++, s3d_mandatory++) {
s3d_preset = edid_find_3d_mandatory_preset(s3d_mandatory);
if (s3d_preset) {
pr_info("EDID: found %s", s3d_preset->name);
s3d_preset->supported = true;
}
}
}
if (!specs->videodb)
return;
/* find 3D multi preset */
if (specs->vsdb->s3d_multi_present == EDID_3D_STRUCTURE_ALL)
for (i = 0; i < specs->videodb_len + 1; i++)
edid_find_3d_preset(&specs->videodb[i], specs->vsdb);
else if (specs->vsdb->s3d_multi_present == EDID_3D_STRUCTURE_MASK)
for (i = 0; i < specs->videodb_len + 1; i++)
if ((specs->vsdb->s3d_structure_mask & (1 << i)) >> i)
edid_find_3d_preset(&specs->videodb[i],
specs->vsdb);
/* find 3D more preset */
if (specs->vsdb->s3d_field) {
for (i = 0; i < specs->videodb_len + 1; i++) {
edid_find_3d_more_preset(&specs->videodb
[specs->vsdb->vic_order[i]],
specs->vsdb->s3d_structure[i]);
if (specs->vsdb->s3d_structure[i] > EDID_3D_TB + 1)
i++;
}
}
/* find UHD preset */
#ifdef CONFIG_SEC_MHL_EDID
if (mhl_max_res >= MHL_UHD) {
#endif
if (specs->vsdb->vic_len) {
for (vic_idx = 0; vic_idx < specs->vsdb->vic_len; vic_idx++) {
udmode_idx = get_ud_timing(specs->vsdb, vic_idx);
ud_preset = edid_find_preset(&ud_modes[udmode_idx]);
if (ud_preset) {
pr_info("EDID: found %s", ud_preset->name);
ud_preset->supported = true;
if (first) {
preferred_preset = ud_preset->dv_timings;
pr_info("EDID: set %s", ud_preset->name);
first = false;
}
}
}
}
#ifdef CONFIG_SEC_MHL_EDID
}
#endif
}
int edid_update(struct hdmi_device *hdev)
{
struct fb_monspecs specs;
struct edid_preset *preset;
#ifdef CONFIG_SEC_MHL_EDID
u16 pre_xres = 0;
u16 pre_refresh = 0;
#endif
bool first = true;
u8 *edid = NULL;
int channels_max = 0, support_bit_rates = 0, support_sample_rates = 0;
#ifdef CONFIG_SEC_MHL_EDID
int basic_audio = 0;
#endif
int block_cnt = 0;
int ret = 0;
int i;
edid_misc = 0;
max_audio_channels = 0;
audio_sample_rates = 0;
audio_bit_rates = 0;
block_cnt = edid_read(hdev, &edid);
if (block_cnt < 0)
goto out;
ret = fb_edid_to_monspecs(edid, &specs);
if (ret < 0)
goto out;
for (i = 1; i < block_cnt; i++)
ret = fb_edid_add_monspecs(edid + i * EDID_BLOCK_SIZE, &specs);
#ifdef CONFIG_SEC_MHL_EDID
basic_audio = edid[EDID_NATIVE_FORMAT] & EDID_BASIC_AUDIO;
#endif
preferred_preset = hdmi_conf[HDMI_DEFAULT_TIMINGS_IDX].dv_timings;
for (i = 0; i < ARRAY_SIZE(edid_presets); i++)
edid_presets[i].supported = false;
for (i = 0; i < ARRAY_SIZE(edid_3d_presets); i++)
edid_3d_presets[i].supported = false;
/* find 2D preset */
for (i = 0; i < specs.modedb_len; i++) {
preset = edid_find_preset(&specs.modedb[i]);
if (preset) {
if (preset->supported == false) {
pr_info("EDID: found %s\n", preset->name);
preset->supported = true;
}
#ifdef CONFIG_SEC_MHL_EDID
if (preset->supported) {
first = false;
if (((preset->xres) > pre_xres) || (((preset->xres) == pre_xres)
&& ((preset->refresh) >= pre_refresh))) {
pre_xres = preset->xres;
pre_refresh = preset->refresh;
preferred_preset = preset->dv_timings;
pr_info("EDID: set %s", preset->name);
}
}
#else
if (first) {
preferred_preset = preset->dv_timings;
pr_info("EDID: set %s", preset->name);
first = false;
}
#endif
}
}
/* number of 128bytes blocks to follow */
if (ret > 0 && block_cnt > 1)
edid_extension_update(&specs);
else
goto out;
if (!edid_misc)
edid_misc = specs.misc;
pr_info("EDID: misc flags %08x", edid_misc);
#ifndef CONFIG_SEC_MHL_EDID
if (!specs.audiodb)
goto out;
#endif
for (i = 0; i < specs.audiodb_len; i++) {
if (specs.audiodb[i].format != FB_AUDIO_LPCM)
continue;
if (specs.audiodb[i].channel_count > channels_max) {
channels_max = specs.audiodb[i].channel_count;
support_sample_rates = specs.audiodb[i].sample_rates;
support_bit_rates = specs.audiodb[i].bit_rates;
}
}
if (edid_misc & FB_MISC_HDMI) {
if (channels_max) {
max_audio_channels = channels_max;
audio_sample_rates = support_sample_rates;
audio_bit_rates = support_bit_rates;
} else {
#ifdef CONFIG_SEC_MHL_EDID
if (basic_audio) {
max_audio_channels = 2;
audio_sample_rates = FB_AUDIO_48KHZ; /*default audio info*/
audio_bit_rates = FB_AUDIO_16BIT;
} else {
max_audio_channels = 0;
audio_sample_rates = 0;
audio_bit_rates = 0;
}
#else
max_audio_channels = 2;
audio_sample_rates = FB_AUDIO_44KHZ; /*default audio info*/
audio_bit_rates = FB_AUDIO_16BIT;
#endif
}
} else {
max_audio_channels = 0;
audio_sample_rates = 0;
audio_bit_rates = 0;
}
pr_info("EDID: Audio channels %d", max_audio_channels);
out:
/* No supported preset found, use default */
if (first)
edid_use_default_preset();
if (block_cnt == -EPROTO)
edid_misc = FB_MISC_HDMI;
#ifndef CONFIG_SEC_MHL_EDID
kfree(edid);
#endif
return block_cnt;
}
struct v4l2_dv_timings edid_preferred_preset(struct hdmi_device *hdev)
{
#ifdef CONFIG_SEC_MHL_EDID
if(hdmi_forced_resolution >= 0 &&
hdmi_forced_resolution < hdmi_pre_cnt)
return
edid_presets[hdmi_forced_resolution].dv_timings;
else
#endif
return preferred_preset;
}
bool edid_supports_hdmi(struct hdmi_device *hdev)
{
return edid_misc & FB_MISC_HDMI;
}
u32 edid_audio_informs(struct hdmi_device *hdev)
{
u32 value = 0, ch_info = 0;
if (max_audio_channels > 0)
ch_info |= (1 << (max_audio_channels - 1));
if (max_audio_channels > 6)
ch_info |= (1 << 5);
value = ((audio_sample_rates << 19) | (audio_bit_rates << 16) |
ch_info);
return value;
}
int edid_source_phy_addr(struct hdmi_device *hdev)
{
return source_phy_addr;
}
static int edid_probe(struct i2c_client *client,
const struct i2c_device_id *dev_id)
{
edid_client = client;
edid_use_default_preset();
dev_info(&client->adapter->dev, "probed exynos edid\n");
return 0;
}
static int edid_remove(struct i2c_client *client)
{
edid_client = NULL;
dev_info(&client->adapter->dev, "removed exynos edid\n");
return 0;
}
static struct i2c_device_id edid_idtable[] = {
{"exynos_edid", 2},
};
MODULE_DEVICE_TABLE(i2c, edid_idtable);
static struct i2c_driver edid_driver = {
.driver = {
.name = "exynos_edid",
.owner = THIS_MODULE,
.of_match_table = of_match_ptr(edid_device_table),
},
.id_table = edid_idtable,
.probe = edid_probe,
.remove = edid_remove,
};
static int __init edid_init(void)
{
return i2c_add_driver(&edid_driver);
}
static void __exit edid_exit(void)
{
i2c_del_driver(&edid_driver);
}
module_init(edid_init);
module_exit(edid_exit);
|