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