xref: /openbmc/u-boot/board/freescale/mpc8610hpcd/mpc8610hpcd_diu.c (revision 2e6e1772c0e34871769be4aef79748fe3e47d953)
1 /*
2  * Copyright 2007 Freescale Semiconductor, Inc.
3  * York Sun <yorksun@freescale.com>
4  *
5  * FSL DIU Framebuffer driver
6  *
7  * See file CREDITS for list of people who contributed to this
8  * project.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of
13  * the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307 USA
24  */
25 
26 #include <common.h>
27 #include <command.h>
28 #include <asm/io.h>
29 
30 #ifdef CONFIG_FSL_DIU_FB
31 
32 #include "../common/fsl_diu_fb.h"
33 
34 #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
35 #include <stdio_dev.h>
36 #include <video_fb.h>
37 #endif
38 
39 static int xres, yres;
40 
41 void diu_set_pixel_clock(unsigned int pixclock)
42 {
43 	volatile immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
44 	volatile ccsr_gur_t *gur = &immap->im_gur;
45 	volatile unsigned int *guts_clkdvdr = &gur->clkdvdr;
46 	unsigned long speed_ccb, temp, pixval;
47 
48 	speed_ccb = get_bus_freq(0);
49 	temp = 1000000000/pixclock;
50 	temp *= 1000;
51 	pixval = speed_ccb / temp;
52 	debug("DIU pixval = %lu\n", pixval);
53 
54 	/* Modify PXCLK in GUTS CLKDVDR */
55 	debug("DIU: Current value of CLKDVDR = 0x%08x\n", *guts_clkdvdr);
56 	temp = *guts_clkdvdr & 0x2000FFFF;
57 	*guts_clkdvdr = temp;				/* turn off clock */
58 	*guts_clkdvdr = temp | 0x80000000 | ((pixval & 0x1F) << 16);
59 	debug("DIU: Modified value of CLKDVDR = 0x%08x\n", *guts_clkdvdr);
60 }
61 
62 int mpc8610hpcd_diu_init(void)
63 {
64 	char *monitor_port;
65 	int gamma_fix;
66 	unsigned int pixel_format;
67 	unsigned char tmp_val;
68 	unsigned char pixis_arch;
69 	u8 *pixis_base = (u8 *)PIXIS_BASE;
70 
71 	tmp_val = in_8(pixis_base + PIXIS_BRDCFG0);
72 	pixis_arch = in_8(pixis_base + PIXIS_VER);
73 
74 	monitor_port = getenv("monitor");
75 	if (!strncmp(monitor_port, "0", 1)) {	/* 0 - DVI */
76 		xres = 1280;
77 		yres = 1024;
78 		if (pixis_arch == 0x01)
79 			pixel_format = 0x88882317;
80 		else
81 			pixel_format = 0x88883316;
82 		gamma_fix = 0;
83 		out_8(pixis_base + PIXIS_BRDCFG0, tmp_val | 0x08);
84 
85 	} else if (!strncmp(monitor_port, "1", 1)) { /* 1 - Single link LVDS */
86 		xres = 1024;
87 		yres = 768;
88 		pixel_format = 0x88883316;
89 		gamma_fix = 0;
90 		out_8(pixis_base + PIXIS_BRDCFG0, (tmp_val & 0xf7) | 0x10);
91 
92 	} else if (!strncmp(monitor_port, "2", 1)) { /* 2 - Double link LVDS */
93 		xres = 1280;
94 		yres = 1024;
95 		pixel_format = 0x88883316;
96 		gamma_fix = 1;
97 		out_8(pixis_base + PIXIS_BRDCFG0, tmp_val & 0xe7);
98 
99 	} else {	/* DVI */
100 		xres = 1280;
101 		yres = 1024;
102 		pixel_format = 0x88882317;
103 		gamma_fix = 0;
104 		out_8(pixis_base + PIXIS_BRDCFG0, tmp_val | 0x08);
105 	}
106 
107 	return fsl_diu_init(xres, pixel_format, gamma_fix);
108 }
109 
110 #if defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE)
111 
112 /*
113  * The Graphic Device
114  */
115 static GraphicDevice ctfb;
116 
117 void *video_hw_init(void)
118 {
119 	struct fb_info *info;
120 
121 	if (mpc8610hpcd_diu_init() < 0)
122 		return NULL;
123 
124 	/* fill in Graphic device struct */
125 	sprintf(ctfb.modeIdent, "%ix%ix%i %ikHz %iHz", xres, yres, 32, 64, 60);
126 
127 	ctfb.frameAdrs = (unsigned int)fsl_fb_open(&info);
128 	ctfb.winSizeX = xres;
129 	ctfb.winSizeY = yres;
130 	ctfb.plnSizeX = ctfb.winSizeX;
131 	ctfb.plnSizeY = ctfb.winSizeY;
132 
133 	ctfb.gdfBytesPP = 4;
134 	ctfb.gdfIndex = GDF_32BIT_X888RGB;
135 
136 	ctfb.isaBase = 0;
137 	ctfb.pciBase = 0;
138 	ctfb.memSize = info->screen_size;
139 
140 	/* Cursor Start Address */
141 	ctfb.dprBase = 0;
142 	ctfb.vprBase = 0;
143 	ctfb.cprBase = 0;
144 
145 	return &ctfb;
146 }
147 
148 #endif /* defined(CONFIG_VIDEO) || defined(CONFIG_CFB_CONSOLE) */
149 
150 #endif /* CONFIG_FSL_DIU_FB */
151