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