2 * This file is part of the coreboot project.
4 * Copyright (C) 2007 Corey Osgood <corey.osgood@gmail.com>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22 * Note: Some of the VGA control registers are located on the memory
23 * controller. Registers are set both in raminit.c and northbridge.c.
26 #include <console/console.h>
29 #include <device/device.h>
30 #include <device/pci.h>
31 #include <device/pci_ids.h>
36 #include <arch/interrupt.h>
38 #include "northbridge.h"
41 static int via_cn700_int15_handler(struct eregs *regs)
44 printk(BIOS_DEBUG, "via_cn700_int15_handler\n");
45 switch(regs->eax & 0xffff) {
50 regs->ebx=0x545; // MCLK = 133, 32M frame buffer, 256 M main memory
59 regs->ecx = (regs->ecx & 0xffffff00 ) | 2; // panel type = 2 = 1024 * 768
64 regs->ebx= (regs->ebx & 0xffff0000) | 2;
65 regs->ecx= (regs->ecx & 0xffff0000) | 0x401; // PAL + crt only
66 regs->edx= (regs->edx & 0xffff0000) | 0; // TV Layout - default
73 printk(BIOS_DEBUG, "Unknown INT15 function %04x!\n",
80 static void vga_init(device_t dev)
84 mainboard_interrupt_handlers(0x15, &via_cn700_int15_handler);
86 #undef OLD_BOCHS_METHOD
87 #ifdef OLD_BOCHS_METHOD
88 print_debug("Copying BOCHS BIOS to 0xf000\n");
90 * Copy BOCHS BIOS from 4G-CONFIG_ROM_SIZE-64k (in flash) to 0xf0000 (in RAM)
91 * This is for compatibility with the VGA ROM's BIOS callbacks.
93 memcpy((void *)0xf0000, (const void *)(0xffffffff - CONFIG_ROM_SIZE - 0xffff), 0x10000);
96 /* Set memory rate to 200 MHz. */
97 outb(0x3d, CRTM_INDEX);
98 reg8 = inb(CRTM_DATA);
101 outb(0x3d, CRTM_INDEX);
102 outb(reg8, CRTM_DATA);
104 /* Set framebuffer size. */
105 reg8 = (CONFIG_VIDEO_MB / 4);
106 outb(0x39, SR_INDEX);
109 pci_write_config8(dev, 0x04, 0x07);
110 pci_write_config8(dev, 0x0d, 0x20);
111 pci_write_config32(dev, 0x10, 0xf4000008);
112 pci_write_config32(dev, 0x14, 0xfb000000);
114 printk(BIOS_DEBUG, "Initializing VGA...\n");
118 /* It's not clear if these need to be programmed before or after
119 * the VGA BIOS runs. Try both, clean up later. */
120 /* Set memory rate to 200 MHz (again). */
121 outb(0x3d, CRTM_INDEX);
122 reg8 = inb(CRTM_DATA);
125 outb(0x3d, CRTM_INDEX);
126 outb(reg8, CRTM_DATA);
128 /* Set framebuffer size (again). */
129 reg8 = (CONFIG_VIDEO_MB / 4);
130 outb(0x39, SR_INDEX);
133 #ifdef OLD_BOCHS_METHOD
134 /* Clear the BOCHS BIOS out of memory, so it doesn't confuse Linux. */
135 memset((void *)0xf0000, 0, 0x10000);
139 static const struct device_operations vga_operations = {
140 .read_resources = pci_dev_read_resources,
141 .set_resources = pci_dev_set_resources,
142 .enable_resources = pci_dev_enable_resources,
147 static const struct pci_driver vga_driver __pci_driver = {
148 .ops = &vga_operations,
149 .vendor = PCI_VENDOR_ID_VIA,
150 .device = PCI_DEVICE_ID_VIA_CN700_VGA,