fix artecgroup dbe61
[coreboot.git] / src / mainboard / artecgroup / dbe61 / romstage.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Advanced Micro Devices, Inc.
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 #include <stdint.h>
22 #include <device/pci_def.h>
23 #include <arch/io.h>
24 #include <device/pnp_def.h>
25 #include <arch/romcc_io.h>
26 #include <arch/hlt.h>
27 #include <stdlib.h>
28 #include "pc80/serial.c"
29 #include "console/console.c"
30 #include "lib/ramtest.c"
31 #include "cpu/x86/bist.h"
32 #include "cpu/x86/msr.h"
33 #include <cpu/amd/lxdef.h>
34 #include <cpu/amd/geode_post_code.h>
35 #include "southbridge/amd/cs5536/cs5536.h"
36 #include "spd_table.h"
37
38 #include "southbridge/amd/cs5536/cs5536_early_smbus.c"
39 #include "southbridge/amd/cs5536/cs5536_early_setup.c"
40
41 #define DIMM0 0xA0
42 #define DIMM1 0xA2
43
44 static int spd_read_byte(unsigned device, unsigned address)
45 {
46         int i;
47
48         if (device == DIMM0){
49                 for (i=0; i < (ARRAY_SIZE(spd_table)); i++){
50                         if (spd_table[i].address == address){
51                                 return spd_table[i].data;
52                         }
53                 }
54         }
55
56         /* returns 0xFF on any failures */
57         return 0xFF;
58 }
59
60 #define ManualConf 0            /* Do automatic strapped PLL config */
61 /* CPU and GLIU mult/div 500/266*/
62 #define PLLMSRhi 0x0000039C /* 33MHz PCI, 0x000003DD for 66MHz PCI */
63 /* Hold Count - how long we will sit in reset */
64 #define PLLMSRlo 0x00DE6000
65
66 #include "northbridge/amd/lx/raminit.h"
67 #include "northbridge/amd/lx/pll_reset.c"
68 #include "northbridge/amd/lx/raminit.c"
69 #include "lib/generic_sdram.c"
70 #include "cpu/amd/model_lx/cpureginit.c"
71 #include "cpu/amd/model_lx/syspreinit.c"
72
73 struct msrinit {
74         u32 msrnum;
75         msr_t msr;
76 };
77
78 static const struct msrinit msr_table[] = 
79 {
80        {CPU_RCONF_DEFAULT, {.hi = 0x24fffc02,.lo = 0x1000A000}}, /* Setup access to cache under 1MB.
81                                                                   * Rom Properties: Write Serialize, WriteProtect.
82                                                                   * RomBase: 0xFFFC0
83                                                                   * SysTop to RomBase Properties: Write Serialize, Cache Disable.
84                                                                   * SysTop: 0x000A0 
85                                                                   * System Memory Properties:  (Write Back) */
86        {CPU_RCONF_A0_BF,   {.hi = 0x00000000,.lo = 0x00000000}}, /* 0xA0000-0xBFFFF : (Write Back) */
87        {CPU_RCONF_C0_DF,   {.hi = 0x00000000,.lo = 0x00000000}}, /* 0xC0000-0xDFFFF : (Write Back) */
88        {CPU_RCONF_E0_FF,   {.hi = 0x00000000,.lo = 0x00000000}}, /* 0xE0000-0xFFFFF : (Write Back) */
89        
90        /* Setup access to memory under 1MB. Note: VGA hole at 0xA0000-0xBFFFF */
91        {MSR_GLIU0_BASE1,   {.hi = 0x20000000,.lo = 0x000fff80}}, // 0x00000-0x7FFFF
92        {MSR_GLIU0_BASE2,   {.hi = 0x20000000,.lo = 0x080fffe0}}, // 0x80000-0x9FFFF
93        {MSR_GLIU0_SHADOW,  {.hi = 0x2000FFFF,.lo = 0xFFFF0003}}, // 0xC0000-0xFFFFF
94        {MSR_GLIU1_BASE1,   {.hi = 0x20000000,.lo = 0x000fff80}}, // 0x00000-0x7FFFF
95        {MSR_GLIU1_BASE2,   {.hi = 0x20000000,.lo = 0x080fffe0}}, // 0x80000-0x9FFFF
96        {MSR_GLIU1_SHADOW,  {.hi = 0x2000FFFF,.lo = 0xFFFF0003}}, // 0xC0000-0xFFFFF
97 };
98
99 static void msr_init(void)
100 {
101         int i;
102         for (i = 0; i < ARRAY_SIZE(msr_table); i++)
103                 wrmsr(msr_table[i].msrnum, msr_table[i].msr);
104 }
105
106 static void mb_gpio_init(void)
107 {
108         /* Early mainboard specific GPIO setup */
109 }
110
111 void cache_as_ram_main(void)
112 {
113         post_code(0x01);
114
115         msr_t msr;
116         static const struct mem_controller memctrl[] = {
117                 {.channel0 = {(0xa << 3) | 0, (0xa << 3) | 1}}
118         };
119
120         SystemPreInit();
121         msr_init();
122
123         cs5536_early_setup();
124
125         /* NOTE: must do this AFTER the early_setup!
126          * it is counting on some early MSR setup
127          * for cs5536
128          */
129         /* cs5536_disable_internal_uart  disable them. Set them up now... */
130         cs5536_setup_onchipuart(2); /* dbe61 uses UART2 as COM1 */
131         /* set address to 3F8 */
132         msr = rdmsr(MDD_LEG_IO);
133         msr.lo |= 0x7 << 20;
134         wrmsr(MDD_LEG_IO, msr);
135
136         mb_gpio_init();
137         uart_init();
138         console_init();
139
140         pll_reset(ManualConf);
141
142         cpuRegInit();
143
144         sdram_initialize(1, memctrl);
145
146         /* Dump memory configuratation */
147         /*{
148         msr_t msr;
149         msr = rdmsr(MC_CF07_DATA);
150         print_debug("MC_CF07_DATA: ");
151         print_debug_hex32(MC_CF07_DATA);
152         print_debug(" value is: ");
153         print_debug_hex32(msr.hi);
154         print_debug(":");
155         print_debug_hex32(msr.lo);
156         print_debug(" \n");
157
158         msr = rdmsr(MC_CF1017_DATA);
159         print_debug("MC_CF1017_DATA: ");
160         print_debug_hex32(MC_CF1017_DATA);
161         print_debug(" value is: ");
162         print_debug_hex32(msr.hi);
163         print_debug(":");
164         print_debug_hex32(msr.lo);
165         print_debug(" \n");
166
167         msr = rdmsr(MC_CF8F_DATA);
168         print_debug("MC_CF8F_DATA: ");
169         print_debug_hex32(MC_CF8F_DATA);
170         print_debug(" value is: ");
171         print_debug_hex32(msr.hi);
172         print_debug(":");
173         print_debug_hex32(msr.lo);
174         msr = rdmsr(MC_CF8F_DATA);
175         print_debug(" \n");
176         }*/
177
178         /* Check memory. */
179         /* ram_check(0x00000000, 640 * 1024); */
180 }
181