uboot-s3c2410_fb.patch
[u-boot-openmoko/mini2440.git] / drivers / video / s3c2410_fb.c
blob9c299879a2a96721d7a1547293a1c78ca121642d
1 /*
2 * (C) Copyright 2006 by OpenMoko, Inc.
3 * Author: Harald Welte <laforge@openmoko.org>
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; either version 2 of
8 * the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
18 * MA 02111-1307 USA
21 #include <common.h>
23 #if defined(CONFIG_VIDEO_S3C2410)
25 #include <video_fb.h>
26 #include "videomodes.h"
27 #include <s3c2410.h>
29 * Export Graphic Device
31 GraphicDevice smi;
33 #define VIDEO_MEM_SIZE 0x200000 /* 480x640x16bit = 614400 bytes */
35 extern void board_video_init(GraphicDevice *pGD);
37 /*******************************************************************************
39 * Init video chip with common Linux graphic modes (lilo)
41 void *video_hw_init (void)
43 S3C24X0_LCD * const lcd = S3C24X0_GetBase_LCD();
44 GraphicDevice *pGD = (GraphicDevice *)&smi;
45 int videomode;
46 unsigned long t1, hsynch, vsynch;
47 char *penv;
48 int tmp, i, bits_per_pixel;
49 struct ctfb_res_modes *res_mode;
50 struct ctfb_res_modes var_mode;
51 unsigned char videoout;
53 /* Search for video chip */
54 printf("Video: ");
56 tmp = 0;
58 videomode = CFG_DEFAULT_VIDEO_MODE;
59 /* get video mode via environment */
60 if ((penv = getenv ("videomode")) != NULL) {
61 /* deceide if it is a string */
62 if (penv[0] <= '9') {
63 videomode = (int) simple_strtoul (penv, NULL, 16);
64 tmp = 1;
66 } else {
67 tmp = 1;
69 if (tmp) {
70 /* parameter are vesa modes */
71 /* search params */
72 for (i = 0; i < VESA_MODES_COUNT; i++) {
73 if (vesa_modes[i].vesanr == videomode)
74 break;
76 if (i == VESA_MODES_COUNT) {
77 printf ("no VESA Mode found, switching to mode 0x%x ", CFG_DEFAULT_VIDEO_MODE);
78 i = 0;
80 res_mode =
81 (struct ctfb_res_modes *) &res_mode_init[vesa_modes[i].
82 resindex];
83 bits_per_pixel = vesa_modes[i].bits_per_pixel;
84 } else {
86 res_mode = (struct ctfb_res_modes *) &var_mode;
87 bits_per_pixel = video_get_params (res_mode, penv);
90 /* calculate hsynch and vsynch freq (info only) */
91 t1 = (res_mode->left_margin + res_mode->xres +
92 res_mode->right_margin + res_mode->hsync_len) / 8;
93 t1 *= 8;
94 t1 *= res_mode->pixclock;
95 t1 /= 1000;
96 hsynch = 1000000000L / t1;
97 t1 *=
98 (res_mode->upper_margin + res_mode->yres +
99 res_mode->lower_margin + res_mode->vsync_len);
100 t1 /= 1000;
101 vsynch = 1000000000L / t1;
103 /* fill in Graphic device struct */
104 sprintf (pGD->modeIdent, "%dx%dx%d %ldkHz %ldHz", res_mode->xres,
105 res_mode->yres, bits_per_pixel, (hsynch / 1000),
106 (vsynch / 1000));
107 printf ("%s\n", pGD->modeIdent);
108 pGD->winSizeX = res_mode->xres;
109 pGD->winSizeY = res_mode->yres;
110 pGD->plnSizeX = res_mode->xres;
111 pGD->plnSizeY = res_mode->yres;
112 switch (bits_per_pixel) {
113 case 8:
114 pGD->gdfBytesPP = 1;
115 pGD->gdfIndex = GDF__8BIT_INDEX;
116 break;
117 case 15:
118 pGD->gdfBytesPP = 2;
119 pGD->gdfIndex = GDF_15BIT_555RGB;
120 break;
121 case 16:
122 pGD->gdfBytesPP = 2;
123 pGD->gdfIndex = GDF_16BIT_565RGB;
124 break;
125 case 24:
126 pGD->gdfBytesPP = 3;
127 pGD->gdfIndex = GDF_24BIT_888RGB;
128 break;
131 /* statically configure settings */
132 pGD->winSizeX = pGD->plnSizeX = 480;
133 pGD->winSizeY = pGD->plnSizeY = 640;
134 pGD->gdfBytesPP = 2;
135 pGD->gdfIndex = GDF_16BIT_565RGB;
137 pGD->frameAdrs = LCD_VIDEO_ADDR;
138 pGD->memSize = VIDEO_MEM_SIZE;
140 board_video_init(pGD);
142 lcd->LCDSADDR1 = pGD->frameAdrs >> 1;
144 /* This marks the end of the frame buffer. */
145 lcd->LCDSADDR2 = (lcd->LCDSADDR1&0x1fffff) + (pGD->winSizeX+0) * pGD->winSizeY;
146 lcd->LCDSADDR3 = pGD->winSizeX;
148 /* Clear video memory */
149 memset(pGD->frameAdrs, 0, pGD->memSize);
151 /* Enable Display */
152 lcd->LCDCON1 |= 0x01; /* ENVID = 1 */
154 return ((void*)&smi);
157 void
158 video_set_lut (unsigned int index, /* color number */
159 unsigned char r, /* red */
160 unsigned char g, /* green */
161 unsigned char b /* blue */
166 #endif /* CONFIG_VIDEO_S3C2410 */