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