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