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