wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Common LCD routines for supported CPUs |
| 3 | * |
| 4 | * (C) Copyright 2001-2002 |
| 5 | * Wolfgang Denk, DENX Software Engineering -- wd@denx.de |
| 6 | * |
Wolfgang Denk | 3765b3e | 2013-10-07 13:07:26 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | /************************************************************************/ |
| 11 | /* ** HEADER FILES */ |
| 12 | /************************************************************************/ |
| 13 | |
| 14 | /* #define DEBUG */ |
| 15 | |
| 16 | #include <config.h> |
| 17 | #include <common.h> |
| 18 | #include <command.h> |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 19 | #include <stdarg.h> |
Nikita Kiryanov | c088048 | 2013-02-24 21:28:43 +0000 | [diff] [blame] | 20 | #include <search.h> |
| 21 | #include <env_callback.h> |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 22 | #include <linux/types.h> |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 23 | #include <stdio_dev.h> |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 24 | #if defined(CONFIG_POST) |
| 25 | #include <post.h> |
| 26 | #endif |
| 27 | #include <lcd.h> |
wdenk | 8b0bfc6 | 2005-04-03 23:11:38 +0000 | [diff] [blame] | 28 | #include <watchdog.h> |
Przemyslaw Marczak | dca2a1c | 2014-01-22 11:24:13 +0100 | [diff] [blame] | 29 | #include <asm/unaligned.h> |
Robert Winkler | dd4425e | 2013-06-17 11:31:29 -0700 | [diff] [blame] | 30 | #include <splash.h> |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 31 | #include <asm/io.h> |
| 32 | #include <asm/unaligned.h> |
Robert Winkler | dd4425e | 2013-06-17 11:31:29 -0700 | [diff] [blame] | 33 | |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 34 | #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \ |
| 35 | defined(CONFIG_CPU_MONAHANS) |
| 36 | #define CONFIG_CPU_PXA |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 37 | #include <asm/byteorder.h> |
| 38 | #endif |
| 39 | |
| 40 | #if defined(CONFIG_MPC823) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 41 | #include <lcdvideo.h> |
| 42 | #endif |
| 43 | |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 44 | #if defined(CONFIG_ATMEL_LCD) |
| 45 | #include <atmel_lcdc.h> |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 46 | #endif |
| 47 | |
Stephen Warren | 6a195d2 | 2013-05-27 18:31:17 +0000 | [diff] [blame] | 48 | #if defined(CONFIG_LCD_DT_SIMPLEFB) |
| 49 | #include <libfdt.h> |
| 50 | #endif |
| 51 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 52 | /************************************************************************/ |
| 53 | /* ** FONT DATA */ |
| 54 | /************************************************************************/ |
| 55 | #include <video_font.h> /* Get font data, width and height */ |
| 56 | |
wdenk | 88804d1 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 57 | /************************************************************************/ |
| 58 | /* ** LOGO DATA */ |
| 59 | /************************************************************************/ |
| 60 | #ifdef CONFIG_LCD_LOGO |
| 61 | # include <bmp_logo.h> /* Get logo data, width and height */ |
Che-Liang Chiou | c270730 | 2011-10-20 23:04:20 +0000 | [diff] [blame] | 62 | # include <bmp_logo_data.h> |
Alessandro Rubini | acb1386 | 2010-03-13 17:44:08 +0100 | [diff] [blame] | 63 | # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16) |
wdenk | 88804d1 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 64 | # error Default Color Map overlaps with Logo Color Map |
| 65 | # endif |
| 66 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 67 | |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 68 | #ifdef CONFIG_SANDBOX |
| 69 | #include <asm/sdl.h> |
| 70 | #endif |
| 71 | |
Simon Glass | 676d319 | 2012-10-17 13:24:54 +0000 | [diff] [blame] | 72 | #ifndef CONFIG_LCD_ALIGNMENT |
| 73 | #define CONFIG_LCD_ALIGNMENT PAGE_SIZE |
| 74 | #endif |
| 75 | |
Simon Glass | 0d89efe | 2012-10-17 13:24:59 +0000 | [diff] [blame] | 76 | /* By default we scroll by a single line */ |
| 77 | #ifndef CONFIG_CONSOLE_SCROLL_LINES |
| 78 | #define CONFIG_CONSOLE_SCROLL_LINES 1 |
| 79 | #endif |
| 80 | |
Jeroen Hofstee | a5796c5 | 2013-01-12 12:07:59 +0000 | [diff] [blame] | 81 | /************************************************************************/ |
| 82 | /* ** CONSOLE DEFINITIONS & FUNCTIONS */ |
| 83 | /************************************************************************/ |
| 84 | #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) |
| 85 | # define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \ |
| 86 | / VIDEO_FONT_HEIGHT) |
| 87 | #else |
| 88 | # define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT) |
| 89 | #endif |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 90 | |
Jeroen Hofstee | a5796c5 | 2013-01-12 12:07:59 +0000 | [diff] [blame] | 91 | #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH) |
| 92 | #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length) |
| 93 | #define CONSOLE_ROW_FIRST lcd_console_address |
| 94 | #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE) |
| 95 | #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \ |
| 96 | - CONSOLE_ROW_SIZE) |
| 97 | #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS) |
| 98 | #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) |
| 99 | |
| 100 | #if LCD_BPP == LCD_MONOCHROME |
| 101 | # define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \ |
| 102 | (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7) |
Hannes Petermaier | 57d76a8 | 2014-03-07 18:55:40 +0100 | [diff] [blame^] | 103 | #elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) || \ |
| 104 | (LCD_BPP == LCD_COLOR32) |
Jeroen Hofstee | a5796c5 | 2013-01-12 12:07:59 +0000 | [diff] [blame] | 105 | # define COLOR_MASK(c) (c) |
| 106 | #else |
| 107 | # error Unsupported LCD BPP. |
| 108 | #endif |
| 109 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 110 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 111 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 112 | static void lcd_drawchars(ushort x, ushort y, uchar *str, int count); |
| 113 | static inline void lcd_puts_xy(ushort x, ushort y, uchar *s); |
| 114 | static inline void lcd_putc_xy(ushort x, ushort y, uchar c); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 115 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 116 | static int lcd_init(void *lcdbase); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 117 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 118 | static void *lcd_logo(void); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 119 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 120 | static int lcd_getbgcolor(void); |
| 121 | static void lcd_setfgcolor(int color); |
| 122 | static void lcd_setbgcolor(int color); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 123 | |
Wolfgang Denk | 46d1d5d | 2013-01-05 09:45:48 +0000 | [diff] [blame] | 124 | static int lcd_color_fg; |
| 125 | static int lcd_color_bg; |
Jeroen Hofstee | f1d205a | 2013-01-22 10:44:11 +0000 | [diff] [blame] | 126 | int lcd_line_length; |
Wolfgang Denk | 46d1d5d | 2013-01-05 09:45:48 +0000 | [diff] [blame] | 127 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 128 | char lcd_is_enabled = 0; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 129 | |
Jeroen Hofstee | f1d205a | 2013-01-22 10:44:11 +0000 | [diff] [blame] | 130 | static short console_col; |
| 131 | static short console_row; |
| 132 | |
| 133 | static void *lcd_console_address; |
Jeroen Hofstee | 00a0ca5 | 2013-01-22 10:44:12 +0000 | [diff] [blame] | 134 | static void *lcd_base; /* Start of framebuffer memory */ |
Jeroen Hofstee | f1d205a | 2013-01-22 10:44:11 +0000 | [diff] [blame] | 135 | |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 136 | static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */ |
| 137 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 138 | /************************************************************************/ |
| 139 | |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 140 | /* Flush LCD activity to the caches */ |
| 141 | void lcd_sync(void) |
| 142 | { |
| 143 | /* |
| 144 | * flush_dcache_range() is declared in common.h but it seems that some |
| 145 | * architectures do not actually implement it. Is there a way to find |
| 146 | * out whether it exists? For now, ARM is safe. |
| 147 | */ |
| 148 | #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF) |
| 149 | int line_length; |
| 150 | |
| 151 | if (lcd_flush_dcache) |
| 152 | flush_dcache_range((u32)lcd_base, |
| 153 | (u32)(lcd_base + lcd_get_size(&line_length))); |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 154 | #elif defined(CONFIG_SANDBOX) && defined(CONFIG_VIDEO_SANDBOX_SDL) |
| 155 | static ulong last_sync; |
| 156 | |
| 157 | if (get_timer(last_sync) > 10) { |
| 158 | sandbox_sdl_sync(lcd_base); |
| 159 | last_sync = get_timer(0); |
| 160 | } |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 161 | #endif |
| 162 | } |
| 163 | |
| 164 | void lcd_set_flush_dcache(int flush) |
| 165 | { |
| 166 | lcd_flush_dcache = (flush != 0); |
| 167 | } |
| 168 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 169 | /*----------------------------------------------------------------------*/ |
| 170 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 171 | static void console_scrollup(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 172 | { |
Simon Glass | 0d89efe | 2012-10-17 13:24:59 +0000 | [diff] [blame] | 173 | const int rows = CONFIG_CONSOLE_SCROLL_LINES; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 174 | |
Simon Glass | 0d89efe | 2012-10-17 13:24:59 +0000 | [diff] [blame] | 175 | /* Copy up rows ignoring those that will be overwritten */ |
| 176 | memcpy(CONSOLE_ROW_FIRST, |
| 177 | lcd_console_address + CONSOLE_ROW_SIZE * rows, |
| 178 | CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows); |
| 179 | |
| 180 | /* Clear the last rows */ |
Hannes Petermaier | 57d76a8 | 2014-03-07 18:55:40 +0100 | [diff] [blame^] | 181 | #if (LCD_BPP != LCD_COLOR32) |
Simon Glass | 0d89efe | 2012-10-17 13:24:59 +0000 | [diff] [blame] | 182 | memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows, |
| 183 | COLOR_MASK(lcd_color_bg), |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 184 | CONSOLE_ROW_SIZE * rows); |
Hannes Petermaier | 57d76a8 | 2014-03-07 18:55:40 +0100 | [diff] [blame^] | 185 | #else |
| 186 | u32 *ppix = lcd_console_address + |
| 187 | CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows; |
| 188 | u32 i; |
| 189 | for (i = 0; |
| 190 | i < (CONSOLE_ROW_SIZE * rows) / NBYTES(panel_info.vl_bpix); |
| 191 | i++) { |
| 192 | *ppix++ = COLOR_MASK(lcd_color_bg); |
| 193 | } |
| 194 | #endif |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 195 | lcd_sync(); |
Simon Glass | 0d89efe | 2012-10-17 13:24:59 +0000 | [diff] [blame] | 196 | console_row -= rows; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 197 | } |
| 198 | |
| 199 | /*----------------------------------------------------------------------*/ |
| 200 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 201 | static inline void console_back(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 202 | { |
| 203 | if (--console_col < 0) { |
| 204 | console_col = CONSOLE_COLS-1 ; |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 205 | if (--console_row < 0) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 206 | console_row = 0; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 207 | } |
| 208 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 209 | lcd_putc_xy(console_col * VIDEO_FONT_WIDTH, |
| 210 | console_row * VIDEO_FONT_HEIGHT, ' '); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 211 | } |
| 212 | |
| 213 | /*----------------------------------------------------------------------*/ |
| 214 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 215 | static inline void console_newline(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 216 | { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 217 | console_col = 0; |
| 218 | |
| 219 | /* Check if we need to scroll the terminal */ |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 220 | if (++console_row >= CONSOLE_ROWS) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 221 | console_scrollup(); |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 222 | else |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 223 | lcd_sync(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 224 | } |
| 225 | |
| 226 | /*----------------------------------------------------------------------*/ |
| 227 | |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 228 | static void lcd_stub_putc(struct stdio_dev *dev, const char c) |
| 229 | { |
| 230 | lcd_putc(c); |
| 231 | } |
| 232 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 233 | void lcd_putc(const char c) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 234 | { |
| 235 | if (!lcd_is_enabled) { |
| 236 | serial_putc(c); |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 237 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 238 | return; |
| 239 | } |
| 240 | |
| 241 | switch (c) { |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 242 | case '\r': |
| 243 | console_col = 0; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 244 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 245 | return; |
| 246 | case '\n': |
| 247 | console_newline(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 248 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 249 | return; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 250 | case '\t': /* Tab (8 chars alignment) */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 251 | console_col += 8; |
| 252 | console_col &= ~7; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 253 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 254 | if (console_col >= CONSOLE_COLS) |
| 255 | console_newline(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 256 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 257 | return; |
| 258 | case '\b': |
| 259 | console_back(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 260 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 261 | return; |
| 262 | default: |
| 263 | lcd_putc_xy(console_col * VIDEO_FONT_WIDTH, |
| 264 | console_row * VIDEO_FONT_HEIGHT, c); |
| 265 | if (++console_col >= CONSOLE_COLS) |
| 266 | console_newline(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 267 | } |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 268 | } |
| 269 | |
| 270 | /*----------------------------------------------------------------------*/ |
| 271 | |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 272 | static void lcd_stub_puts(struct stdio_dev *dev, const char *s) |
| 273 | { |
| 274 | lcd_puts(s); |
| 275 | } |
| 276 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 277 | void lcd_puts(const char *s) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 278 | { |
| 279 | if (!lcd_is_enabled) { |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 280 | serial_puts(s); |
| 281 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 282 | return; |
| 283 | } |
| 284 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 285 | while (*s) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 286 | lcd_putc(*s++); |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 287 | |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 288 | lcd_sync(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 289 | } |
| 290 | |
Haavard Skinnemoen | 15b17ab | 2008-09-01 16:21:20 +0200 | [diff] [blame] | 291 | /*----------------------------------------------------------------------*/ |
| 292 | |
| 293 | void lcd_printf(const char *fmt, ...) |
| 294 | { |
| 295 | va_list args; |
| 296 | char buf[CONFIG_SYS_PBSIZE]; |
| 297 | |
| 298 | va_start(args, fmt); |
| 299 | vsprintf(buf, fmt, args); |
| 300 | va_end(args); |
| 301 | |
| 302 | lcd_puts(buf); |
| 303 | } |
| 304 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 305 | /************************************************************************/ |
| 306 | /* ** Low-Level Graphics Routines */ |
| 307 | /************************************************************************/ |
| 308 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 309 | static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 310 | { |
| 311 | uchar *dest; |
Marek Vasut | be547c6 | 2011-09-26 02:26:04 +0200 | [diff] [blame] | 312 | ushort row; |
| 313 | |
Anatolij Gustschin | 0f999c4 | 2012-04-27 04:41:16 +0000 | [diff] [blame] | 314 | #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) |
| 315 | y += BMP_LOGO_HEIGHT; |
| 316 | #endif |
| 317 | |
Marek Vasut | be547c6 | 2011-09-26 02:26:04 +0200 | [diff] [blame] | 318 | #if LCD_BPP == LCD_MONOCHROME |
| 319 | ushort off = x * (1 << LCD_BPP) % 8; |
| 320 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 321 | |
Hannes Petermaier | 57d76a8 | 2014-03-07 18:55:40 +0100 | [diff] [blame^] | 322 | dest = (uchar *)(lcd_base + y * lcd_line_length + x * NBITS(LCD_BPP)/8); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 323 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 324 | for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 325 | uchar *s = str; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 326 | int i; |
Alessandro Rubini | acb1386 | 2010-03-13 17:44:08 +0100 | [diff] [blame] | 327 | #if LCD_BPP == LCD_COLOR16 |
| 328 | ushort *d = (ushort *)dest; |
Hannes Petermaier | 57d76a8 | 2014-03-07 18:55:40 +0100 | [diff] [blame^] | 329 | #elif LCD_BPP == LCD_COLOR32 |
| 330 | u32 *d = (u32 *)dest; |
Alessandro Rubini | acb1386 | 2010-03-13 17:44:08 +0100 | [diff] [blame] | 331 | #else |
| 332 | uchar *d = dest; |
| 333 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 334 | |
| 335 | #if LCD_BPP == LCD_MONOCHROME |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 336 | uchar rest = *d & -(1 << (8 - off)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 337 | uchar sym; |
| 338 | #endif |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 339 | for (i = 0; i < count; ++i) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 340 | uchar c, bits; |
| 341 | |
| 342 | c = *s++; |
| 343 | bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row]; |
| 344 | |
| 345 | #if LCD_BPP == LCD_MONOCHROME |
| 346 | sym = (COLOR_MASK(lcd_color_fg) & bits) | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 347 | (COLOR_MASK(lcd_color_bg) & ~bits); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 348 | |
| 349 | *d++ = rest | (sym >> off); |
| 350 | rest = sym << (8-off); |
| 351 | #elif LCD_BPP == LCD_COLOR8 |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 352 | for (c = 0; c < 8; ++c) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 353 | *d++ = (bits & 0x80) ? |
| 354 | lcd_color_fg : lcd_color_bg; |
| 355 | bits <<= 1; |
| 356 | } |
| 357 | #elif LCD_BPP == LCD_COLOR16 |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 358 | for (c = 0; c < 8; ++c) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 359 | *d++ = (bits & 0x80) ? |
| 360 | lcd_color_fg : lcd_color_bg; |
| 361 | bits <<= 1; |
| 362 | } |
Hannes Petermaier | 57d76a8 | 2014-03-07 18:55:40 +0100 | [diff] [blame^] | 363 | #elif LCD_BPP == LCD_COLOR32 |
| 364 | for (c = 0; c < 8; ++c) { |
| 365 | *d++ = (bits & 0x80) ? |
| 366 | lcd_color_fg : lcd_color_bg; |
| 367 | bits <<= 1; |
| 368 | } |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 369 | #endif |
| 370 | } |
| 371 | #if LCD_BPP == LCD_MONOCHROME |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 372 | *d = rest | (*d & ((1 << (8 - off)) - 1)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 373 | #endif |
| 374 | } |
| 375 | } |
| 376 | |
| 377 | /*----------------------------------------------------------------------*/ |
| 378 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 379 | static inline void lcd_puts_xy(ushort x, ushort y, uchar *s) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 380 | { |
Anatolij Gustschin | 0f999c4 | 2012-04-27 04:41:16 +0000 | [diff] [blame] | 381 | lcd_drawchars(x, y, s, strlen((char *)s)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 382 | } |
| 383 | |
| 384 | /*----------------------------------------------------------------------*/ |
| 385 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 386 | static inline void lcd_putc_xy(ushort x, ushort y, uchar c) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 387 | { |
Anatolij Gustschin | 0f999c4 | 2012-04-27 04:41:16 +0000 | [diff] [blame] | 388 | lcd_drawchars(x, y, &c, 1); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | /************************************************************************/ |
| 392 | /** Small utility to check that you got the colours right */ |
| 393 | /************************************************************************/ |
| 394 | #ifdef LCD_TEST_PATTERN |
| 395 | |
| 396 | #define N_BLK_VERT 2 |
| 397 | #define N_BLK_HOR 3 |
| 398 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 399 | static int test_colors[N_BLK_HOR * N_BLK_VERT] = { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 400 | CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW, |
| 401 | CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN, |
| 402 | }; |
| 403 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 404 | static void test_pattern(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 405 | { |
| 406 | ushort v_max = panel_info.vl_row; |
| 407 | ushort h_max = panel_info.vl_col; |
| 408 | ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT; |
| 409 | ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR; |
| 410 | ushort v, h; |
| 411 | uchar *pix = (uchar *)lcd_base; |
| 412 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 413 | printf("[LCD] Test Pattern: %d x %d [%d x %d]\n", |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 414 | h_max, v_max, h_step, v_step); |
| 415 | |
| 416 | /* WARNING: Code silently assumes 8bit/pixel */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 417 | for (v = 0; v < v_max; ++v) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 418 | uchar iy = v / v_step; |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 419 | for (h = 0; h < h_max; ++h) { |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 420 | uchar ix = N_BLK_HOR * iy + h / h_step; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 421 | *pix++ = test_colors[ix]; |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | #endif /* LCD_TEST_PATTERN */ |
| 426 | |
| 427 | |
| 428 | /************************************************************************/ |
| 429 | /* ** GENERIC Initialization Routines */ |
| 430 | /************************************************************************/ |
Anatolij Gustschin | cefa471 | 2013-11-09 11:00:09 +0100 | [diff] [blame] | 431 | /* |
| 432 | * With most lcd drivers the line length is set up |
| 433 | * by calculating it from panel_info parameters. Some |
| 434 | * drivers need to calculate the line length differently, |
| 435 | * so make the function weak to allow overriding it. |
| 436 | */ |
| 437 | __weak int lcd_get_size(int *line_length) |
Simon Glass | 676d319 | 2012-10-17 13:24:54 +0000 | [diff] [blame] | 438 | { |
| 439 | *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8; |
| 440 | return *line_length * panel_info.vl_row; |
| 441 | } |
| 442 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 443 | int drv_lcd_init(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 444 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 445 | struct stdio_dev lcddev; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 446 | int rc; |
| 447 | |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 448 | lcd_base = map_sysmem(gd->fb_base, 0); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 449 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 450 | lcd_init(lcd_base); /* LCD initialization */ |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 451 | |
| 452 | /* Device initialization */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 453 | memset(&lcddev, 0, sizeof(lcddev)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 454 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 455 | strcpy(lcddev.name, "lcd"); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 456 | lcddev.ext = 0; /* No extensions */ |
| 457 | lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */ |
Simon Glass | 709ea54 | 2014-07-23 06:54:59 -0600 | [diff] [blame] | 458 | lcddev.putc = lcd_stub_putc; /* 'putc' function */ |
| 459 | lcddev.puts = lcd_stub_puts; /* 'puts' function */ |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 460 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 461 | rc = stdio_register(&lcddev); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 462 | |
| 463 | return (rc == 0) ? 1 : rc; |
| 464 | } |
| 465 | |
| 466 | /*----------------------------------------------------------------------*/ |
Che-Liang Chiou | 0211090 | 2011-10-20 23:07:03 +0000 | [diff] [blame] | 467 | void lcd_clear(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 468 | { |
| 469 | #if LCD_BPP == LCD_MONOCHROME |
| 470 | /* Setting the palette */ |
| 471 | lcd_initcolregs(); |
| 472 | |
| 473 | #elif LCD_BPP == LCD_COLOR8 |
| 474 | /* Setting the palette */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 475 | lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0); |
| 476 | lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0); |
| 477 | lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0); |
| 478 | lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0); |
| 479 | lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF); |
| 480 | lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF); |
| 481 | lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF); |
| 482 | lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA); |
| 483 | lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 484 | #endif |
| 485 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 486 | #ifndef CONFIG_SYS_WHITE_ON_BLACK |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 487 | lcd_setfgcolor(CONSOLE_COLOR_BLACK); |
| 488 | lcd_setbgcolor(CONSOLE_COLOR_WHITE); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 489 | #else |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 490 | lcd_setfgcolor(CONSOLE_COLOR_WHITE); |
| 491 | lcd_setbgcolor(CONSOLE_COLOR_BLACK); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 492 | #endif /* CONFIG_SYS_WHITE_ON_BLACK */ |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 493 | |
| 494 | #ifdef LCD_TEST_PATTERN |
| 495 | test_pattern(); |
| 496 | #else |
| 497 | /* set framebuffer to background color */ |
Hannes Petermaier | 57d76a8 | 2014-03-07 18:55:40 +0100 | [diff] [blame^] | 498 | #if (LCD_BPP != LCD_COLOR32) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 499 | memset((char *)lcd_base, |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 500 | COLOR_MASK(lcd_getbgcolor()), |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 501 | lcd_line_length * panel_info.vl_row); |
Hannes Petermaier | 57d76a8 | 2014-03-07 18:55:40 +0100 | [diff] [blame^] | 502 | #else |
| 503 | u32 *ppix = lcd_base; |
| 504 | u32 i; |
| 505 | for (i = 0; |
| 506 | i < (lcd_line_length * panel_info.vl_row)/NBYTES(panel_info.vl_bpix); |
| 507 | i++) { |
| 508 | *ppix++ = COLOR_MASK(lcd_color_bg); |
| 509 | } |
| 510 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 511 | #endif |
| 512 | /* Paint the logo and retrieve LCD base address */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 513 | debug("[LCD] Drawing the logo...\n"); |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 514 | lcd_console_address = lcd_logo(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 515 | |
| 516 | console_col = 0; |
| 517 | console_row = 0; |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 518 | lcd_sync(); |
| 519 | } |
| 520 | |
| 521 | static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc, |
| 522 | char *const argv[]) |
| 523 | { |
| 524 | lcd_clear(); |
| 525 | return 0; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 526 | } |
| 527 | |
| 528 | U_BOOT_CMD( |
Che-Liang Chiou | 0211090 | 2011-10-20 23:07:03 +0000 | [diff] [blame] | 529 | cls, 1, 1, do_lcd_clear, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 530 | "clear screen", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 531 | "" |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 532 | ); |
| 533 | |
| 534 | /*----------------------------------------------------------------------*/ |
| 535 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 536 | static int lcd_init(void *lcdbase) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 537 | { |
| 538 | /* Initialize the lcd controller */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 539 | debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 540 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 541 | lcd_ctrl_init(lcdbase); |
Anatolij Gustschin | 1d3dea1 | 2013-03-29 14:00:13 +0100 | [diff] [blame] | 542 | |
| 543 | /* |
| 544 | * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi_b) ignores |
| 545 | * the 'lcdbase' argument and uses custom lcd base address |
| 546 | * by setting up gd->fb_base. Check for this condition and fixup |
| 547 | * 'lcd_base' address. |
| 548 | */ |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 549 | if (map_to_sysmem(lcdbase) != gd->fb_base) |
| 550 | lcd_base = map_sysmem(gd->fb_base, 0); |
Anatolij Gustschin | 1d3dea1 | 2013-03-29 14:00:13 +0100 | [diff] [blame] | 551 | |
| 552 | debug("[LCD] Using LCD frambuffer at %p\n", lcd_base); |
| 553 | |
Stephen Warren | 6d33071 | 2013-01-29 16:37:38 +0000 | [diff] [blame] | 554 | lcd_get_size(&lcd_line_length); |
Haavard Skinnemoen | 6f93d2b | 2008-09-01 16:21:21 +0200 | [diff] [blame] | 555 | lcd_is_enabled = 1; |
Che-Liang Chiou | 0211090 | 2011-10-20 23:07:03 +0000 | [diff] [blame] | 556 | lcd_clear(); |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 557 | lcd_enable(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 558 | |
| 559 | /* Initialize the console */ |
| 560 | console_col = 0; |
wdenk | 88804d1 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 561 | #ifdef CONFIG_LCD_INFO_BELOW_LOGO |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 562 | console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT; |
| 563 | #else |
| 564 | console_row = 1; /* leave 1 blank line below logo */ |
| 565 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 566 | |
| 567 | return 0; |
| 568 | } |
| 569 | |
| 570 | |
| 571 | /************************************************************************/ |
| 572 | /* ** ROM capable initialization part - needed to reserve FB memory */ |
| 573 | /************************************************************************/ |
| 574 | /* |
| 575 | * This is called early in the system initialization to grab memory |
| 576 | * for the LCD controller. |
| 577 | * Returns new address for monitor, after reserving LCD buffer memory |
| 578 | * |
| 579 | * Note that this is running from ROM, so no write access to global data. |
| 580 | */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 581 | ulong lcd_setmem(ulong addr) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 582 | { |
| 583 | ulong size; |
Simon Glass | 676d319 | 2012-10-17 13:24:54 +0000 | [diff] [blame] | 584 | int line_length; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 585 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 586 | debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col, |
| 587 | panel_info.vl_row, NBITS(panel_info.vl_bpix)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 588 | |
Simon Glass | 676d319 | 2012-10-17 13:24:54 +0000 | [diff] [blame] | 589 | size = lcd_get_size(&line_length); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 590 | |
Simon Glass | 676d319 | 2012-10-17 13:24:54 +0000 | [diff] [blame] | 591 | /* Round up to nearest full page, or MMU section if defined */ |
| 592 | size = ALIGN(size, CONFIG_LCD_ALIGNMENT); |
| 593 | addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 594 | |
| 595 | /* Allocate pages for the frame buffer. */ |
| 596 | addr -= size; |
| 597 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 598 | debug("Reserving %ldk for LCD Framebuffer at: %08lx\n", |
| 599 | size >> 10, addr); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 600 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 601 | return addr; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 602 | } |
| 603 | |
| 604 | /*----------------------------------------------------------------------*/ |
| 605 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 606 | static void lcd_setfgcolor(int color) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 607 | { |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 608 | lcd_color_fg = color; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /*----------------------------------------------------------------------*/ |
| 612 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 613 | static void lcd_setbgcolor(int color) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 614 | { |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 615 | lcd_color_bg = color; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 616 | } |
| 617 | |
| 618 | /*----------------------------------------------------------------------*/ |
| 619 | |
Wolfgang Denk | 46d1d5d | 2013-01-05 09:45:48 +0000 | [diff] [blame] | 620 | int lcd_getfgcolor(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 621 | { |
| 622 | return lcd_color_fg; |
| 623 | } |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 624 | |
| 625 | /*----------------------------------------------------------------------*/ |
| 626 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 627 | static int lcd_getbgcolor(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 628 | { |
| 629 | return lcd_color_bg; |
| 630 | } |
| 631 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 632 | /************************************************************************/ |
| 633 | /* ** Chipset depending Bitmap / Logo stuff... */ |
| 634 | /************************************************************************/ |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 635 | static inline ushort *configuration_get_cmap(void) |
| 636 | { |
| 637 | #if defined CONFIG_CPU_PXA |
| 638 | struct pxafb_info *fbi = &panel_info.pxa; |
| 639 | return (ushort *)fbi->palette; |
| 640 | #elif defined(CONFIG_MPC823) |
| 641 | immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
| 642 | cpm8xx_t *cp = &(immr->im_cpm); |
| 643 | return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]); |
| 644 | #elif defined(CONFIG_ATMEL_LCD) |
| 645 | return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0)); |
Anatolij Gustschin | d23019f | 2012-09-22 06:55:53 +0000 | [diff] [blame] | 646 | #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB) |
| 647 | return panel_info.cmap; |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 648 | #elif defined(CONFIG_LCD_LOGO) |
Anatolij Gustschin | d23019f | 2012-09-22 06:55:53 +0000 | [diff] [blame] | 649 | return bmp_logo_palette; |
| 650 | #else |
| 651 | return NULL; |
| 652 | #endif |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 653 | } |
| 654 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 655 | #ifdef CONFIG_LCD_LOGO |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 656 | void bitmap_plot(int x, int y) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 657 | { |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 658 | #ifdef CONFIG_ATMEL_LCD |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 659 | uint *cmap = (uint *)bmp_logo_palette; |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 660 | #else |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 661 | ushort *cmap = (ushort *)bmp_logo_palette; |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 662 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 663 | ushort i, j; |
| 664 | uchar *bmap; |
| 665 | uchar *fb; |
| 666 | ushort *fb16; |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 667 | #if defined(CONFIG_MPC823) |
| 668 | immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
| 669 | cpm8xx_t *cp = &(immr->im_cpm); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 670 | #endif |
Andre Renaud | 317461c | 2013-02-13 17:48:00 +0000 | [diff] [blame] | 671 | unsigned bpix = NBITS(panel_info.vl_bpix); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 672 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 673 | debug("Logo: width %d height %d colors %d cmap %d\n", |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 674 | BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS, |
Anatolij Gustschin | 095407d | 2012-04-27 04:41:06 +0000 | [diff] [blame] | 675 | ARRAY_SIZE(bmp_logo_palette)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 676 | |
| 677 | bmap = &bmp_logo_bitmap[0]; |
Andre Renaud | 317461c | 2013-02-13 17:48:00 +0000 | [diff] [blame] | 678 | fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 679 | |
Andre Renaud | 317461c | 2013-02-13 17:48:00 +0000 | [diff] [blame] | 680 | if (bpix < 12) { |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 681 | /* Leave room for default color map |
| 682 | * default case: generic system with no cmap (most likely 16bpp) |
| 683 | * cmap was set to the source palette, so no change is done. |
| 684 | * This avoids even more ifdefs in the next stanza |
| 685 | */ |
| 686 | #if defined(CONFIG_MPC823) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 687 | cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]); |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 688 | #elif defined(CONFIG_ATMEL_LCD) |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 689 | cmap = (uint *)configuration_get_cmap(); |
Alessandro Rubini | acb1386 | 2010-03-13 17:44:08 +0100 | [diff] [blame] | 690 | #else |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 691 | cmap = configuration_get_cmap(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 692 | #endif |
| 693 | |
| 694 | WATCHDOG_RESET(); |
| 695 | |
| 696 | /* Set color map */ |
Anatolij Gustschin | 095407d | 2012-04-27 04:41:06 +0000 | [diff] [blame] | 697 | for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 698 | ushort colreg = bmp_logo_palette[i]; |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 699 | #ifdef CONFIG_ATMEL_LCD |
| 700 | uint lut_entry; |
| 701 | #ifdef CONFIG_ATMEL_LCD_BGR555 |
| 702 | lut_entry = ((colreg & 0x000F) << 11) | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 703 | ((colreg & 0x00F0) << 2) | |
| 704 | ((colreg & 0x0F00) >> 7); |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 705 | #else /* CONFIG_ATMEL_LCD_RGB565 */ |
| 706 | lut_entry = ((colreg & 0x000F) << 1) | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 707 | ((colreg & 0x00F0) << 3) | |
| 708 | ((colreg & 0x0F00) << 4); |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 709 | #endif |
| 710 | *(cmap + BMP_LOGO_OFFSET) = lut_entry; |
| 711 | cmap++; |
| 712 | #else /* !CONFIG_ATMEL_LCD */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 713 | #ifdef CONFIG_SYS_INVERT_COLORS |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 714 | *cmap++ = 0xffff - colreg; |
| 715 | #else |
| 716 | *cmap++ = colreg; |
| 717 | #endif |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 718 | #endif /* CONFIG_ATMEL_LCD */ |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | WATCHDOG_RESET(); |
| 722 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 723 | for (i = 0; i < BMP_LOGO_HEIGHT; ++i) { |
| 724 | memcpy(fb, bmap, BMP_LOGO_WIDTH); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 725 | bmap += BMP_LOGO_WIDTH; |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 726 | fb += panel_info.vl_col; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 727 | } |
| 728 | } |
| 729 | else { /* true color mode */ |
Alessandro Rubini | acb1386 | 2010-03-13 17:44:08 +0100 | [diff] [blame] | 730 | u16 col16; |
Andre Renaud | 317461c | 2013-02-13 17:48:00 +0000 | [diff] [blame] | 731 | fb16 = (ushort *)fb; |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 732 | for (i = 0; i < BMP_LOGO_HEIGHT; ++i) { |
| 733 | for (j = 0; j < BMP_LOGO_WIDTH; j++) { |
Alessandro Rubini | acb1386 | 2010-03-13 17:44:08 +0100 | [diff] [blame] | 734 | col16 = bmp_logo_palette[(bmap[j]-16)]; |
| 735 | fb16[j] = |
| 736 | ((col16 & 0x000F) << 1) | |
| 737 | ((col16 & 0x00F0) << 3) | |
| 738 | ((col16 & 0x0F00) << 4); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 739 | } |
| 740 | bmap += BMP_LOGO_WIDTH; |
| 741 | fb16 += panel_info.vl_col; |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | WATCHDOG_RESET(); |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 746 | lcd_sync(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 747 | } |
Anatolij Gustschin | 2b5cb3d | 2012-04-27 04:41:27 +0000 | [diff] [blame] | 748 | #else |
| 749 | static inline void bitmap_plot(int x, int y) {} |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 750 | #endif /* CONFIG_LCD_LOGO */ |
| 751 | |
| 752 | /*----------------------------------------------------------------------*/ |
Jon Loeliger | c3517f9 | 2007-07-08 18:10:08 -0500 | [diff] [blame] | 753 | #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 754 | /* |
| 755 | * Display the BMP file located at address bmp_image. |
| 756 | * Only uncompressed. |
| 757 | */ |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 758 | |
| 759 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |
| 760 | #define BMP_ALIGN_CENTER 0x7FFF |
Nikita Kiryanov | 7c7e280 | 2012-08-09 00:14:51 +0000 | [diff] [blame] | 761 | |
| 762 | static void splash_align_axis(int *axis, unsigned long panel_size, |
| 763 | unsigned long picture_size) |
| 764 | { |
| 765 | unsigned long panel_picture_delta = panel_size - picture_size; |
| 766 | unsigned long axis_alignment; |
| 767 | |
| 768 | if (*axis == BMP_ALIGN_CENTER) |
| 769 | axis_alignment = panel_picture_delta / 2; |
| 770 | else if (*axis < 0) |
| 771 | axis_alignment = panel_picture_delta + *axis + 1; |
| 772 | else |
| 773 | return; |
| 774 | |
| 775 | *axis = max(0, axis_alignment); |
| 776 | } |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 777 | #endif |
| 778 | |
Tom Wai-Hong Tam | 45d7f52 | 2012-09-28 15:11:16 +0000 | [diff] [blame] | 779 | |
| 780 | #ifdef CONFIG_LCD_BMP_RLE8 |
| 781 | |
| 782 | #define BMP_RLE8_ESCAPE 0 |
| 783 | #define BMP_RLE8_EOL 0 |
| 784 | #define BMP_RLE8_EOBMP 1 |
| 785 | #define BMP_RLE8_DELTA 2 |
| 786 | |
| 787 | static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap, |
| 788 | int cnt) |
| 789 | { |
| 790 | while (cnt > 0) { |
| 791 | *(*fbp)++ = cmap[*bmap++]; |
| 792 | cnt--; |
| 793 | } |
| 794 | } |
| 795 | |
| 796 | static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt) |
| 797 | { |
| 798 | ushort *fb = *fbp; |
| 799 | int cnt_8copy = cnt >> 3; |
| 800 | |
| 801 | cnt -= cnt_8copy << 3; |
| 802 | while (cnt_8copy > 0) { |
| 803 | *fb++ = c; |
| 804 | *fb++ = c; |
| 805 | *fb++ = c; |
| 806 | *fb++ = c; |
| 807 | *fb++ = c; |
| 808 | *fb++ = c; |
| 809 | *fb++ = c; |
| 810 | *fb++ = c; |
| 811 | cnt_8copy--; |
| 812 | } |
| 813 | while (cnt > 0) { |
| 814 | *fb++ = c; |
| 815 | cnt--; |
| 816 | } |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 817 | *fbp = fb; |
Tom Wai-Hong Tam | 45d7f52 | 2012-09-28 15:11:16 +0000 | [diff] [blame] | 818 | } |
| 819 | |
| 820 | /* |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 821 | * Do not call this function directly, must be called from lcd_display_bitmap. |
Tom Wai-Hong Tam | 45d7f52 | 2012-09-28 15:11:16 +0000 | [diff] [blame] | 822 | */ |
| 823 | static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb, |
| 824 | int x_off, int y_off) |
| 825 | { |
| 826 | uchar *bmap; |
| 827 | ulong width, height; |
| 828 | ulong cnt, runlen; |
| 829 | int x, y; |
| 830 | int decode = 1; |
| 831 | |
Przemyslaw Marczak | dca2a1c | 2014-01-22 11:24:13 +0100 | [diff] [blame] | 832 | width = get_unaligned_le32(&bmp->header.width); |
| 833 | height = get_unaligned_le32(&bmp->header.height); |
| 834 | bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); |
Tom Wai-Hong Tam | 45d7f52 | 2012-09-28 15:11:16 +0000 | [diff] [blame] | 835 | |
| 836 | x = 0; |
| 837 | y = height - 1; |
| 838 | |
| 839 | while (decode) { |
| 840 | if (bmap[0] == BMP_RLE8_ESCAPE) { |
| 841 | switch (bmap[1]) { |
| 842 | case BMP_RLE8_EOL: |
| 843 | /* end of line */ |
| 844 | bmap += 2; |
| 845 | x = 0; |
| 846 | y--; |
| 847 | /* 16bpix, 2-byte per pixel, width should *2 */ |
| 848 | fb -= (width * 2 + lcd_line_length); |
| 849 | break; |
| 850 | case BMP_RLE8_EOBMP: |
| 851 | /* end of bitmap */ |
| 852 | decode = 0; |
| 853 | break; |
| 854 | case BMP_RLE8_DELTA: |
| 855 | /* delta run */ |
| 856 | x += bmap[2]; |
| 857 | y -= bmap[3]; |
| 858 | /* 16bpix, 2-byte per pixel, x should *2 */ |
| 859 | fb = (uchar *) (lcd_base + (y + y_off - 1) |
| 860 | * lcd_line_length + (x + x_off) * 2); |
| 861 | bmap += 4; |
| 862 | break; |
| 863 | default: |
| 864 | /* unencoded run */ |
| 865 | runlen = bmap[1]; |
| 866 | bmap += 2; |
| 867 | if (y < height) { |
| 868 | if (x < width) { |
| 869 | if (x + runlen > width) |
| 870 | cnt = width - x; |
| 871 | else |
| 872 | cnt = runlen; |
| 873 | draw_unencoded_bitmap( |
| 874 | (ushort **)&fb, |
| 875 | bmap, cmap, cnt); |
| 876 | } |
| 877 | x += runlen; |
| 878 | } |
| 879 | bmap += runlen; |
| 880 | if (runlen & 1) |
| 881 | bmap++; |
| 882 | } |
| 883 | } else { |
| 884 | /* encoded run */ |
| 885 | if (y < height) { |
| 886 | runlen = bmap[0]; |
| 887 | if (x < width) { |
| 888 | /* aggregate the same code */ |
| 889 | while (bmap[0] == 0xff && |
| 890 | bmap[2] != BMP_RLE8_ESCAPE && |
| 891 | bmap[1] == bmap[3]) { |
| 892 | runlen += bmap[2]; |
| 893 | bmap += 2; |
| 894 | } |
| 895 | if (x + runlen > width) |
| 896 | cnt = width - x; |
| 897 | else |
| 898 | cnt = runlen; |
| 899 | draw_encoded_bitmap((ushort **)&fb, |
| 900 | cmap[bmap[1]], cnt); |
| 901 | } |
| 902 | x += runlen; |
| 903 | } |
| 904 | bmap += 2; |
| 905 | } |
| 906 | } |
| 907 | } |
| 908 | #endif |
| 909 | |
Anatolij Gustschin | d23019f | 2012-09-22 06:55:53 +0000 | [diff] [blame] | 910 | #if defined(CONFIG_MPC823) || defined(CONFIG_MCC200) |
Nikita Kiryanov | bfdcc65 | 2012-08-09 00:14:53 +0000 | [diff] [blame] | 911 | #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++) |
Anatolij Gustschin | d23019f | 2012-09-22 06:55:53 +0000 | [diff] [blame] | 912 | #else |
| 913 | #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++ |
Nikita Kiryanov | bfdcc65 | 2012-08-09 00:14:53 +0000 | [diff] [blame] | 914 | #endif |
| 915 | |
| 916 | #if defined(CONFIG_BMP_16BPP) |
| 917 | #if defined(CONFIG_ATMEL_LCD_BGR555) |
| 918 | static inline void fb_put_word(uchar **fb, uchar **from) |
| 919 | { |
| 920 | *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03); |
| 921 | *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2); |
| 922 | *from += 2; |
| 923 | } |
| 924 | #else |
| 925 | static inline void fb_put_word(uchar **fb, uchar **from) |
| 926 | { |
| 927 | *(*fb)++ = *(*from)++; |
| 928 | *(*fb)++ = *(*from)++; |
| 929 | } |
| 930 | #endif |
| 931 | #endif /* CONFIG_BMP_16BPP */ |
| 932 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 933 | int lcd_display_bitmap(ulong bmp_image, int x, int y) |
| 934 | { |
Anatolij Gustschin | 00cc559 | 2009-02-25 20:28:13 +0100 | [diff] [blame] | 935 | #if !defined(CONFIG_MCC200) |
| 936 | ushort *cmap = NULL; |
| 937 | #endif |
| 938 | ushort *cmap_base = NULL; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 939 | ushort i, j; |
| 940 | uchar *fb; |
Simon Glass | 7d95f2a | 2014-02-27 13:26:19 -0700 | [diff] [blame] | 941 | bmp_image_t *bmp = (bmp_image_t *)map_sysmem(bmp_image, 0); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 942 | uchar *bmap; |
Tom Wai-Hong Tam | fecac46 | 2012-09-28 15:11:14 +0000 | [diff] [blame] | 943 | ushort padded_width; |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 944 | unsigned long width, height, byte_width; |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 945 | unsigned long pwidth = panel_info.vl_col; |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 946 | unsigned colors, bpix, bmp_bpix; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 947 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 948 | if (!bmp || !(bmp->header.signature[0] == 'B' && |
| 949 | bmp->header.signature[1] == 'M')) { |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 950 | printf("Error: no valid bmp image at %lx\n", bmp_image); |
| 951 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 952 | return 1; |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 953 | } |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 954 | |
Przemyslaw Marczak | dca2a1c | 2014-01-22 11:24:13 +0100 | [diff] [blame] | 955 | width = get_unaligned_le32(&bmp->header.width); |
| 956 | height = get_unaligned_le32(&bmp->header.height); |
| 957 | bmp_bpix = get_unaligned_le16(&bmp->header.bit_count); |
| 958 | |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 959 | colors = 1 << bmp_bpix; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 960 | |
| 961 | bpix = NBITS(panel_info.vl_bpix); |
| 962 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 963 | if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) { |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 964 | printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
| 965 | bpix, bmp_bpix); |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 966 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 967 | return 1; |
| 968 | } |
| 969 | |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 970 | /* We support displaying 8bpp BMPs on 16bpp LCDs */ |
Nikita Kiryanov | dad631c | 2012-12-20 00:52:34 +0000 | [diff] [blame] | 971 | if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 972 | printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
Przemyslaw Marczak | dca2a1c | 2014-01-22 11:24:13 +0100 | [diff] [blame] | 973 | bpix, get_unaligned_le16(&bmp->header.bit_count)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 974 | return 1; |
| 975 | } |
| 976 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 977 | debug("Display-bmp: %d x %d with %d colors\n", |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 978 | (int)width, (int)height, (int)colors); |
| 979 | |
Wolfgang Denk | f641471 | 2006-10-20 15:51:21 +0200 | [diff] [blame] | 980 | #if !defined(CONFIG_MCC200) |
| 981 | /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */ |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 982 | if (bmp_bpix == 8) { |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 983 | cmap = configuration_get_cmap(); |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 984 | cmap_base = cmap; |
| 985 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 986 | /* Set color map */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 987 | for (i = 0; i < colors; ++i) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 988 | bmp_color_table_entry_t cte = bmp->color_table[i]; |
Mark Jackson | 1464eff | 2008-08-01 09:48:29 +0100 | [diff] [blame] | 989 | #if !defined(CONFIG_ATMEL_LCD) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 990 | ushort colreg = |
| 991 | ( ((cte.red) << 8) & 0xf800) | |
Wolfgang Denk | 59d80bf | 2005-09-21 15:24:52 +0200 | [diff] [blame] | 992 | ( ((cte.green) << 3) & 0x07e0) | |
| 993 | ( ((cte.blue) >> 3) & 0x001f) ; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 994 | #ifdef CONFIG_SYS_INVERT_COLORS |
wdenk | 25d6712 | 2004-12-10 11:40:40 +0000 | [diff] [blame] | 995 | *cmap = 0xffff - colreg; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 996 | #else |
wdenk | 25d6712 | 2004-12-10 11:40:40 +0000 | [diff] [blame] | 997 | *cmap = colreg; |
| 998 | #endif |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 999 | #if defined(CONFIG_MPC823) |
wdenk | 25d6712 | 2004-12-10 11:40:40 +0000 | [diff] [blame] | 1000 | cmap--; |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 1001 | #else |
| 1002 | cmap++; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1003 | #endif |
Mark Jackson | 1464eff | 2008-08-01 09:48:29 +0100 | [diff] [blame] | 1004 | #else /* CONFIG_ATMEL_LCD */ |
| 1005 | lcd_setcolreg(i, cte.red, cte.green, cte.blue); |
| 1006 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1007 | } |
| 1008 | } |
Wolfgang Denk | f641471 | 2006-10-20 15:51:21 +0200 | [diff] [blame] | 1009 | #endif |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 1010 | /* |
| 1011 | * BMP format for Monochrome assumes that the state of a |
| 1012 | * pixel is described on a per Bit basis, not per Byte. |
| 1013 | * So, in case of Monochrome BMP we should align widths |
| 1014 | * on a byte boundary and convert them from Bit to Byte |
| 1015 | * units. |
Wolfgang Denk | 511d0c7 | 2006-10-09 00:42:01 +0200 | [diff] [blame] | 1016 | * Probably, PXA250 and MPC823 process 1bpp BMP images in |
| 1017 | * their own ways, so make the converting to be MCC200 |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 1018 | * specific. |
| 1019 | */ |
| 1020 | #if defined(CONFIG_MCC200) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1021 | if (bpix == 1) { |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 1022 | width = ((width + 7) & ~7) >> 3; |
| 1023 | x = ((x + 7) & ~7) >> 3; |
| 1024 | pwidth= ((pwidth + 7) & ~7) >> 3; |
| 1025 | } |
| 1026 | #endif |
| 1027 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 1028 | padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width); |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1029 | |
| 1030 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |
Nikita Kiryanov | 7c7e280 | 2012-08-09 00:14:51 +0000 | [diff] [blame] | 1031 | splash_align_axis(&x, pwidth, width); |
| 1032 | splash_align_axis(&y, panel_info.vl_row, height); |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1033 | #endif /* CONFIG_SPLASH_SCREEN_ALIGN */ |
| 1034 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1035 | if ((x + width) > pwidth) |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 1036 | width = pwidth - x; |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1037 | if ((y + height) > panel_info.vl_row) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1038 | height = panel_info.vl_row - y; |
| 1039 | |
Przemyslaw Marczak | dca2a1c | 2014-01-22 11:24:13 +0100 | [diff] [blame] | 1040 | bmap = (uchar *)bmp + get_unaligned_le32(&bmp->header.data_offset); |
| 1041 | fb = (uchar *)(lcd_base + |
Liu Ying | 8d46d5b | 2011-01-11 15:29:58 +0800 | [diff] [blame] | 1042 | (y + height - 1) * lcd_line_length + x * bpix / 8); |
Mark Jackson | a303dfb | 2009-02-06 10:37:49 +0100 | [diff] [blame] | 1043 | |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 1044 | switch (bmp_bpix) { |
Mark Jackson | a303dfb | 2009-02-06 10:37:49 +0100 | [diff] [blame] | 1045 | case 1: /* pass through */ |
| 1046 | case 8: |
Tom Wai-Hong Tam | 45d7f52 | 2012-09-28 15:11:16 +0000 | [diff] [blame] | 1047 | #ifdef CONFIG_LCD_BMP_RLE8 |
Przemyslaw Marczak | dca2a1c | 2014-01-22 11:24:13 +0100 | [diff] [blame] | 1048 | u32 compression = get_unaligned_le32(&bmp->header.compression); |
| 1049 | if (compression == BMP_BI_RLE8) { |
Tom Wai-Hong Tam | 45d7f52 | 2012-09-28 15:11:16 +0000 | [diff] [blame] | 1050 | if (bpix != 16) { |
| 1051 | /* TODO implement render code for bpix != 16 */ |
| 1052 | printf("Error: only support 16 bpix"); |
| 1053 | return 1; |
| 1054 | } |
| 1055 | lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y); |
| 1056 | break; |
| 1057 | } |
| 1058 | #endif |
| 1059 | |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 1060 | if (bpix != 16) |
| 1061 | byte_width = width; |
| 1062 | else |
| 1063 | byte_width = width * 2; |
| 1064 | |
Mark Jackson | a303dfb | 2009-02-06 10:37:49 +0100 | [diff] [blame] | 1065 | for (i = 0; i < height; ++i) { |
| 1066 | WATCHDOG_RESET(); |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 1067 | for (j = 0; j < width; j++) { |
| 1068 | if (bpix != 16) { |
Nikita Kiryanov | bfdcc65 | 2012-08-09 00:14:53 +0000 | [diff] [blame] | 1069 | FB_PUT_BYTE(fb, bmap); |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 1070 | } else { |
| 1071 | *(uint16_t *)fb = cmap_base[*(bmap++)]; |
| 1072 | fb += sizeof(uint16_t) / sizeof(*fb); |
| 1073 | } |
| 1074 | } |
Tom Wai-Hong Tam | fecac46 | 2012-09-28 15:11:14 +0000 | [diff] [blame] | 1075 | bmap += (padded_width - width); |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 1076 | fb -= byte_width + lcd_line_length; |
Mark Jackson | a303dfb | 2009-02-06 10:37:49 +0100 | [diff] [blame] | 1077 | } |
| 1078 | break; |
| 1079 | |
| 1080 | #if defined(CONFIG_BMP_16BPP) |
| 1081 | case 16: |
| 1082 | for (i = 0; i < height; ++i) { |
| 1083 | WATCHDOG_RESET(); |
Nikita Kiryanov | bfdcc65 | 2012-08-09 00:14:53 +0000 | [diff] [blame] | 1084 | for (j = 0; j < width; j++) |
| 1085 | fb_put_word(&fb, &bmap); |
| 1086 | |
Tom Wai-Hong Tam | fecac46 | 2012-09-28 15:11:14 +0000 | [diff] [blame] | 1087 | bmap += (padded_width - width) * 2; |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 1088 | fb -= width * 2 + lcd_line_length; |
Mark Jackson | a303dfb | 2009-02-06 10:37:49 +0100 | [diff] [blame] | 1089 | } |
| 1090 | break; |
| 1091 | #endif /* CONFIG_BMP_16BPP */ |
| 1092 | |
Donghwa Lee | fb6a9aa | 2012-05-09 19:23:37 +0000 | [diff] [blame] | 1093 | #if defined(CONFIG_BMP_32BPP) |
| 1094 | case 32: |
| 1095 | for (i = 0; i < height; ++i) { |
| 1096 | for (j = 0; j < width; j++) { |
| 1097 | *(fb++) = *(bmap++); |
| 1098 | *(fb++) = *(bmap++); |
| 1099 | *(fb++) = *(bmap++); |
| 1100 | *(fb++) = *(bmap++); |
| 1101 | } |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 1102 | fb -= lcd_line_length + width * (bpix / 8); |
Donghwa Lee | fb6a9aa | 2012-05-09 19:23:37 +0000 | [diff] [blame] | 1103 | } |
| 1104 | break; |
| 1105 | #endif /* CONFIG_BMP_32BPP */ |
Mark Jackson | a303dfb | 2009-02-06 10:37:49 +0100 | [diff] [blame] | 1106 | default: |
| 1107 | break; |
| 1108 | }; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1109 | |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 1110 | lcd_sync(); |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1111 | return 0; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1112 | } |
Jon Loeliger | c3517f9 | 2007-07-08 18:10:08 -0500 | [diff] [blame] | 1113 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1114 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1115 | static void *lcd_logo(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1116 | { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1117 | #ifdef CONFIG_SPLASH_SCREEN |
| 1118 | char *s; |
| 1119 | ulong addr; |
| 1120 | static int do_splash = 1; |
| 1121 | |
| 1122 | if (do_splash && (s = getenv("splashimage")) != NULL) { |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1123 | int x = 0, y = 0; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1124 | do_splash = 0; |
| 1125 | |
Nikita Kiryanov | 581bb41 | 2013-01-30 21:39:57 +0000 | [diff] [blame] | 1126 | if (splash_screen_prepare()) |
Robert Winkler | dd4425e | 2013-06-17 11:31:29 -0700 | [diff] [blame] | 1127 | return (void *)lcd_base; |
Nikita Kiryanov | 581bb41 | 2013-01-30 21:39:57 +0000 | [diff] [blame] | 1128 | |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1129 | addr = simple_strtoul (s, NULL, 16); |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1130 | |
Anatolij Gustschin | ff8fb56 | 2013-07-02 00:04:05 +0200 | [diff] [blame] | 1131 | splash_get_pos(&x, &y); |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1132 | |
Nikita Kiryanov | d3a555e | 2012-08-09 00:14:50 +0000 | [diff] [blame] | 1133 | if (bmp_display(addr, x, y) == 0) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1134 | return (void *)lcd_base; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1135 | } |
| 1136 | #endif /* CONFIG_SPLASH_SCREEN */ |
| 1137 | |
Anatolij Gustschin | 2b5cb3d | 2012-04-27 04:41:27 +0000 | [diff] [blame] | 1138 | bitmap_plot(0, 0); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1139 | |
Haavard Skinnemoen | 6b59e03 | 2008-09-01 16:21:22 +0200 | [diff] [blame] | 1140 | #ifdef CONFIG_LCD_INFO |
| 1141 | console_col = LCD_INFO_X / VIDEO_FONT_WIDTH; |
| 1142 | console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT; |
| 1143 | lcd_show_board_info(); |
| 1144 | #endif /* CONFIG_LCD_INFO */ |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 1145 | |
wdenk | 88804d1 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 1146 | #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1147 | return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1148 | #else |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1149 | return (void *)lcd_base; |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 1150 | #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */ |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1151 | } |
| 1152 | |
Nikita Kiryanov | c088048 | 2013-02-24 21:28:43 +0000 | [diff] [blame] | 1153 | #ifdef CONFIG_SPLASHIMAGE_GUARD |
| 1154 | static int on_splashimage(const char *name, const char *value, enum env_op op, |
| 1155 | int flags) |
| 1156 | { |
| 1157 | ulong addr; |
| 1158 | int aligned; |
| 1159 | |
| 1160 | if (op == env_op_delete) |
| 1161 | return 0; |
| 1162 | |
| 1163 | addr = simple_strtoul(value, NULL, 16); |
| 1164 | /* See README.displaying-bmps */ |
| 1165 | aligned = (addr % 4 == 2); |
| 1166 | if (!aligned) { |
| 1167 | printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n"); |
| 1168 | return -1; |
| 1169 | } |
| 1170 | |
| 1171 | return 0; |
| 1172 | } |
| 1173 | |
| 1174 | U_BOOT_ENV_CALLBACK(splashimage, on_splashimage); |
| 1175 | #endif |
| 1176 | |
Vadim Bendebury | 395166c | 2012-09-28 15:11:13 +0000 | [diff] [blame] | 1177 | void lcd_position_cursor(unsigned col, unsigned row) |
| 1178 | { |
| 1179 | console_col = min(col, CONSOLE_COLS - 1); |
| 1180 | console_row = min(row, CONSOLE_ROWS - 1); |
| 1181 | } |
| 1182 | |
| 1183 | int lcd_get_pixel_width(void) |
| 1184 | { |
| 1185 | return panel_info.vl_col; |
| 1186 | } |
| 1187 | |
| 1188 | int lcd_get_pixel_height(void) |
| 1189 | { |
| 1190 | return panel_info.vl_row; |
| 1191 | } |
| 1192 | |
| 1193 | int lcd_get_screen_rows(void) |
| 1194 | { |
| 1195 | return CONSOLE_ROWS; |
| 1196 | } |
| 1197 | |
| 1198 | int lcd_get_screen_columns(void) |
| 1199 | { |
| 1200 | return CONSOLE_COLS; |
| 1201 | } |
Stephen Warren | 6a195d2 | 2013-05-27 18:31:17 +0000 | [diff] [blame] | 1202 | |
| 1203 | #if defined(CONFIG_LCD_DT_SIMPLEFB) |
| 1204 | static int lcd_dt_simplefb_configure_node(void *blob, int off) |
| 1205 | { |
| 1206 | u32 stride; |
| 1207 | fdt32_t cells[2]; |
| 1208 | int ret; |
Stephen Warren | 5af7d0f | 2013-06-13 17:13:11 -0600 | [diff] [blame] | 1209 | static const char format[] = |
Stephen Warren | 6a195d2 | 2013-05-27 18:31:17 +0000 | [diff] [blame] | 1210 | #if LCD_BPP == LCD_COLOR16 |
| 1211 | "r5g6b5"; |
| 1212 | #else |
| 1213 | ""; |
| 1214 | #endif |
| 1215 | |
| 1216 | if (!format[0]) |
| 1217 | return -1; |
| 1218 | |
| 1219 | stride = panel_info.vl_col * 2; |
| 1220 | |
| 1221 | cells[0] = cpu_to_fdt32(gd->fb_base); |
| 1222 | cells[1] = cpu_to_fdt32(stride * panel_info.vl_row); |
| 1223 | ret = fdt_setprop(blob, off, "reg", cells, sizeof(cells[0]) * 2); |
| 1224 | if (ret < 0) |
| 1225 | return -1; |
| 1226 | |
| 1227 | cells[0] = cpu_to_fdt32(panel_info.vl_col); |
| 1228 | ret = fdt_setprop(blob, off, "width", cells, sizeof(cells[0])); |
| 1229 | if (ret < 0) |
| 1230 | return -1; |
| 1231 | |
| 1232 | cells[0] = cpu_to_fdt32(panel_info.vl_row); |
| 1233 | ret = fdt_setprop(blob, off, "height", cells, sizeof(cells[0])); |
| 1234 | if (ret < 0) |
| 1235 | return -1; |
| 1236 | |
| 1237 | cells[0] = cpu_to_fdt32(stride); |
| 1238 | ret = fdt_setprop(blob, off, "stride", cells, sizeof(cells[0])); |
| 1239 | if (ret < 0) |
| 1240 | return -1; |
| 1241 | |
| 1242 | ret = fdt_setprop(blob, off, "format", format, strlen(format) + 1); |
| 1243 | if (ret < 0) |
| 1244 | return -1; |
| 1245 | |
| 1246 | ret = fdt_delprop(blob, off, "status"); |
| 1247 | if (ret < 0) |
| 1248 | return -1; |
| 1249 | |
| 1250 | return 0; |
| 1251 | } |
| 1252 | |
| 1253 | int lcd_dt_simplefb_add_node(void *blob) |
| 1254 | { |
Stephen Warren | 5af7d0f | 2013-06-13 17:13:11 -0600 | [diff] [blame] | 1255 | static const char compat[] = "simple-framebuffer"; |
| 1256 | static const char disabled[] = "disabled"; |
Stephen Warren | 6a195d2 | 2013-05-27 18:31:17 +0000 | [diff] [blame] | 1257 | int off, ret; |
| 1258 | |
| 1259 | off = fdt_add_subnode(blob, 0, "framebuffer"); |
| 1260 | if (off < 0) |
| 1261 | return -1; |
| 1262 | |
| 1263 | ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled)); |
| 1264 | if (ret < 0) |
| 1265 | return -1; |
| 1266 | |
| 1267 | ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat)); |
| 1268 | if (ret < 0) |
| 1269 | return -1; |
| 1270 | |
| 1271 | return lcd_dt_simplefb_configure_node(blob, off); |
| 1272 | } |
| 1273 | |
| 1274 | int lcd_dt_simplefb_enable_existing_node(void *blob) |
| 1275 | { |
| 1276 | int off; |
| 1277 | |
| 1278 | off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer"); |
| 1279 | if (off < 0) |
| 1280 | return -1; |
| 1281 | |
| 1282 | return lcd_dt_simplefb_configure_node(blob, off); |
| 1283 | } |
| 1284 | #endif |