Blame view
common/lcd.c
17.4 KB
83d290c56 SPDX: Convert all... |
1 |
// SPDX-License-Identifier: GPL-2.0+ |
8655b6f86 * Clean up tools/... |
2 |
/* |
c8d2febcc lcd: various clea... |
3 |
* Common LCD routines |
8655b6f86 * Clean up tools/... |
4 5 6 |
* * (C) Copyright 2001-2002 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de |
8655b6f86 * Clean up tools/... |
7 |
*/ |
8655b6f86 * Clean up tools/... |
8 |
/* #define DEBUG */ |
8655b6f86 * Clean up tools/... |
9 10 11 |
#include <config.h> #include <common.h> #include <command.h> |
1eb69ae49 common: Move ARM ... |
12 |
#include <cpu_func.h> |
c08804853 lcd: implement a ... |
13 |
#include <env_callback.h> |
8655b6f86 * Clean up tools/... |
14 |
#include <linux/types.h> |
52cb4d4fb stdio/device: rew... |
15 |
#include <stdio_dev.h> |
8655b6f86 * Clean up tools/... |
16 |
#include <lcd.h> |
0eb25b619 common: Make sure... |
17 |
#include <mapmem.h> |
8b0bfc680 * Patch by Yuli B... |
18 |
#include <watchdog.h> |
dca2a1c18 common: lcd.c: fi... |
19 |
#include <asm/unaligned.h> |
dd4425e85 video: lcd: Add C... |
20 |
#include <splash.h> |
7d95f2a32 sandbox: Add LCD ... |
21 22 |
#include <asm/io.h> #include <asm/unaligned.h> |
c8d2febcc lcd: various clea... |
23 |
#include <video_font.h> |
dd4425e85 video: lcd: Add C... |
24 |
|
88804d19e * Patch by Detlev... |
25 |
#ifdef CONFIG_LCD_LOGO |
c8d2febcc lcd: various clea... |
26 27 28 29 30 |
#include <bmp_logo.h> #include <bmp_logo_data.h> #if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16) #error Default Color Map overlaps with Logo Color Map #endif |
88804d19e * Patch by Detlev... |
31 |
#endif |
8655b6f86 * Clean up tools/... |
32 |
|
676d319ef lcd: Add CONFIG_L... |
33 34 35 |
#ifndef CONFIG_LCD_ALIGNMENT #define CONFIG_LCD_ALIGNMENT PAGE_SIZE #endif |
a7de2953f lcd: get rid of C... |
36 37 |
#if (LCD_BPP != LCD_COLOR8) && (LCD_BPP != LCD_COLOR16) && \ (LCD_BPP != LCD_COLOR32) |
c8d2febcc lcd: various clea... |
38 |
#error Unsupported LCD BPP. |
a5796c51c common/lcd.c: mov... |
39 |
#endif |
d87080b72 GCC-4.x fixes: cl... |
40 |
DECLARE_GLOBAL_DATA_PTR; |
8655b6f86 * Clean up tools/... |
41 |
|
8f47d917c common lcd: minor... |
42 |
static int lcd_init(void *lcdbase); |
7bf71d1f5 lcd: split splash... |
43 |
static void lcd_logo(void); |
8f47d917c common lcd: minor... |
44 45 |
static void lcd_setfgcolor(int color); static void lcd_setbgcolor(int color); |
8655b6f86 * Clean up tools/... |
46 |
|
46d1d5dd4 common/lcd.c: cle... |
47 48 |
static int lcd_color_fg; static int lcd_color_bg; |
f1d205a19 common/lcd.c: cle... |
49 |
int lcd_line_length; |
8655b6f86 * Clean up tools/... |
50 |
char lcd_is_enabled = 0; |
00a0ca598 common/lcd.c: rem... |
51 |
static void *lcd_base; /* Start of framebuffer memory */ |
9a8efc460 lcd: Add support ... |
52 |
static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */ |
8655b6f86 * Clean up tools/... |
53 |
|
9a8efc460 lcd: Add support ... |
54 55 56 57 58 59 60 61 |
/* Flush LCD activity to the caches */ void lcd_sync(void) { /* * flush_dcache_range() is declared in common.h but it seems that some * architectures do not actually implement it. Is there a way to find * out whether it exists? For now, ARM is safe. */ |
100150254 CONFIG_SPL_SYS_[D... |
62 |
#if defined(CONFIG_ARM) && !CONFIG_IS_ENABLED(SYS_DCACHE_OFF) |
9a8efc460 lcd: Add support ... |
63 64 65 |
int line_length; if (lcd_flush_dcache) |
f8f58fbb0 lcd: Fix compile ... |
66 67 |
flush_dcache_range((ulong)lcd_base, (ulong)(lcd_base + lcd_get_size(&line_length))); |
9a8efc460 lcd: Add support ... |
68 69 70 71 72 73 74 |
#endif } void lcd_set_flush_dcache(int flush) { lcd_flush_dcache = (flush != 0); } |
709ea543b stdio: Pass devic... |
75 76 77 78 |
static void lcd_stub_putc(struct stdio_dev *dev, const char c) { lcd_putc(c); } |
709ea543b stdio: Pass devic... |
79 80 81 82 |
static void lcd_stub_puts(struct stdio_dev *dev, const char *s) { lcd_puts(s); } |
c8d2febcc lcd: various clea... |
83 |
/* Small utility to check that you got the colours right */ |
8655b6f86 * Clean up tools/... |
84 |
#ifdef LCD_TEST_PATTERN |
e32951b52 lcd: fix the colo... |
85 |
#if LCD_BPP == LCD_COLOR8 |
8655b6f86 * Clean up tools/... |
86 87 |
#define N_BLK_VERT 2 #define N_BLK_HOR 3 |
6b035141f common/lcd: cosme... |
88 |
static int test_colors[N_BLK_HOR * N_BLK_VERT] = { |
8655b6f86 * Clean up tools/... |
89 90 |
CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW, CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN, |
e32951b52 lcd: fix the colo... |
91 92 93 94 95 96 97 98 99 |
}; /*LCD_BPP == LCD_COLOR8 */ #elif LCD_BPP == LCD_COLOR16 #define N_BLK_VERT 2 #define N_BLK_HOR 4 static int test_colors[N_BLK_HOR * N_BLK_VERT] = { CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW, CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN, CONSOLE_COLOR_GREY, CONSOLE_COLOR_WHITE, |
8655b6f86 * Clean up tools/... |
100 |
}; |
e32951b52 lcd: fix the colo... |
101 |
#endif /*LCD_BPP == LCD_COLOR16 */ |
8655b6f86 * Clean up tools/... |
102 |
|
8f47d917c common lcd: minor... |
103 |
static void test_pattern(void) |
8655b6f86 * Clean up tools/... |
104 105 106 107 108 109 |
{ ushort v_max = panel_info.vl_row; ushort h_max = panel_info.vl_col; ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT; ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR; ushort v, h; |
e32951b52 lcd: fix the colo... |
110 |
#if LCD_BPP == LCD_COLOR8 |
8655b6f86 * Clean up tools/... |
111 |
uchar *pix = (uchar *)lcd_base; |
e32951b52 lcd: fix the colo... |
112 113 114 |
#elif LCD_BPP == LCD_COLOR16 ushort *pix = (ushort *)lcd_base; #endif |
8655b6f86 * Clean up tools/... |
115 |
|
8f47d917c common lcd: minor... |
116 117 |
printf("[LCD] Test Pattern: %d x %d [%d x %d] ", |
8655b6f86 * Clean up tools/... |
118 |
h_max, v_max, h_step, v_step); |
8f47d917c common lcd: minor... |
119 |
for (v = 0; v < v_max; ++v) { |
8655b6f86 * Clean up tools/... |
120 |
uchar iy = v / v_step; |
8f47d917c common lcd: minor... |
121 |
for (h = 0; h < h_max; ++h) { |
6b035141f common/lcd: cosme... |
122 |
uchar ix = N_BLK_HOR * iy + h / h_step; |
8655b6f86 * Clean up tools/... |
123 124 125 126 127 |
*pix++ = test_colors[ix]; } } } #endif /* LCD_TEST_PATTERN */ |
cefa47171 lcd: allow overri... |
128 129 130 131 132 133 134 |
/* * With most lcd drivers the line length is set up * by calculating it from panel_info parameters. Some * drivers need to calculate the line length differently, * so make the function weak to allow overriding it. */ __weak int lcd_get_size(int *line_length) |
676d319ef lcd: Add CONFIG_L... |
135 136 137 138 |
{ *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8; return *line_length * panel_info.vl_row; } |
6b035141f common/lcd: cosme... |
139 |
int drv_lcd_init(void) |
8655b6f86 * Clean up tools/... |
140 |
{ |
52cb4d4fb stdio/device: rew... |
141 |
struct stdio_dev lcddev; |
8655b6f86 * Clean up tools/... |
142 |
int rc; |
7d95f2a32 sandbox: Add LCD ... |
143 |
lcd_base = map_sysmem(gd->fb_base, 0); |
8655b6f86 * Clean up tools/... |
144 |
|
c8d2febcc lcd: various clea... |
145 |
lcd_init(lcd_base); |
8655b6f86 * Clean up tools/... |
146 147 |
/* Device initialization */ |
8f47d917c common lcd: minor... |
148 |
memset(&lcddev, 0, sizeof(lcddev)); |
8655b6f86 * Clean up tools/... |
149 |
|
8f47d917c common lcd: minor... |
150 |
strcpy(lcddev.name, "lcd"); |
8655b6f86 * Clean up tools/... |
151 152 |
lcddev.ext = 0; /* No extensions */ lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */ |
709ea543b stdio: Pass devic... |
153 154 |
lcddev.putc = lcd_stub_putc; /* 'putc' function */ lcddev.puts = lcd_stub_puts; /* 'puts' function */ |
8655b6f86 * Clean up tools/... |
155 |
|
6b035141f common/lcd: cosme... |
156 |
rc = stdio_register(&lcddev); |
8655b6f86 * Clean up tools/... |
157 158 159 |
return (rc == 0) ? 1 : rc; } |
02110903a lcd: add clear an... |
160 |
void lcd_clear(void) |
8655b6f86 * Clean up tools/... |
161 |
{ |
4d03634e5 lcd: introduce ge... |
162 |
int bg_color; |
5eb83c0ac splash: display s... |
163 |
__maybe_unused ulong addr; |
7bf71d1f5 lcd: split splash... |
164 |
static int do_splash = 1; |
f4469f50b lcd: remove LCD_M... |
165 |
#if LCD_BPP == LCD_COLOR8 |
8655b6f86 * Clean up tools/... |
166 |
/* Setting the palette */ |
8f47d917c common lcd: minor... |
167 168 169 170 171 172 173 174 175 |
lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0); lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0); lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0); lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0); lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF); lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF); lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF); lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA); lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF); |
8655b6f86 * Clean up tools/... |
176 |
#endif |
6d0f6bcf3 rename CFG_ macro... |
177 |
#ifndef CONFIG_SYS_WHITE_ON_BLACK |
8f47d917c common lcd: minor... |
178 179 |
lcd_setfgcolor(CONSOLE_COLOR_BLACK); lcd_setbgcolor(CONSOLE_COLOR_WHITE); |
4d03634e5 lcd: introduce ge... |
180 |
bg_color = CONSOLE_COLOR_WHITE; |
8655b6f86 * Clean up tools/... |
181 |
#else |
8f47d917c common lcd: minor... |
182 183 |
lcd_setfgcolor(CONSOLE_COLOR_WHITE); lcd_setbgcolor(CONSOLE_COLOR_BLACK); |
4d03634e5 lcd: introduce ge... |
184 |
bg_color = CONSOLE_COLOR_BLACK; |
6d0f6bcf3 rename CFG_ macro... |
185 |
#endif /* CONFIG_SYS_WHITE_ON_BLACK */ |
8655b6f86 * Clean up tools/... |
186 187 188 189 190 |
#ifdef LCD_TEST_PATTERN test_pattern(); #else /* set framebuffer to background color */ |
57d76a89b Add support for 3... |
191 |
#if (LCD_BPP != LCD_COLOR32) |
4d03634e5 lcd: introduce ge... |
192 |
memset((char *)lcd_base, bg_color, lcd_line_length * panel_info.vl_row); |
57d76a89b Add support for 3... |
193 194 195 196 197 198 |
#else u32 *ppix = lcd_base; u32 i; for (i = 0; i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix); i++) { |
4d03634e5 lcd: introduce ge... |
199 |
*ppix++ = bg_color; |
57d76a89b Add support for 3... |
200 201 |
} #endif |
8655b6f86 * Clean up tools/... |
202 |
#endif |
604c7d4a5 common/lcd_consol... |
203 204 205 206 207 208 209 |
/* setup text-console */ debug("[LCD] setting up console... "); lcd_init_console(lcd_base, panel_info.vl_col, panel_info.vl_row, panel_info.vl_rot); |
8655b6f86 * Clean up tools/... |
210 |
/* Paint the logo and retrieve LCD base address */ |
8f47d917c common lcd: minor... |
211 212 |
debug("[LCD] Drawing the logo... "); |
7bf71d1f5 lcd: split splash... |
213 |
if (do_splash) { |
5eb83c0ac splash: display s... |
214 |
if (splash_display() == 0) { |
7bf71d1f5 lcd: split splash... |
215 |
do_splash = 0; |
5eb83c0ac splash: display s... |
216 217 |
lcd_sync(); return; |
7bf71d1f5 lcd: split splash... |
218 219 220 221 222 223 |
} } lcd_logo(); #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) addr = (ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length; |
3b96b9096 common/lcd_consol... |
224 225 |
lcd_init_console((void *)addr, panel_info.vl_col, panel_info.vl_row, panel_info.vl_rot); |
7bf71d1f5 lcd: split splash... |
226 |
#endif |
9a8efc460 lcd: Add support ... |
227 228 |
lcd_sync(); } |
8f47d917c common lcd: minor... |
229 |
static int lcd_init(void *lcdbase) |
8655b6f86 * Clean up tools/... |
230 |
{ |
8f47d917c common lcd: minor... |
231 232 |
debug("[LCD] Initializing LCD frambuffer at %p ", lcdbase); |
8f47d917c common lcd: minor... |
233 |
lcd_ctrl_init(lcdbase); |
1d3dea12e video: bcm2835: f... |
234 235 |
/* |
9316e1440 ARM: rpi: rename ... |
236 |
* lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores |
1d3dea12e video: bcm2835: f... |
237 238 239 240 |
* the 'lcdbase' argument and uses custom lcd base address * by setting up gd->fb_base. Check for this condition and fixup * 'lcd_base' address. */ |
7d95f2a32 sandbox: Add LCD ... |
241 242 |
if (map_to_sysmem(lcdbase) != gd->fb_base) lcd_base = map_sysmem(gd->fb_base, 0); |
1d3dea12e video: bcm2835: f... |
243 244 245 |
debug("[LCD] Using LCD frambuffer at %p ", lcd_base); |
6d3307195 lcd: calculate li... |
246 |
lcd_get_size(&lcd_line_length); |
6f93d2b8f lcd: Set lcd_is_e... |
247 |
lcd_is_enabled = 1; |
02110903a lcd: add clear an... |
248 |
lcd_clear(); |
6b035141f common/lcd: cosme... |
249 |
lcd_enable(); |
8655b6f86 * Clean up tools/... |
250 251 |
/* Initialize the console */ |
140beb943 lcd: expand conso... |
252 |
lcd_set_col(0); |
88804d19e * Patch by Detlev... |
253 |
#ifdef CONFIG_LCD_INFO_BELOW_LOGO |
140beb943 lcd: expand conso... |
254 |
lcd_set_row(7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT); |
8655b6f86 * Clean up tools/... |
255 |
#else |
140beb943 lcd: expand conso... |
256 |
lcd_set_row(1); /* leave 1 blank line below logo */ |
8655b6f86 * Clean up tools/... |
257 |
#endif |
8655b6f86 * Clean up tools/... |
258 259 260 |
return 0; } |
8655b6f86 * Clean up tools/... |
261 262 263 264 265 266 267 |
/* * This is called early in the system initialization to grab memory * for the LCD controller. * Returns new address for monitor, after reserving LCD buffer memory * * Note that this is running from ROM, so no write access to global data. */ |
8f47d917c common lcd: minor... |
268 |
ulong lcd_setmem(ulong addr) |
8655b6f86 * Clean up tools/... |
269 270 |
{ ulong size; |
676d319ef lcd: Add CONFIG_L... |
271 |
int line_length; |
8655b6f86 * Clean up tools/... |
272 |
|
8f47d917c common lcd: minor... |
273 274 275 |
debug("LCD panel info: %d x %d, %d bit/pix ", panel_info.vl_col, panel_info.vl_row, NBITS(panel_info.vl_bpix)); |
8655b6f86 * Clean up tools/... |
276 |
|
676d319ef lcd: Add CONFIG_L... |
277 |
size = lcd_get_size(&line_length); |
8655b6f86 * Clean up tools/... |
278 |
|
676d319ef lcd: Add CONFIG_L... |
279 280 281 |
/* Round up to nearest full page, or MMU section if defined */ size = ALIGN(size, CONFIG_LCD_ALIGNMENT); addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT); |
8655b6f86 * Clean up tools/... |
282 283 284 |
/* Allocate pages for the frame buffer. */ addr -= size; |
6b035141f common/lcd: cosme... |
285 286 287 |
debug("Reserving %ldk for LCD Framebuffer at: %08lx ", size >> 10, addr); |
8655b6f86 * Clean up tools/... |
288 |
|
8f47d917c common lcd: minor... |
289 |
return addr; |
8655b6f86 * Clean up tools/... |
290 |
} |
8f47d917c common lcd: minor... |
291 |
static void lcd_setfgcolor(int color) |
8655b6f86 * Clean up tools/... |
292 |
{ |
39cf48048 Add ATMEL LCD driver |
293 |
lcd_color_fg = color; |
8655b6f86 * Clean up tools/... |
294 |
} |
4d03634e5 lcd: introduce ge... |
295 296 297 298 |
int lcd_getfgcolor(void) { return lcd_color_fg; } |
8f47d917c common lcd: minor... |
299 |
static void lcd_setbgcolor(int color) |
8655b6f86 * Clean up tools/... |
300 |
{ |
39cf48048 Add ATMEL LCD driver |
301 |
lcd_color_bg = color; |
8655b6f86 * Clean up tools/... |
302 |
} |
4d03634e5 lcd: introduce ge... |
303 304 305 306 |
int lcd_getbgcolor(void) { return lcd_color_bg; } |
8655b6f86 * Clean up tools/... |
307 |
#ifdef CONFIG_LCD_LOGO |
a02e94813 lcd: atmel: intro... |
308 309 |
__weak void lcd_logo_set_cmap(void) { |
2306457c4 lcd: logo: move g... |
310 311 312 313 314 |
int i; ushort *cmap = configuration_get_cmap(); for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) *cmap++ = bmp_logo_palette[i]; |
a02e94813 lcd: atmel: intro... |
315 |
} |
bf21a5deb lcd: rename bitma... |
316 |
void lcd_logo_plot(int x, int y) |
8655b6f86 * Clean up tools/... |
317 |
{ |
8655b6f86 * Clean up tools/... |
318 |
ushort i, j; |
c8d2febcc lcd: various clea... |
319 |
uchar *bmap = &bmp_logo_bitmap[0]; |
317461c1d Fix bitmap offset... |
320 |
unsigned bpix = NBITS(panel_info.vl_bpix); |
c8d2febcc lcd: various clea... |
321 322 |
uchar *fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8); ushort *fb16; |
8655b6f86 * Clean up tools/... |
323 |
|
2306457c4 lcd: logo: move g... |
324 325 326 |
debug("Logo: width %d height %d colors %d ", BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS); |
8655b6f86 * Clean up tools/... |
327 |
|
317461c1d Fix bitmap offset... |
328 |
if (bpix < 12) { |
8655b6f86 * Clean up tools/... |
329 |
WATCHDOG_RESET(); |
a02e94813 lcd: atmel: intro... |
330 |
lcd_logo_set_cmap(); |
8655b6f86 * Clean up tools/... |
331 |
WATCHDOG_RESET(); |
8f47d917c common lcd: minor... |
332 333 |
for (i = 0; i < BMP_LOGO_HEIGHT; ++i) { memcpy(fb, bmap, BMP_LOGO_WIDTH); |
8655b6f86 * Clean up tools/... |
334 |
bmap += BMP_LOGO_WIDTH; |
6b035141f common/lcd: cosme... |
335 |
fb += panel_info.vl_col; |
8655b6f86 * Clean up tools/... |
336 337 338 |
} } else { /* true color mode */ |
acb138689 lcd: make 16bpp work |
339 |
u16 col16; |
317461c1d Fix bitmap offset... |
340 |
fb16 = (ushort *)fb; |
8f47d917c common lcd: minor... |
341 342 |
for (i = 0; i < BMP_LOGO_HEIGHT; ++i) { for (j = 0; j < BMP_LOGO_WIDTH; j++) { |
acb138689 lcd: make 16bpp work |
343 344 345 346 347 |
col16 = bmp_logo_palette[(bmap[j]-16)]; fb16[j] = ((col16 & 0x000F) << 1) | ((col16 & 0x00F0) << 3) | ((col16 & 0x0F00) << 4); |
8655b6f86 * Clean up tools/... |
348 349 350 351 352 353 354 |
} bmap += BMP_LOGO_WIDTH; fb16 += panel_info.vl_col; } } WATCHDOG_RESET(); |
9a8efc460 lcd: Add support ... |
355 |
lcd_sync(); |
8655b6f86 * Clean up tools/... |
356 |
} |
2b5cb3d33 common/lcd.c: red... |
357 |
#else |
bf21a5deb lcd: rename bitma... |
358 |
static inline void lcd_logo_plot(int x, int y) {} |
8655b6f86 * Clean up tools/... |
359 |
#endif /* CONFIG_LCD_LOGO */ |
c3517f919 common/* non-cmd*... |
360 |
#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
1ca298ced Added support for... |
361 |
#ifdef CONFIG_SPLASH_SCREEN_ALIGN |
7c7e280aa common lcd: simpl... |
362 363 364 365 366 367 368 369 370 371 372 373 374 |
static void splash_align_axis(int *axis, unsigned long panel_size, unsigned long picture_size) { unsigned long panel_picture_delta = panel_size - picture_size; unsigned long axis_alignment; if (*axis == BMP_ALIGN_CENTER) axis_alignment = panel_picture_delta / 2; else if (*axis < 0) axis_alignment = panel_picture_delta + *axis + 1; else return; |
b41411954 linux/kernel.h: s... |
375 |
*axis = max(0, (int)axis_alignment); |
7c7e280aa common lcd: simpl... |
376 |
} |
1ca298ced Added support for... |
377 |
#endif |
45d7f5251 lcd: Implement RL... |
378 |
#ifdef CONFIG_LCD_BMP_RLE8 |
45d7f5251 lcd: Implement RL... |
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
#define BMP_RLE8_ESCAPE 0 #define BMP_RLE8_EOL 0 #define BMP_RLE8_EOBMP 1 #define BMP_RLE8_DELTA 2 static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap, int cnt) { while (cnt > 0) { *(*fbp)++ = cmap[*bmap++]; cnt--; } } static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt) { ushort *fb = *fbp; int cnt_8copy = cnt >> 3; cnt -= cnt_8copy << 3; while (cnt_8copy > 0) { *fb++ = c; *fb++ = c; *fb++ = c; *fb++ = c; *fb++ = c; *fb++ = c; *fb++ = c; *fb++ = c; cnt_8copy--; } while (cnt > 0) { *fb++ = c; cnt--; } |
6b035141f common/lcd: cosme... |
414 |
*fbp = fb; |
45d7f5251 lcd: Implement RL... |
415 416 417 |
} /* |
6b035141f common/lcd: cosme... |
418 |
* Do not call this function directly, must be called from lcd_display_bitmap. |
45d7f5251 lcd: Implement RL... |
419 |
*/ |
1c3dbe56f Remove typedefs f... |
420 421 |
static void lcd_display_rle8_bitmap(struct bmp_image *bmp, ushort *cmap, uchar *fb, int x_off, int y_off) |
45d7f5251 lcd: Implement RL... |
422 423 424 425 426 427 |
{ uchar *bmap; ulong width, height; ulong cnt, runlen; int x, y; int decode = 1; |
dca2a1c18 common: lcd.c: fi... |
428 429 430 |
width = get_unaligned_le32(&bmp->header.width); height = get_unaligned_le32(&bmp->header.height); bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); |
45d7f5251 lcd: Implement RL... |
431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 |
x = 0; y = height - 1; while (decode) { if (bmap[0] == BMP_RLE8_ESCAPE) { switch (bmap[1]) { case BMP_RLE8_EOL: /* end of line */ bmap += 2; x = 0; y--; /* 16bpix, 2-byte per pixel, width should *2 */ fb -= (width * 2 + lcd_line_length); break; case BMP_RLE8_EOBMP: /* end of bitmap */ decode = 0; break; case BMP_RLE8_DELTA: /* delta run */ x += bmap[2]; y -= bmap[3]; /* 16bpix, 2-byte per pixel, x should *2 */ fb = (uchar *) (lcd_base + (y + y_off - 1) * lcd_line_length + (x + x_off) * 2); bmap += 4; break; default: /* unencoded run */ runlen = bmap[1]; bmap += 2; if (y < height) { if (x < width) { if (x + runlen > width) cnt = width - x; else cnt = runlen; draw_unencoded_bitmap( (ushort **)&fb, bmap, cmap, cnt); } x += runlen; } bmap += runlen; if (runlen & 1) bmap++; } } else { /* encoded run */ if (y < height) { runlen = bmap[0]; if (x < width) { /* aggregate the same code */ while (bmap[0] == 0xff && bmap[2] != BMP_RLE8_ESCAPE && bmap[1] == bmap[3]) { runlen += bmap[2]; bmap += 2; } if (x + runlen > width) cnt = width - x; else cnt = runlen; draw_encoded_bitmap((ushort **)&fb, cmap[bmap[1]], cnt); } x += runlen; } bmap += 2; } } } #endif |
27fad01b7 lcd: mpc8xx: move... |
505 506 507 508 |
__weak void fb_put_byte(uchar **fb, uchar **from) { *(*fb)++ = *(*from)++; } |
bfdcc65e1 common lcd: simpl... |
509 510 |
#if defined(CONFIG_BMP_16BPP) |
b3d12e9bc lcd: atmel: move ... |
511 |
__weak void fb_put_word(uchar **fb, uchar **from) |
bfdcc65e1 common lcd: simpl... |
512 513 514 515 |
{ *(*fb)++ = *(*from)++; *(*fb)++ = *(*from)++; } |
bfdcc65e1 common lcd: simpl... |
516 |
#endif /* CONFIG_BMP_16BPP */ |
1c3dbe56f Remove typedefs f... |
517 |
__weak void lcd_set_cmap(struct bmp_image *bmp, unsigned colors) |
0b29a8969 lcd: introduce lc... |
518 519 |
{ int i; |
1c3dbe56f Remove typedefs f... |
520 |
struct bmp_color_table_entry cte; |
0b29a8969 lcd: introduce lc... |
521 522 523 524 525 526 527 |
ushort *cmap = configuration_get_cmap(); for (i = 0; i < colors; ++i) { cte = bmp->color_table[i]; *cmap = (((cte.red) << 8) & 0xf800) | (((cte.green) << 3) & 0x07e0) | (((cte.blue) >> 3) & 0x001f); |
0b29a8969 lcd: introduce lc... |
528 |
cmap++; |
0b29a8969 lcd: introduce lc... |
529 530 |
} } |
8655b6f86 * Clean up tools/... |
531 532 |
int lcd_display_bitmap(ulong bmp_image, int x, int y) { |
00cc5595a lcd: Fix compilat... |
533 |
ushort *cmap_base = NULL; |
8655b6f86 * Clean up tools/... |
534 535 |
ushort i, j; uchar *fb; |
1c3dbe56f Remove typedefs f... |
536 |
struct bmp_image *bmp = (struct bmp_image *)map_sysmem(bmp_image, 0); |
8655b6f86 * Clean up tools/... |
537 |
uchar *bmap; |
fecac46cf lcd: Fix BMP deco... |
538 |
ushort padded_width; |
b245e65ee LCD: support 8bpp... |
539 |
unsigned long width, height, byte_width; |
e8143e72e Add splashscreen ... |
540 |
unsigned long pwidth = panel_info.vl_col; |
b245e65ee LCD: support 8bpp... |
541 |
unsigned colors, bpix, bmp_bpix; |
8d379f179 lcd: Support colo... |
542 |
int hdr_size; |
021414a33 lcd: avoid possib... |
543 |
struct bmp_color_table_entry *palette; |
8655b6f86 * Clean up tools/... |
544 |
|
6b035141f common/lcd: cosme... |
545 546 |
if (!bmp || !(bmp->header.signature[0] == 'B' && bmp->header.signature[1] == 'M')) { |
8f47d917c common lcd: minor... |
547 548 |
printf("Error: no valid bmp image at %lx ", bmp_image); |
8655b6f86 * Clean up tools/... |
549 |
return 1; |
b245e65ee LCD: support 8bpp... |
550 |
} |
8655b6f86 * Clean up tools/... |
551 |
|
021414a33 lcd: avoid possib... |
552 |
palette = bmp->color_table; |
dca2a1c18 common: lcd.c: fi... |
553 554 555 |
width = get_unaligned_le32(&bmp->header.width); height = get_unaligned_le32(&bmp->header.height); bmp_bpix = get_unaligned_le16(&bmp->header.bit_count); |
8d379f179 lcd: Support colo... |
556 557 558 |
hdr_size = get_unaligned_le16(&bmp->header.size); debug("hdr_size=%d, bmp_bpix=%d ", hdr_size, bmp_bpix); |
dca2a1c18 common: lcd.c: fi... |
559 |
|
b245e65ee LCD: support 8bpp... |
560 |
colors = 1 << bmp_bpix; |
8655b6f86 * Clean up tools/... |
561 562 |
bpix = NBITS(panel_info.vl_bpix); |
6b035141f common/lcd: cosme... |
563 |
if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) { |
b245e65ee LCD: support 8bpp... |
564 565 566 |
printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel ", bpix, bmp_bpix); |
8f47d917c common lcd: minor... |
567 |
|
8655b6f86 * Clean up tools/... |
568 569 |
return 1; } |
a305fb155 lcd: support disp... |
570 571 572 573 574 575 576 |
/* * We support displaying 8bpp BMPs on 16bpp LCDs * and displaying 24bpp BMPs on 32bpp LCDs * */ if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16) && !(bmp_bpix == 24 && bpix == 32)) { |
8655b6f86 * Clean up tools/... |
577 578 |
printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel ", |
dca2a1c18 common: lcd.c: fi... |
579 |
bpix, get_unaligned_le16(&bmp->header.bit_count)); |
8655b6f86 * Clean up tools/... |
580 581 |
return 1; } |
8d379f179 lcd: Support colo... |
582 583 584 |
debug("Display-bmp: %d x %d with %d colors, display %d ", (int)width, (int)height, (int)colors, 1 << bpix); |
8655b6f86 * Clean up tools/... |
585 |
|
0b29a8969 lcd: introduce lc... |
586 587 |
if (bmp_bpix == 8) lcd_set_cmap(bmp, colors); |
e8143e72e Add splashscreen ... |
588 |
|
6b035141f common/lcd: cosme... |
589 |
padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width); |
1ca298ced Added support for... |
590 591 |
#ifdef CONFIG_SPLASH_SCREEN_ALIGN |
7c7e280aa common lcd: simpl... |
592 593 |
splash_align_axis(&x, pwidth, width); splash_align_axis(&y, panel_info.vl_row, height); |
1ca298ced Added support for... |
594 |
#endif /* CONFIG_SPLASH_SCREEN_ALIGN */ |
8f47d917c common lcd: minor... |
595 |
if ((x + width) > pwidth) |
e8143e72e Add splashscreen ... |
596 |
width = pwidth - x; |
8f47d917c common lcd: minor... |
597 |
if ((y + height) > panel_info.vl_row) |
8655b6f86 * Clean up tools/... |
598 |
height = panel_info.vl_row - y; |
dca2a1c18 common: lcd.c: fi... |
599 600 |
bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); fb = (uchar *)(lcd_base + |
8d46d5b18 lcd: align fb wri... |
601 |
(y + height - 1) * lcd_line_length + x * bpix / 8); |
a303dfb0e Add 16bpp BMP sup... |
602 |
|
b245e65ee LCD: support 8bpp... |
603 |
switch (bmp_bpix) { |
c8d2febcc lcd: various clea... |
604 |
case 1: |
0156444cf lcd: Fix build er... |
605 |
case 8: { |
0b29a8969 lcd: introduce lc... |
606 |
cmap_base = configuration_get_cmap(); |
45d7f5251 lcd: Implement RL... |
607 |
#ifdef CONFIG_LCD_BMP_RLE8 |
dca2a1c18 common: lcd.c: fi... |
608 |
u32 compression = get_unaligned_le32(&bmp->header.compression); |
8d379f179 lcd: Support colo... |
609 610 |
debug("compressed %d %d ", compression, BMP_BI_RLE8); |
dca2a1c18 common: lcd.c: fi... |
611 |
if (compression == BMP_BI_RLE8) { |
45d7f5251 lcd: Implement RL... |
612 613 614 615 616 617 618 619 620 |
if (bpix != 16) { /* TODO implement render code for bpix != 16 */ printf("Error: only support 16 bpix"); return 1; } lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y); break; } #endif |
b245e65ee LCD: support 8bpp... |
621 622 623 624 |
if (bpix != 16) byte_width = width; else byte_width = width * 2; |
a303dfb0e Add 16bpp BMP sup... |
625 626 |
for (i = 0; i < height; ++i) { WATCHDOG_RESET(); |
b245e65ee LCD: support 8bpp... |
627 628 |
for (j = 0; j < width; j++) { if (bpix != 16) { |
27fad01b7 lcd: mpc8xx: move... |
629 |
fb_put_byte(&fb, &bmap); |
b245e65ee LCD: support 8bpp... |
630 |
} else { |
8d379f179 lcd: Support colo... |
631 632 633 634 635 636 637 638 639 640 641 642 643 |
struct bmp_color_table_entry *entry; uint val; if (cmap_base) { val = cmap_base[*bmap]; } else { entry = &palette[*bmap]; val = entry->blue >> 3 | entry->green >> 2 << 5 | entry->red >> 3 << 11; } *(uint16_t *)fb = val; bmap++; |
b245e65ee LCD: support 8bpp... |
644 645 646 |
fb += sizeof(uint16_t) / sizeof(*fb); } } |
fecac46cf lcd: Fix BMP deco... |
647 |
bmap += (padded_width - width); |
6b035141f common/lcd: cosme... |
648 |
fb -= byte_width + lcd_line_length; |
a303dfb0e Add 16bpp BMP sup... |
649 650 |
} break; |
0156444cf lcd: Fix build er... |
651 |
} |
a303dfb0e Add 16bpp BMP sup... |
652 653 654 655 |
#if defined(CONFIG_BMP_16BPP) case 16: for (i = 0; i < height; ++i) { WATCHDOG_RESET(); |
bfdcc65e1 common lcd: simpl... |
656 657 |
for (j = 0; j < width; j++) fb_put_word(&fb, &bmap); |
fecac46cf lcd: Fix BMP deco... |
658 |
bmap += (padded_width - width) * 2; |
6b035141f common/lcd: cosme... |
659 |
fb -= width * 2 + lcd_line_length; |
a303dfb0e Add 16bpp BMP sup... |
660 661 662 |
} break; #endif /* CONFIG_BMP_16BPP */ |
10ba6b333 video: bmp: renam... |
663 |
#if defined(CONFIG_BMP_24BPP) |
a305fb155 lcd: support disp... |
664 665 666 667 668 669 670 671 672 673 674 |
case 24: for (i = 0; i < height; ++i) { for (j = 0; j < width; j++) { *(fb++) = *(bmap++); *(fb++) = *(bmap++); *(fb++) = *(bmap++); *(fb++) = 0; } fb -= lcd_line_length + width * (bpix / 8); } break; |
10ba6b333 video: bmp: renam... |
675 |
#endif /* CONFIG_BMP_24BPP */ |
fb6a9aab7 LCD: display 32bp... |
676 677 678 679 680 681 682 683 684 |
#if defined(CONFIG_BMP_32BPP) case 32: for (i = 0; i < height; ++i) { for (j = 0; j < width; j++) { *(fb++) = *(bmap++); *(fb++) = *(bmap++); *(fb++) = *(bmap++); *(fb++) = *(bmap++); } |
6b035141f common/lcd: cosme... |
685 |
fb -= lcd_line_length + width * (bpix / 8); |
fb6a9aab7 LCD: display 32bp... |
686 687 688 |
} break; #endif /* CONFIG_BMP_32BPP */ |
a303dfb0e Add 16bpp BMP sup... |
689 690 691 |
default: break; }; |
8655b6f86 * Clean up tools/... |
692 |
|
9a8efc460 lcd: Add support ... |
693 |
lcd_sync(); |
8f47d917c common lcd: minor... |
694 |
return 0; |
8655b6f86 * Clean up tools/... |
695 |
} |
c3517f919 common/* non-cmd*... |
696 |
#endif |
8655b6f86 * Clean up tools/... |
697 |
|
7bf71d1f5 lcd: split splash... |
698 |
static void lcd_logo(void) |
8655b6f86 * Clean up tools/... |
699 |
{ |
bf21a5deb lcd: rename bitma... |
700 |
lcd_logo_plot(0, 0); |
8655b6f86 * Clean up tools/... |
701 |
|
6b59e03e0 lcd: Let the boar... |
702 |
#ifdef CONFIG_LCD_INFO |
140beb943 lcd: expand conso... |
703 704 |
lcd_set_col(LCD_INFO_X / VIDEO_FONT_WIDTH); lcd_set_row(LCD_INFO_Y / VIDEO_FONT_HEIGHT); |
6b59e03e0 lcd: Let the boar... |
705 706 |
lcd_show_board_info(); #endif /* CONFIG_LCD_INFO */ |
8655b6f86 * Clean up tools/... |
707 |
} |
c08804853 lcd: implement a ... |
708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 |
#ifdef CONFIG_SPLASHIMAGE_GUARD static int on_splashimage(const char *name, const char *value, enum env_op op, int flags) { ulong addr; int aligned; if (op == env_op_delete) return 0; addr = simple_strtoul(value, NULL, 16); /* See README.displaying-bmps */ aligned = (addr % 4 == 2); if (!aligned) { printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned "); return -1; } return 0; } U_BOOT_ENV_CALLBACK(splashimage, on_splashimage); #endif |
395166cff lcd: Provide an A... |
732 733 734 735 736 737 738 739 740 |
int lcd_get_pixel_width(void) { return panel_info.vl_col; } int lcd_get_pixel_height(void) { return panel_info.vl_row; } |