Tom Rini | 83d290c | 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 | 64e40d7 | 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 | 39f615e | 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 | 64e40d7 | 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 | 64e40d7 | 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 | 64e40d7 | 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 | * |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 45 | * CONFIG_VIDEO_LOGO - display Linux Logo in upper left corner. |
| 46 | * Use CONFIG_SPLASH_SCREEN_ALIGN with |
| 47 | * environment variable "splashpos" to place |
| 48 | * the logo on other position. In this case |
| 49 | * no CONSOLE_EXTRA_INFO is possible. |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 50 | * CONFIG_VIDEO_BMP_LOGO - use bmp_logo instead of linux_logo |
| 51 | * CONFIG_CONSOLE_EXTRA_INFO - display additional board information |
| 52 | * strings that normaly goes to serial |
| 53 | * port. This define requires a board |
| 54 | * specific function: |
| 55 | * video_drawstring (VIDEO_INFO_X, |
| 56 | * VIDEO_INFO_Y + i*VIDEO_FONT_HEIGHT, |
| 57 | * info); |
| 58 | * that fills a info buffer at i=row. |
| 59 | * s.a: board/eltec/bab7xx. |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 60 | * |
| 61 | * CONFIG_VIDEO_SW_CURSOR: - Draws a cursor after the last |
| 62 | * character. No blinking is provided. |
| 63 | * Uses the macros CURSOR_SET and |
| 64 | * CURSOR_OFF. |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 65 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 66 | |
| 67 | #include <common.h> |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame^] | 68 | #include <command.h> |
Simon Glass | 9edefc2 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 69 | #include <cpu_func.h> |
Simon Glass | 7b51b57 | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 70 | #include <env.h> |
Simon Glass | 5692ccf | 2015-03-02 12:40:50 -0700 | [diff] [blame] | 71 | #include <fdtdec.h> |
Simon Glass | 0c670fc | 2019-08-01 09:46:36 -0600 | [diff] [blame] | 72 | #include <gzip.h> |
Andreas Bießmann | 09c2e90 | 2011-07-18 20:24:04 +0200 | [diff] [blame] | 73 | #include <version.h> |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 74 | #include <malloc.h> |
Simon Glass | 0a6eac8 | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 75 | #include <video.h> |
Wolfgang Denk | a9a62af | 2011-11-04 15:55:20 +0000 | [diff] [blame] | 76 | #include <linux/compiler.h> |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 77 | |
Simon Glass | c370d38 | 2016-10-17 20:12:47 -0600 | [diff] [blame] | 78 | #if defined(CONFIG_VIDEO_MXS) |
Marek Vasut | fb8ddc2 | 2013-04-28 09:20:03 +0000 | [diff] [blame] | 79 | #define VIDEO_FB_16BPP_WORD_SWAP |
| 80 | #endif |
| 81 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 82 | /* |
| 83 | * Defines for the MB862xx driver |
| 84 | */ |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 85 | #ifdef CONFIG_VIDEO_MB862xx |
| 86 | |
| 87 | #ifdef CONFIG_VIDEO_CORALP |
| 88 | #define VIDEO_FB_LITTLE_ENDIAN |
| 89 | #endif |
Anatolij Gustschin | 5d16ca8 | 2009-10-23 12:03:14 +0200 | [diff] [blame] | 90 | #ifdef CONFIG_VIDEO_MB862xx_ACCEL |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 91 | #define VIDEO_HW_RECTFILL |
| 92 | #define VIDEO_HW_BITBLT |
| 93 | #endif |
Anatolij Gustschin | 5d16ca8 | 2009-10-23 12:03:14 +0200 | [diff] [blame] | 94 | #endif |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 95 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 96 | /* |
Helmut Raiger | 62a22dc | 2011-10-12 23:16:29 +0000 | [diff] [blame] | 97 | * Defines for the i.MX31 driver (mx3fb.c) |
| 98 | */ |
Fabio Estevam | 695af9a | 2012-05-31 07:23:56 +0000 | [diff] [blame] | 99 | #if defined(CONFIG_VIDEO_MX3) || defined(CONFIG_VIDEO_IPUV3) |
Helmut Raiger | 62a22dc | 2011-10-12 23:16:29 +0000 | [diff] [blame] | 100 | #define VIDEO_FB_16BPP_WORD_SWAP |
| 101 | #endif |
| 102 | |
| 103 | /* |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 104 | * Include video_fb.h after definitions of VIDEO_HW_RECTFILL etc. |
| 105 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 106 | #include <video_fb.h> |
| 107 | |
Robert Winkler | dd4425e | 2013-06-17 11:31:29 -0700 | [diff] [blame] | 108 | #include <splash.h> |
| 109 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 110 | /* |
| 111 | * some Macros |
| 112 | */ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 113 | #define VIDEO_VISIBLE_COLS (pGD->winSizeX) |
| 114 | #define VIDEO_VISIBLE_ROWS (pGD->winSizeY) |
| 115 | #define VIDEO_PIXEL_SIZE (pGD->gdfBytesPP) |
| 116 | #define VIDEO_DATA_FORMAT (pGD->gdfIndex) |
| 117 | #define VIDEO_FB_ADRS (pGD->frameAdrs) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 118 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 119 | /* |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 120 | * Console device |
| 121 | */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 122 | |
| 123 | #include <version.h> |
| 124 | #include <linux/types.h> |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 125 | #include <stdio_dev.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 126 | #include <video_font.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 127 | |
Jon Loeliger | ddb5d86f | 2007-07-10 11:13:21 -0500 | [diff] [blame] | 128 | #if defined(CONFIG_CMD_DATE) |
| 129 | #include <rtc.h> |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 130 | #endif |
| 131 | |
Jon Loeliger | 07d38a1 | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 132 | #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 133 | #include <watchdog.h> |
| 134 | #include <bmp_layout.h> |
Anatolij Gustschin | ff8fb56 | 2013-07-02 00:04:05 +0200 | [diff] [blame] | 135 | #include <splash.h> |
Jon Loeliger | 07d38a1 | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 136 | #endif |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 137 | |
Simon Glass | a420657 | 2016-10-17 20:12:50 -0600 | [diff] [blame] | 138 | #if !defined(CONFIG_VIDEO_SW_CURSOR) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 139 | /* no Cursor defined */ |
| 140 | #define CURSOR_ON |
| 141 | #define CURSOR_OFF |
| 142 | #define CURSOR_SET |
| 143 | #endif |
| 144 | |
Simon Glass | 7fe0933 | 2015-10-18 21:17:18 -0600 | [diff] [blame] | 145 | #if defined(CONFIG_VIDEO_SW_CURSOR) |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 146 | void console_cursor(int state); |
| 147 | |
Timur Tabi | 6561863 | 2010-08-27 15:45:47 -0500 | [diff] [blame] | 148 | #define CURSOR_ON console_cursor(1) |
| 149 | #define CURSOR_OFF console_cursor(0) |
Gabe Black | 03d31fc | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 150 | #define CURSOR_SET video_set_cursor() |
Simon Glass | 7fe0933 | 2015-10-18 21:17:18 -0600 | [diff] [blame] | 151 | #endif /* CONFIG_VIDEO_SW_CURSOR */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 152 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 153 | #ifdef CONFIG_VIDEO_LOGO |
| 154 | #ifdef CONFIG_VIDEO_BMP_LOGO |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 155 | #include <bmp_logo.h> |
Che-Liang Chiou | c270730 | 2011-10-20 23:04:20 +0000 | [diff] [blame] | 156 | #include <bmp_logo_data.h> |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 157 | #define VIDEO_LOGO_WIDTH BMP_LOGO_WIDTH |
| 158 | #define VIDEO_LOGO_HEIGHT BMP_LOGO_HEIGHT |
| 159 | #define VIDEO_LOGO_LUT_OFFSET BMP_LOGO_OFFSET |
| 160 | #define VIDEO_LOGO_COLORS BMP_LOGO_COLORS |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 161 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 162 | #else /* CONFIG_VIDEO_BMP_LOGO */ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 163 | #define LINUX_LOGO_WIDTH 80 |
| 164 | #define LINUX_LOGO_HEIGHT 80 |
| 165 | #define LINUX_LOGO_COLORS 214 |
| 166 | #define LINUX_LOGO_LUT_OFFSET 0x20 |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 167 | #define __initdata |
| 168 | #include <linux_logo.h> |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 169 | #define VIDEO_LOGO_WIDTH LINUX_LOGO_WIDTH |
| 170 | #define VIDEO_LOGO_HEIGHT LINUX_LOGO_HEIGHT |
| 171 | #define VIDEO_LOGO_LUT_OFFSET LINUX_LOGO_LUT_OFFSET |
| 172 | #define VIDEO_LOGO_COLORS LINUX_LOGO_COLORS |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 173 | #endif /* CONFIG_VIDEO_BMP_LOGO */ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 174 | #define VIDEO_INFO_X (VIDEO_LOGO_WIDTH) |
| 175 | #define VIDEO_INFO_Y (VIDEO_FONT_HEIGHT/2) |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 176 | #else /* CONFIG_VIDEO_LOGO */ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 177 | #define VIDEO_LOGO_WIDTH 0 |
| 178 | #define VIDEO_LOGO_HEIGHT 0 |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 179 | #endif /* CONFIG_VIDEO_LOGO */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 180 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 181 | #define VIDEO_COLS VIDEO_VISIBLE_COLS |
| 182 | #define VIDEO_ROWS VIDEO_VISIBLE_ROWS |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 183 | #ifndef VIDEO_LINE_LEN |
| 184 | #define VIDEO_LINE_LEN (VIDEO_COLS * VIDEO_PIXEL_SIZE) |
| 185 | #endif |
| 186 | #define VIDEO_SIZE (VIDEO_ROWS * VIDEO_LINE_LEN) |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 187 | #define VIDEO_BURST_LEN (VIDEO_COLS/8) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 188 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 189 | #ifdef CONFIG_VIDEO_LOGO |
Matthias Weisser | be129aa | 2010-01-12 12:06:31 +0100 | [diff] [blame] | 190 | #define CONSOLE_ROWS ((VIDEO_ROWS - video_logo_height) / VIDEO_FONT_HEIGHT) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 191 | #else |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 192 | #define CONSOLE_ROWS (VIDEO_ROWS / VIDEO_FONT_HEIGHT) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 193 | #endif |
| 194 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 195 | #define CONSOLE_COLS (VIDEO_COLS / VIDEO_FONT_WIDTH) |
| 196 | #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * VIDEO_LINE_LEN) |
| 197 | #define CONSOLE_ROW_FIRST (video_console_address) |
| 198 | #define CONSOLE_ROW_SECOND (video_console_address + CONSOLE_ROW_SIZE) |
| 199 | #define CONSOLE_ROW_LAST (video_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE) |
| 200 | #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS) |
Simon Glass | 3c0b668 | 2015-01-01 16:17:57 -0700 | [diff] [blame] | 201 | |
| 202 | /* By default we scroll by a single line */ |
| 203 | #ifndef CONFIG_CONSOLE_SCROLL_LINES |
| 204 | #define CONFIG_CONSOLE_SCROLL_LINES 1 |
| 205 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 206 | |
| 207 | /* Macros */ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 208 | #ifdef VIDEO_FB_LITTLE_ENDIAN |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 209 | #define SWAP16(x) ((((x) & 0x00ff) << 8) | \ |
| 210 | ((x) >> 8) \ |
| 211 | ) |
| 212 | #define SWAP32(x) ((((x) & 0x000000ff) << 24) | \ |
| 213 | (((x) & 0x0000ff00) << 8) | \ |
| 214 | (((x) & 0x00ff0000) >> 8) | \ |
| 215 | (((x) & 0xff000000) >> 24) \ |
| 216 | ) |
| 217 | #define SHORTSWAP32(x) ((((x) & 0x000000ff) << 8) | \ |
| 218 | (((x) & 0x0000ff00) >> 8) | \ |
| 219 | (((x) & 0x00ff0000) << 8) | \ |
| 220 | (((x) & 0xff000000) >> 8) \ |
| 221 | ) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 222 | #else |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 223 | #define SWAP16(x) (x) |
| 224 | #define SWAP32(x) (x) |
Wolfgang Grandegger | 229b6dc | 2009-10-23 12:03:15 +0200 | [diff] [blame] | 225 | #if defined(VIDEO_FB_16BPP_WORD_SWAP) |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 226 | #define SHORTSWAP32(x) (((x) >> 16) | ((x) << 16)) |
Andrew Dyer | cc34780 | 2008-08-29 12:30:39 -0500 | [diff] [blame] | 227 | #else |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 228 | #define SHORTSWAP32(x) (x) |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 229 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 230 | #endif |
| 231 | |
Anatolij Gustschin | bfd4be8 | 2012-06-05 09:19:18 +0200 | [diff] [blame] | 232 | DECLARE_GLOBAL_DATA_PTR; |
| 233 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 234 | /* Locals */ |
| 235 | static GraphicDevice *pGD; /* Pointer to Graphic array */ |
| 236 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 237 | static void *video_fb_address; /* frame buffer address */ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 238 | static void *video_console_address; /* console buffer start address */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 239 | |
Matthias Weisser | be129aa | 2010-01-12 12:06:31 +0100 | [diff] [blame] | 240 | static int video_logo_height = VIDEO_LOGO_HEIGHT; |
| 241 | |
Anatolij Gustschin | a45adde | 2011-12-07 03:58:10 +0000 | [diff] [blame] | 242 | static int __maybe_unused cursor_state; |
| 243 | static int __maybe_unused old_col; |
| 244 | static int __maybe_unused old_row; |
Gabe Black | 03d31fc | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 245 | |
Wolfgang Denk | 5791293 | 2011-07-30 12:48:09 +0000 | [diff] [blame] | 246 | static int console_col; /* cursor col */ |
| 247 | static int console_row; /* cursor row */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 248 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 249 | static u32 eorx, fgx, bgx; /* color pats */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 250 | |
Anatolij Gustschin | bfd4be8 | 2012-06-05 09:19:18 +0200 | [diff] [blame] | 251 | static int cfb_do_flush_cache; |
| 252 | |
Pali Rohár | 33a35bb | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 253 | #ifdef CONFIG_CFB_CONSOLE_ANSI |
| 254 | static char ansi_buf[10]; |
| 255 | static int ansi_buf_size; |
| 256 | static int ansi_colors_need_revert; |
| 257 | static int ansi_cursor_hidden; |
| 258 | #endif |
| 259 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 260 | static const int video_font_draw_table8[] = { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 261 | 0x00000000, 0x000000ff, 0x0000ff00, 0x0000ffff, |
| 262 | 0x00ff0000, 0x00ff00ff, 0x00ffff00, 0x00ffffff, |
| 263 | 0xff000000, 0xff0000ff, 0xff00ff00, 0xff00ffff, |
| 264 | 0xffff0000, 0xffff00ff, 0xffffff00, 0xffffffff |
| 265 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 266 | |
| 267 | static const int video_font_draw_table15[] = { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 268 | 0x00000000, 0x00007fff, 0x7fff0000, 0x7fff7fff |
| 269 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 270 | |
| 271 | static const int video_font_draw_table16[] = { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 272 | 0x00000000, 0x0000ffff, 0xffff0000, 0xffffffff |
| 273 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 274 | |
| 275 | static const int video_font_draw_table24[16][3] = { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 276 | {0x00000000, 0x00000000, 0x00000000}, |
| 277 | {0x00000000, 0x00000000, 0x00ffffff}, |
| 278 | {0x00000000, 0x0000ffff, 0xff000000}, |
| 279 | {0x00000000, 0x0000ffff, 0xffffffff}, |
| 280 | {0x000000ff, 0xffff0000, 0x00000000}, |
| 281 | {0x000000ff, 0xffff0000, 0x00ffffff}, |
| 282 | {0x000000ff, 0xffffffff, 0xff000000}, |
| 283 | {0x000000ff, 0xffffffff, 0xffffffff}, |
| 284 | {0xffffff00, 0x00000000, 0x00000000}, |
| 285 | {0xffffff00, 0x00000000, 0x00ffffff}, |
| 286 | {0xffffff00, 0x0000ffff, 0xff000000}, |
| 287 | {0xffffff00, 0x0000ffff, 0xffffffff}, |
| 288 | {0xffffffff, 0xffff0000, 0x00000000}, |
| 289 | {0xffffffff, 0xffff0000, 0x00ffffff}, |
| 290 | {0xffffffff, 0xffffffff, 0xff000000}, |
| 291 | {0xffffffff, 0xffffffff, 0xffffffff} |
| 292 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 293 | |
| 294 | static const int video_font_draw_table32[16][4] = { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 295 | {0x00000000, 0x00000000, 0x00000000, 0x00000000}, |
| 296 | {0x00000000, 0x00000000, 0x00000000, 0x00ffffff}, |
| 297 | {0x00000000, 0x00000000, 0x00ffffff, 0x00000000}, |
| 298 | {0x00000000, 0x00000000, 0x00ffffff, 0x00ffffff}, |
| 299 | {0x00000000, 0x00ffffff, 0x00000000, 0x00000000}, |
| 300 | {0x00000000, 0x00ffffff, 0x00000000, 0x00ffffff}, |
| 301 | {0x00000000, 0x00ffffff, 0x00ffffff, 0x00000000}, |
| 302 | {0x00000000, 0x00ffffff, 0x00ffffff, 0x00ffffff}, |
| 303 | {0x00ffffff, 0x00000000, 0x00000000, 0x00000000}, |
| 304 | {0x00ffffff, 0x00000000, 0x00000000, 0x00ffffff}, |
| 305 | {0x00ffffff, 0x00000000, 0x00ffffff, 0x00000000}, |
| 306 | {0x00ffffff, 0x00000000, 0x00ffffff, 0x00ffffff}, |
| 307 | {0x00ffffff, 0x00ffffff, 0x00000000, 0x00000000}, |
| 308 | {0x00ffffff, 0x00ffffff, 0x00000000, 0x00ffffff}, |
| 309 | {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00000000}, |
| 310 | {0x00ffffff, 0x00ffffff, 0x00ffffff, 0x00ffffff} |
| 311 | }; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 312 | |
Heiko Schocher | 2bc4aa5 | 2013-08-03 07:22:53 +0200 | [diff] [blame] | 313 | /* |
| 314 | * Implement a weak default function for boards that optionally |
| 315 | * need to skip the cfb initialization. |
| 316 | */ |
| 317 | __weak int board_cfb_skip(void) |
| 318 | { |
| 319 | /* As default, don't skip cfb init */ |
| 320 | return 0; |
| 321 | } |
| 322 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 323 | static void video_drawchars(int xx, int yy, unsigned char *s, int count) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 324 | { |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 325 | u8 *cdat, *dest, *dest0; |
| 326 | int rows, offset, c; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 327 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 328 | offset = yy * VIDEO_LINE_LEN + xx * VIDEO_PIXEL_SIZE; |
| 329 | dest0 = video_fb_address + offset; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 330 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 331 | switch (VIDEO_DATA_FORMAT) { |
| 332 | case GDF__8BIT_INDEX: |
| 333 | case GDF__8BIT_332RGB: |
| 334 | while (count--) { |
| 335 | c = *s; |
| 336 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; |
| 337 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 338 | rows--; dest += VIDEO_LINE_LEN) { |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 339 | u8 bits = *cdat++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 340 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 341 | ((u32 *) dest)[0] = |
| 342 | (video_font_draw_table8[bits >> 4] & |
| 343 | eorx) ^ bgx; |
Marek Vasut | fd8cf99 | 2013-07-30 23:37:59 +0200 | [diff] [blame] | 344 | |
| 345 | if (VIDEO_FONT_WIDTH == 4) |
| 346 | continue; |
| 347 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 348 | ((u32 *) dest)[1] = |
| 349 | (video_font_draw_table8[bits & 15] & |
| 350 | eorx) ^ bgx; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 351 | } |
| 352 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; |
| 353 | s++; |
| 354 | } |
| 355 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 356 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 357 | case GDF_15BIT_555RGB: |
| 358 | while (count--) { |
| 359 | c = *s; |
| 360 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; |
| 361 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 362 | rows--; dest += VIDEO_LINE_LEN) { |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 363 | u8 bits = *cdat++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 364 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 365 | ((u32 *) dest)[0] = |
| 366 | SHORTSWAP32((video_font_draw_table15 |
| 367 | [bits >> 6] & eorx) ^ |
| 368 | bgx); |
| 369 | ((u32 *) dest)[1] = |
| 370 | SHORTSWAP32((video_font_draw_table15 |
| 371 | [bits >> 4 & 3] & eorx) ^ |
| 372 | bgx); |
Marek Vasut | fd8cf99 | 2013-07-30 23:37:59 +0200 | [diff] [blame] | 373 | |
| 374 | if (VIDEO_FONT_WIDTH == 4) |
| 375 | continue; |
| 376 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 377 | ((u32 *) dest)[2] = |
| 378 | SHORTSWAP32((video_font_draw_table15 |
| 379 | [bits >> 2 & 3] & eorx) ^ |
| 380 | bgx); |
| 381 | ((u32 *) dest)[3] = |
| 382 | SHORTSWAP32((video_font_draw_table15 |
| 383 | [bits & 3] & eorx) ^ |
| 384 | bgx); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 385 | } |
| 386 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; |
| 387 | s++; |
| 388 | } |
| 389 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 390 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 391 | case GDF_16BIT_565RGB: |
| 392 | while (count--) { |
| 393 | c = *s; |
| 394 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; |
| 395 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 396 | rows--; dest += VIDEO_LINE_LEN) { |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 397 | u8 bits = *cdat++; |
| 398 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 399 | ((u32 *) dest)[0] = |
| 400 | SHORTSWAP32((video_font_draw_table16 |
| 401 | [bits >> 6] & eorx) ^ |
| 402 | bgx); |
| 403 | ((u32 *) dest)[1] = |
| 404 | SHORTSWAP32((video_font_draw_table16 |
| 405 | [bits >> 4 & 3] & eorx) ^ |
| 406 | bgx); |
Marek Vasut | fd8cf99 | 2013-07-30 23:37:59 +0200 | [diff] [blame] | 407 | |
| 408 | if (VIDEO_FONT_WIDTH == 4) |
| 409 | continue; |
| 410 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 411 | ((u32 *) dest)[2] = |
| 412 | SHORTSWAP32((video_font_draw_table16 |
| 413 | [bits >> 2 & 3] & eorx) ^ |
| 414 | bgx); |
| 415 | ((u32 *) dest)[3] = |
| 416 | SHORTSWAP32((video_font_draw_table16 |
| 417 | [bits & 3] & eorx) ^ |
| 418 | bgx); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 419 | } |
| 420 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; |
| 421 | s++; |
| 422 | } |
| 423 | break; |
| 424 | |
| 425 | case GDF_32BIT_X888RGB: |
| 426 | while (count--) { |
| 427 | c = *s; |
| 428 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; |
| 429 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 430 | rows--; dest += VIDEO_LINE_LEN) { |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 431 | u8 bits = *cdat++; |
| 432 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 433 | ((u32 *) dest)[0] = |
| 434 | SWAP32((video_font_draw_table32 |
| 435 | [bits >> 4][0] & eorx) ^ bgx); |
| 436 | ((u32 *) dest)[1] = |
| 437 | SWAP32((video_font_draw_table32 |
| 438 | [bits >> 4][1] & eorx) ^ bgx); |
| 439 | ((u32 *) dest)[2] = |
| 440 | SWAP32((video_font_draw_table32 |
| 441 | [bits >> 4][2] & eorx) ^ bgx); |
| 442 | ((u32 *) dest)[3] = |
| 443 | SWAP32((video_font_draw_table32 |
| 444 | [bits >> 4][3] & eorx) ^ bgx); |
Marek Vasut | fd8cf99 | 2013-07-30 23:37:59 +0200 | [diff] [blame] | 445 | |
| 446 | |
| 447 | if (VIDEO_FONT_WIDTH == 4) |
| 448 | continue; |
| 449 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 450 | ((u32 *) dest)[4] = |
| 451 | SWAP32((video_font_draw_table32 |
| 452 | [bits & 15][0] & eorx) ^ bgx); |
| 453 | ((u32 *) dest)[5] = |
| 454 | SWAP32((video_font_draw_table32 |
| 455 | [bits & 15][1] & eorx) ^ bgx); |
| 456 | ((u32 *) dest)[6] = |
| 457 | SWAP32((video_font_draw_table32 |
| 458 | [bits & 15][2] & eorx) ^ bgx); |
| 459 | ((u32 *) dest)[7] = |
| 460 | SWAP32((video_font_draw_table32 |
| 461 | [bits & 15][3] & eorx) ^ bgx); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 462 | } |
| 463 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; |
| 464 | s++; |
| 465 | } |
| 466 | break; |
| 467 | |
| 468 | case GDF_24BIT_888RGB: |
| 469 | while (count--) { |
| 470 | c = *s; |
| 471 | cdat = video_fontdata + c * VIDEO_FONT_HEIGHT; |
| 472 | for (rows = VIDEO_FONT_HEIGHT, dest = dest0; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 473 | rows--; dest += VIDEO_LINE_LEN) { |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 474 | u8 bits = *cdat++; |
| 475 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 476 | ((u32 *) dest)[0] = |
| 477 | (video_font_draw_table24[bits >> 4][0] |
| 478 | & eorx) ^ bgx; |
| 479 | ((u32 *) dest)[1] = |
| 480 | (video_font_draw_table24[bits >> 4][1] |
| 481 | & eorx) ^ bgx; |
| 482 | ((u32 *) dest)[2] = |
| 483 | (video_font_draw_table24[bits >> 4][2] |
| 484 | & eorx) ^ bgx; |
Marek Vasut | fd8cf99 | 2013-07-30 23:37:59 +0200 | [diff] [blame] | 485 | |
| 486 | if (VIDEO_FONT_WIDTH == 4) |
| 487 | continue; |
| 488 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 489 | ((u32 *) dest)[3] = |
| 490 | (video_font_draw_table24[bits & 15][0] |
| 491 | & eorx) ^ bgx; |
| 492 | ((u32 *) dest)[4] = |
| 493 | (video_font_draw_table24[bits & 15][1] |
| 494 | & eorx) ^ bgx; |
| 495 | ((u32 *) dest)[5] = |
| 496 | (video_font_draw_table24[bits & 15][2] |
| 497 | & eorx) ^ bgx; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 498 | } |
| 499 | dest0 += VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE; |
| 500 | s++; |
| 501 | } |
| 502 | break; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 503 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 504 | } |
| 505 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 506 | static inline void video_drawstring(int xx, int yy, unsigned char *s) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 507 | { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 508 | video_drawchars(xx, yy, s, strlen((char *) s)); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 509 | } |
| 510 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 511 | static void video_putchar(int xx, int yy, unsigned char c) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 512 | { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 513 | video_drawchars(xx, yy + video_logo_height, &c, 1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 514 | } |
| 515 | |
Simon Glass | 7fe0933 | 2015-10-18 21:17:18 -0600 | [diff] [blame] | 516 | #if defined(CONFIG_VIDEO_SW_CURSOR) |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 517 | static void video_set_cursor(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 518 | { |
Gabe Black | 03d31fc | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 519 | if (cursor_state) |
| 520 | console_cursor(0); |
| 521 | console_cursor(1); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 522 | } |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 523 | |
Anatolij Gustschin | a45adde | 2011-12-07 03:58:10 +0000 | [diff] [blame] | 524 | static void video_invertchar(int xx, int yy) |
| 525 | { |
| 526 | int firstx = xx * VIDEO_PIXEL_SIZE; |
| 527 | int lastx = (xx + VIDEO_FONT_WIDTH) * VIDEO_PIXEL_SIZE; |
| 528 | int firsty = yy * VIDEO_LINE_LEN; |
| 529 | int lasty = (yy + VIDEO_FONT_HEIGHT) * VIDEO_LINE_LEN; |
| 530 | int x, y; |
| 531 | for (y = firsty; y < lasty; y += VIDEO_LINE_LEN) { |
| 532 | for (x = firstx; x < lastx; x++) { |
| 533 | u8 *dest = (u8 *)(video_fb_address) + x + y; |
| 534 | *dest = ~*dest; |
| 535 | } |
| 536 | } |
| 537 | } |
Gabe Black | 03d31fc | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 538 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 539 | void console_cursor(int state) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 540 | { |
Gabe Black | 03d31fc | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 541 | if (cursor_state != state) { |
| 542 | if (cursor_state) { |
| 543 | /* turn off the cursor */ |
| 544 | video_invertchar(old_col * VIDEO_FONT_WIDTH, |
| 545 | old_row * VIDEO_FONT_HEIGHT + |
| 546 | video_logo_height); |
| 547 | } else { |
| 548 | /* turn off the cursor and record where it is */ |
| 549 | video_invertchar(console_col * VIDEO_FONT_WIDTH, |
| 550 | console_row * VIDEO_FONT_HEIGHT + |
| 551 | video_logo_height); |
| 552 | old_col = console_col; |
| 553 | old_row = console_row; |
| 554 | } |
| 555 | cursor_state = state; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 556 | } |
Eric Nelson | db0d47d | 2013-05-06 14:27:28 +0200 | [diff] [blame] | 557 | if (cfb_do_flush_cache) |
| 558 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 559 | } |
| 560 | #endif |
| 561 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 562 | #ifndef VIDEO_HW_RECTFILL |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 563 | static void memsetl(int *p, int c, int v) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 564 | { |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 565 | while (c--) |
| 566 | *(p++) = v; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 567 | } |
| 568 | #endif |
| 569 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 570 | #ifndef VIDEO_HW_BITBLT |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 571 | static void memcpyl(int *d, int *s, int c) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 572 | { |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 573 | while (c--) |
| 574 | *(d++) = *(s++); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 575 | } |
| 576 | #endif |
| 577 | |
Pali Rohár | 90f60a8 | 2012-04-28 07:26:44 +0000 | [diff] [blame] | 578 | static void console_clear_line(int line, int begin, int end) |
| 579 | { |
| 580 | #ifdef VIDEO_HW_RECTFILL |
| 581 | video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */ |
| 582 | VIDEO_FONT_WIDTH * begin, /* dest pos x */ |
| 583 | video_logo_height + |
| 584 | VIDEO_FONT_HEIGHT * line, /* dest pos y */ |
| 585 | VIDEO_FONT_WIDTH * (end - begin + 1), /* fr. width */ |
| 586 | VIDEO_FONT_HEIGHT, /* frame height */ |
| 587 | bgx /* fill color */ |
| 588 | ); |
| 589 | #else |
| 590 | if (begin == 0 && (end + 1) == CONSOLE_COLS) { |
| 591 | memsetl(CONSOLE_ROW_FIRST + |
| 592 | CONSOLE_ROW_SIZE * line, /* offset of row */ |
| 593 | CONSOLE_ROW_SIZE >> 2, /* length of row */ |
| 594 | bgx /* fill color */ |
| 595 | ); |
| 596 | } else { |
| 597 | void *offset; |
| 598 | int i, size; |
| 599 | |
| 600 | offset = CONSOLE_ROW_FIRST + |
| 601 | CONSOLE_ROW_SIZE * line + /* offset of row */ |
| 602 | VIDEO_FONT_WIDTH * |
| 603 | VIDEO_PIXEL_SIZE * begin; /* offset of col */ |
| 604 | size = VIDEO_FONT_WIDTH * VIDEO_PIXEL_SIZE * (end - begin + 1); |
| 605 | size >>= 2; /* length to end for memsetl() */ |
| 606 | /* fill at col offset of i'th line using bgx as fill color */ |
| 607 | for (i = 0; i < VIDEO_FONT_HEIGHT; i++) |
| 608 | memsetl(offset + i * VIDEO_LINE_LEN, size, bgx); |
| 609 | } |
| 610 | #endif |
| 611 | } |
| 612 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 613 | static void console_scrollup(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 614 | { |
Simon Glass | 3c0b668 | 2015-01-01 16:17:57 -0700 | [diff] [blame] | 615 | const int rows = CONFIG_CONSOLE_SCROLL_LINES; |
| 616 | int i; |
| 617 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 618 | /* copy up rows ignoring the first one */ |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 619 | |
| 620 | #ifdef VIDEO_HW_BITBLT |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 621 | video_hw_bitblt(VIDEO_PIXEL_SIZE, /* bytes per pixel */ |
| 622 | 0, /* source pos x */ |
| 623 | video_logo_height + |
Simon Glass | 3c0b668 | 2015-01-01 16:17:57 -0700 | [diff] [blame] | 624 | VIDEO_FONT_HEIGHT * rows, /* source pos y */ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 625 | 0, /* dest pos x */ |
| 626 | video_logo_height, /* dest pos y */ |
| 627 | VIDEO_VISIBLE_COLS, /* frame width */ |
| 628 | VIDEO_VISIBLE_ROWS |
| 629 | - video_logo_height |
Simon Glass | 3c0b668 | 2015-01-01 16:17:57 -0700 | [diff] [blame] | 630 | - VIDEO_FONT_HEIGHT * rows /* frame height */ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 631 | ); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 632 | #else |
Simon Glass | 3c0b668 | 2015-01-01 16:17:57 -0700 | [diff] [blame] | 633 | memcpyl(CONSOLE_ROW_FIRST, CONSOLE_ROW_FIRST + rows * CONSOLE_ROW_SIZE, |
| 634 | (CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows) >> 2); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 635 | #endif |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 636 | /* clear the last one */ |
Simon Glass | 3c0b668 | 2015-01-01 16:17:57 -0700 | [diff] [blame] | 637 | for (i = 1; i <= rows; i++) |
| 638 | console_clear_line(CONSOLE_ROWS - i, 0, CONSOLE_COLS - 1); |
| 639 | |
| 640 | /* Decrement row number */ |
| 641 | console_row -= rows; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 642 | } |
| 643 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 644 | static void console_back(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 645 | { |
Timur Tabi | 6561863 | 2010-08-27 15:45:47 -0500 | [diff] [blame] | 646 | console_col--; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 647 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 648 | if (console_col < 0) { |
| 649 | console_col = CONSOLE_COLS - 1; |
| 650 | console_row--; |
| 651 | if (console_row < 0) |
| 652 | console_row = 0; |
| 653 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Pali Rohár | 33a35bb | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 656 | #ifdef CONFIG_CFB_CONSOLE_ANSI |
| 657 | |
| 658 | static void console_clear(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 659 | { |
Pali Rohár | 33a35bb | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 660 | #ifdef VIDEO_HW_RECTFILL |
| 661 | video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */ |
| 662 | 0, /* dest pos x */ |
| 663 | video_logo_height, /* dest pos y */ |
| 664 | VIDEO_VISIBLE_COLS, /* frame width */ |
| 665 | VIDEO_VISIBLE_ROWS, /* frame height */ |
| 666 | bgx /* fill color */ |
| 667 | ); |
| 668 | #else |
| 669 | memsetl(CONSOLE_ROW_FIRST, CONSOLE_SIZE, bgx); |
| 670 | #endif |
| 671 | } |
| 672 | |
| 673 | static void console_cursor_fix(void) |
| 674 | { |
| 675 | if (console_row < 0) |
| 676 | console_row = 0; |
| 677 | if (console_row >= CONSOLE_ROWS) |
| 678 | console_row = CONSOLE_ROWS - 1; |
| 679 | if (console_col < 0) |
| 680 | console_col = 0; |
| 681 | if (console_col >= CONSOLE_COLS) |
| 682 | console_col = CONSOLE_COLS - 1; |
| 683 | } |
| 684 | |
| 685 | static void console_cursor_up(int n) |
| 686 | { |
| 687 | console_row -= n; |
| 688 | console_cursor_fix(); |
| 689 | } |
| 690 | |
| 691 | static void console_cursor_down(int n) |
| 692 | { |
| 693 | console_row += n; |
| 694 | console_cursor_fix(); |
| 695 | } |
| 696 | |
| 697 | static void console_cursor_left(int n) |
| 698 | { |
| 699 | console_col -= n; |
| 700 | console_cursor_fix(); |
| 701 | } |
| 702 | |
| 703 | static void console_cursor_right(int n) |
| 704 | { |
| 705 | console_col += n; |
| 706 | console_cursor_fix(); |
| 707 | } |
| 708 | |
| 709 | static void console_cursor_set_position(int row, int col) |
| 710 | { |
| 711 | if (console_row != -1) |
| 712 | console_row = row; |
| 713 | if (console_col != -1) |
| 714 | console_col = col; |
| 715 | console_cursor_fix(); |
| 716 | } |
| 717 | |
| 718 | static void console_previousline(int n) |
| 719 | { |
| 720 | /* FIXME: also scroll terminal ? */ |
| 721 | console_row -= n; |
| 722 | console_cursor_fix(); |
| 723 | } |
| 724 | |
| 725 | static void console_swap_colors(void) |
| 726 | { |
| 727 | eorx = fgx; |
| 728 | fgx = bgx; |
| 729 | bgx = eorx; |
| 730 | eorx = fgx ^ bgx; |
| 731 | } |
| 732 | |
| 733 | static inline int console_cursor_is_visible(void) |
| 734 | { |
| 735 | return !ansi_cursor_hidden; |
| 736 | } |
| 737 | #else |
| 738 | static inline int console_cursor_is_visible(void) |
| 739 | { |
| 740 | return 1; |
| 741 | } |
| 742 | #endif |
| 743 | |
| 744 | static void console_newline(int n) |
| 745 | { |
| 746 | console_row += n; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 747 | console_col = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 748 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 749 | /* Check if we need to scroll the terminal */ |
| 750 | if (console_row >= CONSOLE_ROWS) { |
| 751 | /* Scroll everything up */ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 752 | console_scrollup(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 753 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 754 | } |
| 755 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 756 | static void console_cr(void) |
Anatolij Gustschin | 20c450e | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 757 | { |
Timur Tabi | 6561863 | 2010-08-27 15:45:47 -0500 | [diff] [blame] | 758 | console_col = 0; |
Anatolij Gustschin | 20c450e | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 759 | } |
| 760 | |
Pali Rohár | 33a35bb | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 761 | static void parse_putc(const char c) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 762 | { |
Anatolij Gustschin | 20c450e | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 763 | static int nl = 1; |
| 764 | |
Pali Rohár | 33a35bb | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 765 | if (console_cursor_is_visible()) |
| 766 | CURSOR_OFF; |
Gabe Black | 03d31fc | 2011-11-30 13:50:50 +0000 | [diff] [blame] | 767 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 768 | switch (c) { |
Anatolij Gustschin | 20c450e | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 769 | case 13: /* back to first column */ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 770 | console_cr(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 771 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 772 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 773 | case '\n': /* next line */ |
Heinrich Schuchardt | 41ec127 | 2018-03-18 14:24:39 +0100 | [diff] [blame] | 774 | if (console_col || nl) |
Pali Rohár | 33a35bb | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 775 | console_newline(1); |
Anatolij Gustschin | 20c450e | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 776 | nl = 1; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 777 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 778 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 779 | case 9: /* tab 8 */ |
Timur Tabi | 6561863 | 2010-08-27 15:45:47 -0500 | [diff] [blame] | 780 | console_col |= 0x0008; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 781 | console_col &= ~0x0007; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 782 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 783 | if (console_col >= CONSOLE_COLS) |
Pali Rohár | 33a35bb | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 784 | console_newline(1); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 785 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 786 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 787 | case 8: /* backspace */ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 788 | console_back(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 789 | break; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 790 | |
Pali Rohár | 24fe06c | 2012-04-28 07:26:47 +0000 | [diff] [blame] | 791 | case 7: /* bell */ |
| 792 | break; /* ignored */ |
| 793 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 794 | default: /* draw the char */ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 795 | video_putchar(console_col * VIDEO_FONT_WIDTH, |
| 796 | console_row * VIDEO_FONT_HEIGHT, c); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 797 | console_col++; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 798 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 799 | /* check for newline */ |
Anatolij Gustschin | 20c450e | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 800 | if (console_col >= CONSOLE_COLS) { |
Pali Rohár | 33a35bb | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 801 | console_newline(1); |
Anatolij Gustschin | 20c450e | 2008-01-11 02:39:47 +0100 | [diff] [blame] | 802 | nl = 0; |
| 803 | } |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 804 | } |
Pali Rohár | 33a35bb | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 805 | |
| 806 | if (console_cursor_is_visible()) |
| 807 | CURSOR_SET; |
| 808 | } |
| 809 | |
Simon Glass | 0a6eac8 | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 810 | static void cfb_video_putc(struct stdio_dev *dev, const char c) |
Pali Rohár | 33a35bb | 2012-10-19 13:30:09 +0000 | [diff] [blame] | 811 | { |
| 812 | #ifdef CONFIG_CFB_CONSOLE_ANSI |
| 813 | int i; |
| 814 | |
| 815 | if (c == 27) { |
| 816 | for (i = 0; i < ansi_buf_size; ++i) |
| 817 | parse_putc(ansi_buf[i]); |
| 818 | ansi_buf[0] = 27; |
| 819 | ansi_buf_size = 1; |
| 820 | return; |
| 821 | } |
| 822 | |
| 823 | if (ansi_buf_size > 0) { |
| 824 | /* |
| 825 | * 0 - ESC |
| 826 | * 1 - [ |
| 827 | * 2 - num1 |
| 828 | * 3 - .. |
| 829 | * 4 - ; |
| 830 | * 5 - num2 |
| 831 | * 6 - .. |
| 832 | * - cchar |
| 833 | */ |
| 834 | int next = 0; |
| 835 | |
| 836 | int flush = 0; |
| 837 | int fail = 0; |
| 838 | |
| 839 | int num1 = 0; |
| 840 | int num2 = 0; |
| 841 | int cchar = 0; |
| 842 | |
| 843 | ansi_buf[ansi_buf_size++] = c; |
| 844 | |
| 845 | if (ansi_buf_size >= sizeof(ansi_buf)) |
| 846 | fail = 1; |
| 847 | |
| 848 | for (i = 0; i < ansi_buf_size; ++i) { |
| 849 | if (fail) |
| 850 | break; |
| 851 | |
| 852 | switch (next) { |
| 853 | case 0: |
| 854 | if (ansi_buf[i] == 27) |
| 855 | next = 1; |
| 856 | else |
| 857 | fail = 1; |
| 858 | break; |
| 859 | |
| 860 | case 1: |
| 861 | if (ansi_buf[i] == '[') |
| 862 | next = 2; |
| 863 | else |
| 864 | fail = 1; |
| 865 | break; |
| 866 | |
| 867 | case 2: |
| 868 | if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') { |
| 869 | num1 = ansi_buf[i]-'0'; |
| 870 | next = 3; |
| 871 | } else if (ansi_buf[i] != '?') { |
| 872 | --i; |
| 873 | num1 = 1; |
| 874 | next = 4; |
| 875 | } |
| 876 | break; |
| 877 | |
| 878 | case 3: |
| 879 | if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') { |
| 880 | num1 *= 10; |
| 881 | num1 += ansi_buf[i]-'0'; |
| 882 | } else { |
| 883 | --i; |
| 884 | next = 4; |
| 885 | } |
| 886 | break; |
| 887 | |
| 888 | case 4: |
| 889 | if (ansi_buf[i] != ';') { |
| 890 | --i; |
| 891 | next = 7; |
| 892 | } else |
| 893 | next = 5; |
| 894 | break; |
| 895 | |
| 896 | case 5: |
| 897 | if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') { |
| 898 | num2 = ansi_buf[i]-'0'; |
| 899 | next = 6; |
| 900 | } else |
| 901 | fail = 1; |
| 902 | break; |
| 903 | |
| 904 | case 6: |
| 905 | if (ansi_buf[i] >= '0' && ansi_buf[i] <= '9') { |
| 906 | num2 *= 10; |
| 907 | num2 += ansi_buf[i]-'0'; |
| 908 | } else { |
| 909 | --i; |
| 910 | next = 7; |
| 911 | } |
| 912 | break; |
| 913 | |
| 914 | case 7: |
| 915 | if ((ansi_buf[i] >= 'A' && ansi_buf[i] <= 'H') |
| 916 | || ansi_buf[i] == 'J' |
| 917 | || ansi_buf[i] == 'K' |
| 918 | || ansi_buf[i] == 'h' |
| 919 | || ansi_buf[i] == 'l' |
| 920 | || ansi_buf[i] == 'm') { |
| 921 | cchar = ansi_buf[i]; |
| 922 | flush = 1; |
| 923 | } else |
| 924 | fail = 1; |
| 925 | break; |
| 926 | } |
| 927 | } |
| 928 | |
| 929 | if (fail) { |
| 930 | for (i = 0; i < ansi_buf_size; ++i) |
| 931 | parse_putc(ansi_buf[i]); |
| 932 | ansi_buf_size = 0; |
| 933 | return; |
| 934 | } |
| 935 | |
| 936 | if (flush) { |
| 937 | if (!ansi_cursor_hidden) |
| 938 | CURSOR_OFF; |
| 939 | ansi_buf_size = 0; |
| 940 | switch (cchar) { |
| 941 | case 'A': |
| 942 | /* move cursor num1 rows up */ |
| 943 | console_cursor_up(num1); |
| 944 | break; |
| 945 | case 'B': |
| 946 | /* move cursor num1 rows down */ |
| 947 | console_cursor_down(num1); |
| 948 | break; |
| 949 | case 'C': |
| 950 | /* move cursor num1 columns forward */ |
| 951 | console_cursor_right(num1); |
| 952 | break; |
| 953 | case 'D': |
| 954 | /* move cursor num1 columns back */ |
| 955 | console_cursor_left(num1); |
| 956 | break; |
| 957 | case 'E': |
| 958 | /* move cursor num1 rows up at begin of row */ |
| 959 | console_previousline(num1); |
| 960 | break; |
| 961 | case 'F': |
| 962 | /* move cursor num1 rows down at begin of row */ |
| 963 | console_newline(num1); |
| 964 | break; |
| 965 | case 'G': |
| 966 | /* move cursor to column num1 */ |
| 967 | console_cursor_set_position(-1, num1-1); |
| 968 | break; |
| 969 | case 'H': |
| 970 | /* move cursor to row num1, column num2 */ |
| 971 | console_cursor_set_position(num1-1, num2-1); |
| 972 | break; |
| 973 | case 'J': |
| 974 | /* clear console and move cursor to 0, 0 */ |
| 975 | console_clear(); |
| 976 | console_cursor_set_position(0, 0); |
| 977 | break; |
| 978 | case 'K': |
| 979 | /* clear line */ |
| 980 | if (num1 == 0) |
| 981 | console_clear_line(console_row, |
| 982 | console_col, |
| 983 | CONSOLE_COLS-1); |
| 984 | else if (num1 == 1) |
| 985 | console_clear_line(console_row, |
| 986 | 0, console_col); |
| 987 | else |
| 988 | console_clear_line(console_row, |
| 989 | 0, CONSOLE_COLS-1); |
| 990 | break; |
| 991 | case 'h': |
| 992 | ansi_cursor_hidden = 0; |
| 993 | break; |
| 994 | case 'l': |
| 995 | ansi_cursor_hidden = 1; |
| 996 | break; |
| 997 | case 'm': |
| 998 | if (num1 == 0) { /* reset swapped colors */ |
| 999 | if (ansi_colors_need_revert) { |
| 1000 | console_swap_colors(); |
| 1001 | ansi_colors_need_revert = 0; |
| 1002 | } |
| 1003 | } else if (num1 == 7) { /* once swap colors */ |
| 1004 | if (!ansi_colors_need_revert) { |
| 1005 | console_swap_colors(); |
| 1006 | ansi_colors_need_revert = 1; |
| 1007 | } |
| 1008 | } |
| 1009 | break; |
| 1010 | } |
| 1011 | if (!ansi_cursor_hidden) |
| 1012 | CURSOR_SET; |
| 1013 | } |
| 1014 | } else { |
| 1015 | parse_putc(c); |
| 1016 | } |
| 1017 | #else |
| 1018 | parse_putc(c); |
| 1019 | #endif |
Eric Nelson | db0d47d | 2013-05-06 14:27:28 +0200 | [diff] [blame] | 1020 | if (cfb_do_flush_cache) |
| 1021 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); |
Timur Tabi | 6561863 | 2010-08-27 15:45:47 -0500 | [diff] [blame] | 1022 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1023 | |
Simon Glass | 0a6eac8 | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 1024 | static void cfb_video_puts(struct stdio_dev *dev, const char *s) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1025 | { |
Soeren Moch | d37e96e | 2014-10-24 16:33:30 +0200 | [diff] [blame] | 1026 | int flush = cfb_do_flush_cache; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1027 | int count = strlen(s); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1028 | |
Soeren Moch | d37e96e | 2014-10-24 16:33:30 +0200 | [diff] [blame] | 1029 | /* temporarily disable cache flush */ |
| 1030 | cfb_do_flush_cache = 0; |
| 1031 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1032 | while (count--) |
Simon Glass | 0a6eac8 | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 1033 | cfb_video_putc(dev, *s++); |
Soeren Moch | d37e96e | 2014-10-24 16:33:30 +0200 | [diff] [blame] | 1034 | |
| 1035 | if (flush) { |
| 1036 | cfb_do_flush_cache = flush; |
| 1037 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); |
| 1038 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
Anatolij Gustschin | 1054382 | 2010-05-01 22:21:09 +0200 | [diff] [blame] | 1041 | /* |
| 1042 | * Do not enforce drivers (or board code) to provide empty |
| 1043 | * video_set_lut() if they do not support 8 bpp format. |
| 1044 | * Implement weak default function instead. |
| 1045 | */ |
Jeroen Hofstee | 69d2754 | 2014-10-08 22:57:30 +0200 | [diff] [blame] | 1046 | __weak void video_set_lut(unsigned int index, unsigned char r, |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1047 | unsigned char g, unsigned char b) |
Anatolij Gustschin | 1054382 | 2010-05-01 22:21:09 +0200 | [diff] [blame] | 1048 | { |
| 1049 | } |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1050 | |
Jon Loeliger | 07d38a1 | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 1051 | #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1052 | |
| 1053 | #define FILL_8BIT_332RGB(r,g,b) { \ |
| 1054 | *fb = ((r>>5)<<5) | ((g>>5)<<2) | (b>>6); \ |
| 1055 | fb ++; \ |
| 1056 | } |
| 1057 | |
| 1058 | #define FILL_15BIT_555RGB(r,g,b) { \ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1059 | *(unsigned short *)fb = \ |
| 1060 | SWAP16((unsigned short)(((r>>3)<<10) | \ |
| 1061 | ((g>>3)<<5) | \ |
| 1062 | (b>>3))); \ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1063 | fb += 2; \ |
| 1064 | } |
| 1065 | |
| 1066 | #define FILL_16BIT_565RGB(r,g,b) { \ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1067 | *(unsigned short *)fb = \ |
| 1068 | SWAP16((unsigned short)((((r)>>3)<<11)| \ |
| 1069 | (((g)>>2)<<5) | \ |
| 1070 | ((b)>>3))); \ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1071 | fb += 2; \ |
| 1072 | } |
| 1073 | |
| 1074 | #define FILL_32BIT_X888RGB(r,g,b) { \ |
Andre Przywara | 1d4ed26 | 2017-03-06 01:13:38 +0000 | [diff] [blame] | 1075 | *(u32 *)fb = \ |
| 1076 | SWAP32((unsigned int)(((r<<16) | \ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1077 | (g<<8) | \ |
| 1078 | b))); \ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1079 | fb += 4; \ |
| 1080 | } |
| 1081 | |
| 1082 | #ifdef VIDEO_FB_LITTLE_ENDIAN |
| 1083 | #define FILL_24BIT_888RGB(r,g,b) { \ |
| 1084 | fb[0] = b; \ |
| 1085 | fb[1] = g; \ |
| 1086 | fb[2] = r; \ |
| 1087 | fb += 3; \ |
| 1088 | } |
| 1089 | #else |
| 1090 | #define FILL_24BIT_888RGB(r,g,b) { \ |
| 1091 | fb[0] = r; \ |
| 1092 | fb[1] = g; \ |
| 1093 | fb[2] = b; \ |
| 1094 | fb += 3; \ |
| 1095 | } |
| 1096 | #endif |
| 1097 | |
Anatolij Gustschin | e84d568 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1098 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1099 | static inline void fill_555rgb_pswap(uchar *fb, int x, u8 r, u8 g, u8 b) |
Anatolij Gustschin | e84d568 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1100 | { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1101 | ushort *dst = (ushort *) fb; |
| 1102 | ushort color = (ushort) (((r >> 3) << 10) | |
| 1103 | ((g >> 3) << 5) | |
| 1104 | (b >> 3)); |
Anatolij Gustschin | e84d568 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1105 | if (x & 1) |
| 1106 | *(--dst) = color; |
| 1107 | else |
| 1108 | *(++dst) = color; |
| 1109 | } |
| 1110 | #endif |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1111 | |
| 1112 | /* |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1113 | * RLE8 bitmap support |
| 1114 | */ |
| 1115 | |
| 1116 | #ifdef CONFIG_VIDEO_BMP_RLE8 |
| 1117 | /* Pre-calculated color table entry */ |
| 1118 | struct palette { |
| 1119 | union { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1120 | unsigned short w; /* word */ |
| 1121 | unsigned int dw; /* double word */ |
| 1122 | } ce; /* color entry */ |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1123 | }; |
| 1124 | |
| 1125 | /* |
| 1126 | * Helper to draw encoded/unencoded run. |
| 1127 | */ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1128 | static void draw_bitmap(uchar **fb, uchar *bm, struct palette *p, |
| 1129 | int cnt, int enc) |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1130 | { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1131 | ulong addr = (ulong) *fb; |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1132 | int *off; |
| 1133 | int enc_off = 1; |
| 1134 | int i; |
| 1135 | |
| 1136 | /* |
| 1137 | * Setup offset of the color index in the bitmap. |
| 1138 | * Color index of encoded run is at offset 1. |
| 1139 | */ |
| 1140 | off = enc ? &enc_off : &i; |
| 1141 | |
| 1142 | switch (VIDEO_DATA_FORMAT) { |
| 1143 | case GDF__8BIT_INDEX: |
| 1144 | for (i = 0; i < cnt; i++) |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1145 | *(unsigned char *) addr++ = bm[*off]; |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1146 | break; |
| 1147 | case GDF_15BIT_555RGB: |
| 1148 | case GDF_16BIT_565RGB: |
| 1149 | /* differences handled while pre-calculating palette */ |
| 1150 | for (i = 0; i < cnt; i++) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1151 | *(unsigned short *) addr = p[bm[*off]].ce.w; |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1152 | addr += 2; |
| 1153 | } |
| 1154 | break; |
| 1155 | case GDF_32BIT_X888RGB: |
| 1156 | for (i = 0; i < cnt; i++) { |
Andre Przywara | 1d4ed26 | 2017-03-06 01:13:38 +0000 | [diff] [blame] | 1157 | *(u32 *) addr = p[bm[*off]].ce.dw; |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1158 | addr += 4; |
| 1159 | } |
| 1160 | break; |
| 1161 | } |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1162 | *fb = (uchar *) addr; /* return modified address */ |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1163 | } |
| 1164 | |
Simon Glass | 1c3dbe5 | 2015-05-13 07:02:27 -0600 | [diff] [blame] | 1165 | static int display_rle8_bitmap(struct bmp_image *img, int xoff, int yoff, |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1166 | int width, int height) |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1167 | { |
| 1168 | unsigned char *bm; |
| 1169 | unsigned char *fbp; |
| 1170 | unsigned int cnt, runlen; |
| 1171 | int decode = 1; |
| 1172 | int x, y, bpp, i, ncolors; |
| 1173 | struct palette p[256]; |
Simon Glass | 1c3dbe5 | 2015-05-13 07:02:27 -0600 | [diff] [blame] | 1174 | struct bmp_color_table_entry cte; |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1175 | int green_shift, red_off; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1176 | int limit = (VIDEO_LINE_LEN / VIDEO_PIXEL_SIZE) * VIDEO_ROWS; |
Anatolij Gustschin | 74446b6 | 2011-02-21 21:33:29 +0100 | [diff] [blame] | 1177 | int pixels = 0; |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1178 | |
| 1179 | x = 0; |
| 1180 | y = __le32_to_cpu(img->header.height) - 1; |
| 1181 | ncolors = __le32_to_cpu(img->header.colors_used); |
| 1182 | bpp = VIDEO_PIXEL_SIZE; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1183 | fbp = (unsigned char *) ((unsigned int) video_fb_address + |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1184 | (y + yoff) * VIDEO_LINE_LEN + |
| 1185 | xoff * bpp); |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1186 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1187 | bm = (uchar *) img + __le32_to_cpu(img->header.data_offset); |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1188 | |
| 1189 | /* pre-calculate and setup palette */ |
| 1190 | switch (VIDEO_DATA_FORMAT) { |
| 1191 | case GDF__8BIT_INDEX: |
| 1192 | for (i = 0; i < ncolors; i++) { |
| 1193 | cte = img->color_table[i]; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1194 | video_set_lut(i, cte.red, cte.green, cte.blue); |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1195 | } |
| 1196 | break; |
| 1197 | case GDF_15BIT_555RGB: |
| 1198 | case GDF_16BIT_565RGB: |
| 1199 | if (VIDEO_DATA_FORMAT == GDF_15BIT_555RGB) { |
| 1200 | green_shift = 3; |
| 1201 | red_off = 10; |
| 1202 | } else { |
| 1203 | green_shift = 2; |
| 1204 | red_off = 11; |
| 1205 | } |
| 1206 | for (i = 0; i < ncolors; i++) { |
| 1207 | cte = img->color_table[i]; |
| 1208 | p[i].ce.w = SWAP16((unsigned short) |
| 1209 | (((cte.red >> 3) << red_off) | |
| 1210 | ((cte.green >> green_shift) << 5) | |
| 1211 | cte.blue >> 3)); |
| 1212 | } |
| 1213 | break; |
| 1214 | case GDF_32BIT_X888RGB: |
| 1215 | for (i = 0; i < ncolors; i++) { |
| 1216 | cte = img->color_table[i]; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1217 | p[i].ce.dw = SWAP32((cte.red << 16) | |
| 1218 | (cte.green << 8) | |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1219 | cte.blue); |
| 1220 | } |
| 1221 | break; |
| 1222 | default: |
| 1223 | printf("RLE Bitmap unsupported in video mode 0x%x\n", |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1224 | VIDEO_DATA_FORMAT); |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1225 | return -1; |
| 1226 | } |
| 1227 | |
| 1228 | while (decode) { |
| 1229 | switch (bm[0]) { |
| 1230 | case 0: |
| 1231 | switch (bm[1]) { |
| 1232 | case 0: |
| 1233 | /* scan line end marker */ |
| 1234 | bm += 2; |
| 1235 | x = 0; |
| 1236 | y--; |
| 1237 | fbp = (unsigned char *) |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1238 | ((unsigned int) video_fb_address + |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1239 | (y + yoff) * VIDEO_LINE_LEN + |
| 1240 | xoff * bpp); |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1241 | continue; |
| 1242 | case 1: |
| 1243 | /* end of bitmap data marker */ |
| 1244 | decode = 0; |
| 1245 | break; |
| 1246 | case 2: |
| 1247 | /* run offset marker */ |
| 1248 | x += bm[2]; |
| 1249 | y -= bm[3]; |
| 1250 | fbp = (unsigned char *) |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1251 | ((unsigned int) video_fb_address + |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1252 | (y + yoff) * VIDEO_LINE_LEN + |
| 1253 | xoff * bpp); |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1254 | bm += 4; |
| 1255 | break; |
| 1256 | default: |
| 1257 | /* unencoded run */ |
| 1258 | cnt = bm[1]; |
| 1259 | runlen = cnt; |
Anatolij Gustschin | 74446b6 | 2011-02-21 21:33:29 +0100 | [diff] [blame] | 1260 | pixels += cnt; |
| 1261 | if (pixels > limit) |
| 1262 | goto error; |
| 1263 | |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1264 | bm += 2; |
| 1265 | if (y < height) { |
| 1266 | if (x >= width) { |
| 1267 | x += runlen; |
| 1268 | goto next_run; |
| 1269 | } |
| 1270 | if (x + runlen > width) |
| 1271 | cnt = width - x; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1272 | draw_bitmap(&fbp, bm, p, cnt, 0); |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1273 | x += runlen; |
| 1274 | } |
| 1275 | next_run: |
| 1276 | bm += runlen; |
| 1277 | if (runlen & 1) |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1278 | bm++; /* 0 padding if length is odd */ |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1279 | } |
| 1280 | break; |
| 1281 | default: |
| 1282 | /* encoded run */ |
Anatolij Gustschin | 74446b6 | 2011-02-21 21:33:29 +0100 | [diff] [blame] | 1283 | cnt = bm[0]; |
| 1284 | runlen = cnt; |
| 1285 | pixels += cnt; |
| 1286 | if (pixels > limit) |
| 1287 | goto error; |
| 1288 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1289 | if (y < height) { /* only draw into visible area */ |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1290 | if (x >= width) { |
| 1291 | x += runlen; |
| 1292 | bm += 2; |
| 1293 | continue; |
| 1294 | } |
| 1295 | if (x + runlen > width) |
| 1296 | cnt = width - x; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1297 | draw_bitmap(&fbp, bm, p, cnt, 1); |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1298 | x += runlen; |
| 1299 | } |
| 1300 | bm += 2; |
| 1301 | break; |
| 1302 | } |
| 1303 | } |
Sébastien Szymanski | 47b11c8 | 2018-09-10 09:58:58 +0200 | [diff] [blame] | 1304 | |
| 1305 | if (cfb_do_flush_cache) |
| 1306 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); |
| 1307 | |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1308 | return 0; |
Anatolij Gustschin | 74446b6 | 2011-02-21 21:33:29 +0100 | [diff] [blame] | 1309 | error: |
| 1310 | printf("Error: Too much encoded pixel data, validate your bitmap\n"); |
| 1311 | return -1; |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1312 | } |
| 1313 | #endif |
| 1314 | |
| 1315 | /* |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1316 | * Display the BMP file located at address bmp_image. |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1317 | */ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1318 | int video_display_bitmap(ulong bmp_image, int x, int y) |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1319 | { |
| 1320 | ushort xcount, ycount; |
| 1321 | uchar *fb; |
Simon Glass | 1c3dbe5 | 2015-05-13 07:02:27 -0600 | [diff] [blame] | 1322 | struct bmp_image *bmp = (struct bmp_image *)bmp_image; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1323 | uchar *bmap; |
| 1324 | ushort padded_line; |
| 1325 | unsigned long width, height, bpp; |
| 1326 | unsigned colors; |
| 1327 | unsigned long compression; |
Simon Glass | 1c3dbe5 | 2015-05-13 07:02:27 -0600 | [diff] [blame] | 1328 | struct bmp_color_table_entry cte; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1329 | |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1330 | #ifdef CONFIG_VIDEO_BMP_GZIP |
| 1331 | unsigned char *dst = NULL; |
| 1332 | ulong len; |
| 1333 | #endif |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1334 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1335 | WATCHDOG_RESET(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1336 | |
| 1337 | if (!((bmp->header.signature[0] == 'B') && |
| 1338 | (bmp->header.signature[1] == 'M'))) { |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1339 | |
| 1340 | #ifdef CONFIG_VIDEO_BMP_GZIP |
| 1341 | /* |
| 1342 | * Could be a gzipped bmp image, try to decrompress... |
| 1343 | */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1344 | len = CONFIG_SYS_VIDEO_LOGO_MAX_SIZE; |
| 1345 | dst = malloc(CONFIG_SYS_VIDEO_LOGO_MAX_SIZE); |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 1346 | if (dst == NULL) { |
| 1347 | printf("Error: malloc in gunzip failed!\n"); |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1348 | return 1; |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 1349 | } |
Eric Nelson | 5ca05c8 | 2014-03-08 07:55:52 -0700 | [diff] [blame] | 1350 | /* |
| 1351 | * NB: we need to force offset of +2 |
| 1352 | * See doc/README.displaying-bmps |
| 1353 | */ |
| 1354 | if (gunzip(dst+2, CONFIG_SYS_VIDEO_LOGO_MAX_SIZE-2, |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1355 | (uchar *) bmp_image, |
| 1356 | &len) != 0) { |
| 1357 | printf("Error: no valid bmp or bmp.gz image at %lx\n", |
| 1358 | bmp_image); |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1359 | free(dst); |
| 1360 | return 1; |
| 1361 | } |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 1362 | if (len == CONFIG_SYS_VIDEO_LOGO_MAX_SIZE) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1363 | printf("Image could be truncated " |
| 1364 | "(increase CONFIG_SYS_VIDEO_LOGO_MAX_SIZE)!\n"); |
Stefan Roese | c29ab9d | 2005-10-08 10:19:07 +0200 | [diff] [blame] | 1365 | } |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1366 | |
| 1367 | /* |
| 1368 | * Set addr to decompressed image |
| 1369 | */ |
Simon Glass | 1c3dbe5 | 2015-05-13 07:02:27 -0600 | [diff] [blame] | 1370 | bmp = (struct bmp_image *)(dst+2); |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1371 | |
| 1372 | if (!((bmp->header.signature[0] == 'B') && |
| 1373 | (bmp->header.signature[1] == 'M'))) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1374 | printf("Error: no valid bmp.gz image at %lx\n", |
| 1375 | bmp_image); |
Matthias Fuchs | a49e0d1 | 2008-04-21 11:19:04 +0200 | [diff] [blame] | 1376 | free(dst); |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1377 | return 1; |
| 1378 | } |
| 1379 | #else |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1380 | printf("Error: no valid bmp image at %lx\n", bmp_image); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1381 | return 1; |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1382 | #endif /* CONFIG_VIDEO_BMP_GZIP */ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1383 | } |
| 1384 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1385 | width = le32_to_cpu(bmp->header.width); |
| 1386 | height = le32_to_cpu(bmp->header.height); |
| 1387 | bpp = le16_to_cpu(bmp->header.bit_count); |
| 1388 | colors = le32_to_cpu(bmp->header.colors_used); |
| 1389 | compression = le32_to_cpu(bmp->header.compression); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1390 | |
Marek Vasut | 68da5b1 | 2011-10-21 14:17:04 +0000 | [diff] [blame] | 1391 | debug("Display-bmp: %ld x %ld with %d colors\n", |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1392 | width, height, colors); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1393 | |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1394 | if (compression != BMP_BI_RGB |
| 1395 | #ifdef CONFIG_VIDEO_BMP_RLE8 |
| 1396 | && compression != BMP_BI_RLE8 |
| 1397 | #endif |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1398 | ) { |
| 1399 | printf("Error: compression type %ld not supported\n", |
| 1400 | compression); |
Matthias Fuchs | a49e0d1 | 2008-04-21 11:19:04 +0200 | [diff] [blame] | 1401 | #ifdef CONFIG_VIDEO_BMP_GZIP |
| 1402 | if (dst) |
| 1403 | free(dst); |
| 1404 | #endif |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1405 | return 1; |
| 1406 | } |
| 1407 | |
| 1408 | padded_line = (((width * bpp + 7) / 8) + 3) & ~0x3; |
| 1409 | |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1410 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |
| 1411 | if (x == BMP_ALIGN_CENTER) |
Masahiro Yamada | b414119 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1412 | x = max(0, (int)(VIDEO_VISIBLE_COLS - width) / 2); |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1413 | else if (x < 0) |
Masahiro Yamada | b414119 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1414 | x = max(0, (int)(VIDEO_VISIBLE_COLS - width + x + 1)); |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1415 | |
| 1416 | if (y == BMP_ALIGN_CENTER) |
Masahiro Yamada | b414119 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1417 | y = max(0, (int)(VIDEO_VISIBLE_ROWS - height) / 2); |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1418 | else if (y < 0) |
Masahiro Yamada | b414119 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1419 | y = max(0, (int)(VIDEO_VISIBLE_ROWS - height + y + 1)); |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1420 | #endif /* CONFIG_SPLASH_SCREEN_ALIGN */ |
| 1421 | |
Matthias Weisser | acf3baa | 2013-02-15 03:35:12 +0000 | [diff] [blame] | 1422 | /* |
| 1423 | * Just ignore elements which are completely beyond screen |
| 1424 | * dimensions. |
| 1425 | */ |
| 1426 | if ((x >= VIDEO_VISIBLE_COLS) || (y >= VIDEO_VISIBLE_ROWS)) |
| 1427 | return 0; |
| 1428 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1429 | if ((x + width) > VIDEO_VISIBLE_COLS) |
| 1430 | width = VIDEO_VISIBLE_COLS - x; |
| 1431 | if ((y + height) > VIDEO_VISIBLE_ROWS) |
| 1432 | height = VIDEO_VISIBLE_ROWS - y; |
| 1433 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1434 | bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1435 | fb = (uchar *) (video_fb_address + |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1436 | ((y + height - 1) * VIDEO_LINE_LEN) + |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1437 | x * VIDEO_PIXEL_SIZE); |
| 1438 | |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1439 | #ifdef CONFIG_VIDEO_BMP_RLE8 |
| 1440 | if (compression == BMP_BI_RLE8) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1441 | return display_rle8_bitmap(bmp, x, y, width, height); |
Anatolij Gustschin | d501176 | 2010-03-15 14:50:25 +0100 | [diff] [blame] | 1442 | } |
| 1443 | #endif |
| 1444 | |
Timur Tabi | 68f6618 | 2010-08-23 16:58:00 -0500 | [diff] [blame] | 1445 | /* We handle only 4, 8, or 24 bpp bitmaps */ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1446 | switch (le16_to_cpu(bmp->header.bit_count)) { |
Timur Tabi | 68f6618 | 2010-08-23 16:58:00 -0500 | [diff] [blame] | 1447 | case 4: |
| 1448 | padded_line -= width / 2; |
| 1449 | ycount = height; |
| 1450 | |
| 1451 | switch (VIDEO_DATA_FORMAT) { |
| 1452 | case GDF_32BIT_X888RGB: |
| 1453 | while (ycount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1454 | WATCHDOG_RESET(); |
Timur Tabi | 68f6618 | 2010-08-23 16:58:00 -0500 | [diff] [blame] | 1455 | /* |
| 1456 | * Don't assume that 'width' is an |
| 1457 | * even number |
| 1458 | */ |
| 1459 | for (xcount = 0; xcount < width; xcount++) { |
| 1460 | uchar idx; |
| 1461 | |
| 1462 | if (xcount & 1) { |
| 1463 | idx = *bmap & 0xF; |
| 1464 | bmap++; |
| 1465 | } else |
| 1466 | idx = *bmap >> 4; |
| 1467 | cte = bmp->color_table[idx]; |
| 1468 | FILL_32BIT_X888RGB(cte.red, cte.green, |
| 1469 | cte.blue); |
| 1470 | } |
| 1471 | bmap += padded_line; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1472 | fb -= VIDEO_LINE_LEN + width * |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1473 | VIDEO_PIXEL_SIZE; |
Timur Tabi | 68f6618 | 2010-08-23 16:58:00 -0500 | [diff] [blame] | 1474 | } |
| 1475 | break; |
| 1476 | default: |
| 1477 | puts("4bpp bitmap unsupported with current " |
| 1478 | "video mode\n"); |
| 1479 | break; |
| 1480 | } |
| 1481 | break; |
| 1482 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1483 | case 8: |
| 1484 | padded_line -= width; |
| 1485 | if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) { |
Anatolij Gustschin | 7c050f8 | 2010-06-19 20:41:56 +0200 | [diff] [blame] | 1486 | /* Copy colormap */ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1487 | for (xcount = 0; xcount < colors; ++xcount) { |
| 1488 | cte = bmp->color_table[xcount]; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1489 | video_set_lut(xcount, cte.red, cte.green, |
| 1490 | cte.blue); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1491 | } |
| 1492 | } |
| 1493 | ycount = height; |
| 1494 | switch (VIDEO_DATA_FORMAT) { |
| 1495 | case GDF__8BIT_INDEX: |
| 1496 | while (ycount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1497 | WATCHDOG_RESET(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1498 | xcount = width; |
| 1499 | while (xcount--) { |
| 1500 | *fb++ = *bmap++; |
| 1501 | } |
| 1502 | bmap += padded_line; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1503 | fb -= VIDEO_LINE_LEN + width * |
| 1504 | VIDEO_PIXEL_SIZE; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1505 | } |
| 1506 | break; |
| 1507 | case GDF__8BIT_332RGB: |
| 1508 | while (ycount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1509 | WATCHDOG_RESET(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1510 | xcount = width; |
| 1511 | while (xcount--) { |
| 1512 | cte = bmp->color_table[*bmap++]; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1513 | FILL_8BIT_332RGB(cte.red, cte.green, |
| 1514 | cte.blue); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1515 | } |
| 1516 | bmap += padded_line; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1517 | fb -= VIDEO_LINE_LEN + width * |
| 1518 | VIDEO_PIXEL_SIZE; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1519 | } |
| 1520 | break; |
| 1521 | case GDF_15BIT_555RGB: |
| 1522 | while (ycount--) { |
Anatolij Gustschin | e84d568 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1523 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
| 1524 | int xpos = x; |
| 1525 | #endif |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1526 | WATCHDOG_RESET(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1527 | xcount = width; |
| 1528 | while (xcount--) { |
| 1529 | cte = bmp->color_table[*bmap++]; |
Andrew Dyer | cc34780 | 2008-08-29 12:30:39 -0500 | [diff] [blame] | 1530 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1531 | fill_555rgb_pswap(fb, xpos++, cte.red, |
| 1532 | cte.green, |
| 1533 | cte.blue); |
Anatolij Gustschin | e84d568 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1534 | fb += 2; |
Andrew Dyer | cc34780 | 2008-08-29 12:30:39 -0500 | [diff] [blame] | 1535 | #else |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1536 | FILL_15BIT_555RGB(cte.red, cte.green, |
| 1537 | cte.blue); |
Anatolij Gustschin | e84d568 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1538 | #endif |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1539 | } |
| 1540 | bmap += padded_line; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1541 | fb -= VIDEO_LINE_LEN + width * |
| 1542 | VIDEO_PIXEL_SIZE; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1543 | } |
| 1544 | break; |
| 1545 | case GDF_16BIT_565RGB: |
| 1546 | while (ycount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1547 | WATCHDOG_RESET(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1548 | xcount = width; |
| 1549 | while (xcount--) { |
| 1550 | cte = bmp->color_table[*bmap++]; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1551 | FILL_16BIT_565RGB(cte.red, cte.green, |
| 1552 | cte.blue); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1553 | } |
| 1554 | bmap += padded_line; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1555 | fb -= VIDEO_LINE_LEN + width * |
| 1556 | VIDEO_PIXEL_SIZE; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1557 | } |
| 1558 | break; |
| 1559 | case GDF_32BIT_X888RGB: |
| 1560 | while (ycount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1561 | WATCHDOG_RESET(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1562 | xcount = width; |
| 1563 | while (xcount--) { |
| 1564 | cte = bmp->color_table[*bmap++]; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1565 | FILL_32BIT_X888RGB(cte.red, cte.green, |
| 1566 | cte.blue); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1567 | } |
| 1568 | bmap += padded_line; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1569 | fb -= VIDEO_LINE_LEN + width * |
| 1570 | VIDEO_PIXEL_SIZE; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1571 | } |
| 1572 | break; |
| 1573 | case GDF_24BIT_888RGB: |
| 1574 | while (ycount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1575 | WATCHDOG_RESET(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1576 | xcount = width; |
| 1577 | while (xcount--) { |
| 1578 | cte = bmp->color_table[*bmap++]; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1579 | FILL_24BIT_888RGB(cte.red, cte.green, |
| 1580 | cte.blue); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1581 | } |
| 1582 | bmap += padded_line; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1583 | fb -= VIDEO_LINE_LEN + width * |
| 1584 | VIDEO_PIXEL_SIZE; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1585 | } |
| 1586 | break; |
| 1587 | } |
| 1588 | break; |
| 1589 | case 24: |
| 1590 | padded_line -= 3 * width; |
| 1591 | ycount = height; |
| 1592 | switch (VIDEO_DATA_FORMAT) { |
| 1593 | case GDF__8BIT_332RGB: |
| 1594 | while (ycount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1595 | WATCHDOG_RESET(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1596 | xcount = width; |
| 1597 | while (xcount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1598 | FILL_8BIT_332RGB(bmap[2], bmap[1], |
| 1599 | bmap[0]); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1600 | bmap += 3; |
| 1601 | } |
| 1602 | bmap += padded_line; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1603 | fb -= VIDEO_LINE_LEN + width * |
| 1604 | VIDEO_PIXEL_SIZE; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1605 | } |
| 1606 | break; |
| 1607 | case GDF_15BIT_555RGB: |
| 1608 | while (ycount--) { |
Anatolij Gustschin | e84d568 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1609 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
| 1610 | int xpos = x; |
| 1611 | #endif |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1612 | WATCHDOG_RESET(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1613 | xcount = width; |
| 1614 | while (xcount--) { |
Andrew Dyer | cc34780 | 2008-08-29 12:30:39 -0500 | [diff] [blame] | 1615 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1616 | fill_555rgb_pswap(fb, xpos++, bmap[2], |
| 1617 | bmap[1], bmap[0]); |
Anatolij Gustschin | e84d568 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1618 | fb += 2; |
Andrew Dyer | cc34780 | 2008-08-29 12:30:39 -0500 | [diff] [blame] | 1619 | #else |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1620 | FILL_15BIT_555RGB(bmap[2], bmap[1], |
| 1621 | bmap[0]); |
Anatolij Gustschin | e84d568 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1622 | #endif |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1623 | bmap += 3; |
| 1624 | } |
| 1625 | bmap += padded_line; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1626 | fb -= VIDEO_LINE_LEN + width * |
| 1627 | VIDEO_PIXEL_SIZE; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1628 | } |
| 1629 | break; |
| 1630 | case GDF_16BIT_565RGB: |
| 1631 | while (ycount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1632 | WATCHDOG_RESET(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1633 | xcount = width; |
| 1634 | while (xcount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1635 | FILL_16BIT_565RGB(bmap[2], bmap[1], |
| 1636 | bmap[0]); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1637 | bmap += 3; |
| 1638 | } |
| 1639 | bmap += padded_line; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1640 | fb -= VIDEO_LINE_LEN + width * |
| 1641 | VIDEO_PIXEL_SIZE; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1642 | } |
| 1643 | break; |
| 1644 | case GDF_32BIT_X888RGB: |
| 1645 | while (ycount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1646 | WATCHDOG_RESET(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1647 | xcount = width; |
| 1648 | while (xcount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1649 | FILL_32BIT_X888RGB(bmap[2], bmap[1], |
| 1650 | bmap[0]); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1651 | bmap += 3; |
| 1652 | } |
| 1653 | bmap += padded_line; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1654 | fb -= VIDEO_LINE_LEN + width * |
| 1655 | VIDEO_PIXEL_SIZE; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1656 | } |
| 1657 | break; |
| 1658 | case GDF_24BIT_888RGB: |
| 1659 | while (ycount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1660 | WATCHDOG_RESET(); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1661 | xcount = width; |
| 1662 | while (xcount--) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1663 | FILL_24BIT_888RGB(bmap[2], bmap[1], |
| 1664 | bmap[0]); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1665 | bmap += 3; |
| 1666 | } |
| 1667 | bmap += padded_line; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1668 | fb -= VIDEO_LINE_LEN + width * |
| 1669 | VIDEO_PIXEL_SIZE; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1670 | } |
| 1671 | break; |
| 1672 | default: |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1673 | printf("Error: 24 bits/pixel bitmap incompatible " |
| 1674 | "with current video mode\n"); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1675 | break; |
| 1676 | } |
| 1677 | break; |
| 1678 | default: |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1679 | printf("Error: %d bit/pixel bitmaps not supported by U-Boot\n", |
| 1680 | le16_to_cpu(bmp->header.bit_count)); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1681 | break; |
| 1682 | } |
Stefan Roese | 98f4a3d | 2005-09-22 09:04:17 +0200 | [diff] [blame] | 1683 | |
| 1684 | #ifdef CONFIG_VIDEO_BMP_GZIP |
| 1685 | if (dst) { |
| 1686 | free(dst); |
| 1687 | } |
| 1688 | #endif |
| 1689 | |
Eric Nelson | db0d47d | 2013-05-06 14:27:28 +0200 | [diff] [blame] | 1690 | if (cfb_do_flush_cache) |
| 1691 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1692 | return (0); |
| 1693 | } |
Jon Loeliger | 07d38a1 | 2007-07-09 17:30:01 -0500 | [diff] [blame] | 1694 | #endif |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1695 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1696 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1697 | #ifdef CONFIG_VIDEO_LOGO |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1698 | static int video_logo_xpos; |
| 1699 | static int video_logo_ypos; |
| 1700 | |
Hans de Goede | c4c9e81 | 2015-08-04 12:21:40 +0200 | [diff] [blame] | 1701 | static void plot_logo_or_black(void *screen, int x, int y, int black); |
Bastian Ruppert | 4b7d3a0 | 2012-09-13 22:29:02 +0000 | [diff] [blame] | 1702 | |
Hans de Goede | c4c9e81 | 2015-08-04 12:21:40 +0200 | [diff] [blame] | 1703 | static void logo_plot(void *screen, int x, int y) |
Bastian Ruppert | 4b7d3a0 | 2012-09-13 22:29:02 +0000 | [diff] [blame] | 1704 | { |
Hans de Goede | c4c9e81 | 2015-08-04 12:21:40 +0200 | [diff] [blame] | 1705 | plot_logo_or_black(screen, x, y, 0); |
Bastian Ruppert | 4b7d3a0 | 2012-09-13 22:29:02 +0000 | [diff] [blame] | 1706 | } |
| 1707 | |
| 1708 | static void logo_black(void) |
| 1709 | { |
Hans de Goede | c4c9e81 | 2015-08-04 12:21:40 +0200 | [diff] [blame] | 1710 | plot_logo_or_black(video_fb_address, video_logo_xpos, video_logo_ypos, |
Bastian Ruppert | 4b7d3a0 | 2012-09-13 22:29:02 +0000 | [diff] [blame] | 1711 | 1); |
| 1712 | } |
| 1713 | |
Simon Glass | 0914011 | 2020-05-10 11:40:03 -0600 | [diff] [blame^] | 1714 | static int do_clrlogo(struct cmd_tbl *cmdtp, int flag, int argc, |
| 1715 | char *const argv[]) |
Bastian Ruppert | 4b7d3a0 | 2012-09-13 22:29:02 +0000 | [diff] [blame] | 1716 | { |
| 1717 | if (argc != 1) |
| 1718 | return cmd_usage(cmdtp); |
| 1719 | |
| 1720 | logo_black(); |
| 1721 | return 0; |
| 1722 | } |
| 1723 | |
| 1724 | U_BOOT_CMD( |
| 1725 | clrlogo, 1, 0, do_clrlogo, |
| 1726 | "fill the boot logo area with black", |
| 1727 | " " |
| 1728 | ); |
| 1729 | |
Hans de Goede | c4c9e81 | 2015-08-04 12:21:40 +0200 | [diff] [blame] | 1730 | static void plot_logo_or_black(void *screen, int x, int y, int black) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1731 | { |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1732 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1733 | int xcount, i; |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1734 | int skip = VIDEO_LINE_LEN - VIDEO_LOGO_WIDTH * VIDEO_PIXEL_SIZE; |
Matthias Weisser | be129aa | 2010-01-12 12:06:31 +0100 | [diff] [blame] | 1735 | int ycount = video_logo_height; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1736 | unsigned char r, g, b, *logo_red, *logo_blue, *logo_green; |
| 1737 | unsigned char *source; |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1738 | unsigned char *dest; |
| 1739 | |
| 1740 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |
| 1741 | if (x == BMP_ALIGN_CENTER) |
Masahiro Yamada | b414119 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1742 | x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH) / 2); |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1743 | else if (x < 0) |
Masahiro Yamada | b414119 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1744 | x = max(0, (int)(VIDEO_VISIBLE_COLS - VIDEO_LOGO_WIDTH + x + 1)); |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1745 | |
| 1746 | if (y == BMP_ALIGN_CENTER) |
Masahiro Yamada | b414119 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1747 | y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT) / 2); |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1748 | else if (y < 0) |
Masahiro Yamada | b414119 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1749 | y = max(0, (int)(VIDEO_VISIBLE_ROWS - VIDEO_LOGO_HEIGHT + y + 1)); |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1750 | #endif /* CONFIG_SPLASH_SCREEN_ALIGN */ |
| 1751 | |
Hans de Goede | c67a876 | 2015-08-04 12:15:39 +0200 | [diff] [blame] | 1752 | dest = (unsigned char *)screen + y * VIDEO_LINE_LEN + x * VIDEO_PIXEL_SIZE; |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 1753 | |
| 1754 | #ifdef CONFIG_VIDEO_BMP_LOGO |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1755 | source = bmp_logo_bitmap; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1756 | |
Anatolij Gustschin | 7c050f8 | 2010-06-19 20:41:56 +0200 | [diff] [blame] | 1757 | /* Allocate temporary space for computing colormap */ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1758 | logo_red = malloc(BMP_LOGO_COLORS); |
| 1759 | logo_green = malloc(BMP_LOGO_COLORS); |
| 1760 | logo_blue = malloc(BMP_LOGO_COLORS); |
Anatolij Gustschin | 7c050f8 | 2010-06-19 20:41:56 +0200 | [diff] [blame] | 1761 | /* Compute color map */ |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1762 | for (i = 0; i < VIDEO_LOGO_COLORS; i++) { |
| 1763 | logo_red[i] = (bmp_logo_palette[i] & 0x0f00) >> 4; |
| 1764 | logo_green[i] = (bmp_logo_palette[i] & 0x00f0); |
| 1765 | logo_blue[i] = (bmp_logo_palette[i] & 0x000f) << 4; |
| 1766 | } |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 1767 | #else |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1768 | source = linux_logo; |
| 1769 | logo_red = linux_logo_red; |
| 1770 | logo_green = linux_logo_green; |
| 1771 | logo_blue = linux_logo_blue; |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 1772 | #endif |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1773 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1774 | if (VIDEO_DATA_FORMAT == GDF__8BIT_INDEX) { |
| 1775 | for (i = 0; i < VIDEO_LOGO_COLORS; i++) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1776 | video_set_lut(i + VIDEO_LOGO_LUT_OFFSET, |
| 1777 | logo_red[i], logo_green[i], |
| 1778 | logo_blue[i]); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1779 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1780 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1781 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1782 | while (ycount--) { |
Anatolij Gustschin | e84d568 | 2008-08-08 18:00:40 +0200 | [diff] [blame] | 1783 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
| 1784 | int xpos = x; |
| 1785 | #endif |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1786 | xcount = VIDEO_LOGO_WIDTH; |
| 1787 | while (xcount--) { |
Bastian Ruppert | 4b7d3a0 | 2012-09-13 22:29:02 +0000 | [diff] [blame] | 1788 | if (black) { |
| 1789 | r = 0x00; |
| 1790 | g = 0x00; |
| 1791 | b = 0x00; |
| 1792 | } else { |
| 1793 | r = logo_red[*source - VIDEO_LOGO_LUT_OFFSET]; |
| 1794 | g = logo_green[*source - VIDEO_LOGO_LUT_OFFSET]; |
| 1795 | b = logo_blue[*source - VIDEO_LOGO_LUT_OFFSET]; |
| 1796 | } |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1797 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1798 | switch (VIDEO_DATA_FORMAT) { |
| 1799 | case GDF__8BIT_INDEX: |
| 1800 | *dest = *source; |
| 1801 | break; |
| 1802 | case GDF__8BIT_332RGB: |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1803 | *dest = ((r >> 5) << 5) | |
| 1804 | ((g >> 5) << 2) | |
| 1805 | (b >> 6); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1806 | break; |
| 1807 | case GDF_15BIT_555RGB: |
Andrew Dyer | cc34780 | 2008-08-29 12:30:39 -0500 | [diff] [blame] | 1808 | #if defined(VIDEO_FB_16BPP_PIXEL_SWAP) |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1809 | fill_555rgb_pswap(dest, xpos++, r, g, b); |
Andrew Dyer | cc34780 | 2008-08-29 12:30:39 -0500 | [diff] [blame] | 1810 | #else |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1811 | *(unsigned short *) dest = |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1812 | SWAP16((unsigned short) ( |
| 1813 | ((r >> 3) << 10) | |
| 1814 | ((g >> 3) << 5) | |
| 1815 | (b >> 3))); |
Anatolij Gustschin | bed5375 | 2008-01-11 14:30:01 +0100 | [diff] [blame] | 1816 | #endif |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1817 | break; |
| 1818 | case GDF_16BIT_565RGB: |
| 1819 | *(unsigned short *) dest = |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1820 | SWAP16((unsigned short) ( |
| 1821 | ((r >> 3) << 11) | |
| 1822 | ((g >> 2) << 5) | |
| 1823 | (b >> 3))); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1824 | break; |
| 1825 | case GDF_32BIT_X888RGB: |
Andre Przywara | 1d4ed26 | 2017-03-06 01:13:38 +0000 | [diff] [blame] | 1826 | *(u32 *) dest = |
| 1827 | SWAP32((u32) ( |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1828 | (r << 16) | |
| 1829 | (g << 8) | |
| 1830 | b)); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1831 | break; |
| 1832 | case GDF_24BIT_888RGB: |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1833 | #ifdef VIDEO_FB_LITTLE_ENDIAN |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1834 | dest[0] = b; |
| 1835 | dest[1] = g; |
| 1836 | dest[2] = r; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1837 | #else |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1838 | dest[0] = r; |
| 1839 | dest[1] = g; |
| 1840 | dest[2] = b; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1841 | #endif |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1842 | break; |
| 1843 | } |
| 1844 | source++; |
| 1845 | dest += VIDEO_PIXEL_SIZE; |
| 1846 | } |
| 1847 | dest += skip; |
wdenk | 8bde7f7 | 2003-06-27 21:31:46 +0000 | [diff] [blame] | 1848 | } |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 1849 | #ifdef CONFIG_VIDEO_BMP_LOGO |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1850 | free(logo_red); |
| 1851 | free(logo_green); |
| 1852 | free(logo_blue); |
wdenk | a6c7ad2 | 2002-12-03 21:28:10 +0000 | [diff] [blame] | 1853 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1854 | } |
| 1855 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1856 | static void *video_logo(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1857 | { |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1858 | char info[128]; |
Wolfgang Denk | a9a62af | 2011-11-04 15:55:20 +0000 | [diff] [blame] | 1859 | __maybe_unused int y_off = 0; |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1860 | __maybe_unused ulong addr; |
| 1861 | __maybe_unused char *s; |
Anatolij Gustschin | b4fc6f2 | 2016-11-30 14:30:59 +0100 | [diff] [blame] | 1862 | __maybe_unused int len, ret, space; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1863 | |
Anatolij Gustschin | ff8fb56 | 2013-07-02 00:04:05 +0200 | [diff] [blame] | 1864 | splash_get_pos(&video_logo_xpos, &video_logo_ypos); |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1865 | |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1866 | #ifdef CONFIG_SPLASH_SCREEN |
Simon Glass | 00caae6 | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 1867 | s = env_get("splashimage"); |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1868 | if (s != NULL) { |
Anatolij Gustschin | b4fc6f2 | 2016-11-30 14:30:59 +0100 | [diff] [blame] | 1869 | ret = splash_screen_prepare(); |
| 1870 | if (ret < 0) |
| 1871 | return video_fb_address; |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1872 | addr = simple_strtoul(s, NULL, 16); |
| 1873 | |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1874 | if (video_display_bitmap(addr, |
| 1875 | video_logo_xpos, |
| 1876 | video_logo_ypos) == 0) { |
Matthias Weisser | be129aa | 2010-01-12 12:06:31 +0100 | [diff] [blame] | 1877 | video_logo_height = 0; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1878 | return ((void *) (video_fb_address)); |
| 1879 | } |
| 1880 | } |
| 1881 | #endif /* CONFIG_SPLASH_SCREEN */ |
| 1882 | |
Hans de Goede | c4c9e81 | 2015-08-04 12:21:40 +0200 | [diff] [blame] | 1883 | logo_plot(video_fb_address, video_logo_xpos, video_logo_ypos); |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1884 | |
| 1885 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |
| 1886 | /* |
| 1887 | * when using splashpos for video_logo, skip any info |
| 1888 | * output on video console if the logo is not at 0,0 |
| 1889 | */ |
| 1890 | if (video_logo_xpos || video_logo_ypos) { |
| 1891 | /* |
| 1892 | * video_logo_height is used in text and cursor offset |
| 1893 | * calculations. Since the console is below the logo, |
| 1894 | * we need to adjust the logo height |
| 1895 | */ |
| 1896 | if (video_logo_ypos == BMP_ALIGN_CENTER) |
Masahiro Yamada | b414119 | 2014-11-07 03:03:31 +0900 | [diff] [blame] | 1897 | video_logo_height += max(0, (int)(VIDEO_VISIBLE_ROWS - |
Bastian Ruppert | 1e681f9 | 2012-09-13 22:29:01 +0000 | [diff] [blame] | 1898 | VIDEO_LOGO_HEIGHT) / 2); |
| 1899 | else if (video_logo_ypos > 0) |
| 1900 | video_logo_height += video_logo_ypos; |
| 1901 | |
| 1902 | return video_fb_address + video_logo_height * VIDEO_LINE_LEN; |
| 1903 | } |
| 1904 | #endif |
Heiko Schocher | 2bc4aa5 | 2013-08-03 07:22:53 +0200 | [diff] [blame] | 1905 | if (board_cfb_skip()) |
| 1906 | return 0; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1907 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1908 | sprintf(info, " %s", version_string); |
Anatolij Gustschin | 3dcbe62 | 2009-04-23 12:35:22 +0200 | [diff] [blame] | 1909 | |
Tim Harvey | adde435 | 2016-05-24 14:59:59 -0700 | [diff] [blame] | 1910 | #ifndef CONFIG_HIDE_LOGO_VERSION |
Peng Fan | f9d891f | 2018-01-02 15:25:37 +0800 | [diff] [blame] | 1911 | space = (VIDEO_COLS - VIDEO_INFO_X) / VIDEO_FONT_WIDTH; |
Anatolij Gustschin | 3dcbe62 | 2009-04-23 12:35:22 +0200 | [diff] [blame] | 1912 | len = strlen(info); |
| 1913 | |
| 1914 | if (len > space) { |
Peng Fan | f9d891f | 2018-01-02 15:25:37 +0800 | [diff] [blame] | 1915 | int xx = VIDEO_INFO_X, yy = VIDEO_INFO_Y; |
| 1916 | uchar *p = (uchar *) info; |
| 1917 | |
| 1918 | while (len) { |
| 1919 | if (len > space) { |
| 1920 | video_drawchars(xx, yy, p, space); |
| 1921 | len -= space; |
| 1922 | |
| 1923 | p = (uchar *)p + space; |
| 1924 | |
| 1925 | if (!y_off) { |
| 1926 | xx += VIDEO_FONT_WIDTH; |
| 1927 | space--; |
| 1928 | } |
| 1929 | yy += VIDEO_FONT_HEIGHT; |
| 1930 | |
| 1931 | y_off++; |
| 1932 | } else { |
| 1933 | video_drawchars(xx, yy, p, len); |
| 1934 | len = 0; |
| 1935 | } |
| 1936 | } |
Anatolij Gustschin | 3dcbe62 | 2009-04-23 12:35:22 +0200 | [diff] [blame] | 1937 | } else |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1938 | video_drawstring(VIDEO_INFO_X, VIDEO_INFO_Y, (uchar *) info); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1939 | |
| 1940 | #ifdef CONFIG_CONSOLE_EXTRA_INFO |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1941 | { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1942 | int i, n = |
| 1943 | ((video_logo_height - |
| 1944 | VIDEO_FONT_HEIGHT) / VIDEO_FONT_HEIGHT); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1945 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1946 | for (i = 1; i < n; i++) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1947 | video_get_info_str(i, info); |
Anatolij Gustschin | 3dcbe62 | 2009-04-23 12:35:22 +0200 | [diff] [blame] | 1948 | if (!*info) |
| 1949 | continue; |
| 1950 | |
| 1951 | len = strlen(info); |
| 1952 | if (len > space) { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1953 | video_drawchars(VIDEO_INFO_X, |
| 1954 | VIDEO_INFO_Y + |
| 1955 | (i + y_off) * |
| 1956 | VIDEO_FONT_HEIGHT, |
| 1957 | (uchar *) info, space); |
Anatolij Gustschin | 3dcbe62 | 2009-04-23 12:35:22 +0200 | [diff] [blame] | 1958 | y_off++; |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1959 | video_drawchars(VIDEO_INFO_X + |
| 1960 | VIDEO_FONT_WIDTH, |
| 1961 | VIDEO_INFO_Y + |
| 1962 | (i + y_off) * |
| 1963 | VIDEO_FONT_HEIGHT, |
| 1964 | (uchar *) info + space, |
| 1965 | len - space); |
Anatolij Gustschin | 3dcbe62 | 2009-04-23 12:35:22 +0200 | [diff] [blame] | 1966 | } else { |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 1967 | video_drawstring(VIDEO_INFO_X, |
| 1968 | VIDEO_INFO_Y + |
| 1969 | (i + y_off) * |
| 1970 | VIDEO_FONT_HEIGHT, |
| 1971 | (uchar *) info); |
Anatolij Gustschin | 3dcbe62 | 2009-04-23 12:35:22 +0200 | [diff] [blame] | 1972 | } |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 1973 | } |
| 1974 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1975 | #endif |
Tim Harvey | adde435 | 2016-05-24 14:59:59 -0700 | [diff] [blame] | 1976 | #endif |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1977 | |
Matthias Weisser | be129aa | 2010-01-12 12:06:31 +0100 | [diff] [blame] | 1978 | return (video_fb_address + video_logo_height * VIDEO_LINE_LEN); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 1979 | } |
| 1980 | #endif |
| 1981 | |
Anatolij Gustschin | bfd4be8 | 2012-06-05 09:19:18 +0200 | [diff] [blame] | 1982 | static int cfb_fb_is_in_dram(void) |
| 1983 | { |
| 1984 | bd_t *bd = gd->bd; |
Andy Shevchenko | daab59a | 2017-07-05 16:25:22 +0300 | [diff] [blame] | 1985 | #if defined(CONFIG_ARM) || defined(CONFIG_NDS32) || \ |
Anatolij Gustschin | bfd4be8 | 2012-06-05 09:19:18 +0200 | [diff] [blame] | 1986 | defined(CONFIG_SANDBOX) || defined(CONFIG_X86) |
| 1987 | ulong start, end; |
| 1988 | int i; |
| 1989 | |
| 1990 | for (i = 0; i < CONFIG_NR_DRAM_BANKS; ++i) { |
| 1991 | start = bd->bi_dram[i].start; |
| 1992 | end = bd->bi_dram[i].start + bd->bi_dram[i].size - 1; |
| 1993 | if ((ulong)video_fb_address >= start && |
| 1994 | (ulong)video_fb_address < end) |
| 1995 | return 1; |
| 1996 | } |
| 1997 | #else |
| 1998 | if ((ulong)video_fb_address >= bd->bi_memstart && |
| 1999 | (ulong)video_fb_address < bd->bi_memstart + bd->bi_memsize) |
| 2000 | return 1; |
| 2001 | #endif |
| 2002 | return 0; |
| 2003 | } |
| 2004 | |
Heiko Schocher | 45ae254 | 2013-10-22 11:06:06 +0200 | [diff] [blame] | 2005 | void video_clear(void) |
| 2006 | { |
| 2007 | if (!video_fb_address) |
| 2008 | return; |
| 2009 | #ifdef VIDEO_HW_RECTFILL |
| 2010 | video_hw_rectfill(VIDEO_PIXEL_SIZE, /* bytes per pixel */ |
| 2011 | 0, /* dest pos x */ |
| 2012 | 0, /* dest pos y */ |
| 2013 | VIDEO_VISIBLE_COLS, /* frame width */ |
| 2014 | VIDEO_VISIBLE_ROWS, /* frame height */ |
| 2015 | bgx /* fill color */ |
| 2016 | ); |
| 2017 | #else |
| 2018 | memsetl(video_fb_address, |
| 2019 | (VIDEO_VISIBLE_ROWS * VIDEO_LINE_LEN) / sizeof(int), bgx); |
| 2020 | #endif |
| 2021 | } |
| 2022 | |
Simon Glass | 0a6eac8 | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 2023 | static int cfg_video_init(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2024 | { |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2025 | unsigned char color8; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2026 | |
Wolfgang Denk | 5791293 | 2011-07-30 12:48:09 +0000 | [diff] [blame] | 2027 | pGD = video_hw_init(); |
| 2028 | if (pGD == NULL) |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2029 | return -1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2030 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2031 | video_fb_address = (void *) VIDEO_FB_ADRS; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2032 | |
Anatolij Gustschin | bfd4be8 | 2012-06-05 09:19:18 +0200 | [diff] [blame] | 2033 | cfb_do_flush_cache = cfb_fb_is_in_dram() && dcache_status(); |
| 2034 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2035 | /* Init drawing pats */ |
| 2036 | switch (VIDEO_DATA_FORMAT) { |
| 2037 | case GDF__8BIT_INDEX: |
Simon Glass | 002f967 | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 2038 | video_set_lut(0x01, CONFIG_SYS_CONSOLE_FG_COL, |
| 2039 | CONFIG_SYS_CONSOLE_FG_COL, |
| 2040 | CONFIG_SYS_CONSOLE_FG_COL); |
| 2041 | video_set_lut(0x00, CONFIG_SYS_CONSOLE_BG_COL, |
| 2042 | CONFIG_SYS_CONSOLE_BG_COL, |
| 2043 | CONFIG_SYS_CONSOLE_BG_COL); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2044 | fgx = 0x01010101; |
| 2045 | bgx = 0x00000000; |
| 2046 | break; |
| 2047 | case GDF__8BIT_332RGB: |
Simon Glass | 002f967 | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 2048 | color8 = ((CONFIG_SYS_CONSOLE_FG_COL & 0xe0) | |
| 2049 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) & 0x1c) | |
| 2050 | CONFIG_SYS_CONSOLE_FG_COL >> 6); |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 2051 | fgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | |
| 2052 | color8; |
Simon Glass | 002f967 | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 2053 | color8 = ((CONFIG_SYS_CONSOLE_BG_COL & 0xe0) | |
| 2054 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) & 0x1c) | |
| 2055 | CONFIG_SYS_CONSOLE_BG_COL >> 6); |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 2056 | bgx = (color8 << 24) | (color8 << 16) | (color8 << 8) | |
| 2057 | color8; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2058 | break; |
| 2059 | case GDF_15BIT_555RGB: |
Simon Glass | 002f967 | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 2060 | fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 26) | |
| 2061 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 21) | |
| 2062 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) | |
| 2063 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 10) | |
| 2064 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 5) | |
| 2065 | (CONFIG_SYS_CONSOLE_FG_COL >> 3)); |
| 2066 | bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 26) | |
| 2067 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 21) | |
| 2068 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) | |
| 2069 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 10) | |
| 2070 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 5) | |
| 2071 | (CONFIG_SYS_CONSOLE_BG_COL >> 3)); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2072 | break; |
| 2073 | case GDF_16BIT_565RGB: |
Simon Glass | 002f967 | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 2074 | fgx = (((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 27) | |
| 2075 | ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 21) | |
| 2076 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 16) | |
| 2077 | ((CONFIG_SYS_CONSOLE_FG_COL >> 3) << 11) | |
| 2078 | ((CONFIG_SYS_CONSOLE_FG_COL >> 2) << 5) | |
| 2079 | (CONFIG_SYS_CONSOLE_FG_COL >> 3)); |
| 2080 | bgx = (((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 27) | |
| 2081 | ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 21) | |
| 2082 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 16) | |
| 2083 | ((CONFIG_SYS_CONSOLE_BG_COL >> 3) << 11) | |
| 2084 | ((CONFIG_SYS_CONSOLE_BG_COL >> 2) << 5) | |
| 2085 | (CONFIG_SYS_CONSOLE_BG_COL >> 3)); |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2086 | break; |
| 2087 | case GDF_32BIT_X888RGB: |
Simon Glass | 002f967 | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 2088 | fgx = (CONFIG_SYS_CONSOLE_FG_COL << 16) | |
| 2089 | (CONFIG_SYS_CONSOLE_FG_COL << 8) | |
| 2090 | CONFIG_SYS_CONSOLE_FG_COL; |
| 2091 | bgx = (CONFIG_SYS_CONSOLE_BG_COL << 16) | |
| 2092 | (CONFIG_SYS_CONSOLE_BG_COL << 8) | |
| 2093 | CONFIG_SYS_CONSOLE_BG_COL; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2094 | break; |
| 2095 | case GDF_24BIT_888RGB: |
Simon Glass | 002f967 | 2016-10-17 20:12:44 -0600 | [diff] [blame] | 2096 | fgx = (CONFIG_SYS_CONSOLE_FG_COL << 24) | |
| 2097 | (CONFIG_SYS_CONSOLE_FG_COL << 16) | |
| 2098 | (CONFIG_SYS_CONSOLE_FG_COL << 8) | |
| 2099 | CONFIG_SYS_CONSOLE_FG_COL; |
| 2100 | bgx = (CONFIG_SYS_CONSOLE_BG_COL << 24) | |
| 2101 | (CONFIG_SYS_CONSOLE_BG_COL << 16) | |
| 2102 | (CONFIG_SYS_CONSOLE_BG_COL << 8) | |
| 2103 | CONFIG_SYS_CONSOLE_BG_COL; |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2104 | break; |
| 2105 | } |
| 2106 | eorx = fgx ^ bgx; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2107 | |
Rob Clark | 8ef0535 | 2017-08-03 12:47:01 -0400 | [diff] [blame] | 2108 | if (!CONFIG_IS_ENABLED(NO_FB_CLEAR)) |
| 2109 | video_clear(); |
Heiko Schocher | 45ae254 | 2013-10-22 11:06:06 +0200 | [diff] [blame] | 2110 | |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2111 | #ifdef CONFIG_VIDEO_LOGO |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2112 | /* Plot the logo and get start point of console */ |
Wolfgang Denk | 72c65f6 | 2011-07-29 09:55:28 +0000 | [diff] [blame] | 2113 | debug("Video: Drawing the logo ...\n"); |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 2114 | video_console_address = video_logo(); |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2115 | #else |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2116 | video_console_address = video_fb_address; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2117 | #endif |
| 2118 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2119 | /* Initialize the console */ |
| 2120 | console_col = 0; |
| 2121 | console_row = 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2122 | |
Eric Nelson | db0d47d | 2013-05-06 14:27:28 +0200 | [diff] [blame] | 2123 | if (cfb_do_flush_cache) |
| 2124 | flush_cache(VIDEO_FB_ADRS, VIDEO_SIZE); |
| 2125 | |
wdenk | 4b248f3 | 2004-03-14 16:51:43 +0000 | [diff] [blame] | 2126 | return 0; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2127 | } |
| 2128 | |
Wolfgang Denk | 6cc7ba9 | 2009-05-15 10:07:43 +0200 | [diff] [blame] | 2129 | /* |
| 2130 | * Implement a weak default function for boards that optionally |
| 2131 | * need to skip the video initialization. |
| 2132 | */ |
Jeroen Hofstee | 69d2754 | 2014-10-08 22:57:30 +0200 | [diff] [blame] | 2133 | __weak int board_video_skip(void) |
Wolfgang Denk | 6cc7ba9 | 2009-05-15 10:07:43 +0200 | [diff] [blame] | 2134 | { |
| 2135 | /* As default, don't skip test */ |
| 2136 | return 0; |
| 2137 | } |
Wolfgang Denk | 6cc7ba9 | 2009-05-15 10:07:43 +0200 | [diff] [blame] | 2138 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 2139 | int drv_video_init(void) |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2140 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 2141 | struct stdio_dev console_dev; |
Simon Glass | 5692ccf | 2015-03-02 12:40:50 -0700 | [diff] [blame] | 2142 | bool have_keyboard; |
Bin Meng | 8ceb242 | 2015-08-24 01:00:07 -0700 | [diff] [blame] | 2143 | bool __maybe_unused keyboard_ok = false; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2144 | |
Wolfgang Denk | 6cc7ba9 | 2009-05-15 10:07:43 +0200 | [diff] [blame] | 2145 | /* Check if video initialization should be skipped */ |
| 2146 | if (board_video_skip()) |
| 2147 | return 0; |
| 2148 | |
wdenk | 8105092 | 2004-07-11 20:04:51 +0000 | [diff] [blame] | 2149 | /* Init video chip - returns with framebuffer cleared */ |
Simon Glass | 0a6eac8 | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 2150 | if (cfg_video_init() == -1) |
Bin Meng | 8ceb242 | 2015-08-24 01:00:07 -0700 | [diff] [blame] | 2151 | return 0; |
wdenk | 8105092 | 2004-07-11 20:04:51 +0000 | [diff] [blame] | 2152 | |
Heiko Schocher | 2bc4aa5 | 2013-08-03 07:22:53 +0200 | [diff] [blame] | 2153 | if (board_cfb_skip()) |
| 2154 | return 0; |
| 2155 | |
Simon Glass | 5692ccf | 2015-03-02 12:40:50 -0700 | [diff] [blame] | 2156 | #if defined(CONFIG_VGA_AS_SINGLE_DEVICE) |
| 2157 | have_keyboard = false; |
| 2158 | #elif defined(CONFIG_OF_CONTROL) |
| 2159 | have_keyboard = !fdtdec_get_config_bool(gd->fdt_blob, |
| 2160 | "u-boot,no-keyboard"); |
| 2161 | #else |
| 2162 | have_keyboard = true; |
Wolfgang Denk | f62f646 | 2009-05-15 10:07:42 +0200 | [diff] [blame] | 2163 | #endif |
Simon Glass | 5692ccf | 2015-03-02 12:40:50 -0700 | [diff] [blame] | 2164 | if (have_keyboard) { |
| 2165 | debug("KBD: Keyboard init ...\n"); |
| 2166 | #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE) |
Bin Meng | 8ceb242 | 2015-08-24 01:00:07 -0700 | [diff] [blame] | 2167 | keyboard_ok = !(VIDEO_KBD_INIT_FCT == -1); |
Simon Glass | 5692ccf | 2015-03-02 12:40:50 -0700 | [diff] [blame] | 2168 | #endif |
| 2169 | } |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2170 | |
Wolfgang Denk | f62f646 | 2009-05-15 10:07:42 +0200 | [diff] [blame] | 2171 | /* Init vga device */ |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 2172 | memset(&console_dev, 0, sizeof(console_dev)); |
| 2173 | strcpy(console_dev.name, "vga"); |
Bin Meng | 1caf934 | 2015-11-03 23:23:37 -0800 | [diff] [blame] | 2174 | console_dev.flags = DEV_FLAGS_OUTPUT; |
Simon Glass | 0a6eac8 | 2016-10-17 20:12:54 -0600 | [diff] [blame] | 2175 | console_dev.putc = cfb_video_putc; /* 'putc' function */ |
| 2176 | console_dev.puts = cfb_video_puts; /* 'puts' function */ |
Wolfgang Denk | f62f646 | 2009-05-15 10:07:42 +0200 | [diff] [blame] | 2177 | |
| 2178 | #if !defined(CONFIG_VGA_AS_SINGLE_DEVICE) |
Bin Meng | 8ceb242 | 2015-08-24 01:00:07 -0700 | [diff] [blame] | 2179 | if (have_keyboard && keyboard_ok) { |
Simon Glass | 5692ccf | 2015-03-02 12:40:50 -0700 | [diff] [blame] | 2180 | /* Also init console device */ |
| 2181 | console_dev.flags |= DEV_FLAGS_INPUT; |
| 2182 | console_dev.tstc = VIDEO_TSTC_FCT; /* 'tstc' function */ |
| 2183 | console_dev.getc = VIDEO_GETC_FCT; /* 'getc' function */ |
| 2184 | } |
| 2185 | #endif |
Wolfgang Denk | f62f646 | 2009-05-15 10:07:42 +0200 | [diff] [blame] | 2186 | |
Wolfgang Denk | 64e40d7 | 2011-07-29 09:55:27 +0000 | [diff] [blame] | 2187 | if (stdio_register(&console_dev) != 0) |
Wolfgang Denk | f62f646 | 2009-05-15 10:07:42 +0200 | [diff] [blame] | 2188 | return 0; |
| 2189 | |
| 2190 | /* Return success */ |
| 2191 | return 1; |
wdenk | c609719 | 2002-11-03 00:24:07 +0000 | [diff] [blame] | 2192 | } |
Stefan Reinauer | c20ee07 | 2012-09-28 15:11:12 +0000 | [diff] [blame] | 2193 | |
| 2194 | void video_position_cursor(unsigned col, unsigned row) |
| 2195 | { |
| 2196 | console_col = min(col, CONSOLE_COLS - 1); |
| 2197 | console_row = min(row, CONSOLE_ROWS - 1); |
| 2198 | } |
| 2199 | |
| 2200 | int video_get_pixel_width(void) |
| 2201 | { |
| 2202 | return VIDEO_VISIBLE_COLS; |
| 2203 | } |
| 2204 | |
| 2205 | int video_get_pixel_height(void) |
| 2206 | { |
| 2207 | return VIDEO_VISIBLE_ROWS; |
| 2208 | } |
| 2209 | |
| 2210 | int video_get_screen_rows(void) |
| 2211 | { |
| 2212 | return CONSOLE_ROWS; |
| 2213 | } |
| 2214 | |
| 2215 | int video_get_screen_columns(void) |
| 2216 | { |
| 2217 | return CONSOLE_COLS; |
| 2218 | } |