Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Wenjun Zhang | 4e63ce4 | 2017-11-28 05:11:34 -0500 | [diff] [blame] | 5 | * Copyright (c) 2009-2015, 2018 The Linux Foundation. All rights reserved. |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 6 | * |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 7 | * Redistribution and use in source and binary forms, with or without |
| 8 | * modification, are permitted provided that the following conditions |
| 9 | * are met: |
| 10 | * * Redistributions of source code must retain the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer. |
| 12 | * * Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in |
| 14 | * the documentation and/or other materials provided with the |
| 15 | * distribution. |
| 16 | * |
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 18 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 19 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 20 | * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE |
| 21 | * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
| 23 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS |
lijuang | 7cfbfe3 | 2018-02-06 17:09:13 +0800 | [diff] [blame] | 24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 25 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
| 26 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT |
| 27 | * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 28 | * SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <debug.h> |
| 32 | #include <err.h> |
| 33 | #include <stdlib.h> |
| 34 | #include <dev/fbcon.h> |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 35 | #include <splash.h> |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 36 | #include <platform.h> |
| 37 | #include <string.h> |
Channagoud Kadabi | 7af9fbc | 2015-02-13 20:09:55 -0800 | [diff] [blame] | 38 | #include <arch/ops.h> |
Channagoud Kadabi | 875a2a7 | 2015-04-24 17:26:38 -0700 | [diff] [blame] | 39 | #if ENABLE_WBC |
| 40 | #include <pm_app_smbchg.h> |
| 41 | #endif |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 42 | |
| 43 | #include "font5x12.h" |
| 44 | |
| 45 | struct pos { |
| 46 | int x; |
| 47 | int y; |
| 48 | }; |
| 49 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 50 | struct fb_color { |
| 51 | uint32_t fg; |
| 52 | uint32_t bg; |
| 53 | }; |
| 54 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 55 | static struct fbcon_config *config = NULL; |
| 56 | |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 57 | #define RGB565_BLACK 0x0000 |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 58 | #define RGB565_WHITE 0xffff |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 59 | #define RGB565_CYAN 0x07ff |
| 60 | #define RGB565_BLUE 0x001f |
| 61 | #define RGB565_SILVER 0xc618 |
| 62 | #define RGB565_YELLOW 0xffe0 |
| 63 | #define RGB565_ORANGE 0xfd20 |
| 64 | #define RGB565_RED 0xf800 |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 65 | #define RGB565_GREEN 0x3666 |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 66 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 67 | #define RGB888_BLACK 0x000000 |
| 68 | #define RGB888_WHITE 0xffffff |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 69 | #define RGB888_CYAN 0x00ffff |
| 70 | #define RGB888_BLUE 0x0000FF |
| 71 | #define RGB888_SILVER 0xc0c0c0 |
| 72 | #define RGB888_YELLOW 0xffff00 |
| 73 | #define RGB888_ORANGE 0xffa500 |
| 74 | #define RGB888_RED 0xff0000 |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 75 | #define RGB888_GREEN 0x00ff00 |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 76 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 77 | #define FONT_WIDTH 5 |
| 78 | #define FONT_HEIGHT 12 |
| 79 | |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 80 | #define SCALE_FACTOR 2 |
| 81 | |
| 82 | static uint32_t BGCOLOR; |
| 83 | static uint32_t FGCOLOR; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 84 | static uint32_t SELECT_BGCOLOR; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 85 | |
| 86 | static struct pos cur_pos; |
| 87 | static struct pos max_pos; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 88 | static struct fb_color *fb_color_formats; |
| 89 | static struct fb_color fb_color_formats_555[] = { |
| 90 | [FBCON_COMMON_MSG] = {RGB565_WHITE, RGB565_BLACK}, |
lijuang | f3d7fc5 | 2018-04-23 16:34:29 +0800 | [diff] [blame] | 91 | [FBCON_UNLOCK_TITLE_MSG] = {RGB565_RED, RGB565_BLACK}, |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 92 | [FBCON_TITLE_MSG] = {RGB565_WHITE, RGB565_BLACK}, |
| 93 | [FBCON_SUBTITLE_MSG] = {RGB565_SILVER, RGB565_BLACK}, |
| 94 | [FBCON_YELLOW_MSG] = {RGB565_YELLOW, RGB565_BLACK}, |
| 95 | [FBCON_ORANGE_MSG] = {RGB565_ORANGE, RGB565_BLACK}, |
| 96 | [FBCON_RED_MSG] = {RGB565_RED, RGB565_BLACK}, |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 97 | [FBCON_GREEN_MSG] = {RGB565_GREEN, RGB565_BLACK}, |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 98 | [FBCON_SELECT_MSG_BG_COLOR] = {RGB565_WHITE, RGB565_BLUE}}; |
| 99 | |
| 100 | static struct fb_color fb_color_formats_888[] = { |
| 101 | [FBCON_COMMON_MSG] = {RGB888_WHITE, RGB888_BLACK}, |
lijuang | f3d7fc5 | 2018-04-23 16:34:29 +0800 | [diff] [blame] | 102 | [FBCON_UNLOCK_TITLE_MSG] = {RGB888_RED, RGB888_BLACK}, |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 103 | [FBCON_TITLE_MSG] = {RGB888_WHITE, RGB888_BLACK}, |
| 104 | [FBCON_SUBTITLE_MSG] = {RGB888_SILVER, RGB888_BLACK}, |
| 105 | [FBCON_YELLOW_MSG] = {RGB888_YELLOW, RGB888_BLACK}, |
| 106 | [FBCON_ORANGE_MSG] = {RGB888_ORANGE, RGB888_BLACK}, |
| 107 | [FBCON_RED_MSG] = {RGB888_RED, RGB888_BLACK}, |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 108 | [FBCON_GREEN_MSG] = {RGB888_GREEN, RGB888_BLACK}, |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 109 | [FBCON_SELECT_MSG_BG_COLOR] = {RGB888_WHITE, RGB888_BLUE}}; |
| 110 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 111 | |
lijuang | b3812fb | 2015-12-16 15:42:02 +0800 | [diff] [blame] | 112 | static void fbcon_flush(void); |
| 113 | |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 114 | static void fbcon_drawglyph(char *pixels, uint32_t paint, unsigned stride, |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 115 | unsigned bpp, unsigned *glyph, unsigned scale_factor) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 116 | { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 117 | unsigned x, y, i, j, k; |
| 118 | unsigned data, temp; |
| 119 | uint32_t fg_color = paint; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 120 | stride -= FONT_WIDTH * scale_factor; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 121 | |
| 122 | data = glyph[0]; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 123 | for (y = 0; y < FONT_HEIGHT / 2; ++y) { |
| 124 | temp = data; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 125 | for (i = 0; i < scale_factor; i++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 126 | data = temp; |
| 127 | for (x = 0; x < FONT_WIDTH; ++x) { |
| 128 | if (data & 1) { |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 129 | for (j = 0; j < scale_factor; j++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 130 | fg_color = paint; |
| 131 | for (k = 0; k < bpp; k++) { |
| 132 | *pixels = (unsigned char) fg_color; |
| 133 | fg_color = fg_color >> 8; |
| 134 | pixels++; |
| 135 | } |
| 136 | } |
| 137 | } |
| 138 | else |
| 139 | { |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 140 | for (j = 0; j < scale_factor; j++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 141 | pixels = pixels + bpp; |
| 142 | } |
| 143 | } |
| 144 | data >>= 1; |
| 145 | } |
| 146 | pixels += (stride * bpp); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 147 | } |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 148 | } |
| 149 | |
| 150 | data = glyph[1]; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 151 | for (y = 0; y < FONT_HEIGHT / 2; ++y) { |
| 152 | temp = data; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 153 | for (i = 0; i < scale_factor; i++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 154 | data = temp; |
| 155 | for (x = 0; x < FONT_WIDTH; ++x) { |
| 156 | if (data & 1) { |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 157 | for (j = 0; j < scale_factor; j++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 158 | fg_color = paint; |
| 159 | for (k = 0; k < bpp; k++) { |
| 160 | *pixels = (unsigned char) fg_color; |
| 161 | fg_color = fg_color >> 8; |
| 162 | pixels++; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | else |
| 167 | { |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 168 | for (j = 0; j < scale_factor; j++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 169 | pixels = pixels + bpp; |
| 170 | } |
| 171 | } |
| 172 | data >>= 1; |
| 173 | } |
| 174 | pixels += (stride * bpp); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 175 | } |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 176 | } |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 177 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 178 | } |
| 179 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 180 | void fbcon_draw_msg_background(unsigned y_start, unsigned y_end, |
| 181 | uint32_t old_paint, int update) |
| 182 | { |
| 183 | unsigned i, j; |
| 184 | uint32_t bg_color, check_color, tmp_color, tmp1_color; |
| 185 | char *pixels; |
lijuang | 7cfbfe3 | 2018-02-06 17:09:13 +0800 | [diff] [blame] | 186 | unsigned count; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 187 | |
lijuang | 7cfbfe3 | 2018-02-06 17:09:13 +0800 | [diff] [blame] | 188 | /* ignore anything that happens before fbcon is initialized */ |
| 189 | if (!config) |
| 190 | return; |
| 191 | |
| 192 | count = config->width * (FONT_HEIGHT * (y_end - y_start) - 1); |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 193 | pixels = config->base; |
| 194 | pixels += y_start * ((config->bpp / 8) * FONT_HEIGHT * config->width); |
| 195 | |
| 196 | if (update) { |
| 197 | bg_color = SELECT_BGCOLOR; |
| 198 | check_color = old_paint; |
| 199 | } else { |
| 200 | bg_color = old_paint; |
| 201 | check_color = SELECT_BGCOLOR; |
| 202 | } |
| 203 | |
| 204 | for (i = 0; i < count; i++) { |
| 205 | tmp1_color = bg_color; |
| 206 | tmp_color = 0; |
| 207 | for (j = 0; j < (config->bpp / 8); j++) { |
| 208 | tmp_color |= *(pixels+j) << j*8; |
| 209 | } |
| 210 | |
| 211 | if (tmp_color == check_color) { |
| 212 | for (j = 0; j < (config->bpp / 8); j++) { |
| 213 | *pixels = (unsigned char) tmp1_color; |
| 214 | tmp1_color = tmp1_color >> 8; |
| 215 | pixels++; |
| 216 | } |
| 217 | } else { |
| 218 | pixels += config->bpp / 8; |
| 219 | } |
| 220 | } |
lijuang | b3812fb | 2015-12-16 15:42:02 +0800 | [diff] [blame] | 221 | fbcon_flush(); |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 222 | } |
| 223 | |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 224 | static void fbcon_flush(void) |
| 225 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 226 | unsigned total_x, total_y; |
| 227 | unsigned bytes_per_bpp; |
| 228 | |
lijuang | 7cfbfe3 | 2018-02-06 17:09:13 +0800 | [diff] [blame] | 229 | /* ignore anything that happens before fbcon is initialized */ |
| 230 | if (!config) |
| 231 | return; |
| 232 | |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 233 | if (config->update_start) |
| 234 | config->update_start(); |
| 235 | if (config->update_done) |
| 236 | while (!config->update_done()); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 237 | |
| 238 | total_x = config->width; |
| 239 | total_y = config->height; |
| 240 | bytes_per_bpp = ((config->bpp) / 8); |
| 241 | arch_clean_invalidate_cache_range((addr_t) config->base, (total_x * total_y * bytes_per_bpp)); |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 242 | } |
| 243 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 244 | /* TODO: Take stride into account */ |
| 245 | static void fbcon_scroll_up(void) |
| 246 | { |
lijuang | 7cfbfe3 | 2018-02-06 17:09:13 +0800 | [diff] [blame] | 247 | unsigned short *dst = NULL; |
| 248 | unsigned short *src = NULL; |
| 249 | unsigned count = 0; |
| 250 | |
| 251 | /* ignore anything that happens before fbcon is initialized */ |
| 252 | if (!config) |
| 253 | return; |
| 254 | |
| 255 | dst = config->base; |
| 256 | src = dst + (config->width * FONT_HEIGHT); |
| 257 | count = config->width * (config->height - FONT_HEIGHT); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 258 | |
| 259 | while(count--) { |
| 260 | *dst++ = *src++; |
| 261 | } |
| 262 | |
| 263 | count = config->width * FONT_HEIGHT; |
| 264 | while(count--) { |
| 265 | *dst++ = BGCOLOR; |
| 266 | } |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 267 | |
| 268 | fbcon_flush(); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 269 | } |
| 270 | |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 271 | void fbcon_draw_line(uint32_t type) |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 272 | { |
| 273 | char *pixels; |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 274 | uint32_t line_color, tmp_color; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 275 | int i, j; |
| 276 | |
lijuang | 7cfbfe3 | 2018-02-06 17:09:13 +0800 | [diff] [blame] | 277 | /* ignore anything that happens before fbcon is initialized */ |
| 278 | if (!config) |
| 279 | return; |
| 280 | |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 281 | /* set line's color via diffrent type */ |
| 282 | line_color = fb_color_formats[type].fg; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 283 | |
| 284 | pixels = config->base; |
| 285 | pixels += cur_pos.y * ((config->bpp / 8) * FONT_HEIGHT * config->width); |
| 286 | pixels += cur_pos.x * ((config->bpp / 8) * (FONT_WIDTH + 1)); |
| 287 | |
| 288 | for (i = 0; i < (int)config->width; i++) { |
lijuang | 4304fce | 2015-08-14 20:52:47 +0800 | [diff] [blame] | 289 | tmp_color = line_color; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 290 | for (j = 0; j < (int)(config->bpp / 8); j++) { |
| 291 | *pixels = (unsigned char) tmp_color; |
| 292 | tmp_color = tmp_color >> 8; |
| 293 | pixels++; |
| 294 | } |
| 295 | } |
| 296 | |
| 297 | cur_pos.y += 1; |
| 298 | cur_pos.x = 0; |
| 299 | if(cur_pos.y >= max_pos.y) { |
| 300 | cur_pos.y = max_pos.y - 1; |
| 301 | fbcon_scroll_up(); |
| 302 | } else |
| 303 | fbcon_flush(); |
| 304 | } |
| 305 | |
| 306 | static void fbcon_set_colors(int type) |
| 307 | { |
| 308 | BGCOLOR = fb_color_formats[type].bg; |
| 309 | FGCOLOR = fb_color_formats[type].fg; |
| 310 | } |
| 311 | |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 312 | void fbcon_clear(void) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 313 | { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 314 | unsigned long i = 0, j = 0; |
lijuang | 7cfbfe3 | 2018-02-06 17:09:13 +0800 | [diff] [blame] | 315 | unsigned char *pixels = NULL; |
| 316 | unsigned count; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 317 | uint32_t bg_color; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 318 | |
lijuang | 7cfbfe3 | 2018-02-06 17:09:13 +0800 | [diff] [blame] | 319 | /* ignore anything that happens before fbcon is initialized */ |
| 320 | if (!config) |
| 321 | return; |
| 322 | |
| 323 | pixels = config->base; |
| 324 | count = config->width * config->height; |
| 325 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 326 | fbcon_set_colors(FBCON_COMMON_MSG); |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 327 | for (i = 0; i < count; i++) { |
| 328 | bg_color = BGCOLOR; |
| 329 | for (j = 0; j < (config->bpp / 8); j++) { |
| 330 | *pixels = (unsigned char) bg_color; |
| 331 | bg_color = bg_color >> 8; |
| 332 | pixels++; |
| 333 | } |
| 334 | } |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 335 | cur_pos.x = 0; |
| 336 | cur_pos.y = 0; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 337 | } |
| 338 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 339 | void fbcon_putc_factor(char c, int type, unsigned scale_factor) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 340 | { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 341 | char *pixels; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 342 | |
| 343 | /* ignore anything that happens before fbcon is initialized */ |
| 344 | if (!config) |
| 345 | return; |
| 346 | |
| 347 | if((unsigned char)c > 127) |
| 348 | return; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 349 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 350 | if((unsigned char)c < 32) { |
| 351 | if(c == '\n') |
| 352 | goto newline; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 353 | else if (c == '\r') { |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 354 | cur_pos.x = 0; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 355 | return; |
| 356 | } |
| 357 | else |
| 358 | return; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 359 | } |
| 360 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 361 | if (cur_pos.x == 0 && (unsigned char)c == ' ' && |
| 362 | type != FBCON_SUBTITLE_MSG && |
| 363 | type != FBCON_TITLE_MSG) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 364 | return; |
| 365 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 366 | fbcon_set_colors(type); |
| 367 | |
| 368 | pixels = config->base; |
| 369 | pixels += cur_pos.y * ((config->bpp / 8) * FONT_HEIGHT * config->width); |
| 370 | pixels += cur_pos.x * scale_factor * ((config->bpp / 8) * (FONT_WIDTH + 1)); |
| 371 | |
| 372 | fbcon_drawglyph(pixels, FGCOLOR, config->stride, (config->bpp / 8), |
| 373 | font5x12 + (c - 32) * 2, scale_factor); |
| 374 | |
| 375 | cur_pos.x++; |
| 376 | if (cur_pos.x >= (int)(max_pos.x / scale_factor)) |
| 377 | goto newline; |
| 378 | |
| 379 | return; |
| 380 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 381 | newline: |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 382 | cur_pos.y += scale_factor; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 383 | cur_pos.x = 0; |
| 384 | if(cur_pos.y >= max_pos.y) { |
| 385 | cur_pos.y = max_pos.y - 1; |
| 386 | fbcon_scroll_up(); |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 387 | } else |
| 388 | fbcon_flush(); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 389 | } |
| 390 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 391 | void fbcon_putc(char c) |
| 392 | { |
| 393 | fbcon_putc_factor(c, FBCON_COMMON_MSG, SCALE_FACTOR); |
| 394 | } |
| 395 | |
| 396 | uint32_t fbcon_get_current_line(void) |
| 397 | { |
| 398 | return cur_pos.y; |
| 399 | } |
| 400 | |
| 401 | uint32_t fbcon_get_max_x(void) |
| 402 | { |
| 403 | return max_pos.x; |
| 404 | } |
| 405 | |
lijuang | f3d7fc5 | 2018-04-23 16:34:29 +0800 | [diff] [blame] | 406 | uint32_t fbcon_get_width(void) |
| 407 | { |
| 408 | if (config) |
| 409 | return config->width; |
| 410 | else |
| 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | uint32_t fbcon_get_height(void) |
| 415 | { |
| 416 | if (config) |
| 417 | return config->height; |
| 418 | else |
| 419 | return 0; |
| 420 | } |
| 421 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 422 | uint32_t fbcon_get_current_bg(void) |
| 423 | { |
| 424 | return BGCOLOR; |
| 425 | } |
| 426 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 427 | void fbcon_setup(struct fbcon_config *_config) |
| 428 | { |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 429 | ASSERT(_config); |
| 430 | |
| 431 | config = _config; |
| 432 | |
| 433 | switch (config->format) { |
| 434 | case FB_FORMAT_RGB565: |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 435 | fb_color_formats = fb_color_formats_555; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 436 | break; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 437 | case FB_FORMAT_RGB888: |
| 438 | fb_color_formats = fb_color_formats_888; |
| 439 | break; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 440 | default: |
| 441 | dprintf(CRITICAL, "unknown framebuffer pixel format\n"); |
| 442 | ASSERT(0); |
| 443 | break; |
| 444 | } |
| 445 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 446 | SELECT_BGCOLOR = fb_color_formats[FBCON_SELECT_MSG_BG_COLOR].bg; |
| 447 | fbcon_set_colors(FBCON_COMMON_MSG); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 448 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 449 | cur_pos.x = 0; |
| 450 | cur_pos.y = 0; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 451 | max_pos.x = config->width / (FONT_WIDTH+1); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 452 | max_pos.y = (config->height - 1) / FONT_HEIGHT; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 453 | |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 454 | #if !DISPLAY_SPLASH_SCREEN |
| 455 | fbcon_clear(); |
| 456 | #endif |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 457 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 458 | } |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 459 | |
| 460 | struct fbcon_config* fbcon_display(void) |
| 461 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 462 | return config; |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 463 | } |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 464 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 465 | void fbcon_extract_to_screen(logo_img_header *header, void* address) |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 466 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 467 | const uint8_t *imagestart = (const uint8_t *)address; |
| 468 | uint pos = 0, offset; |
| 469 | uint count = 0; |
| 470 | uint x = 0, y = 0; |
| 471 | uint8_t *base, *p; |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 472 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 473 | if (!config || header->width > config->width |
| 474 | || header->height > config->height) { |
| 475 | dprintf(INFO, "the logo img is too large\n"); |
| 476 | return; |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 477 | } |
| 478 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 479 | base = (uint8_t *) config->base; |
| 480 | |
| 481 | /* put the logo to be center */ |
| 482 | offset = (config->height - header->height) / 2; |
| 483 | if (offset) |
| 484 | base += (offset * config->width) * 3; |
| 485 | offset = (config->width - header->width ) / 2; |
| 486 | |
| 487 | x = offset; |
| 488 | while (count < (uint)header->height * (uint)header->width) { |
| 489 | uint8_t run = *(imagestart + pos); |
| 490 | bool repeat_run = (run & 0x80); |
| 491 | uint runlen = (run & 0x7f) + 1; |
| 492 | uint runpos; |
| 493 | |
| 494 | /* consume the run byte */ |
| 495 | pos++; |
| 496 | |
| 497 | p = base + (y * config->width + x) * 3; |
| 498 | |
| 499 | /* start of a run */ |
| 500 | for (runpos = 0; runpos < runlen; runpos++) { |
| 501 | *p++ = *(imagestart + pos); |
| 502 | *p++ = *(imagestart + pos + 1); |
| 503 | *p++ = *(imagestart + pos + 2); |
| 504 | count++; |
| 505 | |
| 506 | x++; |
| 507 | |
| 508 | /* if a run of raw pixels, consume an input pixel */ |
| 509 | if (!repeat_run) |
| 510 | pos += 3; |
| 511 | } |
| 512 | |
| 513 | /* if this was a run of repeated pixels, consume the one input pixel we repeated */ |
| 514 | if (repeat_run) |
| 515 | pos += 3; |
| 516 | |
| 517 | /* the generator will keep compressing data line by line */ |
| 518 | /* don't cross the lines */ |
| 519 | if (x == header->width + offset) { |
| 520 | y++; |
| 521 | x = offset; |
| 522 | } |
| 523 | } |
| 524 | |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 525 | } |
| 526 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 527 | void display_default_image_on_screen(void) |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 528 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 529 | unsigned i = 0; |
| 530 | unsigned total_x; |
| 531 | unsigned total_y; |
| 532 | unsigned bytes_per_bpp; |
| 533 | unsigned image_base; |
Channagoud Kadabi | 875a2a7 | 2015-04-24 17:26:38 -0700 | [diff] [blame] | 534 | #if DISPLAY_TYPE_MIPI |
| 535 | char *image = NULL; |
| 536 | #endif |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 537 | |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 538 | if (!config) { |
| 539 | dprintf(CRITICAL,"NULL configuration, image cannot be displayed\n"); |
| 540 | return; |
| 541 | } |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 542 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 543 | fbcon_clear(); // clear screen with Black color |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 544 | |
| 545 | total_x = config->width; |
| 546 | total_y = config->height; |
| 547 | bytes_per_bpp = ((config->bpp) / 8); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 548 | image_base = ((((total_y/2) - (SPLASH_IMAGE_HEIGHT / 2) - 1) * |
| 549 | (config->width)) + (total_x/2 - (SPLASH_IMAGE_WIDTH / 2))); |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 550 | |
Channagoud Kadabi | 875a2a7 | 2015-04-24 17:26:38 -0700 | [diff] [blame] | 551 | #if ENABLE_WBC |
| 552 | image = (pm_appsbl_charging_in_progress() ? image_batt888 : imageBuffer_rgb888); |
| 553 | #else |
| 554 | image = imageBuffer_rgb888; |
| 555 | #endif |
| 556 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 557 | if (bytes_per_bpp == 3) { |
| 558 | for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) { |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 559 | memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp), |
Channagoud Kadabi | 875a2a7 | 2015-04-24 17:26:38 -0700 | [diff] [blame] | 560 | image + (i * SPLASH_IMAGE_WIDTH * bytes_per_bpp), |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 561 | SPLASH_IMAGE_WIDTH * bytes_per_bpp); |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 562 | } |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 563 | } |
Zohaib Alam | 0370875 | 2014-10-23 17:51:57 -0400 | [diff] [blame] | 564 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 565 | if (bytes_per_bpp == 2) { |
| 566 | for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) { |
| 567 | memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp), |
| 568 | imageBuffer + (i * SPLASH_IMAGE_WIDTH * bytes_per_bpp), |
| 569 | SPLASH_IMAGE_WIDTH * bytes_per_bpp); |
Zohaib Alam | 0370875 | 2014-10-23 17:51:57 -0400 | [diff] [blame] | 570 | } |
| 571 | } |
Wenjun Zhang | 4e63ce4 | 2017-11-28 05:11:34 -0500 | [diff] [blame] | 572 | |
Zohaib Alam | 0370875 | 2014-10-23 17:51:57 -0400 | [diff] [blame] | 573 | fbcon_flush(); |
Wenjun Zhang | 4e63ce4 | 2017-11-28 05:11:34 -0500 | [diff] [blame] | 574 | |
| 575 | #if DISPLAY_MIPI_PANEL_NOVATEK_BLUE |
| 576 | if(is_cmd_mode_enabled()) |
| 577 | mipi_dsi_cmd_mode_trigger(); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 578 | #endif |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 579 | } |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 580 | |
| 581 | |
| 582 | void display_image_on_screen(void) |
| 583 | { |
| 584 | #if DISPLAY_TYPE_MIPI |
| 585 | int fetch_image_from_partition(); |
| 586 | |
| 587 | if (fetch_image_from_partition() < 0) { |
| 588 | display_default_image_on_screen(); |
| 589 | } else { |
| 590 | /* data has been put into the right place */ |
| 591 | fbcon_flush(); |
| 592 | } |
| 593 | #else |
| 594 | display_default_image_on_screen(); |
| 595 | #endif |
| 596 | } |