blob: f2296a48a95fe3ebe857ce8641965e43a0561e03 [file] [log] [blame]
Dima Zavind5b0b6a2009-01-15 18:09:25 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
Channagoud Kadabi7af9fbc2015-02-13 20:09:55 -08005 * Copyright (c) 2009-2015, 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
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 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
40#include <pm_app_smbchg.h>
41#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},
91 [FBCON_UNLOCK_TITLE_MSG] = {RGB565_CYAN, RGB565_BLACK},
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},
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},
102 [FBCON_UNLOCK_TITLE_MSG] = {RGB888_CYAN, RGB888_BLACK},
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},
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
Sandeep Pandadf39f752015-05-08 14:01:16 +0530112static void fbcon_drawglyph(char *pixels, uint32_t paint, unsigned stride,
lijuangdd73d652015-06-05 21:29:37 +0800113 unsigned bpp, unsigned *glyph, unsigned scale_factor)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800114{
Sandeep Pandadf39f752015-05-08 14:01:16 +0530115 unsigned x, y, i, j, k;
116 unsigned data, temp;
117 uint32_t fg_color = paint;
lijuangdd73d652015-06-05 21:29:37 +0800118 stride -= FONT_WIDTH * scale_factor;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800119
120 data = glyph[0];
Sandeep Pandadf39f752015-05-08 14:01:16 +0530121 for (y = 0; y < FONT_HEIGHT / 2; ++y) {
122 temp = data;
lijuangdd73d652015-06-05 21:29:37 +0800123 for (i = 0; i < scale_factor; i++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530124 data = temp;
125 for (x = 0; x < FONT_WIDTH; ++x) {
126 if (data & 1) {
lijuangdd73d652015-06-05 21:29:37 +0800127 for (j = 0; j < scale_factor; j++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530128 fg_color = paint;
129 for (k = 0; k < bpp; k++) {
130 *pixels = (unsigned char) fg_color;
131 fg_color = fg_color >> 8;
132 pixels++;
133 }
134 }
135 }
136 else
137 {
lijuangdd73d652015-06-05 21:29:37 +0800138 for (j = 0; j < scale_factor; j++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530139 pixels = pixels + bpp;
140 }
141 }
142 data >>= 1;
143 }
144 pixels += (stride * bpp);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800145 }
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800146 }
147
148 data = glyph[1];
Sandeep Pandadf39f752015-05-08 14:01:16 +0530149 for (y = 0; y < FONT_HEIGHT / 2; ++y) {
150 temp = data;
lijuangdd73d652015-06-05 21:29:37 +0800151 for (i = 0; i < scale_factor; i++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530152 data = temp;
153 for (x = 0; x < FONT_WIDTH; ++x) {
154 if (data & 1) {
lijuangdd73d652015-06-05 21:29:37 +0800155 for (j = 0; j < scale_factor; j++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530156 fg_color = paint;
157 for (k = 0; k < bpp; k++) {
158 *pixels = (unsigned char) fg_color;
159 fg_color = fg_color >> 8;
160 pixels++;
161 }
162 }
163 }
164 else
165 {
lijuangdd73d652015-06-05 21:29:37 +0800166 for (j = 0; j < scale_factor; j++) {
Sandeep Pandadf39f752015-05-08 14:01:16 +0530167 pixels = pixels + bpp;
168 }
169 }
170 data >>= 1;
171 }
172 pixels += (stride * bpp);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800173 }
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800174 }
Sandeep Pandadf39f752015-05-08 14:01:16 +0530175
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800176}
177
lijuangdd73d652015-06-05 21:29:37 +0800178void fbcon_draw_msg_background(unsigned y_start, unsigned y_end,
179 uint32_t old_paint, int update)
180{
181 unsigned i, j;
182 uint32_t bg_color, check_color, tmp_color, tmp1_color;
183 char *pixels;
184 unsigned count = config->width * (FONT_HEIGHT * (y_end - y_start) - 1);
185
186 pixels = config->base;
187 pixels += y_start * ((config->bpp / 8) * FONT_HEIGHT * config->width);
188
189 if (update) {
190 bg_color = SELECT_BGCOLOR;
191 check_color = old_paint;
192 } else {
193 bg_color = old_paint;
194 check_color = SELECT_BGCOLOR;
195 }
196
197 for (i = 0; i < count; i++) {
198 tmp1_color = bg_color;
199 tmp_color = 0;
200 for (j = 0; j < (config->bpp / 8); j++) {
201 tmp_color |= *(pixels+j) << j*8;
202 }
203
204 if (tmp_color == check_color) {
205 for (j = 0; j < (config->bpp / 8); j++) {
206 *pixels = (unsigned char) tmp1_color;
207 tmp1_color = tmp1_color >> 8;
208 pixels++;
209 }
210 } else {
211 pixels += config->bpp / 8;
212 }
213 }
214}
215
Dima Zavin25ed9942009-01-28 17:04:19 -0800216static void fbcon_flush(void)
217{
Mao Flynn7b379f32015-04-20 00:28:30 +0800218 unsigned total_x, total_y;
219 unsigned bytes_per_bpp;
220
Dima Zavin25ed9942009-01-28 17:04:19 -0800221 if (config->update_start)
222 config->update_start();
223 if (config->update_done)
224 while (!config->update_done());
Mao Flynn7b379f32015-04-20 00:28:30 +0800225
226 total_x = config->width;
227 total_y = config->height;
228 bytes_per_bpp = ((config->bpp) / 8);
229 arch_clean_invalidate_cache_range((addr_t) config->base, (total_x * total_y * bytes_per_bpp));
Dima Zavin25ed9942009-01-28 17:04:19 -0800230}
231
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800232/* TODO: Take stride into account */
233static void fbcon_scroll_up(void)
234{
235 unsigned short *dst = config->base;
236 unsigned short *src = dst + (config->width * FONT_HEIGHT);
237 unsigned count = config->width * (config->height - FONT_HEIGHT);
238
239 while(count--) {
240 *dst++ = *src++;
241 }
242
243 count = config->width * FONT_HEIGHT;
244 while(count--) {
245 *dst++ = BGCOLOR;
246 }
Dima Zavin25ed9942009-01-28 17:04:19 -0800247
248 fbcon_flush();
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800249}
250
lijuang4304fce2015-08-14 20:52:47 +0800251void fbcon_draw_line(uint32_t type)
lijuangdd73d652015-06-05 21:29:37 +0800252{
253 char *pixels;
lijuang4304fce2015-08-14 20:52:47 +0800254 uint32_t line_color, tmp_color;
lijuangdd73d652015-06-05 21:29:37 +0800255 int i, j;
256
lijuang4304fce2015-08-14 20:52:47 +0800257 /* set line's color via diffrent type */
258 line_color = fb_color_formats[type].fg;
lijuangdd73d652015-06-05 21:29:37 +0800259
260 pixels = config->base;
261 pixels += cur_pos.y * ((config->bpp / 8) * FONT_HEIGHT * config->width);
262 pixels += cur_pos.x * ((config->bpp / 8) * (FONT_WIDTH + 1));
263
264 for (i = 0; i < (int)config->width; i++) {
lijuang4304fce2015-08-14 20:52:47 +0800265 tmp_color = line_color;
lijuangdd73d652015-06-05 21:29:37 +0800266 for (j = 0; j < (int)(config->bpp / 8); j++) {
267 *pixels = (unsigned char) tmp_color;
268 tmp_color = tmp_color >> 8;
269 pixels++;
270 }
271 }
272
273 cur_pos.y += 1;
274 cur_pos.x = 0;
275 if(cur_pos.y >= max_pos.y) {
276 cur_pos.y = max_pos.y - 1;
277 fbcon_scroll_up();
278 } else
279 fbcon_flush();
280}
281
282static void fbcon_set_colors(int type)
283{
284 BGCOLOR = fb_color_formats[type].bg;
285 FGCOLOR = fb_color_formats[type].fg;
286}
287
Shashank Mittal4f99a882010-02-01 13:58:50 -0800288void fbcon_clear(void)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800289{
Sandeep Pandadf39f752015-05-08 14:01:16 +0530290 unsigned long i = 0, j = 0;
291 unsigned char *pixels = config->base;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800292 unsigned count = config->width * config->height;
Sandeep Pandadf39f752015-05-08 14:01:16 +0530293 uint32_t bg_color;
lijuangdd73d652015-06-05 21:29:37 +0800294
295 fbcon_set_colors(FBCON_COMMON_MSG);
Sandeep Pandadf39f752015-05-08 14:01:16 +0530296 for (i = 0; i < count; i++) {
297 bg_color = BGCOLOR;
298 for (j = 0; j < (config->bpp / 8); j++) {
299 *pixels = (unsigned char) bg_color;
300 bg_color = bg_color >> 8;
301 pixels++;
302 }
303 }
lijuangdd73d652015-06-05 21:29:37 +0800304 cur_pos.x = 0;
305 cur_pos.y = 0;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800306}
307
lijuangdd73d652015-06-05 21:29:37 +0800308void fbcon_putc_factor(char c, int type, unsigned scale_factor)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800309{
Sandeep Pandadf39f752015-05-08 14:01:16 +0530310 char *pixels;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800311
312 /* ignore anything that happens before fbcon is initialized */
313 if (!config)
314 return;
315
316 if((unsigned char)c > 127)
317 return;
Sandeep Pandadf39f752015-05-08 14:01:16 +0530318
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800319 if((unsigned char)c < 32) {
320 if(c == '\n')
321 goto newline;
Sandeep Pandadf39f752015-05-08 14:01:16 +0530322 else if (c == '\r') {
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800323 cur_pos.x = 0;
Sandeep Pandadf39f752015-05-08 14:01:16 +0530324 return;
325 }
326 else
327 return;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800328 }
329
lijuangdd73d652015-06-05 21:29:37 +0800330 if (cur_pos.x == 0 && (unsigned char)c == ' ' &&
331 type != FBCON_SUBTITLE_MSG &&
332 type != FBCON_TITLE_MSG)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800333 return;
334
lijuangdd73d652015-06-05 21:29:37 +0800335 fbcon_set_colors(type);
336
337 pixels = config->base;
338 pixels += cur_pos.y * ((config->bpp / 8) * FONT_HEIGHT * config->width);
339 pixels += cur_pos.x * scale_factor * ((config->bpp / 8) * (FONT_WIDTH + 1));
340
341 fbcon_drawglyph(pixels, FGCOLOR, config->stride, (config->bpp / 8),
342 font5x12 + (c - 32) * 2, scale_factor);
343
344 cur_pos.x++;
345 if (cur_pos.x >= (int)(max_pos.x / scale_factor))
346 goto newline;
347
348 return;
349
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800350newline:
lijuangdd73d652015-06-05 21:29:37 +0800351 cur_pos.y += scale_factor;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800352 cur_pos.x = 0;
353 if(cur_pos.y >= max_pos.y) {
354 cur_pos.y = max_pos.y - 1;
355 fbcon_scroll_up();
Dima Zavin25ed9942009-01-28 17:04:19 -0800356 } else
357 fbcon_flush();
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800358}
359
lijuangdd73d652015-06-05 21:29:37 +0800360void fbcon_putc(char c)
361{
362 fbcon_putc_factor(c, FBCON_COMMON_MSG, SCALE_FACTOR);
363}
364
365uint32_t fbcon_get_current_line(void)
366{
367 return cur_pos.y;
368}
369
370uint32_t fbcon_get_max_x(void)
371{
372 return max_pos.x;
373}
374
375uint32_t fbcon_get_current_bg(void)
376{
377 return BGCOLOR;
378}
379
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800380void fbcon_setup(struct fbcon_config *_config)
381{
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800382 ASSERT(_config);
383
384 config = _config;
385
386 switch (config->format) {
387 case FB_FORMAT_RGB565:
lijuangdd73d652015-06-05 21:29:37 +0800388 fb_color_formats = fb_color_formats_555;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800389 break;
lijuangdd73d652015-06-05 21:29:37 +0800390 case FB_FORMAT_RGB888:
391 fb_color_formats = fb_color_formats_888;
392 break;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800393 default:
394 dprintf(CRITICAL, "unknown framebuffer pixel format\n");
395 ASSERT(0);
396 break;
397 }
398
lijuangdd73d652015-06-05 21:29:37 +0800399 SELECT_BGCOLOR = fb_color_formats[FBCON_SELECT_MSG_BG_COLOR].bg;
400 fbcon_set_colors(FBCON_COMMON_MSG);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800401
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800402 cur_pos.x = 0;
403 cur_pos.y = 0;
lijuangdd73d652015-06-05 21:29:37 +0800404 max_pos.x = config->width / (FONT_WIDTH+1);
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800405 max_pos.y = (config->height - 1) / FONT_HEIGHT;
lijuangdd73d652015-06-05 21:29:37 +0800406
Shashank Mittal37040832010-08-24 15:57:57 -0700407#if !DISPLAY_SPLASH_SCREEN
408 fbcon_clear();
409#endif
lijuangdd73d652015-06-05 21:29:37 +0800410
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800411}
Shashank Mittal4f99a882010-02-01 13:58:50 -0800412
413struct fbcon_config* fbcon_display(void)
414{
Mao Flynn7b379f32015-04-20 00:28:30 +0800415 return config;
Shashank Mittal4f99a882010-02-01 13:58:50 -0800416}
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700417
Mao Flynn7b379f32015-04-20 00:28:30 +0800418void fbcon_extract_to_screen(logo_img_header *header, void* address)
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530419{
Mao Flynn7b379f32015-04-20 00:28:30 +0800420 const uint8_t *imagestart = (const uint8_t *)address;
421 uint pos = 0, offset;
422 uint count = 0;
423 uint x = 0, y = 0;
424 uint8_t *base, *p;
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530425
Mao Flynn7b379f32015-04-20 00:28:30 +0800426 if (!config || header->width > config->width
427 || header->height > config->height) {
428 dprintf(INFO, "the logo img is too large\n");
429 return;
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530430 }
431
Mao Flynn7b379f32015-04-20 00:28:30 +0800432 base = (uint8_t *) config->base;
433
434 /* put the logo to be center */
435 offset = (config->height - header->height) / 2;
436 if (offset)
437 base += (offset * config->width) * 3;
438 offset = (config->width - header->width ) / 2;
439
440 x = offset;
441 while (count < (uint)header->height * (uint)header->width) {
442 uint8_t run = *(imagestart + pos);
443 bool repeat_run = (run & 0x80);
444 uint runlen = (run & 0x7f) + 1;
445 uint runpos;
446
447 /* consume the run byte */
448 pos++;
449
450 p = base + (y * config->width + x) * 3;
451
452 /* start of a run */
453 for (runpos = 0; runpos < runlen; runpos++) {
454 *p++ = *(imagestart + pos);
455 *p++ = *(imagestart + pos + 1);
456 *p++ = *(imagestart + pos + 2);
457 count++;
458
459 x++;
460
461 /* if a run of raw pixels, consume an input pixel */
462 if (!repeat_run)
463 pos += 3;
464 }
465
466 /* if this was a run of repeated pixels, consume the one input pixel we repeated */
467 if (repeat_run)
468 pos += 3;
469
470 /* the generator will keep compressing data line by line */
471 /* don't cross the lines */
472 if (x == header->width + offset) {
473 y++;
474 x = offset;
475 }
476 }
477
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530478}
479
Mao Flynn7b379f32015-04-20 00:28:30 +0800480void display_default_image_on_screen(void)
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700481{
Mao Flynn7b379f32015-04-20 00:28:30 +0800482 unsigned i = 0;
483 unsigned total_x;
484 unsigned total_y;
485 unsigned bytes_per_bpp;
486 unsigned image_base;
Channagoud Kadabi875a2a72015-04-24 17:26:38 -0700487#if DISPLAY_TYPE_MIPI
488 char *image = NULL;
489#endif
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530490
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530491 if (!config) {
492 dprintf(CRITICAL,"NULL configuration, image cannot be displayed\n");
493 return;
494 }
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700495
Mao Flynn7b379f32015-04-20 00:28:30 +0800496 fbcon_clear(); // clear screen with Black color
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530497
498 total_x = config->width;
499 total_y = config->height;
500 bytes_per_bpp = ((config->bpp) / 8);
Mao Flynn7b379f32015-04-20 00:28:30 +0800501 image_base = ((((total_y/2) - (SPLASH_IMAGE_HEIGHT / 2) - 1) *
502 (config->width)) + (total_x/2 - (SPLASH_IMAGE_WIDTH / 2)));
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530503
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700504#if DISPLAY_TYPE_MIPI
Channagoud Kadabi875a2a72015-04-24 17:26:38 -0700505#if ENABLE_WBC
506 image = (pm_appsbl_charging_in_progress() ? image_batt888 : imageBuffer_rgb888);
507#else
508 image = imageBuffer_rgb888;
509#endif
510
Mao Flynn7b379f32015-04-20 00:28:30 +0800511 if (bytes_per_bpp == 3) {
512 for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) {
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530513 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
Channagoud Kadabi875a2a72015-04-24 17:26:38 -0700514 image + (i * SPLASH_IMAGE_WIDTH * bytes_per_bpp),
Mao Flynn7b379f32015-04-20 00:28:30 +0800515 SPLASH_IMAGE_WIDTH * bytes_per_bpp);
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530516 }
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700517 }
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530518 fbcon_flush();
Kinson Chike5c93432011-06-17 09:10:29 -0700519#if DISPLAY_MIPI_PANEL_NOVATEK_BLUE
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530520 if(is_cmd_mode_enabled())
Mao Flynn7b379f32015-04-20 00:28:30 +0800521 mipi_dsi_cmd_mode_trigger();
Kinson Chike5c93432011-06-17 09:10:29 -0700522#endif
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800523
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700524#else
Zohaib Alam03708752014-10-23 17:51:57 -0400525
Mao Flynn7b379f32015-04-20 00:28:30 +0800526 if (bytes_per_bpp == 2) {
527 for (i = 0; i < SPLASH_IMAGE_HEIGHT; i++) {
528 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
529 imageBuffer + (i * SPLASH_IMAGE_WIDTH * bytes_per_bpp),
530 SPLASH_IMAGE_WIDTH * bytes_per_bpp);
Zohaib Alam03708752014-10-23 17:51:57 -0400531 }
532 }
533 fbcon_flush();
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800534#endif
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700535}
Mao Flynn7b379f32015-04-20 00:28:30 +0800536
537
538void display_image_on_screen(void)
539{
540#if DISPLAY_TYPE_MIPI
541 int fetch_image_from_partition();
542
543 if (fetch_image_from_partition() < 0) {
544 display_default_image_on_screen();
545 } else {
546 /* data has been put into the right place */
547 fbcon_flush();
548 }
549#else
550 display_default_image_on_screen();
551#endif
552}