2 * Font module for Framebuffer.
4 * Copyright(C) 2009 Samsung Electronics
5 * InKi Dae <inki.dae@samsung.com>
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of
10 * the License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 #include <linux/types.h>
31 #include <asm/global_data.h>
35 #define XORMODE 0x80000000
36 #define CARRIAGE_RETURN 10
37 #define HORIZONTAL_TAP 9
39 extern struct fbcon_font_desc font_vga_8x16;
40 extern vidinfo_t panel_info;
48 static int bytes_per_pixel;
49 static unsigned char **line_addr;
51 static unsigned int g_default_x, g_default_y;
52 static unsigned int color_index;
54 static unsigned colormap [256];
55 extern vidinfo_t panel_info;
57 static char red_length = 8, red_offset = 16;
58 static char green_length = 8, green_offset = 8;
59 static char blue_length = 8, blue_offset = 0;
61 static unsigned int color_table_8[MAX_INDEX_TABLE] ={
66 0xffff00, /* YELLOW */
67 0xff00ff, /* MAGENTA */
70 0x80000000 /* XORMODE */
73 static unsigned int g_x, g_y;
75 void set_font_color(unsigned char index)
77 if (index < 0 || index > 8) {
78 printf("index is invalid.\n");
85 static void set_color_table(unsigned colidx, unsigned value)
88 unsigned short red, green, blue;
90 switch (bytes_per_pixel) {
93 red = (value >> 16) & 0xff;
94 green = (value >> 8) & 0xff;
96 res = ((red >> (8 - red_length)) << red_offset) |
97 ((green >> (8 - green_length)) << green_offset) |
98 ((blue >> (8 - blue_length)) << blue_offset);
101 printf("bpp %d is invalid.\n", bytes_per_pixel);
105 colormap [colidx] = res;
108 static void make_color_table(void)
112 for(i = 0; i < MAX_INDEX_TABLE; i++)
113 set_color_table(i, color_table_8[i]);
116 void set_font_xy(unsigned int x, unsigned int y)
121 /* it needs handling for exception */
127 void get_font_xy(unsigned int *x, unsigned int *y)
133 static inline void __setpixel (union multiptr loc, unsigned xormode, unsigned color)
135 switch(bytes_per_pixel) {
158 static void pixel(int x, int y)
160 unsigned int xormode;
163 if ((x < 0) || ((__u32)x >= panel_info.vl_width) ||
164 (y < 0) || ((__u32)y >= panel_info.vl_height))
167 xormode = (unsigned int)(color_index & XORMODE);
168 color_index &= (unsigned int)~XORMODE;
170 loc.p8 = line_addr [y] + x * bytes_per_pixel;
171 __setpixel (loc, xormode, colormap[color_index]);
174 static void put_char(int c)
178 if (c == CARRIAGE_RETURN) {
179 g_y += font_vga_8x16.height;
180 g_x = g_default_x - font_vga_8x16.width;
184 if (c == HORIZONTAL_TAP) {
189 /* check x-axis limitation. */
190 if (g_x > panel_info.vl_width - font_vga_8x16.width) {
192 g_y += font_vga_8x16.height;
195 for (i = 0; i < font_vga_8x16.height; i++) {
196 bits = font_vga_8x16.data [font_vga_8x16.height * c + i];
197 for (j = 0; j < font_vga_8x16.width; j++, bits <<= 1) {
199 pixel (g_x + j, g_y + i);
204 static void put_char_rotate(int c)
208 if (c == CARRIAGE_RETURN) {
209 g_y += font_vga_8x16.height;
210 g_x = g_default_x - font_vga_8x16.width;
214 if (c == HORIZONTAL_TAP) {
219 /* check y-axis limitation. */
220 if (g_x > panel_info.vl_height) {
222 g_y += font_vga_8x16.height;
225 for (i = 0; i < font_vga_8x16.height; i++) {
226 bits = font_vga_8x16.data [font_vga_8x16.height * c + i];
227 for (j = 0; j < font_vga_8x16.width; j++, bits <<= 1) {
229 pixel (panel_info.vl_width - (g_y + i), g_x + j);
234 void fb_printf(char *s)
238 for (i = 0; *s; i++, g_x += font_vga_8x16.width, s++) {
239 if (panel_info.lcd_rotate == SCREEN_NORMAL)
247 static void draw_ve_wheel(int x, int y, unsigned char color)
250 set_font_color(FONT_XOR);
252 set_font_xy(x, y + 6);
255 set_font_color(color);
256 set_font_xy(x, y + 2);
260 static void draw_ho_wheel(int x, int y, unsigned char color)
262 set_font_xy(x, y + 2);
263 set_font_color(FONT_XOR);
266 set_font_color(color);
269 set_font_xy(x, y + 6);
273 void draw_wheel(int x, int y, unsigned char color)
278 draw_ve_wheel(x, y, color);
280 draw_ho_wheel(x, y, color);
289 void draw_progress(int y, int per, unsigned char color)
294 static char buf[128] ={0,};
298 set_font_color(FONT_XOR);
300 memset(buf, 0x0, 64);
302 if (panel_info.lcd_rotate == SCREEN_NORMAL)
303 chars = panel_info.vl_width / font_vga_8x16.width - 7;
305 chars = panel_info.vl_height / font_vga_8x16.width - 7;
307 num = (per * 100) / (10000 / chars);
311 for (i = 0; i < num; i++)
314 sprintf(per_buf, ">%3d%%", per);
315 strcat(buf, per_buf);
319 for (i = 0; i < num; i++)
324 set_font_color(color);
329 DECLARE_GLOBAL_DATA_PTR;
336 line_length = panel_info.vl_width * 4;
337 bytes_per_pixel = panel_info.vl_bpix / 8;
339 line_addr = (unsigned char **)malloc(sizeof(__u32) * panel_info.vl_height);
341 for (y = 0; y < panel_info.vl_height; y++, addr += line_length) {
342 line_addr[y] = (unsigned char *)(gd->fb_base + addr);
353 g_default_x = g_default_y = 0;
357 void fb_clear(int range)
360 int line_length = panel_info.vl_width * 4;
363 range = panel_info.vl_height;
365 for (y = 0; y < range; y++)
366 memset(line_addr[y], 0x0, line_length);
369 unsigned int get_chars(void)
374 chars = panel_info.vl_width / font_vga_8x16.width - 3;
375 lines = panel_info.vl_height / font_vga_8x16.height;
377 return chars * lines;