printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / northbridge / via / cx700 / cx700_vga.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007-2009 coresystems GmbH
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 #include <console/console.h>
21 #include <arch/io.h>
22 #include <stdint.h>
23 #include <device/device.h>
24 #include <device/pci.h>
25 #include <device/pci_ids.h>
26 #include <stdlib.h>
27 #include <string.h>
28 #include <bitops.h>
29 #include <cpu/cpu.h>
30 #include <cpu/x86/mtrr.h>
31 #include <cpu/x86/msr.h>
32 #include "chip.h"
33 #include "northbridge.h"
34
35 /* PCI Domain 1 Device 0 Function 0 */
36
37 #define SR_INDEX        0x3c4
38 #define SR_DATA         0x3c5
39 #define CRTM_INDEX      0x3b4
40 #define CRTM_DATA       0x3b5
41 #define CRTC_INDEX      0x3d4
42 #define CRTC_DATA       0x3d5
43
44 void setup_realmode_idt(void);
45 void do_vgabios(void);
46 void vga_enable_console(void);
47
48 void write_protect_vgabios(void)
49 {
50         device_t dev;
51
52         printk(BIOS_DEBUG, "write_protect_vgabios\n");
53
54         dev = dev_find_device(PCI_VENDOR_ID_VIA, 0x3324, 0);
55         if (dev)
56                 pci_write_config8(dev, 0x80, 0xff);
57
58         dev = dev_find_device(PCI_VENDOR_ID_VIA, 0x7324, 0);
59         if (dev)
60                 pci_write_config8(dev, 0x61, 0xff);
61 }
62
63 static void vga_init(device_t dev)
64 {
65         u8 reg8;
66
67         printk(BIOS_DEBUG, "Initializing VGA...\n");
68
69         //*
70         pci_write_config8(dev, 0x04, 0x07);
71         pci_write_config8(dev, 0x3e, 0x02);
72         pci_write_config8(dev, 0x0d, 0x40);
73         pci_write_config32(dev, 0x10, 0xa0000008);
74         pci_write_config32(dev, 0x14, 0xdd000000);
75         pci_write_config8(dev, 0x3c, 0x0b);
76         //*/
77
78         printk(BIOS_DEBUG, "Executing VGA option rom in real mode\n");
79         setup_realmode_idt();
80         do_vgabios();
81         printk(BIOS_DEBUG, "Enable VGA console\n");
82         vga_enable_console();
83
84         /* It's not clear if these need to be programmed before or after
85          * the VGA bios runs. Try both, clean up later */
86         /* Set memory rate to 200MHz */
87         outb(0x3d, CRTM_INDEX);
88         reg8 = inb(CRTM_DATA);
89         reg8 &= 0x0f;
90         reg8 |= (0x3 << 4);
91         outb(0x3d, CRTM_INDEX);
92         outb(reg8, CRTM_DATA);
93
94         /* Set framebuffer size to 32mb */
95         reg8 = (32 / 4);
96         outb(0x39, SR_INDEX);
97         outb(reg8, SR_DATA);
98 }
99
100 static struct device_operations vga_operations = {
101         .read_resources = pci_dev_read_resources,
102         .set_resources = pci_dev_set_resources,
103         .enable_resources = pci_dev_enable_resources,
104         .init = vga_init,
105         .ops_pci = 0,
106 };
107
108 static const struct pci_driver vga_driver __pci_driver = {
109         .ops = &vga_operations,
110         .vendor = PCI_VENDOR_ID_VIA,
111         .device = 0x3157,
112 };