blob: cc34b8aee4c484c123d6770d778331b9c8b6e880 [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;
Nikita Kiryanov699c05e2014-12-08 17:14:41 +0200271 lcd_init_console(lcd_logo(), console_rows, console_cols);
Simon Glassef45ffd2012-10-30 13:40:18 +0000272 lcd_sync();
wdenk9ca7bbc2004-10-09 23:25:58 +0000273}
274
Simon Glassef45ffd2012-10-30 13:40:18 +0000275static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc,
276 char *const argv[])
277{
278 lcd_clear();
279 return 0;
280}
281
wdenk9ca7bbc2004-10-09 23:25:58 +0000282U_BOOT_CMD(
Che-Liang Chiou2444b172011-10-20 23:07:03 +0000283 cls, 1, 1, do_lcd_clear,
Peter Tyserdfb72b82009-01-27 18:03:12 -0600284 "clear screen",
Wolfgang Denkc54781c2009-05-24 17:06:54 +0200285 ""
wdenk9ca7bbc2004-10-09 23:25:58 +0000286);
287
288/*----------------------------------------------------------------------*/
289
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000290static int lcd_init(void *lcdbase)
wdenk9ca7bbc2004-10-09 23:25:58 +0000291{
292 /* Initialize the lcd controller */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000293 debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase);
wdenk9ca7bbc2004-10-09 23:25:58 +0000294
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000295 lcd_ctrl_init(lcdbase);
Anatolij Gustschin02591592013-03-29 14:00:13 +0100296
297 /*
Stephen Warren682b6b52014-11-19 20:41:03 -0700298 * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi) ignores
Anatolij Gustschin02591592013-03-29 14:00:13 +0100299 * the 'lcdbase' argument and uses custom lcd base address
300 * by setting up gd->fb_base. Check for this condition and fixup
301 * 'lcd_base' address.
302 */
Simon Glassb9ddbf42014-02-27 13:26:19 -0700303 if (map_to_sysmem(lcdbase) != gd->fb_base)
304 lcd_base = map_sysmem(gd->fb_base, 0);
Anatolij Gustschin02591592013-03-29 14:00:13 +0100305
306 debug("[LCD] Using LCD frambuffer at %p\n", lcd_base);
307
Stephen Warrenefc8f792013-01-29 16:37:38 +0000308 lcd_get_size(&lcd_line_length);
Haavard Skinnemoen7eb8b232008-09-01 16:21:21 +0200309 lcd_is_enabled = 1;
Che-Liang Chiou2444b172011-10-20 23:07:03 +0000310 lcd_clear();
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000311 lcd_enable();
wdenk9ca7bbc2004-10-09 23:25:58 +0000312
313 /* Initialize the console */
Nikita Kiryanov699c05e2014-12-08 17:14:41 +0200314 lcd_set_col(0);
wdenk2b9d1862005-07-04 00:03:16 +0000315#ifdef CONFIG_LCD_INFO_BELOW_LOGO
Nikita Kiryanov699c05e2014-12-08 17:14:41 +0200316 lcd_set_row(7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT);
wdenk9ca7bbc2004-10-09 23:25:58 +0000317#else
Nikita Kiryanov699c05e2014-12-08 17:14:41 +0200318 lcd_set_row(1); /* leave 1 blank line below logo */
wdenk9ca7bbc2004-10-09 23:25:58 +0000319#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000320
321 return 0;
322}
323
324
325/************************************************************************/
326/* ** ROM capable initialization part - needed to reserve FB memory */
327/************************************************************************/
328/*
329 * This is called early in the system initialization to grab memory
330 * for the LCD controller.
331 * Returns new address for monitor, after reserving LCD buffer memory
332 *
333 * Note that this is running from ROM, so no write access to global data.
334 */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000335ulong lcd_setmem(ulong addr)
wdenk9ca7bbc2004-10-09 23:25:58 +0000336{
337 ulong size;
Simon Glass599a4df2012-10-17 13:24:54 +0000338 int line_length;
wdenk9ca7bbc2004-10-09 23:25:58 +0000339
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000340 debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col,
341 panel_info.vl_row, NBITS(panel_info.vl_bpix));
wdenk9ca7bbc2004-10-09 23:25:58 +0000342
Simon Glass599a4df2012-10-17 13:24:54 +0000343 size = lcd_get_size(&line_length);
wdenk9ca7bbc2004-10-09 23:25:58 +0000344
Simon Glass599a4df2012-10-17 13:24:54 +0000345 /* Round up to nearest full page, or MMU section if defined */
346 size = ALIGN(size, CONFIG_LCD_ALIGNMENT);
347 addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT);
wdenk9ca7bbc2004-10-09 23:25:58 +0000348
349 /* Allocate pages for the frame buffer. */
350 addr -= size;
351
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000352 debug("Reserving %ldk for LCD Framebuffer at: %08lx\n",
353 size >> 10, addr);
wdenk9ca7bbc2004-10-09 23:25:58 +0000354
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000355 return addr;
wdenk9ca7bbc2004-10-09 23:25:58 +0000356}
357
358/*----------------------------------------------------------------------*/
359
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000360static void lcd_setfgcolor(int color)
wdenk9ca7bbc2004-10-09 23:25:58 +0000361{
Stelian Popf6f86652008-05-09 21:57:18 +0200362 lcd_color_fg = color;
wdenk9ca7bbc2004-10-09 23:25:58 +0000363}
364
Nikita Kiryanov631d2e12014-12-08 17:14:43 +0200365int lcd_getfgcolor(void)
366{
367 return lcd_color_fg;
368}
369
wdenk9ca7bbc2004-10-09 23:25:58 +0000370/*----------------------------------------------------------------------*/
371
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000372static void lcd_setbgcolor(int color)
wdenk9ca7bbc2004-10-09 23:25:58 +0000373{
Stelian Popf6f86652008-05-09 21:57:18 +0200374 lcd_color_bg = color;
wdenk9ca7bbc2004-10-09 23:25:58 +0000375}
376
Nikita Kiryanov631d2e12014-12-08 17:14:43 +0200377int lcd_getbgcolor(void)
378{
379 return lcd_color_bg;
380}
381
wdenk9ca7bbc2004-10-09 23:25:58 +0000382/************************************************************************/
383/* ** Chipset depending Bitmap / Logo stuff... */
384/************************************************************************/
Nikita Kiryanov22425272012-08-09 00:14:52 +0000385static inline ushort *configuration_get_cmap(void)
386{
387#if defined CONFIG_CPU_PXA
388 struct pxafb_info *fbi = &panel_info.pxa;
389 return (ushort *)fbi->palette;
390#elif defined(CONFIG_MPC823)
391 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
392 cpm8xx_t *cp = &(immr->im_cpm);
393 return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]);
394#elif defined(CONFIG_ATMEL_LCD)
395 return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0));
Anatolij Gustschin4bb5fa42012-09-22 06:55:53 +0000396#elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB)
397 return panel_info.cmap;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000398#elif defined(CONFIG_LCD_LOGO)
Anatolij Gustschin4bb5fa42012-09-22 06:55:53 +0000399 return bmp_logo_palette;
400#else
401 return NULL;
402#endif
Nikita Kiryanov22425272012-08-09 00:14:52 +0000403}
404
wdenk9ca7bbc2004-10-09 23:25:58 +0000405#ifdef CONFIG_LCD_LOGO
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000406void bitmap_plot(int x, int y)
wdenk9ca7bbc2004-10-09 23:25:58 +0000407{
Stelian Popf6f86652008-05-09 21:57:18 +0200408#ifdef CONFIG_ATMEL_LCD
Nikita Kiryanov22425272012-08-09 00:14:52 +0000409 uint *cmap = (uint *)bmp_logo_palette;
Stelian Popf6f86652008-05-09 21:57:18 +0200410#else
Nikita Kiryanov22425272012-08-09 00:14:52 +0000411 ushort *cmap = (ushort *)bmp_logo_palette;
Stelian Popf6f86652008-05-09 21:57:18 +0200412#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000413 ushort i, j;
414 uchar *bmap;
415 uchar *fb;
416 ushort *fb16;
Nikita Kiryanov22425272012-08-09 00:14:52 +0000417#if defined(CONFIG_MPC823)
418 immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
419 cpm8xx_t *cp = &(immr->im_cpm);
wdenk9ca7bbc2004-10-09 23:25:58 +0000420#endif
Andre Renaudada32ec2013-02-13 17:48:00 +0000421 unsigned bpix = NBITS(panel_info.vl_bpix);
wdenk9ca7bbc2004-10-09 23:25:58 +0000422
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000423 debug("Logo: width %d height %d colors %d cmap %d\n",
wdenk9ca7bbc2004-10-09 23:25:58 +0000424 BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS,
Anatolij Gustschin218e6a02012-04-27 04:41:06 +0000425 ARRAY_SIZE(bmp_logo_palette));
wdenk9ca7bbc2004-10-09 23:25:58 +0000426
427 bmap = &bmp_logo_bitmap[0];
Andre Renaudada32ec2013-02-13 17:48:00 +0000428 fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8);
wdenk9ca7bbc2004-10-09 23:25:58 +0000429
Andre Renaudada32ec2013-02-13 17:48:00 +0000430 if (bpix < 12) {
Nikita Kiryanov22425272012-08-09 00:14:52 +0000431 /* Leave room for default color map
432 * default case: generic system with no cmap (most likely 16bpp)
433 * cmap was set to the source palette, so no change is done.
434 * This avoids even more ifdefs in the next stanza
435 */
436#if defined(CONFIG_MPC823)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000437 cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]);
Stelian Popf6f86652008-05-09 21:57:18 +0200438#elif defined(CONFIG_ATMEL_LCD)
Nikita Kiryanov22425272012-08-09 00:14:52 +0000439 cmap = (uint *)configuration_get_cmap();
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100440#else
Nikita Kiryanov22425272012-08-09 00:14:52 +0000441 cmap = configuration_get_cmap();
wdenk9ca7bbc2004-10-09 23:25:58 +0000442#endif
443
444 WATCHDOG_RESET();
445
446 /* Set color map */
Anatolij Gustschin218e6a02012-04-27 04:41:06 +0000447 for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000448 ushort colreg = bmp_logo_palette[i];
Stelian Popf6f86652008-05-09 21:57:18 +0200449#ifdef CONFIG_ATMEL_LCD
450 uint lut_entry;
451#ifdef CONFIG_ATMEL_LCD_BGR555
452 lut_entry = ((colreg & 0x000F) << 11) |
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000453 ((colreg & 0x00F0) << 2) |
454 ((colreg & 0x0F00) >> 7);
Stelian Popf6f86652008-05-09 21:57:18 +0200455#else /* CONFIG_ATMEL_LCD_RGB565 */
456 lut_entry = ((colreg & 0x000F) << 1) |
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000457 ((colreg & 0x00F0) << 3) |
458 ((colreg & 0x0F00) << 4);
Stelian Popf6f86652008-05-09 21:57:18 +0200459#endif
460 *(cmap + BMP_LOGO_OFFSET) = lut_entry;
461 cmap++;
462#else /* !CONFIG_ATMEL_LCD */
wdenk9ca7bbc2004-10-09 23:25:58 +0000463 *cmap++ = colreg;
Stelian Popf6f86652008-05-09 21:57:18 +0200464#endif /* CONFIG_ATMEL_LCD */
wdenk9ca7bbc2004-10-09 23:25:58 +0000465 }
466
467 WATCHDOG_RESET();
468
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000469 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
470 memcpy(fb, bmap, BMP_LOGO_WIDTH);
wdenk9ca7bbc2004-10-09 23:25:58 +0000471 bmap += BMP_LOGO_WIDTH;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000472 fb += panel_info.vl_col;
wdenk9ca7bbc2004-10-09 23:25:58 +0000473 }
474 }
475 else { /* true color mode */
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100476 u16 col16;
Andre Renaudada32ec2013-02-13 17:48:00 +0000477 fb16 = (ushort *)fb;
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000478 for (i = 0; i < BMP_LOGO_HEIGHT; ++i) {
479 for (j = 0; j < BMP_LOGO_WIDTH; j++) {
Alessandro Rubini2d68c262010-03-13 17:44:08 +0100480 col16 = bmp_logo_palette[(bmap[j]-16)];
481 fb16[j] =
482 ((col16 & 0x000F) << 1) |
483 ((col16 & 0x00F0) << 3) |
484 ((col16 & 0x0F00) << 4);
wdenk9ca7bbc2004-10-09 23:25:58 +0000485 }
486 bmap += BMP_LOGO_WIDTH;
487 fb16 += panel_info.vl_col;
488 }
489 }
490
491 WATCHDOG_RESET();
Simon Glassef45ffd2012-10-30 13:40:18 +0000492 lcd_sync();
wdenk9ca7bbc2004-10-09 23:25:58 +0000493}
Anatolij Gustschin6f1378f2012-04-27 04:41:27 +0000494#else
495static inline void bitmap_plot(int x, int y) {}
wdenk9ca7bbc2004-10-09 23:25:58 +0000496#endif /* CONFIG_LCD_LOGO */
497
498/*----------------------------------------------------------------------*/
Jon Loeliger052fc842007-07-08 18:10:08 -0500499#if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN)
wdenk9ca7bbc2004-10-09 23:25:58 +0000500/*
501 * Display the BMP file located at address bmp_image.
502 * Only uncompressed.
503 */
Matthias Weisser53884182009-07-09 16:07:30 +0200504
505#ifdef CONFIG_SPLASH_SCREEN_ALIGN
506#define BMP_ALIGN_CENTER 0x7FFF
Nikita Kiryanovb4eb54d2012-08-09 00:14:51 +0000507
508static void splash_align_axis(int *axis, unsigned long panel_size,
509 unsigned long picture_size)
510{
511 unsigned long panel_picture_delta = panel_size - picture_size;
512 unsigned long axis_alignment;
513
514 if (*axis == BMP_ALIGN_CENTER)
515 axis_alignment = panel_picture_delta / 2;
516 else if (*axis < 0)
517 axis_alignment = panel_picture_delta + *axis + 1;
518 else
519 return;
520
Masahiro Yamadadb204642014-11-07 03:03:31 +0900521 *axis = max(0, (int)axis_alignment);
Nikita Kiryanovb4eb54d2012-08-09 00:14:51 +0000522}
Matthias Weisser53884182009-07-09 16:07:30 +0200523#endif
524
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000525
526#ifdef CONFIG_LCD_BMP_RLE8
527
528#define BMP_RLE8_ESCAPE 0
529#define BMP_RLE8_EOL 0
530#define BMP_RLE8_EOBMP 1
531#define BMP_RLE8_DELTA 2
532
533static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap,
534 int cnt)
535{
536 while (cnt > 0) {
537 *(*fbp)++ = cmap[*bmap++];
538 cnt--;
539 }
540}
541
542static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt)
543{
544 ushort *fb = *fbp;
545 int cnt_8copy = cnt >> 3;
546
547 cnt -= cnt_8copy << 3;
548 while (cnt_8copy > 0) {
549 *fb++ = c;
550 *fb++ = c;
551 *fb++ = c;
552 *fb++ = c;
553 *fb++ = c;
554 *fb++ = c;
555 *fb++ = c;
556 *fb++ = c;
557 cnt_8copy--;
558 }
559 while (cnt > 0) {
560 *fb++ = c;
561 cnt--;
562 }
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000563 *fbp = fb;
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000564}
565
566/*
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000567 * Do not call this function directly, must be called from lcd_display_bitmap.
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000568 */
569static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb,
570 int x_off, int y_off)
571{
572 uchar *bmap;
573 ulong width, height;
574 ulong cnt, runlen;
575 int x, y;
576 int decode = 1;
577
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100578 width = get_unaligned_le32(&bmp->header.width);
579 height = get_unaligned_le32(&bmp->header.height);
580 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000581
582 x = 0;
583 y = height - 1;
584
585 while (decode) {
586 if (bmap[0] == BMP_RLE8_ESCAPE) {
587 switch (bmap[1]) {
588 case BMP_RLE8_EOL:
589 /* end of line */
590 bmap += 2;
591 x = 0;
592 y--;
593 /* 16bpix, 2-byte per pixel, width should *2 */
594 fb -= (width * 2 + lcd_line_length);
595 break;
596 case BMP_RLE8_EOBMP:
597 /* end of bitmap */
598 decode = 0;
599 break;
600 case BMP_RLE8_DELTA:
601 /* delta run */
602 x += bmap[2];
603 y -= bmap[3];
604 /* 16bpix, 2-byte per pixel, x should *2 */
605 fb = (uchar *) (lcd_base + (y + y_off - 1)
606 * lcd_line_length + (x + x_off) * 2);
607 bmap += 4;
608 break;
609 default:
610 /* unencoded run */
611 runlen = bmap[1];
612 bmap += 2;
613 if (y < height) {
614 if (x < width) {
615 if (x + runlen > width)
616 cnt = width - x;
617 else
618 cnt = runlen;
619 draw_unencoded_bitmap(
620 (ushort **)&fb,
621 bmap, cmap, cnt);
622 }
623 x += runlen;
624 }
625 bmap += runlen;
626 if (runlen & 1)
627 bmap++;
628 }
629 } else {
630 /* encoded run */
631 if (y < height) {
632 runlen = bmap[0];
633 if (x < width) {
634 /* aggregate the same code */
635 while (bmap[0] == 0xff &&
636 bmap[2] != BMP_RLE8_ESCAPE &&
637 bmap[1] == bmap[3]) {
638 runlen += bmap[2];
639 bmap += 2;
640 }
641 if (x + runlen > width)
642 cnt = width - x;
643 else
644 cnt = runlen;
645 draw_encoded_bitmap((ushort **)&fb,
646 cmap[bmap[1]], cnt);
647 }
648 x += runlen;
649 }
650 bmap += 2;
651 }
652 }
653}
654#endif
655
Nikita Kiryanov200c12b2014-11-11 15:46:05 +0200656#if defined(CONFIG_MPC823)
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000657#define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++)
Anatolij Gustschin4bb5fa42012-09-22 06:55:53 +0000658#else
659#define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000660#endif
661
662#if defined(CONFIG_BMP_16BPP)
663#if defined(CONFIG_ATMEL_LCD_BGR555)
664static inline void fb_put_word(uchar **fb, uchar **from)
665{
666 *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03);
667 *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2);
668 *from += 2;
669}
670#else
671static inline void fb_put_word(uchar **fb, uchar **from)
672{
673 *(*fb)++ = *(*from)++;
674 *(*fb)++ = *(*from)++;
675}
676#endif
677#endif /* CONFIG_BMP_16BPP */
678
wdenk9ca7bbc2004-10-09 23:25:58 +0000679int lcd_display_bitmap(ulong bmp_image, int x, int y)
680{
Anatolij Gustschina11ca282009-02-25 20:28:13 +0100681 ushort *cmap = NULL;
Anatolij Gustschina11ca282009-02-25 20:28:13 +0100682 ushort *cmap_base = NULL;
wdenk9ca7bbc2004-10-09 23:25:58 +0000683 ushort i, j;
684 uchar *fb;
Simon Glassb9ddbf42014-02-27 13:26:19 -0700685 bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0);
wdenk9ca7bbc2004-10-09 23:25:58 +0000686 uchar *bmap;
Tom Wai-Hong Tam93f04d62012-09-28 15:11:14 +0000687 ushort padded_width;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100688 unsigned long width, height, byte_width;
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200689 unsigned long pwidth = panel_info.vl_col;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100690 unsigned colors, bpix, bmp_bpix;
wdenk9ca7bbc2004-10-09 23:25:58 +0000691
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000692 if (!bmp || !(bmp->header.signature[0] == 'B' &&
693 bmp->header.signature[1] == 'M')) {
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000694 printf("Error: no valid bmp image at %lx\n", bmp_image);
695
wdenk9ca7bbc2004-10-09 23:25:58 +0000696 return 1;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100697 }
wdenk9ca7bbc2004-10-09 23:25:58 +0000698
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100699 width = get_unaligned_le32(&bmp->header.width);
700 height = get_unaligned_le32(&bmp->header.height);
701 bmp_bpix = get_unaligned_le16(&bmp->header.bit_count);
702
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100703 colors = 1 << bmp_bpix;
wdenk9ca7bbc2004-10-09 23:25:58 +0000704
705 bpix = NBITS(panel_info.vl_bpix);
706
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000707 if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) {
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100708 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
709 bpix, bmp_bpix);
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000710
wdenk9ca7bbc2004-10-09 23:25:58 +0000711 return 1;
712 }
713
Hannes Petermaier14b7eed2014-07-15 16:28:46 +0200714 /*
715 * We support displaying 8bpp BMPs on 16bpp LCDs
716 * and displaying 24bpp BMPs on 32bpp LCDs
717 * */
718 if (bpix != bmp_bpix &&
719 !(bmp_bpix == 8 && bpix == 16) &&
720 !(bmp_bpix == 24 && bpix == 32)) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000721 printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n",
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100722 bpix, get_unaligned_le16(&bmp->header.bit_count));
wdenk9ca7bbc2004-10-09 23:25:58 +0000723 return 1;
724 }
725
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000726 debug("Display-bmp: %d x %d with %d colors\n",
wdenk9ca7bbc2004-10-09 23:25:58 +0000727 (int)width, (int)height, (int)colors);
728
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100729 if (bmp_bpix == 8) {
Nikita Kiryanov22425272012-08-09 00:14:52 +0000730 cmap = configuration_get_cmap();
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100731 cmap_base = cmap;
732
wdenk9ca7bbc2004-10-09 23:25:58 +0000733 /* Set color map */
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000734 for (i = 0; i < colors; ++i) {
wdenk9ca7bbc2004-10-09 23:25:58 +0000735 bmp_color_table_entry_t cte = bmp->color_table[i];
Mark Jackson8886b532008-08-01 09:48:29 +0100736#if !defined(CONFIG_ATMEL_LCD)
wdenk9ca7bbc2004-10-09 23:25:58 +0000737 ushort colreg =
738 ( ((cte.red) << 8) & 0xf800) |
Wolfgang Denkc4df5a42005-09-21 15:24:52 +0200739 ( ((cte.green) << 3) & 0x07e0) |
740 ( ((cte.blue) >> 3) & 0x001f) ;
wdenkb3a4a702004-12-10 11:40:40 +0000741 *cmap = colreg;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100742#if defined(CONFIG_MPC823)
wdenkb3a4a702004-12-10 11:40:40 +0000743 cmap--;
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100744#else
745 cmap++;
wdenk9ca7bbc2004-10-09 23:25:58 +0000746#endif
Mark Jackson8886b532008-08-01 09:48:29 +0100747#else /* CONFIG_ATMEL_LCD */
748 lcd_setcolreg(i, cte.red, cte.green, cte.blue);
749#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000750 }
751 }
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200752
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000753 padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width);
Matthias Weisser53884182009-07-09 16:07:30 +0200754
755#ifdef CONFIG_SPLASH_SCREEN_ALIGN
Nikita Kiryanovb4eb54d2012-08-09 00:14:51 +0000756 splash_align_axis(&x, pwidth, width);
757 splash_align_axis(&y, panel_info.vl_row, height);
Matthias Weisser53884182009-07-09 16:07:30 +0200758#endif /* CONFIG_SPLASH_SCREEN_ALIGN */
759
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000760 if ((x + width) > pwidth)
Wolfgang Denkd4321d32006-08-30 23:09:00 +0200761 width = pwidth - x;
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000762 if ((y + height) > panel_info.vl_row)
wdenk9ca7bbc2004-10-09 23:25:58 +0000763 height = panel_info.vl_row - y;
764
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100765 bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset);
766 fb = (uchar *)(lcd_base +
Liu Ying1bb98712011-01-11 15:29:58 +0800767 (y + height - 1) * lcd_line_length + x * bpix / 8);
Mark Jackson7b298f32009-02-06 10:37:49 +0100768
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100769 switch (bmp_bpix) {
Mark Jackson7b298f32009-02-06 10:37:49 +0100770 case 1: /* pass through */
Simon Glassf461f122014-10-15 04:53:04 -0600771 case 8: {
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000772#ifdef CONFIG_LCD_BMP_RLE8
Przemyslaw Marczakc3bf15e2014-01-22 11:24:13 +0100773 u32 compression = get_unaligned_le32(&bmp->header.compression);
774 if (compression == BMP_BI_RLE8) {
Tom Wai-Hong Tam79926a42012-09-28 15:11:16 +0000775 if (bpix != 16) {
776 /* TODO implement render code for bpix != 16 */
777 printf("Error: only support 16 bpix");
778 return 1;
779 }
780 lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y);
781 break;
782 }
783#endif
784
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100785 if (bpix != 16)
786 byte_width = width;
787 else
788 byte_width = width * 2;
789
Mark Jackson7b298f32009-02-06 10:37:49 +0100790 for (i = 0; i < height; ++i) {
791 WATCHDOG_RESET();
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100792 for (j = 0; j < width; j++) {
793 if (bpix != 16) {
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000794 FB_PUT_BYTE(fb, bmap);
Guennadi Liakhovetski332d0b52009-02-06 10:37:53 +0100795 } else {
796 *(uint16_t *)fb = cmap_base[*(bmap++)];
797 fb += sizeof(uint16_t) / sizeof(*fb);
798 }
799 }
Tom Wai-Hong Tam93f04d62012-09-28 15:11:14 +0000800 bmap += (padded_width - width);
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000801 fb -= byte_width + lcd_line_length;
Mark Jackson7b298f32009-02-06 10:37:49 +0100802 }
803 break;
Simon Glassf461f122014-10-15 04:53:04 -0600804 }
Mark Jackson7b298f32009-02-06 10:37:49 +0100805#if defined(CONFIG_BMP_16BPP)
806 case 16:
807 for (i = 0; i < height; ++i) {
808 WATCHDOG_RESET();
Nikita Kiryanovb4571182012-08-09 00:14:53 +0000809 for (j = 0; j < width; j++)
810 fb_put_word(&fb, &bmap);
811
Tom Wai-Hong Tam93f04d62012-09-28 15:11:14 +0000812 bmap += (padded_width - width) * 2;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000813 fb -= width * 2 + lcd_line_length;
Mark Jackson7b298f32009-02-06 10:37:49 +0100814 }
815 break;
816#endif /* CONFIG_BMP_16BPP */
Hannes Petermaier14b7eed2014-07-15 16:28:46 +0200817#if defined(CONFIG_BMP_24BMP)
818 case 24:
819 for (i = 0; i < height; ++i) {
820 for (j = 0; j < width; j++) {
821 *(fb++) = *(bmap++);
822 *(fb++) = *(bmap++);
823 *(fb++) = *(bmap++);
824 *(fb++) = 0;
825 }
826 fb -= lcd_line_length + width * (bpix / 8);
827 }
828 break;
829#endif /* CONFIG_BMP_24BMP */
Donghwa Leebf345a12012-05-09 19:23:37 +0000830#if defined(CONFIG_BMP_32BPP)
831 case 32:
832 for (i = 0; i < height; ++i) {
833 for (j = 0; j < width; j++) {
834 *(fb++) = *(bmap++);
835 *(fb++) = *(bmap++);
836 *(fb++) = *(bmap++);
837 *(fb++) = *(bmap++);
838 }
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000839 fb -= lcd_line_length + width * (bpix / 8);
Donghwa Leebf345a12012-05-09 19:23:37 +0000840 }
841 break;
842#endif /* CONFIG_BMP_32BPP */
Mark Jackson7b298f32009-02-06 10:37:49 +0100843 default:
844 break;
845 };
wdenk9ca7bbc2004-10-09 23:25:58 +0000846
Simon Glassef45ffd2012-10-30 13:40:18 +0000847 lcd_sync();
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000848 return 0;
wdenk9ca7bbc2004-10-09 23:25:58 +0000849}
Jon Loeliger052fc842007-07-08 18:10:08 -0500850#endif
wdenk9ca7bbc2004-10-09 23:25:58 +0000851
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000852static void *lcd_logo(void)
wdenk9ca7bbc2004-10-09 23:25:58 +0000853{
wdenk9ca7bbc2004-10-09 23:25:58 +0000854#ifdef CONFIG_SPLASH_SCREEN
855 char *s;
856 ulong addr;
857 static int do_splash = 1;
858
859 if (do_splash && (s = getenv("splashimage")) != NULL) {
Matthias Weisser53884182009-07-09 16:07:30 +0200860 int x = 0, y = 0;
wdenk9ca7bbc2004-10-09 23:25:58 +0000861 do_splash = 0;
862
Nikita Kiryanove0eba1f2013-01-30 21:39:57 +0000863 if (splash_screen_prepare())
Robert Winkler2a90ed02013-06-17 11:31:29 -0700864 return (void *)lcd_base;
Nikita Kiryanove0eba1f2013-01-30 21:39:57 +0000865
Matthias Weisser53884182009-07-09 16:07:30 +0200866 addr = simple_strtoul (s, NULL, 16);
Matthias Weisser53884182009-07-09 16:07:30 +0200867
Anatolij Gustschinb9b5eaf2013-07-02 00:04:05 +0200868 splash_get_pos(&x, &y);
Matthias Weisser53884182009-07-09 16:07:30 +0200869
Nikita Kiryanov2b246c42012-08-09 00:14:50 +0000870 if (bmp_display(addr, x, y) == 0)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000871 return (void *)lcd_base;
wdenk9ca7bbc2004-10-09 23:25:58 +0000872 }
873#endif /* CONFIG_SPLASH_SCREEN */
874
Anatolij Gustschin6f1378f2012-04-27 04:41:27 +0000875 bitmap_plot(0, 0);
wdenk9ca7bbc2004-10-09 23:25:58 +0000876
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200877#ifdef CONFIG_LCD_INFO
Nikita Kiryanov699c05e2014-12-08 17:14:41 +0200878 lcd_set_col(LCD_INFO_X / VIDEO_FONT_WIDTH);
879 lcd_set_row(LCD_INFO_Y / VIDEO_FONT_HEIGHT);
Haavard Skinnemoenddbcf952008-09-01 16:21:22 +0200880 lcd_show_board_info();
881#endif /* CONFIG_LCD_INFO */
Stelian Popf6f86652008-05-09 21:57:18 +0200882
wdenk2b9d1862005-07-04 00:03:16 +0000883#if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO)
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000884 return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length);
wdenk9ca7bbc2004-10-09 23:25:58 +0000885#else
Nikita Kiryanov1f828412012-05-24 01:42:38 +0000886 return (void *)lcd_base;
Jeroen Hofstee729b09e2013-01-12 12:07:56 +0000887#endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */
wdenk9ca7bbc2004-10-09 23:25:58 +0000888}
889
Nikita Kiryanov2f3e2ca2013-02-24 21:28:43 +0000890#ifdef CONFIG_SPLASHIMAGE_GUARD
891static int on_splashimage(const char *name, const char *value, enum env_op op,
892 int flags)
893{
894 ulong addr;
895 int aligned;
896
897 if (op == env_op_delete)
898 return 0;
899
900 addr = simple_strtoul(value, NULL, 16);
901 /* See README.displaying-bmps */
902 aligned = (addr % 4 == 2);
903 if (!aligned) {
904 printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n");
905 return -1;
906 }
907
908 return 0;
909}
910
911U_BOOT_ENV_CALLBACK(splashimage, on_splashimage);
912#endif
913
Vadim Bendeburya7eaa2f2012-09-28 15:11:13 +0000914int lcd_get_pixel_width(void)
915{
916 return panel_info.vl_col;
917}
918
919int lcd_get_pixel_height(void)
920{
921 return panel_info.vl_row;
922}
923
Stephen Warrenefe64282013-05-27 18:31:17 +0000924#if defined(CONFIG_LCD_DT_SIMPLEFB)
925static int lcd_dt_simplefb_configure_node(void *blob, int off)
926{
Stephen Warrenefe64282013-05-27 18:31:17 +0000927#if LCD_BPP == LCD_COLOR16
Hans de Goedeb2726f22014-11-19 13:53:27 +0100928 return fdt_setup_simplefb_node(blob, off, gd->fb_base,
929 panel_info.vl_col, panel_info.vl_row,
930 panel_info.vl_col * 2, "r5g6b5");
Stephen Warrenefe64282013-05-27 18:31:17 +0000931#else
Hans de Goedeb2726f22014-11-19 13:53:27 +0100932 return -1;
Stephen Warrenefe64282013-05-27 18:31:17 +0000933#endif
Stephen Warrenefe64282013-05-27 18:31:17 +0000934}
935
936int lcd_dt_simplefb_add_node(void *blob)
937{
Stephen Warrenc4b7d652013-06-13 17:13:11 -0600938 static const char compat[] = "simple-framebuffer";
939 static const char disabled[] = "disabled";
Stephen Warrenefe64282013-05-27 18:31:17 +0000940 int off, ret;
941
942 off = fdt_add_subnode(blob, 0, "framebuffer");
943 if (off < 0)
944 return -1;
945
946 ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled));
947 if (ret < 0)
948 return -1;
949
950 ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat));
951 if (ret < 0)
952 return -1;
953
954 return lcd_dt_simplefb_configure_node(blob, off);
955}
956
957int lcd_dt_simplefb_enable_existing_node(void *blob)
958{
959 int off;
960
961 off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer");
962 if (off < 0)
963 return -1;
964
965 return lcd_dt_simplefb_configure_node(blob, off);
966}
967#endif