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>
36 /* This is the video mode that we're going to use for our VGA screen */
38 static const struct mode {
40 unsigned int hactive, hblankstart, hsyncstart;
41 unsigned int hsyncend, hblankend, htotal;
42 unsigned int vactive, vblankstart, vsyncstart;
43 unsigned int vsyncend, vblankend, vtotal;
50 .hsyncstart = 640 + 40,
51 .hsyncend = 640 + 40 + 96,
52 .hblankend = 640 + 40 + 96 + 24,
53 .htotal = 640 + 40 + 96 + 24,
55 .vsyncstart = 400 + 39,
56 .vsyncend = 400 + 39 + 2,
57 .vblankend = 400 + 39 + 2 + 9,
58 .vtotal = 400 + 39 + 2 + 9,
62 /* These are the color definitions for the 16 standard colors */
64 static const unsigned int vga_colors[] = {
65 (0x00 << 16) | (0x00 << 8) | 0x00,
66 (0xAA << 16) | (0x00 << 8) | 0x00,
67 (0x00 << 16) | (0xAA << 8) | 0x00,
68 (0xAA << 16) | (0x55 << 8) | 0x00,
69 (0x00 << 16) | (0x00 << 8) | 0xAA,
70 (0xAA << 16) | (0x00 << 8) | 0xAA,
71 (0x00 << 16) | (0xAA << 8) | 0xAA,
72 (0xAA << 16) | (0xAA << 8) | 0xAA,
73 (0x55 << 16) | (0x55 << 8) | 0x55,
74 (0xFF << 16) | (0x55 << 8) | 0x55,
75 (0x55 << 16) | (0xFF << 8) | 0x55,
76 (0xFF << 16) | (0xFF << 8) | 0x55,
77 (0x55 << 16) | (0x55 << 8) | 0xFF,
78 (0xFF << 16) | (0x55 << 8) | 0xFF,
79 (0x55 << 16) | (0xFF << 8) | 0xFF,
80 (0xFF << 16) | (0xFF << 8) | 0xFF,
83 /* Addresses for the various components */
85 static unsigned long dcaddr;
86 static unsigned long vgaddr;
87 static unsigned long gpaddr;
88 static unsigned long fbaddr;
90 #define FB ((unsigned char *) fbaddr)
92 static void init_video_mode(void)
94 unsigned int lo, hi, val;
99 rdmsr(0x4c000015, lo, hi);
106 wrmsr(0x4c000015, lo, hi);
109 for(i = 0; i < 1000; i++) {
110 rdmsr(0x4c000015, lo, hi);
116 wrmsr(0x4c000015, lo, hi);
118 rdmsr(0x48002001, lo, hi);
120 wrmsr(0x48002001, lo, hi);
122 writel(0x4758, dcaddr + 0x00);
124 val = readl(dcaddr + 0x00);
126 writel(0, dcaddr + 0x10);
127 writel(0, dcaddr + 0x14);
128 writel(0, dcaddr + 0x18);
130 /* Set up the default scaling */
132 val = readl(dcaddr + 0xD4);
134 writel((0x4000 << 16) | 0x4000, dcaddr + 0x90);
135 writel(0, dcaddr + 0x94);
136 writel(val & ~0xf3040000, dcaddr + 0xD4);
138 /* Set up the compression (or lack thereof) */
139 writel(vga_mode.hactive * vga_mode.vactive | 0x01, dcaddr + 0x2C);
141 val = readl(dcaddr + 0x88);
142 writel(val & ~0xC00, dcaddr + 0x88);
143 writel(0, dcaddr + 0x8C);
146 writel(vga_mode.hactive >> 3, dcaddr + 0x34);
147 writel((vga_mode.hactive + 7) >> 3, dcaddr + 0x30);
149 /* Set up default watermarks */
152 wrmsr(0x80000011, lo, hi);
154 /* Write the timings */
156 writel((vga_mode.hactive - 1) | ((vga_mode.htotal - 1) << 16),
159 writel((vga_mode.hblankstart - 1) | ((vga_mode.hblankend - 1) << 16),
162 writel((vga_mode.hsyncstart - 1) | ((vga_mode.hsyncend - 1) << 16),
165 writel((vga_mode.vactive - 1) | ((vga_mode.vtotal - 1) << 16),
168 writel((vga_mode.vblankstart - 1) | ((vga_mode.vblankend - 1) << 16),
171 writel((vga_mode.vsyncstart - 1) | ((vga_mode.vsyncend - 1) << 16),
174 writel(((vga_mode.hactive - 1) << 16) | (vga_mode.vactive - 1),
178 /* Write the VG configuration */
180 writel(0x290000F | vga_mode.synccfg, vgaddr + 0x08);
182 /* Turn on the dacs */
184 val = readl(vgaddr + 0x50);
185 writel((val & ~0xC00) | 0x01, vgaddr + 0x50);
187 /* Set the framebuffer base */
188 writel(fbaddr, dcaddr + 0x84);
190 /* Write the final configuration */
192 writel(0xB000059, dcaddr + 0x08);
193 writel(0, dcaddr + 0x0C);
194 writel(0x2B601, dcaddr + 0x04);
197 static void geode_set_palette(int entry, unsigned int color)
199 writel(entry, dcaddr + 0x70);
200 writel(color, dcaddr + 0x74);
203 static void geode_scroll_up(void)
205 unsigned char *dst = FB;
206 unsigned char *src = FB + vga_mode.hactive;
209 for(y = 0; y < vga_mode.vactive - FONT_HEIGHT; y++) {
210 memcpy(dst, src, vga_mode.hactive);
212 dst += vga_mode.hactive;
213 src += vga_mode.hactive;
216 dst = FB + (vga_mode.vactive - FONT_HEIGHT) * vga_mode.hactive;
218 for(; y < vga_mode.vactive; y++) {
219 memset(dst, 0, vga_mode.hactive);
220 dst += vga_mode.hactive;
224 static void geode_clear(void)
227 unsigned char *ptr = FB;
229 for(row = 0; row < vga_mode.vactive; row++) {
230 memset(ptr, 0, vga_mode.hactive);
231 ptr += vga_mode.hactive;
235 static void geode_putc(u8 row, u8 col, unsigned int ch)
238 unsigned char *glyph = font8x16 + ((ch & 0xFF) * FONT_HEIGHT);
240 unsigned char bg = (ch >> 12) & 0xF;
241 unsigned char fg = (ch >> 8) & 0xF;
245 dst = FB + ((row * FONT_HEIGHT) * vga_mode.hactive);
246 dst += (col * FONT_WIDTH);
248 for(y = 0; y < FONT_HEIGHT; y++) {
250 for(x = FONT_WIDTH - 1; x >= 0; x--)
251 dst[FONT_WIDTH - x] = (*glyph & (1 << x)) ?
254 dst += vga_mode.hactive;
259 static int geode_init(void)
264 if (!pci_find_device(0x1022, 0x2081, &dev))
267 fbaddr = pci_read_resource(dev, 0);
268 gpaddr = pci_read_resource(dev, 1);
269 dcaddr = pci_read_resource(dev, 2);
270 vgaddr = pci_read_resource(dev, 3);
274 /* Set up the palette */
276 for(i = 0; i < ARRAY_SIZE(vga_colors); i++) {
277 geode_set_palette(i, vga_colors[i]);
283 struct video_console geode_video_console = {
286 .clear = geode_clear,
287 .scroll_up = geode_scroll_up