blob: a1b8184f8e2ccc081c7830848e269212af0420ea [file] [log] [blame]
Dima Zavind5b0b6a2009-01-15 18:09:25 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
Aparna Mallavarapuce06a012013-09-06 23:03:24 +05305 * Copyright (c) 2009-2013, 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>
Dima Zavind5b0b6a2009-01-15 18:09:25 -080038
39#include "font5x12.h"
40
41struct pos {
42 int x;
43 int y;
44};
45
46static struct fbcon_config *config = NULL;
47
Chandan Uddaraju2943fd62010-06-21 10:56:39 -070048#define RGB565_BLACK 0x0000
Dima Zavind5b0b6a2009-01-15 18:09:25 -080049#define RGB565_WHITE 0xffff
50
Chandan Uddaraju78ae6752010-10-19 12:57:10 -070051#define RGB888_BLACK 0x000000
52#define RGB888_WHITE 0xffffff
53
Dima Zavind5b0b6a2009-01-15 18:09:25 -080054#define FONT_WIDTH 5
55#define FONT_HEIGHT 12
56
57static uint16_t BGCOLOR;
58static uint16_t FGCOLOR;
59
60static struct pos cur_pos;
61static struct pos max_pos;
62
63static void fbcon_drawglyph(uint16_t *pixels, uint16_t paint, unsigned stride,
64 unsigned *glyph)
65{
66 unsigned x, y, data;
67 stride -= FONT_WIDTH;
68
69 data = glyph[0];
70 for (y = 0; y < (FONT_HEIGHT / 2); ++y) {
71 for (x = 0; x < FONT_WIDTH; ++x) {
72 if (data & 1)
73 *pixels = paint;
74 data >>= 1;
75 pixels++;
76 }
77 pixels += stride;
78 }
79
80 data = glyph[1];
81 for (y = 0; y < (FONT_HEIGHT / 2); y++) {
82 for (x = 0; x < FONT_WIDTH; x++) {
83 if (data & 1)
84 *pixels = paint;
85 data >>= 1;
86 pixels++;
87 }
88 pixels += stride;
89 }
90}
91
Dima Zavin25ed9942009-01-28 17:04:19 -080092static void fbcon_flush(void)
93{
94 if (config->update_start)
95 config->update_start();
96 if (config->update_done)
97 while (!config->update_done());
98}
99
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800100/* TODO: Take stride into account */
101static void fbcon_scroll_up(void)
102{
103 unsigned short *dst = config->base;
104 unsigned short *src = dst + (config->width * FONT_HEIGHT);
105 unsigned count = config->width * (config->height - FONT_HEIGHT);
106
107 while(count--) {
108 *dst++ = *src++;
109 }
110
111 count = config->width * FONT_HEIGHT;
112 while(count--) {
113 *dst++ = BGCOLOR;
114 }
Dima Zavin25ed9942009-01-28 17:04:19 -0800115
116 fbcon_flush();
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800117}
118
119/* TODO: take stride into account */
Shashank Mittal4f99a882010-02-01 13:58:50 -0800120void fbcon_clear(void)
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800121{
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800122 unsigned count = config->width * config->height;
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700123 memset(config->base, BGCOLOR, count * ((config->bpp) / 8));
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800124}
125
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800126
127static void fbcon_set_colors(unsigned bg, unsigned fg)
128{
129 BGCOLOR = bg;
130 FGCOLOR = fg;
131}
132
133void fbcon_putc(char c)
134{
135 uint16_t *pixels;
136
137 /* ignore anything that happens before fbcon is initialized */
138 if (!config)
139 return;
140
141 if((unsigned char)c > 127)
142 return;
143 if((unsigned char)c < 32) {
144 if(c == '\n')
145 goto newline;
146 else if (c == '\r')
147 cur_pos.x = 0;
148 return;
149 }
150
151 pixels = config->base;
152 pixels += cur_pos.y * FONT_HEIGHT * config->width;
153 pixels += cur_pos.x * (FONT_WIDTH + 1);
154 fbcon_drawglyph(pixels, FGCOLOR, config->stride,
155 font5x12 + (c - 32) * 2);
156
157 cur_pos.x++;
158 if (cur_pos.x < max_pos.x)
159 return;
160
161newline:
162 cur_pos.y++;
163 cur_pos.x = 0;
164 if(cur_pos.y >= max_pos.y) {
165 cur_pos.y = max_pos.y - 1;
166 fbcon_scroll_up();
Dima Zavin25ed9942009-01-28 17:04:19 -0800167 } else
168 fbcon_flush();
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800169}
170
171void fbcon_setup(struct fbcon_config *_config)
172{
173 uint32_t bg;
174 uint32_t fg;
175
176 ASSERT(_config);
177
178 config = _config;
179
180 switch (config->format) {
181 case FB_FORMAT_RGB565:
Shashank Mittalc648e712010-10-06 18:37:42 -0700182 fg = RGB565_WHITE;
183 bg = RGB565_BLACK;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800184 break;
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700185 case FB_FORMAT_RGB888:
186 fg = RGB888_WHITE;
187 bg = RGB888_BLACK;
188 break;
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800189 default:
190 dprintf(CRITICAL, "unknown framebuffer pixel format\n");
191 ASSERT(0);
192 break;
193 }
194
195 fbcon_set_colors(bg, fg);
196
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800197 cur_pos.x = 0;
198 cur_pos.y = 0;
199 max_pos.x = config->width / (FONT_WIDTH+1);
200 max_pos.y = (config->height - 1) / FONT_HEIGHT;
Shashank Mittal37040832010-08-24 15:57:57 -0700201#if !DISPLAY_SPLASH_SCREEN
202 fbcon_clear();
203#endif
Dima Zavind5b0b6a2009-01-15 18:09:25 -0800204}
Shashank Mittal4f99a882010-02-01 13:58:50 -0800205
206struct fbcon_config* fbcon_display(void)
207{
208 return config;
209}
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700210
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530211
212extern struct fbimage* fetch_image_from_partition();
213void fbcon_putImage(struct fbimage *fbimg, bool flag);
214
215void display_image_on_screen()
216{
217 struct fbimage default_fbimg, *fbimg;
218 bool flag = true;
219
220 fbcon_clear();
221 fbimg = fetch_image_from_partition();
222
223 if(!fbimg) {
224 flag = false;
225 fbimg = &default_fbimg;
226 fbimg->header.width = SPLASH_IMAGE_HEIGHT;
227 fbimg->header.height = SPLASH_IMAGE_WIDTH;
228 fbimg->image = (unsigned char *)imageBuffer_rgb888;
229 }
230
231 fbcon_putImage(fbimg, flag);
232}
233
234void fbcon_putImage(struct fbimage *fbimg, bool flag)
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700235{
236 unsigned i = 0;
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530237 unsigned total_x;
238 unsigned total_y;
239 unsigned bytes_per_bpp;
240 unsigned image_base;
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530241 unsigned width, pitch, height;
242 unsigned char *logo_base;
243 struct logo_img_header *header;
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530244
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530245
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530246 if (!config) {
247 dprintf(CRITICAL,"NULL configuration, image cannot be displayed\n");
248 return;
249 }
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700250
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530251 if(fbimg) {
252 header = &fbimg->header;
253 width = pitch = header->width;
254 height = header->height;
255 logo_base = (unsigned char *)fbimg->image;
256 }
257
258 total_x = config->width;
259 total_y = config->height;
260 bytes_per_bpp = ((config->bpp) / 8);
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530261
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700262#if DISPLAY_TYPE_MIPI
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530263 if (bytes_per_bpp == 3)
264 {
265 if(flag) {
266 if (header->width == config->width && header->height == config->height)
267 return;
268 else {
269 logo_base = (unsigned char *)config->base + LOGO_IMG_OFFSET;
270 if (header->width > config->width) {
271 width = config->width;
272 pitch = header->width;
273 logo_base += (header->width - config->width) / 2 * bytes_per_bpp;
274 } else {
275 width = pitch = header->width;
276 }
277
278 if (header->height > config->height) {
279 height = config->height;
280 logo_base += (header->height - config->height) / 2 * pitch * bytes_per_bpp;
281 } else {
282 height = header->height;
283 }
284 }
285 }
286
287 image_base = ((((total_y/2) - (height / 2) ) *
288 (config->width)) + (total_x/2 - (width / 2)));
289 for (i = 0; i < height; i++) {
290 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
291 logo_base + (i * pitch * bytes_per_bpp), width * bytes_per_bpp);
292 }
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700293 }
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530294
295 fbcon_flush();
296
Kinson Chike5c93432011-06-17 09:10:29 -0700297#if DISPLAY_MIPI_PANEL_NOVATEK_BLUE
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530298 if(is_cmd_mode_enabled())
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800299 mipi_dsi_cmd_mode_trigger();
Kinson Chike5c93432011-06-17 09:10:29 -0700300#endif
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800301
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700302#else
303 if (bytes_per_bpp == 2)
304 {
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530305 for (i = 0; i < header->width; i++)
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700306 {
307 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
Aparna Mallavarapuce06a012013-09-06 23:03:24 +0530308 fbimg->Image + (i * header->height * bytes_per_bpp),
309 header->height * bytes_per_bpp);
310 }
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700311 }
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700312 fbcon_flush();
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800313#endif
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700314}