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