blob: 1a4ba82d755caa12a507f5bd744c718fbcd7bafb [file] [log] [blame]
Anatolij Gustschinbed53752008-01-11 14:30:01 +01001/*
2 * (C) Copyright 2007
3 * DENX Software Engineering, Anatolij Gustschin, agust@denx.de
4 *
5 * See file CREDITS for list of people who contributed to this
6 * project.
7 *
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.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
Jerry Van Barenae0b05d2009-02-05 22:18:02 -050015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Anatolij Gustschinbed53752008-01-11 14:30:01 +010016 * GNU General Public License for more details.
17 *
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,
21 * MA 02111-1307 USA
22 */
23
24/*
25 * mb862xx.c - Graphic interface for Fujitsu CoralP/Lime
26 * PCI and video mode code was derived from smiLynxEM driver.
27 */
28
29#include <common.h>
30
Anatolij Gustschinbed53752008-01-11 14:30:01 +010031#include <asm/io.h>
32#include <pci.h>
33#include <video_fb.h>
34#include "videomodes.h"
35#include <mb862xx.h>
36
Yuri Tikhonov0d489262008-03-24 11:30:54 +010037#if defined(CONFIG_POST)
38#include <post.h>
39#endif
Anatolij Gustschine8652862009-07-07 13:24:08 +020040
Anatolij Gustschinbed53752008-01-11 14:30:01 +010041/*
42 * Graphic Device
43 */
44GraphicDevice mb862xx;
45
46/*
47 * 32MB external RAM - 256K Chip MMIO = 0x1FC0000 ;
48 */
49#define VIDEO_MEM_SIZE 0x01FC0000
50
51#if defined(CONFIG_PCI)
52#if defined(CONFIG_VIDEO_CORALP)
53
54static 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 },
57 { }
58};
59
60/* Internal clock frequency divider table, index is mode number */
61unsigned int fr_div[] = { 0x00000f00, 0x00000900, 0x00000500 };
62#endif
63#endif
64
65#if defined(CONFIG_VIDEO_CORALP)
66#define rd_io in32r
67#define wr_io out32r
68#else
Anatolij Gustschine8652862009-07-07 13:24:08 +020069#define rd_io(addr) in_be32((volatile unsigned *)(addr))
70#define wr_io(addr, val) out_be32((volatile unsigned *)(addr), (val))
Anatolij Gustschinbed53752008-01-11 14:30:01 +010071#endif
72
Anatolij Gustschincce99b22009-07-07 13:27:07 +020073#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)), \
Anatolij Gustschine8652862009-07-07 13:24:08 +020075 (val))
Anatolij Gustschincce99b22009-07-07 13:27:07 +020076#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)), \
Anatolij Gustschine8652862009-07-07 13:24:08 +020078 (val))
79#define DE_RD_REG(off) rd_io((dev->dprBase + (off)))
80#define DE_WR_REG(off, val) wr_io((dev->dprBase + (off)), (val))
Anatolij Gustschinbed53752008-01-11 14:30:01 +010081
82#if defined(CONFIG_VIDEO_CORALP)
Anatolij Gustschincce99b22009-07-07 13:27:07 +020083#define DE_WR_FIFO(val) wr_io((dev->dprBase + (GC_GEO_FIFO)), (val))
Anatolij Gustschinbed53752008-01-11 14:30:01 +010084#else
Anatolij Gustschincce99b22009-07-07 13:27:07 +020085#define DE_WR_FIFO(val) wr_io((dev->dprBase + (GC_FIFO)), (val))
Anatolij Gustschinbed53752008-01-11 14:30:01 +010086#endif
87
Anatolij Gustschincce99b22009-07-07 13:27:07 +020088#define L0PAL_WR_REG(idx, val) wr_io((dev->frameAdrs + \
89 (GC_DISP_BASE | GC_L0PAL0) + \
Anatolij Gustschine8652862009-07-07 13:24:08 +020090 ((idx) << 2)), (val))
Anatolij Gustschinbed53752008-01-11 14:30:01 +010091
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +020092#if defined(CONFIG_VIDEO_MB862xx_ACCEL)
Anatolij Gustschine8652862009-07-07 13:24:08 +020093static void gdc_sw_reset (void)
Anatolij Gustschinbed53752008-01-11 14:30:01 +010094{
Anatolij Gustschine8652862009-07-07 13:24:08 +020095 GraphicDevice *dev = &mb862xx;
96
Anatolij Gustschincce99b22009-07-07 13:27:07 +020097 HOST_WR_REG (GC_SRST, 0x1);
Anatolij Gustschinbed53752008-01-11 14:30:01 +010098 udelay (500);
99 video_hw_init ();
100}
101
102
Anatolij Gustschine8652862009-07-07 13:24:08 +0200103static void de_wait (void)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100104{
Anatolij Gustschine8652862009-07-07 13:24:08 +0200105 GraphicDevice *dev = &mb862xx;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100106 int lc = 0x10000;
107
Anatolij Gustschine8652862009-07-07 13:24:08 +0200108 /*
109 * Sync with software writes to framebuffer,
110 * try to reset if engine locked
111 */
Anatolij Gustschincce99b22009-07-07 13:27:07 +0200112 while (DE_RD_REG (GC_CTR) & 0x00000131)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100113 if (lc-- < 0) {
114 gdc_sw_reset ();
Anatolij Gustschin9d173e02009-07-07 13:11:36 +0200115 puts ("gdc reset done after drawing engine lock.\n");
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100116 break;
117 }
118}
119
Anatolij Gustschine8652862009-07-07 13:24:08 +0200120static void de_wait_slots (int slots)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100121{
Anatolij Gustschine8652862009-07-07 13:24:08 +0200122 GraphicDevice *dev = &mb862xx;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100123 int lc = 0x10000;
124
125 /* Wait for free fifo slots */
Anatolij Gustschincce99b22009-07-07 13:27:07 +0200126 while (DE_RD_REG (GC_IFCNT) < slots)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100127 if (lc-- < 0) {
128 gdc_sw_reset ();
Anatolij Gustschin9d173e02009-07-07 13:11:36 +0200129 puts ("gdc reset done after drawing engine lock.\n");
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100130 break;
131 }
132}
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200133#endif
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100134
135#if !defined(CONFIG_VIDEO_CORALP)
Anatolij Gustschine8652862009-07-07 13:24:08 +0200136static void board_disp_init (void)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100137{
Anatolij Gustschine8652862009-07-07 13:24:08 +0200138 GraphicDevice *dev = &mb862xx;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100139 const gdc_regs *regs = board_get_regs ();
140
141 while (regs->index) {
142 DISP_WR_REG (regs->index, regs->value);
143 regs++;
144 }
145}
146#endif
147
148/*
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200149 * Init drawing engine if accel enabled.
150 * Also clears visible framebuffer.
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100151 */
152static void de_init (void)
153{
Anatolij Gustschine8652862009-07-07 13:24:08 +0200154 GraphicDevice *dev = &mb862xx;
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200155#if defined(CONFIG_VIDEO_MB862xx_ACCEL)
Anatolij Gustschine8652862009-07-07 13:24:08 +0200156 int cf = (dev->gdfBytesPP == 1) ? 0x0000 : 0x8000;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100157
Anatolij Gustschincce99b22009-07-07 13:27:07 +0200158 dev->dprBase = dev->frameAdrs + GC_DRAW_BASE;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100159
160 /* Setup mode and fbbase, xres, fg, bg */
161 de_wait_slots (2);
162 DE_WR_FIFO (0xf1010108);
163 DE_WR_FIFO (cf | 0x0300);
Anatolij Gustschincce99b22009-07-07 13:27:07 +0200164 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);
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100168 /* Reset clipping */
Anatolij Gustschincce99b22009-07-07 13:27:07 +0200169 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);
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100173
174 /* Clear framebuffer using drawing engine */
175 de_wait_slots (3);
176 DE_WR_FIFO (0x09410000);
177 DE_WR_FIFO (0x00000000);
Anatolij Gustschine8652862009-07-07 13:24:08 +0200178 DE_WR_FIFO (dev->winSizeY << 16 | dev->winSizeX);
Anatolij Gustschin322716a2008-07-12 17:31:36 +0200179 /* sync with SW access to framebuffer */
180 de_wait ();
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200181#else
182 unsigned int i, *p;
183
184 i = dev->winSizeX * dev->winSizeY;
185 p = (unsigned int *)dev->frameAdrs;
186 while (i--)
187 *p++ = 0;
188#endif
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100189}
190
191#if defined(CONFIG_VIDEO_CORALP)
Anatolij Gustschind7ffd272011-05-27 16:08:20 +0200192/* 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
195#endif
196#ifndef CONFIG_SYS_MB862xx_MMR
197#define CONFIG_SYS_MB862xx_MMR 0x11d7fa13
198#endif
199
Anatolij Gustschine8652862009-07-07 13:24:08 +0200200unsigned int pci_video_init (void)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100201{
Anatolij Gustschine8652862009-07-07 13:24:08 +0200202 GraphicDevice *dev = &mb862xx;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100203 pci_dev_t devbusfn;
Anatolij Gustschind7ffd272011-05-27 16:08:20 +0200204 u16 device;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100205
Anatolij Gustschine8652862009-07-07 13:24:08 +0200206 if ((devbusfn = pci_find_devices (supported, 0)) < 0) {
Anatolij Gustschin01b0f502011-07-16 22:28:23 +0200207 puts("controller not present\n");
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100208 return 0;
209 }
210
211 /* PCI setup */
Anatolij Gustschine8652862009-07-07 13:24:08 +0200212 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);
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100216
Anatolij Gustschine8652862009-07-07 13:24:08 +0200217 if (dev->frameAdrs == 0) {
Anatolij Gustschin9d173e02009-07-07 13:11:36 +0200218 puts ("PCI config: failed to get base address\n");
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100219 return 0;
220 }
221
Anatolij Gustschine8652862009-07-07 13:24:08 +0200222 dev->pciBase = dev->frameAdrs;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100223
Anatolij Gustschind7ffd272011-05-27 16:08:20 +0200224 puts("Coral-");
225
226 pci_read_config_word(devbusfn, PCI_DEVICE_ID, &device);
227 switch (device) {
228 case PCI_DEVICE_ID_CORAL_P:
229 puts("P\n");
230 break;
231 case PCI_DEVICE_ID_CORAL_PA:
232 puts("PA\n");
233 break;
234 default:
235 puts("Unknown\n");
236 return 0;
237 }
238
239 /* Setup clocks and memory mode for Coral-P(A) */
240 HOST_WR_REG(GC_CCF, CONFIG_SYS_MB862xx_CCF);
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100241 udelay (200);
Anatolij Gustschind7ffd272011-05-27 16:08:20 +0200242 HOST_WR_REG(GC_MMR, CONFIG_SYS_MB862xx_MMR);
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100243 udelay (100);
Anatolij Gustschine8652862009-07-07 13:24:08 +0200244 return dev->frameAdrs;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100245}
246
247unsigned int card_init (void)
248{
Anatolij Gustschine8652862009-07-07 13:24:08 +0200249 GraphicDevice *dev = &mb862xx;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100250 unsigned int cf, videomode, div = 0;
251 unsigned long t1, hsync, vsync;
252 char *penv;
253 int tmp, i, bpp;
254 struct ctfb_res_modes *res_mode;
255 struct ctfb_res_modes var_mode;
256
Anatolij Gustschine8652862009-07-07 13:24:08 +0200257 memset (dev, 0, sizeof (GraphicDevice));
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100258
Anatolij Gustschine8652862009-07-07 13:24:08 +0200259 if (!pci_video_init ())
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100260 return 0;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100261
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100262 tmp = 0;
263 videomode = 0x310;
264 /* get video mode via environment */
265 if ((penv = getenv ("videomode")) != NULL) {
Anatolij Gustschine8652862009-07-07 13:24:08 +0200266 /* decide if it is a string */
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100267 if (penv[0] <= '9') {
268 videomode = (int) simple_strtoul (penv, NULL, 16);
269 tmp = 1;
270 }
271 } else {
272 tmp = 1;
273 }
Anatolij Gustschine8652862009-07-07 13:24:08 +0200274
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100275 if (tmp) {
Anatolij Gustschine8652862009-07-07 13:24:08 +0200276 /* parameter are vesa modes, search params */
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100277 for (i = 0; i < VESA_MODES_COUNT; i++) {
278 if (vesa_modes[i].vesanr == videomode)
279 break;
280 }
281 if (i == VESA_MODES_COUNT) {
Anatolij Gustschine8652862009-07-07 13:24:08 +0200282 printf ("\tno VESA Mode found, fallback to mode 0x%x\n",
283 videomode);
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100284 i = 0;
285 }
Anatolij Gustschine8652862009-07-07 13:24:08 +0200286 res_mode = (struct ctfb_res_modes *)
287 &res_mode_init[vesa_modes[i].resindex];
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100288 if (vesa_modes[i].resindex > 2) {
Anatolij Gustschin9d173e02009-07-07 13:11:36 +0200289 puts ("\tUnsupported resolution, using default\n");
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100290 bpp = vesa_modes[1].bits_per_pixel;
291 div = fr_div[1];
292 }
293 bpp = vesa_modes[i].bits_per_pixel;
294 div = fr_div[vesa_modes[i].resindex];
295 } else {
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100296 res_mode = (struct ctfb_res_modes *) &var_mode;
297 bpp = video_get_params (res_mode, penv);
298 }
299
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;
303 t1 *= 8;
304 t1 *= res_mode->pixclock;
305 t1 /= 1000;
306 hsync = 1000000000L / t1;
307 t1 *= (res_mode->upper_margin + res_mode->yres +
308 res_mode->lower_margin + res_mode->vsync_len);
309 t1 /= 1000;
310 vsync = 1000000000L / t1;
311
312 /* fill in Graphic device struct */
Anatolij Gustschine8652862009-07-07 13:24:08 +0200313 sprintf (dev->modeIdent, "%dx%dx%d %ldkHz %ldHz", res_mode->xres,
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100314 res_mode->yres, bpp, (hsync / 1000), (vsync / 1000));
Anatolij Gustschine8652862009-07-07 13:24:08 +0200315 printf ("\t%s\n", dev->modeIdent);
316 dev->winSizeX = res_mode->xres;
317 dev->winSizeY = res_mode->yres;
318 dev->memSize = VIDEO_MEM_SIZE;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100319
320 switch (bpp) {
321 case 8:
Anatolij Gustschine8652862009-07-07 13:24:08 +0200322 dev->gdfIndex = GDF__8BIT_INDEX;
323 dev->gdfBytesPP = 1;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100324 break;
325 case 15:
326 case 16:
Anatolij Gustschine8652862009-07-07 13:24:08 +0200327 dev->gdfIndex = GDF_15BIT_555RGB;
328 dev->gdfBytesPP = 2;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100329 break;
330 default:
Anatolij Gustschine8652862009-07-07 13:24:08 +0200331 printf ("\t%d bpp configured, but only 8,15 and 16 supported\n",
332 bpp);
Anatolij Gustschin9d173e02009-07-07 13:11:36 +0200333 puts ("\tfallback to 15bpp\n");
Anatolij Gustschine8652862009-07-07 13:24:08 +0200334 dev->gdfIndex = GDF_15BIT_555RGB;
335 dev->gdfBytesPP = 2;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100336 }
337
338 /* Setup dot clock (internal pll, division rate) */
Anatolij Gustschincce99b22009-07-07 13:27:07 +0200339 DISP_WR_REG (GC_DCM1, div);
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100340 /* L0 init */
Anatolij Gustschine8652862009-07-07 13:24:08 +0200341 cf = (dev->gdfBytesPP == 1) ? 0x00000000 : 0x80000000;
Anatolij Gustschincce99b22009-07-07 13:27:07 +0200342 DISP_WR_REG (GC_L0M, ((dev->winSizeX * dev->gdfBytesPP) / 64) << 16 |
Anatolij Gustschine8652862009-07-07 13:24:08 +0200343 (dev->winSizeY - 1) | cf);
Anatolij Gustschincce99b22009-07-07 13:27:07 +0200344 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);
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100350
351 /* Display timing init */
Anatolij Gustschincce99b22009-07-07 13:27:07 +0200352 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 |
360 (dev->winSizeX +
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 |
366 (dev->winSizeY +
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);
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100370 /* Display enable, L0 layer */
Anatolij Gustschincce99b22009-07-07 13:27:07 +0200371 DISP_WR_REG (GC_DCM1, 0x80010000 | div);
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100372
Anatolij Gustschine8652862009-07-07 13:24:08 +0200373 return dev->frameAdrs;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100374}
375#endif
376
Wolfgang Grandeggerc28d3bb2009-10-23 12:03:13 +0200377
378#if !defined(CONFIG_VIDEO_CORALP)
379int mb862xx_probe(unsigned int addr)
380{
381 GraphicDevice *dev = &mb862xx;
382 unsigned int reg;
383
384 dev->frameAdrs = addr;
385 dev->dprBase = dev->frameAdrs + GC_DRAW_BASE;
386
387 /* Try to access GDC ID/Revision registers */
388 reg = HOST_RD_REG (GC_CID);
389 reg = HOST_RD_REG (GC_CID);
390 if (reg == 0x303) {
391 reg = DE_RD_REG(GC_REV);
392 reg = DE_RD_REG(GC_REV);
393 if ((reg & ~0xff) == 0x20050100)
394 return MB862XX_TYPE_LIME;
395 }
396
397 return 0;
398}
399#endif
400
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100401void *video_hw_init (void)
402{
Anatolij Gustschine8652862009-07-07 13:24:08 +0200403 GraphicDevice *dev = &mb862xx;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100404
Anatolij Gustschin9d173e02009-07-07 13:11:36 +0200405 puts ("Video: Fujitsu ");
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100406
Anatolij Gustschine8652862009-07-07 13:24:08 +0200407 memset (dev, 0, sizeof (GraphicDevice));
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100408
409#if defined(CONFIG_VIDEO_CORALP)
Anatolij Gustschine8652862009-07-07 13:24:08 +0200410 if (card_init () == 0)
411 return NULL;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100412#else
Anatolij Gustschine8652862009-07-07 13:24:08 +0200413 /*
414 * Preliminary init of the onboard graphic controller,
415 * retrieve base address
416 */
417 if ((dev->frameAdrs = board_video_init ()) == 0) {
Anatolij Gustschin9d173e02009-07-07 13:11:36 +0200418 puts ("Controller not found!\n");
Anatolij Gustschine8652862009-07-07 13:24:08 +0200419 return NULL;
Wolfgang Grandeggerc28d3bb2009-10-23 12:03:13 +0200420 } else {
Anatolij Gustschin9d173e02009-07-07 13:11:36 +0200421 puts ("Lime\n");
Wolfgang Grandeggerc28d3bb2009-10-23 12:03:13 +0200422
423 /* Set Change of Clock Frequency Register */
424 HOST_WR_REG (GC_CCF, CONFIG_SYS_MB862xx_CCF);
425 /* Delay required */
426 udelay(300);
427 /* Set Memory I/F Mode Register) */
428 HOST_WR_REG (GC_MMR, CONFIG_SYS_MB862xx_MMR);
429 }
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100430#endif
431
432 de_init ();
433
434#if !defined(CONFIG_VIDEO_CORALP)
Anatolij Gustschine8652862009-07-07 13:24:08 +0200435 board_disp_init ();
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100436#endif
437
Anatolij Gustschine64987a2008-08-15 15:42:13 +0200438#if (defined(CONFIG_LWMON5) || \
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200439 defined(CONFIG_SOCRATES)) && !(CONFIG_POST & CONFIG_SYS_POST_SYSMON)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100440 /* Lamp on */
441 board_backlight_switch (1);
442#endif
443
Anatolij Gustschine8652862009-07-07 13:24:08 +0200444 return dev;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100445}
446
447/*
448 * Set a RGB color in the LUT
449 */
Anatolij Gustschine8652862009-07-07 13:24:08 +0200450void video_set_lut (unsigned int index, unsigned char r,
451 unsigned char g, unsigned char b)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100452{
Anatolij Gustschine8652862009-07-07 13:24:08 +0200453 GraphicDevice *dev = &mb862xx;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100454
455 L0PAL_WR_REG (index, (r << 16) | (g << 8) | (b));
456}
457
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200458#if defined(CONFIG_VIDEO_MB862xx_ACCEL)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100459/*
460 * Drawing engine Fill and BitBlt screen region
461 */
Anatolij Gustschine8652862009-07-07 13:24:08 +0200462void 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)
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100465{
Anatolij Gustschine8652862009-07-07 13:24:08 +0200466 GraphicDevice *dev = &mb862xx;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100467
468 de_wait_slots (3);
Anatolij Gustschincce99b22009-07-07 13:27:07 +0200469 DE_WR_REG (GC_FC, color);
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100470 DE_WR_FIFO (0x09410000);
471 DE_WR_FIFO ((dst_y << 16) | dst_x);
472 DE_WR_FIFO ((dim_y << 16) | dim_x);
473 de_wait ();
474}
475
Anatolij Gustschine8652862009-07-07 13:24:08 +0200476void 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,
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100479 unsigned int height)
480{
Anatolij Gustschine8652862009-07-07 13:24:08 +0200481 GraphicDevice *dev = &mb862xx;
Anatolij Gustschinbed53752008-01-11 14:30:01 +0100482 unsigned int ctrl = 0x0d000000L;
483
484 if (src_x >= dst_x && src_y >= dst_y)
485 ctrl |= 0x00440000L;
486 else if (src_x >= dst_x && src_y <= dst_y)
487 ctrl |= 0x00460000L;
488 else if (src_x <= dst_x && src_y >= dst_y)
489 ctrl |= 0x00450000L;
490 else
491 ctrl |= 0x00470000L;
492
493 de_wait_slots (4);
494 DE_WR_FIFO (ctrl);
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 */
499}
Anatolij Gustschin5d16ca82009-10-23 12:03:14 +0200500#endif