wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Common LCD routines for supported CPUs |
| 3 | * |
| 4 | * (C) Copyright 2001-2002 |
| 5 | * Wolfgang Denk, DENX Software Engineering -- wd@denx.de |
| 6 | * |
| 7 | * See file CREDITS for list of people who contributed to this |
| 8 | * project. |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or |
| 11 | * modify it under the terms of the GNU General Public License as |
| 12 | * published by the Free Software Foundation; either version 2 of |
| 13 | * the License, or (at your option) any later version. |
| 14 | * |
| 15 | * This program is distributed in the hope that it will be useful, |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 18 | * GNU General Public License for more details. |
| 19 | * |
| 20 | * You should have received a copy of the GNU General Public License |
| 21 | * along with this program; if not, write to the Free Software |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 23 | * MA 02111-1307 USA |
| 24 | */ |
| 25 | |
| 26 | /************************************************************************/ |
| 27 | /* ** HEADER FILES */ |
| 28 | /************************************************************************/ |
| 29 | |
| 30 | /* #define DEBUG */ |
| 31 | |
| 32 | #include <config.h> |
| 33 | #include <common.h> |
| 34 | #include <command.h> |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 35 | #include <stdarg.h> |
Nikita Kiryanov | c088048 | 2013-02-24 21:28:43 +0000 | [diff] [blame] | 36 | #include <search.h> |
| 37 | #include <env_callback.h> |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 38 | #include <linux/types.h> |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 39 | #include <stdio_dev.h> |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 40 | #if defined(CONFIG_POST) |
| 41 | #include <post.h> |
| 42 | #endif |
| 43 | #include <lcd.h> |
wdenk | 8b0bfc6 | 2005-04-03 23:11:38 +0000 | [diff] [blame] | 44 | #include <watchdog.h> |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 45 | |
Robert Winkler | dd4425e | 2013-06-17 11:31:29 -0700 | [diff] [blame^] | 46 | #include <splash.h> |
| 47 | |
Marek Vasut | abc20ab | 2011-11-26 07:20:07 +0100 | [diff] [blame] | 48 | #if defined(CONFIG_CPU_PXA25X) || defined(CONFIG_CPU_PXA27X) || \ |
| 49 | defined(CONFIG_CPU_MONAHANS) |
| 50 | #define CONFIG_CPU_PXA |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 51 | #include <asm/byteorder.h> |
| 52 | #endif |
| 53 | |
| 54 | #if defined(CONFIG_MPC823) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 55 | #include <lcdvideo.h> |
| 56 | #endif |
| 57 | |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 58 | #if defined(CONFIG_ATMEL_LCD) |
| 59 | #include <atmel_lcdc.h> |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 60 | #endif |
| 61 | |
Stephen Warren | 6a195d2 | 2013-05-27 18:31:17 +0000 | [diff] [blame] | 62 | #if defined(CONFIG_LCD_DT_SIMPLEFB) |
| 63 | #include <libfdt.h> |
| 64 | #endif |
| 65 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 66 | /************************************************************************/ |
| 67 | /* ** FONT DATA */ |
| 68 | /************************************************************************/ |
| 69 | #include <video_font.h> /* Get font data, width and height */ |
Che-Liang Chiou | d3983ee | 2011-10-21 17:04:21 +0800 | [diff] [blame] | 70 | #include <video_font_data.h> |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 71 | |
wdenk | 88804d1 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 72 | /************************************************************************/ |
| 73 | /* ** LOGO DATA */ |
| 74 | /************************************************************************/ |
| 75 | #ifdef CONFIG_LCD_LOGO |
| 76 | # include <bmp_logo.h> /* Get logo data, width and height */ |
Che-Liang Chiou | c270730 | 2011-10-20 23:04:20 +0000 | [diff] [blame] | 77 | # include <bmp_logo_data.h> |
Alessandro Rubini | acb1386 | 2010-03-13 17:44:08 +0100 | [diff] [blame] | 78 | # if (CONSOLE_COLOR_WHITE >= BMP_LOGO_OFFSET) && (LCD_BPP != LCD_COLOR16) |
wdenk | 88804d1 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 79 | # error Default Color Map overlaps with Logo Color Map |
| 80 | # endif |
| 81 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 82 | |
Simon Glass | 676d319 | 2012-10-17 13:24:54 +0000 | [diff] [blame] | 83 | #ifndef CONFIG_LCD_ALIGNMENT |
| 84 | #define CONFIG_LCD_ALIGNMENT PAGE_SIZE |
| 85 | #endif |
| 86 | |
Simon Glass | 0d89efe | 2012-10-17 13:24:59 +0000 | [diff] [blame] | 87 | /* By default we scroll by a single line */ |
| 88 | #ifndef CONFIG_CONSOLE_SCROLL_LINES |
| 89 | #define CONFIG_CONSOLE_SCROLL_LINES 1 |
| 90 | #endif |
| 91 | |
Jeroen Hofstee | a5796c5 | 2013-01-12 12:07:59 +0000 | [diff] [blame] | 92 | /************************************************************************/ |
| 93 | /* ** CONSOLE DEFINITIONS & FUNCTIONS */ |
| 94 | /************************************************************************/ |
| 95 | #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) |
| 96 | # define CONSOLE_ROWS ((panel_info.vl_row-BMP_LOGO_HEIGHT) \ |
| 97 | / VIDEO_FONT_HEIGHT) |
| 98 | #else |
| 99 | # define CONSOLE_ROWS (panel_info.vl_row / VIDEO_FONT_HEIGHT) |
| 100 | #endif |
Wolfgang Denk | d87080b | 2006-03-31 18:32:53 +0200 | [diff] [blame] | 101 | |
Jeroen Hofstee | a5796c5 | 2013-01-12 12:07:59 +0000 | [diff] [blame] | 102 | #define CONSOLE_COLS (panel_info.vl_col / VIDEO_FONT_WIDTH) |
| 103 | #define CONSOLE_ROW_SIZE (VIDEO_FONT_HEIGHT * lcd_line_length) |
| 104 | #define CONSOLE_ROW_FIRST lcd_console_address |
| 105 | #define CONSOLE_ROW_SECOND (lcd_console_address + CONSOLE_ROW_SIZE) |
| 106 | #define CONSOLE_ROW_LAST (lcd_console_address + CONSOLE_SIZE \ |
| 107 | - CONSOLE_ROW_SIZE) |
| 108 | #define CONSOLE_SIZE (CONSOLE_ROW_SIZE * CONSOLE_ROWS) |
| 109 | #define CONSOLE_SCROLL_SIZE (CONSOLE_SIZE - CONSOLE_ROW_SIZE) |
| 110 | |
| 111 | #if LCD_BPP == LCD_MONOCHROME |
| 112 | # define COLOR_MASK(c) ((c) | (c) << 1 | (c) << 2 | (c) << 3 | \ |
| 113 | (c) << 4 | (c) << 5 | (c) << 6 | (c) << 7) |
| 114 | #elif (LCD_BPP == LCD_COLOR8) || (LCD_BPP == LCD_COLOR16) |
| 115 | # define COLOR_MASK(c) (c) |
| 116 | #else |
| 117 | # error Unsupported LCD BPP. |
| 118 | #endif |
| 119 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 120 | DECLARE_GLOBAL_DATA_PTR; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 121 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 122 | static void lcd_drawchars(ushort x, ushort y, uchar *str, int count); |
| 123 | static inline void lcd_puts_xy(ushort x, ushort y, uchar *s); |
| 124 | static inline void lcd_putc_xy(ushort x, ushort y, uchar c); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 125 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 126 | static int lcd_init(void *lcdbase); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 127 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 128 | static void *lcd_logo(void); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 129 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 130 | static int lcd_getbgcolor(void); |
| 131 | static void lcd_setfgcolor(int color); |
| 132 | static void lcd_setbgcolor(int color); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 133 | |
Wolfgang Denk | 46d1d5d | 2013-01-05 09:45:48 +0000 | [diff] [blame] | 134 | static int lcd_color_fg; |
| 135 | static int lcd_color_bg; |
Jeroen Hofstee | f1d205a | 2013-01-22 10:44:11 +0000 | [diff] [blame] | 136 | int lcd_line_length; |
Wolfgang Denk | 46d1d5d | 2013-01-05 09:45:48 +0000 | [diff] [blame] | 137 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 138 | char lcd_is_enabled = 0; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 139 | |
Jeroen Hofstee | f1d205a | 2013-01-22 10:44:11 +0000 | [diff] [blame] | 140 | static short console_col; |
| 141 | static short console_row; |
| 142 | |
| 143 | static void *lcd_console_address; |
Jeroen Hofstee | 00a0ca5 | 2013-01-22 10:44:12 +0000 | [diff] [blame] | 144 | static void *lcd_base; /* Start of framebuffer memory */ |
Jeroen Hofstee | f1d205a | 2013-01-22 10:44:11 +0000 | [diff] [blame] | 145 | |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 146 | static char lcd_flush_dcache; /* 1 to flush dcache after each lcd update */ |
| 147 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 148 | /************************************************************************/ |
| 149 | |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 150 | /* Flush LCD activity to the caches */ |
| 151 | void lcd_sync(void) |
| 152 | { |
| 153 | /* |
| 154 | * flush_dcache_range() is declared in common.h but it seems that some |
| 155 | * architectures do not actually implement it. Is there a way to find |
| 156 | * out whether it exists? For now, ARM is safe. |
| 157 | */ |
| 158 | #if defined(CONFIG_ARM) && !defined(CONFIG_SYS_DCACHE_OFF) |
| 159 | int line_length; |
| 160 | |
| 161 | if (lcd_flush_dcache) |
| 162 | flush_dcache_range((u32)lcd_base, |
| 163 | (u32)(lcd_base + lcd_get_size(&line_length))); |
| 164 | #endif |
| 165 | } |
| 166 | |
| 167 | void lcd_set_flush_dcache(int flush) |
| 168 | { |
| 169 | lcd_flush_dcache = (flush != 0); |
| 170 | } |
| 171 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 172 | /*----------------------------------------------------------------------*/ |
| 173 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 174 | static void console_scrollup(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 175 | { |
Simon Glass | 0d89efe | 2012-10-17 13:24:59 +0000 | [diff] [blame] | 176 | const int rows = CONFIG_CONSOLE_SCROLL_LINES; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 177 | |
Simon Glass | 0d89efe | 2012-10-17 13:24:59 +0000 | [diff] [blame] | 178 | /* Copy up rows ignoring those that will be overwritten */ |
| 179 | memcpy(CONSOLE_ROW_FIRST, |
| 180 | lcd_console_address + CONSOLE_ROW_SIZE * rows, |
| 181 | CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows); |
| 182 | |
| 183 | /* Clear the last rows */ |
| 184 | memset(lcd_console_address + CONSOLE_SIZE - CONSOLE_ROW_SIZE * rows, |
| 185 | COLOR_MASK(lcd_color_bg), |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 186 | CONSOLE_ROW_SIZE * rows); |
Simon Glass | 0d89efe | 2012-10-17 13:24:59 +0000 | [diff] [blame] | 187 | |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 188 | lcd_sync(); |
Simon Glass | 0d89efe | 2012-10-17 13:24:59 +0000 | [diff] [blame] | 189 | console_row -= rows; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 190 | } |
| 191 | |
| 192 | /*----------------------------------------------------------------------*/ |
| 193 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 194 | static inline void console_back(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 195 | { |
| 196 | if (--console_col < 0) { |
| 197 | console_col = CONSOLE_COLS-1 ; |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 198 | if (--console_row < 0) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 199 | console_row = 0; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 200 | } |
| 201 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 202 | lcd_putc_xy(console_col * VIDEO_FONT_WIDTH, |
| 203 | console_row * VIDEO_FONT_HEIGHT, ' '); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 204 | } |
| 205 | |
| 206 | /*----------------------------------------------------------------------*/ |
| 207 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 208 | static inline void console_newline(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 209 | { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 210 | console_col = 0; |
| 211 | |
| 212 | /* Check if we need to scroll the terminal */ |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 213 | if (++console_row >= CONSOLE_ROWS) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 214 | console_scrollup(); |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 215 | else |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 216 | lcd_sync(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 217 | } |
| 218 | |
| 219 | /*----------------------------------------------------------------------*/ |
| 220 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 221 | void lcd_putc(const char c) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 222 | { |
| 223 | if (!lcd_is_enabled) { |
| 224 | serial_putc(c); |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 225 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 226 | return; |
| 227 | } |
| 228 | |
| 229 | switch (c) { |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 230 | case '\r': |
| 231 | console_col = 0; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 232 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 233 | return; |
| 234 | case '\n': |
| 235 | console_newline(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 236 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 237 | return; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 238 | case '\t': /* Tab (8 chars alignment) */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 239 | console_col += 8; |
| 240 | console_col &= ~7; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 241 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 242 | if (console_col >= CONSOLE_COLS) |
| 243 | console_newline(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 244 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 245 | return; |
| 246 | case '\b': |
| 247 | console_back(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 248 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 249 | return; |
| 250 | default: |
| 251 | lcd_putc_xy(console_col * VIDEO_FONT_WIDTH, |
| 252 | console_row * VIDEO_FONT_HEIGHT, c); |
| 253 | if (++console_col >= CONSOLE_COLS) |
| 254 | console_newline(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 255 | } |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | /*----------------------------------------------------------------------*/ |
| 259 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 260 | void lcd_puts(const char *s) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 261 | { |
| 262 | if (!lcd_is_enabled) { |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 263 | serial_puts(s); |
| 264 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 265 | return; |
| 266 | } |
| 267 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 268 | while (*s) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 269 | lcd_putc(*s++); |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 270 | |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 271 | lcd_sync(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 272 | } |
| 273 | |
Haavard Skinnemoen | 15b17ab | 2008-09-01 16:21:20 +0200 | [diff] [blame] | 274 | /*----------------------------------------------------------------------*/ |
| 275 | |
| 276 | void lcd_printf(const char *fmt, ...) |
| 277 | { |
| 278 | va_list args; |
| 279 | char buf[CONFIG_SYS_PBSIZE]; |
| 280 | |
| 281 | va_start(args, fmt); |
| 282 | vsprintf(buf, fmt, args); |
| 283 | va_end(args); |
| 284 | |
| 285 | lcd_puts(buf); |
| 286 | } |
| 287 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 288 | /************************************************************************/ |
| 289 | /* ** Low-Level Graphics Routines */ |
| 290 | /************************************************************************/ |
| 291 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 292 | static void lcd_drawchars(ushort x, ushort y, uchar *str, int count) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 293 | { |
| 294 | uchar *dest; |
Marek Vasut | be547c6 | 2011-09-26 02:26:04 +0200 | [diff] [blame] | 295 | ushort row; |
| 296 | |
Anatolij Gustschin | 0f999c4 | 2012-04-27 04:41:16 +0000 | [diff] [blame] | 297 | #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) |
| 298 | y += BMP_LOGO_HEIGHT; |
| 299 | #endif |
| 300 | |
Marek Vasut | be547c6 | 2011-09-26 02:26:04 +0200 | [diff] [blame] | 301 | #if LCD_BPP == LCD_MONOCHROME |
| 302 | ushort off = x * (1 << LCD_BPP) % 8; |
| 303 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 304 | |
| 305 | dest = (uchar *)(lcd_base + y * lcd_line_length + x * (1 << LCD_BPP) / 8); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 306 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 307 | for (row = 0; row < VIDEO_FONT_HEIGHT; ++row, dest += lcd_line_length) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 308 | uchar *s = str; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 309 | int i; |
Alessandro Rubini | acb1386 | 2010-03-13 17:44:08 +0100 | [diff] [blame] | 310 | #if LCD_BPP == LCD_COLOR16 |
| 311 | ushort *d = (ushort *)dest; |
| 312 | #else |
| 313 | uchar *d = dest; |
| 314 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 315 | |
| 316 | #if LCD_BPP == LCD_MONOCHROME |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 317 | uchar rest = *d & -(1 << (8 - off)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 318 | uchar sym; |
| 319 | #endif |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 320 | for (i = 0; i < count; ++i) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 321 | uchar c, bits; |
| 322 | |
| 323 | c = *s++; |
| 324 | bits = video_fontdata[c * VIDEO_FONT_HEIGHT + row]; |
| 325 | |
| 326 | #if LCD_BPP == LCD_MONOCHROME |
| 327 | sym = (COLOR_MASK(lcd_color_fg) & bits) | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 328 | (COLOR_MASK(lcd_color_bg) & ~bits); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 329 | |
| 330 | *d++ = rest | (sym >> off); |
| 331 | rest = sym << (8-off); |
| 332 | #elif LCD_BPP == LCD_COLOR8 |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 333 | for (c = 0; c < 8; ++c) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 334 | *d++ = (bits & 0x80) ? |
| 335 | lcd_color_fg : lcd_color_bg; |
| 336 | bits <<= 1; |
| 337 | } |
| 338 | #elif LCD_BPP == LCD_COLOR16 |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 339 | for (c = 0; c < 8; ++c) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 340 | *d++ = (bits & 0x80) ? |
| 341 | lcd_color_fg : lcd_color_bg; |
| 342 | bits <<= 1; |
| 343 | } |
| 344 | #endif |
| 345 | } |
| 346 | #if LCD_BPP == LCD_MONOCHROME |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 347 | *d = rest | (*d & ((1 << (8 - off)) - 1)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 348 | #endif |
| 349 | } |
| 350 | } |
| 351 | |
| 352 | /*----------------------------------------------------------------------*/ |
| 353 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 354 | static inline void lcd_puts_xy(ushort x, ushort y, uchar *s) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 355 | { |
Anatolij Gustschin | 0f999c4 | 2012-04-27 04:41:16 +0000 | [diff] [blame] | 356 | lcd_drawchars(x, y, s, strlen((char *)s)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 357 | } |
| 358 | |
| 359 | /*----------------------------------------------------------------------*/ |
| 360 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 361 | static inline void lcd_putc_xy(ushort x, ushort y, uchar c) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 362 | { |
Anatolij Gustschin | 0f999c4 | 2012-04-27 04:41:16 +0000 | [diff] [blame] | 363 | lcd_drawchars(x, y, &c, 1); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 364 | } |
| 365 | |
| 366 | /************************************************************************/ |
| 367 | /** Small utility to check that you got the colours right */ |
| 368 | /************************************************************************/ |
| 369 | #ifdef LCD_TEST_PATTERN |
| 370 | |
| 371 | #define N_BLK_VERT 2 |
| 372 | #define N_BLK_HOR 3 |
| 373 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 374 | static int test_colors[N_BLK_HOR * N_BLK_VERT] = { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 375 | CONSOLE_COLOR_RED, CONSOLE_COLOR_GREEN, CONSOLE_COLOR_YELLOW, |
| 376 | CONSOLE_COLOR_BLUE, CONSOLE_COLOR_MAGENTA, CONSOLE_COLOR_CYAN, |
| 377 | }; |
| 378 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 379 | static void test_pattern(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 380 | { |
| 381 | ushort v_max = panel_info.vl_row; |
| 382 | ushort h_max = panel_info.vl_col; |
| 383 | ushort v_step = (v_max + N_BLK_VERT - 1) / N_BLK_VERT; |
| 384 | ushort h_step = (h_max + N_BLK_HOR - 1) / N_BLK_HOR; |
| 385 | ushort v, h; |
| 386 | uchar *pix = (uchar *)lcd_base; |
| 387 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 388 | printf("[LCD] Test Pattern: %d x %d [%d x %d]\n", |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 389 | h_max, v_max, h_step, v_step); |
| 390 | |
| 391 | /* WARNING: Code silently assumes 8bit/pixel */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 392 | for (v = 0; v < v_max; ++v) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 393 | uchar iy = v / v_step; |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 394 | for (h = 0; h < h_max; ++h) { |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 395 | uchar ix = N_BLK_HOR * iy + h / h_step; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 396 | *pix++ = test_colors[ix]; |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | #endif /* LCD_TEST_PATTERN */ |
| 401 | |
| 402 | |
| 403 | /************************************************************************/ |
| 404 | /* ** GENERIC Initialization Routines */ |
| 405 | /************************************************************************/ |
| 406 | |
Simon Glass | 676d319 | 2012-10-17 13:24:54 +0000 | [diff] [blame] | 407 | int lcd_get_size(int *line_length) |
| 408 | { |
| 409 | *line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8; |
| 410 | return *line_length * panel_info.vl_row; |
| 411 | } |
| 412 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 413 | int drv_lcd_init(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 414 | { |
Jean-Christophe PLAGNIOL-VILLARD | 52cb4d4 | 2009-05-16 12:14:54 +0200 | [diff] [blame] | 415 | struct stdio_dev lcddev; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 416 | int rc; |
| 417 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 418 | lcd_base = (void *) gd->fb_base; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 419 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 420 | lcd_init(lcd_base); /* LCD initialization */ |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 421 | |
| 422 | /* Device initialization */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 423 | memset(&lcddev, 0, sizeof(lcddev)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 424 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 425 | strcpy(lcddev.name, "lcd"); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 426 | lcddev.ext = 0; /* No extensions */ |
| 427 | lcddev.flags = DEV_FLAGS_OUTPUT; /* Output only */ |
| 428 | lcddev.putc = lcd_putc; /* 'putc' function */ |
| 429 | lcddev.puts = lcd_puts; /* 'puts' function */ |
| 430 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 431 | rc = stdio_register(&lcddev); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 432 | |
| 433 | return (rc == 0) ? 1 : rc; |
| 434 | } |
| 435 | |
| 436 | /*----------------------------------------------------------------------*/ |
Che-Liang Chiou | 0211090 | 2011-10-20 23:07:03 +0000 | [diff] [blame] | 437 | void lcd_clear(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 438 | { |
| 439 | #if LCD_BPP == LCD_MONOCHROME |
| 440 | /* Setting the palette */ |
| 441 | lcd_initcolregs(); |
| 442 | |
| 443 | #elif LCD_BPP == LCD_COLOR8 |
| 444 | /* Setting the palette */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 445 | lcd_setcolreg(CONSOLE_COLOR_BLACK, 0, 0, 0); |
| 446 | lcd_setcolreg(CONSOLE_COLOR_RED, 0xFF, 0, 0); |
| 447 | lcd_setcolreg(CONSOLE_COLOR_GREEN, 0, 0xFF, 0); |
| 448 | lcd_setcolreg(CONSOLE_COLOR_YELLOW, 0xFF, 0xFF, 0); |
| 449 | lcd_setcolreg(CONSOLE_COLOR_BLUE, 0, 0, 0xFF); |
| 450 | lcd_setcolreg(CONSOLE_COLOR_MAGENTA, 0xFF, 0, 0xFF); |
| 451 | lcd_setcolreg(CONSOLE_COLOR_CYAN, 0, 0xFF, 0xFF); |
| 452 | lcd_setcolreg(CONSOLE_COLOR_GREY, 0xAA, 0xAA, 0xAA); |
| 453 | lcd_setcolreg(CONSOLE_COLOR_WHITE, 0xFF, 0xFF, 0xFF); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 454 | #endif |
| 455 | |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 456 | #ifndef CONFIG_SYS_WHITE_ON_BLACK |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 457 | lcd_setfgcolor(CONSOLE_COLOR_BLACK); |
| 458 | lcd_setbgcolor(CONSOLE_COLOR_WHITE); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 459 | #else |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 460 | lcd_setfgcolor(CONSOLE_COLOR_WHITE); |
| 461 | lcd_setbgcolor(CONSOLE_COLOR_BLACK); |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 462 | #endif /* CONFIG_SYS_WHITE_ON_BLACK */ |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 463 | |
| 464 | #ifdef LCD_TEST_PATTERN |
| 465 | test_pattern(); |
| 466 | #else |
| 467 | /* set framebuffer to background color */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 468 | memset((char *)lcd_base, |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 469 | COLOR_MASK(lcd_getbgcolor()), |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 470 | lcd_line_length * panel_info.vl_row); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 471 | #endif |
| 472 | /* Paint the logo and retrieve LCD base address */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 473 | debug("[LCD] Drawing the logo...\n"); |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 474 | lcd_console_address = lcd_logo(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 475 | |
| 476 | console_col = 0; |
| 477 | console_row = 0; |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 478 | lcd_sync(); |
| 479 | } |
| 480 | |
| 481 | static int do_lcd_clear(cmd_tbl_t *cmdtp, int flag, int argc, |
| 482 | char *const argv[]) |
| 483 | { |
| 484 | lcd_clear(); |
| 485 | return 0; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 486 | } |
| 487 | |
| 488 | U_BOOT_CMD( |
Che-Liang Chiou | 0211090 | 2011-10-20 23:07:03 +0000 | [diff] [blame] | 489 | cls, 1, 1, do_lcd_clear, |
Peter Tyser | 2fb2604 | 2009-01-27 18:03:12 -0600 | [diff] [blame] | 490 | "clear screen", |
Wolfgang Denk | a89c33d | 2009-05-24 17:06:54 +0200 | [diff] [blame] | 491 | "" |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 492 | ); |
| 493 | |
| 494 | /*----------------------------------------------------------------------*/ |
| 495 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 496 | static int lcd_init(void *lcdbase) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 497 | { |
| 498 | /* Initialize the lcd controller */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 499 | debug("[LCD] Initializing LCD frambuffer at %p\n", lcdbase); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 500 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 501 | lcd_ctrl_init(lcdbase); |
Anatolij Gustschin | 1d3dea1 | 2013-03-29 14:00:13 +0100 | [diff] [blame] | 502 | |
| 503 | /* |
| 504 | * lcd_ctrl_init() of some drivers (i.e. bcm2835 on rpi_b) ignores |
| 505 | * the 'lcdbase' argument and uses custom lcd base address |
| 506 | * by setting up gd->fb_base. Check for this condition and fixup |
| 507 | * 'lcd_base' address. |
| 508 | */ |
| 509 | if ((unsigned long)lcdbase != gd->fb_base) |
| 510 | lcd_base = (void *)gd->fb_base; |
| 511 | |
| 512 | debug("[LCD] Using LCD frambuffer at %p\n", lcd_base); |
| 513 | |
Stephen Warren | 6d33071 | 2013-01-29 16:37:38 +0000 | [diff] [blame] | 514 | lcd_get_size(&lcd_line_length); |
| 515 | lcd_line_length = (panel_info.vl_col * NBITS(panel_info.vl_bpix)) / 8; |
Haavard Skinnemoen | 6f93d2b | 2008-09-01 16:21:21 +0200 | [diff] [blame] | 516 | lcd_is_enabled = 1; |
Che-Liang Chiou | 0211090 | 2011-10-20 23:07:03 +0000 | [diff] [blame] | 517 | lcd_clear(); |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 518 | lcd_enable(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 519 | |
| 520 | /* Initialize the console */ |
| 521 | console_col = 0; |
wdenk | 88804d1 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 522 | #ifdef CONFIG_LCD_INFO_BELOW_LOGO |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 523 | console_row = 7 + BMP_LOGO_HEIGHT / VIDEO_FONT_HEIGHT; |
| 524 | #else |
| 525 | console_row = 1; /* leave 1 blank line below logo */ |
| 526 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 527 | |
| 528 | return 0; |
| 529 | } |
| 530 | |
| 531 | |
| 532 | /************************************************************************/ |
| 533 | /* ** ROM capable initialization part - needed to reserve FB memory */ |
| 534 | /************************************************************************/ |
| 535 | /* |
| 536 | * This is called early in the system initialization to grab memory |
| 537 | * for the LCD controller. |
| 538 | * Returns new address for monitor, after reserving LCD buffer memory |
| 539 | * |
| 540 | * Note that this is running from ROM, so no write access to global data. |
| 541 | */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 542 | ulong lcd_setmem(ulong addr) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 543 | { |
| 544 | ulong size; |
Simon Glass | 676d319 | 2012-10-17 13:24:54 +0000 | [diff] [blame] | 545 | int line_length; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 546 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 547 | debug("LCD panel info: %d x %d, %d bit/pix\n", panel_info.vl_col, |
| 548 | panel_info.vl_row, NBITS(panel_info.vl_bpix)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 549 | |
Simon Glass | 676d319 | 2012-10-17 13:24:54 +0000 | [diff] [blame] | 550 | size = lcd_get_size(&line_length); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 551 | |
Simon Glass | 676d319 | 2012-10-17 13:24:54 +0000 | [diff] [blame] | 552 | /* Round up to nearest full page, or MMU section if defined */ |
| 553 | size = ALIGN(size, CONFIG_LCD_ALIGNMENT); |
| 554 | addr = ALIGN(addr - CONFIG_LCD_ALIGNMENT + 1, CONFIG_LCD_ALIGNMENT); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 555 | |
| 556 | /* Allocate pages for the frame buffer. */ |
| 557 | addr -= size; |
| 558 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 559 | debug("Reserving %ldk for LCD Framebuffer at: %08lx\n", |
| 560 | size >> 10, addr); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 561 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 562 | return addr; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | /*----------------------------------------------------------------------*/ |
| 566 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 567 | static void lcd_setfgcolor(int color) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 568 | { |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 569 | lcd_color_fg = color; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | /*----------------------------------------------------------------------*/ |
| 573 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 574 | static void lcd_setbgcolor(int color) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 575 | { |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 576 | lcd_color_bg = color; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 577 | } |
| 578 | |
| 579 | /*----------------------------------------------------------------------*/ |
| 580 | |
Wolfgang Denk | 46d1d5d | 2013-01-05 09:45:48 +0000 | [diff] [blame] | 581 | int lcd_getfgcolor(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 582 | { |
| 583 | return lcd_color_fg; |
| 584 | } |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 585 | |
| 586 | /*----------------------------------------------------------------------*/ |
| 587 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 588 | static int lcd_getbgcolor(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 589 | { |
| 590 | return lcd_color_bg; |
| 591 | } |
| 592 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 593 | /************************************************************************/ |
| 594 | /* ** Chipset depending Bitmap / Logo stuff... */ |
| 595 | /************************************************************************/ |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 596 | static inline ushort *configuration_get_cmap(void) |
| 597 | { |
| 598 | #if defined CONFIG_CPU_PXA |
| 599 | struct pxafb_info *fbi = &panel_info.pxa; |
| 600 | return (ushort *)fbi->palette; |
| 601 | #elif defined(CONFIG_MPC823) |
| 602 | immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
| 603 | cpm8xx_t *cp = &(immr->im_cpm); |
| 604 | return (ushort *)&(cp->lcd_cmap[255 * sizeof(ushort)]); |
| 605 | #elif defined(CONFIG_ATMEL_LCD) |
| 606 | return (ushort *)(panel_info.mmio + ATMEL_LCDC_LUT(0)); |
Anatolij Gustschin | d23019f | 2012-09-22 06:55:53 +0000 | [diff] [blame] | 607 | #elif !defined(CONFIG_ATMEL_HLCD) && !defined(CONFIG_EXYNOS_FB) |
| 608 | return panel_info.cmap; |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 609 | #elif defined(CONFIG_LCD_LOGO) |
Anatolij Gustschin | d23019f | 2012-09-22 06:55:53 +0000 | [diff] [blame] | 610 | return bmp_logo_palette; |
| 611 | #else |
| 612 | return NULL; |
| 613 | #endif |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 614 | } |
| 615 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 616 | #ifdef CONFIG_LCD_LOGO |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 617 | void bitmap_plot(int x, int y) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 618 | { |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 619 | #ifdef CONFIG_ATMEL_LCD |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 620 | uint *cmap = (uint *)bmp_logo_palette; |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 621 | #else |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 622 | ushort *cmap = (ushort *)bmp_logo_palette; |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 623 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 624 | ushort i, j; |
| 625 | uchar *bmap; |
| 626 | uchar *fb; |
| 627 | ushort *fb16; |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 628 | #if defined(CONFIG_MPC823) |
| 629 | immap_t *immr = (immap_t *) CONFIG_SYS_IMMR; |
| 630 | cpm8xx_t *cp = &(immr->im_cpm); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 631 | #endif |
Andre Renaud | 317461c | 2013-02-13 17:48:00 +0000 | [diff] [blame] | 632 | unsigned bpix = NBITS(panel_info.vl_bpix); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 633 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 634 | debug("Logo: width %d height %d colors %d cmap %d\n", |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 635 | BMP_LOGO_WIDTH, BMP_LOGO_HEIGHT, BMP_LOGO_COLORS, |
Anatolij Gustschin | 095407d | 2012-04-27 04:41:06 +0000 | [diff] [blame] | 636 | ARRAY_SIZE(bmp_logo_palette)); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 637 | |
| 638 | bmap = &bmp_logo_bitmap[0]; |
Andre Renaud | 317461c | 2013-02-13 17:48:00 +0000 | [diff] [blame] | 639 | fb = (uchar *)(lcd_base + y * lcd_line_length + x * bpix / 8); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 640 | |
Andre Renaud | 317461c | 2013-02-13 17:48:00 +0000 | [diff] [blame] | 641 | if (bpix < 12) { |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 642 | /* Leave room for default color map |
| 643 | * default case: generic system with no cmap (most likely 16bpp) |
| 644 | * cmap was set to the source palette, so no change is done. |
| 645 | * This avoids even more ifdefs in the next stanza |
| 646 | */ |
| 647 | #if defined(CONFIG_MPC823) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 648 | cmap = (ushort *) &(cp->lcd_cmap[BMP_LOGO_OFFSET * sizeof(ushort)]); |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 649 | #elif defined(CONFIG_ATMEL_LCD) |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 650 | cmap = (uint *)configuration_get_cmap(); |
Alessandro Rubini | acb1386 | 2010-03-13 17:44:08 +0100 | [diff] [blame] | 651 | #else |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 652 | cmap = configuration_get_cmap(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 653 | #endif |
| 654 | |
| 655 | WATCHDOG_RESET(); |
| 656 | |
| 657 | /* Set color map */ |
Anatolij Gustschin | 095407d | 2012-04-27 04:41:06 +0000 | [diff] [blame] | 658 | for (i = 0; i < ARRAY_SIZE(bmp_logo_palette); ++i) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 659 | ushort colreg = bmp_logo_palette[i]; |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 660 | #ifdef CONFIG_ATMEL_LCD |
| 661 | uint lut_entry; |
| 662 | #ifdef CONFIG_ATMEL_LCD_BGR555 |
| 663 | lut_entry = ((colreg & 0x000F) << 11) | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 664 | ((colreg & 0x00F0) << 2) | |
| 665 | ((colreg & 0x0F00) >> 7); |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 666 | #else /* CONFIG_ATMEL_LCD_RGB565 */ |
| 667 | lut_entry = ((colreg & 0x000F) << 1) | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 668 | ((colreg & 0x00F0) << 3) | |
| 669 | ((colreg & 0x0F00) << 4); |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 670 | #endif |
| 671 | *(cmap + BMP_LOGO_OFFSET) = lut_entry; |
| 672 | cmap++; |
| 673 | #else /* !CONFIG_ATMEL_LCD */ |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 674 | #ifdef CONFIG_SYS_INVERT_COLORS |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 675 | *cmap++ = 0xffff - colreg; |
| 676 | #else |
| 677 | *cmap++ = colreg; |
| 678 | #endif |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 679 | #endif /* CONFIG_ATMEL_LCD */ |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 680 | } |
| 681 | |
| 682 | WATCHDOG_RESET(); |
| 683 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 684 | for (i = 0; i < BMP_LOGO_HEIGHT; ++i) { |
| 685 | memcpy(fb, bmap, BMP_LOGO_WIDTH); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 686 | bmap += BMP_LOGO_WIDTH; |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 687 | fb += panel_info.vl_col; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 688 | } |
| 689 | } |
| 690 | else { /* true color mode */ |
Alessandro Rubini | acb1386 | 2010-03-13 17:44:08 +0100 | [diff] [blame] | 691 | u16 col16; |
Andre Renaud | 317461c | 2013-02-13 17:48:00 +0000 | [diff] [blame] | 692 | fb16 = (ushort *)fb; |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 693 | for (i = 0; i < BMP_LOGO_HEIGHT; ++i) { |
| 694 | for (j = 0; j < BMP_LOGO_WIDTH; j++) { |
Alessandro Rubini | acb1386 | 2010-03-13 17:44:08 +0100 | [diff] [blame] | 695 | col16 = bmp_logo_palette[(bmap[j]-16)]; |
| 696 | fb16[j] = |
| 697 | ((col16 & 0x000F) << 1) | |
| 698 | ((col16 & 0x00F0) << 3) | |
| 699 | ((col16 & 0x0F00) << 4); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 700 | } |
| 701 | bmap += BMP_LOGO_WIDTH; |
| 702 | fb16 += panel_info.vl_col; |
| 703 | } |
| 704 | } |
| 705 | |
| 706 | WATCHDOG_RESET(); |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 707 | lcd_sync(); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 708 | } |
Anatolij Gustschin | 2b5cb3d | 2012-04-27 04:41:27 +0000 | [diff] [blame] | 709 | #else |
| 710 | static inline void bitmap_plot(int x, int y) {} |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 711 | #endif /* CONFIG_LCD_LOGO */ |
| 712 | |
| 713 | /*----------------------------------------------------------------------*/ |
Jon Loeliger | c3517f9 | 2007-07-08 18:10:08 -0500 | [diff] [blame] | 714 | #if defined(CONFIG_CMD_BMP) || defined(CONFIG_SPLASH_SCREEN) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 715 | /* |
| 716 | * Display the BMP file located at address bmp_image. |
| 717 | * Only uncompressed. |
| 718 | */ |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 719 | |
| 720 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |
| 721 | #define BMP_ALIGN_CENTER 0x7FFF |
Nikita Kiryanov | 7c7e280 | 2012-08-09 00:14:51 +0000 | [diff] [blame] | 722 | |
| 723 | static void splash_align_axis(int *axis, unsigned long panel_size, |
| 724 | unsigned long picture_size) |
| 725 | { |
| 726 | unsigned long panel_picture_delta = panel_size - picture_size; |
| 727 | unsigned long axis_alignment; |
| 728 | |
| 729 | if (*axis == BMP_ALIGN_CENTER) |
| 730 | axis_alignment = panel_picture_delta / 2; |
| 731 | else if (*axis < 0) |
| 732 | axis_alignment = panel_picture_delta + *axis + 1; |
| 733 | else |
| 734 | return; |
| 735 | |
| 736 | *axis = max(0, axis_alignment); |
| 737 | } |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 738 | #endif |
| 739 | |
Tom Wai-Hong Tam | 45d7f52 | 2012-09-28 15:11:16 +0000 | [diff] [blame] | 740 | |
| 741 | #ifdef CONFIG_LCD_BMP_RLE8 |
| 742 | |
| 743 | #define BMP_RLE8_ESCAPE 0 |
| 744 | #define BMP_RLE8_EOL 0 |
| 745 | #define BMP_RLE8_EOBMP 1 |
| 746 | #define BMP_RLE8_DELTA 2 |
| 747 | |
| 748 | static void draw_unencoded_bitmap(ushort **fbp, uchar *bmap, ushort *cmap, |
| 749 | int cnt) |
| 750 | { |
| 751 | while (cnt > 0) { |
| 752 | *(*fbp)++ = cmap[*bmap++]; |
| 753 | cnt--; |
| 754 | } |
| 755 | } |
| 756 | |
| 757 | static void draw_encoded_bitmap(ushort **fbp, ushort c, int cnt) |
| 758 | { |
| 759 | ushort *fb = *fbp; |
| 760 | int cnt_8copy = cnt >> 3; |
| 761 | |
| 762 | cnt -= cnt_8copy << 3; |
| 763 | while (cnt_8copy > 0) { |
| 764 | *fb++ = c; |
| 765 | *fb++ = c; |
| 766 | *fb++ = c; |
| 767 | *fb++ = c; |
| 768 | *fb++ = c; |
| 769 | *fb++ = c; |
| 770 | *fb++ = c; |
| 771 | *fb++ = c; |
| 772 | cnt_8copy--; |
| 773 | } |
| 774 | while (cnt > 0) { |
| 775 | *fb++ = c; |
| 776 | cnt--; |
| 777 | } |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 778 | *fbp = fb; |
Tom Wai-Hong Tam | 45d7f52 | 2012-09-28 15:11:16 +0000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | /* |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 782 | * Do not call this function directly, must be called from lcd_display_bitmap. |
Tom Wai-Hong Tam | 45d7f52 | 2012-09-28 15:11:16 +0000 | [diff] [blame] | 783 | */ |
| 784 | static void lcd_display_rle8_bitmap(bmp_image_t *bmp, ushort *cmap, uchar *fb, |
| 785 | int x_off, int y_off) |
| 786 | { |
| 787 | uchar *bmap; |
| 788 | ulong width, height; |
| 789 | ulong cnt, runlen; |
| 790 | int x, y; |
| 791 | int decode = 1; |
| 792 | |
| 793 | width = le32_to_cpu(bmp->header.width); |
| 794 | height = le32_to_cpu(bmp->header.height); |
| 795 | bmap = (uchar *)bmp + le32_to_cpu(bmp->header.data_offset); |
| 796 | |
| 797 | x = 0; |
| 798 | y = height - 1; |
| 799 | |
| 800 | while (decode) { |
| 801 | if (bmap[0] == BMP_RLE8_ESCAPE) { |
| 802 | switch (bmap[1]) { |
| 803 | case BMP_RLE8_EOL: |
| 804 | /* end of line */ |
| 805 | bmap += 2; |
| 806 | x = 0; |
| 807 | y--; |
| 808 | /* 16bpix, 2-byte per pixel, width should *2 */ |
| 809 | fb -= (width * 2 + lcd_line_length); |
| 810 | break; |
| 811 | case BMP_RLE8_EOBMP: |
| 812 | /* end of bitmap */ |
| 813 | decode = 0; |
| 814 | break; |
| 815 | case BMP_RLE8_DELTA: |
| 816 | /* delta run */ |
| 817 | x += bmap[2]; |
| 818 | y -= bmap[3]; |
| 819 | /* 16bpix, 2-byte per pixel, x should *2 */ |
| 820 | fb = (uchar *) (lcd_base + (y + y_off - 1) |
| 821 | * lcd_line_length + (x + x_off) * 2); |
| 822 | bmap += 4; |
| 823 | break; |
| 824 | default: |
| 825 | /* unencoded run */ |
| 826 | runlen = bmap[1]; |
| 827 | bmap += 2; |
| 828 | if (y < height) { |
| 829 | if (x < width) { |
| 830 | if (x + runlen > width) |
| 831 | cnt = width - x; |
| 832 | else |
| 833 | cnt = runlen; |
| 834 | draw_unencoded_bitmap( |
| 835 | (ushort **)&fb, |
| 836 | bmap, cmap, cnt); |
| 837 | } |
| 838 | x += runlen; |
| 839 | } |
| 840 | bmap += runlen; |
| 841 | if (runlen & 1) |
| 842 | bmap++; |
| 843 | } |
| 844 | } else { |
| 845 | /* encoded run */ |
| 846 | if (y < height) { |
| 847 | runlen = bmap[0]; |
| 848 | if (x < width) { |
| 849 | /* aggregate the same code */ |
| 850 | while (bmap[0] == 0xff && |
| 851 | bmap[2] != BMP_RLE8_ESCAPE && |
| 852 | bmap[1] == bmap[3]) { |
| 853 | runlen += bmap[2]; |
| 854 | bmap += 2; |
| 855 | } |
| 856 | if (x + runlen > width) |
| 857 | cnt = width - x; |
| 858 | else |
| 859 | cnt = runlen; |
| 860 | draw_encoded_bitmap((ushort **)&fb, |
| 861 | cmap[bmap[1]], cnt); |
| 862 | } |
| 863 | x += runlen; |
| 864 | } |
| 865 | bmap += 2; |
| 866 | } |
| 867 | } |
| 868 | } |
| 869 | #endif |
| 870 | |
Anatolij Gustschin | d23019f | 2012-09-22 06:55:53 +0000 | [diff] [blame] | 871 | #if defined(CONFIG_MPC823) || defined(CONFIG_MCC200) |
Nikita Kiryanov | bfdcc65 | 2012-08-09 00:14:53 +0000 | [diff] [blame] | 872 | #define FB_PUT_BYTE(fb, from) *(fb)++ = (255 - *(from)++) |
Anatolij Gustschin | d23019f | 2012-09-22 06:55:53 +0000 | [diff] [blame] | 873 | #else |
| 874 | #define FB_PUT_BYTE(fb, from) *(fb)++ = *(from)++ |
Nikita Kiryanov | bfdcc65 | 2012-08-09 00:14:53 +0000 | [diff] [blame] | 875 | #endif |
| 876 | |
| 877 | #if defined(CONFIG_BMP_16BPP) |
| 878 | #if defined(CONFIG_ATMEL_LCD_BGR555) |
| 879 | static inline void fb_put_word(uchar **fb, uchar **from) |
| 880 | { |
| 881 | *(*fb)++ = (((*from)[0] & 0x1f) << 2) | ((*from)[1] & 0x03); |
| 882 | *(*fb)++ = ((*from)[0] & 0xe0) | (((*from)[1] & 0x7c) >> 2); |
| 883 | *from += 2; |
| 884 | } |
| 885 | #else |
| 886 | static inline void fb_put_word(uchar **fb, uchar **from) |
| 887 | { |
| 888 | *(*fb)++ = *(*from)++; |
| 889 | *(*fb)++ = *(*from)++; |
| 890 | } |
| 891 | #endif |
| 892 | #endif /* CONFIG_BMP_16BPP */ |
| 893 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 894 | int lcd_display_bitmap(ulong bmp_image, int x, int y) |
| 895 | { |
Anatolij Gustschin | 00cc559 | 2009-02-25 20:28:13 +0100 | [diff] [blame] | 896 | #if !defined(CONFIG_MCC200) |
| 897 | ushort *cmap = NULL; |
| 898 | #endif |
| 899 | ushort *cmap_base = NULL; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 900 | ushort i, j; |
| 901 | uchar *fb; |
| 902 | bmp_image_t *bmp=(bmp_image_t *)bmp_image; |
| 903 | uchar *bmap; |
Tom Wai-Hong Tam | fecac46 | 2012-09-28 15:11:14 +0000 | [diff] [blame] | 904 | ushort padded_width; |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 905 | unsigned long width, height, byte_width; |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 906 | unsigned long pwidth = panel_info.vl_col; |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 907 | unsigned colors, bpix, bmp_bpix; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 908 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 909 | if (!bmp || !(bmp->header.signature[0] == 'B' && |
| 910 | bmp->header.signature[1] == 'M')) { |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 911 | printf("Error: no valid bmp image at %lx\n", bmp_image); |
| 912 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 913 | return 1; |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 914 | } |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 915 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 916 | width = le32_to_cpu(bmp->header.width); |
| 917 | height = le32_to_cpu(bmp->header.height); |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 918 | bmp_bpix = le16_to_cpu(bmp->header.bit_count); |
| 919 | colors = 1 << bmp_bpix; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 920 | |
| 921 | bpix = NBITS(panel_info.vl_bpix); |
| 922 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 923 | if (bpix != 1 && bpix != 8 && bpix != 16 && bpix != 32) { |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 924 | printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
| 925 | bpix, bmp_bpix); |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 926 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 927 | return 1; |
| 928 | } |
| 929 | |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 930 | /* We support displaying 8bpp BMPs on 16bpp LCDs */ |
Nikita Kiryanov | dad631c | 2012-12-20 00:52:34 +0000 | [diff] [blame] | 931 | if (bpix != bmp_bpix && !(bmp_bpix == 8 && bpix == 16)) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 932 | printf ("Error: %d bit/pixel mode, but BMP has %d bit/pixel\n", |
| 933 | bpix, |
| 934 | le16_to_cpu(bmp->header.bit_count)); |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 935 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 936 | return 1; |
| 937 | } |
| 938 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 939 | debug("Display-bmp: %d x %d with %d colors\n", |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 940 | (int)width, (int)height, (int)colors); |
| 941 | |
Wolfgang Denk | f641471 | 2006-10-20 15:51:21 +0200 | [diff] [blame] | 942 | #if !defined(CONFIG_MCC200) |
| 943 | /* MCC200 LCD doesn't need CMAP, supports 1bpp b&w only */ |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 944 | if (bmp_bpix == 8) { |
Nikita Kiryanov | 203c37b | 2012-08-09 00:14:52 +0000 | [diff] [blame] | 945 | cmap = configuration_get_cmap(); |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 946 | cmap_base = cmap; |
| 947 | |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 948 | /* Set color map */ |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 949 | for (i = 0; i < colors; ++i) { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 950 | bmp_color_table_entry_t cte = bmp->color_table[i]; |
Mark Jackson | 1464eff | 2008-08-01 09:48:29 +0100 | [diff] [blame] | 951 | #if !defined(CONFIG_ATMEL_LCD) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 952 | ushort colreg = |
| 953 | ( ((cte.red) << 8) & 0xf800) | |
Wolfgang Denk | 59d80bf | 2005-09-21 15:24:52 +0200 | [diff] [blame] | 954 | ( ((cte.green) << 3) & 0x07e0) | |
| 955 | ( ((cte.blue) >> 3) & 0x001f) ; |
Jean-Christophe PLAGNIOL-VILLARD | 6d0f6bc | 2008-10-16 15:01:15 +0200 | [diff] [blame] | 956 | #ifdef CONFIG_SYS_INVERT_COLORS |
wdenk | 25d6712 | 2004-12-10 11:40:40 +0000 | [diff] [blame] | 957 | *cmap = 0xffff - colreg; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 958 | #else |
wdenk | 25d6712 | 2004-12-10 11:40:40 +0000 | [diff] [blame] | 959 | *cmap = colreg; |
| 960 | #endif |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 961 | #if defined(CONFIG_MPC823) |
wdenk | 25d6712 | 2004-12-10 11:40:40 +0000 | [diff] [blame] | 962 | cmap--; |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 963 | #else |
| 964 | cmap++; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 965 | #endif |
Mark Jackson | 1464eff | 2008-08-01 09:48:29 +0100 | [diff] [blame] | 966 | #else /* CONFIG_ATMEL_LCD */ |
| 967 | lcd_setcolreg(i, cte.red, cte.green, cte.blue); |
| 968 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 969 | } |
| 970 | } |
Wolfgang Denk | f641471 | 2006-10-20 15:51:21 +0200 | [diff] [blame] | 971 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 972 | |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 973 | /* |
| 974 | * BMP format for Monochrome assumes that the state of a |
| 975 | * pixel is described on a per Bit basis, not per Byte. |
| 976 | * So, in case of Monochrome BMP we should align widths |
| 977 | * on a byte boundary and convert them from Bit to Byte |
| 978 | * units. |
Wolfgang Denk | 511d0c7 | 2006-10-09 00:42:01 +0200 | [diff] [blame] | 979 | * Probably, PXA250 and MPC823 process 1bpp BMP images in |
| 980 | * their own ways, so make the converting to be MCC200 |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 981 | * specific. |
| 982 | */ |
| 983 | #if defined(CONFIG_MCC200) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 984 | if (bpix == 1) { |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 985 | width = ((width + 7) & ~7) >> 3; |
| 986 | x = ((x + 7) & ~7) >> 3; |
| 987 | pwidth= ((pwidth + 7) & ~7) >> 3; |
| 988 | } |
| 989 | #endif |
| 990 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 991 | padded_width = (width & 0x3 ? (width & ~0x3) + 4 : width); |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 992 | |
| 993 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |
Nikita Kiryanov | 7c7e280 | 2012-08-09 00:14:51 +0000 | [diff] [blame] | 994 | splash_align_axis(&x, pwidth, width); |
| 995 | splash_align_axis(&y, panel_info.vl_row, height); |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 996 | #endif /* CONFIG_SPLASH_SCREEN_ALIGN */ |
| 997 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 998 | if ((x + width) > pwidth) |
Wolfgang Denk | e8143e7 | 2006-08-30 23:09:00 +0200 | [diff] [blame] | 999 | width = pwidth - x; |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1000 | if ((y + height) > panel_info.vl_row) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1001 | height = panel_info.vl_row - y; |
| 1002 | |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 1003 | bmap = (uchar *) bmp + le32_to_cpu(bmp->header.data_offset); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1004 | fb = (uchar *) (lcd_base + |
Liu Ying | 8d46d5b | 2011-01-11 15:29:58 +0800 | [diff] [blame] | 1005 | (y + height - 1) * lcd_line_length + x * bpix / 8); |
Mark Jackson | a303dfb | 2009-02-06 10:37:49 +0100 | [diff] [blame] | 1006 | |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 1007 | switch (bmp_bpix) { |
Mark Jackson | a303dfb | 2009-02-06 10:37:49 +0100 | [diff] [blame] | 1008 | case 1: /* pass through */ |
| 1009 | case 8: |
Tom Wai-Hong Tam | 45d7f52 | 2012-09-28 15:11:16 +0000 | [diff] [blame] | 1010 | #ifdef CONFIG_LCD_BMP_RLE8 |
| 1011 | if (le32_to_cpu(bmp->header.compression) == BMP_BI_RLE8) { |
| 1012 | if (bpix != 16) { |
| 1013 | /* TODO implement render code for bpix != 16 */ |
| 1014 | printf("Error: only support 16 bpix"); |
| 1015 | return 1; |
| 1016 | } |
| 1017 | lcd_display_rle8_bitmap(bmp, cmap_base, fb, x, y); |
| 1018 | break; |
| 1019 | } |
| 1020 | #endif |
| 1021 | |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 1022 | if (bpix != 16) |
| 1023 | byte_width = width; |
| 1024 | else |
| 1025 | byte_width = width * 2; |
| 1026 | |
Mark Jackson | a303dfb | 2009-02-06 10:37:49 +0100 | [diff] [blame] | 1027 | for (i = 0; i < height; ++i) { |
| 1028 | WATCHDOG_RESET(); |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 1029 | for (j = 0; j < width; j++) { |
| 1030 | if (bpix != 16) { |
Nikita Kiryanov | bfdcc65 | 2012-08-09 00:14:53 +0000 | [diff] [blame] | 1031 | FB_PUT_BYTE(fb, bmap); |
Guennadi Liakhovetski | b245e65 | 2009-02-06 10:37:53 +0100 | [diff] [blame] | 1032 | } else { |
| 1033 | *(uint16_t *)fb = cmap_base[*(bmap++)]; |
| 1034 | fb += sizeof(uint16_t) / sizeof(*fb); |
| 1035 | } |
| 1036 | } |
Tom Wai-Hong Tam | fecac46 | 2012-09-28 15:11:14 +0000 | [diff] [blame] | 1037 | bmap += (padded_width - width); |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 1038 | fb -= byte_width + lcd_line_length; |
Mark Jackson | a303dfb | 2009-02-06 10:37:49 +0100 | [diff] [blame] | 1039 | } |
| 1040 | break; |
| 1041 | |
| 1042 | #if defined(CONFIG_BMP_16BPP) |
| 1043 | case 16: |
| 1044 | for (i = 0; i < height; ++i) { |
| 1045 | WATCHDOG_RESET(); |
Nikita Kiryanov | bfdcc65 | 2012-08-09 00:14:53 +0000 | [diff] [blame] | 1046 | for (j = 0; j < width; j++) |
| 1047 | fb_put_word(&fb, &bmap); |
| 1048 | |
Tom Wai-Hong Tam | fecac46 | 2012-09-28 15:11:14 +0000 | [diff] [blame] | 1049 | bmap += (padded_width - width) * 2; |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 1050 | fb -= width * 2 + lcd_line_length; |
Mark Jackson | a303dfb | 2009-02-06 10:37:49 +0100 | [diff] [blame] | 1051 | } |
| 1052 | break; |
| 1053 | #endif /* CONFIG_BMP_16BPP */ |
| 1054 | |
Donghwa Lee | fb6a9aa | 2012-05-09 19:23:37 +0000 | [diff] [blame] | 1055 | #if defined(CONFIG_BMP_32BPP) |
| 1056 | case 32: |
| 1057 | for (i = 0; i < height; ++i) { |
| 1058 | for (j = 0; j < width; j++) { |
| 1059 | *(fb++) = *(bmap++); |
| 1060 | *(fb++) = *(bmap++); |
| 1061 | *(fb++) = *(bmap++); |
| 1062 | *(fb++) = *(bmap++); |
| 1063 | } |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 1064 | fb -= lcd_line_length + width * (bpix / 8); |
Donghwa Lee | fb6a9aa | 2012-05-09 19:23:37 +0000 | [diff] [blame] | 1065 | } |
| 1066 | break; |
| 1067 | #endif /* CONFIG_BMP_32BPP */ |
Mark Jackson | a303dfb | 2009-02-06 10:37:49 +0100 | [diff] [blame] | 1068 | default: |
| 1069 | break; |
| 1070 | }; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1071 | |
Simon Glass | 9a8efc4 | 2012-10-30 13:40:18 +0000 | [diff] [blame] | 1072 | lcd_sync(); |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1073 | return 0; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1074 | } |
Jon Loeliger | c3517f9 | 2007-07-08 18:10:08 -0500 | [diff] [blame] | 1075 | #endif |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1076 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1077 | static void *lcd_logo(void) |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1078 | { |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1079 | #ifdef CONFIG_SPLASH_SCREEN |
| 1080 | char *s; |
| 1081 | ulong addr; |
| 1082 | static int do_splash = 1; |
| 1083 | |
| 1084 | if (do_splash && (s = getenv("splashimage")) != NULL) { |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1085 | int x = 0, y = 0; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1086 | do_splash = 0; |
| 1087 | |
Nikita Kiryanov | 581bb41 | 2013-01-30 21:39:57 +0000 | [diff] [blame] | 1088 | if (splash_screen_prepare()) |
Robert Winkler | dd4425e | 2013-06-17 11:31:29 -0700 | [diff] [blame^] | 1089 | return (void *)lcd_base; |
Nikita Kiryanov | 581bb41 | 2013-01-30 21:39:57 +0000 | [diff] [blame] | 1090 | |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1091 | addr = simple_strtoul (s, NULL, 16); |
| 1092 | #ifdef CONFIG_SPLASH_SCREEN_ALIGN |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1093 | s = getenv("splashpos"); |
| 1094 | if (s != NULL) { |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1095 | if (s[0] == 'm') |
| 1096 | x = BMP_ALIGN_CENTER; |
| 1097 | else |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1098 | x = simple_strtol(s, NULL, 0); |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1099 | |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1100 | s = strchr(s + 1, ','); |
| 1101 | if (s != NULL) { |
Matthias Weisser | 1ca298c | 2009-07-09 16:07:30 +0200 | [diff] [blame] | 1102 | if (s[1] == 'm') |
| 1103 | y = BMP_ALIGN_CENTER; |
| 1104 | else |
| 1105 | y = simple_strtol (s + 1, NULL, 0); |
| 1106 | } |
| 1107 | } |
| 1108 | #endif /* CONFIG_SPLASH_SCREEN_ALIGN */ |
| 1109 | |
Nikita Kiryanov | d3a555e | 2012-08-09 00:14:50 +0000 | [diff] [blame] | 1110 | if (bmp_display(addr, x, y) == 0) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1111 | return (void *)lcd_base; |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1112 | } |
| 1113 | #endif /* CONFIG_SPLASH_SCREEN */ |
| 1114 | |
Anatolij Gustschin | 2b5cb3d | 2012-04-27 04:41:27 +0000 | [diff] [blame] | 1115 | bitmap_plot(0, 0); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1116 | |
Haavard Skinnemoen | 6b59e03 | 2008-09-01 16:21:22 +0200 | [diff] [blame] | 1117 | #ifdef CONFIG_LCD_INFO |
| 1118 | console_col = LCD_INFO_X / VIDEO_FONT_WIDTH; |
| 1119 | console_row = LCD_INFO_Y / VIDEO_FONT_HEIGHT; |
| 1120 | lcd_show_board_info(); |
| 1121 | #endif /* CONFIG_LCD_INFO */ |
Stelian Pop | 39cf480 | 2008-05-09 21:57:18 +0200 | [diff] [blame] | 1122 | |
wdenk | 88804d1 | 2005-07-04 00:03:16 +0000 | [diff] [blame] | 1123 | #if defined(CONFIG_LCD_LOGO) && !defined(CONFIG_LCD_INFO_BELOW_LOGO) |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1124 | return (void *)((ulong)lcd_base + BMP_LOGO_HEIGHT * lcd_line_length); |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1125 | #else |
Nikita Kiryanov | 8f47d91 | 2012-05-24 01:42:38 +0000 | [diff] [blame] | 1126 | return (void *)lcd_base; |
Jeroen Hofstee | 6b03514 | 2013-01-12 12:07:56 +0000 | [diff] [blame] | 1127 | #endif /* CONFIG_LCD_LOGO && !defined(CONFIG_LCD_INFO_BELOW_LOGO) */ |
wdenk | 8655b6f | 2004-10-09 23:25:58 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
Nikita Kiryanov | c088048 | 2013-02-24 21:28:43 +0000 | [diff] [blame] | 1130 | #ifdef CONFIG_SPLASHIMAGE_GUARD |
| 1131 | static int on_splashimage(const char *name, const char *value, enum env_op op, |
| 1132 | int flags) |
| 1133 | { |
| 1134 | ulong addr; |
| 1135 | int aligned; |
| 1136 | |
| 1137 | if (op == env_op_delete) |
| 1138 | return 0; |
| 1139 | |
| 1140 | addr = simple_strtoul(value, NULL, 16); |
| 1141 | /* See README.displaying-bmps */ |
| 1142 | aligned = (addr % 4 == 2); |
| 1143 | if (!aligned) { |
| 1144 | printf("Invalid splashimage value. Value must be 16 bit aligned, but not 32 bit aligned\n"); |
| 1145 | return -1; |
| 1146 | } |
| 1147 | |
| 1148 | return 0; |
| 1149 | } |
| 1150 | |
| 1151 | U_BOOT_ENV_CALLBACK(splashimage, on_splashimage); |
| 1152 | #endif |
| 1153 | |
Vadim Bendebury | 395166c | 2012-09-28 15:11:13 +0000 | [diff] [blame] | 1154 | void lcd_position_cursor(unsigned col, unsigned row) |
| 1155 | { |
| 1156 | console_col = min(col, CONSOLE_COLS - 1); |
| 1157 | console_row = min(row, CONSOLE_ROWS - 1); |
| 1158 | } |
| 1159 | |
| 1160 | int lcd_get_pixel_width(void) |
| 1161 | { |
| 1162 | return panel_info.vl_col; |
| 1163 | } |
| 1164 | |
| 1165 | int lcd_get_pixel_height(void) |
| 1166 | { |
| 1167 | return panel_info.vl_row; |
| 1168 | } |
| 1169 | |
| 1170 | int lcd_get_screen_rows(void) |
| 1171 | { |
| 1172 | return CONSOLE_ROWS; |
| 1173 | } |
| 1174 | |
| 1175 | int lcd_get_screen_columns(void) |
| 1176 | { |
| 1177 | return CONSOLE_COLS; |
| 1178 | } |
Stephen Warren | 6a195d2 | 2013-05-27 18:31:17 +0000 | [diff] [blame] | 1179 | |
| 1180 | #if defined(CONFIG_LCD_DT_SIMPLEFB) |
| 1181 | static int lcd_dt_simplefb_configure_node(void *blob, int off) |
| 1182 | { |
| 1183 | u32 stride; |
| 1184 | fdt32_t cells[2]; |
| 1185 | int ret; |
Stephen Warren | 5af7d0f | 2013-06-13 17:13:11 -0600 | [diff] [blame] | 1186 | static const char format[] = |
Stephen Warren | 6a195d2 | 2013-05-27 18:31:17 +0000 | [diff] [blame] | 1187 | #if LCD_BPP == LCD_COLOR16 |
| 1188 | "r5g6b5"; |
| 1189 | #else |
| 1190 | ""; |
| 1191 | #endif |
| 1192 | |
| 1193 | if (!format[0]) |
| 1194 | return -1; |
| 1195 | |
| 1196 | stride = panel_info.vl_col * 2; |
| 1197 | |
| 1198 | cells[0] = cpu_to_fdt32(gd->fb_base); |
| 1199 | cells[1] = cpu_to_fdt32(stride * panel_info.vl_row); |
| 1200 | ret = fdt_setprop(blob, off, "reg", cells, sizeof(cells[0]) * 2); |
| 1201 | if (ret < 0) |
| 1202 | return -1; |
| 1203 | |
| 1204 | cells[0] = cpu_to_fdt32(panel_info.vl_col); |
| 1205 | ret = fdt_setprop(blob, off, "width", cells, sizeof(cells[0])); |
| 1206 | if (ret < 0) |
| 1207 | return -1; |
| 1208 | |
| 1209 | cells[0] = cpu_to_fdt32(panel_info.vl_row); |
| 1210 | ret = fdt_setprop(blob, off, "height", cells, sizeof(cells[0])); |
| 1211 | if (ret < 0) |
| 1212 | return -1; |
| 1213 | |
| 1214 | cells[0] = cpu_to_fdt32(stride); |
| 1215 | ret = fdt_setprop(blob, off, "stride", cells, sizeof(cells[0])); |
| 1216 | if (ret < 0) |
| 1217 | return -1; |
| 1218 | |
| 1219 | ret = fdt_setprop(blob, off, "format", format, strlen(format) + 1); |
| 1220 | if (ret < 0) |
| 1221 | return -1; |
| 1222 | |
| 1223 | ret = fdt_delprop(blob, off, "status"); |
| 1224 | if (ret < 0) |
| 1225 | return -1; |
| 1226 | |
| 1227 | return 0; |
| 1228 | } |
| 1229 | |
| 1230 | int lcd_dt_simplefb_add_node(void *blob) |
| 1231 | { |
Stephen Warren | 5af7d0f | 2013-06-13 17:13:11 -0600 | [diff] [blame] | 1232 | static const char compat[] = "simple-framebuffer"; |
| 1233 | static const char disabled[] = "disabled"; |
Stephen Warren | 6a195d2 | 2013-05-27 18:31:17 +0000 | [diff] [blame] | 1234 | int off, ret; |
| 1235 | |
| 1236 | off = fdt_add_subnode(blob, 0, "framebuffer"); |
| 1237 | if (off < 0) |
| 1238 | return -1; |
| 1239 | |
| 1240 | ret = fdt_setprop(blob, off, "status", disabled, sizeof(disabled)); |
| 1241 | if (ret < 0) |
| 1242 | return -1; |
| 1243 | |
| 1244 | ret = fdt_setprop(blob, off, "compatible", compat, sizeof(compat)); |
| 1245 | if (ret < 0) |
| 1246 | return -1; |
| 1247 | |
| 1248 | return lcd_dt_simplefb_configure_node(blob, off); |
| 1249 | } |
| 1250 | |
| 1251 | int lcd_dt_simplefb_enable_existing_node(void *blob) |
| 1252 | { |
| 1253 | int off; |
| 1254 | |
| 1255 | off = fdt_node_offset_by_compatible(blob, -1, "simple-framebuffer"); |
| 1256 | if (off < 0) |
| 1257 | return -1; |
| 1258 | |
| 1259 | return lcd_dt_simplefb_configure_node(blob, off); |
| 1260 | } |
| 1261 | #endif |