summaryrefslogtreecommitdiff
path: root/arch/arm/cpu/armv8/imx8m/video_common.c
blob: ee7c844049e88ddd57adb0386f6be57190641a4b (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
/*
 * Copyright 2018 NXP
 *
 * SPDX-License-Identifier:	GPL-2.0+
 */

#include <common.h>
#include <dm.h>
#include <asm/io.h>
#include <linux/errno.h>
#include <asm/arch/clock.h>
#include <asm/arch/imx-regs.h>
#include <i2c.h>
#include <asm/arch/sys_proto.h>

#include <video_fb.h>
#include <asm/arch/video_common.h>
#include <power-domain.h>
#include <imx8_hdmi.h>

DECLARE_GLOBAL_DATA_PTR;

/* test congiurations */
#undef IMXDCSS_LOAD_HDMI_FIRMWARE
#undef IMXDCSS_SET_PIXEL_CLOCK

static struct video_mode_settings gmode;
static uint32_t gpixfmt;
GraphicDevice panel;
struct video_mode_settings *imx8m_get_gmode(void)
{
	return &gmode;
}

void imx8m_show_gmode(void)
{
	printf("gmode =\n"
	       "pixelclock = %u\n"
	       "xres       = %u\n"
	       "yres       = %u\n"
	       "hfp        = %u\n"
	       "hbp        = %u\n"
	       "vfp        = %u\n"
	       "vbp        = %u\n"
	       "hsync      = %u\n"
	       "vsync      = %u\n"
	       "hpol       = %u\n"
	       "vpol       = %u\n",
	       gmode.pixelclock,
	       gmode.xres,
	       gmode.yres,
	       gmode.hfp,
	       gmode.hbp,
	       gmode.vfp,
	       gmode.vbp, gmode.hsync, gmode.vsync, gmode.hpol, gmode.vpol);
}

GraphicDevice *imx8m_get_gd(void)
{
	return &panel;
}

#define REG_BASE_ADDR 0x32e00000UL

/*#define DEBUGREG*/
#ifdef DEBUGREG
#define reg32_write(addr, val) \
do { \
	debug("%s():%d 0x%08x -> 0x%08x\n", __func__, __LINE__, \
	(unsigned int)addr, (unsigned int)val); \
	__raw_writel(val, addr); \
} while (0)
#else
#define reg32_write(addr, val) __raw_writel(val, addr)
#endif

#define reg32_read(addr) __raw_readl(addr)

#define reg32setbit(addr, bitpos) \
	reg32_write((addr), (reg32_read((addr)) | (1<<(bitpos))))
#define reg32clearbit(addr, bitpos) \
	reg32_write((addr), (reg32_read((addr)) & ~(1<<(bitpos))))

#define reg32_read_tst(addr, val, mask) \
do { \
	u32 temp = reg32_read((addr)); \
	if ((temp & (mask)) == ((val) & (mask))) \
		debug("%s():%d 0x%08x -> 0x%08x\n", \
			__func__, __LINE__, addr, val); \
	else  \
		debug("%s():%d 0x%08x -> 0x%08x instead of 0x%08x\n", \
			__func__, __LINE__, addr, temp, val); \
} while (0)

#define COLOR_LIST_SIZE 8
static u32 color_list_argb32[COLOR_LIST_SIZE] = {
	0xFFFFFFFF,		/* white */
	0xFFFF0000,		/* red */
	0xFF00FF00,		/* green */
	0xFF0000FF,		/* blue */
	0xFFFFFF00,		/* yellow */
	0xFF00FFFF,		/* cyan */
	0xFFFF00FF,		/* magenta */
	0xFFC1C2C3,		/* silver */
};				/*AARRGGBB */

static unsigned int get_color_index(unsigned short px, unsigned short py,
				    unsigned short width, unsigned short height,
				    unsigned short bar_size)
{
	const int mw = 5;	/* margin width */
	if ((py >= 0 && py < mw) || (py >= height - mw && py < height) ||
	    (px >= 0 && px < mw) || (px >= width - mw && px < width)) {
		return 1;
	}

	return py / bar_size;
}

void imx8m_create_color_bar(void *start_address,
			   struct video_mode_settings *vms)
{
	/*struct video_mode_settings *vms = &vm_settings[g_vm]; */
	uint32_t color_bar_size = vms->yres / COLOR_LIST_SIZE;
	int i, j;
	u32 *pointer;
	int color_index = 0;
	pointer = (u32 *)start_address;
	uint32_t *color_map = &color_list_argb32[0];
	debug("%s(), %d: start_address %p\n",
	      __func__, __LINE__, start_address);
	debug("%s(), %d: pointer %p\n", __func__, __LINE__, pointer);
	debug("%s(), %d x %d\n", __func__, vms->xres, vms->yres);
	for (i = 0; i < vms->yres; i++) {
		for (j = 0; j < vms->xres; j++) {
			color_index = get_color_index(j, i, vms->xres,
						      vms->yres,
						      color_bar_size);
			*pointer = color_map[color_index];
			pointer++;
		}
	}
	invalidate_dcache_all();
}

static void imx8m_set_clocks(int apb_clk, int b_clk, int hdmi_core_clk,
		      int p_clk, int rtr_clk)
{
	if (b_clk == 800) {
		/* b_clk: bus_clk_root(4) sel 2nd input source and
		   pre_div to 0; output should be 800M */
		reg32_write(CCM_BUS_CLK_ROOT_GEN_TAGET_CLR(4),
			    (0x7 << 24) | (0x7 << 16));
		reg32_write(CCM_BUS_CLK_ROOT_GEN_TAGET_SET(4), (0x2 << 24));
	} else {
		printf("b_clk does not match a supported frequency");
	}
	if (rtr_clk == 400) {
		/* rtr_clk: bus_clk_root(6) sel 1st input source
		   and pre_div to 1; output should be 400M */
		reg32_write(CCM_BUS_CLK_ROOT_GEN_TAGET_CLR(6),
			    (0x7 << 24) | (0x7 << 16));
		reg32_write(CCM_BUS_CLK_ROOT_GEN_TAGET_SET(6),
			    (0x1 << 24) | (0x1 << 16));
	} else {
		debug("rtr_clk does not match a supported frequency");
	}

#ifdef IMXDCSS_LOAD_HDMI_FIRMWARE
	/* If ROM is loading HDMI firmware then this clock should not be set */
	if (hdmi_core_clk == 200) {
		/* hdmi_core_clk: ip_clk_root(69) sel 1st input source and
		   pre_div to 0 */
		reg32_write(CCM_IP_CLK_ROOT_GEN_TAGET_CLR(69),
			    (0x7 << 24) | (0x7 << 16));
		reg32_write(CCM_IP_CLK_ROOT_GEN_TAGET_SET(69), (0x1 << 24));
		g_hdmi_core_clock = 200000000;
	} else {
		debug("hdmi_core_clk does not match a supported frequency");
	}
#endif

#ifdef IMXDCSS_SET_PIXEL_CLOCK
	/* This would be needed for MIPI-DSI DCSS display */
	if (p_clk == 27) {
		/* p_clk: ip_clk_root(9) sel 1st input source and
		   pre_div to 1; post_div to 5, output 100M */
		reg32_write(CCM_IP_CLK_ROOT_GEN_TAGET_CLR(9),
			    (0x7 << 24) | (0x7 << 16));
		reg32_write(CCM_IP_CLK_ROOT_GEN_TAGET_SET(9),
			    (0x1 << 24) | (29 << 16));
	} else if (p_clk == 100) {
		/* p_clk: ip_clk_root(9) sel 1st input source and
		   pre_div to 1; post_div to 5, output 100M */
		reg32_write(CCM_IP_CLK_ROOT_GEN_TAGET_CLR(9),
			    (0x7 << 24) | (0x7 << 16));
		reg32_write(CCM_IP_CLK_ROOT_GEN_TAGET_SET(9),
			    (0x1 << 24) | (0x5 << 16));
	} else if (p_clk == 120) {
		/* p_clk: ip_clk_root(9) sel 1st input source and
		   pre_div to 1; post_div to 4, output 120M */
		reg32_write(CCM_IP_CLK_ROOT_GEN_TAGET_CLR(9),
			    (0x7 << 24) | (0x7 << 16));
		reg32_write(CCM_IP_CLK_ROOT_GEN_TAGET_SET(9),
			    (0x1 << 24) | (0x4 << 16));
	} else if (p_clk == 200) {
		/* I added this to speed up the pixel clock and
		   get frames out faster. may need to adjust this.
		 */
		reg32_write(CCM_IP_CLK_ROOT_GEN_TAGET_CLR(9),
			    (0x7 << 24) | (0x7 << 16));
		reg32_write(CCM_IP_CLK_ROOT_GEN_TAGET_SET(9),
			    (0x4 << 24) | (0x3 << 16)); /*for emu use 800 / 4 */
	} else if (p_clk == 400) {
		/* I added this to speed up the pixel clock and
		   get frames out faster. may need to adjust this.
		 */
		reg32_write(CCM_IP_CLK_ROOT_GEN_TAGET_CLR(9),
			    (0x7 << 24) | (0x7 << 16));
		reg32_write(CCM_IP_CLK_ROOT_GEN_TAGET_SET(9),
			    (0x4 << 24) | (0x1 << 16)); /*for emu use 800 / 2 */
	} else if (p_clk == 40) {	/* Do not reprogram, will get 40MHz */
	} else {
		debug("p_clk does not match a supported frequency");
	}
#endif
}

static int imx8m_power_init(uint32_t clock_control)
{
	u32 temp;
	/*struct video_mode_settings *vms = &vm_settings[g_vm]; */

	debug("\nenabling display clock...\n");
	clock_enable(CCGR_DISPLAY, 1);

	reg32_write(0x303A00EC, 0x0000ffff);	/*PGC_CPU_MAPPING */
	reg32setbit(0x303A00F8, 10);	/*PU_PGC_SW_PUP_REQ : disp was 10 */
#ifdef LOAD_HDMI_FIRMWARE
	reg32setbit(0x303A00F8, 9);	/*PU_PGC_SW_PUP_REQ : hdmi was 9 */
#endif
	imx8m_set_clocks(133, 800, 200, 27, 400);

	/* DCSS reset */
	reg32_write(0x32e2f000, 0xffffffff);

	/* DCSS clock selection */
	reg32_write(0x32e2f010, clock_control);
	temp = reg32_read(0x32e2f010);
	debug("%s(): DCSS clock control 0x%08x\n", __func__, temp);

	/* take DCSS out of reset - not needed OFB */
	/*__raw_writel(0xffffffff, 0x32e2f004); */

	return 0;
}

static void imx8m_display_init(u64 buffer, int encoding,
			       struct video_mode_settings *vms)
{
	/*struct video_mode_settings *vms = &vm_settings[g_vm]; */

	debug("entering %s() ...\n", __func__);
	debug("%s() buffer ...\n", __func__);

	/* DTRC-CHAN2/3 */
	reg32_write(REG_BASE_ADDR + 0x160c8, 0x00000002);
	reg32_write(REG_BASE_ADDR + 0x170c8, 0x00000002);

	/* CHAN1_DPR */
	reg32_write(REG_BASE_ADDR + 0x180c0, (unsigned int)buffer);
	reg32_write(REG_BASE_ADDR + 0x18090, 0x00000002);
	reg32_write(REG_BASE_ADDR + 0x180a0, vms->xres);
	reg32_write(REG_BASE_ADDR + 0x180b0, vms->yres);
	reg32_write(REG_BASE_ADDR + 0x18110,
		    (unsigned int)buffer + vms->xres * vms->yres);
	reg32_write(REG_BASE_ADDR + 0x180f0, 0x00000280);
	reg32_write(REG_BASE_ADDR + 0x18100, 0x000000f0);
	reg32_write(REG_BASE_ADDR + 0x18070, ((vms->xres * 4) << 16));
	reg32_write(REG_BASE_ADDR + 0x18050, 0x000e4203);
	reg32_write(REG_BASE_ADDR + 0x18050, 0x000e4203);
	reg32_write(REG_BASE_ADDR + 0x18200, 0x00000038);
	reg32_write(REG_BASE_ADDR + 0x18000, 0x00000004);
	reg32_write(REG_BASE_ADDR + 0x18000, 0x00000005);

	/* SCALER */
	reg32_write(REG_BASE_ADDR + 0x1c008, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c00c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c010, 0x00000002);
	reg32_write(REG_BASE_ADDR + 0x1c014, 0x00000002);
	reg32_write(REG_BASE_ADDR + 0x1c018,
		    ((vms->yres - 1) << 16 | (vms->xres - 1)));
	reg32_write(REG_BASE_ADDR + 0x1c01c,
		    ((vms->yres - 1) << 16 | (vms->xres - 1)));
	reg32_write(REG_BASE_ADDR + 0x1c020,
		    ((vms->yres - 1) << 16 | (vms->xres - 1)));
	reg32_write(REG_BASE_ADDR + 0x1c024,
		    ((vms->yres - 1) << 16 | (vms->xres - 1)));
	reg32_write(REG_BASE_ADDR + 0x1c028, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c02c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c030, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c034, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c038, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c03c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c040, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c044, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c048, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c04c, 0x00002000);
	reg32_write(REG_BASE_ADDR + 0x1c050, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c054, 0x00002000);
	reg32_write(REG_BASE_ADDR + 0x1c058, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c05c, 0x00002000);
	reg32_write(REG_BASE_ADDR + 0x1c060, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c064, 0x00002000);
	reg32_write(REG_BASE_ADDR + 0x1c080, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0c0, 0x00040000);
	reg32_write(REG_BASE_ADDR + 0x1c100, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c084, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0c4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c104, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c088, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0c8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c108, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c08c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0cc, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c10c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c090, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0d0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c110, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c094, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0d4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c114, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c098, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0d8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c118, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c09c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0dc, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c11c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0a0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0e0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c120, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0a4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0e4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c124, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0a8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0e8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c128, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0ac, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0ec, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c12c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0b0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0f0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c130, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0b4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0f4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c134, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0b8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0f8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c138, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0bc, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c0fc, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c13c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c140, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c180, 0x00040000);
	reg32_write(REG_BASE_ADDR + 0x1c1c0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c144, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c184, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1c4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c148, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c188, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1c8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c14c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c18c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1cc, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c150, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c190, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1d0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c154, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c194, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1d4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c158, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c198, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1d8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c15c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c19c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1dc, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c160, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1a0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1e0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c164, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1a4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1e4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c168, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1a8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1e8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c16c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1ac, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1ec, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c170, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1b0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1f0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c174, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1b4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1f4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c178, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1b8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1f8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c17c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1bc, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c1fc, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c300, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c340, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c380, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c304, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c344, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c384, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c308, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c348, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c388, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c30c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c34c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c38c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c310, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c350, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c390, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c314, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c354, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c394, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c318, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c358, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c398, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c31c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c35c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c39c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c320, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c360, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c3a0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c324, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c364, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c3a4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c328, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c368, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c3a8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c32c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c36c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c3ac, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c330, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c370, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c3b0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c334, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c374, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c3b4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c338, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c378, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c3b8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c33c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c37c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c3bc, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c200, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c240, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c280, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c204, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c244, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c284, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c208, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c248, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c288, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c20c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c24c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c28c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c210, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c250, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c290, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c214, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c254, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c294, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c218, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c258, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c298, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c21c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c25c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c29c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c220, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c260, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c2a0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c224, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c264, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c2a4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c228, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c268, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c2a8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c22c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c26c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c2ac, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c230, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c270, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c2b0, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c234, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c274, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c2b4, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c238, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c278, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c2b8, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c23c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c27c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c2bc, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c2bc, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x1c000, 0x00000011);

	/* SUBSAM */
	reg32_write(REG_BASE_ADDR + 0x1b070, 0x21612161);
	reg32_write(REG_BASE_ADDR + 0x1b080, 0x03ff0000);
	reg32_write(REG_BASE_ADDR + 0x1b090, 0x03ff0000);

	reg32_write(REG_BASE_ADDR + 0x1b010,
		    (((vms->vfp + vms->vbp + vms->vsync + vms->yres -
		       1) << 16) | (vms->hfp + vms->hbp + vms->hsync +
				    vms->xres - 1)));
	reg32_write(REG_BASE_ADDR + 0x1b020,
		    (((vms->hsync - 1) << 16) | vms->hpol << 31 | (vms->hfp +
								   vms->hbp +
								   vms->hsync +
								   vms->xres -
								   1)));
	reg32_write(REG_BASE_ADDR + 0x1b030,
		    (((vms->vfp + vms->vsync -
		       1) << 16) | vms->vpol << 31 | (vms->vfp - 1)));

	reg32_write(REG_BASE_ADDR + 0x1b040,
		    ((1 << 31) | ((vms->vsync + vms->vfp + vms->vbp) << 16) |
		     (vms->hsync + vms->hbp - 1)));
	reg32_write(REG_BASE_ADDR + 0x1b050,
		    (((vms->vsync + vms->vfp + vms->vbp + vms->yres -
		       1) << 16) | (vms->hsync + vms->hbp + vms->xres - 1)));

	/* subsample mode 0 none, 1 422, 2 420 */
	switch (encoding) {
	case 4:
		reg32_write(REG_BASE_ADDR + 0x1b060, 0x00000001);
		break;

	case 8:
		reg32_write(REG_BASE_ADDR + 0x1b060, 0x00000002);
		break;

	case 2:
	case 1:
	default:
		reg32_write(REG_BASE_ADDR + 0x1b060, 0x0000000);
	}

	reg32_write(REG_BASE_ADDR + 0x1b000, 0x00000001);
#if 0
	/* not needed for splash setup */
	/* HDR10 Chan3 LUT */
	reg32_write(REG_BASE_ADDR + 0x03874, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x03080, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x03000, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x03800, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x07874, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x07080, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x07000, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x07800, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0b874, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0b080, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0b000, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0b800, 0x00000000);

	/* HDR10 Tables and Registers */
	/*reg32_write(REG_BASE_ADDR+0x0f074, 0x00000003); */
	/*reg32_write(REG_BASE_ADDR+0x0f000, 0x00000004); */

	reg32_write(REG_BASE_ADDR + 0x0f004, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f008, 0x00000001);
	reg32_write(REG_BASE_ADDR + 0x0f00c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f010, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f014, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f018, 0x00000001);
	reg32_write(REG_BASE_ADDR + 0x0f01c, 0x00000001);
	reg32_write(REG_BASE_ADDR + 0x0f020, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f024, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f028, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f02c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f030, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f034, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f038, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f03c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f040, 0xffffffff);
	reg32_write(REG_BASE_ADDR + 0x0f044, 0xffffffff);
	reg32_write(REG_BASE_ADDR + 0x0f048, 0xffffffff);
	reg32_write(REG_BASE_ADDR + 0x0f04c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f050, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f054, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f058, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f05c, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f060, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f064, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f068, 0xffffffff);
	reg32_write(REG_BASE_ADDR + 0x0f06c, 0xffffffff);
	reg32_write(REG_BASE_ADDR + 0x0f070, 0xffffffff);
	reg32_write(REG_BASE_ADDR + 0x0f074, 0x00000000);
	reg32_write(REG_BASE_ADDR + 0x0f000, 0x00000003);
#endif
	/* DTG */
	/*reg32_write(REG_BASE_ADDR + 0x20000, 0xff000484); */
	/* disable local alpha */
	reg32_write(REG_BASE_ADDR + 0x20000, 0xff005084);
	reg32_write(REG_BASE_ADDR + 0x20004,
		    (((vms->vfp + vms->vbp + vms->vsync + vms->yres -
		       1) << 16) | (vms->hfp + vms->hbp + vms->hsync +
				    vms->xres - 1)));
	reg32_write(REG_BASE_ADDR + 0x20008,
		    (((vms->vsync + vms->vfp + vms->vbp -
		       1) << 16) | (vms->hsync + vms->hbp - 1)));
	reg32_write(REG_BASE_ADDR + 0x2000c,
		    (((vms->vsync + vms->vfp + vms->vbp + vms->yres -
		       1) << 16) | (vms->hsync + vms->hbp + vms->xres - 1)));
	reg32_write(REG_BASE_ADDR + 0x20010,
		    (((vms->vsync + vms->vfp + vms->vbp -
		       1) << 16) | (vms->hsync + vms->hbp - 1)));
	reg32_write(REG_BASE_ADDR + 0x20014,
		    (((vms->vsync + vms->vfp + vms->vbp + vms->yres -
		       1) << 16) | (vms->hsync + vms->hbp + vms->xres - 1)));
	reg32_write(REG_BASE_ADDR + 0x20028, 0x000b000a);

	/* disable local alpha */
	reg32_write(REG_BASE_ADDR + 0x20000, 0xff005184);

	debug("leaving %s() ...\n", __func__);
}

void imx8m_display_shutdown(void)
{
	/* stop the DCSS modules in use */
	/* dtg */
	reg32_write(REG_BASE_ADDR + 0x20000, 0);
	/* scaler */
	reg32_write(REG_BASE_ADDR + 0x1c000, 0);
	reg32_write(REG_BASE_ADDR + 0x1c400, 0);
	reg32_write(REG_BASE_ADDR + 0x1c800, 0);
	/* dpr */
	reg32_write(REG_BASE_ADDR + 0x18000, 0);
	reg32_write(REG_BASE_ADDR + 0x19000, 0);
	reg32_write(REG_BASE_ADDR + 0x1a000, 0);
	/* sub-sampler*/
	reg32_write(REG_BASE_ADDR + 0x1b000, 0);
#if 0
	/* reset the DCSS */
	reg32_write(0x32e2f000, 0xffffe8);
	udelay(100);
	reg32_write(0x32e2f000, 0xffffff);
#endif

}
void *video_hw_init(void)
{
	void *fb;
	int encoding = 1;

	debug("%s()\n", __func__);

	imx8m_power_init(0x1);

	panel.winSizeX = gmode.xres;
	panel.winSizeY = gmode.yres;
	panel.plnSizeX = gmode.xres;
	panel.plnSizeY = gmode.yres;
	panel.gdfBytesPP = 4;
	panel.gdfIndex = GDF_32BIT_X888RGB;
	panel.memSize = gmode.xres * gmode.yres * panel.gdfBytesPP;

	/* Allocate framebuffer */
	fb = memalign(0x1000, roundup(panel.memSize, 0x1000));
	debug("%s(): fb %p\n", __func__, fb);
	if (!fb) {
		printf("%s, %s(): Error allocating framebuffer!\n",
		       __FILE__, __func__);
		return NULL;
	}

	imx8m_create_color_bar((void *)((uint64_t) fb), &gmode);

	imx8_hdmi_enable(encoding, &gmode); /* may change gmode */

	/* start dccs */
	imx8m_display_init((uint64_t) fb, encoding, &gmode);

	panel.frameAdrs = (ulong) fb;
	debug("IMXDCSS display started ...\n");

	return &panel;
}

void imx8m_fb_disable(void)
{
	debug("%s()\n", __func__);
	if (panel.frameAdrs) {
#ifdef CONFIG_VIDEO_IMX8_HDMI
		imx8_hdmi_disable();
#endif
		imx8m_display_shutdown();
	}

}

int imx8m_fb_init(struct fb_videomode const *mode,
		    uint8_t disp, uint32_t pixfmt)
{
	debug("entering %s()\n", __func__);

	if (disp > 1) {
		debug("Invalid disp parameter %d for imxdcss_fb_init()\n",
		      disp);
		return -EINVAL;
	}

	memset(&gmode, 0, sizeof(struct video_mode_settings));
	gmode.pixelclock = PS2KHZ(mode->pixclock) * 1000;
	gmode.xres = mode->xres;
	gmode.hbp = mode->left_margin;
	gmode.hfp = mode->right_margin;

	gmode.yres = mode->yres;
	gmode.vbp = mode->upper_margin;
	gmode.vfp = mode->lower_margin;

	gmode.hsync = mode->hsync_len;
	gmode.vsync = mode->vsync_len;
	gmode.hpol = (mode->flag & FB_SYNC_HOR_HIGH_ACT) ? 1 : 0;
	gmode.vpol = (mode->flag & FB_SYNC_VERT_HIGH_ACT) ? 1 : 0;
	gpixfmt = pixfmt;

	debug("leaving %s()\n", __func__);

	return 0;
}