blob: 608f4c0dc26ea2fc6a89b8bf1e5ccbd8ee82afb4 [file] [log] [blame]
Dima Zavind5b0b6a2009-01-15 18:09:25 -08001/*
2 * Copyright (c) 2008, Google Inc.
3 * All rights reserved.
4 *
Duy Truongf3ac7b32013-02-13 01:07:28 -08005 * Copyright (c) 2009-2011, 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
Greg Griscod6250552011-06-29 14:40:23 -0700211void display_image_on_screen(void)
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700212{
213 unsigned i = 0;
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530214 unsigned total_x;
215 unsigned total_y;
216 unsigned bytes_per_bpp;
217 unsigned image_base;
218
219 if (!config) {
220 dprintf(CRITICAL,"NULL configuration, image cannot be displayed\n");
221 return;
222 }
223
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700224 fbcon_clear();
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700225
Channagoud Kadabi956cf502012-03-08 03:49:50 +0530226 total_x = config->width;
227 total_y = config->height;
228 bytes_per_bpp = ((config->bpp) / 8);
229 image_base = ((((total_y/2) - (SPLASH_IMAGE_WIDTH / 2) - 1) *
230 (config->width)) + (total_x/2 - (SPLASH_IMAGE_HEIGHT / 2)));
231
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700232#if DISPLAY_TYPE_MIPI
233 if (bytes_per_bpp == 3)
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700234 {
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700235 for (i = 0; i < SPLASH_IMAGE_WIDTH; i++)
236 {
237 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
238 imageBuffer_rgb888 + (i * SPLASH_IMAGE_HEIGHT * bytes_per_bpp),
239 SPLASH_IMAGE_HEIGHT * bytes_per_bpp);
240 }
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700241 }
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800242 fbcon_flush();
Kinson Chike5c93432011-06-17 09:10:29 -0700243#if DISPLAY_MIPI_PANEL_NOVATEK_BLUE
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800244 if(is_cmd_mode_enabled())
245 mipi_dsi_cmd_mode_trigger();
Kinson Chike5c93432011-06-17 09:10:29 -0700246#endif
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800247
Chandan Uddaraju78ae6752010-10-19 12:57:10 -0700248#else
249 if (bytes_per_bpp == 2)
250 {
251 for (i = 0; i < SPLASH_IMAGE_WIDTH; i++)
252 {
253 memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp),
254 imageBuffer + (i * SPLASH_IMAGE_HEIGHT * bytes_per_bpp),
255 SPLASH_IMAGE_HEIGHT * bytes_per_bpp);
256 }
257 }
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700258 fbcon_flush();
Chandan Uddarajufe93e822010-11-21 20:44:47 -0800259#endif
Chandan Uddaraju40b227d2010-08-03 19:25:41 -0700260}