York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007 Freescale Semiconductor, Inc. |
| 3 | * 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 Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 26 | #include <common.h> |
| 27 | #include <i2c.h> |
| 28 | #include <malloc.h> |
| 29 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 30 | #include "fsl_diu_fb.h" |
| 31 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 32 | struct fb_videomode { |
| 33 | const char *name; /* optional */ |
| 34 | unsigned int refresh; /* optional */ |
| 35 | unsigned int xres; |
| 36 | unsigned int yres; |
| 37 | unsigned int pixclock; |
| 38 | unsigned int left_margin; |
| 39 | unsigned int right_margin; |
| 40 | unsigned int upper_margin; |
| 41 | unsigned int lower_margin; |
| 42 | unsigned int hsync_len; |
| 43 | unsigned int vsync_len; |
| 44 | unsigned int sync; |
| 45 | unsigned int vmode; |
| 46 | unsigned int flag; |
| 47 | }; |
| 48 | |
| 49 | #define FB_SYNC_VERT_HIGH_ACT 2 /* vertical sync high active */ |
| 50 | #define FB_SYNC_COMP_HIGH_ACT 8 /* composite sync high active */ |
| 51 | #define FB_VMODE_NONINTERLACED 0 /* non interlaced */ |
| 52 | |
| 53 | /* |
| 54 | * These parameters give default parameters |
| 55 | * for video output 1024x768, |
| 56 | * FIXME - change timing to proper amounts |
| 57 | * hsync 31.5kHz, vsync 60Hz |
| 58 | */ |
| 59 | static struct fb_videomode fsl_diu_mode_1024 = { |
| 60 | .refresh = 60, |
| 61 | .xres = 1024, |
| 62 | .yres = 768, |
| 63 | .pixclock = 15385, |
| 64 | .left_margin = 160, |
| 65 | .right_margin = 24, |
| 66 | .upper_margin = 29, |
| 67 | .lower_margin = 3, |
| 68 | .hsync_len = 136, |
| 69 | .vsync_len = 6, |
| 70 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 71 | .vmode = FB_VMODE_NONINTERLACED |
| 72 | }; |
| 73 | |
| 74 | static struct fb_videomode fsl_diu_mode_1280 = { |
| 75 | .name = "1280x1024-60", |
| 76 | .refresh = 60, |
| 77 | .xres = 1280, |
| 78 | .yres = 1024, |
| 79 | .pixclock = 9375, |
| 80 | .left_margin = 38, |
| 81 | .right_margin = 128, |
| 82 | .upper_margin = 2, |
| 83 | .lower_margin = 7, |
| 84 | .hsync_len = 216, |
| 85 | .vsync_len = 37, |
| 86 | .sync = FB_SYNC_COMP_HIGH_ACT | FB_SYNC_VERT_HIGH_ACT, |
| 87 | .vmode = FB_VMODE_NONINTERLACED |
| 88 | }; |
| 89 | |
| 90 | /* |
| 91 | * These are the fields of area descriptor(in DDR memory) for every plane |
| 92 | */ |
| 93 | struct diu_ad { |
| 94 | /* Word 0(32-bit) in DDR memory */ |
| 95 | unsigned int pix_fmt; /* hard coding pixel format */ |
| 96 | /* Word 1(32-bit) in DDR memory */ |
| 97 | unsigned int addr; |
| 98 | /* Word 2(32-bit) in DDR memory */ |
| 99 | unsigned int src_size_g_alpha; |
| 100 | /* Word 3(32-bit) in DDR memory */ |
| 101 | unsigned int aoi_size; |
| 102 | /* Word 4(32-bit) in DDR memory */ |
| 103 | unsigned int offset_xyi; |
| 104 | /* Word 5(32-bit) in DDR memory */ |
| 105 | unsigned int offset_xyd; |
| 106 | /* Word 6(32-bit) in DDR memory */ |
| 107 | unsigned int ckmax_r:8; |
| 108 | unsigned int ckmax_g:8; |
| 109 | unsigned int ckmax_b:8; |
| 110 | unsigned int res9:8; |
| 111 | /* Word 7(32-bit) in DDR memory */ |
| 112 | unsigned int ckmin_r:8; |
| 113 | unsigned int ckmin_g:8; |
| 114 | unsigned int ckmin_b:8; |
| 115 | unsigned int res10:8; |
| 116 | /* Word 8(32-bit) in DDR memory */ |
| 117 | unsigned int next_ad; |
| 118 | /* Word 9(32-bit) in DDR memory, just for 64-bit aligned */ |
| 119 | unsigned int res1; |
| 120 | unsigned int res2; |
| 121 | unsigned int res3; |
| 122 | }__attribute__ ((packed)); |
| 123 | |
| 124 | /* |
| 125 | * DIU register map |
| 126 | */ |
| 127 | struct diu { |
| 128 | unsigned int desc[3]; |
| 129 | unsigned int gamma; |
| 130 | unsigned int pallete; |
| 131 | unsigned int cursor; |
| 132 | unsigned int curs_pos; |
| 133 | unsigned int diu_mode; |
| 134 | unsigned int bgnd; |
| 135 | unsigned int bgnd_wb; |
| 136 | unsigned int disp_size; |
| 137 | unsigned int wb_size; |
| 138 | unsigned int wb_mem_addr; |
| 139 | unsigned int hsyn_para; |
| 140 | unsigned int vsyn_para; |
| 141 | unsigned int syn_pol; |
| 142 | unsigned int thresholds; |
| 143 | unsigned int int_status; |
| 144 | unsigned int int_mask; |
| 145 | unsigned int colorbar[8]; |
| 146 | unsigned int filling; |
| 147 | unsigned int plut; |
| 148 | } __attribute__ ((packed)); |
| 149 | |
| 150 | struct diu_hw { |
| 151 | struct diu *diu_reg; |
| 152 | volatile unsigned int mode; /* DIU operation mode */ |
| 153 | }; |
| 154 | |
| 155 | struct diu_addr { |
| 156 | unsigned char * paddr; /* Virtual address */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 157 | unsigned int offset; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 158 | }; |
| 159 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 160 | /* |
| 161 | * Modes of operation of DIU |
| 162 | */ |
| 163 | #define MFB_MODE0 0 /* DIU off */ |
| 164 | #define MFB_MODE1 1 /* All three planes output to display */ |
| 165 | #define MFB_MODE2 2 /* Plane 1 to display, |
| 166 | * planes 2+3 written back to memory */ |
| 167 | #define MFB_MODE3 3 /* All three planes written back to memory */ |
| 168 | #define MFB_MODE4 4 /* Color bar generation */ |
| 169 | |
| 170 | #define MAX_CURS 32 |
| 171 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 172 | static struct fb_info fsl_fb_info; |
| 173 | static struct diu_addr gamma, cursor; |
| 174 | static struct diu_ad fsl_diu_fb_ad __attribute__ ((aligned(32))); |
| 175 | static struct diu_ad dummy_ad __attribute__ ((aligned(32))); |
| 176 | static unsigned char *dummy_fb; |
| 177 | static struct diu_hw dr = { |
| 178 | .mode = MFB_MODE1, |
| 179 | }; |
| 180 | |
| 181 | int fb_enabled = 0; |
| 182 | int fb_initialized = 0; |
| 183 | const int default_xres = 1280; |
| 184 | const int default_pixel_format = 0x88882317; |
| 185 | |
| 186 | static int map_video_memory(struct fb_info *info, unsigned long bytes_align); |
| 187 | static void enable_lcdc(void); |
| 188 | static void disable_lcdc(void); |
| 189 | static int fsl_diu_enable_panel(struct fb_info *info); |
| 190 | static int fsl_diu_disable_panel(struct fb_info *info); |
| 191 | static int allocate_buf(struct diu_addr *buf, u32 size, u32 bytes_align); |
York Sun | c496438 | 2008-05-05 10:19:59 -0500 | [diff] [blame] | 192 | void diu_set_pixel_clock(unsigned int pixclock); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 193 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 194 | int fsl_diu_init(int xres, |
| 195 | unsigned int pixel_format, |
| 196 | int gamma_fix, |
| 197 | unsigned char *splash_bmp) |
| 198 | { |
| 199 | struct fb_videomode *fsl_diu_mode_db; |
| 200 | struct diu_ad *ad = &fsl_diu_fb_ad; |
| 201 | struct diu *hw; |
| 202 | struct fb_info *info = &fsl_fb_info; |
| 203 | struct fb_var_screeninfo *var = &info->var; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 204 | unsigned char *gamma_table_base; |
| 205 | unsigned int i, j; |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 206 | |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 207 | debug("Enter fsl_diu_init\n"); |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 208 | dr.diu_reg = (struct diu *) (CONFIG_SYS_DIU_ADDR); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 209 | hw = (struct diu *) dr.diu_reg; |
| 210 | |
| 211 | disable_lcdc(); |
| 212 | |
| 213 | if (xres == 1280) { |
| 214 | fsl_diu_mode_db = &fsl_diu_mode_1280; |
| 215 | } else { |
| 216 | fsl_diu_mode_db = &fsl_diu_mode_1024; |
| 217 | } |
| 218 | |
| 219 | if (0 == fb_initialized) { |
| 220 | allocate_buf(&gamma, 768, 32); |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 221 | debug("gamma is allocated @ 0x%x\n", |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 222 | (unsigned int)gamma.paddr); |
| 223 | allocate_buf(&cursor, MAX_CURS * MAX_CURS * 2, 32); |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 224 | debug("curosr is allocated @ 0x%x\n", |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 225 | (unsigned int)cursor.paddr); |
| 226 | |
| 227 | /* create a dummy fb and dummy ad */ |
| 228 | dummy_fb = malloc(64); |
| 229 | if (NULL == dummy_fb) { |
| 230 | printf("Cannot allocate dummy fb\n"); |
| 231 | return -1; |
| 232 | } |
| 233 | dummy_ad.addr = cpu_to_le32((unsigned int)dummy_fb); |
| 234 | dummy_ad.pix_fmt = 0x88882317; |
| 235 | dummy_ad.src_size_g_alpha = 0x04400000; /* alpha = 0 */ |
| 236 | dummy_ad.aoi_size = 0x02000400; |
| 237 | dummy_ad.offset_xyi = 0; |
| 238 | dummy_ad.offset_xyd = 0; |
| 239 | dummy_ad.next_ad = 0; |
| 240 | /* Memory allocation for framebuffer */ |
| 241 | if (map_video_memory(info, 32)) { |
| 242 | printf("Unable to allocate fb memory 1\n"); |
| 243 | return -1; |
| 244 | } |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 245 | } |
| 246 | |
Nikita V. Youshchenko | 7e6647e | 2008-10-03 00:03:55 +0400 | [diff] [blame] | 247 | memset(info->screen_base, 0, info->smem_len); |
| 248 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 249 | dr.diu_reg->desc[0] = (unsigned int) &dummy_ad; |
| 250 | dr.diu_reg->desc[1] = (unsigned int) &dummy_ad; |
| 251 | dr.diu_reg->desc[2] = (unsigned int) &dummy_ad; |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 252 | debug("dummy dr.diu_reg->desc[0] = 0x%x\n", dr.diu_reg->desc[0]); |
| 253 | debug("dummy desc[0] = 0x%x\n", hw->desc[0]); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 254 | |
| 255 | /* read mode info */ |
| 256 | var->xres = fsl_diu_mode_db->xres; |
| 257 | var->yres = fsl_diu_mode_db->yres; |
| 258 | var->bits_per_pixel = 32; |
| 259 | var->pixclock = fsl_diu_mode_db->pixclock; |
| 260 | var->left_margin = fsl_diu_mode_db->left_margin; |
| 261 | var->right_margin = fsl_diu_mode_db->right_margin; |
| 262 | var->upper_margin = fsl_diu_mode_db->upper_margin; |
| 263 | var->lower_margin = fsl_diu_mode_db->lower_margin; |
| 264 | var->hsync_len = fsl_diu_mode_db->hsync_len; |
| 265 | var->vsync_len = fsl_diu_mode_db->vsync_len; |
| 266 | var->sync = fsl_diu_mode_db->sync; |
| 267 | var->vmode = fsl_diu_mode_db->vmode; |
| 268 | info->line_length = var->xres * var->bits_per_pixel / 8; |
| 269 | info->logo_size = 0; |
| 270 | info->logo_height = 0; |
| 271 | |
| 272 | ad->pix_fmt = pixel_format; |
| 273 | ad->addr = cpu_to_le32((unsigned int)info->screen_base); |
| 274 | ad->src_size_g_alpha |
| 275 | = cpu_to_le32((var->yres << 12) | var->xres); |
| 276 | /* fix me. AOI should not be greater than display size */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 277 | ad->aoi_size = cpu_to_le32(( var->yres << 16) | var->xres); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 278 | ad->offset_xyi = 0; |
| 279 | ad->offset_xyd = 0; |
| 280 | |
| 281 | /* Disable chroma keying function */ |
| 282 | ad->ckmax_r = 0; |
| 283 | ad->ckmax_g = 0; |
| 284 | ad->ckmax_b = 0; |
| 285 | |
| 286 | ad->ckmin_r = 255; |
| 287 | ad->ckmin_g = 255; |
| 288 | ad->ckmin_b = 255; |
| 289 | |
| 290 | gamma_table_base = gamma.paddr; |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 291 | debug("gamma_table_base is allocated @ 0x%x\n", |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 292 | (unsigned int)gamma_table_base); |
| 293 | |
| 294 | /* Prep for DIU init - gamma table */ |
| 295 | |
| 296 | for (i = 0; i <= 2; i++) |
| 297 | for (j = 0; j <= 255; j++) |
| 298 | *gamma_table_base++ = j; |
| 299 | |
| 300 | if (gamma_fix == 1) { /* fix the gamma */ |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 301 | debug("Fix gamma table\n"); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 302 | gamma_table_base = gamma.paddr; |
| 303 | for (i = 0; i < 256*3; i++) { |
| 304 | gamma_table_base[i] = (gamma_table_base[i] << 2) |
| 305 | | ((gamma_table_base[i] >> 6) & 0x03); |
| 306 | } |
| 307 | } |
| 308 | |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 309 | debug("update-lcdc: HW - %p\n Disabling DIU\n", hw); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 310 | |
| 311 | /* Program DIU registers */ |
| 312 | |
| 313 | hw->gamma = (unsigned int) gamma.paddr; |
| 314 | hw->cursor= (unsigned int) cursor.paddr; |
| 315 | hw->bgnd = 0x007F7F7F; /* BGND */ |
Wolfgang Denk | a1be476 | 2008-05-20 16:00:29 +0200 | [diff] [blame] | 316 | hw->bgnd_wb = 0; /* BGND_WB */ |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 317 | hw->disp_size = var->yres << 16 | var->xres; /* DISP SIZE */ |
| 318 | hw->wb_size = 0; /* WB SIZE */ |
| 319 | hw->wb_mem_addr = 0; /* WB MEM ADDR */ |
| 320 | hw->hsyn_para = var->left_margin << 22 | /* BP_H */ |
| 321 | var->hsync_len << 11 | /* PW_H */ |
| 322 | var->right_margin; /* FP_H */ |
| 323 | hw->vsyn_para = var->upper_margin << 22 | /* BP_V */ |
| 324 | var->vsync_len << 11 | /* PW_V */ |
| 325 | var->lower_margin; /* FP_V */ |
| 326 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 327 | hw->syn_pol = 0; /* SYNC SIGNALS POLARITY */ |
| 328 | hw->thresholds = 0x00037800; /* The Thresholds */ |
| 329 | hw->int_status = 0; /* INTERRUPT STATUS */ |
| 330 | hw->int_mask = 0; /* INT MASK */ |
| 331 | hw->plut = 0x01F5F666; |
| 332 | |
York Sun | c496438 | 2008-05-05 10:19:59 -0500 | [diff] [blame] | 333 | /* Pixel Clock configuration */ |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 334 | debug("DIU pixclock in ps - %d\n", var->pixclock); |
York Sun | c496438 | 2008-05-05 10:19:59 -0500 | [diff] [blame] | 335 | diu_set_pixel_clock(var->pixclock); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 336 | |
| 337 | fb_initialized = 1; |
| 338 | |
| 339 | if (splash_bmp) { |
| 340 | info->logo_height = fsl_diu_display_bmp(splash_bmp, 0, 0, 0); |
| 341 | info->logo_size = info->logo_height * info->line_length; |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 342 | debug("logo height %d, logo_size 0x%x\n", |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 343 | info->logo_height,info->logo_size); |
| 344 | } |
| 345 | |
| 346 | /* Enable the DIU */ |
| 347 | fsl_diu_enable_panel(info); |
| 348 | enable_lcdc(); |
| 349 | |
| 350 | return 0; |
| 351 | } |
| 352 | |
| 353 | char *fsl_fb_open(struct fb_info **info) |
| 354 | { |
| 355 | *info = &fsl_fb_info; |
| 356 | return (char *) ((unsigned int)(*info)->screen_base |
| 357 | + (*info)->logo_size); |
| 358 | } |
| 359 | |
| 360 | void fsl_diu_close(void) |
| 361 | { |
| 362 | struct fb_info *info = &fsl_fb_info; |
| 363 | fsl_diu_disable_panel(info); |
| 364 | } |
| 365 | |
| 366 | static int fsl_diu_enable_panel(struct fb_info *info) |
| 367 | { |
| 368 | struct diu *hw = dr.diu_reg; |
| 369 | struct diu_ad *ad = &fsl_diu_fb_ad; |
| 370 | |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 371 | debug("Entered: enable_panel\n"); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 372 | if (hw->desc[0] != (unsigned int)ad) |
| 373 | hw->desc[0] = (unsigned int)ad; |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 374 | debug("desc[0] = 0x%x\n", hw->desc[0]); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 375 | return 0; |
| 376 | } |
| 377 | |
| 378 | static int fsl_diu_disable_panel(struct fb_info *info) |
| 379 | { |
| 380 | struct diu *hw = dr.diu_reg; |
| 381 | |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 382 | debug("Entered: disable_panel\n"); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 383 | if (hw->desc[0] != (unsigned int)&dummy_ad) |
| 384 | hw->desc[0] = (unsigned int)&dummy_ad; |
| 385 | return 0; |
| 386 | } |
| 387 | |
| 388 | static int map_video_memory(struct fb_info *info, unsigned long bytes_align) |
| 389 | { |
| 390 | unsigned long offset; |
| 391 | unsigned long mask; |
| 392 | |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 393 | debug("Entered: map_video_memory\n"); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 394 | /* allocate maximum 1280*1024 with 32bpp */ |
| 395 | info->smem_len = 1280 * 4 *1024 + bytes_align; |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 396 | debug("MAP_VIDEO_MEMORY: smem_len = %d\n", info->smem_len); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 397 | info->screen_base = malloc(info->smem_len); |
| 398 | if (info->screen_base == NULL) { |
| 399 | printf("Unable to allocate fb memory\n"); |
| 400 | return -1; |
| 401 | } |
| 402 | info->smem_start = (unsigned int) info->screen_base; |
| 403 | mask = bytes_align - 1; |
| 404 | offset = (unsigned long)info->screen_base & mask; |
| 405 | if (offset) { |
Nikita V. Youshchenko | 7e6647e | 2008-10-03 00:03:55 +0400 | [diff] [blame] | 406 | info->screen_base += (bytes_align - offset); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 407 | info->smem_len = info->smem_len - (bytes_align - offset); |
| 408 | } else |
| 409 | info->smem_len = info->smem_len - bytes_align; |
| 410 | |
| 411 | info->screen_size = info->smem_len; |
| 412 | |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 413 | debug("Allocated fb @ 0x%08lx, size=%d.\n", |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 414 | info->smem_start, info->smem_len); |
| 415 | |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | static void enable_lcdc(void) |
| 420 | { |
| 421 | struct diu *hw = dr.diu_reg; |
| 422 | |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 423 | debug("Entered: enable_lcdc, fb_enabled = %d\n", fb_enabled); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 424 | if (!fb_enabled) { |
| 425 | hw->diu_mode = dr.mode; |
| 426 | fb_enabled++; |
| 427 | } |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 428 | debug("diu_mode = %d\n", hw->diu_mode); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | static void disable_lcdc(void) |
| 432 | { |
| 433 | struct diu *hw = dr.diu_reg; |
| 434 | |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 435 | debug("Entered: disable_lcdc, fb_enabled = %d\n", fb_enabled); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 436 | if (fb_enabled) { |
| 437 | hw->diu_mode = 0; |
| 438 | fb_enabled = 0; |
| 439 | } |
| 440 | } |
| 441 | |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 442 | /* |
| 443 | * Align to 64-bit(8-byte), 32-byte, etc. |
| 444 | */ |
| 445 | static int allocate_buf(struct diu_addr *buf, u32 size, u32 bytes_align) |
| 446 | { |
| 447 | u32 offset, ssize; |
| 448 | u32 mask; |
| 449 | |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 450 | debug("Entered: allocate_buf\n"); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 451 | ssize = size + bytes_align; |
| 452 | buf->paddr = malloc(ssize); |
| 453 | if (!buf->paddr) |
| 454 | return -1; |
| 455 | |
| 456 | memset(buf->paddr, 0, ssize); |
| 457 | mask = bytes_align - 1; |
| 458 | offset = (u32)buf->paddr & mask; |
| 459 | if (offset) { |
| 460 | buf->offset = bytes_align - offset; |
| 461 | buf->paddr = (unsigned char *) ((u32)buf->paddr + offset); |
| 462 | } else |
| 463 | buf->offset = 0; |
| 464 | return 0; |
| 465 | } |
| 466 | |
| 467 | int fsl_diu_display_bmp(unsigned char *bmp, |
| 468 | int xoffset, |
| 469 | int yoffset, |
| 470 | int transpar) |
| 471 | { |
| 472 | struct fb_info *info = &fsl_fb_info; |
| 473 | unsigned char r, g, b; |
| 474 | unsigned int *fb_t, val; |
| 475 | unsigned char *bitmap; |
| 476 | unsigned int palette[256]; |
| 477 | int width, height, bpp, ncolors, raster, offset, x, y, i, k, cpp; |
| 478 | |
| 479 | if (!bmp) { |
| 480 | printf("Must supply a bitmap address\n"); |
| 481 | return 0; |
| 482 | } |
| 483 | |
| 484 | raster = bmp[10] + (bmp[11] << 8) + (bmp[12] << 16) + (bmp[13] << 24); |
| 485 | width = (bmp[21] << 24) | (bmp[20] << 16) | (bmp[19] << 8) | bmp[18]; |
| 486 | height = (bmp[25] << 24) | (bmp[24] << 16) | (bmp[23] << 8) | bmp[22]; |
| 487 | bpp = (bmp[29] << 8) | (bmp[28]); |
| 488 | ncolors = bmp[46] + (bmp[47] << 8) + (bmp[48] << 16) + (bmp[49] << 24); |
| 489 | bitmap = bmp + raster; |
| 490 | cpp = info->var.bits_per_pixel / 8; |
| 491 | |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 492 | debug("bmp = 0x%08x\n", (unsigned int)bmp); |
| 493 | debug("bitmap = 0x%08x\n", (unsigned int)bitmap); |
| 494 | debug("width = %d\n", width); |
| 495 | debug("height = %d\n", height); |
| 496 | debug("bpp = %d\n", bpp); |
| 497 | debug("ncolors = %d\n", ncolors); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 498 | |
York Sun | 94cbda9 | 2008-05-05 10:20:00 -0500 | [diff] [blame] | 499 | debug("xres = %d\n", info->var.xres); |
| 500 | debug("yres = %d\n", info->var.yres); |
| 501 | debug("Screen_base = 0x%x\n", (unsigned int)info->screen_base); |
York Sun | b714517 | 2007-10-29 13:58:39 -0500 | [diff] [blame] | 502 | |
| 503 | if (((width+xoffset) > info->var.xres) || |
| 504 | ((height+yoffset) > info->var.yres)) { |
| 505 | printf("bitmap is out of range, image too large or too much offset\n"); |
| 506 | return 0; |
| 507 | } |
| 508 | if (bpp < 24) { |
| 509 | for (i = 0, offset = 54; i < ncolors; i++, offset += 4) |
| 510 | palette[i] = (bmp[offset+2] << 16) |
| 511 | + (bmp[offset+1] << 8) + bmp[offset]; |
| 512 | } |
| 513 | |
| 514 | switch (bpp) { |
| 515 | case 1: |
| 516 | for (y = height - 1; y >= 0; y--) { |
| 517 | fb_t = (unsigned int *) ((unsigned int)info->screen_base + (((y+yoffset) * info->var.xres) + xoffset)*cpp); |
| 518 | for (x = 0; x < width; x += 8) { |
| 519 | b = *bitmap++; |
| 520 | for (k = 0; k < 8; k++) { |
| 521 | if (b & 0x80) |
| 522 | *fb_t = palette[1]; |
| 523 | else |
| 524 | *fb_t = palette[0]; |
| 525 | b = b << 1; |
| 526 | } |
| 527 | } |
| 528 | for (i = (width / 2) % 4; i > 0; i--) |
| 529 | bitmap++; |
| 530 | } |
| 531 | break; |
| 532 | case 4: |
| 533 | for (y = height - 1; y >= 0; y--) { |
| 534 | fb_t = (unsigned int *) ((unsigned int)info->screen_base + (((y+yoffset) * info->var.xres) + xoffset)*cpp); |
| 535 | for (x = 0; x < width; x += 2) { |
| 536 | b = *bitmap++; |
| 537 | r = (b >> 4) & 0x0F; |
| 538 | g = b & 0x0F; |
| 539 | *fb_t++ = palette[r]; |
| 540 | *fb_t++ = palette[g]; |
| 541 | } |
| 542 | for (i = (width / 2) % 4; i > 0; i--) |
| 543 | bitmap++; |
| 544 | } |
| 545 | break; |
| 546 | case 8: |
| 547 | for (y = height - 1; y >= 0; y--) { |
| 548 | fb_t = (unsigned int *) ((unsigned int)info->screen_base + (((y+yoffset) * info->var.xres) + xoffset)*cpp); |
| 549 | for (x = 0; x < width; x++) { |
| 550 | *fb_t++ = palette[ *bitmap++ ]; |
| 551 | } |
| 552 | for (i = (width / 2) % 4; i > 0; i--) |
| 553 | bitmap++; |
| 554 | } |
| 555 | break; |
| 556 | case 24: |
| 557 | for (y = height - 1; y >= 0; y--) { |
| 558 | fb_t = (unsigned int *) ((unsigned int)info->screen_base + (((y+yoffset) * info->var.xres) + xoffset)*cpp); |
| 559 | for (x = 0; x < width; x++) { |
| 560 | b = *bitmap++; |
| 561 | g = *bitmap++; |
| 562 | r = *bitmap++; |
| 563 | val = (r << 16) + (g << 8) + b; |
| 564 | *fb_t++ = val; |
| 565 | } |
| 566 | for (; (x % 4) != 0; x++) /* 4-byte alignment */ |
| 567 | bitmap++; |
| 568 | } |
| 569 | break; |
| 570 | } |
| 571 | |
| 572 | return height; |
| 573 | } |
| 574 | |
| 575 | void fsl_diu_clear_screen(void) |
| 576 | { |
| 577 | struct fb_info *info = &fsl_fb_info; |
| 578 | |
| 579 | memset(info->screen_base, 0, info->smem_len); |
| 580 | } |