2 * This file is part of the libpayload project.
4 * Copyright (C) 2008 Advanced Micro Devices, Inc.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 #include <libpayload.h>
32 #include <video_console.h>
38 /* This is the video mode that we're going to use for our VGA screen */
40 static const struct mode {
42 unsigned int hactive, hblankstart, hsyncstart;
43 unsigned int hsyncend, hblankend, htotal;
44 unsigned int vactive, vblankstart, vsyncstart;
45 unsigned int vsyncend, vblankend, vtotal;
52 .hsyncstart = 640 + 40,
53 .hsyncend = 640 + 40 + 96,
54 .hblankend = 640 + 40 + 96 + 24,
55 .htotal = 640 + 40 + 96 + 24,
57 .vsyncstart = 400 + 39,
58 .vsyncend = 400 + 39 + 2,
59 .vblankend = 400 + 39 + 2 + 9,
60 .vtotal = 400 + 39 + 2 + 9,
64 /* These are the color definitions for the 16 standard colors */
66 static const unsigned int vga_colors[] = {
67 (0x00 << 16) | (0x00 << 8) | 0x00,
68 (0xAA << 16) | (0x00 << 8) | 0x00,
69 (0x00 << 16) | (0xAA << 8) | 0x00,
70 (0xAA << 16) | (0x55 << 8) | 0x00,
71 (0x00 << 16) | (0x00 << 8) | 0xAA,
72 (0xAA << 16) | (0x00 << 8) | 0xAA,
73 (0x00 << 16) | (0xAA << 8) | 0xAA,
74 (0xAA << 16) | (0xAA << 8) | 0xAA,
75 (0x55 << 16) | (0x55 << 8) | 0x55,
76 (0xFF << 16) | (0x55 << 8) | 0x55,
77 (0x55 << 16) | (0xFF << 8) | 0x55,
78 (0xFF << 16) | (0xFF << 8) | 0x55,
79 (0x55 << 16) | (0x55 << 8) | 0xFF,
80 (0xFF << 16) | (0x55 << 8) | 0xFF,
81 (0x55 << 16) | (0xFF << 8) | 0xFF,
82 (0xFF << 16) | (0xFF << 8) | 0xFF,
85 /* Addresses for the various components */
87 static unsigned long dcaddr;
88 static unsigned long vgaddr;
89 static unsigned long gpaddr;
90 static unsigned long fbaddr;
92 #define FB ((unsigned char *) 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, dcaddr + 0x00);
126 val = readl(dcaddr + 0x00);
128 writel(0, dcaddr + 0x10);
129 writel(0, dcaddr + 0x14);
130 writel(0, dcaddr + 0x18);
132 /* Set up the default scaling */
134 val = readl(dcaddr + 0xD4);
136 writel((0x4000 << 16) | 0x4000, dcaddr + 0x90);
137 writel(0, dcaddr + 0x94);
138 writel(val & ~0xf3040000, dcaddr + 0xD4);
140 /* Set up the compression (or lack thereof) */
141 writel(vga_mode.hactive * vga_mode.vactive | 0x01, dcaddr + 0x2C);
143 val = readl(dcaddr + 0x88);
144 writel(val & ~0xC00, dcaddr + 0x88);
145 writel(0, dcaddr + 0x8C);
148 writel(vga_mode.hactive >> 3, dcaddr + 0x34);
149 writel((vga_mode.hactive + 7) >> 3, dcaddr + 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),
180 /* Write the VG configuration */
182 writel(0x290000F | vga_mode.synccfg, vgaddr + 0x08);
184 /* Turn on the dacs */
186 val = readl(vgaddr + 0x50);
187 writel((val & ~0xC00) | 0x01, vgaddr + 0x50);
189 /* Set the framebuffer base */
190 writel(fbaddr, dcaddr + 0x84);
192 /* Write the final configuration */
194 writel(0xB000059, dcaddr + 0x08);
195 writel(0, dcaddr + 0x0C);
196 writel(0x2B601, dcaddr + 0x04);
199 static void geode_set_palette(int entry, unsigned int color)
201 writel(entry, dcaddr + 0x70);
202 writel(color, dcaddr + 0x74);
205 static void geode_scroll_up(void)
207 unsigned char *dst = FB;
208 unsigned char *src = FB + vga_mode.hactive;
211 for(y = 0; y < vga_mode.vactive - FONT_HEIGHT; y++) {
212 memcpy(dst, src, vga_mode.hactive);
214 dst += vga_mode.hactive;
215 src += vga_mode.hactive;
218 dst = FB + (vga_mode.vactive - FONT_HEIGHT) * vga_mode.hactive;
220 for(; y < vga_mode.vactive; y++) {
221 memset(dst, 0, vga_mode.hactive);
222 dst += vga_mode.hactive;
226 static void geode_clear(void)
229 unsigned char *ptr = FB;
231 for(row = 0; row < vga_mode.vactive; row++) {
232 memset(ptr, 0, vga_mode.hactive);
233 ptr += vga_mode.hactive;
237 static void geode_putc(u8 row, u8 col, unsigned int ch)
240 unsigned char *glyph = font8x16 + ((ch & 0xFF) * FONT_HEIGHT);
242 unsigned char bg = (ch >> 12) & 0xF;
243 unsigned char fg = (ch >> 8) & 0xF;
247 dst = FB + ((row * FONT_HEIGHT) * vga_mode.hactive);
248 dst += (col * FONT_WIDTH);
250 for(y = 0; y < FONT_HEIGHT; y++) {
252 for(x = FONT_WIDTH - 1; x >= 0; x--)
253 dst[FONT_WIDTH - x] = (*glyph & (1 << x)) ?
256 dst += vga_mode.hactive;
261 static int geode_init(void)
266 if (!pci_find_device(0x1022, 0x2081, &dev))
269 fbaddr = pci_read_resource(dev, 0);
270 gpaddr = pci_read_resource(dev, 1);
271 dcaddr = pci_read_resource(dev, 2);
272 vgaddr = pci_read_resource(dev, 3);
276 /* Set up the palette */
278 for(i = 0; i < ARRAY_SIZE(vga_colors); i++) {
279 geode_set_palette(i, vga_colors[i]);
285 struct video_console geode_video_console = {
288 .clear = geode_clear,
289 .scroll_up = geode_scroll_up