blob: 8a8d6c3e94a6a6d473bb4a11a6f785ba4752ea61 [file] [log] [blame]
wdenk8655b6f2004-10-09 23:25:58 +00001/*
2 * Common LCD routines for supported CPUs
3 *
4 * (C) Copyright 2001-2002
5 * Wolfgang Denk, DENX Software Engineering -- wd@denx.de
6 *
Wolfgang Denk3765b3e2013-10-07 13:07:26 +02007 * SPDX-License-Identifier: GPL-2.0+
wdenk8655b6f2004-10-09 23:25:58 +00008 */
9
10/************************************************************************/
11/* ** HEADER FILES */
12/************************************************************************/
13
14/* #define DEBUG */
15
16#include <config.h>
17#include <common.h>
18#include <command.h>
wdenk8655b6f2004-10-09 23:25:58 +000019#include <stdarg.h>
Nikita Kiryanovc0880482013-02-24 21:28:43 +000020#include <search.h>
21#include <env_callback.h>
wdenk8655b6f2004-10-09 23:25:58 +000022#include <linux/types.h>
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +020023#include <stdio_dev.h>
wdenk8655b6f2004-10-09 23:25:58 +000024#if defined(CONFIG_POST)
25#include <post.h>
26#endif
27#include <lcd.h>
wdenk8b0bfc62005-04-03 23:11:38 +000028#include <watchdog.h>
Przemyslaw Marczakdca2a1c2014-01-22 11:24:13 +010029#include <asm/unaligned.h>
Robert Winklerdd4425e2013-06-17 11:31:29 -070030#include <splash.h>
Simon Glass7d95f2a2014-02-27 13:26:19 -070031#include <asm/io.h>
32#include <asm/unaligned.h>
Hans de Goede11b8dfa2014-11-19 13:53:27 +010033#include <fdt_support.h>
Robert Winklerdd4425e2013-06-17 11:31:29 -070034
Marek Vasutabc20ab2011-11-26 07:20:07 +010035#if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \
36 defined(CONFIG_CPU_MONAHANS)
wdenk8655b6f2004-10-09 23:25:58 +000037#include <asm/byteorder.h>
38#endif
39
40#if defined(CONFIG_MPC823)
wdenk8655b6f2004-10-09 23:25:58 +000041#include <lcdvideo.h>
42#endif
43
Stelian Pop39cf4802008-05-09 21:57:18 +020044#if defined(CONFIG_ATMEL_LCD)
45#include <atmel_lcdc.h>
Stelian Pop39cf4802008-05-09 21:57:18 +020046#endif
47
Stephen Warren6a195d22013-05-27 18:31:17 +000048#if defined(CONFIG_LCD_DT_SIMPLEFB)
49#include <libfdt.h>
50#endif
51
wdenk8655b6f2004-10-09 23:25:58 +000052/************************************************************************/
53/* ** FONT DATA */
54/************************************************************************/
55#include <video_font.h> /* Get font data, width and height */
56
wdenk88804d12005-07-04 00:03:16 +000057/************************************************************************/
58/* ** LOGO DATA */
59/************************************************************************/
60#ifdef CONFIG_LCD_LOGO
61# include <bmp_logo.h> /* Get logo data, width and height */
Che-Liang Chiouc2707302011-10-20 23:04:20 +000062# include <bmp_logo_data.h>
Alessandro Rubiniacb13862010-03-13 17:44:08 +010063# if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16)
wdenk88804d12005-07-04 00:03:16 +000064# error Default Color Map overlaps with Logo Color Map
65# endif
66#endif
wdenk8655b6f2004-10-09 23:25:58 +000067
Simon Glass7d95f2a2014-02-27 13:26:19 -070068#ifdef CONFIG_SANDBOX
69#include <asm/sdl.h>
70#endif
71
Simon Glass676d3192012-10-17 13:24:54 +000072#ifndef CONFIG_LCD_ALIGNMENT
73#define CONFIG_LCD_ALIGNMENT PAGE_SIZE
74#endif
75
Nikita Kiryanova7de2952014-12-08 17:14:42 +020076#if (LCD_BPP != LCD_COLOR8) && (LCD_BPP != LCD_COLOR16) && \
77 (LCD_BPP != LCD_COLOR32)
Jeroen Hofsteea5796c52013-01-12 12:07:59 +000078# error Unsupported LCD BPP.
79#endif
80
Wolfgang Denkd87080b2006-03-31 18:32:53 +020081DECLARE_GLOBAL_DATA_PTR;
wdenk8655b6f2004-10-09 23:25:58 +000082
Nikita Kiryanov8f47d912012-05-24 01:42:38 +000083static int lcd_init(void *lcdbase);
wdenk8655b6f2004-10-09 23:25:58 +000084
Jeroen Hofstee6b035142013-01-12 12:07:56 +000085static void *lcd_logo(void);
wdenk8655b6f2004-10-09 23:25:58 +000086
Nikita Kiryanov8f47d912012-05-24 01:42:38 +000087static void lcd_setfgcolor(int color);
88static void lcd_setbgcolor(int color);
wdenk8655b6f2004-10-09 23:25:58 +000089
Wolfgang Denk46d1d5d2013-01-05 09:45:48 +000090static int lcd_color_fg;
91static int lcd_color_bg;
Jeroen Hofsteef1d205a2013-01-22 10:44:11 +000092int lcd_line_length;
Wolfgang Denk46d1d5d2013-01-05 09:45:48 +000093
wdenk8655b6f2004-10-09 23:25:58 +000094char lcd_is_enabled = 0;
wdenk8655b6f2004-10-09 23:25:58 +000095
Jeroen Hofstee00a0ca52013-01-22 10:44:12 +000096static void *lcd_base; /* Start of framebuffer memory */
Jeroen Hofsteef1d205a2013-01-22 10:44:11 +000097
Simon Glass9a8efc42012-10-30 13:40:18 +000098static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */
99
wdenk8655b6f2004-10-09 23:25:58 +0000100/************************************************************************/
101
Simon Glass9a8efc42012-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 Glass7d95f2a2014-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 Glass9a8efc42012-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
wdenk8655b6f2004-10-09 23:25:58 +0000131/*----------------------------------------------------------------------*/
132
Simon Glass709ea542014-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 Glass709ea542014-07-23 06:54:59 -0600138static void lcd_stub_puts(struct stdio_dev *dev, const char *s)
139{
140 lcd_puts(s);
141}
142
wdenk8655b6f2004-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 Hofstee6b035142013-01-12 12:07:56 +0000151static int test_colors[N_BLK_HOR * N_BLK_VERT] = {
wdenk8655b6f2004-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 Kiryanov8f47d912012-05-24 01:42:38 +0000156static void test_pattern(void)
wdenk8655b6f2004-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 Kiryanov8f47d912012-05-24 01:42:38 +0000165 printf("[LCD] Test Pattern: %d x %d [%d x %d]\n",
wdenk8655b6f2004-10-09 23:25:58 +0000166 h_max, v_max, h_step, v_step);
167
168 /* WARNING: Code silently assumes 8bit/pixel */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000169 for (v = 0; v < v_max; ++v) {
wdenk8655b6f2004-10-09 23:25:58 +0000170 uchar iy = v / v_step;
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000171 for (h = 0; h < h_max; ++h) {
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000172 uchar ix = N_BLK_HOR * iy + h / h_step;
wdenk8655b6f2004-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 Gustschincefa4712013-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 Glass676d3192012-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 Hofstee6b035142013-01-12 12:07:56 +0000195int drv_lcd_init(void)
wdenk8655b6f2004-10-09 23:25:58 +0000196{
Jean-Christophe PLAGNIOL-VILLARD52cb4d42009-05-16 12:14:54 +0200197 struct stdio_dev lcddev;
wdenk8655b6f2004-10-09 23:25:58 +0000198 int rc;
199
Simon Glass7d95f2a2014-02-27 13:26:19 -0700200 lcd_base = map_sysmem(gd->fb_base, 0);
wdenk8655b6f2004-10-09 23:25:58 +0000201
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000202 lcd_init(lcd_base); /* LCD initialization */
wdenk8655b6f2004-10-09 23:25:58 +0000203
204 /* Device initialization */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000205 memset(&lcddev, 0, sizeof(lcddev));
wdenk8655b6f2004-10-09 23:25:58 +0000206
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000207 strcpy(lcddev.name, "lcd");
wdenk8655b6f2004-10-09 23:25:58 +0000208 lcddev.ext = 0; /* No extensions */
209 lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */
Simon Glass709ea542014-07-23 06:54:59 -0600210 lcddev.putc = lcd_stub_putc; /* 'putc' function */
211 lcddev.puts = lcd_stub_puts; /* 'puts' function */
wdenk8655b6f2004-10-09 23:25:58 +0000212
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000213 rc = stdio_register(&lcddev);
wdenk8655b6f2004-10-09 23:25:58 +0000214
215 return (rc == 0) ? 1 : rc;
216}
217
218/*----------------------------------------------------------------------*/
Che-Liang Chiou02110902011-10-20 23:07:03 +0000219void lcd_clear(void)
wdenk8655b6f2004-10-09 23:25:58 +0000220{
Nikita Kiryanov140beb92014-12-08 17:14:41 +0200221 short console_rows, console_cols;
Nikita Kiryanov4d036342014-12-08 17:14:43 +0200222 int bg_color;
Nikita Kiryanovf4469f52014-12-08 17:14:38 +0200223#if LCD_BPP == LCD_COLOR8
wdenk8655b6f2004-10-09 23:25:58 +0000224 /* Setting the palette */
Nikita Kiryanov8f47d912012-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);
wdenk8655b6f2004-10-09 23:25:58 +0000234#endif
235
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200236#ifndef CONFIG_SYS_WHITE_ON_BLACK
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000237 lcd_setfgcolor(CONSOLE_COLOR_BLACK);
238 lcd_setbgcolor(CONSOLE_COLOR_WHITE);
Nikita Kiryanov4d036342014-12-08 17:14:43 +0200239 bg_color = CONSOLE_COLOR_WHITE;
wdenk8655b6f2004-10-09 23:25:58 +0000240#else
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000241 lcd_setfgcolor(CONSOLE_COLOR_WHITE);
242 lcd_setbgcolor(CONSOLE_COLOR_BLACK);
Nikita Kiryanov4d036342014-12-08 17:14:43 +0200243 bg_color = CONSOLE_COLOR_BLACK;
Jean-Christophe PLAGNIOL-VILLARD6d0f6bc2008-10-16 15:01:15 +0200244#endif /* CONFIG_SYS_WHITE_ON_BLACK */
wdenk8655b6f2004-10-09 23:25:58 +0000245
246#ifdef LCD_TEST_PATTERN
247 test_pattern();
248#else
249 /* set framebuffer to background color */
Hannes Petermaier57d76a82014-03-07 18:55:40 +0100250#if (LCD_BPP != LCD_COLOR32)
Nikita Kiryanov4d036342014-12-08 17:14:43 +0200251 memset((char *)lcd_base, bg_color, lcd_line_length * panel_info.vl_row);
Hannes Petermaier57d76a82014-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 Kiryanov4d036342014-12-08 17:14:43 +0200258 *ppix++ = bg_color;
Hannes Petermaier57d76a82014-03-07 18:55:40 +0100259 }
260#endif
wdenk8655b6f2004-10-09 23:25:58 +0000261#endif
262 /* Paint the logo and retrieve LCD base address */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000263 debug("[LCD] Drawing the logo...\n");
Nikita Kiryanovefd7c4a2014-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 Shen2af13d62015-01-28 09:13:22 +0800271 lcd_init_console(lcd_base, console_rows, console_cols);
Nikita Kiryanov140beb92014-12-08 17:14:41 +0200272 lcd_init_console(lcd_logo(), console_rows, console_cols);
Simon Glass9a8efc42012-10-30 13:40:18 +0000273 lcd_sync();
274}
275
276static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
277 char *const argv[])
278{
279 lcd_clear();
280 return 0;
wdenk8655b6f2004-10-09 23:25:58 +0000281}
282
283U_BOOT_CMD(
Che-Liang Chiou02110902011-10-20 23:07:03 +0000284 cls, 1, 1, do_lcd_clear,
Peter Tyser2fb26042009-01-27 18:03:12 -0600285 "clear screen",
Wolfgang Denka89c33d2009-05-24 17:06:54 +0200286 ""
wdenk8655b6f2004-10-09 23:25:58 +0000287);
288
289/*----------------------------------------------------------------------*/
290
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000291static int lcd_init(void *lcdbase)
wdenk8655b6f2004-10-09 23:25:58 +0000292{
293 /* Initialize the lcd controller */
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000294 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
wdenk8655b6f2004-10-09 23:25:58 +0000295
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000296 lcd_ctrl_init(lcdbase);
Anatolij Gustschin1d3dea12013-03-29 14:00:13 +0100297
298 /*
Stephen Warren9316e142014-11-19 20:41:03 -0700299 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
Anatolij Gustschin1d3dea12013-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 Glass7d95f2a2014-02-27 13:26:19 -0700304 if (map_to_sysmem(lcdbase) != gd->fb_base)
305 lcd_base = map_sysmem(gd->fb_base, 0);
Anatolij Gustschin1d3dea12013-03-29 14:00:13 +0100306
307 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
308
Stephen Warren6d330712013-01-29 16:37:38 +0000309 lcd_get_size(&lcd_line_length);
Haavard Skinnemoen6f93d2b2008-09-01 16:21:21 +0200310 lcd_is_enabled = 1;
Che-Liang Chiou02110902011-10-20 23:07:03 +0000311 lcd_clear();
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000312 lcd_enable();
wdenk8655b6f2004-10-09 23:25:58 +0000313
314 /* Initialize the console */
Nikita Kiryanov140beb92014-12-08 17:14:41 +0200315 lcd_set_col(0);
wdenk88804d12005-07-04 00:03:16 +0000316#ifdef CONFIG_LCD_INFO_BELOW_LOGO
Nikita Kiryanov140beb92014-12-08 17:14:41 +0200317 lcd_set_row(7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT);
wdenk8655b6f2004-10-09 23:25:58 +0000318#else
Nikita Kiryanov140beb92014-12-08 17:14:41 +0200319 lcd_set_row(1); /* leave 1 blank line below logo */
wdenk8655b6f2004-10-09 23:25:58 +0000320#endif
wdenk8655b6f2004-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 Kiryanov8f47d912012-05-24 01:42:38 +0000336ulong lcd_setmem(ulong addr)
wdenk8655b6f2004-10-09 23:25:58 +0000337{
338 ulong size;
Simon Glass676d3192012-10-17 13:24:54 +0000339 int line_length;
wdenk8655b6f2004-10-09 23:25:58 +0000340
Nikita Kiryanov8f47d912012-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));
wdenk8655b6f2004-10-09 23:25:58 +0000343
Simon Glass676d3192012-10-17 13:24:54 +0000344 size = lcd_get_size(&line_length);
wdenk8655b6f2004-10-09 23:25:58 +0000345
Simon Glass676d3192012-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);
wdenk8655b6f2004-10-09 23:25:58 +0000349
350 /* Allocate pages for the frame buffer. */
351 addr -= size;
352
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000353 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
354 size >> 10, addr);
wdenk8655b6f2004-10-09 23:25:58 +0000355
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000356 return addr;
wdenk8655b6f2004-10-09 23:25:58 +0000357}
358
359/*----------------------------------------------------------------------*/
360
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000361static void lcd_setfgcolor(int color)
wdenk8655b6f2004-10-09 23:25:58 +0000362{
Stelian Pop39cf4802008-05-09 21:57:18 +0200363 lcd_color_fg = color;
wdenk8655b6f2004-10-09 23:25:58 +0000364}
365
Nikita Kiryanov4d036342014-12-08 17:14:43 +0200366int lcd_getfgcolor(void)
367{
368 return lcd_color_fg;
369}
370
wdenk8655b6f2004-10-09 23:25:58 +0000371/*----------------------------------------------------------------------*/
372
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000373static void lcd_setbgcolor(int color)
wdenk8655b6f2004-10-09 23:25:58 +0000374{
Stelian Pop39cf4802008-05-09 21:57:18 +0200375 lcd_color_bg = color;
wdenk8655b6f2004-10-09 23:25:58 +0000376}
377
Nikita Kiryanov4d036342014-12-08 17:14:43 +0200378int lcd_getbgcolor(void)
379{
380 return lcd_color_bg;
381}
382
wdenk8655b6f2004-10-09 23:25:58 +0000383/************************************************************************/
384/* ** Chipset depending Bitmap / Logo stuff... */
385/************************************************************************/
Nikita Kiryanov203c37b2012-08-09 00:14:52 +0000386
wdenk8655b6f2004-10-09 23:25:58 +0000387#ifdef CONFIG_LCD_LOGO
Nikita Kiryanova02e9482015-02-03 13:32:24 +0200388__weak void lcd_logo_set_cmap(void)
389{
Nikita Kiryanov23064572015-02-03 13:32:26 +0200390 int i;
391 ushort *cmap = configuration_get_cmap();
392
393 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i)
394 *cmap++ = bmp_logo_palette[i];
Nikita Kiryanova02e9482015-02-03 13:32:24 +0200395}
396
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000397void bitmap_plot(int x, int y)
wdenk8655b6f2004-10-09 23:25:58 +0000398{
wdenk8655b6f2004-10-09 23:25:58 +0000399 ushort i, j;
400 uchar *bmap;
401 uchar *fb;
402 ushort *fb16;
Andre Renaud317461c2013-02-13 17:48:00 +0000403 unsigned bpix = NBITS(panel_info.vl_bpix);
wdenk8655b6f2004-10-09 23:25:58 +0000404
Nikita Kiryanov23064572015-02-03 13:32:26 +0200405 debug("Logo: width %d height %d colors %d\n",
406 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS);
wdenk8655b6f2004-10-09 23:25:58 +0000407
408 bmap = &bmp_logo_bitmap[0];
Andre Renaud317461c2013-02-13 17:48:00 +0000409 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
wdenk8655b6f2004-10-09 23:25:58 +0000410
Andre Renaud317461c2013-02-13 17:48:00 +0000411 if (bpix < 12) {
wdenk8655b6f2004-10-09 23:25:58 +0000412 WATCHDOG_RESET();
Nikita Kiryanova02e9482015-02-03 13:32:24 +0200413 lcd_logo_set_cmap();
wdenk8655b6f2004-10-09 23:25:58 +0000414 WATCHDOG_RESET();
415
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000416 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
417 memcpy(fb, bmap, BMP_LOGO_WIDTH);
wdenk8655b6f2004-10-09 23:25:58 +0000418 bmap += BMP_LOGO_WIDTH;
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000419 fb += panel_info.vl_col;
wdenk8655b6f2004-10-09 23:25:58 +0000420 }
421 }
422 else { /* true color mode */
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100423 u16 col16;
Andre Renaud317461c2013-02-13 17:48:00 +0000424 fb16 = (ushort *)fb;
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000425 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
426 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
Alessandro Rubiniacb13862010-03-13 17:44:08 +0100427 col16 = bmp_logo_palette[(bmap[j]-16)];
428 fb16[j] =
429 ((col16 & 0x000F) << 1) |
430 ((col16 & 0x00F0) << 3) |
431 ((col16 & 0x0F00) << 4);
wdenk8655b6f2004-10-09 23:25:58 +0000432 }
433 bmap += BMP_LOGO_WIDTH;
434 fb16 += panel_info.vl_col;
435 }
436 }
437
438 WATCHDOG_RESET();
Simon Glass9a8efc42012-10-30 13:40:18 +0000439 lcd_sync();
wdenk8655b6f2004-10-09 23:25:58 +0000440}
Anatolij Gustschin2b5cb3d2012-04-27 04:41:27 +0000441#else
442static inline void bitmap_plot(int x, int y) {}
wdenk8655b6f2004-10-09 23:25:58 +0000443#endif /* CONFIG_LCD_LOGO */
444
445/*----------------------------------------------------------------------*/
Jon Loeligerc3517f92007-07-08 18:10:08 -0500446#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk8655b6f2004-10-09 23:25:58 +0000447/*
448 * Display the BMP file located at address bmp_image.
449 * Only uncompressed.
450 */
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200451
452#ifdef CONFIG_SPLASH_SCREEN_ALIGN
453#define BMP_ALIGN_CENTER 0x7FFF
Nikita Kiryanov7c7e2802012-08-09 00:14:51 +0000454
455static void splash_align_axis(int *axis, unsigned long panel_size,
456 unsigned long picture_size)
457{
458 unsigned long panel_picture_delta = panel_size - picture_size;
459 unsigned long axis_alignment;
460
461 if (*axis == BMP_ALIGN_CENTER)
462 axis_alignment = panel_picture_delta / 2;
463 else if (*axis < 0)
464 axis_alignment = panel_picture_delta + *axis + 1;
465 else
466 return;
467
Masahiro Yamadab4141192014-11-07 03:03:31 +0900468 *axis = max(0, (int)axis_alignment);
Nikita Kiryanov7c7e2802012-08-09 00:14:51 +0000469}
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200470#endif
471
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000472
473#ifdef CONFIG_LCD_BMP_RLE8
474
475#define BMP_RLE8_ESCAPE 0
476#define BMP_RLE8_EOL 0
477#define BMP_RLE8_EOBMP 1
478#define BMP_RLE8_DELTA 2
479
480static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
481 int cnt)
482{
483 while (cnt > 0) {
484 *(*fbp)++ = cmap[*bmap++];
485 cnt--;
486 }
487}
488
489static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
490{
491 ushort *fb = *fbp;
492 int cnt_8copy = cnt >> 3;
493
494 cnt -= cnt_8copy << 3;
495 while (cnt_8copy > 0) {
496 *fb++ = c;
497 *fb++ = c;
498 *fb++ = c;
499 *fb++ = c;
500 *fb++ = c;
501 *fb++ = c;
502 *fb++ = c;
503 *fb++ = c;
504 cnt_8copy--;
505 }
506 while (cnt > 0) {
507 *fb++ = c;
508 cnt--;
509 }
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000510 *fbp = fb;
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000511}
512
513/*
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000514 * Do not call this function directly, must be called from lcd_display_bitmap.
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000515 */
516static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
517 int x_off, int y_off)
518{
519 uchar *bmap;
520 ulong width, height;
521 ulong cnt, runlen;
522 int x, y;
523 int decode = 1;
524
Przemyslaw Marczakdca2a1c2014-01-22 11:24:13 +0100525 width = get_unaligned_le32(&bmp->header.width);
526 height = get_unaligned_le32(&bmp->header.height);
527 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000528
529 x = 0;
530 y = height - 1;
531
532 while (decode) {
533 if (bmap[0] == BMP_RLE8_ESCAPE) {
534 switch (bmap[1]) {
535 case BMP_RLE8_EOL:
536 /* end of line */
537 bmap += 2;
538 x = 0;
539 y--;
540 /* 16bpix, 2-byte per pixel, width should *2 */
541 fb -= (width * 2 + lcd_line_length);
542 break;
543 case BMP_RLE8_EOBMP:
544 /* end of bitmap */
545 decode = 0;
546 break;
547 case BMP_RLE8_DELTA:
548 /* delta run */
549 x += bmap[2];
550 y -= bmap[3];
551 /* 16bpix, 2-byte per pixel, x should *2 */
552 fb = (uchar *) (lcd_base + (y + y_off - 1)
553 * lcd_line_length + (x + x_off) * 2);
554 bmap += 4;
555 break;
556 default:
557 /* unencoded run */
558 runlen = bmap[1];
559 bmap += 2;
560 if (y < height) {
561 if (x < width) {
562 if (x + runlen > width)
563 cnt = width - x;
564 else
565 cnt = runlen;
566 draw_unencoded_bitmap(
567 (ushort **)&fb,
568 bmap, cmap, cnt);
569 }
570 x += runlen;
571 }
572 bmap += runlen;
573 if (runlen & 1)
574 bmap++;
575 }
576 } else {
577 /* encoded run */
578 if (y < height) {
579 runlen = bmap[0];
580 if (x < width) {
581 /* aggregate the same code */
582 while (bmap[0] == 0xff &&
583 bmap[2] != BMP_RLE8_ESCAPE &&
584 bmap[1] == bmap[3]) {
585 runlen += bmap[2];
586 bmap += 2;
587 }
588 if (x + runlen > width)
589 cnt = width - x;
590 else
591 cnt = runlen;
592 draw_encoded_bitmap((ushort **)&fb,
593 cmap[bmap[1]], cnt);
594 }
595 x += runlen;
596 }
597 bmap += 2;
598 }
599 }
600}
601#endif
602
Nikita Kiryanov27fad012015-02-03 13:32:23 +0200603__weak void fb_put_byte(uchar **fb, uchar **from)
604{
605 *(*fb)++ = *(*from)++;
606}
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +0000607
608#if defined(CONFIG_BMP_16BPP)
Nikita Kiryanovb3d12e92015-02-03 13:32:22 +0200609__weak void fb_put_word(uchar **fb, uchar **from)
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +0000610{
611 *(*fb)++ = *(*from)++;
612 *(*fb)++ = *(*from)++;
613}
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +0000614#endif /* CONFIG_BMP_16BPP */
615
Nikita Kiryanov0b29a892015-02-03 13:32:27 +0200616__weak void lcd_set_cmap(bmp_image_t *bmp, unsigned colors)
617{
618 int i;
619 bmp_color_table_entry_t cte;
620 ushort *cmap = configuration_get_cmap();
621
622 for (i = 0; i < colors; ++i) {
623 cte = bmp->color_table[i];
624 *cmap = (((cte.red) << 8) & 0xf800) |
625 (((cte.green) << 3) & 0x07e0) |
626 (((cte.blue) >> 3) & 0x001f);
627#if defined(CONFIG_MPC823)
628 cmap--;
629#else
630 cmap++;
631#endif
632 }
633}
634
wdenk8655b6f2004-10-09 23:25:58 +0000635int lcd_display_bitmap(ulong bmp_image, int x, int y)
636{
Anatolij Gustschin00cc5592009-02-25 20:28:13 +0100637 ushort *cmap_base = NULL;
wdenk8655b6f2004-10-09 23:25:58 +0000638 ushort i, j;
639 uchar *fb;
Simon Glass7d95f2a2014-02-27 13:26:19 -0700640 bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
wdenk8655b6f2004-10-09 23:25:58 +0000641 uchar *bmap;
Tom Wai-Hong Tamfecac462012-09-28 15:11:14 +0000642 ushort padded_width;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100643 unsigned long width, height, byte_width;
Wolfgang Denke8143e72006-08-30 23:09:00 +0200644 unsigned long pwidth = panel_info.vl_col;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100645 unsigned colors, bpix, bmp_bpix;
wdenk8655b6f2004-10-09 23:25:58 +0000646
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000647 if (!bmp || !(bmp->header.signature[0] == 'B' &&
648 bmp->header.signature[1] == 'M')) {
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000649 printf("Error: no valid bmp image at %lx\n", bmp_image);
650
wdenk8655b6f2004-10-09 23:25:58 +0000651 return 1;
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100652 }
wdenk8655b6f2004-10-09 23:25:58 +0000653
Przemyslaw Marczakdca2a1c2014-01-22 11:24:13 +0100654 width = get_unaligned_le32(&bmp->header.width);
655 height = get_unaligned_le32(&bmp->header.height);
656 bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
657
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100658 colors = 1 << bmp_bpix;
wdenk8655b6f2004-10-09 23:25:58 +0000659
660 bpix = NBITS(panel_info.vl_bpix);
661
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000662 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100663 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
664 bpix, bmp_bpix);
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000665
wdenk8655b6f2004-10-09 23:25:58 +0000666 return 1;
667 }
668
Hannes Petermaiera305fb12014-07-15 16:28:46 +0200669 /*
670 * We support displaying 8bpp BMPs on 16bpp LCDs
671 * and displaying 24bpp BMPs on 32bpp LCDs
672 * */
673 if (bpix != bmp_bpix &&
674 !(bmp_bpix == 8 && bpix == 16) &&
675 !(bmp_bpix == 24 && bpix == 32)) {
wdenk8655b6f2004-10-09 23:25:58 +0000676 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
Przemyslaw Marczakdca2a1c2014-01-22 11:24:13 +0100677 bpix, get_unaligned_le16(&bmp->header.bit_count));
wdenk8655b6f2004-10-09 23:25:58 +0000678 return 1;
679 }
680
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000681 debug("Display-bmp: %d x %d with %d colors\n",
wdenk8655b6f2004-10-09 23:25:58 +0000682 (int)width, (int)height, (int)colors);
683
Nikita Kiryanov0b29a892015-02-03 13:32:27 +0200684 if (bmp_bpix == 8)
685 lcd_set_cmap(bmp, colors);
Wolfgang Denke8143e72006-08-30 23:09:00 +0200686
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000687 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200688
689#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Nikita Kiryanov7c7e2802012-08-09 00:14:51 +0000690 splash_align_axis(&x, pwidth, width);
691 splash_align_axis(&y, panel_info.vl_row, height);
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200692#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
693
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000694 if ((x + width) > pwidth)
Wolfgang Denke8143e72006-08-30 23:09:00 +0200695 width = pwidth - x;
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000696 if ((y + height) > panel_info.vl_row)
wdenk8655b6f2004-10-09 23:25:58 +0000697 height = panel_info.vl_row - y;
698
Przemyslaw Marczakdca2a1c2014-01-22 11:24:13 +0100699 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
700 fb = (uchar *)(lcd_base +
Liu Ying8d46d5b2011-01-11 15:29:58 +0800701 (y + height - 1) * lcd_line_length + x * bpix / 8);
Mark Jacksona303dfb2009-02-06 10:37:49 +0100702
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100703 switch (bmp_bpix) {
Mark Jacksona303dfb2009-02-06 10:37:49 +0100704 case 1: /* pass through */
Simon Glass01564442014-10-15 04:53:04 -0600705 case 8: {
Nikita Kiryanov0b29a892015-02-03 13:32:27 +0200706 cmap_base = configuration_get_cmap();
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000707#ifdef CONFIG_LCD_BMP_RLE8
Przemyslaw Marczakdca2a1c2014-01-22 11:24:13 +0100708 u32 compression = get_unaligned_le32(&bmp->header.compression);
709 if (compression == BMP_BI_RLE8) {
Tom Wai-Hong Tam45d7f522012-09-28 15:11:16 +0000710 if (bpix != 16) {
711 /* TODO implement render code for bpix != 16 */
712 printf("Error: only support 16 bpix");
713 return 1;
714 }
715 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
716 break;
717 }
718#endif
719
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100720 if (bpix != 16)
721 byte_width = width;
722 else
723 byte_width = width * 2;
724
Mark Jacksona303dfb2009-02-06 10:37:49 +0100725 for (i = 0; i < height; ++i) {
726 WATCHDOG_RESET();
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100727 for (j = 0; j < width; j++) {
728 if (bpix != 16) {
Nikita Kiryanov27fad012015-02-03 13:32:23 +0200729 fb_put_byte(&fb, &bmap);
Guennadi Liakhovetskib245e652009-02-06 10:37:53 +0100730 } else {
731 *(uint16_t *)fb = cmap_base[*(bmap++)];
732 fb += sizeof(uint16_t) / sizeof(*fb);
733 }
734 }
Tom Wai-Hong Tamfecac462012-09-28 15:11:14 +0000735 bmap += (padded_width - width);
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000736 fb -= byte_width + lcd_line_length;
Mark Jacksona303dfb2009-02-06 10:37:49 +0100737 }
738 break;
Simon Glass01564442014-10-15 04:53:04 -0600739 }
Mark Jacksona303dfb2009-02-06 10:37:49 +0100740#if defined(CONFIG_BMP_16BPP)
741 case 16:
742 for (i = 0; i < height; ++i) {
743 WATCHDOG_RESET();
Nikita Kiryanovbfdcc652012-08-09 00:14:53 +0000744 for (j = 0; j < width; j++)
745 fb_put_word(&fb, &bmap);
746
Tom Wai-Hong Tamfecac462012-09-28 15:11:14 +0000747 bmap += (padded_width - width) * 2;
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000748 fb -= width * 2 + lcd_line_length;
Mark Jacksona303dfb2009-02-06 10:37:49 +0100749 }
750 break;
751#endif /* CONFIG_BMP_16BPP */
Hannes Petermaiera305fb12014-07-15 16:28:46 +0200752#if defined(CONFIG_BMP_24BMP)
753 case 24:
754 for (i = 0; i < height; ++i) {
755 for (j = 0; j < width; j++) {
756 *(fb++) = *(bmap++);
757 *(fb++) = *(bmap++);
758 *(fb++) = *(bmap++);
759 *(fb++) = 0;
760 }
761 fb -= lcd_line_length + width * (bpix / 8);
762 }
763 break;
764#endif /* CONFIG_BMP_24BMP */
Donghwa Leefb6a9aa2012-05-09 19:23:37 +0000765#if defined(CONFIG_BMP_32BPP)
766 case 32:
767 for (i = 0; i < height; ++i) {
768 for (j = 0; j < width; j++) {
769 *(fb++) = *(bmap++);
770 *(fb++) = *(bmap++);
771 *(fb++) = *(bmap++);
772 *(fb++) = *(bmap++);
773 }
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000774 fb -= lcd_line_length + width * (bpix / 8);
Donghwa Leefb6a9aa2012-05-09 19:23:37 +0000775 }
776 break;
777#endif /* CONFIG_BMP_32BPP */
Mark Jacksona303dfb2009-02-06 10:37:49 +0100778 default:
779 break;
780 };
wdenk8655b6f2004-10-09 23:25:58 +0000781
Simon Glass9a8efc42012-10-30 13:40:18 +0000782 lcd_sync();
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000783 return 0;
wdenk8655b6f2004-10-09 23:25:58 +0000784}
Jon Loeligerc3517f92007-07-08 18:10:08 -0500785#endif
wdenk8655b6f2004-10-09 23:25:58 +0000786
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000787static void *lcd_logo(void)
wdenk8655b6f2004-10-09 23:25:58 +0000788{
wdenk8655b6f2004-10-09 23:25:58 +0000789#ifdef CONFIG_SPLASH_SCREEN
790 char *s;
791 ulong addr;
792 static int do_splash = 1;
793
794 if (do_splash && (s = getenv("splashimage")) != NULL) {
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200795 int x = 0, y = 0;
wdenk8655b6f2004-10-09 23:25:58 +0000796 do_splash = 0;
797
Nikita Kiryanov581bb412013-01-30 21:39:57 +0000798 if (splash_screen_prepare())
Robert Winklerdd4425e2013-06-17 11:31:29 -0700799 return (void *)lcd_base;
Nikita Kiryanov581bb412013-01-30 21:39:57 +0000800
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200801 addr = simple_strtoul (s, NULL, 16);
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200802
Anatolij Gustschinff8fb562013-07-02 00:04:05 +0200803 splash_get_pos(&x, &y);
Matthias Weisser1ca298c2009-07-09 16:07:30 +0200804
Nikita Kiryanovd3a555e2012-08-09 00:14:50 +0000805 if (bmp_display(addr, x, y) == 0)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000806 return (void *)lcd_base;
wdenk8655b6f2004-10-09 23:25:58 +0000807 }
808#endif /* CONFIG_SPLASH_SCREEN */
809
Anatolij Gustschin2b5cb3d2012-04-27 04:41:27 +0000810 bitmap_plot(0, 0);
wdenk8655b6f2004-10-09 23:25:58 +0000811
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +0200812#ifdef CONFIG_LCD_INFO
Nikita Kiryanov140beb92014-12-08 17:14:41 +0200813 lcd_set_col(LCD_INFO_X / VIDEO_FONT_WIDTH);
814 lcd_set_row(LCD_INFO_Y / VIDEO_FONT_HEIGHT);
Haavard Skinnemoen6b59e032008-09-01 16:21:22 +0200815 lcd_show_board_info();
816#endif /* CONFIG_LCD_INFO */
Stelian Pop39cf4802008-05-09 21:57:18 +0200817
wdenk88804d12005-07-04 00:03:16 +0000818#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000819 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
wdenk8655b6f2004-10-09 23:25:58 +0000820#else
Nikita Kiryanov8f47d912012-05-24 01:42:38 +0000821 return (void *)lcd_base;
Jeroen Hofstee6b035142013-01-12 12:07:56 +0000822#endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
wdenk8655b6f2004-10-09 23:25:58 +0000823}
824
Nikita Kiryanovc0880482013-02-24 21:28:43 +0000825#ifdef CONFIG_SPLASHIMAGE_GUARD
826static int on_splashimage(const char *name, const char *value, enum env_op op,
827 int flags)
828{
829 ulong addr;
830 int aligned;
831
832 if (op == env_op_delete)
833 return 0;
834
835 addr = simple_strtoul(value, NULL, 16);
836 /* See README.displaying-bmps */
837 aligned = (addr % 4 == 2);
838 if (!aligned) {
839 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
840 return -1;
841 }
842
843 return 0;
844}
845
846U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
847#endif
848
Vadim Bendebury395166c2012-09-28 15:11:13 +0000849int lcd_get_pixel_width(void)
850{
851 return panel_info.vl_col;
852}
853
854int lcd_get_pixel_height(void)
855{
856 return panel_info.vl_row;
857}
858
Stephen Warren6a195d22013-05-27 18:31:17 +0000859#if defined(CONFIG_LCD_DT_SIMPLEFB)
860static int lcd_dt_simplefb_configure_node(void *blob, int off)
861{
Stephen Warren6a195d22013-05-27 18:31:17 +0000862#if LCD_BPP == LCD_COLOR16
Hans de Goede11b8dfa2014-11-19 13:53:27 +0100863 return fdt_setup_simplefb_node(blob, off, gd->fb_base,
864 panel_info.vl_col, panel_info.vl_row,
865 panel_info.vl_col * 2, "r5g6b5");
Stephen Warren6a195d22013-05-27 18:31:17 +0000866#else
Hans de Goede11b8dfa2014-11-19 13:53:27 +0100867 return -1;
Stephen Warren6a195d22013-05-27 18:31:17 +0000868#endif
Stephen Warren6a195d22013-05-27 18:31:17 +0000869}
870
871int lcd_dt_simplefb_add_node(void *blob)
872{
Stephen Warren5af7d0f2013-06-13 17:13:11 -0600873 static const char compat[] = "simple-framebuffer";
874 static const char disabled[] = "disabled";
Stephen Warren6a195d22013-05-27 18:31:17 +0000875 int off, ret;
876
877 off = fdt_add_subnode(blob, 0, "framebuffer");
878 if (off < 0)
879 return -1;
880
881 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
882 if (ret < 0)
883 return -1;
884
885 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
886 if (ret < 0)
887 return -1;
888
889 return lcd_dt_simplefb_configure_node(blob, off);
890}
891
892int lcd_dt_simplefb_enable_existing_node(void *blob)
893{
894 int off;
895
896 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
897 if (off < 0)
898 return -1;
899
900 return lcd_dt_simplefb_configure_node(blob, off);
901}
902#endif