Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 5 | * Copyright (c) 2009-2013, 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> |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 38 | |
| 39 | #include "font5x12.h" |
| 40 | |
| 41 | struct pos { |
| 42 | int x; |
| 43 | int y; |
| 44 | }; |
| 45 | |
| 46 | static struct fbcon_config *config = NULL; |
| 47 | |
Chandan Uddaraju | 2943fd6 | 2010-06-21 10:56:39 -0700 | [diff] [blame] | 48 | #define RGB565_BLACK 0x0000 |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 49 | #define RGB565_WHITE 0xffff |
| 50 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 51 | #define RGB888_BLACK 0x000000 |
| 52 | #define RGB888_WHITE 0xffffff |
| 53 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 54 | #define FONT_WIDTH 5 |
| 55 | #define FONT_HEIGHT 12 |
| 56 | |
| 57 | static uint16_t BGCOLOR; |
| 58 | static uint16_t FGCOLOR; |
| 59 | |
| 60 | static struct pos cur_pos; |
| 61 | static struct pos max_pos; |
| 62 | |
| 63 | static 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 Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 92 | static 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 Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 100 | /* TODO: Take stride into account */ |
| 101 | static 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 Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 115 | |
| 116 | fbcon_flush(); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 117 | } |
| 118 | |
| 119 | /* TODO: take stride into account */ |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 120 | void fbcon_clear(void) |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 121 | { |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 122 | unsigned count = config->width * config->height; |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 123 | memset(config->base, BGCOLOR, count * ((config->bpp) / 8)); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 126 | |
| 127 | static void fbcon_set_colors(unsigned bg, unsigned fg) |
| 128 | { |
| 129 | BGCOLOR = bg; |
| 130 | FGCOLOR = fg; |
| 131 | } |
| 132 | |
| 133 | void 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 | |
| 161 | newline: |
| 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 Zavin | 25ed994 | 2009-01-28 17:04:19 -0800 | [diff] [blame] | 167 | } else |
| 168 | fbcon_flush(); |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void 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 Mittal | c648e71 | 2010-10-06 18:37:42 -0700 | [diff] [blame] | 182 | fg = RGB565_WHITE; |
| 183 | bg = RGB565_BLACK; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 184 | break; |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 185 | case FB_FORMAT_RGB888: |
| 186 | fg = RGB888_WHITE; |
| 187 | bg = RGB888_BLACK; |
| 188 | break; |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 189 | default: |
| 190 | dprintf(CRITICAL, "unknown framebuffer pixel format\n"); |
| 191 | ASSERT(0); |
| 192 | break; |
| 193 | } |
| 194 | |
| 195 | fbcon_set_colors(bg, fg); |
| 196 | |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 197 | 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 Mittal | 3704083 | 2010-08-24 15:57:57 -0700 | [diff] [blame] | 201 | #if !DISPLAY_SPLASH_SCREEN |
| 202 | fbcon_clear(); |
| 203 | #endif |
Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 204 | } |
Shashank Mittal | 4f99a88 | 2010-02-01 13:58:50 -0800 | [diff] [blame] | 205 | |
| 206 | struct fbcon_config* fbcon_display(void) |
| 207 | { |
| 208 | return config; |
| 209 | } |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 210 | |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 211 | |
| 212 | extern struct fbimage* fetch_image_from_partition(); |
| 213 | void fbcon_putImage(struct fbimage *fbimg, bool flag); |
| 214 | |
| 215 | void 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 | |
| 234 | void fbcon_putImage(struct fbimage *fbimg, bool flag) |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 235 | { |
| 236 | unsigned i = 0; |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 237 | unsigned total_x; |
| 238 | unsigned total_y; |
| 239 | unsigned bytes_per_bpp; |
| 240 | unsigned image_base; |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 241 | unsigned width, pitch, height; |
| 242 | unsigned char *logo_base; |
| 243 | struct logo_img_header *header; |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 244 | |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 245 | |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 246 | if (!config) { |
| 247 | dprintf(CRITICAL,"NULL configuration, image cannot be displayed\n"); |
| 248 | return; |
| 249 | } |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 250 | |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 251 | 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 Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 261 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 262 | #if DISPLAY_TYPE_MIPI |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 263 | 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 Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 293 | } |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 294 | |
| 295 | fbcon_flush(); |
| 296 | |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 297 | #if DISPLAY_MIPI_PANEL_NOVATEK_BLUE |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 298 | if(is_cmd_mode_enabled()) |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 299 | mipi_dsi_cmd_mode_trigger(); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 300 | #endif |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 301 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 302 | #else |
| 303 | if (bytes_per_bpp == 2) |
| 304 | { |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 305 | for (i = 0; i < header->width; i++) |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 306 | { |
| 307 | memcpy (config->base + ((image_base + (i * (config->width))) * bytes_per_bpp), |
Aparna Mallavarapu | ce06a01 | 2013-09-06 23:03:24 +0530 | [diff] [blame] | 308 | fbimg->Image + (i * header->height * bytes_per_bpp), |
| 309 | header->height * bytes_per_bpp); |
| 310 | } |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 311 | } |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 312 | fbcon_flush(); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 313 | #endif |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 314 | } |