4526ddcde84ae998c007f94ac37b38a5908efba0
[coreboot.git] / src / mainboard / via / epia-n / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2008 VIA Technologies, Inc.
5  * (Written by Aaron Lwe <aaron.lwe@gmail.com> for VIA)
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
20  */
21
22 #include <stdint.h>
23 #include <device/pci_def.h>
24 #include <device/pci_ids.h>
25 #include <arch/io.h>
26 #include <device/pnp_def.h>
27 #include <arch/romcc_io.h>
28 #include <arch/hlt.h>
29 #include <console/console.h>
30 #include "lib/ramtest.c"
31 #include "northbridge/via/cn400/raminit.h"
32 #include "cpu/x86/mtrr/earlymtrr.c"
33 #include "cpu/x86/bist.h"
34 #include "pc80/udelay_io.c"
35 #include "lib/delay.c"
36 #include "cpu/x86/lapic/boot_cpu.c"
37 #include "southbridge/via/vt8237r/vt8237r_early_smbus.c"
38 #include "superio/winbond/w83697hf/w83697hf_early_serial.c"
39
40 #define SERIAL_DEV PNP_DEV(0x2e, W83697HF_SP1)
41
42 /*
43  * NOOB ::
44  * d0f0 - Device 0 Function 0 etc.
45  */
46 static const struct mem_controller ctrl = {
47         .d0f0 = 0x0000,
48         .d0f2 = 0x2000,
49         .d0f3 = 0x3000,
50         .d0f4 = 0x4000,
51         .d0f7 = 0x7000,
52         .d1f0 = 0x8000,
53         .channel0 = { 0x50 },
54 };
55
56 static inline int spd_read_byte(unsigned device, unsigned address)
57 {
58         return smbus_read_byte(device, address);
59 }
60
61 #include "northbridge/via/cn400/raminit.c"
62
63 static void enable_mainboard_devices(void)
64 {
65         device_t dev;
66         u8 reg;
67
68         dev = pci_locate_device(PCI_ID(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT8237R_LPC), 0);
69         if (dev == PCI_DEV_INVALID)
70                 die("Southbridge not found!!!\n");
71
72         /* bit=0 means enable function (per VT8237R datasheet)
73          *   7 17.6 MC97
74          *   6 17.5 AC97
75          *   5 16.1 USB 2
76          *   4 16.0 USB 1
77          *   3 15.0 SATA and PATA
78          *   2 16.2 USB 3
79          *   1 16.4 USB EHCI
80          */
81         pci_write_config8(dev, 0x50, 0xC0);
82
83         /*bit=0 means enable internal function (per VT8237R datasheet)
84          *   7 USB Device Mode
85          *bit=1 means enable internal function (per VT8237R datasheet)
86          *   6 Reserved
87          *   5 LAN Controller Clock Gating
88          *   4 LAN Controller
89          *   3 Internal RTC
90          *   2 Internal PS2 Mouse
91          *   1 Internal KBC Configuration
92          *   0 Internal Keyboard Controller
93          */
94         pci_write_config8(dev, 0x51, 0x9d);
95 }
96
97 static void enable_shadow_ram(void)
98 {
99         unsigned char shadowreg;
100
101         shadowreg = pci_read_config8(ctrl.d0f3, 0x82);
102         /* 0xf0000-0xfffff Read/Write*/
103         shadowreg |= 0x30;
104         pci_write_config8(ctrl.d0f3, 0x82, shadowreg);
105 }
106
107 static void main(unsigned long bist)
108 {
109         unsigned long x;
110         device_t dev;
111
112         /* Enable multifunction for northbridge. */
113         pci_write_config8(ctrl.d0f0, 0x4f, 0x01);
114
115         w83697hf_set_clksel_48(SERIAL_DEV);
116
117         w83697hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
118
119         uart_init();
120         console_init();
121
122         print_spew("In romstage.c:main()\n");
123
124         enable_smbus();
125         smbus_fixup(&ctrl);
126
127         /* Halt if there was a built-in self test failure. */
128         report_bist_failure(bist);
129
130         print_debug("Enabling mainboard devices\n");
131         enable_mainboard_devices();
132
133         print_debug("Enable F-ROM Shadow RAM\n");
134         enable_shadow_ram();
135
136         /* setup cpu */
137         print_debug("Setup CPU Interface\n");
138         c3_cpu_setup(ctrl.d0f2);
139
140         ddr_ram_setup();
141
142         if (bist == 0) {
143                 print_debug("doing early_mtrr\n");
144                 early_mtrr_init();
145         }
146
147         //ram_check(0, 640 * 1024);
148
149         print_spew("Leaving romstage.c:main()\n");
150 }
151