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 * SPDX-License-Identifier: GPL-2.0+
15 #include "videomodes.h"
17 #include <fsl_diu_fb.h>
18 #include <linux/list.h>
21 /* This setting is used for the ifm pdm360ng with PRIMEVIEW PM070WL3 */
22 static struct fb_videomode fsl_diu_mode_800_480
= {
35 .vmode
= FB_VMODE_NONINTERLACED
38 /* For the SHARP LQ084S3LG01, used on the P1022DS board */
39 static struct fb_videomode fsl_diu_mode_800_600
= {
51 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
52 .vmode
= FB_VMODE_NONINTERLACED
56 * These parameters give default parameters
57 * for video output 1024x768,
58 * FIXME - change timing to proper amounts
59 * hsync 31.5kHz, vsync 60Hz
61 static struct fb_videomode fsl_diu_mode_1024_768
= {
62 .name
= "1024x768-60",
73 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
74 .vmode
= FB_VMODE_NONINTERLACED
77 static struct fb_videomode fsl_diu_mode_1280_1024
= {
78 .name
= "1280x1024-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_720
= {
94 .name
= "1280x720-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_1920_1080
= {
110 .name
= "1920x1080-60",
121 .sync
= FB_SYNC_COMP_HIGH_ACT
| FB_SYNC_VERT_HIGH_ACT
,
122 .vmode
= FB_VMODE_NONINTERLACED
126 * These are the fields of area descriptor(in DDR memory) for every plane
129 /* Word 0(32-bit) in DDR memory */
130 __le32 pix_fmt
; /* hard coding pixel format */
131 /* Word 1(32-bit) in DDR memory */
133 /* Word 2(32-bit) in DDR memory */
134 __le32 src_size_g_alpha
;
135 /* Word 3(32-bit) in DDR memory */
137 /* Word 4(32-bit) in DDR memory */
139 /* Word 5(32-bit) in DDR memory */
141 /* Word 6(32-bit) in DDR memory */
146 /* Word 7(32-bit) in DDR memory */
151 /* Word 8(32-bit) in DDR memory */
153 /* Word 9(32-bit) in DDR memory, just for 64-bit aligned */
155 } __attribute__ ((packed
));
181 } __attribute__ ((packed
));
184 void *vaddr
; /* Virtual address */
185 u32 paddr
; /* 32-bit physical address */
186 unsigned int offset
; /* Alignment offset */
189 static struct fb_info info
;
192 * Align to 64-bit(8-byte), 32-byte, etc.
194 static int allocate_buf(struct diu_addr
*buf
, u32 size
, u32 bytes_align
)
199 ssize
= size
+ bytes_align
;
200 buf
->vaddr
= malloc(ssize
);
204 memset(buf
->vaddr
, 0, ssize
);
205 mask
= bytes_align
- 1;
206 offset
= (u32
)buf
->vaddr
& mask
;
208 buf
->offset
= bytes_align
- offset
;
209 buf
->vaddr
+= offset
;
213 buf
->paddr
= virt_to_phys(buf
->vaddr
);
218 * Allocate a framebuffer and an Area Descriptor that points to it. Both
219 * are created in the same memory block. The Area Descriptor is updated to
220 * point to the framebuffer memory. Memory is aligned as needed.
222 static struct diu_ad
*allocate_fb(unsigned int xres
, unsigned int yres
,
223 unsigned int depth
, char **fb
)
225 unsigned long size
= xres
* yres
* depth
;
226 struct diu_addr addr
;
228 size_t ad_size
= roundup(sizeof(struct diu_ad
), 32);
231 * Allocate a memory block that holds the Area Descriptor and the
232 * frame buffer right behind it. To keep the code simple, everything
233 * is aligned on a 32-byte address.
235 if (allocate_buf(&addr
, ad_size
+ size
, 32) < 0)
239 ad
->addr
= cpu_to_le32(addr
.paddr
+ ad_size
);
240 ad
->aoi_size
= cpu_to_le32((yres
<< 16) | xres
);
241 ad
->src_size_g_alpha
= cpu_to_le32((yres
<< 12) | xres
);
246 *fb
= addr
.vaddr
+ ad_size
;
251 int fsl_diu_init(u16 xres
, u16 yres
, u32 pixel_format
, int gamma_fix
)
253 struct fb_videomode
*fsl_diu_mode_db
;
255 struct diu
*hw
= (struct diu
*)CONFIG_SYS_DIU_ADDR
;
256 u8
*gamma_table_base
;
258 struct diu_addr gamma
;
259 struct diu_addr cursor
;
261 /* Convert the X,Y resolution pair into a single number */
262 #define RESOLUTION(x, y) (((u32)(x) << 16) | (y))
264 switch (RESOLUTION(xres
, yres
)) {
265 case RESOLUTION(800, 480):
266 fsl_diu_mode_db
= &fsl_diu_mode_800_480
;
268 case RESOLUTION(800, 600):
269 fsl_diu_mode_db
= &fsl_diu_mode_800_600
;
271 case RESOLUTION(1024, 768):
272 fsl_diu_mode_db
= &fsl_diu_mode_1024_768
;
274 case RESOLUTION(1280, 1024):
275 fsl_diu_mode_db
= &fsl_diu_mode_1280_1024
;
277 case RESOLUTION(1280, 720):
278 fsl_diu_mode_db
= &fsl_diu_mode_1280_720
;
280 case RESOLUTION(1920, 1080):
281 fsl_diu_mode_db
= &fsl_diu_mode_1920_1080
;
284 printf("DIU: Unsupported resolution %ux%u\n", xres
, yres
);
289 info
.var
.xres
= fsl_diu_mode_db
->xres
;
290 info
.var
.yres
= fsl_diu_mode_db
->yres
;
291 info
.var
.bits_per_pixel
= 32;
292 info
.var
.pixclock
= fsl_diu_mode_db
->pixclock
;
293 info
.var
.left_margin
= fsl_diu_mode_db
->left_margin
;
294 info
.var
.right_margin
= fsl_diu_mode_db
->right_margin
;
295 info
.var
.upper_margin
= fsl_diu_mode_db
->upper_margin
;
296 info
.var
.lower_margin
= fsl_diu_mode_db
->lower_margin
;
297 info
.var
.hsync_len
= fsl_diu_mode_db
->hsync_len
;
298 info
.var
.vsync_len
= fsl_diu_mode_db
->vsync_len
;
299 info
.var
.sync
= fsl_diu_mode_db
->sync
;
300 info
.var
.vmode
= fsl_diu_mode_db
->vmode
;
301 info
.fix
.line_length
= info
.var
.xres
* info
.var
.bits_per_pixel
/ 8;
303 /* Memory allocation for framebuffer */
305 info
.var
.xres
* info
.var
.yres
* (info
.var
.bits_per_pixel
/ 8);
306 ad
= allocate_fb(info
.var
.xres
, info
.var
.yres
,
307 info
.var
.bits_per_pixel
/ 8, &info
.screen_base
);
309 printf("DIU: Out of memory\n");
313 ad
->pix_fmt
= pixel_format
;
315 /* Disable chroma keying function */
324 /* Initialize the gamma table */
325 if (allocate_buf(&gamma
, 256 * 3, 32) < 0) {
326 printf("DIU: Out of memory\n");
329 gamma_table_base
= gamma
.vaddr
;
330 for (i
= 0; i
<= 2; i
++)
331 for (j
= 0; j
< 256; j
++)
332 *gamma_table_base
++ = j
;
334 if (gamma_fix
== 1) { /* fix the gamma */
335 gamma_table_base
= gamma
.vaddr
;
336 for (i
= 0; i
< 256 * 3; i
++) {
337 gamma_table_base
[i
] = (gamma_table_base
[i
] << 2)
338 | ((gamma_table_base
[i
] >> 6) & 0x03);
342 /* Initialize the cursor */
343 if (allocate_buf(&cursor
, 32 * 32 * 2, 32) < 0) {
344 printf("DIU: Can't alloc cursor data\n");
348 /* Program DIU registers */
349 out_be32(&hw
->diu_mode
, 0); /* Temporarily disable the DIU */
351 out_be32(&hw
->gamma
, gamma
.paddr
);
352 out_be32(&hw
->cursor
, cursor
.paddr
);
353 out_be32(&hw
->bgnd
, 0x007F7F7F);
354 out_be32(&hw
->disp_size
, info
.var
.yres
<< 16 | info
.var
.xres
);
355 out_be32(&hw
->hsyn_para
, info
.var
.left_margin
<< 22 |
356 info
.var
.hsync_len
<< 11 |
357 info
.var
.right_margin
);
359 out_be32(&hw
->vsyn_para
, info
.var
.upper_margin
<< 22 |
360 info
.var
.vsync_len
<< 11 |
361 info
.var
.lower_margin
);
363 /* Pixel Clock configuration */
364 diu_set_pixel_clock(info
.var
.pixclock
);
366 /* Set the frame buffers */
367 out_be32(&hw
->desc
[0], virt_to_phys(ad
));
368 out_be32(&hw
->desc
[1], 0);
369 out_be32(&hw
->desc
[2], 0);
371 /* Enable the DIU, set display to all three planes */
372 out_be32(&hw
->diu_mode
, 1);
377 void *video_hw_init(void)
379 static GraphicDevice ctfb
;
381 unsigned int depth
= 0, freq
= 0;
383 if (!video_get_video_mode(&ctfb
.winSizeX
, &ctfb
.winSizeY
, &depth
, &freq
,
387 /* Find the monitor port, which is a required option */
390 if (strncmp(options
, "monitor=", 8) != 0)
393 if (platform_diu_init(ctfb
.winSizeX
, ctfb
.winSizeY
, options
+ 8) < 0)
396 /* fill in Graphic device struct */
397 sprintf(ctfb
.modeIdent
, "%ix%ix%i %ikHz %iHz",
398 ctfb
.winSizeX
, ctfb
.winSizeY
, depth
, 64, freq
);
400 ctfb
.frameAdrs
= (unsigned int)info
.screen_base
;
401 ctfb
.plnSizeX
= ctfb
.winSizeX
;
402 ctfb
.plnSizeY
= ctfb
.winSizeY
;
405 ctfb
.gdfIndex
= GDF_32BIT_X888RGB
;
409 ctfb
.memSize
= info
.screen_size
;
411 /* Cursor Start Address */