732963de4654249390fff8af779a43413c858938
[coreboot.git] / src / northbridge / via / vx800 / vga.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2009 One Laptop per Child, Association, Inc.
5  *
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.
9  *
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.
14  *
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
18  */
19
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 */
22
23 #include <console/console.h>
24 #include <arch/io.h>
25 #include <stdint.h>
26 #include <device/device.h>
27 #include <device/pci.h>
28 #include <device/pci_ids.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <bitops.h>
32 #include <cpu/cpu.h>
33 #include <cpu/x86/mtrr.h>
34 #include <cpu/x86/msr.h>
35 #include "chip.h"
36 #include "northbridge.h"
37 #include "vgachip.h"
38
39 /* PCI Domain 1 Device 0 Function 0 */
40
41 #define SR_INDEX        0x3c4
42 #define SR_DATA         0x3c5
43 #define CRTM_INDEX      0x3b4
44 #define CRTM_DATA       0x3b5
45 #define CRTC_INDEX      0x3d4
46 #define CRTC_DATA       0x3d5
47
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
51
52 void write_protect_vgabios(void)
53 {
54         device_t dev;
55
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);
60         if (dev)
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);
64            //if(dev)
65            //   pci_write_config8(dev, 0x61, 0xff); */
66 }
67
68 extern u8 acpi_sleep_type;
69 static void vga_init(device_t dev)
70 {
71         uint8_t reg8;
72
73         print_debug("Initiailizing VGA...\n");
74         u8 tmp8;
75 //A20 OPEN
76         tmp8 = inb(0x92);
77         tmp8 = tmp8 | 2;
78         outb(tmp8, 0x92);
79
80         //*
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
87         //*/
88         printk_emerg("file '%s', line %d\n\n", __FILE__, __LINE__);
89
90 #if 1
91         printk_debug("INSTALL REAL-MODE IDT\n");
92         setup_realmode_idt();
93         printk_debug("DO THE VGA BIOS\n");
94
95         do_vgabios();
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();
102         }
103 #else
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);
108 #endif
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);
115                 reg8 &= 0x0f;
116                 reg8 |= (0x3 << 4);
117                 outb(0x3d, CRTM_INDEX);
118                 outb(reg8, CRTM_DATA);
119
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); */
124         }
125         printk_emerg("file '%s', line %d\n\n", __FILE__, __LINE__);
126
127 }
128
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,
133         .init = vga_init,
134         .ops_pci = 0,
135 };
136
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,
141 };