janitor task: unify and cleanup naming.
[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 #define ASSEMBLY 1
22 #define __PRE_RAM__
23
24 #include <stdint.h>
25 #include <device/pci_def.h>
26 #include <arch/io.h>
27 #include <device/pnp_def.h>
28 #include <arch/romcc_io.h>
29 #include <arch/hlt.h>
30 #include <stdlib.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 #include "spd_table.h"
40
41
42 #define POST_CODE(x) outb(x, 0x80)
43
44 #include "southbridge/amd/cs5536/cs5536_early_smbus.c"
45 #include "southbridge/amd/cs5536/cs5536_early_setup.c"
46
47 #define DIMM0 0xA0
48 #define DIMM1 0xA2
49
50
51 static int spd_read_byte(unsigned device, unsigned address)
52 {
53         int i;
54
55         if (device == DIMM0){
56                 for (i=0; i < (ARRAY_SIZE(spd_table)); i++){
57                         if (spd_table[i].address == address){
58                                 return spd_table[i].data;
59                         }
60                 }
61         }
62
63         /* returns 0xFF on any failures */
64         return 0xFF;
65 }
66
67 #define ManualConf 0            /* Do automatic strapped PLL config */
68 /* CPU and GLIU mult/div 500/266*/
69 #define PLLMSRhi 0x0000039C /* 33MHz PCI, 0x000003DD for 66MHz PCI */
70 /* Hold Count - how long we will sit in reset */
71 #define PLLMSRlo 0x00DE6000
72
73 #include "northbridge/amd/lx/raminit.h"
74 #include "northbridge/amd/lx/pll_reset.c"
75 #include "northbridge/amd/lx/raminit.c"
76 #include "lib/generic_sdram.c"
77 #include "cpu/amd/model_lx/cpureginit.c"
78 #include "cpu/amd/model_lx/syspreinit.c"
79
80 static void msr_init(void)
81 {
82         msr_t msr;
83         /* Setup access to the cache for under 1MB. */
84         msr.hi = 0x24fffc02;
85         msr.lo = 0x1000A000;    /* 0-A0000 write back */
86         wrmsr(CPU_RCONF_DEFAULT, msr);
87
88         msr.hi = 0x0;           /* write back */
89         msr.lo = 0x0;
90         wrmsr(CPU_RCONF_A0_BF, msr);
91         wrmsr(CPU_RCONF_C0_DF, msr);
92         wrmsr(CPU_RCONF_E0_FF, msr);
93
94         /* Setup access to the cache for under 640K. Note MC not setup yet. */
95         msr.hi = 0x20000000;
96         msr.lo = 0xfff80;
97         wrmsr(MSR_GLIU0 + 0x20, msr);
98
99         msr.hi = 0x20000000;
100         msr.lo = 0x80fffe0;
101         wrmsr(MSR_GLIU0 + 0x21, msr);
102
103         msr.hi = 0x20000000;
104         msr.lo = 0xfff80;
105         wrmsr(MSR_GLIU1 + 0x20, msr);
106
107         msr.hi = 0x20000000;
108         msr.lo = 0x80fffe0;
109         wrmsr(MSR_GLIU1 + 0x21, msr);
110
111 }
112
113 static void mb_gpio_init(void)
114 {
115         /* Early mainboard specific GPIO setup */
116 }
117
118 static void cs5536_setup_onchipuart2(void)
119 {
120         msr_t msr;
121
122         /* GPIO4 - UART2_TX */
123         /* Set: Output Enable  (0x4) */
124         outl(GPIOL_4_SET, GPIO_IO_BASE + GPIOL_OUTPUT_ENABLE);
125         /* Set: OUTAUX1 Select (0x10) */
126         outl(GPIOL_4_SET, GPIO_IO_BASE + GPIOL_OUT_AUX1_SELECT);
127         /* GPIO4 - UART2_RX */
128         /* Set: Input Enable   (0x20) */
129         outl(GPIOL_3_SET, GPIO_IO_BASE + GPIOL_INPUT_ENABLE);
130         /* Set: INAUX1 Select  (0x34) */
131         outl(GPIOL_3_SET, GPIO_IO_BASE + GPIOL_IN_AUX1_SELECT);
132
133         /* Set: GPIO 3 + 3 Pull Up  (0x18) */
134         outl(GPIOL_3_SET | GPIOL_4_SET, GPIO_IO_BASE + GPIOL_PULLUP_ENABLE);
135
136         /* set address to 3F8 */
137         msr = rdmsr(MDD_LEG_IO);
138         msr.lo |= 0x7 << 20;
139         wrmsr(MDD_LEG_IO, msr);
140
141         /* Bit 1 = DEVEN (device enable)
142          * Bit 4 = EN_BANKS (allow access to the upper banks
143          */
144         msr.lo = (1 << 4) | (1 << 1);
145         msr.hi = 0;
146
147         /* enable COM2 */
148         wrmsr(MDD_UART2_CONF, msr);
149 }
150
151 void cache_as_ram_main(void)
152 {
153         POST_CODE(0x01);
154
155         static const struct mem_controller memctrl[] = {
156                 {.channel0 = {(0xa << 3) | 0, (0xa << 3) | 1}}
157         };
158
159         SystemPreInit();
160         msr_init();
161
162         cs5536_early_setup();
163
164         /* NOTE: must do this AFTER the early_setup!
165          * it is counting on some early MSR setup
166          * for cs5536
167          */
168         /* cs5536_disable_internal_uart  disable them. Set them up now... */
169         cs5536_setup_onchipuart2(); /* dbe61 uses UART2 as COM1 */
170         mb_gpio_init();
171         uart_init();
172         console_init();
173
174         pll_reset(ManualConf);
175
176         cpuRegInit();
177
178         sdram_initialize(1, memctrl);
179
180         /* Dump memory configuratation */
181         /*{
182         msr_t msr;
183         msr = rdmsr(MC_CF07_DATA);
184         print_debug("MC_CF07_DATA: ");
185         print_debug_hex32(MC_CF07_DATA);
186         print_debug(" value is: ");
187         print_debug_hex32(msr.hi);
188         print_debug(":");
189         print_debug_hex32(msr.lo);
190         print_debug(" \n");
191
192         msr = rdmsr(MC_CF1017_DATA);
193         print_debug("MC_CF1017_DATA: ");
194         print_debug_hex32(MC_CF1017_DATA);
195         print_debug(" value is: ");
196         print_debug_hex32(msr.hi);
197         print_debug(":");
198         print_debug_hex32(msr.lo);
199         print_debug(" \n");
200
201         msr = rdmsr(MC_CF8F_DATA);
202         print_debug("MC_CF8F_DATA: ");
203         print_debug_hex32(MC_CF8F_DATA);
204         print_debug(" value is: ");
205         print_debug_hex32(msr.hi);
206         print_debug(":");
207         print_debug_hex32(msr.lo);
208         msr = rdmsr(MC_CF8F_DATA);
209         print_debug(" \n");
210         }*/
211
212         /* Check memory. */
213         /* ram_check(0x00000000, 640 * 1024); */
214
215         /* Memory is setup. Return to cache_as_ram.inc and continue to boot */
216         return;
217 }