Add support for A-Open DXPL Plus-U motherboard
[coreboot.git] / src / mainboard / aopen / dxplplusu / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2011 Kyösti Mälkki <kyosti.malkki@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; 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 <stdint.h>
21 #include <device/pci_def.h>
22 #include <arch/io.h>
23 #include <device/pnp_def.h>
24 #include <arch/romcc_io.h>
25 #include <cpu/x86/lapic.h>
26 #include <arch/cpu.h>
27 #include <stdlib.h>
28 #include <pc80/mc146818rtc.h>
29 #include <console/console.h>
30
31 #include "southbridge/intel/i82801dx/i82801dx.h"
32 #include "southbridge/intel/i82801dx/early_smbus.c"
33 #include "southbridge/intel/i82801dx/reset.c"
34 #include "northbridge/intel/e7505/raminit.h"
35 #include "northbridge/intel/e7505/debug.c"
36 #include "superio/smsc/lpc47m10x/early_serial.c"
37
38 #if !CONFIG_CACHE_AS_RAM
39 #include "cpu/x86/lapic/boot_cpu.c"
40 #include "cpu/x86/mtrr/earlymtrr.c"
41 #endif
42 #include "cpu/x86/bist.h"
43
44 #include <spd.h>
45
46 #define SERIAL_DEV PNP_DEV(0x2e, LPC47M10X2_SP1)
47
48 static inline int spd_read_byte(unsigned device, unsigned address)
49 {
50         return smbus_read_byte(device, address);
51 }
52
53 /* Cache-As-Ram compiles for this board, but with the CPUs I have,
54  * it halts on boot while in Local Apic ID negotiation.
55  */
56
57 #if CONFIG_CACHE_AS_RAM
58 #define BOARD_MAIN(x) void main(x)
59 #define early_mtrr_init()   do {} while (0)
60 #else
61 #define BOARD_MAIN(x) static void main(x)
62 #endif
63
64 #include "northbridge/intel/e7505/raminit.c"
65 #include "northbridge/intel/e7505/reset_test.c"
66 #include "lib/generic_sdram.c"
67
68 // This function MUST appear last (ROMCC limitation)
69 BOARD_MAIN(unsigned long bist)
70 {
71         static const struct mem_controller memctrl[] = {
72                 {
73                         .d0 = PCI_DEV(0, 0, 0),
74                         .d0f1 = PCI_DEV(0, 0, 1),
75                         .channel0 = { 0x50, 0x52, 0, 0 },
76                         .channel1 = { 0x51, 0x53, 0, 0 },
77                 },
78         };
79
80         if (bist == 0)  {
81                 // Skip this if there was a built in self test failure
82                 early_mtrr_init();
83                 enable_lapic();
84         }
85
86         // Get the serial port running and print a welcome banner
87         lpc47m10x_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
88         console_init();
89
90         // Halt if there was a built in self test failure
91         report_bist_failure(bist);
92
93         // If this is a warm boot, some initialization can be skipped
94         if (!bios_reset_detected()) {
95                 enable_smbus();
96                 sdram_initialize(ARRAY_SIZE(memctrl), memctrl);
97         }
98
99         // NOTE: ROMCC dies with an internal compiler error
100         //               if the following line is removed.
101         print_debug("SDRAM is up.\r\n");
102
103 }