blob: 8d5c63c29ef924166576d9d3793379429acfe0e4 [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 Denk1a459662013-07-08 09:37:19 +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 */
Che-Liang Chioud3983ee2011-10-21 17:04:21 +080054#include <video_font_data.h>
wdenk8655b6f2004-10-09 23:25:58 +000055
wdenk88804d12005-07-04 00:03:16 +000056/************************************************************************/
57/* ** LOGO DATA */
58/************************************************************************/
59#ifdef CONFIG_LCD_LOGO
60# include <bmp_logo.h> /* Get logo data, width and height */
Che-Liang Chiouc2707302011-10-20 23:04:20 +000061# include <bmp_logo_data.h>
Alessandro Rubiniacb13862010-03-13 17:44:08 +010062# if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
wdenk88804d12005-07-04 00:03:16 +000063# error Default Color Map overlaps with Logo Color Map
64# endif
65#endif
wdenk8655b6f2004-10-09 23:25:58 +000066
Simon Glass676d3192012-10-17 13:24:54 +000067#ifndef CONFIG_LCD_ALIGNMENT
68#define CONFIG_LCD_ALIGNMENT PAGE_SIZE
69#endif
70
Simon Glass0d89efe2012-10-17 13:24:59 +000071/* By default we scroll by a single line */
72#ifndef CONFIG_CONSOLE_SCROLL_LINES
73#define CONFIG_CONSOLE_SCROLL_LINES 1
74#endif
75
Jeroen Hofsteea5796c52013-01-12 12:07:59 +000076/************************************************************************/
77/* ** CONSOLE DEFINITIONS & FUNCTIONS */
78/************************************************************************/
79#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
80# define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
81 / VIDEO_FONT_HEIGHT)
82#else
83# define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
84#endif
Wolfgang Denkd87080b2006-03-31 18:32:53 +020085
Jeroen Hofsteea5796c52013-01-12 12:07:59 +000086#define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
87#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
88#define CONSOLE_ROW_FIRST lcd_console_address
89#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
90#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
91 - CONSOLE_ROW_SIZE)
92#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
93#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
94
95#if LCD_BPP == LCD_MONOCHROME
96# define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
97 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
98#elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16)
99# define COLOR_MASK(c) (c)
100#else
101# error Unsupported LCD BPP.
102#endif
103
wdenk8655b6f2004-10-09 23:25:58 +0000104DECLARE_GLOBAL_DATA_PTR;
wdenk8655b6f2004-10-09 23:25:58 +0000105
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000106static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
107static inline void lcd_puts_xy(ushort x, ushort y, uchar *s);
108static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
wdenk8655b6f2004-10-09 23:25:58 +0000109
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000110static int lcd_init(void *lcdbase);
wdenk8655b6f2004-10-09 23:25:58 +0000111
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000112static void *lcd_logo(void);
wdenk8655b6f2004-10-09 23:25:58 +0000113
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000114static int lcd_getbgcolor(void);
115static void lcd_setfgcolor(int color);
116static void lcd_setbgcolor(int color);
wdenk8655b6f2004-10-09 23:25:58 +0000117
Wolfgang Denk46d1d5d2013-01-05 09:45:48 +0000118static int lcd_color_fg;
119static int lcd_color_bg;
Jeroen Hofsteef1d205a2013-01-22 10:44:11 +0000120int lcd_line_length;
Wolfgang Denk46d1d5d2013-01-05 09:45:48 +0000121
wdenk8655b6f2004-10-09 23:25:58 +0000122char lcd_is_enabled = 0;
wdenk8655b6f2004-10-09 23:25:58 +0000123
Jeroen Hofsteef1d205a2013-01-22 10:44:11 +0000124static short console_col;
125static short console_row;
126
127static void *lcd_console_address;
Jeroen Hofstee00a0ca52013-01-22 10:44:12 +0000128static void *lcd_base; /* Start of framebuffer memory */
Jeroen Hofsteef1d205a2013-01-22 10:44:11 +0000129
Simon Glass9a8efc42012-10-30 13:40:18 +0000130static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
131
wdenk8655b6f2004-10-09 23:25:58 +0000132/************************************************************************/
133
Simon Glass9a8efc42012-10-30 13:40:18 +0000134/* Flush LCD activity to the caches */
135void lcd_sync(void)
136{
137 /*
138 * flush_dcache_range() is declared in common.h but it seems that some
139 * architectures do not actually implement it. Is there a way to find
140 * out whether it exists? For now, ARM is safe.
141 */
142#if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
143 int line_length;
144
145 if (lcd_flush_dcache)
146 flush_dcache_range((u32)lcd_base,
147 (u32)(lcd_base + lcd_get_size(&line_length)));
148#endif
149}
150
151void lcd_set_flush_dcache(int flush)
152{
153 lcd_flush_dcache = (flush != 0);
154}
155
wdenk8655b6f2004-10-09 23:25:58 +0000156/*----------------------------------------------------------------------*/
157
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000158static void console_scrollup(void)
wdenk8655b6f2004-10-09 23:25:58 +0000159{
Simon Glass0d89efe2012-10-17 13:24:59 +0000160 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
wdenk8655b6f2004-10-09 23:25:58 +0000161
Simon Glass0d89efe2012-10-17 13:24:59 +0000162 /* Copy up rows ignoring those that will be overwritten */
163 memcpy(CONSOLE_ROW_FIRST,
164 lcd_console_address + CONSOLE_ROW_SIZE * rows,
165 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
166
167 /* Clear the last rows */
168 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
169 COLOR_MASK(lcd_color_bg),
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000170 CONSOLE_ROW_SIZE * rows);
Simon Glass0d89efe2012-10-17 13:24:59 +0000171
Simon Glass9a8efc42012-10-30 13:40:18 +0000172 lcd_sync();
Simon Glass0d89efe2012-10-17 13:24:59 +0000173 console_row -= rows;
wdenk8655b6f2004-10-09 23:25:58 +0000174}
175
176/*----------------------------------------------------------------------*/
177
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000178static inline void console_back(void)
wdenk8655b6f2004-10-09 23:25:58 +0000179{
180 if (--console_col < 0) {
181 console_col = CONSOLE_COLS-1 ;
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000182 if (--console_row < 0)
wdenk8655b6f2004-10-09 23:25:58 +0000183 console_row = 0;
wdenk8655b6f2004-10-09 23:25:58 +0000184 }
185
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000186 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
187 console_row * VIDEO_FONT_HEIGHT, ' ');
wdenk8655b6f2004-10-09 23:25:58 +0000188}
189
190/*----------------------------------------------------------------------*/
191
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000192static inline void console_newline(void)
wdenk8655b6f2004-10-09 23:25:58 +0000193{
wdenk8655b6f2004-10-09 23:25:58 +0000194 console_col = 0;
195
196 /* Check if we need to scroll the terminal */
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000197 if (++console_row >= CONSOLE_ROWS)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000198 console_scrollup();
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000199 else
Simon Glass9a8efc42012-10-30 13:40:18 +0000200 lcd_sync();
wdenk8655b6f2004-10-09 23:25:58 +0000201}
202
203/*----------------------------------------------------------------------*/
204
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000205void lcd_putc(const char c)
wdenk8655b6f2004-10-09 23:25:58 +0000206{
207 if (!lcd_is_enabled) {
208 serial_putc(c);
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000209
wdenk8655b6f2004-10-09 23:25:58 +0000210 return;
211 }
212
213 switch (c) {
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000214 case '\r':
215 console_col = 0;
wdenk8655b6f2004-10-09 23:25:58 +0000216
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000217 return;
218 case '\n':
219 console_newline();
wdenk8655b6f2004-10-09 23:25:58 +0000220
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000221 return;
wdenk8655b6f2004-10-09 23:25:58 +0000222 case '\t': /* Tab (8 chars alignment) */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000223 console_col += 8;
224 console_col &= ~7;
wdenk8655b6f2004-10-09 23:25:58 +0000225
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000226 if (console_col >= CONSOLE_COLS)
227 console_newline();
wdenk8655b6f2004-10-09 23:25:58 +0000228
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000229 return;
230 case '\b':
231 console_back();
wdenk8655b6f2004-10-09 23:25:58 +0000232
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000233 return;
234 default:
235 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
236 console_row * VIDEO_FONT_HEIGHT, c);
237 if (++console_col >= CONSOLE_COLS)
238 console_newline();
wdenk8655b6f2004-10-09 23:25:58 +0000239 }
wdenk8655b6f2004-10-09 23:25:58 +0000240}
241
242/*----------------------------------------------------------------------*/
243
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000244void lcd_puts(const char *s)
wdenk8655b6f2004-10-09 23:25:58 +0000245{
246 if (!lcd_is_enabled) {
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000247 serial_puts(s);
248
wdenk8655b6f2004-10-09 23:25:58 +0000249 return;
250 }
251
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000252 while (*s)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000253 lcd_putc(*s++);
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000254
Simon Glass9a8efc42012-10-30 13:40:18 +0000255 lcd_sync();
wdenk8655b6f2004-10-09 23:25:58 +0000256}
257
Haavard Skinnemoen15b17ab2008-09-01 16:21:20 +0200258/*----------------------------------------------------------------------*/
259
260void lcd_printf(const char *fmt, ...)
261{
262 va_list args;
263 char buf[CONFIG_SYS_PBSIZE];
264
265 va_start(args, fmt);
266 vsprintf(buf, fmt, args);
267 va_end(args);
268
269 lcd_puts(buf);
270}
271
wdenk8655b6f2004-10-09 23:25:58 +0000272/************************************************************************/
273/* ** Low-Level Graphics Routines */
274/************************************************************************/
275
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000276static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
wdenk8655b6f2004-10-09 23:25:58 +0000277{
278 uchar *dest;
Marek Vasutbe547c62011-09-26 02:26:04 +0200279 ushort row;
280
Anatolij Gustschin0f999c42012-04-27 04:41:16 +0000281#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
282 y += BMP_LOGO_HEIGHT;
283#endif
284
Marek Vasutbe547c62011-09-26 02:26:04 +0200285#if LCD_BPP == LCD_MONOCHROME
286 ushort off = x * (1 << LCD_BPP) % 8;
287#endif
wdenk8655b6f2004-10-09 23:25:58 +0000288
289 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
wdenk8655b6f2004-10-09 23:25:58 +0000290
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000291 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
wdenk8655b6f2004-10-09 23:25:58 +0000292 uchar *s = str;
wdenk8655b6f2004-10-09 23:25:58 +0000293 int i;
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100294#if LCD_BPP == LCD_COLOR16
295 ushort *d = (ushort *)dest;
296#else
297 uchar *d = dest;
298#endif
wdenk8655b6f2004-10-09 23:25:58 +0000299
300#if LCD_BPP == LCD_MONOCHROME
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000301 uchar rest = *d & -(1 << (8 - off));
wdenk8655b6f2004-10-09 23:25:58 +0000302 uchar sym;
303#endif
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000304 for (i = 0; i < count; ++i) {
wdenk8655b6f2004-10-09 23:25:58 +0000305 uchar c, bits;
306
307 c = *s++;
308 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
309
310#if LCD_BPP == LCD_MONOCHROME
311 sym = (COLOR_MASK(lcd_color_fg) & bits) |
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000312 (COLOR_MASK(lcd_color_bg) & ~bits);
wdenk8655b6f2004-10-09 23:25:58 +0000313
314 *d++ = rest | (sym >> off);
315 rest = sym << (8-off);
316#elif LCD_BPP == LCD_COLOR8
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000317 for (c = 0; c < 8; ++c) {
wdenk8655b6f2004-10-09 23:25:58 +0000318 *d++ = (bits & 0x80) ?
319 lcd_color_fg : lcd_color_bg;
320 bits <<= 1;
321 }
322#elif LCD_BPP == LCD_COLOR16
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000323 for (c = 0; c < 8; ++c) {
wdenk8655b6f2004-10-09 23:25:58 +0000324 *d++ = (bits & 0x80) ?
325 lcd_color_fg : lcd_color_bg;
326 bits <<= 1;
327 }
328#endif
329 }
330#if LCD_BPP == LCD_MONOCHROME
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000331 *d = rest | (*d & ((1 << (8 - off)) - 1));
wdenk8655b6f2004-10-09 23:25:58 +0000332#endif
333 }
334}
335
336/*----------------------------------------------------------------------*/
337
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000338static inline void lcd_puts_xy(ushort x, ushort y, uchar *s)
wdenk8655b6f2004-10-09 23:25:58 +0000339{
Anatolij Gustschin0f999c42012-04-27 04:41:16 +0000340 lcd_drawchars(x, y, s, strlen((char *)s));
wdenk8655b6f2004-10-09 23:25:58 +0000341}
342
343/*----------------------------------------------------------------------*/
344
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000345static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
wdenk8655b6f2004-10-09 23:25:58 +0000346{
Anatolij Gustschin0f999c42012-04-27 04:41:16 +0000347 lcd_drawchars(x, y, &c, 1);
wdenk8655b6f2004-10-09 23:25:58 +0000348}
349
350/************************************************************************/
351/** Small utility to check that you got the colours right */
352/************************************************************************/
353#ifdef LCD_TEST_PATTERN
354
355#define N_BLK_VERT 2
356#define N_BLK_HOR 3
357
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000358static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
wdenk8655b6f2004-10-09 23:25:58 +0000359 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
360 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
361};
362
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000363static void test_pattern(void)
wdenk8655b6f2004-10-09 23:25:58 +0000364{
365 ushort v_max = panel_info.vl_row;
366 ushort h_max = panel_info.vl_col;
367 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
368 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
369 ushort v, h;
370 uchar *pix = (uchar *)lcd_base;
371
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000372 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
wdenk8655b6f2004-10-09 23:25:58 +0000373 h_max, v_max, h_step, v_step);
374
375 /* WARNING: Code silently assumes 8bit/pixel */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000376 for (v = 0; v < v_max; ++v) {
wdenk8655b6f2004-10-09 23:25:58 +0000377 uchar iy = v / v_step;
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000378 for (h = 0; h < h_max; ++h) {
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000379 uchar ix = N_BLK_HOR * iy + h / h_step;
wdenk8655b6f2004-10-09 23:25:58 +0000380 *pix++ = test_colors[ix];
381 }
382 }
383}
384#endif /* LCD_TEST_PATTERN */
385
386
387/************************************************************************/
388/* ** GENERIC Initialization Routines */
389/************************************************************************/
390
Simon Glass676d3192012-10-17 13:24:54 +0000391int lcd_get_size(int *line_length)
392{
393 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
394 return *line_length * panel_info.vl_row;
395}
396
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000397int drv_lcd_init(void)
wdenk8655b6f2004-10-09 23:25:58 +0000398{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200399 struct stdio_dev lcddev;
wdenk8655b6f2004-10-09 23:25:58 +0000400 int rc;
401
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000402 lcd_base = (void *) gd->fb_base;
wdenk8655b6f2004-10-09 23:25:58 +0000403
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000404 lcd_init(lcd_base); /* LCD initialization */
wdenk8655b6f2004-10-09 23:25:58 +0000405
406 /* Device initialization */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000407 memset(&lcddev, 0, sizeof(lcddev));
wdenk8655b6f2004-10-09 23:25:58 +0000408
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000409 strcpy(lcddev.name, "lcd");
wdenk8655b6f2004-10-09 23:25:58 +0000410 lcddev.ext = 0; /* No extensions */
411 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
412 lcddev.putc = lcd_putc; /* 'putc' function */
413 lcddev.puts = lcd_puts; /* 'puts' function */
414
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000415 rc = stdio_register(&lcddev);
wdenk8655b6f2004-10-09 23:25:58 +0000416
417 return (rc == 0) ? 1 : rc;
418}
419
420/*----------------------------------------------------------------------*/
Che-Liang Chiou02110902011-10-20 23:07:03 +0000421void lcd_clear(void)
wdenk8655b6f2004-10-09 23:25:58 +0000422{
423#if LCD_BPP == LCD_MONOCHROME
424 /* Setting the palette */
425 lcd_initcolregs();
426
427#elif LCD_BPP == LCD_COLOR8
428 /* Setting the palette */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000429 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
430 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
431 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
432 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
433 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
434 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
435 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
436 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
437 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
wdenk8655b6f2004-10-09 23:25:58 +0000438#endif
439
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200440#ifndef CONFIG_SYS_WHITE_ON_BLACK
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000441 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
442 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
wdenk8655b6f2004-10-09 23:25:58 +0000443#else
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000444 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
445 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200446#endif /* CONFIG_SYS_WHITE_ON_BLACK */
wdenk8655b6f2004-10-09 23:25:58 +0000447
448#ifdef LCD_TEST_PATTERN
449 test_pattern();
450#else
451 /* set framebuffer to background color */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000452 memset((char *)lcd_base,
wdenk8655b6f2004-10-09 23:25:58 +0000453 COLOR_MASK(lcd_getbgcolor()),
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000454 lcd_line_length * panel_info.vl_row);
wdenk8655b6f2004-10-09 23:25:58 +0000455#endif
456 /* Paint the logo and retrieve LCD base address */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000457 debug("[LCD] Drawing the logo...\n");
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000458 lcd_console_address = lcd_logo();
wdenk8655b6f2004-10-09 23:25:58 +0000459
460 console_col = 0;
461 console_row = 0;
Simon Glass9a8efc42012-10-30 13:40:18 +0000462 lcd_sync();
463}
464
465static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
466 char *const argv[])
467{
468 lcd_clear();
469 return 0;
wdenk8655b6f2004-10-09 23:25:58 +0000470}
471
472U_BOOT_CMD(
Che-Liang Chiou02110902011-10-20 23:07:03 +0000473 cls, 1, 1, do_lcd_clear,
Peter Tyser2fb26042009-01-27 18:03:12 -0600474 "clear screen",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200475 ""
wdenk8655b6f2004-10-09 23:25:58 +0000476);
477
478/*----------------------------------------------------------------------*/
479
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000480static int lcd_init(void *lcdbase)
wdenk8655b6f2004-10-09 23:25:58 +0000481{
482 /* Initialize the lcd controller */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000483 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
wdenk8655b6f2004-10-09 23:25:58 +0000484
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000485 lcd_ctrl_init(lcdbase);
Anatolij Gustschin1d3dea12013-03-29 14:00:13 +0100486
487 /*
488 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi_b) ignores
489 * the 'lcdbase' argument and uses custom lcd base address
490 * by setting up gd->fb_base. Check for this condition and fixup
491 * 'lcd_base' address.
492 */
493 if ((unsigned long)lcdbase != gd->fb_base)
494 lcd_base = (void *)gd->fb_base;
495
496 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
497
Stephen Warren6d330712013-01-29 16:37:38 +0000498 lcd_get_size(&lcd_line_length);
499 lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
Haavard Skinnemoen6f93d2b2008-09-01 16:21:21 +0200500 lcd_is_enabled = 1;
Che-Liang Chiou02110902011-10-20 23:07:03 +0000501 lcd_clear();
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000502 lcd_enable();
wdenk8655b6f2004-10-09 23:25:58 +0000503
504 /* Initialize the console */
505 console_col = 0;
wdenk88804d12005-07-04 00:03:16 +0000506#ifdef CONFIG_LCD_INFO_BELOW_LOGO
wdenk8655b6f2004-10-09 23:25:58 +0000507 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
508#else
509 console_row = 1; /* leave 1 blank line below logo */
510#endif
wdenk8655b6f2004-10-09 23:25:58 +0000511
512 return 0;
513}
514
515
516/************************************************************************/
517/* ** ROM capable initialization part - needed to reserve FB memory */
518/************************************************************************/
519/*
520 * This is called early in the system initialization to grab memory
521 * for the LCD controller.
522 * Returns new address for monitor, after reserving LCD buffer memory
523 *
524 * Note that this is running from ROM, so no write access to global data.
525 */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000526ulong lcd_setmem(ulong addr)
wdenk8655b6f2004-10-09 23:25:58 +0000527{
528 ulong size;
Simon Glass676d3192012-10-17 13:24:54 +0000529 int line_length;
wdenk8655b6f2004-10-09 23:25:58 +0000530
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000531 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
532 panel_info.vl_row, NBITS(panel_info.vl_bpix));
wdenk8655b6f2004-10-09 23:25:58 +0000533
Simon Glass676d3192012-10-17 13:24:54 +0000534 size = lcd_get_size(&line_length);
wdenk8655b6f2004-10-09 23:25:58 +0000535
Simon Glass676d3192012-10-17 13:24:54 +0000536 /* Round up to nearest full page, or MMU section if defined */
537 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
538 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
wdenk8655b6f2004-10-09 23:25:58 +0000539
540 /* Allocate pages for the frame buffer. */
541 addr -= size;
542
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000543 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
544 size >> 10, addr);
wdenk8655b6f2004-10-09 23:25:58 +0000545
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000546 return addr;
wdenk8655b6f2004-10-09 23:25:58 +0000547}
548
549/*----------------------------------------------------------------------*/
550
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000551static void lcd_setfgcolor(int color)
wdenk8655b6f2004-10-09 23:25:58 +0000552{
Stelian Pop39cf4802008-05-09 21:57:18 +0200553 lcd_color_fg = color;
wdenk8655b6f2004-10-09 23:25:58 +0000554}
555
556/*----------------------------------------------------------------------*/
557
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000558static void lcd_setbgcolor(int color)
wdenk8655b6f2004-10-09 23:25:58 +0000559{
Stelian Pop39cf4802008-05-09 21:57:18 +0200560 lcd_color_bg = color;
wdenk8655b6f2004-10-09 23:25:58 +0000561}
562
563/*----------------------------------------------------------------------*/
564
Wolfgang Denk46d1d5d2013-01-05 09:45:48 +0000565int lcd_getfgcolor(void)
wdenk8655b6f2004-10-09 23:25:58 +0000566{
567 return lcd_color_fg;
568}
wdenk8655b6f2004-10-09 23:25:58 +0000569
570/*----------------------------------------------------------------------*/
571
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000572static int lcd_getbgcolor(void)
wdenk8655b6f2004-10-09 23:25:58 +0000573{
574 return lcd_color_bg;
575}
576
wdenk8655b6f2004-10-09 23:25:58 +0000577/************************************************************************/
578/* ** Chipset depending Bitmap / Logo stuff... */
579/************************************************************************/
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000580static inline ushort *configuration_get_cmap(void)
581{
582#if defined CONFIG_CPU_PXA
583 struct pxafb_info *fbi = &panel_info.pxa;
584 return (ushort *)fbi->palette;
585#elif defined(CONFIG_MPC823)
586 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
587 cpm8xx_t *cp = &(immr->im_cpm);
588 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
589#elif defined(CONFIG_ATMEL_LCD)
590 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
Anatolij Gustschind23019f2012-09-22 06:55:53 +0000591#elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
592 return panel_info.cmap;
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000593#elif defined(CONFIG_LCD_LOGO)
Anatolij Gustschind23019f2012-09-22 06:55:53 +0000594 return bmp_logo_palette;
595#else
596 return NULL;
597#endif
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000598}
599
wdenk8655b6f2004-10-09 23:25:58 +0000600#ifdef CONFIG_LCD_LOGO
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000601void bitmap_plot(int x, int y)
wdenk8655b6f2004-10-09 23:25:58 +0000602{
Stelian Pop39cf4802008-05-09 21:57:18 +0200603#ifdef CONFIG_ATMEL_LCD
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000604 uint *cmap = (uint *)bmp_logo_palette;
Stelian Pop39cf4802008-05-09 21:57:18 +0200605#else
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000606 ushort *cmap = (ushort *)bmp_logo_palette;
Stelian Pop39cf4802008-05-09 21:57:18 +0200607#endif
wdenk8655b6f2004-10-09 23:25:58 +0000608 ushort i, j;
609 uchar *bmap;
610 uchar *fb;
611 ushort *fb16;
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000612#if defined(CONFIG_MPC823)
613 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
614 cpm8xx_t *cp = &(immr->im_cpm);
wdenk8655b6f2004-10-09 23:25:58 +0000615#endif
Andre Renaud317461c2013-02-13 17:48:00 +0000616 unsigned bpix = NBITS(panel_info.vl_bpix);
wdenk8655b6f2004-10-09 23:25:58 +0000617
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000618 debug("Logo: width %d height %d colors %d cmap %d\n",
wdenk8655b6f2004-10-09 23:25:58 +0000619 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
Anatolij Gustschin095407d2012-04-27 04:41:06 +0000620 ARRAY_SIZE(bmp_logo_palette));
wdenk8655b6f2004-10-09 23:25:58 +0000621
622 bmap = &bmp_logo_bitmap[0];
Andre Renaud317461c2013-02-13 17:48:00 +0000623 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
wdenk8655b6f2004-10-09 23:25:58 +0000624
Andre Renaud317461c2013-02-13 17:48:00 +0000625 if (bpix < 12) {
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000626 /* Leave room for default color map
627 * default case: generic system with no cmap (most likely 16bpp)
628 * cmap was set to the source palette, so no change is done.
629 * This avoids even more ifdefs in the next stanza
630 */
631#if defined(CONFIG_MPC823)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000632 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
Stelian Pop39cf4802008-05-09 21:57:18 +0200633#elif defined(CONFIG_ATMEL_LCD)
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000634 cmap = (uint *)configuration_get_cmap();
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100635#else
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000636 cmap = configuration_get_cmap();
wdenk8655b6f2004-10-09 23:25:58 +0000637#endif
638
639 WATCHDOG_RESET();
640
641 /* Set color map */
Anatolij Gustschin095407d2012-04-27 04:41:06 +0000642 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
wdenk8655b6f2004-10-09 23:25:58 +0000643 ushort colreg = bmp_logo_palette[i];
Stelian Pop39cf4802008-05-09 21:57:18 +0200644#ifdef CONFIG_ATMEL_LCD
645 uint lut_entry;
646#ifdef CONFIG_ATMEL_LCD_BGR555
647 lut_entry = ((colreg & 0x000F) << 11) |
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000648 ((colreg & 0x00F0) << 2) |
649 ((colreg & 0x0F00) >> 7);
Stelian Pop39cf4802008-05-09 21:57:18 +0200650#else /* CONFIG_ATMEL_LCD_RGB565 */
651 lut_entry = ((colreg & 0x000F) << 1) |
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000652 ((colreg & 0x00F0) << 3) |
653 ((colreg & 0x0F00) << 4);
Stelian Pop39cf4802008-05-09 21:57:18 +0200654#endif
655 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
656 cmap++;
657#else /* !CONFIG_ATMEL_LCD */
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200658#ifdef CONFIG_SYS_INVERT_COLORS
wdenk8655b6f2004-10-09 23:25:58 +0000659 *cmap++ = 0xffff - colreg;
660#else
661 *cmap++ = colreg;
662#endif
Stelian Pop39cf4802008-05-09 21:57:18 +0200663#endif /* CONFIG_ATMEL_LCD */
wdenk8655b6f2004-10-09 23:25:58 +0000664 }
665
666 WATCHDOG_RESET();
667
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000668 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
669 memcpy(fb, bmap, BMP_LOGO_WIDTH);
wdenk8655b6f2004-10-09 23:25:58 +0000670 bmap += BMP_LOGO_WIDTH;
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000671 fb += panel_info.vl_col;
wdenk8655b6f2004-10-09 23:25:58 +0000672 }
673 }
674 else { /* true color mode */
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100675 u16 col16;
Andre Renaud317461c2013-02-13 17:48:00 +0000676 fb16 = (ushort *)fb;
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000677 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
678 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100679 col16 = bmp_logo_palette[(bmap[j]-16)];
680 fb16[j] =
681 ((col16 & 0x000F) << 1) |
682 ((col16 & 0x00F0) << 3) |
683 ((col16 & 0x0F00) << 4);
wdenk8655b6f2004-10-09 23:25:58 +0000684 }
685 bmap += BMP_LOGO_WIDTH;
686 fb16 += panel_info.vl_col;
687 }
688 }
689
690 WATCHDOG_RESET();
Simon Glass9a8efc42012-10-30 13:40:18 +0000691 lcd_sync();
wdenk8655b6f2004-10-09 23:25:58 +0000692}
Anatolij Gustschin2b5cb3d2012-04-27 04:41:27 +0000693#else
694static inline void bitmap_plot(int x, int y) {}
wdenk8655b6f2004-10-09 23:25:58 +0000695#endif /* CONFIG_LCD_LOGO */
696
697/*----------------------------------------------------------------------*/
Jon Loeligerc3517f92007-07-08 18:10:08 -0500698#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk8655b6f2004-10-09 23:25:58 +0000699/*
700 * Display the BMP file located at address bmp_image.
701 * Only uncompressed.
702 */
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200703
704#ifdef CONFIG_SPLASH_SCREEN_ALIGN
705#define BMP_ALIGN_CENTER 0x7FFF
Nikita Kiryanov7c7e2802012-08-09 00:14:51 +0000706
707static void splash_align_axis(int *axis, unsigned long panel_size,
708 unsigned long picture_size)
709{
710 unsigned long panel_picture_delta = panel_size - picture_size;
711 unsigned long axis_alignment;
712
713 if (*axis == BMP_ALIGN_CENTER)
714 axis_alignment = panel_picture_delta / 2;
715 else if (*axis < 0)
716 axis_alignment = panel_picture_delta + *axis + 1;
717 else
718 return;
719
720 *axis = max(0, axis_alignment);
721}
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200722#endif
723
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000724
725#ifdef CONFIG_LCD_BMP_RLE8
726
727#define BMP_RLE8_ESCAPE 0
728#define BMP_RLE8_EOL 0
729#define BMP_RLE8_EOBMP 1
730#define BMP_RLE8_DELTA 2
731
732static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
733 int cnt)
734{
735 while (cnt > 0) {
736 *(*fbp)++ = cmap[*bmap++];
737 cnt--;
738 }
739}
740
741static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
742{
743 ushort *fb = *fbp;
744 int cnt_8copy = cnt >> 3;
745
746 cnt -= cnt_8copy << 3;
747 while (cnt_8copy > 0) {
748 *fb++ = c;
749 *fb++ = c;
750 *fb++ = c;
751 *fb++ = c;
752 *fb++ = c;
753 *fb++ = c;
754 *fb++ = c;
755 *fb++ = c;
756 cnt_8copy--;
757 }
758 while (cnt > 0) {
759 *fb++ = c;
760 cnt--;
761 }
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000762 *fbp = fb;
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000763}
764
765/*
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000766 * Do not call this function directly, must be called from lcd_display_bitmap.
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000767 */
768static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
769 int x_off, int y_off)
770{
771 uchar *bmap;
772 ulong width, height;
773 ulong cnt, runlen;
774 int x, y;
775 int decode = 1;
776
777 width = le32_to_cpu(bmp->header.width);
778 height = le32_to_cpu(bmp->header.height);
779 bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset);
780
781 x = 0;
782 y = height - 1;
783
784 while (decode) {
785 if (bmap[0] == BMP_RLE8_ESCAPE) {
786 switch (bmap[1]) {
787 case BMP_RLE8_EOL:
788 /* end of line */
789 bmap += 2;
790 x = 0;
791 y--;
792 /* 16bpix, 2-byte per pixel, width should *2 */
793 fb -= (width * 2 + lcd_line_length);
794 break;
795 case BMP_RLE8_EOBMP:
796 /* end of bitmap */
797 decode = 0;
798 break;
799 case BMP_RLE8_DELTA:
800 /* delta run */
801 x += bmap[2];
802 y -= bmap[3];
803 /* 16bpix, 2-byte per pixel, x should *2 */
804 fb = (uchar *) (lcd_base + (y + y_off - 1)
805 * lcd_line_length + (x + x_off) * 2);
806 bmap += 4;
807 break;
808 default:
809 /* unencoded run */
810 runlen = bmap[1];
811 bmap += 2;
812 if (y < height) {
813 if (x < width) {
814 if (x + runlen > width)
815 cnt = width - x;
816 else
817 cnt = runlen;
818 draw_unencoded_bitmap(
819 (ushort **)&fb,
820 bmap, cmap, cnt);
821 }
822 x += runlen;
823 }
824 bmap += runlen;
825 if (runlen & 1)
826 bmap++;
827 }
828 } else {
829 /* encoded run */
830 if (y < height) {
831 runlen = bmap[0];
832 if (x < width) {
833 /* aggregate the same code */
834 while (bmap[0] == 0xff &&
835 bmap[2] != BMP_RLE8_ESCAPE &&
836 bmap[1] == bmap[3]) {
837 runlen += bmap[2];
838 bmap += 2;
839 }
840 if (x + runlen > width)
841 cnt = width - x;
842 else
843 cnt = runlen;
844 draw_encoded_bitmap((ushort **)&fb,
845 cmap[bmap[1]], cnt);
846 }
847 x += runlen;
848 }
849 bmap += 2;
850 }
851 }
852}
853#endif
854
Anatolij Gustschind23019f2012-09-22 06:55:53 +0000855#if defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +0000856#define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
Anatolij Gustschind23019f2012-09-22 06:55:53 +0000857#else
858#define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +0000859#endif
860
861#if defined(CONFIG_BMP_16BPP)
862#if defined(CONFIG_ATMEL_LCD_BGR555)
863static inline void fb_put_word(uchar **fb, uchar **from)
864{
865 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
866 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
867 *from += 2;
868}
869#else
870static inline void fb_put_word(uchar **fb, uchar **from)
871{
872 *(*fb)++ = *(*from)++;
873 *(*fb)++ = *(*from)++;
874}
875#endif
876#endif /* CONFIG_BMP_16BPP */
877
wdenk8655b6f2004-10-09 23:25:58 +0000878int lcd_display_bitmap(ulong bmp_image, int x, int y)
879{
Anatolij Gustschin00cc5592009-02-25 20:28:13 +0100880#if !defined(CONFIG_MCC200)
881 ushort *cmap = NULL;
882#endif
883 ushort *cmap_base = NULL;
wdenk8655b6f2004-10-09 23:25:58 +0000884 ushort i, j;
885 uchar *fb;
886 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
887 uchar *bmap;
Tom Wai-Hong Tamfecac462012-09-28 15:11:14 +0000888 ushort padded_width;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100889 unsigned long width, height, byte_width;
Wolfgang Denke8143e72006-08-30 23:09:00 +0200890 unsigned long pwidth = panel_info.vl_col;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100891 unsigned colors, bpix, bmp_bpix;
wdenk8655b6f2004-10-09 23:25:58 +0000892
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000893 if (!bmp || !(bmp->header.signature[0] == 'B' &&
894 bmp->header.signature[1] == 'M')) {
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000895 printf("Error: no valid bmp image at %lx\n", bmp_image);
896
wdenk8655b6f2004-10-09 23:25:58 +0000897 return 1;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100898 }
wdenk8655b6f2004-10-09 23:25:58 +0000899
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000900 width = le32_to_cpu(bmp->header.width);
901 height = le32_to_cpu(bmp->header.height);
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100902 bmp_bpix = le16_to_cpu(bmp->header.bit_count);
903 colors = 1 << bmp_bpix;
wdenk8655b6f2004-10-09 23:25:58 +0000904
905 bpix = NBITS(panel_info.vl_bpix);
906
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000907 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100908 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
909 bpix, bmp_bpix);
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000910
wdenk8655b6f2004-10-09 23:25:58 +0000911 return 1;
912 }
913
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100914 /* We support displaying 8bpp BMPs on 16bpp LCDs */
Nikita Kiryanovdad631c2012-12-20 00:52:34 +0000915 if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) {
wdenk8655b6f2004-10-09 23:25:58 +0000916 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
917 bpix,
918 le16_to_cpu(bmp->header.bit_count));
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000919
wdenk8655b6f2004-10-09 23:25:58 +0000920 return 1;
921 }
922
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000923 debug("Display-bmp: %d x %d with %d colors\n",
wdenk8655b6f2004-10-09 23:25:58 +0000924 (int)width, (int)height, (int)colors);
925
Wolfgang Denkf6414712006-10-20 15:51:21 +0200926#if !defined(CONFIG_MCC200)
927 /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100928 if (bmp_bpix == 8) {
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000929 cmap = configuration_get_cmap();
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100930 cmap_base = cmap;
931
wdenk8655b6f2004-10-09 23:25:58 +0000932 /* Set color map */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000933 for (i = 0; i < colors; ++i) {
wdenk8655b6f2004-10-09 23:25:58 +0000934 bmp_color_table_entry_t cte = bmp->color_table[i];
Mark Jackson1464eff2008-08-01 09:48:29 +0100935#if !defined(CONFIG_ATMEL_LCD)
wdenk8655b6f2004-10-09 23:25:58 +0000936 ushort colreg =
937 ( ((cte.red) << 8) & 0xf800) |
Wolfgang Denk59d80bf2005-09-21 15:24:52 +0200938 ( ((cte.green) << 3) & 0x07e0) |
939 ( ((cte.blue) >> 3) & 0x001f) ;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200940#ifdef CONFIG_SYS_INVERT_COLORS
wdenk25d67122004-12-10 11:40:40 +0000941 *cmap = 0xffff - colreg;
wdenk8655b6f2004-10-09 23:25:58 +0000942#else
wdenk25d67122004-12-10 11:40:40 +0000943 *cmap = colreg;
944#endif
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100945#if defined(CONFIG_MPC823)
wdenk25d67122004-12-10 11:40:40 +0000946 cmap--;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100947#else
948 cmap++;
wdenk8655b6f2004-10-09 23:25:58 +0000949#endif
Mark Jackson1464eff2008-08-01 09:48:29 +0100950#else /* CONFIG_ATMEL_LCD */
951 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
952#endif
wdenk8655b6f2004-10-09 23:25:58 +0000953 }
954 }
Wolfgang Denkf6414712006-10-20 15:51:21 +0200955#endif
wdenk8655b6f2004-10-09 23:25:58 +0000956
Wolfgang Denke8143e72006-08-30 23:09:00 +0200957 /*
958 * BMP format for Monochrome assumes that the state of a
959 * pixel is described on a per Bit basis, not per Byte.
960 * So, in case of Monochrome BMP we should align widths
961 * on a byte boundary and convert them from Bit to Byte
962 * units.
Wolfgang Denk511d0c72006-10-09 00:42:01 +0200963 * Probably, PXA250 and MPC823 process 1bpp BMP images in
964 * their own ways, so make the converting to be MCC200
Wolfgang Denke8143e72006-08-30 23:09:00 +0200965 * specific.
966 */
967#if defined(CONFIG_MCC200)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000968 if (bpix == 1) {
Wolfgang Denke8143e72006-08-30 23:09:00 +0200969 width = ((width + 7) & ~7) >> 3;
970 x = ((x + 7) & ~7) >> 3;
971 pwidth= ((pwidth + 7) & ~7) >> 3;
972 }
973#endif
974
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000975 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200976
977#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Nikita Kiryanov7c7e2802012-08-09 00:14:51 +0000978 splash_align_axis(&x, pwidth, width);
979 splash_align_axis(&y, panel_info.vl_row, height);
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200980#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
981
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000982 if ((x + width) > pwidth)
Wolfgang Denke8143e72006-08-30 23:09:00 +0200983 width = pwidth - x;
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000984 if ((y + height) > panel_info.vl_row)
wdenk8655b6f2004-10-09 23:25:58 +0000985 height = panel_info.vl_row - y;
986
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000987 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk8655b6f2004-10-09 23:25:58 +0000988 fb = (uchar *) (lcd_base +
Liu Ying8d46d5b2011-01-11 15:29:58 +0800989 (y + height - 1) * lcd_line_length + x * bpix / 8);
Mark Jacksona303dfb2009-02-06 10:37:49 +0100990
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100991 switch (bmp_bpix) {
Mark Jacksona303dfb2009-02-06 10:37:49 +0100992 case 1: /* pass through */
993 case 8:
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000994#ifdef CONFIG_LCD_BMP_RLE8
995 if (le32_to_cpu(bmp->header.compression) == BMP_BI_RLE8) {
996 if (bpix != 16) {
997 /* TODO implement render code for bpix != 16 */
998 printf("Error: only support 16 bpix");
999 return 1;
1000 }
1001 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
1002 break;
1003 }
1004#endif
1005
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +01001006 if (bpix != 16)
1007 byte_width = width;
1008 else
1009 byte_width = width * 2;
1010
Mark Jacksona303dfb2009-02-06 10:37:49 +01001011 for (i = 0; i < height; ++i) {
1012 WATCHDOG_RESET();
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +01001013 for (j = 0; j < width; j++) {
1014 if (bpix != 16) {
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +00001015 FB_PUT_BYTE(fb, bmap);
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +01001016 } else {
1017 *(uint16_t *)fb = cmap_base[*(bmap++)];
1018 fb += sizeof(uint16_t) / sizeof(*fb);
1019 }
1020 }
Tom Wai-Hong Tamfecac462012-09-28 15:11:14 +00001021 bmap += (padded_width - width);
Jeroen Hofstee6b035142013-01-12 12:07:56 +00001022 fb -= byte_width + lcd_line_length;
Mark Jacksona303dfb2009-02-06 10:37:49 +01001023 }
1024 break;
1025
1026#if defined(CONFIG_BMP_16BPP)
1027 case 16:
1028 for (i = 0; i < height; ++i) {
1029 WATCHDOG_RESET();
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +00001030 for (j = 0; j < width; j++)
1031 fb_put_word(&fb, &bmap);
1032
Tom Wai-Hong Tamfecac462012-09-28 15:11:14 +00001033 bmap += (padded_width - width) * 2;
Jeroen Hofstee6b035142013-01-12 12:07:56 +00001034 fb -= width * 2 + lcd_line_length;
Mark Jacksona303dfb2009-02-06 10:37:49 +01001035 }
1036 break;
1037#endif /* CONFIG_BMP_16BPP */
1038
Donghwa Leefb6a9aa2012-05-09 19:23:37 +00001039#if defined(CONFIG_BMP_32BPP)
1040 case 32:
1041 for (i = 0; i < height; ++i) {
1042 for (j = 0; j < width; j++) {
1043 *(fb++) = *(bmap++);
1044 *(fb++) = *(bmap++);
1045 *(fb++) = *(bmap++);
1046 *(fb++) = *(bmap++);
1047 }
Jeroen Hofstee6b035142013-01-12 12:07:56 +00001048 fb -= lcd_line_length + width * (bpix / 8);
Donghwa Leefb6a9aa2012-05-09 19:23:37 +00001049 }
1050 break;
1051#endif /* CONFIG_BMP_32BPP */
Mark Jacksona303dfb2009-02-06 10:37:49 +01001052 default:
1053 break;
1054 };
wdenk8655b6f2004-10-09 23:25:58 +00001055
Simon Glass9a8efc42012-10-30 13:40:18 +00001056 lcd_sync();
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001057 return 0;
wdenk8655b6f2004-10-09 23:25:58 +00001058}
Jon Loeligerc3517f92007-07-08 18:10:08 -05001059#endif
wdenk8655b6f2004-10-09 23:25:58 +00001060
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001061static void *lcd_logo(void)
wdenk8655b6f2004-10-09 23:25:58 +00001062{
wdenk8655b6f2004-10-09 23:25:58 +00001063#ifdef CONFIG_SPLASH_SCREEN
1064 char *s;
1065 ulong addr;
1066 static int do_splash = 1;
1067
1068 if (do_splash && (s = getenv("splashimage")) != NULL) {
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001069 int x = 0, y = 0;
wdenk8655b6f2004-10-09 23:25:58 +00001070 do_splash = 0;
1071
Nikita Kiryanov581bb412013-01-30 21:39:57 +00001072 if (splash_screen_prepare())
Robert Winklerdd4425e2013-06-17 11:31:29 -07001073 return (void *)lcd_base;
Nikita Kiryanov581bb412013-01-30 21:39:57 +00001074
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001075 addr = simple_strtoul (s, NULL, 16);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001076
Anatolij Gustschinff8fb562013-07-02 00:04:05 +02001077 splash_get_pos(&x, &y);
Matthias Weisser1ca298c2009-07-09 16:07:30 +02001078
Nikita Kiryanovd3a555e2012-08-09 00:14:50 +00001079 if (bmp_display(addr, x, y) == 0)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001080 return (void *)lcd_base;
wdenk8655b6f2004-10-09 23:25:58 +00001081 }
1082#endif /* CONFIG_SPLASH_SCREEN */
1083
Anatolij Gustschin2b5cb3d2012-04-27 04:41:27 +00001084 bitmap_plot(0, 0);
wdenk8655b6f2004-10-09 23:25:58 +00001085
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +02001086#ifdef CONFIG_LCD_INFO
1087 console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
1088 console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
1089 lcd_show_board_info();
1090#endif /* CONFIG_LCD_INFO */
Stelian Pop39cf4802008-05-09 21:57:18 +02001091
wdenk88804d12005-07-04 00:03:16 +00001092#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001093 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
wdenk8655b6f2004-10-09 23:25:58 +00001094#else
Nikita Kiryanov8f47d912012-05-24 01:42:38 +00001095 return (void *)lcd_base;
Jeroen Hofstee6b035142013-01-12 12:07:56 +00001096#endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
wdenk8655b6f2004-10-09 23:25:58 +00001097}
1098
Nikita Kiryanovc0880482013-02-24 21:28:43 +00001099#ifdef CONFIG_SPLASHIMAGE_GUARD
1100static int on_splashimage(const char *name, const char *value, enum env_op op,
1101 int flags)
1102{
1103 ulong addr;
1104 int aligned;
1105
1106 if (op == env_op_delete)
1107 return 0;
1108
1109 addr = simple_strtoul(value, NULL, 16);
1110 /* See README.displaying-bmps */
1111 aligned = (addr % 4 == 2);
1112 if (!aligned) {
1113 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1114 return -1;
1115 }
1116
1117 return 0;
1118}
1119
1120U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1121#endif
1122
Vadim Bendebury395166c2012-09-28 15:11:13 +00001123void lcd_position_cursor(unsigned col, unsigned row)
1124{
1125 console_col = min(col, CONSOLE_COLS - 1);
1126 console_row = min(row, CONSOLE_ROWS - 1);
1127}
1128
1129int lcd_get_pixel_width(void)
1130{
1131 return panel_info.vl_col;
1132}
1133
1134int lcd_get_pixel_height(void)
1135{
1136 return panel_info.vl_row;
1137}
1138
1139int lcd_get_screen_rows(void)
1140{
1141 return CONSOLE_ROWS;
1142}
1143
1144int lcd_get_screen_columns(void)
1145{
1146 return CONSOLE_COLS;
1147}
Stephen Warren6a195d22013-05-27 18:31:17 +00001148
1149#if defined(CONFIG_LCD_DT_SIMPLEFB)
1150static int lcd_dt_simplefb_configure_node(void *blob, int off)
1151{
1152 u32 stride;
1153 fdt32_t cells[2];
1154 int ret;
Stephen Warren5af7d0f2013-06-13 17:13:11 -06001155 static const char format[] =
Stephen Warren6a195d22013-05-27 18:31:17 +00001156#if LCD_BPP == LCD_COLOR16
1157 "r5g6b5";
1158#else
1159 "";
1160#endif
1161
1162 if (!format[0])
1163 return -1;
1164
1165 stride = panel_info.vl_col * 2;
1166
1167 cells[0] = cpu_to_fdt32(gd->fb_base);
1168 cells[1] = cpu_to_fdt32(stride * panel_info.vl_row);
1169 ret = fdt_setprop(blob, off, "reg", cells, sizeof(cells[0]) * 2);
1170 if (ret < 0)
1171 return -1;
1172
1173 cells[0] = cpu_to_fdt32(panel_info.vl_col);
1174 ret = fdt_setprop(blob, off, "width", cells, sizeof(cells[0]));
1175 if (ret < 0)
1176 return -1;
1177
1178 cells[0] = cpu_to_fdt32(panel_info.vl_row);
1179 ret = fdt_setprop(blob, off, "height", cells, sizeof(cells[0]));
1180 if (ret < 0)
1181 return -1;
1182
1183 cells[0] = cpu_to_fdt32(stride);
1184 ret = fdt_setprop(blob, off, "stride", cells, sizeof(cells[0]));
1185 if (ret < 0)
1186 return -1;
1187
1188 ret = fdt_setprop(blob, off, "format", format, strlen(format) + 1);
1189 if (ret < 0)
1190 return -1;
1191
1192 ret = fdt_delprop(blob, off, "status");
1193 if (ret < 0)
1194 return -1;
1195
1196 return 0;
1197}
1198
1199int lcd_dt_simplefb_add_node(void *blob)
1200{
Stephen Warren5af7d0f2013-06-13 17:13:11 -06001201 static const char compat[] = "simple-framebuffer";
1202 static const char disabled[] = "disabled";
Stephen Warren6a195d22013-05-27 18:31:17 +00001203 int off, ret;
1204
1205 off = fdt_add_subnode(blob, 0, "framebuffer");
1206 if (off < 0)
1207 return -1;
1208
1209 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
1210 if (ret < 0)
1211 return -1;
1212
1213 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
1214 if (ret < 0)
1215 return -1;
1216
1217 return lcd_dt_simplefb_configure_node(blob, off);
1218}
1219
1220int lcd_dt_simplefb_enable_existing_node(void *blob)
1221{
1222 int off;
1223
1224 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
1225 if (off < 0)
1226 return -1;
1227
1228 return lcd_dt_simplefb_configure_node(blob, off);
1229}
1230#endif