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