xref: /rk3399_rockchip-uboot/board/freescale/ls1021aiot/dcu.c (revision 2d221489df021393654805536be7effcb9d39702)
1*20c700f8SFeng Li /*
2*20c700f8SFeng Li  * Copyright 2016 Freescale Semiconductor, Inc.
3*20c700f8SFeng Li  *
4*20c700f8SFeng Li  * FSL DCU Framebuffer driver
5*20c700f8SFeng Li  *
6*20c700f8SFeng Li  * SPDX-License-Identifier:	GPL-2.0+
7*20c700f8SFeng Li  */
8*20c700f8SFeng Li 
9*20c700f8SFeng Li #include <common.h>
10*20c700f8SFeng Li #include <fsl_dcu_fb.h>
11*20c700f8SFeng Li #include "div64.h"
12*20c700f8SFeng Li #include "../common/dcu_sii9022a.h"
13*20c700f8SFeng Li 
14*20c700f8SFeng Li DECLARE_GLOBAL_DATA_PTR;
15*20c700f8SFeng Li 
dcu_set_pixel_clock(unsigned int pixclock)16*20c700f8SFeng Li unsigned int dcu_set_pixel_clock(unsigned int pixclock)
17*20c700f8SFeng Li {
18*20c700f8SFeng Li 	unsigned long long div;
19*20c700f8SFeng Li 
20*20c700f8SFeng Li 	div = (unsigned long long)(gd->bus_clk / 1000);
21*20c700f8SFeng Li 	div *= (unsigned long long)pixclock;
22*20c700f8SFeng Li 	do_div(div, 1000000000);
23*20c700f8SFeng Li 
24*20c700f8SFeng Li 	return div;
25*20c700f8SFeng Li }
26*20c700f8SFeng Li 
platform_dcu_init(unsigned int xres,unsigned int yres,const char * port,struct fb_videomode * dcu_fb_videomode)27*20c700f8SFeng Li int platform_dcu_init(unsigned int xres, unsigned int yres,
28*20c700f8SFeng Li 		const char *port,
29*20c700f8SFeng Li 		struct fb_videomode *dcu_fb_videomode)
30*20c700f8SFeng Li {
31*20c700f8SFeng Li 	const char *name;
32*20c700f8SFeng Li 	unsigned int pixel_format;
33*20c700f8SFeng Li 
34*20c700f8SFeng Li 	if (strncmp(port, "twr_lcd", 4) == 0) {
35*20c700f8SFeng Li 		name = "TWR_LCD_RGB card";
36*20c700f8SFeng Li 	} else {
37*20c700f8SFeng Li 		name = "HDMI";
38*20c700f8SFeng Li 		dcu_set_dvi_encoder(dcu_fb_videomode);
39*20c700f8SFeng Li 	}
40*20c700f8SFeng Li 
41*20c700f8SFeng Li 	printf("DCU: Switching to %s monitor @ %ux%u\n", name, xres, yres);
42*20c700f8SFeng Li 
43*20c700f8SFeng Li 	pixel_format = 32;
44*20c700f8SFeng Li 	fsl_dcu_init(xres, yres, pixel_format);
45*20c700f8SFeng Li 
46*20c700f8SFeng Li 	return 0;
47*20c700f8SFeng Li }
48