blob: edae835fb0be1e6eb1fccdbf373b42dfc588ee31 [file] [log] [blame]
wdenk9ca7bbc2004-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 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26/************************************************************************/
27/* ** HEADER FILES */
28/************************************************************************/
29
30/* #define DEBUG */
31
32#include <config.h>
33#include <common.h>
34#include <command.h>
wdenk9ca7bbc2004-10-09 23:25:58 +000035#include <stdarg.h>
Nikita Kiryanov2f3e2ca2013-02-24 21:28:43 +000036#include <search.h>
37#include <env_callback.h>
wdenk9ca7bbc2004-10-09 23:25:58 +000038#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020039#include <stdio_dev.h>
wdenk9ca7bbc2004-10-09 23:25:58 +000040#if defined(CONFIG_POST)
41#include <post.h>
42#endif
43#include <lcd.h>
wdenkbc3202a2005-04-03 23:11:38 +000044#include <watchdog.h>
wdenk9ca7bbc2004-10-09 23:25:58 +000045
Marek Vasut85cc88a2011-11-26 07:20:07 +010046#if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
47 defined(CONFIG_CPU_MONAHANS)
48#define CONFIG_CPU_PXA
wdenk9ca7bbc2004-10-09 23:25:58 +000049#include <asm/byteorder.h>
50#endif
51
52#if defined(CONFIG_MPC823)
wdenk9ca7bbc2004-10-09 23:25:58 +000053#include <lcdvideo.h>
54#endif
55
Stelian Popf6f86652008-05-09 21:57:18 +020056#if defined(CONFIG_ATMEL_LCD)
57#include <atmel_lcdc.h>
Stelian Popf6f86652008-05-09 21:57:18 +020058#endif
59
wdenk9ca7bbc2004-10-09 23:25:58 +000060/************************************************************************/
61/* ** FONT DATA */
62/************************************************************************/
63#include <video_font.h> /* Get font data, width and height */
Che-Liang Chiou41132c02011-10-21 17:04:21 +080064#include <video_font_data.h>
wdenk9ca7bbc2004-10-09 23:25:58 +000065
wdenk2b9d1862005-07-04 00:03:16 +000066/************************************************************************/
67/* ** LOGO DATA */
68/************************************************************************/
69#ifdef CONFIG_LCD_LOGO
70# include <bmp_logo.h> /* Get logo data, width and height */
Che-Liang Chiou5639fc62011-10-20 23:04:20 +000071# include <bmp_logo_data.h>
Alessandro Rubini2d68c262010-03-13 17:44:08 +010072# if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
wdenk2b9d1862005-07-04 00:03:16 +000073# error Default Color Map overlaps with Logo Color Map
74# endif
75#endif
wdenk9ca7bbc2004-10-09 23:25:58 +000076
Simon Glass599a4df2012-10-17 13:24:54 +000077#ifndef CONFIG_LCD_ALIGNMENT
78#define CONFIG_LCD_ALIGNMENT PAGE_SIZE
79#endif
80
Simon Glassaf3e2802012-10-17 13:24:59 +000081/* By default we scroll by a single line */
82#ifndef CONFIG_CONSOLE_SCROLL_LINES
83#define CONFIG_CONSOLE_SCROLL_LINES 1
84#endif
85
Jeroen Hofsteecdc348a2013-01-12 12:07:59 +000086/************************************************************************/
87/* ** CONSOLE DEFINITIONS & FUNCTIONS */
88/************************************************************************/
89#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
90# define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
91 / VIDEO_FONT_HEIGHT)
92#else
93# define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
94#endif
95
96#define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
97#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
98#define CONSOLE_ROW_FIRST lcd_console_address
99#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
100#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
101 - CONSOLE_ROW_SIZE)
102#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
103#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
Wolfgang Denk6405a152006-03-31 18:32:53 +0200104
Jeroen Hofsteecdc348a2013-01-12 12:07:59 +0000105#if LCD_BPP == LCD_MONOCHROME
106# define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \
107 (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7)
108#elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16)
109# define COLOR_MASK(c) (c)
110#else
111# error Unsupported LCD BPP.
112#endif
113
wdenk9ca7bbc2004-10-09 23:25:58 +0000114DECLARE_GLOBAL_DATA_PTR;
wdenk9ca7bbc2004-10-09 23:25:58 +0000115
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000116static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
117static inline void lcd_puts_xy(ushort x, ushort y, uchar *s);
118static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
wdenk9ca7bbc2004-10-09 23:25:58 +0000119
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000120static int lcd_init(void *lcdbase);
wdenk9ca7bbc2004-10-09 23:25:58 +0000121
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000122static void *lcd_logo(void);
wdenk9ca7bbc2004-10-09 23:25:58 +0000123
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000124static int lcd_getbgcolor(void);
125static void lcd_setfgcolor(int color);
126static void lcd_setbgcolor(int color);
wdenk9ca7bbc2004-10-09 23:25:58 +0000127
Wolfgang Denk67f53912013-01-05 09:45:48 +0000128static int lcd_color_fg;
129static int lcd_color_bg;
Jeroen Hofsteeb9092e62013-01-22 10:44:11 +0000130int lcd_line_length;
Wolfgang Denk67f53912013-01-05 09:45:48 +0000131
wdenk9ca7bbc2004-10-09 23:25:58 +0000132char lcd_is_enabled = 0;
wdenk9ca7bbc2004-10-09 23:25:58 +0000133
Jeroen Hofsteeb9092e62013-01-22 10:44:11 +0000134static short console_col;
135static short console_row;
Simon Glassef45ffd2012-10-30 13:40:18 +0000136
Jeroen Hofsteeb9092e62013-01-22 10:44:11 +0000137static void *lcd_console_address;
Jeroen Hofstee881c4ec2013-01-22 10:44:12 +0000138static void *lcd_base; /* Start of framebuffer memory */
Simon Glassef45ffd2012-10-30 13:40:18 +0000139
wdenk9ca7bbc2004-10-09 23:25:58 +0000140static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
wdenk9ca7bbc2004-10-09 23:25:58 +0000141
142/************************************************************************/
143
Simon Glassef45ffd2012-10-30 13:40:18 +0000144/* Flush LCD activity to the caches */
145void lcd_sync(void)
146{
147 /*
148 * flush_dcache_range() is declared in common.h but it seems that some
149 * architectures do not actually implement it. Is there a way to find
150 * out whether it exists? For now, ARM is safe.
151 */
152#if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
153 int line_length;
154
155 if (lcd_flush_dcache)
156 flush_dcache_range((u32)lcd_base,
157 (u32)(lcd_base + lcd_get_size(&line_length)));
158#endif
159}
160
161void lcd_set_flush_dcache(int flush)
162{
163 lcd_flush_dcache = (flush != 0);
164}
165
wdenk9ca7bbc2004-10-09 23:25:58 +0000166/*----------------------------------------------------------------------*/
167
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000168static void console_scrollup(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000169{
Simon Glassaf3e2802012-10-17 13:24:59 +0000170 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
wdenk9ca7bbc2004-10-09 23:25:58 +0000171
Simon Glassaf3e2802012-10-17 13:24:59 +0000172 /* Copy up rows ignoring those that will be overwritten */
173 memcpy(CONSOLE_ROW_FIRST,
174 lcd_console_address + CONSOLE_ROW_SIZE * rows,
175 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
176
177 /* Clear the last rows */
178 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
179 COLOR_MASK(lcd_color_bg),
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000180 CONSOLE_ROW_SIZE * rows);
Simon Glassaf3e2802012-10-17 13:24:59 +0000181
Simon Glassef45ffd2012-10-30 13:40:18 +0000182 lcd_sync();
Simon Glassaf3e2802012-10-17 13:24:59 +0000183 console_row -= rows;
wdenk9ca7bbc2004-10-09 23:25:58 +0000184}
185
186/*----------------------------------------------------------------------*/
187
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000188static inline void console_back(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000189{
190 if (--console_col < 0) {
191 console_col = CONSOLE_COLS-1 ;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000192 if (--console_row < 0)
wdenk9ca7bbc2004-10-09 23:25:58 +0000193 console_row = 0;
wdenk9ca7bbc2004-10-09 23:25:58 +0000194 }
195
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000196 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
197 console_row * VIDEO_FONT_HEIGHT, ' ');
wdenk9ca7bbc2004-10-09 23:25:58 +0000198}
199
200/*----------------------------------------------------------------------*/
201
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000202static inline void console_newline(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000203{
wdenk9ca7bbc2004-10-09 23:25:58 +0000204 console_col = 0;
205
206 /* Check if we need to scroll the terminal */
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000207 if (++console_row >= CONSOLE_ROWS)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000208 console_scrollup();
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000209 else
Simon Glassef45ffd2012-10-30 13:40:18 +0000210 lcd_sync();
wdenk9ca7bbc2004-10-09 23:25:58 +0000211}
212
213/*----------------------------------------------------------------------*/
214
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000215void lcd_putc(const char c)
wdenk9ca7bbc2004-10-09 23:25:58 +0000216{
217 if (!lcd_is_enabled) {
218 serial_putc(c);
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000219
wdenk9ca7bbc2004-10-09 23:25:58 +0000220 return;
221 }
222
223 switch (c) {
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000224 case '\r':
225 console_col = 0;
wdenk9ca7bbc2004-10-09 23:25:58 +0000226
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000227 return;
228 case '\n':
229 console_newline();
wdenk9ca7bbc2004-10-09 23:25:58 +0000230
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000231 return;
wdenk9ca7bbc2004-10-09 23:25:58 +0000232 case '\t': /* Tab (8 chars alignment) */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000233 console_col += 8;
234 console_col &= ~7;
wdenk9ca7bbc2004-10-09 23:25:58 +0000235
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000236 if (console_col >= CONSOLE_COLS)
237 console_newline();
wdenk9ca7bbc2004-10-09 23:25:58 +0000238
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000239 return;
240 case '\b':
241 console_back();
wdenk9ca7bbc2004-10-09 23:25:58 +0000242
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000243 return;
244 default:
245 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
246 console_row * VIDEO_FONT_HEIGHT, c);
247 if (++console_col >= CONSOLE_COLS)
248 console_newline();
wdenk9ca7bbc2004-10-09 23:25:58 +0000249 }
wdenk9ca7bbc2004-10-09 23:25:58 +0000250}
251
252/*----------------------------------------------------------------------*/
253
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000254void lcd_puts(const char *s)
wdenk9ca7bbc2004-10-09 23:25:58 +0000255{
256 if (!lcd_is_enabled) {
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000257 serial_puts(s);
258
wdenk9ca7bbc2004-10-09 23:25:58 +0000259 return;
260 }
261
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000262 while (*s)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000263 lcd_putc(*s++);
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000264
Simon Glassef45ffd2012-10-30 13:40:18 +0000265 lcd_sync();
wdenk9ca7bbc2004-10-09 23:25:58 +0000266}
267
Haavard Skinnemoen010c7732008-09-01 16:21:20 +0200268/*----------------------------------------------------------------------*/
269
270void lcd_printf(const char *fmt, ...)
271{
272 va_list args;
273 char buf[CONFIG_SYS_PBSIZE];
274
275 va_start(args, fmt);
276 vsprintf(buf, fmt, args);
277 va_end(args);
278
279 lcd_puts(buf);
280}
281
wdenk9ca7bbc2004-10-09 23:25:58 +0000282/************************************************************************/
283/* ** Low-Level Graphics Routines */
284/************************************************************************/
285
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000286static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
wdenk9ca7bbc2004-10-09 23:25:58 +0000287{
288 uchar *dest;
Marek Vasutdf5d8c12011-09-26 02:26:04 +0200289 ushort row;
290
Anatolij Gustschin81b99b82012-04-27 04:41:16 +0000291#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
292 y += BMP_LOGO_HEIGHT;
293#endif
294
Marek Vasutdf5d8c12011-09-26 02:26:04 +0200295#if LCD_BPP == LCD_MONOCHROME
296 ushort off = x * (1 << LCD_BPP) % 8;
297#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000298
299 dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8);
wdenk9ca7bbc2004-10-09 23:25:58 +0000300
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000301 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000302 uchar *s = str;
wdenk9ca7bbc2004-10-09 23:25:58 +0000303 int i;
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100304#if LCD_BPP == LCD_COLOR16
305 ushort *d = (ushort *)dest;
306#else
307 uchar *d = dest;
308#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000309
310#if LCD_BPP == LCD_MONOCHROME
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000311 uchar rest = *d & -(1 << (8 - off));
wdenk9ca7bbc2004-10-09 23:25:58 +0000312 uchar sym;
313#endif
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000314 for (i = 0; i < count; ++i) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000315 uchar c, bits;
316
317 c = *s++;
318 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
319
320#if LCD_BPP == LCD_MONOCHROME
321 sym = (COLOR_MASK(lcd_color_fg) & bits) |
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000322 (COLOR_MASK(lcd_color_bg) & ~bits);
wdenk9ca7bbc2004-10-09 23:25:58 +0000323
324 *d++ = rest | (sym >> off);
325 rest = sym << (8-off);
326#elif LCD_BPP == LCD_COLOR8
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000327 for (c = 0; c < 8; ++c) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000328 *d++ = (bits & 0x80) ?
329 lcd_color_fg : lcd_color_bg;
330 bits <<= 1;
331 }
332#elif LCD_BPP == LCD_COLOR16
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000333 for (c = 0; c < 8; ++c) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000334 *d++ = (bits & 0x80) ?
335 lcd_color_fg : lcd_color_bg;
336 bits <<= 1;
337 }
338#endif
339 }
340#if LCD_BPP == LCD_MONOCHROME
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000341 *d = rest | (*d & ((1 << (8 - off)) - 1));
wdenk9ca7bbc2004-10-09 23:25:58 +0000342#endif
343 }
344}
345
346/*----------------------------------------------------------------------*/
347
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000348static inline void lcd_puts_xy(ushort x, ushort y, uchar *s)
wdenk9ca7bbc2004-10-09 23:25:58 +0000349{
Anatolij Gustschin81b99b82012-04-27 04:41:16 +0000350 lcd_drawchars(x, y, s, strlen((char *)s));
wdenk9ca7bbc2004-10-09 23:25:58 +0000351}
352
353/*----------------------------------------------------------------------*/
354
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000355static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
wdenk9ca7bbc2004-10-09 23:25:58 +0000356{
Anatolij Gustschin81b99b82012-04-27 04:41:16 +0000357 lcd_drawchars(x, y, &c, 1);
wdenk9ca7bbc2004-10-09 23:25:58 +0000358}
359
360/************************************************************************/
361/** Small utility to check that you got the colours right */
362/************************************************************************/
363#ifdef LCD_TEST_PATTERN
364
365#define N_BLK_VERT 2
366#define N_BLK_HOR 3
367
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000368static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
wdenk9ca7bbc2004-10-09 23:25:58 +0000369 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
370 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
371};
372
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000373static void test_pattern(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000374{
375 ushort v_max = panel_info.vl_row;
376 ushort h_max = panel_info.vl_col;
377 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
378 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
379 ushort v, h;
380 uchar *pix = (uchar *)lcd_base;
381
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000382 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
wdenk9ca7bbc2004-10-09 23:25:58 +0000383 h_max, v_max, h_step, v_step);
384
385 /* WARNING: Code silently assumes 8bit/pixel */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000386 for (v = 0; v < v_max; ++v) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000387 uchar iy = v / v_step;
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000388 for (h = 0; h < h_max; ++h) {
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000389 uchar ix = N_BLK_HOR * iy + h / h_step;
wdenk9ca7bbc2004-10-09 23:25:58 +0000390 *pix++ = test_colors[ix];
391 }
392 }
393}
394#endif /* LCD_TEST_PATTERN */
395
396
397/************************************************************************/
398/* ** GENERIC Initialization Routines */
399/************************************************************************/
400
Simon Glass599a4df2012-10-17 13:24:54 +0000401int lcd_get_size(int *line_length)
402{
403 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
404 return *line_length * panel_info.vl_row;
405}
406
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000407int drv_lcd_init(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000408{
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200409 struct stdio_dev lcddev;
wdenk9ca7bbc2004-10-09 23:25:58 +0000410 int rc;
411
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000412 lcd_base = (void *) gd->fb_base;
wdenk9ca7bbc2004-10-09 23:25:58 +0000413
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000414 lcd_init(lcd_base); /* LCD initialization */
wdenk9ca7bbc2004-10-09 23:25:58 +0000415
416 /* Device initialization */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000417 memset(&lcddev, 0, sizeof(lcddev));
wdenk9ca7bbc2004-10-09 23:25:58 +0000418
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000419 strcpy(lcddev.name, "lcd");
wdenk9ca7bbc2004-10-09 23:25:58 +0000420 lcddev.ext = 0; /* No extensions */
421 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
422 lcddev.putc = lcd_putc; /* 'putc' function */
423 lcddev.puts = lcd_puts; /* 'puts' function */
424
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000425 rc = stdio_register(&lcddev);
wdenk9ca7bbc2004-10-09 23:25:58 +0000426
427 return (rc == 0) ? 1 : rc;
428}
429
430/*----------------------------------------------------------------------*/
Che-Liang Chiou2444b172011-10-20 23:07:03 +0000431void lcd_clear(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000432{
433#if LCD_BPP == LCD_MONOCHROME
434 /* Setting the palette */
435 lcd_initcolregs();
436
437#elif LCD_BPP == LCD_COLOR8
438 /* Setting the palette */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000439 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
440 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
441 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
442 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
443 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
444 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
445 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
446 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
447 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
wdenk9ca7bbc2004-10-09 23:25:58 +0000448#endif
449
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200450#ifndef CONFIG_SYS_WHITE_ON_BLACK
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000451 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
452 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
wdenk9ca7bbc2004-10-09 23:25:58 +0000453#else
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000454 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
455 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200456#endif /* CONFIG_SYS_WHITE_ON_BLACK */
wdenk9ca7bbc2004-10-09 23:25:58 +0000457
458#ifdef LCD_TEST_PATTERN
459 test_pattern();
460#else
461 /* set framebuffer to background color */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000462 memset((char *)lcd_base,
wdenk9ca7bbc2004-10-09 23:25:58 +0000463 COLOR_MASK(lcd_getbgcolor()),
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000464 lcd_line_length * panel_info.vl_row);
wdenk9ca7bbc2004-10-09 23:25:58 +0000465#endif
466 /* Paint the logo and retrieve LCD base address */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000467 debug("[LCD] Drawing the logo...\n");
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000468 lcd_console_address = lcd_logo();
wdenk9ca7bbc2004-10-09 23:25:58 +0000469
470 console_col = 0;
471 console_row = 0;
Simon Glassef45ffd2012-10-30 13:40:18 +0000472 lcd_sync();
wdenk9ca7bbc2004-10-09 23:25:58 +0000473}
474
Simon Glassef45ffd2012-10-30 13:40:18 +0000475static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
476 char *const argv[])
477{
478 lcd_clear();
479 return 0;
480}
481
wdenk9ca7bbc2004-10-09 23:25:58 +0000482U_BOOT_CMD(
Che-Liang Chiou2444b172011-10-20 23:07:03 +0000483 cls, 1, 1, do_lcd_clear,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600484 "clear screen",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200485 ""
wdenk9ca7bbc2004-10-09 23:25:58 +0000486);
487
488/*----------------------------------------------------------------------*/
489
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000490static int lcd_init(void *lcdbase)
wdenk9ca7bbc2004-10-09 23:25:58 +0000491{
492 /* Initialize the lcd controller */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000493 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
wdenk9ca7bbc2004-10-09 23:25:58 +0000494
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000495 lcd_ctrl_init(lcdbase);
Anatolij Gustschin02591592013-03-29 14:00:13 +0100496
497 /*
498 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi_b) ignores
499 * the 'lcdbase' argument and uses custom lcd base address
500 * by setting up gd->fb_base. Check for this condition and fixup
501 * 'lcd_base' address.
502 */
503 if ((unsigned long)lcdbase != gd->fb_base)
504 lcd_base = (void *)gd->fb_base;
505
506 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
507
Stephen Warrenefc8f792013-01-29 16:37:38 +0000508 lcd_get_size(&lcd_line_length);
509 lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
Haavard Skinnemoen7eb8b232008-09-01 16:21:21 +0200510 lcd_is_enabled = 1;
Che-Liang Chiou2444b172011-10-20 23:07:03 +0000511 lcd_clear();
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000512 lcd_enable();
wdenk9ca7bbc2004-10-09 23:25:58 +0000513
514 /* Initialize the console */
515 console_col = 0;
wdenk2b9d1862005-07-04 00:03:16 +0000516#ifdef CONFIG_LCD_INFO_BELOW_LOGO
wdenk9ca7bbc2004-10-09 23:25:58 +0000517 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
518#else
519 console_row = 1; /* leave 1 blank line below logo */
520#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000521
522 return 0;
523}
524
525
526/************************************************************************/
527/* ** ROM capable initialization part - needed to reserve FB memory */
528/************************************************************************/
529/*
530 * This is called early in the system initialization to grab memory
531 * for the LCD controller.
532 * Returns new address for monitor, after reserving LCD buffer memory
533 *
534 * Note that this is running from ROM, so no write access to global data.
535 */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000536ulong lcd_setmem(ulong addr)
wdenk9ca7bbc2004-10-09 23:25:58 +0000537{
538 ulong size;
Simon Glass599a4df2012-10-17 13:24:54 +0000539 int line_length;
wdenk9ca7bbc2004-10-09 23:25:58 +0000540
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000541 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
542 panel_info.vl_row, NBITS(panel_info.vl_bpix));
wdenk9ca7bbc2004-10-09 23:25:58 +0000543
Simon Glass599a4df2012-10-17 13:24:54 +0000544 size = lcd_get_size(&line_length);
wdenk9ca7bbc2004-10-09 23:25:58 +0000545
Simon Glass599a4df2012-10-17 13:24:54 +0000546 /* Round up to nearest full page, or MMU section if defined */
547 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
548 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
wdenk9ca7bbc2004-10-09 23:25:58 +0000549
550 /* Allocate pages for the frame buffer. */
551 addr -= size;
552
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000553 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
554 size >> 10, addr);
wdenk9ca7bbc2004-10-09 23:25:58 +0000555
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000556 return addr;
wdenk9ca7bbc2004-10-09 23:25:58 +0000557}
558
559/*----------------------------------------------------------------------*/
560
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000561static void lcd_setfgcolor(int color)
wdenk9ca7bbc2004-10-09 23:25:58 +0000562{
Stelian Popf6f86652008-05-09 21:57:18 +0200563 lcd_color_fg = color;
wdenk9ca7bbc2004-10-09 23:25:58 +0000564}
565
566/*----------------------------------------------------------------------*/
567
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000568static void lcd_setbgcolor(int color)
wdenk9ca7bbc2004-10-09 23:25:58 +0000569{
Stelian Popf6f86652008-05-09 21:57:18 +0200570 lcd_color_bg = color;
wdenk9ca7bbc2004-10-09 23:25:58 +0000571}
572
573/*----------------------------------------------------------------------*/
574
Wolfgang Denk67f53912013-01-05 09:45:48 +0000575int lcd_getfgcolor(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000576{
577 return lcd_color_fg;
578}
wdenk9ca7bbc2004-10-09 23:25:58 +0000579
580/*----------------------------------------------------------------------*/
581
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000582static int lcd_getbgcolor(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000583{
584 return lcd_color_bg;
585}
586
wdenk9ca7bbc2004-10-09 23:25:58 +0000587/************************************************************************/
588/* ** Chipset depending Bitmap / Logo stuff... */
589/************************************************************************/
Nikita Kiryanov22425272012-08-09 00:14:52 +0000590static inline ushort *configuration_get_cmap(void)
591{
592#if defined CONFIG_CPU_PXA
593 struct pxafb_info *fbi = &panel_info.pxa;
594 return (ushort *)fbi->palette;
595#elif defined(CONFIG_MPC823)
596 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
597 cpm8xx_t *cp = &(immr->im_cpm);
598 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
599#elif defined(CONFIG_ATMEL_LCD)
600 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
Anatolij Gustschin4bb5fa42012-09-22 06:55:53 +0000601#elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
602 return panel_info.cmap;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000603#elif defined(CONFIG_LCD_LOGO)
Anatolij Gustschin4bb5fa42012-09-22 06:55:53 +0000604 return bmp_logo_palette;
605#else
606 return NULL;
607#endif
Nikita Kiryanov22425272012-08-09 00:14:52 +0000608}
609
wdenk9ca7bbc2004-10-09 23:25:58 +0000610#ifdef CONFIG_LCD_LOGO
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000611void bitmap_plot(int x, int y)
wdenk9ca7bbc2004-10-09 23:25:58 +0000612{
Stelian Popf6f86652008-05-09 21:57:18 +0200613#ifdef CONFIG_ATMEL_LCD
Nikita Kiryanov22425272012-08-09 00:14:52 +0000614 uint *cmap = (uint *)bmp_logo_palette;
Stelian Popf6f86652008-05-09 21:57:18 +0200615#else
Nikita Kiryanov22425272012-08-09 00:14:52 +0000616 ushort *cmap = (ushort *)bmp_logo_palette;
Stelian Popf6f86652008-05-09 21:57:18 +0200617#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000618 ushort i, j;
619 uchar *bmap;
620 uchar *fb;
621 ushort *fb16;
Nikita Kiryanov22425272012-08-09 00:14:52 +0000622#if defined(CONFIG_MPC823)
623 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
624 cpm8xx_t *cp = &(immr->im_cpm);
wdenk9ca7bbc2004-10-09 23:25:58 +0000625#endif
Andre Renaudada32ec2013-02-13 17:48:00 +0000626 unsigned bpix = NBITS(panel_info.vl_bpix);
wdenk9ca7bbc2004-10-09 23:25:58 +0000627
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000628 debug("Logo: width %d height %d colors %d cmap %d\n",
wdenk9ca7bbc2004-10-09 23:25:58 +0000629 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
Anatolij Gustschin218e6a02012-04-27 04:41:06 +0000630 ARRAY_SIZE(bmp_logo_palette));
wdenk9ca7bbc2004-10-09 23:25:58 +0000631
632 bmap = &bmp_logo_bitmap[0];
Andre Renaudada32ec2013-02-13 17:48:00 +0000633 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
wdenk9ca7bbc2004-10-09 23:25:58 +0000634
Andre Renaudada32ec2013-02-13 17:48:00 +0000635 if (bpix < 12) {
Nikita Kiryanov22425272012-08-09 00:14:52 +0000636 /* Leave room for default color map
637 * default case: generic system with no cmap (most likely 16bpp)
638 * cmap was set to the source palette, so no change is done.
639 * This avoids even more ifdefs in the next stanza
640 */
641#if defined(CONFIG_MPC823)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000642 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
Stelian Popf6f86652008-05-09 21:57:18 +0200643#elif defined(CONFIG_ATMEL_LCD)
Nikita Kiryanov22425272012-08-09 00:14:52 +0000644 cmap = (uint *)configuration_get_cmap();
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100645#else
Nikita Kiryanov22425272012-08-09 00:14:52 +0000646 cmap = configuration_get_cmap();
wdenk9ca7bbc2004-10-09 23:25:58 +0000647#endif
648
649 WATCHDOG_RESET();
650
651 /* Set color map */
Anatolij Gustschin218e6a02012-04-27 04:41:06 +0000652 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000653 ushort colreg = bmp_logo_palette[i];
Stelian Popf6f86652008-05-09 21:57:18 +0200654#ifdef CONFIG_ATMEL_LCD
655 uint lut_entry;
656#ifdef CONFIG_ATMEL_LCD_BGR555
657 lut_entry = ((colreg & 0x000F) << 11) |
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000658 ((colreg & 0x00F0) << 2) |
659 ((colreg & 0x0F00) >> 7);
Stelian Popf6f86652008-05-09 21:57:18 +0200660#else /* CONFIG_ATMEL_LCD_RGB565 */
661 lut_entry = ((colreg & 0x000F) << 1) |
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000662 ((colreg & 0x00F0) << 3) |
663 ((colreg & 0x0F00) << 4);
Stelian Popf6f86652008-05-09 21:57:18 +0200664#endif
665 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
666 cmap++;
667#else /* !CONFIG_ATMEL_LCD */
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200668#ifdef CONFIG_SYS_INVERT_COLORS
wdenk9ca7bbc2004-10-09 23:25:58 +0000669 *cmap++ = 0xffff - colreg;
670#else
671 *cmap++ = colreg;
672#endif
Stelian Popf6f86652008-05-09 21:57:18 +0200673#endif /* CONFIG_ATMEL_LCD */
wdenk9ca7bbc2004-10-09 23:25:58 +0000674 }
675
676 WATCHDOG_RESET();
677
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000678 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
679 memcpy(fb, bmap, BMP_LOGO_WIDTH);
wdenk9ca7bbc2004-10-09 23:25:58 +0000680 bmap += BMP_LOGO_WIDTH;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000681 fb += panel_info.vl_col;
wdenk9ca7bbc2004-10-09 23:25:58 +0000682 }
683 }
684 else { /* true color mode */
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100685 u16 col16;
Andre Renaudada32ec2013-02-13 17:48:00 +0000686 fb16 = (ushort *)fb;
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000687 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
688 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100689 col16 = bmp_logo_palette[(bmap[j]-16)];
690 fb16[j] =
691 ((col16 & 0x000F) << 1) |
692 ((col16 & 0x00F0) << 3) |
693 ((col16 & 0x0F00) << 4);
wdenk9ca7bbc2004-10-09 23:25:58 +0000694 }
695 bmap += BMP_LOGO_WIDTH;
696 fb16 += panel_info.vl_col;
697 }
698 }
699
700 WATCHDOG_RESET();
Simon Glassef45ffd2012-10-30 13:40:18 +0000701 lcd_sync();
wdenk9ca7bbc2004-10-09 23:25:58 +0000702}
Anatolij Gustschin6f1378f2012-04-27 04:41:27 +0000703#else
704static inline void bitmap_plot(int x, int y) {}
wdenk9ca7bbc2004-10-09 23:25:58 +0000705#endif /* CONFIG_LCD_LOGO */
706
707/*----------------------------------------------------------------------*/
Jon Loeliger052fc842007-07-08 18:10:08 -0500708#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk9ca7bbc2004-10-09 23:25:58 +0000709/*
710 * Display the BMP file located at address bmp_image.
711 * Only uncompressed.
712 */
Matthias Weisser53884182009-07-09 16:07:30 +0200713
714#ifdef CONFIG_SPLASH_SCREEN_ALIGN
715#define BMP_ALIGN_CENTER 0x7FFF
Nikita Kiryanovb4eb54d2012-08-09 00:14:51 +0000716
717static void splash_align_axis(int *axis, unsigned long panel_size,
718 unsigned long picture_size)
719{
720 unsigned long panel_picture_delta = panel_size - picture_size;
721 unsigned long axis_alignment;
722
723 if (*axis == BMP_ALIGN_CENTER)
724 axis_alignment = panel_picture_delta / 2;
725 else if (*axis < 0)
726 axis_alignment = panel_picture_delta + *axis + 1;
727 else
728 return;
729
730 *axis = max(0, axis_alignment);
731}
Matthias Weisser53884182009-07-09 16:07:30 +0200732#endif
733
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000734
735#ifdef CONFIG_LCD_BMP_RLE8
736
737#define BMP_RLE8_ESCAPE 0
738#define BMP_RLE8_EOL 0
739#define BMP_RLE8_EOBMP 1
740#define BMP_RLE8_DELTA 2
741
742static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
743 int cnt)
744{
745 while (cnt > 0) {
746 *(*fbp)++ = cmap[*bmap++];
747 cnt--;
748 }
749}
750
751static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
752{
753 ushort *fb = *fbp;
754 int cnt_8copy = cnt >> 3;
755
756 cnt -= cnt_8copy << 3;
757 while (cnt_8copy > 0) {
758 *fb++ = c;
759 *fb++ = c;
760 *fb++ = c;
761 *fb++ = c;
762 *fb++ = c;
763 *fb++ = c;
764 *fb++ = c;
765 *fb++ = c;
766 cnt_8copy--;
767 }
768 while (cnt > 0) {
769 *fb++ = c;
770 cnt--;
771 }
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000772 *fbp = fb;
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000773}
774
775/*
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000776 * Do not call this function directly, must be called from lcd_display_bitmap.
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000777 */
778static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
779 int x_off, int y_off)
780{
781 uchar *bmap;
782 ulong width, height;
783 ulong cnt, runlen;
784 int x, y;
785 int decode = 1;
786
787 width = le32_to_cpu(bmp->header.width);
788 height = le32_to_cpu(bmp->header.height);
789 bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset);
790
791 x = 0;
792 y = height - 1;
793
794 while (decode) {
795 if (bmap[0] == BMP_RLE8_ESCAPE) {
796 switch (bmap[1]) {
797 case BMP_RLE8_EOL:
798 /* end of line */
799 bmap += 2;
800 x = 0;
801 y--;
802 /* 16bpix, 2-byte per pixel, width should *2 */
803 fb -= (width * 2 + lcd_line_length);
804 break;
805 case BMP_RLE8_EOBMP:
806 /* end of bitmap */
807 decode = 0;
808 break;
809 case BMP_RLE8_DELTA:
810 /* delta run */
811 x += bmap[2];
812 y -= bmap[3];
813 /* 16bpix, 2-byte per pixel, x should *2 */
814 fb = (uchar *) (lcd_base + (y + y_off - 1)
815 * lcd_line_length + (x + x_off) * 2);
816 bmap += 4;
817 break;
818 default:
819 /* unencoded run */
820 runlen = bmap[1];
821 bmap += 2;
822 if (y < height) {
823 if (x < width) {
824 if (x + runlen > width)
825 cnt = width - x;
826 else
827 cnt = runlen;
828 draw_unencoded_bitmap(
829 (ushort **)&fb,
830 bmap, cmap, cnt);
831 }
832 x += runlen;
833 }
834 bmap += runlen;
835 if (runlen & 1)
836 bmap++;
837 }
838 } else {
839 /* encoded run */
840 if (y < height) {
841 runlen = bmap[0];
842 if (x < width) {
843 /* aggregate the same code */
844 while (bmap[0] == 0xff &&
845 bmap[2] != BMP_RLE8_ESCAPE &&
846 bmap[1] == bmap[3]) {
847 runlen += bmap[2];
848 bmap += 2;
849 }
850 if (x + runlen > width)
851 cnt = width - x;
852 else
853 cnt = runlen;
854 draw_encoded_bitmap((ushort **)&fb,
855 cmap[bmap[1]], cnt);
856 }
857 x += runlen;
858 }
859 bmap += 2;
860 }
861 }
862}
863#endif
864
Anatolij Gustschin4bb5fa42012-09-22 06:55:53 +0000865#if defined(CONFIG_MPC823) || defined(CONFIG_MCC200)
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000866#define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
Anatolij Gustschin4bb5fa42012-09-22 06:55:53 +0000867#else
868#define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000869#endif
870
871#if defined(CONFIG_BMP_16BPP)
872#if defined(CONFIG_ATMEL_LCD_BGR555)
873static inline void fb_put_word(uchar **fb, uchar **from)
874{
875 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
876 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
877 *from += 2;
878}
879#else
880static inline void fb_put_word(uchar **fb, uchar **from)
881{
882 *(*fb)++ = *(*from)++;
883 *(*fb)++ = *(*from)++;
884}
885#endif
886#endif /* CONFIG_BMP_16BPP */
887
wdenk9ca7bbc2004-10-09 23:25:58 +0000888int lcd_display_bitmap(ulong bmp_image, int x, int y)
889{
Anatolij Gustschina11ca282009-02-25 20:28:13 +0100890#if !defined(CONFIG_MCC200)
891 ushort *cmap = NULL;
892#endif
893 ushort *cmap_base = NULL;
wdenk9ca7bbc2004-10-09 23:25:58 +0000894 ushort i, j;
895 uchar *fb;
896 bmp_image_t *bmp=(bmp_image_t *)bmp_image;
897 uchar *bmap;
Tom Wai-Hong Tam93f04d62012-09-28 15:11:14 +0000898 ushort padded_width;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100899 unsigned long width, height, byte_width;
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200900 unsigned long pwidth = panel_info.vl_col;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100901 unsigned colors, bpix, bmp_bpix;
wdenk9ca7bbc2004-10-09 23:25:58 +0000902
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000903 if (!bmp || !(bmp->header.signature[0] == 'B' &&
904 bmp->header.signature[1] == 'M')) {
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000905 printf("Error: no valid bmp image at %lx\n", bmp_image);
906
wdenk9ca7bbc2004-10-09 23:25:58 +0000907 return 1;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100908 }
wdenk9ca7bbc2004-10-09 23:25:58 +0000909
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000910 width = le32_to_cpu(bmp->header.width);
911 height = le32_to_cpu(bmp->header.height);
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100912 bmp_bpix = le16_to_cpu(bmp->header.bit_count);
913 colors = 1 << bmp_bpix;
wdenk9ca7bbc2004-10-09 23:25:58 +0000914
915 bpix = NBITS(panel_info.vl_bpix);
916
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000917 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100918 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
919 bpix, bmp_bpix);
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000920
wdenk9ca7bbc2004-10-09 23:25:58 +0000921 return 1;
922 }
923
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100924 /* We support displaying 8bpp BMPs on 16bpp LCDs */
Nikita Kiryanov8ef7f1f2012-12-20 00:52:34 +0000925 if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000926 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
927 bpix,
928 le16_to_cpu(bmp->header.bit_count));
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000929
wdenk9ca7bbc2004-10-09 23:25:58 +0000930 return 1;
931 }
932
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000933 debug("Display-bmp: %d x %d with %d colors\n",
wdenk9ca7bbc2004-10-09 23:25:58 +0000934 (int)width, (int)height, (int)colors);
935
Wolfgang Denk6d89f0c2006-10-20 15:51:21 +0200936#if !defined(CONFIG_MCC200)
937 /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100938 if (bmp_bpix == 8) {
Nikita Kiryanov22425272012-08-09 00:14:52 +0000939 cmap = configuration_get_cmap();
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100940 cmap_base = cmap;
941
wdenk9ca7bbc2004-10-09 23:25:58 +0000942 /* Set color map */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000943 for (i = 0; i < colors; ++i) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000944 bmp_color_table_entry_t cte = bmp->color_table[i];
Mark Jackson8886b532008-08-01 09:48:29 +0100945#if !defined(CONFIG_ATMEL_LCD)
wdenk9ca7bbc2004-10-09 23:25:58 +0000946 ushort colreg =
947 ( ((cte.red) << 8) & 0xf800) |
Wolfgang Denkc4df5a42005-09-21 15:24:52 +0200948 ( ((cte.green) << 3) & 0x07e0) |
949 ( ((cte.blue) >> 3) & 0x001f) ;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200950#ifdef CONFIG_SYS_INVERT_COLORS
wdenkb3a4a702004-12-10 11:40:40 +0000951 *cmap = 0xffff - colreg;
wdenk9ca7bbc2004-10-09 23:25:58 +0000952#else
wdenkb3a4a702004-12-10 11:40:40 +0000953 *cmap = colreg;
954#endif
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100955#if defined(CONFIG_MPC823)
wdenkb3a4a702004-12-10 11:40:40 +0000956 cmap--;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100957#else
958 cmap++;
wdenk9ca7bbc2004-10-09 23:25:58 +0000959#endif
Mark Jackson8886b532008-08-01 09:48:29 +0100960#else /* CONFIG_ATMEL_LCD */
961 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
962#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000963 }
964 }
Wolfgang Denk6d89f0c2006-10-20 15:51:21 +0200965#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000966
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200967 /*
968 * BMP format for Monochrome assumes that the state of a
969 * pixel is described on a per Bit basis, not per Byte.
970 * So, in case of Monochrome BMP we should align widths
971 * on a byte boundary and convert them from Bit to Byte
972 * units.
Wolfgang Denk4df0da52006-10-09 00:42:01 +0200973 * Probably, PXA250 and MPC823 process 1bpp BMP images in
974 * their own ways, so make the converting to be MCC200
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200975 * specific.
976 */
977#if defined(CONFIG_MCC200)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000978 if (bpix == 1) {
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200979 width = ((width + 7) & ~7) >> 3;
980 x = ((x + 7) & ~7) >> 3;
981 pwidth= ((pwidth + 7) & ~7) >> 3;
982 }
983#endif
984
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000985 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
Matthias Weisser53884182009-07-09 16:07:30 +0200986
987#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Nikita Kiryanovb4eb54d2012-08-09 00:14:51 +0000988 splash_align_axis(&x, pwidth, width);
989 splash_align_axis(&y, panel_info.vl_row, height);
Matthias Weisser53884182009-07-09 16:07:30 +0200990#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
991
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000992 if ((x + width) > pwidth)
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200993 width = pwidth - x;
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000994 if ((y + height) > panel_info.vl_row)
wdenk9ca7bbc2004-10-09 23:25:58 +0000995 height = panel_info.vl_row - y;
996
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000997 bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset);
wdenk9ca7bbc2004-10-09 23:25:58 +0000998 fb = (uchar *) (lcd_base +
Liu Ying1bb98712011-01-11 15:29:58 +0800999 (y + height - 1) * lcd_line_length + x * bpix / 8);
Mark Jackson7b298f32009-02-06 10:37:49 +01001000
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +01001001 switch (bmp_bpix) {
Mark Jackson7b298f32009-02-06 10:37:49 +01001002 case 1: /* pass through */
1003 case 8:
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +00001004#ifdef CONFIG_LCD_BMP_RLE8
1005 if (le32_to_cpu(bmp->header.compression) == BMP_BI_RLE8) {
1006 if (bpix != 16) {
1007 /* TODO implement render code for bpix != 16 */
1008 printf("Error: only support 16 bpix");
1009 return 1;
1010 }
1011 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
1012 break;
1013 }
1014#endif
1015
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +01001016 if (bpix != 16)
1017 byte_width = width;
1018 else
1019 byte_width = width * 2;
1020
Mark Jackson7b298f32009-02-06 10:37:49 +01001021 for (i = 0; i < height; ++i) {
1022 WATCHDOG_RESET();
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +01001023 for (j = 0; j < width; j++) {
1024 if (bpix != 16) {
Nikita Kiryanovb4571182012-08-09 00:14:53 +00001025 FB_PUT_BYTE(fb, bmap);
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +01001026 } else {
1027 *(uint16_t *)fb = cmap_base[*(bmap++)];
1028 fb += sizeof(uint16_t) / sizeof(*fb);
1029 }
1030 }
Tom Wai-Hong Tam93f04d62012-09-28 15:11:14 +00001031 bmap += (padded_width - width);
Jeroen Hofstee729b09e2013-01-12 12:07:56 +00001032 fb -= byte_width + lcd_line_length;
Mark Jackson7b298f32009-02-06 10:37:49 +01001033 }
1034 break;
1035
1036#if defined(CONFIG_BMP_16BPP)
1037 case 16:
1038 for (i = 0; i < height; ++i) {
1039 WATCHDOG_RESET();
Nikita Kiryanovb4571182012-08-09 00:14:53 +00001040 for (j = 0; j < width; j++)
1041 fb_put_word(&fb, &bmap);
1042
Tom Wai-Hong Tam93f04d62012-09-28 15:11:14 +00001043 bmap += (padded_width - width) * 2;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +00001044 fb -= width * 2 + lcd_line_length;
Mark Jackson7b298f32009-02-06 10:37:49 +01001045 }
1046 break;
1047#endif /* CONFIG_BMP_16BPP */
1048
Donghwa Leebf345a12012-05-09 19:23:37 +00001049#if defined(CONFIG_BMP_32BPP)
1050 case 32:
1051 for (i = 0; i < height; ++i) {
1052 for (j = 0; j < width; j++) {
1053 *(fb++) = *(bmap++);
1054 *(fb++) = *(bmap++);
1055 *(fb++) = *(bmap++);
1056 *(fb++) = *(bmap++);
1057 }
Jeroen Hofstee729b09e2013-01-12 12:07:56 +00001058 fb -= lcd_line_length + width * (bpix / 8);
Donghwa Leebf345a12012-05-09 19:23:37 +00001059 }
1060 break;
1061#endif /* CONFIG_BMP_32BPP */
Mark Jackson7b298f32009-02-06 10:37:49 +01001062 default:
1063 break;
1064 };
wdenk9ca7bbc2004-10-09 23:25:58 +00001065
Simon Glassef45ffd2012-10-30 13:40:18 +00001066 lcd_sync();
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001067 return 0;
wdenk9ca7bbc2004-10-09 23:25:58 +00001068}
Jon Loeliger052fc842007-07-08 18:10:08 -05001069#endif
wdenk9ca7bbc2004-10-09 23:25:58 +00001070
Nikita Kiryanove0eba1f2013-01-30 21:39:57 +00001071#ifdef CONFIG_SPLASH_SCREEN_PREPARE
1072static inline int splash_screen_prepare(void)
1073{
1074 return board_splash_screen_prepare();
1075}
1076#else
1077static inline int splash_screen_prepare(void)
1078{
1079 return 0;
1080}
1081#endif
1082
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001083static void *lcd_logo(void)
wdenk9ca7bbc2004-10-09 23:25:58 +00001084{
wdenk9ca7bbc2004-10-09 23:25:58 +00001085#ifdef CONFIG_SPLASH_SCREEN
1086 char *s;
1087 ulong addr;
1088 static int do_splash = 1;
1089
1090 if (do_splash && (s = getenv("splashimage")) != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +02001091 int x = 0, y = 0;
wdenk9ca7bbc2004-10-09 23:25:58 +00001092 do_splash = 0;
1093
Nikita Kiryanove0eba1f2013-01-30 21:39:57 +00001094 if (splash_screen_prepare())
1095 return (void *)gd->fb_base;
1096
Matthias Weisser53884182009-07-09 16:07:30 +02001097 addr = simple_strtoul (s, NULL, 16);
1098#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001099 s = getenv("splashpos");
1100 if (s != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +02001101 if (s[0] == 'm')
1102 x = BMP_ALIGN_CENTER;
1103 else
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001104 x = simple_strtol(s, NULL, 0);
Matthias Weisser53884182009-07-09 16:07:30 +02001105
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001106 s = strchr(s + 1, ',');
1107 if (s != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +02001108 if (s[1] == 'm')
1109 y = BMP_ALIGN_CENTER;
1110 else
1111 y = simple_strtol (s + 1, NULL, 0);
1112 }
1113 }
1114#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
1115
Nikita Kiryanov2b246c42012-08-09 00:14:50 +00001116 if (bmp_display(addr, x, y) == 0)
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001117 return (void *)lcd_base;
wdenk9ca7bbc2004-10-09 23:25:58 +00001118 }
1119#endif /* CONFIG_SPLASH_SCREEN */
1120
Anatolij Gustschin6f1378f2012-04-27 04:41:27 +00001121 bitmap_plot(0, 0);
wdenk9ca7bbc2004-10-09 23:25:58 +00001122
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +02001123#ifdef CONFIG_LCD_INFO
1124 console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
1125 console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
1126 lcd_show_board_info();
1127#endif /* CONFIG_LCD_INFO */
Stelian Popf6f86652008-05-09 21:57:18 +02001128
wdenk2b9d1862005-07-04 00:03:16 +00001129#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001130 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
wdenk9ca7bbc2004-10-09 23:25:58 +00001131#else
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001132 return (void *)lcd_base;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +00001133#endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
wdenk9ca7bbc2004-10-09 23:25:58 +00001134}
1135
Nikita Kiryanov2f3e2ca2013-02-24 21:28:43 +00001136#ifdef CONFIG_SPLASHIMAGE_GUARD
1137static int on_splashimage(const char *name, const char *value, enum env_op op,
1138 int flags)
1139{
1140 ulong addr;
1141 int aligned;
1142
1143 if (op == env_op_delete)
1144 return 0;
1145
1146 addr = simple_strtoul(value, NULL, 16);
1147 /* See README.displaying-bmps */
1148 aligned = (addr % 4 == 2);
1149 if (!aligned) {
1150 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1151 return -1;
1152 }
1153
1154 return 0;
1155}
1156
1157U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1158#endif
1159
Vadim Bendeburya7eaa2f2012-09-28 15:11:13 +00001160void lcd_position_cursor(unsigned col, unsigned row)
1161{
1162 console_col = min(col, CONSOLE_COLS - 1);
1163 console_row = min(row, CONSOLE_ROWS - 1);
1164}
1165
1166int lcd_get_pixel_width(void)
1167{
1168 return panel_info.vl_col;
1169}
1170
1171int lcd_get_pixel_height(void)
1172{
1173 return panel_info.vl_row;
1174}
1175
1176int lcd_get_screen_rows(void)
1177{
1178 return CONSOLE_ROWS;
1179}
1180
1181int lcd_get_screen_columns(void)
1182{
1183 return CONSOLE_COLS;
1184}