Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Channagoud Kadabi | 7af9fbc | 2015-02-13 20:09:55 -0800 | [diff] [blame] | 5 | * Copyright (c) 2009-2015, 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 |
| 24 | * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
| 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 |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 65 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 66 | #define RGB888_BLACK 0x000000 |
| 67 | #define RGB888_WHITE 0xffffff |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 68 | #define RGB888_CYAN 0x00ffff |
| 69 | #define RGB888_BLUE 0x0000FF |
| 70 | #define RGB888_SILVER 0xc0c0c0 |
| 71 | #define RGB888_YELLOW 0xffff00 |
| 72 | #define RGB888_ORANGE 0xffa500 |
| 73 | #define RGB888_RED 0xff0000 |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 74 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 75 | #define FONT_WIDTH 5 |
| 76 | #define FONT_HEIGHT 12 |
| 77 | |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 78 | #define SCALE_FACTOR 2 |
| 79 | |
| 80 | static uint32_t BGCOLOR; |
| 81 | static uint32_t FGCOLOR; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 82 | static uint32_t SELECT_BGCOLOR; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 83 | |
| 84 | static struct pos cur_pos; |
| 85 | static struct pos max_pos; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 86 | static struct fb_color *fb_color_formats; |
| 87 | static struct fb_color fb_color_formats_555[] = { |
| 88 | [FBCON_COMMON_MSG] = {RGB565_WHITE, RGB565_BLACK}, |
| 89 | [FBCON_UNLOCK_TITLE_MSG] = {RGB565_CYAN, RGB565_BLACK}, |
| 90 | [FBCON_TITLE_MSG] = {RGB565_WHITE, RGB565_BLACK}, |
| 91 | [FBCON_SUBTITLE_MSG] = {RGB565_SILVER, RGB565_BLACK}, |
| 92 | [FBCON_YELLOW_MSG] = {RGB565_YELLOW, RGB565_BLACK}, |
| 93 | [FBCON_ORANGE_MSG] = {RGB565_ORANGE, RGB565_BLACK}, |
| 94 | [FBCON_RED_MSG] = {RGB565_RED, RGB565_BLACK}, |
| 95 | [FBCON_LINE_COLOR] = {RGB565_WHITE, RGB565_WHITE}, |
| 96 | [FBCON_SELECT_MSG_BG_COLOR] = {RGB565_WHITE, RGB565_BLUE}}; |
| 97 | |
| 98 | static struct fb_color fb_color_formats_888[] = { |
| 99 | [FBCON_COMMON_MSG] = {RGB888_WHITE, RGB888_BLACK}, |
| 100 | [FBCON_UNLOCK_TITLE_MSG] = {RGB888_CYAN, RGB888_BLACK}, |
| 101 | [FBCON_TITLE_MSG] = {RGB888_WHITE, RGB888_BLACK}, |
| 102 | [FBCON_SUBTITLE_MSG] = {RGB888_SILVER, RGB888_BLACK}, |
| 103 | [FBCON_YELLOW_MSG] = {RGB888_YELLOW, RGB888_BLACK}, |
| 104 | [FBCON_ORANGE_MSG] = {RGB888_ORANGE, RGB888_BLACK}, |
| 105 | [FBCON_RED_MSG] = {RGB888_RED, RGB888_BLACK}, |
| 106 | [FBCON_LINE_COLOR] = {RGB888_WHITE, RGB888_WHITE}, |
| 107 | [FBCON_SELECT_MSG_BG_COLOR] = {RGB888_WHITE, RGB888_BLUE}}; |
| 108 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 109 | |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 110 | static void fbcon_drawglyph(char *pixels, uint32_t paint, unsigned stride, |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 111 | unsigned bpp, unsigned *glyph, unsigned scale_factor) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 112 | { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 113 | unsigned x, y, i, j, k; |
| 114 | unsigned data, temp; |
| 115 | uint32_t fg_color = paint; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 116 | stride -= FONT_WIDTH * scale_factor; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 117 | |
| 118 | data = glyph[0]; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 119 | for (y = 0; y < FONT_HEIGHT / 2; ++y) { |
| 120 | temp = data; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 121 | for (i = 0; i < scale_factor; i++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 122 | data = temp; |
| 123 | for (x = 0; x < FONT_WIDTH; ++x) { |
| 124 | if (data & 1) { |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 125 | for (j = 0; j < scale_factor; j++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 126 | fg_color = paint; |
| 127 | for (k = 0; k < bpp; k++) { |
| 128 | *pixels = (unsigned char) fg_color; |
| 129 | fg_color = fg_color >> 8; |
| 130 | pixels++; |
| 131 | } |
| 132 | } |
| 133 | } |
| 134 | else |
| 135 | { |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 136 | for (j = 0; j < scale_factor; j++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 137 | pixels = pixels + bpp; |
| 138 | } |
| 139 | } |
| 140 | data >>= 1; |
| 141 | } |
| 142 | pixels += (stride * bpp); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 143 | } |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | data = glyph[1]; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 147 | for (y = 0; y < FONT_HEIGHT / 2; ++y) { |
| 148 | temp = data; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 149 | for (i = 0; i < scale_factor; i++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 150 | data = temp; |
| 151 | for (x = 0; x < FONT_WIDTH; ++x) { |
| 152 | if (data & 1) { |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 153 | for (j = 0; j < scale_factor; j++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 154 | fg_color = paint; |
| 155 | for (k = 0; k < bpp; k++) { |
| 156 | *pixels = (unsigned char) fg_color; |
| 157 | fg_color = fg_color >> 8; |
| 158 | pixels++; |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | else |
| 163 | { |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 164 | for (j = 0; j < scale_factor; j++) { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 165 | pixels = pixels + bpp; |
| 166 | } |
| 167 | } |
| 168 | data >>= 1; |
| 169 | } |
| 170 | pixels += (stride * bpp); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 171 | } |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 172 | } |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 173 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 174 | } |
| 175 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 176 | void fbcon_draw_msg_background(unsigned y_start, unsigned y_end, |
| 177 | uint32_t old_paint, int update) |
| 178 | { |
| 179 | unsigned i, j; |
| 180 | uint32_t bg_color, check_color, tmp_color, tmp1_color; |
| 181 | char *pixels; |
| 182 | unsigned count = config->width * (FONT_HEIGHT * (y_end - y_start) - 1); |
| 183 | |
| 184 | pixels = config->base; |
| 185 | pixels += y_start * ((config->bpp / 8) * FONT_HEIGHT * config->width); |
| 186 | |
| 187 | if (update) { |
| 188 | bg_color = SELECT_BGCOLOR; |
| 189 | check_color = old_paint; |
| 190 | } else { |
| 191 | bg_color = old_paint; |
| 192 | check_color = SELECT_BGCOLOR; |
| 193 | } |
| 194 | |
| 195 | for (i = 0; i < count; i++) { |
| 196 | tmp1_color = bg_color; |
| 197 | tmp_color = 0; |
| 198 | for (j = 0; j < (config->bpp / 8); j++) { |
| 199 | tmp_color |= *(pixels+j) << j*8; |
| 200 | } |
| 201 | |
| 202 | if (tmp_color == check_color) { |
| 203 | for (j = 0; j < (config->bpp / 8); j++) { |
| 204 | *pixels = (unsigned char) tmp1_color; |
| 205 | tmp1_color = tmp1_color >> 8; |
| 206 | pixels++; |
| 207 | } |
| 208 | } else { |
| 209 | pixels += config->bpp / 8; |
| 210 | } |
| 211 | } |
| 212 | } |
| 213 | |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 214 | static void fbcon_flush(void) |
| 215 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 216 | unsigned total_x, total_y; |
| 217 | unsigned bytes_per_bpp; |
| 218 | |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 219 | if (config->update_start) |
| 220 | config->update_start(); |
| 221 | if (config->update_done) |
| 222 | while (!config->update_done()); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 223 | |
| 224 | total_x = config->width; |
| 225 | total_y = config->height; |
| 226 | bytes_per_bpp = ((config->bpp) / 8); |
| 227 | 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] | 228 | } |
| 229 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 230 | /* TODO: Take stride into account */ |
| 231 | static void fbcon_scroll_up(void) |
| 232 | { |
| 233 | unsigned short *dst = config->base; |
| 234 | unsigned short *src = dst + (config->width * FONT_HEIGHT); |
| 235 | unsigned count = config->width * (config->height - FONT_HEIGHT); |
| 236 | |
| 237 | while(count--) { |
| 238 | *dst++ = *src++; |
| 239 | } |
| 240 | |
| 241 | count = config->width * FONT_HEIGHT; |
| 242 | while(count--) { |
| 243 | *dst++ = BGCOLOR; |
| 244 | } |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 245 | |
| 246 | fbcon_flush(); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 247 | } |
| 248 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 249 | void fbcon_draw_line() |
| 250 | { |
| 251 | char *pixels; |
| 252 | uint32_t bg_color, tmp_color; |
| 253 | int i, j; |
| 254 | |
| 255 | bg_color = fb_color_formats[FBCON_LINE_COLOR].bg; |
| 256 | |
| 257 | pixels = config->base; |
| 258 | pixels += cur_pos.y * ((config->bpp / 8) * FONT_HEIGHT * config->width); |
| 259 | pixels += cur_pos.x * ((config->bpp / 8) * (FONT_WIDTH + 1)); |
| 260 | |
| 261 | for (i = 0; i < (int)config->width; i++) { |
| 262 | tmp_color = bg_color; |
| 263 | for (j = 0; j < (int)(config->bpp / 8); j++) { |
| 264 | *pixels = (unsigned char) tmp_color; |
| 265 | tmp_color = tmp_color >> 8; |
| 266 | pixels++; |
| 267 | } |
| 268 | } |
| 269 | |
| 270 | cur_pos.y += 1; |
| 271 | cur_pos.x = 0; |
| 272 | if(cur_pos.y >= max_pos.y) { |
| 273 | cur_pos.y = max_pos.y - 1; |
| 274 | fbcon_scroll_up(); |
| 275 | } else |
| 276 | fbcon_flush(); |
| 277 | } |
| 278 | |
| 279 | static void fbcon_set_colors(int type) |
| 280 | { |
| 281 | BGCOLOR = fb_color_formats[type].bg; |
| 282 | FGCOLOR = fb_color_formats[type].fg; |
| 283 | } |
| 284 | |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 285 | void fbcon_clear(void) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 286 | { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 287 | unsigned long i = 0, j = 0; |
| 288 | unsigned char *pixels = config->base; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 289 | unsigned count = config->width * config->height; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 290 | uint32_t bg_color; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 291 | |
| 292 | fbcon_set_colors(FBCON_COMMON_MSG); |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 293 | for (i = 0; i < count; i++) { |
| 294 | bg_color = BGCOLOR; |
| 295 | for (j = 0; j < (config->bpp / 8); j++) { |
| 296 | *pixels = (unsigned char) bg_color; |
| 297 | bg_color = bg_color >> 8; |
| 298 | pixels++; |
| 299 | } |
| 300 | } |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 301 | cur_pos.x = 0; |
| 302 | cur_pos.y = 0; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 303 | } |
| 304 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 305 | void fbcon_putc_factor(char c, int type, unsigned scale_factor) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 306 | { |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 307 | char *pixels; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 308 | |
| 309 | /* ignore anything that happens before fbcon is initialized */ |
| 310 | if (!config) |
| 311 | return; |
| 312 | |
| 313 | if((unsigned char)c > 127) |
| 314 | return; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 315 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 316 | if((unsigned char)c < 32) { |
| 317 | if(c == '\n') |
| 318 | goto newline; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 319 | else if (c == '\r') { |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 320 | cur_pos.x = 0; |
Sandeep Panda | df39f75 | 2015-05-08 14:01:16 +0530 | [diff] [blame] | 321 | return; |
| 322 | } |
| 323 | else |
| 324 | return; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 325 | } |
| 326 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 327 | if (cur_pos.x == 0 && (unsigned char)c == ' ' && |
| 328 | type != FBCON_SUBTITLE_MSG && |
| 329 | type != FBCON_TITLE_MSG) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 330 | return; |
| 331 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 332 | fbcon_set_colors(type); |
| 333 | |
| 334 | pixels = config->base; |
| 335 | pixels += cur_pos.y * ((config->bpp / 8) * FONT_HEIGHT * config->width); |
| 336 | pixels += cur_pos.x * scale_factor * ((config->bpp / 8) * (FONT_WIDTH + 1)); |
| 337 | |
| 338 | fbcon_drawglyph(pixels, FGCOLOR, config->stride, (config->bpp / 8), |
| 339 | font5x12 + (c - 32) * 2, scale_factor); |
| 340 | |
| 341 | cur_pos.x++; |
| 342 | if (cur_pos.x >= (int)(max_pos.x / scale_factor)) |
| 343 | goto newline; |
| 344 | |
| 345 | return; |
| 346 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 347 | newline: |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 348 | cur_pos.y += scale_factor; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 349 | cur_pos.x = 0; |
| 350 | if(cur_pos.y >= max_pos.y) { |
| 351 | cur_pos.y = max_pos.y - 1; |
| 352 | fbcon_scroll_up(); |
Dima Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 353 | } else |
| 354 | fbcon_flush(); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 355 | } |
| 356 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 357 | void fbcon_putc(char c) |
| 358 | { |
| 359 | fbcon_putc_factor(c, FBCON_COMMON_MSG, SCALE_FACTOR); |
| 360 | } |
| 361 | |
| 362 | uint32_t fbcon_get_current_line(void) |
| 363 | { |
| 364 | return cur_pos.y; |
| 365 | } |
| 366 | |
| 367 | uint32_t fbcon_get_max_x(void) |
| 368 | { |
| 369 | return max_pos.x; |
| 370 | } |
| 371 | |
| 372 | uint32_t fbcon_get_current_bg(void) |
| 373 | { |
| 374 | return BGCOLOR; |
| 375 | } |
| 376 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 377 | void fbcon_setup(struct fbcon_config *_config) |
| 378 | { |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 379 | ASSERT(_config); |
| 380 | |
| 381 | config = _config; |
| 382 | |
| 383 | switch (config->format) { |
| 384 | case FB_FORMAT_RGB565: |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 385 | fb_color_formats = fb_color_formats_555; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 386 | break; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 387 | case FB_FORMAT_RGB888: |
| 388 | fb_color_formats = fb_color_formats_888; |
| 389 | break; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 390 | default: |
| 391 | dprintf(CRITICAL, "unknown framebuffer pixel format\n"); |
| 392 | ASSERT(0); |
| 393 | break; |
| 394 | } |
| 395 | |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 396 | SELECT_BGCOLOR = fb_color_formats[FBCON_SELECT_MSG_BG_COLOR].bg; |
| 397 | fbcon_set_colors(FBCON_COMMON_MSG); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 398 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 399 | cur_pos.x = 0; |
| 400 | cur_pos.y = 0; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 401 | max_pos.x = config->width / (FONT_WIDTH+1); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 402 | max_pos.y = (config->height - 1) / FONT_HEIGHT; |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 403 | |
Shashank Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 404 | #if !DISPLAY_SPLASH_SCREEN |
| 405 | fbcon_clear(); |
| 406 | #endif |
lijuang | dd73d65 | 2015-06-05 21:29:37 +0800 | [diff] [blame] | 407 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 408 | } |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 409 | |
| 410 | struct fbcon_config* fbcon_display(void) |
| 411 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 412 | return config; |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 413 | } |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 414 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 415 | void fbcon_extract_to_screen(logo_img_header *header, void* address) |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 416 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 417 | const uint8_t *imagestart = (const uint8_t *)address; |
| 418 | uint pos = 0, offset; |
| 419 | uint count = 0; |
| 420 | uint x = 0, y = 0; |
| 421 | uint8_t *base, *p; |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 422 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 423 | if (!config || header->width > config->width |
| 424 | || header->height > config->height) { |
| 425 | dprintf(INFO, "the logo img is too large\n"); |
| 426 | return; |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 427 | } |
| 428 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 429 | base = (uint8_t *) config->base; |
| 430 | |
| 431 | /* put the logo to be center */ |
| 432 | offset = (config->height - header->height) / 2; |
| 433 | if (offset) |
| 434 | base += (offset * config->width) * 3; |
| 435 | offset = (config->width - header->width ) / 2; |
| 436 | |
| 437 | x = offset; |
| 438 | while (count < (uint)header->height * (uint)header->width) { |
| 439 | uint8_t run = *(imagestart + pos); |
| 440 | bool repeat_run = (run & 0x80); |
| 441 | uint runlen = (run & 0x7f) + 1; |
| 442 | uint runpos; |
| 443 | |
| 444 | /* consume the run byte */ |
| 445 | pos++; |
| 446 | |
| 447 | p = base + (y * config->width + x) * 3; |
| 448 | |
| 449 | /* start of a run */ |
| 450 | for (runpos = 0; runpos < runlen; runpos++) { |
| 451 | *p++ = *(imagestart + pos); |
| 452 | *p++ = *(imagestart + pos + 1); |
| 453 | *p++ = *(imagestart + pos + 2); |
| 454 | count++; |
| 455 | |
| 456 | x++; |
| 457 | |
| 458 | /* if a run of raw pixels, consume an input pixel */ |
| 459 | if (!repeat_run) |
| 460 | pos += 3; |
| 461 | } |
| 462 | |
| 463 | /* if this was a run of repeated pixels, consume the one input pixel we repeated */ |
| 464 | if (repeat_run) |
| 465 | pos += 3; |
| 466 | |
| 467 | /* the generator will keep compressing data line by line */ |
| 468 | /* don't cross the lines */ |
| 469 | if (x == header->width + offset) { |
| 470 | y++; |
| 471 | x = offset; |
| 472 | } |
| 473 | } |
| 474 | |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 475 | } |
| 476 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 477 | void display_default_image_on_screen(void) |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 478 | { |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 479 | unsigned i = 0; |
| 480 | unsigned total_x; |
| 481 | unsigned total_y; |
| 482 | unsigned bytes_per_bpp; |
| 483 | unsigned image_base; |
Channagoud Kadabi | 875a2a7 | 2015-04-24 17:26:38 -0700 | [diff] [blame] | 484 | #if DISPLAY_TYPE_MIPI |
| 485 | char *image = NULL; |
| 486 | #endif |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 487 | |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 488 | if (!config) { |
| 489 | dprintf(CRITICAL,"NULL configuration, image cannot be displayed\n"); |
| 490 | return; |
| 491 | } |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 492 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 493 | fbcon_clear(); // clear screen with Black color |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 494 | |
| 495 | total_x = config->width; |
| 496 | total_y = config->height; |
| 497 | bytes_per_bpp = ((config->bpp) / 8); |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 498 | image_base = ((((total_y/2) - (SPLASH_IMAGE_HEIGHT / 2) - 1) * |
| 499 | (config->width)) + (total_x/2 - (SPLASH_IMAGE_WIDTH / 2))); |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 500 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 501 | #if DISPLAY_TYPE_MIPI |
Channagoud Kadabi | 875a2a7 | 2015-04-24 17:26:38 -0700 | [diff] [blame] | 502 | #if ENABLE_WBC |
| 503 | image = (pm_appsbl_charging_in_progress() ? image_batt888 : imageBuffer_rgb888); |
| 504 | #else |
| 505 | image = imageBuffer_rgb888; |
| 506 | #endif |
| 507 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 508 | if (bytes_per_bpp == 3) { |
| 509 | for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) { |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 510 | memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp), |
Channagoud Kadabi | 875a2a7 | 2015-04-24 17:26:38 -0700 | [diff] [blame] | 511 | image + (i * SPLASH_IMAGE_WIDTH * bytes_per_bpp), |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 512 | SPLASH_IMAGE_WIDTH * bytes_per_bpp); |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 513 | } |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 514 | } |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 515 | fbcon_flush(); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 516 | #if DISPLAY_MIPI_PANEL_NOVATEK_BLUE |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 517 | if(is_cmd_mode_enabled()) |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 518 | mipi_dsi_cmd_mode_trigger(); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 519 | #endif |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 520 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 521 | #else |
Zohaib Alam | 0370875 | 2014-10-23 17:51:57 -0400 | [diff] [blame] | 522 | |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 523 | if (bytes_per_bpp == 2) { |
| 524 | for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) { |
| 525 | memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp), |
| 526 | imageBuffer + (i * SPLASH_IMAGE_WIDTH * bytes_per_bpp), |
| 527 | SPLASH_IMAGE_WIDTH * bytes_per_bpp); |
Zohaib Alam | 0370875 | 2014-10-23 17:51:57 -0400 | [diff] [blame] | 528 | } |
| 529 | } |
| 530 | fbcon_flush(); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 531 | #endif |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 532 | } |
Mao Flynn | 7b379f3 | 2015-04-20 00:28:30 +0800 | [diff] [blame] | 533 | |
| 534 | |
| 535 | void display_image_on_screen(void) |
| 536 | { |
| 537 | #if DISPLAY_TYPE_MIPI |
| 538 | int fetch_image_from_partition(); |
| 539 | |
| 540 | if (fetch_image_from_partition() < 0) { |
| 541 | display_default_image_on_screen(); |
| 542 | } else { |
| 543 | /* data has been put into the right place */ |
| 544 | fbcon_flush(); |
| 545 | } |
| 546 | #else |
| 547 | display_default_image_on_screen(); |
| 548 | #endif |
| 549 | } |