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