2 * Copyright 2007, 2010-2011 Freescale Semiconductor, Inc.
3 * Authors: York Sun <yorksun@freescale.com>
4 * Timur Tabi <timur@freescale.com>
6 * FSL DIU Framebuffer driver
8 * See file CREDITS for list of people who contributed to this
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License as
13 * published by the Free Software Foundation; either version 2 of
14 * the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
31 #include "videomodes.h"
33 #include <fsl_diu_fb.h>
34 #include <linux/list.h>
37 /* This setting is used for the ifm pdm360ng with PRIMEVIEW PM070WL3 */
38 static struct fb_videomode fsl_diu_mode_800_480 = {
51 .vmode = FB_VMODE_NONINTERLACED
54 /* For the SHARP LQ084S3LG01, used on the P1022DS board */
55 static struct fb_videomode fsl_diu_mode_800_600 = {
67 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
68 .vmode = FB_VMODE_NONINTERLACED
72 * These parameters give default parameters
73 * for video output 1024x768,
74 * FIXME - change timing to proper amounts
75 * hsync 31.5kHz, vsync 60Hz
77 static struct fb_videomode fsl_diu_mode_1024_768 = {
78 .name = "1024x768-60",
89 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
90 .vmode = FB_VMODE_NONINTERLACED
93 static struct fb_videomode fsl_diu_mode_1280_1024 = {
94 .name = "1280x1024-60",
105 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
106 .vmode = FB_VMODE_NONINTERLACED
109 static struct fb_videomode fsl_diu_mode_1280_720 = {
110 .name = "1280x720-60",
121 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
122 .vmode = FB_VMODE_NONINTERLACED
125 static struct fb_videomode fsl_diu_mode_1920_1080 = {
126 .name = "1920x1080-60",
137 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
138 .vmode = FB_VMODE_NONINTERLACED
142 * These are the fields of area descriptor(in DDR memory) for every plane
145 /* Word 0(32-bit) in DDR memory */
146 __le32 pix_fmt; /* hard coding pixel format */
147 /* Word 1(32-bit) in DDR memory */
149 /* Word 2(32-bit) in DDR memory */
150 __le32 src_size_g_alpha;
151 /* Word 3(32-bit) in DDR memory */
153 /* Word 4(32-bit) in DDR memory */
155 /* Word 5(32-bit) in DDR memory */
157 /* Word 6(32-bit) in DDR memory */
162 /* Word 7(32-bit) in DDR memory */
167 /* Word 8(32-bit) in DDR memory */
169 /* Word 9(32-bit) in DDR memory, just for 64-bit aligned */
171 } __attribute__ ((packed));
197 } __attribute__ ((packed));
200 void *vaddr; /* Virtual address */
201 u32 paddr; /* 32-bit physical address */
202 unsigned int offset; /* Alignment offset */
205 static struct fb_info info;
208 * Align to 64-bit(8-byte), 32-byte, etc.
210 static int allocate_buf(struct diu_addr *buf, u32 size, u32 bytes_align)
215 ssize = size + bytes_align;
216 buf->vaddr = malloc(ssize);
220 memset(buf->vaddr, 0, ssize);
221 mask = bytes_align - 1;
222 offset = (u32)buf->vaddr & mask;
224 buf->offset = bytes_align - offset;
225 buf->vaddr += offset;
229 buf->paddr = virt_to_phys(buf->vaddr);
234 * Allocate a framebuffer and an Area Descriptor that points to it. Both
235 * are created in the same memory block. The Area Descriptor is updated to
236 * point to the framebuffer memory. Memory is aligned as needed.
238 static struct diu_ad *allocate_fb(unsigned int xres, unsigned int yres,
239 unsigned int depth, char **fb)
241 unsigned long size = xres * yres * depth;
242 struct diu_addr addr;
244 size_t ad_size = roundup(sizeof(struct diu_ad), 32);
247 * Allocate a memory block that holds the Area Descriptor and the
248 * frame buffer right behind it. To keep the code simple, everything
249 * is aligned on a 32-byte address.
251 if (allocate_buf(&addr, ad_size + size, 32) < 0)
255 ad->addr = cpu_to_le32(addr.paddr + ad_size);
256 ad->aoi_size = cpu_to_le32((yres << 16) | xres);
257 ad->src_size_g_alpha = cpu_to_le32((yres << 12) | xres);
262 *fb = addr.vaddr + ad_size;
267 int fsl_diu_init(u16 xres, u16 yres, u32 pixel_format, int gamma_fix)
269 struct fb_videomode *fsl_diu_mode_db;
271 struct diu *hw = (struct diu *)CONFIG_SYS_DIU_ADDR;
272 u8 *gamma_table_base;
274 struct diu_ad *dummy_ad;
275 struct diu_addr gamma;
276 struct diu_addr cursor;
278 /* Convert the X,Y resolution pair into a single number */
279 #define RESOLUTION(x, y) (((u32)(x) << 16) | (y))
281 switch (RESOLUTION(xres, yres)) {
282 case RESOLUTION(800, 480):
283 fsl_diu_mode_db = &fsl_diu_mode_800_480;
285 case RESOLUTION(800, 600):
286 fsl_diu_mode_db = &fsl_diu_mode_800_600;
288 case RESOLUTION(1024, 768):
289 fsl_diu_mode_db = &fsl_diu_mode_1024_768;
291 case RESOLUTION(1280, 1024):
292 fsl_diu_mode_db = &fsl_diu_mode_1280_1024;
294 case RESOLUTION(1280, 720):
295 fsl_diu_mode_db = &fsl_diu_mode_1280_720;
297 case RESOLUTION(1920, 1080):
298 fsl_diu_mode_db = &fsl_diu_mode_1920_1080;
301 printf("DIU: Unsupported resolution %ux%u\n", xres, yres);
305 /* The AD struct for the dummy framebuffer and the FB itself */
306 dummy_ad = allocate_fb(2, 4, 4, NULL);
308 printf("DIU: Out of memory\n");
311 dummy_ad->pix_fmt = 0x88883316;
314 info.var.xres = fsl_diu_mode_db->xres;
315 info.var.yres = fsl_diu_mode_db->yres;
316 info.var.bits_per_pixel = 32;
317 info.var.pixclock = fsl_diu_mode_db->pixclock;
318 info.var.left_margin = fsl_diu_mode_db->left_margin;
319 info.var.right_margin = fsl_diu_mode_db->right_margin;
320 info.var.upper_margin = fsl_diu_mode_db->upper_margin;
321 info.var.lower_margin = fsl_diu_mode_db->lower_margin;
322 info.var.hsync_len = fsl_diu_mode_db->hsync_len;
323 info.var.vsync_len = fsl_diu_mode_db->vsync_len;
324 info.var.sync = fsl_diu_mode_db->sync;
325 info.var.vmode = fsl_diu_mode_db->vmode;
326 info.fix.line_length = info.var.xres * info.var.bits_per_pixel / 8;
328 /* Memory allocation for framebuffer */
330 info.var.xres * info.var.yres * (info.var.bits_per_pixel / 8);
331 ad = allocate_fb(info.var.xres, info.var.yres,
332 info.var.bits_per_pixel / 8, &info.screen_base);
334 printf("DIU: Out of memory\n");
338 ad->pix_fmt = pixel_format;
340 /* Disable chroma keying function */
349 /* Initialize the gamma table */
350 if (allocate_buf(&gamma, 256 * 3, 32) < 0) {
351 printf("DIU: Out of memory\n");
354 gamma_table_base = gamma.vaddr;
355 for (i = 0; i <= 2; i++)
356 for (j = 0; j < 256; j++)
357 *gamma_table_base++ = j;
359 if (gamma_fix == 1) { /* fix the gamma */
360 gamma_table_base = gamma.vaddr;
361 for (i = 0; i < 256 * 3; i++) {
362 gamma_table_base[i] = (gamma_table_base[i] << 2)
363 | ((gamma_table_base[i] >> 6) & 0x03);
367 /* Initialize the cursor */
368 if (allocate_buf(&cursor, 32 * 32 * 2, 32) < 0) {
369 printf("DIU: Can't alloc cursor data\n");
373 /* Program DIU registers */
374 out_be32(&hw->diu_mode, 0); /* Temporarily disable the DIU */
376 out_be32(&hw->gamma, gamma.paddr);
377 out_be32(&hw->cursor, cursor.paddr);
378 out_be32(&hw->bgnd, 0x007F7F7F);
379 out_be32(&hw->bgnd_wb, 0);
380 out_be32(&hw->disp_size, info.var.yres << 16 | info.var.xres);
381 out_be32(&hw->wb_size, 0);
382 out_be32(&hw->wb_mem_addr, 0);
383 out_be32(&hw->hsyn_para, info.var.left_margin << 22 |
384 info.var.hsync_len << 11 |
385 info.var.right_margin);
387 out_be32(&hw->vsyn_para, info.var.upper_margin << 22 |
388 info.var.vsync_len << 11 |
389 info.var.lower_margin);
391 out_be32(&hw->syn_pol, 0);
392 out_be32(&hw->thresholds, 0x00037800);
393 out_be32(&hw->int_status, 0);
394 out_be32(&hw->int_mask, 0);
395 out_be32(&hw->plut, 0x01F5F666);
396 /* Pixel Clock configuration */
397 diu_set_pixel_clock(info.var.pixclock);
399 /* Set the frame buffers */
400 out_be32(&hw->desc[0], virt_to_phys(ad));
401 out_be32(&hw->desc[1], virt_to_phys(dummy_ad));
402 out_be32(&hw->desc[2], virt_to_phys(dummy_ad));
404 /* Enable the DIU, set display to all three planes */
405 out_be32(&hw->diu_mode, 1);
410 void *video_hw_init(void)
412 static GraphicDevice ctfb;
414 unsigned int depth = 0, freq = 0;
416 if (!video_get_video_mode(&ctfb.winSizeX, &ctfb.winSizeY, &depth, &freq,
420 /* Find the monitor port, which is a required option */
423 if (strncmp(options, "monitor=", 8) != 0)
426 if (platform_diu_init(ctfb.winSizeX, ctfb.winSizeY, options + 8) < 0)
429 /* fill in Graphic device struct */
430 sprintf(ctfb.modeIdent, "%ix%ix%i %ikHz %iHz",
431 ctfb.winSizeX, ctfb.winSizeY, depth, 64, freq);
433 ctfb.frameAdrs = (unsigned int)info.screen_base;
434 ctfb.plnSizeX = ctfb.winSizeX;
435 ctfb.plnSizeY = ctfb.winSizeY;
438 ctfb.gdfIndex = GDF_32BIT_X888RGB;
442 ctfb.memSize = info.screen_size;
444 /* Cursor Start Address */