3 * DENX Software Engineering, Anatolij Gustschin, agust@denx.de
5 * See file CREDITS for list of people who contributed to this
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of
11 * the License, or (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
25 * mb862xx.c - Graphic interface for Fujitsu CoralP/Lime
26 * PCI and video mode code was derived from smiLynxEM driver.
34 #include "videomodes.h"
37 #if defined(CONFIG_POST)
44 GraphicDevice mb862xx;
47 * 32MB external RAM - 256K Chip MMIO = 0x1FC0000 ;
49 #define VIDEO_MEM_SIZE 0x01FC0000
51 #if defined(CONFIG_PCI)
52 #if defined(CONFIG_VIDEO_CORALP)
54 static struct pci_device_id supported[] = {
55 { PCI_VENDOR_ID_FUJITSU, PCI_DEVICE_ID_CORAL_P },
56 { PCI_VENDOR_ID_FUJITSU, PCI_DEVICE_ID_CORAL_PA },
60 /* Internal clock frequency divider table, index is mode number */
61 unsigned int fr_div[] = { 0x00000f00, 0x00000900, 0x00000500 };
65 #if defined(CONFIG_VIDEO_CORALP)
69 #define rd_io(addr) in_be32((volatile unsigned *)(addr))
70 #define wr_io(addr, val) out_be32((volatile unsigned *)(addr), (val))
73 #define HOST_RD_REG(off) rd_io((dev->frameAdrs + GC_HOST_BASE + (off)))
74 #define HOST_WR_REG(off, val) wr_io((dev->frameAdrs + GC_HOST_BASE + (off)), \
76 #define DISP_RD_REG(off) rd_io((dev->frameAdrs + GC_DISP_BASE + (off)))
77 #define DISP_WR_REG(off, val) wr_io((dev->frameAdrs + GC_DISP_BASE + (off)), \
79 #define DE_RD_REG(off) rd_io((dev->dprBase + (off)))
80 #define DE_WR_REG(off, val) wr_io((dev->dprBase + (off)), (val))
82 #if defined(CONFIG_VIDEO_CORALP)
83 #define DE_WR_FIFO(val) wr_io((dev->dprBase + (GC_GEO_FIFO)), (val))
85 #define DE_WR_FIFO(val) wr_io((dev->dprBase + (GC_FIFO)), (val))
88 #define L0PAL_WR_REG(idx, val) wr_io((dev->frameAdrs + \
89 (GC_DISP_BASE | GC_L0PAL0) + \
92 #if defined(CONFIG_VIDEO_MB862xx_ACCEL)
93 static void gdc_sw_reset (void)
95 GraphicDevice *dev = &mb862xx;
97 HOST_WR_REG (GC_SRST, 0x1);
103 static void de_wait (void)
105 GraphicDevice *dev = &mb862xx;
109 * Sync with software writes to framebuffer,
110 * try to reset if engine locked
112 while (DE_RD_REG (GC_CTR) & 0x00000131)
115 puts ("gdc reset done after drawing engine lock.\n");
120 static void de_wait_slots (int slots)
122 GraphicDevice *dev = &mb862xx;
125 /* Wait for free fifo slots */
126 while (DE_RD_REG (GC_IFCNT) < slots)
129 puts ("gdc reset done after drawing engine lock.\n");
135 #if !defined(CONFIG_VIDEO_CORALP)
136 static void board_disp_init (void)
138 GraphicDevice *dev = &mb862xx;
139 const gdc_regs *regs = board_get_regs ();
141 while (regs->index) {
142 DISP_WR_REG (regs->index, regs->value);
149 * Init drawing engine if accel enabled.
150 * Also clears visible framebuffer.
152 static void de_init (void)
154 GraphicDevice *dev = &mb862xx;
155 #if defined(CONFIG_VIDEO_MB862xx_ACCEL)
156 int cf = (dev->gdfBytesPP == 1) ? 0x0000 : 0x8000;
158 dev->dprBase = dev->frameAdrs + GC_DRAW_BASE;
160 /* Setup mode and fbbase, xres, fg, bg */
162 DE_WR_FIFO (0xf1010108);
163 DE_WR_FIFO (cf | 0x0300);
164 DE_WR_REG (GC_FBR, 0x0);
165 DE_WR_REG (GC_XRES, dev->winSizeX);
166 DE_WR_REG (GC_FC, 0x0);
167 DE_WR_REG (GC_BC, 0x0);
169 DE_WR_REG (GC_CXMIN, 0x0);
170 DE_WR_REG (GC_CXMAX, dev->winSizeX);
171 DE_WR_REG (GC_CYMIN, 0x0);
172 DE_WR_REG (GC_CYMAX, dev->winSizeY);
174 /* Clear framebuffer using drawing engine */
176 DE_WR_FIFO (0x09410000);
177 DE_WR_FIFO (0x00000000);
178 DE_WR_FIFO (dev->winSizeY << 16 | dev->winSizeX);
179 /* sync with SW access to framebuffer */
184 i = dev->winSizeX * dev->winSizeY;
185 p = (unsigned int *)dev->frameAdrs;
191 #if defined(CONFIG_VIDEO_CORALP)
192 /* use CCF and MMR parameters for Coral-P Eval. Board as default */
193 #ifndef CONFIG_SYS_MB862xx_CCF
194 #define CONFIG_SYS_MB862xx_CCF 0x00090000
196 #ifndef CONFIG_SYS_MB862xx_MMR
197 #define CONFIG_SYS_MB862xx_MMR 0x11d7fa13
200 unsigned int pci_video_init (void)
202 GraphicDevice *dev = &mb862xx;
206 if ((devbusfn = pci_find_devices (supported, 0)) < 0) {
207 puts("controller not present\n");
212 pci_write_config_dword (devbusfn, PCI_COMMAND,
213 (PCI_COMMAND_MEMORY | PCI_COMMAND_IO));
214 pci_read_config_dword (devbusfn, PCI_BASE_ADDRESS_0, &dev->frameAdrs);
215 dev->frameAdrs = pci_mem_to_phys (devbusfn, dev->frameAdrs);
217 if (dev->frameAdrs == 0) {
218 puts ("PCI config: failed to get base address\n");
222 dev->pciBase = dev->frameAdrs;
226 pci_read_config_word(devbusfn, PCI_DEVICE_ID, &device);
228 case PCI_DEVICE_ID_CORAL_P:
231 case PCI_DEVICE_ID_CORAL_PA:
239 /* Setup clocks and memory mode for Coral-P(A) */
240 HOST_WR_REG(GC_CCF, CONFIG_SYS_MB862xx_CCF);
242 HOST_WR_REG(GC_MMR, CONFIG_SYS_MB862xx_MMR);
244 return dev->frameAdrs;
247 unsigned int card_init (void)
249 GraphicDevice *dev = &mb862xx;
250 unsigned int cf, videomode, div = 0;
251 unsigned long t1, hsync, vsync;
254 struct ctfb_res_modes *res_mode;
255 struct ctfb_res_modes var_mode;
257 memset (dev, 0, sizeof (GraphicDevice));
259 if (!pci_video_init ())
264 /* get video mode via environment */
265 if ((penv = getenv ("videomode")) != NULL) {
266 /* decide if it is a string */
267 if (penv[0] <= '9') {
268 videomode = (int) simple_strtoul (penv, NULL, 16);
276 /* parameter are vesa modes, search params */
277 for (i = 0; i < VESA_MODES_COUNT; i++) {
278 if (vesa_modes[i].vesanr == videomode)
281 if (i == VESA_MODES_COUNT) {
282 printf ("\tno VESA Mode found, fallback to mode 0x%x\n",
286 res_mode = (struct ctfb_res_modes *)
287 &res_mode_init[vesa_modes[i].resindex];
288 if (vesa_modes[i].resindex > 2) {
289 puts ("\tUnsupported resolution, using default\n");
290 bpp = vesa_modes[1].bits_per_pixel;
293 bpp = vesa_modes[i].bits_per_pixel;
294 div = fr_div[vesa_modes[i].resindex];
296 res_mode = (struct ctfb_res_modes *) &var_mode;
297 bpp = video_get_params (res_mode, penv);
300 /* calculate hsync and vsync freq (info only) */
301 t1 = (res_mode->left_margin + res_mode->xres +
302 res_mode->right_margin + res_mode->hsync_len) / 8;
304 t1 *= res_mode->pixclock;
306 hsync = 1000000000L / t1;
307 t1 *= (res_mode->upper_margin + res_mode->yres +
308 res_mode->lower_margin + res_mode->vsync_len);
310 vsync = 1000000000L / t1;
312 /* fill in Graphic device struct */
313 sprintf (dev->modeIdent, "%dx%dx%d %ldkHz %ldHz", res_mode->xres,
314 res_mode->yres, bpp, (hsync / 1000), (vsync / 1000));
315 printf ("\t%s\n", dev->modeIdent);
316 dev->winSizeX = res_mode->xres;
317 dev->winSizeY = res_mode->yres;
318 dev->memSize = VIDEO_MEM_SIZE;
322 dev->gdfIndex = GDF__8BIT_INDEX;
327 dev->gdfIndex = GDF_15BIT_555RGB;
331 printf ("\t%d bpp configured, but only 8,15 and 16 supported\n",
333 puts ("\tfallback to 15bpp\n");
334 dev->gdfIndex = GDF_15BIT_555RGB;
338 /* Setup dot clock (internal pll, division rate) */
339 DISP_WR_REG (GC_DCM1, div);
341 cf = (dev->gdfBytesPP == 1) ? 0x00000000 : 0x80000000;
342 DISP_WR_REG (GC_L0M, ((dev->winSizeX * dev->gdfBytesPP) / 64) << 16 |
343 (dev->winSizeY - 1) | cf);
344 DISP_WR_REG (GC_L0OA0, 0x0);
345 DISP_WR_REG (GC_L0DA0, 0x0);
346 DISP_WR_REG (GC_L0DY_L0DX, 0x0);
347 DISP_WR_REG (GC_L0EM, 0x0);
348 DISP_WR_REG (GC_L0WY_L0WX, 0x0);
349 DISP_WR_REG (GC_L0WH_L0WW, (dev->winSizeY - 1) << 16 | dev->winSizeX);
351 /* Display timing init */
352 DISP_WR_REG (GC_HTP_A, (dev->winSizeX +
353 res_mode->left_margin +
354 res_mode->right_margin +
355 res_mode->hsync_len - 1) << 16);
356 DISP_WR_REG (GC_HDB_HDP_A, (dev->winSizeX - 1) << 16 |
357 (dev->winSizeX - 1));
358 DISP_WR_REG (GC_VSW_HSW_HSP_A, (res_mode->vsync_len - 1) << 24 |
359 (res_mode->hsync_len - 1) << 16 |
361 res_mode->right_margin - 1));
362 DISP_WR_REG (GC_VTR_A, (dev->winSizeY + res_mode->lower_margin +
363 res_mode->upper_margin +
364 res_mode->vsync_len - 1) << 16);
365 DISP_WR_REG (GC_VDP_VSP_A, (dev->winSizeY-1) << 16 |
367 res_mode->lower_margin - 1));
368 DISP_WR_REG (GC_WY_WX, 0x0);
369 DISP_WR_REG (GC_WH_WW, dev->winSizeY << 16 | dev->winSizeX);
370 /* Display enable, L0 layer */
371 DISP_WR_REG (GC_DCM1, 0x80010000 | div);
373 return dev->frameAdrs;
378 #if !defined(CONFIG_VIDEO_CORALP)
379 int mb862xx_probe(unsigned int addr)
381 GraphicDevice *dev = &mb862xx;
384 dev->frameAdrs = addr;
385 dev->dprBase = dev->frameAdrs + GC_DRAW_BASE;
387 /* Try to access GDC ID/Revision registers */
388 reg = HOST_RD_REG (GC_CID);
389 reg = HOST_RD_REG (GC_CID);
391 reg = DE_RD_REG(GC_REV);
392 reg = DE_RD_REG(GC_REV);
393 if ((reg & ~0xff) == 0x20050100)
394 return MB862XX_TYPE_LIME;
401 void *video_hw_init (void)
403 GraphicDevice *dev = &mb862xx;
405 puts ("Video: Fujitsu ");
407 memset (dev, 0, sizeof (GraphicDevice));
409 #if defined(CONFIG_VIDEO_CORALP)
410 if (card_init () == 0)
414 * Preliminary init of the onboard graphic controller,
415 * retrieve base address
417 if ((dev->frameAdrs = board_video_init ()) == 0) {
418 puts ("Controller not found!\n");
423 /* Set Change of Clock Frequency Register */
424 HOST_WR_REG (GC_CCF, CONFIG_SYS_MB862xx_CCF);
427 /* Set Memory I/F Mode Register) */
428 HOST_WR_REG (GC_MMR, CONFIG_SYS_MB862xx_MMR);
434 #if !defined(CONFIG_VIDEO_CORALP)
438 #if (defined(CONFIG_LWMON5) || \
439 defined(CONFIG_SOCRATES)) && !(CONFIG_POST & CONFIG_SYS_POST_SYSMON)
441 board_backlight_switch (1);
448 * Set a RGB color in the LUT
450 void video_set_lut (unsigned int index, unsigned char r,
451 unsigned char g, unsigned char b)
453 GraphicDevice *dev = &mb862xx;
455 L0PAL_WR_REG (index, (r << 16) | (g << 8) | (b));
458 #if defined(CONFIG_VIDEO_MB862xx_ACCEL)
460 * Drawing engine Fill and BitBlt screen region
462 void video_hw_rectfill (unsigned int bpp, unsigned int dst_x,
463 unsigned int dst_y, unsigned int dim_x,
464 unsigned int dim_y, unsigned int color)
466 GraphicDevice *dev = &mb862xx;
469 DE_WR_REG (GC_FC, color);
470 DE_WR_FIFO (0x09410000);
471 DE_WR_FIFO ((dst_y << 16) | dst_x);
472 DE_WR_FIFO ((dim_y << 16) | dim_x);
476 void video_hw_bitblt (unsigned int bpp, unsigned int src_x,
477 unsigned int src_y, unsigned int dst_x,
478 unsigned int dst_y, unsigned int width,
481 GraphicDevice *dev = &mb862xx;
482 unsigned int ctrl = 0x0d000000L;
484 if (src_x >= dst_x && src_y >= dst_y)
486 else if (src_x >= dst_x && src_y <= dst_y)
488 else if (src_x <= dst_x && src_y >= dst_y)
495 DE_WR_FIFO ((src_y << 16) | src_x);
496 DE_WR_FIFO ((dst_y << 16) | dst_x);
497 DE_WR_FIFO ((height << 16) | width);
498 de_wait (); /* sync */