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