printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / northbridge / via / cn400 / vga.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Corey Osgood <corey.osgood@gmail.com>
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; either version 2 of the License, or
9  * (at your option) any later version.
10  *
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.
15  *
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
19  */
20
21 /*
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.
24  */
25
26 #include <console/console.h>
27 #include <arch/io.h>
28 #include <stdint.h>
29 #include <device/device.h>
30 #include <device/pci.h>
31 #include <device/pci_ids.h>
32 #include <stdlib.h>
33 #include <string.h>
34 #include <bitops.h>
35 #include <cpu/cpu.h>
36 #include "chip.h"
37 #include "northbridge.h"
38 #include "cn400.h"
39 #include "vgachip.h"
40
41 void write_protect_vgabios(void)
42 {
43         /* Don't bother for now. */
44 }
45
46 static void vga_init(device_t dev)
47 {
48         u8 reg8;
49         u32 temp;
50 #ifdef DEBUG_CN400
51         int i, j;
52 #endif
53
54         temp = (0xffffffff - CONFIG_FALLBACK_SIZE - 0xffff);
55         printk(BIOS_DEBUG, "Copying BOCHS BIOS from 0x%08X      to 0xf000\n", temp);
56         /*
57          * Copy BOCHS BIOS from 4G-CONFIG_FALLBACK_SIZE-64k (in flash) to 0xf0000 (in RAM)
58          * This is for compatibility with the VGA ROM's BIOS callbacks.
59          */
60         //memcpy(0xf0000, (0xffffffff - CONFIG_ROM_SIZE - 0xffff), 0x10000);
61         memcpy(0xf0000, temp, 0x10000);
62         printk(BIOS_DEBUG, "Initializing VGA\n");
63
64         /* Set memory rate to 200 MHz. */
65         outb(0x3d, CRTM_INDEX);
66         reg8 = inb(CRTM_DATA);
67         reg8 &= 0x0f;
68         reg8 |= (0x1 << 4);
69         outb(0x3d, CRTM_INDEX);
70         outb(reg8, CRTM_DATA);
71
72         /* Set framebuffer size. */
73         reg8 = (CONFIG_VIDEO_MB / 4);
74         outb(0x39, SR_INDEX);
75         outb(reg8, SR_DATA);
76
77         pci_write_config8(dev, 0x04, 0x07);
78         pci_write_config8(dev, 0x0d, 0x20);
79         pci_write_config32(dev, 0x10, 0xf0000008);
80         pci_write_config32(dev, 0x14, 0xf4000000);
81
82         printk(BIOS_DEBUG, "INSTALL REAL-MODE IDT\n");
83         setup_realmode_idt();
84         printk(BIOS_DEBUG, "DO THE VGA BIOS\n");
85         do_vgabios();
86         /* VGA seems to work without this, but crash & burn with it. */
87         // printk(BIOS_DEBUG, "Enable VGA console\n");
88         // vga_enable_console();
89
90         /* It's not clear if these need to be programmed before or after
91          * the VGA BIOS runs. Try both, clean up later. */
92         /* Set memory rate to 200 MHz (again). */
93         outb(0x3d, CRTM_INDEX);
94         reg8 = inb(CRTM_DATA);
95         reg8 &= 0x0f;
96         reg8 |= (0x1 << 4);
97         outb(0x3d, CRTM_INDEX);
98         outb(reg8, CRTM_DATA);
99
100         /* Set framebuffer size (again). */
101         reg8 = (CONFIG_VIDEO_MB / 4);
102         outb(0x39, SR_INDEX);
103         outb(reg8, SR_DATA);
104
105         /* Clear the BOCHS BIOS out of memory, so it doesn't confuse Linux. */
106         memset(0xf0000, 0, 0x10000);
107
108 #ifdef DEBUG_CN400
109         printk(BIOS_SPEW, "%s PCI Header Regs::\n", dev_path(dev));
110
111         for (i = 0 ; i < 16; i++)
112         {
113                 printk(BIOS_SPEW, "%02X: ", i*16);
114                 for (j = 0; j < 16; j++)
115                 {
116                         reg8 = pci_read_config8(dev, j+(i*16));
117                         printk(BIOS_SPEW, "%02X ", reg8);
118                 }
119                 printk(BIOS_SPEW, "\n");
120         }
121 #endif
122 }
123
124 static const struct device_operations vga_operations = {
125         .read_resources   = pci_dev_read_resources,
126         .set_resources    = pci_dev_set_resources,
127         .enable_resources = pci_dev_enable_resources,
128         .init             = vga_init,
129         .ops_pci          = 0,
130 };
131
132 static const struct pci_driver vga_driver __pci_driver = {
133         .ops    = &vga_operations,
134         .vendor = PCI_VENDOR_ID_VIA,
135         .device = PCI_DEVICE_ID_VIA_CN400_VGA,
136 };