blob: 19b86b7c55013abc621621aaf94f06fe095d63dc [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>
Przemyslaw Marczakdca2a1c2014-01-22 11:24:13 +010029#include <asm/unaligned.h>
Robert Winklerdd4425e2013-06-17 11:31:29 -070030#include <splash.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070031#include <asm/io.h>
32#include <asm/unaligned.h>
Robert Winklerdd4425e2013-06-17 11:31:29 -070033
Marek Vasutabc20ab2011-11-26 07:20:07 +010034#if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
35 defined(CONFIG_CPU_MONAHANS)
36#define CONFIG_CPU_PXA
wdenk8655b6f2004-10-09 23:25:58 +000037#include <asm/byteorder.h>
38#endif
39
40#if defined(CONFIG_MPC823)
wdenk8655b6f2004-10-09 23:25:58 +000041#include <lcdvideo.h>
42#endif
43
Stelian Pop39cf4802008-05-09 21:57:18 +020044#if defined(CONFIG_ATMEL_LCD)
45#include <atmel_lcdc.h>
Stelian Pop39cf4802008-05-09 21:57:18 +020046#endif
47
Stephen Warren6a195d22013-05-27 18:31:17 +000048#if defined(CONFIG_LCD_DT_SIMPLEFB)
49#include <libfdt.h>
50#endif
51
wdenk8655b6f2004-10-09 23:25:58 +000052/************************************************************************/
53/* ** FONT DATA */
54/************************************************************************/
55#include <video_font.h> /* Get font data, width and height */
56
wdenk88804d12005-07-04 00:03:16 +000057/************************************************************************/
58/* ** LOGO DATA */
59/************************************************************************/
60#ifdef CONFIG_LCD_LOGO
61# include <bmp_logo.h> /* Get logo data, width and height */
Che-Liang Chiouc2707302011-10-20 23:04:20 +000062# include <bmp_logo_data.h>
Alessandro Rubiniacb13862010-03-13 17:44:08 +010063# if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
wdenk88804d12005-07-04 00:03:16 +000064# error Default Color Map overlaps with Logo Color Map
65# endif
66#endif
wdenk8655b6f2004-10-09 23:25:58 +000067
Simon Glass7d95f2a2014-02-27 13:26:19 -070068#ifdef CONFIG_SANDBOX
69#include <asm/sdl.h>
70#endif
71
Simon Glass676d3192012-10-17 13:24:54 +000072#ifndef CONFIG_LCD_ALIGNMENT
73#define CONFIG_LCD_ALIGNMENT PAGE_SIZE
74#endif
75
Simon Glass0d89efe2012-10-17 13:24:59 +000076/* By default we scroll by a single line */
77#ifndef CONFIG_CONSOLE_SCROLL_LINES
78#define CONFIG_CONSOLE_SCROLL_LINES 1
79#endif
80
Jeroen Hofsteea5796c52013-01-12 12:07:59 +000081/************************************************************************/
82/* ** CONSOLE DEFINITIONS & FUNCTIONS */
83/************************************************************************/
84#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
85# define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
86 / VIDEO_FONT_HEIGHT)
87#else
88# define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
89#endif
Wolfgang Denkd87080b2006-03-31 18:32:53 +020090
Jeroen Hofsteea5796c52013-01-12 12:07:59 +000091#define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
92#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
93#define CONSOLE_ROW_FIRST lcd_console_address
94#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
95#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
96 - CONSOLE_ROW_SIZE)
97#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
98#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
99
100#if LCD_BPP == LCD_MONOCHROME
101# define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
102 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
103#elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16)
104# define COLOR_MASK(c) (c)
105#else
106# error Unsupported LCD BPP.
107#endif
108
wdenk8655b6f2004-10-09 23:25:58 +0000109DECLARE_GLOBAL_DATA_PTR;
wdenk8655b6f2004-10-09 23:25:58 +0000110
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000111static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
112static inline void lcd_puts_xy(ushort x, ushort y, uchar *s);
113static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
wdenk8655b6f2004-10-09 23:25:58 +0000114
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000115static int lcd_init(void *lcdbase);
wdenk8655b6f2004-10-09 23:25:58 +0000116
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000117static void *lcd_logo(void);
wdenk8655b6f2004-10-09 23:25:58 +0000118
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000119static int lcd_getbgcolor(void);
120static void lcd_setfgcolor(int color);
121static void lcd_setbgcolor(int color);
wdenk8655b6f2004-10-09 23:25:58 +0000122
Wolfgang Denk46d1d5d2013-01-05 09:45:48 +0000123static int lcd_color_fg;
124static int lcd_color_bg;
Jeroen Hofsteef1d205a2013-01-22 10:44:11 +0000125int lcd_line_length;
Wolfgang Denk46d1d5d2013-01-05 09:45:48 +0000126
wdenk8655b6f2004-10-09 23:25:58 +0000127char lcd_is_enabled = 0;
wdenk8655b6f2004-10-09 23:25:58 +0000128
Jeroen Hofsteef1d205a2013-01-22 10:44:11 +0000129static short console_col;
130static short console_row;
131
132static void *lcd_console_address;
Jeroen Hofstee00a0ca52013-01-22 10:44:12 +0000133static void *lcd_base; /* Start of framebuffer memory */
Jeroen Hofsteef1d205a2013-01-22 10:44:11 +0000134
Simon Glass9a8efc42012-10-30 13:40:18 +0000135static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
136
wdenk8655b6f2004-10-09 23:25:58 +0000137/************************************************************************/
138
Simon Glass9a8efc42012-10-30 13:40:18 +0000139/* Flush LCD activity to the caches */
140void lcd_sync(void)
141{
142 /*
143 * flush_dcache_range() is declared in common.h but it seems that some
144 * architectures do not actually implement it. Is there a way to find
145 * out whether it exists? For now, ARM is safe.
146 */
147#if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
148 int line_length;
149
150 if (lcd_flush_dcache)
151 flush_dcache_range((u32)lcd_base,
152 (u32)(lcd_base + lcd_get_size(&line_length)));
Simon Glass7d95f2a2014-02-27 13:26:19 -0700153#elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
154 static ulong last_sync;
155
156 if (get_timer(last_sync) > 10) {
157 sandbox_sdl_sync(lcd_base);
158 last_sync = get_timer(0);
159 }
Simon Glass9a8efc42012-10-30 13:40:18 +0000160#endif
161}
162
163void lcd_set_flush_dcache(int flush)
164{
165 lcd_flush_dcache = (flush != 0);
166}
167
wdenk8655b6f2004-10-09 23:25:58 +0000168/*----------------------------------------------------------------------*/
169
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000170static void console_scrollup(void)
wdenk8655b6f2004-10-09 23:25:58 +0000171{
Simon Glass0d89efe2012-10-17 13:24:59 +0000172 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
wdenk8655b6f2004-10-09 23:25:58 +0000173
Simon Glass0d89efe2012-10-17 13:24:59 +0000174 /* Copy up rows ignoring those that will be overwritten */
175 memcpy(CONSOLE_ROW_FIRST,
176 lcd_console_address + CONSOLE_ROW_SIZE * rows,
177 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
178
179 /* Clear the last rows */
180 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
181 COLOR_MASK(lcd_color_bg),
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000182 CONSOLE_ROW_SIZE * rows);
Simon Glass0d89efe2012-10-17 13:24:59 +0000183
Simon Glass9a8efc42012-10-30 13:40:18 +0000184 lcd_sync();
Simon Glass0d89efe2012-10-17 13:24:59 +0000185 console_row -= rows;
wdenk8655b6f2004-10-09 23:25:58 +0000186}
187
188/*----------------------------------------------------------------------*/
189
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000190static inline void console_back(void)
wdenk8655b6f2004-10-09 23:25:58 +0000191{
192 if (--console_col < 0) {
193 console_col = CONSOLE_COLS-1 ;
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000194 if (--console_row < 0)
wdenk8655b6f2004-10-09 23:25:58 +0000195 console_row = 0;
wdenk8655b6f2004-10-09 23:25:58 +0000196 }
197
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000198 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
199 console_row * VIDEO_FONT_HEIGHT, ' ');
wdenk8655b6f2004-10-09 23:25:58 +0000200}
201
202/*----------------------------------------------------------------------*/
203
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000204static inline void console_newline(void)
wdenk8655b6f2004-10-09 23:25:58 +0000205{
wdenk8655b6f2004-10-09 23:25:58 +0000206 console_col = 0;
207
208 /* Check if we need to scroll the terminal */
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000209 if (++console_row >= CONSOLE_ROWS)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000210 console_scrollup();
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000211 else
Simon Glass9a8efc42012-10-30 13:40:18 +0000212 lcd_sync();
wdenk8655b6f2004-10-09 23:25:58 +0000213}
214
215/*----------------------------------------------------------------------*/
216
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000217void lcd_putc(const char c)
wdenk8655b6f2004-10-09 23:25:58 +0000218{
219 if (!lcd_is_enabled) {
220 serial_putc(c);
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000221
wdenk8655b6f2004-10-09 23:25:58 +0000222 return;
223 }
224
225 switch (c) {
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000226 case '\r':
227 console_col = 0;
wdenk8655b6f2004-10-09 23:25:58 +0000228
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000229 return;
230 case '\n':
231 console_newline();
wdenk8655b6f2004-10-09 23:25:58 +0000232
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000233 return;
wdenk8655b6f2004-10-09 23:25:58 +0000234 case '\t': /* Tab (8 chars alignment) */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000235 console_col += 8;
236 console_col &= ~7;
wdenk8655b6f2004-10-09 23:25:58 +0000237
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000238 if (console_col >= CONSOLE_COLS)
239 console_newline();
wdenk8655b6f2004-10-09 23:25:58 +0000240
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000241 return;
242 case '\b':
243 console_back();
wdenk8655b6f2004-10-09 23:25:58 +0000244
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000245 return;
246 default:
247 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
248 console_row * VIDEO_FONT_HEIGHT, c);
249 if (++console_col >= CONSOLE_COLS)
250 console_newline();
wdenk8655b6f2004-10-09 23:25:58 +0000251 }
wdenk8655b6f2004-10-09 23:25:58 +0000252}
253
254/*----------------------------------------------------------------------*/
255
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000256void lcd_puts(const char *s)
wdenk8655b6f2004-10-09 23:25:58 +0000257{
258 if (!lcd_is_enabled) {
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000259 serial_puts(s);
260
wdenk8655b6f2004-10-09 23:25:58 +0000261 return;
262 }
263
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000264 while (*s)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000265 lcd_putc(*s++);
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000266
Simon Glass9a8efc42012-10-30 13:40:18 +0000267 lcd_sync();
wdenk8655b6f2004-10-09 23:25:58 +0000268}
269
Haavard Skinnemoen15b17ab2008-09-01 16:21:20 +0200270/*----------------------------------------------------------------------*/
271
272void lcd_printf(const char *fmt, ...)
273{
274 va_list args;
275 char buf[CONFIG_SYS_PBSIZE];
276
277 va_start(args, fmt);
278 vsprintf(buf, fmt, args);
279 va_end(args);
280
281 lcd_puts(buf);
282}
283
wdenk8655b6f2004-10-09 23:25:58 +0000284/************************************************************************/
285/* ** Low-Level Graphics Routines */
286/************************************************************************/
287
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000288static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
wdenk8655b6f2004-10-09 23:25:58 +0000289{
290 uchar *dest;
Marek Vasutbe547c62011-09-26 02:26:04 +0200291 ushort row;
292
Anatolij Gustschin0f999c42012-04-27 04:41:16 +0000293#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
294 y += BMP_LOGO_HEIGHT;
295#endif
296
Marek Vasutbe547c62011-09-26 02:26:04 +0200297#if LCD_BPP == LCD_MONOCHROME
298 ushort off = x * (1 << LCD_BPP) % 8;
299#endif
wdenk8655b6f2004-10-09 23:25:58 +0000300
301 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
wdenk8655b6f2004-10-09 23:25:58 +0000302
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000303 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
wdenk8655b6f2004-10-09 23:25:58 +0000304 uchar *s = str;
wdenk8655b6f2004-10-09 23:25:58 +0000305 int i;
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100306#if LCD_BPP == LCD_COLOR16
307 ushort *d = (ushort *)dest;
308#else
309 uchar *d = dest;
310#endif
wdenk8655b6f2004-10-09 23:25:58 +0000311
312#if LCD_BPP == LCD_MONOCHROME
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000313 uchar rest = *d & -(1 << (8 - off));
wdenk8655b6f2004-10-09 23:25:58 +0000314 uchar sym;
315#endif
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000316 for (i = 0; i < count; ++i) {
wdenk8655b6f2004-10-09 23:25:58 +0000317 uchar c, bits;
318
319 c = *s++;
320 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
321
322#if LCD_BPP == LCD_MONOCHROME
323 sym = (COLOR_MASK(lcd_color_fg) & bits) |
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000324 (COLOR_MASK(lcd_color_bg) & ~bits);
wdenk8655b6f2004-10-09 23:25:58 +0000325
326 *d++ = rest | (sym >> off);
327 rest = sym << (8-off);
328#elif LCD_BPP == LCD_COLOR8
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000329 for (c = 0; c < 8; ++c) {
wdenk8655b6f2004-10-09 23:25:58 +0000330 *d++ = (bits & 0x80) ?
331 lcd_color_fg : lcd_color_bg;
332 bits <<= 1;
333 }
334#elif LCD_BPP == LCD_COLOR16
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000335 for (c = 0; c < 8; ++c) {
wdenk8655b6f2004-10-09 23:25:58 +0000336 *d++ = (bits & 0x80) ?
337 lcd_color_fg : lcd_color_bg;
338 bits <<= 1;
339 }
340#endif
341 }
342#if LCD_BPP == LCD_MONOCHROME
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000343 *d = rest | (*d & ((1 << (8 - off)) - 1));
wdenk8655b6f2004-10-09 23:25:58 +0000344#endif
345 }
346}
347
348/*----------------------------------------------------------------------*/
349
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000350static inline void lcd_puts_xy(ushort x, ushort y, uchar *s)
wdenk8655b6f2004-10-09 23:25:58 +0000351{
Anatolij Gustschin0f999c42012-04-27 04:41:16 +0000352 lcd_drawchars(x, y, s, strlen((char *)s));
wdenk8655b6f2004-10-09 23:25:58 +0000353}
354
355/*----------------------------------------------------------------------*/
356
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000357static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
wdenk8655b6f2004-10-09 23:25:58 +0000358{
Anatolij Gustschin0f999c42012-04-27 04:41:16 +0000359 lcd_drawchars(x, y, &c, 1);
wdenk8655b6f2004-10-09 23:25:58 +0000360}
361
362/************************************************************************/
363/** Small utility to check that you got the colours right */
364/************************************************************************/
365#ifdef LCD_TEST_PATTERN
366
367#define N_BLK_VERT 2
368#define N_BLK_HOR 3
369
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000370static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
wdenk8655b6f2004-10-09 23:25:58 +0000371 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
372 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
373};
374
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000375static void test_pattern(void)
wdenk8655b6f2004-10-09 23:25:58 +0000376{
377 ushort v_max = panel_info.vl_row;
378 ushort h_max = panel_info.vl_col;
379 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
380 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
381 ushort v, h;
382 uchar *pix = (uchar *)lcd_base;
383
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000384 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
wdenk8655b6f2004-10-09 23:25:58 +0000385 h_max, v_max, h_step, v_step);
386
387 /* WARNING: Code silently assumes 8bit/pixel */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000388 for (v = 0; v < v_max; ++v) {
wdenk8655b6f2004-10-09 23:25:58 +0000389 uchar iy = v / v_step;
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000390 for (h = 0; h < h_max; ++h) {
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000391 uchar ix = N_BLK_HOR * iy + h / h_step;
wdenk8655b6f2004-10-09 23:25:58 +0000392 *pix++ = test_colors[ix];
393 }
394 }
395}
396#endif /* LCD_TEST_PATTERN */
397
398
399/************************************************************************/
400/* ** GENERIC Initialization Routines */
401/************************************************************************/
Anatolij Gustschincefa4712013-11-09 11:00:09 +0100402/*
403 * With most lcd drivers the line length is set up
404 * by calculating it from panel_info parameters. Some
405 * drivers need to calculate the line length differently,
406 * so make the function weak to allow overriding it.
407 */
408__weak int lcd_get_size(int *line_length)
Simon Glass676d3192012-10-17 13:24:54 +0000409{
410 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
411 return *line_length * panel_info.vl_row;
412}
413
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000414int drv_lcd_init(void)
wdenk8655b6f2004-10-09 23:25:58 +0000415{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200416 struct stdio_dev lcddev;
wdenk8655b6f2004-10-09 23:25:58 +0000417 int rc;
418
Simon Glass7d95f2a2014-02-27 13:26:19 -0700419 lcd_base = map_sysmem(gd->fb_base, 0);
wdenk8655b6f2004-10-09 23:25:58 +0000420
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000421 lcd_init(lcd_base); /* LCD initialization */
wdenk8655b6f2004-10-09 23:25:58 +0000422
423 /* Device initialization */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000424 memset(&lcddev, 0, sizeof(lcddev));
wdenk8655b6f2004-10-09 23:25:58 +0000425
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000426 strcpy(lcddev.name, "lcd");
wdenk8655b6f2004-10-09 23:25:58 +0000427 lcddev.ext = 0; /* No extensions */
428 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
429 lcddev.putc = lcd_putc; /* 'putc' function */
430 lcddev.puts = lcd_puts; /* 'puts' function */
431
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000432 rc = stdio_register(&lcddev);
wdenk8655b6f2004-10-09 23:25:58 +0000433
434 return (rc == 0) ? 1 : rc;
435}
436
437/*----------------------------------------------------------------------*/
Che-Liang Chiou02110902011-10-20 23:07:03 +0000438void lcd_clear(void)
wdenk8655b6f2004-10-09 23:25:58 +0000439{
440#if LCD_BPP == LCD_MONOCHROME
441 /* Setting the palette */
442 lcd_initcolregs();
443
444#elif LCD_BPP == LCD_COLOR8
445 /* Setting the palette */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000446 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
447 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
448 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
449 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
450 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
451 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
452 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
453 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
454 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
wdenk8655b6f2004-10-09 23:25:58 +0000455#endif
456
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200457#ifndef CONFIG_SYS_WHITE_ON_BLACK
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000458 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
459 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
wdenk8655b6f2004-10-09 23:25:58 +0000460#else
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000461 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
462 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200463#endif /* CONFIG_SYS_WHITE_ON_BLACK */
wdenk8655b6f2004-10-09 23:25:58 +0000464
465#ifdef LCD_TEST_PATTERN
466 test_pattern();
467#else
468 /* set framebuffer to background color */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000469 memset((char *)lcd_base,
wdenk8655b6f2004-10-09 23:25:58 +0000470 COLOR_MASK(lcd_getbgcolor()),
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000471 lcd_line_length * panel_info.vl_row);
wdenk8655b6f2004-10-09 23:25:58 +0000472#endif
473 /* Paint the logo and retrieve LCD base address */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000474 debug("[LCD] Drawing the logo...\n");
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000475 lcd_console_address = lcd_logo();
wdenk8655b6f2004-10-09 23:25:58 +0000476
477 console_col = 0;
478 console_row = 0;
Simon Glass9a8efc42012-10-30 13:40:18 +0000479 lcd_sync();
480}
481
482static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
483 char *const argv[])
484{
485 lcd_clear();
486 return 0;
wdenk8655b6f2004-10-09 23:25:58 +0000487}
488
489U_BOOT_CMD(
Che-Liang Chiou02110902011-10-20 23:07:03 +0000490 cls, 1, 1, do_lcd_clear,
Peter Tyser2fb26042009-01-27 18:03:12 -0600491 "clear screen",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200492 ""
wdenk8655b6f2004-10-09 23:25:58 +0000493);
494
495/*----------------------------------------------------------------------*/
496
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000497static int lcd_init(void *lcdbase)
wdenk8655b6f2004-10-09 23:25:58 +0000498{
499 /* Initialize the lcd controller */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000500 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
wdenk8655b6f2004-10-09 23:25:58 +0000501
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000502 lcd_ctrl_init(lcdbase);
Anatolij Gustschin1d3dea12013-03-29 14:00:13 +0100503
504 /*
505 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi_b) ignores
506 * the 'lcdbase' argument and uses custom lcd base address
507 * by setting up gd->fb_base. Check for this condition and fixup
508 * 'lcd_base' address.
509 */
Simon Glass7d95f2a2014-02-27 13:26:19 -0700510 if (map_to_sysmem(lcdbase) != gd->fb_base)
511 lcd_base = map_sysmem(gd->fb_base, 0);
Anatolij Gustschin1d3dea12013-03-29 14:00:13 +0100512
513 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
514
Stephen Warren6d330712013-01-29 16:37:38 +0000515 lcd_get_size(&lcd_line_length);
Haavard Skinnemoen6f93d2b2008-09-01 16:21:21 +0200516 lcd_is_enabled = 1;
Che-Liang Chiou02110902011-10-20 23:07:03 +0000517 lcd_clear();
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000518 lcd_enable();
wdenk8655b6f2004-10-09 23:25:58 +0000519
520 /* Initialize the console */
521 console_col = 0;
wdenk88804d12005-07-04 00:03:16 +0000522#ifdef CONFIG_LCD_INFO_BELOW_LOGO
wdenk8655b6f2004-10-09 23:25:58 +0000523 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
524#else
525 console_row = 1; /* leave 1 blank line below logo */
526#endif
wdenk8655b6f2004-10-09 23:25:58 +0000527
528 return 0;
529}
530
531
532/************************************************************************/
533/* ** ROM capable initialization part - needed to reserve FB memory */
534/************************************************************************/
535/*
536 * This is called early in the system initialization to grab memory
537 * for the LCD controller.
538 * Returns new address for monitor, after reserving LCD buffer memory
539 *
540 * Note that this is running from ROM, so no write access to global data.
541 */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000542ulong lcd_setmem(ulong addr)
wdenk8655b6f2004-10-09 23:25:58 +0000543{
544 ulong size;
Simon Glass676d3192012-10-17 13:24:54 +0000545 int line_length;
wdenk8655b6f2004-10-09 23:25:58 +0000546
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000547 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
548 panel_info.vl_row, NBITS(panel_info.vl_bpix));
wdenk8655b6f2004-10-09 23:25:58 +0000549
Simon Glass676d3192012-10-17 13:24:54 +0000550 size = lcd_get_size(&line_length);
wdenk8655b6f2004-10-09 23:25:58 +0000551
Simon Glass676d3192012-10-17 13:24:54 +0000552 /* Round up to nearest full page, or MMU section if defined */
553 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
554 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
wdenk8655b6f2004-10-09 23:25:58 +0000555
556 /* Allocate pages for the frame buffer. */
557 addr -= size;
558
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000559 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
560 size >> 10, addr);
wdenk8655b6f2004-10-09 23:25:58 +0000561
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000562 return addr;
wdenk8655b6f2004-10-09 23:25:58 +0000563}
564
565/*----------------------------------------------------------------------*/
566
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000567static void lcd_setfgcolor(int color)
wdenk8655b6f2004-10-09 23:25:58 +0000568{
Stelian Pop39cf4802008-05-09 21:57:18 +0200569 lcd_color_fg = color;
wdenk8655b6f2004-10-09 23:25:58 +0000570}
571
572/*----------------------------------------------------------------------*/
573
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000574static void lcd_setbgcolor(int color)
wdenk8655b6f2004-10-09 23:25:58 +0000575{
Stelian Pop39cf4802008-05-09 21:57:18 +0200576 lcd_color_bg = color;
wdenk8655b6f2004-10-09 23:25:58 +0000577}
578
579/*----------------------------------------------------------------------*/
580
Wolfgang Denk46d1d5d2013-01-05 09:45:48 +0000581int lcd_getfgcolor(void)
wdenk8655b6f2004-10-09 23:25:58 +0000582{
583 return lcd_color_fg;
584}
wdenk8655b6f2004-10-09 23:25:58 +0000585
586/*----------------------------------------------------------------------*/
587
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000588static int lcd_getbgcolor(void)
wdenk8655b6f2004-10-09 23:25:58 +0000589{
590 return lcd_color_bg;
591}
592
wdenk8655b6f2004-10-09 23:25:58 +0000593/************************************************************************/
594/* ** Chipset depending Bitmap / Logo stuff... */
595/************************************************************************/
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000596static inline ushort *configuration_get_cmap(void)
597{
598#if defined CONFIG_CPU_PXA
599 struct pxafb_info *fbi = &panel_info.pxa;
600 return (ushort *)fbi->palette;
601#elif defined(CONFIG_MPC823)
602 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
603 cpm8xx_t *cp = &(immr->im_cpm);
604 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
605#elif defined(CONFIG_ATMEL_LCD)
606 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
Anatolij Gustschind23019f2012-09-22 06:55:53 +0000607#elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
608 return panel_info.cmap;
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000609#elif defined(CONFIG_LCD_LOGO)
Anatolij Gustschind23019f2012-09-22 06:55:53 +0000610 return bmp_logo_palette;
611#else
612 return NULL;
613#endif
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000614}
615
wdenk8655b6f2004-10-09 23:25:58 +0000616#ifdef CONFIG_LCD_LOGO
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000617void bitmap_plot(int x, int y)
wdenk8655b6f2004-10-09 23:25:58 +0000618{
Stelian Pop39cf4802008-05-09 21:57:18 +0200619#ifdef CONFIG_ATMEL_LCD
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000620 uint *cmap = (uint *)bmp_logo_palette;
Stelian Pop39cf4802008-05-09 21:57:18 +0200621#else
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000622 ushort *cmap = (ushort *)bmp_logo_palette;
Stelian Pop39cf4802008-05-09 21:57:18 +0200623#endif
wdenk8655b6f2004-10-09 23:25:58 +0000624 ushort i, j;
625 uchar *bmap;
626 uchar *fb;
627 ushort *fb16;
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000628#if defined(CONFIG_MPC823)
629 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
630 cpm8xx_t *cp = &(immr->im_cpm);
wdenk8655b6f2004-10-09 23:25:58 +0000631#endif
Andre Renaud317461c2013-02-13 17:48:00 +0000632 unsigned bpix = NBITS(panel_info.vl_bpix);
wdenk8655b6f2004-10-09 23:25:58 +0000633
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000634 debug("Logo: width %d height %d colors %d cmap %d\n",
wdenk8655b6f2004-10-09 23:25:58 +0000635 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
Anatolij Gustschin095407d2012-04-27 04:41:06 +0000636 ARRAY_SIZE(bmp_logo_palette));
wdenk8655b6f2004-10-09 23:25:58 +0000637
638 bmap = &bmp_logo_bitmap[0];
Andre Renaud317461c2013-02-13 17:48:00 +0000639 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
wdenk8655b6f2004-10-09 23:25:58 +0000640
Andre Renaud317461c2013-02-13 17:48:00 +0000641 if (bpix < 12) {
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000642 /* Leave room for default color map
643 * default case: generic system with no cmap (most likely 16bpp)
644 * cmap was set to the source palette, so no change is done.
645 * This avoids even more ifdefs in the next stanza
646 */
647#if defined(CONFIG_MPC823)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000648 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
Stelian Pop39cf4802008-05-09 21:57:18 +0200649#elif defined(CONFIG_ATMEL_LCD)
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000650 cmap = (uint *)configuration_get_cmap();
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100651#else
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000652 cmap = configuration_get_cmap();
wdenk8655b6f2004-10-09 23:25:58 +0000653#endif
654
655 WATCHDOG_RESET();
656
657 /* Set color map */
Anatolij Gustschin095407d2012-04-27 04:41:06 +0000658 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
wdenk8655b6f2004-10-09 23:25:58 +0000659 ushort colreg = bmp_logo_palette[i];
Stelian Pop39cf4802008-05-09 21:57:18 +0200660#ifdef CONFIG_ATMEL_LCD
661 uint lut_entry;
662#ifdef CONFIG_ATMEL_LCD_BGR555
663 lut_entry = ((colreg & 0x000F) << 11) |
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000664 ((colreg & 0x00F0) << 2) |
665 ((colreg & 0x0F00) >> 7);
Stelian Pop39cf4802008-05-09 21:57:18 +0200666#else /* CONFIG_ATMEL_LCD_RGB565 */
667 lut_entry = ((colreg & 0x000F) << 1) |
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000668 ((colreg & 0x00F0) << 3) |
669 ((colreg & 0x0F00) << 4);
Stelian Pop39cf4802008-05-09 21:57:18 +0200670#endif
671 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
672 cmap++;
673#else /* !CONFIG_ATMEL_LCD */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200674#ifdef CONFIG_SYS_INVERT_COLORS
wdenk8655b6f2004-10-09 23:25:58 +0000675 *cmap++ = 0xffff - colreg;
676#else
677 *cmap++ = colreg;
678#endif
Stelian Pop39cf4802008-05-09 21:57:18 +0200679#endif /* CONFIG_ATMEL_LCD */
wdenk8655b6f2004-10-09 23:25:58 +0000680 }
681
682 WATCHDOG_RESET();
683
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000684 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
685 memcpy(fb, bmap, BMP_LOGO_WIDTH);
wdenk8655b6f2004-10-09 23:25:58 +0000686 bmap += BMP_LOGO_WIDTH;
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000687 fb += panel_info.vl_col;
wdenk8655b6f2004-10-09 23:25:58 +0000688 }
689 }
690 else { /* true color mode */
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100691 u16 col16;
Andre Renaud317461c2013-02-13 17:48:00 +0000692 fb16 = (ushort *)fb;
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000693 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
694 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100695 col16 = bmp_logo_palette[(bmap[j]-16)];
696 fb16[j] =
697 ((col16 & 0x000F) << 1) |
698 ((col16 & 0x00F0) << 3) |
699 ((col16 & 0x0F00) << 4);
wdenk8655b6f2004-10-09 23:25:58 +0000700 }
701 bmap += BMP_LOGO_WIDTH;
702 fb16 += panel_info.vl_col;
703 }
704 }
705
706 WATCHDOG_RESET();
Simon Glass9a8efc42012-10-30 13:40:18 +0000707 lcd_sync();
wdenk8655b6f2004-10-09 23:25:58 +0000708}
Anatolij Gustschin2b5cb3d2012-04-27 04:41:27 +0000709#else
710static inline void bitmap_plot(int x, int y) {}
wdenk8655b6f2004-10-09 23:25:58 +0000711#endif /* CONFIG_LCD_LOGO */
712
713/*----------------------------------------------------------------------*/
Jon Loeligerc3517f92007-07-08 18:10:08 -0500714#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk8655b6f2004-10-09 23:25:58 +0000715/*
716 * Display the BMP file located at address bmp_image.
717 * Only uncompressed.
718 */
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200719
720#ifdef CONFIG_SPLASH_SCREEN_ALIGN
721#define BMP_ALIGN_CENTER 0x7FFF
Nikita Kiryanov7c7e2802012-08-09 00:14:51 +0000722
723static void splash_align_axis(int *axis, unsigned long panel_size,
724 unsigned long picture_size)
725{
726 unsigned long panel_picture_delta = panel_size - picture_size;
727 unsigned long axis_alignment;
728
729 if (*axis == BMP_ALIGN_CENTER)
730 axis_alignment = panel_picture_delta / 2;
731 else if (*axis < 0)
732 axis_alignment = panel_picture_delta + *axis + 1;
733 else
734 return;
735
736 *axis = max(0, axis_alignment);
737}
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200738#endif
739
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000740
741#ifdef CONFIG_LCD_BMP_RLE8
742
743#define BMP_RLE8_ESCAPE 0
744#define BMP_RLE8_EOL 0
745#define BMP_RLE8_EOBMP 1
746#define BMP_RLE8_DELTA 2
747
748static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
749 int cnt)
750{
751 while (cnt > 0) {
752 *(*fbp)++ = cmap[*bmap++];
753 cnt--;
754 }
755}
756
757static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
758{
759 ushort *fb = *fbp;
760 int cnt_8copy = cnt >> 3;
761
762 cnt -= cnt_8copy << 3;
763 while (cnt_8copy > 0) {
764 *fb++ = c;
765 *fb++ = c;
766 *fb++ = c;
767 *fb++ = c;
768 *fb++ = c;
769 *fb++ = c;
770 *fb++ = c;
771 *fb++ = c;
772 cnt_8copy--;
773 }
774 while (cnt > 0) {
775 *fb++ = c;
776 cnt--;
777 }
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000778 *fbp = fb;
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000779}
780
781/*
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000782 * Do not call this function directly, must be called from lcd_display_bitmap.
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000783 */
784static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
785 int x_off, int y_off)
786{
787 uchar *bmap;
788 ulong width, height;
789 ulong cnt, runlen;
790 int x, y;
791 int decode = 1;
792
Przemyslaw Marczakdca2a1c2014-01-22 11:24:13 +0100793 width = get_unaligned_le32(&bmp->header.width);
794 height = get_unaligned_le32(&bmp->header.height);
795 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000796
797 x = 0;
798 y = height - 1;
799
800 while (decode) {
801 if (bmap[0] == BMP_RLE8_ESCAPE) {
802 switch (bmap[1]) {
803 case BMP_RLE8_EOL:
804 /* end of line */
805 bmap += 2;
806 x = 0;
807 y--;
808 /* 16bpix, 2-byte per pixel, width should *2 */
809 fb -= (width * 2 + lcd_line_length);
810 break;
811 case BMP_RLE8_EOBMP:
812 /* end of bitmap */
813 decode = 0;
814 break;
815 case BMP_RLE8_DELTA:
816 /* delta run */
817 x += bmap[2];
818 y -= bmap[3];
819 /* 16bpix, 2-byte per pixel, x should *2 */
820 fb = (uchar *) (lcd_base + (y + y_off - 1)
821 * lcd_line_length + (x + x_off) * 2);
822 bmap += 4;
823 break;
824 default:
825 /* unencoded run */
826 runlen = bmap[1];
827 bmap += 2;
828 if (y < height) {
829 if (x < width) {
830 if (x + runlen > width)
831 cnt = width - x;
832 else
833 cnt = runlen;
834 draw_unencoded_bitmap(
835 (ushort **)&fb,
836 bmap, cmap, cnt);
837 }
838 x += runlen;
839 }
840 bmap += runlen;
841 if (runlen & 1)
842 bmap++;
843 }
844 } else {
845 /* encoded run */
846 if (y < height) {
847 runlen = bmap[0];
848 if (x < width) {
849 /* aggregate the same code */
850 while (bmap[0] == 0xff &&
851 bmap[2] != BMP_RLE8_ESCAPE &&
852 bmap[1] == bmap[3]) {
853 runlen += bmap[2];
854 bmap += 2;
855 }
856 if (x + runlen > width)
857 cnt = width - x;
858 else
859 cnt = runlen;
860 draw_encoded_bitmap((ushort **)&fb,
861 cmap[bmap[1]], cnt);
862 }
863 x += runlen;
864 }
865 bmap += 2;
866 }
867 }
868}
869#endif
870
Anatolij Gustschind23019f2012-09-22 06:55:53 +0000871#if defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +0000872#define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
Anatolij Gustschind23019f2012-09-22 06:55:53 +0000873#else
874#define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +0000875#endif
876
877#if defined(CONFIG_BMP_16BPP)
878#if defined(CONFIG_ATMEL_LCD_BGR555)
879static inline void fb_put_word(uchar **fb, uchar **from)
880{
881 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
882 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
883 *from += 2;
884}
885#else
886static inline void fb_put_word(uchar **fb, uchar **from)
887{
888 *(*fb)++ = *(*from)++;
889 *(*fb)++ = *(*from)++;
890}
891#endif
892#endif /* CONFIG_BMP_16BPP */
893
wdenk8655b6f2004-10-09 23:25:58 +0000894int lcd_display_bitmap(ulong bmp_image, int x, int y)
895{
Anatolij Gustschin00cc5592009-02-25 20:28:13 +0100896#if !defined(CONFIG_MCC200)
897 ushort *cmap = NULL;
898#endif
899 ushort *cmap_base = NULL;
wdenk8655b6f2004-10-09 23:25:58 +0000900 ushort i, j;
901 uchar *fb;
Simon Glass7d95f2a2014-02-27 13:26:19 -0700902 bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
wdenk8655b6f2004-10-09 23:25:58 +0000903 uchar *bmap;
Tom Wai-Hong Tamfecac462012-09-28 15:11:14 +0000904 ushort padded_width;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100905 unsigned long width, height, byte_width;
Wolfgang Denke8143e72006-08-30 23:09:00 +0200906 unsigned long pwidth = panel_info.vl_col;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100907 unsigned colors, bpix, bmp_bpix;
wdenk8655b6f2004-10-09 23:25:58 +0000908
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000909 if (!bmp || !(bmp->header.signature[0] == 'B' &&
910 bmp->header.signature[1] == 'M')) {
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000911 printf("Error: no valid bmp image at %lx\n", bmp_image);
912
wdenk8655b6f2004-10-09 23:25:58 +0000913 return 1;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100914 }
wdenk8655b6f2004-10-09 23:25:58 +0000915
Przemyslaw Marczakdca2a1c2014-01-22 11:24:13 +0100916 width = get_unaligned_le32(&bmp->header.width);
917 height = get_unaligned_le32(&bmp->header.height);
918 bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
919
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100920 colors = 1 << bmp_bpix;
wdenk8655b6f2004-10-09 23:25:58 +0000921
922 bpix = NBITS(panel_info.vl_bpix);
923
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000924 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100925 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
926 bpix, bmp_bpix);
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000927
wdenk8655b6f2004-10-09 23:25:58 +0000928 return 1;
929 }
930
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100931 /* We support displaying 8bpp BMPs on 16bpp LCDs */
Nikita Kiryanovdad631c2012-12-20 00:52:34 +0000932 if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) {
wdenk8655b6f2004-10-09 23:25:58 +0000933 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
Przemyslaw Marczakdca2a1c2014-01-22 11:24:13 +0100934 bpix, get_unaligned_le16(&bmp->header.bit_count));
wdenk8655b6f2004-10-09 23:25:58 +0000935 return 1;
936 }
937
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000938 debug("Display-bmp: %d x %d with %d colors\n",
wdenk8655b6f2004-10-09 23:25:58 +0000939 (int)width, (int)height, (int)colors);
940
Wolfgang Denkf6414712006-10-20 15:51:21 +0200941#if !defined(CONFIG_MCC200)
942 /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100943 if (bmp_bpix == 8) {
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000944 cmap = configuration_get_cmap();
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100945 cmap_base = cmap;
946
wdenk8655b6f2004-10-09 23:25:58 +0000947 /* Set color map */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000948 for (i = 0; i < colors; ++i) {
wdenk8655b6f2004-10-09 23:25:58 +0000949 bmp_color_table_entry_t cte = bmp->color_table[i];
Mark Jackson1464eff2008-08-01 09:48:29 +0100950#if !defined(CONFIG_ATMEL_LCD)
wdenk8655b6f2004-10-09 23:25:58 +0000951 ushort colreg =
952 ( ((cte.red) << 8) & 0xf800) |
Wolfgang Denk59d80bf2005-09-21 15:24:52 +0200953 ( ((cte.green) << 3) & 0x07e0) |
954 ( ((cte.blue) >> 3) & 0x001f) ;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200955#ifdef CONFIG_SYS_INVERT_COLORS
wdenk25d67122004-12-10 11:40:40 +0000956 *cmap = 0xffff - colreg;
wdenk8655b6f2004-10-09 23:25:58 +0000957#else
wdenk25d67122004-12-10 11:40:40 +0000958 *cmap = colreg;
959#endif
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100960#if defined(CONFIG_MPC823)
wdenk25d67122004-12-10 11:40:40 +0000961 cmap--;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100962#else
963 cmap++;
wdenk8655b6f2004-10-09 23:25:58 +0000964#endif
Mark Jackson1464eff2008-08-01 09:48:29 +0100965#else /* CONFIG_ATMEL_LCD */
966 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
967#endif
wdenk8655b6f2004-10-09 23:25:58 +0000968 }
969 }
Wolfgang Denkf6414712006-10-20 15:51:21 +0200970#endif
Wolfgang Denke8143e72006-08-30 23:09:00 +0200971 /*
972 * BMP format for Monochrome assumes that the state of a
973 * pixel is described on a per Bit basis, not per Byte.
974 * So, in case of Monochrome BMP we should align widths
975 * on a byte boundary and convert them from Bit to Byte
976 * units.
Wolfgang Denk511d0c72006-10-09 00:42:01 +0200977 * Probably, PXA250 and MPC823 process 1bpp BMP images in
978 * their own ways, so make the converting to be MCC200
Wolfgang Denke8143e72006-08-30 23:09:00 +0200979 * specific.
980 */
981#if defined(CONFIG_MCC200)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000982 if (bpix == 1) {
Wolfgang Denke8143e72006-08-30 23:09:00 +0200983 width = ((width + 7) & ~7) >> 3;
984 x = ((x + 7) & ~7) >> 3;
985 pwidth= ((pwidth + 7) & ~7) >> 3;
986 }
987#endif
988
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000989 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200990
991#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Nikita Kiryanov7c7e2802012-08-09 00:14:51 +0000992 splash_align_axis(&x, pwidth, width);
993 splash_align_axis(&y, panel_info.vl_row, height);
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200994#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
995
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000996 if ((x + width) > pwidth)
Wolfgang Denke8143e72006-08-30 23:09:00 +0200997 width = pwidth - x;
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000998 if ((y + height) > panel_info.vl_row)
wdenk8655b6f2004-10-09 23:25:58 +0000999 height = panel_info.vl_row - y;
1000
Przemyslaw Marczakdca2a1c2014-01-22 11:24:13 +01001001 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
1002 fb = (uchar *)(lcd_base +
Liu Ying8d46d5b2011-01-11 15:29:58 +08001003 (y + height - 1) * lcd_line_length + x * bpix / 8);
Mark Jacksona303dfb2009-02-06 10:37:49 +01001004
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +01001005 switch (bmp_bpix) {
Mark Jacksona303dfb2009-02-06 10:37:49 +01001006 case 1: /* pass through */
1007 case 8:
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +00001008#ifdef CONFIG_LCD_BMP_RLE8
Przemyslaw Marczakdca2a1c2014-01-22 11:24:13 +01001009 u32 compression = get_unaligned_le32(&bmp->header.compression);
1010 if (compression == BMP_BI_RLE8) {
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +00001011 if (bpix != 16) {
1012 /* TODO implement render code for bpix != 16 */
1013 printf("Error: only support 16 bpix");
1014 return 1;
1015 }
1016 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
1017 break;
1018 }
1019#endif
1020
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +01001021 if (bpix != 16)
1022 byte_width = width;
1023 else
1024 byte_width = width * 2;
1025
Mark Jacksona303dfb2009-02-06 10:37:49 +01001026 for (i = 0; i < height; ++i) {
1027 WATCHDOG_RESET();
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +01001028 for (j = 0; j < width; j++) {
1029 if (bpix != 16) {
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +00001030 FB_PUT_BYTE(fb, bmap);
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +01001031 } else {
1032 *(uint16_t *)fb = cmap_base[*(bmap++)];
1033 fb += sizeof(uint16_t) / sizeof(*fb);
1034 }
1035 }
Tom Wai-Hong Tamfecac462012-09-28 15:11:14 +00001036 bmap += (padded_width - width);
Jeroen Hofstee6b035142013-01-12 12:07:56 +00001037 fb -= byte_width + lcd_line_length;
Mark Jacksona303dfb2009-02-06 10:37:49 +01001038 }
1039 break;
1040
1041#if defined(CONFIG_BMP_16BPP)
1042 case 16:
1043 for (i = 0; i < height; ++i) {
1044 WATCHDOG_RESET();
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +00001045 for (j = 0; j < width; j++)
1046 fb_put_word(&fb, &bmap);
1047
Tom Wai-Hong Tamfecac462012-09-28 15:11:14 +00001048 bmap += (padded_width - width) * 2;
Jeroen Hofstee6b035142013-01-12 12:07:56 +00001049 fb -= width * 2 + lcd_line_length;
Mark Jacksona303dfb2009-02-06 10:37:49 +01001050 }
1051 break;
1052#endif /* CONFIG_BMP_16BPP */
1053
Donghwa Leefb6a9aa2012-05-09 19:23:37 +00001054#if defined(CONFIG_BMP_32BPP)
1055 case 32:
1056 for (i = 0; i < height; ++i) {
1057 for (j = 0; j < width; j++) {
1058 *(fb++) = *(bmap++);
1059 *(fb++) = *(bmap++);
1060 *(fb++) = *(bmap++);
1061 *(fb++) = *(bmap++);
1062 }
Jeroen Hofstee6b035142013-01-12 12:07:56 +00001063 fb -= lcd_line_length + width * (bpix / 8);
Donghwa Leefb6a9aa2012-05-09 19:23:37 +00001064 }
1065 break;
1066#endif /* CONFIG_BMP_32BPP */
Mark Jacksona303dfb2009-02-06 10:37:49 +01001067 default:
1068 break;
1069 };
wdenk8655b6f2004-10-09 23:25:58 +00001070
Simon Glass9a8efc42012-10-30 13:40:18 +00001071 lcd_sync();
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001072 return 0;
wdenk8655b6f2004-10-09 23:25:58 +00001073}
Jon Loeligerc3517f92007-07-08 18:10:08 -05001074#endif
wdenk8655b6f2004-10-09 23:25:58 +00001075
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001076static void *lcd_logo(void)
wdenk8655b6f2004-10-09 23:25:58 +00001077{
wdenk8655b6f2004-10-09 23:25:58 +00001078#ifdef CONFIG_SPLASH_SCREEN
1079 char *s;
1080 ulong addr;
1081 static int do_splash = 1;
1082
1083 if (do_splash && (s = getenv("splashimage")) != NULL) {
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001084 int x = 0, y = 0;
wdenk8655b6f2004-10-09 23:25:58 +00001085 do_splash = 0;
1086
Nikita Kiryanov581bb412013-01-30 21:39:57 +00001087 if (splash_screen_prepare())
Robert Winklerdd4425e2013-06-17 11:31:29 -07001088 return (void *)lcd_base;
Nikita Kiryanov581bb412013-01-30 21:39:57 +00001089
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001090 addr = simple_strtoul (s, NULL, 16);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001091
Anatolij Gustschinff8fb562013-07-02 00:04:05 +02001092 splash_get_pos(&x, &y);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001093
Nikita Kiryanovd3a555e2012-08-09 00:14:50 +00001094 if (bmp_display(addr, x, y) == 0)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001095 return (void *)lcd_base;
wdenk8655b6f2004-10-09 23:25:58 +00001096 }
1097#endif /* CONFIG_SPLASH_SCREEN */
1098
Anatolij Gustschin2b5cb3d2012-04-27 04:41:27 +00001099 bitmap_plot(0, 0);
wdenk8655b6f2004-10-09 23:25:58 +00001100
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +02001101#ifdef CONFIG_LCD_INFO
1102 console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
1103 console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
1104 lcd_show_board_info();
1105#endif /* CONFIG_LCD_INFO */
Stelian Pop39cf4802008-05-09 21:57:18 +02001106
wdenk88804d12005-07-04 00:03:16 +00001107#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001108 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
wdenk8655b6f2004-10-09 23:25:58 +00001109#else
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001110 return (void *)lcd_base;
Jeroen Hofstee6b035142013-01-12 12:07:56 +00001111#endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
wdenk8655b6f2004-10-09 23:25:58 +00001112}
1113
Nikita Kiryanovc0880482013-02-24 21:28:43 +00001114#ifdef CONFIG_SPLASHIMAGE_GUARD
1115static int on_splashimage(const char *name, const char *value, enum env_op op,
1116 int flags)
1117{
1118 ulong addr;
1119 int aligned;
1120
1121 if (op == env_op_delete)
1122 return 0;
1123
1124 addr = simple_strtoul(value, NULL, 16);
1125 /* See README.displaying-bmps */
1126 aligned = (addr % 4 == 2);
1127 if (!aligned) {
1128 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1129 return -1;
1130 }
1131
1132 return 0;
1133}
1134
1135U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1136#endif
1137
Vadim Bendebury395166c2012-09-28 15:11:13 +00001138void lcd_position_cursor(unsigned col, unsigned row)
1139{
1140 console_col = min(col, CONSOLE_COLS - 1);
1141 console_row = min(row, CONSOLE_ROWS - 1);
1142}
1143
1144int lcd_get_pixel_width(void)
1145{
1146 return panel_info.vl_col;
1147}
1148
1149int lcd_get_pixel_height(void)
1150{
1151 return panel_info.vl_row;
1152}
1153
1154int lcd_get_screen_rows(void)
1155{
1156 return CONSOLE_ROWS;
1157}
1158
1159int lcd_get_screen_columns(void)
1160{
1161 return CONSOLE_COLS;
1162}
Stephen Warren6a195d22013-05-27 18:31:17 +00001163
1164#if defined(CONFIG_LCD_DT_SIMPLEFB)
1165static int lcd_dt_simplefb_configure_node(void *blob, int off)
1166{
1167 u32 stride;
1168 fdt32_t cells[2];
1169 int ret;
Stephen Warren5af7d0f2013-06-13 17:13:11 -06001170 static const char format[] =
Stephen Warren6a195d22013-05-27 18:31:17 +00001171#if LCD_BPP == LCD_COLOR16
1172 "r5g6b5";
1173#else
1174 "";
1175#endif
1176
1177 if (!format[0])
1178 return -1;
1179
1180 stride = panel_info.vl_col * 2;
1181
1182 cells[0] = cpu_to_fdt32(gd->fb_base);
1183 cells[1] = cpu_to_fdt32(stride * panel_info.vl_row);
1184 ret = fdt_setprop(blob, off, "reg", cells, sizeof(cells[0]) * 2);
1185 if (ret < 0)
1186 return -1;
1187
1188 cells[0] = cpu_to_fdt32(panel_info.vl_col);
1189 ret = fdt_setprop(blob, off, "width", cells, sizeof(cells[0]));
1190 if (ret < 0)
1191 return -1;
1192
1193 cells[0] = cpu_to_fdt32(panel_info.vl_row);
1194 ret = fdt_setprop(blob, off, "height", cells, sizeof(cells[0]));
1195 if (ret < 0)
1196 return -1;
1197
1198 cells[0] = cpu_to_fdt32(stride);
1199 ret = fdt_setprop(blob, off, "stride", cells, sizeof(cells[0]));
1200 if (ret < 0)
1201 return -1;
1202
1203 ret = fdt_setprop(blob, off, "format", format, strlen(format) + 1);
1204 if (ret < 0)
1205 return -1;
1206
1207 ret = fdt_delprop(blob, off, "status");
1208 if (ret < 0)
1209 return -1;
1210
1211 return 0;
1212}
1213
1214int lcd_dt_simplefb_add_node(void *blob)
1215{
Stephen Warren5af7d0f2013-06-13 17:13:11 -06001216 static const char compat[] = "simple-framebuffer";
1217 static const char disabled[] = "disabled";
Stephen Warren6a195d22013-05-27 18:31:17 +00001218 int off, ret;
1219
1220 off = fdt_add_subnode(blob, 0, "framebuffer");
1221 if (off < 0)
1222 return -1;
1223
1224 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
1225 if (ret < 0)
1226 return -1;
1227
1228 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
1229 if (ret < 0)
1230 return -1;
1231
1232 return lcd_dt_simplefb_configure_node(blob, off);
1233}
1234
1235int lcd_dt_simplefb_enable_existing_node(void *blob)
1236{
1237 int off;
1238
1239 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
1240 if (off < 0)
1241 return -1;
1242
1243 return lcd_dt_simplefb_configure_node(blob, off);
1244}
1245#endif