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