Add Win Enterprises' PL6064 board
[coreboot.git] / src / mainboard / winent / pl6064 / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Advanced Micro Devices, Inc.
5  * Copyright (C) 2010 Win Enterprises, Inc (anishp@win-ent.com)
6  *
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21  */
22
23 #define ASSEMBLY 1
24 #define __PRE_RAM__
25
26 #include <stdint.h>
27 #include <device/pci_def.h>
28 #include <arch/io.h>
29 #include <device/pnp_def.h>
30 #include <arch/hlt.h>
31 #include "pc80/serial.c"
32 #include "arch/i386/lib/console.c"
33 #include "lib/ramtest.c"
34 #include "cpu/x86/bist.h"
35 #include "cpu/x86/msr.h"
36 #include <cpu/amd/lxdef.h>
37 #include <cpu/amd/geode_post_code.h>
38 #include "southbridge/amd/cs5536/cs5536.h"
39
40 #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
41 #define POST_CODE(x) outb(x, 0x80)
42 #define SERIAL_DEV PNP_DEV(0x2e, W83627HF_SP1)
43
44 #include "southbridge/amd/cs5536/cs5536_early_smbus.c"
45 #include "southbridge/amd/cs5536/cs5536_early_setup.c"
46 #include "superio/winbond/w83627hf/w83627hf_early_serial.c"
47
48 static inline int spd_read_byte(unsigned int device, unsigned int address)
49 {
50         return smbus_read_byte(device, address);
51 }
52
53 #define ManualConf 0            /* Do automatic strapped PLL config */
54 #define PLLMSRhi 0x00001490     /* Manual settings for the PLL */
55 #define PLLMSRlo 0x02000030
56 #define DIMM0 0xA0
57 #define DIMM1 0xA2
58
59 #include "northbridge/amd/lx/raminit.h"
60 #include "northbridge/amd/lx/pll_reset.c"
61 #include "northbridge/amd/lx/raminit.c"
62 #include "lib/generic_sdram.c"
63 #include "cpu/amd/model_lx/cpureginit.c"
64 #include "cpu/amd/model_lx/syspreinit.c"
65
66 struct msrinit {
67             u32 msrnum;
68             msr_t msr;
69       };
70
71 static const struct msrinit msr_table[] = 
72 {
73        {CPU_RCONF_DEFAULT, {.hi = 0x24fffc02,.lo = 0x1000A000}}, /* Setup access to cache under 1MB.
74                                                                   * Rom Properties: Write Serialize, WriteProtect.
75                                                                   * RomBase: 0xFFFC0
76                                                                   * SysTop to RomBase Properties: Write Serialize, Cache Disable.
77                                                                   * SysTop: 0x000A0 
78                                                                   * System Memory Properties:  (Write Back) */
79        {CPU_RCONF_A0_BF,   {.hi = 0x00000000,.lo = 0x00000000}}, /* 0xA0000-0xBFFFF : (Write Back) */
80        {CPU_RCONF_C0_DF,   {.hi = 0x00000000,.lo = 0x00000000}}, /* 0xC0000-0xDFFFF : (Write Back) */
81        {CPU_RCONF_E0_FF,   {.hi = 0x00000000,.lo = 0x00000000}}, /* 0xE0000-0xFFFFF : (Write Back) */
82        
83        /* Setup access to memory under 1MB. Note: VGA hole at 0xA0000-0xBFFFF */
84        {MSR_GLIU0_BASE1,   {.hi = 0x20000000,.lo = 0x000fff80}}, // 0x00000-0x7FFFF
85        {MSR_GLIU0_BASE2,   {.hi = 0x20000000,.lo = 0x080fffe0}}, // 0x80000-0x9FFFF
86        {MSR_GLIU0_SHADOW,  {.hi = 0x2000FFFF,.lo = 0xFFFF0003}}, // 0xC0000-0xFFFFF
87        {MSR_GLIU1_BASE1,   {.hi = 0x20000000,.lo = 0x000fff80}}, // 0x00000-0x7FFFF
88        {MSR_GLIU1_BASE2,   {.hi = 0x20000000,.lo = 0x080fffe0}}, // 0x80000-0x9FFFF
89        {MSR_GLIU1_SHADOW,  {.hi = 0x2000FFFF,.lo = 0xFFFF0003}}, // 0xC0000-0xFFFFF
90 };
91
92
93 static void msr_init(void)
94 {
95   int i;
96        for (i = 0; i < ARRAY_SIZE(msr_table); i++)
97                            wrmsr(msr_table[i].msrnum, msr_table[i].msr);
98 }
99
100 static void mb_gpio_init(void)
101 {
102         /* Early mainboard specific GPIO setup. */
103 }
104
105 void cache_as_ram_main(void)
106 {
107         POST_CODE(0x01);
108
109         static const struct mem_controller memctrl[] = {
110                 {.channel0 = {(0xa << 3) | 0, (0xa << 3) | 1}}
111         };
112
113         SystemPreInit();
114         msr_init();
115
116         cs5536_early_setup();
117
118         /* Note: must do this AFTER the early_setup! It is counting on some
119          * early MSR setup for CS5536.
120          */
121         w83627hf_set_clksel_48(SERIAL_DEV);
122         w83627hf_enable_serial(SERIAL_DEV, CONFIG_TTYS0_BASE);
123         mb_gpio_init();
124         uart_init();
125         console_init();
126
127         pll_reset(ManualConf);
128
129         cpuRegInit();
130
131         sdram_initialize(1, memctrl);
132
133         /* Check memory. */
134         /* ram_check(0x00000000, 640 * 1024); */
135
136         /* Memory is setup. Return to cache_as_ram.inc and continue to boot. */
137         return;
138 }