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