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