3 * Copyright (C) 2008 Advanced Micro Devices, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <libpayload.h>
31 #include <video_console.h>
35 /* This is the video mode that we're going to use for our VGA screen */
37 static const struct mode
{
39 unsigned int hactive
, hblankstart
, hsyncstart
;
40 unsigned int hsyncend
, hblankend
, htotal
;
41 unsigned int vactive
, vblankstart
, vsyncstart
;
42 unsigned int vsyncend
, vblankend
, vtotal
;
49 .hsyncstart
= 640 + 40,
50 .hsyncend
= 640 + 40 + 96,
51 .hblankend
= 640 + 40 + 96 + 24,
52 .htotal
= 640 + 40 + 96 + 24,
54 .vsyncstart
= 400 + 39,
55 .vsyncend
= 400 + 39 + 2,
56 .vblankend
= 400 + 39 + 2 + 9,
57 .vtotal
= 400 + 39 + 2 + 9,
61 /* These are the color definitions for the 16 standard colors */
63 static const unsigned int vga_colors
[] = {
64 (0x00 << 16) | (0x00 << 8) | 0x00,
65 (0xAA << 16) | (0x00 << 8) | 0x00,
66 (0x00 << 16) | (0xAA << 8) | 0x00,
67 (0xAA << 16) | (0x55 << 8) | 0x00,
68 (0x00 << 16) | (0x00 << 8) | 0xAA,
69 (0xAA << 16) | (0x00 << 8) | 0xAA,
70 (0x00 << 16) | (0xAA << 8) | 0xAA,
71 (0xAA << 16) | (0xAA << 8) | 0xAA,
72 (0x55 << 16) | (0x55 << 8) | 0x55,
73 (0xFF << 16) | (0x55 << 8) | 0x55,
74 (0x55 << 16) | (0xFF << 8) | 0x55,
75 (0xFF << 16) | (0xFF << 8) | 0x55,
76 (0x55 << 16) | (0x55 << 8) | 0xFF,
77 (0xFF << 16) | (0x55 << 8) | 0xFF,
78 (0x55 << 16) | (0xFF << 8) | 0xFF,
79 (0xFF << 16) | (0xFF << 8) | 0xFF,
82 /* Addresses for the various components */
84 static unsigned long dcaddr
;
85 static unsigned long vgaddr
;
86 static unsigned long gpaddr
;
87 static unsigned long fbaddr
;
89 #define DC (phys_to_virt(dcaddr))
90 #define VG (phys_to_virt(vgaddr))
91 #define GP (phys_to_virt(gpaddr))
92 #define FB ((unsigned char *) phys_to_virt(fbaddr))
94 static void init_video_mode(void)
96 unsigned int lo
, hi
, val
;
101 rdmsr(0x4c000015, lo
, hi
);
108 wrmsr(0x4c000015, lo
, hi
);
111 for(i
= 0; i
< 1000; i
++) {
112 rdmsr(0x4c000015, lo
, hi
);
118 wrmsr(0x4c000015, lo
, hi
);
120 rdmsr(0x48002001, lo
, hi
);
122 wrmsr(0x48002001, lo
, hi
);
124 writel(0x4758, DC
+ 0x00);
126 val
= readl(DC
+ 0x00);
128 writel(0, DC
+ 0x10);
129 writel(0, DC
+ 0x14);
130 writel(0, DC
+ 0x18);
132 /* Set up the default scaling */
134 val
= readl(DC
+ 0xD4);
136 writel((0x4000 << 16) | 0x4000, DC
+ 0x90);
137 writel(0, DC
+ 0x94);
138 writel(val
& ~0xf3040000, DC
+ 0xD4);
140 /* Set up the compression (or lack thereof) */
141 writel(vga_mode
.hactive
* vga_mode
.vactive
| 0x01, DC
+ 0x2C);
143 val
= readl(DC
+ 0x88);
144 writel(val
& ~0xC00, DC
+ 0x88);
145 writel(0, DC
+ 0x8C);
148 writel(vga_mode
.hactive
>> 3, DC
+ 0x34);
149 writel((vga_mode
.hactive
+ 7) >> 3, DC
+ 0x30);
151 /* Set up default watermarks */
154 wrmsr(0x80000011, lo
, hi
);
156 /* Write the timings */
158 writel((vga_mode
.hactive
- 1) | ((vga_mode
.htotal
- 1) << 16),
161 writel((vga_mode
.hblankstart
- 1) | ((vga_mode
.hblankend
- 1) << 16),
164 writel((vga_mode
.hsyncstart
- 1) | ((vga_mode
.hsyncend
- 1) << 16),
167 writel((vga_mode
.vactive
- 1) | ((vga_mode
.vtotal
- 1) << 16),
170 writel((vga_mode
.vblankstart
- 1) | ((vga_mode
.vblankend
- 1) << 16),
173 writel((vga_mode
.vsyncstart
- 1) | ((vga_mode
.vsyncend
- 1) << 16),
176 writel(((vga_mode
.hactive
- 1) << 16) | (vga_mode
.vactive
- 1),
179 /* Write the VG configuration */
181 writel(0x290000F | vga_mode
.synccfg
, VG
+ 0x08);
183 /* Turn on the dacs */
185 val
= readl(VG
+ 0x50);
186 writel((val
& ~0xC00) | 0x01, VG
+ 0x50);
188 /* Set the framebuffer base */
189 writel(fbaddr
, DC
+ 0x84);
191 /* Write the final configuration */
193 writel(0xB000059, DC
+ 0x08);
194 writel(0, DC
+ 0x0C);
195 writel(0x2B601, DC
+ 0x04);
198 static void geodelx_set_palette(int entry
, unsigned int color
)
200 writel(entry
, DC
+ 0x70);
201 writel(color
, DC
+ 0x74);
204 static void geodelx_scroll_up(void)
206 unsigned char *dst
= FB
;
207 unsigned char *src
= FB
+ font_height
* vga_mode
.hactive
;
210 for(y
= 0; y
< vga_mode
.vactive
- font_height
; y
++) {
211 memcpy(dst
, src
, vga_mode
.hactive
);
213 dst
+= vga_mode
.hactive
;
214 src
+= vga_mode
.hactive
;
217 for(; y
< vga_mode
.vactive
; y
++) {
218 memset(dst
, 0, vga_mode
.hactive
);
219 dst
+= vga_mode
.hactive
;
223 static void geodelx_clear(void)
226 unsigned char *ptr
= FB
;
228 for(row
= 0; row
< vga_mode
.vactive
; row
++) {
229 memset(ptr
, 0, vga_mode
.hactive
);
230 ptr
+= vga_mode
.hactive
;
234 static void geodelx_putc(u8 row
, u8 col
, unsigned int ch
)
238 unsigned char bg
= (ch
>> 12) & 0xF;
239 unsigned char fg
= (ch
>> 8) & 0xF;
243 dst
= FB
+ ((row
* font_height
) * vga_mode
.hactive
);
244 dst
+= (col
* font_width
);
246 for(y
= 0; y
< font_height
; y
++) {
248 for(x
= font_width
- 1; x
>= 0; x
--)
249 dst
[font_width
- x
] = font_glyph_filled(ch
, x
, y
) ?
252 dst
+= vga_mode
.hactive
;
256 static int geodelx_init(void)
261 if (!pci_find_device(0x1022, 0x2081, &dev
))
264 fbaddr
= pci_read_resource(dev
, 0);
265 gpaddr
= pci_read_resource(dev
, 1);
266 dcaddr
= pci_read_resource(dev
, 2);
267 vgaddr
= pci_read_resource(dev
, 3);
269 font_init(vga_mode
.hactive
);
273 /* Set up the palette */
275 for(i
= 0; i
< ARRAY_SIZE(vga_colors
); i
++) {
276 geodelx_set_palette(i
, vga_colors
[i
]);
284 struct video_console geodelx_video_console
= {
285 .init
= geodelx_init
,
286 .putc
= geodelx_putc
,
287 .clear
= geodelx_clear
,
288 .scroll_up
= geodelx_scroll_up
,
290 /* TODO .get_cursor */
291 /* TODO .set_cursor */
292 /* TODO .enable_cursor */