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