blob: 86fed46633501d7ec99e07219b310b2e37362b5a [file] [log] [blame]
Dima Zavind5b0b6a2009-01-15 18:09:25 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
Monika Singhb879e492019-09-16 16:00:15 +05305 * Copyright (c) 2009-2015, 2018, 2019 The Linux Foundation. All rights reserved.
Shashank Mittal4f99a882010-02-01 13:58:50 -08006 *
Dima Zavind5b0b6a2009-01-15 18:09:25 -08007 * 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
lijuang7cfbfe32018-02-06 17:09:13 +080024 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
Dima Zavind5b0b6a2009-01-15 18:09:25 -080025 * 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 Uddaraju40b227d2010-08-03 19:25:41 -070035#include <splash.h>
Greg Griscod6250552011-06-29 14:40:23 -070036#include <platform.h>
37#include <string.h>
Channagoud Kadabi7af9fbc2015-02-13 20:09:55 -080038#include <arch/ops.h>
Channagoud Kadabi875a2a72015-04-24 17:26:38 -070039#if ENABLE_WBC
Umang Chheda4c140de2019-12-19 14:30:38 +053040#include <pm_smbchg_common.h>
Channagoud Kadabi875a2a72015-04-24 17:26:38 -070041#endif
Dima Zavind5b0b6a2009-01-15 18:09:25 -080042
43#include "font5x12.h"
44
45struct pos {
46 int x;
47 int y;
48};
49
lijuangdd73d652015-06-05 21:29:37 +080050struct fb_color {
51 uint32_t fg;
52 uint32_t bg;
53};
54
Dima Zavind5b0b6a2009-01-15 18:09:25 -080055static struct fbcon_config *config = NULL;
56
Chandan Uddaraju2943fd62010-06-21 10:56:39 -070057#define RGB565_BLACK 0x0000
Dima Zavind5b0b6a2009-01-15 18:09:25 -080058#define RGB565_WHITE 0xffff
lijuangdd73d652015-06-05 21:29:37 +080059#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
lijuang4304fce2015-08-14 20:52:47 +080065#define RGB565_GREEN 0x3666
Dima Zavind5b0b6a2009-01-15 18:09:25 -080066
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070067#define RGB888_BLACK 0x000000
68#define RGB888_WHITE 0xffffff
lijuangdd73d652015-06-05 21:29:37 +080069#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
lijuang4304fce2015-08-14 20:52:47 +080075#define RGB888_GREEN 0x00ff00
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070076
Dima Zavind5b0b6a2009-01-15 18:09:25 -080077#define FONT_WIDTH 5
78#define FONT_HEIGHT 12
79
Sandeep Pandadf39f752015-05-08 14:01:16 +053080#define SCALE_FACTOR 2
81
82static uint32_t BGCOLOR;
83static uint32_t FGCOLOR;
lijuangdd73d652015-06-05 21:29:37 +080084static uint32_t SELECT_BGCOLOR;
Dima Zavind5b0b6a2009-01-15 18:09:25 -080085
86static struct pos cur_pos;
87static struct pos max_pos;
lijuangdd73d652015-06-05 21:29:37 +080088static struct fb_color *fb_color_formats;
89static struct fb_color fb_color_formats_555[] = {
90 [FBCON_COMMON_MSG] = {RGB565_WHITE, RGB565_BLACK},
lijuangf3d7fc52018-04-23 16:34:29 +080091 [FBCON_UNLOCK_TITLE_MSG] = {RGB565_RED, RGB565_BLACK},
lijuangdd73d652015-06-05 21:29:37 +080092 [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},
lijuang4304fce2015-08-14 20:52:47 +080097 [FBCON_GREEN_MSG] = {RGB565_GREEN, RGB565_BLACK},
lijuangdd73d652015-06-05 21:29:37 +080098 [FBCON_SELECT_MSG_BG_COLOR] = {RGB565_WHITE, RGB565_BLUE}};
99
100static struct fb_color fb_color_formats_888[] = {
101 [FBCON_COMMON_MSG] = {RGB888_WHITE, RGB888_BLACK},
lijuangf3d7fc52018-04-23 16:34:29 +0800102 [FBCON_UNLOCK_TITLE_MSG] = {RGB888_RED, RGB888_BLACK},
lijuangdd73d652015-06-05 21:29:37 +0800103 [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},
lijuang4304fce2015-08-14 20:52:47 +0800108 [FBCON_GREEN_MSG] = {RGB888_GREEN, RGB888_BLACK},
lijuangdd73d652015-06-05 21:29:37 +0800109 [FBCON_SELECT_MSG_BG_COLOR] = {RGB888_WHITE, RGB888_BLUE}};
110
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800111
lijuangb3812fb2015-12-16 15:42:02 +0800112static void fbcon_flush(void);
113
Sandeep Pandadf39f752015-05-08 14:01:16 +0530114static void fbcon_drawglyph(char *pixels, uint32_t paint, unsigned stride,
lijuangdd73d652015-06-05 21:29:37 +0800115 unsigned bpp, unsigned *glyph, unsigned scale_factor)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800116{
Sandeep Pandadf39f752015-05-08 14:01:16 +0530117 unsigned x, y, i, j, k;
118 unsigned data, temp;
119 uint32_t fg_color = paint;
lijuangdd73d652015-06-05 21:29:37 +0800120 stride -= FONT_WIDTH * scale_factor;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800121
122 data = glyph[0];
Sandeep Pandadf39f752015-05-08 14:01:16 +0530123 for (y = 0; y < FONT_HEIGHT / 2; ++y) {
124 temp = data;
lijuangdd73d652015-06-05 21:29:37 +0800125 for (i = 0; i < scale_factor; i++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530126 data = temp;
127 for (x = 0; x < FONT_WIDTH; ++x) {
128 if (data & 1) {
lijuangdd73d652015-06-05 21:29:37 +0800129 for (j = 0; j < scale_factor; j++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530130 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 {
lijuangdd73d652015-06-05 21:29:37 +0800140 for (j = 0; j < scale_factor; j++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530141 pixels = pixels + bpp;
142 }
143 }
144 data >>= 1;
145 }
146 pixels += (stride * bpp);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800147 }
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800148 }
149
150 data = glyph[1];
Sandeep Pandadf39f752015-05-08 14:01:16 +0530151 for (y = 0; y < FONT_HEIGHT / 2; ++y) {
152 temp = data;
lijuangdd73d652015-06-05 21:29:37 +0800153 for (i = 0; i < scale_factor; i++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530154 data = temp;
155 for (x = 0; x < FONT_WIDTH; ++x) {
156 if (data & 1) {
lijuangdd73d652015-06-05 21:29:37 +0800157 for (j = 0; j < scale_factor; j++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530158 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 {
lijuangdd73d652015-06-05 21:29:37 +0800168 for (j = 0; j < scale_factor; j++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530169 pixels = pixels + bpp;
170 }
171 }
172 data >>= 1;
173 }
174 pixels += (stride * bpp);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800175 }
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800176 }
Sandeep Pandadf39f752015-05-08 14:01:16 +0530177
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800178}
179
lijuangdd73d652015-06-05 21:29:37 +0800180void 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;
lijuang7cfbfe32018-02-06 17:09:13 +0800186 unsigned count;
lijuangdd73d652015-06-05 21:29:37 +0800187
lijuang7cfbfe32018-02-06 17:09:13 +0800188 /* 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);
lijuangdd73d652015-06-05 21:29:37 +0800193 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 }
lijuangb3812fb2015-12-16 15:42:02 +0800221 fbcon_flush();
lijuangdd73d652015-06-05 21:29:37 +0800222}
223
Dima Zavin25ed9942009-01-28 17:04:19 -0800224static void fbcon_flush(void)
225{
Mao Flynn7b379f32015-04-20 00:28:30 +0800226 unsigned total_x, total_y;
227 unsigned bytes_per_bpp;
228
lijuang7cfbfe32018-02-06 17:09:13 +0800229 /* ignore anything that happens before fbcon is initialized */
230 if (!config)
231 return;
232
Dima Zavin25ed9942009-01-28 17:04:19 -0800233 if (config->update_start)
234 config->update_start();
235 if (config->update_done)
236 while (!config->update_done());
Mao Flynn7b379f32015-04-20 00:28:30 +0800237
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 Zavin25ed9942009-01-28 17:04:19 -0800242}
243
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800244/* TODO: Take stride into account */
245static void fbcon_scroll_up(void)
246{
lijuang7cfbfe32018-02-06 17:09:13 +0800247 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 Zavind5b0b6a2009-01-15 18:09:25 -0800258
259 while(count--) {
260 *dst++ = *src++;
261 }
262
263 count = config->width * FONT_HEIGHT;
264 while(count--) {
265 *dst++ = BGCOLOR;
266 }
Dima Zavin25ed9942009-01-28 17:04:19 -0800267
268 fbcon_flush();
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800269}
270
lijuang4304fce2015-08-14 20:52:47 +0800271void fbcon_draw_line(uint32_t type)
lijuangdd73d652015-06-05 21:29:37 +0800272{
273 char *pixels;
lijuang4304fce2015-08-14 20:52:47 +0800274 uint32_t line_color, tmp_color;
lijuangdd73d652015-06-05 21:29:37 +0800275 int i, j;
276
lijuang7cfbfe32018-02-06 17:09:13 +0800277 /* ignore anything that happens before fbcon is initialized */
278 if (!config)
279 return;
280
lijuang4304fce2015-08-14 20:52:47 +0800281 /* set line's color via diffrent type */
282 line_color = fb_color_formats[type].fg;
lijuangdd73d652015-06-05 21:29:37 +0800283
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++) {
lijuang4304fce2015-08-14 20:52:47 +0800289 tmp_color = line_color;
lijuangdd73d652015-06-05 21:29:37 +0800290 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
306static void fbcon_set_colors(int type)
307{
308 BGCOLOR = fb_color_formats[type].bg;
309 FGCOLOR = fb_color_formats[type].fg;
310}
311
Shashank Mittal4f99a882010-02-01 13:58:50 -0800312void fbcon_clear(void)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800313{
Sandeep Pandadf39f752015-05-08 14:01:16 +0530314 unsigned long i = 0, j = 0;
lijuang7cfbfe32018-02-06 17:09:13 +0800315 unsigned char *pixels = NULL;
316 unsigned count;
Sandeep Pandadf39f752015-05-08 14:01:16 +0530317 uint32_t bg_color;
lijuangdd73d652015-06-05 21:29:37 +0800318
lijuang7cfbfe32018-02-06 17:09:13 +0800319 /* 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
lijuangdd73d652015-06-05 21:29:37 +0800326 fbcon_set_colors(FBCON_COMMON_MSG);
Sandeep Pandadf39f752015-05-08 14:01:16 +0530327 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 }
lijuangdd73d652015-06-05 21:29:37 +0800335 cur_pos.x = 0;
336 cur_pos.y = 0;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800337}
338
Monika Singhb879e492019-09-16 16:00:15 +0530339void fbcon_clear_msg(unsigned y_start, unsigned y_end)
340{
341 unsigned i, j;
342 uint32_t bg_color;
343 char *pixels;
344 unsigned count;
345
346 /* ignore anything that happens before fbcon is initialized */
347 if (!config)
348 return;
349
350 count = config->width * (FONT_HEIGHT * (y_end - y_start) - 1);
351 pixels = config->base;
352 pixels += y_start * ((config->bpp / 8) * FONT_HEIGHT * config->width);
353
354 fbcon_set_colors(FBCON_COMMON_MSG);
355 for (i = 0; i < count; i++) {
356 bg_color = BGCOLOR;
357 for (j = 0; j < (config->bpp / 8); j++) {
358 *pixels = (unsigned char) bg_color;
359 bg_color = bg_color >> 8;
360 pixels++;
361 }
362 }
363}
364
365void fbcon_putc_factor(char c, int type, unsigned scale_factor, int y_start)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800366{
Sandeep Pandadf39f752015-05-08 14:01:16 +0530367 char *pixels;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800368
369 /* ignore anything that happens before fbcon is initialized */
370 if (!config)
371 return;
372
373 if((unsigned char)c > 127)
374 return;
Sandeep Pandadf39f752015-05-08 14:01:16 +0530375
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800376 if((unsigned char)c < 32) {
377 if(c == '\n')
378 goto newline;
Sandeep Pandadf39f752015-05-08 14:01:16 +0530379 else if (c == '\r') {
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800380 cur_pos.x = 0;
Sandeep Pandadf39f752015-05-08 14:01:16 +0530381 return;
382 }
383 else
384 return;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800385 }
386
lijuangdd73d652015-06-05 21:29:37 +0800387 if (cur_pos.x == 0 && (unsigned char)c == ' ' &&
388 type != FBCON_SUBTITLE_MSG &&
389 type != FBCON_TITLE_MSG)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800390 return;
391
lijuangdd73d652015-06-05 21:29:37 +0800392 fbcon_set_colors(type);
393
394 pixels = config->base;
Monika Singhb879e492019-09-16 16:00:15 +0530395 /* if y_start is null, it will start from current y loaction */
396 if (y_start) {
397 cur_pos.x = 0;
398 cur_pos.y = y_start;
399 }
lijuangdd73d652015-06-05 21:29:37 +0800400 pixels += cur_pos.y * ((config->bpp / 8) * FONT_HEIGHT * config->width);
401 pixels += cur_pos.x * scale_factor * ((config->bpp / 8) * (FONT_WIDTH + 1));
402
403 fbcon_drawglyph(pixels, FGCOLOR, config->stride, (config->bpp / 8),
404 font5x12 + (c - 32) * 2, scale_factor);
405
406 cur_pos.x++;
407 if (cur_pos.x >= (int)(max_pos.x / scale_factor))
408 goto newline;
409
410 return;
411
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800412newline:
lijuangdd73d652015-06-05 21:29:37 +0800413 cur_pos.y += scale_factor;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800414 cur_pos.x = 0;
415 if(cur_pos.y >= max_pos.y) {
416 cur_pos.y = max_pos.y - 1;
417 fbcon_scroll_up();
Dima Zavin25ed9942009-01-28 17:04:19 -0800418 } else
419 fbcon_flush();
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800420}
421
Monika Singhb879e492019-09-16 16:00:15 +0530422void fbcon_putc(char c, int y_start)
lijuangdd73d652015-06-05 21:29:37 +0800423{
Monika Singhb879e492019-09-16 16:00:15 +0530424 fbcon_putc_factor(c, FBCON_COMMON_MSG, SCALE_FACTOR, y_start);
lijuangdd73d652015-06-05 21:29:37 +0800425}
426
427uint32_t fbcon_get_current_line(void)
428{
429 return cur_pos.y;
430}
431
432uint32_t fbcon_get_max_x(void)
433{
434 return max_pos.x;
435}
436
lijuangf3d7fc52018-04-23 16:34:29 +0800437uint32_t fbcon_get_width(void)
438{
439 if (config)
440 return config->width;
441 else
442 return 0;
443}
444
445uint32_t fbcon_get_height(void)
446{
447 if (config)
448 return config->height;
449 else
450 return 0;
451}
452
lijuangdd73d652015-06-05 21:29:37 +0800453uint32_t fbcon_get_current_bg(void)
454{
455 return BGCOLOR;
456}
457
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800458void fbcon_setup(struct fbcon_config *_config)
459{
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800460 ASSERT(_config);
461
462 config = _config;
463
464 switch (config->format) {
465 case FB_FORMAT_RGB565:
lijuangdd73d652015-06-05 21:29:37 +0800466 fb_color_formats = fb_color_formats_555;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800467 break;
lijuangdd73d652015-06-05 21:29:37 +0800468 case FB_FORMAT_RGB888:
469 fb_color_formats = fb_color_formats_888;
470 break;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800471 default:
472 dprintf(CRITICAL, "unknown framebuffer pixel format\n");
473 ASSERT(0);
474 break;
475 }
476
lijuangdd73d652015-06-05 21:29:37 +0800477 SELECT_BGCOLOR = fb_color_formats[FBCON_SELECT_MSG_BG_COLOR].bg;
478 fbcon_set_colors(FBCON_COMMON_MSG);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800479
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800480 cur_pos.x = 0;
481 cur_pos.y = 0;
lijuangdd73d652015-06-05 21:29:37 +0800482 max_pos.x = config->width / (FONT_WIDTH+1);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800483 max_pos.y = (config->height - 1) / FONT_HEIGHT;
lijuangdd73d652015-06-05 21:29:37 +0800484
Shashank Mittal37040832010-08-24 15:57:57 -0700485#if !DISPLAY_SPLASH_SCREEN
486 fbcon_clear();
487#endif
lijuangdd73d652015-06-05 21:29:37 +0800488
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800489}
Shashank Mittal4f99a882010-02-01 13:58:50 -0800490
491struct fbcon_config* fbcon_display(void)
492{
Mao Flynn7b379f32015-04-20 00:28:30 +0800493 return config;
Shashank Mittal4f99a882010-02-01 13:58:50 -0800494}
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700495
Mao Flynn7b379f32015-04-20 00:28:30 +0800496void fbcon_extract_to_screen(logo_img_header *header, void* address)
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530497{
Mao Flynn7b379f32015-04-20 00:28:30 +0800498 const uint8_t *imagestart = (const uint8_t *)address;
499 uint pos = 0, offset;
500 uint count = 0;
501 uint x = 0, y = 0;
502 uint8_t *base, *p;
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530503
Mao Flynn7b379f32015-04-20 00:28:30 +0800504 if (!config || header->width > config->width
505 || header->height > config->height) {
506 dprintf(INFO, "the logo img is too large\n");
507 return;
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530508 }
509
Mao Flynn7b379f32015-04-20 00:28:30 +0800510 base = (uint8_t *) config->base;
511
512 /* put the logo to be center */
513 offset = (config->height - header->height) / 2;
514 if (offset)
515 base += (offset * config->width) * 3;
516 offset = (config->width - header->width ) / 2;
517
518 x = offset;
519 while (count < (uint)header->height * (uint)header->width) {
520 uint8_t run = *(imagestart + pos);
521 bool repeat_run = (run & 0x80);
522 uint runlen = (run & 0x7f) + 1;
523 uint runpos;
524
525 /* consume the run byte */
526 pos++;
527
528 p = base + (y * config->width + x) * 3;
529
530 /* start of a run */
531 for (runpos = 0; runpos < runlen; runpos++) {
532 *p++ = *(imagestart + pos);
533 *p++ = *(imagestart + pos + 1);
534 *p++ = *(imagestart + pos + 2);
535 count++;
536
537 x++;
538
539 /* if a run of raw pixels, consume an input pixel */
540 if (!repeat_run)
541 pos += 3;
542 }
543
544 /* if this was a run of repeated pixels, consume the one input pixel we repeated */
545 if (repeat_run)
546 pos += 3;
547
548 /* the generator will keep compressing data line by line */
549 /* don't cross the lines */
550 if (x == header->width + offset) {
551 y++;
552 x = offset;
553 }
554 }
555
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530556}
557
Mao Flynn7b379f32015-04-20 00:28:30 +0800558void display_default_image_on_screen(void)
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700559{
Mao Flynn7b379f32015-04-20 00:28:30 +0800560 unsigned i = 0;
561 unsigned total_x;
562 unsigned total_y;
563 unsigned bytes_per_bpp;
564 unsigned image_base;
Channagoud Kadabi875a2a72015-04-24 17:26:38 -0700565#if DISPLAY_TYPE_MIPI
566 char *image = NULL;
567#endif
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530568
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530569 if (!config) {
570 dprintf(CRITICAL,"NULL configuration, image cannot be displayed\n");
571 return;
572 }
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700573
Mao Flynn7b379f32015-04-20 00:28:30 +0800574 fbcon_clear(); // clear screen with Black color
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530575
576 total_x = config->width;
577 total_y = config->height;
578 bytes_per_bpp = ((config->bpp) / 8);
jialongjhan1efba002020-05-22 18:25:56 +0800579
Mao Flynn7b379f32015-04-20 00:28:30 +0800580 image_base = ((((total_y/2) - (SPLASH_IMAGE_HEIGHT / 2) - 1) *
581 (config->width)) + (total_x/2 - (SPLASH_IMAGE_WIDTH / 2)));
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530582
jialongjhan1efba002020-05-22 18:25:56 +0800583
Channagoud Kadabi875a2a72015-04-24 17:26:38 -0700584#if ENABLE_WBC
585 image = (pm_appsbl_charging_in_progress() ? image_batt888 : imageBuffer_rgb888);
586#else
587 image = imageBuffer_rgb888;
588#endif
589
jialongjhan1efba002020-05-22 18:25:56 +0800590//[Arima][8901][JialongJhan]modify Boot logo 20190418 Start
591
592#if 0 //ignore default
Mao Flynn7b379f32015-04-20 00:28:30 +0800593 if (bytes_per_bpp == 3) {
594 for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) {
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530595 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
Channagoud Kadabi875a2a72015-04-24 17:26:38 -0700596 image + (i * SPLASH_IMAGE_WIDTH * bytes_per_bpp),
Mao Flynn7b379f32015-04-20 00:28:30 +0800597 SPLASH_IMAGE_WIDTH * bytes_per_bpp);
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530598 }
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700599 }
jialongjhan1efba002020-05-22 18:25:56 +0800600#endif
Zohaib Alam03708752014-10-23 17:51:57 -0400601
Mao Flynn7b379f32015-04-20 00:28:30 +0800602 if (bytes_per_bpp == 2) {
603 for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) {
604 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
605 imageBuffer + (i * SPLASH_IMAGE_WIDTH * bytes_per_bpp),
606 SPLASH_IMAGE_WIDTH * bytes_per_bpp);
Zohaib Alam03708752014-10-23 17:51:57 -0400607 }
608 }
Wenjun Zhang4e63ce42017-11-28 05:11:34 -0500609
jialongjhan1efba002020-05-22 18:25:56 +0800610 /*[Jialong]Description:
611 image_base is picture's placemark which we want wirte.
612 The formula is (Row * Total_Column)+Column, so we can obtain placemark of first pixel of picture.
613
614 image is array of picture.
615
616 We use memcpy function display all pixels of line,
617 and use "for loop" function display all lines of picture.*/
618
619 //Show logo's top parts.
620 image_base=(913*1080)+208;
621 image = logo_top;
622
623 if (bytes_per_bpp == 3) {
624 for (i = 0; i < FAIRPHONE_SPLASH_IMAGE_TOP_HEIGHT; i++) {
625 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
626 image + (i * FAIRPHONE_SPLASH_IMAGE_TOP_WIDTH * bytes_per_bpp),
627 FAIRPHONE_SPLASH_IMAGE_TOP_WIDTH * bytes_per_bpp);
628 }
629 }
630 //Show logo's top parts end.
631
632 //Show logo's bottom parts.
jialongjhan790b7aa2020-07-10 16:10:15 +0800633 image_base=(1843*1080)+296;
jialongjhan1efba002020-05-22 18:25:56 +0800634 image = logo_bottom;
635
636 if (bytes_per_bpp == 3) {
637 for (i = 0; i < FAIRPHONE_SPLASH_IMAGE_BOTTOM_HEIGHT; i++) {
638 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
639 image + (i * FAIRPHONE_SPLASH_IMAGE_BOTTOM_WIDTH * bytes_per_bpp),
640 FAIRPHONE_SPLASH_IMAGE_BOTTOM_WIDTH * bytes_per_bpp);
641 }
642 }
643 //Show logo's bottom parts end.
644
645 //[Arima][8901][JialongJhan]modify Boot logo 20190418 End
646
Zohaib Alam03708752014-10-23 17:51:57 -0400647 fbcon_flush();
Wenjun Zhang4e63ce42017-11-28 05:11:34 -0500648
649#if DISPLAY_MIPI_PANEL_NOVATEK_BLUE
650 if(is_cmd_mode_enabled())
651 mipi_dsi_cmd_mode_trigger();
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800652#endif
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700653}
Mao Flynn7b379f32015-04-20 00:28:30 +0800654
jialongjhan1efba002020-05-22 18:25:56 +0800655//[Arima][8901][JialongJhan]Show Fastboot logo 20190418 Start
656void display_fastboot_image_on_screen(void)
657{
658 unsigned i = 0;
659 unsigned bytes_per_bpp;
660 unsigned image_base;
661#if DISPLAY_TYPE_MIPI
662 char *image = NULL;
663#endif
664
665 if (!config) {
666 dprintf(CRITICAL,"NULL configuration, image cannot be displayed\n");
667 return;
668 }
669 fbcon_clear(); // clear screen with Black color
670 bytes_per_bpp = ((config->bpp) / 8);
671
672 //Show fastboot image 1
673 image_base=(702*1080)+319;
674 image = fastboot_logo1;
675
676 if (bytes_per_bpp == 3) {
677 for (i = 0; i < FAIRPHONE_FASTBOOT_IMAGE_1_HEIGHT; i++) {
678 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
679 image + (i * FAIRPHONE_FASTBOOT_IMAGE_1_WIDTH * bytes_per_bpp),
680 FAIRPHONE_FASTBOOT_IMAGE_1_WIDTH * bytes_per_bpp);
681 }
682 }
683
684 //Show fastboot image 2
685 image_base=(905*1080)+475;
686 image = fastboot_logo2;
687
688 if (bytes_per_bpp == 3) {
689 for (i = 0; i < FAIRPHONE_FASTBOOT_IMAGE_2_HEIGHT; i++) {
690 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
691 image + (i * FAIRPHONE_FASTBOOT_IMAGE_2_WIDTH * bytes_per_bpp),
692 FAIRPHONE_FASTBOOT_IMAGE_2_WIDTH * bytes_per_bpp);
693 }
694 }
695
696 //Show fastboot image 3
697 image_base=(1191*1080)+502;
698 image = fastboot_logo3;
699
700 if (bytes_per_bpp == 3) {
701 for (i = 0; i < FAIRPHONE_FASTBOOT_IMAGE_3_HEIGHT; i++) {
702 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
703 image + (i * FAIRPHONE_FASTBOOT_IMAGE_3_WIDTH * bytes_per_bpp),
704 FAIRPHONE_FASTBOOT_IMAGE_3_WIDTH * bytes_per_bpp);
705 }
706 }
707
708 //Show fastboot image 4
709 image_base=(1720*1080)+450;
710 image = fastboot_logo4;
711
712 if (bytes_per_bpp == 3) {
713 for (i = 0; i < FAIRPHONE_FASTBOOT_IMAGE_4_HEIGHT; i++) {
714 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
715 image + (i * FAIRPHONE_FASTBOOT_IMAGE_4_WIDTH * bytes_per_bpp),
716 FAIRPHONE_FASTBOOT_IMAGE_4_WIDTH * bytes_per_bpp);
717 }
718 }
719
720 fbcon_flush();
721}
722
723//[Arima][8901][JialongJhan]Show Fastboot logo 20190418 End
724
725//[Arima][8901][JialongJhan]Show Low battery logo 20190418 Start
726void display_lowbattery_image_on_screen(void)
727{
728 unsigned i = 0;
729 unsigned bytes_per_bpp;
730 unsigned image_base;
731#if DISPLAY_TYPE_MIPI
732 char *image = NULL;
733#endif
734
735 if (!config) {
736 dprintf(CRITICAL,"NULL configuration, image cannot be displayed\n");
737 return;
738 }
739 fbcon_clear(); // clear screen with Black color
740 bytes_per_bpp = ((config->bpp) / 8);
741
742 //Show lowb battery image 1
743 image_base=(758*1080)+421;
744 image = lowbattery_logo1;
745
746 if (bytes_per_bpp == 3) {
747 for (i = 0; i < FAIRPHONE_LOWBATTERY_IMAGE_1_HEIGHT; i++) {
748 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
749 image + (i * FAIRPHONE_LOWBATTERY_IMAGE_1_WIDTH * bytes_per_bpp),
750 FAIRPHONE_LOWBATTERY_IMAGE_1_WIDTH * bytes_per_bpp);
751 }
752 }
753
754 //Show lowb battery image 2
755 image_base=(1246*1080)+502;
756 image = lowbattery_logo2;
757
758 if (bytes_per_bpp == 3) {
759 for (i = 0; i < FAIRPHONE_LOWBATTERY_IMAGE_2_HEIGHT; i++) {
760 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
761 image + (i * FAIRPHONE_LOWBATTERY_IMAGE_2_WIDTH * bytes_per_bpp),
762 FAIRPHONE_LOWBATTERY_IMAGE_2_WIDTH * bytes_per_bpp);
763 }
764 }
765
766 //Show lowb battery image 3
767 image_base=(1452*1080)+488;
768 image = lowbattery_logo3;
769
770 if (bytes_per_bpp == 3) {
771 for (i = 0; i < FAIRPHONE_LOWBATTERY_IMAGE_3_HEIGHT; i++) {
772 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
773 image + (i * FAIRPHONE_LOWBATTERY_IMAGE_3_WIDTH * bytes_per_bpp),
774 FAIRPHONE_LOWBATTERY_IMAGE_3_WIDTH * bytes_per_bpp);
775 }
776 }
777
778 //Show lowb battery image 4
779 image_base=(1623*1080)+530;
780 image = lowbattery_logo4;
781
782 if (bytes_per_bpp == 3) {
783 for (i = 0; i < FAIRPHONE_LOWBATTERY_IMAGE_4_HEIGHT; i++) {
784 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
785 image + (i * FAIRPHONE_LOWBATTERY_IMAGE_4_WIDTH * bytes_per_bpp),
786 FAIRPHONE_LOWBATTERY_IMAGE_4_WIDTH * bytes_per_bpp);
787 }
788 }
789
790
791
792 fbcon_flush();
793}
794
795//[Arima][8901][JialongJhan]Show Low battery logo 20190418 End
796
Mao Flynn7b379f32015-04-20 00:28:30 +0800797
798void display_image_on_screen(void)
799{
800#if DISPLAY_TYPE_MIPI
801 int fetch_image_from_partition();
jialongjhan790b7aa2020-07-10 16:10:15 +0800802//[Arima][8901][JialongJhan][20200710]let bootlogo shows from lk for OTA Start
803 display_default_image_on_screen();
804// if (fetch_image_from_partition() < 0) {
805// display_default_image_on_screen();
806// } else {
807// /* data has been put into the right place */
808// fbcon_flush();
809// }
810//[Arima][8901][JialongJhan][20200710]let bootlogo shows from lk for OTA End
Mao Flynn7b379f32015-04-20 00:28:30 +0800811#else
812 display_default_image_on_screen();
813#endif
814}