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