blob: e7f077e0f7e6c8b2033b148402190e88975c5ef6 [file] [log] [blame]
York Sunb7145172007-10-29 13:58:39 -05001/*
Jerry Huang54e4b892010-04-08 15:56:07 +08002 * Copyright 2007, 2010 Freescale Semiconductor, Inc.
York Sunb7145172007-10-29 13:58:39 -05003 * York Sun <yorksun@freescale.com>
4 *
5 * FSL DIU Framebuffer driver
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
York Sunb7145172007-10-29 13:58:39 -050026#include <common.h>
27#include <i2c.h>
28#include <malloc.h>
Jerry Huang54e4b892010-04-08 15:56:07 +080029#include <asm/io.h>
York Sunb7145172007-10-29 13:58:39 -050030
York Sunb7145172007-10-29 13:58:39 -050031#include "fsl_diu_fb.h"
32
York Sunb7145172007-10-29 13:58:39 -050033struct fb_videomode {
34 const char *name; /* optional */
35 unsigned int refresh; /* optional */
36 unsigned int xres;
37 unsigned int yres;
38 unsigned int pixclock;
39 unsigned int left_margin;
40 unsigned int right_margin;
41 unsigned int upper_margin;
42 unsigned int lower_margin;
43 unsigned int hsync_len;
44 unsigned int vsync_len;
45 unsigned int sync;
46 unsigned int vmode;
47 unsigned int flag;
48};
49
50#define FB_SYNC_VERT_HIGH_ACT 2 /* vertical sync high active */
51#define FB_SYNC_COMP_HIGH_ACT 8 /* composite sync high active */
52#define FB_VMODE_NONINTERLACED 0 /* non interlaced */
53
Anatolij Gustschin81cad142010-04-24 19:27:09 +020054/* This setting is used for the ifm pdm360ng with PRIMEVIEW PM070WL3 */
55static struct fb_videomode fsl_diu_mode_800 = {
56 .refresh = 60,
57 .xres = 800,
58 .yres = 480,
59 .pixclock = 31250,
60 .left_margin = 86,
61 .right_margin = 42,
62 .upper_margin = 33,
63 .lower_margin = 10,
64 .hsync_len = 128,
65 .vsync_len = 2,
66 .sync = 0,
67 .vmode = FB_VMODE_NONINTERLACED
68};
69
York Sunb7145172007-10-29 13:58:39 -050070/*
71 * These parameters give default parameters
72 * for video output 1024x768,
73 * FIXME - change timing to proper amounts
74 * hsync 31.5kHz, vsync 60Hz
75 */
76static struct fb_videomode fsl_diu_mode_1024 = {
77 .refresh = 60,
78 .xres = 1024,
79 .yres = 768,
80 .pixclock = 15385,
81 .left_margin = 160,
82 .right_margin = 24,
83 .upper_margin = 29,
84 .lower_margin = 3,
85 .hsync_len = 136,
86 .vsync_len = 6,
87 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
88 .vmode = FB_VMODE_NONINTERLACED
89};
90
91static struct fb_videomode fsl_diu_mode_1280 = {
92 .name = "1280x1024-60",
93 .refresh = 60,
94 .xres = 1280,
95 .yres = 1024,
96 .pixclock = 9375,
97 .left_margin = 38,
98 .right_margin = 128,
99 .upper_margin = 2,
100 .lower_margin = 7,
101 .hsync_len = 216,
102 .vsync_len = 37,
103 .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT,
104 .vmode = FB_VMODE_NONINTERLACED
105};
106
107/*
108 * These are the fields of area descriptor(in DDR memory) for every plane
109 */
110struct diu_ad {
111 /* Word 0(32-bit) in DDR memory */
112 unsigned int pix_fmt; /* hard coding pixel format */
113 /* Word 1(32-bit) in DDR memory */
114 unsigned int addr;
115 /* Word 2(32-bit) in DDR memory */
116 unsigned int src_size_g_alpha;
117 /* Word 3(32-bit) in DDR memory */
118 unsigned int aoi_size;
119 /* Word 4(32-bit) in DDR memory */
120 unsigned int offset_xyi;
121 /* Word 5(32-bit) in DDR memory */
122 unsigned int offset_xyd;
123 /* Word 6(32-bit) in DDR memory */
124 unsigned int ckmax_r:8;
125 unsigned int ckmax_g:8;
126 unsigned int ckmax_b:8;
127 unsigned int res9:8;
128 /* Word 7(32-bit) in DDR memory */
129 unsigned int ckmin_r:8;
130 unsigned int ckmin_g:8;
131 unsigned int ckmin_b:8;
132 unsigned int res10:8;
133 /* Word 8(32-bit) in DDR memory */
134 unsigned int next_ad;
135 /* Word 9(32-bit) in DDR memory, just for 64-bit aligned */
136 unsigned int res1;
137 unsigned int res2;
138 unsigned int res3;
139}__attribute__ ((packed));
140
141/*
142 * DIU register map
143 */
144struct diu {
145 unsigned int desc[3];
146 unsigned int gamma;
147 unsigned int pallete;
148 unsigned int cursor;
149 unsigned int curs_pos;
150 unsigned int diu_mode;
151 unsigned int bgnd;
152 unsigned int bgnd_wb;
153 unsigned int disp_size;
154 unsigned int wb_size;
155 unsigned int wb_mem_addr;
156 unsigned int hsyn_para;
157 unsigned int vsyn_para;
158 unsigned int syn_pol;
159 unsigned int thresholds;
160 unsigned int int_status;
161 unsigned int int_mask;
162 unsigned int colorbar[8];
163 unsigned int filling;
164 unsigned int plut;
165} __attribute__ ((packed));
166
167struct diu_hw {
168 struct diu *diu_reg;
169 volatile unsigned int mode; /* DIU operation mode */
170};
171
172struct diu_addr {
173 unsigned char * paddr; /* Virtual address */
Wolfgang Denka1be4762008-05-20 16:00:29 +0200174 unsigned int offset;
York Sunb7145172007-10-29 13:58:39 -0500175};
176
York Sunb7145172007-10-29 13:58:39 -0500177/*
178 * Modes of operation of DIU
179 */
180#define MFB_MODE0 0 /* DIU off */
181#define MFB_MODE1 1 /* All three planes output to display */
182#define MFB_MODE2 2 /* Plane 1 to display,
183 * planes 2+3 written back to memory */
184#define MFB_MODE3 3 /* All three planes written back to memory */
185#define MFB_MODE4 4 /* Color bar generation */
186
187#define MAX_CURS 32
188
York Sunb7145172007-10-29 13:58:39 -0500189static struct fb_info fsl_fb_info;
190static struct diu_addr gamma, cursor;
191static struct diu_ad fsl_diu_fb_ad __attribute__ ((aligned(32)));
192static struct diu_ad dummy_ad __attribute__ ((aligned(32)));
193static unsigned char *dummy_fb;
194static struct diu_hw dr = {
195 .mode = MFB_MODE1,
196};
197
198int fb_enabled = 0;
199int fb_initialized = 0;
200const int default_xres = 1280;
201const int default_pixel_format = 0x88882317;
202
203static int map_video_memory(struct fb_info *info, unsigned long bytes_align);
204static void enable_lcdc(void);
205static void disable_lcdc(void);
206static int fsl_diu_enable_panel(struct fb_info *info);
207static int fsl_diu_disable_panel(struct fb_info *info);
208static int allocate_buf(struct diu_addr *buf, u32 size, u32 bytes_align);
York Sunc4964382008-05-05 10:19:59 -0500209void diu_set_pixel_clock(unsigned int pixclock);
York Sunb7145172007-10-29 13:58:39 -0500210
York Sunb7145172007-10-29 13:58:39 -0500211int fsl_diu_init(int xres,
212 unsigned int pixel_format,
213 int gamma_fix,
214 unsigned char *splash_bmp)
215{
216 struct fb_videomode *fsl_diu_mode_db;
217 struct diu_ad *ad = &fsl_diu_fb_ad;
218 struct diu *hw;
219 struct fb_info *info = &fsl_fb_info;
220 struct fb_var_screeninfo *var = &info->var;
York Sunb7145172007-10-29 13:58:39 -0500221 unsigned char *gamma_table_base;
222 unsigned int i, j;
York Sunb7145172007-10-29 13:58:39 -0500223
York Sun94cbda92008-05-05 10:20:00 -0500224 debug("Enter fsl_diu_init\n");
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200225 dr.diu_reg = (struct diu *) (CONFIG_SYS_DIU_ADDR);
York Sunb7145172007-10-29 13:58:39 -0500226 hw = (struct diu *) dr.diu_reg;
227
228 disable_lcdc();
229
Anatolij Gustschin81cad142010-04-24 19:27:09 +0200230 switch (xres) {
231 case 800:
232 fsl_diu_mode_db = &fsl_diu_mode_800;
233 break;
234 case 1280:
York Sunb7145172007-10-29 13:58:39 -0500235 fsl_diu_mode_db = &fsl_diu_mode_1280;
Anatolij Gustschin81cad142010-04-24 19:27:09 +0200236 break;
237 default:
York Sunb7145172007-10-29 13:58:39 -0500238 fsl_diu_mode_db = &fsl_diu_mode_1024;
239 }
240
241 if (0 == fb_initialized) {
242 allocate_buf(&gamma, 768, 32);
York Sun94cbda92008-05-05 10:20:00 -0500243 debug("gamma is allocated @ 0x%x\n",
York Sunb7145172007-10-29 13:58:39 -0500244 (unsigned int)gamma.paddr);
245 allocate_buf(&cursor, MAX_CURS * MAX_CURS * 2, 32);
York Sun94cbda92008-05-05 10:20:00 -0500246 debug("curosr is allocated @ 0x%x\n",
York Sunb7145172007-10-29 13:58:39 -0500247 (unsigned int)cursor.paddr);
248
249 /* create a dummy fb and dummy ad */
250 dummy_fb = malloc(64);
251 if (NULL == dummy_fb) {
252 printf("Cannot allocate dummy fb\n");
253 return -1;
254 }
255 dummy_ad.addr = cpu_to_le32((unsigned int)dummy_fb);
256 dummy_ad.pix_fmt = 0x88882317;
257 dummy_ad.src_size_g_alpha = 0x04400000; /* alpha = 0 */
258 dummy_ad.aoi_size = 0x02000400;
259 dummy_ad.offset_xyi = 0;
260 dummy_ad.offset_xyd = 0;
261 dummy_ad.next_ad = 0;
262 /* Memory allocation for framebuffer */
263 if (map_video_memory(info, 32)) {
264 printf("Unable to allocate fb memory 1\n");
265 return -1;
266 }
York Sunb7145172007-10-29 13:58:39 -0500267 }
268
Nikita V. Youshchenko7e6647e2008-10-03 00:03:55 +0400269 memset(info->screen_base, 0, info->smem_len);
270
Jerry Huang54e4b892010-04-08 15:56:07 +0800271 out_be32(&dr.diu_reg->desc[0], &dummy_ad);
272 out_be32(&dr.diu_reg->desc[1], &dummy_ad);
273 out_be32(&dr.diu_reg->desc[2], &dummy_ad);
York Sun94cbda92008-05-05 10:20:00 -0500274 debug("dummy dr.diu_reg->desc[0] = 0x%x\n", dr.diu_reg->desc[0]);
275 debug("dummy desc[0] = 0x%x\n", hw->desc[0]);
York Sunb7145172007-10-29 13:58:39 -0500276
277 /* read mode info */
278 var->xres = fsl_diu_mode_db->xres;
279 var->yres = fsl_diu_mode_db->yres;
280 var->bits_per_pixel = 32;
281 var->pixclock = fsl_diu_mode_db->pixclock;
282 var->left_margin = fsl_diu_mode_db->left_margin;
283 var->right_margin = fsl_diu_mode_db->right_margin;
284 var->upper_margin = fsl_diu_mode_db->upper_margin;
285 var->lower_margin = fsl_diu_mode_db->lower_margin;
286 var->hsync_len = fsl_diu_mode_db->hsync_len;
287 var->vsync_len = fsl_diu_mode_db->vsync_len;
288 var->sync = fsl_diu_mode_db->sync;
289 var->vmode = fsl_diu_mode_db->vmode;
290 info->line_length = var->xres * var->bits_per_pixel / 8;
291 info->logo_size = 0;
292 info->logo_height = 0;
293
294 ad->pix_fmt = pixel_format;
295 ad->addr = cpu_to_le32((unsigned int)info->screen_base);
296 ad->src_size_g_alpha
297 = cpu_to_le32((var->yres << 12) | var->xres);
298 /* fix me. AOI should not be greater than display size */
Wolfgang Denka1be4762008-05-20 16:00:29 +0200299 ad->aoi_size = cpu_to_le32(( var->yres << 16) | var->xres);
York Sunb7145172007-10-29 13:58:39 -0500300 ad->offset_xyi = 0;
301 ad->offset_xyd = 0;
302
303 /* Disable chroma keying function */
304 ad->ckmax_r = 0;
305 ad->ckmax_g = 0;
306 ad->ckmax_b = 0;
307
308 ad->ckmin_r = 255;
309 ad->ckmin_g = 255;
310 ad->ckmin_b = 255;
311
312 gamma_table_base = gamma.paddr;
York Sun94cbda92008-05-05 10:20:00 -0500313 debug("gamma_table_base is allocated @ 0x%x\n",
York Sunb7145172007-10-29 13:58:39 -0500314 (unsigned int)gamma_table_base);
315
316 /* Prep for DIU init - gamma table */
317
318 for (i = 0; i <= 2; i++)
319 for (j = 0; j <= 255; j++)
320 *gamma_table_base++ = j;
321
322 if (gamma_fix == 1) { /* fix the gamma */
York Sun94cbda92008-05-05 10:20:00 -0500323 debug("Fix gamma table\n");
York Sunb7145172007-10-29 13:58:39 -0500324 gamma_table_base = gamma.paddr;
325 for (i = 0; i < 256*3; i++) {
326 gamma_table_base[i] = (gamma_table_base[i] << 2)
327 | ((gamma_table_base[i] >> 6) & 0x03);
328 }
329 }
330
York Sun94cbda92008-05-05 10:20:00 -0500331 debug("update-lcdc: HW - %p\n Disabling DIU\n", hw);
York Sunb7145172007-10-29 13:58:39 -0500332
333 /* Program DIU registers */
334
Jerry Huang54e4b892010-04-08 15:56:07 +0800335 out_be32(&hw->gamma, gamma.paddr);
336 out_be32(&hw->cursor, cursor.paddr);
337 out_be32(&hw->bgnd, 0x007F7F7F);
338 out_be32(&hw->bgnd_wb, 0); /* BGND_WB */
339 out_be32(&hw->disp_size, var->yres << 16 | var->xres); /* DISP SIZE */
340 out_be32(&hw->wb_size, 0); /* WB SIZE */
341 out_be32(&hw->wb_mem_addr, 0); /* WB MEM ADDR */
342 out_be32(&hw->hsyn_para, var->left_margin << 22 | /* BP_H */
York Sunb7145172007-10-29 13:58:39 -0500343 var->hsync_len << 11 | /* PW_H */
Jerry Huang54e4b892010-04-08 15:56:07 +0800344 var->right_margin); /* FP_H */
York Sunb7145172007-10-29 13:58:39 -0500345
Jerry Huang54e4b892010-04-08 15:56:07 +0800346 out_be32(&hw->vsyn_para, var->upper_margin << 22 | /* BP_V */
347 var->vsync_len << 11 | /* PW_V */
348 var->lower_margin); /* FP_V */
York Sunb7145172007-10-29 13:58:39 -0500349
Jerry Huang54e4b892010-04-08 15:56:07 +0800350 out_be32(&hw->syn_pol, 0); /* SYNC SIGNALS POLARITY */
351 out_be32(&hw->thresholds, 0x00037800); /* The Thresholds */
352 out_be32(&hw->int_status, 0); /* INTERRUPT STATUS */
353 out_be32(&hw->int_mask, 0); /* INT MASK */
354 out_be32(&hw->plut, 0x01F5F666);
York Sunc4964382008-05-05 10:19:59 -0500355 /* Pixel Clock configuration */
York Sun94cbda92008-05-05 10:20:00 -0500356 debug("DIU pixclock in ps - %d\n", var->pixclock);
York Sunc4964382008-05-05 10:19:59 -0500357 diu_set_pixel_clock(var->pixclock);
York Sunb7145172007-10-29 13:58:39 -0500358
359 fb_initialized = 1;
360
361 if (splash_bmp) {
362 info->logo_height = fsl_diu_display_bmp(splash_bmp, 0, 0, 0);
363 info->logo_size = info->logo_height * info->line_length;
York Sun94cbda92008-05-05 10:20:00 -0500364 debug("logo height %d, logo_size 0x%x\n",
York Sunb7145172007-10-29 13:58:39 -0500365 info->logo_height,info->logo_size);
366 }
367
368 /* Enable the DIU */
369 fsl_diu_enable_panel(info);
370 enable_lcdc();
371
372 return 0;
373}
374
375char *fsl_fb_open(struct fb_info **info)
376{
377 *info = &fsl_fb_info;
378 return (char *) ((unsigned int)(*info)->screen_base
379 + (*info)->logo_size);
380}
381
382void fsl_diu_close(void)
383{
384 struct fb_info *info = &fsl_fb_info;
385 fsl_diu_disable_panel(info);
386}
387
388static int fsl_diu_enable_panel(struct fb_info *info)
389{
390 struct diu *hw = dr.diu_reg;
391 struct diu_ad *ad = &fsl_diu_fb_ad;
392
York Sun94cbda92008-05-05 10:20:00 -0500393 debug("Entered: enable_panel\n");
Jerry Huang54e4b892010-04-08 15:56:07 +0800394 if (in_be32(&hw->desc[0]) != (u32)ad)
395 out_be32(&hw->desc[0], ad);
York Sun94cbda92008-05-05 10:20:00 -0500396 debug("desc[0] = 0x%x\n", hw->desc[0]);
York Sunb7145172007-10-29 13:58:39 -0500397 return 0;
398}
399
400static int fsl_diu_disable_panel(struct fb_info *info)
401{
402 struct diu *hw = dr.diu_reg;
403
York Sun94cbda92008-05-05 10:20:00 -0500404 debug("Entered: disable_panel\n");
Jerry Huang54e4b892010-04-08 15:56:07 +0800405 if (in_be32(&hw->desc[0]) != (u32)&dummy_ad)
406 out_be32(&hw->desc[0], &dummy_ad);
York Sunb7145172007-10-29 13:58:39 -0500407 return 0;
408}
409
410static int map_video_memory(struct fb_info *info, unsigned long bytes_align)
411{
412 unsigned long offset;
413 unsigned long mask;
414
York Sun94cbda92008-05-05 10:20:00 -0500415 debug("Entered: map_video_memory\n");
York Sunb7145172007-10-29 13:58:39 -0500416 /* allocate maximum 1280*1024 with 32bpp */
417 info->smem_len = 1280 * 4 *1024 + bytes_align;
York Sun94cbda92008-05-05 10:20:00 -0500418 debug("MAP_VIDEO_MEMORY: smem_len = %d\n", info->smem_len);
York Sunb7145172007-10-29 13:58:39 -0500419 info->screen_base = malloc(info->smem_len);
420 if (info->screen_base == NULL) {
421 printf("Unable to allocate fb memory\n");
422 return -1;
423 }
424 info->smem_start = (unsigned int) info->screen_base;
425 mask = bytes_align - 1;
426 offset = (unsigned long)info->screen_base & mask;
427 if (offset) {
Nikita V. Youshchenko7e6647e2008-10-03 00:03:55 +0400428 info->screen_base += (bytes_align - offset);
York Sunb7145172007-10-29 13:58:39 -0500429 info->smem_len = info->smem_len - (bytes_align - offset);
430 } else
431 info->smem_len = info->smem_len - bytes_align;
432
433 info->screen_size = info->smem_len;
434
York Sun94cbda92008-05-05 10:20:00 -0500435 debug("Allocated fb @ 0x%08lx, size=%d.\n",
York Sunb7145172007-10-29 13:58:39 -0500436 info->smem_start, info->smem_len);
437
438 return 0;
439}
440
441static void enable_lcdc(void)
442{
443 struct diu *hw = dr.diu_reg;
444
York Sun94cbda92008-05-05 10:20:00 -0500445 debug("Entered: enable_lcdc, fb_enabled = %d\n", fb_enabled);
York Sunb7145172007-10-29 13:58:39 -0500446 if (!fb_enabled) {
Jerry Huang54e4b892010-04-08 15:56:07 +0800447 out_be32(&hw->diu_mode, dr.mode);
York Sunb7145172007-10-29 13:58:39 -0500448 fb_enabled++;
449 }
York Sun94cbda92008-05-05 10:20:00 -0500450 debug("diu_mode = %d\n", hw->diu_mode);
York Sunb7145172007-10-29 13:58:39 -0500451}
452
453static void disable_lcdc(void)
454{
455 struct diu *hw = dr.diu_reg;
456
York Sun94cbda92008-05-05 10:20:00 -0500457 debug("Entered: disable_lcdc, fb_enabled = %d\n", fb_enabled);
York Sunb7145172007-10-29 13:58:39 -0500458 if (fb_enabled) {
Jerry Huang54e4b892010-04-08 15:56:07 +0800459 out_be32(&hw->diu_mode, 0);
York Sunb7145172007-10-29 13:58:39 -0500460 fb_enabled = 0;
461 }
462}
463
York Sunb7145172007-10-29 13:58:39 -0500464/*
465 * Align to 64-bit(8-byte), 32-byte, etc.
466 */
467static int allocate_buf(struct diu_addr *buf, u32 size, u32 bytes_align)
468{
469 u32 offset, ssize;
470 u32 mask;
471
York Sun94cbda92008-05-05 10:20:00 -0500472 debug("Entered: allocate_buf\n");
York Sunb7145172007-10-29 13:58:39 -0500473 ssize = size + bytes_align;
474 buf->paddr = malloc(ssize);
475 if (!buf->paddr)
476 return -1;
477
478 memset(buf->paddr, 0, ssize);
479 mask = bytes_align - 1;
480 offset = (u32)buf->paddr & mask;
481 if (offset) {
482 buf->offset = bytes_align - offset;
483 buf->paddr = (unsigned char *) ((u32)buf->paddr + offset);
484 } else
485 buf->offset = 0;
486 return 0;
487}
488
489int fsl_diu_display_bmp(unsigned char *bmp,
490 int xoffset,
491 int yoffset,
492 int transpar)
493{
494 struct fb_info *info = &fsl_fb_info;
495 unsigned char r, g, b;
496 unsigned int *fb_t, val;
497 unsigned char *bitmap;
498 unsigned int palette[256];
499 int width, height, bpp, ncolors, raster, offset, x, y, i, k, cpp;
500
501 if (!bmp) {
502 printf("Must supply a bitmap address\n");
503 return 0;
504 }
505
506 raster = bmp[10] + (bmp[11] << 8) + (bmp[12] << 16) + (bmp[13] << 24);
507 width = (bmp[21] << 24) | (bmp[20] << 16) | (bmp[19] << 8) | bmp[18];
508 height = (bmp[25] << 24) | (bmp[24] << 16) | (bmp[23] << 8) | bmp[22];
509 bpp = (bmp[29] << 8) | (bmp[28]);
510 ncolors = bmp[46] + (bmp[47] << 8) + (bmp[48] << 16) + (bmp[49] << 24);
511 bitmap = bmp + raster;
512 cpp = info->var.bits_per_pixel / 8;
513
York Sun94cbda92008-05-05 10:20:00 -0500514 debug("bmp = 0x%08x\n", (unsigned int)bmp);
515 debug("bitmap = 0x%08x\n", (unsigned int)bitmap);
516 debug("width = %d\n", width);
517 debug("height = %d\n", height);
518 debug("bpp = %d\n", bpp);
519 debug("ncolors = %d\n", ncolors);
York Sunb7145172007-10-29 13:58:39 -0500520
York Sun94cbda92008-05-05 10:20:00 -0500521 debug("xres = %d\n", info->var.xres);
522 debug("yres = %d\n", info->var.yres);
523 debug("Screen_base = 0x%x\n", (unsigned int)info->screen_base);
York Sunb7145172007-10-29 13:58:39 -0500524
525 if (((width+xoffset) > info->var.xres) ||
526 ((height+yoffset) > info->var.yres)) {
527 printf("bitmap is out of range, image too large or too much offset\n");
528 return 0;
529 }
530 if (bpp < 24) {
531 for (i = 0, offset = 54; i < ncolors; i++, offset += 4)
532 palette[i] = (bmp[offset+2] << 16)
533 + (bmp[offset+1] << 8) + bmp[offset];
534 }
535
536 switch (bpp) {
537 case 1:
538 for (y = height - 1; y >= 0; y--) {
539 fb_t = (unsigned int *) ((unsigned int)info->screen_base + (((y+yoffset) * info->var.xres) + xoffset)*cpp);
540 for (x = 0; x < width; x += 8) {
541 b = *bitmap++;
542 for (k = 0; k < 8; k++) {
543 if (b & 0x80)
Anatolij Gustschin81cad142010-04-24 19:27:09 +0200544 *fb_t++ = palette[1];
York Sunb7145172007-10-29 13:58:39 -0500545 else
Anatolij Gustschin81cad142010-04-24 19:27:09 +0200546 *fb_t++ = palette[0];
York Sunb7145172007-10-29 13:58:39 -0500547 b = b << 1;
548 }
549 }
550 for (i = (width / 2) % 4; i > 0; i--)
551 bitmap++;
552 }
553 break;
554 case 4:
555 for (y = height - 1; y >= 0; y--) {
556 fb_t = (unsigned int *) ((unsigned int)info->screen_base + (((y+yoffset) * info->var.xres) + xoffset)*cpp);
557 for (x = 0; x < width; x += 2) {
558 b = *bitmap++;
559 r = (b >> 4) & 0x0F;
560 g = b & 0x0F;
561 *fb_t++ = palette[r];
562 *fb_t++ = palette[g];
563 }
564 for (i = (width / 2) % 4; i > 0; i--)
565 bitmap++;
566 }
567 break;
568 case 8:
569 for (y = height - 1; y >= 0; y--) {
570 fb_t = (unsigned int *) ((unsigned int)info->screen_base + (((y+yoffset) * info->var.xres) + xoffset)*cpp);
571 for (x = 0; x < width; x++) {
572 *fb_t++ = palette[ *bitmap++ ];
573 }
574 for (i = (width / 2) % 4; i > 0; i--)
575 bitmap++;
576 }
577 break;
578 case 24:
579 for (y = height - 1; y >= 0; y--) {
580 fb_t = (unsigned int *) ((unsigned int)info->screen_base + (((y+yoffset) * info->var.xres) + xoffset)*cpp);
581 for (x = 0; x < width; x++) {
582 b = *bitmap++;
583 g = *bitmap++;
584 r = *bitmap++;
585 val = (r << 16) + (g << 8) + b;
586 *fb_t++ = val;
587 }
588 for (; (x % 4) != 0; x++) /* 4-byte alignment */
589 bitmap++;
590 }
591 break;
592 }
593
594 return height;
595}
596
597void fsl_diu_clear_screen(void)
598{
599 struct fb_info *info = &fsl_fb_info;
600
601 memset(info->screen_base, 0, info->smem_len);
602}