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