1 // Copyright 2008-2009 Segher Boessenkool <segher@kernel.crashing.org>
2 // Copyright 2003-2004 Felix Domke <tmbinc@elitedvb.net>
3 // This code is licensed to you under the terms of the GNU GPL, version 2;
4 // see file COPYING or http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
8 extern u8 console_font_10x16x4[];
16 u32 xres, yres, stride;
18 u32 cursor_x, cursor_y;
20 u32 border_left, border_right, border_top, border_bottom;
23 static void fb_write(u32 offset, u32 x)
25 // write32(0x00f00000 + offset, x);
26 u32 *p = (u32 *)(0x80f00000 + offset);
28 sync_after_write(p, 4);
31 static u32 fb_read(u32 offset)
33 // return read32(0x00f00000 + offset);
34 u32 *p = (u32 *)(0x80f00000 + offset);
39 static void fb_clear_lines(u32 top, u32 lines)
44 offset = fb.stride * top;
46 for (y = 0; y < lines; y++) {
47 for (x = 0; x < fb.xres/2; x++)
48 fb_write(offset + 4*x, 0x00800080);
54 static void fb_scroll_line(void)
58 u32 lines = FONT_YSIZE + FONT_YGAP;
60 offset = fb.stride * fb.border_top;
61 delta = fb.stride * lines;
63 for (y = fb.border_top; y < fb.yres - lines; y++) {
64 for (x = 0; x < fb.xres/2; x++)
65 fb_write(offset + 4*x, fb_read(offset + 4*x + delta));
70 fb_clear_lines(fb.yres - lines, lines);
75 static void fb_drawc(u32 x, u32 y, u8 c)
77 if (c < 0x20 || c > 0x7f)
81 u32 offset = fb.stride*y + 2*x;
82 u8 *font = &console_font_10x16x4[c * FONT_XSIZE * FONT_YSIZE / 2];
85 for (ay = 0; ay < FONT_YSIZE; ay++) {
86 for (ax = 0; ax < FONT_XSIZE / 2; ax++) {
88 u32 nybh = bits & 0xf0;
89 u32 nybl = bits & 0x0f;
91 q |= (nybh << 24) | (nybh << 20);
92 q |= (nybl << 12) | (nybl << 8);
93 fb_write(offset + 4*ax, q);
103 fb.cursor_y += FONT_YSIZE + FONT_YGAP;
106 fb.cursor_x = fb.border_left;
110 fb_drawc(fb.cursor_x, fb.cursor_y, c);
111 fb.cursor_x += FONT_XSIZE + FONT_XGAP;
112 if ((fb.cursor_x + FONT_XSIZE) > fb.border_right) {
113 fb.cursor_y += FONT_YSIZE + FONT_YGAP;
114 fb.cursor_x = fb.border_left;
118 if (fb.cursor_y + FONT_YSIZE >= fb.border_bottom)
123 static void fb_init(u32 xres, u32 yres, u32 stride)
131 fb.border_right = fb.xres - 30;
132 fb.border_bottom = fb.yres - 30;
134 fb.cursor_x = fb.border_left;
135 fb.cursor_y = fb.border_top;
137 fb_clear_lines(0, fb.yres);
140 void video_init(void)
142 // read VTR register to determine linecount and mode
143 u32 vtr = read16(0x0c002000);
144 u32 lines = vtr >> 4;
146 if ((vtr & 0x0f) > 10) { // progressive
147 // set framebuffer position
148 write32(0x0c00201c, 0x00f00000);
149 write32(0x0c002024, 0x00f00000);
150 } else { //interlaced
153 u32 vto = read32(0x0c00200c);
154 u32 vte = read32(0x0c002010);
156 // set framebuffer position
157 // try to figure out the interlacing order
158 if ((vto & 0x03ff) < (vte & 0x03ff)) {
159 write32(0x0c00201c, 0x00f00000);
160 write32(0x0c002024, 0x00f00000 + 2*640);
162 write32(0x0c00201c, 0x00f00000 + 2*640);
163 write32(0x0c002024, 0x00f00000);
167 fb_init(640, lines, 2*640);