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