+ char *penv;
+ u32 memsize;
+ unsigned long t1, hsynch, vsynch;
+ int bits_per_pixel, i, tmp, vesa_idx = 0, videomode;
+
+ tmp = 0;
+
+ puts("Video: ");
+
+ videomode = CONFIG_SYS_DEFAULT_VIDEO_MODE;
+ /* get video mode via environment */
+ penv = getenv("videomode");
+ if (penv) {
+ /* decide if it is a string */
+ if (penv[0] <= '9') {
+ videomode = (int) simple_strtoul(penv, NULL, 16);
+ tmp = 1;
+ }
+ } else {
+ tmp = 1;
+ }
+ if (tmp) {
+ /* parameter are vesa modes */
+ /* search params */
+ for (i = 0; i < VESA_MODES_COUNT; i++) {
+ if (vesa_modes[i].vesanr == videomode)
+ break;
+ }
+ if (i == VESA_MODES_COUNT) {
+ printf("No VESA Mode found, switching to mode 0x%x ",
+ CONFIG_SYS_DEFAULT_VIDEO_MODE);
+ i = 0;
+ }
+ mode = (struct ctfb_res_modes *)
+ &res_mode_init[vesa_modes[i].resindex];
+ bits_per_pixel = vesa_modes[i].bits_per_pixel;
+ vesa_idx = vesa_modes[i].resindex;
+ } else {
+ mode = (struct ctfb_res_modes *) &var_mode;
+ bits_per_pixel = video_get_params(mode, penv);
+ }
+
+ /* calculate hsynch and vsynch freq (info only) */
+ t1 = (mode->left_margin + mode->xres +
+ mode->right_margin + mode->hsync_len) / 8;
+ t1 *= 8;
+ t1 *= mode->pixclock;
+ t1 /= 1000;
+ hsynch = 1000000000L / t1;
+ t1 *= (mode->upper_margin + mode->yres +
+ mode->lower_margin + mode->vsync_len);
+ t1 /= 1000;
+ vsynch = 1000000000L / t1;
+
+ /* fill in Graphic device struct */
+ sprintf(panel.modeIdent, "%dx%dx%d %ldkHz %ldHz",
+ mode->xres, mode->yres,
+ bits_per_pixel, (hsynch / 1000), (vsynch / 1000));
+ printf("%s\n", panel.modeIdent);
+ panel.winSizeX = mode->xres;
+ panel.winSizeY = mode->yres;
+ panel.plnSizeX = mode->xres;
+ panel.plnSizeY = mode->yres;
+
+ switch (bits_per_pixel) {
+ case 24:
+ panel.gdfBytesPP = 4;
+ panel.gdfIndex = GDF_32BIT_X888RGB;
+ break;
+ case 16:
+ panel.gdfBytesPP = 2;
+ panel.gdfIndex = GDF_16BIT_565RGB;
+ break;
+ default:
+ panel.gdfBytesPP = 1;
+ panel.gdfIndex = GDF__8BIT_INDEX;
+ break;
+ }
+
+ /* set up Hardware */
+ memsize = calc_fbsize();
+
+ debug("%s() allocating %d bytes\n", __func__, memsize);
+
+ /* fill in missing Graphic device struct */
+ panel.frameAdrs = (u32) malloc(memsize);
+ if (panel.frameAdrs == 0) {
+ printf("%s() malloc(%d) failed\n", __func__, memsize);
+ return 0;
+ }
+ panel.memSize = memsize;
+
+ ll_disp3_enable((void *) panel.frameAdrs);
+ memset((void *) panel.frameAdrs, 0, memsize);
+
+ debug("%s() done, framebuffer at 0x%x, size=%d cleared\n",
+ __func__, panel.frameAdrs, memsize);
+
+ return (void *) &panel;