blob: 5dd79481212ab272568cc4df824923a63fdcdaa8 [file] [log] [blame]
wdenk8655b6f2004-10-09 23:25:58 +00001/*
2 * Common LCD routines for supported CPUs
3 *
4 * (C) Copyright 2001-2002
5 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
6 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02007 * SPDX-License-Identifier: GPL-2.0+
wdenk8655b6f2004-10-09 23:25:58 +00008 */
9
10/************************************************************************/
11/* ** HEADER FILES */
12/************************************************************************/
13
14/* #define DEBUG */
15
16#include <config.h>
17#include <common.h>
18#include <command.h>
wdenk8655b6f2004-10-09 23:25:58 +000019#include <stdarg.h>
Nikita Kiryanovc0880482013-02-24 21:28:43 +000020#include <search.h>
21#include <env_callback.h>
wdenk8655b6f2004-10-09 23:25:58 +000022#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020023#include <stdio_dev.h>
wdenk8655b6f2004-10-09 23:25:58 +000024#if defined(CONFIG_POST)
25#include <post.h>
26#endif
27#include <lcd.h>
wdenk8b0bfc62005-04-03 23:11:38 +000028#include <watchdog.h>
wdenk8655b6f2004-10-09 23:25:58 +000029
Robert Winklerdd4425e2013-06-17 11:31:29 -070030#include <splash.h>
31
Marek Vasutabc20ab2011-11-26 07:20:07 +010032#if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
33 defined(CONFIG_CPU_MONAHANS)
34#define CONFIG_CPU_PXA
wdenk8655b6f2004-10-09 23:25:58 +000035#include <asm/byteorder.h>
36#endif
37
38#if defined(CONFIG_MPC823)
wdenk8655b6f2004-10-09 23:25:58 +000039#include <lcdvideo.h>
40#endif
41
Stelian Pop39cf4802008-05-09 21:57:18 +020042#if defined(CONFIG_ATMEL_LCD)
43#include <atmel_lcdc.h>
Stelian Pop39cf4802008-05-09 21:57:18 +020044#endif
45
Stephen Warren6a195d22013-05-27 18:31:17 +000046#if defined(CONFIG_LCD_DT_SIMPLEFB)
47#include <libfdt.h>
48#endif
49
wdenk8655b6f2004-10-09 23:25:58 +000050/************************************************************************/
51/* ** FONT DATA */
52/************************************************************************/
53#include <video_font.h> /* Get font data, width and height */
54
wdenk88804d12005-07-04 00:03:16 +000055/************************************************************************/
56/* ** LOGO DATA */
57/************************************************************************/
58#ifdef CONFIG_LCD_LOGO
59# include <bmp_logo.h> /* Get logo data, width and height */
Che-Liang Chiouc2707302011-10-20 23:04:20 +000060# include <bmp_logo_data.h>
Alessandro Rubiniacb13862010-03-13 17:44:08 +010061# if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
wdenk88804d12005-07-04 00:03:16 +000062# error Default Color Map overlaps with Logo Color Map
63# endif
64#endif
wdenk8655b6f2004-10-09 23:25:58 +000065
Simon Glass676d3192012-10-17 13:24:54 +000066#ifndef CONFIG_LCD_ALIGNMENT
67#define CONFIG_LCD_ALIGNMENT PAGE_SIZE
68#endif
69
Simon Glass0d89efe2012-10-17 13:24:59 +000070/* By default we scroll by a single line */
71#ifndef CONFIG_CONSOLE_SCROLL_LINES
72#define CONFIG_CONSOLE_SCROLL_LINES 1
73#endif
74
Jeroen Hofsteea5796c52013-01-12 12:07:59 +000075/************************************************************************/
76/* ** CONSOLE DEFINITIONS & FUNCTIONS */
77/************************************************************************/
78#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
79# define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
80 / VIDEO_FONT_HEIGHT)
81#else
82# define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
83#endif
Wolfgang Denkd87080b2006-03-31 18:32:53 +020084
Jeroen Hofsteea5796c52013-01-12 12:07:59 +000085#define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
86#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
87#define CONSOLE_ROW_FIRST lcd_console_address
88#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
89#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
90 - CONSOLE_ROW_SIZE)
91#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
92#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
93
94#if LCD_BPP == LCD_MONOCHROME
95# define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
96 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
97#elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16)
98# define COLOR_MASK(c) (c)
99#else
100# error Unsupported LCD BPP.
101#endif
102
wdenk8655b6f2004-10-09 23:25:58 +0000103DECLARE_GLOBAL_DATA_PTR;
wdenk8655b6f2004-10-09 23:25:58 +0000104
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000105static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
106static inline void lcd_puts_xy(ushort x, ushort y, uchar *s);
107static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
wdenk8655b6f2004-10-09 23:25:58 +0000108
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000109static int lcd_init(void *lcdbase);
wdenk8655b6f2004-10-09 23:25:58 +0000110
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000111static void *lcd_logo(void);
wdenk8655b6f2004-10-09 23:25:58 +0000112
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000113static int lcd_getbgcolor(void);
114static void lcd_setfgcolor(int color);
115static void lcd_setbgcolor(int color);
wdenk8655b6f2004-10-09 23:25:58 +0000116
Wolfgang Denk46d1d5d2013-01-05 09:45:48 +0000117static int lcd_color_fg;
118static int lcd_color_bg;
Jeroen Hofsteef1d205a2013-01-22 10:44:11 +0000119int lcd_line_length;
Wolfgang Denk46d1d5d2013-01-05 09:45:48 +0000120
wdenk8655b6f2004-10-09 23:25:58 +0000121char lcd_is_enabled = 0;
wdenk8655b6f2004-10-09 23:25:58 +0000122
Jeroen Hofsteef1d205a2013-01-22 10:44:11 +0000123static short console_col;
124static short console_row;
125
126static void *lcd_console_address;
Jeroen Hofstee00a0ca52013-01-22 10:44:12 +0000127static void *lcd_base; /* Start of framebuffer memory */
Jeroen Hofsteef1d205a2013-01-22 10:44:11 +0000128
Simon Glass9a8efc42012-10-30 13:40:18 +0000129static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
130
wdenk8655b6f2004-10-09 23:25:58 +0000131/************************************************************************/
132
Simon Glass9a8efc42012-10-30 13:40:18 +0000133/* Flush LCD activity to the caches */
134void lcd_sync(void)
135{
136 /*
137 * flush_dcache_range() is declared in common.h but it seems that some
138 * architectures do not actually implement it. Is there a way to find
139 * out whether it exists? For now, ARM is safe.
140 */
141#if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
142 int line_length;
143
144 if (lcd_flush_dcache)
145 flush_dcache_range((u32)lcd_base,
146 (u32)(lcd_base + lcd_get_size(&line_length)));
147#endif
148}
149
150void lcd_set_flush_dcache(int flush)
151{
152 lcd_flush_dcache = (flush != 0);
153}
154
wdenk8655b6f2004-10-09 23:25:58 +0000155/*----------------------------------------------------------------------*/
156
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000157static void console_scrollup(void)
wdenk8655b6f2004-10-09 23:25:58 +0000158{
Simon Glass0d89efe2012-10-17 13:24:59 +0000159 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
wdenk8655b6f2004-10-09 23:25:58 +0000160
Simon Glass0d89efe2012-10-17 13:24:59 +0000161 /* Copy up rows ignoring those that will be overwritten */
162 memcpy(CONSOLE_ROW_FIRST,
163 lcd_console_address + CONSOLE_ROW_SIZE * rows,
164 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
165
166 /* Clear the last rows */
167 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
168 COLOR_MASK(lcd_color_bg),
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000169 CONSOLE_ROW_SIZE * rows);
Simon Glass0d89efe2012-10-17 13:24:59 +0000170
Simon Glass9a8efc42012-10-30 13:40:18 +0000171 lcd_sync();
Simon Glass0d89efe2012-10-17 13:24:59 +0000172 console_row -= rows;
wdenk8655b6f2004-10-09 23:25:58 +0000173}
174
175/*----------------------------------------------------------------------*/
176
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000177static inline void console_back(void)
wdenk8655b6f2004-10-09 23:25:58 +0000178{
179 if (--console_col < 0) {
180 console_col = CONSOLE_COLS-1 ;
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000181 if (--console_row < 0)
wdenk8655b6f2004-10-09 23:25:58 +0000182 console_row = 0;
wdenk8655b6f2004-10-09 23:25:58 +0000183 }
184
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000185 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
186 console_row * VIDEO_FONT_HEIGHT, ' ');
wdenk8655b6f2004-10-09 23:25:58 +0000187}
188
189/*----------------------------------------------------------------------*/
190
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000191static inline void console_newline(void)
wdenk8655b6f2004-10-09 23:25:58 +0000192{
wdenk8655b6f2004-10-09 23:25:58 +0000193 console_col = 0;
194
195 /* Check if we need to scroll the terminal */
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000196 if (++console_row >= CONSOLE_ROWS)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000197 console_scrollup();
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000198 else
Simon Glass9a8efc42012-10-30 13:40:18 +0000199 lcd_sync();
wdenk8655b6f2004-10-09 23:25:58 +0000200}
201
202/*----------------------------------------------------------------------*/
203
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000204void lcd_putc(const char c)
wdenk8655b6f2004-10-09 23:25:58 +0000205{
206 if (!lcd_is_enabled) {
207 serial_putc(c);
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000208
wdenk8655b6f2004-10-09 23:25:58 +0000209 return;
210 }
211
212 switch (c) {
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000213 case '\r':
214 console_col = 0;
wdenk8655b6f2004-10-09 23:25:58 +0000215
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000216 return;
217 case '\n':
218 console_newline();
wdenk8655b6f2004-10-09 23:25:58 +0000219
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000220 return;
wdenk8655b6f2004-10-09 23:25:58 +0000221 case '\t': /* Tab (8 chars alignment) */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000222 console_col += 8;
223 console_col &= ~7;
wdenk8655b6f2004-10-09 23:25:58 +0000224
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000225 if (console_col >= CONSOLE_COLS)
226 console_newline();
wdenk8655b6f2004-10-09 23:25:58 +0000227
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000228 return;
229 case '\b':
230 console_back();
wdenk8655b6f2004-10-09 23:25:58 +0000231
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000232 return;
233 default:
234 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
235 console_row * VIDEO_FONT_HEIGHT, c);
236 if (++console_col >= CONSOLE_COLS)
237 console_newline();
wdenk8655b6f2004-10-09 23:25:58 +0000238 }
wdenk8655b6f2004-10-09 23:25:58 +0000239}
240
241/*----------------------------------------------------------------------*/
242
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000243void lcd_puts(const char *s)
wdenk8655b6f2004-10-09 23:25:58 +0000244{
245 if (!lcd_is_enabled) {
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000246 serial_puts(s);
247
wdenk8655b6f2004-10-09 23:25:58 +0000248 return;
249 }
250
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000251 while (*s)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000252 lcd_putc(*s++);
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000253
Simon Glass9a8efc42012-10-30 13:40:18 +0000254 lcd_sync();
wdenk8655b6f2004-10-09 23:25:58 +0000255}
256
Haavard Skinnemoen15b17ab2008-09-01 16:21:20 +0200257/*----------------------------------------------------------------------*/
258
259void lcd_printf(const char *fmt, ...)
260{
261 va_list args;
262 char buf[CONFIG_SYS_PBSIZE];
263
264 va_start(args, fmt);
265 vsprintf(buf, fmt, args);
266 va_end(args);
267
268 lcd_puts(buf);
269}
270
wdenk8655b6f2004-10-09 23:25:58 +0000271/************************************************************************/
272/* ** Low-Level Graphics Routines */
273/************************************************************************/
274
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000275static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
wdenk8655b6f2004-10-09 23:25:58 +0000276{
277 uchar *dest;
Marek Vasutbe547c62011-09-26 02:26:04 +0200278 ushort row;
279
Anatolij Gustschin0f999c42012-04-27 04:41:16 +0000280#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
281 y += BMP_LOGO_HEIGHT;
282#endif
283
Marek Vasutbe547c62011-09-26 02:26:04 +0200284#if LCD_BPP == LCD_MONOCHROME
285 ushort off = x * (1 << LCD_BPP) % 8;
286#endif
wdenk8655b6f2004-10-09 23:25:58 +0000287
288 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
wdenk8655b6f2004-10-09 23:25:58 +0000289
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000290 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
wdenk8655b6f2004-10-09 23:25:58 +0000291 uchar *s = str;
wdenk8655b6f2004-10-09 23:25:58 +0000292 int i;
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100293#if LCD_BPP == LCD_COLOR16
294 ushort *d = (ushort *)dest;
295#else
296 uchar *d = dest;
297#endif
wdenk8655b6f2004-10-09 23:25:58 +0000298
299#if LCD_BPP == LCD_MONOCHROME
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000300 uchar rest = *d & -(1 << (8 - off));
wdenk8655b6f2004-10-09 23:25:58 +0000301 uchar sym;
302#endif
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000303 for (i = 0; i < count; ++i) {
wdenk8655b6f2004-10-09 23:25:58 +0000304 uchar c, bits;
305
306 c = *s++;
307 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
308
309#if LCD_BPP == LCD_MONOCHROME
310 sym = (COLOR_MASK(lcd_color_fg) & bits) |
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000311 (COLOR_MASK(lcd_color_bg) & ~bits);
wdenk8655b6f2004-10-09 23:25:58 +0000312
313 *d++ = rest | (sym >> off);
314 rest = sym << (8-off);
315#elif LCD_BPP == LCD_COLOR8
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000316 for (c = 0; c < 8; ++c) {
wdenk8655b6f2004-10-09 23:25:58 +0000317 *d++ = (bits & 0x80) ?
318 lcd_color_fg : lcd_color_bg;
319 bits <<= 1;
320 }
321#elif LCD_BPP == LCD_COLOR16
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000322 for (c = 0; c < 8; ++c) {
wdenk8655b6f2004-10-09 23:25:58 +0000323 *d++ = (bits & 0x80) ?
324 lcd_color_fg : lcd_color_bg;
325 bits <<= 1;
326 }
327#endif
328 }
329#if LCD_BPP == LCD_MONOCHROME
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000330 *d = rest | (*d & ((1 << (8 - off)) - 1));
wdenk8655b6f2004-10-09 23:25:58 +0000331#endif
332 }
333}
334
335/*----------------------------------------------------------------------*/
336
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000337static inline void lcd_puts_xy(ushort x, ushort y, uchar *s)
wdenk8655b6f2004-10-09 23:25:58 +0000338{
Anatolij Gustschin0f999c42012-04-27 04:41:16 +0000339 lcd_drawchars(x, y, s, strlen((char *)s));
wdenk8655b6f2004-10-09 23:25:58 +0000340}
341
342/*----------------------------------------------------------------------*/
343
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000344static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
wdenk8655b6f2004-10-09 23:25:58 +0000345{
Anatolij Gustschin0f999c42012-04-27 04:41:16 +0000346 lcd_drawchars(x, y, &c, 1);
wdenk8655b6f2004-10-09 23:25:58 +0000347}
348
349/************************************************************************/
350/** Small utility to check that you got the colours right */
351/************************************************************************/
352#ifdef LCD_TEST_PATTERN
353
354#define N_BLK_VERT 2
355#define N_BLK_HOR 3
356
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000357static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
wdenk8655b6f2004-10-09 23:25:58 +0000358 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
359 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
360};
361
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000362static void test_pattern(void)
wdenk8655b6f2004-10-09 23:25:58 +0000363{
364 ushort v_max = panel_info.vl_row;
365 ushort h_max = panel_info.vl_col;
366 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
367 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
368 ushort v, h;
369 uchar *pix = (uchar *)lcd_base;
370
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000371 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
wdenk8655b6f2004-10-09 23:25:58 +0000372 h_max, v_max, h_step, v_step);
373
374 /* WARNING: Code silently assumes 8bit/pixel */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000375 for (v = 0; v < v_max; ++v) {
wdenk8655b6f2004-10-09 23:25:58 +0000376 uchar iy = v / v_step;
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000377 for (h = 0; h < h_max; ++h) {
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000378 uchar ix = N_BLK_HOR * iy + h / h_step;
wdenk8655b6f2004-10-09 23:25:58 +0000379 *pix++ = test_colors[ix];
380 }
381 }
382}
383#endif /* LCD_TEST_PATTERN */
384
385
386/************************************************************************/
387/* ** GENERIC Initialization Routines */
388/************************************************************************/
389
Simon Glass676d3192012-10-17 13:24:54 +0000390int lcd_get_size(int *line_length)
391{
392 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
393 return *line_length * panel_info.vl_row;
394}
395
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000396int drv_lcd_init(void)
wdenk8655b6f2004-10-09 23:25:58 +0000397{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200398 struct stdio_dev lcddev;
wdenk8655b6f2004-10-09 23:25:58 +0000399 int rc;
400
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000401 lcd_base = (void *) gd->fb_base;
wdenk8655b6f2004-10-09 23:25:58 +0000402
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000403 lcd_init(lcd_base); /* LCD initialization */
wdenk8655b6f2004-10-09 23:25:58 +0000404
405 /* Device initialization */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000406 memset(&lcddev, 0, sizeof(lcddev));
wdenk8655b6f2004-10-09 23:25:58 +0000407
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000408 strcpy(lcddev.name, "lcd");
wdenk8655b6f2004-10-09 23:25:58 +0000409 lcddev.ext = 0; /* No extensions */
410 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
411 lcddev.putc = lcd_putc; /* 'putc' function */
412 lcddev.puts = lcd_puts; /* 'puts' function */
413
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000414 rc = stdio_register(&lcddev);
wdenk8655b6f2004-10-09 23:25:58 +0000415
416 return (rc == 0) ? 1 : rc;
417}
418
419/*----------------------------------------------------------------------*/
Che-Liang Chiou02110902011-10-20 23:07:03 +0000420void lcd_clear(void)
wdenk8655b6f2004-10-09 23:25:58 +0000421{
422#if LCD_BPP == LCD_MONOCHROME
423 /* Setting the palette */
424 lcd_initcolregs();
425
426#elif LCD_BPP == LCD_COLOR8
427 /* Setting the palette */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000428 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
429 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
430 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
431 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
432 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
433 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
434 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
435 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
436 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
wdenk8655b6f2004-10-09 23:25:58 +0000437#endif
438
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200439#ifndef CONFIG_SYS_WHITE_ON_BLACK
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000440 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
441 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
wdenk8655b6f2004-10-09 23:25:58 +0000442#else
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000443 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
444 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200445#endif /* CONFIG_SYS_WHITE_ON_BLACK */
wdenk8655b6f2004-10-09 23:25:58 +0000446
447#ifdef LCD_TEST_PATTERN
448 test_pattern();
449#else
450 /* set framebuffer to background color */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000451 memset((char *)lcd_base,
wdenk8655b6f2004-10-09 23:25:58 +0000452 COLOR_MASK(lcd_getbgcolor()),
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000453 lcd_line_length * panel_info.vl_row);
wdenk8655b6f2004-10-09 23:25:58 +0000454#endif
455 /* Paint the logo and retrieve LCD base address */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000456 debug("[LCD] Drawing the logo...\n");
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000457 lcd_console_address = lcd_logo();
wdenk8655b6f2004-10-09 23:25:58 +0000458
459 console_col = 0;
460 console_row = 0;
Simon Glass9a8efc42012-10-30 13:40:18 +0000461 lcd_sync();
462}
463
464static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
465 char *const argv[])
466{
467 lcd_clear();
468 return 0;
wdenk8655b6f2004-10-09 23:25:58 +0000469}
470
471U_BOOT_CMD(
Che-Liang Chiou02110902011-10-20 23:07:03 +0000472 cls, 1, 1, do_lcd_clear,
Peter Tyser2fb26042009-01-27 18:03:12 -0600473 "clear screen",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200474 ""
wdenk8655b6f2004-10-09 23:25:58 +0000475);
476
477/*----------------------------------------------------------------------*/
478
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000479static int lcd_init(void *lcdbase)
wdenk8655b6f2004-10-09 23:25:58 +0000480{
481 /* Initialize the lcd controller */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000482 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
wdenk8655b6f2004-10-09 23:25:58 +0000483
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000484 lcd_ctrl_init(lcdbase);
Anatolij Gustschin1d3dea12013-03-29 14:00:13 +0100485
486 /*
487 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi_b) ignores
488 * the 'lcdbase' argument and uses custom lcd base address
489 * by setting up gd->fb_base. Check for this condition and fixup
490 * 'lcd_base' address.
491 */
492 if ((unsigned long)lcdbase != gd->fb_base)
493 lcd_base = (void *)gd->fb_base;
494
495 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
496
Stephen Warren6d330712013-01-29 16:37:38 +0000497 lcd_get_size(&lcd_line_length);
498 lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
Haavard Skinnemoen6f93d2b2008-09-01 16:21:21 +0200499 lcd_is_enabled = 1;
Che-Liang Chiou02110902011-10-20 23:07:03 +0000500 lcd_clear();
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000501 lcd_enable();
wdenk8655b6f2004-10-09 23:25:58 +0000502
503 /* Initialize the console */
504 console_col = 0;
wdenk88804d12005-07-04 00:03:16 +0000505#ifdef CONFIG_LCD_INFO_BELOW_LOGO
wdenk8655b6f2004-10-09 23:25:58 +0000506 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
507#else
508 console_row = 1; /* leave 1 blank line below logo */
509#endif
wdenk8655b6f2004-10-09 23:25:58 +0000510
511 return 0;
512}
513
514
515/************************************************************************/
516/* ** ROM capable initialization part - needed to reserve FB memory */
517/************************************************************************/
518/*
519 * This is called early in the system initialization to grab memory
520 * for the LCD controller.
521 * Returns new address for monitor, after reserving LCD buffer memory
522 *
523 * Note that this is running from ROM, so no write access to global data.
524 */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000525ulong lcd_setmem(ulong addr)
wdenk8655b6f2004-10-09 23:25:58 +0000526{
527 ulong size;
Simon Glass676d3192012-10-17 13:24:54 +0000528 int line_length;
wdenk8655b6f2004-10-09 23:25:58 +0000529
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000530 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
531 panel_info.vl_row, NBITS(panel_info.vl_bpix));
wdenk8655b6f2004-10-09 23:25:58 +0000532
Simon Glass676d3192012-10-17 13:24:54 +0000533 size = lcd_get_size(&line_length);
wdenk8655b6f2004-10-09 23:25:58 +0000534
Simon Glass676d3192012-10-17 13:24:54 +0000535 /* Round up to nearest full page, or MMU section if defined */
536 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
537 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
wdenk8655b6f2004-10-09 23:25:58 +0000538
539 /* Allocate pages for the frame buffer. */
540 addr -= size;
541
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000542 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
543 size >> 10, addr);
wdenk8655b6f2004-10-09 23:25:58 +0000544
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000545 return addr;
wdenk8655b6f2004-10-09 23:25:58 +0000546}
547
548/*----------------------------------------------------------------------*/
549
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000550static void lcd_setfgcolor(int color)
wdenk8655b6f2004-10-09 23:25:58 +0000551{
Stelian Pop39cf4802008-05-09 21:57:18 +0200552 lcd_color_fg = color;
wdenk8655b6f2004-10-09 23:25:58 +0000553}
554
555/*----------------------------------------------------------------------*/
556
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000557static void lcd_setbgcolor(int color)
wdenk8655b6f2004-10-09 23:25:58 +0000558{
Stelian Pop39cf4802008-05-09 21:57:18 +0200559 lcd_color_bg = color;
wdenk8655b6f2004-10-09 23:25:58 +0000560}
561
562/*----------------------------------------------------------------------*/
563
Wolfgang Denk46d1d5d2013-01-05 09:45:48 +0000564int lcd_getfgcolor(void)
wdenk8655b6f2004-10-09 23:25:58 +0000565{
566 return lcd_color_fg;
567}
wdenk8655b6f2004-10-09 23:25:58 +0000568
569/*----------------------------------------------------------------------*/
570
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000571static int lcd_getbgcolor(void)
wdenk8655b6f2004-10-09 23:25:58 +0000572{
573 return lcd_color_bg;
574}
575
wdenk8655b6f2004-10-09 23:25:58 +0000576/************************************************************************/
577/* ** Chipset depending Bitmap / Logo stuff... */
578/************************************************************************/
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000579static inline ushort *configuration_get_cmap(void)
580{
581#if defined CONFIG_CPU_PXA
582 struct pxafb_info *fbi = &panel_info.pxa;
583 return (ushort *)fbi->palette;
584#elif defined(CONFIG_MPC823)
585 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
586 cpm8xx_t *cp = &(immr->im_cpm);
587 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
588#elif defined(CONFIG_ATMEL_LCD)
589 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
Anatolij Gustschind23019f2012-09-22 06:55:53 +0000590#elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
591 return panel_info.cmap;
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000592#elif defined(CONFIG_LCD_LOGO)
Anatolij Gustschind23019f2012-09-22 06:55:53 +0000593 return bmp_logo_palette;
594#else
595 return NULL;
596#endif
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000597}
598
wdenk8655b6f2004-10-09 23:25:58 +0000599#ifdef CONFIG_LCD_LOGO
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000600void bitmap_plot(int x, int y)
wdenk8655b6f2004-10-09 23:25:58 +0000601{
Stelian Pop39cf4802008-05-09 21:57:18 +0200602#ifdef CONFIG_ATMEL_LCD
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000603 uint *cmap = (uint *)bmp_logo_palette;
Stelian Pop39cf4802008-05-09 21:57:18 +0200604#else
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000605 ushort *cmap = (ushort *)bmp_logo_palette;
Stelian Pop39cf4802008-05-09 21:57:18 +0200606#endif
wdenk8655b6f2004-10-09 23:25:58 +0000607 ushort i, j;
608 uchar *bmap;
609 uchar *fb;
610 ushort *fb16;
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000611#if defined(CONFIG_MPC823)
612 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
613 cpm8xx_t *cp = &(immr->im_cpm);
wdenk8655b6f2004-10-09 23:25:58 +0000614#endif
Andre Renaud317461c2013-02-13 17:48:00 +0000615 unsigned bpix = NBITS(panel_info.vl_bpix);
wdenk8655b6f2004-10-09 23:25:58 +0000616
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000617 debug("Logo: width %d height %d colors %d cmap %d\n",
wdenk8655b6f2004-10-09 23:25:58 +0000618 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
Anatolij Gustschin095407d2012-04-27 04:41:06 +0000619 ARRAY_SIZE(bmp_logo_palette));
wdenk8655b6f2004-10-09 23:25:58 +0000620
621 bmap = &bmp_logo_bitmap[0];
Andre Renaud317461c2013-02-13 17:48:00 +0000622 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
wdenk8655b6f2004-10-09 23:25:58 +0000623
Andre Renaud317461c2013-02-13 17:48:00 +0000624 if (bpix < 12) {
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000625 /* Leave room for default color map
626 * default case: generic system with no cmap (most likely 16bpp)
627 * cmap was set to the source palette, so no change is done.
628 * This avoids even more ifdefs in the next stanza
629 */
630#if defined(CONFIG_MPC823)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000631 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
Stelian Pop39cf4802008-05-09 21:57:18 +0200632#elif defined(CONFIG_ATMEL_LCD)
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000633 cmap = (uint *)configuration_get_cmap();
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100634#else
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000635 cmap = configuration_get_cmap();
wdenk8655b6f2004-10-09 23:25:58 +0000636#endif
637
638 WATCHDOG_RESET();
639
640 /* Set color map */
Anatolij Gustschin095407d2012-04-27 04:41:06 +0000641 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
wdenk8655b6f2004-10-09 23:25:58 +0000642 ushort colreg = bmp_logo_palette[i];
Stelian Pop39cf4802008-05-09 21:57:18 +0200643#ifdef CONFIG_ATMEL_LCD
644 uint lut_entry;
645#ifdef CONFIG_ATMEL_LCD_BGR555
646 lut_entry = ((colreg & 0x000F) << 11) |
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000647 ((colreg & 0x00F0) << 2) |
648 ((colreg & 0x0F00) >> 7);
Stelian Pop39cf4802008-05-09 21:57:18 +0200649#else /* CONFIG_ATMEL_LCD_RGB565 */
650 lut_entry = ((colreg & 0x000F) << 1) |
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000651 ((colreg & 0x00F0) << 3) |
652 ((colreg & 0x0F00) << 4);
Stelian Pop39cf4802008-05-09 21:57:18 +0200653#endif
654 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
655 cmap++;
656#else /* !CONFIG_ATMEL_LCD */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200657#ifdef CONFIG_SYS_INVERT_COLORS
wdenk8655b6f2004-10-09 23:25:58 +0000658 *cmap++ = 0xffff - colreg;
659#else
660 *cmap++ = colreg;
661#endif
Stelian Pop39cf4802008-05-09 21:57:18 +0200662#endif /* CONFIG_ATMEL_LCD */
wdenk8655b6f2004-10-09 23:25:58 +0000663 }
664
665 WATCHDOG_RESET();
666
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000667 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
668 memcpy(fb, bmap, BMP_LOGO_WIDTH);
wdenk8655b6f2004-10-09 23:25:58 +0000669 bmap += BMP_LOGO_WIDTH;
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000670 fb += panel_info.vl_col;
wdenk8655b6f2004-10-09 23:25:58 +0000671 }
672 }
673 else { /* true color mode */
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100674 u16 col16;
Andre Renaud317461c2013-02-13 17:48:00 +0000675 fb16 = (ushort *)fb;
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000676 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
677 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100678 col16 = bmp_logo_palette[(bmap[j]-16)];
679 fb16[j] =
680 ((col16 & 0x000F) << 1) |
681 ((col16 & 0x00F0) << 3) |
682 ((col16 & 0x0F00) << 4);
wdenk8655b6f2004-10-09 23:25:58 +0000683 }
684 bmap += BMP_LOGO_WIDTH;
685 fb16 += panel_info.vl_col;
686 }
687 }
688
689 WATCHDOG_RESET();
Simon Glass9a8efc42012-10-30 13:40:18 +0000690 lcd_sync();
wdenk8655b6f2004-10-09 23:25:58 +0000691}
Anatolij Gustschin2b5cb3d2012-04-27 04:41:27 +0000692#else
693static inline void bitmap_plot(int x, int y) {}
wdenk8655b6f2004-10-09 23:25:58 +0000694#endif /* CONFIG_LCD_LOGO */
695
696/*----------------------------------------------------------------------*/
Jon Loeligerc3517f92007-07-08 18:10:08 -0500697#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk8655b6f2004-10-09 23:25:58 +0000698/*
699 * Display the BMP file located at address bmp_image.
700 * Only uncompressed.
701 */
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200702
703#ifdef CONFIG_SPLASH_SCREEN_ALIGN
704#define BMP_ALIGN_CENTER 0x7FFF
Nikita Kiryanov7c7e2802012-08-09 00:14:51 +0000705
706static void splash_align_axis(int *axis, unsigned long panel_size,
707 unsigned long picture_size)
708{
709 unsigned long panel_picture_delta = panel_size - picture_size;
710 unsigned long axis_alignment;
711
712 if (*axis == BMP_ALIGN_CENTER)
713 axis_alignment = panel_picture_delta / 2;
714 else if (*axis < 0)
715 axis_alignment = panel_picture_delta + *axis + 1;
716 else
717 return;
718
719 *axis = max(0, axis_alignment);
720}
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200721#endif
722
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000723
724#ifdef CONFIG_LCD_BMP_RLE8
725
726#define BMP_RLE8_ESCAPE 0
727#define BMP_RLE8_EOL 0
728#define BMP_RLE8_EOBMP 1
729#define BMP_RLE8_DELTA 2
730
731static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
732 int cnt)
733{
734 while (cnt > 0) {
735 *(*fbp)++ = cmap[*bmap++];
736 cnt--;
737 }
738}
739
740static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
741{
742 ushort *fb = *fbp;
743 int cnt_8copy = cnt >> 3;
744
745 cnt -= cnt_8copy << 3;
746 while (cnt_8copy > 0) {
747 *fb++ = c;
748 *fb++ = c;
749 *fb++ = c;
750 *fb++ = c;
751 *fb++ = c;
752 *fb++ = c;
753 *fb++ = c;
754 *fb++ = c;
755 cnt_8copy--;
756 }
757 while (cnt > 0) {
758 *fb++ = c;
759 cnt--;
760 }
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000761 *fbp = fb;
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000762}
763
764/*
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000765 * Do not call this function directly, must be called from lcd_display_bitmap.
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000766 */
767static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
768 int x_off, int y_off)
769{
770 uchar *bmap;
771 ulong width, height;
772 ulong cnt, runlen;
773 int x, y;
774 int decode = 1;
775
776 width = le32_to_cpu(bmp->header.width);
777 height = le32_to_cpu(bmp->header.height);
778 bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset);
779
780 x = 0;
781 y = height - 1;
782
783 while (decode) {
784 if (bmap[0] == BMP_RLE8_ESCAPE) {
785 switch (bmap[1]) {
786 case BMP_RLE8_EOL:
787 /* end of line */
788 bmap += 2;
789 x = 0;
790 y--;
791 /* 16bpix, 2-byte per pixel, width should *2 */
792 fb -= (width * 2 + lcd_line_length);
793 break;
794 case BMP_RLE8_EOBMP:
795 /* end of bitmap */
796 decode = 0;
797 break;
798 case BMP_RLE8_DELTA:
799 /* delta run */
800 x += bmap[2];
801 y -= bmap[3];
802 /* 16bpix, 2-byte per pixel, x should *2 */
803 fb = (uchar *) (lcd_base + (y + y_off - 1)
804 * lcd_line_length + (x + x_off) * 2);
805 bmap += 4;
806 break;
807 default:
808 /* unencoded run */
809 runlen = bmap[1];
810 bmap += 2;
811 if (y < height) {
812 if (x < width) {
813 if (x + runlen > width)
814 cnt = width - x;
815 else
816 cnt = runlen;
817 draw_unencoded_bitmap(
818 (ushort **)&fb,
819 bmap, cmap, cnt);
820 }
821 x += runlen;
822 }
823 bmap += runlen;
824 if (runlen & 1)
825 bmap++;
826 }
827 } else {
828 /* encoded run */
829 if (y < height) {
830 runlen = bmap[0];
831 if (x < width) {
832 /* aggregate the same code */
833 while (bmap[0] == 0xff &&
834 bmap[2] != BMP_RLE8_ESCAPE &&
835 bmap[1] == bmap[3]) {
836 runlen += bmap[2];
837 bmap += 2;
838 }
839 if (x + runlen > width)
840 cnt = width - x;
841 else
842 cnt = runlen;
843 draw_encoded_bitmap((ushort **)&fb,
844 cmap[bmap[1]], cnt);
845 }
846 x += runlen;
847 }
848 bmap += 2;
849 }
850 }
851}
852#endif
853
Anatolij Gustschind23019f2012-09-22 06:55:53 +0000854#if defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +0000855#define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
Anatolij Gustschind23019f2012-09-22 06:55:53 +0000856#else
857#define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +0000858#endif
859
860#if defined(CONFIG_BMP_16BPP)
861#if defined(CONFIG_ATMEL_LCD_BGR555)
862static inline void fb_put_word(uchar **fb, uchar **from)
863{
864 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
865 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
866 *from += 2;
867}
868#else
869static inline void fb_put_word(uchar **fb, uchar **from)
870{
871 *(*fb)++ = *(*from)++;
872 *(*fb)++ = *(*from)++;
873}
874#endif
875#endif /* CONFIG_BMP_16BPP */
876
wdenk8655b6f2004-10-09 23:25:58 +0000877int lcd_display_bitmap(ulong bmp_image, int x, int y)
878{
Anatolij Gustschin00cc5592009-02-25 20:28:13 +0100879#if !defined(CONFIG_MCC200)
880 ushort *cmap = NULL;
881#endif
882 ushort *cmap_base = NULL;
wdenk8655b6f2004-10-09 23:25:58 +0000883 ushort i, j;
884 uchar *fb;
885 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
886 uchar *bmap;
Tom Wai-Hong Tamfecac462012-09-28 15:11:14 +0000887 ushort padded_width;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100888 unsigned long width, height, byte_width;
Wolfgang Denke8143e72006-08-30 23:09:00 +0200889 unsigned long pwidth = panel_info.vl_col;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100890 unsigned colors, bpix, bmp_bpix;
wdenk8655b6f2004-10-09 23:25:58 +0000891
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000892 if (!bmp || !(bmp->header.signature[0] == 'B' &&
893 bmp->header.signature[1] == 'M')) {
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000894 printf("Error: no valid bmp image at %lx\n", bmp_image);
895
wdenk8655b6f2004-10-09 23:25:58 +0000896 return 1;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100897 }
wdenk8655b6f2004-10-09 23:25:58 +0000898
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000899 width = le32_to_cpu(bmp->header.width);
900 height = le32_to_cpu(bmp->header.height);
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100901 bmp_bpix = le16_to_cpu(bmp->header.bit_count);
902 colors = 1 << bmp_bpix;
wdenk8655b6f2004-10-09 23:25:58 +0000903
904 bpix = NBITS(panel_info.vl_bpix);
905
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000906 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100907 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
908 bpix, bmp_bpix);
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000909
wdenk8655b6f2004-10-09 23:25:58 +0000910 return 1;
911 }
912
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100913 /* We support displaying 8bpp BMPs on 16bpp LCDs */
Nikita Kiryanovdad631c2012-12-20 00:52:34 +0000914 if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) {
wdenk8655b6f2004-10-09 23:25:58 +0000915 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
916 bpix,
917 le16_to_cpu(bmp->header.bit_count));
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000918
wdenk8655b6f2004-10-09 23:25:58 +0000919 return 1;
920 }
921
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000922 debug("Display-bmp: %d x %d with %d colors\n",
wdenk8655b6f2004-10-09 23:25:58 +0000923 (int)width, (int)height, (int)colors);
924
Wolfgang Denkf6414712006-10-20 15:51:21 +0200925#if !defined(CONFIG_MCC200)
926 /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100927 if (bmp_bpix == 8) {
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000928 cmap = configuration_get_cmap();
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100929 cmap_base = cmap;
930
wdenk8655b6f2004-10-09 23:25:58 +0000931 /* Set color map */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000932 for (i = 0; i < colors; ++i) {
wdenk8655b6f2004-10-09 23:25:58 +0000933 bmp_color_table_entry_t cte = bmp->color_table[i];
Mark Jackson1464eff2008-08-01 09:48:29 +0100934#if !defined(CONFIG_ATMEL_LCD)
wdenk8655b6f2004-10-09 23:25:58 +0000935 ushort colreg =
936 ( ((cte.red) << 8) & 0xf800) |
Wolfgang Denk59d80bf2005-09-21 15:24:52 +0200937 ( ((cte.green) << 3) & 0x07e0) |
938 ( ((cte.blue) >> 3) & 0x001f) ;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200939#ifdef CONFIG_SYS_INVERT_COLORS
wdenk25d67122004-12-10 11:40:40 +0000940 *cmap = 0xffff - colreg;
wdenk8655b6f2004-10-09 23:25:58 +0000941#else
wdenk25d67122004-12-10 11:40:40 +0000942 *cmap = colreg;
943#endif
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100944#if defined(CONFIG_MPC823)
wdenk25d67122004-12-10 11:40:40 +0000945 cmap--;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100946#else
947 cmap++;
wdenk8655b6f2004-10-09 23:25:58 +0000948#endif
Mark Jackson1464eff2008-08-01 09:48:29 +0100949#else /* CONFIG_ATMEL_LCD */
950 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
951#endif
wdenk8655b6f2004-10-09 23:25:58 +0000952 }
953 }
Wolfgang Denkf6414712006-10-20 15:51:21 +0200954#endif
wdenk8655b6f2004-10-09 23:25:58 +0000955
Wolfgang Denke8143e72006-08-30 23:09:00 +0200956 /*
957 * BMP format for Monochrome assumes that the state of a
958 * pixel is described on a per Bit basis, not per Byte.
959 * So, in case of Monochrome BMP we should align widths
960 * on a byte boundary and convert them from Bit to Byte
961 * units.
Wolfgang Denk511d0c72006-10-09 00:42:01 +0200962 * Probably, PXA250 and MPC823 process 1bpp BMP images in
963 * their own ways, so make the converting to be MCC200
Wolfgang Denke8143e72006-08-30 23:09:00 +0200964 * specific.
965 */
966#if defined(CONFIG_MCC200)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000967 if (bpix == 1) {
Wolfgang Denke8143e72006-08-30 23:09:00 +0200968 width = ((width + 7) & ~7) >> 3;
969 x = ((x + 7) & ~7) >> 3;
970 pwidth= ((pwidth + 7) & ~7) >> 3;
971 }
972#endif
973
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000974 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200975
976#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Nikita Kiryanov7c7e2802012-08-09 00:14:51 +0000977 splash_align_axis(&x, pwidth, width);
978 splash_align_axis(&y, panel_info.vl_row, height);
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200979#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
980
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000981 if ((x + width) > pwidth)
Wolfgang Denke8143e72006-08-30 23:09:00 +0200982 width = pwidth - x;
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000983 if ((y + height) > panel_info.vl_row)
wdenk8655b6f2004-10-09 23:25:58 +0000984 height = panel_info.vl_row - y;
985
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000986 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk8655b6f2004-10-09 23:25:58 +0000987 fb = (uchar *) (lcd_base +
Liu Ying8d46d5b2011-01-11 15:29:58 +0800988 (y + height - 1) * lcd_line_length + x * bpix / 8);
Mark Jacksona303dfb2009-02-06 10:37:49 +0100989
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100990 switch (bmp_bpix) {
Mark Jacksona303dfb2009-02-06 10:37:49 +0100991 case 1: /* pass through */
992 case 8:
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000993#ifdef CONFIG_LCD_BMP_RLE8
994 if (le32_to_cpu(bmp->header.compression) == BMP_BI_RLE8) {
995 if (bpix != 16) {
996 /* TODO implement render code for bpix != 16 */
997 printf("Error: only support 16 bpix");
998 return 1;
999 }
1000 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
1001 break;
1002 }
1003#endif
1004
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +01001005 if (bpix != 16)
1006 byte_width = width;
1007 else
1008 byte_width = width * 2;
1009
Mark Jacksona303dfb2009-02-06 10:37:49 +01001010 for (i = 0; i < height; ++i) {
1011 WATCHDOG_RESET();
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +01001012 for (j = 0; j < width; j++) {
1013 if (bpix != 16) {
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +00001014 FB_PUT_BYTE(fb, bmap);
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +01001015 } else {
1016 *(uint16_t *)fb = cmap_base[*(bmap++)];
1017 fb += sizeof(uint16_t) / sizeof(*fb);
1018 }
1019 }
Tom Wai-Hong Tamfecac462012-09-28 15:11:14 +00001020 bmap += (padded_width - width);
Jeroen Hofstee6b035142013-01-12 12:07:56 +00001021 fb -= byte_width + lcd_line_length;
Mark Jacksona303dfb2009-02-06 10:37:49 +01001022 }
1023 break;
1024
1025#if defined(CONFIG_BMP_16BPP)
1026 case 16:
1027 for (i = 0; i < height; ++i) {
1028 WATCHDOG_RESET();
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +00001029 for (j = 0; j < width; j++)
1030 fb_put_word(&fb, &bmap);
1031
Tom Wai-Hong Tamfecac462012-09-28 15:11:14 +00001032 bmap += (padded_width - width) * 2;
Jeroen Hofstee6b035142013-01-12 12:07:56 +00001033 fb -= width * 2 + lcd_line_length;
Mark Jacksona303dfb2009-02-06 10:37:49 +01001034 }
1035 break;
1036#endif /* CONFIG_BMP_16BPP */
1037
Donghwa Leefb6a9aa2012-05-09 19:23:37 +00001038#if defined(CONFIG_BMP_32BPP)
1039 case 32:
1040 for (i = 0; i < height; ++i) {
1041 for (j = 0; j < width; j++) {
1042 *(fb++) = *(bmap++);
1043 *(fb++) = *(bmap++);
1044 *(fb++) = *(bmap++);
1045 *(fb++) = *(bmap++);
1046 }
Jeroen Hofstee6b035142013-01-12 12:07:56 +00001047 fb -= lcd_line_length + width * (bpix / 8);
Donghwa Leefb6a9aa2012-05-09 19:23:37 +00001048 }
1049 break;
1050#endif /* CONFIG_BMP_32BPP */
Mark Jacksona303dfb2009-02-06 10:37:49 +01001051 default:
1052 break;
1053 };
wdenk8655b6f2004-10-09 23:25:58 +00001054
Simon Glass9a8efc42012-10-30 13:40:18 +00001055 lcd_sync();
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001056 return 0;
wdenk8655b6f2004-10-09 23:25:58 +00001057}
Jon Loeligerc3517f92007-07-08 18:10:08 -05001058#endif
wdenk8655b6f2004-10-09 23:25:58 +00001059
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001060static void *lcd_logo(void)
wdenk8655b6f2004-10-09 23:25:58 +00001061{
wdenk8655b6f2004-10-09 23:25:58 +00001062#ifdef CONFIG_SPLASH_SCREEN
1063 char *s;
1064 ulong addr;
1065 static int do_splash = 1;
1066
1067 if (do_splash && (s = getenv("splashimage")) != NULL) {
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001068 int x = 0, y = 0;
wdenk8655b6f2004-10-09 23:25:58 +00001069 do_splash = 0;
1070
Nikita Kiryanov581bb412013-01-30 21:39:57 +00001071 if (splash_screen_prepare())
Robert Winklerdd4425e2013-06-17 11:31:29 -07001072 return (void *)lcd_base;
Nikita Kiryanov581bb412013-01-30 21:39:57 +00001073
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001074 addr = simple_strtoul (s, NULL, 16);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001075
Anatolij Gustschinff8fb562013-07-02 00:04:05 +02001076 splash_get_pos(&x, &y);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001077
Nikita Kiryanovd3a555e2012-08-09 00:14:50 +00001078 if (bmp_display(addr, x, y) == 0)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001079 return (void *)lcd_base;
wdenk8655b6f2004-10-09 23:25:58 +00001080 }
1081#endif /* CONFIG_SPLASH_SCREEN */
1082
Anatolij Gustschin2b5cb3d2012-04-27 04:41:27 +00001083 bitmap_plot(0, 0);
wdenk8655b6f2004-10-09 23:25:58 +00001084
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +02001085#ifdef CONFIG_LCD_INFO
1086 console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
1087 console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
1088 lcd_show_board_info();
1089#endif /* CONFIG_LCD_INFO */
Stelian Pop39cf4802008-05-09 21:57:18 +02001090
wdenk88804d12005-07-04 00:03:16 +00001091#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001092 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
wdenk8655b6f2004-10-09 23:25:58 +00001093#else
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001094 return (void *)lcd_base;
Jeroen Hofstee6b035142013-01-12 12:07:56 +00001095#endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
wdenk8655b6f2004-10-09 23:25:58 +00001096}
1097
Nikita Kiryanovc0880482013-02-24 21:28:43 +00001098#ifdef CONFIG_SPLASHIMAGE_GUARD
1099static int on_splashimage(const char *name, const char *value, enum env_op op,
1100 int flags)
1101{
1102 ulong addr;
1103 int aligned;
1104
1105 if (op == env_op_delete)
1106 return 0;
1107
1108 addr = simple_strtoul(value, NULL, 16);
1109 /* See README.displaying-bmps */
1110 aligned = (addr % 4 == 2);
1111 if (!aligned) {
1112 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1113 return -1;
1114 }
1115
1116 return 0;
1117}
1118
1119U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1120#endif
1121
Vadim Bendebury395166c2012-09-28 15:11:13 +00001122void lcd_position_cursor(unsigned col, unsigned row)
1123{
1124 console_col = min(col, CONSOLE_COLS - 1);
1125 console_row = min(row, CONSOLE_ROWS - 1);
1126}
1127
1128int lcd_get_pixel_width(void)
1129{
1130 return panel_info.vl_col;
1131}
1132
1133int lcd_get_pixel_height(void)
1134{
1135 return panel_info.vl_row;
1136}
1137
1138int lcd_get_screen_rows(void)
1139{
1140 return CONSOLE_ROWS;
1141}
1142
1143int lcd_get_screen_columns(void)
1144{
1145 return CONSOLE_COLS;
1146}
Stephen Warren6a195d22013-05-27 18:31:17 +00001147
1148#if defined(CONFIG_LCD_DT_SIMPLEFB)
1149static int lcd_dt_simplefb_configure_node(void *blob, int off)
1150{
1151 u32 stride;
1152 fdt32_t cells[2];
1153 int ret;
Stephen Warren5af7d0f2013-06-13 17:13:11 -06001154 static const char format[] =
Stephen Warren6a195d22013-05-27 18:31:17 +00001155#if LCD_BPP == LCD_COLOR16
1156 "r5g6b5";
1157#else
1158 "";
1159#endif
1160
1161 if (!format[0])
1162 return -1;
1163
1164 stride = panel_info.vl_col * 2;
1165
1166 cells[0] = cpu_to_fdt32(gd->fb_base);
1167 cells[1] = cpu_to_fdt32(stride * panel_info.vl_row);
1168 ret = fdt_setprop(blob, off, "reg", cells, sizeof(cells[0]) * 2);
1169 if (ret < 0)
1170 return -1;
1171
1172 cells[0] = cpu_to_fdt32(panel_info.vl_col);
1173 ret = fdt_setprop(blob, off, "width", cells, sizeof(cells[0]));
1174 if (ret < 0)
1175 return -1;
1176
1177 cells[0] = cpu_to_fdt32(panel_info.vl_row);
1178 ret = fdt_setprop(blob, off, "height", cells, sizeof(cells[0]));
1179 if (ret < 0)
1180 return -1;
1181
1182 cells[0] = cpu_to_fdt32(stride);
1183 ret = fdt_setprop(blob, off, "stride", cells, sizeof(cells[0]));
1184 if (ret < 0)
1185 return -1;
1186
1187 ret = fdt_setprop(blob, off, "format", format, strlen(format) + 1);
1188 if (ret < 0)
1189 return -1;
1190
1191 ret = fdt_delprop(blob, off, "status");
1192 if (ret < 0)
1193 return -1;
1194
1195 return 0;
1196}
1197
1198int lcd_dt_simplefb_add_node(void *blob)
1199{
Stephen Warren5af7d0f2013-06-13 17:13:11 -06001200 static const char compat[] = "simple-framebuffer";
1201 static const char disabled[] = "disabled";
Stephen Warren6a195d22013-05-27 18:31:17 +00001202 int off, ret;
1203
1204 off = fdt_add_subnode(blob, 0, "framebuffer");
1205 if (off < 0)
1206 return -1;
1207
1208 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
1209 if (ret < 0)
1210 return -1;
1211
1212 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
1213 if (ret < 0)
1214 return -1;
1215
1216 return lcd_dt_simplefb_configure_node(blob, off);
1217}
1218
1219int lcd_dt_simplefb_enable_existing_node(void *blob)
1220{
1221 int off;
1222
1223 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
1224 if (off < 0)
1225 return -1;
1226
1227 return lcd_dt_simplefb_configure_node(blob, off);
1228}
1229#endif