stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2003-2004 |
| 3 | * Stefan Roese, esd gmbh germany, stefan.roese@esd-electronics.com |
| 4 | * |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 5 | * (C) Copyright 2005 |
| 6 | * Stefan Roese, DENX Software Engineering, sr@denx.de. |
| 7 | * |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 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. |
| 15 | * |
| 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. |
| 20 | * |
| 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, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
Matthias Fuchs | 77660c4 | 2007-12-28 17:10:44 +0100 | [diff] [blame^] | 27 | #include "asm/io.h" |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 28 | #include "lcd.h" |
| 29 | |
| 30 | |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 31 | extern int video_display_bitmap (ulong, int, int); |
| 32 | |
| 33 | |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 34 | int palette_index; |
| 35 | int palette_value; |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 36 | int lcd_depth; |
| 37 | unsigned char *glob_lcd_reg; |
| 38 | unsigned char *glob_lcd_mem; |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 39 | |
| 40 | #ifdef CFG_LCD_ENDIAN |
| 41 | void lcd_setup(int lcd, int config) |
| 42 | { |
| 43 | if (lcd == 0) { |
| 44 | /* |
| 45 | * Set endianess and reset lcd controller 0 (small) |
| 46 | */ |
| 47 | out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD0_RST); /* set reset to low */ |
| 48 | udelay(10); /* wait 10us */ |
| 49 | if (config == 1) { |
| 50 | out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */ |
| 51 | } else { |
| 52 | out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */ |
| 53 | } |
| 54 | udelay(10); /* wait 10us */ |
| 55 | out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD0_RST); /* set reset to high */ |
| 56 | } else { |
| 57 | /* |
| 58 | * Set endianess and reset lcd controller 1 (big) |
| 59 | */ |
| 60 | out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD1_RST); /* set reset to low */ |
| 61 | udelay(10); /* wait 10us */ |
| 62 | if (config == 1) { |
| 63 | out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* big-endian */ |
| 64 | } else { |
| 65 | out32(GPIO0_OR, in32(GPIO0_OR) & ~CFG_LCD_ENDIAN); /* little-endian */ |
| 66 | } |
| 67 | udelay(10); /* wait 10us */ |
| 68 | out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD1_RST); /* set reset to high */ |
| 69 | } |
| 70 | |
| 71 | /* |
| 72 | * CFG_LCD_ENDIAN may also be FPGA_RESET, so set inactive |
| 73 | */ |
| 74 | out32(GPIO0_OR, in32(GPIO0_OR) | CFG_LCD_ENDIAN); /* set reset high again */ |
| 75 | } |
| 76 | #endif /* #ifdef CFG_LCD_ENDIAN */ |
| 77 | |
| 78 | |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 79 | void lcd_bmp(uchar *logo_bmp) |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 80 | { |
| 81 | int i; |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 82 | uchar *ptr; |
| 83 | ushort *ptr2; |
| 84 | ushort val; |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 85 | unsigned char *dst = NULL; |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 86 | int x, y; |
| 87 | int width, height, bpp, colors, line_size; |
| 88 | int header_size; |
| 89 | unsigned char *bmp; |
| 90 | unsigned char r, g, b; |
| 91 | BITMAPINFOHEADER *bm_info; |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 92 | ulong len; |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 93 | |
| 94 | /* |
| 95 | * Check for bmp mark 'BM' |
| 96 | */ |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 97 | if (*(ushort *)logo_bmp != 0x424d) { |
| 98 | |
| 99 | /* |
| 100 | * Decompress bmp image |
| 101 | */ |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 102 | len = CFG_VIDEO_LOGO_MAX_SIZE; |
| 103 | dst = malloc(CFG_VIDEO_LOGO_MAX_SIZE); |
| 104 | if (dst == NULL) { |
| 105 | printf("Error: malloc in gunzip failed!\n"); |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 106 | return; |
| 107 | } |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 108 | if (gunzip(dst, CFG_VIDEO_LOGO_MAX_SIZE, (uchar *)logo_bmp, &len) != 0) { |
| 109 | return; |
| 110 | } |
| 111 | if (len == CFG_VIDEO_LOGO_MAX_SIZE) { |
| 112 | printf("Image could be truncated (increase CFG_VIDEO_LOGO_MAX_SIZE)!\n"); |
| 113 | } |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 114 | |
| 115 | /* |
| 116 | * Check for bmp mark 'BM' |
| 117 | */ |
| 118 | if (*(ushort *)dst != 0x424d) { |
| 119 | printf("LCD: Unknown image format!\n"); |
| 120 | free(dst); |
| 121 | return; |
| 122 | } |
| 123 | } else { |
| 124 | /* |
| 125 | * Uncompressed BMP image, just use this pointer |
| 126 | */ |
| 127 | dst = (uchar *)logo_bmp; |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 128 | } |
| 129 | |
| 130 | /* |
| 131 | * Get image info from bmp-header |
| 132 | */ |
| 133 | bm_info = (BITMAPINFOHEADER *)(dst + 14); |
| 134 | bpp = LOAD_SHORT(bm_info->biBitCount); |
| 135 | width = LOAD_LONG(bm_info->biWidth); |
| 136 | height = LOAD_LONG(bm_info->biHeight); |
| 137 | switch (bpp) { |
| 138 | case 1: |
| 139 | colors = 1; |
| 140 | line_size = width >> 3; |
| 141 | break; |
| 142 | case 4: |
| 143 | colors = 16; |
| 144 | line_size = width >> 1; |
| 145 | break; |
| 146 | case 8: |
| 147 | colors = 256; |
| 148 | line_size = width; |
| 149 | break; |
| 150 | case 24: |
| 151 | colors = 0; |
| 152 | line_size = width * 3; |
| 153 | break; |
| 154 | default: |
| 155 | printf("LCD: Unknown bpp (%d) im image!\n", bpp); |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 156 | if ((dst != NULL) && (dst != (uchar *)logo_bmp)) { |
| 157 | free(dst); |
| 158 | } |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 159 | return; |
| 160 | } |
| 161 | printf(" (%d*%d, %dbpp)\n", width, height, bpp); |
| 162 | |
| 163 | /* |
| 164 | * Write color palette |
| 165 | */ |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 166 | if ((colors <= 256) && (lcd_depth <= 8)) { |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 167 | ptr = (unsigned char *)(dst + 14 + 40); |
| 168 | for (i=0; i<colors; i++) { |
| 169 | b = *ptr++; |
| 170 | g = *ptr++; |
| 171 | r = *ptr++; |
| 172 | ptr++; |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 173 | S1D_WRITE_PALETTE(glob_lcd_reg, i, r, g, b); |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | |
| 177 | /* |
| 178 | * Write bitmap data into framebuffer |
| 179 | */ |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 180 | ptr = glob_lcd_mem; |
| 181 | ptr2 = (ushort *)glob_lcd_mem; |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 182 | header_size = 14 + 40 + 4*colors; /* skip bmp header */ |
| 183 | for (y=0; y<height; y++) { |
| 184 | bmp = &dst[(height-1-y)*line_size + header_size]; |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 185 | if (lcd_depth == 16) { |
| 186 | if (bpp == 24) { |
| 187 | for (x=0; x<width; x++) { |
| 188 | /* |
| 189 | * Generate epson 16bpp fb-format from 24bpp image |
| 190 | */ |
| 191 | b = *bmp++ >> 3; |
| 192 | g = *bmp++ >> 2; |
| 193 | r = *bmp++ >> 3; |
| 194 | val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f); |
| 195 | *ptr2++ = val; |
| 196 | } |
| 197 | } else if (bpp == 8) { |
| 198 | for (x=0; x<line_size; x++) { |
| 199 | /* query rgb value from palette */ |
| 200 | ptr = (unsigned char *)(dst + 14 + 40) ; |
| 201 | ptr += (*bmp++) << 2; |
| 202 | b = *ptr++ >> 3; |
| 203 | g = *ptr++ >> 2; |
| 204 | r = *ptr++ >> 3; |
| 205 | val = ((r & 0x1f) << 11) | ((g & 0x3f) << 5) | (b & 0x1f); |
| 206 | *ptr2++ = val; |
| 207 | } |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 208 | } |
| 209 | } else { |
| 210 | for (x=0; x<line_size; x++) { |
| 211 | *ptr++ = *bmp++; |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 216 | if ((dst != NULL) && (dst != (uchar *)logo_bmp)) { |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 217 | free(dst); |
| 218 | } |
stroese | 0621f6f | 2004-12-16 18:43:13 +0000 | [diff] [blame] | 219 | } |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 220 | |
| 221 | |
| 222 | void lcd_init(uchar *lcd_reg, uchar *lcd_mem, S1D_REGS *regs, int reg_count, |
| 223 | uchar *logo_bmp, ulong len) |
| 224 | { |
| 225 | int i; |
| 226 | ushort s1dReg; |
| 227 | uchar s1dValue; |
| 228 | int reg_byte_swap; |
| 229 | |
| 230 | /* |
| 231 | * Detect epson |
| 232 | */ |
Matthias Fuchs | 77660c4 | 2007-12-28 17:10:44 +0100 | [diff] [blame^] | 233 | out_8(&lcd_reg[0], 0x00); |
| 234 | out_8(&lcd_reg[1], 0x00); |
Stefan Roese | 48a05a5 | 2006-02-07 16:51:04 +0100 | [diff] [blame] | 235 | |
Matthias Fuchs | 77660c4 | 2007-12-28 17:10:44 +0100 | [diff] [blame^] | 236 | if (in_8(&lcd_reg[0]) == 0x1c) { |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 237 | /* |
| 238 | * Big epson detected |
| 239 | */ |
| 240 | reg_byte_swap = FALSE; |
| 241 | palette_index = 0x1e2; |
| 242 | palette_value = 0x1e4; |
| 243 | lcd_depth = 16; |
| 244 | puts("LCD: S1D13806"); |
Matthias Fuchs | 77660c4 | 2007-12-28 17:10:44 +0100 | [diff] [blame^] | 245 | } else if (in_8(&lcd_reg[1]) == 0x1c) { |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 246 | /* |
| 247 | * Big epson detected (with register swap bug) |
| 248 | */ |
| 249 | reg_byte_swap = TRUE; |
| 250 | palette_index = 0x1e3; |
| 251 | palette_value = 0x1e5; |
| 252 | lcd_depth = 16; |
| 253 | puts("LCD: S1D13806S"); |
Matthias Fuchs | 77660c4 | 2007-12-28 17:10:44 +0100 | [diff] [blame^] | 254 | } else if (in_8(&lcd_reg[0]) == 0x18) { |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 255 | /* |
| 256 | * Small epson detected (704) |
| 257 | */ |
| 258 | reg_byte_swap = FALSE; |
| 259 | palette_index = 0x15; |
| 260 | palette_value = 0x17; |
| 261 | lcd_depth = 8; |
| 262 | puts("LCD: S1D13704"); |
Matthias Fuchs | 77660c4 | 2007-12-28 17:10:44 +0100 | [diff] [blame^] | 263 | } else if (in_8(&lcd_reg[0x10000]) == 0x24) { |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 264 | /* |
| 265 | * Small epson detected (705) |
| 266 | */ |
| 267 | reg_byte_swap = FALSE; |
| 268 | palette_index = 0x15; |
| 269 | palette_value = 0x17; |
| 270 | lcd_depth = 8; |
| 271 | lcd_reg += 0x10000; /* add offset for 705 regs */ |
| 272 | puts("LCD: S1D13705"); |
| 273 | } else { |
| 274 | puts("LCD: No controller detected!\n"); |
| 275 | return; |
| 276 | } |
| 277 | |
| 278 | /* |
| 279 | * Setup lcd controller regs |
| 280 | */ |
Matthias Fuchs | 77660c4 | 2007-12-28 17:10:44 +0100 | [diff] [blame^] | 281 | for (i = 0; i < reg_count; i++) { |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 282 | s1dReg = regs[i].Index; |
| 283 | if (reg_byte_swap) { |
| 284 | if ((s1dReg & 0x0001) == 0) |
| 285 | s1dReg |= 0x0001; |
| 286 | else |
| 287 | s1dReg &= ~0x0001; |
| 288 | } |
| 289 | s1dValue = regs[i].Value; |
| 290 | lcd_reg[s1dReg] = s1dValue; |
| 291 | } |
| 292 | |
| 293 | /* |
| 294 | * Save reg & mem pointer for later usage (e.g. bmp command) |
| 295 | */ |
| 296 | glob_lcd_reg = lcd_reg; |
| 297 | glob_lcd_mem = lcd_mem; |
| 298 | |
| 299 | /* |
| 300 | * Display bmp image |
| 301 | */ |
| 302 | lcd_bmp(logo_bmp); |
| 303 | } |
| 304 | |
Wolfgang Denk | c177bb5 | 2005-09-25 16:31:16 +0200 | [diff] [blame] | 305 | #ifdef CONFIG_VIDEO_SM501 |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 306 | int do_esdbmp(cmd_tbl_t *cmdtp, int flag, int argc, char *argv[]) |
| 307 | { |
| 308 | ulong addr; |
| 309 | char *str; |
| 310 | |
| 311 | if (argc != 2) { |
| 312 | printf ("Usage:\n%s\n", cmdtp->usage); |
| 313 | return 1; |
| 314 | } |
| 315 | |
| 316 | addr = simple_strtoul(argv[1], NULL, 16); |
| 317 | |
| 318 | str = getenv("bd_type"); |
| 319 | if ((strcmp(str, "ppc221") == 0) || (strcmp(str, "ppc231") == 0)) { |
| 320 | /* |
| 321 | * SM501 available, use standard bmp command |
| 322 | */ |
| 323 | return (video_display_bitmap(addr, 0, 0)); |
| 324 | } else { |
| 325 | /* |
| 326 | * No SM501 available, use esd epson bmp command |
| 327 | */ |
| 328 | lcd_bmp((uchar *)addr); |
| 329 | return 0; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | U_BOOT_CMD( |
| 334 | esdbmp, 2, 1, do_esdbmp, |
| 335 | "esdbmp - display BMP image\n", |
| 336 | "<imageAddr> - display image\n" |
| 337 | ); |
Wolfgang Denk | c177bb5 | 2005-09-25 16:31:16 +0200 | [diff] [blame] | 338 | #endif |