blob: efd9a875456b76a080a464d6287be840a618ed95 [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
Nikita Kiryanov6c8cf8d2014-12-08 17:14:42 +020076#if (LCD_BPP != LCD_COLOR8) && (LCD_BPP != LCD_COLOR16) && \
77 (LCD_BPP != LCD_COLOR32)
Jeroen Hofsteecdc348a2013-01-12 12:07:59 +000078# error Unsupported LCD BPP.
79#endif
80
Wolfgang Denk6405a152006-03-31 18:32:53 +020081DECLARE_GLOBAL_DATA_PTR;
wdenk9ca7bbc2004-10-09 23:25:58 +000082
Nikita Kiryanov1f828412012-05-24 01:42:38 +000083static int lcd_init(void *lcdbase);
wdenk9ca7bbc2004-10-09 23:25:58 +000084
Jeroen Hofstee729b09e2013-01-12 12:07:56 +000085static void *lcd_logo(void);
wdenk9ca7bbc2004-10-09 23:25:58 +000086
Nikita Kiryanov1f828412012-05-24 01:42:38 +000087static void lcd_setfgcolor(int color);
88static void lcd_setbgcolor(int color);
wdenk9ca7bbc2004-10-09 23:25:58 +000089
Wolfgang Denk67f53912013-01-05 09:45:48 +000090static int lcd_color_fg;
91static int lcd_color_bg;
Jeroen Hofsteeb9092e62013-01-22 10:44:11 +000092int lcd_line_length;
Wolfgang Denk67f53912013-01-05 09:45:48 +000093
wdenk9ca7bbc2004-10-09 23:25:58 +000094char lcd_is_enabled = 0;
wdenk9ca7bbc2004-10-09 23:25:58 +000095
Jeroen Hofstee881c4ec2013-01-22 10:44:12 +000096static void *lcd_base; /* Start of framebuffer memory */
Simon Glassef45ffd2012-10-30 13:40:18 +000097
wdenk9ca7bbc2004-10-09 23:25:58 +000098static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
wdenk9ca7bbc2004-10-09 23:25:58 +000099
100/************************************************************************/
101
Simon Glassef45ffd2012-10-30 13:40:18 +0000102/* Flush LCD activity to the caches */
103void lcd_sync(void)
104{
105 /*
106 * flush_dcache_range() is declared in common.h but it seems that some
107 * architectures do not actually implement it. Is there a way to find
108 * out whether it exists? For now, ARM is safe.
109 */
110#if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF)
111 int line_length;
112
113 if (lcd_flush_dcache)
114 flush_dcache_range((u32)lcd_base,
115 (u32)(lcd_base + lcd_get_size(&line_length)));
Simon Glassb9ddbf42014-02-27 13:26:19 -0700116#elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL)
117 static ulong last_sync;
118
119 if (get_timer(last_sync) > 10) {
120 sandbox_sdl_sync(lcd_base);
121 last_sync = get_timer(0);
122 }
Simon Glassef45ffd2012-10-30 13:40:18 +0000123#endif
124}
125
126void lcd_set_flush_dcache(int flush)
127{
128 lcd_flush_dcache = (flush != 0);
129}
130
wdenk9ca7bbc2004-10-09 23:25:58 +0000131/*----------------------------------------------------------------------*/
132
Simon Glass0d1e1f72014-07-23 06:54:59 -0600133static void lcd_stub_putc(struct stdio_dev *dev, const char c)
134{
135 lcd_putc(c);
136}
137
Simon Glass0d1e1f72014-07-23 06:54:59 -0600138static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
139{
140 lcd_puts(s);
141}
142
wdenk9ca7bbc2004-10-09 23:25:58 +0000143/************************************************************************/
144/** Small utility to check that you got the colours right */
145/************************************************************************/
146#ifdef LCD_TEST_PATTERN
147
148#define N_BLK_VERT 2
149#define N_BLK_HOR 3
150
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000151static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
wdenk9ca7bbc2004-10-09 23:25:58 +0000152 CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW,
153 CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN,
154};
155
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000156static void test_pattern(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000157{
158 ushort v_max = panel_info.vl_row;
159 ushort h_max = panel_info.vl_col;
160 ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT;
161 ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR;
162 ushort v, h;
163 uchar *pix = (uchar *)lcd_base;
164
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000165 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
wdenk9ca7bbc2004-10-09 23:25:58 +0000166 h_max, v_max, h_step, v_step);
167
168 /* WARNING: Code silently assumes 8bit/pixel */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000169 for (v = 0; v < v_max; ++v) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000170 uchar iy = v / v_step;
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000171 for (h = 0; h < h_max; ++h) {
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000172 uchar ix = N_BLK_HOR * iy + h / h_step;
wdenk9ca7bbc2004-10-09 23:25:58 +0000173 *pix++ = test_colors[ix];
174 }
175 }
176}
177#endif /* LCD_TEST_PATTERN */
178
179
180/************************************************************************/
181/* ** GENERIC Initialization Routines */
182/************************************************************************/
Anatolij Gustschinfa50d902013-11-09 11:00:09 +0100183/*
184 * With most lcd drivers the line length is set up
185 * by calculating it from panel_info parameters. Some
186 * drivers need to calculate the line length differently,
187 * so make the function weak to allow overriding it.
188 */
189__weak int lcd_get_size(int *line_length)
Simon Glass599a4df2012-10-17 13:24:54 +0000190{
191 *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8;
192 return *line_length * panel_info.vl_row;
193}
194
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000195int drv_lcd_init(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000196{
Jean-Christophe PLAGNIOL-VILLARD2a7a0312009-05-16 12:14:54 +0200197 struct stdio_dev lcddev;
wdenk9ca7bbc2004-10-09 23:25:58 +0000198 int rc;
199
Simon Glassb9ddbf42014-02-27 13:26:19 -0700200 lcd_base = map_sysmem(gd->fb_base, 0);
wdenk9ca7bbc2004-10-09 23:25:58 +0000201
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000202 lcd_init(lcd_base); /* LCD initialization */
wdenk9ca7bbc2004-10-09 23:25:58 +0000203
204 /* Device initialization */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000205 memset(&lcddev, 0, sizeof(lcddev));
wdenk9ca7bbc2004-10-09 23:25:58 +0000206
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000207 strcpy(lcddev.name, "lcd");
wdenk9ca7bbc2004-10-09 23:25:58 +0000208 lcddev.ext = 0; /* No extensions */
209 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
Simon Glass0d1e1f72014-07-23 06:54:59 -0600210 lcddev.putc = lcd_stub_putc; /* 'putc' function */
211 lcddev.puts = lcd_stub_puts; /* 'puts' function */
wdenk9ca7bbc2004-10-09 23:25:58 +0000212
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000213 rc = stdio_register(&lcddev);
wdenk9ca7bbc2004-10-09 23:25:58 +0000214
215 return (rc == 0) ? 1 : rc;
216}
217
218/*----------------------------------------------------------------------*/
Che-Liang Chiou2444b172011-10-20 23:07:03 +0000219void lcd_clear(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000220{
Nikita Kiryanov699c05e2014-12-08 17:14:41 +0200221 short console_rows, console_cols;
Nikita Kiryanov631d2e12014-12-08 17:14:43 +0200222 int bg_color;
Nikita Kiryanov5aec5812014-12-08 17:14:38 +0200223#if LCD_BPP == LCD_COLOR8
wdenk9ca7bbc2004-10-09 23:25:58 +0000224 /* Setting the palette */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000225 lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0);
226 lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0);
227 lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0);
228 lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0);
229 lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF);
230 lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF);
231 lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF);
232 lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA);
233 lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF);
wdenk9ca7bbc2004-10-09 23:25:58 +0000234#endif
235
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200236#ifndef CONFIG_SYS_WHITE_ON_BLACK
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000237 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
238 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
Nikita Kiryanov631d2e12014-12-08 17:14:43 +0200239 bg_color = CONSOLE_COLOR_WHITE;
wdenk9ca7bbc2004-10-09 23:25:58 +0000240#else
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000241 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
242 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
Nikita Kiryanov631d2e12014-12-08 17:14:43 +0200243 bg_color = CONSOLE_COLOR_BLACK;
Jean-Christophe PLAGNIOL-VILLARD03836942008-10-16 15:01:15 +0200244#endif /* CONFIG_SYS_WHITE_ON_BLACK */
wdenk9ca7bbc2004-10-09 23:25:58 +0000245
246#ifdef LCD_TEST_PATTERN
247 test_pattern();
248#else
249 /* set framebuffer to background color */
Hannes Petermaier95f87df2014-03-07 18:55:40 +0100250#if (LCD_BPP != LCD_COLOR32)
Nikita Kiryanov631d2e12014-12-08 17:14:43 +0200251 memset((char *)lcd_base, bg_color, lcd_line_length * panel_info.vl_row);
Hannes Petermaier95f87df2014-03-07 18:55:40 +0100252#else
253 u32 *ppix = lcd_base;
254 u32 i;
255 for (i = 0;
256 i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix);
257 i++) {
Nikita Kiryanov631d2e12014-12-08 17:14:43 +0200258 *ppix++ = bg_color;
Hannes Petermaier95f87df2014-03-07 18:55:40 +0100259 }
260#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000261#endif
262 /* Paint the logo and retrieve LCD base address */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000263 debug("[LCD] Drawing the logo...\n");
Nikita Kiryanov0a6ed532014-12-08 17:14:40 +0200264#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
265 console_rows = (panel_info.vl_row - BMP_LOGO_HEIGHT);
266 console_rows /= VIDEO_FONT_HEIGHT;
267#else
268 console_rows = panel_info.vl_row / VIDEO_FONT_HEIGHT;
269#endif
270 console_cols = panel_info.vl_col / VIDEO_FONT_WIDTH;
Bo Shen18901132015-01-28 09:13:22 +0800271 lcd_init_console(lcd_base, console_rows, console_cols);
Nikita Kiryanov699c05e2014-12-08 17:14:41 +0200272 lcd_init_console(lcd_logo(), console_rows, console_cols);
Simon Glassef45ffd2012-10-30 13:40:18 +0000273 lcd_sync();
wdenk9ca7bbc2004-10-09 23:25:58 +0000274}
275
Simon Glassef45ffd2012-10-30 13:40:18 +0000276static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
277 char *const argv[])
278{
279 lcd_clear();
280 return 0;
281}
282
wdenk9ca7bbc2004-10-09 23:25:58 +0000283U_BOOT_CMD(
Che-Liang Chiou2444b172011-10-20 23:07:03 +0000284 cls, 1, 1, do_lcd_clear,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600285 "clear screen",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200286 ""
wdenk9ca7bbc2004-10-09 23:25:58 +0000287);
288
289/*----------------------------------------------------------------------*/
290
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000291static int lcd_init(void *lcdbase)
wdenk9ca7bbc2004-10-09 23:25:58 +0000292{
293 /* Initialize the lcd controller */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000294 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
wdenk9ca7bbc2004-10-09 23:25:58 +0000295
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000296 lcd_ctrl_init(lcdbase);
Anatolij Gustschin02591592013-03-29 14:00:13 +0100297
298 /*
Stephen Warren682b6b52014-11-19 20:41:03 -0700299 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
Anatolij Gustschin02591592013-03-29 14:00:13 +0100300 * the 'lcdbase' argument and uses custom lcd base address
301 * by setting up gd->fb_base. Check for this condition and fixup
302 * 'lcd_base' address.
303 */
Simon Glassb9ddbf42014-02-27 13:26:19 -0700304 if (map_to_sysmem(lcdbase) != gd->fb_base)
305 lcd_base = map_sysmem(gd->fb_base, 0);
Anatolij Gustschin02591592013-03-29 14:00:13 +0100306
307 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
308
Stephen Warrenefc8f792013-01-29 16:37:38 +0000309 lcd_get_size(&lcd_line_length);
Haavard Skinnemoen7eb8b232008-09-01 16:21:21 +0200310 lcd_is_enabled = 1;
Che-Liang Chiou2444b172011-10-20 23:07:03 +0000311 lcd_clear();
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000312 lcd_enable();
wdenk9ca7bbc2004-10-09 23:25:58 +0000313
314 /* Initialize the console */
Nikita Kiryanov699c05e2014-12-08 17:14:41 +0200315 lcd_set_col(0);
wdenk2b9d1862005-07-04 00:03:16 +0000316#ifdef CONFIG_LCD_INFO_BELOW_LOGO
Nikita Kiryanov699c05e2014-12-08 17:14:41 +0200317 lcd_set_row(7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT);
wdenk9ca7bbc2004-10-09 23:25:58 +0000318#else
Nikita Kiryanov699c05e2014-12-08 17:14:41 +0200319 lcd_set_row(1); /* leave 1 blank line below logo */
wdenk9ca7bbc2004-10-09 23:25:58 +0000320#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000321
322 return 0;
323}
324
325
326/************************************************************************/
327/* ** ROM capable initialization part - needed to reserve FB memory */
328/************************************************************************/
329/*
330 * This is called early in the system initialization to grab memory
331 * for the LCD controller.
332 * Returns new address for monitor, after reserving LCD buffer memory
333 *
334 * Note that this is running from ROM, so no write access to global data.
335 */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000336ulong lcd_setmem(ulong addr)
wdenk9ca7bbc2004-10-09 23:25:58 +0000337{
338 ulong size;
Simon Glass599a4df2012-10-17 13:24:54 +0000339 int line_length;
wdenk9ca7bbc2004-10-09 23:25:58 +0000340
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000341 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
342 panel_info.vl_row, NBITS(panel_info.vl_bpix));
wdenk9ca7bbc2004-10-09 23:25:58 +0000343
Simon Glass599a4df2012-10-17 13:24:54 +0000344 size = lcd_get_size(&line_length);
wdenk9ca7bbc2004-10-09 23:25:58 +0000345
Simon Glass599a4df2012-10-17 13:24:54 +0000346 /* Round up to nearest full page, or MMU section if defined */
347 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
348 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
wdenk9ca7bbc2004-10-09 23:25:58 +0000349
350 /* Allocate pages for the frame buffer. */
351 addr -= size;
352
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000353 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
354 size >> 10, addr);
wdenk9ca7bbc2004-10-09 23:25:58 +0000355
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000356 return addr;
wdenk9ca7bbc2004-10-09 23:25:58 +0000357}
358
359/*----------------------------------------------------------------------*/
360
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000361static void lcd_setfgcolor(int color)
wdenk9ca7bbc2004-10-09 23:25:58 +0000362{
Stelian Popf6f86652008-05-09 21:57:18 +0200363 lcd_color_fg = color;
wdenk9ca7bbc2004-10-09 23:25:58 +0000364}
365
Nikita Kiryanov631d2e12014-12-08 17:14:43 +0200366int lcd_getfgcolor(void)
367{
368 return lcd_color_fg;
369}
370
wdenk9ca7bbc2004-10-09 23:25:58 +0000371/*----------------------------------------------------------------------*/
372
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000373static void lcd_setbgcolor(int color)
wdenk9ca7bbc2004-10-09 23:25:58 +0000374{
Stelian Popf6f86652008-05-09 21:57:18 +0200375 lcd_color_bg = color;
wdenk9ca7bbc2004-10-09 23:25:58 +0000376}
377
Nikita Kiryanov631d2e12014-12-08 17:14:43 +0200378int lcd_getbgcolor(void)
379{
380 return lcd_color_bg;
381}
382
wdenk9ca7bbc2004-10-09 23:25:58 +0000383/************************************************************************/
384/* ** Chipset depending Bitmap / Logo stuff... */
385/************************************************************************/
Nikita Kiryanov22425272012-08-09 00:14:52 +0000386
wdenk9ca7bbc2004-10-09 23:25:58 +0000387#ifdef CONFIG_LCD_LOGO
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000388void bitmap_plot(int x, int y)
wdenk9ca7bbc2004-10-09 23:25:58 +0000389{
Stelian Popf6f86652008-05-09 21:57:18 +0200390#ifdef CONFIG_ATMEL_LCD
Nikita Kiryanov22425272012-08-09 00:14:52 +0000391 uint *cmap = (uint *)bmp_logo_palette;
Stelian Popf6f86652008-05-09 21:57:18 +0200392#else
Nikita Kiryanov22425272012-08-09 00:14:52 +0000393 ushort *cmap = (ushort *)bmp_logo_palette;
Stelian Popf6f86652008-05-09 21:57:18 +0200394#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000395 ushort i, j;
396 uchar *bmap;
397 uchar *fb;
398 ushort *fb16;
Nikita Kiryanov22425272012-08-09 00:14:52 +0000399#if defined(CONFIG_MPC823)
400 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
401 cpm8xx_t *cp = &(immr->im_cpm);
wdenk9ca7bbc2004-10-09 23:25:58 +0000402#endif
Andre Renaudada32ec2013-02-13 17:48:00 +0000403 unsigned bpix = NBITS(panel_info.vl_bpix);
wdenk9ca7bbc2004-10-09 23:25:58 +0000404
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000405 debug("Logo: width %d height %d colors %d cmap %d\n",
wdenk9ca7bbc2004-10-09 23:25:58 +0000406 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
Anatolij Gustschin218e6a02012-04-27 04:41:06 +0000407 ARRAY_SIZE(bmp_logo_palette));
wdenk9ca7bbc2004-10-09 23:25:58 +0000408
409 bmap = &bmp_logo_bitmap[0];
Andre Renaudada32ec2013-02-13 17:48:00 +0000410 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
wdenk9ca7bbc2004-10-09 23:25:58 +0000411
Andre Renaudada32ec2013-02-13 17:48:00 +0000412 if (bpix < 12) {
Nikita Kiryanov22425272012-08-09 00:14:52 +0000413 /* Leave room for default color map
414 * default case: generic system with no cmap (most likely 16bpp)
415 * cmap was set to the source palette, so no change is done.
416 * This avoids even more ifdefs in the next stanza
417 */
418#if defined(CONFIG_MPC823)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000419 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
Stelian Popf6f86652008-05-09 21:57:18 +0200420#elif defined(CONFIG_ATMEL_LCD)
Nikita Kiryanov22425272012-08-09 00:14:52 +0000421 cmap = (uint *)configuration_get_cmap();
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100422#else
Nikita Kiryanov22425272012-08-09 00:14:52 +0000423 cmap = configuration_get_cmap();
wdenk9ca7bbc2004-10-09 23:25:58 +0000424#endif
425
426 WATCHDOG_RESET();
427
428 /* Set color map */
Anatolij Gustschin218e6a02012-04-27 04:41:06 +0000429 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000430 ushort colreg = bmp_logo_palette[i];
Stelian Popf6f86652008-05-09 21:57:18 +0200431#ifdef CONFIG_ATMEL_LCD
432 uint lut_entry;
433#ifdef CONFIG_ATMEL_LCD_BGR555
434 lut_entry = ((colreg & 0x000F) << 11) |
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000435 ((colreg & 0x00F0) << 2) |
436 ((colreg & 0x0F00) >> 7);
Stelian Popf6f86652008-05-09 21:57:18 +0200437#else /* CONFIG_ATMEL_LCD_RGB565 */
438 lut_entry = ((colreg & 0x000F) << 1) |
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000439 ((colreg & 0x00F0) << 3) |
440 ((colreg & 0x0F00) << 4);
Stelian Popf6f86652008-05-09 21:57:18 +0200441#endif
442 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
443 cmap++;
444#else /* !CONFIG_ATMEL_LCD */
wdenk9ca7bbc2004-10-09 23:25:58 +0000445 *cmap++ = colreg;
Stelian Popf6f86652008-05-09 21:57:18 +0200446#endif /* CONFIG_ATMEL_LCD */
wdenk9ca7bbc2004-10-09 23:25:58 +0000447 }
448
449 WATCHDOG_RESET();
450
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000451 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
452 memcpy(fb, bmap, BMP_LOGO_WIDTH);
wdenk9ca7bbc2004-10-09 23:25:58 +0000453 bmap += BMP_LOGO_WIDTH;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000454 fb += panel_info.vl_col;
wdenk9ca7bbc2004-10-09 23:25:58 +0000455 }
456 }
457 else { /* true color mode */
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100458 u16 col16;
Andre Renaudada32ec2013-02-13 17:48:00 +0000459 fb16 = (ushort *)fb;
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000460 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
461 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100462 col16 = bmp_logo_palette[(bmap[j]-16)];
463 fb16[j] =
464 ((col16 & 0x000F) << 1) |
465 ((col16 & 0x00F0) << 3) |
466 ((col16 & 0x0F00) << 4);
wdenk9ca7bbc2004-10-09 23:25:58 +0000467 }
468 bmap += BMP_LOGO_WIDTH;
469 fb16 += panel_info.vl_col;
470 }
471 }
472
473 WATCHDOG_RESET();
Simon Glassef45ffd2012-10-30 13:40:18 +0000474 lcd_sync();
wdenk9ca7bbc2004-10-09 23:25:58 +0000475}
Anatolij Gustschin6f1378f2012-04-27 04:41:27 +0000476#else
477static inline void bitmap_plot(int x, int y) {}
wdenk9ca7bbc2004-10-09 23:25:58 +0000478#endif /* CONFIG_LCD_LOGO */
479
480/*----------------------------------------------------------------------*/
Jon Loeliger052fc842007-07-08 18:10:08 -0500481#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk9ca7bbc2004-10-09 23:25:58 +0000482/*
483 * Display the BMP file located at address bmp_image.
484 * Only uncompressed.
485 */
Matthias Weisser53884182009-07-09 16:07:30 +0200486
487#ifdef CONFIG_SPLASH_SCREEN_ALIGN
488#define BMP_ALIGN_CENTER 0x7FFF
Nikita Kiryanovb4eb54d2012-08-09 00:14:51 +0000489
490static void splash_align_axis(int *axis, unsigned long panel_size,
491 unsigned long picture_size)
492{
493 unsigned long panel_picture_delta = panel_size - picture_size;
494 unsigned long axis_alignment;
495
496 if (*axis == BMP_ALIGN_CENTER)
497 axis_alignment = panel_picture_delta / 2;
498 else if (*axis < 0)
499 axis_alignment = panel_picture_delta + *axis + 1;
500 else
501 return;
502
Masahiro Yamadadb204642014-11-07 03:03:31 +0900503 *axis = max(0, (int)axis_alignment);
Nikita Kiryanovb4eb54d2012-08-09 00:14:51 +0000504}
Matthias Weisser53884182009-07-09 16:07:30 +0200505#endif
506
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000507
508#ifdef CONFIG_LCD_BMP_RLE8
509
510#define BMP_RLE8_ESCAPE 0
511#define BMP_RLE8_EOL 0
512#define BMP_RLE8_EOBMP 1
513#define BMP_RLE8_DELTA 2
514
515static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
516 int cnt)
517{
518 while (cnt > 0) {
519 *(*fbp)++ = cmap[*bmap++];
520 cnt--;
521 }
522}
523
524static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
525{
526 ushort *fb = *fbp;
527 int cnt_8copy = cnt >> 3;
528
529 cnt -= cnt_8copy << 3;
530 while (cnt_8copy > 0) {
531 *fb++ = c;
532 *fb++ = c;
533 *fb++ = c;
534 *fb++ = c;
535 *fb++ = c;
536 *fb++ = c;
537 *fb++ = c;
538 *fb++ = c;
539 cnt_8copy--;
540 }
541 while (cnt > 0) {
542 *fb++ = c;
543 cnt--;
544 }
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000545 *fbp = fb;
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000546}
547
548/*
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000549 * Do not call this function directly, must be called from lcd_display_bitmap.
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000550 */
551static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
552 int x_off, int y_off)
553{
554 uchar *bmap;
555 ulong width, height;
556 ulong cnt, runlen;
557 int x, y;
558 int decode = 1;
559
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100560 width = get_unaligned_le32(&bmp->header.width);
561 height = get_unaligned_le32(&bmp->header.height);
562 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000563
564 x = 0;
565 y = height - 1;
566
567 while (decode) {
568 if (bmap[0] == BMP_RLE8_ESCAPE) {
569 switch (bmap[1]) {
570 case BMP_RLE8_EOL:
571 /* end of line */
572 bmap += 2;
573 x = 0;
574 y--;
575 /* 16bpix, 2-byte per pixel, width should *2 */
576 fb -= (width * 2 + lcd_line_length);
577 break;
578 case BMP_RLE8_EOBMP:
579 /* end of bitmap */
580 decode = 0;
581 break;
582 case BMP_RLE8_DELTA:
583 /* delta run */
584 x += bmap[2];
585 y -= bmap[3];
586 /* 16bpix, 2-byte per pixel, x should *2 */
587 fb = (uchar *) (lcd_base + (y + y_off - 1)
588 * lcd_line_length + (x + x_off) * 2);
589 bmap += 4;
590 break;
591 default:
592 /* unencoded run */
593 runlen = bmap[1];
594 bmap += 2;
595 if (y < height) {
596 if (x < width) {
597 if (x + runlen > width)
598 cnt = width - x;
599 else
600 cnt = runlen;
601 draw_unencoded_bitmap(
602 (ushort **)&fb,
603 bmap, cmap, cnt);
604 }
605 x += runlen;
606 }
607 bmap += runlen;
608 if (runlen & 1)
609 bmap++;
610 }
611 } else {
612 /* encoded run */
613 if (y < height) {
614 runlen = bmap[0];
615 if (x < width) {
616 /* aggregate the same code */
617 while (bmap[0] == 0xff &&
618 bmap[2] != BMP_RLE8_ESCAPE &&
619 bmap[1] == bmap[3]) {
620 runlen += bmap[2];
621 bmap += 2;
622 }
623 if (x + runlen > width)
624 cnt = width - x;
625 else
626 cnt = runlen;
627 draw_encoded_bitmap((ushort **)&fb,
628 cmap[bmap[1]], cnt);
629 }
630 x += runlen;
631 }
632 bmap += 2;
633 }
634 }
635}
636#endif
637
Nikita Kiryanovc999bcc2015-02-03 13:32:23 +0200638__weak void fb_put_byte(uchar **fb, uchar **from)
639{
640 *(*fb)++ = *(*from)++;
641}
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000642
643#if defined(CONFIG_BMP_16BPP)
Nikita Kiryanovc6cc0652015-02-03 13:32:22 +0200644__weak void fb_put_word(uchar **fb, uchar **from)
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000645{
646 *(*fb)++ = *(*from)++;
647 *(*fb)++ = *(*from)++;
648}
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000649#endif /* CONFIG_BMP_16BPP */
650
wdenk9ca7bbc2004-10-09 23:25:58 +0000651int lcd_display_bitmap(ulong bmp_image, int x, int y)
652{
Anatolij Gustschina11ca282009-02-25 20:28:13 +0100653 ushort *cmap = NULL;
Anatolij Gustschina11ca282009-02-25 20:28:13 +0100654 ushort *cmap_base = NULL;
wdenk9ca7bbc2004-10-09 23:25:58 +0000655 ushort i, j;
656 uchar *fb;
Simon Glassb9ddbf42014-02-27 13:26:19 -0700657 bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
wdenk9ca7bbc2004-10-09 23:25:58 +0000658 uchar *bmap;
Tom Wai-Hong Tam93f04d62012-09-28 15:11:14 +0000659 ushort padded_width;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100660 unsigned long width, height, byte_width;
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200661 unsigned long pwidth = panel_info.vl_col;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100662 unsigned colors, bpix, bmp_bpix;
wdenk9ca7bbc2004-10-09 23:25:58 +0000663
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000664 if (!bmp || !(bmp->header.signature[0] == 'B' &&
665 bmp->header.signature[1] == 'M')) {
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000666 printf("Error: no valid bmp image at %lx\n", bmp_image);
667
wdenk9ca7bbc2004-10-09 23:25:58 +0000668 return 1;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100669 }
wdenk9ca7bbc2004-10-09 23:25:58 +0000670
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100671 width = get_unaligned_le32(&bmp->header.width);
672 height = get_unaligned_le32(&bmp->header.height);
673 bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
674
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100675 colors = 1 << bmp_bpix;
wdenk9ca7bbc2004-10-09 23:25:58 +0000676
677 bpix = NBITS(panel_info.vl_bpix);
678
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000679 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100680 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
681 bpix, bmp_bpix);
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000682
wdenk9ca7bbc2004-10-09 23:25:58 +0000683 return 1;
684 }
685
Hannes Petermaier14b7eed2014-07-15 16:28:46 +0200686 /*
687 * We support displaying 8bpp BMPs on 16bpp LCDs
688 * and displaying 24bpp BMPs on 32bpp LCDs
689 * */
690 if (bpix != bmp_bpix &&
691 !(bmp_bpix == 8 && bpix == 16) &&
692 !(bmp_bpix == 24 && bpix == 32)) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000693 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100694 bpix, get_unaligned_le16(&bmp->header.bit_count));
wdenk9ca7bbc2004-10-09 23:25:58 +0000695 return 1;
696 }
697
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000698 debug("Display-bmp: %d x %d with %d colors\n",
wdenk9ca7bbc2004-10-09 23:25:58 +0000699 (int)width, (int)height, (int)colors);
700
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100701 if (bmp_bpix == 8) {
Nikita Kiryanov22425272012-08-09 00:14:52 +0000702 cmap = configuration_get_cmap();
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100703 cmap_base = cmap;
704
wdenk9ca7bbc2004-10-09 23:25:58 +0000705 /* Set color map */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000706 for (i = 0; i < colors; ++i) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000707 bmp_color_table_entry_t cte = bmp->color_table[i];
Mark Jackson8886b532008-08-01 09:48:29 +0100708#if !defined(CONFIG_ATMEL_LCD)
wdenk9ca7bbc2004-10-09 23:25:58 +0000709 ushort colreg =
710 ( ((cte.red) << 8) & 0xf800) |
Wolfgang Denkc4df5a42005-09-21 15:24:52 +0200711 ( ((cte.green) << 3) & 0x07e0) |
712 ( ((cte.blue) >> 3) & 0x001f) ;
wdenkb3a4a702004-12-10 11:40:40 +0000713 *cmap = colreg;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100714#if defined(CONFIG_MPC823)
wdenkb3a4a702004-12-10 11:40:40 +0000715 cmap--;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100716#else
717 cmap++;
wdenk9ca7bbc2004-10-09 23:25:58 +0000718#endif
Mark Jackson8886b532008-08-01 09:48:29 +0100719#else /* CONFIG_ATMEL_LCD */
720 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
721#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000722 }
723 }
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200724
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000725 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
Matthias Weisser53884182009-07-09 16:07:30 +0200726
727#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Nikita Kiryanovb4eb54d2012-08-09 00:14:51 +0000728 splash_align_axis(&x, pwidth, width);
729 splash_align_axis(&y, panel_info.vl_row, height);
Matthias Weisser53884182009-07-09 16:07:30 +0200730#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
731
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000732 if ((x + width) > pwidth)
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200733 width = pwidth - x;
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000734 if ((y + height) > panel_info.vl_row)
wdenk9ca7bbc2004-10-09 23:25:58 +0000735 height = panel_info.vl_row - y;
736
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100737 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
738 fb = (uchar *)(lcd_base +
Liu Ying1bb98712011-01-11 15:29:58 +0800739 (y + height - 1) * lcd_line_length + x * bpix / 8);
Mark Jackson7b298f32009-02-06 10:37:49 +0100740
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100741 switch (bmp_bpix) {
Mark Jackson7b298f32009-02-06 10:37:49 +0100742 case 1: /* pass through */
Simon Glassf461f122014-10-15 04:53:04 -0600743 case 8: {
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000744#ifdef CONFIG_LCD_BMP_RLE8
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100745 u32 compression = get_unaligned_le32(&bmp->header.compression);
746 if (compression == BMP_BI_RLE8) {
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000747 if (bpix != 16) {
748 /* TODO implement render code for bpix != 16 */
749 printf("Error: only support 16 bpix");
750 return 1;
751 }
752 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
753 break;
754 }
755#endif
756
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100757 if (bpix != 16)
758 byte_width = width;
759 else
760 byte_width = width * 2;
761
Mark Jackson7b298f32009-02-06 10:37:49 +0100762 for (i = 0; i < height; ++i) {
763 WATCHDOG_RESET();
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100764 for (j = 0; j < width; j++) {
765 if (bpix != 16) {
Nikita Kiryanovc999bcc2015-02-03 13:32:23 +0200766 fb_put_byte(&fb, &bmap);
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100767 } else {
768 *(uint16_t *)fb = cmap_base[*(bmap++)];
769 fb += sizeof(uint16_t) / sizeof(*fb);
770 }
771 }
Tom Wai-Hong Tam93f04d62012-09-28 15:11:14 +0000772 bmap += (padded_width - width);
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000773 fb -= byte_width + lcd_line_length;
Mark Jackson7b298f32009-02-06 10:37:49 +0100774 }
775 break;
Simon Glassf461f122014-10-15 04:53:04 -0600776 }
Mark Jackson7b298f32009-02-06 10:37:49 +0100777#if defined(CONFIG_BMP_16BPP)
778 case 16:
779 for (i = 0; i < height; ++i) {
780 WATCHDOG_RESET();
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000781 for (j = 0; j < width; j++)
782 fb_put_word(&fb, &bmap);
783
Tom Wai-Hong Tam93f04d62012-09-28 15:11:14 +0000784 bmap += (padded_width - width) * 2;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000785 fb -= width * 2 + lcd_line_length;
Mark Jackson7b298f32009-02-06 10:37:49 +0100786 }
787 break;
788#endif /* CONFIG_BMP_16BPP */
Hannes Petermaier14b7eed2014-07-15 16:28:46 +0200789#if defined(CONFIG_BMP_24BMP)
790 case 24:
791 for (i = 0; i < height; ++i) {
792 for (j = 0; j < width; j++) {
793 *(fb++) = *(bmap++);
794 *(fb++) = *(bmap++);
795 *(fb++) = *(bmap++);
796 *(fb++) = 0;
797 }
798 fb -= lcd_line_length + width * (bpix / 8);
799 }
800 break;
801#endif /* CONFIG_BMP_24BMP */
Donghwa Leebf345a12012-05-09 19:23:37 +0000802#if defined(CONFIG_BMP_32BPP)
803 case 32:
804 for (i = 0; i < height; ++i) {
805 for (j = 0; j < width; j++) {
806 *(fb++) = *(bmap++);
807 *(fb++) = *(bmap++);
808 *(fb++) = *(bmap++);
809 *(fb++) = *(bmap++);
810 }
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000811 fb -= lcd_line_length + width * (bpix / 8);
Donghwa Leebf345a12012-05-09 19:23:37 +0000812 }
813 break;
814#endif /* CONFIG_BMP_32BPP */
Mark Jackson7b298f32009-02-06 10:37:49 +0100815 default:
816 break;
817 };
wdenk9ca7bbc2004-10-09 23:25:58 +0000818
Simon Glassef45ffd2012-10-30 13:40:18 +0000819 lcd_sync();
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000820 return 0;
wdenk9ca7bbc2004-10-09 23:25:58 +0000821}
Jon Loeliger052fc842007-07-08 18:10:08 -0500822#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000823
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000824static void *lcd_logo(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000825{
wdenk9ca7bbc2004-10-09 23:25:58 +0000826#ifdef CONFIG_SPLASH_SCREEN
827 char *s;
828 ulong addr;
829 static int do_splash = 1;
830
831 if (do_splash && (s = getenv("splashimage")) != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +0200832 int x = 0, y = 0;
wdenk9ca7bbc2004-10-09 23:25:58 +0000833 do_splash = 0;
834
Nikita Kiryanove0eba1f2013-01-30 21:39:57 +0000835 if (splash_screen_prepare())
Robert Winkler2a90ed02013-06-17 11:31:29 -0700836 return (void *)lcd_base;
Nikita Kiryanove0eba1f2013-01-30 21:39:57 +0000837
Matthias Weisser53884182009-07-09 16:07:30 +0200838 addr = simple_strtoul (s, NULL, 16);
Matthias Weisser53884182009-07-09 16:07:30 +0200839
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +0200840 splash_get_pos(&x, &y);
Matthias Weisser53884182009-07-09 16:07:30 +0200841
Nikita Kiryanov2b246c42012-08-09 00:14:50 +0000842 if (bmp_display(addr, x, y) == 0)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000843 return (void *)lcd_base;
wdenk9ca7bbc2004-10-09 23:25:58 +0000844 }
845#endif /* CONFIG_SPLASH_SCREEN */
846
Anatolij Gustschin6f1378f2012-04-27 04:41:27 +0000847 bitmap_plot(0, 0);
wdenk9ca7bbc2004-10-09 23:25:58 +0000848
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200849#ifdef CONFIG_LCD_INFO
Nikita Kiryanov699c05e2014-12-08 17:14:41 +0200850 lcd_set_col(LCD_INFO_X / VIDEO_FONT_WIDTH);
851 lcd_set_row(LCD_INFO_Y / VIDEO_FONT_HEIGHT);
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200852 lcd_show_board_info();
853#endif /* CONFIG_LCD_INFO */
Stelian Popf6f86652008-05-09 21:57:18 +0200854
wdenk2b9d1862005-07-04 00:03:16 +0000855#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000856 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
wdenk9ca7bbc2004-10-09 23:25:58 +0000857#else
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000858 return (void *)lcd_base;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000859#endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
wdenk9ca7bbc2004-10-09 23:25:58 +0000860}
861
Nikita Kiryanov2f3e2ca2013-02-24 21:28:43 +0000862#ifdef CONFIG_SPLASHIMAGE_GUARD
863static int on_splashimage(const char *name, const char *value, enum env_op op,
864 int flags)
865{
866 ulong addr;
867 int aligned;
868
869 if (op == env_op_delete)
870 return 0;
871
872 addr = simple_strtoul(value, NULL, 16);
873 /* See README.displaying-bmps */
874 aligned = (addr % 4 == 2);
875 if (!aligned) {
876 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
877 return -1;
878 }
879
880 return 0;
881}
882
883U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
884#endif
885
Vadim Bendeburya7eaa2f2012-09-28 15:11:13 +0000886int lcd_get_pixel_width(void)
887{
888 return panel_info.vl_col;
889}
890
891int lcd_get_pixel_height(void)
892{
893 return panel_info.vl_row;
894}
895
Stephen Warrenefe64282013-05-27 18:31:17 +0000896#if defined(CONFIG_LCD_DT_SIMPLEFB)
897static int lcd_dt_simplefb_configure_node(void *blob, int off)
898{
Stephen Warrenefe64282013-05-27 18:31:17 +0000899#if LCD_BPP == LCD_COLOR16
Hans de Goedeb2726f22014-11-19 13:53:27 +0100900 return fdt_setup_simplefb_node(blob, off, gd->fb_base,
901 panel_info.vl_col, panel_info.vl_row,
902 panel_info.vl_col * 2, "r5g6b5");
Stephen Warrenefe64282013-05-27 18:31:17 +0000903#else
Hans de Goedeb2726f22014-11-19 13:53:27 +0100904 return -1;
Stephen Warrenefe64282013-05-27 18:31:17 +0000905#endif
Stephen Warrenefe64282013-05-27 18:31:17 +0000906}
907
908int lcd_dt_simplefb_add_node(void *blob)
909{
Stephen Warrenc4b7d652013-06-13 17:13:11 -0600910 static const char compat[] = "simple-framebuffer";
911 static const char disabled[] = "disabled";
Stephen Warrenefe64282013-05-27 18:31:17 +0000912 int off, ret;
913
914 off = fdt_add_subnode(blob, 0, "framebuffer");
915 if (off < 0)
916 return -1;
917
918 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
919 if (ret < 0)
920 return -1;
921
922 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
923 if (ret < 0)
924 return -1;
925
926 return lcd_dt_simplefb_configure_node(blob, off);
927}
928
929int lcd_dt_simplefb_enable_existing_node(void *blob)
930{
931 int off;
932
933 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
934 if (off < 0)
935 return -1;
936
937 return lcd_dt_simplefb_configure_node(blob, off);
938}
939#endif