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