blob: 18f71f245a1133fd749b6e5aac0c612ea30b852b [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 *
Wolfgang Denkbd8ec7e2013-10-07 13:07:26 +02007 * SPDX-License-Identifier: GPL-2.0+
wdenk9ca7bbc2004-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>
wdenk9ca7bbc2004-10-09 23:25:58 +000019#include <stdarg.h>
Nikita Kiryanov2f3e2ca2013-02-24 21:28:43 +000020#include <search.h>
21#include <env_callback.h>
wdenk9ca7bbc2004-10-09 23:25:58 +000022#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +020023#include <stdio_dev.h>
wdenk9ca7bbc2004-10-09 23:25:58 +000024#if defined(CONFIG_POST)
25#include <post.h>
26#endif
27#include <lcd.h>
wdenkbc3202a2005-04-03 23:11:38 +000028#include <watchdog.h>
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +010029#include <asm/unaligned.h>
Robert Winkler2a90ed02013-06-17 11:31:29 -070030#include <splash.h>
Simon Glassb9ddbf42014-02-27 13:26:19 -070031#include <asm/io.h>
32#include <asm/unaligned.h>
Hans de Goedeb2726f22014-11-19 13:53:27 +010033#include <fdt_support.h>
Robert Winkler2a90ed02013-06-17 11:31:29 -070034
Marek Vasut85cc88a2011-11-26 07:20:07 +010035#if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
36 defined(CONFIG_CPU_MONAHANS)
wdenk9ca7bbc2004-10-09 23:25:58 +000037#include <asm/byteorder.h>
38#endif
39
40#if defined(CONFIG_MPC823)
wdenk9ca7bbc2004-10-09 23:25:58 +000041#include <lcdvideo.h>
42#endif
43
Stelian Popf6f86652008-05-09 21:57:18 +020044#if defined(CONFIG_ATMEL_LCD)
45#include <atmel_lcdc.h>
Stelian Popf6f86652008-05-09 21:57:18 +020046#endif
47
Stephen Warrenefe64282013-05-27 18:31:17 +000048#if defined(CONFIG_LCD_DT_SIMPLEFB)
49#include <libfdt.h>
50#endif
51
wdenk9ca7bbc2004-10-09 23:25:58 +000052/************************************************************************/
53/* ** FONT DATA */
54/************************************************************************/
55#include <video_font.h> /* Get font data, width and height */
56
wdenk2b9d1862005-07-04 00:03:16 +000057/************************************************************************/
58/* ** LOGO DATA */
59/************************************************************************/
60#ifdef CONFIG_LCD_LOGO
61# include <bmp_logo.h> /* Get logo data, width and height */
Che-Liang Chiou5639fc62011-10-20 23:04:20 +000062# include <bmp_logo_data.h>
Alessandro Rubini2d68c262010-03-13 17:44:08 +010063# if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
wdenk2b9d1862005-07-04 00:03:16 +000064# error Default Color Map overlaps with Logo Color Map
65# endif
66#endif
wdenk9ca7bbc2004-10-09 23:25:58 +000067
Simon Glassb9ddbf42014-02-27 13:26:19 -070068#ifdef CONFIG_SANDBOX
69#include <asm/sdl.h>
70#endif
71
Simon Glass599a4df2012-10-17 13:24:54 +000072#ifndef CONFIG_LCD_ALIGNMENT
73#define CONFIG_LCD_ALIGNMENT PAGE_SIZE
74#endif
75
Simon Glassaf3e2802012-10-17 13:24:59 +000076/* By default we scroll by a single line */
77#ifndef CONFIG_CONSOLE_SCROLL_LINES
78#define CONFIG_CONSOLE_SCROLL_LINES 1
79#endif
80
Jeroen Hofsteecdc348a2013-01-12 12:07:59 +000081/************************************************************************/
82/* ** CONSOLE DEFINITIONS & FUNCTIONS */
83/************************************************************************/
84#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
85# define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \
86 / VIDEO_FONT_HEIGHT)
87#else
88# define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT)
89#endif
90
91#define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH)
92#define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length)
93#define CONSOLE_ROW_FIRST lcd_console_address
94#define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE)
95#define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \
96 - CONSOLE_ROW_SIZE)
97#define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS)
98#define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE)
Wolfgang Denk6405a152006-03-31 18:32:53 +020099
Nikita Kiryanov5aec5812014-12-08 17:14:38 +0200100#if (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \
Hannes Petermaier95f87df2014-03-07 18:55:40 +0100101 (LCD_BPP == LCD_COLOR32)
Jeroen Hofsteecdc348a2013-01-12 12:07:59 +0000102# define COLOR_MASK(c) (c)
103#else
104# error Unsupported LCD BPP.
105#endif
106
wdenk9ca7bbc2004-10-09 23:25:58 +0000107DECLARE_GLOBAL_DATA_PTR;
wdenk9ca7bbc2004-10-09 23:25:58 +0000108
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000109static void lcd_drawchars(ushort x, ushort y, uchar *str, int count);
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000110static inline void lcd_putc_xy(ushort x, ushort y, uchar c);
wdenk9ca7bbc2004-10-09 23:25:58 +0000111
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000112static int lcd_init(void *lcdbase);
wdenk9ca7bbc2004-10-09 23:25:58 +0000113
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000114static void *lcd_logo(void);
wdenk9ca7bbc2004-10-09 23:25:58 +0000115
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000116static void lcd_setfgcolor(int color);
117static void lcd_setbgcolor(int color);
wdenk9ca7bbc2004-10-09 23:25:58 +0000118
Wolfgang Denk67f53912013-01-05 09:45:48 +0000119static int lcd_color_fg;
120static int lcd_color_bg;
Jeroen Hofsteeb9092e62013-01-22 10:44:11 +0000121int lcd_line_length;
Wolfgang Denk67f53912013-01-05 09:45:48 +0000122
wdenk9ca7bbc2004-10-09 23:25:58 +0000123char lcd_is_enabled = 0;
wdenk9ca7bbc2004-10-09 23:25:58 +0000124
Jeroen Hofsteeb9092e62013-01-22 10:44:11 +0000125static short console_col;
126static short console_row;
Simon Glassef45ffd2012-10-30 13:40:18 +0000127
Jeroen Hofsteeb9092e62013-01-22 10:44:11 +0000128static void *lcd_console_address;
Jeroen Hofstee881c4ec2013-01-22 10:44:12 +0000129static void *lcd_base; /* Start of framebuffer memory */
Simon Glassef45ffd2012-10-30 13:40:18 +0000130
wdenk9ca7bbc2004-10-09 23:25:58 +0000131static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
wdenk9ca7bbc2004-10-09 23:25:58 +0000132
133/************************************************************************/
134
Simon Glassef45ffd2012-10-30 13:40:18 +0000135/* Flush LCD activity to the caches */
136void lcd_sync(void)
137{
138 /*
139 * flush_dcache_range() is declared in common.h but it seems that some
140 * architectures do not actually implement it. Is there a way to find
141 * out whether it exists? For now, ARM is safe.
142 */
143#if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
144 int line_length;
145
146 if (lcd_flush_dcache)
147 flush_dcache_range((u32)lcd_base,
148 (u32)(lcd_base + lcd_get_size(&line_length)));
Simon Glassb9ddbf42014-02-27 13:26:19 -0700149#elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
150 static ulong last_sync;
151
152 if (get_timer(last_sync) > 10) {
153 sandbox_sdl_sync(lcd_base);
154 last_sync = get_timer(0);
155 }
Simon Glassef45ffd2012-10-30 13:40:18 +0000156#endif
157}
158
159void lcd_set_flush_dcache(int flush)
160{
161 lcd_flush_dcache = (flush != 0);
162}
163
wdenk9ca7bbc2004-10-09 23:25:58 +0000164/*----------------------------------------------------------------------*/
165
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000166static void console_scrollup(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000167{
Simon Glassaf3e2802012-10-17 13:24:59 +0000168 const int rows = CONFIG_CONSOLE_SCROLL_LINES;
wdenk9ca7bbc2004-10-09 23:25:58 +0000169
Simon Glassaf3e2802012-10-17 13:24:59 +0000170 /* Copy up rows ignoring those that will be overwritten */
171 memcpy(CONSOLE_ROW_FIRST,
172 lcd_console_address + CONSOLE_ROW_SIZE * rows,
173 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows);
174
175 /* Clear the last rows */
Hannes Petermaier95f87df2014-03-07 18:55:40 +0100176#if (LCD_BPP != LCD_COLOR32)
Simon Glassaf3e2802012-10-17 13:24:59 +0000177 memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows,
178 COLOR_MASK(lcd_color_bg),
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000179 CONSOLE_ROW_SIZE * rows);
Hannes Petermaier95f87df2014-03-07 18:55:40 +0100180#else
181 u32 *ppix = lcd_console_address +
182 CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows;
183 u32 i;
184 for (i = 0;
185 i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix);
186 i++) {
187 *ppix++ = COLOR_MASK(lcd_color_bg);
188 }
189#endif
Simon Glassef45ffd2012-10-30 13:40:18 +0000190 lcd_sync();
Simon Glassaf3e2802012-10-17 13:24:59 +0000191 console_row -= rows;
wdenk9ca7bbc2004-10-09 23:25:58 +0000192}
193
194/*----------------------------------------------------------------------*/
195
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000196static inline void console_back(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000197{
198 if (--console_col < 0) {
199 console_col = CONSOLE_COLS-1 ;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000200 if (--console_row < 0)
wdenk9ca7bbc2004-10-09 23:25:58 +0000201 console_row = 0;
wdenk9ca7bbc2004-10-09 23:25:58 +0000202 }
203
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000204 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
205 console_row * VIDEO_FONT_HEIGHT, ' ');
wdenk9ca7bbc2004-10-09 23:25:58 +0000206}
207
208/*----------------------------------------------------------------------*/
209
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000210static inline void console_newline(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000211{
wdenk9ca7bbc2004-10-09 23:25:58 +0000212 console_col = 0;
213
214 /* Check if we need to scroll the terminal */
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000215 if (++console_row >= CONSOLE_ROWS)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000216 console_scrollup();
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000217 else
Simon Glassef45ffd2012-10-30 13:40:18 +0000218 lcd_sync();
wdenk9ca7bbc2004-10-09 23:25:58 +0000219}
220
221/*----------------------------------------------------------------------*/
222
Simon Glass0d1e1f72014-07-23 06:54:59 -0600223static void lcd_stub_putc(struct stdio_dev *dev, const char c)
224{
225 lcd_putc(c);
226}
227
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000228void lcd_putc(const char c)
wdenk9ca7bbc2004-10-09 23:25:58 +0000229{
230 if (!lcd_is_enabled) {
231 serial_putc(c);
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000232
wdenk9ca7bbc2004-10-09 23:25:58 +0000233 return;
234 }
235
236 switch (c) {
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000237 case '\r':
238 console_col = 0;
wdenk9ca7bbc2004-10-09 23:25:58 +0000239
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000240 return;
241 case '\n':
242 console_newline();
wdenk9ca7bbc2004-10-09 23:25:58 +0000243
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000244 return;
wdenk9ca7bbc2004-10-09 23:25:58 +0000245 case '\t': /* Tab (8 chars alignment) */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000246 console_col += 8;
247 console_col &= ~7;
wdenk9ca7bbc2004-10-09 23:25:58 +0000248
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000249 if (console_col >= CONSOLE_COLS)
250 console_newline();
wdenk9ca7bbc2004-10-09 23:25:58 +0000251
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000252 return;
253 case '\b':
254 console_back();
wdenk9ca7bbc2004-10-09 23:25:58 +0000255
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000256 return;
257 default:
258 lcd_putc_xy(console_col * VIDEO_FONT_WIDTH,
259 console_row * VIDEO_FONT_HEIGHT, c);
260 if (++console_col >= CONSOLE_COLS)
261 console_newline();
wdenk9ca7bbc2004-10-09 23:25:58 +0000262 }
wdenk9ca7bbc2004-10-09 23:25:58 +0000263}
264
265/*----------------------------------------------------------------------*/
266
Simon Glass0d1e1f72014-07-23 06:54:59 -0600267static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
268{
269 lcd_puts(s);
270}
271
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000272void lcd_puts(const char *s)
wdenk9ca7bbc2004-10-09 23:25:58 +0000273{
274 if (!lcd_is_enabled) {
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000275 serial_puts(s);
276
wdenk9ca7bbc2004-10-09 23:25:58 +0000277 return;
278 }
279
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000280 while (*s)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000281 lcd_putc(*s++);
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000282
Simon Glassef45ffd2012-10-30 13:40:18 +0000283 lcd_sync();
wdenk9ca7bbc2004-10-09 23:25:58 +0000284}
285
Haavard Skinnemoen010c7732008-09-01 16:21:20 +0200286/*----------------------------------------------------------------------*/
287
288void lcd_printf(const char *fmt, ...)
289{
290 va_list args;
291 char buf[CONFIG_SYS_PBSIZE];
292
293 va_start(args, fmt);
294 vsprintf(buf, fmt, args);
295 va_end(args);
296
297 lcd_puts(buf);
298}
299
wdenk9ca7bbc2004-10-09 23:25:58 +0000300/************************************************************************/
301/* ** Low-Level Graphics Routines */
302/************************************************************************/
303
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000304static void lcd_drawchars(ushort x, ushort y, uchar *str, int count)
wdenk9ca7bbc2004-10-09 23:25:58 +0000305{
306 uchar *dest;
Marek Vasutdf5d8c12011-09-26 02:26:04 +0200307 ushort row;
308
Anatolij Gustschin81b99b82012-04-27 04:41:16 +0000309#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
310 y += BMP_LOGO_HEIGHT;
311#endif
312
Hannes Petermaier95f87df2014-03-07 18:55:40 +0100313 dest = (uchar *)(lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP)/8);
wdenk9ca7bbc2004-10-09 23:25:58 +0000314
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000315 for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000316 uchar *s = str;
wdenk9ca7bbc2004-10-09 23:25:58 +0000317 int i;
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100318#if LCD_BPP == LCD_COLOR16
319 ushort *d = (ushort *)dest;
Hannes Petermaier95f87df2014-03-07 18:55:40 +0100320#elif LCD_BPP == LCD_COLOR32
321 u32 *d = (u32 *)dest;
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100322#else
323 uchar *d = dest;
324#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000325
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000326 for (i = 0; i < count; ++i) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000327 uchar c, bits;
328
329 c = *s++;
330 bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row];
331
Hannes Petermaier95f87df2014-03-07 18:55:40 +0100332 for (c = 0; c < 8; ++c) {
333 *d++ = (bits & 0x80) ?
334 lcd_color_fg : lcd_color_bg;
335 bits <<= 1;
336 }
wdenk9ca7bbc2004-10-09 23:25:58 +0000337 }
wdenk9ca7bbc2004-10-09 23:25:58 +0000338 }
339}
340
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000341static inline void lcd_putc_xy(ushort x, ushort y, uchar c)
wdenk9ca7bbc2004-10-09 23:25:58 +0000342{
Anatolij Gustschin81b99b82012-04-27 04:41:16 +0000343 lcd_drawchars(x, y, &c, 1);
wdenk9ca7bbc2004-10-09 23:25:58 +0000344}
345
346/************************************************************************/
347/** Small utility to check that you got the colours right */
348/************************************************************************/
349#ifdef LCD_TEST_PATTERN
350
351#define N_BLK_VERT 2
352#define N_BLK_HOR 3
353
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000354static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
wdenk9ca7bbc2004-10-09 23:25:58 +0000355 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
356 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
357};
358
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000359static void test_pattern(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000360{
361 ushort v_max = panel_info.vl_row;
362 ushort h_max = panel_info.vl_col;
363 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
364 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
365 ushort v, h;
366 uchar *pix = (uchar *)lcd_base;
367
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000368 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
wdenk9ca7bbc2004-10-09 23:25:58 +0000369 h_max, v_max, h_step, v_step);
370
371 /* WARNING: Code silently assumes 8bit/pixel */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000372 for (v = 0; v < v_max; ++v) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000373 uchar iy = v / v_step;
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000374 for (h = 0; h < h_max; ++h) {
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000375 uchar ix = N_BLK_HOR * iy + h / h_step;
wdenk9ca7bbc2004-10-09 23:25:58 +0000376 *pix++ = test_colors[ix];
377 }
378 }
379}
380#endif /* LCD_TEST_PATTERN */
381
382
383/************************************************************************/
384/* ** GENERIC Initialization Routines */
385/************************************************************************/
Anatolij Gustschinfa50d902013-11-09 11:00:09 +0100386/*
387 * With most lcd drivers the line length is set up
388 * by calculating it from panel_info parameters. Some
389 * drivers need to calculate the line length differently,
390 * so make the function weak to allow overriding it.
391 */
392__weak int lcd_get_size(int *line_length)
Simon Glass599a4df2012-10-17 13:24:54 +0000393{
394 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
395 return *line_length * panel_info.vl_row;
396}
397
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000398int drv_lcd_init(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000399{
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200400 struct stdio_dev lcddev;
wdenk9ca7bbc2004-10-09 23:25:58 +0000401 int rc;
402
Simon Glassb9ddbf42014-02-27 13:26:19 -0700403 lcd_base = map_sysmem(gd->fb_base, 0);
wdenk9ca7bbc2004-10-09 23:25:58 +0000404
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000405 lcd_init(lcd_base); /* LCD initialization */
wdenk9ca7bbc2004-10-09 23:25:58 +0000406
407 /* Device initialization */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000408 memset(&lcddev, 0, sizeof(lcddev));
wdenk9ca7bbc2004-10-09 23:25:58 +0000409
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000410 strcpy(lcddev.name, "lcd");
wdenk9ca7bbc2004-10-09 23:25:58 +0000411 lcddev.ext = 0; /* No extensions */
412 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
Simon Glass0d1e1f72014-07-23 06:54:59 -0600413 lcddev.putc = lcd_stub_putc; /* 'putc' function */
414 lcddev.puts = lcd_stub_puts; /* 'puts' function */
wdenk9ca7bbc2004-10-09 23:25:58 +0000415
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000416 rc = stdio_register(&lcddev);
wdenk9ca7bbc2004-10-09 23:25:58 +0000417
418 return (rc == 0) ? 1 : rc;
419}
420
421/*----------------------------------------------------------------------*/
Che-Liang Chiou2444b172011-10-20 23:07:03 +0000422void lcd_clear(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000423{
Nikita Kiryanov5aec5812014-12-08 17:14:38 +0200424#if LCD_BPP == LCD_COLOR8
wdenk9ca7bbc2004-10-09 23:25:58 +0000425 /* Setting the palette */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000426 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
427 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
428 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
429 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
430 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
431 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
432 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
433 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
434 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
wdenk9ca7bbc2004-10-09 23:25:58 +0000435#endif
436
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200437#ifndef CONFIG_SYS_WHITE_ON_BLACK
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000438 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
439 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
wdenk9ca7bbc2004-10-09 23:25:58 +0000440#else
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000441 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
442 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200443#endif /* CONFIG_SYS_WHITE_ON_BLACK */
wdenk9ca7bbc2004-10-09 23:25:58 +0000444
445#ifdef LCD_TEST_PATTERN
446 test_pattern();
447#else
448 /* set framebuffer to background color */
Hannes Petermaier95f87df2014-03-07 18:55:40 +0100449#if (LCD_BPP != LCD_COLOR32)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000450 memset((char *)lcd_base,
Hannes Petermaier021c2b32014-03-07 18:45:20 +0100451 COLOR_MASK(lcd_color_bg),
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000452 lcd_line_length * panel_info.vl_row);
Hannes Petermaier95f87df2014-03-07 18:55:40 +0100453#else
454 u32 *ppix = lcd_base;
455 u32 i;
456 for (i = 0;
457 i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix);
458 i++) {
459 *ppix++ = COLOR_MASK(lcd_color_bg);
460 }
461#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000462#endif
463 /* Paint the logo and retrieve LCD base address */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000464 debug("[LCD] Drawing the logo...\n");
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000465 lcd_console_address = lcd_logo();
wdenk9ca7bbc2004-10-09 23:25:58 +0000466
467 console_col = 0;
468 console_row = 0;
Simon Glassef45ffd2012-10-30 13:40:18 +0000469 lcd_sync();
wdenk9ca7bbc2004-10-09 23:25:58 +0000470}
471
Simon Glassef45ffd2012-10-30 13:40:18 +0000472static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
473 char *const argv[])
474{
475 lcd_clear();
476 return 0;
477}
478
wdenk9ca7bbc2004-10-09 23:25:58 +0000479U_BOOT_CMD(
Che-Liang Chiou2444b172011-10-20 23:07:03 +0000480 cls, 1, 1, do_lcd_clear,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600481 "clear screen",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200482 ""
wdenk9ca7bbc2004-10-09 23:25:58 +0000483);
484
485/*----------------------------------------------------------------------*/
486
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000487static int lcd_init(void *lcdbase)
wdenk9ca7bbc2004-10-09 23:25:58 +0000488{
489 /* Initialize the lcd controller */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000490 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
wdenk9ca7bbc2004-10-09 23:25:58 +0000491
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000492 lcd_ctrl_init(lcdbase);
Anatolij Gustschin02591592013-03-29 14:00:13 +0100493
494 /*
Stephen Warren682b6b52014-11-19 20:41:03 -0700495 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
Anatolij Gustschin02591592013-03-29 14:00:13 +0100496 * the 'lcdbase' argument and uses custom lcd base address
497 * by setting up gd->fb_base. Check for this condition and fixup
498 * 'lcd_base' address.
499 */
Simon Glassb9ddbf42014-02-27 13:26:19 -0700500 if (map_to_sysmem(lcdbase) != gd->fb_base)
501 lcd_base = map_sysmem(gd->fb_base, 0);
Anatolij Gustschin02591592013-03-29 14:00:13 +0100502
503 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
504
Stephen Warrenefc8f792013-01-29 16:37:38 +0000505 lcd_get_size(&lcd_line_length);
Haavard Skinnemoen7eb8b232008-09-01 16:21:21 +0200506 lcd_is_enabled = 1;
Che-Liang Chiou2444b172011-10-20 23:07:03 +0000507 lcd_clear();
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000508 lcd_enable();
wdenk9ca7bbc2004-10-09 23:25:58 +0000509
510 /* Initialize the console */
511 console_col = 0;
wdenk2b9d1862005-07-04 00:03:16 +0000512#ifdef CONFIG_LCD_INFO_BELOW_LOGO
wdenk9ca7bbc2004-10-09 23:25:58 +0000513 console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT;
514#else
515 console_row = 1; /* leave 1 blank line below logo */
516#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000517
518 return 0;
519}
520
521
522/************************************************************************/
523/* ** ROM capable initialization part - needed to reserve FB memory */
524/************************************************************************/
525/*
526 * This is called early in the system initialization to grab memory
527 * for the LCD controller.
528 * Returns new address for monitor, after reserving LCD buffer memory
529 *
530 * Note that this is running from ROM, so no write access to global data.
531 */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000532ulong lcd_setmem(ulong addr)
wdenk9ca7bbc2004-10-09 23:25:58 +0000533{
534 ulong size;
Simon Glass599a4df2012-10-17 13:24:54 +0000535 int line_length;
wdenk9ca7bbc2004-10-09 23:25:58 +0000536
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000537 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
538 panel_info.vl_row, NBITS(panel_info.vl_bpix));
wdenk9ca7bbc2004-10-09 23:25:58 +0000539
Simon Glass599a4df2012-10-17 13:24:54 +0000540 size = lcd_get_size(&line_length);
wdenk9ca7bbc2004-10-09 23:25:58 +0000541
Simon Glass599a4df2012-10-17 13:24:54 +0000542 /* Round up to nearest full page, or MMU section if defined */
543 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
544 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
wdenk9ca7bbc2004-10-09 23:25:58 +0000545
546 /* Allocate pages for the frame buffer. */
547 addr -= size;
548
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000549 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
550 size >> 10, addr);
wdenk9ca7bbc2004-10-09 23:25:58 +0000551
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000552 return addr;
wdenk9ca7bbc2004-10-09 23:25:58 +0000553}
554
555/*----------------------------------------------------------------------*/
556
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000557static void lcd_setfgcolor(int color)
wdenk9ca7bbc2004-10-09 23:25:58 +0000558{
Stelian Popf6f86652008-05-09 21:57:18 +0200559 lcd_color_fg = color;
wdenk9ca7bbc2004-10-09 23:25:58 +0000560}
561
562/*----------------------------------------------------------------------*/
563
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000564static void lcd_setbgcolor(int color)
wdenk9ca7bbc2004-10-09 23:25:58 +0000565{
Stelian Popf6f86652008-05-09 21:57:18 +0200566 lcd_color_bg = color;
wdenk9ca7bbc2004-10-09 23:25:58 +0000567}
568
wdenk9ca7bbc2004-10-09 23:25:58 +0000569/************************************************************************/
570/* ** Chipset depending Bitmap / Logo stuff... */
571/************************************************************************/
Nikita Kiryanov22425272012-08-09 00:14:52 +0000572static inline ushort *configuration_get_cmap(void)
573{
574#if defined CONFIG_CPU_PXA
575 struct pxafb_info *fbi = &panel_info.pxa;
576 return (ushort *)fbi->palette;
577#elif defined(CONFIG_MPC823)
578 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
579 cpm8xx_t *cp = &(immr->im_cpm);
580 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
581#elif defined(CONFIG_ATMEL_LCD)
582 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
Anatolij Gustschin4bb5fa42012-09-22 06:55:53 +0000583#elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
584 return panel_info.cmap;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000585#elif defined(CONFIG_LCD_LOGO)
Anatolij Gustschin4bb5fa42012-09-22 06:55:53 +0000586 return bmp_logo_palette;
587#else
588 return NULL;
589#endif
Nikita Kiryanov22425272012-08-09 00:14:52 +0000590}
591
wdenk9ca7bbc2004-10-09 23:25:58 +0000592#ifdef CONFIG_LCD_LOGO
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000593void bitmap_plot(int x, int y)
wdenk9ca7bbc2004-10-09 23:25:58 +0000594{
Stelian Popf6f86652008-05-09 21:57:18 +0200595#ifdef CONFIG_ATMEL_LCD
Nikita Kiryanov22425272012-08-09 00:14:52 +0000596 uint *cmap = (uint *)bmp_logo_palette;
Stelian Popf6f86652008-05-09 21:57:18 +0200597#else
Nikita Kiryanov22425272012-08-09 00:14:52 +0000598 ushort *cmap = (ushort *)bmp_logo_palette;
Stelian Popf6f86652008-05-09 21:57:18 +0200599#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000600 ushort i, j;
601 uchar *bmap;
602 uchar *fb;
603 ushort *fb16;
Nikita Kiryanov22425272012-08-09 00:14:52 +0000604#if defined(CONFIG_MPC823)
605 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
606 cpm8xx_t *cp = &(immr->im_cpm);
wdenk9ca7bbc2004-10-09 23:25:58 +0000607#endif
Andre Renaudada32ec2013-02-13 17:48:00 +0000608 unsigned bpix = NBITS(panel_info.vl_bpix);
wdenk9ca7bbc2004-10-09 23:25:58 +0000609
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000610 debug("Logo: width %d height %d colors %d cmap %d\n",
wdenk9ca7bbc2004-10-09 23:25:58 +0000611 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
Anatolij Gustschin218e6a02012-04-27 04:41:06 +0000612 ARRAY_SIZE(bmp_logo_palette));
wdenk9ca7bbc2004-10-09 23:25:58 +0000613
614 bmap = &bmp_logo_bitmap[0];
Andre Renaudada32ec2013-02-13 17:48:00 +0000615 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
wdenk9ca7bbc2004-10-09 23:25:58 +0000616
Andre Renaudada32ec2013-02-13 17:48:00 +0000617 if (bpix < 12) {
Nikita Kiryanov22425272012-08-09 00:14:52 +0000618 /* Leave room for default color map
619 * default case: generic system with no cmap (most likely 16bpp)
620 * cmap was set to the source palette, so no change is done.
621 * This avoids even more ifdefs in the next stanza
622 */
623#if defined(CONFIG_MPC823)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000624 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
Stelian Popf6f86652008-05-09 21:57:18 +0200625#elif defined(CONFIG_ATMEL_LCD)
Nikita Kiryanov22425272012-08-09 00:14:52 +0000626 cmap = (uint *)configuration_get_cmap();
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100627#else
Nikita Kiryanov22425272012-08-09 00:14:52 +0000628 cmap = configuration_get_cmap();
wdenk9ca7bbc2004-10-09 23:25:58 +0000629#endif
630
631 WATCHDOG_RESET();
632
633 /* Set color map */
Anatolij Gustschin218e6a02012-04-27 04:41:06 +0000634 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000635 ushort colreg = bmp_logo_palette[i];
Stelian Popf6f86652008-05-09 21:57:18 +0200636#ifdef CONFIG_ATMEL_LCD
637 uint lut_entry;
638#ifdef CONFIG_ATMEL_LCD_BGR555
639 lut_entry = ((colreg & 0x000F) << 11) |
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000640 ((colreg & 0x00F0) << 2) |
641 ((colreg & 0x0F00) >> 7);
Stelian Popf6f86652008-05-09 21:57:18 +0200642#else /* CONFIG_ATMEL_LCD_RGB565 */
643 lut_entry = ((colreg & 0x000F) << 1) |
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000644 ((colreg & 0x00F0) << 3) |
645 ((colreg & 0x0F00) << 4);
Stelian Popf6f86652008-05-09 21:57:18 +0200646#endif
647 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
648 cmap++;
649#else /* !CONFIG_ATMEL_LCD */
wdenk9ca7bbc2004-10-09 23:25:58 +0000650 *cmap++ = colreg;
Stelian Popf6f86652008-05-09 21:57:18 +0200651#endif /* CONFIG_ATMEL_LCD */
wdenk9ca7bbc2004-10-09 23:25:58 +0000652 }
653
654 WATCHDOG_RESET();
655
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000656 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
657 memcpy(fb, bmap, BMP_LOGO_WIDTH);
wdenk9ca7bbc2004-10-09 23:25:58 +0000658 bmap += BMP_LOGO_WIDTH;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000659 fb += panel_info.vl_col;
wdenk9ca7bbc2004-10-09 23:25:58 +0000660 }
661 }
662 else { /* true color mode */
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100663 u16 col16;
Andre Renaudada32ec2013-02-13 17:48:00 +0000664 fb16 = (ushort *)fb;
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000665 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
666 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100667 col16 = bmp_logo_palette[(bmap[j]-16)];
668 fb16[j] =
669 ((col16 & 0x000F) << 1) |
670 ((col16 & 0x00F0) << 3) |
671 ((col16 & 0x0F00) << 4);
wdenk9ca7bbc2004-10-09 23:25:58 +0000672 }
673 bmap += BMP_LOGO_WIDTH;
674 fb16 += panel_info.vl_col;
675 }
676 }
677
678 WATCHDOG_RESET();
Simon Glassef45ffd2012-10-30 13:40:18 +0000679 lcd_sync();
wdenk9ca7bbc2004-10-09 23:25:58 +0000680}
Anatolij Gustschin6f1378f2012-04-27 04:41:27 +0000681#else
682static inline void bitmap_plot(int x, int y) {}
wdenk9ca7bbc2004-10-09 23:25:58 +0000683#endif /* CONFIG_LCD_LOGO */
684
685/*----------------------------------------------------------------------*/
Jon Loeliger052fc842007-07-08 18:10:08 -0500686#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk9ca7bbc2004-10-09 23:25:58 +0000687/*
688 * Display the BMP file located at address bmp_image.
689 * Only uncompressed.
690 */
Matthias Weisser53884182009-07-09 16:07:30 +0200691
692#ifdef CONFIG_SPLASH_SCREEN_ALIGN
693#define BMP_ALIGN_CENTER 0x7FFF
Nikita Kiryanovb4eb54d2012-08-09 00:14:51 +0000694
695static void splash_align_axis(int *axis, unsigned long panel_size,
696 unsigned long picture_size)
697{
698 unsigned long panel_picture_delta = panel_size - picture_size;
699 unsigned long axis_alignment;
700
701 if (*axis == BMP_ALIGN_CENTER)
702 axis_alignment = panel_picture_delta / 2;
703 else if (*axis < 0)
704 axis_alignment = panel_picture_delta + *axis + 1;
705 else
706 return;
707
Masahiro Yamadadb204642014-11-07 03:03:31 +0900708 *axis = max(0, (int)axis_alignment);
Nikita Kiryanovb4eb54d2012-08-09 00:14:51 +0000709}
Matthias Weisser53884182009-07-09 16:07:30 +0200710#endif
711
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000712
713#ifdef CONFIG_LCD_BMP_RLE8
714
715#define BMP_RLE8_ESCAPE 0
716#define BMP_RLE8_EOL 0
717#define BMP_RLE8_EOBMP 1
718#define BMP_RLE8_DELTA 2
719
720static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
721 int cnt)
722{
723 while (cnt > 0) {
724 *(*fbp)++ = cmap[*bmap++];
725 cnt--;
726 }
727}
728
729static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
730{
731 ushort *fb = *fbp;
732 int cnt_8copy = cnt >> 3;
733
734 cnt -= cnt_8copy << 3;
735 while (cnt_8copy > 0) {
736 *fb++ = c;
737 *fb++ = c;
738 *fb++ = c;
739 *fb++ = c;
740 *fb++ = c;
741 *fb++ = c;
742 *fb++ = c;
743 *fb++ = c;
744 cnt_8copy--;
745 }
746 while (cnt > 0) {
747 *fb++ = c;
748 cnt--;
749 }
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000750 *fbp = fb;
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000751}
752
753/*
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000754 * Do not call this function directly, must be called from lcd_display_bitmap.
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000755 */
756static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
757 int x_off, int y_off)
758{
759 uchar *bmap;
760 ulong width, height;
761 ulong cnt, runlen;
762 int x, y;
763 int decode = 1;
764
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100765 width = get_unaligned_le32(&bmp->header.width);
766 height = get_unaligned_le32(&bmp->header.height);
767 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000768
769 x = 0;
770 y = height - 1;
771
772 while (decode) {
773 if (bmap[0] == BMP_RLE8_ESCAPE) {
774 switch (bmap[1]) {
775 case BMP_RLE8_EOL:
776 /* end of line */
777 bmap += 2;
778 x = 0;
779 y--;
780 /* 16bpix, 2-byte per pixel, width should *2 */
781 fb -= (width * 2 + lcd_line_length);
782 break;
783 case BMP_RLE8_EOBMP:
784 /* end of bitmap */
785 decode = 0;
786 break;
787 case BMP_RLE8_DELTA:
788 /* delta run */
789 x += bmap[2];
790 y -= bmap[3];
791 /* 16bpix, 2-byte per pixel, x should *2 */
792 fb = (uchar *) (lcd_base + (y + y_off - 1)
793 * lcd_line_length + (x + x_off) * 2);
794 bmap += 4;
795 break;
796 default:
797 /* unencoded run */
798 runlen = bmap[1];
799 bmap += 2;
800 if (y < height) {
801 if (x < width) {
802 if (x + runlen > width)
803 cnt = width - x;
804 else
805 cnt = runlen;
806 draw_unencoded_bitmap(
807 (ushort **)&fb,
808 bmap, cmap, cnt);
809 }
810 x += runlen;
811 }
812 bmap += runlen;
813 if (runlen & 1)
814 bmap++;
815 }
816 } else {
817 /* encoded run */
818 if (y < height) {
819 runlen = bmap[0];
820 if (x < width) {
821 /* aggregate the same code */
822 while (bmap[0] == 0xff &&
823 bmap[2] != BMP_RLE8_ESCAPE &&
824 bmap[1] == bmap[3]) {
825 runlen += bmap[2];
826 bmap += 2;
827 }
828 if (x + runlen > width)
829 cnt = width - x;
830 else
831 cnt = runlen;
832 draw_encoded_bitmap((ushort **)&fb,
833 cmap[bmap[1]], cnt);
834 }
835 x += runlen;
836 }
837 bmap += 2;
838 }
839 }
840}
841#endif
842
Nikita Kiryanov200c12b2014-11-11 15:46:05 +0200843#if defined(CONFIG_MPC823)
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000844#define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
Anatolij Gustschin4bb5fa42012-09-22 06:55:53 +0000845#else
846#define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000847#endif
848
849#if defined(CONFIG_BMP_16BPP)
850#if defined(CONFIG_ATMEL_LCD_BGR555)
851static inline void fb_put_word(uchar **fb, uchar **from)
852{
853 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
854 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
855 *from += 2;
856}
857#else
858static inline void fb_put_word(uchar **fb, uchar **from)
859{
860 *(*fb)++ = *(*from)++;
861 *(*fb)++ = *(*from)++;
862}
863#endif
864#endif /* CONFIG_BMP_16BPP */
865
wdenk9ca7bbc2004-10-09 23:25:58 +0000866int lcd_display_bitmap(ulong bmp_image, int x, int y)
867{
Anatolij Gustschina11ca282009-02-25 20:28:13 +0100868 ushort *cmap = NULL;
Anatolij Gustschina11ca282009-02-25 20:28:13 +0100869 ushort *cmap_base = NULL;
wdenk9ca7bbc2004-10-09 23:25:58 +0000870 ushort i, j;
871 uchar *fb;
Simon Glassb9ddbf42014-02-27 13:26:19 -0700872 bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
wdenk9ca7bbc2004-10-09 23:25:58 +0000873 uchar *bmap;
Tom Wai-Hong Tam93f04d62012-09-28 15:11:14 +0000874 ushort padded_width;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100875 unsigned long width, height, byte_width;
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200876 unsigned long pwidth = panel_info.vl_col;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100877 unsigned colors, bpix, bmp_bpix;
wdenk9ca7bbc2004-10-09 23:25:58 +0000878
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000879 if (!bmp || !(bmp->header.signature[0] == 'B' &&
880 bmp->header.signature[1] == 'M')) {
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000881 printf("Error: no valid bmp image at %lx\n", bmp_image);
882
wdenk9ca7bbc2004-10-09 23:25:58 +0000883 return 1;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100884 }
wdenk9ca7bbc2004-10-09 23:25:58 +0000885
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100886 width = get_unaligned_le32(&bmp->header.width);
887 height = get_unaligned_le32(&bmp->header.height);
888 bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
889
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100890 colors = 1 << bmp_bpix;
wdenk9ca7bbc2004-10-09 23:25:58 +0000891
892 bpix = NBITS(panel_info.vl_bpix);
893
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000894 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100895 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
896 bpix, bmp_bpix);
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000897
wdenk9ca7bbc2004-10-09 23:25:58 +0000898 return 1;
899 }
900
Hannes Petermaier14b7eed2014-07-15 16:28:46 +0200901 /*
902 * We support displaying 8bpp BMPs on 16bpp LCDs
903 * and displaying 24bpp BMPs on 32bpp LCDs
904 * */
905 if (bpix != bmp_bpix &&
906 !(bmp_bpix == 8 && bpix == 16) &&
907 !(bmp_bpix == 24 && bpix == 32)) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000908 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100909 bpix, get_unaligned_le16(&bmp->header.bit_count));
wdenk9ca7bbc2004-10-09 23:25:58 +0000910 return 1;
911 }
912
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000913 debug("Display-bmp: %d x %d with %d colors\n",
wdenk9ca7bbc2004-10-09 23:25:58 +0000914 (int)width, (int)height, (int)colors);
915
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100916 if (bmp_bpix == 8) {
Nikita Kiryanov22425272012-08-09 00:14:52 +0000917 cmap = configuration_get_cmap();
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100918 cmap_base = cmap;
919
wdenk9ca7bbc2004-10-09 23:25:58 +0000920 /* Set color map */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000921 for (i = 0; i < colors; ++i) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000922 bmp_color_table_entry_t cte = bmp->color_table[i];
Mark Jackson8886b532008-08-01 09:48:29 +0100923#if !defined(CONFIG_ATMEL_LCD)
wdenk9ca7bbc2004-10-09 23:25:58 +0000924 ushort colreg =
925 ( ((cte.red) << 8) & 0xf800) |
Wolfgang Denkc4df5a42005-09-21 15:24:52 +0200926 ( ((cte.green) << 3) & 0x07e0) |
927 ( ((cte.blue) >> 3) & 0x001f) ;
wdenkb3a4a702004-12-10 11:40:40 +0000928 *cmap = colreg;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100929#if defined(CONFIG_MPC823)
wdenkb3a4a702004-12-10 11:40:40 +0000930 cmap--;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100931#else
932 cmap++;
wdenk9ca7bbc2004-10-09 23:25:58 +0000933#endif
Mark Jackson8886b532008-08-01 09:48:29 +0100934#else /* CONFIG_ATMEL_LCD */
935 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
936#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000937 }
938 }
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200939
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000940 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
Matthias Weisser53884182009-07-09 16:07:30 +0200941
942#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Nikita Kiryanovb4eb54d2012-08-09 00:14:51 +0000943 splash_align_axis(&x, pwidth, width);
944 splash_align_axis(&y, panel_info.vl_row, height);
Matthias Weisser53884182009-07-09 16:07:30 +0200945#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
946
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000947 if ((x + width) > pwidth)
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200948 width = pwidth - x;
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000949 if ((y + height) > panel_info.vl_row)
wdenk9ca7bbc2004-10-09 23:25:58 +0000950 height = panel_info.vl_row - y;
951
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100952 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
953 fb = (uchar *)(lcd_base +
Liu Ying1bb98712011-01-11 15:29:58 +0800954 (y + height - 1) * lcd_line_length + x * bpix / 8);
Mark Jackson7b298f32009-02-06 10:37:49 +0100955
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100956 switch (bmp_bpix) {
Mark Jackson7b298f32009-02-06 10:37:49 +0100957 case 1: /* pass through */
Simon Glassf461f122014-10-15 04:53:04 -0600958 case 8: {
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000959#ifdef CONFIG_LCD_BMP_RLE8
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100960 u32 compression = get_unaligned_le32(&bmp->header.compression);
961 if (compression == BMP_BI_RLE8) {
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000962 if (bpix != 16) {
963 /* TODO implement render code for bpix != 16 */
964 printf("Error: only support 16 bpix");
965 return 1;
966 }
967 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
968 break;
969 }
970#endif
971
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100972 if (bpix != 16)
973 byte_width = width;
974 else
975 byte_width = width * 2;
976
Mark Jackson7b298f32009-02-06 10:37:49 +0100977 for (i = 0; i < height; ++i) {
978 WATCHDOG_RESET();
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100979 for (j = 0; j < width; j++) {
980 if (bpix != 16) {
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000981 FB_PUT_BYTE(fb, bmap);
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100982 } else {
983 *(uint16_t *)fb = cmap_base[*(bmap++)];
984 fb += sizeof(uint16_t) / sizeof(*fb);
985 }
986 }
Tom Wai-Hong Tam93f04d62012-09-28 15:11:14 +0000987 bmap += (padded_width - width);
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000988 fb -= byte_width + lcd_line_length;
Mark Jackson7b298f32009-02-06 10:37:49 +0100989 }
990 break;
Simon Glassf461f122014-10-15 04:53:04 -0600991 }
Mark Jackson7b298f32009-02-06 10:37:49 +0100992#if defined(CONFIG_BMP_16BPP)
993 case 16:
994 for (i = 0; i < height; ++i) {
995 WATCHDOG_RESET();
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000996 for (j = 0; j < width; j++)
997 fb_put_word(&fb, &bmap);
998
Tom Wai-Hong Tam93f04d62012-09-28 15:11:14 +0000999 bmap += (padded_width - width) * 2;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +00001000 fb -= width * 2 + lcd_line_length;
Mark Jackson7b298f32009-02-06 10:37:49 +01001001 }
1002 break;
1003#endif /* CONFIG_BMP_16BPP */
Hannes Petermaier14b7eed2014-07-15 16:28:46 +02001004#if defined(CONFIG_BMP_24BMP)
1005 case 24:
1006 for (i = 0; i < height; ++i) {
1007 for (j = 0; j < width; j++) {
1008 *(fb++) = *(bmap++);
1009 *(fb++) = *(bmap++);
1010 *(fb++) = *(bmap++);
1011 *(fb++) = 0;
1012 }
1013 fb -= lcd_line_length + width * (bpix / 8);
1014 }
1015 break;
1016#endif /* CONFIG_BMP_24BMP */
Donghwa Leebf345a12012-05-09 19:23:37 +00001017#if defined(CONFIG_BMP_32BPP)
1018 case 32:
1019 for (i = 0; i < height; ++i) {
1020 for (j = 0; j < width; j++) {
1021 *(fb++) = *(bmap++);
1022 *(fb++) = *(bmap++);
1023 *(fb++) = *(bmap++);
1024 *(fb++) = *(bmap++);
1025 }
Jeroen Hofstee729b09e2013-01-12 12:07:56 +00001026 fb -= lcd_line_length + width * (bpix / 8);
Donghwa Leebf345a12012-05-09 19:23:37 +00001027 }
1028 break;
1029#endif /* CONFIG_BMP_32BPP */
Mark Jackson7b298f32009-02-06 10:37:49 +01001030 default:
1031 break;
1032 };
wdenk9ca7bbc2004-10-09 23:25:58 +00001033
Simon Glassef45ffd2012-10-30 13:40:18 +00001034 lcd_sync();
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001035 return 0;
wdenk9ca7bbc2004-10-09 23:25:58 +00001036}
Jon Loeliger052fc842007-07-08 18:10:08 -05001037#endif
wdenk9ca7bbc2004-10-09 23:25:58 +00001038
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001039static void *lcd_logo(void)
wdenk9ca7bbc2004-10-09 23:25:58 +00001040{
wdenk9ca7bbc2004-10-09 23:25:58 +00001041#ifdef CONFIG_SPLASH_SCREEN
1042 char *s;
1043 ulong addr;
1044 static int do_splash = 1;
1045
1046 if (do_splash && (s = getenv("splashimage")) != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +02001047 int x = 0, y = 0;
wdenk9ca7bbc2004-10-09 23:25:58 +00001048 do_splash = 0;
1049
Nikita Kiryanove0eba1f2013-01-30 21:39:57 +00001050 if (splash_screen_prepare())
Robert Winkler2a90ed02013-06-17 11:31:29 -07001051 return (void *)lcd_base;
Nikita Kiryanove0eba1f2013-01-30 21:39:57 +00001052
Matthias Weisser53884182009-07-09 16:07:30 +02001053 addr = simple_strtoul (s, NULL, 16);
Matthias Weisser53884182009-07-09 16:07:30 +02001054
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +02001055 splash_get_pos(&x, &y);
Matthias Weisser53884182009-07-09 16:07:30 +02001056
Nikita Kiryanov2b246c42012-08-09 00:14:50 +00001057 if (bmp_display(addr, x, y) == 0)
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001058 return (void *)lcd_base;
wdenk9ca7bbc2004-10-09 23:25:58 +00001059 }
1060#endif /* CONFIG_SPLASH_SCREEN */
1061
Anatolij Gustschin6f1378f2012-04-27 04:41:27 +00001062 bitmap_plot(0, 0);
wdenk9ca7bbc2004-10-09 23:25:58 +00001063
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +02001064#ifdef CONFIG_LCD_INFO
1065 console_col = LCD_INFO_X / VIDEO_FONT_WIDTH;
1066 console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT;
1067 lcd_show_board_info();
1068#endif /* CONFIG_LCD_INFO */
Stelian Popf6f86652008-05-09 21:57:18 +02001069
wdenk2b9d1862005-07-04 00:03:16 +00001070#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001071 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
wdenk9ca7bbc2004-10-09 23:25:58 +00001072#else
Nikita Kiryanov1f828412012-05-24 01:42:38 +00001073 return (void *)lcd_base;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +00001074#endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
wdenk9ca7bbc2004-10-09 23:25:58 +00001075}
1076
Nikita Kiryanov2f3e2ca2013-02-24 21:28:43 +00001077#ifdef CONFIG_SPLASHIMAGE_GUARD
1078static int on_splashimage(const char *name, const char *value, enum env_op op,
1079 int flags)
1080{
1081 ulong addr;
1082 int aligned;
1083
1084 if (op == env_op_delete)
1085 return 0;
1086
1087 addr = simple_strtoul(value, NULL, 16);
1088 /* See README.displaying-bmps */
1089 aligned = (addr % 4 == 2);
1090 if (!aligned) {
1091 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
1092 return -1;
1093 }
1094
1095 return 0;
1096}
1097
1098U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
1099#endif
1100
Vadim Bendeburya7eaa2f2012-09-28 15:11:13 +00001101void lcd_position_cursor(unsigned col, unsigned row)
1102{
Masahiro Yamadadb204642014-11-07 03:03:31 +09001103 console_col = min_t(short, col, CONSOLE_COLS - 1);
1104 console_row = min_t(short, row, CONSOLE_ROWS - 1);
Vadim Bendeburya7eaa2f2012-09-28 15:11:13 +00001105}
1106
1107int lcd_get_pixel_width(void)
1108{
1109 return panel_info.vl_col;
1110}
1111
1112int lcd_get_pixel_height(void)
1113{
1114 return panel_info.vl_row;
1115}
1116
1117int lcd_get_screen_rows(void)
1118{
1119 return CONSOLE_ROWS;
1120}
1121
1122int lcd_get_screen_columns(void)
1123{
1124 return CONSOLE_COLS;
1125}
Stephen Warrenefe64282013-05-27 18:31:17 +00001126
1127#if defined(CONFIG_LCD_DT_SIMPLEFB)
1128static int lcd_dt_simplefb_configure_node(void *blob, int off)
1129{
Stephen Warrenefe64282013-05-27 18:31:17 +00001130#if LCD_BPP == LCD_COLOR16
Hans de Goedeb2726f22014-11-19 13:53:27 +01001131 return fdt_setup_simplefb_node(blob, off, gd->fb_base,
1132 panel_info.vl_col, panel_info.vl_row,
1133 panel_info.vl_col * 2, "r5g6b5");
Stephen Warrenefe64282013-05-27 18:31:17 +00001134#else
Hans de Goedeb2726f22014-11-19 13:53:27 +01001135 return -1;
Stephen Warrenefe64282013-05-27 18:31:17 +00001136#endif
Stephen Warrenefe64282013-05-27 18:31:17 +00001137}
1138
1139int lcd_dt_simplefb_add_node(void *blob)
1140{
Stephen Warrenc4b7d652013-06-13 17:13:11 -06001141 static const char compat[] = "simple-framebuffer";
1142 static const char disabled[] = "disabled";
Stephen Warrenefe64282013-05-27 18:31:17 +00001143 int off, ret;
1144
1145 off = fdt_add_subnode(blob, 0, "framebuffer");
1146 if (off < 0)
1147 return -1;
1148
1149 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
1150 if (ret < 0)
1151 return -1;
1152
1153 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
1154 if (ret < 0)
1155 return -1;
1156
1157 return lcd_dt_simplefb_configure_node(blob, off);
1158}
1159
1160int lcd_dt_simplefb_enable_existing_node(void *blob)
1161{
1162 int off;
1163
1164 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
1165 if (off < 0)
1166 return -1;
1167
1168 return lcd_dt_simplefb_configure_node(blob, off);
1169}
1170#endif