Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2002 ELTEC Elektronik AG |
| 4 | * Frank Gottschling <fgottschling@eltec.de> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * cfb_console.c |
| 9 | * |
| 10 | * Color Framebuffer Console driver for 8/15/16/24/32 bits per pixel. |
| 11 | * |
| 12 | * At the moment only the 8x16 font is tested and the font fore- and |
| 13 | * background color is limited to black/white/gray colors. The Linux |
| 14 | * logo can be placed in the upper left corner and additional board |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 15 | * information strings (that normally goes to serial port) can be drawn. |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 16 | * |
Simon Glass | eaba37e | 2015-11-11 10:05:47 -0700 | [diff] [blame] | 17 | * The console driver can use a keyboard interface for character input |
| 18 | * but this is deprecated. Only rk51 uses it. |
| 19 | * |
| 20 | * Character output goes to a memory-mapped video |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 21 | * framebuffer with little or big-endian organisation. |
| 22 | * With environment setting 'console=serial' the console i/o can be |
| 23 | * forced to serial port. |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 24 | * |
| 25 | * The driver uses graphic specific defines/parameters/functions: |
| 26 | * |
| 27 | * (for SMI LynxE graphic chip) |
| 28 | * |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 29 | * VIDEO_FB_LITTLE_ENDIAN - framebuffer organisation default: big endian |
| 30 | * VIDEO_HW_RECTFILL - graphic driver supports hardware rectangle fill |
| 31 | * VIDEO_HW_BITBLT - graphic driver supports hardware bit blt |
| 32 | * |
| 33 | * Console Parameters are set by graphic drivers global struct: |
| 34 | * |
| 35 | * VIDEO_VISIBLE_COLS - x resolution |
| 36 | * VIDEO_VISIBLE_ROWS - y resolution |
| 37 | * VIDEO_PIXEL_SIZE - storage size in byte per pixel |
| 38 | * VIDEO_DATA_FORMAT - graphical data format GDF |
| 39 | * VIDEO_FB_ADRS - start of video memory |
| 40 | * |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 41 | * VIDEO_KBD_INIT_FCT - init function for keyboard |
| 42 | * VIDEO_TSTC_FCT - keyboard_tstc function |
| 43 | * VIDEO_GETC_FCT - keyboard_getc function |
| 44 | * |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 45 | * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo |
| 46 | * CONFIG_CONSOLE_EXTRA_INFO - display additional board information |
| 47 | * strings that normaly goes to serial |
| 48 | * port. This define requires a board |
| 49 | * specific function: |
| 50 | * video_drawstring (VIDEO_INFO_X, |
| 51 | * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT, |
| 52 | * info); |
| 53 | * that fills a info buffer at i=row. |
| 54 | * s.a: board/eltec/bab7xx. |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 55 | * |
| 56 | * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last |
| 57 | * character. No blinking is provided. |
| 58 | * Uses the macros CURSOR_SET and |
| 59 | * CURSOR_OFF. |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 60 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 61 | |
| 62 | #include <common.h> |
Simon Glass | ed38aef | 2020-05-10 11:40:03 -0600 | [diff] [blame] | 63 | #include <command.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 64 | #include <cpu_func.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 65 | #include <env.h> |
Simon Glass | e9fa1f0 | 2015-03-02 12:40:50 -0700 | [diff] [blame] | 66 | #include <fdtdec.h> |
Simon Glass | 1a974af | 2019-08-01 09:46:36 -0600 | [diff] [blame] | 67 | #include <gzip.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 68 | #include <log.h> |
Pali Rohár | ba87ddf | 2021-08-02 15:18:31 +0200 | [diff] [blame] | 69 | #include <version_string.h> |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 70 | #include <malloc.h> |
Simon Glass | 88ecb9b | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 71 | #include <video.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 72 | #include <asm/global_data.h> |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 73 | #include <dm/ofnode.h> |
Wolfgang Denk | ffbd9ee | 2011-11-04 15:55:20 +0000 | [diff] [blame] | 74 | #include <linux/compiler.h> |
wdenk | 9dd2b88 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 75 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 76 | /* |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 77 | * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc. |
| 78 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 79 | #include <video_fb.h> |
| 80 | |
Robert Winkler | 2a90ed0 | 2013-06-17 11:31:29 -0700 | [diff] [blame] | 81 | #include <splash.h> |
| 82 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 83 | /* |
| 84 | * some Macros |
| 85 | */ |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 86 | #define VIDEO_VISIBLE_COLS (pGD->winSizeX) |
| 87 | #define VIDEO_VISIBLE_ROWS (pGD->winSizeY) |
| 88 | #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP) |
| 89 | #define VIDEO_DATA_FORMAT (pGD->gdfIndex) |
| 90 | #define VIDEO_FB_ADRS (pGD->frameAdrs) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 91 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 92 | /* |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 93 | * Console device |
| 94 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 95 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 96 | #include <linux/types.h> |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 97 | #include <stdio_dev.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 98 | #include <video_font.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 99 | |
Jon Loeliger | 30c2f24 | 2007-07-10 11:13:21 -0500 | [diff] [blame] | 100 | #if defined(CONFIG_CMD_DATE) |
| 101 | #include <rtc.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 102 | #endif |
| 103 | |
Jon Loeliger | b1d408a | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 104 | #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 105 | #include <watchdog.h> |
| 106 | #include <bmp_layout.h> |
Anatolij Gustschin | b9b5eaf | 2013-07-02 00:04:05 +0200 | [diff] [blame] | 107 | #include <splash.h> |
Matthias Weisser | 5388418 | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 108 | #endif |
| 109 | |
Simon Glass | d615c89 | 2016-10-17 20:12:50 -0600 | [diff] [blame] | 110 | #if !defined(CONFIG_VIDEO_SW_CURSOR) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 111 | /* no Cursor defined */ |
| 112 | #define CURSOR_ON |
| 113 | #define CURSOR_OFF |
| 114 | #define CURSOR_SET |
| 115 | #endif |
| 116 | |
Simon Glass | f406a1b | 2015-10-18 21:17:18 -0600 | [diff] [blame] | 117 | #if defined(CONFIG_VIDEO_SW_CURSOR) |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 118 | void console_cursor(int state); |
| 119 | |
Timur Tabi | be0c74e | 2010-08-27 15:45:47 -0500 | [diff] [blame] | 120 | #define CURSOR_ON console_cursor(1) |
| 121 | #define CURSOR_OFF console_cursor(0) |
Gabe Black | 12874de | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 122 | #define CURSOR_SET video_set_cursor() |
Simon Glass | f406a1b | 2015-10-18 21:17:18 -0600 | [diff] [blame] | 123 | #endif /* CONFIG_VIDEO_SW_CURSOR */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 124 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 125 | #define VIDEO_COLS VIDEO_VISIBLE_COLS |
| 126 | #define VIDEO_ROWS VIDEO_VISIBLE_ROWS |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 127 | #ifndef VIDEO_LINE_LEN |
| 128 | #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE) |
| 129 | #endif |
| 130 | #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN) |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 131 | #define VIDEO_BURST_LEN (VIDEO_COLS/8) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 132 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 133 | #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 134 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 135 | #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH) |
| 136 | #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN) |
| 137 | #define CONSOLE_ROW_FIRST (video_console_address) |
| 138 | #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE) |
| 139 | #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE) |
| 140 | #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS) |
Simon Glass | 6ceb7f0 | 2015-01-01 16:17:57 -0700 | [diff] [blame] | 141 | |
| 142 | /* By default we scroll by a single line */ |
| 143 | #ifndef CONFIG_CONSOLE_SCROLL_LINES |
| 144 | #define CONFIG_CONSOLE_SCROLL_LINES 1 |
| 145 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 146 | |
| 147 | /* Macros */ |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 148 | #ifdef VIDEO_FB_LITTLE_ENDIAN |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 149 | #define SWAP16(x) ((((x) & 0x00ff) << 8) | \ |
| 150 | ((x) >> 8) \ |
| 151 | ) |
| 152 | #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \ |
| 153 | (((x) & 0x0000ff00) << 8) | \ |
| 154 | (((x) & 0x00ff0000) >> 8) | \ |
| 155 | (((x) & 0xff000000) >> 24) \ |
| 156 | ) |
| 157 | #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \ |
| 158 | (((x) & 0x0000ff00) >> 8) | \ |
| 159 | (((x) & 0x00ff0000) << 8) | \ |
| 160 | (((x) & 0xff000000) >> 8) \ |
| 161 | ) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 162 | #else |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 163 | #define SWAP16(x) (x) |
| 164 | #define SWAP32(x) (x) |
Wolfgang Grandegger | e1b0584 | 2009-10-23 12:03:15 +0200 | [diff] [blame] | 165 | #if defined(VIDEO_FB_16BPP_WORD_SWAP) |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 166 | #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16)) |
Andrew Dyer | 5601c61 | 2008-08-29 12:30:39 -0500 | [diff] [blame] | 167 | #else |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 168 | #define SHORTSWAP32(x) (x) |
Anatolij Gustschin | 3545f59 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 169 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 170 | #endif |
| 171 | |
Anatolij Gustschin | dbad2b8 | 2012-06-05 09:19:18 +0200 | [diff] [blame] | 172 | DECLARE_GLOBAL_DATA_PTR; |
| 173 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 174 | /* Locals */ |
| 175 | static GraphicDevice *pGD; /* Pointer to Graphic array */ |
| 176 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 177 | static void *video_fb_address; /* frame buffer address */ |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 178 | static void *video_console_address; /* console buffer start address */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 179 | |
Simon Glass | c87ddf7 | 2021-11-19 13:24:02 -0700 | [diff] [blame] | 180 | static int video_logo_height; /* not supported anymore */ |
Matthias Weisser | 76d7086 | 2010-01-12 12:06:31 +0100 | [diff] [blame] | 181 | |
Anatolij Gustschin | 814d0e1 | 2011-12-07 03:58:10 +0000 | [diff] [blame] | 182 | static int __maybe_unused cursor_state; |
| 183 | static int __maybe_unused old_col; |
| 184 | static int __maybe_unused old_row; |
Gabe Black | 12874de | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 185 | |
Wolfgang Denk | a87b2a95 | 2011-07-30 12:48:09 +0000 | [diff] [blame] | 186 | static int console_col; /* cursor col */ |
| 187 | static int console_row; /* cursor row */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 188 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 189 | static u32 eorx, fgx, bgx; /* color pats */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 190 | |
Anatolij Gustschin | dbad2b8 | 2012-06-05 09:19:18 +0200 | [diff] [blame] | 191 | static int cfb_do_flush_cache; |
| 192 | |
Pali Rohár | 4a57da3 | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 193 | #ifdef CONFIG_CFB_CONSOLE_ANSI |
| 194 | static char ansi_buf[10]; |
| 195 | static int ansi_buf_size; |
| 196 | static int ansi_colors_need_revert; |
| 197 | static int ansi_cursor_hidden; |
| 198 | #endif |
| 199 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 200 | static const int video_font_draw_table8[] = { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 201 | 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff, |
| 202 | 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff, |
| 203 | 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff, |
| 204 | 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff |
| 205 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 206 | |
| 207 | static const int video_font_draw_table15[] = { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 208 | 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff |
| 209 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 210 | |
| 211 | static const int video_font_draw_table16[] = { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 212 | 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff |
| 213 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 214 | |
| 215 | static const int video_font_draw_table24[16][3] = { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 216 | {0x00000000, 0x00000000, 0x00000000}, |
| 217 | {0x00000000, 0x00000000, 0x00ffffff}, |
| 218 | {0x00000000, 0x0000ffff, 0xff000000}, |
| 219 | {0x00000000, 0x0000ffff, 0xffffffff}, |
| 220 | {0x000000ff, 0xffff0000, 0x00000000}, |
| 221 | {0x000000ff, 0xffff0000, 0x00ffffff}, |
| 222 | {0x000000ff, 0xffffffff, 0xff000000}, |
| 223 | {0x000000ff, 0xffffffff, 0xffffffff}, |
| 224 | {0xffffff00, 0x00000000, 0x00000000}, |
| 225 | {0xffffff00, 0x00000000, 0x00ffffff}, |
| 226 | {0xffffff00, 0x0000ffff, 0xff000000}, |
| 227 | {0xffffff00, 0x0000ffff, 0xffffffff}, |
| 228 | {0xffffffff, 0xffff0000, 0x00000000}, |
| 229 | {0xffffffff, 0xffff0000, 0x00ffffff}, |
| 230 | {0xffffffff, 0xffffffff, 0xff000000}, |
| 231 | {0xffffffff, 0xffffffff, 0xffffffff} |
| 232 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 233 | |
| 234 | static const int video_font_draw_table32[16][4] = { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 235 | {0x00000000, 0x00000000, 0x00000000, 0x00000000}, |
| 236 | {0x00000000, 0x00000000, 0x00000000, 0x00ffffff}, |
| 237 | {0x00000000, 0x00000000, 0x00ffffff, 0x00000000}, |
| 238 | {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff}, |
| 239 | {0x00000000, 0x00ffffff, 0x00000000, 0x00000000}, |
| 240 | {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff}, |
| 241 | {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000}, |
| 242 | {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff}, |
| 243 | {0x00ffffff, 0x00000000, 0x00000000, 0x00000000}, |
| 244 | {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff}, |
| 245 | {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000}, |
| 246 | {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff}, |
| 247 | {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000}, |
| 248 | {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff}, |
| 249 | {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000}, |
| 250 | {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff} |
| 251 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 252 | |
Heiko Schocher | 9cff8ad | 2013-08-03 07:22:53 +0200 | [diff] [blame] | 253 | /* |
| 254 | * Implement a weak default function for boards that optionally |
| 255 | * need to skip the cfb initialization. |
| 256 | */ |
| 257 | __weak int board_cfb_skip(void) |
| 258 | { |
| 259 | /* As default, don't skip cfb init */ |
| 260 | return 0; |
| 261 | } |
| 262 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 263 | static void video_drawchars(int xx, int yy, unsigned char *s, int count) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 264 | { |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 265 | u8 *cdat, *dest, *dest0; |
| 266 | int rows, offset, c; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 267 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 268 | offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE; |
| 269 | dest0 = video_fb_address + offset; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 270 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 271 | switch (VIDEO_DATA_FORMAT) { |
| 272 | case GDF__8BIT_INDEX: |
| 273 | case GDF__8BIT_332RGB: |
| 274 | while (count--) { |
| 275 | c = *s; |
| 276 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; |
| 277 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 278 | rows--; dest += VIDEO_LINE_LEN) { |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 279 | u8 bits = *cdat++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 280 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 281 | ((u32 *) dest)[0] = |
| 282 | (video_font_draw_table8[bits >> 4] & |
| 283 | eorx) ^ bgx; |
Marek Vasut | 118959f | 2013-07-30 23:37:59 +0200 | [diff] [blame] | 284 | |
| 285 | if (VIDEO_FONT_WIDTH == 4) |
| 286 | continue; |
| 287 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 288 | ((u32 *) dest)[1] = |
| 289 | (video_font_draw_table8[bits & 15] & |
| 290 | eorx) ^ bgx; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 291 | } |
| 292 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; |
| 293 | s++; |
| 294 | } |
| 295 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 296 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 297 | case GDF_15BIT_555RGB: |
| 298 | while (count--) { |
| 299 | c = *s; |
| 300 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; |
| 301 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 302 | rows--; dest += VIDEO_LINE_LEN) { |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 303 | u8 bits = *cdat++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 304 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 305 | ((u32 *) dest)[0] = |
| 306 | SHORTSWAP32((video_font_draw_table15 |
| 307 | [bits >> 6] & eorx) ^ |
| 308 | bgx); |
| 309 | ((u32 *) dest)[1] = |
| 310 | SHORTSWAP32((video_font_draw_table15 |
| 311 | [bits >> 4 & 3] & eorx) ^ |
| 312 | bgx); |
Marek Vasut | 118959f | 2013-07-30 23:37:59 +0200 | [diff] [blame] | 313 | |
| 314 | if (VIDEO_FONT_WIDTH == 4) |
| 315 | continue; |
| 316 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 317 | ((u32 *) dest)[2] = |
| 318 | SHORTSWAP32((video_font_draw_table15 |
| 319 | [bits >> 2 & 3] & eorx) ^ |
| 320 | bgx); |
| 321 | ((u32 *) dest)[3] = |
| 322 | SHORTSWAP32((video_font_draw_table15 |
| 323 | [bits & 3] & eorx) ^ |
| 324 | bgx); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 325 | } |
| 326 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; |
| 327 | s++; |
| 328 | } |
| 329 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 330 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 331 | case GDF_16BIT_565RGB: |
| 332 | while (count--) { |
| 333 | c = *s; |
| 334 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; |
| 335 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 336 | rows--; dest += VIDEO_LINE_LEN) { |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 337 | u8 bits = *cdat++; |
| 338 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 339 | ((u32 *) dest)[0] = |
| 340 | SHORTSWAP32((video_font_draw_table16 |
| 341 | [bits >> 6] & eorx) ^ |
| 342 | bgx); |
| 343 | ((u32 *) dest)[1] = |
| 344 | SHORTSWAP32((video_font_draw_table16 |
| 345 | [bits >> 4 & 3] & eorx) ^ |
| 346 | bgx); |
Marek Vasut | 118959f | 2013-07-30 23:37:59 +0200 | [diff] [blame] | 347 | |
| 348 | if (VIDEO_FONT_WIDTH == 4) |
| 349 | continue; |
| 350 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 351 | ((u32 *) dest)[2] = |
| 352 | SHORTSWAP32((video_font_draw_table16 |
| 353 | [bits >> 2 & 3] & eorx) ^ |
| 354 | bgx); |
| 355 | ((u32 *) dest)[3] = |
| 356 | SHORTSWAP32((video_font_draw_table16 |
| 357 | [bits & 3] & eorx) ^ |
| 358 | bgx); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 359 | } |
| 360 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; |
| 361 | s++; |
| 362 | } |
| 363 | break; |
| 364 | |
| 365 | case GDF_32BIT_X888RGB: |
| 366 | while (count--) { |
| 367 | c = *s; |
| 368 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; |
| 369 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 370 | rows--; dest += VIDEO_LINE_LEN) { |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 371 | u8 bits = *cdat++; |
| 372 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 373 | ((u32 *) dest)[0] = |
| 374 | SWAP32((video_font_draw_table32 |
| 375 | [bits >> 4][0] & eorx) ^ bgx); |
| 376 | ((u32 *) dest)[1] = |
| 377 | SWAP32((video_font_draw_table32 |
| 378 | [bits >> 4][1] & eorx) ^ bgx); |
| 379 | ((u32 *) dest)[2] = |
| 380 | SWAP32((video_font_draw_table32 |
| 381 | [bits >> 4][2] & eorx) ^ bgx); |
| 382 | ((u32 *) dest)[3] = |
| 383 | SWAP32((video_font_draw_table32 |
| 384 | [bits >> 4][3] & eorx) ^ bgx); |
Marek Vasut | 118959f | 2013-07-30 23:37:59 +0200 | [diff] [blame] | 385 | |
| 386 | |
| 387 | if (VIDEO_FONT_WIDTH == 4) |
| 388 | continue; |
| 389 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 390 | ((u32 *) dest)[4] = |
| 391 | SWAP32((video_font_draw_table32 |
| 392 | [bits & 15][0] & eorx) ^ bgx); |
| 393 | ((u32 *) dest)[5] = |
| 394 | SWAP32((video_font_draw_table32 |
| 395 | [bits & 15][1] & eorx) ^ bgx); |
| 396 | ((u32 *) dest)[6] = |
| 397 | SWAP32((video_font_draw_table32 |
| 398 | [bits & 15][2] & eorx) ^ bgx); |
| 399 | ((u32 *) dest)[7] = |
| 400 | SWAP32((video_font_draw_table32 |
| 401 | [bits & 15][3] & eorx) ^ bgx); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 402 | } |
| 403 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; |
| 404 | s++; |
| 405 | } |
| 406 | break; |
| 407 | |
| 408 | case GDF_24BIT_888RGB: |
| 409 | while (count--) { |
| 410 | c = *s; |
| 411 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; |
| 412 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 413 | rows--; dest += VIDEO_LINE_LEN) { |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 414 | u8 bits = *cdat++; |
| 415 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 416 | ((u32 *) dest)[0] = |
| 417 | (video_font_draw_table24[bits >> 4][0] |
| 418 | & eorx) ^ bgx; |
| 419 | ((u32 *) dest)[1] = |
| 420 | (video_font_draw_table24[bits >> 4][1] |
| 421 | & eorx) ^ bgx; |
| 422 | ((u32 *) dest)[2] = |
| 423 | (video_font_draw_table24[bits >> 4][2] |
| 424 | & eorx) ^ bgx; |
Marek Vasut | 118959f | 2013-07-30 23:37:59 +0200 | [diff] [blame] | 425 | |
| 426 | if (VIDEO_FONT_WIDTH == 4) |
| 427 | continue; |
| 428 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 429 | ((u32 *) dest)[3] = |
| 430 | (video_font_draw_table24[bits & 15][0] |
| 431 | & eorx) ^ bgx; |
| 432 | ((u32 *) dest)[4] = |
| 433 | (video_font_draw_table24[bits & 15][1] |
| 434 | & eorx) ^ bgx; |
| 435 | ((u32 *) dest)[5] = |
| 436 | (video_font_draw_table24[bits & 15][2] |
| 437 | & eorx) ^ bgx; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 438 | } |
| 439 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; |
| 440 | s++; |
| 441 | } |
| 442 | break; |
wdenk | 57b2d80 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 443 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 444 | } |
| 445 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 446 | static inline void video_drawstring(int xx, int yy, unsigned char *s) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 447 | { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 448 | video_drawchars(xx, yy, s, strlen((char *) s)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 449 | } |
| 450 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 451 | static void video_putchar(int xx, int yy, unsigned char c) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 452 | { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 453 | video_drawchars(xx, yy + video_logo_height, &c, 1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 454 | } |
| 455 | |
Simon Glass | f406a1b | 2015-10-18 21:17:18 -0600 | [diff] [blame] | 456 | #if defined(CONFIG_VIDEO_SW_CURSOR) |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 457 | static void video_set_cursor(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 458 | { |
Gabe Black | 12874de | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 459 | if (cursor_state) |
| 460 | console_cursor(0); |
| 461 | console_cursor(1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 462 | } |
Gabe Black | 12874de | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 463 | |
Anatolij Gustschin | 814d0e1 | 2011-12-07 03:58:10 +0000 | [diff] [blame] | 464 | static void video_invertchar(int xx, int yy) |
| 465 | { |
| 466 | int firstx = xx * VIDEO_PIXEL_SIZE; |
| 467 | int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE; |
| 468 | int firsty = yy * VIDEO_LINE_LEN; |
| 469 | int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN; |
| 470 | int x, y; |
| 471 | for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) { |
| 472 | for (x = firstx; x < lastx; x++) { |
| 473 | u8 *dest = (u8 *)(video_fb_address) + x + y; |
| 474 | *dest = ~*dest; |
| 475 | } |
| 476 | } |
| 477 | } |
Gabe Black | 12874de | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 478 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 479 | void console_cursor(int state) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 480 | { |
Gabe Black | 12874de | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 481 | if (cursor_state != state) { |
| 482 | if (cursor_state) { |
| 483 | /* turn off the cursor */ |
| 484 | video_invertchar(old_col * VIDEO_FONT_WIDTH, |
| 485 | old_row * VIDEO_FONT_HEIGHT + |
| 486 | video_logo_height); |
| 487 | } else { |
| 488 | /* turn off the cursor and record where it is */ |
| 489 | video_invertchar(console_col * VIDEO_FONT_WIDTH, |
| 490 | console_row * VIDEO_FONT_HEIGHT + |
| 491 | video_logo_height); |
| 492 | old_col = console_col; |
| 493 | old_row = console_row; |
| 494 | } |
| 495 | cursor_state = state; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 496 | } |
Eric Nelson | 5414242 | 2013-05-06 14:27:28 +0200 | [diff] [blame] | 497 | if (cfb_do_flush_cache) |
| 498 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 499 | } |
| 500 | #endif |
| 501 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 502 | #ifndef VIDEO_HW_RECTFILL |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 503 | static void memsetl(int *p, int c, int v) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 504 | { |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 505 | while (c--) |
| 506 | *(p++) = v; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 507 | } |
| 508 | #endif |
| 509 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 510 | #ifndef VIDEO_HW_BITBLT |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 511 | static void memcpyl(int *d, int *s, int c) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 512 | { |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 513 | while (c--) |
| 514 | *(d++) = *(s++); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 515 | } |
| 516 | #endif |
| 517 | |
Pali Rohár | 1665861 | 2012-04-28 07:26:44 +0000 | [diff] [blame] | 518 | static void console_clear_line(int line, int begin, int end) |
| 519 | { |
| 520 | #ifdef VIDEO_HW_RECTFILL |
| 521 | video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */ |
| 522 | VIDEO_FONT_WIDTH * begin, /* dest pos x */ |
| 523 | video_logo_height + |
| 524 | VIDEO_FONT_HEIGHT * line, /* dest pos y */ |
| 525 | VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */ |
| 526 | VIDEO_FONT_HEIGHT, /* frame height */ |
| 527 | bgx /* fill color */ |
| 528 | ); |
| 529 | #else |
| 530 | if (begin == 0 && (end + 1) == CONSOLE_COLS) { |
| 531 | memsetl(CONSOLE_ROW_FIRST + |
| 532 | CONSOLE_ROW_SIZE * line, /* offset of row */ |
| 533 | CONSOLE_ROW_SIZE >> 2, /* length of row */ |
| 534 | bgx /* fill color */ |
| 535 | ); |
| 536 | } else { |
| 537 | void *offset; |
| 538 | int i, size; |
| 539 | |
| 540 | offset = CONSOLE_ROW_FIRST + |
| 541 | CONSOLE_ROW_SIZE * line + /* offset of row */ |
| 542 | VIDEO_FONT_WIDTH * |
| 543 | VIDEO_PIXEL_SIZE * begin; /* offset of col */ |
| 544 | size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1); |
| 545 | size >>= 2; /* length to end for memsetl() */ |
| 546 | /* fill at col offset of i'th line using bgx as fill color */ |
| 547 | for (i = 0; i < VIDEO_FONT_HEIGHT; i++) |
| 548 | memsetl(offset + i * VIDEO_LINE_LEN, size, bgx); |
| 549 | } |
| 550 | #endif |
| 551 | } |
| 552 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 553 | static void console_scrollup(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 554 | { |
Simon Glass | 6ceb7f0 | 2015-01-01 16:17:57 -0700 | [diff] [blame] | 555 | const int rows = CONFIG_CONSOLE_SCROLL_LINES; |
| 556 | int i; |
| 557 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 558 | /* copy up rows ignoring the first one */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 559 | |
| 560 | #ifdef VIDEO_HW_BITBLT |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 561 | video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */ |
| 562 | 0, /* source pos x */ |
| 563 | video_logo_height + |
Simon Glass | 6ceb7f0 | 2015-01-01 16:17:57 -0700 | [diff] [blame] | 564 | VIDEO_FONT_HEIGHT * rows, /* source pos y */ |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 565 | 0, /* dest pos x */ |
| 566 | video_logo_height, /* dest pos y */ |
| 567 | VIDEO_VISIBLE_COLS, /* frame width */ |
| 568 | VIDEO_VISIBLE_ROWS |
| 569 | - video_logo_height |
Simon Glass | 6ceb7f0 | 2015-01-01 16:17:57 -0700 | [diff] [blame] | 570 | - VIDEO_FONT_HEIGHT * rows /* frame height */ |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 571 | ); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 572 | #else |
Simon Glass | 6ceb7f0 | 2015-01-01 16:17:57 -0700 | [diff] [blame] | 573 | memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE, |
| 574 | (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 575 | #endif |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 576 | /* clear the last one */ |
Simon Glass | 6ceb7f0 | 2015-01-01 16:17:57 -0700 | [diff] [blame] | 577 | for (i = 1; i <= rows; i++) |
| 578 | console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1); |
| 579 | |
| 580 | /* Decrement row number */ |
| 581 | console_row -= rows; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 582 | } |
| 583 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 584 | static void console_back(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 585 | { |
Timur Tabi | be0c74e | 2010-08-27 15:45:47 -0500 | [diff] [blame] | 586 | console_col--; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 587 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 588 | if (console_col < 0) { |
| 589 | console_col = CONSOLE_COLS - 1; |
| 590 | console_row--; |
| 591 | if (console_row < 0) |
| 592 | console_row = 0; |
| 593 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 594 | } |
| 595 | |
Pali Rohár | 4a57da3 | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 596 | #ifdef CONFIG_CFB_CONSOLE_ANSI |
| 597 | |
| 598 | static void console_clear(void) |
| 599 | { |
| 600 | #ifdef VIDEO_HW_RECTFILL |
| 601 | video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */ |
| 602 | 0, /* dest pos x */ |
| 603 | video_logo_height, /* dest pos y */ |
| 604 | VIDEO_VISIBLE_COLS, /* frame width */ |
| 605 | VIDEO_VISIBLE_ROWS, /* frame height */ |
| 606 | bgx /* fill color */ |
| 607 | ); |
| 608 | #else |
| 609 | memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx); |
| 610 | #endif |
| 611 | } |
| 612 | |
| 613 | static void console_cursor_fix(void) |
| 614 | { |
| 615 | if (console_row < 0) |
| 616 | console_row = 0; |
| 617 | if (console_row >= CONSOLE_ROWS) |
| 618 | console_row = CONSOLE_ROWS - 1; |
| 619 | if (console_col < 0) |
| 620 | console_col = 0; |
| 621 | if (console_col >= CONSOLE_COLS) |
| 622 | console_col = CONSOLE_COLS - 1; |
| 623 | } |
| 624 | |
| 625 | static void console_cursor_up(int n) |
| 626 | { |
| 627 | console_row -= n; |
| 628 | console_cursor_fix(); |
| 629 | } |
| 630 | |
| 631 | static void console_cursor_down(int n) |
| 632 | { |
| 633 | console_row += n; |
| 634 | console_cursor_fix(); |
| 635 | } |
| 636 | |
| 637 | static void console_cursor_left(int n) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 638 | { |
Pali Rohár | 4a57da3 | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 639 | console_col -= n; |
| 640 | console_cursor_fix(); |
| 641 | } |
| 642 | |
| 643 | static void console_cursor_right(int n) |
| 644 | { |
| 645 | console_col += n; |
| 646 | console_cursor_fix(); |
| 647 | } |
| 648 | |
| 649 | static void console_cursor_set_position(int row, int col) |
| 650 | { |
| 651 | if (console_row != -1) |
| 652 | console_row = row; |
| 653 | if (console_col != -1) |
| 654 | console_col = col; |
| 655 | console_cursor_fix(); |
| 656 | } |
| 657 | |
| 658 | static void console_previousline(int n) |
| 659 | { |
| 660 | /* FIXME: also scroll terminal ? */ |
| 661 | console_row -= n; |
| 662 | console_cursor_fix(); |
| 663 | } |
| 664 | |
| 665 | static void console_swap_colors(void) |
| 666 | { |
| 667 | eorx = fgx; |
| 668 | fgx = bgx; |
| 669 | bgx = eorx; |
| 670 | eorx = fgx ^ bgx; |
| 671 | } |
| 672 | |
| 673 | static inline int console_cursor_is_visible(void) |
| 674 | { |
| 675 | return !ansi_cursor_hidden; |
| 676 | } |
| 677 | #else |
| 678 | static inline int console_cursor_is_visible(void) |
| 679 | { |
| 680 | return 1; |
| 681 | } |
| 682 | #endif |
| 683 | |
| 684 | static void console_newline(int n) |
| 685 | { |
| 686 | console_row += n; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 687 | console_col = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 688 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 689 | /* Check if we need to scroll the terminal */ |
| 690 | if (console_row >= CONSOLE_ROWS) { |
| 691 | /* Scroll everything up */ |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 692 | console_scrollup(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 693 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 694 | } |
| 695 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 696 | static void console_cr(void) |
Anatolij Gustschin | 938db91 | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 697 | { |
Timur Tabi | be0c74e | 2010-08-27 15:45:47 -0500 | [diff] [blame] | 698 | console_col = 0; |
Anatolij Gustschin | 938db91 | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 699 | } |
| 700 | |
Pali Rohár | 4a57da3 | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 701 | static void parse_putc(const char c) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 702 | { |
Anatolij Gustschin | 938db91 | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 703 | static int nl = 1; |
| 704 | |
Pali Rohár | 4a57da3 | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 705 | if (console_cursor_is_visible()) |
| 706 | CURSOR_OFF; |
Gabe Black | 12874de | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 707 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 708 | switch (c) { |
Anatolij Gustschin | 938db91 | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 709 | case 13: /* back to first column */ |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 710 | console_cr(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 711 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 712 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 713 | case '\n': /* next line */ |
Heinrich Schuchardt | d6ef669 | 2018-03-18 14:24:39 +0100 | [diff] [blame] | 714 | if (console_col || nl) |
Pali Rohár | 4a57da3 | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 715 | console_newline(1); |
Anatolij Gustschin | 938db91 | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 716 | nl = 1; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 717 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 718 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 719 | case 9: /* tab 8 */ |
Timur Tabi | be0c74e | 2010-08-27 15:45:47 -0500 | [diff] [blame] | 720 | console_col |= 0x0008; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 721 | console_col &= ~0x0007; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 722 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 723 | if (console_col >= CONSOLE_COLS) |
Pali Rohár | 4a57da3 | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 724 | console_newline(1); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 725 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 726 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 727 | case 8: /* backspace */ |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 728 | console_back(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 729 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 730 | |
Pali Rohár | 9d735b6 | 2012-04-28 07:26:47 +0000 | [diff] [blame] | 731 | case 7: /* bell */ |
| 732 | break; /* ignored */ |
| 733 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 734 | default: /* draw the char */ |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 735 | video_putchar(console_col * VIDEO_FONT_WIDTH, |
| 736 | console_row * VIDEO_FONT_HEIGHT, c); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 737 | console_col++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 738 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 739 | /* check for newline */ |
Anatolij Gustschin | 938db91 | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 740 | if (console_col >= CONSOLE_COLS) { |
Pali Rohár | 4a57da3 | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 741 | console_newline(1); |
Anatolij Gustschin | 938db91 | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 742 | nl = 0; |
| 743 | } |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 744 | } |
Pali Rohár | 4a57da3 | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 745 | |
| 746 | if (console_cursor_is_visible()) |
| 747 | CURSOR_SET; |
| 748 | } |
| 749 | |
Simon Glass | 88ecb9b | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 750 | static void cfb_video_putc(struct stdio_dev *dev, const char c) |
Pali Rohár | 4a57da3 | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 751 | { |
| 752 | #ifdef CONFIG_CFB_CONSOLE_ANSI |
| 753 | int i; |
| 754 | |
| 755 | if (c == 27) { |
| 756 | for (i = 0; i < ansi_buf_size; ++i) |
| 757 | parse_putc(ansi_buf[i]); |
| 758 | ansi_buf[0] = 27; |
| 759 | ansi_buf_size = 1; |
| 760 | return; |
| 761 | } |
| 762 | |
| 763 | if (ansi_buf_size > 0) { |
| 764 | /* |
| 765 | * 0 - ESC |
| 766 | * 1 - [ |
| 767 | * 2 - num1 |
| 768 | * 3 - .. |
| 769 | * 4 - ; |
| 770 | * 5 - num2 |
| 771 | * 6 - .. |
| 772 | * - cchar |
| 773 | */ |
| 774 | int next = 0; |
| 775 | |
| 776 | int flush = 0; |
| 777 | int fail = 0; |
| 778 | |
| 779 | int num1 = 0; |
| 780 | int num2 = 0; |
| 781 | int cchar = 0; |
| 782 | |
| 783 | ansi_buf[ansi_buf_size++] = c; |
| 784 | |
| 785 | if (ansi_buf_size >= sizeof(ansi_buf)) |
| 786 | fail = 1; |
| 787 | |
| 788 | for (i = 0; i < ansi_buf_size; ++i) { |
| 789 | if (fail) |
| 790 | break; |
| 791 | |
| 792 | switch (next) { |
| 793 | case 0: |
| 794 | if (ansi_buf[i] == 27) |
| 795 | next = 1; |
| 796 | else |
| 797 | fail = 1; |
| 798 | break; |
| 799 | |
| 800 | case 1: |
| 801 | if (ansi_buf[i] == '[') |
| 802 | next = 2; |
| 803 | else |
| 804 | fail = 1; |
| 805 | break; |
| 806 | |
| 807 | case 2: |
| 808 | if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') { |
| 809 | num1 = ansi_buf[i]-'0'; |
| 810 | next = 3; |
| 811 | } else if (ansi_buf[i] != '?') { |
| 812 | --i; |
| 813 | num1 = 1; |
| 814 | next = 4; |
| 815 | } |
| 816 | break; |
| 817 | |
| 818 | case 3: |
| 819 | if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') { |
| 820 | num1 *= 10; |
| 821 | num1 += ansi_buf[i]-'0'; |
| 822 | } else { |
| 823 | --i; |
| 824 | next = 4; |
| 825 | } |
| 826 | break; |
| 827 | |
| 828 | case 4: |
| 829 | if (ansi_buf[i] != ';') { |
| 830 | --i; |
| 831 | next = 7; |
| 832 | } else |
| 833 | next = 5; |
| 834 | break; |
| 835 | |
| 836 | case 5: |
| 837 | if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') { |
| 838 | num2 = ansi_buf[i]-'0'; |
| 839 | next = 6; |
| 840 | } else |
| 841 | fail = 1; |
| 842 | break; |
| 843 | |
| 844 | case 6: |
| 845 | if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') { |
| 846 | num2 *= 10; |
| 847 | num2 += ansi_buf[i]-'0'; |
| 848 | } else { |
| 849 | --i; |
| 850 | next = 7; |
| 851 | } |
| 852 | break; |
| 853 | |
| 854 | case 7: |
| 855 | if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H') |
| 856 | || ansi_buf[i] == 'J' |
| 857 | || ansi_buf[i] == 'K' |
| 858 | || ansi_buf[i] == 'h' |
| 859 | || ansi_buf[i] == 'l' |
| 860 | || ansi_buf[i] == 'm') { |
| 861 | cchar = ansi_buf[i]; |
| 862 | flush = 1; |
| 863 | } else |
| 864 | fail = 1; |
| 865 | break; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | if (fail) { |
| 870 | for (i = 0; i < ansi_buf_size; ++i) |
| 871 | parse_putc(ansi_buf[i]); |
| 872 | ansi_buf_size = 0; |
| 873 | return; |
| 874 | } |
| 875 | |
| 876 | if (flush) { |
| 877 | if (!ansi_cursor_hidden) |
| 878 | CURSOR_OFF; |
| 879 | ansi_buf_size = 0; |
| 880 | switch (cchar) { |
| 881 | case 'A': |
| 882 | /* move cursor num1 rows up */ |
| 883 | console_cursor_up(num1); |
| 884 | break; |
| 885 | case 'B': |
| 886 | /* move cursor num1 rows down */ |
| 887 | console_cursor_down(num1); |
| 888 | break; |
| 889 | case 'C': |
| 890 | /* move cursor num1 columns forward */ |
| 891 | console_cursor_right(num1); |
| 892 | break; |
| 893 | case 'D': |
| 894 | /* move cursor num1 columns back */ |
| 895 | console_cursor_left(num1); |
| 896 | break; |
| 897 | case 'E': |
| 898 | /* move cursor num1 rows up at begin of row */ |
| 899 | console_previousline(num1); |
| 900 | break; |
| 901 | case 'F': |
| 902 | /* move cursor num1 rows down at begin of row */ |
| 903 | console_newline(num1); |
| 904 | break; |
| 905 | case 'G': |
| 906 | /* move cursor to column num1 */ |
| 907 | console_cursor_set_position(-1, num1-1); |
| 908 | break; |
| 909 | case 'H': |
| 910 | /* move cursor to row num1, column num2 */ |
| 911 | console_cursor_set_position(num1-1, num2-1); |
| 912 | break; |
| 913 | case 'J': |
| 914 | /* clear console and move cursor to 0, 0 */ |
| 915 | console_clear(); |
| 916 | console_cursor_set_position(0, 0); |
| 917 | break; |
| 918 | case 'K': |
| 919 | /* clear line */ |
| 920 | if (num1 == 0) |
| 921 | console_clear_line(console_row, |
| 922 | console_col, |
| 923 | CONSOLE_COLS-1); |
| 924 | else if (num1 == 1) |
| 925 | console_clear_line(console_row, |
| 926 | 0, console_col); |
| 927 | else |
| 928 | console_clear_line(console_row, |
| 929 | 0, CONSOLE_COLS-1); |
| 930 | break; |
| 931 | case 'h': |
| 932 | ansi_cursor_hidden = 0; |
| 933 | break; |
| 934 | case 'l': |
| 935 | ansi_cursor_hidden = 1; |
| 936 | break; |
| 937 | case 'm': |
| 938 | if (num1 == 0) { /* reset swapped colors */ |
| 939 | if (ansi_colors_need_revert) { |
| 940 | console_swap_colors(); |
| 941 | ansi_colors_need_revert = 0; |
| 942 | } |
| 943 | } else if (num1 == 7) { /* once swap colors */ |
| 944 | if (!ansi_colors_need_revert) { |
| 945 | console_swap_colors(); |
| 946 | ansi_colors_need_revert = 1; |
| 947 | } |
| 948 | } |
| 949 | break; |
| 950 | } |
| 951 | if (!ansi_cursor_hidden) |
| 952 | CURSOR_SET; |
| 953 | } |
| 954 | } else { |
| 955 | parse_putc(c); |
| 956 | } |
| 957 | #else |
| 958 | parse_putc(c); |
| 959 | #endif |
Eric Nelson | 5414242 | 2013-05-06 14:27:28 +0200 | [diff] [blame] | 960 | if (cfb_do_flush_cache) |
| 961 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); |
Timur Tabi | be0c74e | 2010-08-27 15:45:47 -0500 | [diff] [blame] | 962 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 963 | |
Simon Glass | 88ecb9b | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 964 | static void cfb_video_puts(struct stdio_dev *dev, const char *s) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 965 | { |
Soeren Moch | bd9c131 | 2014-10-24 16:33:30 +0200 | [diff] [blame] | 966 | int flush = cfb_do_flush_cache; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 967 | int count = strlen(s); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 968 | |
Soeren Moch | bd9c131 | 2014-10-24 16:33:30 +0200 | [diff] [blame] | 969 | /* temporarily disable cache flush */ |
| 970 | cfb_do_flush_cache = 0; |
| 971 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 972 | while (count--) |
Simon Glass | 88ecb9b | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 973 | cfb_video_putc(dev, *s++); |
Soeren Moch | bd9c131 | 2014-10-24 16:33:30 +0200 | [diff] [blame] | 974 | |
| 975 | if (flush) { |
| 976 | cfb_do_flush_cache = flush; |
| 977 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); |
| 978 | } |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 979 | } |
| 980 | |
Anatolij Gustschin | a043c34 | 2010-05-01 22:21:09 +0200 | [diff] [blame] | 981 | /* |
| 982 | * Do not enforce drivers (or board code) to provide empty |
| 983 | * video_set_lut() if they do not support 8 bpp format. |
| 984 | * Implement weak default function instead. |
| 985 | */ |
Jeroen Hofstee | f7ae3ed | 2014-10-08 22:57:30 +0200 | [diff] [blame] | 986 | __weak void video_set_lut(unsigned int index, unsigned char r, |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 987 | unsigned char g, unsigned char b) |
Anatolij Gustschin | a043c34 | 2010-05-01 22:21:09 +0200 | [diff] [blame] | 988 | { |
| 989 | } |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 990 | |
Jon Loeliger | b1d408a | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 991 | #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 992 | |
| 993 | #define FILL_8BIT_332RGB(r,g,b) { \ |
| 994 | *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \ |
| 995 | fb ++; \ |
| 996 | } |
| 997 | |
| 998 | #define FILL_15BIT_555RGB(r,g,b) { \ |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 999 | *(unsigned short *)fb = \ |
| 1000 | SWAP16((unsigned short)(((r>>3)<<10) | \ |
| 1001 | ((g>>3)<<5) | \ |
| 1002 | (b>>3))); \ |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1003 | fb += 2; \ |
| 1004 | } |
| 1005 | |
| 1006 | #define FILL_16BIT_565RGB(r,g,b) { \ |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1007 | *(unsigned short *)fb = \ |
| 1008 | SWAP16((unsigned short)((((r)>>3)<<11)| \ |
| 1009 | (((g)>>2)<<5) | \ |
| 1010 | ((b)>>3))); \ |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1011 | fb += 2; \ |
| 1012 | } |
| 1013 | |
| 1014 | #define FILL_32BIT_X888RGB(r,g,b) { \ |
Andre Przywara | cd7b1ee | 2017-03-06 01:13:38 +0000 | [diff] [blame] | 1015 | *(u32 *)fb = \ |
| 1016 | SWAP32((unsigned int)(((r<<16) | \ |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1017 | (g<<8) | \ |
| 1018 | b))); \ |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1019 | fb += 4; \ |
| 1020 | } |
| 1021 | |
| 1022 | #ifdef VIDEO_FB_LITTLE_ENDIAN |
| 1023 | #define FILL_24BIT_888RGB(r,g,b) { \ |
| 1024 | fb[0] = b; \ |
| 1025 | fb[1] = g; \ |
| 1026 | fb[2] = r; \ |
| 1027 | fb += 3; \ |
| 1028 | } |
| 1029 | #else |
| 1030 | #define FILL_24BIT_888RGB(r,g,b) { \ |
| 1031 | fb[0] = r; \ |
| 1032 | fb[1] = g; \ |
| 1033 | fb[2] = b; \ |
| 1034 | fb += 3; \ |
| 1035 | } |
| 1036 | #endif |
| 1037 | |
Anatolij Gustschin | 18b8036 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1038 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1039 | static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b) |
Anatolij Gustschin | 18b8036 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1040 | { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1041 | ushort *dst = (ushort *) fb; |
| 1042 | ushort color = (ushort) (((r >> 3) << 10) | |
| 1043 | ((g >> 3) << 5) | |
| 1044 | (b >> 3)); |
Anatolij Gustschin | 18b8036 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1045 | if (x & 1) |
| 1046 | *(--dst) = color; |
| 1047 | else |
| 1048 | *(++dst) = color; |
| 1049 | } |
| 1050 | #endif |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1051 | |
| 1052 | /* |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1053 | * RLE8 bitmap support |
| 1054 | */ |
| 1055 | |
| 1056 | #ifdef CONFIG_VIDEO_BMP_RLE8 |
| 1057 | /* Pre-calculated color table entry */ |
| 1058 | struct palette { |
| 1059 | union { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1060 | unsigned short w; /* word */ |
| 1061 | unsigned int dw; /* double word */ |
| 1062 | } ce; /* color entry */ |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1063 | }; |
| 1064 | |
| 1065 | /* |
| 1066 | * Helper to draw encoded/unencoded run. |
| 1067 | */ |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1068 | static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p, |
| 1069 | int cnt, int enc) |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1070 | { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1071 | ulong addr = (ulong) *fb; |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1072 | int *off; |
| 1073 | int enc_off = 1; |
| 1074 | int i; |
| 1075 | |
| 1076 | /* |
| 1077 | * Setup offset of the color index in the bitmap. |
| 1078 | * Color index of encoded run is at offset 1. |
| 1079 | */ |
| 1080 | off = enc ? &enc_off : &i; |
| 1081 | |
| 1082 | switch (VIDEO_DATA_FORMAT) { |
| 1083 | case GDF__8BIT_INDEX: |
| 1084 | for (i = 0; i < cnt; i++) |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1085 | *(unsigned char *) addr++ = bm[*off]; |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1086 | break; |
| 1087 | case GDF_15BIT_555RGB: |
| 1088 | case GDF_16BIT_565RGB: |
| 1089 | /* differences handled while pre-calculating palette */ |
| 1090 | for (i = 0; i < cnt; i++) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1091 | *(unsigned short *) addr = p[bm[*off]].ce.w; |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1092 | addr += 2; |
| 1093 | } |
| 1094 | break; |
| 1095 | case GDF_32BIT_X888RGB: |
| 1096 | for (i = 0; i < cnt; i++) { |
Andre Przywara | cd7b1ee | 2017-03-06 01:13:38 +0000 | [diff] [blame] | 1097 | *(u32 *) addr = p[bm[*off]].ce.dw; |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1098 | addr += 4; |
| 1099 | } |
| 1100 | break; |
| 1101 | } |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1102 | *fb = (uchar *) addr; /* return modified address */ |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1103 | } |
| 1104 | |
Simon Glass | 92e1f85 | 2015-05-13 07:02:27 -0600 | [diff] [blame] | 1105 | static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff, |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1106 | int width, int height) |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1107 | { |
| 1108 | unsigned char *bm; |
| 1109 | unsigned char *fbp; |
| 1110 | unsigned int cnt, runlen; |
| 1111 | int decode = 1; |
| 1112 | int x, y, bpp, i, ncolors; |
| 1113 | struct palette p[256]; |
Simon Glass | 92e1f85 | 2015-05-13 07:02:27 -0600 | [diff] [blame] | 1114 | struct bmp_color_table_entry cte; |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1115 | int green_shift, red_off; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1116 | int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS; |
Anatolij Gustschin | ce5f8df | 2011-02-21 21:33:29 +0100 | [diff] [blame] | 1117 | int pixels = 0; |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1118 | |
| 1119 | x = 0; |
| 1120 | y = __le32_to_cpu(img->header.height) - 1; |
| 1121 | ncolors = __le32_to_cpu(img->header.colors_used); |
| 1122 | bpp = VIDEO_PIXEL_SIZE; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1123 | fbp = (unsigned char *) ((unsigned int) video_fb_address + |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1124 | (y + yoff) * VIDEO_LINE_LEN + |
| 1125 | xoff * bpp); |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1126 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1127 | bm = (uchar *) img + __le32_to_cpu(img->header.data_offset); |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1128 | |
| 1129 | /* pre-calculate and setup palette */ |
| 1130 | switch (VIDEO_DATA_FORMAT) { |
| 1131 | case GDF__8BIT_INDEX: |
| 1132 | for (i = 0; i < ncolors; i++) { |
| 1133 | cte = img->color_table[i]; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1134 | video_set_lut(i, cte.red, cte.green, cte.blue); |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1135 | } |
| 1136 | break; |
| 1137 | case GDF_15BIT_555RGB: |
| 1138 | case GDF_16BIT_565RGB: |
| 1139 | if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) { |
| 1140 | green_shift = 3; |
| 1141 | red_off = 10; |
| 1142 | } else { |
| 1143 | green_shift = 2; |
| 1144 | red_off = 11; |
| 1145 | } |
| 1146 | for (i = 0; i < ncolors; i++) { |
| 1147 | cte = img->color_table[i]; |
| 1148 | p[i].ce.w = SWAP16((unsigned short) |
| 1149 | (((cte.red >> 3) << red_off) | |
| 1150 | ((cte.green >> green_shift) << 5) | |
| 1151 | cte.blue >> 3)); |
| 1152 | } |
| 1153 | break; |
| 1154 | case GDF_32BIT_X888RGB: |
| 1155 | for (i = 0; i < ncolors; i++) { |
| 1156 | cte = img->color_table[i]; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1157 | p[i].ce.dw = SWAP32((cte.red << 16) | |
| 1158 | (cte.green << 8) | |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1159 | cte.blue); |
| 1160 | } |
| 1161 | break; |
| 1162 | default: |
| 1163 | printf("RLE Bitmap unsupported in video mode 0x%x\n", |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1164 | VIDEO_DATA_FORMAT); |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1165 | return -1; |
| 1166 | } |
| 1167 | |
| 1168 | while (decode) { |
| 1169 | switch (bm[0]) { |
| 1170 | case 0: |
| 1171 | switch (bm[1]) { |
| 1172 | case 0: |
| 1173 | /* scan line end marker */ |
| 1174 | bm += 2; |
| 1175 | x = 0; |
| 1176 | y--; |
| 1177 | fbp = (unsigned char *) |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1178 | ((unsigned int) video_fb_address + |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1179 | (y + yoff) * VIDEO_LINE_LEN + |
| 1180 | xoff * bpp); |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1181 | continue; |
| 1182 | case 1: |
| 1183 | /* end of bitmap data marker */ |
| 1184 | decode = 0; |
| 1185 | break; |
| 1186 | case 2: |
| 1187 | /* run offset marker */ |
| 1188 | x += bm[2]; |
| 1189 | y -= bm[3]; |
| 1190 | fbp = (unsigned char *) |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1191 | ((unsigned int) video_fb_address + |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1192 | (y + yoff) * VIDEO_LINE_LEN + |
| 1193 | xoff * bpp); |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1194 | bm += 4; |
| 1195 | break; |
| 1196 | default: |
| 1197 | /* unencoded run */ |
| 1198 | cnt = bm[1]; |
| 1199 | runlen = cnt; |
Anatolij Gustschin | ce5f8df | 2011-02-21 21:33:29 +0100 | [diff] [blame] | 1200 | pixels += cnt; |
| 1201 | if (pixels > limit) |
| 1202 | goto error; |
| 1203 | |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1204 | bm += 2; |
| 1205 | if (y < height) { |
| 1206 | if (x >= width) { |
| 1207 | x += runlen; |
| 1208 | goto next_run; |
| 1209 | } |
| 1210 | if (x + runlen > width) |
| 1211 | cnt = width - x; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1212 | draw_bitmap(&fbp, bm, p, cnt, 0); |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1213 | x += runlen; |
| 1214 | } |
| 1215 | next_run: |
| 1216 | bm += runlen; |
| 1217 | if (runlen & 1) |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1218 | bm++; /* 0 padding if length is odd */ |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1219 | } |
| 1220 | break; |
| 1221 | default: |
| 1222 | /* encoded run */ |
Anatolij Gustschin | ce5f8df | 2011-02-21 21:33:29 +0100 | [diff] [blame] | 1223 | cnt = bm[0]; |
| 1224 | runlen = cnt; |
| 1225 | pixels += cnt; |
| 1226 | if (pixels > limit) |
| 1227 | goto error; |
| 1228 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1229 | if (y < height) { /* only draw into visible area */ |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1230 | if (x >= width) { |
| 1231 | x += runlen; |
| 1232 | bm += 2; |
| 1233 | continue; |
| 1234 | } |
| 1235 | if (x + runlen > width) |
| 1236 | cnt = width - x; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1237 | draw_bitmap(&fbp, bm, p, cnt, 1); |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1238 | x += runlen; |
| 1239 | } |
| 1240 | bm += 2; |
| 1241 | break; |
| 1242 | } |
| 1243 | } |
Sébastien Szymanski | a14dbb5 | 2018-09-10 09:58:58 +0200 | [diff] [blame] | 1244 | |
| 1245 | if (cfb_do_flush_cache) |
| 1246 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); |
| 1247 | |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1248 | return 0; |
Anatolij Gustschin | ce5f8df | 2011-02-21 21:33:29 +0100 | [diff] [blame] | 1249 | error: |
| 1250 | printf("Error: Too much encoded pixel data, validate your bitmap\n"); |
| 1251 | return -1; |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1252 | } |
| 1253 | #endif |
| 1254 | |
| 1255 | /* |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1256 | * Display the BMP file located at address bmp_image. |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1257 | */ |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1258 | int video_display_bitmap(ulong bmp_image, int x, int y) |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1259 | { |
| 1260 | ushort xcount, ycount; |
| 1261 | uchar *fb; |
Simon Glass | 92e1f85 | 2015-05-13 07:02:27 -0600 | [diff] [blame] | 1262 | struct bmp_image *bmp = (struct bmp_image *)bmp_image; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1263 | uchar *bmap; |
| 1264 | ushort padded_line; |
| 1265 | unsigned long width, height, bpp; |
| 1266 | unsigned colors; |
| 1267 | unsigned long compression; |
Simon Glass | 92e1f85 | 2015-05-13 07:02:27 -0600 | [diff] [blame] | 1268 | struct bmp_color_table_entry cte; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1269 | |
Stefan Roese | d9d9774 | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1270 | #ifdef CONFIG_VIDEO_BMP_GZIP |
| 1271 | unsigned char *dst = NULL; |
| 1272 | ulong len; |
| 1273 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1274 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1275 | WATCHDOG_RESET(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1276 | |
| 1277 | if (!((bmp->header.signature[0] == 'B') && |
| 1278 | (bmp->header.signature[1] == 'M'))) { |
Stefan Roese | d9d9774 | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1279 | |
| 1280 | #ifdef CONFIG_VIDEO_BMP_GZIP |
| 1281 | /* |
| 1282 | * Could be a gzipped bmp image, try to decrompress... |
| 1283 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1284 | len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE; |
| 1285 | dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE); |
Stefan Roese | 13b9369 | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 1286 | if (dst == NULL) { |
| 1287 | printf("Error: malloc in gunzip failed!\n"); |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1288 | return 1; |
Stefan Roese | 13b9369 | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 1289 | } |
Eric Nelson | fba7087 | 2014-03-08 07:55:52 -0700 | [diff] [blame] | 1290 | /* |
| 1291 | * NB: we need to force offset of +2 |
| 1292 | * See doc/README.displaying-bmps |
| 1293 | */ |
| 1294 | if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2, |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1295 | (uchar *) bmp_image, |
| 1296 | &len) != 0) { |
| 1297 | printf("Error: no valid bmp or bmp.gz image at %lx\n", |
| 1298 | bmp_image); |
Stefan Roese | d9d9774 | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1299 | free(dst); |
| 1300 | return 1; |
| 1301 | } |
Jean-Christophe PLAGNIOL-VILLARD | 0383694 | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1302 | if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1303 | printf("Image could be truncated " |
| 1304 | "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n"); |
Stefan Roese | 13b9369 | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 1305 | } |
Stefan Roese | d9d9774 | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1306 | |
| 1307 | /* |
| 1308 | * Set addr to decompressed image |
| 1309 | */ |
Simon Glass | 92e1f85 | 2015-05-13 07:02:27 -0600 | [diff] [blame] | 1310 | bmp = (struct bmp_image *)(dst+2); |
Stefan Roese | d9d9774 | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1311 | |
| 1312 | if (!((bmp->header.signature[0] == 'B') && |
| 1313 | (bmp->header.signature[1] == 'M'))) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1314 | printf("Error: no valid bmp.gz image at %lx\n", |
| 1315 | bmp_image); |
Matthias Fuchs | a7c5a59 | 2008-04-21 11:19:04 +0200 | [diff] [blame] | 1316 | free(dst); |
Stefan Roese | d9d9774 | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1317 | return 1; |
| 1318 | } |
| 1319 | #else |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1320 | printf("Error: no valid bmp image at %lx\n", bmp_image); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1321 | return 1; |
Stefan Roese | d9d9774 | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1322 | #endif /* CONFIG_VIDEO_BMP_GZIP */ |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1323 | } |
| 1324 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1325 | width = le32_to_cpu(bmp->header.width); |
| 1326 | height = le32_to_cpu(bmp->header.height); |
| 1327 | bpp = le16_to_cpu(bmp->header.bit_count); |
| 1328 | colors = le32_to_cpu(bmp->header.colors_used); |
| 1329 | compression = le32_to_cpu(bmp->header.compression); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1330 | |
Marek Vasut | 2eb9a49 | 2011-10-21 14:17:04 +0000 | [diff] [blame] | 1331 | debug("Display-bmp: %ld x %ld with %d colors\n", |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1332 | width, height, colors); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1333 | |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1334 | if (compression != BMP_BI_RGB |
| 1335 | #ifdef CONFIG_VIDEO_BMP_RLE8 |
| 1336 | && compression != BMP_BI_RLE8 |
| 1337 | #endif |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1338 | ) { |
| 1339 | printf("Error: compression type %ld not supported\n", |
| 1340 | compression); |
Matthias Fuchs | a7c5a59 | 2008-04-21 11:19:04 +0200 | [diff] [blame] | 1341 | #ifdef CONFIG_VIDEO_BMP_GZIP |
| 1342 | if (dst) |
| 1343 | free(dst); |
| 1344 | #endif |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1345 | return 1; |
| 1346 | } |
| 1347 | |
| 1348 | padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3; |
| 1349 | |
Matthias Weisser | 5388418 | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1350 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |
| 1351 | if (x == BMP_ALIGN_CENTER) |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1352 | x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2); |
Matthias Weisser | 5388418 | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1353 | else if (x < 0) |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1354 | x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1)); |
Matthias Weisser | 5388418 | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1355 | |
| 1356 | if (y == BMP_ALIGN_CENTER) |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1357 | y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2); |
Matthias Weisser | 5388418 | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1358 | else if (y < 0) |
Masahiro Yamada | db20464 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1359 | y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1)); |
Matthias Weisser | 5388418 | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1360 | #endif /* CONFIG_SPLASH_SCREEN_ALIGN */ |
| 1361 | |
Matthias Weisser | 5e5ed76 | 2013-02-15 03:35:12 +0000 | [diff] [blame] | 1362 | /* |
| 1363 | * Just ignore elements which are completely beyond screen |
| 1364 | * dimensions. |
| 1365 | */ |
| 1366 | if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS)) |
| 1367 | return 0; |
| 1368 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1369 | if ((x + width) > VIDEO_VISIBLE_COLS) |
| 1370 | width = VIDEO_VISIBLE_COLS - x; |
| 1371 | if ((y + height) > VIDEO_VISIBLE_ROWS) |
| 1372 | height = VIDEO_VISIBLE_ROWS - y; |
| 1373 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1374 | bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1375 | fb = (uchar *) (video_fb_address + |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1376 | ((y + height - 1) * VIDEO_LINE_LEN) + |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1377 | x * VIDEO_PIXEL_SIZE); |
| 1378 | |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1379 | #ifdef CONFIG_VIDEO_BMP_RLE8 |
| 1380 | if (compression == BMP_BI_RLE8) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1381 | return display_rle8_bitmap(bmp, x, y, width, height); |
Anatolij Gustschin | 6b4e4fc | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1382 | } |
| 1383 | #endif |
| 1384 | |
Timur Tabi | 0fce992 | 2010-08-23 16:58:00 -0500 | [diff] [blame] | 1385 | /* We handle only 4, 8, or 24 bpp bitmaps */ |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1386 | switch (le16_to_cpu(bmp->header.bit_count)) { |
Timur Tabi | 0fce992 | 2010-08-23 16:58:00 -0500 | [diff] [blame] | 1387 | case 4: |
| 1388 | padded_line -= width / 2; |
| 1389 | ycount = height; |
| 1390 | |
| 1391 | switch (VIDEO_DATA_FORMAT) { |
| 1392 | case GDF_32BIT_X888RGB: |
| 1393 | while (ycount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1394 | WATCHDOG_RESET(); |
Timur Tabi | 0fce992 | 2010-08-23 16:58:00 -0500 | [diff] [blame] | 1395 | /* |
| 1396 | * Don't assume that 'width' is an |
| 1397 | * even number |
| 1398 | */ |
| 1399 | for (xcount = 0; xcount < width; xcount++) { |
| 1400 | uchar idx; |
| 1401 | |
| 1402 | if (xcount & 1) { |
| 1403 | idx = *bmap & 0xF; |
| 1404 | bmap++; |
| 1405 | } else |
| 1406 | idx = *bmap >> 4; |
| 1407 | cte = bmp->color_table[idx]; |
| 1408 | FILL_32BIT_X888RGB(cte.red, cte.green, |
| 1409 | cte.blue); |
| 1410 | } |
| 1411 | bmap += padded_line; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1412 | fb -= VIDEO_LINE_LEN + width * |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1413 | VIDEO_PIXEL_SIZE; |
Timur Tabi | 0fce992 | 2010-08-23 16:58:00 -0500 | [diff] [blame] | 1414 | } |
| 1415 | break; |
| 1416 | default: |
| 1417 | puts("4bpp bitmap unsupported with current " |
| 1418 | "video mode\n"); |
| 1419 | break; |
| 1420 | } |
| 1421 | break; |
| 1422 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1423 | case 8: |
| 1424 | padded_line -= width; |
| 1425 | if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) { |
Anatolij Gustschin | 794b25c | 2010-06-19 20:41:56 +0200 | [diff] [blame] | 1426 | /* Copy colormap */ |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1427 | for (xcount = 0; xcount < colors; ++xcount) { |
| 1428 | cte = bmp->color_table[xcount]; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1429 | video_set_lut(xcount, cte.red, cte.green, |
| 1430 | cte.blue); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1431 | } |
| 1432 | } |
| 1433 | ycount = height; |
| 1434 | switch (VIDEO_DATA_FORMAT) { |
| 1435 | case GDF__8BIT_INDEX: |
| 1436 | while (ycount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1437 | WATCHDOG_RESET(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1438 | xcount = width; |
| 1439 | while (xcount--) { |
| 1440 | *fb++ = *bmap++; |
| 1441 | } |
| 1442 | bmap += padded_line; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1443 | fb -= VIDEO_LINE_LEN + width * |
| 1444 | VIDEO_PIXEL_SIZE; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1445 | } |
| 1446 | break; |
| 1447 | case GDF__8BIT_332RGB: |
| 1448 | while (ycount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1449 | WATCHDOG_RESET(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1450 | xcount = width; |
| 1451 | while (xcount--) { |
| 1452 | cte = bmp->color_table[*bmap++]; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1453 | FILL_8BIT_332RGB(cte.red, cte.green, |
| 1454 | cte.blue); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1455 | } |
| 1456 | bmap += padded_line; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1457 | fb -= VIDEO_LINE_LEN + width * |
| 1458 | VIDEO_PIXEL_SIZE; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1459 | } |
| 1460 | break; |
| 1461 | case GDF_15BIT_555RGB: |
| 1462 | while (ycount--) { |
Anatolij Gustschin | 18b8036 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1463 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
| 1464 | int xpos = x; |
| 1465 | #endif |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1466 | WATCHDOG_RESET(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1467 | xcount = width; |
| 1468 | while (xcount--) { |
| 1469 | cte = bmp->color_table[*bmap++]; |
Andrew Dyer | 5601c61 | 2008-08-29 12:30:39 -0500 | [diff] [blame] | 1470 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1471 | fill_555rgb_pswap(fb, xpos++, cte.red, |
| 1472 | cte.green, |
| 1473 | cte.blue); |
Anatolij Gustschin | 18b8036 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1474 | fb += 2; |
Andrew Dyer | 5601c61 | 2008-08-29 12:30:39 -0500 | [diff] [blame] | 1475 | #else |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1476 | FILL_15BIT_555RGB(cte.red, cte.green, |
| 1477 | cte.blue); |
Anatolij Gustschin | 18b8036 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1478 | #endif |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1479 | } |
| 1480 | bmap += padded_line; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1481 | fb -= VIDEO_LINE_LEN + width * |
| 1482 | VIDEO_PIXEL_SIZE; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1483 | } |
| 1484 | break; |
| 1485 | case GDF_16BIT_565RGB: |
| 1486 | while (ycount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1487 | WATCHDOG_RESET(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1488 | xcount = width; |
| 1489 | while (xcount--) { |
| 1490 | cte = bmp->color_table[*bmap++]; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1491 | FILL_16BIT_565RGB(cte.red, cte.green, |
| 1492 | cte.blue); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1493 | } |
| 1494 | bmap += padded_line; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1495 | fb -= VIDEO_LINE_LEN + width * |
| 1496 | VIDEO_PIXEL_SIZE; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1497 | } |
| 1498 | break; |
| 1499 | case GDF_32BIT_X888RGB: |
| 1500 | while (ycount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1501 | WATCHDOG_RESET(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1502 | xcount = width; |
| 1503 | while (xcount--) { |
| 1504 | cte = bmp->color_table[*bmap++]; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1505 | FILL_32BIT_X888RGB(cte.red, cte.green, |
| 1506 | cte.blue); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1507 | } |
| 1508 | bmap += padded_line; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1509 | fb -= VIDEO_LINE_LEN + width * |
| 1510 | VIDEO_PIXEL_SIZE; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1511 | } |
| 1512 | break; |
| 1513 | case GDF_24BIT_888RGB: |
| 1514 | while (ycount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1515 | WATCHDOG_RESET(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1516 | xcount = width; |
| 1517 | while (xcount--) { |
| 1518 | cte = bmp->color_table[*bmap++]; |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1519 | FILL_24BIT_888RGB(cte.red, cte.green, |
| 1520 | cte.blue); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1521 | } |
| 1522 | bmap += padded_line; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1523 | fb -= VIDEO_LINE_LEN + width * |
| 1524 | VIDEO_PIXEL_SIZE; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1525 | } |
| 1526 | break; |
| 1527 | } |
| 1528 | break; |
| 1529 | case 24: |
| 1530 | padded_line -= 3 * width; |
| 1531 | ycount = height; |
| 1532 | switch (VIDEO_DATA_FORMAT) { |
| 1533 | case GDF__8BIT_332RGB: |
| 1534 | while (ycount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1535 | WATCHDOG_RESET(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1536 | xcount = width; |
| 1537 | while (xcount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1538 | FILL_8BIT_332RGB(bmap[2], bmap[1], |
| 1539 | bmap[0]); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1540 | bmap += 3; |
| 1541 | } |
| 1542 | bmap += padded_line; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1543 | fb -= VIDEO_LINE_LEN + width * |
| 1544 | VIDEO_PIXEL_SIZE; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1545 | } |
| 1546 | break; |
| 1547 | case GDF_15BIT_555RGB: |
| 1548 | while (ycount--) { |
Anatolij Gustschin | 18b8036 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1549 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
| 1550 | int xpos = x; |
| 1551 | #endif |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1552 | WATCHDOG_RESET(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1553 | xcount = width; |
| 1554 | while (xcount--) { |
Andrew Dyer | 5601c61 | 2008-08-29 12:30:39 -0500 | [diff] [blame] | 1555 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1556 | fill_555rgb_pswap(fb, xpos++, bmap[2], |
| 1557 | bmap[1], bmap[0]); |
Anatolij Gustschin | 18b8036 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1558 | fb += 2; |
Andrew Dyer | 5601c61 | 2008-08-29 12:30:39 -0500 | [diff] [blame] | 1559 | #else |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1560 | FILL_15BIT_555RGB(bmap[2], bmap[1], |
| 1561 | bmap[0]); |
Anatolij Gustschin | 18b8036 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1562 | #endif |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1563 | bmap += 3; |
| 1564 | } |
| 1565 | bmap += padded_line; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1566 | fb -= VIDEO_LINE_LEN + width * |
| 1567 | VIDEO_PIXEL_SIZE; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1568 | } |
| 1569 | break; |
| 1570 | case GDF_16BIT_565RGB: |
| 1571 | while (ycount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1572 | WATCHDOG_RESET(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1573 | xcount = width; |
| 1574 | while (xcount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1575 | FILL_16BIT_565RGB(bmap[2], bmap[1], |
| 1576 | bmap[0]); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1577 | bmap += 3; |
| 1578 | } |
| 1579 | bmap += padded_line; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1580 | fb -= VIDEO_LINE_LEN + width * |
| 1581 | VIDEO_PIXEL_SIZE; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1582 | } |
| 1583 | break; |
| 1584 | case GDF_32BIT_X888RGB: |
| 1585 | while (ycount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1586 | WATCHDOG_RESET(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1587 | xcount = width; |
| 1588 | while (xcount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1589 | FILL_32BIT_X888RGB(bmap[2], bmap[1], |
| 1590 | bmap[0]); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1591 | bmap += 3; |
| 1592 | } |
| 1593 | bmap += padded_line; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1594 | fb -= VIDEO_LINE_LEN + width * |
| 1595 | VIDEO_PIXEL_SIZE; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1596 | } |
| 1597 | break; |
| 1598 | case GDF_24BIT_888RGB: |
| 1599 | while (ycount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1600 | WATCHDOG_RESET(); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1601 | xcount = width; |
| 1602 | while (xcount--) { |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1603 | FILL_24BIT_888RGB(bmap[2], bmap[1], |
| 1604 | bmap[0]); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1605 | bmap += 3; |
| 1606 | } |
| 1607 | bmap += padded_line; |
Hans de Goede | a8287e7 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1608 | fb -= VIDEO_LINE_LEN + width * |
| 1609 | VIDEO_PIXEL_SIZE; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1610 | } |
| 1611 | break; |
| 1612 | default: |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1613 | printf("Error: 24 bits/pixel bitmap incompatible " |
| 1614 | "with current video mode\n"); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1615 | break; |
| 1616 | } |
| 1617 | break; |
| 1618 | default: |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1619 | printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n", |
| 1620 | le16_to_cpu(bmp->header.bit_count)); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1621 | break; |
| 1622 | } |
Stefan Roese | d9d9774 | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1623 | |
| 1624 | #ifdef CONFIG_VIDEO_BMP_GZIP |
| 1625 | if (dst) { |
| 1626 | free(dst); |
| 1627 | } |
| 1628 | #endif |
| 1629 | |
Eric Nelson | 5414242 | 2013-05-06 14:27:28 +0200 | [diff] [blame] | 1630 | if (cfb_do_flush_cache) |
| 1631 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1632 | return (0); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1633 | } |
Jon Loeliger | b1d408a | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 1634 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1635 | |
Anatolij Gustschin | dbad2b8 | 2012-06-05 09:19:18 +0200 | [diff] [blame] | 1636 | static int cfb_fb_is_in_dram(void) |
| 1637 | { |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 1638 | struct bd_info *bd = gd->bd; |
Anatolij Gustschin | dbad2b8 | 2012-06-05 09:19:18 +0200 | [diff] [blame] | 1639 | ulong start, end; |
| 1640 | int i; |
| 1641 | |
| 1642 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { |
| 1643 | start = bd->bi_dram[i].start; |
| 1644 | end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1; |
| 1645 | if ((ulong)video_fb_address >= start && |
| 1646 | (ulong)video_fb_address < end) |
| 1647 | return 1; |
| 1648 | } |
Stefan Roese | e584215 | 2020-08-12 13:32:41 +0200 | [diff] [blame] | 1649 | |
Anatolij Gustschin | dbad2b8 | 2012-06-05 09:19:18 +0200 | [diff] [blame] | 1650 | return 0; |
| 1651 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1652 | |
Heiko Schocher | 6275956 | 2013-10-22 11:06:06 +0200 | [diff] [blame] | 1653 | void video_clear(void) |
| 1654 | { |
| 1655 | if (!video_fb_address) |
| 1656 | return; |
| 1657 | #ifdef VIDEO_HW_RECTFILL |
| 1658 | video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */ |
| 1659 | 0, /* dest pos x */ |
| 1660 | 0, /* dest pos y */ |
| 1661 | VIDEO_VISIBLE_COLS, /* frame width */ |
| 1662 | VIDEO_VISIBLE_ROWS, /* frame height */ |
| 1663 | bgx /* fill color */ |
| 1664 | ); |
| 1665 | #else |
| 1666 | memsetl(video_fb_address, |
| 1667 | (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx); |
| 1668 | #endif |
| 1669 | } |
| 1670 | |
Simon Glass | 88ecb9b | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 1671 | static int cfg_video_init(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1672 | { |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1673 | unsigned char color8; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1674 | |
Wolfgang Denk | a87b2a95 | 2011-07-30 12:48:09 +0000 | [diff] [blame] | 1675 | pGD = video_hw_init(); |
| 1676 | if (pGD == NULL) |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1677 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1678 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1679 | video_fb_address = (void *) VIDEO_FB_ADRS; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1680 | |
Anatolij Gustschin | dbad2b8 | 2012-06-05 09:19:18 +0200 | [diff] [blame] | 1681 | cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status(); |
| 1682 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1683 | /* Init drawing pats */ |
| 1684 | switch (VIDEO_DATA_FORMAT) { |
| 1685 | case GDF__8BIT_INDEX: |
Simon Glass | 884889d | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 1686 | video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL, |
| 1687 | CONFIG_SYS_CONSOLE_FG_COL, |
| 1688 | CONFIG_SYS_CONSOLE_FG_COL); |
| 1689 | video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL, |
| 1690 | CONFIG_SYS_CONSOLE_BG_COL, |
| 1691 | CONFIG_SYS_CONSOLE_BG_COL); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1692 | fgx = 0x01010101; |
| 1693 | bgx = 0x00000000; |
| 1694 | break; |
| 1695 | case GDF__8BIT_332RGB: |
Simon Glass | 884889d | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 1696 | color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) | |
| 1697 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) | |
| 1698 | CONFIG_SYS_CONSOLE_FG_COL >> 6); |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1699 | fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | |
| 1700 | color8; |
Simon Glass | 884889d | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 1701 | color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) | |
| 1702 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) | |
| 1703 | CONFIG_SYS_CONSOLE_BG_COL >> 6); |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1704 | bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | |
| 1705 | color8; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1706 | break; |
| 1707 | case GDF_15BIT_555RGB: |
Simon Glass | 884889d | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 1708 | fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) | |
| 1709 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) | |
| 1710 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) | |
| 1711 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) | |
| 1712 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) | |
| 1713 | (CONFIG_SYS_CONSOLE_FG_COL >> 3)); |
| 1714 | bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) | |
| 1715 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) | |
| 1716 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) | |
| 1717 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) | |
| 1718 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) | |
| 1719 | (CONFIG_SYS_CONSOLE_BG_COL >> 3)); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1720 | break; |
| 1721 | case GDF_16BIT_565RGB: |
Simon Glass | 884889d | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 1722 | fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) | |
| 1723 | ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) | |
| 1724 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) | |
| 1725 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) | |
| 1726 | ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) | |
| 1727 | (CONFIG_SYS_CONSOLE_FG_COL >> 3)); |
| 1728 | bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) | |
| 1729 | ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) | |
| 1730 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) | |
| 1731 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) | |
| 1732 | ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) | |
| 1733 | (CONFIG_SYS_CONSOLE_BG_COL >> 3)); |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1734 | break; |
| 1735 | case GDF_32BIT_X888RGB: |
Simon Glass | 884889d | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 1736 | fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) | |
| 1737 | (CONFIG_SYS_CONSOLE_FG_COL << 8) | |
| 1738 | CONFIG_SYS_CONSOLE_FG_COL; |
| 1739 | bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) | |
| 1740 | (CONFIG_SYS_CONSOLE_BG_COL << 8) | |
| 1741 | CONFIG_SYS_CONSOLE_BG_COL; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1742 | break; |
| 1743 | case GDF_24BIT_888RGB: |
Simon Glass | 884889d | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 1744 | fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) | |
| 1745 | (CONFIG_SYS_CONSOLE_FG_COL << 16) | |
| 1746 | (CONFIG_SYS_CONSOLE_FG_COL << 8) | |
| 1747 | CONFIG_SYS_CONSOLE_FG_COL; |
| 1748 | bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) | |
| 1749 | (CONFIG_SYS_CONSOLE_BG_COL << 16) | |
| 1750 | (CONFIG_SYS_CONSOLE_BG_COL << 8) | |
| 1751 | CONFIG_SYS_CONSOLE_BG_COL; |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1752 | break; |
| 1753 | } |
| 1754 | eorx = fgx ^ bgx; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1755 | |
Rob Clark | f141188 | 2017-08-03 12:47:01 -0400 | [diff] [blame] | 1756 | if (!CONFIG_IS_ENABLED(NO_FB_CLEAR)) |
| 1757 | video_clear(); |
Heiko Schocher | 6275956 | 2013-10-22 11:06:06 +0200 | [diff] [blame] | 1758 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1759 | #ifdef CONFIG_VIDEO_LOGO |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1760 | /* Plot the logo and get start point of console */ |
Wolfgang Denk | 4671771 | 2011-07-29 09:55:28 +0000 | [diff] [blame] | 1761 | debug("Video: Drawing the logo ...\n"); |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1762 | video_console_address = video_logo(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1763 | #else |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1764 | video_console_address = video_fb_address; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1765 | #endif |
| 1766 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1767 | /* Initialize the console */ |
| 1768 | console_col = 0; |
| 1769 | console_row = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1770 | |
Eric Nelson | 5414242 | 2013-05-06 14:27:28 +0200 | [diff] [blame] | 1771 | if (cfb_do_flush_cache) |
| 1772 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); |
| 1773 | |
wdenk | e55402c | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1774 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1775 | } |
| 1776 | |
Wolfgang Denk | d0e4e2a | 2009-05-15 10:07:43 +0200 | [diff] [blame] | 1777 | /* |
| 1778 | * Implement a weak default function for boards that optionally |
| 1779 | * need to skip the video initialization. |
| 1780 | */ |
Jeroen Hofstee | f7ae3ed | 2014-10-08 22:57:30 +0200 | [diff] [blame] | 1781 | __weak int board_video_skip(void) |
Wolfgang Denk | d0e4e2a | 2009-05-15 10:07:43 +0200 | [diff] [blame] | 1782 | { |
| 1783 | /* As default, don't skip test */ |
| 1784 | return 0; |
| 1785 | } |
Wolfgang Denk | d0e4e2a | 2009-05-15 10:07:43 +0200 | [diff] [blame] | 1786 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1787 | int drv_video_init(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1788 | { |
Jean-Christophe PLAGNIOL-VILLARD | 2a7a031 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 1789 | struct stdio_dev console_dev; |
Simon Glass | e9fa1f0 | 2015-03-02 12:40:50 -0700 | [diff] [blame] | 1790 | bool have_keyboard; |
Bin Meng | e52e17a | 2015-08-24 01:00:07 -0700 | [diff] [blame] | 1791 | bool __maybe_unused keyboard_ok = false; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1792 | |
Wolfgang Denk | d0e4e2a | 2009-05-15 10:07:43 +0200 | [diff] [blame] | 1793 | /* Check if video initialization should be skipped */ |
| 1794 | if (board_video_skip()) |
| 1795 | return 0; |
| 1796 | |
wdenk | 7dd1329 | 2004-07-11 20:04:51 +0000 | [diff] [blame] | 1797 | /* Init video chip - returns with framebuffer cleared */ |
Simon Glass | 88ecb9b | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 1798 | if (cfg_video_init() == -1) |
Bin Meng | e52e17a | 2015-08-24 01:00:07 -0700 | [diff] [blame] | 1799 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1800 | |
Heiko Schocher | 9cff8ad | 2013-08-03 07:22:53 +0200 | [diff] [blame] | 1801 | if (board_cfb_skip()) |
| 1802 | return 0; |
| 1803 | |
Simon Glass | e9fa1f0 | 2015-03-02 12:40:50 -0700 | [diff] [blame] | 1804 | #if defined(CONFIG_VGA_AS_SINGLE_DEVICE) |
| 1805 | have_keyboard = false; |
| 1806 | #elif defined(CONFIG_OF_CONTROL) |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 1807 | have_keyboard = !ofnode_conf_read_bool("u-boot,no-keyboard"); |
Simon Glass | e9fa1f0 | 2015-03-02 12:40:50 -0700 | [diff] [blame] | 1808 | #else |
| 1809 | have_keyboard = true; |
| 1810 | #endif |
| 1811 | if (have_keyboard) { |
| 1812 | debug("KBD: Keyboard init ...\n"); |
Wolfgang Denk | 50bc99c | 2009-05-15 10:07:42 +0200 | [diff] [blame] | 1813 | #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE) |
Bin Meng | e52e17a | 2015-08-24 01:00:07 -0700 | [diff] [blame] | 1814 | keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1); |
Wolfgang Denk | 50bc99c | 2009-05-15 10:07:42 +0200 | [diff] [blame] | 1815 | #endif |
Simon Glass | e9fa1f0 | 2015-03-02 12:40:50 -0700 | [diff] [blame] | 1816 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1817 | |
Wolfgang Denk | 50bc99c | 2009-05-15 10:07:42 +0200 | [diff] [blame] | 1818 | /* Init vga device */ |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1819 | memset(&console_dev, 0, sizeof(console_dev)); |
| 1820 | strcpy(console_dev.name, "vga"); |
Bin Meng | 6abe4b6 | 2015-11-03 23:23:37 -0800 | [diff] [blame] | 1821 | console_dev.flags = DEV_FLAGS_OUTPUT; |
Simon Glass | 88ecb9b | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 1822 | console_dev.putc = cfb_video_putc; /* 'putc' function */ |
| 1823 | console_dev.puts = cfb_video_puts; /* 'puts' function */ |
Wolfgang Denk | 50bc99c | 2009-05-15 10:07:42 +0200 | [diff] [blame] | 1824 | |
| 1825 | #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE) |
Bin Meng | e52e17a | 2015-08-24 01:00:07 -0700 | [diff] [blame] | 1826 | if (have_keyboard && keyboard_ok) { |
Simon Glass | e9fa1f0 | 2015-03-02 12:40:50 -0700 | [diff] [blame] | 1827 | /* Also init console device */ |
| 1828 | console_dev.flags |= DEV_FLAGS_INPUT; |
| 1829 | console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */ |
| 1830 | console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */ |
| 1831 | } |
| 1832 | #endif |
Wolfgang Denk | 50bc99c | 2009-05-15 10:07:42 +0200 | [diff] [blame] | 1833 | |
Wolfgang Denk | 0b4b56e | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1834 | if (stdio_register(&console_dev) != 0) |
Wolfgang Denk | 50bc99c | 2009-05-15 10:07:42 +0200 | [diff] [blame] | 1835 | return 0; |
| 1836 | |
| 1837 | /* Return success */ |
| 1838 | return 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1839 | } |
Stefan Reinauer | 7870da3 | 2012-09-28 15:11:12 +0000 | [diff] [blame] | 1840 | |
| 1841 | void video_position_cursor(unsigned col, unsigned row) |
| 1842 | { |
| 1843 | console_col = min(col, CONSOLE_COLS - 1); |
| 1844 | console_row = min(row, CONSOLE_ROWS - 1); |
| 1845 | } |
| 1846 | |
| 1847 | int video_get_pixel_width(void) |
| 1848 | { |
| 1849 | return VIDEO_VISIBLE_COLS; |
| 1850 | } |
| 1851 | |
| 1852 | int video_get_pixel_height(void) |
| 1853 | { |
| 1854 | return VIDEO_VISIBLE_ROWS; |
| 1855 | } |
| 1856 | |
| 1857 | int video_get_screen_rows(void) |
| 1858 | { |
| 1859 | return CONSOLE_ROWS; |
| 1860 | } |
| 1861 | |
| 1862 | int video_get_screen_columns(void) |
| 1863 | { |
| 1864 | return CONSOLE_COLS; |
| 1865 | } |