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