2 * This file is part of the coreboot project.
4 * Copyright (C) 2009 One Laptop per Child, Association, Inc.
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; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 /* Note: Some of the VGA control registers are located on the memory controller.
21 Registers are set both in raminit.c and northbridge.c */
23 #include <console/console.h>
26 #include <device/device.h>
27 #include <device/pci.h>
28 #include <device/pci_ids.h>
33 #include <cpu/x86/mtrr.h>
34 #include <cpu/x86/msr.h>
36 #include "northbridge.h"
39 /* PCI Domain 1 Device 0 Function 0 */
41 #define SR_INDEX 0x3c4
43 #define CRTM_INDEX 0x3b4
44 #define CRTM_DATA 0x3b5
45 #define CRTC_INDEX 0x3d4
46 #define CRTC_DATA 0x3d5
48 /* !!FIXME!! These were CONFIG_ options. Fix it in uma_ram_setting.c too. */
49 #define VIACONFIG_VGA_PCI_10 0xf8000008
50 #define VIACONFIG_VGA_PCI_14 0xfc000000
52 void write_protect_vgabios(void)
56 printk_info("write_protect_vgabios\n");
57 /* there are two possible devices. Just do both. */
58 dev = dev_find_device(PCI_VENDOR_ID_VIA,
59 PCI_DEVICE_ID_VIA_VX855_MEMCTRL, 0);
61 pci_write_config8(dev, 0x80, 0xff);
62 /*vx855 no th 0x61 reg */
63 /*dev = dev_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VX855_VLINK, 0);
65 // pci_write_config8(dev, 0x61, 0xff); */
68 extern u8 acpi_sleep_type;
69 static void vga_init(device_t dev)
73 print_debug("Initiailizing VGA...\n");
81 //pci_write_config8(dev, 0x04, 0x07);
82 //pci_write_config32(dev,0x10, 0xa0000008);
83 //pci_write_config32(dev,0x14, 0xdd000000);
84 pci_write_config32(dev, 0x10, VIACONFIG_VGA_PCI_10);
85 pci_write_config32(dev, 0x14, VIACONFIG_VGA_PCI_14);
86 pci_write_config8(dev, 0x3c, 0x0a); //same with vx855_lpc.c
88 printk_emerg("file '%s', line %d\n\n", __FILE__, __LINE__);
91 printk_debug("INSTALL REAL-MODE IDT\n");
93 printk_debug("DO THE VGA BIOS\n");
96 if ((acpi_sleep_type == 3)/* || (PAYLOAD_IS_SEABIOS == 0)*/) {
97 printk_debug("Enable VGA console\n");
98 // remove this function since in cn700 it is said "VGA seems to work without this, but crash & burn with it"
99 //but the existense of vga_enable_console() seems do not hurt my coreboot. XP+ubuntu s3 can resume with and without this function.
100 //and remove it also do not help my s3 problem: desktop screen have some thin black line, after resuming back to win.
101 vga_enable_console();
104 /* Attempt to manually force the rom to load */
105 printk_debug("Forcing rom load\r\n");
106 pci_rom_load(dev, 0xfff80000);
107 run_bios(dev, 0xc0000);
109 if ((acpi_sleep_type == 3)/* || (PAYLOAD_IS_SEABIOS == 0)*/) {
110 /* It's not clear if these need to be programmed before or after
111 * the VGA bios runs. Try both, clean up later */
112 /* Set memory rate to 200MHz */
113 outb(0x3d, CRTM_INDEX);
114 reg8 = inb(CRTM_DATA);
117 outb(0x3d, CRTM_INDEX);
118 outb(reg8, CRTM_DATA);
120 /* Set framebuffer size to CONFIG_VIDEO_MB mb */
121 /*reg8 = (CONFIG_VIDEO_MB/4);
122 outb(0x39, SR_INDEX);
123 outb(reg8, SR_DATA); */
125 printk_emerg("file '%s', line %d\n\n", __FILE__, __LINE__);
129 static struct device_operations vga_operations = {
130 .read_resources = pci_dev_read_resources,
131 .set_resources = pci_dev_set_resources,
132 .enable_resources = pci_dev_enable_resources,
137 static const struct pci_driver vga_driver __pci_driver = {
138 .ops = &vga_operations,
139 .vendor = PCI_VENDOR_ID_VIA,
140 .device = PCI_DEVICE_ID_VIA_VX855_VGA,