summaryrefslogtreecommitdiff
path: root/drivers/video/wmt/vout-wmt.c
blob: b7ff0bf41881dc0cfbabe71e7ffe4f556ca6acfb (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
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
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
/*++
 * linux/drivers/video/wmt/vout-wmt.c
 * WonderMedia video post processor (VPP) driver
 *
 * Copyright c 2014  WonderMedia  Technologies, Inc.
 *
 * 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, see <http://www.gnu.org/licenses/>.
 *
 * WonderMedia Technologies, Inc.
 * 4F, 533, Chung-Cheng Road, Hsin-Tien, Taipei 231, R.O.C
--*/
#undef DEBUG
/* #define DEBUG */
/* #define DEBUG_DETAIL */

#include "vpp.h"

#ifndef CFG_LOADER
static int vo_plug_flag;
#endif
int vo_plug_vout;
int (*vo_plug_func)(int hotplug);
enum vout_mode_t dvo_vout_mode;
enum vout_mode_t int_vout_mode;
int hdmi_cur_plugin;
struct vout_t *vo_poll_vout;

/* GPIO 10 & 11 */
struct swi2c_reg_s vo_gpio_scl = {
	.bit_mask = BIT10,
	.gpio_en = (__GPIO_BASE + 0x40),
	.out_en = (__GPIO_BASE + 0x80),
	.data_in = (__GPIO_BASE + 0x00),
	.data_out = (__GPIO_BASE + 0xC0),
	.pull_en = (__GPIO_BASE + 0x480),
	.pull_en_bit_mask = BIT10,
};

struct swi2c_reg_s vo_gpio_sda = {
	.bit_mask = BIT11,
	.gpio_en = (__GPIO_BASE + 0x40),
	.out_en = (__GPIO_BASE + 0x80),
	.data_in = (__GPIO_BASE + 0x00),
	.data_out = (__GPIO_BASE + 0xC0),
	.pull_en = (__GPIO_BASE + 0x480),
	.pull_en_bit_mask = BIT11,
};

struct swi2c_handle_s vo_swi2c_dvi = {
	.scl_reg = &vo_gpio_scl,
	.sda_reg = &vo_gpio_sda,
};

#define DVI_POLL_TIME_MS	1000

extern void hdmi_config_audio(struct vout_audio_t *info);

/*---------------------------------- API ------------------------------------*/
#ifdef DEBUG
void vout_print_entry(struct vout_t *vo)
{
	if (vo == 0)
		return;

	MSG(" =============== vout %d ===============\n", vo->num);
	MSG("fix 0x%x", vo->fix_cap);
	MSG("(inf %d,bus %d,govr %d,ext dev %d,fix plug %d,aud %d,edid %d)\n",
		(vo->fix_cap & VOUT_CAP_INTERFACE),
		(vo->fix_cap & VOUT_CAP_BUS) >> 8,
		(vo->fix_cap & VOUT_CAP_GOVR) >> 12,
		(vo->fix_cap & VOUT_CAP_EXT_DEV) ? 1 : 0,
		(vo->fix_cap & VOUT_CAP_FIX_PLUG) ? 1 : 0,
		(vo->fix_cap & VOUT_CAP_AUDIO) ? 1 : 0,
		(vo->fix_cap & VOUT_CAP_EDID) ? 1 : 0);
	MSG("info %d,%s\n", vo->info->num, vpp_mod_str[vo->govr->mod]);
	MSG("inf 0x%x,dev 0x%x\n", (int)vo->inf, (int)vo->dev);
	MSG("resx %d,resy %d,fps %d\n", vo->resx, vo->resy, vo->fps);
	MSG("pixclk %d,option %d,%d,%d,disable %d\n", vo->pixclk,
		vo->option[0], vo->option[1], vo->option[2], vo->disable);
	MSG("sts(reg %d,act %d,plug %d,edid %d,blank %d,pwrdn %d,cp %d)\n",
		(vo->status & VPP_VOUT_STS_REGISTER) ? 1 : 0,
		(vo->status & VPP_VOUT_STS_ACTIVE) ? 1 : 0,
		(vo->status & VPP_VOUT_STS_PLUGIN) ? 1 : 0,
		(vo->status & VPP_VOUT_STS_EDID) ? 1 : 0,
		(vo->status & VPP_VOUT_STS_BLANK) ? 1 : 0,
		(vo->status & VPP_VOUT_STS_POWERDN) ? 1 : 0,
		(vo->status & VPP_VOUT_STS_CONTENT_PROTECT) ? 1 : 0);

	if (vo->inf) {
		MSG(" ===== inf entry =====\n");
		MSG("mode %d, %s\n",
			vo->inf->mode, vout_inf_str[vo->inf->mode]);
	}

	if (vo->dev) {
		MSG(" ===== dev entry =====\n");
		MSG("name %s,inf %d,%s\n", vo->dev->name,
			vo->dev->mode, vout_inf_str[vo->dev->mode]);
		MSG("vout 0x%x,capability 0x%x\n",
			(int)vo->dev->vout, vo->dev->capability);
	}
}
#endif

int vo_i2c_proc(int id, unsigned int addr, unsigned int index,
			char *pdata, int len)
{
	struct swi2c_handle_s *handle = 0;
	int ret = 0;

	switch (id) {
	case 1:	/* dvi */
		if (lcd_get_type())	/* share pin with LVDS */
			return -1;
		handle = &vo_swi2c_dvi;
		break;
	default:
		break;
	}

	if (handle) {
		if (wmt_swi2c_check(handle))
			return -1;
		if (addr & 0x1) { /* read */
			*pdata = 0xff;
#ifdef CONFIG_WMT_EDID
			ret = wmt_swi2c_read(handle, addr & ~0x1,
						index, pdata, len);
#else
			ret = -1;
#endif
		} else { /* write */
			DBG_ERR("not support sw i2c write\n");
		}
	}
	return ret;
}

#ifndef CONFIG_UBOOT
static void vo_do_plug(struct work_struct *ptr)
{
	struct vout_t *vo;
	int plugin;

	if (vo_plug_func == 0)
		return;

	vo = vout_get_entry(vo_plug_vout);
	govrh_set_dvo_enable(vo->govr, 1);
	plugin = vo_plug_func(1);
/*	govrh_set_dvo_enable(vo->govr, plugin); */
	vout_change_status(vo, VPP_VOUT_STS_PLUGIN, plugin);
	vo_plug_flag = 0;
	DBG_DETAIL("vo_do_plug %d\n", plugin);
	/* GPIO irq enable */
	vppif_reg32_write(GPIO_BASE_ADDR + 0x300 + VPP_VOINT_NO, 0x80, 7, 1);
	/* GPIO input mode */
	vppif_reg32_write(GPIO_BASE_ADDR + 0x80, 0x1 << VPP_VOINT_NO,
				VPP_VOINT_NO, 0x0);
#ifdef __KERNEL__
	vpp_netlink_notify_plug(VPP_VOUT_NUM_DVI, plugin);
#endif
	return;
}

DECLARE_DELAYED_WORK(vo_plug_work, vo_do_plug);

static irqreturn_t vo_plug_interrupt_routine
(
	int irq,		/*!<; // irq id */
	void *dev_id		/*!<; // device id */
)
{
	DBG_DETAIL("Enter\n");
	if ((inb(GPIO_BASE_ADDR + 0x360) &
		(0x1 << VPP_VOINT_NO)) == 0)
		return IRQ_NONE;

	/* clear int status */
	outb(0x1 << VPP_VOINT_NO, GPIO_BASE_ADDR + 0x360);
#ifdef __KERNEL__
	/* if (vo_plug_flag == 0) { */
	/* GPIO irq disable */
	vppif_reg32_write(GPIO_BASE_ADDR + 0x300 + VPP_VOINT_NO, 0x80, 7, 0);
	schedule_delayed_work(&vo_plug_work, HZ/5);
	vo_plug_flag = 1;
	/* } */
#else
	if (vo_plug_func)
		vo_do_plug(0);
#endif
	return IRQ_HANDLED;
}

#define CONFIG_VO_POLL_WORKQUEUE
struct timer_list vo_poll_timer;
#ifdef CONFIG_VO_POLL_WORKQUEUE
static void vo_do_poll(struct work_struct *ptr)
{
	struct vout_t *vo;

	vo = vo_poll_vout;
	if (vo) {
		if (vo->dev)
			vo->dev->poll();
		mod_timer(&vo_poll_timer,
			jiffies + msecs_to_jiffies(vo_poll_timer.data));
	}
	return;
}

DECLARE_DELAYED_WORK(vo_poll_work, vo_do_poll);
#else
struct tasklet_struct vo_poll_tasklet;
static void vo_do_poll_tasklet
(
	unsigned long data		/*!<; // tasklet input data */
)
{
	struct vout_t *vo;

	vpp_lock();
	vo = vo_poll_vout;
	if (vo) {
		if (vo->dev)
			vo->dev->poll();
		mod_timer(&vo_poll_timer,
			jiffies + msecs_to_jiffies(vo_poll_timer.data));
	}
	vpp_unlock();
}
#endif

void vo_do_poll_tmr(int ms)
{
#ifdef CONFIG_VO_POLL_WORKQUEUE
	schedule_delayed_work(&vo_poll_work, msecs_to_jiffies(ms));
#else
	tasklet_schedule(&vo_poll_tasklet);
#endif
}

static void vo_set_poll(struct vout_t *vo, int on, int ms)
{
	DMSG("%d\n", on);

	if (on) {
		vo_poll_vout = vo;
		if (vo_poll_timer.function) {
			vo_poll_timer.data = ms / 2;
			mod_timer(&vo_poll_timer,
				jiffies + msecs_to_jiffies(vo_poll_timer.data));
		} else {
			init_timer(&vo_poll_timer);
			vo_poll_timer.data = ms / 2;
			vo_poll_timer.function = (void *) vo_do_poll_tmr;
			vo_poll_timer.expires = jiffies +
				msecs_to_jiffies(vo_poll_timer.data);
			add_timer(&vo_poll_timer);
		}
#ifndef CONFIG_VO_POLL_WORKQUEUE
		tasklet_init(&vo_poll_tasklet, vo_do_poll_tasklet, 0);
#endif
	} else {
		del_timer(&vo_poll_timer);
#ifndef CONFIG_VO_POLL_WORKQUEUE
		tasklet_kill(&vo_poll_tasklet);
#endif
		vo_poll_vout = 0;
	}
}
#endif

void vout_set_int_type(int type)
{
	unsigned char reg;

	reg = inb(GPIO_BASE_ADDR + 0x300 + VPP_VOINT_NO);
	reg &= ~0x7;
	switch (type) {
	case 0:	/* low level */
	case 1:	/* high level */
	case 2:	/* falling edge */
	case 3:	/* rising edge */
	case 4:	/* rising edge or falling */
		reg |= type;
		break;
	default:
		break;
	}
	outb(reg, GPIO_BASE_ADDR + 0x300 + VPP_VOINT_NO);
}
EXPORT_SYMBOL(vout_set_int_type);

void vout_set_int_enable(int enable)
{
	vppif_reg32_write(GPIO_BASE_ADDR + 0x300 +
		VPP_VOINT_NO, 0x80, 7, enable);	/* GPIO irq enable/disable */
}
EXPORT_SYMBOL(vout_set_int_enable);

int vout_get_clr_int(void)
{
	if ((inb(GPIO_BASE_ADDR + 0x360) &
		(0x1 << VPP_VOINT_NO)) == 0)
		return 1;
	/* clear int status */
	outb(0x1 << VPP_VOINT_NO, GPIO_BASE_ADDR + 0x360);
	return 0;
}
EXPORT_SYMBOL(vout_get_clr_int);

static void vo_plug_enable(int enable, void *func, int no)
{
	struct vout_t *vo;

	DBG_DETAIL("%d\n", enable);
	vo_plug_vout = no;
	vo = vout_get_entry(no);
#ifdef CONFIG_WMT_EXT_DEV_PLUG_DISABLE
	vo_plug_func = 0;
	govrh_set_dvo_enable(vo->govr, enable);
#else
	vo_plug_func = func;
	if (vo_plug_func == 0)
		return;

	if (enable) {
		vppif_reg32_write(GPIO_BASE_ADDR + 0x40, 0x1 << VPP_VOINT_NO,
			VPP_VOINT_NO, 0x0); /* GPIO disable */
		vppif_reg32_write(GPIO_BASE_ADDR + 0x80, 0x1 << VPP_VOINT_NO,
			VPP_VOINT_NO, 0x0); /* GPIO input mode */
		vppif_reg32_write(GPIO_BASE_ADDR + 0x480, 0x1 << VPP_VOINT_NO,
			VPP_VOINT_NO, 0x1); /* GPIO pull enable */
		vppif_reg32_write(GPIO_BASE_ADDR + 0x4c0, 0x1 << VPP_VOINT_NO,
			VPP_VOINT_NO, 0x1); /* GPIO pull-up */
#ifndef CONFIG_UBOOT
		vo_do_plug(0);
		if (vpp_request_irq(IRQ_GPIO, vo_plug_interrupt_routine,
			IRQF_SHARED, "vo plug", (void *) &vo_plug_vout))
			DBG_ERR("request GPIO ISR fail\n");

		vppif_reg32_write(GPIO_BASE_ADDR + 0x300 + VPP_VOINT_NO,
			0x80, 7, 1); /* GPIO irq enable */
	} else {
		vpp_free_irq(IRQ_GPIO, (void *) &vo_plug_vout);
#endif
	}
#endif
}

/*--------------------------------- DVI ------------------------------------*/
#ifdef WMT_FTBLK_VOUT_DVI
static int vo_dvi_blank(struct vout_t *vo, enum vout_blank_t arg)
{
	DMSG("(%d, %d)\n", vo->pre_blank, arg);
        if(vo->pre_blank == arg)
                return 0;

        if (vo->pre_blank == VOUT_BLANK_POWERDOWN) {
                if (vo->dev) {
#ifdef __KERNEL__
                        if (!g_vpp.dvi_int_disable && vo->dev->interrupt)
                                vo_plug_enable(VPP_FLAG_ENABLE,
                                                vo->dev->interrupt, vo->num);
                        else if (vo->dev->poll)
                                vo_set_poll(vo, (vo->dev->poll) ? 1 : 0,
                                        DVI_POLL_TIME_MS);
#endif
                }
        }
#ifdef __KERNEL__
        if (arg == VOUT_BLANK_POWERDOWN)
                vo_set_poll(vo, 0, 0);
#endif
        if (!lcd_get_dev()) /* enable DVO not contain LCD */
                govrh_set_dvo_enable(vo->govr,
                                (arg == VOUT_BLANK_UNBLANK) ? 1 : 0);
        vo->pre_blank = arg;
        return 0;
}

static int vo_dvi_config(struct vout_t *vo, int arg)
{
	struct vout_info_t *vo_info;

	DBG_DETAIL("Enter\n");

	vo_info = (struct vout_info_t *) arg;
	govrh_set_dvo_sync_polar(vo->govr,
		(vo_info->option & VPP_DVO_SYNC_POLAR_HI) ? 0 : 1,
		(vo_info->option & VPP_DVO_VSYNC_POLAR_HI) ? 0 : 1);
	return 0;
}

static int vo_dvi_init(struct vout_t *vo, int arg)
{
	unsigned int clk_delay;

	DBG_DETAIL("(%d)\n", arg);

	vo->pre_blank = VOUT_BLANK_POWERDOWN;

	lvds_set_enable(0);
	govrh_set_dvo_color_format(vo->govr, vo->option[0]);
	govrh_set_dvo_outdatw(vo->govr, vo->option[1] & WMT_DISP_FB_DVI_24BIT);
	govrh_IGS_set_mode(vo->govr, 0, WMT_DISP_FB_GET_RGB_MODE(vo->option[1]),
		(vo->option[1] & WMT_DISP_FB_MSB) ? 1 : 0);
	govrh_IGS_set_RGB_swap(vo->govr, WMT_DISP_FB_RGB_SWAP(vo->option[1]));
	clk_delay = (vo->option[1] & WMT_DISP_FB_DVI_24BIT) ?
		VPP_GOVR_DVO_DELAY_24 : VPP_GOVR_DVO_DELAY_12;
	govrh_set_dvo_clock_delay(vo->govr, ((clk_delay & BIT14) != 0x0),
		clk_delay & 0x3FFF);
	if (vo->dev) {
		vo->dev->set_mode(&vo->option[0]);
		vo->dev->set_power_down(VPP_FLAG_DISABLE);
		if (!g_vpp.dvi_int_disable && vo->dev->interrupt)
			vo_plug_enable(VPP_FLAG_ENABLE,
					vo->dev->interrupt, vo->num);
#ifdef __KERNEL__
		else if (vo->dev->poll) {
			vo_set_poll(vo, (vo->dev->poll) ? 1 : 0,
					DVI_POLL_TIME_MS);
		}
#endif
		vout_change_status(vo, VPP_VOUT_STS_PLUGIN,
				vo->dev->check_plugin(0));
	}
	vo->govr->fb_p->set_csc(vo->govr->fb_p->csc_mode);
	if (!lcd_get_dev()) {
		govrh_set_dvo_enable(vo->govr,
			(vo->status & VPP_VOUT_STS_BLANK) ? 0 : 1);
	}
	return 0;
}

static int vo_dvi_uninit(struct vout_t *vo, int arg)
{
	DBG_DETAIL("(%d)\n", arg);

	vo_plug_enable(VPP_FLAG_DISABLE, 0, VPP_VOUT_NUM);
	govrh_set_dvo_enable(vo->govr, VPP_FLAG_DISABLE);
#ifdef __KERNEL__
	vo_set_poll(vo, 0, DVI_POLL_TIME_MS);
#endif
	return 0;
}

static int vo_dvi_chkplug(struct vout_t *vo, int arg)
{
	int plugin = 1;

	DBG_MSG("plugin %d\n", plugin);
	return plugin;
}

static int vo_dvi_get_edid(struct vout_t *vo, int arg)
{
	char *buf;
	int i, cnt;

	DBG_DETAIL("Enter\n");

	buf = (char *) arg;
	memset(&buf[0], 0x0, 128 * EDID_BLOCK_MAX);
	if (vpp_i2c_read(VPP_DVI_EDID_ID, 0xA0, 0, &buf[0], 128)) {
		DBG_ERR("read edid\n");
		return 1;
	}

	if (edid_checksum(buf, 128)) {
		DBG_ERR("checksum\n");
		return 1;
	}

	cnt = buf[0x7E];
	if (cnt >= 3)
		cnt = 3;
	for (i = 1; i <= cnt; i++) {
		vpp_i2c_read(VPP_DVI_EDID_ID, 0xA0, 0x80 * i,
			&buf[128 * i], 128);
	}
	return 0;
}

struct vout_inf_t vo_dvi_inf = {
	.mode = VOUT_INF_DVI,
	.init = vo_dvi_init,
	.uninit = vo_dvi_uninit,
	.blank = vo_dvi_blank,
	.config = vo_dvi_config,
	.chkplug = vo_dvi_chkplug,
	.get_edid = vo_dvi_get_edid,
};

int vo_dvi_initial(void)
{
	vout_inf_register(VOUT_INF_DVI, &vo_dvi_inf);
	return 0;
}
module_init(vo_dvi_initial);

#endif /* WMT_FTBLK_VOUT_DVI */

/*---------------------------------- HDMI -----------------------------------*/
void vo_hdmi_set_clock(int enable)
{
	DBG_DETAIL("(%d)\n", enable);

	enable = (enable) ? CLK_ENABLE : CLK_DISABLE;
	vpp_set_clock_enable(DEV_HDMII2C, enable, 0);
	vpp_set_clock_enable(DEV_HDMI, enable, 0);
	vpp_set_clock_enable(DEV_HDCE, enable, 0);
}

#ifdef WMT_FTBLK_VOUT_HDMI
#ifdef __KERNEL__
struct timer_list hdmi_cp_timer;
static struct timer_list hdmi_plug_timer;
#endif

void vo_hdmi_cp_set_enable_tmr(int sec)
{
#ifdef __KERNEL__
	int ms = sec * 1000;
#endif

	DBG_MSG("[HDMI] set enable tmr %d sec\n", sec);

	if (sec == 0) {
		hdmi_set_cp_enable(VPP_FLAG_ENABLE);
		return ;
	}
#ifdef __KERNEL__
	if (hdmi_cp_timer.function)
		del_timer(&hdmi_cp_timer);
	init_timer(&hdmi_cp_timer);
	hdmi_cp_timer.data = VPP_FLAG_ENABLE;
	hdmi_cp_timer.function = (void *) hdmi_set_cp_enable;
	hdmi_cp_timer.expires = jiffies + msecs_to_jiffies(ms);
	add_timer(&hdmi_cp_timer);
#else
	hdmi_set_cp_enable(VPP_FLAG_ENABLE);
#endif
}
EXPORT_SYMBOL(vo_hdmi_cp_set_enable_tmr);

static int vo_hdmi_blank(struct vout_t *vo, enum vout_blank_t arg)
{
	int enable;

	DBG_DETAIL("(%d)\n", arg);

	enable = (arg == VOUT_BLANK_UNBLANK) ? 1 : 0;
	if (g_vpp.hdmi_cp_enable && enable)
		vo_hdmi_cp_set_enable_tmr(2);
	else
		hdmi_set_cp_enable(VPP_FLAG_DISABLE);
	hdmi_set_enable(enable);
	hdmi_set_power_down((enable) ? 0 : 1);
	return 0;
}

#ifndef CFG_LOADER
static irqreturn_t vo_hdmi_cp_interrupt
(
	int irq,		/*!<; // irq id */
	void *dev_id		/*!<; // device id */
)
{
	struct vout_t *vo;

	DBG_DETAIL("%d\n", irq);
	vo = vout_get_entry(VPP_VOUT_NUM_HDMI);
	switch (hdmi_check_cp_int()) {
	case 1:
		if (hdmi_cp)
			hdmi_cp->enable(VPP_FLAG_DISABLE);
		vo_hdmi_cp_set_enable_tmr(HDMI_CP_TIME);
		vout_change_status(vo, VPP_VOUT_STS_CONTENT_PROTECT, 0);
		vpp_netlink_notify_cp(0);
		break;
	case 0:
		vout_change_status(vo, VPP_VOUT_STS_CONTENT_PROTECT, 1);
		vpp_netlink_notify_cp(1);
		break;
	case 2:
		hdmi_ri_tm_cnt = 3 * 30;
		break;
	default:
		break;
	}
	return IRQ_HANDLED;
}

#ifdef __KERNEL__
static void vo_hdmi_do_plug(struct work_struct *ptr)
#else
static void vo_hdmi_do_plug(void)
#endif
{
	struct vout_t *vo;
	int plugin;
	int option = 0;

	plugin = hdmi_check_plugin(1);
	vo = vout_get_entry(VPP_VOUT_NUM_HDMI);
	vout_change_status(vo, VPP_VOUT_STS_PLUGIN, plugin);
	if (plugin) {
		option = vout_get_edid_option(VPP_VOUT_NUM_HDMI);
#ifdef CONFIG_VPP_DEMO
		option |= (EDID_OPT_HDMI + EDID_OPT_AUDIO);
#endif
		hdmi_set_option(option);
	} else {
		g_vpp.hdmi_bksv[0] = g_vpp.hdmi_bksv[1] = 0;
	}
	vo_hdmi_blank(vo, (vo->status & VPP_VOUT_STS_BLANK) ? 1 : !(plugin));
	if (!g_vpp.hdmi_certify_flag)
		hdmi_hotplug_notify(plugin);
	DBG_MSG("%d\n", plugin);
	return;
}
DECLARE_WORK(vo_hdmi_plug_work, vo_hdmi_do_plug);

static void hdmi_handle_plug(vpp_flag_t enable)
{
	schedule_work(&vo_hdmi_plug_work);
}

static void vo_hdmi_handle_plug_tmr(int ms)
{
	static int timer_init;

	if (timer_init == 0) {
		init_timer(&hdmi_plug_timer);
		hdmi_plug_timer.data = VPP_FLAG_ENABLE;
		hdmi_plug_timer.function = (void *) hdmi_handle_plug;
		timer_init = 1;
	}
	hdmi_plug_timer.expires = jiffies + msecs_to_jiffies(ms);
	mod_timer(&hdmi_plug_timer, hdmi_plug_timer.expires);
}

static irqreturn_t vo_hdmi_plug_interrupt
(
	int irq,		/*!<; // irq id */
	void *dev_id		/*!<; // device id */
)
{
	DBG_MSG("vo_hdmi_plug_interrupt %d\n", irq);
	hdmi_clear_plug_status();
	if (g_vpp.hdmi_certify_flag)
		vo_hdmi_do_plug(0);
	else
		vo_hdmi_handle_plug_tmr(HDMI_PLUG_DELAY);
	return IRQ_HANDLED;
}
#endif

static int vo_hdmi_init(struct vout_t *vo, int arg)
{
	DBG_DETAIL("(%d)\n", arg);

	vo_hdmi_set_clock(1);
	vout_change_status(vout_get_entry(VPP_VOUT_NUM_HDMI),
		VPP_VOUT_STS_PLUGIN, hdmi_check_plugin(0));
	hdmi_enable_plugin(1);

	if (g_vpp.hdmi_disable)
		return 0;
#ifndef CONFIG_UBOOT
	if (vpp_request_irq(VPP_IRQ_HDMI_CP, vo_hdmi_cp_interrupt,
		SA_INTERRUPT, "hdmi cp", (void *) 0)) {
		DBG_ERR("*E* request HDMI ISR fail\n");
	}
	if (vpp_request_irq(VPP_IRQ_HDMI_HPDH, vo_hdmi_plug_interrupt,
		SA_INTERRUPT, "hdmi plug", (void *) 0)) {
		DBG_ERR("*E* request HDMI ISR fail\n");
	}
	if (vpp_request_irq(VPP_IRQ_HDMI_HPDL, vo_hdmi_plug_interrupt,
		SA_INTERRUPT, "hdmi plug", (void *) 0)) {
		DBG_ERR("*E* request HDMI ISR fail\n");
	}
#endif
	hdmi_set_enable((vo->status & VPP_VOUT_STS_BLANK) ?
		VPP_FLAG_DISABLE : VPP_FLAG_ENABLE);
	return 0;
}

static int vo_hdmi_uninit(struct vout_t *vo, int arg)
{
	DBG_DETAIL("(%d)\n", arg);
	hdmi_enable_plugin(0);
	hdmi_set_cp_enable(VPP_FLAG_DISABLE);
	hdmi_set_enable(VPP_FLAG_DISABLE);
#ifndef CONFIG_UBOOT
	vpp_free_irq(VPP_IRQ_HDMI_CP, (void *) 0);
	vpp_free_irq(VPP_IRQ_HDMI_HPDH, (void *) 0);
	vpp_free_irq(VPP_IRQ_HDMI_HPDL, (void *) 0);
#endif
	vo_hdmi_set_clock(0);
	return 0;
}

static int vo_hdmi_config(struct vout_t *vo, int arg)
{
	struct vout_info_t *vo_info;
	vdo_color_fmt colfmt;

	hdmi_set_enable(0);
	vo_info = (struct vout_info_t *) arg;

	DBG_DETAIL("(%dx%d@%d)\n", vo_info->resx, vo_info->resy, vo_info->fps);

	/* 1280x720@60, HDMI pixel clock 74250060 not 74500000 */
	if ((vo_info->resx == 1280)
		&& (vo_info->resy == 720) && (vo_info->pixclk == 74500000))
		vo_info->pixclk = 74250060;
	colfmt = (vo->option[0] == VDO_COL_FMT_YUV422V) ?
		VDO_COL_FMT_YUV422H : vo->option[0];
	hdmi_cur_plugin = hdmi_check_plugin(0);
	hdmi_info.option = (hdmi_cur_plugin) ?
		vout_get_edid_option(VPP_VOUT_NUM_HDMI) : 0;
	hdmi_info.outfmt = colfmt;
	hdmi_info.vic = hdmi_get_vic(vo_info->resx, vo_info->resy,
		vo_info->fps, (vo_info->option & VPP_OPT_INTERLACE) ? 1 : 0);

	govrh_set_csc_mode(vo->govr, vo->govr->fb_p->csc_mode);
	hdmi_set_sync_low_active((vo_info->option & VPP_DVO_SYNC_POLAR_HI) ?
		0 : 1, (vo_info->option & VPP_DVO_VSYNC_POLAR_HI) ? 0 : 1);
	hdmi_config(&hdmi_info);
#ifdef __KERNEL__
	mdelay(200);	/* patch for VIZIO change resolution issue */
#endif
	hdmi_cur_plugin = hdmi_check_plugin(0);
	vo_hdmi_blank(vo, (vo->status & VPP_VOUT_STS_BLANK) ?
		1 : !(hdmi_cur_plugin));
	return 0;
}

static int vo_hdmi_chkplug(struct vout_t *vo, int arg)
{
	int plugin;

	if (g_vpp.hdmi_disable)
		return 0;
	plugin = hdmi_get_plugin();
	DBG_DETAIL("%d\n", plugin);
	return plugin;
}

static int vo_hdmi_get_edid(struct vout_t *vo, int arg)
{
	char *buf;
#ifdef CONFIG_WMT_EDID
	int i, cnt;
#endif
	DBG_DETAIL("Enter\n");
	buf = (char *) arg;
#ifdef CONFIG_WMT_EDID
	memset(&buf[0], 0x0, 128*EDID_BLOCK_MAX);
	if (!hdmi_get_plugin())
		return 1;

	if (hdmi_DDC_read(0xA0, 0x0, &buf[0], 128)) {
		DBG_ERR("read edid\n");
		return 1;
	}

	if (edid_checksum(buf, 128)) {
		DBG_ERR("hdmi checksum\n");
/*		g_vpp.dbg_hdmi_ddc_crc_err++; */
		return 1;
	}

	cnt = buf[0x7E];
	if (cnt >= 3)
		cnt = 3;
	for (i = 1; i <= cnt; i++)
		hdmi_DDC_read(0xA0, 0x80 * i, &buf[128 * i], 128);
#endif
	return 0;
}

struct vout_inf_t vo_hdmi_inf = {
	.mode = VOUT_INF_HDMI,
	.init = vo_hdmi_init,
	.uninit = vo_hdmi_uninit,
	.blank = vo_hdmi_blank,
	.config = vo_hdmi_config,
	.chkplug = vo_hdmi_chkplug,
	.get_edid = vo_hdmi_get_edid,
};

int vo_hdmi_initial(void)
{
	vout_inf_register(VOUT_INF_HDMI, &vo_hdmi_inf);
	return 0;
}
module_init(vo_hdmi_initial);

#endif /* WMT_FTBLK_VOUT_HDMI */

/*--------------------------------- LVDS ------------------------------------*/
#ifdef WMT_FTBLK_VOUT_LVDS
int vo_lvds_init_flag;
static int vo_lvds_blank(struct vout_t *vo, enum vout_blank_t arg)
{
	DBG_DETAIL("(%d)\n", arg);
	if (arg == VOUT_BLANK_POWERDOWN) {
		lvds_regs->test.b.tre_en = 0;
	} else { /* avoid suspend signal not clear */
		lvds_set_enable((arg == VOUT_BLANK_UNBLANK) ? 1 : 0);
	}

	if (vo_lvds_init_flag)
		lvds_set_power_down(arg);
	return 0;
}

static int vo_lvds_config(struct vout_t *vo, int arg)
{
	DBG_DETAIL("(%d)\n", arg);
	lvds_set_power_down(VPP_FLAG_DISABLE);
	vo_lvds_init_flag = 1;
	return 0;
}

static int vo_lvds_init(struct vout_t *vo, int arg)
{
	DBG_DETAIL("(%d)\n", arg);

	vpp_set_clock_enable(DEV_LVDS, 1, 0);
	if (vo->dev)
		vo->dev->set_mode(&vo->option[0]);
	govrh_set_dvo_enable(p_govrh2, 0);
	govrh_set_csc_mode(vo->govr, vo->govr->fb_p->csc_mode);
	lvds_set_enable((vo->status & VPP_VOUT_STS_BLANK) ?
		VPP_FLAG_DISABLE : VPP_FLAG_ENABLE);
	return 0;
}

static int vo_lvds_uninit(struct vout_t *vo, int arg)
{
	DBG_DETAIL("(%d)\n", arg);
	lvds_set_enable(VPP_FLAG_DISABLE);
	if (vo->dev)
		vo->dev->set_mode(0);
	lvds_set_power_down(VPP_FLAG_ENABLE);
	vpp_set_clock_enable(DEV_LVDS, 0, 0);
	vo_lvds_init_flag = 0;
	return 0;
}

static int vo_lvds_chkplug(struct vout_t *vo, int arg)
{
	DBG_DETAIL("\n");
#if 0
	vo = vout_get_info(VOUT_LVDS);
	if (vo->dev)
		return vo->dev->check_plugin(0);
#endif
	return 1;
}

struct vout_inf_t vo_lvds_inf = {
	.mode = VOUT_INF_LVDS,
	.capability = VOUT_INF_CAP_FIX_PLUG,
	.init = vo_lvds_init,
	.uninit = vo_lvds_uninit,
	.blank = vo_lvds_blank,
	.config = vo_lvds_config,
	.chkplug = vo_lvds_chkplug,
#ifdef WMT_FTBLK_VOUT_HDMI
	.get_edid = vo_hdmi_get_edid,
#endif
};

int vo_lvds_initial(void)
{
	vout_inf_register(VOUT_INF_LVDS, &vo_lvds_inf);
	return 0;
}
module_init(vo_lvds_initial);

#endif /* WMT_FTBLK_VOUT_LVDS */
/*---------------------------------- API ------------------------------------*/
#ifndef CFG_LOADER
int vout_set_audio(struct vout_audio_t *arg)
{
	struct vout_t *vout;
	int ret = 0;

#if 0
	vout = vout_get_info(VPP_VOUT_DVO2HDMI);
	if (vout && (vout->status & VPP_VOUT_STS_PLUGIN)) {
		if (vout->dev->set_audio)
			vout->dev->set_audio(arg);
	}
#endif

#ifdef WMT_FTBLK_VOUT_HDMI
	vout = vout_get_entry(VPP_VOUT_NUM_HDMI);
	if (vout) {
		g_vpp.hdmi_ch_change = 1;
		hdmi_config_audio(arg);
		g_vpp.hdmi_ch_change = 0;
		ret = 1;
	}
#endif
	return ret;
}
#endif

/* 3445 port1 : DVI/SDD, port2 : VGA/SDA, port3 : HDMI/LVDS */
/* 3481 port1 : HDMI/LVDS, port2 : DVI */
/* 3498 port1 : HDMI, port2 : DVI/LVDS */
struct vout_t vout_entry_0 = {
	.fix_cap = BIT(VOUT_INF_HDMI),
	.option[0] = VDO_COL_FMT_ARGB,
	.option[1] = VPP_DATAWIDHT_24,
	.option[2] = 0,
};

struct vout_t vout_entry_1 = {
	.fix_cap = BIT(VOUT_INF_DVI) + BIT(VOUT_INF_LVDS) +
		VOUT_CAP_EXT_DEV + 0x100,	/* i2c bus 1,ext dev */
	.option[0] = VDO_COL_FMT_ARGB,
	.option[1] = VPP_DATAWIDHT_24,
	.option[2] = 0,
};

int vout_add_display(int fb_no, unsigned int *parm)
{
	struct vout_info_t *info;
	struct vout_t *vout;
	int ret = 0;

	info = vout_info[fb_no];
	if (!info) {
		info = kmalloc(sizeof(struct vout_info_t), GFP_KERNEL);
		if (!info)
			return 1;
		memset(info, 0, sizeof(struct vout_info_t));
		vout_info[fb_no] = info;
		DBG_MSG("malloc vout_info %d,0x%x\n", fb_no, (int) info);
#ifdef CONFIG_KERNEL
		sema_init(&info->sem, 1);
#endif
	}

	if (parm[0] == VOUT_BOOT) {
		struct vout_t *vo_boot;

		MSG("[VOUT] %s (%d:%d:%d)\n",
			(fb_no == 0) ? "tvbox" : "virtual display",
			parm[0], parm[1], parm[2]);
		if (fb_no == 0) {
			g_vpp.virtual_display = 1;
			g_vpp.fb0_bitblit = 1;
		} else {
			g_vpp.stream_fb = fb_no;
		}
		vo_boot = kmalloc(sizeof(struct vout_t), GFP_KERNEL);
		if (vo_boot == 0)
			return 1;
		memset(vo_boot, 0, sizeof(struct vout_t));
		vo_boot->resx = parm[3];
		vo_boot->resy = parm[4];
		vo_boot->fps = parm[5];
		vo_boot->num = VPP_VOUT_NUM;
		vout_info_add_entry(fb_no, vo_boot);
		kfree(vo_boot);
		return 0;
	}

	vout = vout_get_entry_adapter(parm[0]);
	vout->inf = vout_get_inf_entry_adapter(parm[0]);
	vout->option[0] = parm[1];
	vout->option[1] = parm[2];
	vout->resx = parm[3];
	vout->resy = parm[4];
	vout->fps = parm[5];
	vout->disable = (parm[2] & VOUT_OPT_BLANK) ? 1 : 0;
	switch (parm[0]) {
	case VOUT_LVDS:
		{
		struct fb_videomode *vmode = 0;

		/* lvds auto detect edid */
		if ((parm[1] == 0) && (parm[3] == 0) && (parm[4] == 0)) {
			if (vout_get_edid_option(vout->num)) {
				vmode = &vout->edid_info.detail_timing[0];
				if (vmode->pixclock == 0) {
					vmode = 0;
					DBG_ERR("LVDS timing\n");
				}
			}

			if (vout->inf->get_edid(vout, (int)vout->edid) == 0) {
				if (edid_parse(vout->edid,
					&vout->edid_info) == 0)
					DBG_ERR("LVDS edid parse\n");
			} else {
				DBG_ERR("LVDS edid read\n");
			}
		}

		if (vmode == 0) { /* use internal timing */
			struct lcd_parm_t *p = 0;

			if (parm[1]) {
				p = lcd_get_parm(parm[1], parm[2]);
				if (p)
					lcd_set_lvds_id(parm[1]);
			}

			if (p == 0)
				p = lcd_get_oem_parm(parm[3], parm[4]);
			vmode = &p->vmode;
		}
		vout->option[2] = vmode->vmode;
		info->resx = vmode->xres;
		info->resy = vmode->yres;
		info->fps  = vmode->refresh;
		vout_info_set_fixed_timing(fb_no, vmode);
		lcd_set_type(1);
		}
	case VOUT_LCD:
		{
		struct vout_dev_t *dev;

		lcd_set_parm(parm[1], parm[2] & 0xFF);
		dev = lcd_get_dev();
		vout->dev = dev;
		dev->vout = vout;
		vout->option[0] = VDO_COL_FMT_ARGB;
		vout->option[1] &= ~0xFF;
		vout->option[1] |= VPP_DATAWIDHT_24;
		vout->dev->init(vout);
		vout_info_set_fixed_timing(fb_no, &p_lcd->vmode);
		}
		break;
	case VOUT_DVI:
		{
		struct vout_dev_t *dev = 0;

		g_vpp.dvi_int_disable =
			(parm[2] & WMT_DISP_FB_DISBALE_DVI_INT) ? 1 : 0;
		g_vpp.dvi_int_no = (parm[2] & WMT_DISP_FB_DVI_INT) ?
			((parm[1] & 0xF000) >> 12) : VPP_DVI_INT_DEFAULT;
		g_vpp.dvi_i2c_no = (parm[2] & WMT_DISP_FB_DVI_I2C) ?
			((parm[1] & 0xF00) >> 8) : VPP_DVI_I2C_DEFAULT;
		g_vpp.dvi_i2c_no &= VPP_DVI_I2C_ID_MASK;

		if (parm[2] & WMT_DISP_FB_DISABLE_EXTDEV)
			vout->dev = 0;
		else {
			vpp_i2c_init(VPP_DVI_I2C_ID, 0xA0);
			do {
				dev = vout_get_device(dev);
				if (dev == 0)
					break;
				if (vout->fix_cap & BIT(dev->mode)) {
					vout->inf =
						vout_inf_get_entry(dev->mode);
					if (dev->init(vout) == 0) {
						vout->dev = dev;
						dev->vout = vout;
						break;
					}
				}
			} while (1);
		}

		DBG_MSG("DVI ext dev : %s\n",
			(vout->dev) ? vout->dev->name : "NO");
		}
		info->option = (parm[2] & WMT_DISP_FB_INTERLACE) ?
			VPP_OPT_INTERLACE : 0;
		break;
	case VOUT_HDMI:
		info->option = (parm[2] & WMT_DISP_FB_INTERLACE) ?
			VPP_OPT_INTERLACE : 0;
#if 0 /* use old uboot param and wait next chip */
		g_vpp.hdmi_disable =
			(parm[2] & WMT_DISP_FB_HDMI_DISABLE) ? 1 : 0;

		g_vpp.hdmi_sp_mode =
			(parm[2] & WMT_DISP_FB_HDMI_SP_MODE) ? 1 : 0;
#endif
		break;
	default:
		break;
	}

	if (ret == 0)
		vout_info_add_entry(fb_no, vout);
	return ret;
}

int vout_check_display(void)
{
	#define BUF_LEN 100
	char buf[BUF_LEN];
	int varlen = BUF_LEN;
	unsigned int parm[32];
	int i, idx;

	if (wmt_getsyspara("wmt.display.fb0", buf, &varlen)) {
		/* default for no uboot parameter */
		parm[0] = VOUT_HDMI;
		parm[1] = VDO_COL_FMT_ARGB;
		parm[2] = VPP_DATAWIDHT_24;
		parm[3] = 1280;
		parm[4] = 720;
		parm[5] = 60;
		vout_add_display(0, &parm[0]);
		parm[0] = VOUT_DVI;
		parm[1] = VDO_COL_FMT_ARGB;
		parm[2] = VPP_DATAWIDHT_24;
		parm[3] = 1024;
		parm[4] = 768;
		parm[5] = 60;
		vout_add_display(0, &parm[0]);
		return 1;
	} else {
		int fb_no = 0;
		int num;

		while (fb_no < VPP_VOUT_INFO_NUM) {
			sprintf(buf, "wmt.display.fb%d", fb_no);
			varlen = BUF_LEN;
			if (wmt_getsyspara(buf, buf, &varlen))
				break;

			DBG_DETAIL("fb%d : %s\n", fb_no, buf);
			varlen = vpp_parse_param(buf,
				(unsigned int *)parm, 32, 0x1C1C1C1D);
			DBG_DETAIL("op 0x%x\n", parm[0]);
			num = (varlen - 1) / 7;
			for (i = 0; i < num; i++) {
				idx = 1 + 8 * i; /* [ + 6 + ] = 8 */
				DBG_DETAIL("%d : %x, %x, %x (%dx%d@%d)\n", i,
					parm[idx + 1], parm[idx + 2],
					parm[idx + 3], parm[idx + 4],
					parm[idx + 5], parm[idx + 6]);
				vout_add_display(fb_no, &parm[idx + 1]);
			}

			vout_info[fb_no]->multi =
				(parm[0] & WMT_DISP_FB_MULTI) ? 1 : 0;
			vout_info[fb_no]->alloc_mode = (parm[0] & 0xF);
			vout_info[fb_no]->hwc_mode = (parm[0] & 0xF0) >> 4;
			if (parm[0] & WMT_DISP_FB_COLFMT)
				vout_info[fb_no]->fb.col_fmt = ((parm[0] &
					WMT_DISP_FB_COLFMT_MASK) >> 16);
			fb_no++;
		}
	}

	/* [uboot parameter] oem timing :
		pixclk:option:hsync:hbp:hpixel:hfp:vsync:vbp:vpixel:vfp */
	varlen = BUF_LEN;
	if (wmt_getsyspara("wmt.display.tmr", buf, &varlen) == 0) {
		struct fb_videomode *p;
		int xres, yres;
		struct fb_videomode vo_oem_vmode;

		p = &vo_oem_vmode;
		DBG_MSG("tmr %s\n", buf);
		vpp_parse_param(buf, parm, 12, 0);
		p->pixclock = parm[0];
		p->vmode = parm[1];
		p->hsync_len = parm[2];
		p->left_margin = parm[3];
		p->xres = parm[4];
		p->right_margin = parm[5];
		p->vsync_len = parm[6];
		p->upper_margin = parm[7];
		p->yres = parm[8];
		p->lower_margin = parm[9];
		p->pixclock *= 1000;
		xres = p->hsync_len + p->left_margin + p->xres +
			p->right_margin;
		yres = p->vsync_len + p->upper_margin + p->yres +
			p->lower_margin;
		p->refresh = vpp_calc_refresh(p->pixclock, xres, yres);
		if (p->refresh == 59)
			p->refresh = 60;
		p->vmode = (parm[1] & VPP_OPT_INTERLACE) ? FB_VMODE_INTERLACED : 0;
		p->sync = (parm[1] & VPP_DVO_SYNC_POLAR_HI) ? FB_SYNC_HOR_HIGH_ACT : 0;
		p->sync |= (parm[1] & VPP_DVO_VSYNC_POLAR_HI) ? FB_SYNC_VERT_HIGH_ACT : 0;
		DBG_MSG("tmr pixclk %d,option 0x%x\n",
			p->pixclock, p->vmode);
		DBG_MSG("H sync %d,bp %d,pixel %d,fp %d\n", p->hsync_len,
			p->left_margin,	p->xres, p->right_margin);
		DBG_MSG("V sync %d,bp %d,pixel %d,fp %d\n", p->vsync_len,
			p->upper_margin, p->yres, p->lower_margin);
		p->pixclock = KHZ2PICOS(p->pixclock / 1000);
		vout_info_set_fixed_timing(0, &vo_oem_vmode);
		vout_info[0]->fixed_width = parm[10];
		vout_info[0]->fixed_height = parm[11];
		vout_info[0]->resx = p->xres;
		vout_info[0]->resy = p->yres;
		vout_info[0]->fps = p->refresh;
		vout_info[0]->vout[0]->resx = p->xres;
		vout_info[0]->vout[0]->resy = p->yres;
		vout_info[0]->vout[0]->fps = p->refresh;
	}
	return 0;
}

int vout_init(void)
{
	struct vout_info_t *info;
	struct vout_t *vout;
	int i, j;

	DBG_DETAIL("Enter\n");

	for(i = 0; i < VPP_VOUT_INFO_NUM; i++) {
		if(vout_info[i] != NULL) {
			kfree(vout_info[i]);
			vout_info[i] = NULL;
		}
	}

	/* register vout & set default */
	vout_register(0, &vout_entry_0);
	vout_entry_0.inf = vout_inf_get_entry(VOUT_INF_HDMI);
	vout_entry_0.govr = p_govrh;
	vout_register(1, &vout_entry_1);
	vout_entry_1.inf = vout_inf_get_entry(VOUT_INF_DVI);
	vout_entry_1.govr = p_govrh2;

	/* check vout info */
	DBG_DETAIL("check display\n");
	vout_check_display();

	/* initial vout */
	DBG_DETAIL("init display\n");
	for (i = 0; i < VPP_VOUT_INFO_NUM; i++) {
		info = vout_info[i];
		if (!info)
			break;
		for (j = 0; ; j++) {
			vout = info->vout[j];
			if (vout == 0)
				break;
			if (vout->inf)
				vout->inf->init(vout, 0);
		}
	}

	/* check monitor resolution */
	DBG_DETAIL("check resolution\n");
	for (i = 0; i < VPP_VOUT_INFO_NUM; i++) {
		struct vout_t *vout_first = 0;
		struct vout_t *vout_plug = 0;

		info = vout_info[i];
		if (!info)
			break;
		for (j = 0; ; j++) {
			vout = info->vout[j];
			if (vout == 0)
				break;

			if (vout_first == 0) /* first priority */
				vout_first = vout;

			if (vout_chkplug(vout->num)) {
				struct fb_videomode vmode;

				vmode.xres = vout->resx;
				vmode.yres = vout->resy;
				vmode.refresh = vout->fps;
				vmode.vmode = 0;
				vout_find_match_mode(i, &vmode, 1);
				vout->resx = vmode.xres;
				vout->resy = vmode.yres;
				vout->fps = vmode.refresh;
				if (vout_plug == 0) /* first plugin */
					vout_plug = vout;
			}

			if (info->multi)
				vout_change_status(vout,
					VPP_VOUT_STS_ACTIVE, 1);
		}

		vout = (vout_plug) ? vout_plug : vout_first;
		if (vout) {
			vout_change_status(vout, VPP_VOUT_STS_ACTIVE, 1);
			info->resx = vout->resx;
			info->resy = vout->resy;
			info->fps = vout->fps;
		}
	}

#ifdef DEBUG
	/* show display info */
	for (i = 0; i < VPP_VOUT_INFO_NUM; i++) {
		info = vout_info[i];
		if (!info)
			break;
		MSG("-----------------------------------------------------\n");
		MSG("fb%d, resx %d,resy %d,fps %d\n", i,
			info->resx, info->resy, info->fps);
		MSG("resx_vir %d,resy_vir %d,pixclk %d\n", info->resx_virtual,
			info->resy_virtual, info->pixclk);
		MSG("multi %d,alloc %d,option 0x%x\n", info->multi,
			info->alloc_mode, info->option);

		for (j = 0; ; j++) {
			vout = info->vout[j];
			if (vout == 0)
				break;
			vout_print_entry(vout);
		}
	}
	MSG("-----------------------------------------------------\n");
#endif
	DBG_DETAIL("Leave\n");
	return 0;
}

int vout_exit(void)
{
	return 0;
}