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