Dima Zavin | d5b0b6a | 2009-01-15 18:09:25 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2008, Google Inc. |
| 3 | * All rights reserved. |
| 4 | * |
Duy Truong | f3ac7b3 | 2013-02-13 01:07:28 -0800 | [diff] [blame] | 5 | * Copyright (c) 2009-2011, 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 | |
Greg Grisco | d625055 | 2011-06-29 14:40:23 -0700 | [diff] [blame] | 211 | void display_image_on_screen(void) |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 212 | { |
| 213 | unsigned i = 0; |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 214 | 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 Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 224 | fbcon_clear(); |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 225 | |
Channagoud Kadabi | 956cf50 | 2012-03-08 03:49:50 +0530 | [diff] [blame] | 226 | 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 Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 232 | #if DISPLAY_TYPE_MIPI |
| 233 | if (bytes_per_bpp == 3) |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 234 | { |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 235 | 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 Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 241 | } |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 242 | fbcon_flush(); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 243 | #if DISPLAY_MIPI_PANEL_NOVATEK_BLUE |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 244 | if(is_cmd_mode_enabled()) |
| 245 | mipi_dsi_cmd_mode_trigger(); |
Kinson Chik | e5c9343 | 2011-06-17 09:10:29 -0700 | [diff] [blame] | 246 | #endif |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 247 | |
Chandan Uddaraju | 78ae675 | 2010-10-19 12:57:10 -0700 | [diff] [blame] | 248 | #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 Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 258 | fbcon_flush(); |
Chandan Uddaraju | fe93e82 | 2010-11-21 20:44:47 -0800 | [diff] [blame] | 259 | #endif |
Chandan Uddaraju | 40b227d | 2010-08-03 19:25:41 -0700 | [diff] [blame] | 260 | } |