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